'pydoc'에 해당되는 글 1건

  1. 2010.04.04 파이썬 문자열 쌍따옴표 세개 - """ python string
파이썬에서 문자열은 " 나 ' 로 표시가 된다.
하지만 HTML의 <PRE> 태그 처럼 """ 를 사용하면 엔터표시 없이 보이는대로 출력해주는 특이한(?!) 문법이 존재한다.
처음에는 도대체 이녀석을 왜쓸까? 했는데,
python 자체 util 인 pydocs가 문서화를 하는데 __doc__ 사용한다고 한다.

아래는 파이썬 튜토리얼중 문자열에 대한 부분인데,
단순하게 사용법을 출력하기 위해 \n 없이 문자열을 입력하는 것을 보여준다.

Or, strings can be surrounded in a pair of matching triple-quotes: """ or '''. End of lines do not need to be escaped when using triple-quotes, but they will be included in the string.

print """
Usage: thingy [OPTIONS]
     -h                        Display this usage message
     -H hostname               Hostname to connect to
"""

produces the following output:
Usage: thingy [OPTIONS]
     -h                        Display this usage message
     -H hostname               Hostname to connect to

[링크 : http://docs.python.org/tutorial/introduction.html#strings]

파이썬 class 문서로서, """A Simple example class"" 는
MyClass.__doc__ attribute로 문자열로 인식이 되며, pydocs나 doxygen에서
이를 이용하여 함수의 간략한 설명을 넣는데 이용될 수 있다.

class MyClass:
    """A simple example class"""
    i = 12345
    def f(self):
        return 'hello world'

[링크 : http://docs.python.org/tutorial/classes.html]


위는 전형적인 python 의 주석 스타일이며, 아래는 doxygen을 위한 주석 스타일이다.
그러고 보니.. 파이썬도 #를 이용한 주석을 인정하는군..(Makefile이나 쉘 스크립트는 #로 시작하는 줄은 주석으로 인식함)

For Python there is a standard way of documenting the code using so called documentation strings. Such strings are stored in __doc__ and can be retrieved at runtime. Doxygen will extract such comments and assume they have to be represented in a preformatted way.

"""@package docstring
Documentation for this module.

More details.
"""

def func():
    """Documentation for a function.

    More details.
    """
    pass



## @package pyexample
#  Documentation for this module.
#
#  More details.

## Documentation for a function.
#
#  More details.
def func():
    pass

[링크 : http://www.stack.nl/~dimitri/doxygen/docblocks.html]

'Programming > python(파이썬)' 카테고리의 다른 글

python 버전 골라서 실행하기  (0) 2011.05.08
python C/api - PyObject_GetAttrString()  (0) 2010.04.06
python c/api 관련문서  (0) 2010.03.25
python c/api - Py_DECREF  (0) 2010.03.25
python c/api 에서 모듈 불러오기  (0) 2010.03.19
Posted by 구차니