每日学习笔记(3)

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

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

ExpandedBlockStart.gif 代码
<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />--> for root,dirs,files in os.walk(sdir,topdown = False):
for file in files:
full_path
= sdir + file
if os.path.exists(full_path) == True:
# processfile

3,python处理命令行参数

ExpandedBlockStart.gif 代码
<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />--> import sys
import getopt
while true:
try :
opts,args
= getopt.getopt(sys.argv[ 1 :], " hs:t:d:i " ,[ " help " , " source= " , " targe= " , " ip= " ])
for opt,arg in opts:
if opt in ( " -h " , " --help " ):
print ( " showhelpinfo/n " )
elif opt in ( " -t " , " --targe " ):
target
= arg
elif opt in ( " -s " , " --source " ):
source
= arg
elif opt in ( " -e " , " --exit " ):
sys.exit(0)
except getopt.GetoptError:
sys.exit(
- 1 )

4,python中的信号处理机制

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

def handler(signum,frame):
print ' Signalhandlercalledwithsignal ' ,signum
raise TimeOutError, " TimeOut! "

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值