我做了一个日志功能,它有两个参数:log_message
和mode
。出于某种原因,当我使用的功能和参数传递,我得到以下错误:函数不允许第二个参数
Traceback (most recent call last):
File "/Users/user/git/rip/rip.py", line 248, in <module>
main()
File "/Users/user/git/rip/rip.py", line 195, in main
log('STARTING RIPPER', 'i')
TypeError: log() takes 1 positional argument but 2 were given
这是奇怪的,因为log()
绝对需要两个参数。
这里是我的代码:
import os
import sys
import time
import mmap
import json
import requests
from bs4 import BeautifulSoup
from clint.textui import puts, colored
def log(log_message, mode='s'):
log_date = '[' + time.strftime("%d.%m_%H:%M:%S") + ']'
if mode == 'e':
log_file = 'test_error.log'
log_ouput = colored.white(log_date) + colored.red('[ERROR]' + log_message)
elif mode == 'i':
log_file = 'test_info.log'
log_ouput = colored.white(log_date) + colored.yellow('[INFO]' + log_message)
elif mode == 'c':
log_file = 'test_info.log'
log_ouput = colored.white(log_date) + colored.white('[COMMENT]' + log_message)
else:
log_file = 'test_download.log'
log_ouput = colored.white(log_date) + colored.green(log_message)
with open(log_file, 'a') as file_writer:
file_writer.write(log_message + '\n')
file_writer.close()
puts(log_ouput)
def main():
log('STARTING RIPPER', 'i')
能不能请你到什么创建一个[Minimal,* Complete *和Verifiable示例](http://stackoverflow.com/help/mcve)并向我们展示? –
@Someprogrammerdude这个例子有什么问题? – rhillhouse
上面的代码看起来没问题。争议没有问题。请让我们知道你如何运行它。 – Raptor