I'm new to programming and I can't able to run this code it often shows an error like module object is not callable. Can anyone sort this out for me?
import simplekml
kml = simplekml.kml() #what's wrong here?
kml.newpoit(name="sample",coords[(11,12)])
kml.save("H:\\python\\point.kml")`
Traceback (most recent call last):
File "H:/programs/practice.py", line 2, in <module>
kml = simplekml.kml()
TypeError: 'module' object is not callable
I guess you meant to call simplekml.Kml() (with capital K) to create an instance of this class. So probably it was just misspelling.
simplekml is a module, which you import in the very first line of your code.
I advise you to have a look at simplekml.Kml class documentation.
simplekml.kml is a module inside simplekml, and thus isn't callable, as the error message says. You probably meant to call simplekml.Kml() (with a capital K), to create a Kml instance.
Related
I want to add functions to python's built in module. As a example, there is no find function in list. I want to add it. There is some other functions I want to add. Can somebody please tell me how can I do that? Is their any way I can do that?
Adding functions to the builtins module is simple:
import builtins
builtins.find = my_find_function
But the built in classes are usually immutable, so they cannot be changed.
>>> list.hello = "hello"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't set attributes of built-in/extension type 'list'
I know we can import modules and just embed Python code in C++ and evaluate it. But how can I use built-in functions like print or open? These functions off course aren't module. Evaluating embedded open statement just gives me the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'open' is not defined
Stuck. Please help me.
Try importing the builtins and io module and if you want any other function just call the __module__ attribute to find about which module to import
>>> print.__module__
'builtins'
>>> open.__module__
'io'
This is pretty simple:
import threading as t
t.local().x = 1
print t.local().x
When I run it, I get this:
Traceback (most recent call last):
File "C:\Documents and Settings\e272nk\Desktop\tst.py", line 3, in <module>
print t.local().x
AttributeError: 'thread._local' object has no attribute 'x'
The attribute assignment seems to be working ok, why can't I retrieve the value?
This is Python v2.7.5 on Windows XP.
You're creating an instance of the class local, setting an attribute on it, then discarding it. Then in the next line, you are creating another instance of local and trying to print a certain attribute from it. Since you didn't set the attribute on that instance, it doesn't have it, and you get an error.
As shown in the documentation, you should be creating an instance of local and keeping it around:
import threading as t
locs = t.local()
locs.x = 1
print locs.x
This seems like a simple issue but I'm having a very difficult time understanding why I am getting the following error:
Traceback (most recent call last):
File "....py", line 46, in update
self.Grob3Text.SetLabel('Grob 3: ' + str(Grob3))
AttributeError: 'Frame' object has no attribute 'Grob3Text'
When running the following script:
Please see -
.
I understand the message is telling me that the static text variable 'Grob3Text' is not defined in the Frame, but it appears to me that the definition for update event is under the same class. All I'm trying to do is execute the faultreport function and update the static text. I have got this working in another script but for whatever reason I am overlooking something here.
You create a local variable Grob3Text in __init__, but you don't actually store it as an instance attribute on the class instance. To do that, you could simply do:
self.Grob3Text = Grob3Text
in __init__ after you create Grob3Text.
I've got file named recommend.py. It has a dict data named critics.
When I try to reload it in the interpreter it gives the following error:
>>> from recommend import critics
>>> reload(recommend.py)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'recommend' is not defined
>>>
I'm new to python. Please help me.
recommend.py is parsed as recommend . py which means that python looks for an object bound to the name recommend and then tries to get the py attribute from it. That doesn't work because you don't have an object named recommend in the current namespace and because even if you did have an object bound to that name, it probably wouldn't have an attribute py.
Of course, you'll need to give reload an actual module object. Something more like:
import recommend
reload(recommend)
reload() takes a module object, not a filename:
import recommend
reload(recommend)