這是我的代碼:如何刪除特定文件的消息?蟒蛇
old_stdout = sys.stdout
pymol.finish_launching()
log_file=open('loops.log', "w")
sys.stdout = log_file
def myfunc(resi):
print '%s' % (resi)
file= '%s'%model_initial
x= pymol.cmd.load (file, 'r')
myspace = {'myfunc': myfunc}
d= pymol.cmd.iterate('(ss l)', 'myfunc(resi)', space=myspace)
print d
pymol.cmd.quit()
sys.stdout = old_stdout
log_file.close()
old_stdout = sys.stdout
pymol.finish_launching()
log_file=open('list.log', "w")
sys.stdout = log_file
infile = 'loops.log'
outfile = 'loops1.log'
try:
delete_list = [ "Adjusting settings to improve performance for Intel cards."]
fin = open(infile)
fout = open(outfile, "w+")
for line in fin:
for word in delete_list:
line = line.replace(word, "")
fout.write(line)
fin.close()
fout.close()
outfile = infile
except:
infile = infile
with open(INFILE) as f:
lines = f.read().splitlines()
lines = lines
lines=lines[:-1]
lines=map(int, lines) #Convert str list to int list
lines=lines[:-1]
lines=map(int, lines) #Convert str list to int list
def group_runs(li,tolerance=2):
out = []
last = li[0]
for x in li:
if x-last > tolerance:
yield out
out = []
out.append(x)
last = x
yield out
print list(group_runs(lines))
sys.stdout = old_stdout
log_file.close()
old_stdout = sys.stdout
pymol.finish_launching()
log_file=open('list.log', "w")
sys.stdout = log_file
fhand=open('list.log')
for lines in fhand:
print lines
for k, g in groupby(enumerate(lines), lambda (i,x):i-x):
ranges = []
group = map(itemgetter(1), g)
ranges.append((group[0], group[-1]))
print ranges
sys.stdout = old_stdout
log_file.close()
文件loops.log,與許多數字(選擇模式初始的他們,該代碼的功能主要文件是他們實驗組:
組它們:
(1,4)
(8,9)
(11 ,11)
(15,15)
此代碼的工作,但是,當文件中有很多很多的數字,我有這樣的消息:
Traceback (most recent call last):
File "./automaticvF.py", line 232, in <module>
lines=map(int, lines) #Convert str list to int list
ValueError: invalid literal for int() with base 10: 'Adjusting settings to improve performance for Intel cards.
和日誌是白色的。我認爲這是更容易刪除我的文件loops.log的消息,並更改文件的名稱。這隻發生在有許多很多很多數字組的時候,但是當我有80個數字時,例如沒有問題。那麼我可以在這個CODe中改變什麼,以便使用變量infile,這取決於消息是否在infile中是舊的?
有人可以幫助我嗎?
感謝
發生此錯誤是因爲此行(「調整設置以提高英特爾卡的性能」)包含在輸入文件中。 – yole 2015-02-23 20:55:33
如何避免在輸入文件中打印此消息? 當輸入文件中元素(數字)數量較少時,不會發生。 – Hdez 2015-02-23 20:58:48
您可能想告訴我們您的輸入文件是如何生成的。 – yole 2015-02-23 20:59:52