Write File in Python on Mac - DevPops-Inc/python GitHub Wiki
• Press the “command” key and spacebar to launch Spotlight Search, type “terminal” and select the “Terminal” application.
•
• Type python3
and press the return key to go into the Python interactive shell.
•
• 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.
•
• 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.
•
• Type < write variable >.write(“< text >”)
and press the return key to write text to the file.
•
• Type < write variable >.close()
and press the return key to close the file.
•
• Type print(< read variable >.read())
and press the return key to print the contents of the file in the shell.
•
• Type quit()
or exit()
and press the return key to exit the Python shell and return to the UNIX-like shell.
•