2つの引数:log_message
とmode
をとるログ機能を作成しました。2番目の引数を許可しない関数
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()
は間違いなく2つの引数を取ることから、奇妙です:私は、引数を関数を使用すると、渡す際に何らかの理由で、私は次のエラーを取得します。ここで
が私のコードです:
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 Example](http://stackoverflow.com/help/mcve)を作成して表示しますか? –
@Someprogrammerdudeこの例で何が問題になっていますか? – rhillhouse
上記のコードはOKです。議論に問題はありません。どのように実行するかお知らせください。 – Raptor