AnswerBun.com

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

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

#Appending Inputs
film.append(filmname)
film.append(category)
film.append(score)
film.append(complement)
film.append(valuablenames)

#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
liste_append("FilmSet.csv",film)

#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 "converter.py").So when i run this program,it will update the csv file and jump to "converter.py" 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 conversion.py 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('file.py', 'r').read())

Correct answer by Kieran Wood on November 26, 2020

Add your own answers!

Related Questions

Laravel Slow queries

5  Asked on November 7, 2021 by squiggs

     

Display image that returns HTTP 503 in Firefox

2  Asked on November 7, 2021 by brainstone

       

Simple TCP listener on swift

1  Asked on November 7, 2021 by mr-park

       

check the type of the only child in react

1  Asked on November 7, 2021

 

Cannot update document using the NodeJS MongoDB driver

1  Asked on November 7, 2021 by niaz-m-sameer

   

Can not convert umlauts (Ü Ö Ä ü ö ä è é) to .utf8

2  Asked on November 7, 2021 by salome-tsiramua

       

elegant way of extracting option value when need it

1  Asked on November 7, 2021 by user804968

 

Sign PDF asynchronous using PDFBox

0  Asked on November 7, 2021 by lawrence-leung

         

Get non hidden element with previousElementSibling

2  Asked on November 7, 2021 by jens-trnell

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir