这是什么意思?我有一段很长的老代码,它打开文件并涉及for循环。我只是在主分支中添加了另一个“ with open(file)”,与原始分支相同,目的是不同的。该新块中for循环的范围比原始块小1,这就是为什么我将其分开。此外,这整个过程还包括一个计时器,该计时器应在最后打印时间。它已经工作了很长时间,但是现在甚至还没有到达代码的最后几行。看看:
with open(file, 'rb') as fi:
start_time = time.time() #starts timer
eltime = ""
with open('outfinal.xvg','a') as outfinal:
for frame in range(fr):
# ... bunch of code
with open('outfinal.xvg','r') as outf:
for line in outf:
c_o.append(line)
with open(file, 'rb') as fi:
start_time = time.time() #starts timer
eltime = ""
for frame in range(fr+1):
frame_time = time.time()
with open('frame.gro', 'w') as out:
for line in chunk:
out.write(line)
with open("frame.gro", 'r') as f:
o = np.genfromtxt("frame.gro", dtype=None, skip_header=2, usecols=(0,1,3,4,5), max_rows=atoms) #line w/ error
#... lots of code
print "Total Elapsed Time: %s"%(str(datetime.timedelta(seconds=sec)))
终端中的错误:
anewone.py:219:VisibleDeprecationWarning:不建议在不指定encoding参数的情况下读取unicode字符串。设置编码,对系统默认值使用无。 o = np.genfromtxt(“ frame.gro”,dtype = None,skip_header = 2,usecols =(0,1,3,4,5),max_rows = atoms) 回溯(最近一次通话):: 00:22.135060 |预计剩余时间:0:00:00.031266 在文件“ anewone.py”的第219行中 o = np.genfromtxt(“ frame.gro”,dtype = None,skip_header = 2,usecols =(0,1,3,4,5),max_rows = atoms) genfromtxt中的文件“ /usr/local/lib/python2.7/dist-packages/numpy/lib/npyio.py”,行1707 下一个(fhd) StopIteration
我习惯于看到此错误,因为该代码实际上在将数据读取和写入所需文件时效果很好。但是我想在终端上显示时间