numpy.genfromtxt path value



我想加载一个带有genformtxt()的txt文件。TXT文件已经在C中:。

stock=np.genfromtxt('c:9012017.txt',delimiter=' ',dtype=str,skip_header=1)
C:Anaconda3libsite-packagesnumpylibnpyio.py in genfromtxt(fname, dtype, comments, delimiter, skip_header, skip_footer, converters, missing_values, filling_values, usecols, names, excludelist, deletechars, replace_space, autostrip, case_sensitive, defaultfmt, unpack, usemask, loose, invalid_raise, max_rows)
   1549                 fhd = iter(np.lib._datasource.open(fname, 'rbU'))
   1550             else:
-> 1551                 fhd = iter(np.lib._datasource.open(fname, 'rb'))
   1552             own_fhd = True
   1553         else:
C:Anaconda3libsite-packagesnumpylib_datasource.py in open(path, mode, destpath)
    149 
    150     ds = DataSource(destpath)
--> 151     return ds.open(path, mode)
    152 
    153 
C:Anaconda3libsite-packagesnumpylib_datasource.py in open(self, path, mode)
    492 
    493         # NOTE: _findfile will fail on a new file opened for writing.
--> 494         found = self._findfile(path)
    495         if found:
    496             _fname, ext = self._splitzipext(found)
C:Anaconda3libsite-packagesnumpylib_datasource.py in _findfile(self, path)
    335 
    336         for name in filelist:
--> 337             if self.exists(name):
    338                 if self._isurl(name):
    339                     name = self._cache(name)
C:Anaconda3libsite-packagesnumpylib_datasource.py in exists(self, path)
    440 
    441         # Test local path
--> 442         if os.path.exists(path):
    443             return True
    444 
C:Anaconda3libgenericpath.py in exists(path)
     17     """Test whether a path exists.  Returns False for broken symbolic links"""
     18     try:
---> 19         os.stat(path)
     20     except OSError:
     21         return False
ValueError: stat: embedded null character in path

在路径上看起来像是错误的。我100%确定TXT在圆盘c:路径下。请提供一些帮助。谢谢

您要么必须使用前向斜线,要么要使用双反斜线

stock=np.genfromtxt('c:/09012017.txt',delimiter=' ',dtype=str,skip_header=1)

stock=np.genfromtxt('c:\09012017.txt',delimiter=' ',dtype=str,skip_header=1)

如果您只使用一个后斜线,它将被视为逃生命令,这不是您想在那里做的事情。

如果您只调用文件名而不是绝对路径,则文件必须位于python进程的工作目录中;这是Shell的工作目录,它启动了您的Python过程。

相关内容

  • 没有找到相关文章

最新更新