2011.11.1好日子,今天博客访问量超过1000了。 2012.01.29,访问量突破2000了. 2012.02.01,访问量突破3000了.继续进步

对比测试脚本语言Tcl和Python的语法以及处理(实战篇)

上一篇 / 下一篇  2011-11-17 17:29:57 / 个人分类:自动化脚本

#本脚本的功能是把最近的版本找出来,版本文件夹的格式例:Ver2C_20110102
#按照文件夹的日期来判断是否最新.用tcl和python语言分别写出来.
#在tcl中用到正则表达式,python直接用索引.

Tcl:
#初始化信息,后续会移动到配置文件中
set FilePath  [file join D:/ TclAndPyhton TestDir]
set PointP  [file join D:/ TclAndPyhton PonitDir]

#过程作用:根据特定的条件分析最新的文件夹
#FPath:存放目录的文件夹
proc VerDir {FPath } {

 #获取文件夹下所有目录信息
 set AllDir [glob -directory $FPath {*/}]
 set ODir1 [lindex $AllDir 0]
 
 #录入第一条文件夹的安装包时间.
 regexp -nocase {.*_([0-9]*).*} $ODir1 x VerTime
 set LastTime $VerTime
 set LFilePath $ODir1
 
 #把每一个文件夹的时间进行比较,取出最新的文件夹返回给函数
 for {set i 1} {$i < [llength $AllDir]} {incr i 1} {
  set ODir [lindex $AllDir $i]
  regexp -nocase {.*_([0-9]*).*} $ODir x VerSTime
  
  for {set j 0} {$j < 8} {incr j 1} {
   #这里本来想直接减,但是不知道出什么错误,结果一直是负数,就改变了方法
   set TimeRt [expr [string index $VerSTime $j] - [string index $LastTime $j]]
   if {$TimeRt > 0} {
    set LastTime  $VerSTime
    set LFilePath $ODir
    break
   }
  }

 }
 return $LFilePath
}

puts [VerDir $FilePath]


python:

import glob
# coding=utf-8
#初始化信息,后续会移动到配置文件中
FilePath = 'D:\TclAndPyhton\TestDir\\'
AllDir = glob.glob(r'D:\TclAndPyhton\TestDir\*')

#过程作用:根据特定的条件分析最新的文件夹
#FPath:存放目录的文件夹
def VerDir(AL):
 ODir1 = AL[0]
 #录入第一条文件夹的安装包时间.
 VerTime = int(ODir1[-8:])
 print VerTime
 LastTime = VerTime #LastTime 没用到额。
 LFilePath=ODir1
 
 #把每一个文件夹的时间进行比较,取出最新的文件夹返回给函数
 for  element in AL:
  VerSTime = int(element[-8:])
  print VerSTime
  TimeRt=VerSTime-LastTime
  if TimeRt > 0:
   LastTime =  VerSTime
   LFilePath=element
 return LFilePath

#非空判断
if AllDir != []:
 aaa = VerDir(AllDir)
 print aaa

后记:
python没有大括号来编写控制语句和过程比较不适应,同时字符和整形转换较多,不过语法简洁.
tcl的语法用起来没有那么简洁,但是字符串和列表的处理较好点.


TAG:

 

评分:0

我来说两句

acbennn

acbennn

站在云端看浮云,晕. CSDN的博客:http://blog.csdn.net/bullswu/article/details/6798437

日历

« 2024-04-25  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 60081
  • 日志数: 44
  • 建立时间: 2011-09-18
  • 更新时间: 2013-09-22

RSS订阅

Open Toolbar