its all about wordpress_xmlrpc for python lets start with code:
wp1 = Client(' http://example.com/xmlrpc.php ', 'username1', 'pass1') wp2 = Client(' http://example.com/xmlrpc.php ', 'username2', 'pass2')
this works fine when I try to add new comment: komment_id = wp1.call(NewComment(post_id, komment)) komment_id = wp2.call(NewComment(post_id, komment))
however I would like to do it randomly, so Im looking for solution to change X to number:
komment_id = wpX.call(NewComment(post_id, komment))
I have tried a lot of options and non of them works:
Fail1:
wpnumber = randint(1,10)
test = str('wp')+str(wpnumber)
komment_id = test.call(NewComment(post_id, komment))
Fail2:
komment_id = %d.call(NewComment(post_id, komment)) % (test)
Fail3: (and all its mutation with " ' ( ) , ( ) ) etc.
komment_id = test + .call(NewComment(post_id, komment))
Fail4:
komment_id = wp+wpnumber+.call(NewComment(post_id, komment))
To be honest, I tried 10 different ways with %s with %d, joining variables, spliting everything...
Anyone Could Help?
This is not possible using string concatenation. The test
variable which you are using must have exactly the same type as wp1
or wp2
, which cannot be generated using string concatenation.
You can do it like this. Store the randint(1,10) in a number and check that number through all the options.
number = randint(1,10)
if (number == 1):
test = wp1
elif (number == 2):
test = wp2
This will ensure both, randomness and that your test
variable is of the same type( Client
) as wp
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.