Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert list to interger
#4
If the file looks like this:
Whatever
114436
114474
114514

You can skip the first line in the file.
with open("data.csv", "r") as file:
    next(file)
    for line in file:
        print(int(line))
Output:
114436 114474 114514
When using a contact manager (with), the file only remains open for code that is in the context block (indented 1 level deeper than the with). In your latest example the manhole_id file is closed before the for loop executes.
Reply


Messages In This Thread
Convert list to interger - by Clives - May-06-2022, 01:45 PM
RE: Convert list to interger - by deanhystad - May-06-2022, 02:02 PM
RE: Convert list to interger - by Clives - May-06-2022, 02:33 PM
RE: Convert list to interger - by deanhystad - May-06-2022, 03:44 PM
RE: Convert list to interger - by Clives - May-09-2022, 11:22 AM
RE: Convert list to interger - by deanhystad - May-09-2022, 12:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  convert string to float in list jacklee26 6 2,041 Feb-13-2023, 01:14 AM
Last Post: jacklee26
Thumbs Up Convert an Interger into any base !? [Solved] SpongeB0B 8 1,572 Jan-16-2023, 10:24 AM
Last Post: SpongeB0B
  convert a list to links Pir8Radio 3 1,172 Nov-28-2022, 01:52 PM
Last Post: Pir8Radio
  convert this List Comprehensions to loop jacklee26 8 1,639 Oct-21-2022, 04:25 PM
Last Post: deanhystad
  Convert each element of a list to a string for processing tester_V 6 5,520 Jun-16-2021, 02:11 AM
Last Post: tester_V
  convert numbers into list lokesh 1 2,441 Jun-03-2021, 06:37 AM
Last Post: menator01
Question convert unlabeled list of tuples to json (string) masterAndreas 4 7,622 Apr-27-2021, 10:35 AM
Last Post: masterAndreas
Star Convert Bytearray into List using list() Shlok 2 4,357 Feb-18-2021, 10:44 AM
Last Post: deanhystad
  convert List with dictionaries to a single dictionary iamaghost 3 2,947 Jan-22-2021, 03:56 PM
Last Post: iamaghost
Sad Convert python list to dictionary akanowhere 6 3,571 Dec-27-2020, 09:26 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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