Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python不使用w+;使用绝对路径_Python_Numpy_Save - Fatal编程技术网

python不使用w+;使用绝对路径

python不使用w+;使用绝对路径,python,numpy,save,Python,Numpy,Save,我已检查目录是否存在,并且正在使用Pathlib 据我所知,我已经成功地使用了相同的语法,但对于某些行,只有代码失败,出现了“文件不存在”错误: 只是一个失败的例子 print(data_folder.is_dir()) #when I run, returns True with (data_folder / "lensingtimedelayswithinimage.npy" ).open(mode="w+b") as lensingtimedelaysfile: np.sav

我已检查目录是否存在,并且正在使用Pathlib

据我所知,我已经成功地使用了相同的语法,但对于某些行,只有代码失败,出现了“文件不存在”错误:

只是一个失败的例子

print(data_folder.is_dir()) #when I run, returns True

with (data_folder / "lensingtimedelayswithinimage.npy" ).open(mode="w+b") as lensingtimedelaysfile: 
     np.save(lensingtimedelaysfile, np.array(tdwithinimage))
并返回错误

FileNotFoundError:[Errno 2]没有这样的文件或目录:“C:\Users\angel\u 000\Documents\ArchiveofDocuments\2019\New\u Time\u Delay\u Code\Thin\Rmax\u 200\u Fractinc\u 0p5\200\LCDM\zs\u 3\u zl\u 1\u C\u 299792458\u H0\u 75\beta\u 0p065\软化椭球\u等温\b\u 1s\u 0p1\u 0p1\u\u0\u0\u0\u1\u0\u0\u0\u1\u0\u0\u0\u0\u0\u0\u0\u0\u0\u0\u0\u0

同一代码中的另一个示例

data_folder_main.mkdir(parents=True, exist_ok=True)

try:
    if (data_folder_main / "imagepositions.npy").stat().st_size == 0:
        raise ValueError('Empty file')
    with (data_folder_main / "imagepositions.npy").open(mode="rb") as imagepositionsfile:
        theta_all_arraylist = np.load(imagepositionsfile)        
except (FileNotFoundError, ValueError) as error:
    theta_all_arraylist = lensmodel.theta_all_arraylist(betaarray.astype('float64'))
    with (data_folder_main / "imagepositions.npy").open(mode="w+b") as imagepositionsfile: #save the image position of the particles
        np.save(imagepositionsfile, theta_all_arraylist)  #this runs fine each time      
    with (data_folder_main / "imagepositionscentre.npy").open(mode="w+b") as imagepositionscentrefile: save the image position of the particles
        np.save(imagepositionscentrefile, theta_centresource) #this fails each time with file not found
您给出的示例(路径加文件名)长度为280个字符,超过了Windows上文件名的最大长度(约260个字符,请参见示例)。请尝试使用较短的文件名或路径(或两者都使用!)