By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,501 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,501 IT Pros & Developers. It's quick & easy.

problem with datetime

P: n/a
Relatively new to python. I can get the following to work from the
command line:

Python 2.3.4 (#2, Aug 18 2004, 21:49:15)
[GCC 3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import datetime
d = datetime.datetime.today()
d datetime.datetime(2004, 12, 10, 6, 13, 28, 154472)


But when I try to run the following small program I get the following
results:

import datetime
d = datetime.datetime.today()
print d

Traceback (most recent call last):
File "datetime.py", line 1, in ?
import datetime
File "/home/bob/pyshow/datetime.py", line 3, in ?
d = datetime.datetime.today()
AttributeError: 'module' object has no attribute 'today'

Do I need to change a path?
Running python 2.3.4 on linux redhat 7.3.

Bob

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Fri, Dec 10, 2004 at 04:19:56AM -0800, bn******@cs.com wrote:
Relatively new to python. I can get the following to work from the
command line:

Python 2.3.4 (#2, Aug 18 2004, 21:49:15)
[GCC 3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import datetime
d = datetime.datetime.today()
d datetime.datetime(2004, 12, 10, 6, 13, 28, 154472)

But when I try to run the following small program I get the following
results:

import datetime
d = datetime.datetime.today()
print d

Traceback (most recent call last):
File "datetime.py", line 1, in ?
import datetime
File "/home/bob/pyshow/datetime.py", line 3, in ?

^^^^^^^^^^^
d = datetime.datetime.today()
AttributeError: 'module' object has no attribute 'today'

Do I need to change a path?
Running python 2.3.4 on linux redhat 7.3.


Change your script's name from datetime.py to something else. Otherwise the
script will import itself, and not the datetime module from the standard
library.

-- Gerhard
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBuZXddIO4ozGCH14RApIoAJ9viDHd8FYHAYv+cd0rvd eaQjL/RACfVZm6
3t42eLZdhQ3jVlUwPtjjEHM=
=0c2v
-----END PGP SIGNATURE-----

Jul 18 '05 #2

P: n/a
Bob
Thanks. That did it. And I know better than to use the module name.
Bob

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.