ITeye博客

python

ericFang · 2009-09-04 15:18 · 编程语言 · Markdown

import os
filenames=os.listdir(os.getcwd())
num=raw_input('請輸入一個數字:')
for name in filenames:
 filenames[filenames.index(name)]=name[:-int(num)]
out=open('names.txt','w')
for name in filenames:
 out.write(name+'\n')
out.close()

 

 

try:
 filename=raw_input("eric")
 fobj=open(filename,'r')
 for eachLine in fobj:
  print eachLine,
 fobj.close()
except IOError e:

评论(1)

  1. #1 楼 · ericFang · 2011-04-18 18:41
    
    def getItemStandard(versionNumber,itemId):
        """
        versionNumber 版本号是excel中工作表的名称,如:ENIP_SUSE_V100R003C03
        itemId 巡检项对应的文件名,如:Item00_01_02
        得到对itemId的巡检标准
        """
        itemId = itemId.strip()
        itemStandard = None
        app = win32com.client.Dispatch('Excel.Application')
    #    app.Visible = 1#不显示excel
        book = app.Workbooks.Open("E:\\ENIP_SUSE_V100R003C03.xls")
        sheet = book.Worksheets(versionNumber)#得到相应的工作表  
        sheetColumns = sheet.UsedRange.Columns(1)#得到工作表的第一列的实例
        totalRowCount = sheetColumns.Rows.Count#得到总的行数
        sheetCells = sheetColumns.Cells#得到一列的所有单元格对象
        #循环找到对应itemId的标准
    #   print totalRowCount
        i = 1 
        while i < totalRowCount:
            tmpCell = sheetCells[i] #得到单元格对象
            tempItemId = str(tmpCell.Value)#得到单元格内容
    #       print tempItemId + "  row:"+str(rowValue)+"  col:"+str(3)+" i="+str(i)
            if itemId == tempItemId:
                rowValue = tmpCell.Row #得到单元格行数
                colValue = tmpCell.Column + 2 #得到单元格列数
                itemStandard = sheet.Cells (rowValue, 3).Value#得到itemId对应的标准值                
                break
            else:
                i = i+1
        app.ActiveWorkbook.Close()
        #book.Close()
        #app.Quit()
        return itemStandard
    
    

评论功能维护中,当前仅展示历史评论。