I have got two (.py) files. When the first program comes to end, it will close itself then open and run the second program file. How can ı do it?

Stack Overflow Asked by Ömer Can on November 26, 2020

Here is my first file’s codes:

from csv import writer

film=[""] #The list contains informations about the film

filmname=input("Film name: ")
category=input("category: ")
score=input("point: ")
complement=input("complement: ")
valuablenames=input("İmportant actors: ")

#Appending Inputs

#The Function which appends the list into csv file:
def liste_append(filename,inf_list):
    with open("FilmSet.csv", 'a+', newline='') as write_obj: # Open file in append mode
        csv_writer = writer(write_obj)                       # Create a writer object from csv module
        csv_writer.writerow(film)                            # Add contents of list as last row in the csv file

#Calling Function

#Jumping to File which converts csv to xlsx

#Jumping to File which converts csv to xlsx
The part i need your help to close this file and jump to the other one (which is a converter program and named as "").So when i run this program,it will update the csv file and jump to "" for updating excel file from csv converted.( deletes the old xlsx and creates new xlsx which is converted from csv )

One Answer

Best solution

My recommendation would be to turn one of the python files into a package and simply import the required functions.

So in this case put your csv conversion from into a function like csv_to_xlsx() and then from conversion import csv_to_xlsx() and then run it at the end of your main file.

Other solutions

You could use the subprocess module with subprocess.Popen() or os.system(). These will allow you to execute python code from another file. Also the worst other solution is exec() this allows you to pass python code as a string and execute it. so you could do

exec(open('', 'r').read())

Correct answer by Kieran Wood on November 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP