【发布时间】:2016-06-18 20:53:13
【问题描述】:
我正在尝试打开一个文件,如果该文件不存在,我需要创建它并打开它进行写入。到目前为止我有这个:
#open file for reading
fn = input("Enter file to open: ")
fh = open(fn,'r')
# if file does not exist, create it
if (!fh)
fh = open ( fh, "w")
错误消息显示if(!fh) 行存在问题。我可以像在 Perl 中一样使用exist 吗?
【问题讨论】:
标签: python createfile