Python嵌套的if语句返回错误 - python

我正在尝试读取.txt和.log文件,搜索特定的单词,然后使用if语句将结果返回到CSV。如何打开其他文件以读取if语句?

我运行了让我在另一个python文件中出现错误的部分,它工作正常并且能够打开和读取。所以这不是我不认为的代码本身。尽管我对Python还是很陌生。

运行以下命令时,出现以下错误。

  最新文件=最大值(list_of_files,key = os.path.getctime)
  ValueError:max()arg为空序列”

with open('//' + hostName + '/C$/Windows/System32/inetsrv/config/applicationHost.config') as doc:
    lines1 = doc.read()
    if ("logFormat=" + '"W3C"' in lines1):
        list_of_files = glob.glob('//' + hostName + '/C$/inetpub/logs/LogFiles/W3SVC1/*')
        latest_file = max(list_of_files, key=os.path.getctime)
        y = latest_file
        with open(y) as doc1:

参考方案

显然,它适用于大多数主机名。我添加了try和except语句,并捕获了错误。

R'relaimpo'软件包的Python端口 - python

我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。

Python sqlite3数据库已锁定 - python

我在Windows上使用Python 3和sqlite3。我正在开发一个使用数据库存储联系人的小型应用程序。我注意到,如果应用程序被强制关闭(通过错误或通过任务管理器结束),则会收到sqlite3错误(sqlite3.OperationalError:数据库已锁定)。我想这是因为在应用程序关闭之前,我没有正确关闭数据库连接。我已经试过了: connectio…

Python:传递记录器是个好主意吗? - python

我的Web服务器的API日志如下:started started succeeded failed 那是同时收到的两个请求。很难说哪一个成功或失败。为了彼此分离请求,我为每个请求创建了一个随机数,并将其用作记录器的名称logger = logging.getLogger(random_number) 日志变成[111] started [222] start…

Python-Excel导出 - python

我有以下代码:import pandas as pd import requests from bs4 import BeautifulSoup res = requests.get("https://www.bankier.pl/gielda/notowania/akcje") soup = BeautifulSoup(res.cont…

Matplotlib'粗体'字体 - python

跟随this example:import numpy as np import matplotlib.pyplot as plt fig = plt.figure() for i, label in enumerate(('A', 'B', 'C', 'D')): ax = f…