Fix Python – Python: Figure out local timezone

I want to compare UTC timestamps from a log file with local timestamps. When creating the local datetime object, I use something like:
>>> local_time=datetime.datetime(2010, 4, 27, 12, 0, 0, 0,
tzinfo=pytz.timezone(‘Israel’))

I want to find an automatic tool that would replace thetzinfo=pytz.timezone(‘Israel’) wi….

Fix Python – Python time measure function

I want to create a python function to test the time spent in each function and print its name with its time, how i can print the function name and if there is another way to do so please tell me
def measureTime(a):
start = time.clock()
a()
elapsed = time.clock()
elapsed = elapsed – start
print “Time spent in (function name) is….

Fix Python – Using %f with strftime() in Python to get microseconds

I’m trying to use strftime() to microsecond precision, which seems possible using %f (as stated here). However when I try the following code:
import time
import strftime from time

print strftime(“%H:%M:%S.%f”)

…I get the hour, the minutes and the seconds, but %f prints as %f, with no sign of the microseconds. I’m running Python 2.6.5 on Ubuntu….

Fix Python – How to measure time taken between lines of code in python?

So in Java, we can do How to measure time taken by a function to execute
But how is it done in python? To measure the time start and end time between lines of codes?
Something that does this:
import some_time_library

starttime = some_time_library.some_module()
code_tobe_measured()
endtime = some_time_library.some_module()

time_taken = endtime -….

Fix Python – Python speed testing – Time Difference – milliseconds

What is the proper way to compare 2 times in Python in order to speed test a section of code? I tried reading the API docs. I’m not sure I understand the timedelta thing.
So far I have this code:
from datetime import datetime

tstart = datetime.now()
print t1

# code to speed test

tend = datetime.now()
print t2
# what am I missing?
# I’d like to ….

Fix Python – python date of the previous month

I am trying to get the date of the previous month with python.
Here is what i’ve tried:
str( time.strftime(‘%Y’) ) + str( int(time.strftime(‘%m’))-1 )

However, this way is bad for 2 reasons: First it returns 20122 for the February of 2012 (instead of 201202) and secondly it will return 0 instead of 12 on January.
I have solved this trouble in bas….

Fix Python – How to get the seconds since epoch from the time + date output of gmtime()?

How do you do reverse gmtime(), where you put the time + date and get the number of seconds?
I have strings like ‘Jul 9, 2009 @ 20:02:58 UTC’, and I want to get back the number of seconds between the epoch and July 9, 2009.
I have tried time.strftime but I don’t know how to use it properly, or if it is the correct command to use.
….