python 3.x - how can I use a variable from a class in another file? -
i have 2 scripts, 1 holds log file creation , script holds email configuration. need pass variable log file creation script send email script, have imported log file send email script from logfile import logfilet
:
log code:
import configparser configparser import rawconfigparser import codecs import unittest import time import sys import logging config = configparser.rawconfigparser() configfilepath = 'c:\\python\\pi_webuitesting\\envconfig.cfg' config.read(configfilepath) class logfilet: def log_file(log_name): timestr = time.strftime("%y%m%d-%h%m%s") timestemp = time.strftime("%a, %d %b %y %h:%m:%s") logfilename = config.get('envconfig', 'logfile_path') + timestr + log_name logging.basicconfig(filename=logfilename, filemode='w',format= timestemp + '--%(levelname)s:%(message)s', level=logging.debug)
sendemail code:
import configparser configparser import rawconfigparser import codecs import unittest import time import sys import logging import trace import smtplib,ssl import base64 email import encoders email.mime.multipart import mimemultipart email.mime.base import mimebase email.mime.text import mimetext email.utils import formatdate logfile import logfilet config = configparser.rawconfigparser() configfilepath = 'c:\\python\\pi_webuitesting\\envconfig.cfg' config.read(configfilepath) class sendemail: def send_mail(self,email_subject): msg = mimemultipart() send_from = (config.get('mailconfig', 'send_from')) send_to = (config.get('mailconfig', 'send_to')) email_filename = logfile.logfilename msg['from'] = send_from msg['to'] = send_to msg['date'] = formatdate(localtime = true) msg['subject'] = email_subject msg.attach(mimetext(email_filename)) part = mimebase('application', "octet-stream") part.set_payload(open(email_filename, "rb").read()) encoders.encode_base64(part) part.add_header('content-disposition', 'attachment; filename="pi_test.log"') msg.attach(part) smtp = smtplib.smtp(config.get('mailconfig', 'smtp')) smtp.sendmail(send_from, send_to, msg.as_string()) smtp.quit()
i need logfilename
log class add email_filename
on send email code.
can assist please?
Comments
Post a Comment