Changing tab behavior in Python Interactive mode

2010-01-29 Thread Andrej Mitrovic
I've noticed that when running Python in interactive mode (via cmd on
windows), the first time I hit tab it will move 4 spaces to the right,
however each new tab will move 8 spaces instead of 4. Why this
inconsistent behavior? And how could I change this to be consistent
and always move only 4 spaces?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing tab behavior in Python Interactive mode

2010-01-29 Thread Andrej Mitrovic
On Jan 29, 6:47 pm, Steve Holden  wrote:
> Andrej Mitrovic wrote:
> > I've noticed that when running Python in interactive mode (via cmd on
> > windows), the first time I hit tab it will move 4 spaces to the right,
> > however each new tab will move 8 spaces instead of 4. Why this
> > inconsistent behavior? And how could I change this to be consistent
> > and always move only 4 spaces?
>
> The first tab you are starting four characters in due to the interpreter
> already having printed ">>> ".
>
> regards
>  Steve
> --
> Steve Holden           +1 571 484 6266   +1 800 494 3119
> PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
> Holden Web LLC                http://www.holdenweb.com/
> UPCOMING EVENTS:        http://holdenweb.eventbrite.com/

I see. I wonder if I could modify this behavior.. I guess I'll have to
take a look at the source. Thanks anyway!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing tab behavior in Python Interactive mode

2010-01-29 Thread Andrej Mitrovic
On Jan 29, 10:07 pm, Steve Holden  wrote:
> Andrej Mitrovic wrote:
> > On Jan 29, 6:47 pm, Steve Holden  wrote:
> >> Andrej Mitrovic wrote:
> >>> I've noticed that when running Python in interactive mode (via cmd on
> >>> windows), the first time I hit tab it will move 4 spaces to the right,
> >>> however each new tab will move 8 spaces instead of 4. Why this
> >>> inconsistent behavior? And how could I change this to be consistent
> >>> and always move only 4 spaces?
> >> The first tab you are starting four characters in due to the interpreter
> >> already having printed ">>> ".
>
> >> regards
> >>  Steve
> >> --
> >> Steve Holden           +1 571 484 6266   +1 800 494 3119
> >> PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
> >> Holden Web LLC                http://www.holdenweb.com/
> >> UPCOMING EVENTS:        http://holdenweb.eventbrite.com/
>
> > I see. I wonder if I could modify this behavior.. I guess I'll have to
> > take a look at the source. Thanks anyway!
>
> I's nothing to do with the source: it isn't the interpreter that's
> deciding where the "tab stops" are, it's the console window the
> interpreter is running in.
>
> regards
>  Steve
> --
> Steve Holden           +1 571 484 6266   +1 800 494 3119
> PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
> Holden Web LLC                http://www.holdenweb.com/
> UPCOMING EVENTS:        http://holdenweb.eventbrite.com/

I see. Well I'm nitpicking here, it's not all that important (I just
use cmd when I'm trying out small pieces of code). And I doubt there's
a tabstop setting for cmd that I could use.

Thanks for all your help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3147 - new .pyc format

2010-01-31 Thread Andrej Mitrovic
Leave magic to the witches of Perl. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Python distutils build problems with MinGW

2010-01-31 Thread Andrej Mitrovic
Hi,

I've made a similar post on the Cython mailing list, however I think
this is more python-specific. I'm having trouble setting up distutils
to use MinGW instead of Visual Studio when building a module. Even tho
I've just uninstalled VS, and cleared out any leftover VS environment
variables, distutils keeps wanting to use it.

The steps I took:

Fresh installation of Python 3.1.1
Successfully installed MinGW, added to the path variable (gcc in
command prompt works)
Successfully installed Cython, imports from Cython in Python work.
Added a distutils.cfg file in \Python31\Lib\distutils\ directory with:

[build]
compiler=mingw32

(also tried adding [build_ext] compiler=mingw32)

There's a demo setup.py module that came with Cython, I tried the
following commands:


> python setup.py build_ext --inplace

error: Unable to find vcvarsall.bat

> python setup.py build

error: Unable to find vcvarsall.bat


I'm having the exact same issue with trying to build the Polygon
library via MinGW. In fact, the reason I had installed Visual Studio
in the first place was to be able to build the Polygon library, since
I was having these errors.

What do I need to do to make distutils/python use MinGW?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python distutils build problems with MinGW

2010-01-31 Thread Andrej Mitrovic
On Feb 1, 2:59 am, Andrej Mitrovic  wrote:
> Hi,
>
> I've made a similar post on the Cython mailing list, however I think
> this is more python-specific. I'm having trouble setting up distutils
> to use MinGW instead of Visual Studio when building a module. Even tho
> I've just uninstalled VS, and cleared out any leftover VS environment
> variables, distutils keeps wanting to use it.
>
> The steps I took:
>
> Fresh installation of Python 3.1.1
> Successfully installed MinGW, added to the path variable (gcc in
> command prompt works)
> Successfully installed Cython, imports from Cython in Python work.
> Added a distutils.cfg file in \Python31\Lib\distutils\ directory with:
>
> [build]
> compiler=mingw32
>
> (also tried adding [build_ext] compiler=mingw32)
>
> There's a demo setup.py module that came with Cython, I tried the
> following commands:
>
> 
>
> > python setup.py build_ext --inplace
>
> error: Unable to find vcvarsall.bat
>
> > python setup.py build
>
> error: Unable to find vcvarsall.bat
> 
>
> I'm having the exact same issue with trying to build the Polygon
> library via MinGW. In fact, the reason I had installed Visual Studio
> in the first place was to be able to build the Polygon library, since
> I was having these errors.
>
> What do I need to do to make distutils/python use MinGW?

Update:

I installed and tried building with Python 2.6, it calls MinGW when I
have the distutils.cfg file configured properly (same configuration as
the Python 3.1.1 one)

But why doesn't it work on a fresh Python 3.1.1 installation as well?
Is this a bug?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: whassup? builtins? python3000? Naah can't be right?

2010-02-01 Thread Andrej Mitrovic
Hey, it's really simple! Just like the excerpt from the Learning
Python book says:

"Really, the built-in scope is just a built-in module called builtins,
but
you have to import builtins to query built-ins because the name
builtins is not itself
built-in"

:)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python distutils build problems with MinGW

2010-02-01 Thread Andrej Mitrovic
On Feb 1, 4:03 am, Andrej Mitrovic  wrote:
> On Feb 1, 2:59 am, Andrej Mitrovic  wrote:
>
>
>
> > Hi,
>
> > I've made a similar post on the Cython mailing list, however I think
> > this is more python-specific. I'm having trouble setting up distutils
> > to use MinGW instead of Visual Studio when building a module. Even tho
> > I've just uninstalled VS, and cleared out any leftover VS environment
> > variables, distutils keeps wanting to use it.
>
> > The steps I took:
>
> > Fresh installation of Python 3.1.1
> > Successfully installed MinGW, added to the path variable (gcc in
> > command prompt works)
> > Successfully installed Cython, imports from Cython in Python work.
> > Added a distutils.cfg file in \Python31\Lib\distutils\ directory with:
>
> > [build]
> > compiler=mingw32
>
> > (also tried adding [build_ext] compiler=mingw32)
>
> > There's a demo setup.py module that came with Cython, I tried the
> > following commands:
>
> > 
>
> > > python setup.py build_ext --inplace
>
> > error: Unable to find vcvarsall.bat
>
> > > python setup.py build
>
> > error: Unable to find vcvarsall.bat
> > 
>
> > I'm having the exact same issue with trying to build the Polygon
> > library via MinGW. In fact, the reason I had installed Visual Studio
> > in the first place was to be able to build the Polygon library, since
> > I was having these errors.
>
> > What do I need to do to make distutils/python use MinGW?
>
> Update:
>
> I installed and tried building with Python 2.6, it calls MinGW when I
> have the distutils.cfg file configured properly (same configuration as
> the Python 3.1.1 one)
>
> But why doesn't it work on a fresh Python 3.1.1 installation as well?
> Is this a bug?

Also tried calling (Python 3.1.1):


python setup.py build --compiler=mingw32

error: Unable to find vcvarsall.bat


I've tried using pexports and the dlltool to build new python31.def
and libpython31.a files, and put them in the libs folder. That didn't
work either.

I've also tried adding some print statements in the \distutils\dist.py
file, in the parse_config_files() function, just to see if Python
properly parses the config file. And it does, both Python 2.6 and 3.1
parse the distutils.cfg file properly. Yet something is making python
3 look for the VS/VC compiler instead of MinGW. I'll keep updating on
any progres..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python distutils build problems with MinGW

2010-02-01 Thread Andrej Mitrovic
I've found the problem:

For the windows Python 3.1.1 x86 installation, the file \Python31\Lib
\Distutils\command\build_ext.py, has this:

Line 313:

self.compiler = new_compiler(compiler=None,

But Python 2.6 has this line:

Line 306:

self.compiler = new_compiler(compiler=self.compiler,



I've changed the Python 3.1.1 \Python31\Lib\Distutils\command
\build_ext.py, Line 313 to this:

self.compiler = new_compiler(compiler=self.compiler,

And now MinGW gets properly called in Python 3.1.1. I think this must
have been a typo.


Is there anyone else that can confirm this?

The installation that distributes the file with that line is from this
Python ftp link: http://python.org/ftp/python/3.1.1/python-3.1.1.msi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python distutils build problems with MinGW

2010-02-01 Thread Andrej Mitrovic
On Feb 1, 5:44 pm, casevh  wrote:
> On Feb 1, 8:31 am, Andrej Mitrovic  wrote:
>
>
>
> > On Feb 1, 4:03 am, Andrej Mitrovic  wrote:
>
> > > On Feb 1, 2:59 am, Andrej Mitrovic  wrote:
>
> > > > Hi,
>
> > > > I've made a similar post on the Cython mailing list, however I think
> > > > this is more python-specific. I'm having trouble setting up distutils
> > > > to use MinGW instead of Visual Studio when building a module. Even tho
> > > > I've just uninstalled VS, and cleared out any leftover VS environment
> > > > variables, distutils keeps wanting to use it.
>
> > > > The steps I took:
>
> > > > Fresh installation of Python 3.1.1
> > > > Successfully installed MinGW, added to the path variable (gcc in
> > > > command prompt works)
> > > > Successfully installed Cython, imports from Cython in Python work.
> > > > Added a distutils.cfg file in \Python31\Lib\distutils\ directory with:
>
> > > > [build]
> > > > compiler=mingw32
>
> > > > (also tried adding [build_ext] compiler=mingw32)
>
> > > > There's a demo setup.py module that came with Cython, I tried the
> > > > following commands:
>
> > > > 
>
> > > > > python setup.py build_ext --inplace
>
> > > > error: Unable to find vcvarsall.bat
>
> > > > > python setup.py build
>
> > > > error: Unable to find vcvarsall.bat
> > > > 
>
> > > > I'm having the exact same issue with trying to build the Polygon
> > > > library via MinGW. In fact, the reason I had installed Visual Studio
> > > > in the first place was to be able to build the Polygon library, since
> > > > I was having these errors.
>
> > > > What do I need to do to make distutils/python use MinGW?
>
> > > Update:
>
> > > I installed and tried building with Python 2.6, it calls MinGW when I
> > > have the distutils.cfg file configured properly (same configuration as
> > > the Python 3.1.1 one)
>
> > > But why doesn't it work on a fresh Python 3.1.1 installation as well?
> > > Is this a bug?
>
> > Also tried calling (Python 3.1.1):
>
> > 
> > python setup.py build --compiler=mingw32
>
> > error: Unable to find vcvarsall.bat
> > 
>
> > I've tried using pexports and the dlltool to build new python31.def
> > and libpython31.a files, and put them in the libs folder. That didn't
> > work either.
>
> > I've also tried adding some print statements in the \distutils\dist.py
> > file, in the parse_config_files() function, just to see if Python
> > properly parses the config file. And it does, both Python 2.6 and 3.1
> > parse the distutils.cfg file properly. Yet something is making python
> > 3 look for the VS/VC compiler instead of MinGW. I'll keep updating on
> > any progres..- Hide quoted text -
>
> > - Show quoted text -
>
> I think this ishttp://bugs.python.org/issue6377.
>
> I applied the patch to my local copy of Python 3.1 and it seems to
> work.
>
> casevh

Thanks for the link, it seems like it's got more to do than what I
just posted. But in any case, it works for me now.

I think I'll have to open myself a blog and post some guides for
problems like these, so people can avoid spending whole nights around
a problem like this. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python distutils build problems with MinGW

2010-02-01 Thread Andrej Mitrovic
Well, in any case this seems to be working ok for me now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google AI Challenge at U of Waterloo

2010-02-06 Thread Andrej Mitrovic
Sweet, something to keep my brain busy for the next couple of weeks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TABS in the CPython C source code

2010-02-06 Thread Andrej Mitrovic
On Feb 6, 9:31 pm, "Alf P. Steinbach"  wrote:
> Just trying to delve into the CPython source code.
>
> Pleasant surprise: while e.g. the gcc compiler is written in K&R C (1975 style
> C), CPython seems to be written in almost modern C (1989 and on).
>
> But, hey, TABS used for indenting, combined haphazardly and randomly with 
> SPACES
> used for indenting, in the same source files...
>
> The size-8 tabs look really bad in an editor configured with tab size 4, as is
> common in Windows. I'm concluding that the CPython programmers configure their
> Visual Studio's to *nix convention. Or perhaps modern Visual Studio has 
> default
> tab size 8, it wouldn't surprise me (the best version was the MSVC 6.0 
> Developer
> Studio, since then that IDE has only gone downhill being re-based on the 
> Office
> Assistant inspired "for dummies" IDE that Microsoft had for web designers).
>
> Anyways, I would suggest converting all those tabs to spaces, as e.g. the 
> Boost
> library project does  --  no tabs allowed.
>
> That's much more platform-independent. :-)
>
> Cheers,
>
> - Alf

So what's stopping you from doing this yourself?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking the coding style

2010-02-07 Thread Andrej Mitrovic
On Feb 7, 8:22 pm, Kev Dwyer  wrote:
> On Sun, 07 Feb 2010 19:36:10 +0100, Pablo Recio Quijano wrote:
> > Hi!
>
> > I'm finishing a project writen in Python, and I realize about the
> > document PEP8 - Style Guide for Python Code [1].
>
> > Is there any app or script that checks if my project pass that style
> > guide? I also worked with Drupal, and I know there is some modules and
> > scripts that checks its coding standars [2] and it's very usefull to
> > clean the code.
>
> > Thanks in advance!
>
> > [1]http://www.python.org/dev/peps/pep-0008/[2]
> >http://drupal.org/coding-standards
>
> Hello Pablo,
>
> The pep8 package (http://pypi.python.org/pypi/pep8) can do this, though
> I have never used it myself.  PyLint is a customisable static analysis
> program that checks style among other things.
>
> Cheers,
>
> Kev

I've used pep8.py myself for some Python 3.x projects, and it's pretty
good. You don't need to install it either, a simple call via python
pep8.py 'yourpythonfile.py' should do.

I think PyLint can be used for Python 2.x, but I'm not sure about 3.x.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7

2010-02-07 Thread Andrej Mitrovic
On Feb 8, 1:26 am, escalation746  wrote:
> I am having a heck of a time doing the simplest thing: installing
> Python and the pywin extensions, including the PythonWin editor I have
> always relied on, into my new Windows 7 Professional 64-bit OS. I
> tried the Python package from python.org and pywin32 from sourceforge.
> But the latter would not install, saying that it could not find Python
> 2.6 in the registry. And apparently it will not let me specify the
> location of same, although a dialogue window tantalises me with blank
> text boxes I cannot type into.
>
> I then tried the 64-bit version of ActiveState's Python, but this
> installed sans the PythonWin editor, apparently. At least I cannot
> find it either in the Start menu or in the Python folder.
>
> What am I missing? What have I not been told?
>
> -- robin

Perhaps you've accidentally downloaded the wrong version of PythonWin?
I think this should be the one:
http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/pywin32-214.win-amd64-py2.6.exe/download
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Awful book warning: How to think like a (Python) programmer - non-working examples

2010-02-08 Thread Andrej Mitrovic
The book covers Python 2.x syntax.

You might have downloaded Python 3.1, which has different syntax then
Python 2.x. From what I can tell, the first example on page 7 is ">>>
print 1 + 1".

Try issuing this command:
print(1 + 1)

If everything goes well, and you get '2' as the answer, then you're
probably using Python 3.x. You will have to download the Python 2.x
binaries from the Python website, install Python 2.x, and try the
example from the book again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Awful book warning: How to think like a (Python) programmer - non-working examples

2010-02-08 Thread Andrej Mitrovic
On Feb 8, 10:14 pm, David Malcolm  wrote:
> On Mon, 2010-02-08 at 12:53 -0800, Andrej Mitrovic wrote:
> > The book covers Python 2.x syntax.
>
> > You might have downloaded Python 3.1, which has different syntax then
> > Python 2.x. From what I can tell, the first example on page 7 is ">>>
> > print 1 + 1".
>
> > Try issuing this command:
> > print(1 + 1)
>
> > If everything goes well, and you get '2' as the answer, then you're
> > probably using Python 3.x. You will have to download the Python 2.x
> > binaries from the Python website, install Python 2.x, and try the
> > example from the book again.
>
> Sorry to nitpick; the main thrust of the above sounds correct, in that:
>     print 1 + 1
> works in Python 2 but fails in Python 3, but, a minor correction, note
> that:
>     print(1+1)
> does work in Python 2 as well as in Python 3; the parentheses are
> treated (in the former) as denoting grouping of a subexpression, rather
> than function invocation (in the latter):
>
> Python 2.6.2 (r262:71600, Jan 25 2010, 13:22:47)
> [GCC 4.4.2 20100121 (Red Hat 4.4.2-28)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> print(1+1)
>
> 2
>
> This can be useful if you're trying to write short fragments of code
> that work with both.
>
> Look at the startup message, or run this command, which should work on
> both python2 and python3:
>   import sys; print(sys.version)
>
> Hope this is helpful
> Dave

Oops, you're right. I'm used to Python 3 syntax so I'm only aware of
some basic differences. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-16 Thread Andrej Mitrovic
On Feb 16, 7:38 pm, Casey Hawthorne 
wrote:
> Interesting talk on Python vs. Ruby and how he would like Python to
> have just a bit more syntactic flexibility.
>
> http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-de...
> --
> Regards,
> Casey

Gary's friend Geoffrey Grosenbach says in his blog post (which Gary
linked to): "Python has no comparable equivalent to Ruby’s do end
block. Python lambdas are limited to one line and can’t contain
statements (for, if, def, etc.). Which leaves me wondering, what’s the
point?"

I'm sorry, lambda's do support if's and for's. Also, lambda's are
expressions, not statements, but you can pass them around, keep them
in a dictionary if you want to. And if you need more than one line of
statements, for crying out loud use a def? And who needs those "do-
end" blocks anyway, trying to turn Python into Pascal?
-- 
http://mail.python.org/mailman/listinfo/python-list


Traversing through variable-sized lists

2010-02-17 Thread Andrej Mitrovic
Hi,

I couldn't figure out a better description for the Subject line, but
anyway, I have the following:

_num_frames = 32
_frames = range(0, _num_frames) # This is a list of actual objects,
I'm just pseudocoding here.
_values = [0, 1, 2, 3, 4]

I want to call a function of _frames for each frame with a _values
argument, but in a way to "spread out" the actual values.

I would want something similar to the following to be called:

_frames[0].func(_values[0])
_frames[1].func(_values[0])
_frames[2].func(_values[0])
_frames[3].func(_values[0])
_frames[4].func(_values[1])
_frames[5].func(_values[1])
_frames[6].func(_values[1])
_frames[7].func(_values[1])
_frames[8].func(_values[2])
...etc...

Both the _values list and _frames list can be of variable and uneven
size, which is what is giving me the problems. I'm using Python 2.6.

I've tried the following workaround, but it often gives me inaccurate
results (due to integer division), so I had to add a safety check:

num_frames = 32
values = [0, 1, 2, 3, 4]
offset_step = num_frames / len(values)
for index in xrange(0, num_frames):
offset = index / offset_step
if offset > offset_values[-1]:
offset = offset_values[-1]
frames[index].func(values[offset])

There has to be a better way to do this. I'd appreciate any help.
Cheers!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Traversing through variable-sized lists

2010-02-17 Thread Andrej Mitrovic
On Feb 17, 8:24 pm, John Posner  wrote:
> On 2/17/2010 1:10 PM, Andrej Mitrovic wrote:
>
>
>
> > Hi,
>
> > I couldn't figure out a better description for the Subject line, but
> > anyway, I have the following:
>
> > _num_frames = 32
> > _frames = range(0, _num_frames) # This is a list of actual objects,
> > I'm just pseudocoding here.
> > _values = [0, 1, 2, 3, 4]
>
> > I want to call a function of _frames for each frame with a _values
> > argument, but in a way to "spread out" the actual values.
>
> > I would want something similar to the following to be called:
>
> > _frames[0].func(_values[0])
> > _frames[1].func(_values[0])
> > _frames[2].func(_values[0])
> > _frames[3].func(_values[0])
> > _frames[4].func(_values[1])
> > _frames[5].func(_values[1])
> > _frames[6].func(_values[1])
> > _frames[7].func(_values[1])
> > _frames[8].func(_values[2])
> > ...etc...
>
> The lines above show that you are using two different series of index
> values. Each function call (more properly, "method call") has the form:
>
>    frames[INDEX_FROM_FIRST_SERIES].func(INDEX_FROM_SECOND_SERIES)
>
> (I've dropped the underscores in the names, for simplicity.) You're
> getting hung up trying to keep the two series of index values in sync.
> But you don't really need to. More below ...
>
>
>
>
>
> > Both the _values list and _frames list can be of variable and uneven
> > size, which is what is giving me the problems. I'm using Python 2.6.
>
> > I've tried the following workaround, but it often gives me inaccurate
> > results (due to integer division), so I had to add a safety check:
>
> > num_frames = 32
> > values = [0, 1, 2, 3, 4]
> > offset_step = num_frames / len(values)
> >      for index in xrange(0, num_frames):
> >          offset = index / offset_step
> >          if offset>  offset_values[-1]:
> >              offset = offset_values[-1]
> >          frames[index].func(values[offset])
>
> > There has to be a better way to do this. I'd appreciate any help.
> > Cheers!
>
> As you've shown above, a "for" loop takes care of the first series of
> index values:
>
>    for index in xrange(num_frames):       # "0" arg unnecessary
>        frames[index].func(INDEX_FROM_SECOND_SERIES)
>
> The second series of index values needs to look like this:
>
>    0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3 ...
>
> The trick is not to worry about matching the second series to the first
> series. Instead, create an "infinite" second series using a Python
> generator, and use as many of its values as you need. Don't worry about
> the unused values, because the series isn't *really* infinite. :-)
>
> Here's an easy way to create the generator
>
>    import itertools
>    second_series_gen = (i/4 for i in itertools.count())
>
> Now, every time you need another number from this series, use its next()
> method. So the above code becomes:
>
>    for index in xrange(num_frames):
>        frames[index].func(second_series_gen.next())
>
> -John

That's a cool trick, but maybe I wasn't specific enough. The values
series are the range of values that the frames.func() function should
use, it should not overflow, and I would want the function to use as
evenly distributed number of values as possible from the first series.
The "," was just an example. Let me see if I can be more
specific:

values = [2, 3, 4]
frames = [obj1, obj2, obj3, obj4, obj5, obj6]

And the calls:

frames[0].func(values[0])  # func.(values[2])
frames[1].func(values[0])  # func.(values[2])
frames[2].func(values[1])  # func.(values[3])
frames[3].func(values[1])  # func.(values[3])
frames[4].func(values[2])  # func.(values[4])
frames[5].func(values[2])  # func.(values[4])


However the values list might have an uneven number of items. I would
like to make it as evenly distributed as possible, e.g.:

values = [-2, -1, 0]
frames = [obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8]

frames[0].func(values[0])  # func.(values[-2])
frames[1].func(values[0])  # func.(values[-2])
frames[2].func(values[1])  # func.(values[-2])
frames[3].func(values[1])  # func.(values[-1])
frames[4].func(values[1])  # func.(values[-1])
frames[5].func(values[2])  # func.(values[-1])
frames[6].func(values[2])  # func.(values[0])
frames[7].func(values[2])  # func.(values[0])


I'll be even more specific. I have a Minimum and Maximum value that
the user enters. The frame.func() function is a "translate" function,
it basically moves a frame in the application in one direction or
another depending on the argum

Re: Traversing through variable-sized lists

2010-02-17 Thread Andrej Mitrovic
On Feb 17, 11:56 pm, Dave Angel  wrote:
> Andrej Mitrovic wrote:
> > On Feb 17, 8:24 pm, John Posner  wrote:
>
> >> On 2/17/2010 1:10 PM, Andrej Mitrovic wrote:
>
> >> 
>
> > However the values list might have an uneven number of items. I would
> > like to make it as evenly distributed as possible, e.g.:
>
> > values =-2, -1, 0]
> > frames =obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8]
>
> > frames[0].func(values[0])  # func.(values[-2])
> > frames[1].func(values[0])  # func.(values[-2])
> > frames[2].func(values[1])  # func.(values[-2])
> > frames[3].func(values[1])  # func.(values[-1])
> > frames[4].func(values[1])  # func.(values[-1])
> > frames[5].func(values[2])  # func.(values[-1])
> > frames[6].func(values[2])  # func.(values[0])
> > frames[7].func(values[2])  # func.(values[0])
>
> > I'll be even more specific. I have a Minimum and Maximum value that
> > the user enters. The frame.func() function is a "translate" function,
> > it basically moves a frame in the application in one direction or
> > another depending on the argument value. So frame[0].func(2) would
> > move the frame[0] 2 pixels to the right. So what I want is the
> > function to create a smooth transition of all the frames from the
> > Minimum to the Maximum value. If minimum was 0, and maximum was 10,
> > I'd want the first frame moved 0 pixels (it stays in place), the last
> > frame to move 10 pixels, and the frames between are gradually moved
> > from 1 pixels to 9 pixels relative from their positions.
>
> > Perhaps I'm just overcomplicating. I'll have a look at some drawing
> > apps and see how they've implemented drawing straight lines under an
> > angle, I guess that could be called a gradual change of values.
>
> > Thanks for all the suggestions everyone, I'll have a look at the rest
> > shortly.
>
> I think you're overcomplicating.  If you have 27 frames, and you want
> frame 0 to move 0 pixels, and frame 27 to move 10 pixels, then you want
> to move frame[i] by i*10/27.  And since you do the multiply first, the
> fact that Python 2.x division gives you integers isn't a problem.
>
> There are fancier methods for drawing lines (bresenham for example), but
> the main purpose of them is to to avoid multiply and divide, as well as
> floats.  But in Python, an integer multiply is just as fast as an add or
> subtract, so there's no point.
>
> DaveA

Doh! Such a simple solution, just what I was looking for. Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Documentation website layout changed?

2010-03-17 Thread Andrej Mitrovic
Hi,

What happened to the sidebar on the left of the documentation website?
It seems to be gone:

http://docs.python.org/py3k/index.html

I found it quite useful since I can quickly swap between Python2/3
documentation, and between other parts of the documentation as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Documentation website layout changed?

2010-03-17 Thread Andrej Mitrovic
On Mar 17, 6:41 pm, Andrej Mitrovic 
wrote:
> Hi,
>
> What happened to the sidebar on the left of the documentation website?
> It seems to be gone:
>
> http://docs.python.org/py3k/index.html
>
> I found it quite useful since I can quickly swap between Python2/3
> documentation, and between other parts of the documentation as well.

Edit: It looks like only the Python 3 pages are affected, the Python 2
pages are the same as before:

http://docs.python.org/index.html

Might be a bug?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Documentation website layout changed?

2010-03-21 Thread Andrej Mitrovic
On Mar 20, 12:32 am, Steve Holden  wrote:
> Steve Holden wrote:
> > Andrej Mitrovic wrote:
> >> On Mar 17, 6:41 pm, Andrej Mitrovic 
> >> wrote:
> >>> Hi,
>
> >>> What happened to the sidebar on the left of the documentation website?
> >>> It seems to be gone:
>
> >>>http://docs.python.org/py3k/index.html
>
> >>> I found it quite useful since I can quickly swap between Python2/3
> >>> documentation, and between other parts of the documentation as well.
> >> Edit: It looks like only the Python 3 pages are affected, the Python 2
> >> pages are the same as before:
>
> >>http://docs.python.org/index.html
>
> >> Might be a bug?
>
> > I'll ask. Georg - is this known behavior or a temporary problem?
>
> It's a bug. Georg is on it.
>
> regards
>  Steve
> --
> Steve Holden           +1 571 484 6266   +1 800 494 3119
> See PyCon Talks from Atlanta 2010  http://pycon.blip.tv/
> Holden Web LLC                http://www.holdenweb.com/
> UPCOMING EVENTS:        http://holdenweb.eventbrite.com/

Looks like it's fixed now. Thanks Georg & Steve!
-- 
http://mail.python.org/mailman/listinfo/python-list


Traversing through Dir()

2010-03-25 Thread Andrej Mitrovic
I would like to traverse through the entire structure of dir(), and
write it to a file.

Now, if I try to write the contents of dir() to a file (via pickle), I
only get the top layer. So even if there are lists within the returned
list from dir(), they get written as a list of strings to the file.

Basically, I have an embedded and somewhat stripped version of Python.
I would like to find out just how much functionality it has (I have no
documentation for it), so I thought the best way to do that is
traverse thru the dir() call. Any clues as to how I could write the
whole structure to a file? I guess I'll need some kind of recursion
here. :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Traversing through Dir()

2010-03-26 Thread Andrej Mitrovic
On Mar 26, 9:18 am, "Alf P. Steinbach"  wrote:
> * Andrej Mitrovic:
>
> > I would like to traverse through the entire structure of dir(), and
> > write it to a file.
>
> > Now, if I try to write the contents of dir() to a file (via pickle), I
> > only get the top layer. So even if there are lists within the returned
> > list from dir(), they get written as a list of strings to the file.
>
> > Basically, I have an embedded and somewhat stripped version of Python.
> > I would like to find out just how much functionality it has (I have no
> > documentation for it), so I thought the best way to do that is
> > traverse thru the dir() call. Any clues as to how I could write the
> > whole structure to a file? I guess I'll need some kind of recursion
> > here. :)
>
> The built-in dir() function just produces a sequence of strings.
>
> You can inspect the attributes via the getattr() function. The getattr()
> function produces a reference to an object (as does every expression). 
> Problem:
> if you start with the number 42 and apply dir(), do getattr() on the first
> string, apply dir() on that object, and so on, with CPython you then get into 
> an
> infinite recursion because those objects are produced on demand...
>
> 
> obj = 42
> obj_name = "42"
> for n in range( 12 ):
>      where = id( obj )
>      t = type( obj ).__name__
>      print( "{:>2} {:>10} {:20} of type '{}'".format( n, where, obj_name, t ) 
> )
>      attribute_names = dir( obj )
>      obj_name = attribute_names[0]
>      obj = getattr( obj, obj_name )
> 
>
> Similarly, if you do this with the Turtle module as starting point, with 
> CPython
> you get into a different kind of infinite recursion because the chain of
> attributes so obtained is circular.
>
> 
> import turtle
>
> obj = turtle
> obj_name = 'turtle'
> for n in range( 12 ):
>      where = id( obj )
>      t = type( obj ).__name__
>      print( "{:>2} {:>10} {:20} of type '{}'".format( n, where, obj_name, t ) 
> )
>      attribute_names = dir( obj )
>      obj_name = attribute_names[0]
>      obj = getattr( obj, obj_name )
> 
>
> It's not a clean, strict hierarchy of objects.
>
> However, the basic idea is sound when you only want to obtain some limited,
> known information, such as e.g. short descriptions of all string methods, or a
> listing of the standard exception hierarchy.
>
> 
> for attribute_name in dir( str ):
>      if attribute_name.startswith( "_" ):
>          pass
>      else:
>          attribute = getattr( str, attribute_name )
>          doc_string = attribute.__doc__
>          doc_lines = doc_string.splitlines()
>          if len( doc_lines ) > 2:
>              essential_doc = doc_lines[2]
>          else:
>              essential_doc = doc_lines[0]
>          print( attribute_name.ljust( 15 ) + essential_doc )
> 
>
> 
> "Lists the standard exception class hierarchy with short descriptions."
> import builtins
> import inspect
>
> indentation     = "." + 2*" "
>
> def is_type( o ):
>      # Could use inspect.isclass for this, but in the DIY spirit:
>      return isinstance( o, type )
>
> def beginning_of( s, max_chars ):
>      return s[:max_chars]    # Not yet discussed, but doesn't matter.
>
> def print_hierarchy( h, level ):
>      for o in h:
>          if isinstance( o, tuple ):
>              # o is a tuple describing a class
>              cls = o[0]
>              doc_lines = cls.__doc__.splitlines()
>              short_doc = beginning_of( doc_lines[0], 55 )
>              print( "{:<34} {}".format(
>                  level*indentation + cls.__name__, short_doc
>                  ) )
>          else:
>              # o is a list array of subclasses
>              print_hierarchy( o, level + 1 )
>
> classes = []
> for name in dir( builtins ):
>      o = getattr( builtins, name )
>      if is_type( o ):
>          if issubclass( o, BaseException ):
>              classes.append( o )
>
> hierarchy = inspect.getclasstree( classes )
> # 'hierarchy' is a list array of tuples and nested list arrays of the same 
> form.
> # The top level is an array of two items, the first item a tuple describing 
> the
> 'object'
> # class, and the second item a list array representing the BaseException 
> hierarchy.
> print_hierarchy( hierarchy[1], level = 0 )
> 
>
> Cheers & hth.,
>
> - Alf

Thanks for all of that. And yes, I've noticed I get into infinite
recursions all the time, which is why I was asking if there was a
simple way to do this. I'll have a look at these later.

Kind regards,
Andrej Mitrovic
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Have you embraced Python 3.x yet?

2010-03-26 Thread Andrej Mitrovic
I use both, really. I started by learning and using Python 3, but I
ended up using Python 2 much more often compared to Py3. Not because
of the functionality of the language, but because most software that
embeds Python or is extendable in some way is usually using Python 2.
+ There's the whole libraries issue (or the lack of them).

But I have to say, Python 3 is a sexy language, I can't wait for more
libraries to appear so I could focus more of my attention there.
-- 
http://mail.python.org/mailman/listinfo/python-list


Vertical line in function arguments

2010-03-27 Thread Andrej Mitrovic
There is this peace of code in a 3rd party module:

MidiIn.SetFilter(pypm.FILT_ACTIVE | pypm.FILT_CLOCK |
pypm.FILT_PITCHBEND |
 pypm.FILT_NOTE)

What are the vertical lines in a function call such as this? This
actually calls a function from a Pyrex module that was compiled into
a .pyd. Those filters are hex constants, but I've no idea what these
vertical lines mean. Is this some form of binary "or" operation?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vertical line in function arguments

2010-03-27 Thread Andrej Mitrovic
Well I hate it when this happens. I ask a question, and literally 2
seconds later I bump into the answer.

This explains it a bit: 
http://docs.python.org/library/stdtypes.html#bit-string-operations-on-integer-types
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Script Creator/Generator (function factory)

2010-03-30 Thread Andrej Mitrovic
Hello,

I have the following situation: I've got a 3rd party application that
has a Python API. The applicaiton has integrated support for MIDI
Hardware Controllers, which can be used to manipulate various
parameters of the application. The app can also load Python User
Scripts, which can define the mapping between the Controllers and
Parameters, but they can also be used to define the behavior of those
mappings as well.

I want to provide my users a GUI App that allows them to map their
MIDI Controllers to the application's Parameters, but with a specific
behavior. Once they've defined the mappings and behavior, my
application would generate a custom Python User Script, which then
gets loaded by the 3rd party app.

I've already got MIDI covered, and the GUI. Deployment via Pyinstaller
has been taken care of as well. My application can currently map
Controllers to Parameters in a 1:1 fashion, and can generate a simple
python User Script with all the mappings. What I'm left with
implementing is the behavior part.

Let me give you a simple example of a possible behavior that the user
could select:

- The user has a button on their MIDI Hardware (a simple type of MIDI
controller)
- The first time the button is hit, a specific parameter is selected
in the 3rd party application.
- The second time the button is hit, a different parameter is
selected.
- And so on, depending on the behavior of the function that's mapped
to that MIDI button

So, in essence, a simple User Script would look something like this
(pseudocode-ish):

~
swap_parameters()
if button1 was_hit_the_first_time:
select parameter1
else:
select parameter2

buttons = (
button1 = swap_parameters()
button3 = parameter3
button4 = parameter4
...
)
~

What I had in mind, was to have a collection of behaviors stored in a
file (basically functions such as "swap_parameters") which the user
could select via my application, map them to a specific MIDI
Controller (such as a Button), and generate the User Script.

In essence, I'm trying to build a function factory that's specific to
the 3rd party application's provided API. But the user would have the
ability to change the way the function works. In the above example,
the user might want their MIDI Button to select parameter2 first, and
parameter1 the second time.

Has anyone had any experience with generating functionality this way,
and could you give me some pointers in the right direction? Any tips,
advice, book recommendations are more than welcome.


Kind regards,
Andrej Mitrovic
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Script Creator/Generator (function factory)

2010-03-30 Thread Andrej Mitrovic
I forgot to mention, I'm using Python 2.5.x. I can't use Python 3
unfortunately, the 3rd party application uses Py2.5.x internally, so I
have to limit the functionality to that version.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Updated License Term Agreement for VC Redistributable in VS 2008 SP1

2010-04-14 Thread Andrej Mitrovic
On Apr 14, 10:11 pm, pyt...@bdurham.com wrote:
> I just stumbled across the following page which seems to indicate that
> the MS VC 2008 runtime files[1] required to distribute Python
> applications compiled with Py2exe and similar tools can be shipped
> without the license restriction many previously thought.
>
> See: Updated License Term Agreement for VC Redistributable in VS 2008
> SP1http://code.msdn.microsoft.com/KB956414
>
> 
> The End User License Agreement (EULA) attached to the English version of
> Visual C++ (VC) Redistributable Package (VCRedistx86.exe,
> VCRedistx64.exe, and VCRedist_ia64.exe) in Microsoft Visual Studio 2008
> does not let you redistribute the VC Redist files. It specifies that you
> may only install and use one copy of the software.
>
> > The correct EULA allows installation and use of any number of
> copies of the VC Redist packages. <
>
> CAUSE
>
> This problem occurs when Visual Studio 2008 SP1 installs incorrect VC
> Redist files that have the wrong EULAs to the computer.
> 
>
> I know there's been lots of confusion about whether developers can ship
> these DLL files directly or whether developers must ship the Visual C++
> 2008 Redistributable Package SP 1 files (vcredist_x86.exe or
> vcredist_x64.exe) - I think the above article should settle this debate
> once and for all.
>
> Malcolm
>
> 1. MS VC 2008 runtime files: msvcr90.dll, msvcp90.dll, msvcm90.dll

The article links to this Knowledge Base article:
http://support.microsoft.com/kb/956414

In that article, under the More Information, it reads:

APPLIES TO

* Microsoft Visual Studio Team System 2008 Team Suite
* Microsoft Visual Studio Team System 2008 Team Foundation Server
* Microsoft Visual Studio Team System 2008 Test Load Agent
* Microsoft Visual Studio Team System 2008 Database Edition
* Microsoft Visual Studio Team System 2008 Architecture Edition
* Microsoft Visual Studio Team System 2008 Development Edition
* Microsoft Visual Studio Team System 2008 Test Edition
* Microsoft Visual Studio 2008 Standard Edition
* Microsoft Visual Studio 2008 Professional Edition
* Microsoft Visual Studio 2008 Academic Edition
* Microsoft Visual Studio 2008 Tools for Applications Software
Development Kit

I don't think this license agreement change involves the express
editions, which are free. Correct me if I'm wrong here?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why this exception catch doesn't work?? (python 3)

2010-04-20 Thread Andrej Mitrovic
On Apr 20, 1:06 pm, MRAB  wrote:
> Dodo wrote:
> > Hello,
>
> > I don't understand why this won't execute
>
> > import urllib.request as u
> > import socket
> > socket.setdefaulttimeout(10)
>
> > l = "http://img144.imageshack.us/my.php?image=koumakandg8.jpg"; #
> > supposed to timeout
> > try:
> >     h = u.urlretrieve(l)
> > except u.URLError, e: # I tried u.e too, no effect.
> >     print(e)
> > except:
> >     print("other error")
>
> > The error :
>
> > ...\Python>err.py
> >   File "...\err.py", line 8
> >     except u.URLError, e: # I tried u.e too, no effect.
> >                      ^
> > SyntaxError: invalid syntax
>
> In Python 3 it's:
>
>      except u.URLError as e:
>
> This a because in Python 2 people sometimes write:
>
>      except OSError, IOError:
>
> thinking that it will catch both OSError and IOError.

except (OSError, IOError), e:  # Python 2.x

If you put them in a tuple, it will catch them, right?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Download Proprietary Microsoft Products Now

2010-04-26 Thread Andrej Mitrovic
On Apr 26, 12:16 pm, Lawrence D'Oliveiro  wrote:
> Just been looking at this review of Visual Studio 2010
> :
>
>     ... the 2GB ISO was quicker to download than it was to install - not
>     even counting the several reboots required.
>
> Since when do you need to REBOOT just to install a development environment?

Sure beats having to recompile a kernel to support 3rd party audio
drivers. But YMMV.

Although I agree, moving away from VS would be nice. Since Unladen
Swallow will eventually be merged with Python, will the dev team
consider trying out Clang as an alternative to VS?
-- 
http://mail.python.org/mailman/listinfo/python-list