Submitted by 月黑风高 on 2009年02月24日 19:24:32
一个起步教程
可能教程的版本比较旧
Python代码
- from django.utils.httpwrappers import HttpResponse
-
- def index(request):
- return HttpResponse("Job Index View")
1。httpresponse已经挪到django.http下面了,放在__init__.py这个感觉没什么用的文件里,找了好一会儿
框架的文件全放在site-packages里面,没想到和zf差不多,传入request对象,输出response对象
2。egg是什么格式
3。昨天清理笔记本,有二颗螺丝滑丝了,死按拧上了一个,用了快二年。宽裕的时候换一个。
python | 评论:1
| Trackbacks:0
| 阅读:2372
Submitted by 月黑风高 on 2009年02月23日 18:06:25
今天把django,NND,这个单词我还不会拼,给装了,没用nginx,担心把我的php环境给搞坏了,用他自带的那个web server,
http://yuehei.37net.com:8080/
1。现在一头雾水,以前用php就是开启fastcgi监听,web server转发处理响应,然后把框架布署在目录里,django把这些东西都放在一起,我茫然了,迷茫了,找不前进的方向了,恶。。
2。试了一下php gtk,这种鸡肋的东西,除了证明一下PHP能写桌面也没别的用了。
3。wxpython GUI组件 http://www.ibm.com/developerworks/cn/linux/sdk/python/wxpy/
4。PHPRPC 比 soap之类的东西简单多了,好用多了。。就是页面太艺术。。
mod:将解释器加载为web server 的一部分
cgi:每次接受请求解释器都会初始化,比较消耗资源
fastcgi:会生成解释进程,常驻内存,速度比较理想
cli:php安静模式,一般在命令行下用
饿了,撤
python | 评论:0
| Trackbacks:0
| 阅读:1554
Submitted by 月黑风高 on 2009年02月16日 23:38:33
类和异常与文件处理,没什么特别的。。很想睡觉,困
py类中的变量就相当静态变量
Python代码
- from UserDict import UserDict
- class dict(UserDict):
- data = {}
- num = 0
- def __init__(self, data={}):
- if (data is None):
- data = {}
- else:
- self.data.update(data)
- self.num+=1
- def addNum(self, num):
- self.__class__.num+=num
- def items(self):
- return self.data.items()
- def keys(self):
- return self.data.keys()
- def values(self):
- return self.data.values()
- def getClass(self):
- return self.__class__
- def __setitem__(self, key, values):
- key = "s_"+str(key)
- self.key = values
- def __getitem__(self, key):
- key = "s_"+str(key)
- return self.data[key]
- d = dict({"aa":"bnb"})
- d.addNum(4)
- print d.num
- e = dict()
- print e.num
- print dict.num
- print e.data
-
-
-
-
-
-
-
-
-
Python代码
- try:
- fh = open('D:/music/KuGou/寒衣调.mp3', 'rb')
- except Exception:
- print 'error'
- else:
- print 'ok'
-
-
-
-
- fh.seek(-1024, 2)
-
- data = fh.read(1024);
-
-
- fh.close()
-
-
- try:
- fh = open('D:/project/a.txt', 'wb')
- fh.write("aaaaaa")
- fh.close();
-
- except IOError:
- pass
- print file('D:/project/a.txt').read()
-
-
-
- import os
- print os.path.expanduser('~')
Tags: python
python | 评论:0
| Trackbacks:0
| 阅读:1213
Submitted by 月黑风高 on 2009年02月13日 23:58:25
看完了,对数组的映射和过滤有了比较清楚的了解,这么快就看到了最爱用的三元运算,这章的例子非常有用,我默了出来
Python代码
- def setRunEnv():
- import sys
- sys.path.append('D:\project\mypy')
- setRunEnv()
- def info(object, spacing = 10, collapse = 1):
- methodList = dir(object)
- methodList = [method for method in methodList if callable(getattr(object, method))]
- processFunction = collapse and (lambda s:" ".join(s.split())) or (lambda s:s)
- return "\n".join(["%s%s" % (method.ljust(spacing),
- processFunction(str(getattr(getattr(object, method), "__doc__"))))
- for method in methodList])
- li = []
-
- print 1 and 'ok' or 'no'
- print 1 and '' or 'no'
- print 1 and [''] or 'no'
用and和or进行判断,我用这种偷懒的方法写PHP还是比较单一,一般就是一个and或or,这里直接把这个当三元来用。太帅了。。逻辑表达式PHP虽然返回的true或false,但是PHP可以直接赋值,所以也可以用这种方式。
PHP代码
- <?php
- $a = 1;
- $b = '';
- $a == 1 && ($b = 'ok') || ($b = 'no');
- echo $b;
- ?>
很有意思,py逻辑表达式可以返回最后的值,但里面不能进行赋值操作,一赋值,报syntax error
Python代码
- a==1 and b='ok' or b='no'
PHP虽然返回只是表达式最后运算的结果,但可以进行赋值操作,所以他们都可以用这种写法。
第二个表达式一定不能为 false,否则完蛋。。
Tags: python
python | 评论:0
| Trackbacks:0
| 阅读:1091
Submitted by 月黑风高 on 2009年02月13日 17:30:28
刚看完前三节
Python代码
- def setRunEnv():
- import sys
- sys.path.append('E:\mypy')
- setRunEnv()
- import calc
- import string_operation
-
- print calc.add(110, 33)
- print calc.sub(110, 22)
- print calc.mul(44, 55)
- print calc.div(6, 3)
-
- list = {"name":"yuehei", "email":"none", "sex":"man"}
- params = list.keys()
- print params
- params = list.values()
- str = string_operation.arrToStr("###", params)
- print str
- print "--------"
- print string_operation.strToArr("###", str)
感觉很像JS,有一个问题,怎么能让他不生成pyc文件,每次删不方便
和PHP相比,她是强类型语言,做一个1/3,不会得0.33333
关于后缀名 http://bbs.chinaunix.net/thread-852032-1-1.html
update:2009/02/14 不用删除,如果用help老是看到没有变化,是因为新改的编译没有通过,过了就会重新生pyc
Tags: python
python | 评论:0
| Trackbacks:0
| 阅读:1609