본문 바로가기

컴퓨터

raise 구문 의도적으로 예외 발생 raise[Exception] 해당 예외를 발생raise[Exception(data)] 예외 발생 시 관련 데이터를 전달raise 발생된 예외를 상위로 전달 내장 예외 발생 예제>>> def RaiseErrorFunc():raise NameError>>> try:RaiseErrorFunc()except:print("NameError is Catched")NameError is Catched 내장 예외 전달 예제>>> def RaiseErrorFunc():raise NameError("Parameter of NameError")>>> def PropagateError():try:RaiseErrorFunc()except:print("before")raise>>> PropagateErro.. 더보기
사용자정의 예외 >>> class NegativeDivisionError(Exception): >> def PositiveDivide(a, b):if(b > try:ret = PositiveDivide(10, -3)print('10 / 3 = {0}'.format(ret))except NegativeDivisionError as e:print("Error - Second argument of PositiveDivide is ", e.value)except ZeroDivisionError as e:print("Error - ", e.args[0])except:print("Unexpected exception") Error - Second argument o.. 더보기
예외처리 try 블록예외가 예상되는 부분에 작성 except 블록에외발생 시 처리를 담당하는 부분 else 블록예외가 발생하지 않은 경우 수행 finally 블록예외발생과 상관 없이 수행 >>> def divide(a, b):return a/b>>> try:c = divide(5, 0)except:print("Exception is occured!!")Exception is occured!! 처리할 예외를 명시 할 수 있다.>>> def divide(a, b):return a/b>>> try:c = divide(5, 'string')except ZeroDivisionError:print('ZeroDivisonError.')except TypeError:print("TypeError")except:print("I .. 더보기
JAVA에서 높이 넓이 설정 m_viewFlipper = (ViewFlipper)findViewById(R.id.viewFlipper1);LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 0);m_viewFlipper.setLayoutParams(lp); 더보기
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.. 더보기