简体   繁体   English

获取python可执行文件的原始脚本名称

[英]Get the original script name of a python executable

I have a program coded in python named: "main.exe" And I would like to know the name of the script it had before being convert into an executable.我有一个用 python 编码的程序,名为:“main.exe” 我想知道它在转换为可执行文件之前的脚本名称。

In case the executable has been renamed, it doesn't have the same name as the original script.如果可执行文件已重命名,则它与原始脚本的名称不同。

I hope you understood me.我希望你理解我。 An example to illustrate:举例说明:

get_original_name(main.exe)
-> script.py

Thanks a lot.非常感谢。

It is Not Possible, Since the Filename and the Compiled Program Have No Link,这是不可能的,因为文件名和编译的程序没有链接,

But tools like Resource Hacker Can get you alot of information about that particular Program, and it can be used in other things Too但是像Resource Hacker这样的工具可以让你获得关于那个特定程序的大量信息,它也可以用在其他事情上

If possible, you can access the name of the py file via:如果可能,您可以通过以下方式访问py文件的名称:

import os
print(os.path.basename(__file__))

If you were to compile this code and give the exe a new name with pyinstaller, the original script name will be printed.如果您要编译此代码并使用 pyinstaller 为exe一个新名称,则会打印原始脚本名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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