2012来了

Posted by Linda in Life | Leave a comment

2011对与我,对于我的家人,都是重要的一年,因为宝宝的出生。

2011也完成了许多事情,买车,学驾照,开始慢慢习惯有宝宝,有车的生活。可以说,从2011年开始,我的生活有了很多不同。

2012来了,希望新的一年里,

1. 家人都健康平安。

2. 宝宝能快乐成长。

3. 工作会有新的起色和突破。

4. 能出去旅游一次。

宝宝快八个月了

Posted by Linda in Life | Leave a comment

当我和别人说起,宝宝快八个月了,他们都说“过的太快了”。在别人眼里,时间过的很快,可对于我来讲,真的是很慢。

那天好友问我当妈妈的感受时,我说“养儿才知父母恩”。真的是这样,尽管宝宝出世前,我自认为做好了思想准备,可是当她真的来到我身边,我才发现,我还是没有准备好。没有办法,不经历永远不知道当父母是怎么回事!

做妈妈很累。晚上正要准备睡觉或者刚刚睡着,或者睡得正香,她哭了。不管我有多么的不情愿,都要起来喂她,哄她,她安稳的睡了,我才能睡。有时一晚上折腾好几次。刚刚洗完澡,她拉便便了,还要给她洗屁屁。把尿她打挺,刚放下,她尿了,裤子全湿,都要换洗。不吃东西着急,吃多了还着急。有时我想,也就是自己亲生的,不然我肯定把她送人了。

但不管怎样,看着她一点一点的进步,心里很安慰,总算是没白忙活。现在宝宝能坐的很稳了,她很乖,给个小纸片都能玩半天,也很少哭。总喜欢让我抱,我一拍手,就会把胳膊伸起来要抱抱。我抱着她,她就很兴奋,会咯咯地乐或者哇哇的叫,放下她,她就不高兴,但给点玩具哄哄就又自己玩去了。每天一下班进门,她都冲着我笑,那一刻,所有的不快就都烟消云散了。

盼着她会走路,能带出去玩。看着她一天天长大,我也变得更坚强,因为我知道,有这样一个小人人要依靠我。希望宝宝快乐成长。

Python: 字符串的方法

Posted by Linda in Technology | Leave a comment

find方法: 返回一个较长字符串中查找的子字符串。返回子串最左端的索引。如果没有找到,返回-1
>>> str = ‘abc efg hij efg nio efg’
>>> str.find(‘efg’)
4.

join方法: 是split的逆方法,在队列中添加元素
>>> seq = ['1', '2', '3', '4', '5']
>>> sep=’+’
>>> sep.join(seq)
’1+2+3+4+5′

>>> dirs = ”, ‘usr’, ‘bin’, ‘env’
>>> ‘/’.join(dirs)
‘/usr/bin/env’
>>> print (‘C:’ + ‘\\’.join(dirs))
C:\usr\bin\env

lower方法: 返回字符串的小写
>>> ‘TEST’.lower()
‘test’

>>> name=’Linda’
>>> names=['linda', 'wang', 'liu']
>>> if name.lower() in names: print (‘OK’)

replace方法:
>>> test=’This is a test’
>>> test.replace(‘is’, ‘eez’)
‘Theez eez a test’

split方法:join的逆方法,用了将字符串分割成序列
>>> test=’1+2+3+4+5′
>>> test.split(‘+’)
['1', '2', '3', '4', '5']
>>> test=’usr/bin/env’
>>> test.split(‘/’)
['usr', 'bin', 'env']

strip方法: 去掉字符串两侧的空格
>>> test=’ 123 ‘
>>> test.strip()
’123′

Python: 符号,对齐和0填充

Posted by Linda in Technology | Leave a comment

在字段宽度和精度之前可以放置一个标号, 可以是零, +, -或空格。

零表示数字会用0填充
>>> from math import pi
>>> ‘%10.2f’ % pi
‘      3.14′
>>> ‘%010.2f’ % pi
’0000003.14′

- 表示左对齐
>>> ‘%-10.2f’ % pi
’3.14      ‘

空格表示在正数前加上空格

+表示不管正数还是负数,都表示出符号
>>> print (‘%+5d’ % 10)
  +10

Example:

width = 30
price_width = 10
item_width = width – price_width
header_format = ‘%-*s%*s’
format = ‘%-*s%*.2f’

print (‘=’ * width)
print (header_format % (item_width, ‘Item’, price_width, ‘Price’))

print (‘-’ * width)

print (format % (item_width, ‘Apples’, price_width, 0.4))
print (format % (item_width, ‘Pears’, price_width, 0.5))
print (format % (item_width, ‘Cantaloupes’, price_width, 1.92))
print (format % (item_width, ‘Dried Apricots’, price_width, 8))
print (format % (item_width, ‘Prunes’, price_width, 12))
print (‘=’ * width)

Result:

==============================
Item                     Price
——————————
Apples                    0.40
Pears                     0.50
Cantaloupes               1.92
Dried Apricots            8.00
Prunes                   12.00
==============================

Python: 字符串格式化

Posted by Linda in Technology | Leave a comment

Example 1:

>>> format = “Pi with three decimals: %.3f”
>>> from math import pi
>>> print(format % pi)
Pi with three decimals: 3.142

d, i: 带符号的十进制整数
o:     不带符号的八进制整数
u:      不带符号的十进制整数
x:     不带符号的十六进制整数(小写)
X:      不带符号的十六进制整数(大写)
e:       科学计数法表示的浮点数(小写)
E:       科学计数法表示的浮点数(大写)
f,F:    十进制浮点数
g:
G:
C:        单字符
r:         字符串(使用repr转换成python对象)
s:          字符串(使用str转换成python对象)

Python: 列表方法

Posted by Linda in Technology | Leave a comment

1. append: 在列表末尾追加新的对象

>>> lst=[1,2,3]
>>> lst.append(4)
>>> lst
[1, 2, 3, 4]

2. count: 统计某个元素在列表中出现的次数

>>> mst=['to', 'be', 'or', 'not', 'to', 'be']
>>> mst.count(‘to’)
2

3. extend: 用新的列表扩展原有的列表

>>> a=[1,2,3]
>>> b=[4,5,6]
>>> a.extend(b)
>>> a
[1, 2, 3, 4, 5, 6]

注:和a+b不同的是,a+b返回一个新的序列,a.extend(b)修改的是a

可以用a=a+b或者a[len(a):]=b

4. index: 从列表中找出某个值第一个匹配项的索引位置

>>> a=[1,2,3]
>>> a.index(3)
2

5. insert: 用于将对象插入到列表中

>>> a=[1,2,3]
>>> a.insert(1,4)
>>> a
[1, 4, 2, 3]

6. pop: 移除列表中的一个元素,默认是最后一个

>>> a.pop(1)
4
>>> a
[1, 2, 3]

7. remove: 移除列表中某个值的第一个匹配项

>>> a=[1,2,1,1,2,1]
>>> a.remove(2)
>>> a
[1, 1, 1, 2, 1]

8.reverse: 反向

>>> a=[1,2,3]
>>> a.reverse()
>>> a
[3, 2, 1]

9.sort: 改变原来的列表,让元素按一定的顺序排序

>>> a=[1,5,3,2,8]
>>> a.sort()
>>> a
[1, 2, 3, 5, 8]

注意:当需要一个排序的副本,同时又保留原有列表不变:

>>> x=[3,2,5]
>>> y=x.sort()
>>> y

是错误的,因为sort方法修改了x但返回了空值,正确的做法是

>>> x=[3,2,5]
>>> y=x[:]
>>> y.sort()
>>> y
[2, 3, 5]
>>> x
[3, 2, 5]

y先等于x的副本,然后给y排序

但这样也是错误的:

>>> x=[3,2,5]
>>> y=x
>>> y.sort()
>>> x
[2, 3, 5]
>>> y
[2, 3, 5]

只是让y等于x,其实y和x指向的是同一个列表,对y排序,也修改了x的值

Python: 列表2

Posted by Linda in Technology | Leave a comment

1. list函数将字符串转换成列表

>>> list(‘hello’)
['h', 'e', 'l', 'l', 'o']

2. 修改列表

>>> x=[1,1,1]
>>> x[1]=2
>>> x
[1, 2, 1]

3. 删除元素值

>>> names=['Alice', 'Beth', 'Cecil', 'Dee-Dee', 'Earl']
>>> del names[2]
>>> names
['Alice', 'Beth', 'Dee-Dee', 'Earl']

>>> name=list(‘hello’)
>>> name
['h', 'e', 'l', 'l', 'o']
>>> name[2:]=list(‘ar’)
>>> name
['h', 'e', 'a', 'r']

>>> numbers=[1,2,3,4,5]
>>> numbers[1:4]=[]
>>> numbers
[1, 5]

Python:列表1

Posted by Linda in Technology | Leave a comment

1. Python最基本的数据结构是序列(sequence).

2. 元素的位置,索引从0开始。

3. Python有六种内建的序列,列表,元组,string, Unicode string, buffer对象和xrange对象。

4. 列表和元组的最大区别是列表可以修改,元组则不能。

5. 序列可以包含其他的序列。

>>> edward = ['Edward Gumby', 42]
>>> john = ['John Smith', 50]
>>> database = [edward, john]
>>> database
[['Edward Gumby', 42], ['John Smith', 50]]

6. 序列操作:

1). 索引

>>> greeting = ‘hello’
>>> greeting[0]
‘h’
>>> greeting[-1]
‘o’

I. 很有意思的是可以使用负数从右访问元素,-1表示最后一个元素

II. 字符常量可以直接使用索引,而不需要一个变量引用他们

>>> ‘hello’[1]
‘e’

>>> fourth = input(‘Year: ‘)[3]
Year: 2005
>>> fourth
’5′

取输入的第四个数字

III. 使用:访问一定范围的元素

>>> tag=’<a href=”http://www.python.org”>Python web site</a>’
>>> tag[9:30]
‘http://www.python.org’
>>> tag[32:-4]
‘Python web site’

注意第一个元素包含在内,最后一个不包含在内

>>> number=[1,2,3,4,5,6,7,8,9,10]
>>> number[3:6]
[4, 5, 6]
>>> number[0:1]

如果操作最后一个元素,

number[7:10]
[8, 9, 10]

>>> number[-3:]
[8, 9, 10]
>>> number[-3:-1]
[8, 9]
>>> number[-3:0]
[]
>>> number[:3]
[1, 2, 3]
>>> number[:]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

IV.  步长

默认步长是1,但可以指定

>>> number[0:10:2]
[1, 3, 5, 7, 9]

>>> number[10:0:-2]
[10, 8, 6, 4, 2]

V. 相同类型的序列可以相加

>>> [1, 2, 3] + [4, 5, 6]
[1, 2, 3, 4, 5, 6]

VI. 数字乘以序列可以产生新的序列

>>> ‘python ‘ * 5
‘python python python python python ‘

VII. in 操作符可以判断元素是否在序列内

>>> permission=’rw’
>>> ‘w’ in permission
True
>>> ‘x’ in permission
False

VIII. max, len, min

>>> number=[100, 34, 678]
>>> len(number)
3
>>> max(number)
678
>>> min(number)
34

python 的 string

Posted by Linda in Technology | Leave a comment

1. 如果string中有‘, string可以用”括起来。

2.如果string中有”, string可以用’括起来。

3. 用转义符表示’或”是字符串

4. 拼接string

>>> x=”hello, ”
>>> y=”world”
>>> x + y
‘hello, world’

要当妈妈了

Posted by Linda in Life | 4 Comments

这两天工作比较轻松,终于有时间整理一下blog了。
把MSN Space的Blog都import到这里,然后重新整理了一下。MSN Space的blog是从自己到WR工作开始的,大部分文章都是自我激励,思考工作时的心路历程。重新整理它们的时候,又重温了一遍自己当年是如何面对工作的压力,如何balance工作和生活的。两年的时间很快,一下子就过去了。虽然自己在这两年时间很辛苦,付出了很多,但我从来没有后悔过。如果时光重新来过,我还是会坚持当年的选择。
那天对老公说,感觉回来工作以后,自己的幸福感大大增加了,尤其在有了宝宝之后。现在的工作很轻松,不用去学习新的知识,而且WR的工作经验也让我做起这份工作来游刃有余。只是有些担心自己这样长期下去,会不会把以前的技术都忘了?而且这份工作的附加值有多少?
但现在已经不是我要考虑的主要问题了。宝宝五月份出生,如何迎接他/她的到来,才是当前的重要任务。
要当妈妈了。