I'm getting this weird error. I am following the documentation closely and don't understand what I am doing wrong. I pasted an minimal example to replicate the error. Any tip to this fix?
Error message:
TypeError: 'Collection' object is not callable. If you meant to call the 'dictinct' method on a 'Collection' object it is failing because no such method exists.
Code:
import pymongo
client = pymongo.MongoClient('mongodb://localhost:27017')
detached = client['realestate'].detached
print(detached.dictinct('key_facts-build_year'))
You have a typo; the method is distinct() (not dictinct())
Related
I'm porting a Python GTK application from python2 to python3, using version 3.5.2. As part of this, I'm switching to updated GTK API calls. I need to call the gtk.TextBuffer constructor, described [here][1]. Following that documentation, I wrote:
tb = gtk.TextBuffer(table=text_tag_table)
This gives the following error:
*** TypeError: gobject `GtkTextBuffer' doesn't support property 'table'
I tried removing the table= part of the call:
gtk.TextBuffer(table=text_tag_table)
This gives:
*** TypeError: GObject.__init__() takes exactly 0 arguments (1 given)
I can call the constructor without arguments, e.g., tb = gtk.TextBuffer(). I tried setting the tag table manually, like this:
tb.set_property("tag-table", text_tag_table)
This gives a warning:
__main__:1: Warning: g_object_set_property: construct property "tag-table" for object 'GtkTextBuffer' can't be set after construction
It seems like the original constructor with the table= arg should work. Can anyone help me figure out why it throws a TypeError? I did confirm using pydb that text_tag_table is an object of the correct type:
(Pdb) p text_tag_table
<Gtk.TextTagTable object at 0x7fb723d6b288 (GtkTextTagTable at 0x2b2e8e0)>
Thanks very much in advance!
The fix for this was to use the new method:
tb = gtk.TextBuffer.new(table=text_tag_table)
I'm a bit surprised that this works, but it seems fine!
I am trying to use to excel function using the code below. I am getting the error df.to_excel('dataset1.xlsx')
Below is the code.
df=qgrid.show_grid(data)
df.to_excel('dataset1.xlsx')
qgrid.show_grid() returns a QgridWidget instance. You can access the underlying dataframe using the df attribute:
grid = qgrid.show_grid(data)
grid.df.to_excel('dataset1.xlsx')
I'm using Python to work with networkx and draw some graphs.
I ran into a problem raising:
TypeError: 'dict' object is not callable
on this line of code:
set_node_color(num, list(Graph.node()))
I searched to find that this error is raised when I'm using a variable name dict.
The problem is, I'm not using any variables with the name dict, nor am I using any dictionary types anywhere in the code.
In case it's necessary, printing the type of Graph gives <class 'networkx.classes.digraph.Digraph'>.
I also tried printing the type for Graph.node() only to receive the same error, telling me 'dict' object is not callable.
So I suspect Graph.node() to be a dict type variable, but using (Graph.node()).items() raises the same TypeError.
Any help or advices would be nice. Thanks.
Maybe Graph.node is a dict object, so Graph.node() is not callable.
I'm trying to retrieve the last 1000 comments from a user since 1000 is the Reddit limit.
I followed the code example here, and modified a few of the calls for the updated API. Such as user.get_comments now seems to be just user.comments.
Here is the code I've run.
import praw
my_user_agent = 'USERAGENT'
my_client_id = 'CLIENTID'
my_client_secret = 'SECRET'
r = praw.Reddit(user_agent=my_user_agent,
client_id=my_client_id,
client_secret=my_client_secret)
user = r.redditor('REDDITUSERNAME')
for comment in user.comments(limit=None):
print comment.body
I get an error every time on the last line, though.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'SubListing' object is not callable
I have connected to the API and have an active connection as I can do print(user.comment_karma) and it displays correctly.
Any ideas what I'm doing wrong?
According to the documentation, comments is an attribute of the Redditor model in PRAW 4, not a function. Therefore, calling .comments(limit=None) is invalid syntax because .comments isn't a function. Instead, you must specify a listing sort order, like so, because SubListing objects (what user.comments is) inherit from BaseListingMixin:
for comment in user.comments.new():
print(comment.body)
Admittedly, the documentation for PRAW 4 is very unclear, and you'll probably find the best documentation by searching through the code directly.
When I execute my Python script using mininet-wifi, I am getting the following error, and I don't know why?
error:'Mininet' object has no attribute 'addBaseStation'
Should I change addBaseStation into addAcessPoint? If so, what is the difference between these?
Try out addAccessPoint() instead.