Skip to content

Commit ff21335

Browse files
committed
This is a repository for python.
0 parents  commit ff21335

19 files changed

+347
-0
lines changed

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>PythonKnowledge</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.python.pydev.PyDevBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.python.pydev.pythonNature</nature>
16+
</natures>
17+
</projectDescription>

.pydevproject

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?eclipse-pydev version="1.0"?>
3+
4+
<pydev_project>
5+
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
6+
<path>/PythonKnowledge</path>
7+
</pydev_pathproperty>
8+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
9+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
10+
</pydev_project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
eclipse.preferences.version=1
2+
encoding//src/python/TestStr.py=utf-8
3+
encoding//src/python/demo/Encode.py=utf-8
4+
encoding//src/python/demo/ListComposite.py=utf-8
5+
encoding//src/python/demo/TestCPickle.py=utf-8
6+
encoding//src/python/demo/TestClass.py=utf-8
7+
encoding//src/python/demo/TestControl.py=utf-8
8+
encoding//src/python/demo/TestDataStruct.py=utf-8
9+
encoding//src/python/demo/TestExtends.py=utf-8
10+
encoding//src/python/demo/TestLambda.py=utf-8
11+
encoding//src/python/demo/TestModule.py=utf-8
12+
encoding//src/python/demo/TestTryCatchFinal.py=utf-8
13+
encoding/<project>=UTF-8

src/__init__.py

Whitespace-only changes.

src/python/TestStr.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding:utf-8 -*-
2+
#
3+
# Author : sushiting
4+
# E-mail : sushiting@163.com
5+
# Date : 2013-7-5
6+
# Desc : str 方法
7+
#
8+
string = "sushiting"
9+
strArrays = ["s","h","i","t","i","n","g"]
10+
print string.capitalize()
11+
print string.join("-")
12+
print "-".join(strArrays)
13+
print string.split()

src/python/__init__.py

Whitespace-only changes.

src/python/demo/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Encode.pyc

src/python/demo/Encode.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
# 用于解决gvim控制台输出乱码
3+
import sys
4+
reload(sys)
5+
class UnicodeStreamFilter:
6+
def __init__(self, target):
7+
self.target = target
8+
self.encoding = 'utf-8'
9+
self.errors = 'replace'
10+
self.encode_to = 'cp936'
11+
def write(self, s):
12+
if type(s) == str:
13+
s = s.decode("utf-8")
14+
s = s.encode(self.encode_to, self.errors).decode(self.encode_to)
15+
self.target.write(s)
16+
sys.setdefaultencoding('cp936') # @UndefinedVariable
17+
sys.stdout = UnicodeStreamFilter(sys.stdout)
18+
if __name__ == "__main__":
19+
print '苏'
20+
21+

src/python/demo/ListComposite.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding:utf-8 -*-
2+
#
3+
# Author : sushiting
4+
# E-mail : sushiting@163.com
5+
# Date : 2013-7-9
6+
# Desc : 列表综合
7+
#
8+
intArr = [1,2,3,4,5]
9+
newIntArr = [3*i for i in intArr if i%2==0]
10+
print newIntArr
11+
12+
#在函数中接收元组和列表
13+
#当要使函数接收元组或字典形式的参数的时候,有一种特殊的方法,它分别使用*和**前缀。
14+
#这种方法在函数需要获取可变数量的参数的时候特别有用。
15+
def powsersum(power,*args):
16+
total = 0
17+
for i in args:
18+
total += pow(power, i)
19+
return total
20+
print powsersum(2,1,3,4),powsersum(1,1,2,3,4,5)
21+
def printmaps(args):
22+
print args
23+
for i in args:
24+
print args[i]
25+
printmaps({"name":"sushiting"})
26+
27+
#以下较为特殊 **
28+
def testdict(**args):
29+
print args
30+
testdict(a=3,b=3)

src/python/demo/TestCPickle.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding:utf-8 -*-
2+
#
3+
# Author : sushiting
4+
# E-mail : sushiting@163.com
5+
# Date : 2013-7-8
6+
# Desc : 类似于java的序列化,反序列化
7+
#
8+
# Python提供一个标准的模块,称为pickle。使用它你可以在一个文件中储存任何Python对象,
9+
# 之后你又可以把它完整无缺地取出来。这被称为 持久地 储存对象。
10+
# 还有另一个模块称为cPickle,它的功能和pickle模块完全相同,只不过它是用C语言编写的,因此要快得多(比pickle快1000倍)。你可以使用它们中的任一个,而我们在这里将使用cPickle模块。记住,我们把这两个模块都简称为pickle模块。
11+
import cPickle as p
12+
shoplist = ['apple','orange','banana']
13+
shopdata = file("shop.data","w")
14+
p.dump(shoplist, shopdata)
15+
shopdata.close()
16+
shopdata = file("shop.data")
17+
shoplist2 = p.load(shopdata)
18+
print shoplist2
19+

0 commit comments

Comments
 (0)