Wxpython脚本给出“TypeError:”in<string>“需要字符串作为左操作数,而不是QString”

2024-10-01 09:42:01 发布

您现在位置:Python中文网/ 问答频道 /正文

这个简单的wxpytohn脚本给出了以下错误,怎么了?错误消息不会给出脚本中发生错误的行:

Traceback (most recent call last):
  File "c:\Python27\lib\site-packages\spyderlib\plugins\externalconsole.py", line 721, in run_script_in_current_shell
    "and try again.") % osp.basename(filename), QMessageBox.Ok)
  File "c:\Python27\lib\ntpath.py", line 198, in basename
    return split(p)[1]
  File "c:\Python27\lib\ntpath.py", line 173, in split
    while i and p[i-1] not in '/\\':
TypeError: 'in <string>' requires string as left operand, not QString

脚本如下:

^{pr2}$

Tags: andinpy脚本stringlib错误line
3条回答

问题似乎是

p[i-1] not in '/\\'

p[i-1]QString,而Python需要一个字符串。也许是

^{pr2}$

解决问题。在

截至2015年12月,奇怪的是,同样的问题仍然存在,尽管据报道的1540问题已被修复:代码包含(例如)以下行:

newPath = os.path.dirname(newFile)

在蜘蛛下面跑。在windows中用cmd编译时,会抛出TypeError: TypeError:“in”需要字符串作为左操作数,而不是QString

您可以考虑:

^{pr2}$

here存在spyderlib问题。显然它已经关闭了,所以也许可以尝试更新你的库,看看它是否仍然是个问题。在

Log

Log message

Executing script in current Python/IPython interpreter while no interpreter is
running was raising a TypeError exception:

Traceback (most recent call last):
  File "[...]\spyderlib\plugins\externalconsole.py", line 722, in
run_script_in_current_shell
    "and try again.") % osp.basename(filename), QMessageBox.Ok)
  File "[...]\python-2.7.5.amd64\lib\ntpath.py", line 198, in basename
    return split(p)[1]
  File "[...]\python-2.7.5.amd64\lib\ntpath.py", line 173, in split
    while i and p[i-1] not in '/\\':
TypeError: 'in <string>' requires string as left operand, not QString

Update  Issue 1540 
Status: Fixed

Affected files
    expand all   collapse all
    Modify  /spyderlib/plugins/externalconsole.py   diff

相关问题 更多 >