Opening and Writing files (Python)

fw = open("myfile.txt", "w") # For writing only fw.write("I inserted something in this file\n") fw.write("Added a new line woot woot") fw.close() fr = open("myfile.txt", "r") # For reading only text = fr.read() print(text) fr.close()
Using FR (file read) and FW (file write) to do simple output/input operations with files using python.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.