我需要知道是否存在python模块,而不导入它.
导入可能不存在的东西(不是我想要的东西):
try:
import eggs
except ImportError:
pass
Run Code Online (Sandbox Code Playgroud) 我正在尝试将文字写给我正在关注此帖子的excel 。这之前工作正常,但现在却没有。我得到:
错误:
line 122, in <module>
worksheet.write(0, 11, 'HI')
AttributeError: 'Worksheet' object has no attribute 'write'
Run Code Online (Sandbox Code Playgroud)
df1
A E
c d
c D
Run Code Online (Sandbox Code Playgroud)
码:
writer = pd.ExcelWriter("C:\\33.xlsx")
df1.to_excel(writer, startrow=0, startcol=0, index = False)
worksheet = writer.sheets['Sheet1']
worksheet.write(0, 11, 'YO')
worksheet.write(1, 11, 'HI')
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
import xlrd
import xlwt
from xlutils.copy import copy
import os.path
rb = xlrd.open_workbook('C:\\13.xlsx',formatting_info=True)
r_sheet = rb.sheet_by_index(0)
wb = copy(rb)
sheet = wb.get_sheet(0)
sheet.write(5,2,"string")
wb.save('C:\\13.xlsx')
Run Code Online (Sandbox Code Playgroud)
我得到:
with open(filename, "rb") as f:
OSError: [Errno 22] Invalid …Run Code Online (Sandbox Code Playgroud)