>From the small snippets you have supplied what you are showing isn't 
possible.

e..g 

>>> import datetime
>>> class MyHandler(object):
... def get(self):
... print datetime
... 
>>> datetime
<module 'datetime' (built-in)>
>>> x = MyHandler()
>>> x.get()
<module 'datetime' (built-in)>

So other things are at work here.  You need to show a full set of working 
code that exhibits this problem.
You may have monkey patching going on. 

T



On Wednesday, February 12, 2014 3:44:21 PM UTC+8, John Del Rosario wrote:
>
> I'm getting `type object 'datetime.datetime' has no attribute 'datetime'` 
> errors on AppEngine, complaining about the datetime type, but my import is 
> `import datetime`. There *are* `from datetime import datetime` in *other* 
> files, but I don't think that should affect this file? 
>
> There's no 'accidental' re-imports, I've checked. I've checked my 
> AppEngine logs, and it only started happening 2 days ago. 
>
> I'm using 2.7 runtime. 
>
> Here's the line that's causing the error (note that I'm using `import 
> datetime`, NOT `from datetime import datetime`)
>
>     task.due_at = datetime.datetime.strptime(date, '%Y-%m-%d %I:%M%p')
>
> Stack trace
>
>     type object 'datetime.datetime' has no attribute 'datetime'
>     Traceback (most recent call last):
>       File 
> "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py",
>  
> line 570, in dispatch
>         return method(*args, **kwargs)
>       File 
> "/base/data/home/apps/s~wmphighrise/1.373696587983821954/myapp/handler/decorators.py",
>  
> line 22, in wrapper
>         return fn(*args, **kwargs)
>       File 
> "/base/data/home/apps/s~wmphighrise/1.373696587983821954/myapp/handler/api/main.py",
>  
> line 1343, in post
>         task.due_at = datetime.datetime.strptime(date, '%Y-%m-%d %I:%M%p')
>     AttributeError: type object 'datetime.datetime' has no attribute 
> 'datetime'
>
> Some debugging
>
> *Note*: `import datetime` is at the top
>
>     #1st attempt
>     import datetime
>     class MyHandler():
>       def get(self):
>         logging.info(datetime) # => "<type 'datetime.datetime'>"
>     
>     #2nd attempt
>     import datetime
>     class MyHandler():
>       def get(self):
>         import datetime  # explicitly re-import the module
>         logging.info(datetime) # => "<module 'datetime' (built-in)>"
>     
>     #3rd attempt
>     import datetime
>     class MyHandler():
>       def get(self):
>         logging.info(datetime) # => Throws UnboundLocalError: local 
> variable 'datetime' referenced before assignment
>                                # Is this normal? This is new to me.
>         import datetime
>         logging.info(datetime)
>
>     #4th attempt
>     import datetime
>     logging.info(datetime) # => "<module 'datetime' (built-in)>"
>     class MyHandler():
>       def get(self):
>         logging.info(datetime) # => "<type 'datetime.datetime'>"
>                               
> Is there a way for a variable to be redefined *outside* the current file 
> or module? Because I've looked and looked at this file and there's no 
> redefining at all.
>
> See Stackoverflow 
> discussion<http://stackoverflow.com/questions/21720678/type-object-datetime-datetime-has-no-attribute-datetime-even-with-import/21720833?noredirect=1#comment32847011_21720833>for
>  more info.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to