Python Forum
ValueErrors: need more than 3 values to unpack
Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueErrors: need more than 3 values to unpack
#1
the goal of this code is to match year_link and tla_2 and output variables from_, to, digit, name2, min_value, max_value. I am using a CSV file, that's where the data is being read from. It is posted here:    
Unfortunately I receive this error:
Error:
Traceback (most recent call last): File "C:/Users/RM/Desktop/win6.py", line 150, in <module> for from_,to,digit,name2,min_value,max_value in voltage_envelopes[tla_2]: ValueError: need more than 3 values to unpack.
data = list(csv.reader(open(LOAD_GEN_DATAFILE)))
    year = raw_input(" ")
    location=raw_input(" ")
    for row in data:
        year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16]
        year_link = year
        tla_2=location
        if year_link not in mydict:
            mydict[year_link]={}
    
        voltage_envelopes=mydict[year_link]
        
        if tla_2 not in voltage_envelopes:
            voltage_envelopes[tla_2]=[]
            
        voltage_envelopes[tla_2].append((from_,to,digit,name2,min_value,max_value))
    
    if year_link in mydict and tla_2 in mydict[year_link]:
         voltage_envelopes=mydict[year_link]
         
         for from_,to,digit,name2,min_value,max_value in voltage_envelopes[tla_2]:
             from_=int(from_)
             to=int(to)
             min_value=float(min_value)
             max_value=float(max_value)
             digit=int(digit)
            
             output = 'From Bus #: {}\tTo Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' 
             print(output.format(from_, to,name2, min_value, max_value))
             print("\n")
            
            #_c=psspy.getdefaultchar()
            #_i=psspy.getdefaultint()
            #_f=psspy.getdefaultreal()
            #psspy.two_winding_chng_4(from_,to,'%d'% digit,[_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f, max_value, min_value,_f,_f,_f],[])
    else:
        exit
Reply
#2
looks like voltage_envelopes[tla_2] has only 3 values, while you are expecting it to have 6?
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Too much values to unpack actualpy 3 472 Feb-11-2024, 05:38 PM
Last Post: deanhystad
  unpack dict menator01 1 1,193 Apr-09-2022, 03:10 PM
Last Post: menator01
  ValueError: not enough values to unpack (expected 4, got 1) vlearner 2 6,329 Jan-28-2022, 06:36 PM
Last Post: deanhystad
  [SOLVED] [geopy] "ValueError: too many values to unpack (expected 2)" Winfried 2 2,874 Mar-30-2021, 07:01 PM
Last Post: Winfried
  Cannot unpack non-iterable NoneType object, i would like to ask for help on this. Jadiac 3 8,913 Oct-18-2020, 02:11 PM
Last Post: Jadiac
  subprogram issues: cannot unpack non-iterable function object error djwilson0495 13 5,997 Aug-20-2020, 05:53 PM
Last Post: deanhystad
  struct.unpack failed Roro 2 3,354 Jun-13-2020, 05:28 PM
Last Post: DreamingInsanity
  Can't unpack values of dictionary with ** Snake 3 3,565 Mar-11-2020, 11:17 AM
Last Post: Snake
  Error: too many values to unpack Mike 1 5,136 Oct-30-2019, 03:07 PM
Last Post: buran
  How to unpack tuples in if statements saurkkum 1 5,168 May-05-2019, 09:43 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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