Python 如何处理:log.write len([name
我有个问题。我不知道如何“连接”日志 大约在10号线Python 如何处理:log.write len([name,python,python-2.7,Python,Python 2.7,我有个问题。我不知道如何“连接”日志 大约在10号线 import os import os.path import time DIR = '/home/richard/DB/' #while a != 0: log = open("logfile.log","wt") log.write len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) log.close() 使用: 使
import os
import os.path
import time
DIR = '/home/richard/DB/'
#while a != 0:
log = open("logfile.log","wt")
log.write len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
log.close()
使用:
使用:
小语法错误
import os
import os.path
import time
DIR = '/home/richard/DB/'
#while a != 0:
log = open("logfile.log","wt")
log.write(len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]))
log.close()
小语法错误
import os
import os.path
import time
DIR = '/home/richard/DB/'
#while a != 0:
log = open("logfile.log","wt")
log.write(len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]))
log.close()
您需要向log.write传递一个字符串
log.write("{}".format(len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]))
或
您需要向log.write传递一个字符串
log.write("{}".format(len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]))
或
log.write(len(…)
Traceback(最近一次调用):File/home/richard/db1.py,第13行,在log.write(len([name for name in os.listdir(DIR)if os.path.isfile(os.path.join(DIR,name)))中键入错误:需要字符串或其他字符缓冲区对象log.write(len(…)
Traceback(最近一次调用):File“/home/richard/db1.py”,log.write中的第13行(len([name for name in os.list DIR(DIR)if os.path.isfile(os.path.join(DIR,name)))))type错误:应为字符串或其他字符缓冲区对象回溯(最近一次调用):File)/home/richard/db1.py,log.write中的第13行(len([name for name in os.listdir(DIR)if os.path.isfile)(os.path.join(DIR,name))]))类型错误:应为字符串或其他字符缓冲区对象回溯(上次调用):文件“/home/richard/db1.py”,第13行,在log.write中(len([name for name in os.listdir(DIR)if os.path.isfile(os.path.join(DIR,name)))类型错误:应为字符串或其他字符缓冲区对象回溯(最近一次调用):log.write中的文件“/home/richard/db1.py”,第13行(len([name for name in os.listdir(DIR)if os.path.isfile(os.path.join(DIR,name))]))类型错误:需要字符串或其他字符缓冲区对象谢谢您的帮助!回溯(最近一次调用):log.write中的文件“/home/richard/db1.py”,第13行([如果os.path.isfile(os.path.join(DIR,name)),则为os.listdir(DIR)中的名称命名])类型错误:需要字符串或其他字符缓冲区对象谢谢您的帮助!