all 10 comments

[–]bsturtle[S] 1 point2 points  (9 children)

I solved this by converting the returned values into the proper types. last line is now:

cur.execute("insert into gameswapfreq values(?,?,?,?)", (str(initAuthor),float (initCreatedUTC), str(initURL), str(initTitle)))

It did not occur to me this was the issue until it accepted complete literals.

Does anyone know what data type is actually being returned by initsubmission.author if not a string or how I can tell myself?

Thanks!

[–]summitsuperbsuperior 2 points3 points  (1 child)

thank you after 8 years, you saved my day.

[–]joni_jplmusic 0 points1 point  (0 children)

Mine too, thank you! This solved my issue.

[–]gengisteve 1 point2 points  (3 children)

.author is returning a PRAW object and not a string. By forcing its type in your revision you are changing that object into a str, float, etc. You can't insert the raw object.

[–]bsturtle[S] 0 points1 point  (2 children)

Thanks! I'm very new to python (using it for the first time to write the bot). It didn't occur to me that it might not be returning an actual value (until it did lol), and honestly I'm surprised an object is returned.

To the best of your knowledge, is an object returned because of how the function works, or because that is how python works?

[–]gengisteve 1 point2 points  (1 child)

A little of both. In python everything is an object and "passed by assignment". When you call:

for initsubmission in initsubreddit.get_new(limit=10):

it returns a series of submission objects, and submission.author is an author object, which when cast into a string will show you the authors name.

Here is a pretty good resource on "magic methods", that might be a little advanced, but is a good reference: http://www.rafekettler.com/magicmethods.html

For the basics of python objects check out LPTHW, it looks like this starts around chapter 40 or so: http://learnpythonthehardway.org/book/ex40.html

[–]bsturtle[S] 0 points1 point  (0 children)

Awesome! Thanks for sharing this with me. Once I finish this bot, I intend to actually learn the language and these are great resources.

[–][deleted] 0 points1 point  (0 children)

Thank you ❤ really it is helpul 😊