簡體   English   中英

將文件從python轉換為exe

[英]Converting file from python to exe

我編寫了一個文件,將 CSV 中的分隔符從格式“,”轉換為“;”。 我正在嘗試使用 auto-py-to-exe 將此文件從 .py 轉換為 .exe。 雖然此過程確實有效並正確執行,但單擊應用程序不會執行任何操作。

我在代碼中遺漏了什么嗎? 也許是自動執行命令?

# import necessary libraries
import pandas as pd
import os
import glob
  
  
# use glob to get all the csv files 
# in the folder
path = os.getcwd()
csv_files = glob.glob(os.path.join(path, "*.csv"))
  
  
# loop over the list of csv files
for f in csv_files:
      
    # read the csv file
    df = pd.read_csv(f, delimiter=',')
    df.to_csv(f, sep=';', index = False)
    

您應該使用argparse來提供 inpu# 導入所需的庫

import pandas as pd
import os
import glob
import argparse
  
# use glob to get all the csv files 
# in the folder

parser = argparse.ArgumentParser()

# Adding optional argument
parser.add_argument("-i", "--InputPath", help="Input path files")
parser.add_argument("-i", "--OutPath", help="Out path files")


path = os.path.abspath(args.InputPath)
csv_files = glob.glob(os.path.join(path, "*.csv"))
  
  
# loop over the list of csv files
for f in csv_files:
      
    # read the csv file
    df = pd.read_csv(f, delimiter=',')
    df.to_csv(os.path.join(os.path.abspath(args.OutPath),f), sep=';', index = False) 

然后只需使用auto-py-to-exe即可生成 exe。

打開cmd到exe所在的地方,然后相應地使用它。

指令:
$ file.py -i "input path" -o "Out path"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM