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

asked Jul 31, 2013 at 13:51
2
  • 1
    int_unknown_hours = int(unknown_hours)? Commented Jul 31, 2013 at 14:47
  • Thank you! I always tend to think outside the easy answers for some reason, but this helped me! Commented Aug 1, 2013 at 10:58

1 Answer 1

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'
answered Jul 31, 2013 at 15:11
Sign up to request clarification or add additional context in comments.

2 Comments

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! =)
Consider using a list comprehension for the integer conversion instead of map(). Comparison of the two approaches here.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.