Best way to go about embedding python

Chris Angelico rosuav at gmail.com
Sun Nov 13 20:03:10 EST 2016


On Mon, Nov 14, 2016 at 11:40 AM, Steve D'Aprano
<steve+python at pearwood.info> wrote:
> On Mon, 14 Nov 2016 12:23 am, Chris Angelico wrote:
>
>> Python without its stdlib is a disappointingly featureless
>> language :)
>
>
> I don't think that's true. You can do a lot in Python without any imports in
> your code:
>
> - basic string processing
> - BigNum (int) and float arithmetic
> - lists and tuples
> - dicts
> - lazy processing of iterators
> - custom functions and classes
> - functional style zip, map and filter
>
> and more.
>
> Some parts of the standard library are required for built-in functions, e.g.
> the io module is needed to open files. But I think you could probably
> reduce the standard library by, oh, 90% and still have a decent language
> for game scripting.

Perhaps what would be more accurate is that Python without its stdlib
is as featureless as (say) Lua, but still without being safe to embed.
Yes, it's technically usable, but you really don't have a lot. And
remember, some of the stdlib is what we call builtins; if you embed
Python and engage "restricted mode", it's by emptying out the
builtins. You're pretty much down to three things:

1) Stuff that you could pass to ast.literal_eval
2) Control flow statements
3) Hacks that get you around the limitations, thus proving that
Python-without-stdlib is really really hard to actually test anything
with.

ChrisA



More information about the Python-list mailing list