Reading a file in Python for text -
i given
bus_stops0.txt 01012,victoria st,hotel grand pacific 01013,victoria st,st. joseph's ch 01019,victoria st,bras basah cplx
in notepad , have no idea how open file inside idle.
also, want define
def read_data(filename): stops = [] open(filename, 'r') f: line in f: line = line[:-1] code, road_name, desc = line.split(',') stops.append(filename) return str(stops)
such
read_data('bus_stops0.txt')
['01012,victoria st,hotel grand pacific', "01013,victoria st,st. joseph's ch", '01019,victoria st,bras basah cplx']
is definition correct in first place?
if understand correctly, need output this
['01012,victoria st,hotel grand pacific', "01013,victoria st,st. joseph's ch", '01019,victoria st,bras basah cplx']
if case here code. make sure file has read permission.
def read_data(filename): stops = [] open(filename, 'r') fobj: line in fobj: stops.append(line.strip()) return stops
Comments
Post a Comment