Python Distilled

Discussion in 'Python' started by Simon Wittber, Nov 6, 2006.

  1. I want to build a Python2.5 interpreter for an embedded system. I only
    have 4MB of RAM to play with, so I want to really minimise the python
    binary.

    Things I can think of removing safely are:
    - Unicode
    - Long numbers
    - Complex number
    - Compiler / Parser
    - Thread support
    - OS specific stuff

    I'd also like to remove any deprecated or stuff which is left in for
    backwards functionality (eg Classic classes).

    Google tells me that people have done this before, back in Python1.5.2
    days. Has anyone tried to do this recently with a more modern Python?

    -Sw.
    Simon Wittber, Nov 6, 2006
    #1
    1. Advertising

  2. In <>, Simon Wittber
    wrote:

    > I'd also like to remove any deprecated or stuff which is left in for
    > backwards functionality (eg Classic classes).


    Classic classes are still needed for exceptions:

    >>> class E(object):

    .... pass
    ....
    >>> raise E

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: exceptions must be classes, instances, or strings (deprecated),
    not type

    Ciao,
    Marc 'BlackJack' Rintsch
    Marc 'BlackJack' Rintsch, Nov 6, 2006
    #2
    1. Advertising

  3. Simon Wittber

    Georg Brandl Guest

    Marc 'BlackJack' Rintsch wrote:
    > In <>, Simon Wittber
    > wrote:
    >
    >> I'd also like to remove any deprecated or stuff which is left in for
    >> backwards functionality (eg Classic classes).

    >
    > Classic classes are still needed for exceptions:
    >
    >>>> class E(object):

    > ... pass
    > ...
    >>>> raise E

    > Traceback (most recent call last):
    > File "<stdin>", line 1, in <module>
    > TypeError: exceptions must be classes, instances, or strings (deprecated),
    > not type


    The error is a bit misleading, since in Python 2.5 all exceptions are new-style,
    but new exception classes must be derived from an existing one.
    Classic classes, their instances and strings are only allowed for backwards
    compatibility.

    Georg
    Georg Brandl, Nov 6, 2006
    #3
  4. Simon Wittber

    Jorge Godoy Guest

    Marc 'BlackJack' Rintsch <> writes:

    > In <>, Simon Wittber
    > wrote:
    >
    >> I'd also like to remove any deprecated or stuff which is left in for
    >> backwards functionality (eg Classic classes).

    >
    > Classic classes are still needed for exceptions:
    >
    >>>> class E(object):

    > ... pass
    > ...
    >>>> raise E

    > Traceback (most recent call last):
    > File "<stdin>", line 1, in <module>
    > TypeError: exceptions must be classes, instances, or strings (deprecated),
    > not type


    On the other hand...

    >>> import exceptions
    >>> class E(exceptions.Exception):

    .... pass
    ....
    >>> raise E

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    __main__.E
    >>>



    This also has the advantage to let it explicit in the code that E is an
    exception.


    --
    Jorge Godoy <>
    Jorge Godoy, Nov 6, 2006
    #4
  5. Simon Wittber

    Paul McGuire Guest

    "Marc 'BlackJack' Rintsch" <> wrote in message
    news:p...
    > In <>, Simon Wittber
    > wrote:
    >
    >> I'd also like to remove any deprecated or stuff which is left in for
    >> backwards functionality (eg Classic classes).

    >
    > Classic classes are still needed for exceptions:
    >
    >>>> class E(object):

    > ... pass
    > ...
    >>>> raise E

    > Traceback (most recent call last):
    > File "<stdin>", line 1, in <module>
    > TypeError: exceptions must be classes, instances, or strings (deprecated),
    > not type
    >
    > Ciao,
    > Marc 'BlackJack' Rintsch


    I thought exceptions were converted to new-style classes for Py2.5
    (http://docs.python.org/whatsnew/pep-352.html). I've not upgraded yet, so
    cannot easily test this - under what version of Python was your posted code
    run?

    -- Paul
    Paul McGuire, Nov 6, 2006
    #5
  6. Simon Wittber

    Georg Brandl Guest

    Paul McGuire wrote:
    > "Marc 'BlackJack' Rintsch" <> wrote in message
    > news:p...
    >> In <>, Simon Wittber
    >> wrote:
    >>
    >>> I'd also like to remove any deprecated or stuff which is left in for
    >>> backwards functionality (eg Classic classes).

    >>
    >> Classic classes are still needed for exceptions:
    >>
    >>>>> class E(object):

    >> ... pass
    >> ...
    >>>>> raise E

    >> Traceback (most recent call last):
    >> File "<stdin>", line 1, in <module>
    >> TypeError: exceptions must be classes, instances, or strings (deprecated),
    >> not type
    >>
    >> Ciao,
    >> Marc 'BlackJack' Rintsch

    >
    > I thought exceptions were converted to new-style classes for Py2.5
    > (http://docs.python.org/whatsnew/pep-352.html).


    Yes, they were. Still, you can't raise instance of arbitrary new-style classes
    as exceptions, and you will never be able to. In Py3k, only instances of
    "BaseException" subclasses will be raisable.

    Georg
    Georg Brandl, Nov 6, 2006
    #6
  7. Simon Wittber wrote:
    > I want to build a Python2.5 interpreter for an embedded system. I only
    > have 4MB of RAM to play with, so I want to really minimise the python
    > binary.

    [snip]
    > Google tells me that people have done this before, back in Python1.5.2
    > days. Has anyone tried to do this recently with a more modern Python?


    http://www.python.org/dev/summary/2006-09-16_2006-09-30/#shrinking-python

    STeVe
    Steven Bethard, Nov 6, 2006
    #7
  8. Simon Wittber, Nov 7, 2006
    #8
  9. The Eternal Squire, Nov 7, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rogue Chameleon
    Replies:
    0
    Views:
    472
    Rogue Chameleon
    Oct 18, 2004
  2. Replies:
    0
    Views:
    729
  3. Paul Moore
    Replies:
    0
    Views:
    601
    Paul Moore
    Mar 1, 2008
  4. Martin v. Löwis
    Replies:
    0
    Views:
    641
    Martin v. Löwis
    Mar 1, 2008
  5. T. Onoma
    Replies:
    0
    Views:
    87
    T. Onoma
    Nov 22, 2003
Loading...

Share This Page