I need to know a way to call a function defined in the exe from a python script. I know how to call entire exe from py file.
Unless the said executable takes command line arguments which will specify which function to use, I don't think this is possible.
With that being said, if you created the EXE, command line arguments are a good way to implement the functionality you're looking for.
Unless your EXE is a COM object, or specifically exports certain functions like a dll does, then this is not possible.
For the COM method take a look at these resources:
- Python Programming On Win32 book, by Mark Hammond and Andy Robinson.
- COM and Python quick start on learning COM with python
For the exported functions like a dll method, please use python's win32 module along with the Win32 API LoadLibrary and related functions.
If you have access to the EXE's source code:
If you have access to the source code of this EXE though, you should define command line arguments and tie that into calling the function you want to call. In this case you can use the python os.system call to start your application or subprocess.call().
Not sure if it is for windows. But you can treat an exe like a dll (if functions are exported). And they can be used by other programs.