Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tuple no attribute error
#3
enumerate() returns a tuple containing two items. First is an index (starting with 0) and second is an item from the iterable you enumerated.

for line in enumerate(yrs_file):
Here line is a tuple (index, item), so you can't use split on it, which is a method of string type.
You could instead unpack the tuple into two variables like this:
for index, line in enumerate(yrs_file):
Then line will be a string which you can split.
You could also access only the second element of the tuple - the string you want to split:
for line in enumerate(yrs_file):
    (pdate,catg,amt,howp) = line[1].split(',')
But in any case, I don't really see why you would need enumerate() in your code at all.
Reply


Messages In This Thread
Tuple no attribute error - by oldcity - Oct-06-2018, 02:51 PM
RE: Tuple no attribute error - by ichabod801 - Oct-06-2018, 03:00 PM
RE: Tuple no attribute error - by j.crater - Oct-06-2018, 03:11 PM
RE: Tuple no attribute error - by snippsat - Oct-06-2018, 05:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error: audioio has no attribute 'AudioOut' netwrok 3 752 Oct-22-2023, 05:53 PM
Last Post: netwrok
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,668 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Getting 'NoneType' object has no attribute 'find' error when WebScraping with BS Franky77 2 5,433 Aug-17-2021, 05:24 PM
Last Post: Franky77
  Attribute Error received not understood (Please Help) crocolicious 5 2,781 Jun-19-2021, 08:45 PM
Last Post: crocolicious
  AttributeError: 'tuple' object has no attribute 'format' Anldra12 7 17,574 Apr-13-2021, 07:45 AM
Last Post: Anldra12
  error in scapy attribute 'haslayer' evilcode1 5 6,719 Mar-02-2021, 11:19 AM
Last Post: evilcode1
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 2,966 Nov-04-2020, 11:26 AM
Last Post: Aggam
  attribute error instead of correct output MaartenRo 2 2,276 Aug-28-2020, 10:22 AM
Last Post: Larz60+
  attribute error stumped on how to fix it. hank4eva 7 5,030 Aug-11-2020, 04:47 AM
Last Post: hank4eva
  Python Error- TypeError: ('Params must be in a list, tuple, or Row', 'HY000') DarkCoder2020 3 5,725 Jul-29-2020, 12:02 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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