Notice: wp_deregister_script的调用方法不正确。脚本和样式应在wp_enqueue_scriptsadmin_enqueue_scriptslogin_enqueue_scripts钩子之后再加入加载队列(enqueue)或注册(register)。 This notice was triggered by the l10n handle. 请查阅调试WordPress来获取更多信息。 (这个消息是在3.3.0版本添加的。) in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 5225

Notice: Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-banner.php on line 11

Deprecated: 在d_banner中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用__construct()。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866

Notice: Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-slidebanner.php on line 11

Deprecated: 在d_slidebanner中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用__construct()。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866

Notice: Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-readers.php on line 11

Deprecated: 在d_reader中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用__construct()。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866

Notice: Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-postlist.php on line 11

Deprecated: 在d_postlist中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用__construct()。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866

Notice: Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-comment.php on line 11

Deprecated: 在d_comment中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用__construct()。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866

Notice: Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-tags.php on line 11

Deprecated: 在d_tag中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用__construct()。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866

Notice: Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-textbanner.php on line 11

Deprecated: 在d_textbanner中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用__construct()。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866
【已解决】Python3中,使用xlwt3去生成excel文件时出错:struct.error: argument for ‘s’ must be a bytes object – 在路上
最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【已解决】Python3中,使用xlwt3去生成excel文件时出错:struct.error: argument for ‘s’ must be a bytes object

Python3 crifan 2221浏览 0评论

【问题】

Python3中,使用xlwt3时,出现错误:

Traceback (most recent call last):
  File "G:\34563264_data_from_site\34563264_data_from_site.py", line 283, in <module>
    main();
  File "G:\34563264_data_from_site\34563264_data_from_site.py", line 262, in main
    wb.save(excelFilename);
  File "E:\dev_install_root\Python32\lib\site-packages\xlwt3\Workbook.py", line 633, in save
    doc.save(filename, self.get_biff_data())
  File "E:\dev_install_root\Python32\lib\site-packages\xlwt3\Workbook.py", line 583, in get_biff_data
    before += self.__write_access_rec()
  File "E:\dev_install_root\Python32\lib\site-packages\xlwt3\Workbook.py", line 436, in __write_access_rec
    return BIFFRecords.WriteAccessRecord(self.__owner).get()
  File "E:\dev_install_root\Python32\lib\site-packages\xlwt3\BIFFRecords.py", line 233, in __init__
    uowner, b' '*(0x70 - uowner_len)) # (to_py3): added b'...'
struct.error: argument for 's' must be a bytes object

 

【解决过程】

1.参考:

python32版本,出现问题“struct.error: argument for ‘s’ must be a bytes object”的解决办法

去找到出错位置:

Python32\Lib\site-packages\xlwt3\BIFFRecords.py

把WriteAccessRecord -> __init__

中的,pack中的uowner改为uowner.encode("utf-8"),即:

把:

        self._rec_data = pack('%ds%ds' % (uowner_len, 0x70 - uowner_len),
                              uowner, b' '*(0x70 - uowner_len)) # (to_py3): added b'...'

改为:

        self._rec_data = pack('%ds%ds' % (uowner_len, 0x70 - uowner_len),
                              uowner.encode("utf-8"), b' '*(0x70 - uowner_len)) # (to_py3): added b'...'

即可。

 

【总结】

Python3中的bytes和str,不知道别人用的是否爽,总之我是用着很郁闷,还是没有Python2中str和unicode用着爽。

转载请注明:在路上 » 【已解决】Python3中,使用xlwt3去生成excel文件时出错:struct.error: argument for ‘s’ must be a bytes object


Warning: Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17

Deprecated: 自4.5.0版本起,已不建议使用get_currentuserinfo,请换用wp_get_current_user()。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4773
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

Notice: Undefined variable: wp_sh_class_name in /data/wwwroot/www.crifan.com/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1002

Notice: Undefined variable: wp_sh_class_name in /data/wwwroot/www.crifan.com/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1002

Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.com/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048
53 queries in 0.175 seconds, using 18.60MB memory