from abc import ABCMeta, abstractmethod
print __name__
class IServer:
def __init__(self):
pass
@abstractmethod
def DoWithA(self):
pass
@abstractmethod
def DoWithB(self):
pass
import IServer
serverType ='1001'
print __name__
dir()
from CreatFactory import GLOBAL_class_dic
dir()
class IServer_A(IServer.IServer):
def __init__(self):
pass
def DoWithA(self):
print 'Server_A do with interface A'
def DoWithB(self):
print 'Server_A do with interface B'
global GLOBAL_class_dic
print 'the id of GLOBAL_class_dic in A is:',id(GLOBAL_class_dic)
GLOBAL_class_dic[serverType] = IServer_A
print 'GLOBAL_class_dic in a is:', GLOBAL_class_dic
import IServer
serverType ='1002'from CreatFactory import GLOBAL_class_dic
print __name__
class IServer_B(IServer.IServer):
def __init__(self):
pass
def DoWithA(self):
print 'Server_B do with interface A'
def DoWithB(self):
print 'Server_B do with interface B'
print 'the id of GLOBAL_class_dic in B is:',id(GLOBAL_class_dic)
GLOBAL_class_dic[serverType] = IServer_B
print 'GLOBAL_class_dic in b is:', GLOBAL_class_dic
#coding:UTF-8
import os;
import sys;
import threading
from misc import *
global GLOBAL_class_dic
GLOBAL_class_dic ={1:1}
print 'GLOBAL_class_dic in define is:', GLOBAL_class_dic
print 'the id of GLOBAL_class_dic in define is:', id(GLOBAL_class_dic)
dir()
import IServer_A
import IServer_B
def CreateServer(serverType):
global GLOBAL_class_dic
print 'GLOBAL_class_dic in use is:', GLOBAL_class_dic
print 'the id of GLOBAL_class_dic in USE is:', id(GLOBAL_class_dic)
if GLOBAL_class_dic.has_key(serverType):
return GLOBAL_class_dic[serverType]
else:
return 'no'
if __name__ == '__main__':
pass
# 接收到报文后,根据报文的内容,从db中获取到serverType,假设获取到的serverType=1001
print 'main'
print 'GLOBAL_class_dic in main A is:', GLOBAL_class_dic
serverType = '1002'
server = CreateServer(serverType)
print 'GLOBAL_class_dic in main B is:', GLOBAL_class_dic
print 'server :',server
server.DoWithA(server())
D:\Python27\python.exe "D:/DesignMode/Server --00/CreatFactory.py"
GLOBAL_class_dic in define is: {1: 1}
the id of GLOBAL_class_dic in define is: 36230176
['GLOBAL_class_dic', 'Misc', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'binascii', 'inspect', 'minidom', 'os', 'struct', 'sys', 'threading']
IServer
IServer_A
['IServer', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'serverType']
GLOBAL_class_dic in define is: {1: 1}
the id of GLOBAL_class_dic in define is: 36230032
['GLOBAL_class_dic', 'Misc', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'binascii', 'inspect', 'minidom', 'os', 'struct', 'sys', 'threading']
['IServer', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'serverType']
['GLOBAL_class_dic', 'IServer', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'serverType']
IServer_B
the id of GLOBAL_class_dic in B is: 36230032
GLOBAL_class_dic in b is: {1: 1, '1002': <class IServer_B.IServer_B at 0x022C2ED8>}
['GLOBAL_class_dic', 'IServer', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'serverType']
the id of GLOBAL_class_dic in A is: 36230032
GLOBAL_class_dic in a is: {1: 1, '1002': <class IServer_B.IServer_B at 0x022C2ED8>, '1001': <class IServer_A.IServer_A at 0x02273420>}
main
GLOBAL_class_dic in main A is: {1: 1}
GLOBAL_class_dic in use is: {1: 1}
the id of GLOBAL_class_dic in USE is: 36230176
GLOBAL_class_dic in main B is: {1: 1}
server : no
Traceback (most recent call last):
File "D:/DesignMode/Server --00/CreatFactory.py", line 38, in <module>
server.DoWithA(server())
AttributeError: 'str' object has no attribute 'DoWithA'
Process finished with exit code 1
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有