我需要将字符串转换为名为引用的代码。目前唯一已知的选项是制作脚本的脚本,我认为它可以像 exec
一样内联。
class finder:
def __init__(self, parent):
self.parent = parent
def isin(self, what):
return what in self.parent
def find(self, what):
if self.isin(what): return self.parent.__dict__[what.__name__]
else: return __import__("pull").__dict__["downloader"](self.parent.hosts).download(what)
def put(self, what):
f = self.find(what)
self.parent.__dict__[f.__name__] = f
from sock import Socket
from unpack import unpacker
...
class downloader:
def __init__(self, hosts):
self.hosts = hosts
def download(name):
for host in hosts:
pack = unpacker()
s = Socket(host[0], host[1])
s.send("get " + name)
f = pack.unpack(s)
if f is not None: return f
我是一名优秀的程序员,十分优秀!