我在trial.txt
中搜索存在于non_int_ram_var
中的文本。non_int_ram_var
从基本上是unicode的excel表中获取数据。所以我将其类型转换为str
,这样trial.txt
类型将与non_int_ram_var
匹配。但是控件没有进入if var in line:
。我已经交叉验证了var
存在于文本文件的一行中。我可能弄错了。谁能给我一个建议吗?你知道吗
from xlrd import open_workbook
import unicodedata
work_book= open_workbook("C:\\Users\\E542639\\Desktop\\non_sram_mem\\SEU_MBU_FINAL_VARIABLE_LIST.xls");
# reading xls file for non_int sram..............
non_int_ram_var = [] * 376
row=1
for sheet in work_book.sheets():
if "Data" == sheet.name :
print sheet.nrows, sheet.ncols
while row < sheet.nrows:
if "int_sram" != sheet.cell(row,5).value:
if "file name only" != sheet.cell(row,7).value :
non_int_ram_var.append(str(sheet.cell(row,1).value))
row=row + 1
# checking variable in mapfile.........
map_file = open("C:\\Users\\E542639\\Desktop\\non_sram_mem\\trial.txt", "r")
non_categorized = open("C:\\Users\\E542639\\Desktop\\non_sram_mem\\non_categorized.txt","w")
print "processing..."
for var in non_int_ram_var:
while True:
line = str.encode(map_file.readline())
if not line: break
if var in line:
print "control here"
non_categorized.writelines(line) # write won't work
print 'done!!!'
map_file.close()
non_categorized.close()
==============================================================================
在下一次迭代中读取到文件末尾之后,光标并没有到达文件的开头。那是我的错。谢谢你,你的建议给我指明了方向。这就是我现在所做的,工作很好。你知道吗
如果不是直线: 地图_文件.seek(0) 中断
默认情况下,Python将文件读入str对象。你知道吗
我想你可以试试
相关问题 更多 >
编程相关推荐