Ask coding questions

← Back to all posts
Bits of help might be needed
LukeShomper (26)

I really don't understand how file reading works like,
r = read? I want to know how to read 1 line of a file I'm assuming it's somthing like FileName[0] but it's not.
I need help reading 1 line of a file
Can someone send me an example please :D

Commentshotnewtop
mwilki7 (741)
# open file
with open('your_file_name') as file:
    for line in file:
        # do stuff here
LukeShomper (26)

@mwilki7 ok well thats step 1 it prints ALL the lines like
D

C

H

I need that to go into a list so the list would contain D, C, H,

LukeShomper (26)

Or well the way i made it print all the lines I need it to go into a list

LukeShomper (26)

Like getting 1 line from a list would also work