开发者

Port Python v2 function to v3

开发者 https://www.devze.com 2023-02-16 17:23 出处:网络
This v2 function gives a 开发者_如何学编程\"NameError: global name \'file\' is not defined\" error when run in v3.

This v2 function gives a 开发者_如何学编程"NameError: global name 'file' is not defined" error when run in v3.

def from_file(filename, sep='\n'):  
    "Parse a file into a list of strings, separated by sep."  
    return file(filename).read().strip().split(sep)  

Could someone please provide a v3 version?


Change the file call to open.

0

精彩评论

暂无评论...
验证码 换一张
取 消