From the course: Learning ArcGIS Python Scripting (2018)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Read and write to a text file

Read and write to a text file - ArcGIS Tutorial

From the course: Learning ArcGIS Python Scripting (2018)

Start my 1-month free trial

Read and write to a text 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…

Contents