1

code:

date=int(raw_input("Date:"))
ammount=int(raw_input("Ammount:"))
desc=str(raw_input("Description:"))
account=str(raw_input("Account:"))
def addEntry(date, ammount, desc, account):
 transact=open("transactions.txt", "w")
 transact.write(date, ammount, desc, account)
 transact.close()
addEntry(date, ammount, desc, account)

gives

Traceback (most recent call last):
 File "C:\tbank.py", line 11, in <module>
 addEntry(date, ammount, desc, account)
 File "C:\tbank.py", line 8, in addEntry
 transact.write(date, ammount, desc, account)
TypeError: function takes exactly 1 argument (4 given)

how can i make it work?

aaronasterling
71.5k20 gold badges133 silver badges127 bronze badges
asked Nov 6, 2010 at 21:33
1
  • 6
    Read the error it gives you? Commented Nov 6, 2010 at 21:37

3 Answers 3

1
date=int(raw_input("Date:"))
ammount=int(raw_input("Ammount:"))
desc=str(raw_input("Description:"))
account=str(raw_input("Account:"))
def addEntry(date, ammount, desc, account):
 transact=open("transactions.txt", "w")
 transact.write('%s, %s, %s , %s' % (date, ammount, desc, account))
 transact.close()
addEntry(date, ammount, desc, account)
answered Nov 6, 2010 at 21:36
Sign up to request clarification or add additional context in comments.

Comments

0

You are opening a file to write to it. It takes a single string as argument.

transact.write("your string")

Since all you are doing is write to file. You can avoid conversion. And raw_input returns a string.

date=raw_input("Date:")
amount =raw_input("Ammount:")
desc=raw_input("Description:")
account=raw_input("Account:")

You can add all of them as one string, before writing it to file

answered Nov 6, 2010 at 21:36

3 Comments

this combine with the print works the best, another thing is how can i select the second word? or should i try to use a csv file, any guides on that?
@Gjorgji: Sorry. I could respond back earlier. I was offline. I couldn't get what you meant by selecting the second word.
Well i write date/amount/stuff/otherstuff now if i want to filter by date but get the amount values, how do i select the second value (amount) of each line?
0

As others have noted, you must pass write a single string argument. There is another way to write things out to an open file that should be mentioned: the special form of print

print >>transact, date, amount, desc, account

This directs print to output to the file that immediatedly follows the '>>' It behaves exactly like print normally does, so it will write out all the values separated by a space, with a newline at the end (which you can suppress by adding a trailing comma).

answered Nov 6, 2010 at 21:43

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.