我发现了同样的问题.但PyCrypto并没有在python 3.6.5和3.7.0上安装.
所以,我实现了某种类似Gronsfeld的密码.我知道,这很糟糕,但我可以简单地用密码加密和解密字符串
def encrypt(string, password):
int_list = []
password_len = len(password)
for cnt, sym in enumerate(string):
password_sym = password[cnt % password_len]
int_list.append(ord(sym)-ord(password_sym))
return int_list
# got some list which contain mine key to Todoist api, yes, this can be bruteforced, but same as any other API key
>>> [-20, -20, -50, -14, -61, -54, 2, 0, 32, 27, -51, -21, -54, -53, 4, 3, 29, -14, -51, 29, -10, -6, 1, 4, 28,
29, -55, -17, -59, -42, …Run Code Online (Sandbox Code Playgroud) 所以,我创建了一些课程
class Some:
@classmethod
def __init__(cls, somevar):
cls.somevar = somevar
@classmethod
def read(cls):
return cls.somevar
Run Code Online (Sandbox Code Playgroud)
现在我尝试在外部设置变量并从类中读取它:
instance = Some([1, 2, 3])
instance.somevar = [4, 5, 6]
print(instance.read())
>>>> [1, 2, 3]
Run Code Online (Sandbox Code Playgroud)
但是在类外调用相同的命名变量会给我预期的输出,
print(instance.somevar)
>>>> [4, 5, 6]
Run Code Online (Sandbox Code Playgroud)
我对OOP的误解是什么?
编辑
我的目标是创建Some具有自己值的多个实例.