python 通过地址操作函数和对象

test_base.py

import uuid

class Test_obj:
    def __init__(self):
        self.list_value = []
        self.inti_list_value()

    def inti_list_value(self):
        for i in range(5):
            self.list_value.append(f"对象初始化list_value {i}")

    def get_mac_address(self):
        """
        获取mac地址
        """
        mac = uuid.UUID(int = uuid.getnode()).hex[-12:] 
        mac = ":".join([mac[e:e+2] for e in range(0,11,2)])
        return mac

if __name__ == '__main__':
    pass

test_01.py

import sys
from test_base import Test_obj

def add_funtion():
    funtion_name = sys._getframe().f_code.co_name
    print("funtion_name:", funtion_name)
    return "add_funtion"


def get_obj_address():
    temp = {}
    temp["funtion_address"] = add_funtion
    temp["obj_address"] = Test_obj()
    return temp

test_02.py

from test_01 import get_obj_address

struct =  get_obj_address()

if __name__ == "__main__":
    print("结构体地址:",struct)


    # 通过函数地址调用函数
    funtion_result = struct["funtion_address"]()
    print(f"通过函数地址调用函数结果 : {funtion_result}")
    # 获取对象地址
    obj_address = struct["obj_address"]

    list_value = obj_address.list_value
    print(f"通过对象地址获取属性值 : {list_value}")

    obj_address.get_mac_address()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值