Reputation: 323
I am writing a program to quickly find the wire size quickly so I don't have to reference a chart all the time but am having a small issue.
I have a dictionary that looks like this:
#From Table 310.16 - Article 310 -
#75 degree rated Copper RHW,THHW,THWN,XHHW,USE,ZW - 2008 NEC
wireAmpacityTable = [
(25, '#12'),
(35, '#10'),
(50, '#8'),
(65, '#6'),
(85, '#4'),
(100, '#3'),
(115, '#2'),
(130, '#1'),
(150, '1/0'),
(175, '2/0'),
(200, '3/0'),
(230, '4/0'),
(255, '250MCM'),
(285, '300MCM'),
(310, '350MCM'),
(335, '400MCM'),
(380, '500MCM'),
(420, '600MCM'),
]
I was successfully able to use the bisect function to get me the right wire size.
My question is how can I access just the wire size value. For example if I input 15 amps I want it to return just the wire size - #12. Currently it returns (25, '#12')
Here is the code I wrote to lookup the values
import bisect
# sort list
wireAmpacityTable.sort()
def wireLookup(amps):
pos1 = bisect.bisect_right(wireAmpacityTable, (amps,))
print "ampacity"
print wireAmpacityTable[pos1]
amp = int(raw_input("How many Amps:"))
print wireLookup(amp)
Upvotes: 0
Views: 521
Reputation: 1111
Just index into the tuple, the gauge of wire is at position 1 so
print wireAmpicity[posl][1]
Will print out just the wire gauge.
Upvotes: 0
Reputation: 13222
At the moment wireLookup
returns nothing. First you have to return something (and not just print it) and second you just need the second entry of the tuple.
return wireAmpacityTable[pos1][1]
By the way, you might want to name your functions and variables according to PEP-8.
Upvotes: 1