![]() |
python update binary object (override delivered Object properties) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: python update binary object (override delivered Object properties) (/thread-37248.html) |
python update binary object (override delivered Object properties) - pierre38 - May-17-2022 Hello, I did many trials without success. I need to have flexibility in my Python code, so I use already .yaml configuration for deliverable scripts (generated executable from pyInstaller), but this is not enough. I am trying to find out if it is possible to redefine some methods from a python wrapper script calling the executable binary script. Below is the example: wrap.py: import os # import invest or ?? def displayParam(self): print("overriden text") Foo.displayParam = displayParam os.system("/prj/mms_nvm/cad_prj/python/users/paolipie/python/py_workdev/create_deliverable/dist/invest/invest")invest.py import sys from src.foo import Foo def main(argv): foo = Foo() foo.displayParam() # exec if __name__ == "__main__": main(sys.argv[1:])foo.py import sys import os from pathlib import Path # main class Foo: def __init__(self): self.other = None def displayParam(self): print("default text")When I execute the wrap.py: > python wrap.py Traceback (most recent call last): File "wrap.py", line 7, in <module> Foo.displayParam = displayParam NameError: name 'Foo' is not defined Can someone provide me some advice ? thanks a lot, Pierre RE: python update binary object (override delivered Object properties) - ibreeden - May-18-2022 (May-17-2022, 03:30 PM)pierre38 Wrote: NameError: name 'Foo' is not definedThat is correct. You did not import foo. RE: python update binary object (override delivered Object properties) - pierre38 - May-18-2022 Yes and how to "import" it from the delivered script ? thanks, Pierre RE: python update binary object (override delivered Object properties) - bowlofred - May-18-2022 The class is defined in foo.py. So you'd import from that file whenever you need to reference it. It appears you do that in invest.py. But in wrap.py you refer to Foo without an import. One would be necessary there as well (although the code in wrap.py doesn't seem to call the class properly. Looks like you're overwriting the method rather than calling it). RE: python update binary object (override delivered Object properties) - pierre38 - May-19-2022 Yes my goal is to override a method. The method is into a python script which is "delivered" via PyInstaller into a binary .so suite of files: Quote:paolipie@gnbsx26072:/<4>users/paolipie/python/py_workdev/invest_overwritte_func/> ll ../create_deliverable/dist/invest/ I cannot understand well the import doc: https://docs.python.org/3/reference/import.html#importsystem It may appear that importing .so "shared libraries as they call" is possible but I did not find how. Quote:5.5. The Path Based Finder thanks for helping, Pierre |