ECS 32A Lecture 27: Writing Files

47 views2 pages
Verified Note

Document Summary

Recall that the syntax to open a file is the open() function and the . close() method. Writing to a file and then reading from it. With open( output_file. txt , w ) as outfile: outfile. write( hello ) outfile. write( world ) Modern file systems represent information as a sequence of bytes. Different operating systems have completely different directory structures. The previous method can get very long and tedious. Os. path. join() allows you to correctly format a path given just strings sperated by commas (csv) Os. path. isfile)_ checks to see if a path is even a file. Os. path. exists() checks to see if a path even exists. Creating a python command line script that takes file arguments. Recall that after you import sys, you can use sys. argv to get arguments from the command line. Since the open() function just needs a string, you could have the user specify the file when calling your script.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents