我使用cx_freeze将python文件转换为exe。以下是setup.py文件。当我运行hello.exe时,输出是这样的。 '你好兄弟 !!!'但是,当我在hi.py文件中更改“早安”并运行hello.exe时,“您好,兄弟!!”它出现。为此,我应该在安装文件中怎么做才能对hi.py进行更改?
setup.py
from cx_Freeze import setup, Executable
setup(name="hello",
version="0.1",
description="hellov1",
executables=[Executable("hello.py")],
)
hi.py
print("Hello Brother!!!")
hello.py
import cx_Freeze
import hi
因为.py文件将成为exe文件,并且小文件的编辑复杂。但是安装了hi.py文件后,请尝试制作onw数据文件。基本只是一个文本文件,因此很容易。那可悲的数据库将失去代码,并且可以轻易编辑后也将影响您的代码。hello.py将如下所示:
#import cx_Freeze #// I do not know what this do. You know
from hi import DataBase, Logic
# Make shore that base is take it
DataBase.GetDataBase()
# Now make shore to import data base library updated
from hi import dataBaseLib
# Hello message
Logic.Hello(dataBaseLib["hello_message"])
hi.py看起来像这样:
dataBaseFile = "custom_data.kmb_bey"
dataBaseLib = {}
class Logic:
def Hello(msg):
print(msg)
class DataBase:
def GetDataBase(fileName=dataBaseFile):
try:
DataBase.ReadFile(fileName)
except FileNotFoundError:
DataBase.WriteFile(fileName)
DataBase.ReadFile(fileName)
def WriteFile(fileName):
with open(fileName, "w") as file:
file.write("""#// Custom Data Base for KMB_Bey
hello_message=Hello Brother!!!""")
def ReadFile(fileName):
with open(fileName, "r") as file:
line = file.readline()
while line:
if "=" in line:
x = line.strip().split("=")
data, info = x[0], x[1]
if data not in dataBaseLib.keys():
dataBaseLib[data] = info
line = file.readline()
如果文件custom_data.kmb_bey不存在,那蜜蜂就不做任何事情。如果不存在,将创建该文件,您可以在=之后更改任何thex,并且thex将是新值,并在您的项目中显示。 (您可以使用任何文本编辑器编辑该文件)
您将代码放回首页会为您提供帮助。我只是直接将它写在浏览器上,我尚未对其进行测试。但是我支持90%的工作。