- 浏览: 579821 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (253)
- java (84)
- python (22)
- 设计模式 (12)
- 数据结构和算法 (7)
- ibatis (1)
- 数据挖掘 (2)
- 集体智慧读书笔记 (1)
- ubuntu (4)
- lucene (11)
- 算法 第4版 (11)
- apache mina (16)
- memcached (1)
- android (9)
- netty (6)
- mongodb (2)
- maven (2)
- openfire (2)
- 服务端 (21)
- 产品 (0)
- apache (1)
- 选择 (2)
- 构架WEB高性能站点 (7)
- redis (8)
- 诗词歌赋 (3)
- 源代码阅读 (5)
- 前端 (1)
- javascript (3)
- guice (1)
- 分布式 (5)
- 总结-2014 (4)
- jvm (1)
最新评论
-
liu_jiaqiang:
写的挺好
maven多项目管理 -
H972900846:
我想知道哪里整的,如果是自己写的,那有点牛呀如果是抄的请说明出 ...
SSL身份认证原理 -
春天好:
博主写的很好,赞一个,多谢分享 *(^-^*)分享一个免费好用 ...
定向网站爬虫---初级例子 -
fenglingabc:
经过测试,parameterType="java.u ...
mybatis获取主键和存储过程返回值 -
jyghqpkl:
[u][/u] ...
Cookie的secure 属性
1:一上午看Dive Into Python,在线到第7章,有些细节我过滤了
总结下python和java的区别:
没有数据类型的定义
内置的dict,list,等和hashmap,arrylist等有些类似
python中import和java中import意思相同
python的语法很不同
可以寻列赋值
严格的缩进 表示一个语句块
def 定义一个函数 当然还有lamab方法
if--elif--elif- :中判断没有()用:
万物皆对象,模块什么的
for循环的不同
写python就像写英语一样
面向对象,class 同样的,(fater)fater就是父类
写在类中属性是类所共有的,就是java中static的意思
类中有_init_相当与构造函数,在类初始化的时候执行
self相当于java中this的
实例化对象p=Person()不需要java中的new
处理异常的
..................................
python有很多模块
1:学习 urllib模块 -------------------相当于java中的jsoup,解析html文件的
推荐的书籍:深入 Python :Dive Into Python
个人觉得比简明教程好看点,跟着作者来 基本上没问题
http://sebug.net/paper/books/dive-into-python/html/index.html
一篇关于urllib模块的blog
http://www.blogjava.net/ashutc/archive/2011/03/21/346695.html
实例:
>>> def fib(n): print 'n=',n if n>1: return n*fib(n-1) else: print 'end of the line' return 1 >>> d = {"server":"hello","database":"mysql"} >>> d {'database': 'mysql', 'server': 'hello'} >>> fib(5) n= 5 n= 4 n= 3 n= 2 n= 1 end of the line 120 >>> d["server"] 'hello' >>> d["database"] 'mysql' >>> d["database"] = 'oracle' >>> d["database"] 'oracle' >>> del d["server"] >>> d {'database': 'oracle'} >>> d["boy"] ='ljq' >>> d {'boy': 'ljq', 'database': 'oracle'} >>> d.clear() >>> d {} >>> d {} >>> li = ['a','b','c','woaini'] >>> li ['a', 'b', 'c', 'woaini'] >>> li[0] 'a' >>> li[4] Traceback (most recent call last): File "<pyshell#27>", line 1, in <module> li[4] IndexError: list index out of range >>> li[3] 'woaini' >>> li[-1] 'woaini' >>> li[-3] 'b' >>> li ['a', 'b', 'c', 'woaini'] >>> li[1:-1] ['b', 'c'] >>> li[1,2] Traceback (most recent call last): File "<pyshell#33>", line 1, in <module> li[1,2] TypeError: list indices must be integers, not tuple >>> li ['a', 'b', 'c', 'woaini'] >>> li[0:2] ['a', 'b'] >>> li[1:2] ['b'] >>> li[1:-1] ['b', 'c'] >>> li[1:4] ['b', 'c', 'woaini'] >>> li[1:0] [] >>> li ['a', 'b', 'c', 'woaini'] >>> li[:3] ['a', 'b', 'c'] >>> li[1:] ['b', 'c', 'woaini'] >>> li[2:] ['c', 'woaini'] >>> li[:] ['a', 'b', 'c', 'woaini'] >>> li.append('girl') >>> li ['a', 'b', 'c', 'woaini', 'girl'] >>> li.insert(2,'new') >>> li ['a', 'b', 'new', 'c', 'woaini', 'girl'] >>> li.extend(["two","element"]) >>> li ['a', 'b', 'new', 'c', 'woaini', 'girl', 'two', 'element'] >>> li ['a', 'b', 'new', 'c', 'woaini', 'girl', 'two', 'element'] >>> li.extend(['d','ff','ddd']) >>> li ['a', 'b', 'new', 'c', 'woaini', 'girl', 'two', 'element', 'd', 'ff', 'ddd'] >>> len(li) 11 >>> li[-1] 'ddd' >>> li.append(['2','dd','dddddd']) >>> li ['a', 'b', 'new', 'c', 'woaini', 'girl', 'two', 'element', 'd', 'ff', 'ddd', ['2', 'dd', 'dddddd']] >>> li.index('new') 2 >>> li.index('wddddd') Traceback (most recent call last): File "<pyshell#59>", line 1, in <module> li.index('wddddd') ValueError: list.index(x): x not in list >>> "a" in li True >>> "ddddddd" in li False >>> li.remove('a') >>> li ['b', 'new', 'c', 'woaini', 'girl', 'two', 'element', 'd', 'ff', 'ddd', ['2', 'dd', 'dddddd']] >>> li.pop() ['2', 'dd', 'dddddd'] >>> li ['b', 'new', 'c', 'woaini', 'girl', 'two', 'element', 'd', 'ff', 'ddd'] >>> li = ['a','d','mygirl'] >>> li ['a', 'd', 'mygirl'] >>> li = li +['hello','mybory'] >>> li ['a', 'd', 'mygirl', 'hello', 'mybory'] >>> li = li * 2 >>> l Traceback (most recent call last): File "<pyshell#71>", line 1, in <module> l NameError: name 'l' is not defined >>> li ['a', 'd', 'mygirl', 'hello', 'mybory', 'a', 'd', 'mygirl', 'hello', 'mybory'] >>> t = ('a','b','c') >>> t ('a', 'b', 'c') >>> t[1] 'b' >>> t[-1] 'c' >>> t.append('new') Traceback (most recent call last): File "<pyshell#77>", line 1, in <module> t.append('new') AttributeError: 'tuple' object has no attribute 'append' >>> "a" in t True >>> v=('a','b','c') >>> v ('a', 'b', 'c') >>> (x,y,z)=v >>> x 'a' >>> y 'b' >>> b Traceback (most recent call last): File "<pyshell#84>", line 1, in <module> b NameError: name 'b' is not defined >>> c Traceback (most recent call last): File "<pyshell#85>", line 1, in <module> c NameError: name 'c' is not defined >>> z 'c' >>> v ('a', 'b', 'c') >>> range(7) [0, 1, 2, 3, 4, 5, 6] >>> (MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY) = range(7) >>> MONDAY 0 >>> K='UID' >>> V = 'SA' >>> '%S=%S' % (K,V) Traceback (most recent call last): File "<pyshell#93>", line 1, in <module> '%S=%S' % (K,V) ValueError: unsupported format character 'S' (0x53) at index 1 >>> k = "uid" >>> v = "sa" >>> "%s=%s" % (k, v) 'uid=sa' >>> print "%s is not a good password for %s" % (pwd, uid) Traceback (most recent call last): File "<pyshell#97>", line 1, in <module> print "%s is not a good password for %s" % (pwd, uid) NameError: name 'pwd' is not defined >>> print "%s is not a good password for %s" % (K, V) UID is not a good password for SA >>> print "today" stock price : %f" % 50.5556666 SyntaxError: invalid syntax >>> print "Today's stock price: %f" % 50.4625 File "<pyshell#100>", line 1 print "Today's stock price: %f" % 50.4625 ^ IndentationError: unexpected indent >>> print "Today's stock price: %f" % 50.4625 Today's stock price: 50.462500 >>> print "Today's stock price: %.2f" % 50.4625 Today's stock price: 50.46 >>> print "Today's stock price: %f+.2" % 50.4625 Today's stock price: 50.462500+.2 >>> li = [1,9,8,4] >>> [elem*2 for elem in li] [2, 18, 16, 8] >>> li [1, 9, 8, 4] >>> li = [elem*2 for elem in li] >>> li [2, 18, 16, 8] >>> d {} >>> d =[]params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"} SyntaxError: invalid syntax >>> params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"} >>> params {'pwd': 'secret', 'database': 'master', 'uid': 'sa', 'server': 'mpilgrim'} >>> params.keys() ['pwd', 'database', 'uid', 'server'] >>> params.values(); ['secret', 'master', 'sa', 'mpilgrim'] >>> params.items() [('pwd', 'secret'), ('database', 'master'), ('uid', 'sa'), ('server', 'mpilgrim')] >>> li = ['server=mpilgrim', 'uid=sa', 'database=master', 'pwd=secret'] >>> li ['server=mpilgrim', 'uid=sa', 'database=master', 'pwd=secret'] >>> s=":".join(li) >>> s 'server=mpilgrim:uid=sa:database=master:pwd=secret' >>> s.split(':') ['server=mpilgrim', 'uid=sa', 'database=master', 'pwd=secret'] >>> type(1) <type 'int'> >>> type("hello") <type 'str'> >>> type[d] Traceback (most recent call last): File "<pyshell#123>", line 1, in <module> type[d] TypeError: 'type' object is unsubscriptable >>> type(li) <type 'list'> >>> type(params) <type 'dict'> >>> str(1) '1' >>> dir(li) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> li=[] >>> dir(li) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> li=["boy","girl"] >>> li ['boy', 'girl'] >>> li.pop() 'girl' >>> li ['boy'] >>> getattr(li,"pop") <built-in method pop of list object at 0x011CE080> >>> li = ["a", "mpilgrim", "foo", "b", "c", "b", "d", "d"] >>> li ['a', 'mpilgrim', 'foo', 'b', 'c', 'b', 'd', 'd'] >>> [elem for elem in li if len(elem)>2] ['mpilgrim', 'foo'] >>> li=[elem for elem in li if len(elem)>2] >>> li ['mpilgrim', 'foo'] >>> 'a' adn 'b' SyntaxError: invalid syntax >>> 'a' and 'b' 'b' >>> '' and 'b' '' >>> def f(x) SyntaxError: invalid syntax >>> def f(x): return x*2 >>> >>> >>> f(4) 8 >>> g = lambda x:x*2 >>> g(3) 6 >>> s = "this is\na\ttest" >>> print s this is a test >>> print s.split() ['this', 'is', 'a', 'test'] >>> print " ".join(s.split) Traceback (most recent call last): File "<pyshell#159>", line 1, in <module> print " ".join(s.split) TypeError >>> print " ".join(s.split()) this is a test >>> import types >>> types.FunctionType <type 'function'> >>> FunctionType Traceback (most recent call last): File "<pyshell#163>", line 1, in <module> FunctionType NameError: name 'FunctionType' is not defined >>> from types import FunctionType >>> FunctionType <type 'function'> >>> fsoc = open('/onttt','r') Traceback (most recent call last): File "<pyshell#166>", line 1, in <module> fsoc = open('/onttt','r') IOError: [Errno 2] No such file or directory: '/onttt' >>> try: fsock = open('/onttt','r') except IOError File "<pyshell#173>", line 3 except IOError ^ IndentationError: unindent does not match any outer indentation level >>> >>> try: fsock = open('/onttt','r') except IOError: File "<pyshell#175>", line 3 except IOError: ^ IndentationError: unindent does not match any outer indentation level >>> try: fsock = open('/dddddd') except IOError: File "<pyshell#178>", line 3 except IOError: ^ IndentationError: unindent does not match any outer indentation level >>> try: fsock = open('/dddd') except IOError: File "<pyshell#202>", line 3 except IOError: ^ IndentationError: unindent does not match any outer indentation level >>> try: fscok = open('/ddddd') except IOError: File "<pyshell#205>", line 3 except IOError: ^ IndentationError: unindent does not match any outer indentation level >>> import urllib >>> sock = urllib.urllib.urlopen("www.baidu.com") Traceback (most recent call last): File "<pyshell#207>", line 1, in <module> sock = urllib.urllib.urlopen("www.baidu.com") AttributeError: 'module' object has no attribute 'urllib' >>> sock = urllib.urlopen("www.baidu.com") Traceback (most recent call last): File "<pyshell#208>", line 1, in <module> sock = urllib.urlopen("www.baidu.com") File "C:\Python26\lib\urllib.py", line 86, in urlopen return opener.open(url) File "C:\Python26\lib\urllib.py", line 205, in open return getattr(self, name)(url) File "C:\Python26\lib\urllib.py", line 467, in open_file return self.open_local_file(url) File "C:\Python26\lib\urllib.py", line 481, in open_local_file raise IOError(e.errno, e.strerror, e.filename) IOError: [Errno 2] : 'www.baidu.com' >>> urllib <module 'urllib' from 'C:\Python26\lib\urllib.py'> >>> sock = urllib.URLopener >>> sock <class urllib.URLopener at 0x011F7990> >>> htmlSource = sock.read() Traceback (most recent call last): File "<pyshell#212>", line 1, in <module> htmlSource = sock.read() AttributeError: class URLopener has no attribute 'read' >>> import urllib >>> print urllib.urlopen('http://www.baidu.com').read()
发表评论
-
python处理excele表格
2013-09-04 09:51 8321: 安装xlrd----python2.5选择对应版本 ( ... -
linux上python运行注意
2013-08-16 10:04 6761: 用editplus 把py文件改成unix类型: ... -
python 传值和引用
2013-06-18 14:06 11751:python中 count =0 你要 count = ... -
python简单封装MySQLdb模块
2013-05-20 15:01 2036# -*- coding: UTF-8 -*- impor ... -
django中simplejson的使用
2012-11-29 21:05 3258转自:那忘了 ,,,,,请包涵,,,,,非原创 需求问 ... -
python获得当前时间等
2012-11-29 20:55 960你可以试下下面的方式来取得当前时间的时间戳:import ti ... -
django获取url参数总结
2012-11-29 19:36 3402Django URL传递参数的方法总结 ian | P ... -
python乱码
2012-10-26 13:40 896我在python中使用的碰到的中文相关的问题有:1.执行 ... -
python多线程
2012-10-26 13:24 592# -- coding:utf-8 -- import th ... -
文件目录和操作库
2012-10-26 10:57 634import os import string ... -
python 图形处理pil
2012-10-25 09:50 8151:为了识别验证码,首先必须学习下python的图形处理 ... -
django--静态文件路径和模板路径配置
2012-10-18 14:18 168451:django处理静态文件: 比如 : 我的工程是 ... -
皮尔逊相关度评价-寻找用户相似度
2012-10-12 16:14 15721:python的数据字典格式在《集体智慧》中的, p ... -
python-mysqldb的安装
2012-09-03 08:55 782下载与安装Python中使用MySQL需要安装MySQL ... -
python-正则表达式
2012-08-24 10:25 413别人的 那来看看 -
从C/C++程序员角度看Python的动态类型
2012-08-23 09:39 2414从C/C++程序员角度 ... -
python----网站日志分析,状态吗,下载量等---第一篇
2012-08-22 19:56 2937首先分析log文件的规律 判断 所需要的数据结构 注 ... -
python一点点
2012-08-22 17:37 670看过很多python的code都有这段代码: if __na ... -
python dict字典使用大全
2012-08-21 20:29 10011:初始化 方法1 >>> ... -
关于pydev在eclipse下的问题-python
2012-08-21 16:13 9391: 在eclipse下安装dydev插件 在help ...
相关推荐
《Dive Into Python3》和《深入Python3》是两本深受Python爱好者欢迎的书籍,分别提供了英文和中文的学习资源,旨在帮助读者全面理解和掌握Python3编程语言。这两本书覆盖了Python3的基础语法、高级特性以及实际应用...
Dive Into Python 是为有经验的程序员编写的一本 Python 书
在Python的世界里,"dive into"通常意味着深入探索,这表明本书将带领读者逐步深入Python的核心概念和技术。教程内容可能涵盖变量、数据类型(如整型、浮点型、字符串、列表、元组、字典等)、控制结构(如条件语句...
深入python,深入Python (Dive Into Python) 译者序 by limodou 主页(http://phprecord.126.com) Python论坛 本书英文名字为《Dive Into Python》,其发布遵守 GNU 的自由文档许可证(Free Document Lience)的...
《深入 Python_Dive Into Python 中文版》是一本专为Python初学者和进阶者设计的教程,旨在帮助读者深入理解和掌握Python编程语言的核心概念、语法结构以及实用技巧。这本书全面覆盖了Python的基础知识和高级特性,...
Dive Into Python 3涵盖了Python 3及其与Python 2的区别。与Dive Into Python相比,Dive Into Python 3的修订版约为20%,新材料为80%。
《深入Python 3》是一本全面且深入介绍Python 3编程语言的电子书籍,旨在帮助读者从...压缩包中的文件“diveintomark-diveintopython3-793871b”很可能是该书的源代码或HTML文件,可以配合阅读,加深对书中示例的理解。
《深入Python3(中文版)》是一本系统介绍Python 3的书籍,旨在帮助读者深入学习Python 3的基本知识与应用。本文将根据给定文件的信息,展开介绍Python 3的基础知识点。 首先,安装Python是学习Python语言的第一步...
《深入理解Python Dive Into Python》是一本专注于Python编程语言的深度学习书籍,旨在帮助读者全面掌握Python的核心概念、语法和编程技巧。这本书以其详尽的解释和实例,为初学者和有经验的开发者提供了深入了解...
"DiveIntoPython3.pdf"应该是书籍的PDF版,而"DiveIntoPythonExamples"很可能是书中示例代码的集合,这些资源对于自学Python 3非常有帮助。通过实践,读者可以更好地掌握书中的知识点,并逐步提升自己的Python编程...
《Dive into Python3》的压缩包文件名为diveintopython3-r860-2010-01-13,这可能表示它是2010年1月13日发布的第860个修订版。这个版本可能包含了作者对初版的修正和更新,以适应Python 3的最新发展。 通过阅读这...
《Dive Into Python 3中文版》是一本深入学习Python 3编程语言的教程,适合初学者和有一定编程基础的开发者。这本书详细介绍了Python 3的各种特性,包括语法、数据结构、函数、类、模块、异常处理、输入/输出、网络...
《Dive Into Python》是一本深受编程初学者和有经验开发者喜爱的Python编程教程。这本书以其深入浅出的讲解方式,让学习者能够快速掌握Python编程语言的核心概念和实际应用,特别是对于想要涉足Web开发领域的读者,...
在“diveintopython3-master”这个压缩包中,包含了这本书的所有源代码示例。通过这些代码,我们可以学习到以下关键知识点: 1. **Python基础**:包括变量、数据类型(如整型、浮点型、字符串、列表、元组、字典)...
PDF版本的《Dive Into Python 中文译文版》(diveintopython-pdfzh-cn-5.4b.zip)提供了完整的书籍内容,涵盖了Python的基础知识到高级特性。书中通过实际案例引导读者深入学习,包括但不限于变量、数据类型、控制...
深入Python3中文版 PDF格式 深入 Python 3》 的内容涵盖了 Python 3 及其与 Python 2 的区别。相对《深入 Python》而言,它 20% 的内容进行了修订,80% 的内容是全新的。
《Dive Into Python 2 中文版》是一本深度探讨Python编程语言的教程,适合已经有一定编程基础,希望深入理解Python特性和应用的读者。这本书以其详尽的解释和丰富的实例,为Python初学者和进阶者提供了全面的学习...