Python Distilled

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Wittber

    #1

    Python Distilled

    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.

  • Marc 'BlackJack' Rintsch

    #2
    Re: Python Distilled

    In <1162790565.418 382.237050@m73g 2000cwd.googleg roups.com>, 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

    Comment

    • Georg Brandl

      #3
      Re: Python Distilled

      Marc 'BlackJack' Rintsch wrote:
      In <1162790565.418 382.237050@m73g 2000cwd.googleg roups.com>, 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

      Comment

      • Jorge Godoy

        #4
        Re: Python Distilled

        Marc 'BlackJack' Rintsch <bj_666@gmx.net writes:
        In <1162790565.418 382.237050@m73g 2000cwd.googleg roups.com>, 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.Ex ception):
        .... 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 <jgodoy@gmail.c om>

        Comment

        • Paul McGuire

          #5
          Re: Python Distilled

          "Marc 'BlackJack' Rintsch" <bj_666@gmx.net wrote in message
          news:pan.2006.1 1.06.10.11.35.3 35058@gmx.net.. .
          In <1162790565.418 382.237050@m73g 2000cwd.googleg roups.com>, 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


          Comment

          • Georg Brandl

            #6
            Re: Python Distilled

            Paul McGuire wrote:
            "Marc 'BlackJack' Rintsch" <bj_666@gmx.net wrote in message
            news:pan.2006.1 1.06.10.11.35.3 35058@gmx.net.. .
            >In <1162790565.418 382.237050@m73g 2000cwd.googleg roups.com>, 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
            "BaseExcept ion" subclasses will be raisable.

            Georg

            Comment

            • Steven Bethard

              #7
              Re: Python Distilled

              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?


              STeVe

              Comment

              • Simon Wittber

                #8
                Re: Python Distilled



                Excellent, just what I was hoping for. Thanks!

                -Sw.

                Comment

                • The Eternal Squire

                  #9
                  Re: Python Distilled

                  Try also Diet Python on SourceForge.

                  It's the first step toward a shrunken Python for embedded Win32
                  systems.

                  Cheers,

                  The Eternal Squire


                  Simon Wittber wrote:
                  >
                  Excellent, just what I was hoping for. Thanks!
                  >
                  -Sw.

                  Comment

                  Working...