Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何处理:log.write len([name_Python_Python 2.7 - Fatal编程技术网

Python 如何处理:log.write len([name

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() 使用: 使

我有个问题。我不知道如何“连接”日志 大约在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()

您需要向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)中的名称命名])类型错误:需要字符串或其他字符缓冲区对象谢谢您的帮助!