运行Py2Exe时接收以下内容:
running py2exe
12 missing Modules
------------------
? Image imported from openpyxl.drawing.image
? PIL._imagingagg imported from PIL.ImageDraw
? PyQt5 imported from PIL.ImageQt
? PySide imported from PIL.ImageQt
? _abcoll imported from openpyxl.compat.odict
? _imaging_gif imported from PIL.GifImagePlugin
? _util imported from PIL.ImageCms
? cffi imported from PIL.Image, PIL.PyAccess
? lxml imported from openpyxl.xml, openpyxl.xml.functions
? openpyxl.tests imported from openpyxl.reader.excel
? readline imported from cmd, code, pdb
? tkinter imported from PIL.ImageTk
Building 'dist\dlpreport.exe'.
error: [Errno 2] No such file or …Run Code Online (Sandbox Code Playgroud) 我有一个CSV文件,我读作每行的字典列表.我想删除列表中具有EmailAddress的所有条目''.我试过了:
#!/usr/bin/python
import csv
def import_users(location_of_file):
with open(location_of_file, 'r', newline='', encoding='utf-8-sig') as openfile:
reader = csv.DictReader(openfile)
for row in reader:
yield row
def save_csv(data, location):
with open(location, 'w', newline='', encoding='utf-8-sig') as file:
fieldnames = ['EmailAddress', 'GivenName', 'Surname', 'Company', 'Department']
writer = csv.DictWriter(file, fieldnames=fieldnames)
writer.writeheader()
for item in data:
writer.writerow(item)
if __name__ == '__main__':
users = list(import_users('C:\Temp\Example.csv'))
for user in users:
if user['EmailAddress'] == '':
del user
else:
pass
save_csv(users, 'C:\Temp\Output.csv')
Run Code Online (Sandbox Code Playgroud)
但我的结果仍然是没有电子邮件地址的条目.我究竟做错了什么?
我正在开发一个函数,它接受一个CSV的文件名并将每一行转换为一个字典,然后返回一个创建的字典列表(以便能够迭代并在以后的函数中组织.我已经得到它通过以下方式做我想做的事,但觉得必须有更好的方法.有任何改进的建议吗?
import re
def import_incidents(filename):
"""Imports CSV and returns list of dictionaries for each incident"""
with open(filename, 'r') as file:
data = file.read()
data = data.split('\n')
list_of_data = []
headers = True
for line in data:
line = line.split('","')
if headers == True:
#Skip header and set to false
headers = False
elif len(line) == 1 or line[3] == '':
#File always has a 1 lenth final line, skip it.
#Events can leave blank policies, skip those too.
pass
else: …Run Code Online (Sandbox Code Playgroud) 我在这里阅读了这个问题,但没有看到我的案例的解决方案.
我已经创建了一个基本程序,它打开并使用位于.xslx文件中的数据,但我总是在运行时收到"UserWarning:Discarded range with reserved name".我不明白这意味着什么,也不知道如何避免错误.我不想绕过错误...我想修复代码,以免它被抛出.
这是我的代码:
from openpyxl import Workbook
from openpyxl import load_workbook
def get_unique_vulns(worksheet):
crit_vulns = worksheet.cell(row=4,column=2).value
high_vulns = worksheet.cell(row=5,column=2).value
med_vulns = worksheet.cell(row=6,column=2).value
low_vulns = worksheet.cell(row=7,column=2).value
list_vulns = (crit_vulns, high_vulns, med_vulns, low_vulns)
return list_vulns
workbook = load_workbook('test.xlsx', data_only=True)
vuln = {}
month = "May"
summarySheet = workbook.active
vuln[month] = get_unique_vulns(summarySheet)
print (vuln)
Run Code Online (Sandbox Code Playgroud)