【整理】Python中,关于字符串的查找并替换
crifan 13年前 (2012-03-16) 5080浏览 1评论
关于如何替换,参考这里: http://www.cnpythoner.com/post/65.html 解释有两种: (1)用字符串本身的replace方法 a = 'hello word'; a....
在路上on the way - 走别人没走过的路,让别人有路可走
crifan 13年前 (2012-03-16) 5080浏览 1评论
关于如何替换,参考这里: http://www.cnpythoner.com/post/65.html 解释有两种: (1)用字符串本身的replace方法 a = 'hello word'; a....
crifan 13年前 (2012-03-16) 5844浏览 2评论
【Python中如何获得当前所执行的脚本的名字】 sys.argv[0]是传入的参数,通过解析,可以得到当前python脚本的文件名。 直接给出参考代码: # got script self's name # for : python hi-baid...
crifan 13年前 (2012-03-16) 5017浏览 0评论
参考代码: import os; cur_path = os.getcwd(); new_dir = cur_path + '\\' + 'dir0' + '\\dir1'; print "new dir exist=",os....
crifan 13年前 (2012-03-16) 2771浏览 0评论
参考这里: python学习笔记——字符串 摘录其整理的表格,供参考: 类型 方法 注解 填充 center(width[, fillchar]), ljust(width[, fillchar]), ...
crifan 13年前 (2012-03-16) 16587浏览 0评论
通过百分号%,加上括号来实现,直接上参考代码: int_val = 123; str_val = "hello"; formated_str = " Python sprintf test: digit=%d, stri...
crifan 13年前 (2012-03-16) 16493浏览 2评论
首先我们知道,python中字符包括两种,一个是普通的字符str,另一种是unicode字符。 我们实际的需求,很可能是不知道字符是什么编码的,即不知道是普通的str还是unicode,即使知道unicode,也不一定知道是什么格式存储的,即是u...
crifan 13年前 (2012-03-16) 3234浏览 0评论
isinstance函数的原型是: isinstance(object, classinfo) Return true if the object argument is an instance of the classinfo argumen...
crifan 13年前 (2012-03-16) 4627浏览 0评论
(1) 如何用for循环去枚举出一个字符串中所有的字母 Python基础篇 http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/python/basic.htm#id2878558 已经介绍了,字...
crifan 13年前 (2012-03-16) 11056浏览 0评论
python中没有goto,好像也有其他模块模拟出来goto供有需要的人使用,但是很明显,goto破坏程序的逻辑,所以一般来说,也不推荐使用goto,能不用,最好不要用。 但是,很多时候,我们又有类似需求。 经过测试,自己写了个,类似goto的实现,...
crifan 13年前 (2012-03-16) 3546浏览 0评论
Python中实现,将两个字典变量合并,并且覆盖已有的值,参考代码如下: print 'dict test ++++++++++++++++++' dict1 = {1:111, 2:333} dict2 = {2:22, 4:4444} dict...