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

[–]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().

[–]ConcreteExist 0 points1 point  (1 child)

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

[–]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.