In [1]:
ls


404.md          LICENSE         Untitled.ipynb  _config.yml~    _layouts/       _sass/          feed.xml        index.html
CNAME           README.md       _config.yml     _includes/      _posts/         about.md        images/         style.scss*

In [2]:
!ls


404.md         LICENSE        Untitled.ipynb _config.yml~   _layouts       _sass          feed.xml       index.html
CNAME          README.md      _config.yml    _includes      _posts         about.md       images         style.scss

In [3]:
toy_file =open("shiny_new_file.txt", "w")
toy_file.write("hey guys \n")
toy_file.write("what's up \n")
toy_file.close()
!ls


404.md             README.md          _config.yml~       _posts             feed.xml           shiny_new_file.txt
CNAME              Untitled.ipynb     _includes          _sass              images             style.scss
LICENSE            _config.yml        _layouts           about.md           index.html

In [6]:
our_file=open("shiny_new_file.txt", "r")
new_file=open("even_newer_file.txt","w")
new_file.write(our_file.read())
our_file.close()
new_file.close()
!ls


404.md              README.md           _config.yml~        _posts              even_newer_file.txt index.html
CNAME               Untitled.ipynb      _includes           _sass               feed.xml            shiny_new_file.txt
LICENSE             _config.yml         _layouts            about.md            images              style.scss

In [7]:
!cat even_newer_file.txt


hey guys 
what's up 

In [9]:
import urllib2
online_image_file=urllib2.urlopen("http://i.kinja-img.com/gawker-media/image/upload/s--lcZ52NA8--/19c0uzmi9bmv1jpg.jpg")
local_file=open('star_wars_image.jpg',"w")
local_file.write(online_image_file.read())
local_file.close()
online_image_file.close()
!ls


404.md              README.md           _config.yml~        _posts              even_newer_file.txt index.html          style.scss
CNAME               Untitled.ipynb      _includes           _sass               feed.xml            shiny_new_file.txt
LICENSE             _config.yml         _layouts            about.md            images              star_wars_image.jpg

In [10]:
!curl http://i.kinja-img.com/gawker-media/image/upload/s--lcZ52NA8--/19c0uzmi9bmv1jpg.jpg >star_wars_image_curl.jpg


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  557k  100  557k    0     0  3970k      0 --:--:-- --:--:-- --:--:-- 4358k

In [11]:
!ls
!open star_wars_image.jpg


404.md                   Untitled.ipynb           _layouts                 even_newer_file.txt      shiny_new_file.txt
CNAME                    _config.yml              _posts                   feed.xml                 star_wars_image.jpg
LICENSE                  _config.yml~             _sass                    images                   star_wars_image_curl.jpg
README.md                _includes                about.md                 index.html               style.scss

In [21]:
Bo_super_math= 3+7.4
with open("super_math_results.txt","w") as results:
    results.write("3+7 =")
    results.write(str(Bo_super_math))
!cat super_math_results.txt


3+7 =10.4

In [18]:
import csv
with open("new_csv_toy.csv",'w') as csv_output:
    writer =csv.writer(csv_output)
    row1=["Bo","is","awesome"]
    row2=["Aaron","is","awesome"]
    writer.writerow(row1)
    writer.writerow(row2)
    
!cat new_csv_toy.csv




In [22]:
!wget http://web.mta.info/developers/data/nyct/turnstile/turnstile_150404.txt


--2015-04-07 11:22:03--  http://web.mta.info/developers/data/nyct/turnstile/turnstile_150404.txt
Resolving web.mta.info... 63.88.100.208, 63.88.100.184
Connecting to web.mta.info|63.88.100.208|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: 'turnstile_150404.txt'

turnstile_150404.tx     [                 <=>  ]  23.91M  1.69MB/s   in 12s    

2015-04-07 11:22:16 (2.05 MB/s) - 'turnstile_150404.txt' saved [25071566]


In [23]:
!ls


404.md                   Untitled.ipynb           _layouts                 even_newer_file.txt      new_csv_toy.csv          style.scss
CNAME                    _config.yml              _posts                   feed.xml                 shiny_new_file.txt       super_math_results.txt
LICENSE                  _config.yml~             _sass                    images                   star_wars_image.jpg      turnstile_150404.txt
README.md                _includes                about.md                 index.html               star_wars_image_curl.jpg

In [24]:
!head turnstile_150404.txt


C/A,UNIT,SCP,STATION,LINENAME,DIVISION,DATE,TIME,DESC,ENTRIES,EXITS                                                               
A002,R051,02-00-00,LEXINGTON AVE,NQR456,BMT,03/28/2015,00:00:00,REGULAR,0005065968,0001716046                                     
A002,R051,02-00-00,LEXINGTON AVE,NQR456,BMT,03/28/2015,04:00:00,REGULAR,0005066006,0001716049                                     
A002,R051,02-00-00,LEXINGTON AVE,NQR456,BMT,03/28/2015,08:00:00,REGULAR,0005066018,0001716072                                     
A002,R051,02-00-00,LEXINGTON AVE,NQR456,BMT,03/28/2015,12:00:00,REGULAR,0005066153,0001716183                                     
A002,R051,02-00-00,LEXINGTON AVE,NQR456,BMT,03/28/2015,16:00:00,REGULAR,0005066453,0001716263                                     
A002,R051,02-00-00,LEXINGTON AVE,NQR456,BMT,03/28/2015,20:00:00,REGULAR,0005066883,0001716327                                     
A002,R051,02-00-00,LEXINGTON AVE,NQR456,BMT,03/29/2015,00:00:00,REGULAR,0005067073,0001716368                                     
A002,R051,02-00-00,LEXINGTON AVE,NQR456,BMT,03/29/2015,04:00:00,REGULAR,0005067111,0001716377                                     
A002,R051,02-00-00,LEXINGTON AVE,NQR456,BMT,03/29/2015,08:00:00,REGULAR,0005067124,0001716394                                     

In [28]:
LINE_NUM=3
with open("turnstile_150404.txt","r") as turnstile_file:
    reader = csv.reader(turnstile_file)
    reader.next()
    for index, row in enumerate(reader):
        print row
        if index ==LINE_NUM:
            break


['A002', 'R051', '02-00-00', 'LEXINGTON AVE', 'NQR456', 'BMT', '03/28/2015', '00:00:00', 'REGULAR', '0005065968', '0001716046                                     ']
['A002', 'R051', '02-00-00', 'LEXINGTON AVE', 'NQR456', 'BMT', '03/28/2015', '04:00:00', 'REGULAR', '0005066006', '0001716049                                     ']
['A002', 'R051', '02-00-00', 'LEXINGTON AVE', 'NQR456', 'BMT', '03/28/2015', '08:00:00', 'REGULAR', '0005066018', '0001716072                                     ']
['A002', 'R051', '02-00-00', 'LEXINGTON AVE', 'NQR456', 'BMT', '03/28/2015', '12:00:00', 'REGULAR', '0005066153', '0001716183                                     ']

In [36]:
import sys
with open("turnstile_150404.txt","r") as turnstile_file:
    reader = csv.reader(turnstile_file)
    three_rows=open("three_rows.txt","w")
    writer = csv.writer(three_rows)
    
    for num, row in enumerate(reader):
        try:
            if num==3:
                break
                print "I am processing row %i" %num
                #some fancy processing goes here..
                writer.writerow(row)
            if num==2:
                my_value=row/2 #this doesn't work
        except:
                print>>sys.stderr,"oh noews, row %i failed" %num
 three_rows.close()


  File "<ipython-input-36-29140d7b9638>", line 18
    three_rows.close()
                      ^
IndentationError: unindent does not match any outer indentation level

In [ ]: