본문 바로가기

2013/07

TextView setTextColor 설정 String strColor = "#000000";btn1.setTextColor(Color.parseColor(strColor)); 더보기
모듈 임포트 파헤치기 import simpleset을 실행하면 simpleset.pyc 파일이 생성 됨pyc 파일이 생성된 다음 import 구문을 실행하면 별도의 인터프리팅 없이 어트리뷰트를 현재의 이름공간으로 가져오거나 모듈의 이름을 현재 이름공간으로 가져 옴 testmodule.py 생성 후 저장# -*- coding: cp949 -*-print("test module")defaultvalue = 1def printDefaultValue():print(defaultvalue) >>> import testmoduletest module>>> testmodule.printDefaultValue()1 testmodule.py의 코드를 수정 # -*- coding: cp949 -*-print("hello world")defau.. 더보기
모듈 임포트 import 구문을 어디서나 사용>>> def loadMathMod():print("import math")import mathprint(dir(math)) >>> loadMathMod()import math['__doc__', '__file__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isfinite', 'isi.. 더보기
모듈 만들기 # -*- coding: cp949 -*-from functools import * def intersect(*ar):"교집합"return reduce(__intersectSC, ar) def __intersectSC(listX, listY):setList = []for x in listX:if x in listY:setList.append(x)return setList def difference(*ar):"차집합"setList = []intersectSet = intersect(*ar)unionSet = union(*ar)for x in unionSet:if not x in intersectSet:setList.append(x)return setListdef union(*ar):"합집합"setList .. 더보기
다중상속 # -*- coding: cp949 -*- class Tiger: def Jump(self): print("호랑이처럼 멀리 점프하기") class Lion: def Bite(self): print("사자처럼 한입에 꿀꺽하기") class Liger(Tiger, Lion): def Play(self): print("라이거만의 사육사와 재미잇게 놀기 ") l = Liger() l.Bite() l.Jump() l.Play() 사자처럼 한입에 꿀꺽하기 호랑이처럼 멀리 점프하기 라이거만의 사육사와 재미잇게 놀기 다중 상속 시 메서드의 이름 검색 방법# -*- coding: cp949 -*- class Tiger: def Jump(self): print("호랑이처럼 멀리 점프하기") def Cry(self): pr.. 더보기
상속 부모클래스>>> class Person:" Paretn class "def __init__(self, name, phoneNumber):self.Name = nameself.PhoneNumber = phoneNumberdef PrintInfo(self):print("Info(Name:{0}, Phone Number: {1})".format(self.Name, self.PhoneNumber))def PrintPersonData(self):print("Person(Name:{0}, Phone Number: {1})".format(self.Name, self.PhonNumber)) 자식클래스>>> class Student(Person):"child class"def __init__(self, name, pho.. 더보기
연산자 중복 정의 메서드로 동작 시키지 않고 연산자로 메서드를 동작 시킬 수 있다 >>> class GString:def __init__(self, init=None):self.content = initdef __sub__(self, str):for i in str:self.content = self.content.replace(i,'')return GString(self.content)def Remove(self, str):return self.__sub__(str) >> g = GString("ABCDEFGabcdefg")>>> g.Remove("Adg")>>> g.content'BCDEFGabcef'>>> g - "Bcf">>> g.content'CDEFGabe' __sub__는 연산자 중복을 위해 미리 정의된 특별.. 더보기
정적메서드, 클래스메서드 정적메서드 - 인스턴스 객체를 통하지 않고 클래스를 직접 호출할 수 있는 메서드클래스메서드 - 암묵적으로 첫 인자로 클래스 객체가 전달두 경우 모두 클래스 내에서 등록해야 함 = staticmethod(클래스 내에 정의한 메서드 이름) = classmethod(클래스 내에 정의한 메서드 이름) >>> class CounterManager:insCount = 0def __init__(self):CounterManager.insCount += 1def printInstaceCount():print("Instance Count: ", CounterManager.insCount)>>> a, b, c = CounterManager(), CounterManager(), CounterManager()>>> Count.. 더보기
생성자, 소멸자 메서드 생성자 메서드 __init__()소멸자 메서드 __del__()>>> class MyClass: def __init__(self, value): self.Value = value print("Class is created! Value = ", value) def __del__(self): print("Class is deleted!") >>> def foo(): d = MyClass(10) >>> foo() Class is created! Value = 10 Class is deleted! >>> class MyClass: def __init__(self, value): self.Value = value print("Class is created! Value = ", value) def __del__(s.. 더보기
클래스 객체와 인스턴스 객체의 관계 인스턴스 객체가 어떤 클래스로부터 생성됐는지 확인하는 방법isinstance(인스턴스 객체, 클래스 객체) >>> class Person: pass >>> class Bird: pass >>> class Student(Person): pass >>> p, s = Person(), Student() >>> print("p is instance of Person: ", isinstance(p, Person)) p is instance of Person: True >>> print("p is instance of Person: ", isinstance(s, Person)) > print("p is instance of Person: ", isinstance(p, object)) > print("p is ins.. 더보기