1. Notes on HW1 - due Sunday night 11:59pm

Do not include cell output in the file you write.

print() vs .write()

Both are ok

In [17]:
f = open('foo.txt','w')
print('blah',123,file=f)
print('blah',123,file=f)
f.close()

g = open('goo.txt','w')
g.write('blah'+str(123))
g.write('blah'+str(123))
g.close()

Just be aware that .write() only accepts a single argument, and does not tack a newline at the end.

cat foo.txt:

blah 123

blah 123

cat goo.txt:

blah123blah123

If you want a newline, you need explicitly add it yourself:

In [11]:
g = open('goo2.txt','w')
g.write('blah'+str(123)+'\n')
g.write('blah'+str(123)+'\n')
g.close()

Using "with"

No need to close the files: "with" takes care of that for you.

In [16]:
with open('foo.txt') as f, open('goo3.txt','w') as g:
    # read and write to these files
    g.write('blah'+str(123)+'\n')
    g.write('blah'+str(123)+'\n')

2. JSON Exercise: Chevy Cobalt Scandal


Click here for the jupyter notebok.

3. XML

Click here for XML notebook.