numpy.genfromtxt路径值

时间:2017-09-04 14:51:35

标签: python numpy genfromtxt

我想用genformtxt()加载一个txt文件。 txt文件已经在c:。

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

C:\Anaconda3\lib\site-packages\numpy\lib\npyio.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:\Anaconda3\lib\site-packages\numpy\lib\_datasource.py in open(path, mode, destpath)
    149 
    150     ds = DataSource(destpath)
--> 151     return ds.open(path, mode)
    152 
    153 

C:\Anaconda3\lib\site-packages\numpy\lib\_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:\Anaconda3\lib\site-packages\numpy\lib\_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:\Anaconda3\lib\site-packages\numpy\lib\_datasource.py in exists(self, path)
    440 
    441         # Test local path
--> 442         if os.path.exists(path):
    443             return True
    444 

C:\Anaconda3\lib\genericpath.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在disc c:path下。 请给我一些帮助。感谢

1 个答案:

答案 0 :(得分:0)

您必须使用正斜杠或双反斜杠

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

python

如果你只使用一个反斜杠,它将被视为一个转义命令,这不是你想要做的事情。

如果只调用文件名而不是绝对路径,则该文件必须位于<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ var max_fields = 10; var wrapper = $(".container1"); var add_button = $(".add_form_field"); var x=1; $(add_button).click(function(e){ e.preventDefault(); if(x < max_fields){ x++; $(wrapper).append('<div><input type="text" name="mytext[]"/></div><div><input type="text" name="mytext2[]"/><a href="#" class="delete">Delete</a></div>'); //add input box } else{ alert('You Reached the limits'); } }); $(wrapper).on("click", ".delete", function(e){ e.preventDefault(); $(this).parent('div').remove(); x--; }); }); </script> <form action="<?php base_url();?>index.php/Welcome/formdata" method="POST"> <div class="container1"> <button class="add_form_field">Add New Field &nbsp; <span style="font-size:16px; font-weight:bold;">+ </span></button> <div><input type="text" name="mytext[]"></div> <div><input type="text" name="mytext2[]"></div> </div> <input type="submit" name="submit"/> </form> 进程的工作目录中;这是shell的工作目录,它启动了你的python进程。