导入MIMEMultipart

时间:2017-03-23 18:11:06

标签: python python-3.x

我正在阅读的所有内容都说email.MIMEMultipart包含在Python的基本库中,但在尝试运行需要它的代码时,我收到的消息是:

ModuleNotFoundError: No module named 'email.MIMEMultipart' 

我在这里缺少一些简单的东西,或者由于某些原因我没有这个模块吗?

import sys
import time
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText

1 个答案:

答案 0 :(得分:0)

MIMEMultipart不是模块;它是#include <iostream> #include <fstream> #include <sstream> #include <string> #include <vector> #include <iterator> #include <algorithm> using namespace std; const string records_file("records.txt"); // declaring a struct for each record struct record { int number; // number of record vector<int> content; // content of record }; // declaring an input operator to read a single record from a stream istream& operator>>(istream &in, record &out) { out.number = 0; out.content.clear(); string line; if (getline(in, line)) { istringstream iss(line); if (iss >> out.number) { cout << out.number << " "; out.content.reserve(32); // WE KNOW THERE WILL BE 32 ENTRIES copy(istream_iterator<int>(iss), istream_iterator<int>(), back_inserter(out.content)); for (int d = 0; d < out.content.size(); d++) cout << out.content[d] << " "; } } return in; } int main() { vector<record> batch_1; // stores integers from 1 - 64 vector<record> batch_2; // stores integers from 65 - 128 record temp; // read the data file ifstream read_records(records_file.c_str()); if (!read_records) { cerr << "Cannot open " << records_file << endl; exit(EXIT_FAILURE); } cout << "Reading data file: " << records_file << endl; while (read_records >> temp) { switch (temp.number) { case 1: batch_1.push_back(temp); break; case 2: batch_2.push_back(temp); break; } } read_records.close(); // process batch_1 and batch_2 as needed... return 0; } 模块中的一个类。要导入它,您必须:

email.mime.multipart