with open('james.txt') as jaf:
data=jaf.readline()
james=data.strip().split(',')
这是部分代码,但是运行后strip()方法不起作用
strip()方法只删除开头和结尾处的空格。
代码本身并没有问题,但是可能不是你想要的结果。
该代码运行的是将第一行的开头和结尾空格去掉。
如果是想去点“,”前后的空格,应该是:
with open('james.txt') as jaf:
data=jaf.readline()
james=[d.strip() for d in data.split(',')]
print(james)
strip()如果不写其他内容,默认是去除首尾的空格的