I created a text file, and renamed it into testTreeGen.py.
The problem is that PyCharm does not detect it as a python source so that I can't execute it.
How can I teach PyCharm that this is python script?
I tried remove the file and recreated it, and created another python file and renamed it; all ends up being the file as text file not Python script.
The version is 3.0.2.
Settings (Preferences on Mac) | Editor | File Types | Text
Check patterns there (bottom list) -- you must have had
testTreeGen or similar pattern. Just remove it.
This usually happens when creating new file and instead of using specific file template you use
New | File and forgetting to enter file extension (which is required here as opposed to specific file template which adds file extension automatically) -- this is to allow to create ANY file with any extension (e.g.
.htaccess or just
Since such file (
testTreeGen in your case) does not have extension, IDE does not know how to treat it and treats it as plain text (not automatically though -- it asking you to choose correct file type with "text file" type preselected, but vast majority of users just hitting enter instead of reading what that screen says -- "relax, I'm a professional and I know what I'm doing").
Now, since the
testTreeGen pattern is there and it is bigger/more precise that generic
*.py, file is treated as Text file regardless of file extension -- renaming will not help.
Conclusion / advice -- pay a bit more attention to confirmation dialogs.