显示标签为“Google 技术”的博文。显示所有博文
显示标签为“Google 技术”的博文。显示所有博文

2012年6月12日

Python-字串样式比对


Python-字串样式比对

首先必须先汇入re模组,有关regular expression的相关说明可参考http://en.wikipedia.org/wiki/Regular_expression
ex1: 比对字串样式:句首为Wellcome中间有空格或tab隔开,句子结尾是here。括号中的字串会抓取到match.groups()中。要取出其中的每个字串,可以用match.group(i),i为要取出找到的第几个字串。
>>> import re>>> match=re.match('Wellcome[ \t]*(.*)here','Wellcome to here')>>> dir(match)['__copy__', '__deepcopy__', 'end', 'expand', 'group', 'groupdict', 'groups', 'span', 'start']>>> print match.groups()('to ',)>>> match.group(1)'to '

ex2 取出字串样式为'/(.*)/(.*)/(.*)'括号中的字串>>> match=re.match('/(.*)/(.*)/(.*)','/usr/home/sample')>>> match.groups()('usr', 'home', 'sample')>>> match.group(1)'usr'>>>

2012年6月10日

Python-原始段落显示方法-三个单引号或双引号


Python-原始段落显示方法-三个单引号或双引号
一般指定一个单引号或双引号的字串给变数时,无法断行,要断行或空格需要使用特殊符号'\n' 及'\t'。
>>> s='\nHello \n Where are you \nHear Hear\n\n'>>> print s
Hello
Where are youHear Hear

当你要显示一个段落,不想用特殊符号且希望在显示时格式遭到破坏时,可以使用三个单引号或双引号将一个段落的字串包含在其中即可。>>> s='''... Hello... Where are you... Hear Hear...... '''>>> s'\nHello \n Where are you \nHear Hear\n\n'>>> print s
Hello
Where are youHear Hear

2012年6月9日

python 物件型态取得使用方法协助-help 指令


python 物件型态取得使用方法协助-help 指令
当你对python物件使用上有不清楚或想知道更多使用方法时,可利用dir或help的指令直接对已指定值的变数或方法套上这两个指令即可。
dir函式只是给出可使用的方法或属性名称,要详细了解这个方法或名称如何使用,就必须用help的函式了。


>>> S'Hello'>>> dir(S)['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode','encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

>>> help(S.split)Help on built-in function split:
split(...)
S.split([sep [,maxsplit]]) -> list of strings

Return a list of the words in the string S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator.
>>>
利用help函式,会显示这个方法或函式的语法与说明。

2012年6月8日

python 物件型态取得使用方法协助-dir 指令


python 物件型态取得使用方法协助-dir 指令
当你对python物件使用上有不清楚或想知道更多使用方法时,可利用dir或help的指令直接对已指定值的变数或方法套上这两个指令即可。
当你呼叫内建的dir函式时,会传回来指定物件可用的属性及方法串列。

>>> S='hello'>>> dir(S)['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode','encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']>>>
dir 会显示此物件的所有方法串列,有底线的代表是此物件的实作,前后双底线的是python用于实作细节的命名模式,一般我们是用不到。串列中没有底线的名称是可以对此物件呼叫的方法或属性。

2012年6月6日

Python-物件型态-字串-2

Python-物件型态-字串-2 
字串运算时,原字串并未作任何改变。字串常用的方法有:


1.寻找子字串的偏移量
>>> S='Hello'
>>> S.find('el')
1
>>> S'Hello'


2.以另一个字串取代子字串的内容
>>> S.replace('el','ABC')
'HABClo'
>>> S'Hello'


3.以分界字元或字串将原字串切割成多个子字串串列
>>> S='aaa,bbb,ccc,ddd'
>>> S.split(',')
['aaa', 'bbb', 'ccc', 'ddd']
>>> S'aaa,bbb,ccc,ddd'


2012年5月31日

Python-物件型态-字串-1


Python-物件型态-字串-1

1.序列运算1.1 取得字串长度
>>> S='Hello'>>> len(S)5
1.2取得字串之中的任一项目或字元
字串的索引值是从0开始到len(S)-1,另外也可使用负索值的方式取得字串中的字元
ex:取得第一个字元
>>> S[0]'H'

ex:取得最后一个字元
>>> S[len(S)-1]'o'


2012年5月29日

如何在Google blogger的文章的HTML程式码中直接插入Google Adsense的广告


如何在Google blogger的文章的HTML程式码中直接插入Google Adsense的广告
如果你希望你的Google Adsense广告出现在你想出现的文章位置,你可以参考以下的做法:
1.首先你必须在你的Google Adsense中建立一个你想要的广告,并按[获取代码]以取得JavaScript程式码。

图_如果你希望你的Google Adsense广告出现在你想出现的文章位置_1
图_如果你希望你的Google Adsense广告出现在你想出现的文章位置_1

2012年5月21日

利用Python Gmail SMTP 寄送Email


利用Python Gmail SMTP 寄送Email

其中'GmailUserName' 为寄件者Gmail的帐号'GmailPassword'为寄件者Gmail密码'receive@XXX.XXX.XXX'为接收者帐号,一次只能一个,若要寄多个,则必须用成List来依序寄出'subject'寄邮件的标题'testcontent'为邮件的内容程式内容如下:


在Blogger ,WordPress , TypePad加入"您或许对这些文章有兴趣" 教学(use LinkWithin)

在Blogger ,WordPress , TypePad加入"您或许对这些文章有兴趣" 教学(use LinkWithin)1.若你要在blog中加入"您或许对这些文章有兴趣" 这个功能时,可依照下面所介绍的步骤进行。



图_在Blogger ,WordPress , TypePad加入"您或许对这些文章有兴趣" 教学LinkWithin_1
图_在Blogger ,WordPress , TypePad加入"您或许对这些文章有兴趣" 教学LinkWithin_1




2012年5月20日

设定Google日历所提供的免费简讯功能

设定Google日历所提供的免费简讯功能


一、进入Gmail 之后,选取画面左上方的「日历」功能,再选取「设定」功能。

2012年5月9日

Google 部落格- 网志 (blogger)移植或转移方法

Google 部落格-  网志 (blogger)移植或转移方法

当你的google 部落格-网志(blogger)移植或转移时 ,可参考下列的作法


1.登入网志,进入网志“设定”==>“其他”后,点选 “汇出网志"

BlogAD