首页 > 解决方案 > IOError although file name is correct and in the same folder

问题描述

I imported an Excel file (.xlsx) with pandas, and it worked great.

Then, I tested my code with a copy of the same file (I changed something in its content to test something). I named it differently, and changed the name of the file in the code as well, and it worked great.

HOWEVER NOW - I tried to import the original file again (I didn't forget to change the name in the code as well) - and it doesn't recognizes it anymore!

I checked many times that the name of the file is identical to the one I wrote in the code, and that the .py file is in the same folder as the .xlsx file - I don't get it - why doesn't it work anymore?

Please look at the attached screenshot, where you can see the code, and also the actual file name and that the files are in the same folder (left side of the screenshot)

Please help me understand and fix the situation.

Thank you!

p.s - the "Invalid file name" message is what I wrote in the 'except' block after the 'try' block.

except IOError: print("Invalid file name")

[Screenshot showing file name matches in code + excel file and python file in the same folder][1]

[1]: https://i.stack.imgur.com/FPWhM.pngstrong text

标签: pandaspycharmpython-importimport-from-excelioerror

解决方案


RESOLVED Has something to do with Right to Left languages aka Hebrew and Arabic... If your language is one of these and you face the same problem - try what I did

How I found out and what I did to fix it: I tried to rewrite the file name, and when I started deleting it, I noticed the typing pointer is facing the left side (like in languages that write Right to Left).. After deleting the entire file name I made sure my keyboard is set to English (my native language is Hebrew, which is Right to Left) - although as you saw, I did wrote the file name in English - weird... And then I wrote the file name again - exactly the same - and it worked! Apparently some bug regarding RtL languages...

Hope it'll help someone in the future, or that Pycharm will fix the issue...


推荐阅读