dreamyeyu 发表于 2020-9-16 10:32:34

excel-wt

大佬们求助一下 为什么这段代码报错了 没生成新excel 谢谢大佬

import xlwt

#write
new_workbook = xlwt.Workbook()
worksheet = new_workbook.add_sheet('test_sheet')
worksheet.write(0,0,'test')
new_workbook.save('d:/test.xls')

报错原因       
Traceback (most recent call last):
File "c:\Users\11573\python练手\excel - 副本.py", line 1, in <module>
    import xlwt
File "C:\Python37\lib\site-packages\xlwt\__init__.py", line 4, in <module>
    from .Worksheet import Worksheet
File "C:\Python37\lib\site-packages\xlwt\Worksheet.py", line 41, in <module>
    import tempfile
File "C:\Python37\lib\tempfile.py", line 45, in <module>
    from random import Random as _Random
File "c:\Users\11573\python练手\random.py", line 3, in <module>
    secret=random.randint(1,100)
AttributeError: module 'random' has no attribute 'randint'

疾风怪盗 发表于 2020-9-16 10:35:59

运行了下这段代码,并没有报错,正常运行,在D盘根目录下也找到了test.xls,里面也有内容
import xlwt

#write
new_workbook = xlwt.Workbook()
worksheet = new_workbook.add_sheet('test_sheet')
worksheet.write(0,0,'test')
new_workbook.save('d:/test.xls')

挥舞乾坤 发表于 2020-9-16 10:41:27

c:\Users\11573\python练手\random.py
这个文件造成的,为了避免出错,自己写的代码尽量不要与python的模块重名

dreamyeyu 发表于 2020-9-16 10:43:53

挥舞乾坤 发表于 2020-9-16 10:41
c:%users\11573\python练手\random.py
这个文件造成的,为了避免出错,自己写的代码尽量不要与python的模 ...

好的 谢谢大佬!

dreamyeyu 发表于 2020-9-16 10:50:18

疾风怪盗 发表于 2020-9-16 10:35
运行了下这段代码,并没有报错,正常运行,在D盘根目录下也找到了test.xls,里面也有内容

好的谢谢大佬
页: [1]
查看完整版本: excel-wt