Importerror:无法导入名称Spli

2024-09-29 21:23:30 发布

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

我对python很陌生,需要一些帮助。 我认为它来自路径,但我不知道如何修复它。请帮忙。在

Once I type in import split and it keeps popping up

runfile('/Users/zhihaowang/Desktop/untitled1.py', wdir='/Users/zhihaowang/Desktop') Traceback (most recent call last):

File "", line 1, in runfile('/Users/zhihaowang/Desktop/untitled1.py', wdir='/Users/zhihaowang/Desktop')

File "/Users/zhihaowang/anaconda3/lib/python3.5/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 714, in runfile execfile(filename, namespace)

File "/Users/zhihaowang/anaconda3/lib/python3.5/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 89, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "/Users/zhihaowang/Desktop/untitled1.py", line 8, in from string import split

ImportError: cannot import name 'split'


Tags: inpyimportliblinesiteusersfile
2条回答

您不导入split,只需像以下那样使用它: print("my comment".split()) 返回[my,comment]

顺便说一句,拆分是在内置的,而不是字符串。 你不能导入它,你能做的最大值(不会影响任何东西)是from builtins import str

split是标准字符串方法的一部分,而不是来自string模块。不导入也可以只应用分割方法。你的_结构分裂()

相关问题 更多 >

    热门问题