1

I want to query the following:

The attribute Unknown Hrs is Yes if the employee works on at least one project with NULL hours, and No otherwise.

And I do this by first making a list, theList containing all relevant social security numbers and consequently:

for i in theList:

unknown_hours=process_query("SELECT Distinct COUNT(*) FROM Works_On WHERE ISNULL(Hours) AND ESSN='%s'" %i) 

temp.append(unknown_hours)

the trouble is that I get answers like 1L or 0L and I need them to be integers (for an algorithm). Any thoughts?

Regards Cenderze

Cenderze
  • 1,202
  • 5
  • 33
  • 56

1 Answers1

1

1L is just the long integer representation of the integer value 1:

>> type(1L)
<type 'long'>
>>> long(1)
1L
>>> int(1L)
1

Convert in Python:

int(unknown_hours)

Or in the database layer:

SELECT Distinct CAST(COUNT(*) AS UNSIGNED) FROM Works_On WHERE ISNULL(Hours) AND ESSN='%s'
Bryan
  • 17,112
  • 7
  • 57
  • 80
  • Thank you! This is my first laboration in python so I forgot to mention that I used a list and int() was not possible. However with your answer I knew what to look for and eventually googled up the map function, so thank you! =) – Cenderze Aug 01 '13 at 10:57
  • Consider using a list comprehension for the integer conversion instead of `map()`. Comparison of the two approaches [here](http://stackoverflow.com/questions/1247486/python-list-comprehension-vs-map). – Bryan Aug 01 '13 at 12:38