Run .py when .txt is opened? - python

This feels like a simple question, but I don't know if there's a simple answer. I basically just need to make a .py file run when I open up a .txt. I don't really want a loop to check and then run it, preferably i'd like to bundle the txt and the py so all the user sees is a .txt file. Thanks!
EDIT: More Specifically, is there some type of program that can bundle the txt and py so when they double click the txt it runs the py as well as opening the txt file?

This is not as simple as it seems to be. For running a script when a file is being opened you somehow need to recognize the open file event, and I don't know if this would be possible, especially in Windows.
If you want to do something when the file is being modified (saved), you could give the watchdog package a try.
If this does not help, and you know what program is being used for opening the file, you could do it manually: Write a script which first does whatever you need to have done, then opens the text file using subprocess.call.

Related

Made OSX .sh file into .app, refuses to execute

To preface, I've read other threads on the topic, but all their solutions don't work for me.
I have a small .sh file that just runs python3 foo.py. I used a script to turn this file into a .app file, but when I try to open it, I can see the app begin to appear in the dock and then disappear. However, when I open the file inside of the Unix executable itself in Terminal, all is well.
I have tried:
Changing the shebang in the .sh file to both #!/usr/bin and #!/urs/bin/env
Creating an empty .plist file
Making sure every file has execute permissions
Oddly enough, running open appname.app gives the following:
LSOpenURLsWithRole() failed with error -10810 for the file /Users/blah/blah/Lofi.app.
Thanks in advance
When you say you've read other threads on the topic, and the solutions don't work, does that mean you tried every thing in the comments under the sh-to-app script? There are a couple of specific fixes enumerated there.
What OS are using? Looks like higher OS needs you to register the app with the OS.
Check permissions of your personal shell script
Does it open in Terminal with open APP.app? I think you're saying it does. You can look at the last comment under the the sh-to-app script for possibly helpful instructions.
Not so much an answer, more of a workaround. I ended up taking the APP.app/Contents/MacOS/APP executable and creating an application in Automator that simply runs the file, and saving that process as an application in the Applications folder.

How can I edit a .py file in idle and then save my changes to the original file?

Is it possible to edit a script in idle and then save the changes to the original .py file? Firstly you have to run it using the exec command,(Note: I do not use the idle because I am a linux user and I use the terminal instead.)then edit it and after all these actions, what can I do to save the changes to the original .py file???
P.S It is obvious I am a beginner so I would appreciate a simple answer(if possible)Thanks :)

In which directory should I save my .dat file?

I am currently writing a very simple script on python which requires that I download a .dat file posted online. I then use loadtxt to plot the data using matplotlib. However, in order to read the file, I had to change directory (os.chdir) to 'downloads' (where the file had been saved). This works fine for me, but I will need to send the script to somebody else, in which case it seems as though the directory would again need to be something else in order to find the file... Where might I save the file so that no matter to whom I send it, the script will run properly?
User-specific path to the dat file can be acquired using:
os.chdir(raw_input('Which is the path to the download folder?'))

Notepad++ can't open files sepearately for python

I have recently started using notepad++ for my coding in various different programming languages. In Python specifically, I have tried to open a basic text file (.txt), and print the text inside the file. If I run this file via just double clicking it (in Windows Explorer, not in Notepad++), it will run, and do exactly what I want it to do; print the contents of the text file. However, if I try and run it directly from Notepad++ with the line
C:\Python25\python.exe "$(FULL_CURRENT_PATH)"
then it comes up with an error telling me 'it cannot find the file specified'.
I am under the suspicion that it is using its own directory to try and find the files, so if that is the case is it possible to change it to the files directory?
C:\Python25\python.exe probably isnt your path to python ... I think you just copied it from somewhere
you should probably put the path to your python installation instead (I would guess its something like C:\Python27\python.exe

Calling python script from PowerPoint/VBA

I'd like to be able to run Python scripts (that create slides and contents) from PowerPoint, just like an icon in an add-in. I saw that it's possible in Excel using a programm called ExcelPython and the Py scripts are called using VBA.
But for PowerPoint, any way ?
Many thanks
As long as you can execute your script from the command line, it should be possible from PPT as well. Here's an example of starting Notepad with a filename as a command line parameter:
Sub CallExternalProgram()
Shell "Notepad.exe newfile.txt"
End Sub
You'd have to supply the full path to the executable if it's not on the path.

Categories

Resources