So be it

Just another WordPress.com weblog

Archive for the ‘计算机与 Internet’ Category

python notes(1)

Posted by wanyancan 于 8月 3, 2006

Comment

(#) not inside ("") begins a comment

miscellaneous

empty physical line to terminate a multiline statement

() join two adjacent physical line into a single logical line.
but, if an open parenthesis ( (,[,{ ) has not been closed,
python automatically joins them.

continuation line do not need to be indented but only the logical line begins with.

_ in interactive : last expression

identifier nomenclature

[A-Z]w* : class names
^_			: private identifier
^__			: strongly private identifier
^__w+__$	: language-defined special name
_ in interactive	: last expression

numeric data type

d*(l|L)$ : explicitly denote a long integer, (‘l’) is not recommended!! 长得太像1了!

sys.maxint(as 0111) : lagest positive plain integer

-sys.maxint-1(as 1000=1111(-1)-0111) : most negative plain integer

z.imag : this bizar name(maybe wanna to keep 4 characters long as ‘real’) means
the image part of a complex literal.

关于浮点,这篇文章不得不提:
What Every Computer Scientist Should Know About Floating-Point Arithmetic
at http://docs.sun.com/source/806-3568/ncg_goldberg.html
有空去翻译一遍。

Sequences

Sequences 有strings,tuples,lists。strings下面有单独介绍。
分别用tuple(an iterable ),list(an iterable )来构造。
Python 中的iterable是sequence概念的推广,all sequences are iterables.

tuple series of expressions (the items of the tuple) separated by commas (,).
外面的括号不是必须的,但要表示一个tuple传给函数做变量则需要括号,否则逗号会被
解释为函数参数列表分隔用。当然,要表示空tuple就少不了;要表示一个项的tuple,
还需要在最后右括号前加逗号。如下:

need_tuple((3,4,5))    # 一个tuple做一个参数
need_3args(3,4,5)		# 3个int作3个参数
(),tuple()				# 空tuple 
(3,)				# 一个项的tuple
(3)				# 3 , an int

list 与tuple不同,需要外面的([和] )。
比较有特色的是List comprehension 。实际就是用for loop把
一个个满足条件的target, append到生成的list里面。
比如:

# 生成一个不为0的list
result1 = [x+1 for x in some_sequence if x!=0]
# 还可以多嵌套,
[x+y for x in alist for y in another]
# 这与下面的双循环等价
result6 = []
for x in alist:
    for y in another:
        result6.append(x+y)

Sets

set and frozenset which are found in module ‘sets’
use the following codes to auto select for either Python 2.3 or Python 2.4:

try:
  set except NameError:
  from sets import Set as set, ImmutableSet as frozenset
# create a set
set
set('rrrrr') 		#->set(['r'])

Items in sets is Hashable , frozenset it self is Hashable, but not set.
So no set(except frozenset) can belong to set(include frozenset).

Dictionaries

As sets, keys in a dict should be hashable , value could be any type.
dict itself is mutable, not hashable.

# only last key matters
{'x':1, 'x':2}   #=> {'x':2}
dict()		#=> empty dict
dict([(1,2)])		#=> from an itarable of **pairs**
dict(x=1)		#=> what the fucking is this??!!  a {'x':1} ?? I hate it!
#and the following eccentric mixture! gives {'y': 2, 'x': 42, 'z': 7}
dict({'z':1} ,x=42, y=2, z=7)

#this is useful
dict.fromkeys('iloveu',8)	#=> {'e': 8, 'i': 8, 'l': 8, 'o': 8, 'u': 8, 'v': 8}

boolean

Any nonzero number or nonempty container(string, tuple, list, set, or dictionary)
are True .

0 (of any numeric type), None, and empty containers are false.

i = 1
i += True	# i = 2

String !

一般的quoting可以使用( ‘或" ),但python比较特色的triple-quoting( """或”’
二者的区别就在于一般的quoting里不能有 换行 quote符号本身 ,相同点是:都不能有
没被反斜杠的反斜杠(原因当然是因为反斜杠比较反斜杠,或者叫比较转义,另类的意思)

开头加r或R的则上面的连反斜杠的问题都解决了,缺点当然就是你输入不了DDD或xXX,因为已经
变成平民了,不再具有任何特权。不过想连接多行(single-quoting),行末尾的还是少不了的,
但不是起原来反斜杠的作用了,而是表示“这里换行前面有一个我其实不想要,但不得不要的 "

Unicode String
如果代码里有中文,那么只有把中文放在u"" 这unicode string里,而且还要在文件开头 指定编码,
就像:

# -*- coding: cp936 -*-

unicode string除了有相同的反斜杠类:行尾的, \, ‘, ", a(Bell), b(Backspace),
f(form feed, 不知道干吗的),n, r(Carriage return, 著名的^M), t, v, DDD, xXX,
other(不变,但没有),还多了个uXXXX指明一个unicode字符,而且还有一个N{name },
name
http://www.unicode.org/charts/
里找。(比如N{Copyright Sign})


All about character/encoding/utf-8

use other character set ONLY in string literals and comments
add following at the start of source file

# -*- coding: utf-8 -*-

Posted in 计算机与 Internet | Leave a Comment »

windows live!evil swodniw

Posted by wanyancan 于 8月 2, 2006

windows live 空间终于改版了,终于改得更慢了。
而且地址也要多打一个字了(msn->live,虽然用msn还是能访问)。
30秒后居然才刚能看到顶上硕大无比的广告条。我顶!你个广告条!~

但更令人惊讶的是竟然还是有如此众多的用户。。。
最近开始发到这里的唯一原因是用了 Performancing(应该还有别的工具可以完成这个功能),不用打开这巨space无比的space就能直接发表,大大提高发贴的速度和激情! Just publish it!

如果你有多个blog 空间需要你去照顾,那么恭喜你, Performancing又可以助你一臂之力。

  • 添加多个blogs易如反掌;
  • 同时还可以自动获取分类,并提供发表分类的选择;
  • 更新或删除旧的文章;
  • 暂存草稿,修改后随时发表。

心动了就赶紧行动。
介绍链接地址:http://performancing.com/
下载地址:https://addons.mozilla.org/addon.php?id=1730

Posted in 计算机与 Internet | Leave a Comment »

cURL —libcurl

Posted by wanyancan 于 12月 3, 2004

https://rrette.com/curlpp.html

libcurl is a free and easy-to-use client-side URL transfer library, supporting FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP. libcurl supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, kerberos, HTTP form based upload, proxies, cookies, user+password authentication, file transfer resume, http proxy tunneling and more!

libcurl is highly portable, it builds and works identically on numerous platforms, including Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, HPUX, IRIX, AIX, Tru64, Linux, Windows, Amiga, OS/2, BeOs, Mac OS X, Ultrix, QNX, OpenVMS, RISC OS, Novell NetWare, DOS and more…

libcurl is free, thread-safe, IPv6 compatible, feature rich, well supported and fast.

Posted in 计算机与 Internet | 1 Comment »