In this video, Jennifer Harrison describes the methods for reading from and writing to a text file in Python. Learn to read records into a file and split them into their individual fields. Additionally, learn to redirect output to a file.
- [Instructor] Python can read from…and write to ASCII files, scripts can read records…in from a file and print statements can print to a file,…instead of to the IDLE shell window.…The process goes like this,…you open the file, with either read, write or append access.…You read from the file or you write to the file.…You either get the string with a read function…or you write to the file with a print statement.…
And when you're finished you close…up the file with the close function.…So open it, read or write to it, close it up.…When the file is opened, a file handle is created.…A file handle is an open connection to a file.…For the rest of the script when…that file needs to be accessed,…the file handle is used rather than the file name.…So it's very similar to a map document object…or a layer object or a dataframe object.…
To open a file handle you use the open function.…The open function takes two arguments,…the name of the file and an access type,…read, write or append.…Here's an example of using read.…inFile, that's the file handled, equals open,…
- Writing and running Python scripts in IDLE
- Making scripts flexible with variables
- Commenting scripts
- Manipulating string data
- Object-oriented programming in Python
- Creating loops
- Reading and writing text files
- Capturing input at runtime
- Documenting your scripts
Skill Level Beginner
1. Python for ArcGIS Basics
2. Strings, Numbers, and Variables
Work with numeric values5m 22s
3. Syntax Rules
4. Manipulating Strings
5. Object-Oriented Programming
6. Using Loops
7. Generate Log Files
8. Input at Run Time
9. Help Documents
Documenting a script1m 59s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.