This question already has answers here:
How do I execute a program or call a system command?
(65 answers)
Closed 12 months ago.
i am wondering if it is possible to open an app with python. I did some googling but i did not find anything that works. I tried:
import os
os.system("Settings")
and
import subprocess
subprocess.Popen("C:\Program Files (x86)\Steam\steam.exe")
but these do not work and i cant find anything else
Thanks in advance!
Your code didn't work because the format of the path is wrong
import subprocess
subprocess.Popen("C:\\Program Files (x86)\\Steam\\steam.exe")
or
import subprocess
subprocess.Popen(r"C:\Program Files (x86)\Steam\steam.exe")
Related
This question already has answers here:
How can I make one python file run another? [duplicate]
(8 answers)
Closed 4 years ago.
I'm in this 1.py file, and I would like to execute the main.py at some point. I tried using:
import os
os.chdir("/storage/emulated/0/qpython/projects3/seila")
os.system("/storage/emulated/0/qpython/projects3/seila/main.py")
But the result indicated that the access was denied.
How can I solve this?
I Just user the "import" and It worked.
Thank you all for the Help.
This question already has answers here:
Run a .bat file using python code
(9 answers)
Closed 6 years ago.
Is this possible? I yes, can anyone help me how to do it. I don't know how to use subprocess and Popen() to run my sort.bat file.
You can use os.system:
import os
os.system('Path to your .bat file')
This question already has answers here:
Importing files in Python?
(6 answers)
Closed 7 years ago.
I am trying to import a file into Python shell. I have read multiple answers on this site to the same question asked by other users, but none of them have worked.
The command I type is:
import filename.py
I have also tried typing:
from filename import *
In IDLE I clicked File -> Path Browser
to make sure my file was saved in one of those folders.
Am I doing any steps wrong?
Look here: Importing files in Python?
Credit to Pradyun for his excellent answer:
If you are working in the same directory, that is, b.py is in the same folder as a.py, I am unable to reproduce this problem (and do not know why this problem occurs), but it would be helpful if you post what os.getcwd() returns for b.py.
If that's not the case, add this on top of b.py
import sys
sys.path.append('PATH TO a.py')
OR if they are in the same path,
import sys
sys.path.append(os.basename(sys.argv[0])) # It should be there anyway but still..
Please do further research before posting your answer.
This question already has answers here:
How do I watch a file for changes?
(28 answers)
Closed 8 years ago.
I would like to monitor the directory using python. Whenever there is a new file the program will notify the user.
Current I am using a loop, which run os.listdir, to poll the directory regularly. However this is very inefficient. Is there any way that I could setup some software trigger (in Python) to enhance the efficiency?
Thanks in advance
See http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html for Windows and http://sourceforge.net/projects/python-fam/ for Linux. Also, you can check out https://github.com/gorakhargosh/watchdog/, which is multi-platform.
This question already has answers here:
How to know/change current directory in Python shell?
(7 answers)
Closed 9 years ago.
Windows 7
As I'm learning Python (3.2) I prefer using IDLE than CMD.
In order to change the path where I can import scripts of my own, I use a little trick that I found in this site: I go FILE>OPEN>directory>myscript and then run it and from then on I'm on this directory.
Nevertheless, I wonder whether there is a simple command, like CD... to move to the correct directory, without using tricks.
Thank you,
http://www.skylit.com/python/Appendix-A.html
Check section A.2, just before section A.3:
>>> from os import chdir
>>> chdir("C:/myOtherWork")
And also to check the working directory:
>>> from os.path import abspath
>>> abspath('.')
If the current directory is not already in the path you need to add it:
>>> import sys
>>> sys.path.append('.')