A pointer to python
Project description
Pointer
一个在python中的指针类
本模块有一个Pointer的指针基类,当他被与其他类继承时将创造一个指针类
例:
from Pointer import Pointer
class A:
def __init__(self, a):
self.a = a
class B(Pointer, A):
pass
这时,B类就是A类的指针类,同时,除了赋值操作外,其他功能和使用A类没有任何区别
而赋值操作需要对类的变量__value__进行赋值
即:
b = B()
b.__value__ = A()
想获取被指向的对象也要通过__value__获取
即:
a = b.__value__
但是如果直接输出是可以调用被指向的类的__str__方法的
即:
class String(Pointer, str):
pass
a = String('b')
print(a) # 输出: b
包括其他调用魔法方法的情况。
同时,普通方法也是可以直接调用的
即:
a = String('a b')
print(a.split(' ')) # 输出: ['a', 'b']
本模块自带了str, int, bool的指针类
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
PyPointer-1.0.0.tar.gz
(3.6 kB
view details)
File details
Details for the file PyPointer-1.0.0.tar.gz.
File metadata
- Download URL: PyPointer-1.0.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8401bfb625449ce1fff5c8d353e13913701d3aeb9fa40c461350a9be656d1491
|
|
| MD5 |
d5d34cd4909a5ac4b0e3d68db80f8de2
|
|
| BLAKE2b-256 |
b94e9fb4672255db9234a30157caf5f473334135d0b19671438f921bb110a804
|