This example demonstrates some basic text file reading and writing.<br><br><br>diff --git a/data/GSOC examples/file writing and reading b/data/GSOC examples/fi<br>new file mode 100644<br>index 0000000..13b7436<br>--- /dev/null<br>
+++ b/data/GSOC examples/file writing and reading <br>@@ -0,0 +1,41 @@<br>+import time<br>+<br>+print "This example demonstrates how to create a text file, write something to <br>+<br>+print "How shall we call the file?"<br>
+filename = raw_input()<br>+<br>+print "Where would you like to store the file? (can be left empty)"<br>+# Practice: Where does the file get stored if we leave this empty?<br>+directory = raw_input()<br>+<br>+full_name = directory + filename<br>
+<br>+print "Please enter the text you would like to store."<br>+text = raw_input()<br>+<br>+# Open the file in the "w"rite mode.<br>+my_file = open(full_name, "w")<br>+<br>+# Let's write the current time to that file.<br>
+# \n is the way of saying "i'm finished with that line, move to the next one."<br>+current_time = time.ctime()<br>+my_file.write("The following text was written at: " + current_time + "\n")<br>
+<br>+# Write our text to the open file.<br>+my_file.write(text)<br>+my_file.write("\n")<br>+<br>+# Close the file.<br>+my_file.close()<br>+<br>+# Now lets read from that same file. This is how reading is done.<br>
+# First: Open the file in "r"ead mode.<br>+my_file = open(full_name, "r")<br>+# Second: Read from it.<br>+from_file = my_file.read()<br>+# Third: Close the file.<br>+my_file.close()<br>+<br>+# Print what we've read.<br>
+print from_file<br><br>