I am currently working on a file that needs to readout excel rows. I have made to seperate files. one where i define functions and the main script. In the functions i am trying to create a dictionary, which works, but python cant unpack it into the main file. My functions are:
def ColVal( RowName , x , sheet):
ColA = str( RowName ) + str( x )
ColAVal = ( sheet[ColA].value )
return ( ColA , ColAVal )
def MakeDictionary(sheet):
X = {}
RowName = 'A'
print( sheet.max_row )
for x in range( 1 , sheet.max_row ):
[ColA , ColAVal] = ColVal( RowName , x , sheet)
X[ColA] = str( ColAVal )
return X
sheet.max_row = 301. When i try to use the function in the main script like this:
[X] = MakeDictionary2(sheet)
print(X)
It gives the error: ValueError: too many values to unpack (expected 1)
How can i solve this?
Best regard
MakeDictionary2. Is that a typo? - Akash ShendeMakeDictionary2? In any case, this happens when the function has more than one value that you're unpacking; ifMakeDictionary2returnsnvalues or returns one value of lengthn, then the Left Hand Side of the expression[...] = MakeDictionary2(sheet)needs to havenfree variables in the list (or tuple) constructor[...]or(...,)for the error to not occur. - dROOOze