Python HW 2번문제
Sorce Bank 2010. 5. 6. 00:06
import os.path import glob import sys if(len(sys.argv)!=2): print("Usage : python <Script name> <Dir Name>") sys.exit(1) class Du: def searchDir(self,dirName): fileList = glob.glob(dirName) size=0; for fullFile in fileList: if os.path.isdir(fullFile): size+=self.searchDir(fullFile+"/*") else: s = os.path.getsize(fullFile) size+=s print size/1024,dirName return size test = Du() test.searchDir(sys.argv[1]+"/*")
'Sorce Bank' 카테고리의 다른 글
그래픽스 : Solar System (0) | 2010.05.11 |
---|---|
Python BST + AVL (0) | 2010.05.08 |
Python HW 1번문제 (0) | 2010.05.06 |
그래픽스 실습 4.27 (0) | 2010.04.27 |
파이썬 c API 하다 만거 (0) | 2010.04.15 |
Python HW 1번문제
Sorce Bank 2010. 5. 6. 00:05
import os.path import glob import cStringIO import os import sys if(len(sys.argv)!=2): print("Usage : python <Script name> <Dir Name>") sys.exit(1) files={} id=0 def countWord(filename): in_file = open(filename) text = in_file.read() in_file.close() strIO = cStringIO.StringIO(text) filelines = strIO.readlines() numOfWd=0 numOfLn=0 word=[] for line in filelines: word+=line.split() numOfLn+=1 for w in word: numOfWd+=1 return numOfWd, numOfLn def searchDir(dirName): fileList = glob.glob(dirName) for fullFile in fileList: if os.path.isdir(fullFile): searchDir(fullFile+"/*") else: d_name = os.path.dirname(fullFile) f_name = os.path.basename(fullFile) words,lines = countWord(fullFile) value=(d_name,f_name,lines,words) global id id+=1 files[id]=value searchDir(sys.argv[1]+"/*") f_keys = files.keys() for a in f_keys: print "id", a info = files[a] print "Path : ", info[0] print "File name : ", info[1] print "Number of lines :", info[2] print "Number of Words :",info[3]
'Sorce Bank' 카테고리의 다른 글
Python BST + AVL (0) | 2010.05.08 |
---|---|
Python HW 2번문제 (0) | 2010.05.06 |
그래픽스 실습 4.27 (0) | 2010.04.27 |
파이썬 c API 하다 만거 (0) | 2010.04.15 |
네트워크 홈워크 1 (0) | 2010.03.25 |
그래픽스 실습 4.27
Sorce Bank 2010. 4. 27. 15:56
#include#include void draw_axes(); void init(); void draw_drag(); void display(void); void mouse(int button,int status,int x, int y); void motion(int,int); int last_x,last_y; //last (x,y) position , where the left button pressed. int current_x, current_y; // current (x,y) position bool b_draw_dragbox = false; int main() { glutCreateWindow("TransFormation"); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); init(); glutMainLoop(); return 0; } void init() { glClearColor(1.0f,1.0f,1.0f,1.0f); } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set the current camera // f) extrinsic camera property, which can be specified by GL_MODELVIEW matirix // s) intrinsic camera property, which can be specified by GL_PROJECTION matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1,1,- 1,1 ,-1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // M = I gluLookAt(0, 0, 1, 0, 0, 0, 0, 1 , 0); draw_axes(); // Object를 조작함. //glRotatef(75.0f,0,0,1); // R 메트릭스 M *=R => M=R //glScalef(2.0f,2.0f,2.0f); // S 메트릭스 M *=S => M=RS glTranslatef(0.3f,0.3f,0.0f); // T 메트릭스 M *=T => M=RST // T ( S ( Rx)) // Model Matrix Continue.... M' = RSTx => T먼저 적용됨. // Draw DragBox if(b_draw_dragbox) draw_drag(); //Drawing an object (a red box) // Object는 절대 건들이지 않는다. 메트릭스만 곱해서 조절 ->그리는건 조형대 애들이. glColor3f(1.0f,0.0f,0.0f); glBegin(GL_QUADS); // ------------------------------- glVertex2f(0.5f,0.5f); glVertex2f(-0.5f,0.5f); // x메트릭스 glVertex2f(-0.5f,-0.5f); glVertex2f(0.5f,-0.5f); // ------------------------------- glEnd(); // = > Tx glFlush(); } void draw_drag() { glColor3f(0.0f,1.0f,0.0f); glBegin(GL_LINE_LOOP); glVertex2f(last_x,last_y); glVertex2f(last_x,current_y); glVertex2f(current_x,current_y); glVertex2f(current_x,last_y); glEnd(); printf("adfasd"); } void draw_axes() { glMatrixMode(GL_MODELVIEW); glBegin(GL_LINES); glColor3f(1.0f,0.0f,0.0f); glVertex2d(-5,0); glVertex2d(5,0); glColor3f(1.0f,1.0f,0.0f); glVertex2d(0,-5); glVertex2d(0,5); glEnd(); glFlush(); } void mouse(int button,int state,int x, int y) { if( button == GLUT_LEFT_BUTTON&& state == GLUT_DOWN) { printf("left mouse button is pressed!\n"); last_x = x; last_y = y; b_draw_dragbox=true; // 네모 그리고 } else if( button == GLUT_LEFT_BUTTON && state == GLUT_UP) { printf("left mouse button is Releassed!\n"); b_draw_dragbox=false; // 네모지우고 } } void motion(int x,int y) { current_x =x; current_y = y; printf("mouse is dragging : x : %d y: %d \n",x,y); }
'Sorce Bank' 카테고리의 다른 글
Python HW 2번문제 (0) | 2010.05.06 |
---|---|
Python HW 1번문제 (0) | 2010.05.06 |
파이썬 c API 하다 만거 (0) | 2010.04.15 |
네트워크 홈워크 1 (0) | 2010.03.25 |
GeneralTree to BinaryTree (2) | 2010.03.18 |