By minitia, on 八月 6th, 2009, Category: Python
Tags: Programming, Python, 编程
1、Dictionary语法
l Dictionary由key/value对(称为项目)组成,key和value之间用“:”分割,项目用“,”分割,所有项目用“{}”包括起来
>>> phonebook = {’Alice’: ‘2341′, ‘Beth’: ‘9102′, ‘Cecil’: ‘3258′}
l Dictionary的key值必须唯一,否则后者会覆盖前者:
>>> phonebook = {’Alice’: ‘2341′, ‘Alice’: ‘9102′, ‘Cecil’: ‘3258′}
>>> phonebook
{’Alice’: ‘9102′, ‘Cecil’: ‘3258′}
l 使用dict()函数可以从Mapping(如其它的Dictionary)或key/value形式的Sequence创建Dictionary:
>>> items = [('name', 'Gumby'), ('age', 42)]
>>> d = dict(items)
>>> d
{’age’: 42, ‘name’: ‘Gumby’}
l 也可以用keyword参数来创建Dictionary:
>>> d = dict(name=’Gumby’, age=42)
>>> d
{’age’: 42, ‘name’: ‘Gumby’}
Continue reading 开始Python — Dictionary - 全文阅读
Blogpump中想在list中添加一个嵌套的list为其子项,但是调用extend发现总是结果不对,才发现原来extend和append的调用有如此的差别。
1. list extend (扩展) 与 append (追加) 的差别 >>>li=['a','b'] >>>li.extend(['c','d']) >>>li ['a', 'b', 'c', 'd'] >>>li.append(['e','f']) >>>li ['a', 'b', 'c', 'd',['e','f']]
Continue reading Python programming- List extend() and append() - 全文阅读
By Bryan Wu, on 七月 7th, 2009, Category: BlogPump, Python
Tags: BlogBump, Crawler, Programming, Python, SGMLParser, urllib2, 编程, 网页抓取
在网上看见用Python用SGMLParser抓取网页连接的大部分都是用以下代码: #!/usr/bin/env python # -*- coding: utf-8 -*- from sgmllib import SGMLParser import urllib import urllib2 import socket socket.setdefaulttimeout(210)
class URLLister(SGMLParser):
Continue reading Python用SGMLParser抓取网页连接的改进 - 全文阅读
Python核心编程-读书笔记1
Python 语句中有一些基本规则和特殊字符: 1 井号(#)表示之后的字符为 Python 注释 2 换行 (\n) 是标准的行分隔符(通常一个语句一行) 3 反斜线 ( \ ) 继续上一行 4 分号 ( ; )将两个语句连接在一行中 5 冒号 ( : ) 将代码块的头和体分开 6 语句(代码块)用缩进块的方式体现 7 不同的缩进深度分隔不同的代码块 8 Python 文件以模块的形式组织
Continue reading Core Python Programming(1) - Basic - 全文阅读
By Bryan Wu, on 七月 2nd, 2009, Category: Eclipse, Python
Tags: Eclipse, IDE Family, Programming, PyDev, Python, 开放源代码, 编程
一直不太喜欢Eclipse的庞大,但是现在也不能容忍IDLE的脆弱,还是尝试使用前者加PyDev来开发Python程序,参考了网上的一些文章基本上在一个小时之内完成了从0到环境的搭建和配置,并且成功的运行了以前的一个Python项目。以下链接和相关说明供参考。
安装配置Django开发环境(Eclipse + Pydev)
Continue reading Eclipse SDK + PyDev = Python IDE - 全文阅读
By Bryan Wu, on 七月 2nd, 2009, Category: Open Source, Python
Tags: Data Persistence, DataBase, Programming, Python, SQL, Sqlite, 编程
SQLite is a C library that provides a lightweight disk-based database that doesn’t require a separate server process and allows accessing the database using a nonstandard variant of the SQL query language. Some applications can use SQLite for internal data storage. It’s also possible to prototype an application using SQLite and then port the code to a larger database such as PostgreSQL or Oracle.
sqlite3 was written by Gerhard Häring and provides a SQL interface compliant with the DB-API 2.0 specification described by PEP 249.
Continue reading Python Programming – Sqlite for data persistence - 全文阅读
By Bryan Wu, on 六月 24th, 2009, Category: Python
Tags: Beautiful Soap, cElementTree, HTML, lxml, Parser, Performance, Programming, Python, XML, 编程
凡是涉及到对页面的处理,就需要一个强大的HTML/XML Parser支持解析,通过对目标文件的格式化处理,我们才能够实现特定信息提取、特定信息删除和遍历等操作。使用过靓汤Beautiful Soap和ElementTree,个人感觉Beautiful Soap可以实现很多功能,但是性能不是太好。下面这篇文章具体分析和比较了各种常用解析器的性能供大家参考,包括lxml, HTMLParser, cElementTree等。
Continue reading Python HTML Parser Performance - 全文阅读
Big Picture is:
1) Module A: Interface with supported Weblog Server to post/retrieve web page, article and others;
2) Module B: Container to support editor or list for data;
3) Module C: Interface with Web Crawler to grasp pages you wanted or articles relevant information against popular search engines;
4) Module D: Profile management for source, patterns and destination combination flexibility;
5) Module E: Data persistent module to store/read locally;
Continue reading BlogPump: Blog Post Client with Web Crawler(1) – big picture - 全文阅读
利用Python做字符处理非常方便,这当然离不开正则表达式的支持,下面是一篇CSDN上转载过来的关于re的文章。
今天学习了Python中有关正则表达式的知识。关于正则表达式的语法,不作过多解释,网上有许多学习的资料。这里主要介绍Python中常用的正则表达式处理函数。
re.match re.match 尝试从字符串的开始匹配一个模式,如:下面的例子匹配第一个单词。import re text = "JGood is a handsome boy, he is cool, clever, and so on…"
Continue reading Python模块学习 - re 正则表达式 - 全文阅读
|
|
|