Retrieve an
attribute named attr_name from object o. Returns the
attribute
value on success, or NULL on failure. This is the equivalent of
the Python
expression o.attr_name.
파이썬에서 문자열은 " 나 ' 로 표시가 된다.
하지만 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
위는 전형적인 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
Py_DECREF() 함수는 PyObject 변수의 참조의 값을 줄어주며,
python 자체의 garbage collector를 호출하여, 사용하지 않는 변수를 청소하는 역활을 한다.
아무튼, PyObject를 선언하고 사용후 종료하게 되면
Exception AttributeError: "'module' object has no attribute 'YouTubeService'" in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection
컴파일이 되었으므로, pyc나 pyo는 py에 비해 속도 향상이 있으며
pyc는 py를 -O 옵션을 통해(모든 py파일에서 pyc를 생성)
pyo는 py를 -OO 옵션을 통해 생성이 가능하다.
(이부분은 확인필요. py 파일을 이상없이 실행가능하면 컴파일 가능하며, 자동으로 pyc가 생성된다고 하지만, 밑에
-O 옵션으로 디렉토리 내의 모든 py를 pyc로 컴파일 한다는 내용도 존재한다.)
pyc는 assert 문만을 삭제함으로 속도 향상폭은 크지 않으며
pyo는 pyc에 비해 __doc__ 구분도 삭제하므로 더욱 작이진다.(일부 프로그램은 __doc__ 구분 사용할수 있으니 주의)
6.1.3. “Compiled” Python files
As an important speed-up of the start-up time for short programs that use a lot
of standard modules, if a file called spam.pyc exists in the directory
where spam.py is found, this is assumed to contain an
already-“byte-compiled” version of the module spam. The modification time
of the version of spam.py used to create spam.pyc is recorded in
spam.pyc, and the .pyc file is ignored if these don’t match.
Normally, you don’t need to do anything to create the spam.pyc file.
Whenever spam.py is successfully compiled, an attempt is made to write
the compiled version to spam.pyc. It is not an error if this attempt
fails; if for any reason the file is not written completely, the resulting
spam.pyc file will be recognized as invalid and thus ignored later. The
contents of the spam.pyc file are platform independent, so a Python
module directory can be shared by machines of different architectures.
Some tips for experts:
When the Python interpreter is invoked with the -O flag, optimized
code is generated and stored in .pyo files. The optimizer currently
doesn’t help much; it only removes assert statements. When
-O is used, allbytecode is optimized; .pyc files are
ignored and .py files are compiled to optimized bytecode.
Passing two -O flags to the Python interpreter (-OO) will
cause the bytecode compiler to perform optimizations that could in some rare
cases result in malfunctioning programs. Currently only __doc__ strings are
removed from the bytecode, resulting in more compact .pyo files. Since
some programs may rely on having these available, you should only use this
option if you know what you’re doing.
A program doesn’t run any faster when it is read from a .pyc or
.pyo file than when it is read from a .py file; the only thing
that’s faster about .pyc or .pyo files is the speed with which
they are loaded.
When a script is run by giving its name on the command line, the bytecode for
the script is never written to a .pyc or .pyo file. Thus, thet
startup time of a scrip may be reduced by moving most of its code to a module
and having a small bootstrap script that imports that module. It is also
possible to name a .pyc or .pyo file directly on the command
line.
It is possible to have a file called spam.pyc (or spam.pyo
when -O is used) without a file spam.pyfor the same module.
This can be used to distribute a library of Python code in a form that is
moderately hard to reverse engineer.
The module compileall can create .pyc files (or .pyo
files when -O is used) for all modules in a directory.
아마 2.4와 2.6이 혼합되어 설치되어있고, 2.6이 정상설치가 되지 않은듯 싶다.
옵션에 따라서 이러한 오류가 발생했다.
# gcc py.c -I/usr/local/include/python2.6 -L/usr/local/lib/libpython2.6.a
/tmp/cc88iTD7.o: In function `main':
py.c:(.text+0x12): undefined reference to `Py_Initialize'
py.c:(.text+0x26): undefined reference to `PyRun_SimpleStringFlags'
py.c:(.text+0x2b): undefined reference to `Py_Finalize'
collect2: ld returned 1 exit status
# gcc py.c -I/usr/local/include/python2.6 -lpython2.6
/usr/local/lib/libpython2.6.a(posixmodule.o): In function
`posix_tmpnam':
./Modules/posixmodule.c:7180: warning: the use of `tmpnam_r' is
dangerous, better use `mkstemp'
/usr/local/lib/libpython2.6.a(posixmodule.o): In function
`posix_tempnam':
./Modules/posixmodule.c:7135: warning: the use of `tempnam' is
dangerous, better use `mkstemp'
/usr/local/lib/libpython2.6.a(signalmodule.o): In function
`timeval_from_double':
./Modules/signalmodule.c:106: undefined reference to `floor'
./Modules/signalmodule.c:107: undefined reference to `fmod'
./Modules/signalmodule.c:106: undefined reference to `floor'
./Modules/signalmodule.c:107: undefined reference to `fmod'
/usr/local/lib/libpython2.6.a(floatobject.o): In function `float_pow':
Objects/floatobject.c:972: undefined reference to `pow'
/usr/local/lib/libpython2.6.a(floatobject.o): In function
`float_divmod':
Objects/floatobject.c:856: undefined reference to `fmod'
/usr/local/lib/libpython2.6.a(floatobject.o): In function `float_rem':
Objects/floatobject.c:834: undefined reference to `fmod'
/usr/local/lib/libpython2.6.a(longobject.o): In function
`PyLong_FromString':
Objects/longobject.c:1610: undefined reference to `log'
Objects/longobject.c:1610: undefined reference to `log'
/usr/local/lib/libpython2.6.a(dynload_shlib.o): In function
`_PyImport_GetDynLoadFunc':
Python/dynload_shlib.c:94: undefined reference to `dlsym'
Python/dynload_shlib.c:130: undefined reference to `dlopen'
Python/dynload_shlib.c:141: undefined reference to `dlsym'
Python/dynload_shlib.c:133: undefined reference to `dlerror'
/usr/local/lib/libpython2.6.a(thread.o): In function
`_pythread_pthread_set_stacksize':
Python/thread_pthread.h:519: undefined reference to
`pthread_attr_setstacksize'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_release_lock':
Python/thread_pthread.h:374: undefined reference to `sem_post'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_free_lock':
Python/thread_pthread.h:320: undefined reference to `sem_destroy'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_allocate_lock':
Python/thread_pthread.h:296: undefined reference to `sem_init'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_acquire_lock':
Python/thread_pthread.h:351: undefined reference to `sem_trywait'
Python/thread_pthread.h:349: undefined reference to `sem_wait'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_start_new_thread':
Python/thread_pthread.h:171: undefined reference to
`pthread_attr_setstacksize'
Python/thread_pthread.h:181: undefined reference to `pthread_create'
Python/thread_pthread.h:197: undefined reference to `pthread_detach'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_release_lock':
Python/thread_pthread.h:374: undefined reference to `sem_post'
Python/thread_pthread.h:374: undefined reference to `sem_post'
Python/thread_pthread.h:374: undefined reference to `sem_post'
/usr/local/lib/libpython2.6.a(thread.o): In function
`PyThread_allocate_lock':
Python/thread_pthread.h:296: undefined reference to `sem_init'
Python/thread_pthread.h:296: undefined reference to `sem_init'
/usr/local/lib/libpython2.6.a(posixmodule.o): In function
`posix_forkpty':
posixmodule.c:(.text+0x2653): undefined reference to `forkpty'
/usr/local/lib/libpython2.6.a(posixmodule.o): In function
`posix_openpty':
posixmodule.c:(.text+0x26fc): undefined reference to `openpty'
/usr/local/lib/libpython2.6.a(complexobject.o): In function `_Py_c_abs':
Objects/complexobject.c:214: undefined reference to `hypot'
/usr/local/lib/libpython2.6.a(complexobject.o): In function `_Py_c_pow':
Objects/complexobject.c:143: undefined reference to `hypot'
Objects/complexobject.c:144: undefined reference to `pow'
Objects/complexobject.c:145: undefined reference to `atan2'
Objects/complexobject.c:151: undefined reference to `cos'
Objects/complexobject.c:152: undefined reference to `sin'
Objects/complexobject.c:148: undefined reference to `exp'
Objects/complexobject.c:149: undefined reference to `log'
collect2: ld returned 1 exit status
x86 계열에서 메모리 팍팍 쓰면서 속도를 향상시켜준다는,
마법의(!?) JIT(Just In Time) compiler 이다.
결론은.. x86이 아니면 안되는군 ㅠ.ㅠ
What you can do with it
In short: run your existing Python software much faster, with no change in your source.
Think of Psyco as a kind of just-in-time (JIT) compiler, a little bit like what exists for other languages, that emit machine code on the fly instead of interpreting your Python program step by step. The difference with the traditional approach to JIT compilers is that Psyco writes several version of the same blocks (a block is a bit of a function), which are optimized by being specialized to some kinds of variables (a "kind" can mean a type, but it is more general). The result is that your unmodified Python programs run faster.
Benefits
2x to 100x speed-ups, typically 4x, with an unmodified Python interpreter and unmodified source code, just a dynamically loadable C extension module.
Drawbacks
Psyco currently uses a lot of memory. It only runs on Intel 386-compatible processors (under any OS) right now. There are some subtle semantic differences (i.e. bugs) with the way Python works; they should not be apparent in most programs.
Python 2.6 이라고 명시한 이유는, 3.0 에서는 없어지거나 이름이 바뀌었기 때문이다.
htmllib Deprecated since version 2.6: The htmllib module has been removed in Python 3.0. urlib
The urllib module has been split into parts and renamed in
Python 3.0 to urllib.request, urllib.parse,
and urllib.error. httplib
The httplib module has been renamed to http.client in Python
3.0. The 2to3 tool will automatically adapt imports when converting
your sources to 3.0.
아무튼, 파이썬 프로젝트 분석시에 버전 정보가 애매모호하면 htmllib가 존재하면 2.6.x 대라고 이해하면 되겠다.(?)