Lynne
0
Q:

readlines from file python

f = open("test.txt", "w")
f.writelines(["Hello", "World"])
f.close
3
import wget

url = "https://www.python.org/static/img/[email protected]"

wget.download(url, 'c:/users/LikeGeeks/downloads/pythonLogo.png')
1
f = open("test.txt", "w")
f.write("Hello \nWorld")
f.close
3
f = open("file.txt", 'r')
print(f.readlines())  # array of file lines
5
f = open("filename")
lines = f.readlines()
1
# Python code to 
# demonstrate readlines() 
  
L = ["Geeks\n", "for\n", "Geeks\n"] 
  
# writing to file 
file1 = open('myfile.txt', 'w') 
file1.writelines(L) 
file1.close() 
  
# Using readlines() 
file1 = open('myfile.txt', 'r') 
Lines = file1.readlines() 
  
count = 0
# Strips the newline character 
for line in Lines: 
    print("Line{}: {}".format(count, line.strip())) 
5
import netCDF4
import numpy as np

str_out = netCDF4.stringtochar(np.array(['test'], 'S4'))

nc = netCDF4.Dataset('./test.nc', 'w', format='NETCDF4_CLASSIC')
nc.createDimension('lat', 1)
nc.createDimension('lon', 1)
nc.createDimension('nchar', 4)

lat = nc.createVariable('lat', 'f4', ('lat',))
lon = nc.createVariable('lon', 'f4', ('lon',))
place = nc.createVariable('place', 'S1', ('nchar'))

lat[:] = 17.002
lon[:] = -81.501
place[:] = str_out

nc.close()
0
import urllib.request

print('Beginning file download with urllib2...')

url = 'http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg'
urllib.request.urlretrieve(url, '/Users/scott/Downloads/cat.jpg')
0

New to Communities?

Join the community