In this video, Jennifer Harrison demonstrates how to use a loop to write multiple records to a file. Learn how to use loops when writing to a file, and how to use the ListBrokenDataSources function to find the broken links in a file.
- [Instructor] Let's talk about using Python…to write records out to an output file.…To write to a file you have to open a file handle.…If the script redirects multiple print statements…to the same output text file, the file handle…only has to be opened once.…The same thing goes for reading multiple records…from a file with a loop.…You only have to open the file handle once…outside the loop.…So you open the file handle with read or write access,…and then you use a loop to either read the records in…or write the records out.…
And when you're finished you close up the file.…So let's see how this looks in a script.…I'll make a quick script that looks at the layers…in a map document and creates a list…of all the broken links.…It will write that list out to a text file.…I've got a script already started here in IDLE.…I've added a comment block and a pseudo code.…And I've also already imported ArcPy.…I've created a variable to point to the map document…that I wanna use, and created a variable…to point to the output text file that I want to create.…
- 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.