标签: with-statement

VBA - “With”语句的目的是什么

我阅读了 Microsoft 的 With-Statement 文档,但仍然不明白该With语句的目的是什么......


来自 Reddit 的 Xpost认为这确实应该在 Stack Overflow 上的某个地方,但找不到任何此类性质的问题。

vba with-statement

0
推荐指数
1
解决办法
1017
查看次数

php中的语句是什么?

我刚刚在我刚刚安装的laravel包中发现了这个,并且真的不知道是什么with()...因为它没有在任何地方声明

public static function of($query)
{
    $ins = with(new static); // What is with(new static) ?
    $ins->save_query($query);
    return $ins;
}
Run Code Online (Sandbox Code Playgroud)

php static with-statement

-1
推荐指数
1
解决办法
140
查看次数

python3中自动关闭文件?

我的想法是否正确,这会自动关闭文件?

def get_file():
    with open("file.csv", "rb") as f:
        yield f

f = get_file()
do_stuff(f)
Run Code Online (Sandbox Code Playgroud)

如果没有,我如何编写一个返回文件对象的函数,同时确保它在接收器使用完文件后关闭该文件?

python yield file with-statement python-3.x

-1
推荐指数
1
解决办法
1669
查看次数

无法使用'with'删除已打开(并关闭?)的文件

如何关闭此文件.任何的想法?

 with open('output.txt','w', encoding='UTF-8') as output:
       output.writelines(str(i)+'\n' for i in range(5))
Run Code Online (Sandbox Code Playgroud)

python with-statement python-3.x

-2
推荐指数
1
解决办法
151
查看次数

如何在严格模式下替换`with`语句

此代码运行最佳并且易于理解:

function evalInScope(js, contextAsScope) {
    //# Return the results of the in-line anonymous function we .call with the passed context
    return function() {
        with(this) {
            return eval(js);
        };
    }.call(contextAsScope);
}
evalInScope("a + b", {a: 1, b: 2}); // 3 obviously, but fails in strict mode!
Run Code Online (Sandbox Code Playgroud)

然而,“聪明”的大脑决定删除该with声明,而不进行适当的替换。

问题:如何让它在自动处于严格模式的 ES6 中再次工作?

javascript with-statement strict-mode ecmascript-6

-3
推荐指数
1
解决办法
135
查看次数