Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does this code work?
#2
First, you need to have a reference or your learning will be very slow. Here is the documentation for Python: https://docs.python.org/3/

Now, answering your specific question -
First line opens the file "file.txt" for reading and associates that file with the variable "readfile1"
Next line reads the contents of that file as a list of lines, assigns that list the name f
Next you create a new empty list called newList (btw - that variable name is called CamelCase and is frowned upon in Python. Better to use new_list)
Then you start a loop, through each item in the list f you strip the whitespace off the item and append it to the new list
Finally you print the new list.
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
  Can't get graph code to work properly. KDDDC2DS 1 732 Sep-16-2024, 09:17 PM
Last Post: deanhystad
  I can't for the life of me get this basic If statement code to work CandleType1a 8 2,502 May-21-2024, 03:58 PM
Last Post: CandleType1a
  hi need help to make this code work correctly atulkul1985 5 2,077 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 1,619 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Beginner: Code not work when longer list raiviscoding 2 1,818 May-19-2023, 11:19 AM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 3,769 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Code used to work 100%, now sometimes works! muzicman0 5 2,893 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  color code doesn't work harryvl 1 1,931 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  Something the code dont work AlexPython 13 4,626 Oct-17-2022, 08:34 PM
Last Post: AlexPython
  cannot get code to work Led_Zeppelin 10 4,844 Jun-30-2022, 06:28 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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