Python files created do not save as python file - python

https://drive.google.com/file/d/0BwR0ium7uufRWnhXWWNFcVJ3S2c/edit?usp=sharing
The files that are blank and say "Credit Card Balance" and "mine" are the files which I created by opening up a new document in IDLE and creating a file. The ones with the little pictures and say ps2_newton are programs which I downloaded off of the internet. I can't open my files which I created like they are regular programs and have to open them under notepad to see the code. Why is this? How can I change my files to look and act like the ones I downloaded?

The files you downloaded have an extension of ".py", which tells Windows to open them with the Python launcher, while the ones you created have no extension, or an extension of ".txt", which tells Windows to open them in Notepad.
Since ".py" and ".txt" are both "known extensions", and you have Explorer configured to hide known extensions (which I believe is the default in all versions of Windows), it doesn't show them to you. However, you can see the difference in the icons.
You can configure Explorer to show all extensions, but this site is not the place to ask about that—try SuperUser.
Meanwhile, when you save your scripts, make sure you save them with a .py extension (or, if they're Tkinter or other GUI apps, with a .pyw extension).

I had the same problem. But I just deleted all of the é's and á's etc. And it worked! So try that IF it is an .py file. Otherwise I understand if it does not work becouse it isn't a python file. You change that by doing this: Save as. Just simply type .py after the file name.
PS Sorry for my bad english...

Related

File Permission InstallForge

I have written a Python program, this must change the contents of a file for a function.
This also works so far, but I have now converted this with Auto-py-to-exe into a folder, and also the required file is inserted.
When I open this exe file, everything works!
The problem occurs when I use InstallForge to convert the file to an installer file, transfer the file to another PC, restart the PC, open the software, and then try to use the function that describes a file. The software then crashes and the file is not saved.
If I run the software as admin, it doesn't get the error, so that means yes, to be able to rewrite files in the folder, you need admin permission. But it's just inconvenient to always be able to open the app by right clicking and then using "run as administrator".
Is there any way to simplify this? Can i use InstallForge to set special permissions to the files?
I have try, to search about it in the internet, but i havn't found anything about that.

Visual Studio Code - setting it up for multiple languages

I've just downloaded VSC, because I wanted to edit all my code in one editor (I'm writing in C, Python and HTML). On my computer I have a folder (Programming), in which I have 3 sub-folders (C, Python, HTML). So when I started up VSC I opened this Programming folder, and also downloaded the necessary extensions for python and C in VSC.
Here comes my problem: if I run for example a .py which generates a .txt file, it's not generated in the same location as the .py file is, however in the main folder (programming). Also this issue occurs, when I build an .exe from a .c, it also builds in the main folder and not where my .c is.
Thank you for your help!
The default cwd(current working directory) is the folder you open, like you can see:
Even the script_2.py is under VSCODE\Python\Too\b_folder, its cwd is still under the folder VSCODE and not the specific project.
We can change cwd by the method os.chdir() in the file:
OR the second way, add "python.terminal.executeInFileDir": true, in settings.json
These are some workarounds, and it's still recommended that you turn to the specific project and go on development.

How to read a .py file after I install Anaconda?

I have installed Anaconda, but I do not know how to open a .py file..
If it is possible, please explain plainly, I browsed several threads, but I understood none of them..
Thanks a lot for your helps..
Best,
In the menu structure of your operating system, you should see a folder for Anaconda. In that folder is an icon for Spyder. Click that icon.
After a while (Spyder loads slowly) you will see the Spyder integrated environment. You can choose File then Open from the menu, or just click the Open icon that looks like an open folder. In the resulting Open dialog box, navigate to the relevant folder and open the relevant .py file. The Open dialog box will see .py, .pyw, and .ipy files by default, but clicking the relevant list box will enable you to see and load many other kinds of files. Opening that file will load the contents into the editor section of Spyder. You can view or edit the file there, or use other parts of Spyder to run, debug, and do other things with the file.
As of now, there is no in-built way to load a .py file in Spyder directly from the operating system. You can set that up in Windows by double-clicking a .py file, then choosing the spyder.exe file, and telling Windows to always use that application to load the file. The Anaconda developers have said that a soon-to-come version of Anaconda will modify the operating system so that .py and other files will load in Spyder with a double-click. But what I said above works for Windows.
This answer was a bit condensed, since I do not know your level of understanding. Ask if you need more details.
You can use any text editor to open a .py file, e.g. TextMate, TextWrangler, TextEdit, PyCharm, AquaMacs, etc.

How to remove clutter from PyInstaller one-folder build?

Alright, so I managed to use PyInstaller to build a homework assignment I made with Pygame. Cool. The executable works fine and everything.
Problem is, alongside the executable, there is so much clutter. So many files, like pyds and dlls accompany the exe in the same directory, making it look so ugly.
Now, I know that these files are important; the modules I used, such as Pygame, need them to work. Still, how do I make PyInstaller build my game, so that it puts the clutter into its own folder? I could just manually make a folder and move the files in there, but it stops the exe from working.
If this info would help any, I used Python 3.4.3 and am on Windows.
Apparently this is an open request for pyinstaller, but hasn't happened in the past two years.
My workaround for this one was to create a shortcut one folder higher than the .exe folder with all the files.
The difficult part here is to set up the shortcut to work in all PCs. I did two things in the shortcut properties.
Delete the "Starts in:" path
Set as the "Target": "%windir%\system32\cmd.exe" /c start "" "%CD%\YourFolder\YourEXE.exe"
The second one calls a command line and launches your exe with a relative path. I have only tested it with windows 7. The downside is that this becomes a shortcut to the command line and you get a console window.
A different option is to create a batch file in the one folder higher than the .exe and call it. This shows only briefly the console window, but won't allow you to set your own icon. A sample code that launches your code:
#echo off
setlocal enabledelayedexpansion enableextensions
set CDir=%~dp0
set EXEF=%CDir%MyEXEFolder\
cd %EXEF%
start "MyCode" "MyCode.exe"
exit
Just open a notepad, add the code and save it as a .bat file.
This answer also describes a workaround with py2exe, but a similar approach can be used in pyinstaller. However, I find this quite "ugly" and I am not sure if it's that easy to collect all dependencies in one folder.
There is also Relative, but I didn't want to use another program.
Not trying to dig up this old question, but this was at the top of my Google search so it may be for others as well.
If you intend to distribute the program in some kind of folder, you can always just mark everything unnecessary as hidden in Windows, and it will remain hidden even if you compress or extract it.
For a program that I designed to be very user friendly, I just selected each file and folder that was not necessary to the user and hid them. If the user has show hidden files on (rarely default), they aren't likely to be intimidated by the mess of files that pyinstaller creates.

Save Python scripts with .py extension automatically

In Python IDE, while we save the script, it will prompt the save Dialog. If we specify the filename as "Test". Then file will be saved without extension as "Test" and not "Test.py".
Is it possible to save the script with .py extension automatically (as Test.py)?
Unfortunately, IDLE doesn't and can't add the .py extension automatically; you will just have to get into the habit of adding it yourself, or use another IDE like Eclipse or Komodo that will do it for you.
There is a bug report for IDLE about this: http://bugs.python.org/issue10364
If you want, you can edit IDLE itself to do this for you. A good place to start is save_as in IOBinding.py.

Categories

Resources