SOに関するいくつかの質問が見つかりましたが、まだ答えがありません...データクラスがあります
class Proxy(object):
def __init__(self, ip, port):
self.ip = ip
self.port = port
これらのデータをさまざまなソースから読み取ることになっている getter クラスがあります。
class FileProxyGetter(ProxyGetter):
def __init__(self, fname = "d:\\proxies.txt"):
self.fileName = fname
def Get(self):
proxies = []
f = open(self.fileName)
for l in f.xreadlines():
proxies.append(Proxy.fromstring(l[:-1]))
f.close()
return proxies
def Update(self):
return []
次のようなより多くのオプションを備えたプロキシクラスが必要です
class SecureProxy(Proxy):
def __init__(self, ip, port):
super(SecureProxy, self).__init__(ip, port)
self.transparent = None
FileProxyGetter を次のように改善したいと思います。
class FileSecureProxyGetter(FileProxyGetter):
def Get(self):
proxies = super(FileProxyGetter, self).Get()
secureProxies = []
for proxy in proxies:
# Create or Cast Proxy to SecureProxy.
# The transparent should be initialized to None or any other value that I may need
secureProxies.append(SecureProxy(proxy))
return secureProxies
では、Pythonの基本クラスから派生クラスのインスタンスを普遍的にキャストまたは作成するにはどうすればよいですか。クラスに変更が必要ない方が良いでしょう。
または、そのような関係とアーキテクチャを開発するためのよりpythonicな方法を提案できますか?