VS Code turned .ipynb file to binary and cannot open - python

I was working on a project in python in MS VSCODE and saved a file. When returning to it, the file wouldn't open in the editor and claims
"the file is not displayed in the editor because it is either binary or uses an unsupported text encoding"
Any ideas or help on how to resolve this? And also why this happened? I cannot find any helpful threads any where.

Related

File Not Found Using np.loadtxt Even Though Saved In Same Directory Python

I am running Spyder in Linux Ubuntu and am trying to use data saved in a .txt file that is saved in the same directory as the python script I am trying to load it to using numpy's loadtxt function, however every time i try to, an error comes up stating that the file is not found which doesn't make sense as they are both in the same directory.
I am just wondering if anyone knows what this issue could be, other than the file not being in the same directory or the file name being spelt wrong in my code as neither is the case.
Any help would be very much appreciated!

ipynb file does not open anymore

I was working on a ipynb in pycharm. And suddenly I'm not able anymore to open that file. I can see raw code with a text editor like sublime and pasting it in online validator I get this error. How can I find a solution? I'm worried that I've lost everythng.

Can opening a .py file in PyCharm be harmful/malicious?

I've just started learning Python and have downloaded PyCharm and understand this is likely to be a very basic question but wanted to ask before I set off with a false sense of security.
I'm interested to know whether:
a) Simply opening but not running a .py file as a project in PyCharm IDE could be malicious.
b) Opening and running a .py file in the PyCharm IDE can be malicious
If not either, why not? Would the file need to be a .exe to do anything without PyCharm being involved?
Again, appreciate any help/insight you can provide.
So just opening a file in PyCharm will not harm any computer in any way.
But running code can do that, so I would be careful were you get the code which you want to execute. And it would be best if you understood the basic of the code you are running. Therefore you would be able to spot strange lines in your code.
A Python source file (like any other programming language) is just a plain text file, so until the instructions that are written in the file are evaluated (by the python interpreter in this case) the file itself cannot be in any way harmful.
Only once you run python myfile.py in a shell or by using an IDE like PyCharm the code is actually executed... at that point what happens depends on what is written in the file (which you can check before executing it).

IDLE can not open the .py file and it hints that "The file's encoding is invalid for Python 3.x."

I used the command scrapy startproject tutorial in cmd, and it creates some files, but these files can not be opened by IDLE. It hints that:
The file's encoding is invalid for Python 3.x.
IDLE will convert it to UTF-8.
What's the current encoding of the file?
Here's a screenshot:
What's the reason and how to solve it?
If you are sure that you have not manually edited the contents of the ofending files before opening them with IDLE, the reason is probably a bug.
In that case, please open a bug report about it, preferrably detailing all the steps to follow to reproduce the issue, starting with the installation of Scrapy and ending with the issue you show on the screenshot.
In the meantime, you should be able to convert those files automatically from their current encoding to UTF-8 with any good plain text editor (e.g. Notepad++) or a specialized tool.

Python xlwt create faulty excel book

I am trying to use xlwt to create a output file (in .xlsx format) with multiple tabs. The version number of my Python is 2.7, and I am using Aptana Studio 3 as IDE.
I've used the xlwt package before, with the same environment, to carry out the same task. It worked well. But this time, it works well at first, then suddenly, the output file became faulty that cannot be opened by MS Excel.
Here is a clue that might be helpful. My Aptana Studio 3 decide to open .xlsx in its own editor rather than start MS Excel. Although this happens before the problem, I am wondering if it is related.
The file looks normal when it is opened in Aptana3, but when I closed it, and open it with MS Excel, an error pops up:"Excel cannot open the file "output.xlsx" because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."
May I know how I can get over this? Any suggestions are welcome. Thanks.
The xlwt module cannot create .xlsx files. It is a writer for .xls files.
The warning is due to a feature in newer versions of Excel called "extension hardening" which means that the file extension has to match the file type.
If you change the output file extension in your program to .xls the warning should go away and Excel will read the file.

Categories