ECS 32A Lecture 27: Writing Files
ECS 32A verified notes
27/30View all
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.