Skip to main content

Add methods and properties to an existing object

Project description

Add methods and properties to an existing object

$pip install add-methods-and-properties-to-existing-object

from add_methods_and_properties_to_existing_object import AddMethodsAndProperties



class NewClass(AddMethodsAndProperties): #inherit from AddMethodsAndProperties to add the method add_methods

    def __init__(self):

        self.bubu = 5



    def _delete_files(self, file): #some random methods 

        print(f"File will be deleted: {file}")



    def delete_files(self, file):

        self._delete_files(file)



    def _copy_files(self, file, dst):

        print(f"File will be copied: {file} Dest: {dst}")



    def copy_files(self, file, dst):

        self._copy_files(file, dst)



    def _create_files(self, file, folder):

        print(f"File will be created: {file} {folder}")



    def create_files(self, file, folder):

        self._create_files(file, folder)



    def method_with_more_kwargs(self, file, folder, one_more):

        print(file, folder, one_more)

        return self





nc = NewClass()

dict_all_files = {

    r"C:\Windows\notepad.exe_delete": {

        "function": "delete_files",

        "args": (),

        "kwargs": {"file": r"C:\Windows\notepad.exe"},

        "this_args_first": True,

    },

    r"C:\Windows\notepad.exe_argsfirst": {

        "function": "delete_files",

        "args": (),

        "kwargs": {"file": r"C:\Windows\notepad.exe"},

        "this_args_first": True,

    },

    r"C:\Windows\notepad.exe_copy": {

        "function": "copy_files",

        "args": (),

        "kwargs": {

            "file": r"C:\Windows\notepad.exe",

            "dst": r"C:\Windows\notepad555.exe",

        },

        "this_args_first": True,

    },

    r"C:\Windows\notepad.exe_create": {

        "function": "create_files",

        "args": (),

        "kwargs": {"file": r"C:\Windows\notepad.exe", "folder": "c:\\windows95"},

        "this_args_first": True,

    },

    r"C:\Windows\notepad.exe_upper": {

        "function": str.upper,

        "args": (r"C:\Windows\notepad.exe",),

        "kwargs": {},

        "this_args_first": True,

    },

    r"C:\Windows\notepad.exe_method_with_more_kwargs": {

        "function": "method_with_more_kwargs",

        "args": (),

        "kwargs": {"file": r"C:\Windows\notepad.exe", "folder": "c:\\windows95"},

        "this_args_first": True,

    },

    r"C:\Windows\notepad.exe_method_with_more_kwargs_as_args_first": {

        "function": "method_with_more_kwargs",

        "args": (r"C:\Windows\notepad.exe", "c:\\windows95"),

        "kwargs": {},

        "this_args_first": True,

    },

    r"C:\Windows\notepad.exe_method_with_more_kwargs_as_args_last": {

        "function": "method_with_more_kwargs",

        "args": (r"C:\Windows\notepad.exe", "c:\\windows95"),

        "kwargs": {},

        "this_args_first": False,

    },

    "this_is_a_list": [55, 3, 3, 1, 4, 43],

}



nc.add_methods(dict_all_files)





print(nc.C_Windows_notepad_exe_delete)

print(nc.C_Windows_notepad_exe_delete(), end="\n\n")

print(nc.C_Windows_notepad_exe_argsfirst)

print(nc.C_Windows_notepad_exe_argsfirst(), end="\n\n")

print(nc.C_Windows_notepad_exe_copy)

print(nc.C_Windows_notepad_exe_copy(), end="\n\n")

print(nc.C_Windows_notepad_exe_create)

print(nc.C_Windows_notepad_exe_create(), end="\n\n")

print(nc.C_Windows_notepad_exe_upper)

print(nc.C_Windows_notepad_exe_upper(), end="\n\n")

print(nc.C_Windows_notepad_exe_method_with_more_kwargs)

print(

    nc.C_Windows_notepad_exe_method_with_more_kwargs(

        one_more="f:\\blaaaaaaaaaaaaaaaaaaaaaaaa"

    )

    .C_Windows_notepad_exe_method_with_more_kwargs(

        one_more="f:\\ASJVASDFASÇDFJASÇDJFÇASWFJASÇ"

    )

    .C_Windows_notepad_exe_method_with_more_kwargs(

        one_more="f:\\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

    ),

    end="\n\n",

)

print(nc.C_Windows_notepad_exe_method_with_more_kwargs_as_args_first)

print(

    nc.C_Windows_notepad_exe_method_with_more_kwargs_as_args_first(

        "f:\\blaaaaaaaaaaaaaaaaaaaaaaaa"

    ),

    end="\n\n",

)

print(

    nc.C_Windows_notepad_exe_method_with_more_kwargs_as_args_first(

        "f:\\blaaaaaaaaaaaaaaaaaaaaaaaa"

    )

    .C_Windows_notepad_exe_method_with_more_kwargs_as_args_first(

        "f:\\ASJVASDFASÇDFJASÇDJFÇASWFJASÇ"

    )

    .C_Windows_notepad_exe_method_with_more_kwargs_as_args_first(

        "f:\\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

    ),

    end="\n\n",

)

print(nc.C_Windows_notepad_exe_method_with_more_kwargs_as_args_last)

print(

    nc.C_Windows_notepad_exe_method_with_more_kwargs_as_args_last(

        "f:\\blaaaaaaaaaaaaaaaaaaaaaaaa"

    )

    .C_Windows_notepad_exe_method_with_more_kwargs_as_args_last(

        "f:\\ASJVASDFASÇDFJASÇDJFÇASWFJASÇ"

    )

    .C_Windows_notepad_exe_method_with_more_kwargs_as_args_last(

        "f:\\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

    ),

    end="\n\n",

)

print(

    nc.C_Windows_notepad_exe_method_with_more_kwargs_as_args_last(

        "f:\\blaaaaaaaaaaaaaaaaaaaaaaaa"

    )

    .C_Windows_notepad_exe_method_with_more_kwargs_as_args_last(

        "f:\\ASJVASDFASÇDFJASÇDJFÇASWFJASÇ"

    )

    .C_Windows_notepad_exe_method_with_more_kwargs_as_args_last(

        "f:\\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

    ),

    end="\n\n",

)

print(nc.this_is_a_list)

checkit = (

    nc.C_Windows_notepad_exe_method_with_more_kwargs_as_args_last(

        "f:\\blaaaaaaaaaaaaaaaaaaaaaaaa"

    )

    .C_Windows_notepad_exe_method_with_more_kwargs_as_args_last(

        "f:\\ASJVASDFASÇDFJASÇDJFÇASWFJASÇ"

    )

    .C_Windows_notepad_exe_method_with_more_kwargs_as_args_last(

        "f:\\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

    )

)

print(f'nc is checkit? -> {nc is checkit}')





#output:





NewClass.delete_files(self, file='C:\\Windows\\notepad.exe')

File will be deleted: C:\Windows\notepad.exe

None





NewClass.delete_files(self, file='C:\\Windows\\notepad.exe')

File will be deleted: C:\Windows\notepad.exe

None





NewClass.copy_files(self, file='C:\\Windows\\notepad.exe', dst='C:\\Windows\\notepad555.exe')

File will be copied: C:\Windows\notepad.exe Dest: C:\Windows\notepad555.exe

None





NewClass.create_files(self, file='C:\\Windows\\notepad.exe', folder='c:\\windows95')

File will be created: C:\Windows\notepad.exe c:\windows95

None





NewClass.upper(self, 'C:\\Windows\\notepad.exe')

C:\WINDOWS\NOTEPAD.EXE





NewClass.method_with_more_kwargs(self, file='C:\\Windows\\notepad.exe', folder='c:\\windows95')

C:\Windows\notepad.exe c:\windows95 f:\blaaaaaaaaaaaaaaaaaaaaaaaa

C:\Windows\notepad.exe c:\windows95 f:\ASJVASDFASÇDFJASÇDJFÇASWFJASÇ

C:\Windows\notepad.exe c:\windows95 f:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

<__main__.NewClass object at 0x0000000005F199A0>





NewClass.method_with_more_kwargs(self, 'C:\\Windows\\notepad.exe', 'c:\\windows95')

C:\Windows\notepad.exe c:\windows95 f:\blaaaaaaaaaaaaaaaaaaaaaaaa

<__main__.NewClass object at 0x0000000005F199A0>





C:\Windows\notepad.exe c:\windows95 f:\blaaaaaaaaaaaaaaaaaaaaaaaa

C:\Windows\notepad.exe c:\windows95 f:\ASJVASDFASÇDFJASÇDJFÇASWFJASÇ

C:\Windows\notepad.exe c:\windows95 f:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

<__main__.NewClass object at 0x0000000005F199A0>





NewClass.method_with_more_kwargs(self, 'C:\\Windows\\notepad.exe', 'c:\\windows95')

f:\blaaaaaaaaaaaaaaaaaaaaaaaa C:\Windows\notepad.exe c:\windows95

f:\ASJVASDFASÇDFJASÇDJFÇASWFJASÇ C:\Windows\notepad.exe c:\windows95

f:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX C:\Windows\notepad.exe c:\windows95

<__main__.NewClass object at 0x0000000005F199A0>





f:\blaaaaaaaaaaaaaaaaaaaaaaaa C:\Windows\notepad.exe c:\windows95

f:\ASJVASDFASÇDFJASÇDJFÇASWFJASÇ C:\Windows\notepad.exe c:\windows95

f:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX C:\Windows\notepad.exe c:\windows95

<__main__.NewClass object at 0x0000000005F199A0>





[55, 3, 3, 1, 4, 43]





f:\blaaaaaaaaaaaaaaaaaaaaaaaa C:\Windows\notepad.exe c:\windows95

f:\ASJVASDFASÇDFJASÇDJFÇASWFJASÇ C:\Windows\notepad.exe c:\windows95

f:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX C:\Windows\notepad.exe c:\windows95





nc is checkit? -> True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

File details

Details for the file add_methods_and_properties_to_existing_object-0.10.tar.gz.

File metadata

File hashes

Hashes for add_methods_and_properties_to_existing_object-0.10.tar.gz
Algorithm Hash digest
SHA256 f6c15558e5e34ca59ed3aec2ae2b536d0fcc4c609fd0df00dc7c72bc881b0266
MD5 54e627f57f4e35f59fb14914653dbeb1
BLAKE2b-256 7d494d7e9da9c0d3aa128812316cde1d8535339c19dd91f059f20119f6fb60f8

See more details on using hashes here.

File details

Details for the file add_methods_and_properties_to_existing_object-0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for add_methods_and_properties_to_existing_object-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 72d68eab57f0da530c51be7d25c874f25f4495adeeffc836411f92c6bb283d2c
MD5 26cd8f0e73b00582d577ecd2eef07afe
BLAKE2b-256 3f54d95442491fe215fcbd13b5d90d8524ec21f505c551bc237a575cf84fc233

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page