【发布时间】:2014-02-21 07:28:45
【问题描述】:
我正在尝试读取以字符串形式存储在数据文件中的文件名。那里没问题。如果我将它传递给 genfromtxt,我会收到错误“IOError: Z:\Python\Rb input.txt not found”。如果我将文件名明确地放入 genfromtxt 中,它就可以工作
此操作失败并出现错误“IOError: Z:\Python\Rb input.txt not found.”
import numpy
modat = open('z:\python\mot1 input.txt') # open file with names in
rbfile = modat.readline() # read data file name
print rbfile # print the file name
rb = numpy.genfromtxt(rbfile, delimiter =',')
print rb
但他的作品
import numpy
modat = open('z:\python\mot1 input.txt') # open file with names in
rbfile = modat.readline() # read data file name
print rbfile
rb = numpy.genfromtxt('z:\python\Rb input.txt', delimiter =',')
print rb
两个打印语句给出
%run "c:\users\ian\appdata\local\temp\tmpkiz1n0.py"
Z:\Python\Rb input.txt
[[ 2. 10.]
[ 3. 11.]
[ 5. 13.]
[ 10. 15.]
[ 15. 16.]
[ 20. 16.]
[ 30. 22.]]
现在似乎与传递字符串有关 - 请提供任何建议
【问题讨论】:
-
你试过
rbfile.rstrip()吗?
标签: python file numpy names genfromtxt