I need the .py file to create executable .exe files on python, something like this:

k = open('blabla.exe','w') k.write('print(\'Hello\')') k.close() 

    2 answers 2

    First, I recommend to start with the fact that understand the basic concepts. Namely - "executable file! = Exe-file". With this in mind, the text you have written quite quite correctly creates a file with the extension "exe" (however, with any other), but it will not be an executable file.

    Secondly, if you want to create an executable file, it means that you need to compile the text you create. Those. you write a program (in which language, by the way?), and pass it to the input of the compiler, which you call from your script, which for some reason does not just create an executable file, but returns it to the program that caused it, so that it already writes her to some file. Do not you think that it is to put it mildly complicated and illogical. Perhaps it is better to once again think over and modify the logic of your program?

    If, however, you just need to compile a file written in Python, and create an executable file as a result, then, you can read:

    https://pythonworld.ru/osnovy/program-compilation-with-cx-freeze.html

    http://www.py2exe.org/

    http://www.pyinstaller.org/

    https://golos.io/ru--programmirovanie/@pythono/python-kompilyaciya-skriptov-v-exe-fail

      In order for the exe file to work, you cannot simply enter some text, you can compile the python code in exe using pyinstaller, first you need to download it, with pip, write pd install pyinstaller in cmd, and then write pyinstaller in the same cmd --onefile your_.py_file