Write File in Python on Mac - VicPhanDevOps/mac GitHub Wiki

• Press the “command” key and spacebar to launch Spotlight Search, type “terminal” and select the “Terminal” application.
image

• Type python3 and press the return key to go into the Python interactive shell.
image

• Type < write variable >=open(“< filepath/filename”, “w”) and press the return key to declare a write variable and set it to the file you wish to write.
image

• Type < read variable >=open(“< filepath/filename >”) and press the return key to declare a read variable and set it to the file you wish to read.
image

• Type < write variable >.write(“< text >”) and press the return key to write text to the file.
image

• Type < write variable >.close() and press the return key to close the file.
image

• Type print(< read variable >.read()) and press the return key to print the contents of the file in the shell.
image

• Type quit() or exit() and press the return key to exit the Python shell and return to the UNIX-like shell.
image

⚠️ **GitHub.com Fallback** ⚠️