Working with Files
Importing files _without_ Pandas
A Quick Aside for Modules
Opening Basic Files
# Reading a file; do this unless you're editing it
with open('real_cool_document.txt') as cool_doc:
cool_contents = cool_doc.read()
print(cool_contents)
# Or for just the top line, to preserve performance
with open('just_the_first.txt') as first_line_doc:
first_line = first_line_doc.readline()
print(first_line)
# Writing to a file
with open('bad_bands.txt', 'w') as bad_bands_doc:
bad_bands_doc.write('Nickelback')
# Opening and appending to a file
with open('cool_dogs.txt', 'a') as cool_dogs_file:
cool_dogs_file.write("Air Buddy")CSV Fiddling
Freaking JSON
Last updated