我现在正在学习python模块,并且尝试使用xlsxwriter模块,我在线使用了示例代码,但是似乎存在导入错误
import xlrd
from optparse import OptionParser
import xlsxwriter
workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Hello world')
workbook.close()
loc = ("~/desktop/dictionary.xlsx")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
workbook = xlsxwriter.Workbook('random.xlsx')
worksheet = workbook.add_worksheet()
worksheet.set_column('A:A', 40)
temp = random.sample(random(100),100)
for x in temp:
a = sheet.cell_value(x, 0)
b = sheet.cell_value(x, 1)
c = sheet.cell_value(x, 2)
worksheet.write(a,b,c)
workbook.save("~/desktop/random.xlsx")
workbook.close
但是,有一个错误称为:
Traceback (most recent call last):
File "/Users/mingtaosun/Desktop/hi.py", line 4, in <module>
import xlsxwriter
File "/Library/Python/2.7/site-packages/xlsxwriter/__init__.py", line 3, in <module>
from .workbook import Workbook
File "/Library/Python/2.7/site-packages/xlsxwriter/workbook.py", line 24, in <module>
from .worksheet import Worksheet
File "/Library/Python/2.7/site-packages/xlsxwriter/worksheet.py", line 14, in <module>
import tempfile
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
我该怎么办