2016-05-01 12 views

答えて

2

にコードオフパスを追加します。

他のパスを使用する場合は、のパスにopen("/path/to/something/{}.txt".format(i),"w")、またはより確実にはopen(os.path.join(yourpath, "{}.txt".format(i),"w")のようなものを使用できます。

これで、増分値のループは一般的にはPythonでは良い形とは考えられません。私はお勧めします

for i in range(1,11): # range doesn't include the last value 
    with open("{}.txt".format(i), 'w') as f: 
     f.write("content") 
関連する問題

 関連する問題