Python论坛  - 讨论区

标题:[python-chinese] 似乎 Module 的加载有问题

2007年06月12日 星期二 11:16

宇蠢 btyuest在gmail.com
星期二 六月 12 11:16:13 HKT 2007

我写了几行程序来计算今天该复习哪天学习的内容:

import datetime
review = [1,2,7,14,14,14,30,60,180,360]
print " day(s) | date"
for i in review:
	print str(i).rjust(6) + "  |",
	print str(datetime.date.today()+datetime.timedelta(0-i))

用 Python 运行会有问题:

[yuest在canna-zev ~]$ python time.py
 day(s) | date
     1  |  day(s) | date
     1  |
Traceback (most recent call last):
  File "time.py", line 6, in 
    print str(datetime.date.today()+datetime.timedelta(0-i))
  File "time.py", line 6, in 
    print str(datetime.date.today()+datetime.timedelta(0-i))
AttributeError: time

但是 IPython 却正常:
[yuest在canna-zev ~]$ ipython time.py
 day(s) | date
     1  | 2007-06-11
     2  | 2007-06-10
     7  | 2007-06-05
    14  | 2007-05-29
    14  | 2007-05-29
    14  | 2007-05-29
    30  | 2007-05-13
    60  | 2007-04-13
   180  | 2006-12-14
   360  | 2006-06-17
Python 2.5.1 (r251:54863, Apr 19 2007, 11:03:39)
Type "copyright", "credits" or "license" for more information.

IPython 0.8.1 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import sys

In [2]: sys.path
Out[2]:
['',
 '/usr/bin',
 '/usr/lib/python25.zip',
 '/usr/lib/python2.5',
 '/usr/lib/python2.4/site-packages',
 '/usr/lib/python2.5/plat-linux2',
 '/usr/lib/python2.5/lib-tk',
 '/usr/lib/python2.5/lib-dynload',
 '/usr/lib/python2.5/site-packages',
 '/usr/lib/python2.5/site-packages/Numeric',
 '/usr/lib/python2.5/site-packages/gtk-2.0',
 '/usr/lib/python2.5/site-packages/IPython/Extensions',
 '/home/yuest/.ipython']

In [3]:
Do you really want to exit ([y]/n)?
[yuest在canna-zev ~]$ python
Python 2.5.1 (r251:54863, Apr 19 2007, 11:03:39)
[GCC 4.1.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.date(2007, 6, 12)
datetime.date(2007, 6, 12)
>>> datetime.timedelta(10)
datetime.timedelta(10)
>>> today = datetime.date(2007, 6, 12)
>>> today = datetime.date.today()
 day(s) | date
     1  |
Traceback (most recent call last):
  File "", line 1, in 
  File "time.py", line 6, in 
    print str(datetime.date.today()+datetime.timedelta(0-i))
AttributeError: time
>>> import time
 day(s) | date
     1  |
Traceback (most recent call last):
  File "", line 1, in 
  File "time.py", line 6, in 
    print str(datetime.date.today()+datetime.timedelta(0-i))
AttributeError: time
>>>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年06月12日 星期二 11:25

宇蠢 btyuest在gmail.com
星期二 六月 12 11:25:30 HKT 2007

原来是我的文件名的问题,把它改成 viewtime.py,问题就解决了。

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号