01
~ 12
(12 개월마다 하나씩)을 나열하면 어떻게 될까요? 현재 달은 항상 가장 오래된 것이있는 곳에서 마지막으로 오게됩니다. 먼저. 즉, 그 숫자가 현재 달보다 크다면, 그것은 전년도의 것입니다.월 및 연도 산술에 기초한 파일 이름 목록 생성
02
은 2011 년 2 월 (현재 당월)이고 03
은 2010 년 3 월이고 09
은 2010 년 9 월이지만 01
은 2011 년 1 월입니다.이 경우 [09, 03, 01, 02]
을 갖고 싶습니다. 이것은 올해를 결정하기 위해 내가하고있는 일입니다.
for inFile in os.listdir('.'):
if inFile.isdigit():
month = months[int(inFile)]
if int(inFile) <= int(strftime("%m")):
year = strftime("%Y")
else:
year = int(strftime("%Y"))-1
mnYear = month + ", " + str(year)
나는 다음에해야 할 일이 하나도 없습니다. 내가 여기서 뭘해야하지?
업데이트 :
나는 생각한다, 나는 더 나은 이해를 위해 전체 스크립트를 업로드 할 수 있습니다. 내가 스크립트를 실행하면
#!/usr/bin/env python
import os, sys
from time import strftime
from calendar import month_abbr
vGroup = {}
vo = "group_lhcb"
SI00_fig = float(2.478)
months = tuple(month_abbr)
print "\n%-12s\t%10s\t%8s\t%10s" % ('VOs','CPU-time','CPU-time','kSI2K-hrs')
print "%-12s\t%10s\t%8s\t%10s" % ('','(in Sec)','(in Hrs)','(*2.478)')
print "=" * 58
for inFile in os.listdir('.'):
if inFile.isdigit():
readFile = open(inFile, 'r')
lines = readFile.readlines()
readFile.close()
month = months[int(inFile)]
if int(inFile) <= int(strftime("%m")):
year = strftime("%Y")
else:
year = int(strftime("%Y"))-1
mnYear = month + ", " + str(year)
for line in lines[2:]:
if line.find(vo)==0:
g, i = line.split()
s = vGroup.get(g, 0)
vGroup[g] = s + int(i)
sumHrs = ((vGroup[g]/60)/60)
sumSi2k = sumHrs*SI00_fig
print "%-12s\t%10s\t%8s\t%10.2f" % (mnYear,vGroup[g],sumHrs,sumSi2k)
del vGroup[g]
, 나는이 얻을 :
Sep, 2010 210874275 58576 145151.33
Dec, 2010 5064337 1406 3484.07
Jan, 2011 211201372 58667 145376.83
Feb, 2011 17506049 4862 12048.04
:
[[email protected] usage]# ./test.py
VOs CPU-time CPU-time kSI2K-hrs
(in Sec) (in Hrs) (*2.478)
==================================================
Jan, 2011 211201372 58667 145376.83
Dec, 2010 5064337 1406 3484.07
Feb, 2011 17506049 4862 12048.04
Sep, 2010 210874275 58576 145151.33
내가 원래 게시물에 말했듯이, 나는 결과가 대신 순서로 좋아 원본 디렉토리의 파일은 다음과 같습니다.
[[email protected] usage]# ls -l
total 3632
-rw-r--r-- 1 root root 1144972 Feb 9 19:23 01
-rw-r--r-- 1 root root 556630 Feb 13 09:11 02
-rw-r--r-- 1 root root 443782 Feb 11 17:23 02.bak
-rw-r--r-- 1 root root 1144556 Feb 14 09:30 09
-rw-r--r-- 1 root root 370822 Feb 9 19:24 12
더 나은 사진을 제공 했습니까? 처음부터 매우 명확하지 않은 것에 대해 유감스럽게 생각합니다. 건배!! 내가 전에 말했듯이, 나는이 순서대로 인쇄 B에 결과를 찾고 있어요
[[email protected] usage]# ./test.py
VOs CPU-time CPU-time kSI2K-hrs
(in Sec) (in Hrs) (*2.478)
==========================================================
Dec, 2010 5064337 1406 3484.07
Sep, 2010 210874275 58576 145151.33
Feb, 2011 17506049 4862 12048.04
Jan, 2011 211201372 58667 145376.83
:
업데이트 @ 마크가 몸값
이 마크의 제안의 결과입니다 : 2010 년 9 월 -> 2010 년 12 월 -> 1 월, 2011 -> 2 월, 2012 건배 !!
파일 이름이 월 단위로 명명 된 것 같습니다. – KyleWpppd
설명에 따라 필요한 출력이 [09, 03, 01, 02]가 아닌 [03, 09, 01, 02]이 될 수 있습니까? – rajeshnair
@geekGod : 맞아요. [03, 09, 01, 02]이어야합니다. 그건 내 실수 였어. – MacUsers