我写了一个程序打开文件和打印每一行,如果该文件不存在创建它,并写一些线将其 它完美的作品时,该文件不存在目录 但是当文件有它打开的文件中读取它 - >然后将其写入文件,但它只能读取文件 print("We will do some file operation")
filename=input("enter a file name: ")
try:
file=open(filename,'r
我意识到已经讨论过是否使用If/Else或Try/Except块。这样的问题所在位置:Better to 'try' something and catch the exception or test if its possible first to avoid an exception? 但我想讨论一点点进一步扩大到嵌套try/except和嵌套if/elif/else逻辑块。这是设置...我想