my code:
import time
print hasattr(time.tzset)#error
and why someone do this like next:
if hasattr(time, 'tzset'):
# Move the time zone info into os.environ. See ticket #2315 for why
# we don't do this unconditionally (breaks Windows).
os.environ['TZ'] = self.TIME_ZONE
time.tzset()
i can't understand.
thanks
See the docs for tzset
: they clearly say
Availability: Unix.
so you would have it in, say, MacOSX, Solaris, or Linux, but not on Windows.
Also: there is no such thing as "your time class", despite your Q's title: the time
you're trying to use is a module, not a class.
And finally, as @Daniel says, your first use of hasattr
is totally wrong (the second one, which you don't understand, is correct).
Your use of hasattr
is wrong. The correct syntax is shown in your second snippet.
hasattr
takes two arguments - an object, and a string represent the attribute you want to check for. The way you've done it, Python will try to evaluate time.tzset
first, before passing it to hasattr
- thus causing the very error you're trying to avoid.
Either you have a local module that is shadowing the stock time
module, you're using a version of Python older than 2.3, or you're running Python on Windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With