python - 简单函数错误

标签 python

代码:

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)

给出

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)

我怎样才能让它工作?

最佳答案

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)

关于python - 简单函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4115275/

相关文章:

python - 在 pandas 中快速高效地用历史平均值填充缺失数据

python - 使用pandas索引作为字典键,根据匹配键用值填充字典

Python 脚本策略 : running script twice vs excec

python - 在不同模块中运行的线程之间共享队列

python - Beautiful Soup - 选择没有类的下一个跨度元素的文本

python - 当用户使用 pip 卸载我的包时如何运行脚本?

python - 如何在 python 中检查指定函数的至少一个默认参数

python - 事件处理 : Matplotlib's Figure() and pyplot's figure()

python - 使用 Python 从 Excel 到 PowerPoint 的图表

python - 在 Python 的子进程中列出超出范围的索引