Re: Fractional Hours from datetime?
How about: import time arizona_utc_offset = -7.00 h = (time.time() / 3600 + arizona_utc_offset) % 24 dt.timetuple()[6] is the day of the week; struct tm_time doesn't include a sub-second field. On Jan 10, 10:28 am, "W. eWatson" wrote: > Maybe there's a more elegant way to do this. I want to express the > result of datetime.datetime.now() in fractional hours. > > Here's one way. > > dt=datetime.datetime.now() > xtup = dt.timetuple() > h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6 > # now is in fractions of an hour -- http://mail.python.org/mailman/listinfo/python-list
Re: Fractional Hours from datetime?
Here's an improvement in case you want your code to work outside of Arizona: from time import time, timezone h = ((time() - timezone) / 3600) % 24 On Jan 10, 9:04 pm, Austyn wrote: > How about: > > import time > arizona_utc_offset = -7.00 > h = (time.time() / 3600 + arizona_utc_offset) % 24 > > dt.timetuple()[6] is the day of the week; struct tm_time doesn't > include a sub-second field. > > On Jan 10, 10:28 am, "W. eWatson" wrote: > > > > > Maybe there's a more elegant way to do this. I want to express the > > result of datetime.datetime.now() in fractional hours. > > > Here's one way. > > > dt=datetime.datetime.now() > > xtup = dt.timetuple() > > h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6 > > # now is in fractions of an hour -- http://mail.python.org/mailman/listinfo/python-list
Re: SQL Query via python
How about: cursor.execute(""" SELECT name, month, day ,category, city FROM bday WHERE %(col_name)s = %%s """ % dict(col_name=arg1), (arg2) ) The "%(col_name)s" will be replaced by normal Python string substitution, while the "%%s" will be quoted by the db module. Watch out for SQL injection in arg1, though! Maybe check beforehand that it is a string containing only word characters... Jeff Elkins wrote: > I'm attempting to pass an SQL query via the console: > > $ ./getbd month 05 > > The arguments get seem to passed correctly (via print statements) and then: > > cursor.execute (""" > SELECT name, month, day ,category, city FROM bday > WHERE %s = %s >""",(arg1,arg2)) > > No results. However, if I hardcode the WHERE argument with a field name: > > cursor.execute (""" > SELECT name, month, day ,category, city FROM bday > WHERE month = %s >""",(arg2)) > > It works. > > How can I code the left side of the WHERE clause so I can pass an arbitrary > field name to search on? > > > Thanks, > > Jeff Elkins > > -- http://mail.python.org/mailman/listinfo/python-list