我正在尝试读取作为字符串存储在数据文件中的文件名。那里没问题。如果我将它传递给 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
2个打印语句给出
%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.]]
现在似乎与传递字符串有关-请提供任何建议