0
votes

I am very new to python and need some help here. I think it comes from PATH,but I have no clue about fixing it. Please help.

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'

2

2 Answers

0
votes

split is part of standard string method not from string module. Without importing also you could just apply split method. your_str.split()

0
votes

You don't import split, you just use it like: print("my comment".split()) which returns [my,comment]

btw, split is at builtins , not string. and you cant import it, the maximum you can do(which don't effects anything) is from builtins import str