首页 > 解决方案 > 使用批处理脚本调用读取 mbox 文件的 python 脚本

问题描述

我有这个代码,它将文件路径作为参数mbox并打印最后一个 mbox 文件。

import mailbox
import sys
messages = mailbox.mbox(sys.argv[1])
print(messages[len(messages)-1])

我想.bat在 Windows 中使用脚本调用这个脚本,所以我使用了以下代码,但它给了我这个错误

KeyError:没有带有密钥的消息:-1

这是我使用的脚本:

@echo off
set VAR_1= "C:\Users\hmk\Desktop\PFE 2019\ML\MachineLearningPhishing-master\MachineLearningPhishing-master\code\resources\email-enron.mbox"
python get_last_mail.py %1 VAR_1
pause

我在 jupyter notebook 上使用了相同的代码,只有文件路径的静态条目,它可以工作。

标签: pythonbatch-file

解决方案


推荐阅读