with open()Python 2.6支持该语句,您必须有其他错误。
有关详细信息,请参见PEP 343和python File
Objects文档。
快速演示:
Python 2.6.8 (unknown, Apr 19 2012, 01:24:00) [GCC 4.2.1 (based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> with open('/tmp/test/a.txt') as f:... print f.readline()... foo>>>
但是,您尝试将
with语句与多个上下文管理器一起使用,该语句仅在Python
2.7中添加:
在2.7版中进行了更改:支持多个上下文表达式。
在2.6中使用嵌套语句:
with open("check_files/"+exportfileCheckFilesFolder+".txt") as f1: with open("transfer-out/"+exportfileTransferFolder) as f2: # f1 and f2 are now both open.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)