Thursday, 26 February 2015

Python Evidence - Session 6 - Write/Read Files

Using Python Basics - Writing to and Reading Files

Lesson Objectives


Use Python to write to a text file
Add data to an existing file
Use Python to read() the contents of a file



Starter
Copy the following Key Words and Definitions in to your book.

Main
Red Task
Create and write to a simple text file using Python.







~~~Evidence~~~
1. Create a program that uses write() mode to create a file that contains some simple text. 
Then use the print() function to print the contents of the file.



Orange Task
Add text to an existing text file using Python.




~~~Evidence~~~ 
2. Write a program to add 3 new lines of text to your file.
 - print it, stick it in your book and write a note to explain what you've done


Green Task
Create a program that will simply read() the contents of your file and display it on the screen.








~~~Evidence~~~ 
3. Write a program that will open() and read() the contents of your file and display it in the screen.
 - print it, stick them in your book and write a note to explain what you've done




Extension Task
Try these EXERCISES



Blog Post (to finish for hwk)
Add the following notes/code snippets to your  blog entitled
 'Writing to and Reading a File in Python'
 


Plenary

Further reading:


Homeowrk
Spend at leasst 30 minutes working on Code Academy - http://www.codecademy.com/learn

5 comments: