Re: Weird local variables behaviors

2008-06-20 Thread Dan Bishop
On Jun 20, 7:32 pm, Matt Nordhoff <[EMAIL PROTECTED]> wrote: > Sebastjan Trepca wrote: > > Hey, > > > can someone please explain this behavior: > > > The code: > > > def test1(value=1): > >     def inner(): > >         print value > >     inner() > > > def test2(value=2): > >     def inner(): > >  

Sqlite3 textfactory and user-defined function

2008-06-20 Thread jeff_d_harper
I've run into a problem with text encoding in the Sqlite3 module. I think it may be a bug. By default sqlite3 converts strings in the database from UTF-8 to unicode. This conversion can be controlled by changing the connection's text_factory. I have a database that stores strings in 8-bit ISO-8

Re: An idiom for code generation with exec

2008-06-20 Thread eliben
> So you are saying that for example "if do_reverse: data.reverse()" is > *much* slower than "data.reverse()" ? I would expect that checking the > truthness of a boolean would be negligible compared to the reverse > itself. Did you try converting all checks to identity comparisons with > None ? I m

Learning Python: Code critique please

2008-06-20 Thread macoovacany
Hello all, I'm trying to learn various programming languages (I did MATLAB at uni), and have decided to start with Python. The programming exercises are derived from Larry O'brien's http://www.knowing.net/ PermaLink,guid,f3b9ba36-848e-43f8-9caa-232ec216192d.aspx">15 Programming Exercises . First

Re: An idiom for code generation with exec

2008-06-20 Thread eliben
>d = {} > execcode in globals(), d > return d['foo'] > > My way: > > return function(compile(code, '', 'exec'), globals()) > With some help from the guys at IRC I came to realize your way doesn't do the same. It creates a function that, when called, creates 'foo' on globals(). This is not

Re: An idiom for code generation with exec

2008-06-20 Thread eliben
On Jun 20, 2:44 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > eliben wrote: > > Additionally, I've found indentation to be a problem in such > > constructs. Is there a workable way to indent the code at the level of > > build_func, and not on column 0 ? > > exec"if 1:" + code.rstrip() > > Peter Why

<    1   2