Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does this code work?
#4
Oder auch so?

All in one fell swoop!

@pd_minh12: if you use with open(myfile) as any_name_here: you don't need to worry about closing the file afterwards, it will be closed automatically!

myfile = '/home/pedro/summer2022/breakingnewsEnglish/heat_or_eat_UK.txt'

with open(myfile) as mf:
    newList = mf.read().splitlines()    
    for l in newList:
        print(l)
Reply


Messages In This Thread
How does this code work? - by pd_minh12 - Apr-14-2022, 03:24 PM
RE: How does this code work? - by jefsummers - Apr-14-2022, 04:30 PM
RE: How does this code work? - by Axel_Erfurt - Apr-14-2022, 04:42 PM
RE: How does this code work? - by Pedroski55 - Apr-15-2022, 02:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I can't for the life of me get this basic If statement code to work CandleType1a 8 235 May-21-2024, 03:58 PM
Last Post: CandleType1a
  hi need help to make this code work correctly atulkul1985 5 892 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 750 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Beginner: Code not work when longer list raiviscoding 2 896 May-19-2023, 11:19 AM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,941 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Code used to work 100%, now sometimes works! muzicman0 5 1,548 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  color code doesn't work harryvl 1 959 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  Something the code dont work AlexPython 13 2,435 Oct-17-2022, 08:34 PM
Last Post: AlexPython
  cannot get code to work Led_Zeppelin 10 2,571 Jun-30-2022, 06:28 PM
Last Post: deanhystad
  What should i do, for this code to work -> description hamad 2 1,524 Nov-18-2021, 01:22 PM
Last Post: ghoul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020