Python Forum
python update binary object (override delivered Object properties)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python update binary object (override delivered Object properties)
#1
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
Reply
#2
(May-17-2022, 03:30 PM)pierre38 Wrote: NameError: name 'Foo' is not defined
That is correct. You did not import foo.
Reply
#3
Yes and how to "import" it from the delivered script ?

thanks,
Pierre
Reply
#4
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).
Reply
#5
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/
base_library.zip invest* _random.cpython-37m-x86_64-linux-gnu.so*
binascii.cpython-37m-x86_64-linux-gnu.so* libbz2.so.1* readline.cpython-37m-x86_64-linux-gnu.so*
_bisect.cpython-37m-x86_64-linux-gnu.so* liblzma.so.5* resource.cpython-37m-x86_64-linux-gnu.so*
_blake2.cpython-37m-x86_64-linux-gnu.so* libpython3.7m.so.1.0* select.cpython-37m-x86_64-linux-gnu.so*
_bz2.cpython-37m-x86_64-linux-gnu.so* libreadline.so.6* _sha1.cpython-37m-x86_64-linux-gnu.so*
_codecs_cn.cpython-37m-x86_64-linux-gnu.so* libtinfo.so.5* _sha256.cpython-37m-x86_64-linux-gnu.so*
_codecs_hk.cpython-37m-x86_64-linux-gnu.so* libz.so.1* _sha3.cpython-37m-x86_64-linux-gnu.so*
_codecs_iso2022.cpython-37m-x86_64-linux-gnu.so* _lzma.cpython-37m-x86_64-linux-gnu.so* _sha512.cpython-37m-x86_64-linux-gnu.so*
_codecs_jp.cpython-37m-x86_64-linux-gnu.so* math.cpython-37m-x86_64-linux-gnu.so* _socket.cpython-37m-x86_64-linux-gnu.so*
_codecs_kr.cpython-37m-x86_64-linux-gnu.so* _md5.cpython-37m-x86_64-linux-gnu.so* _ssl.cpython-37m-x86_64-linux-gnu.so*
_codecs_tw.cpython-37m-x86_64-linux-gnu.so* _multibytecodec.cpython-37m-x86_64-linux-gnu.so* _struct.cpython-37m-x86_64-linux-gnu.so*
_datetime.cpython-37m-x86_64-linux-gnu.so* _opcode.cpython-37m-x86_64-linux-gnu.so* termios.cpython-37m-x86_64-linux-gnu.so*
grp.cpython-37m-x86_64-linux-gnu.so* _pickle.cpython-37m-x86_64-linux-gnu.so* unicodedata.cpython-37m-x86_64-linux-gnu.so*
_hashlib.cpython-37m-x86_64-linux-gnu.so* _posixsubprocess.cpython-37m-x86_64-linux-gnu.so* zlib.cpython-37m-x86_64-linux-gnu.so*
_heapq.cpython-37m-x86_64-linux-gnu.so* pyexpat.cpython-37m-x86_64-linux-gnu.so*

I cannot understand well the import doc: https://docs.python.org/3/reference/impo...portsystem
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
As mentioned previously, Python comes with several default meta path finders. One of these, called the path based finder (PathFinder), searches an import path, which contains a list of path entries. Each path entry names a location to search for modules.

The path based finder itself doesn’t know how to import anything. Instead, it traverses the individual path entries, associating each of them with a path entry finder that knows how to handle that particular kind of path.

The default set of path entry finders implement all the semantics for finding modules on the file system, handling special file types such as Python source code (.py files), Python byte code (.pyc files) and shared libraries (e.g. .so files). When supported by the zipimport module in the standard library, the default path entry finders also handle loading all of these file types (other than shared libraries) from zipfiles.

thanks for helping,
Pierre
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 273 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  How can I pause only one object? actualpy 1 324 Feb-01-2024, 07:43 PM
Last Post: deanhystad
  This result object does not return rows. It has been closed automatically dawid294 5 686 Jan-10-2024, 10:55 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 456 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Question Chain object that have parent child relation.. SpongeB0B 10 970 Dec-12-2023, 01:01 PM
Last Post: Gribouillis
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 679 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  Python Code for Preorder Traversal of a Binary Tree Bolt 1 555 Sep-22-2023, 09:32 AM
Last Post: Gribouillis
  TypeError: 'NoneType' object is not callable akbarza 4 922 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,262 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,533 Aug-04-2023, 12:41 PM
Last Post: Konstantin23

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020