Today is my first day at Python and have been going through problems. One that I was working on was, "Write a short program which extracts the current date and time from the operating system and prints it on screen in the following format: day, month, year, current time in GMT.
Demonstrate that it works."
I was going to use pytz, so used easy_install pytz
This installed it in my site-packages (pytz-2012d-py2.7.egg)
Is this the correct directory for me to be able to import the module?
In my python shell i use from pytz import timezone I get,
"ImportError: No module named pytz"
Any ideas? Thanks in advance
time
module can also help here..
UTC is Coordinated Universal Time (formerly known as Greenwich Mean Time, or GMT)
In [18]: import timeIn [19]: time.gmtime()
Out[19]: time.struct_time(tm_year=2012, tm_mon=9, tm_mday=22, tm_hour=3, tm_min=37, tm_sec=15, tm_wday=5, tm_yday=266, tm_isdst=0)In [20]: x = time.gmtime()In [21]: x.tm_year
Out[21]: 2012In [22]: x.tm_mon
Out[22]: 9In [23]: x.tm_mday
Out[23]: 22In [24]: x.tm_hour
Out[24]: 3
Also can you Check the logs while you installed pytz with the below ones...
C:\>easy_install pytz
Searching for pytz
Reading http://pypi.python.org/simple/pytz/
Reading http://pytz.sourceforge.net
Reading http://sourceforge.net/project/showfiles.php?group_id=79122
Reading http://www.stuartbishop.net/Software/pytz
Reading http://sourceforge.net/projects/pytz/
Best match: pytz 2012d
Downloading http://pypi.python.org/packages/2.7/p/pytz/pytz-2012d-py2.7.egg#md5=
e6f9219ae6eff242f13c6700413df69e
Processing pytz-2012d-py2.7.egg
Moving pytz-2012d-py2.7.egg to c:\python27\lib\site-packages
Adding pytz 2012d to easy-install.pth fileInstalled c:\python27\lib\site-packages\pytz-2012d-py2.7.egg
Processing dependencies for pytz
Finished processing dependencies for pytzC:\>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytz
>>> from datetime import datetime, timedelta
>>> utc = pytz.utc
>>> utc.zone
'UTC'