De-Shebanging a Python program file

  • Context: Python 
  • Thread starter Thread starter WWGD
  • Start date Start date
  • Tags Tags
    File Program Python
Click For Summary

Discussion Overview

The discussion revolves around issues related to file associations for Python (.py) files after modifying them to run from the command line. Participants explore methods to access the text format of these files instead of executing them directly in the command line.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant expresses difficulty accessing .py files as text files after they have been shebanged to run in the command line.
  • Another participant suggests dragging and dropping the files onto an editor icon as a potential solution.
  • Some participants propose using the right-click menu to change the file association to a text editor like NotePad or NotePad++.
  • There is a mention of the possibility of renaming .py files to a different extension to prompt for a file association when opening.
  • One participant shares their preference for running Python scripts directly from the command prompt instead of through file associations.
  • A later reply indicates that right-clicking provides an option to edit with IDLE, which is the participant's preferred editor.

Areas of Agreement / Disagreement

Participants generally agree on the methods to change file associations, but there are differing preferences on how to run Python scripts, with some favoring command line execution and others preferring to open files directly in an editor.

Contextual Notes

Some participants reference the need for a pause in the script to prevent it from closing immediately after execution, indicating a potential limitation in the current setup.

Who May Find This Useful

Individuals experiencing similar issues with file associations for Python scripts, as well as those interested in different methods of executing Python code from various environments.

WWGD
Science Advisor
Homework Helper
Messages
7,802
Reaction score
13,105
Hi all,
I had shebanged a Python program file to train myself to run Python from the command line or search box. Problem is now I cannot access my old text-based .py files. Every time I click on them to open, they run in the command line. How can I access the text format again?
 
Technology news on Phys.org
Can you drag drop them on an editor icon?
 
  • Like
Likes   Reactions: WWGD
Or see if selecting it and pressing button two of the mouse might bring up a menu where you can select how to open.

Lastly there's always the good old command line.
 
Last edited:
  • Like
Likes   Reactions: WWGD
Thanks, I wish I had remembered to include a pause. The 1/100 second exposure doesn't quite do it.
 
  • Like
Likes   Reactions: jedishrfu
WWGD said:
Hi all,
I had shebanged a Python program file to train myself to run Python from the command line or search box. Problem is now I cannot access my old text-based .py files. Every time I click on them to open, they run in the command line. How can I access the text format again?
If I understand the problem you're describing, all you need to do is change the file association. Right now, if you click on these files, which are text files, they open by default with some application.

Go to the directory where you keep the .py files, select one of them, and on the right-click menu, choose Open. The dialog that opens should show the icons of several programs, but gives you options to look for other applications, or to browse for an application.

You want to open these files with NotePad or NotePad++ or whatever editor you've been using, and you want to click the box that indicates to always use this application.

Alternatively, you can right-click on one of these files, and Open with... It should list your text editor as one of the options.

BTW, is "shebanging" a thing, let alone "de-shebanging"?
 
Last edited:
  • Like
Likes   Reactions: WWGD
Mark44 said:
If I understand the problem you're describing, all you need to do is change the file association. Right now, if you click on these files, which are text files, they open by default with some application.

Go to the directory where you keep the .py files, select one of them, and on the right-click menu, choose Open. The dialog that opens should show the icons of several programs, but gives you options to look for other applications, or to browse for an application.

You want to open these files with NotePad or NotePad++ or whatever editor you've been using, and you want to click the box that indicates to always use this application.

Alternatively, you can right-click on one of these files, and Open with... It should list your text editor as one of the options.
Now they open-- and automatically run -- in the command line, for a full hundredth of a second or so. Like I said, guess I should have added a pause at the end of the program.
 
WWGD said:
Now they open-- and automatically run -- in the command line, for a full hundredth of a second or so. Like I said, guess I should have added a pause at the end of the program.
My preference is to open a command prompt in the appropriate directory, and then type python xxx.py. Doing this won't do what you're describing.
 
Thanks. I would just like to run them in the shell, in IDLE. I will try the suggestions in your previous reply.
 
It's easy enough to change or remove file type associations, as @Mark44 pointed out, but you could also just rename all your .py files to (e.g.) .py0 (from a command prompt, after navigating to the appropriate directory: ren *.py *.py0), which would result in your being prompted for what you wanted to open them with, and you could then check or uncheck the 'always' box to make or not make a new persistent file type association.
 
Last edited:
  • Like
Likes   Reactions: jedishrfu and WWGD
  • #10
Followup.
Thanks for suggestions, to follow-up , right-clicking gives me the option to edit with IDLE ( my editor). Thanks all.
 
  • Like
Likes   Reactions: sysprog
  • #11
You can also open the editor and then open the file there.
 
  • Like
Likes   Reactions: jtbell, WWGD and jedishrfu

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
2K
Replies
6
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
1
Views
7K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 3 ·
Replies
3
Views
3K