如何将程序从一个.py继续到另一个.py

时间:2015-07-27 23:12:45

标签: python python-import

在我有script1.py和script2.py的文件夹中。一旦script1.py运行,我可以使用

从script1.py运行script2.py中的整个程序
import script2

实际上使用script2.py作为模块吗?

他们必须在同一个文件夹中吗?只要我设置了script2.py

的位置,他们就可以在其他地方

我希望我能正确解释自己。

两个脚本都没有类或函数。

----------------------------------------------- ---------------------

SCRIPT1.py

import smtplib
import xbmc
import xbmcgui
import datetime

list = ("tom", "pete", "cris")


kb = xbmc.Keyboard('', 'Please type in your name to continue')
kb.doModal()
typedin = kb.getText()

if typedin.lower() in list:
    now = datetime.datetime.now()
    runtime = now.strftime("%Y-%m-%d %H:%M")

    content = xbmc.executebuiltin('kb.getText()')
    mailserver = smtplib.SMTP("smtp.mail.com",25)
    mailserver.ehlo()
    mailserver.starttls()
    mailserver.login('mail@somemail.com','somepwd')
    mailserver.sendmail('mail@somemail.com','mail@somemail.com',typedin + ' has run keymail ' + runtime)
    mailserver.close()
    xbmc.executebuiltin("Notification(An email has been sent, confirming the installation,()")
else:
    xbmc.executebuiltin("THE INPUTTED NAME, IS NOT VALID,()")
    xbmcgui.Dialog().ok(
    "Please try again - User name not correct",
    "yada",
    "yada",
    "yada")

----------------------------------------------- ---------------------

SCRIPT2.py

import os
import xbmc
import xbmcgui
import zipfile
import shutil
import time


remaaa = xbmc.translatePath('special://home/addons/plugin.video.aaastream')
remudaaa = xbmc.translatePath('special://home/userdata/addon_data/plugin.video.aaastream')
repoaaa = xbmc.translatePath('special://home/addons/repository.aaarepo')
zeusrepo = xbmc.translatePath('special://home/userdata/addon_data/plugin.program.super.favourites/Super Favourites/Maintenance/ZEUS/repository.zeus.zip')
zeusaddon = xbmc.translatePath('special://home/userdata/addon_data/plugin.program.super.favourites/Super Favourites/Maintenance/ZEUS/plugin.video.zeus-1.0.0.zip')


delold = os.path.exists(remaaa)

if delold:
    shutil.rmtree(remaaa, ignore_errors=False)
    xbmc.executebuiltin("Notification(AAA addon Removed, Proceeding to userdata,()")

else:
    xbmc.executebuiltin("Notification(AAA addon already been removed, removing userdata,()")

time.sleep(10)

deludaaa = os.path.exists(remudaaa)

if deludaaa:
    shutil.rmtree(remudaaa, ignore_errors=False)
    xbmc.executebuiltin("Notification(AAA Userdata Removed, Proceeding to install Zeus,()")

else:
    xbmc.executebuiltin("Notification(AAA userdata removed, Installing Zeus repository now please wait,()")

time.sleep(5)

targetzip = zeusrepo
targetaddon = zeusaddon
extractto = xbmc.translatePath('special://home/addons/')

fh = open(targetzip, 'rb')
z = zipfile.ZipFile(fh)
for name in z.namelist():
    z.extract(name, extractto)
fh.close()

time.sleep(4)

xbmc.executebuiltin("Notification(Zeus Repository Installed, Moving to addon,()")

hf = open(targetaddon, 'rb')
z = zipfile.ZipFile(hf)
for name in z.namelist():
    z.extract(name, extractto)
fh.close()

xbmc.executebuiltin("Notification(Zeus Addon Installed, All Done,()")

YESNOWINDOW = xbmcgui.Dialog().yesno(
    "This Code written by Simon the Microwave chef :)",
    "Zeus Video Addon Has been Installed",
    "You need to reboot your System to complete",
    "the installation. Reboot now?")
if YESNOWINDOW:
    xbmc.executebuiltin("RestartApp")
else:
    xbmc.executebuiltin("ActivateWindow(10000,return)")

----------------------------------------------- ----------------------

所以我想要做的是在这里导入脚本2:

if typedin.lower() in list:
    now = datetime.datetime.now()
    runtime = now.strftime("%Y-%m-%d %H:%M")

    content = xbmc.executebuiltin('kb.getText()')
    mailserver = smtplib.SMTP("smtp.mail.com",25)
    mailserver.ehlo()
    mailserver.starttls()
    mailserver.login('mail@somemail.com','somepwd')
    mailserver.sendmail('mail@somemail.com','mail@somemail.com',typedin + ' has run keymail ' + runtime)
    mailserver.close()
    xbmc.executebuiltin("Notification(An email has been sent, confirming the installation,()")
#I want to import script2 here...is this valid
    import script2

0 个答案:

没有答案