-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpydev.py
More file actions
executable file
·44 lines (34 loc) · 862 Bytes
/
pydev.py
File metadata and controls
executable file
·44 lines (34 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
__author__ = 'zhenghaitao'
#coding=utf8
#! /usr/bin/env python
import httplib
import re
import socket
import urllib
a = [1,2,3]
b = {'a':1,'b':2,'c':3}
c = True
print type(a),type(b),type(c) # <type 'list'> <type 'dict'> <type 'bool'>
print isinstance(a,list) # True
class Singleton(object):
def __new__(cls, *args, **kw):
if not hasattr(cls, '_instance'):
orig = super(Singleton, cls)
cls._instance = orig.__new__(cls, *args, **kw)
return cls._instance
class MyClass(Singleton):
a = 1
myclass = MyClass()
myclass.a = 2
testlcass2 = MyClass()
print testlcass2.a
def singleton(cls, *args, **kw):
instances = {}
def getinstance():
if cls not in instances:
instances[cls] = cls(*args, **kw)
return instances[cls]
return getinstance
@singleton
class MyClass:
pass