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")
for currency in f.readlines():
    if len(currency.strip())>0: yp.append(currency.strip())

what i use to save the numbers to the file:

def saveyp(user):
f = open("yp.txt", "w")

and my command i have for the bot:

if used_prefix and cmd == "test" and in owners:
    if args:
        room.message("$"+args+" has been added to your currency :)")
        room.message(", you now have $"+yp)

Aucun commentaire:

Enregistrer un commentaire