Python
/
Scheduler
- 1 Language 9
-
Hello World S
-
Variables S
-
Functions S
-
Conditional A S
-
Operators S
-
While S
-
Turtle S
-
Script Mode S
-
Debugging S
- 2 Strings 7
-
Slice S
-
Raw Strings S
-
Regex A S
-
Validation S
-
Config S
-
Security S
-
Encrypt A S
- 3 Collections 6
-
Lists S
-
Dictionaries S
-
Efficiency S
-
Tree S
-
Tuples S
-
References S
- 4 Functions 5
-
Recursion S
-
Factorial S
-
Modulus S
-
Reassignment S
-
Approximate S
- 5 Storage 8
-
Files S
-
Databases S
-
Pipes S
-
With open S
-
Shelve A S
-
Zip S
-
Csv S
-
Json S
- 6 Class 4
-
Definition S
-
Attributes S
-
Functional S
-
Methods S
- 7 Goodies 5
-
Conditional Expression S
-
List Comprehension A S
-
Generator S
-
Named Tuple S
-
Modules S
- 8 Applications 5
-
Pythagora A S
-
Palindrome A S
-
Binary Search A S
-
Conway Game A S
-
Coin Flip A S
- 9 Scheduler 4
-
Time S
-
Multithreading A S
-
Subprocess S
-
Logging S
- 10 Packages 6
-
Clipboard A S
-
Ocr A S
-
Socket S
-
Image S
-
Virtualenv S
-
Jupyter S
S
R
Q
Python Scheduler Subprocess
Use Python to start other programs subprocess.Popen('/bin/gnome-calculator') subprocess.Popen('/bin/gnome-calculator') # Opens calculator twice
Popen
p405 You can use Python to start other programs on your computer.
"""Open subprocess:
If you open for example calculator program multiple times,
each window is a different process of the application.
Every process can have multiple threads.
Unlike threads, a process cannot read and write another process's variable.
It's like having a separate copy of the program code.
"""
import subprocess
subprocess.Popen('/usr/bin/gnome-calculator')
subprocess.Popen('/usr/bin/gnome-calculator')
# Opens calculator twice
Arguments
p408 Most applications accept a file to open argument.
"""Open subprocess arguments:
Most GUI applications will accept a single argument for a file to be open.
You pass a list as sole argument to Popen()
"""
import subprocess, pathlib, sys
DIR = pathlib.Path(__file__).resolve().parent
"""The wait() method will block until the launched process has terminated.
This is useful to let the user finish with other programs.
"""
A = subprocess.Popen(['/usr/bin/gedit', DIR/'files/A.txt'])
A.wait()
"""Each operating system has a program that is equivalent to double-click
Windows: start / Linux: see
"""
with open(DIR / 'files/B.txt', 'w') as f:
f.write('Hello World!')
B = subprocess.Popen(['/usr/bin/see', DIR / 'files/B.txt'])
B.wait()
➥ Questions