Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
5 Cards in this Set
- Front
- Back
opening a file |
Opening the file communicates with your operating system which knows where the data for each file is stored. When you open a file, you are asking the operating system to find the by name and make sure the file exists.
fhand = open('filename.txt') print fhand |
|
newline character |
In Python we use backslash--n in string constants. >>> stuff = 'X\nY' |
|
startswith() |
Checks what a string starts with like this fhand = open('mbox-short.txt')
would print all lines starting with From: |
|
Writing files |
To write a file you have to open it with mode 'w' as a second parameter. >>> fout = open('output.txt', 'w')
The write method of the file handle object puts data into the file. |
|
repr() |
Takes any object as an argument and returns a string representation of the object. For strings, it represents whitespace characters with backslash sequences: >>> s = '1 2\t 3\n 4' >>> print repr(s) |