Havard
Havard

Reputation: 31

TypeError, When calculating variables from a dictionary

What Type is a val_dict.get(filename)[1]? I keep getting this Typeerror, telling me its a NoneType:

TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'

When I try to run a script with this line :

water = (float(x1[count]) * (val_dict.get(filename[1])) 

I keep getting the errors. I've tried calling a float, int and str, but it obviously didn't help.

I've written a script to import certain values from an Excel-spreadsheet and scale them. After that my script is supposed to extract these values to a new excel spreadsheet, and what I thought was the easiest way was storing all my data in a dictionary that looks like this:

        val_dict[filename] = [model, lenghtvalue, dispvalue, Froudemax, Froudemin]

return val_dict

val_dict = locate_vals()
print val_dict
#output:
{'C:/eclipse/TST-folder\\Test spreadsheet model 151B WL3.xls': [u'M151B', 14.89128, 316.29, 1.0, 0.4041900066850382], 'C:/eclipse/TST-folder\\FolderA\\Test spreadsheet model 151 WL1 Lastet.xls': [u'M151', 14.672460000000001, 316.28887, 1.0, 0.4041900066850382]}

In case it is interesting, the x1-list's output looks like this:

[0.35714285714285715, 0.35714285714285715] [1.5845602477694463e-07, 1.5845602477694463e-07]

Upvotes: 0

Views: 169

Answers (2)

jtuki
jtuki

Reputation: 415

val_dict[filename] is an array which can be indexed, however filename is not.

P.S. I think the following picture might help (from the blog post 29 common beginner Python errors on one page).

29 common beginner Python errors on one page

Upvotes: 1

FMcC
FMcC

Reputation: 349

The issue is this line:

water = (float(x1[count]) * (val_dict.get(filename[1]))

Which should be:

water = (float(x1[count]) * (val_dict.get(filename)[1]))

Upvotes: 0

Related Questions