파이썬 2.7과 파이썬 3.3 두가지 버전이 있어서 무슨 차이가 있나 찾아보니
2.7이후로는 업데이트도 하지 않을 것이기에 3.3을 쓰라고 되어 있다.

2.x에서 3.x으로 이전하게 된 이유가
과거의 잘못 구현된 부분을 바로잡기 위함이기에
5년 정도의 이전기간을 고려하고 있다고 하는데
다르게 말하면 한동안 2.7을 사용해야만 하고
나중에 3.x대로 이전을 반드시 해야 하지만 그동안 언어가 살아있을지도 조금 의문이 되는 상황...

[링크 : http://wiki.python.org/moin/Python2orPython3]
[링크 : http://docs.python.org/3/whatsnew/3.0.html]

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

python smtplib의 신비..?  (0) 2016.12.30
python이 인기라는데..  (0) 2014.03.19
PyOpenGL  (0) 2011.10.04
python 3.2.2 64bit 버전 설치  (4) 2011.09.13
python 버전 골라서 실행하기  (0) 2011.05.08
Posted by 구차니
Python의 openGL 바인딩이다.
linux 개발용 노트북을 해놔서 C를 통해 개발을 해도 상관은 없지만
다른 언어도 배울겸 한번 openGL을 python으로 하면 어떨까? 싶어서 찾아본 내용인데 흐음..
함수 이름이라던가 거의 100% C와 동일한데 별 의미가 없으려나?

import OpenGL 
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import * 

[링크 : http://pyopengl.sourceforge.net/]
[링크 : http://pypi.python.org/pypi/PyOpenGL-Demo] demo 

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

python이 인기라는데..  (0) 2014.03.19
python2 vs python3  (0) 2013.01.02
python 3.2.2 64bit 버전 설치  (4) 2011.09.13
python 버전 골라서 실행하기  (0) 2011.05.08
python C/api - PyObject_GetAttrString()  (0) 2010.04.06
Posted by 구차니
이유는 모르겠지만 Windows7 Ultimate 64bit 버전에서 윈도우즈 업데이트를 진행하며 실행하니 오류가 발생했다.
리부팅하고 나니 문제없이 넘어가서 대략 황당 -ㅁ-


 

 

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

python2 vs python3  (0) 2013.01.02
PyOpenGL  (0) 2011.10.04
python 버전 골라서 실행하기  (0) 2011.05.08
python C/api - PyObject_GetAttrString()  (0) 2010.04.06
파이썬 문자열 쌍따옴표 세개 - """ python string  (0) 2010.04.04
Posted by 구차니
pythonbrew 라는 녀석이 있어서, 여러개 버전을 설치해서 골라가며 실행을 할 수 있다고 한다.

[링크 :  http://kldp.org/node/122865]
  [링크 : http://gauryan.blogspot.com/2011/05/pythonbrew-python.html]

[링크 : https://github.com/utahta/pythonbrew]

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

PyOpenGL  (0) 2011.10.04
python 3.2.2 64bit 버전 설치  (4) 2011.09.13
python C/api - PyObject_GetAttrString()  (0) 2010.04.06
파이썬 문자열 쌍따옴표 세개 - """ python string  (0) 2010.04.04
python c/api 관련문서  (0) 2010.03.25
Posted by 구차니
PyObject_GetAttrString() 함수는 파이썬 내의 변수 객체를 받아오는 녀석이다.

PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name)
Return value: New reference.

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.


[링크 : http://docs.python.org/c-api/object.html#PyObject_GetAttrString]

문제는 PyObject *o 인데, o는 전체를 의미하는 __main__을 사용하면 될듯하다.
아무튼 간략하게 사용하자면, 이런식으로 문자열을 출력 가능하다.

    Py_Initialize();
        PyRun_SimpleString("teststr=\"test test\"");

        PyObject* po_main = PyImport_AddModule("__main__");
        PyObject* po_dict = PyObject_GetAttrString(po_main, "teststr");

        printf("teststr [%s]\n",PyString_AsString(po_dict));

        Py_DECREF(po_main);
        Py_DECREF(po_dict);

    Py_Finalize();


[링크 : http://koichitamura.blogspot.com/2008/06/this-is-small-python-capi-tutorial.html]
Posted by 구차니
파이썬에서 문자열은 " 나 ' 로 표시가 된다.
하지만 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 구차니
c에서 python을 쓰는건 embedding 이라고 하고
python에서 c를 쓰는건 extend(확장) 이라고 한다.

[링크 : http://kukuta.tistory.com/69]
[링크 : http://kukuta.tistory.com/83]
[링크 : http://kukuta.tistory.com/91]
[링크 : http://kukuta.tistory.com/92]
[링크 : http://www.codeproject.com/KB/cpp/embedpython_1.aspx]
[링크 : http://koichitamura.blogspot.com/2008/06/this-is-small-python-capi-tutorial.html]
Posted by 구차니
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
이런 에러가 발생했다.

[링크 : http://docs.python.org/c-api/refcounting.html?highlight=py_decref#Py_DECREF]
Posted by 구차니
import 라는 키워드로 python에서는 모듈을 불러온다.
이녀석을 c/api에서 사용하는 방법은 크게 두가지가 있다.

하나는 문자열로 인터프리트 방식으로 import 명령을 실행하는 것과
PyRun_SimpleString("import hashlib");

다른 하나는, __main__ 모듈을 추가하고 그에 원하는 모듈을 import 하는 방식이다.
PyObject * mainModule = PyImport_AddModule("__main__");
PyObject * hashlibModule = PyImport_ImportModule("hashlib");
PyModule_AddObject(mainModule, "hashlib", hashlibModule);

[링크 : http://dmaggot.wordpress.com/2009/12/30/embed-python-and-import-modules-in-cc/]



사족 : 음.. curses 나 hashlib은
/usr/local/lib/python2.6/hashlib.py
/usr/local/lib/python2.6/curses/__init__.py
에 존재해서 위의 방법으로 import가 되지만

gdata(google api)의 경우에는 되지가 않는다. 도대체 머가 문제일까?
/usr/local/lib/python2.6/site-packages/gdata/__init__.py 도 일단은 존재하는데 말이다..

Posted by 구차니
아무 생각없이 libpython.so만 복사했더니 아래와 같은 경고가 발생한다.

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
'import site' failed; use -v for traceback

머 실행결과는 나오니까 (단순한 print 테스트) 경고라고 했지만
아마 import os 등을 하면 에러가 났을것으로 생각이 된다.

해결방법은 (Python2.6 기준 기본값으로)
/usr/local/lib/python2.6 디렉토리를 복사해주면 된다.
(python2.6 아래에는 각종 *.py *.pyo *.pyc

덧 : Python2.6 기준으로
# du -h python2.6
75M     python2.6/
용량이 좀.. 안습이다?!
Posted by 구차니