컴파일이 되었으므로, 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.
머, 중요한건 일단
1. wxPython은 Python이 있어야 작동을 하고.
2. wxPython은 wxWidgets 의 wrapper 라는 것 (그러니까 wxWidget도 설치 되어있어야 하겠지?)
음.. 근데 버전에 따라 다른가? 이제는 glib 와 gtk+ 가 필요하다고 하는군!
The first thing you'll need are the glib and gtk+
libraries. Before you run off and download the sources check your
system, you probably already have it. Most distributions of Linux come
with it and you'll start seeing it on many other systems too now that
Sun and others have chosen GNOME as the desktop of choice. If you don't
have glib and gtk+ already, you can get the sources here. Build and install them following the directions included.
In order to use the wxGLCanvas you'll need to have either OpenGL or the Mesa3D library on your system. wxPython's wx.glcanvas.GLCanvas only provides the GL Context and a wx.Window to put it in, so you will also need the PyOpenGL Python extension modules as well, if you want to use OpenGL.
If you are building wxPython yourself and don't care to use
OpenGL/Mesa then you can easily skip building it and can ignore this
step. See the build instructions for details.
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 대라고 이해하면 되겠다.(?)
문자열은 * 연산을 오버로딩 하고 있고 + 연산으로 여러가지 문장을 합쳐서 출력할수 있다.
(마이너스와 나누기는 안되는듯)
리스트는 배열과 비슷하게 사용이 가능하고
list[0:0] = [value] 이런식으로 리스트의 특정 위치에 값을 추가 할수 있다.
list[0:1] 하면 0번째 에서 1번째 미만의 값을 출력한다.(머 실질적으로 배열에서 0번째 값을 출력하는 셈이다)
리스트를 선언하려면
var = []
라고 선언하고 추후에 추가해주면된다.
사전도 리스트와 비슷하지만
문자열로 값을 찾아야 하고, 값과 숫자를 묶어서 입력해야 한다.
사전을 선언하려면
var = {}
라고 선언하고 추후에 추가해주면된다.
Another useful data type built into Python is the dictionary (see
Mapping Types — dict). Dictionaries are sometimes found in other languages as
“associative memories” or “associative arrays”. Unlike sequences, which are
indexed by a range of numbers, dictionaries are indexed by keys, which can be
any immutable type; strings and numbers can always be keys. Tuples can be used
as keys if they contain only strings, numbers, or tuples; if a tuple contains
any mutable object either directly or indirectly, it cannot be used as a key.
You can’t use lists as keys, since lists can be modified in place using index
assignments, slice assignments, or methods like append() and
extend().
솔찍히 이해를 못한 부분인데, 간단한 함수를 만드는 것 같다.
함수 포인터 같기도 한데 LISP에서 따왔다고도 하는데 먼소리인지 안드로메다로.
Python supports the creation of anonymous functions
(i.e. functions that are not bound to a name) at
runtime, using a construct called "lambda".
>>> def f (x): return x**2 ... >>> print f(8)
64
>>> >>> g = lambda x: x**2 >>> >>> print g(8)
64
As you can see, f() and g() do exactly the same and can be
used in the same ways. Note that the lambda definition
does not include a "return" statement -- it always contains
an expression which is returned. Also note that you can
put a lambda definition anywhere a function is expected,
and you don't have to assign it to a variable at all.
By popular demand, a few features commonly found in functional programming
languages like Lisp have been added to Python. With the lambda
keyword, small anonymous functions can be created. Here’s a function that
returns the sum of its two arguments: lambdaa,b:a+b. Lambda forms can be
used wherever function objects are required. They are syntactically restricted
to a single expression. Semantically, they are just syntactic sugar for a
normal function definition. Like nested function definitions, lambda forms can
reference variables from the containing scope: