我寫了一個程序打開文件和打印每一行,如果該文件不存在創建它,並寫一些線將其 它完美的作品時,該文件不存在目錄 但是當文件有它打開的文件中讀取它 - >然後將其寫入文件,但它只能讀取文件 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邏輯塊。這是設置...我想