나름분류해서써보기173 파이썬 공부하기_모듈 만들고 불러보기 ( if __name__ == "__main__" ) https://wikidocs.net/29 mod1.py이라는 파일에sum 이라는 함수만 정의하기python 인터프리터를 실행>import 모듈이름(= 모듈이름이란, .py 확장자를 제거한 mod1만을 말함) 함수 sum이 제대로 동작하는지호출해보기 [root@tpl-master module]# cat mod1.pydef sum(a,b):return a+b[root@iaas-dms2-mysql-tpl-master module]# python Python 2.6.4 (r264:75706, Oct 23 2012, 16:21:35) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 Type "help", "copyright", "credits" or "license" f.. 2015. 11. 10. 파이썬 공부하기_클래스 (상속, 함수 오버라이딩, 연산자 + 오버라이딩) https://wikidocs.net/87 Person 이라는 부모클래스 /Person을 상속받은Baby 클래스를 선언class Baby(Person): def eat(self): return "bottle^^" def play(self): return "burning!" 부모클래스에eat 이라는 함수를 오버라이딩class Baby(Person):def eat(self):return "bottle^^"def play(self): return "burning!" Person 이라는 클래스를 선언하고, Baby 클래스는 Person을 상속받는다. ptr 은 Person 인스턴스, zzazzan 은 Baby 인스턴스를. 그리고eat이라는 메소드를 호출해보자. Baby 에 맞는 eat함수 결과가 나왔는지 확인하.. 2015. 11. 10. 드디어 클래스! 아. 드디어 객체지향까지 왔구나 (참고 https://wikidocs.net/85 , https://wikidocs.net/28 ) 객체와 인스턴스의 차이 클래스에 의해서 만들어진 객체를 인스턴스라고도 한다. 그렇다면 객체와 인스턴스의 차이는 무엇일까? 이렇게 생각 해 보자. cat = Animal() 이렇게 만들어진 cat은 객체이다. 그리고 cat이라는 객체는 Animal의 인스턴스(instance)이다. 즉 인스턴스라는 말은 특정 객체(cat)가 어떤 클래스(Animal)의 객체인지를 관계위주로 설명할 때 사용된다. 즉, "cat은 인스턴스" 보다는 "cat은 객체"라는 표현이 / "cat은 Animal의 객체" 보다는 "cat은 Animal의 인스턴스" 라는 표현이 훨씬 잘 어울린다. 클래스안에서.. 2015. 11. 10. 파이썬 공부하기_파일 다루기 https://wikidocs.net/82 한줄씩 다루기현재경로에있는파일 읽기import ospwd = os.getcwd()f = open(pwd+'/fileTest.log')line = f.read()현재경로에파일 쓰기letter =open(pwd+'/letter-'+ number +'.log', 'a+')letter.write(number +' th letter') letter.write('\n') letter.write('hi. i am catherine') letter.close() 파일 한줄 읽기: \n 이 나타나면 stop line = f.readline() 스크립트 전문이다. [lhr@master python]# cat handleFile.py #!/usr/bin/python ## read .. 2015. 11. 10. 이전 1 ··· 34 35 36 37 38 39 40 ··· 44 다음