lundi 29 juin 2015

addition with python into a .txt file

i am creating a chatroom bot using python 2.7.9 and i wanna know how to take the number i have in the .txt file and add a number to it, im stuck and i wanna know how to do this so i can add currency to my chatroom bot. ive tried to do this before but i am having too many problems with it. "args" is the argument/number i want to add "yp" is the currency i am using this is what i have, but it isnt working Definition for the currency:

yp = []
f = open("yp.txt", "r")
time.sleep(1)
for currency in f.readlines():
    if len(currency.strip())>0: yp.append(currency.strip())
f.close()

what i use to save the numbers to the file:

def saveyp(user):
f = open("yp.txt", "w")
f.write("\n".join(wl+args))
f.close()

and my command i have for the bot:

if used_prefix and cmd == "test" and user.name in owners:
    if args:
        yp.append(yp+args)
        saveyp(yp+args)
        room.message("$"+args+" has been added to your currency :)")
        room.message(user.name.capitalize()+", you now have $"+yp)
    else:
        room.message("ERROR!")

Aucun commentaire:

Enregistrer un commentaire