#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11

    Creating your own Libs


    hi

    I was wondering for a long time...

    How would I create my own pure python Libraries?

    like for networks or soemthing
    Those people who think they know everything are a great annoyance to those of us who do.
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Very simply, you make a Python file with whatever functions, classes variables etc. that you want and you save it somewhere that Python can see any location given in the sys.path list. You can then import it using its filename without the .py extension.

    Note: It's a bad idea to give your module the same name as another module since this can lead to import errors and alike.

    Hope this helps,

    Mark.

    Comments on this post

    • Yegg` agrees
    • LinuxPenguin agrees
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    well I meant like for example a graphical library?
    Those people who think they know everything are a great annoyance to those of us who do.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    35
    How would I create my own pure python Libraries?
    If your graphics library is "pure Python", then write the Python and save it in an accessible folder - somewhere in the PATH or maybe in PYTHONPATH as well, I'm not sure.

    If it's not pure Python, then it may be C or C++ wrapped in Python - in which case you need something like CTypes which allows you to call functions in DLLs with Python.

    I have got it to drive the BASS audio library from Python.

    For more performance, e.g. a graphics library, you wont be writing anything much in Python, you will need an extension written in C...
    See: Extending and Embedding Python.

IMN logo majestic logo threadwatch logo seochat tools logo