虽然我从来没有需要这个,但让我感到震惊的是在Python中创建一个不可变对象可能会有点棘手.你不能只是覆盖__setattr__,因为那时你甚至不能设置属性__init__.对元组进行子类化是一种有效的技巧:
class Immutable(tuple):
def __new__(cls, a, b):
return tuple.__new__(cls, (a, b))
@property
def a(self):
return self[0]
@property
def b(self):
return self[1]
def __str__(self):
return "<Immutable {0}, {1}>".format(self.a, self.b)
def __setattr__(self, *ignored):
raise NotImplementedError
def __delattr__(self, *ignored):
raise NotImplementedError
Run Code Online (Sandbox Code Playgroud)
但是你可以通过和访问a和b变量,这很烦人.self[0]self[1]
这在纯Python中是否可行?如果没有,我将如何使用C扩展?
(只能在Python 3中使用的答案是可以接受的).
更新:
因此,子类的元组是做纯Python,效果很好,除了通过访问数据的另一种可能性的方式[0],[1]等等.所以,要完成这个问题,所有这一切都缺少的是HOWTO在C,做"正确的",这我怀疑是非常简单,只是没有实现任何geititem或setattribute等等.但我不是自己做,我为此提供赏金,因为我很懒.:)
有没有办法允许MySQL从多个目录加载数据而无需设置secure-file-priv=''?
例如,类似:
secure-file-priv="path/to/dir1","path/to/dir2"
Run Code Online (Sandbox Code Playgroud)
通过阅读文档,尚不清楚是否允许多个目录,以及是否允许多个目录。