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