Want to update document in reThinkDB using setInsert Python - python

r.db('usersData').table('smsRaw').get("3413b71c-1628-47eb-83fa-6a3cccdb3e62").update({"MESSAGE": r.row('MESSAGE').setInsert({"DATE":"20160111","MESSAGE":[{"ADDR":"LONDON","date":"1468385398746"}]})})
This is what i am able to run on console.I want to convert it to python code.
Below is python code i tried r.db(dbName).table(tableName).get(id).update({'MESSAGE':r.row.get_field('MESSAGE').setInsert(Doc)}).run(con)
its throwing exception. AttributeError 'GetField' object has no attribute 'setInsert

You probably want setInsert to be set_insert.

Related

Imported six module but Python 2 print function is giving error

I am using python 3.10.I have had to use code that was originally written with python 2.7. In order to make it compatible with python 3.10 I am importing six. However the print function from 2.7 still gives me an error saying End of statement expected. My code is as follows:
import six
print 'Result OK!'
Why is six not able to import the print function from python 2.7?
NB:I am using python files written with 2.7, I don't want to update them to 3.10 syntax. I just want to use functions from them without having to update them because they are files I share with other people who at the moment don't want to migrate to python 3, so I am trying to find a walk around to the situation.
If you want to print in python 3 you need to use parenthesis around the print statement like :
print('Result OK!')
Also to print you don't need to import anything :)

'gi.repository.GObject' object has no attribute 'threads_init' while excuting bundle build by cx_freeze

I built my application with cx_freeze in python3. When I execute the application, it report that:
AttributeError: 'gi.repository.GObject' object has no attribute 'threads_init'
As check the code of GObject.py and GLib.py, it is said that threads_init is now obseleted, I try to remove threads_init from GObject.py, but get the same result, problem remain unsolved.
Could anyone give me a hand? Thank you in advanced.

Not able find Twython.getFollowersIDs functions

I am using Twython on Ubuntu 12.04 an when I write this line
twitter.getFollowersIDs(screen_name='someName')
I am getting this error
AttributeError: 'Twython' object has no attribute 'getFollowersIDs'
what should I do?
I think the correct method name is:
twitter.get_followers_ids(screen_name='someName')
If this is not the case please provide the output of dir(twitter).

find all items in list object

I would like to interrogate all new emails (one by one) and find the contents of them so that I can use the contents for another application.
My first step was interpreting the return values from a search done via the search attr of an IMAP4 object. I'm trying to figure out what data is in a list that I have returned to me.
How can I examine the object tree via print? Or, better yet, how can I get the contents of the email in a string?
For ex., I am returned the following via print:
unseen email content: ['3 4'] from a variable named "response".
If I run print response.__class__.__name__, I get "list" returned.
I know that there is other data in "3", and "4", I just don't know what.
update: Specifically, this is the return of a call to an IMAP4obj.search(None, '(UNSEEN)')
from the python docs (here) this example:
# M is a connected IMAP4 instance...
typ, msgnums = M.search(None, 'FROM', '"LDJ"')
it seems a tuple is returned, you can try,
print(type(typ))
print(dir(typ))
print(type(msgnums))
print(dir(msgnums))
try reading the docs, see if it can help clarify your doubts or even make your question clearer.
You may try importing pdb and doing a pdb.pprint.pprint(response)
If it's a program running on your own machine, you can also do a pdb.set_trace() and play with response.
The ipdb module has nicer versions, but it's not usually installed by default.
Sounds like a debugger might help. If you are using an IDE with a debugger set a break point and introspect the objects.
If you do not use an IDE yet, try Eclipse in combination with PyDev

Getting Started with Python: Attribute Error

I am new to python and just downloaded it today. I am using it to work on a web spider, so to test it out and make sure everything was working, I downloaded a sample code. Unfortunately, it does not work and gives me the error:
"AttributeError: 'MyShell' object has no attribute 'loaded' "
I am not sure if the code its self has an error or I failed to do something correctly when installing python. Is there anything you have to do when installing python like adding environmental variables, etc.? And what does that error generally mean?
Here is the sample code I used with imported spider class:
import chilkat
spider = chilkat.CkSpider()
spider.Initialize("www.chilkatsoft.com")
spider.AddUnspidered("http://www.chilkatsoft.com/")
for i in range(0,10):
success = spider.CrawlNext()
if (success == True):
print spider.lastUrl()
else:
if (spider.get_NumUnspidered() == 0):
print "No more URLs to spider"
else:
print spider.lastErrorText()
# Sleep 1 second before spidering the next URL.
spider.SleepMs(1000)
And what does that error generally
mean?
An Attribute in Python is a name belonging to an object - a method or a variable. An AttributeError means that the program tried to use an attribute of an object, but the object did not have the requested attribute.
For instance, string objects have the 'upper' attribute, which is a method that returns the uppercase version of the string. You could write a method that uses it like this:
def get_upper(my_string):
return my_string.upper()
However, note that there's nothing in that method to ensure that you have to give it a string. You could pass in a file object, or a number. Neither of those have the 'upper' attribute, and Python will raise an Attribute Error.
As for why you're seeing it in this instance, you haven't provided enough detail for us to work it out. Add the full error message to your question.
1) Put code in Try ... Except block. get exception details.
2) Could you tell StackTrace details means which line # and method thrown error
And also are you able to run other simple python scripts without any error. Means just try to run some sample script etc.

Categories

Resources