简体   繁体   中英

Printing all sets in list python

fob=open('c:/Users/username/Desktop/CE151 Python/ass2/grid.txt','r')
text_file = open("grid.txt","r")
for item in fob:
    tuple(item.split(';')[0:])
print(item[0:])

I have loaded a text file and I am trying put each line into a list.When I can for the first line it prints only 1 line. Even when i call for all lines it still outputs 1 line. How do I print a line i request for.

grid.txt contains:

paghzkctudptjdphsztprhttl
sbsnakjwqbouftmgnjqbtlinu
tsewohvobdsduqjiffkyylodo
oukwwefroyamapmlrrpvdolop
cqkfxtlksjvtmtrsbycmqrrri
kfervlqidqaxaoanfqjlmcpjh
yoyywrbpfcjlfbcbbcoecspwl
twbxetyuyufvvmauawjmbwlqh
txokdexmdbtgvhpsvsqtmljdx
dcatenrehteoxqdgeueljtrrn
jarteqvtxejfsqddkbuhcysfq
hpdrowssapxtrxhpdxcdhicon
fob=open('c:/Users/username/Desktop/CE151 Python/ass2/grid.txt','r')
text_file = open("grid.txt","r")
listy=[]
for elem in text_file.read().split('\n'):
   listy.append(elem)
text_file.close()

You could try this. The lines are stored in the list listy .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM