简体   繁体   English

(Python)IOError出现问题:[Errno 2]没有这样的文件或目录:

[英](Python) Having problems with IOError: [Errno 2] No such file or directory:

Ok, so I've been developing this code to open File1 to extract the first column of it and paste it into the first column of File2 . 好的,所以我一直在开发此代码以打开File1来提取它的第一列并将其粘贴到File2的第一列中。 So far I believe my code as it is coded would work, but for some reason, my File1 isn't reading. 到目前为止,我相信我的代码可以正常工作,但是由于某种原因,我的File1无法读取。 I keep getting this error: 我不断收到此错误:

IOError: [Errno 2] No such file or directory: 'C:\\Data_reader_project_(HARBOR)\\TestFilesForAlan-Aerostat160215\\Aerostat160215\\AtmoSniffer160215\\dyn_0' 

I have checked the paths and they seem to exist, my parent directory also exists. 我检查了路径,它们似乎存在,我的父目录也存在。

Here is my code: 这是我的代码:

 File1= 'C:\Data_reader_project_(HARBOR)\TestFilesForAlan-Aerostat160215\Aerostat160215\AtmoSniffer160215\dyn_0'

 File2 = 'C:\Data_reader_project_(HARBOR)\TestFilesForAlan-Aerostat160215\Aerostat160215\HiSAM1_data_160215_164858'


with open(File1,'r') as file1, open(File2,'w') as file2:
    for line in file1:
       x=line.split()
       file2.write('\n',join((x[0],x[0]))+'\n')

I've made sure that in both of my file paths there isn't anything like I like apples , I know that would make python to not detect my path, so in my file path I have everything like this `I_like_apples'. 我已经确保在我的两个文件路径中都没有像I like apples这样的东西,我知道这会使python无法检测到我的路径,因此在我的文件路径中我拥有类似“ I_like_apples”的所有内容。 Nonetheless, other than this potential bug I can't think of anything else. 尽管如此,除了这个潜在的错误之外,我别无其他。

Any input would help. 任何输入都会有所帮助。

try this: 尝试这个:

 File1= 'C:\\Data_reader_project_(HARBOR)\\TestFilesForAlan-Aerostat160215\\Aerostat160215\\AtmoSniffer160215\\dyn_0'

 File2 = 'C:\\Data_reader_project_(HARBOR)\\TestFilesForAlan-Aerostat160215\\Aerostat160215\\HiSAM1_data_160215_164858'

or 要么

File1= 'C:/Data_reader_project_(HARBOR)/TestFilesForAlan-Aerostat160215/Aerostat160215/AtmoSniffer160215/dyn_0'

File2 = 'C:/Data_reader_project_(HARBOR)/TestFilesForAlan-Aerostat160215/Aerostat160215/HiSAM1_data_160215_164858'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM