You are viewing a single comment's thread from:

RE: Upvote bot in less than 10 lines of code

in #steem8 years ago (edited)

Hey @xeroc, love your stuff but I found a small bug with this logic:

if c["author"] in authors:

This will be true for substring matches in authors.

So if authors contains a name such as "longtestname"
and c["author"] contains a name such as "name" or "test"

It will evaluate as true

(Python is still new for me)

Sort:  

Thanks for taking a closer look, but since this expression

"a" in ["aa"]

evaluates to False in python, I'd say that python interprets all elements of authors independently and in full. That's because authors is an array or list.

If it was just a single author then you would be right since

"a" in "aa"

evaluates to True

Agreed?

Just tested this more and found out what the error was:

If you include the single quotes around the array, both statements return True

stringList = '["list","of","strings"]'
print("list" in stringList)
True
print ("li" in stringList)
True

But if you remove the single quotes around the array, it functions as intended:

stringList = ["list","of","strings"]
print("list" in stringList)
True
print ("li" in stringList)
False

Hope this helps!

In the first case, the stringList is actually a simple string and is not interpreted as an array. that's why the test returns true in both cases.

Coin Marketplace

STEEM 0.16
TRX 0.15
JST 0.029
BTC 56596.99
ETH 2394.78
USDT 1.00
SBD 2.32