`
phinecos
  • 浏览: 343523 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

每日学习笔记(3)

 
阅读更多

1,先说说今天体会最深刻的一点:写python代码,一个好的编辑器至关重要,这其中VIM确实是最佳选择。由于python是根据缩进来判断上下文的,因此tab和空格使用不当会害死你的。一段代码在Notepad++里看起来对齐格式没问题,可就是死活编译不过,来到vim下一看,damn it,格式是乱的。本想用4个空格替换掉所有的tab,可该死的Notepad++居然并没有全部替换掉,再换UltraEdit32,依然如故,不得已,最后换了EmEditor,比前面两个强多了,

2,python实现遍历文件夹下所有文件

代码
<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />-->forroot,dirs,filesinos.walk(sdir,topdown=False):
forfileinfiles:
full_path
=sdir+file
ifos.path.exists(full_path)==True:
#processfile

3,python处理命令行参数

代码
<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />-->importsys
importgetopt
whiletrue:
try:
opts,args
=getopt.getopt(sys.argv[1:],"hs:t:d:i",["help","source=","targe=","ip="])
foropt,arginopts:
ifoptin("-h","--help"):
print("showhelpinfo/n")
elifoptin("-t","--targe"):
target
=arg
elifoptin("-s","--source"):
source
=arg
elifoptin("-e","--exit"):
sys.exit(0)
exceptgetopt.GetoptError:
sys.exit(
-1)

4,python中的信号处理机制

代码
<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />-->importsignal

defhandler(signum,frame):
print'Signalhandlercalledwithsignal',signum
raiseTimeOutError,"TimeOut!"

try:
#Setthesignalhandleranda1-secondalarm
signal.signal(signal.SIGALRM,handler)
signal.alarm(
1)
#Thiswhileloophangindefinitely
whileTrue:
print'a',
signal.alarm(0)
#Disablethealarm
except:
print
print'Timeoutcaught!'

5mysql的几个常用点:1truncate table tablename用来删除表中所有数据。2limit相当于其他数据库中的top,取指定条数记录。3desc 表名用来查看表结构 4)若表中字段是关键字,例如group,那么需要使用`group`(不是单引号,是数字1旁边那个键)。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics