简体   繁体   中英

Why does my application close immediately after launching

I am a beginner to python language. I have two questions.

  1. When I run auto-py-to-exe my application does not work correctly.

Up to line 8 of my code I want user to select the .csv file to upload to the py program. After running the auto-py-to-exe, the application closes and does not let the user select the file to upload.

What am I missing in my code to have the application stay open until the user selects the required file, then run the rest of the code?

when running this py.file in pycharm it works as it should.

This next question is un-related t this topic but...

  1. How to i pass a filename dynamically?

In line 33 of my code I will be writing a specially formatted .csv as result.csv to a local dir. How do I pass the variable "filename" as a filename in the path statement in line 33.

df.to_csv('C:\\WriteFilesHere\\ result.csv')

When I run the program it always overwrites "result.csv" with the new file selected in line 8 of my code. I want a new file create with a different name every time I run the program.

from tkinter import *
import pandas as pd
import csv
from tkinter.filedialog import askopenfilename

Tk().withdraw()
filename = askopenfilename()
print(filename)

with open('preliminary.csv', 'w') as output:
    with open(filename) as csv_file:
        output_data = csv.writer(output, delimiter=",")
        data = csv.reader(csv_file, delimiter=',')
        line_count = 0
        for row in data:

            if line_count == 0:
                output_data.writerow(row)
                line_count += 1
            else:
                output_data.writerow(row)
                line_count += 1
with open("preliminary.csv") as readfile:
    reader1 = csv.reader(readfile)
    read =[]
    for row in reader1:
        if len(row) !=0:
            read = read +[row]
readfile.close()
pd.set_option('display.max_rows',4000)
df = pd.DataFrame(read)
print(df)
df.to_csv('C:\WriteFilesHere\ result.csv')

About the exe, you can declare a variable and add at the end of your program:

DonotClose=input("press close to exit") 

It will pause the program, you can use any variable you like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM