顺着你的思路, 我又在网上搜了一些代码,整体如下, 但是运行会报错,能看看这个代码哪里有问题么?D:\Pycharmprojects\mmW_Efield_postprocessing\venv\Scripts\python.exe D:/Pycharmprojects/mmW_Efield_postprocessing/collect_EIRP.py
"0.222W"
Traceback (most recent call last):
"100deg"
File "D:/Pycharmprojects/mmW_Efield_postprocessing/collect_EIRP.py", line 20, in <module>
for line in f:
io.UnsupportedOperation: not readable
谢谢from openpyxl import Workbook
from openpyxl import load_workbook
from openpyxl.writer.excel import ExcelWriter
rEIRP = load_workbook('C:\\Users\\gaoqiang5\\Desktop\\1111.xlsx')
A_sheet = rEIRP['Sheet1']
sheet = rEIRP.active
b = sheet.max_row
A_AG0_V1_P = A_sheet.cell(4,2).value
A_AG0_V1_phi = A_sheet.cell(4,3).value
A_AG0_V1_P = """+A_AG0_V1_P+"""
A_AG0_V1_phi = """ +A_AG0_V1_phi +"""
print(A_AG0_V1_P)
print(A_AG0_V1_phi)
f = open('C:\\Users\\gaoqiang5\\Desktop\\test.txt', mode="w", encoding="utf-8")
f_new = open('C:\\Users\\gaoqiang5\\Desktop\\new.txt', mode="w", encoding="utf-8")
find_str = "A_Raw"
replace_str = A_AG0_V1_P
for line in f:
if find_str in line:
line = line.replace(find_str,replace_str)
f_new = write(line)
f.close()
f_new.close()
#os.remove("test.txt")
os.rename("new.txt", "new.py")
|