1dir = 'C:\\myprogram.exe'
2
3import os
4os.startfile(dir)
5os.system(dir)
6
7import subprocess
8subprocess.Popen([dir])
9subprocess.call(dir)
1# Reference https://docs.python.org/3/library/functions.html#open
2
3# Method 1
4file = open("welcome.txt", "r") # mode can be r(read) w(write) and others
5data = file.read()
6file.close()
7
8# Method 2 - automatic close
9with open("welcome.txt") as infile:
10 data = file.read()
11
1#there are many modes you can open files in. r means read.
2file = open('C:\Users\yourname\files\file.txt','r')
3text = file.read()
4
5#you can write a string to it, too!
6file = open('C:\Users\yourname\files\file.txt','w')
7file.write('This is a typical string')
8
9#don't forget to close it afterwards!
10file.close()
1with open('output.txt', 'w') as file: # Use file to refer to the file object
2
3 file.write('Hi there!')
4
1#pystyle
2with open("test.txt", encoding = 'utf-8') as f:
3 file = f.read()
4#classic
5file = open("file.txt")
6file.close()
7