import osfor i in range1000 with opensdtxtiwencoding=utf-8 as f fwrite111111111111 100000 i += 1 printr已经完成!formatinti1000end= 运行总是0
It seems that your code is not running properly and always printing 0. There are a couple of issues with your code that might be causing this problem.
Firstly, the line i += 1 is unnecessary as you are already incrementing i in the for loop. Removing this line will fix the issue of always printing 0.
Secondly, the path 's/%d.txt'%i suggests that you are trying to create files in a directory named 's'. However, it seems that this directory does not exist. You need to create the directory before running this code.
Here is an updated version of your code that should work as expected:
import os
# Create the 's' directory if it doesn't exist
if not os.path.exists('s'):
os.makedirs('s')
for i in range(1000):
with open('s/%d.txt' % i, 'w', encoding='utf-8') as f:
f.write('111111111111' * 100000)
print("\r已经完成{}%!".format(int((i + 1) / 1000 * 100)), end=" ")
Make sure to create the 's' directory before running this code, and it should display the progress correctly
原文地址: https://www.cveoy.top/t/topic/hABi 著作权归作者所有。请勿转载和采集!