import urllib
urllib.urlretrieve("http://www.einstein-online.info/spotlights/binding_energy-data_file/index.txt/at_download/file", "index.txt")

f=open('index.txt'); print f

print f.readline()

print f.readlines()

for row in f.readlines():
    print row

for row in open('index.txt').readlines():
    print row

s="# Mass number, number of protons, name of isotope, mass [MeV/c^2]"
print s.startswith('#')
print not s.startswith('#')

for row in open('index.txt').readlines():
    if not row.startswith('#'):
        print row

"""
Explanation: Opening files
The open() function opens files. 
It can take two arguments:
open(filename, mode='r')
Mode can be:

r Open for reading
w Open for writing
a Open for appending

To which you can add:
- b for binary files.
- + to allow both reading and writing.
- U to convert all newline styles to \n.
You can actually get the data directly from web using urllib package:
End of explanation
"""


for row in open('index.txt').readlines():
    if not row.startswith('#'):
        print row.strip()

"""
Explanation: Remove the newline character at the end of each line by .strip()
End of explanation
"""


s="Remove the newline character at the end of each line by .strip()"
print s.split()

for row in open('index.txt').readlines():
    if not row.startswith('#'):
        print row.strip().split()

"""
Explanation: Split the line into list by .split()!
End of explanation
"""


data=[]
for row in open('index.txt').readlines():
    if not row.startswith('#'):
        data.append(row.strip().split())
print data

"""
Explanation: If you want to store them into a container use a list
End of explanation
"""


f = open('temp', 'w+')
f.write('0123456789abcdef')
f.close()

print open('temp').readlines()

f = open('temp', 'w+')
for i in range(1,100):
    f.write(i*i)
f.close()

f = open('temp', 'w')
for i in range(1,100):
    f.write('%s' % (i*i))
f.close()

print open('temp').readlines()

f = open('temp', 'w')
for i in range(1,100):
    f.write('%s\n' % (i*i))
f.close()

print open('temp').readlines()

"""
Explanation: Write Files
End of explanation
"""


