-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·93 lines (73 loc) · 2.04 KB
/
test.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python
#coding=utf-8
import sys
import string
import glob
import os
# def GetFileList(dir, fileList):
# if os.path.isfile(dir):
# fileList.append(dir)
# elif os.path.isdir(dir):
# for s in os.listdir(dir):
# newDir = os.path.join(dir, s)
# GetFileList(newDir, fileList)
# return fileList
def GetFileList(dir, fileList):
if os.path.isfile(dir):
fileList.append(dir)
elif os.path.isdir(dir):
for x in os.listdir(dir):
newDir = os.path.join(dir,x)
GetFileList(newDir, fileList)
return fileList
def fab(n):
if n<2:
return 1
else:
return fab(n-1)+fab(n-2)
class Singlet(object):
# _instance=None
_first_init=False
# 类一创建就初始化(个人理解:类似java中的构造方法),必须有返回值
def __new__(cls,age,name):
# if not cls._instance:
if not hasattr(cls, "instance"):
cls.instance=object.__new__(cls)
return cls.instance
# 初始化数据
def __init__(self,age,name):
if not self._first_init:
# if not hasattr(self, "first_init"):
self.age=age
self.name=name
Singlet._first_init=True
if __name__ == "__main__":
print 'hello'
print '你好'
a=Singlet(26,"xiaokeke")
b=Singlet(22,"liulili")
print(id(a))
print(id(b))
print(a.name)
print(b.name)
# for file in GetFileList('/home/liyang/mm',[]):
# print file
# print fab(5)
# print "this is %s %s" % ("my",'apple')
# print "this is %(whose)s %(fruit)s" % {'whose': 'my', 'fruit': 'apple'}
# print "this is {0} {1}".format("my",'apple')
# print "this is {whose} {fruit}".format(whose="my",fruit='apple')
# f = open('string_help.txt','w')
# sys.stdout = f
# help(string)
# f.close()
# temp = glob.glob('/home/liyang/mm/*.*')
# print temp
# print os.listdir('/home/liyang/mm')
# print '----------------------------------------'
# path = '/home/liyang/mm'
# print os.path.isdir(path)
# print os.path.exists(path)
# print os.path.isfile(path)
# with open('/home/liyang/mm/string_help.txt','r') as f:
# print f.read()