attributeerror

python “import datetime” v.s. “from datetime import datetime”

会有一股神秘感。 提交于 2019-11-26 22:20:08
问题 I have a script that needs to execute the following at different lines in the script: today_date = datetime.date.today() date_time = datetime.strp(date_time_string, '%Y-%m-%d %H:%M') In my import statements I have the following: from datetime import datetime import datetime I get the following error: AttributeError: 'module' object has no attribute 'strp' If I change the order of the import statements to: import datetime from datetime import datetime I get the following error: AttributeError:

AttributeError: 'module' object has no attribute 'cbook'

房东的猫 提交于 2019-11-26 21:42:19
问题 I am trying to run a simple code and I have all the dependencies for matplotlib and numpy installed in my Canopy. Still I am getting error. import cv2 import numpy as np import matplotlib.pyplot as plt x = cv2.imread('jay.jpg') plt.imshow(x, cmap = 'gray', interpolation = 'bicubic') plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis plt.show() Error: %run "c:\users\jay\appdata\local\temp\tmppvibq9.py" --------------------------------------------------------------------------

Python attributeError on __del__

一曲冷凌霜 提交于 2019-11-26 17:48:27
问题 I have a python class object and I want to assign the value of one class variable class Groupclass(Workerclass): """worker class""" count = 0 def __init__(self): """initialize time""" Groupclass.count += 1 self.membercount = 0; self.members = [] def __del__(self): """delte a worker data""" Groupclass.count -= 1 if __name__ == "__main__": group1 = Groupclass() This execution result is correct, but there's an error message that says: Exception AttributeError: "'NoneType' object has no attribute

Why does this AttributeError in python occur?

时光毁灭记忆、已成空白 提交于 2019-11-26 13:51:18
问题 There is one thing, that I do not understand. Why does this import scipy # happens with several other modules, too. I took scipy as an example now... matrix = scipy.sparse.coo_matrix(some_params) produce this error: AttributeError: 'module' object has no attribute 'sparse' 回答1: This happens because the scipy module doesn't have any attribute named sparse . That attribute only gets defined when you import scipy.sparse . Submodules don't automatically get imported when you just import scipy ;

AttributeError: 'module' object has no attribute

自作多情 提交于 2019-11-26 03:39:41
I have two python modules: a.py import b def hello(): print "hello" print "a.py" print hello() print b.hi() b.py import a def hi(): print "hi" When I run a.py , I get: AttributeError: 'module' object has no attribute 'hi' What does the error mean? How do I fix it? You have mutual top-level imports, which is almost always a bad idea. If you really must have mutual imports in Python, the way to do it is to import them within a function: # In b.py: def cause_a_to_do_something(): import a a.do_something() Now a.py can safely do import b without causing problems. (At first glance it might appear

AttributeError: 'module' object has no attribute

你说的曾经没有我的故事 提交于 2019-11-26 01:06:35
问题 I have two python modules: a.py import b def hello(): print \"hello\" print \"a.py\" print hello() print b.hi() b.py import a def hi(): print \"hi\" When I run a.py , I get: AttributeError: \'module\' object has no attribute \'hi\' What does the error mean? How do I fix it? 回答1: You have mutual top-level imports, which is almost always a bad idea. If you really must have mutual imports in Python, the way to do it is to import them within a function: # In b.py: def cause_a_to_do_something():

__getattr__ on a module

て烟熏妆下的殇ゞ 提交于 2019-11-26 00:41:54
问题 How can implement the equivalent of a __getattr__ on a class, on a module? Example When calling a function that does not exist in a module\'s statically defined attributes, I wish to create an instance of a class in that module, and invoke the method on it with the same name as failed in the attribute lookup on the module. class A(object): def salutation(self, accusative): print \"hello\", accusative # note this function is intentionally on the module, and not the class above def __getattr__

Why do I get AttributeError: 'NoneType' object has no attribute 'something'?

僤鯓⒐⒋嵵緔 提交于 2019-11-25 21:57:55
问题 I keep getting an error that says AttributeError: \'NoneType\' object has no attribute \'something\' The code I have is too long to post here. What general scenarios would cause this AttributeError , what is NoneType supposed to mean and how can I narrow down what\'s going on? 回答1: NoneType means that instead of an instance of whatever Class or Object you think you're working with, you've actually got None . That usually means that an assignment or function call up above failed or returned an

__getattr__ on a module

我是研究僧i 提交于 2019-11-25 16:51:34
How can implement the equivalent of a __getattr__ on a class, on a module? Example When calling a function that does not exist in a module's statically defined attributes, I wish to create an instance of a class in that module, and invoke the method on it with the same name as failed in the attribute lookup on the module. class A(object): def salutation(self, accusative): print "hello", accusative # note this function is intentionally on the module, and not the class above def __getattr__(mod, name): return getattr(A(), name) if __name__ == "__main__": # i hope here to have my __getattr__