I am new to Pycharm and Python?

I am new to Pycharm and wondering about filetypes. When creating a new file it asks you to choose a filetype such as text or Python.py etc. I usually choose text, I dont know why, the coding seems to work when I run it.

So, my question is: When should I do my coding within a text file, and when with Python.py file? How do they differ? Are there any other filetypes from the list I should consider?
3 comments
Comment actions Permalink
The file extensions are only to help programs associate files with what they contain. If you run a .txt file in a python interpreter, it will work.


% cat hello.txt
print "hello world"
% python hello.txt
hello world


But in an IDE or text editor, you won't see any of the Filetype associations with the .py file, if you edit python in a .txt file. You will lose syntax hilighting, auto completion, language specific refactoring, etc.


Another VERY important point, is that if you are writing multiple files, python won't see the .txt as a python file, and you won't be able to import from it.

So it's always best to write Python in .py files (or .pyx if doing Cython)
0
Comment actions Permalink
So, the only time I should use a text file would be if I was writing code for notes, for example, learning the code from a book and creating code snippets to aid me in learning (I am doing this at the moment)?
0
Comment actions Permalink
Thats a god use case. Documentation, would be another good thing for a .txt file

For example a README.txt file like you will find in most (if not all) open source projects. (Well, anything on github would probably use .md, but thats a different story)
0

Please sign in to leave a comment.