是否可以从另一个python脚本中运行python脚本?

时间:2019-04-12 15:40:31

标签: python windows file-transfer

我有两个python脚本,一个将视频文件从我的下载文件夹移动到我的视频文件夹中的一个文件夹,第二个是carykh的Jumpcutter程序https://github.com/carykh/jumpcutter。当您运行cary的程序时,它会使用解析器参数。我希望我的第一个移动文件的程序(连续运行并在检测到文件后立即移动文件)在文件移动后执行cary的jumpcutter。有办法吗?

我目前有一个批处理文件,它使用所有预定义的解析器参数运行cary的jumpcutter,但我必须手动为每个视频运行它,并希望它自动为每个视频依次运行。

今天下午晚些时候,我将在此帖子中添加一些代码。

因此,程序应该做的是,检测视频是否已下载,将其移到我的视频文件夹中的文件夹中,然后对视频运行cary的jumpcutter。 当前正在执行的操作是检测视频是否已下载,然后将其移至正确的文件夹,然后再执行任何操作。

1 个答案:

答案 0 :(得分:1)

您至少有两个选择:

  1. 使用cloudpickle#!/usr/bin/python3 import tkinter as tk from tkinter import ttk from tkinter import messagebox from tkinter.scrolledtext import ScrolledText class Main(ttk.Frame): def __init__(self, parent): super().__init__() self.parent = parent self.answer = tk.StringVar() self.questions = ("There is anybody ot there?", "Did you like spaghetti?", "Is the weather nice in Italy in the winter?", "Did you like this example?",) self.init_ui() def init_ui(self): f = ttk.Frame() ttk.Label(f, text = "Answer").pack() self.txAnswer = ttk.Entry(f, textvariable=self.answer) self.txAnswer.pack(fill=tk.X, expand=1) self.txAnswer.bind("<Return>",self.get_answer) self.txQuestion = ScrolledText(f) self.txQuestion.pack(fill=tk.BOTH, expand=1) f.pack(fill=tk.BOTH, expand=1) def on_set_question(self,): self.txQuestion.insert(tk.END, '\nQ:') self.txQuestion.insert(tk.END, self.questions[0]) self.which = 0 self.clear_answer() def get_answer(self, evt=None): if self.answer.get() in ("Yes","yes","YES","42"): if self.which ==len(self.questions)-1: self.which = 0 else: self.which +=1 self.txQuestion.insert(tk.END, '\nA:') self.txQuestion.insert(tk.END, self.answer.get()) self.txQuestion.insert(tk.END, '\nQ:') self.txQuestion.insert(tk.END, self.questions[self.which]) else: self.txQuestion.insert(tk.END, '\nA:') self.txQuestion.insert(tk.END, self.answer.get()) self.txQuestion.insert(tk.END, "\nThis is not the right answer...") self.clear_answer() def clear_answer(self): self.answer.set('') self.txAnswer.focus() def on_close(self): self.parent.on_exit() class App(tk.Tk): """Start here""" def __init__(self): super().__init__() self.protocol("WM_DELETE_WINDOW", self.on_exit) self.set_title() self.set_style() Main(self,).on_set_question() def set_style(self): self.style = ttk.Style() #('winnative', 'clam', 'alt', 'default', 'classic', 'vista', 'xpnative') self.style.theme_use("clam") def set_title(self): s = "{0}".format('Simple App') self.title(s) def on_exit(self): """Close all""" if messagebox.askokcancel("Simple App", "Do you want to quit?", parent=self): self.destroy() if __name__ == '__main__': app = App() app.mainloop()
  2. 打开包含要运行的脚本的文件,并将其传递给os.system()

我会先尝试第一个选项,因为它们允许传递参数。