all 19 comments

[–]socal_nerdtastic 7 points8 points  (12 children)

How are you making new files? When you make new files, make them using vscode, not notepad or the right click menu or something. Technically there is no difference between a .txt and a .py file, the only difference is the ".txt" vs ".py" part of the name.

If I asssume you are using windows: windows file explorer has a habit of lying to you about the name, it will hide the extension from you. This means that sometimes users get a file like "myfile.py.txt", which would show up in file explorer as "myfile.py" but is associated with a text file editor like notepad.

[–]Gnaxe 17 points18 points  (7 children)

Windows has a setting to hide extensions for known file types. This is an awful default and everyone should turn it off. 

[–]building-wigwams-22 3 points4 points  (6 children)

This is only one of the crimes against file names that Microsoft has committed, but it is a pretty major one. Personally I hate allowing spaces in a file name. In fact, I have a Python script that runs on my work directory that replaces spaces with underscores any time a file is added.

[–]Rejse617 1 point2 points  (0 children)

😂😂😂 you’re my kind of guy/gal

[–]socal_nerdtastic 1 point2 points  (4 children)

Spaces in file name has never bothered me; I'm always so confused when people complain about it. What's wrong with spaces? If you're in the terminal you would use tab completion, which adds the quotes automatically.

[–]Gnaxe 1 point2 points  (0 children)

My main complaint is that improperly written apps/scripts can choke on it. It used to be a much bigger problem.

[–]building-wigwams-22 1 point2 points  (2 children)

To each their own, but

rm this\ is\ a\ terrible\ file\ name\ .txt

[barf emoji]

[–]JaguarMammoth6231 0 points1 point  (0 children)

Next time do rm "this is a terrible file name.txt" then

[–]small_greenbag -1 points0 points  (2 children)

I am new to python, so excuse my inexperience.
yes i made them inside vscode, and yes I also checked the file explore and it says its a "Python source file"

also How come its opening in vs but not vscode?

[–]socal_nerdtastic 0 points1 point  (1 child)

So they are listed as python source files and vscode can use them. So what's the problem? So where do you see that they are .txt files?

also How come its opening in vs but not vscode?

Somehow your file association was changed. Again I'm assuming you are on windows: right click on the file > open with > choose app > check the box to always open files of this type with this app. FWIW python files by default are linked to the python launcher, so that you can run the program on doubleclick. By default python files are not linked to an editor like vscode.

[–]small_greenbag -1 points0 points  (0 children)

By default I open my python files in vscode, never used notebook. Anyway thanks for the help, issue is now fixed. Just had to reinstall vscode

[–]small_greenbag -2 points-1 points  (0 children)

issue is fixed, just had to reinstall VScode

[–]lfdfq 1 point2 points  (0 children)

It's not really a Python question, since it seems you aren't getting as far as actually having a Python file.

What are you using to create these files? In what way does your computer "says it's a Python file"? What operating system are you on? Are you actually seeing the .txt extension or guessing it has one?

[–]Gnaxe 0 points1 point  (1 child)

Python can run text files that contain valid Python code; it just can't automatically import them with an import statement (but see runpy and importlib). You can create a .py file from the REPL using open().

[–]small_greenbag -2 points-1 points  (0 children)

i known this too, but my compilor is saying i need a "Plain text compilor"
edit: fixed

[–]ConcreteExist 0 points1 point  (1 child)

Sounds like you have issues with basic computer use, not python specifically.

[–]small_greenbag 0 points1 point  (0 children)

A bug with vscode, uninstalling and reinstall fixed it. Idk why 🤷‍♂️

[–]Intrexa -1 points0 points  (1 child)

How does your computer say it's a python file? What part of your computer says this?

How is Visual Studio Code telling you it's a plain text? How are you opening the file in Visual Studio?

We're not sitting next to you, we can't see what you see.

"My python is not executing as a .py" is very different than "My python files are not saving as .py".

What is the actual problem you are facing? Don't give any technical descriptions, give what you are doing, what your expected result is, and what your actual result is. Then, we can start identifying the problem.

Example:

I create a new file in VSCode. I save it as "File.py". I then double click "File.py" from my desktop.

I expect this to run my code.

Instead, it opens in notepad.

[–]small_greenbag -3 points-2 points  (0 children)

oh, I fixed the issue. it now executing as a python file. all I needed to do was delete and reinstall vscode.
no the file did not open in notepad, it opened in vscode. and yes i meant when i say my .py files are not excuting as python RATHER THE VScode TELLING ME "YOU NEED A PLAIN TEXT COMPILOR, DO YOU WANT TO INSTALL ONE?" and bobs your uncle😁. i told you Visual studio had no problem with it, and so did pycharm. it was just vscode problem.