Форум сайта python.su
Доброе время суток! У меня возникла проблема при роботе с datetime.
import datetime .............. now = datetime.datetime.now()
'builtin_function_or_method' object has no attribute 'datetime'
Офлайн
Надо так:
from datetime import datetime now = datetime.now
Отредактировано (Июнь 11, 2008 18:51:00)
Офлайн
так вот и дело в том, что в
./manage shell
now = datetime.datetime.now()
Отредактировано (Июнь 11, 2008 19:22:12)
Офлайн
Поищи еще один импорт
import datetime
# а где-то тут, в троеточиях, скрывается
from datetime import datetime
now = datetime.datetime.now()
Офлайн
нет
from mysite import settings from mysite.foo.decorstors import staff_member_required from django.shortcuts import get_object_or_404, render_to_response, Httpresponse from django.views.decorator.cache import never_cache from django import template from django.db import models from mysite.foo.models import * import datetime from Sybase import * import pytils from xlwt import *
import datetime
.................. mysite.foo.models, ................... mysite.foo.decorstors, ..................
Отредактировано (Июнь 12, 2008 09:09:50)
Офлайн
mysite.foo.models
__all__ = ['SampleModel', 'AnotherSampleModel', 'WowModel']
from mysite.foo.models import *
from mysite.foo.models import SampleModel, AnotherSampleModel, WowModel
Python documentation. 6.12 The import statement
The public names defined by a module are determined by checking the module's namespace for a variable named __all__; if defined, it must be a sequence of strings which are names defined or imported by that module. The names given in __all__ are all considered public and are required to exist. If __all__ is not defined, the set of public names includes all names found in the module's namespace which do not begin with an underscore character (“_”). __all__ should contain the entire public API. It is intended to avoid accidentally exporting items that are not part of the API (such as library modules which were imported and used within the module).
Офлайн
Проблема решена!
import datetime
Офлайн
Еще одна причина не использовать ‘from foo import *’
Офлайн