Re: seemingly simple list indexing problem

2008-07-28 Thread iu2
On Jul 29, 2:26 am, John Krukoff <[EMAIL PROTECTED]> wrote:
> On Mon, 2008-07-28 at 16:00 -0700, iu2 wrote:
> > On Jul 29, 12:10 am, John Krukoff <[EMAIL PROTECTED]> wrote:
> > > On Mon, 2008-07-28 at 16:24 -0500, Ervan Ensis wrote:
> > > > My programming skills are pretty rusty and I'm just learning Python so
> > > > this problem is giving me trouble.
>
> > > > I have a list like [108, 58, 68].  I want to return the sorted indices
> > > > of these items in the same order as the original list.  So I should
> > > > return [2, 0, 1]
>
> > > > For a list that's already in order, I'll just return the indices, i.e.
> > > > [56, 66, 76] should return [0, 1, 2]
>
> > > > Any help would be appreciated.
>
> > > > --
> > > >http://mail.python.org/mailman/listinfo/python-list
>
> > > If your lists aren't so large that memory is an issue, this might be a
> > > good place for a variation of decorate, sort, undecorate.
>
> > > >>> listToSort = [ 108, 58, 68 ]
> > > >>> decorated = [ ( data, index ) for index, data in
>
> > > enumerate( listToSort ) ]>>> decorated
>
> > > [(108, 0), (58, 1), (68, 2)]>>> result = [ None, ] * len( listToSort )
> > > >>> for sortedIndex, ( ignoredValue, originalIndex ) in
>
> > > enumerate( sorted( decorated ) ):
> > > ...     result[ originalIndex ] = sortedIndex
> > > ...>>> result
>
> > > [2, 0, 1]
>
> > > --
> > > John Krukoff <[EMAIL PROTECTED]>
> > > Land Title Guarantee Company
>
> > Inspired by your idea and the above one, here is another try:
>
> > >>> a0 = [108, 58, 68, 108, 58]
> > >>> a1 = [(x, y) for x, y in enumerate(a0)]
>
> You know this line is a no-op, right?
>
> > >>> a1
> > [(0, 108), (1, 58), (2, 68), (3, 108), (4, 58)]
> > >>> a2 = sorted(a1, lambda x, y: cmp(x[1], y[1]))
>
> If you're going to do the unpacking here for the sort, just use
> enumerate directly. Since this is a simple case, should use the key
> parameter instead of the cmp parameter for speed. Can also use the
> operator module to avoid a bit of lambda overhead:
>
> >>> import operator
> >>> a2 = sorted( enumerate( a0 ), key = operator.itemgetter( 1 ) )
> > >>> a2
> > [(1, 58), (4, 58), (2, 68), (0, 108), (3, 108)]
> > >>> a3 = [a2.index(x) for x in a1]
> > >>> a3
> > [3, 0, 2, 4, 1]
>
> > The idea is to make each item unique (by making it a tuple), and then
> > apply the naive solution.
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> Using index is still kinda evil, due to the exponential time required
> since you're rescanning half the list (on average) to find each index
> value.
>
> --
> John Krukoff <[EMAIL PROTECTED]>
> Land Title Guarantee Company- Hide quoted text -
>
> - Show quoted text -

Well, a dictionary can replace the index search

helper_dict = dict(zip(a2, xrange(len(a2
>>> helper_dict
{(1, 58): 0, (4, 58): 1, (3, 108): 4, (2, 68): 2, (0, 108): 3}

a3 = [helper_dict[x] for x in a1]
>>> a3
[3, 0, 2, 4, 1]

The performance now should be n*log(n)
--
http://mail.python.org/mailman/listinfo/python-list


Re: interpreter vs. compiled

2008-07-28 Thread Tim Roberts
castironpi <[EMAIL PROTECTED]> wrote:
>
>In CPython yes.  In IronPython yes:  the parts that are compiled into
>machine code are the interpreter, *not user's code*. 

WRONG!  You are WRONG.  At "compile" time, the Python code is compiled to
an intermediate language.  At "run" time, the intermediate language (which
is still the user's code, just in another representation) is compiled into
machine language.  It is the user's program, not the interpreter.

It's the exact same process that occurs in a C compiler.  Most C compilers
translate the C program to an intermediate form before finally converting
it to machine language.  The only difference is that, in a C compiler, both
steps occur within the compiler.  In IronPython, the two steps are
separated in time.  There is no other difference.

>Without that
>step, the interpreter would be running on an interpreter, but that
>doesn't get the user's statement 'a= b+ 1' into registers-- it gets
>'push, push, add, pop' into registers.

You have a fundamental misunderstanding of the compilation process.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: seemingly simple list indexing problem

2008-07-28 Thread iu2
On Jul 29, 3:59 am, John Machin <[EMAIL PROTECTED]> wrote:
> On Jul 29, 8:10 am, John Krukoff <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On Mon, 2008-07-28 at 16:24 -0500, Ervan Ensis wrote:
> > > My programming skills are pretty rusty and I'm just learning Python so
> > > this problem is giving me trouble.
>
> > > I have a list like [108, 58, 68].  I want to return the sorted indices
> > > of these items in the same order as the original list.  So I should
> > > return [2, 0, 1]
>
> > > For a list that's already in order, I'll just return the indices, i.e.
> > > [56, 66, 76] should return [0, 1, 2]
>
> > > Any help would be appreciated.
>
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
>
> > If your lists aren't so large that memory is an issue, this might be a
> > good place for a variation of decorate, sort, undecorate.
>
> > >>> listToSort = [ 108, 58, 68 ]
> > >>> decorated = [ ( data, index ) for index, data in
>
> > enumerate( listToSort ) ]>>> decorated
>
> > [(108, 0), (58, 1), (68, 2)]>>> result = [ None, ] * len( listToSort )
> > >>> for sortedIndex, ( ignoredValue, originalIndex ) in
>
> > enumerate( sorted( decorated ) ):
> > ...     result[ originalIndex ] = sortedIndex
> > ...>>> result
>
> > [2, 0, 1]
>
> Simpliciter:
>
>
>
> >>> data = [99, 88, 77, 88, 66]
> >>> [x[1] for x in sorted(zip(data, xrange(len(data]
> [4, 2, 1, 3, 0]
>
> Use case? Think data == database table, result == index ...- Hide quoted text 
> -
>
> - Show quoted text -

I think it is wrong, using this on my data returns the wrong result
 data = [108, 58, 68, 108]
>>> [x[1] for x in sorted(zip(data, xrange(len(data]
[1, 2, 0, 3]
--
http://mail.python.org/mailman/listinfo/python-list


Re: block/lambda

2008-07-28 Thread John Nagle

iu2 wrote:

Hi,

Playing with imitating lambdas and ruby blocks in Python, I came up
with a very simple construct, for example:

import compiler


   Python supports nested functions.  You don't have to use a lambda
form just to get a local function.  Just write an ordinary nested
def within another def.

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


Re: Questions on 64 bit versions of Python (Thank-you!)

2008-07-28 Thread python
Dear List,

Thanks for everyone's feedback - excellent detail - all my questions
have been answered.

BTW: Roel was correct that I got confused over the AMD and Intel naming
conventions regarding the 64 bit versions of Python for Windows. (I
missed that nuance that the Intel build refered to the Itanium vs. the
standard off-the-rack 64 bit version of Intel's 586/686 CPU)

Best regards,
Malcolm
--
http://mail.python.org/mailman/listinfo/python-list


Re: Download excel file from web?

2008-07-28 Thread [EMAIL PROTECTED]
On Jul 28, 6:05 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> On Mon, Jul 28, 2008 at 9:39 PM, MRAB <[EMAIL PROTECTED]> wrote:
> > On Jul 29, 12:41 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> >> On Jul 28, 4:20 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>
> >> > On Mon, Jul 28, 2008 at 8:04 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
> >> > wrote:
> >> > > On Jul 28, 3:52 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> >> > >> On Mon, Jul 28, 2008 at 7:43 PM, [EMAIL PROTECTED] <[EMAIL 
> >> > >> PROTECTED]> wrote:
> >> > >> > On Jul 28, 3:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> >> > >> >> On Jul 28, 3:29 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> >> > >> >> > [EMAIL PROTECTED] schrieb:
>
> >> > >> >> > > On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> 
> >> > >> >> > > wrote:
> >> > >> >> > >> Hi - experienced programmer but this is my first Python 
> >> > >> >> > >> program.
>
> >> > >> >> > >> This URL will retrieve an excel spreadsheet containing (that 
> >> > >> >> > >> day's)
> >> > >> >> > >> msci stock index returns.
>
> >> > >> >> > >>http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>
> >> > >> >> > >> Want to write python to download and save the file.
>
> >> > >> >> > >> So far I've arrived at this:
>
> >> > >> >> > >> [quote]
> >> > >> >> > >> # import pdb
> >> > >> >> > >> import urllib2
> >> > >> >> > >> from win32com.client import Dispatch
>
> >> > >> >> > >> xlApp = Dispatch("Excel.Application")
>
> >> > >> >> > >> # test 1
> >> > >> >> > >> # xlApp.Workbooks.Add()
> >> > >> >> > >> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
> >> > >> >> > >> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
> >> > >> >> > >> # xlBook = xlApp.ActiveWorkbook
> >> > >> >> > >> # xlBook.SaveAs(Filename='C:\\test.xls')
>
> >> > >> >> > >> # pdb.set_trace()
> >> > >> >> > >> response = 
> >> > >> >> > >> urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> >> > >> >> > >> excel?
> >> > >> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> >> > >> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional')
> >> > >> >> > >> # test 2 - returns check = False
> >> > >> >> > >> check_for_data = 
> >> > >> >> > >> urllib2.Request('http://www.mscibarra.com/webapp/
> >> > >> >> > >> indexperf/excel?
> >> > >> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> >> > >> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>
> >> > >> >> > >> xlApp = response.fp
> >> > >> >> > >> print(response.fp.name)
> >> > >> >> > >> print(xlApp.name)
> >> > >> >> > >> xlApp.write
> >> > >> >> > >> xlApp.Close
> >> > >> >> > >> [/quote]
>
> >> > >> >> > > Woops hit Send when I wanted Preview.  Looks like the html 
> >> > >> >> > > [quote] tag
> >> > >> >> > > doesn't work from groups.google.com (nice).
>
> >> > >> >> > > Anway, in test 1 above, I determined how to instantiate an 
> >> > >> >> > > excel
> >> > >> >> > > object; put some stuff in it; then save to disk.
>
> >> > >> >> > > So, in theory, I'm retrieving my excel spreadsheet with
>
> >> > >> >> > > response = urllib2.urlopen()
>
> >> > >> >> > > Except what then do I do with this?
>
> >> > >> >> > > Well for one read some of the urllib2 documentation and found 
> >> > >> >> > > the
> >> > >> >> > > Request class with the method has_data() on it.  It returns 
> >> > >> >> > > False.
> >> > >> >> > > Hmm that's not encouraging.
>
> >> > >> >> > > I supposed the trick to understand what urllib2.urlopen is 
> >> > >> >> > > returning
> >> > >> >> > > to me; rummage around in there; and hopefully find my excel 
> >> > >> >> > > file.
>
> >> > >> >> > > I use pdb to debug.  This is interesting:
>
> >> > >> >> > > (Pdb) dir(response)
> >> > >> >> > > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 
> >> > >> >> > > 'close',
> >> > >> >> > > 'code', '
> >> > >> >> > > fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 
> >> > >> >> > > 'read',
> >> > >> >> > > 'readline', '
> >> > >> >> > > readlines', 'url']
> >> > >> >> > > (Pdb)
>
> >> > >> >> > > I suppose the members with __*_ are methods; and the names 
> >> > >> >> > > without the
> >> > >> >> > > underbars are attributes (variables) (?).
>
> >> > >> >> > No, these are the names of all attributes and methods. read is a 
> >> > >> >> > method,
> >> > >> >> > for example.
>
> >> > >> >> right - I got it backwards.
>
> >> > >> >> > > Or maybe this isn't at all the right direction to take (maybe 
> >> > >> >> > > there
> >> > >> >> > > are much better modules to do this stuff).  Would be happy to 
> >> > >> >> > > learn if
> >> > >> >> > > that's the case (and if that gets the job done for me).
>
> >> > >> >> > The docs (http://docs.python.org/lib/module-urllib2.html) are 
> >> > >> >> > pretty
> >> > >> >> > clear on this:
>
> >> > >> >> > """
> >> > >> >> > This function returns a file-like object with two additional 
> >> > >> >> > methods:
> >> > >> >> > """
>
> 

Re: Download excel file from web?

2008-07-28 Thread [EMAIL PROTECTED]
On Jul 28, 6:05 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> On Mon, Jul 28, 2008 at 9:39 PM, MRAB <[EMAIL PROTECTED]> wrote:
> > On Jul 29, 12:41 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> >> On Jul 28, 4:20 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>
> >> > On Mon, Jul 28, 2008 at 8:04 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
> >> > wrote:
> >> > > On Jul 28, 3:52 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> >> > >> On Mon, Jul 28, 2008 at 7:43 PM, [EMAIL PROTECTED] <[EMAIL 
> >> > >> PROTECTED]> wrote:
> >> > >> > On Jul 28, 3:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> >> > >> >> On Jul 28, 3:29 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> >> > >> >> > [EMAIL PROTECTED] schrieb:
>
> >> > >> >> > > On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> 
> >> > >> >> > > wrote:
> >> > >> >> > >> Hi - experienced programmer but this is my first Python 
> >> > >> >> > >> program.
>
> >> > >> >> > >> This URL will retrieve an excel spreadsheet containing (that 
> >> > >> >> > >> day's)
> >> > >> >> > >> msci stock index returns.
>
> >> > >> >> > >>http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>
> >> > >> >> > >> Want to write python to download and save the file.
>
> >> > >> >> > >> So far I've arrived at this:
>
> >> > >> >> > >> [quote]
> >> > >> >> > >> # import pdb
> >> > >> >> > >> import urllib2
> >> > >> >> > >> from win32com.client import Dispatch
>
> >> > >> >> > >> xlApp = Dispatch("Excel.Application")
>
> >> > >> >> > >> # test 1
> >> > >> >> > >> # xlApp.Workbooks.Add()
> >> > >> >> > >> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
> >> > >> >> > >> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
> >> > >> >> > >> # xlBook = xlApp.ActiveWorkbook
> >> > >> >> > >> # xlBook.SaveAs(Filename='C:\\test.xls')
>
> >> > >> >> > >> # pdb.set_trace()
> >> > >> >> > >> response = 
> >> > >> >> > >> urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> >> > >> >> > >> excel?
> >> > >> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> >> > >> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional')
> >> > >> >> > >> # test 2 - returns check = False
> >> > >> >> > >> check_for_data = 
> >> > >> >> > >> urllib2.Request('http://www.mscibarra.com/webapp/
> >> > >> >> > >> indexperf/excel?
> >> > >> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> >> > >> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>
> >> > >> >> > >> xlApp = response.fp
> >> > >> >> > >> print(response.fp.name)
> >> > >> >> > >> print(xlApp.name)
> >> > >> >> > >> xlApp.write
> >> > >> >> > >> xlApp.Close
> >> > >> >> > >> [/quote]
>
> >> > >> >> > > Woops hit Send when I wanted Preview.  Looks like the html 
> >> > >> >> > > [quote] tag
> >> > >> >> > > doesn't work from groups.google.com (nice).
>
> >> > >> >> > > Anway, in test 1 above, I determined how to instantiate an 
> >> > >> >> > > excel
> >> > >> >> > > object; put some stuff in it; then save to disk.
>
> >> > >> >> > > So, in theory, I'm retrieving my excel spreadsheet with
>
> >> > >> >> > > response = urllib2.urlopen()
>
> >> > >> >> > > Except what then do I do with this?
>
> >> > >> >> > > Well for one read some of the urllib2 documentation and found 
> >> > >> >> > > the
> >> > >> >> > > Request class with the method has_data() on it.  It returns 
> >> > >> >> > > False.
> >> > >> >> > > Hmm that's not encouraging.
>
> >> > >> >> > > I supposed the trick to understand what urllib2.urlopen is 
> >> > >> >> > > returning
> >> > >> >> > > to me; rummage around in there; and hopefully find my excel 
> >> > >> >> > > file.
>
> >> > >> >> > > I use pdb to debug.  This is interesting:
>
> >> > >> >> > > (Pdb) dir(response)
> >> > >> >> > > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 
> >> > >> >> > > 'close',
> >> > >> >> > > 'code', '
> >> > >> >> > > fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 
> >> > >> >> > > 'read',
> >> > >> >> > > 'readline', '
> >> > >> >> > > readlines', 'url']
> >> > >> >> > > (Pdb)
>
> >> > >> >> > > I suppose the members with __*_ are methods; and the names 
> >> > >> >> > > without the
> >> > >> >> > > underbars are attributes (variables) (?).
>
> >> > >> >> > No, these are the names of all attributes and methods. read is a 
> >> > >> >> > method,
> >> > >> >> > for example.
>
> >> > >> >> right - I got it backwards.
>
> >> > >> >> > > Or maybe this isn't at all the right direction to take (maybe 
> >> > >> >> > > there
> >> > >> >> > > are much better modules to do this stuff).  Would be happy to 
> >> > >> >> > > learn if
> >> > >> >> > > that's the case (and if that gets the job done for me).
>
> >> > >> >> > The docs (http://docs.python.org/lib/module-urllib2.html) are 
> >> > >> >> > pretty
> >> > >> >> > clear on this:
>
> >> > >> >> > """
> >> > >> >> > This function returns a file-like object with two additional 
> >> > >> >> > methods:
> >> > >> >> > """
>
> 

Re: with statement for two files

2008-07-28 Thread greg

Diez B. Roggisch wrote:

Paul Rubin wrote:

>

> use contextlib.nexted().

You mean contextlib.nested I guess.


Although "nexted" is an intriguing-sounding word. I wonder
what it could mean?

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


Re: Rant (was Re: x*x if x>10

2008-07-28 Thread greg

Diez B. Roggisch wrote:

I maybe should paraphrase "don't return objects you passed as arguments 
from a function".


The important thing is that a function shouldn't modify
any object unless it's the express purpose of the function
to do so.

You could call this the "look but don't touch" rule.

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


Re: Attack a sacred Python Cow

2008-07-28 Thread Russ P.
On Jul 28, 8:44 pm, alex23 <[EMAIL PROTECTED]> wrote:
> On Jul 29, 4:46 am, "Russ P." <[EMAIL PROTECTED]> wrote:
>
> > As I said, I could write a pre-processor myself to
> > implement it in less than a day.
>
> So WHY DON'T YOU WRITE IT ALREADY?

I'm working on something else right now if you don't mind, but I'll
get to it in good time.

Conceptually, the matter is simple. All I need to do is to grab the
first formal argument of each def, then search for occurrences of any
word in the body of the def that starts with a dot, and insert that
first argument in front of it.

I expect the "hard" part will be breaking up the body of the def into
"words." I could just split each line on white space, except for
situations like

x+=.zzz

So I need to account for the fact that operators do not need to be
surrounded by spaces. That's the hardest part I can think of off the
top of my head.

Maybe I'll encounter an insurmountable problem and realize that the
idea can't work in general. If so, then so be it. Certainly, no one on
this thread has anticipated such a problem. Had someone pointed out an
actual technical problem with the idea, I would have gladly thanked
them. But I got a load of irrelevant crap instead, not to mention
being addressed as "boy."

> If you're meeting so much resistance to your idea, why not scratch
> your own damn itch and just do it?
>
> Or doesn't that afford you as many chances to insult others while
> feeling smugly superior?

This coming from a guy who insulted my reading comprehension ability
-- when he was the one who was wrong!
--
http://mail.python.org/mailman/listinfo/python-list


Re: interpreter vs. compiled

2008-07-28 Thread castironpi
On Jul 28, 5:58 pm, Fuzzyman <[EMAIL PROTECTED]> wrote:
> On Jul 27, 6:02 am, castironpi <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jul 24, 11:04 pm, Tim Roberts <[EMAIL PROTECTED]> wrote:
>
> > > castironpi <[EMAIL PROTECTED]> wrote:
>
> > > >Compiling a program is different than running it.  A JIT compiler is a
> > > >kind of compiler and it makes a compilation step.  I am saying that
> > > >Python is not a compiler and in order to implement JIT, it would have
> > > >to change that fact.
>
> > > And I'm saying you are wrong.  There is NOTHING inherent in Python that
> > > dictates that it be either compiled or interpreted.  That is simply an
> > > implementation decision.  The CPython implementation happens to interpret.
> > > The IronPython implementation compiles the intermediate language to native
> > > machine language.
>
> > > >> of Python that uses .NET.  In that case, the code *IS* JIT compiled to
> > > >> assembly when the program starts.
>
> > > >But still not the user's code, only the interpreter, which is running
> > > >in assembly already anyway in CPython.
>
> > > In CPython, yes.  In IronPython, no; the user's code is compiled into
> > > machine language.  Both of them are "Python".
> > > --
> > > Tim Roberts, [EMAIL PROTECTED]
> > > Providenza & Boekelheide, Inc.
>
> > In CPython yes.  In IronPython yes:  the parts that are compiled into
> > machine code are the interpreter, *not user's code*.  Without that
> > step, the interpreter would be running on an interpreter, but that
> > doesn't get the user's statement 'a= b+ 1' into registers-- it gets
> > 'push, push, add, pop' into registers.
>
> Well - in IronPython user code gets compiled to in memory assemblies
> which can be JIT'ed.
>
> Michael Foord
> --http://www.ironpythoninaction.com/

I don't believe so.

Take a sample interpreted language, to be compiled by a sample JIT.

a= stack( )
a.push( 0 )
a.push( 2 )
a.push( 4 )

Bytecode output is:

allocate var0
call STACK_CONSTRUCTOR
initialize var0 return
call METH0 var0 const 0
call METH0 var0 const 2
call METH0 var0 const 4

JIT output is assembly:

reg0 malloc 4
setjmp
jmp STACK_CONSTRUCTOR
popjmpv reg1
setjmp
reg1 0
jmp METH0
reg1 2
jmp METH0
reg1 4
jmp METH0

But when you compare the C code for 'x= y+ 1' to Python JIT code for
'x= y+ 1', there is no stack and no error checking.  They're quite
different.  In a JIT language, Python runs in native assembly, output
similar to CPython, theoretically.  User's code -does- -not- -run-.
It is moved in to and out of a stack by a program that is running,
namely the interpreter, whether it came from C and a compiler,
or .NEt, bytecode, and a JIT.
--
http://mail.python.org/mailman/listinfo/python-list


Re: exec(code) not allowing import on top level?

2008-07-28 Thread Gary Herron

Peter Teuben wrote:


if I define a simple string code, with the following contents:

import math
def foo(x):
  return math.sqrt(x)


What?  You have not told us something important here.  First, that code 
won't fail because it does not even execute the function foo -- it just 
defines it.Second, if I extended your string with one more line 
"foo(123)" to actually execute the code, it still works as expected.


So let's try this again...  and this time please please also show us the 
full text of the error message.


Gary Herron




and i run it using exec(code) in python, math is not known. But when I
recode the string as:

def foo(x):
  import math
  return math.sqrt(x)

it works fine. That seemed like an inconsistency, since it works
fine otherwise, as expected. It's easy to work around, but
just odd to find this out.

thanks

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


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


Re: exec(code) not allowing import on top level?

2008-07-28 Thread Gary Herron

Peter Teuben wrote:


if I define a simple string code, with the following contents:

import math
def foo(x):
  return math.sqrt(x)


What?  You have not told us something important here.  First, that code 
won't fail because it does not even execute the function foo -- it just 
defines it.Second, if I exend your string with one more line 
"foo(123)" to actually execute the code, it still works as expected.


So let's try this again...  and this time please please also show us the 
full text of the error message.


Gary Herron




and i run it using exec(code) in python, math is not known. But when I
recode the string as:

def foo(x):
  import math
  return math.sqrt(x)

it works fine. That seemed like an inconsistency, since it works
fine otherwise, as expected. It's easy to work around, but
just odd to find this out.

thanks

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


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


Dynamically adding methods to a class...

2008-07-28 Thread Piyush Anonymous
class MyObject:
   def __init__(self, name):
 self.name = name

   def do_this_default(self):
  print "default do_this implementation for %s" % self.name

def custom_do_this(): #method to be added
   print "custom do_this implementation for %s" % self.name


def funcToMethod(func,clas,method_name=None):
"""Adds func to class so it is an accessible method; use method_name to
specify the name to be used for calling the method.
The new method is accessible to any instance immediately."""
import new
method = new.instancemethod(func,None,clas)
print method
if not method_name: method_name=func.__name__
clas.__dict__[method_name]=func


myobj = MyObject('myobj1')
funcToMethod(custom_do_this,MyObject) #trying 2 add method to class not
instance
print myobj.custom_do_this()

---
Error I am getting;
TypeError: custom_do_this() takes no arguments (1 given)

Why am I getting it?

Also how can I do this in new style class (inherited from 'object')?
--
http://mail.python.org/mailman/listinfo/python-list

Re: block/lambda

2008-07-28 Thread castironpi
On Jul 28, 3:12 pm, iu2 <[EMAIL PROTECTED]> wrote:
> On Jul 28, 10:06 pm, iu2 <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
>
> > Playing with imitating lambdas and ruby blocks in Python, I came up
> > with a very simple construct, for example:
>
> > import compiler
>
> > def dotimes(i, code):
> >     for i in range(i):
> >         exec code
>
> > dotimes(5, '''
> > for j in range(i):
> >         print j,
> > print
> > ''', '', 'exec')
>
> > This will print
> > 0
> > 0 1
> > 0 1 2
> > 0 1 2 3
>
> > A more efficient code would probably be
>
> > dotimes(5, compiler.compile('''
> > for j in range(i):
> >         print j,
> > print
> > ''', '', 'exec'))
>
> > which is, to my understanding, exactly what a ruby block is.
>
> > But the actual "discovery" here, is that the triple quote - ''' -
> > makes a syntax for block passing. Having a code editor that keeps
> > colorizing what's inside the quotes like a normal code would make it
> > easier to maintain.
>
> > Is it possible to grant Python another syntactic mark, similar to
> > triple quotes, that will actually make the enclosed code a compiled
> > code, or an anonymous function?
>
> > I know that anonymous functions (long lambdas...) are not on the road
> > map. But I ask this because, as I understand it, the triple quote
> > actually presents a syntax for it.
> > Isn't it actually a matter of taking the triple-quotes a little bit
> > further?
>
> > Thanks
>
> There is a mistake in my first example, the code is, of course:
> dotimes(5, '''
> for j in range(i):
>         print j,
> print
> ''')
>
> Sorry...

You could do

code= '''#
for _ in range( 2 ):
  pass
'''

and signify the code block to your editor with the leading blank
comment.
--
http://mail.python.org/mailman/listinfo/python-list


Re: derivative in numpy

2008-07-28 Thread castironpi
On Jul 28, 5:34 pm, [EMAIL PROTECTED] wrote:
> Hi,
>
> I am looking to do a simple derivative. I would expect such a function
> to be available in numpy, but can't find it. I have written my own,
> but just curious if anybody knows of such function in numpy.
>
> Cheers,
>  Kim

I presume you are taking the numerical derivative, not the symbolic
one.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Attack a sacred Python Cow

2008-07-28 Thread alex23
On Jul 29, 4:46 am, "Russ P." <[EMAIL PROTECTED]> wrote:
> As I said, I could write a pre-processor myself to
> implement it in less than a day.

So WHY DON'T YOU WRITE IT ALREADY?

If you're meeting so much resistance to your idea, why not scratch
your own damn itch and just do it?

Or doesn't that afford you as many chances to insult others while
feeling smugly superior?
--
http://mail.python.org/mailman/listinfo/python-list


exec(code) not allowing import on top level?

2008-07-28 Thread Peter Teuben


if I define a simple string code, with the following contents:

import math
def foo(x):
  return math.sqrt(x)

and i run it using exec(code) in python, math is not known. But when I
recode the string as:

def foo(x):
  import math
  return math.sqrt(x)

it works fine. That seemed like an inconsistency, since it works
fine otherwise, as expected. It's easy to work around, but
just odd to find this out.

thanks

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


Re: Attack a sacred Python Cow

2008-07-28 Thread Ben Finney
Ben Finney <[EMAIL PROTECTED]> writes:

> It has, at least, long ago bought him a place in my kill-file.
> Seeing your side of the conversation, I can only confirm that
> decision as correct.

This should perhaps say "seeing the parts of his communication that
leak through by being quoted in others's posts, I can only confirm my
decision as correct."

-- 
 \“Pinky, are you pondering what I'm pondering?” “Wuh, I think |
  `\   so, Brain, but wouldn't anything lose its flavor on the bedpost |
_o__)   overnight?” —_Pinky and The Brain_ |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: Is it allowed to use function results as default arguments ?

2008-07-28 Thread Benjamin
On Jul 28, 3:28 pm, Stef Mientki <[EMAIL PROTECTED]> wrote:
> hello,
>
> I've a perfect working procedure,
> at least as far I've tested it it works perfect.
>
> But I was just experimenting with inspect,
> and saw that the default argument was not parsed correctly.
>
> So I wonder if this is allowed:
>
> def Get_Relative_Path ( target, base=os.curdir ) :

Did you perhaps mean to say def Get_Relative_Path(target,
base=os.getcwd()):
>   ...
>
> As inspect returns the following:
>
> (['target', 'base'], None, None, ('.',))
>
> thanks,
> Stef Mientki

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


Re: Attack a sacred Python Cow

2008-07-28 Thread Russ P.
On Jul 28, 12:08 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:

> > It's a very simple idea that you insist on
> > making complicated. As I said, I could write a pre-processor myself to
> > implement it in less than a day.
>
> Preprocessor are not a solution. Sorry.

I never said that a pre-processor is a good permanent solution, but
the simple fact that my proposal can be done with a simple pre-
processor means that it does not change the inner workings of the
Python interpreter.

> Oh, you don't stand people disagreing with you, that's it ?

I can stand people disagreeing with me all day long, so long as they
are making sense. You are simply making the issue more complicated
that it is because you are apparently incapable of understanding the
substance of it.

> > You seem to think that being a "regular" on this newsgroup somehow
> > gives you special status.
>
> Why so ? Because I answer to your proposition and not agree with  your
> arguments ??? C'mon, be serious, you have the right to post your
> proposition here, I have the right to post my reaction to your
> proposition, period. Grow up, boy.

> Boy, I don't know who you think you're talking to, but you're obviously
> out of luck here. I'm 41, married, our son is now a teenager, I have an
> happy social life, quite a lot of work, and no time to waste in the
> streets. And FWIW, name-calling won't buy you much here.

There you go again. Do you think you are proving something by
addressing me as "boy"? I'll make a little wager with you. I'll bet
that what I am using Python for dwarfs in importance what you are
using it for. Care to put the cards on the table, big man?

I'll tell you something else while I'm at it. I'm ten years older than
you, but I pump iron and stay in excellent shape. If you addressed me
as "boy" in person, I'd be more than happy to teach you a badly needed
lesson you won't soon forget, big man.
--
http://mail.python.org/mailman/listinfo/python-list


Re: ctypes - unloading implicitly loaded dlls

2008-07-28 Thread pigmartian

Nick Craig-Wood wrote:


You could try loading C explicitly with ctypes.LoadLibrary() before
loading A, then you'll have a handle to unload it before you load B.


I did think of that, but no luck.  Guess the cdll doesn't look for a dll 
loaded already by python.  I guess that does make sense.




I think I'd probably split the code into two or three processes
though.  Perhaps use http://pypi.python.org/pypi/processing to
communicate between them.  That should get you out of DLL Hell!
(Don't load any of the DLLs before you start the worker processes
off.)


That was quite a helpful suggestion, thank you.  I had been using the 
subprocess module actually, but really didn't like that approach. 
processing is much nicer.  Pipes, in particular, is quite handy.


~Scott

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


Re: Attack a sacred Python Cow

2008-07-28 Thread Russ P.
On Jul 28, 5:44 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
> > Boy, I don't know who you think you're talking to, but you're
> > obviously out of luck here. I'm 41, married, our son is now a
> > teenager, I have an happy social life, quite a lot of work, and no
> > time to waste in the streets. And FWIW, name-calling won't buy you
> > much here.
>
> It has, at least, long ago bought him a place in my kill-file. Seeing
> your side of the conversation, I can only confirm that decision as
> correct.

Now there's a classic reply from another comp.lang.python regular. All
he needs is one side of the conversation to know what's going on!

I'd really like to know where both of you guys find the time to spend
here, because unless you type extremely fast, I figure it's about
10-20 hours per week every week. Sorry, but if you also have "quite a
lot of work," I don't believe that leaves much time for a "happy
social life."

Each and every time I get involved in an extended discussion about
Python here, I end up realizing that I've wasted a lot of time trying
to reason with unreasonable people who are infatuated with Python and
incapable of recognizing any deficiencies.

I will thank you for one thing. By taking your best shot at my
suggestion and coming up with nothing significant or relevant, you
have given me confidence to go ahead with a PEP. I may just do it. If
it is rejected, then so be it. Unlike you, they will have to give me a
valid reason to reject it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-28 Thread Steven D'Aprano
On Tue, 29 Jul 2008 00:23:02 +, Steven D'Aprano wrote:

> Dude. Dude. Just... learn some Python before you embarrass yourself
> further.


I'm sorry Anders, that was a needlessly harsh thing for me to say. I 
apologize for the unpleasant tone. 

Still, __nonzero__ is a fundamental part of Python's behaviour. You 
should learn about it.



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


Re: Download excel file from web?

2008-07-28 Thread Guilherme Polo
On Mon, Jul 28, 2008 at 9:39 PM, MRAB <[EMAIL PROTECTED]> wrote:
> On Jul 29, 12:41 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> On Jul 28, 4:20 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>>
>>
>>
>> > On Mon, Jul 28, 2008 at 8:04 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
>> > wrote:
>> > > On Jul 28, 3:52 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>> > >> On Mon, Jul 28, 2008 at 7:43 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
>> > >> wrote:
>> > >> > On Jul 28, 3:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> > >> >> On Jul 28, 3:29 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>>
>> > >> >> > [EMAIL PROTECTED] schrieb:
>>
>> > >> >> > > On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> 
>> > >> >> > > wrote:
>> > >> >> > >> Hi - experienced programmer but this is my first Python program.
>>
>> > >> >> > >> This URL will retrieve an excel spreadsheet containing (that 
>> > >> >> > >> day's)
>> > >> >> > >> msci stock index returns.
>>
>> > >> >> > >>http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>>
>> > >> >> > >> Want to write python to download and save the file.
>>
>> > >> >> > >> So far I've arrived at this:
>>
>> > >> >> > >> [quote]
>> > >> >> > >> # import pdb
>> > >> >> > >> import urllib2
>> > >> >> > >> from win32com.client import Dispatch
>>
>> > >> >> > >> xlApp = Dispatch("Excel.Application")
>>
>> > >> >> > >> # test 1
>> > >> >> > >> # xlApp.Workbooks.Add()
>> > >> >> > >> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
>> > >> >> > >> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
>> > >> >> > >> # xlBook = xlApp.ActiveWorkbook
>> > >> >> > >> # xlBook.SaveAs(Filename='C:\\test.xls')
>>
>> > >> >> > >> # pdb.set_trace()
>> > >> >> > >> response = 
>> > >> >> > >> urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
>> > >> >> > >> excel?
>> > >> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
>> > >> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional')
>> > >> >> > >> # test 2 - returns check = False
>> > >> >> > >> check_for_data = 
>> > >> >> > >> urllib2.Request('http://www.mscibarra.com/webapp/
>> > >> >> > >> indexperf/excel?
>> > >> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
>> > >> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>>
>> > >> >> > >> xlApp = response.fp
>> > >> >> > >> print(response.fp.name)
>> > >> >> > >> print(xlApp.name)
>> > >> >> > >> xlApp.write
>> > >> >> > >> xlApp.Close
>> > >> >> > >> [/quote]
>>
>> > >> >> > > Woops hit Send when I wanted Preview.  Looks like the html 
>> > >> >> > > [quote] tag
>> > >> >> > > doesn't work from groups.google.com (nice).
>>
>> > >> >> > > Anway, in test 1 above, I determined how to instantiate an excel
>> > >> >> > > object; put some stuff in it; then save to disk.
>>
>> > >> >> > > So, in theory, I'm retrieving my excel spreadsheet with
>>
>> > >> >> > > response = urllib2.urlopen()
>>
>> > >> >> > > Except what then do I do with this?
>>
>> > >> >> > > Well for one read some of the urllib2 documentation and found the
>> > >> >> > > Request class with the method has_data() on it.  It returns 
>> > >> >> > > False.
>> > >> >> > > Hmm that's not encouraging.
>>
>> > >> >> > > I supposed the trick to understand what urllib2.urlopen is 
>> > >> >> > > returning
>> > >> >> > > to me; rummage around in there; and hopefully find my excel file.
>>
>> > >> >> > > I use pdb to debug.  This is interesting:
>>
>> > >> >> > > (Pdb) dir(response)
>> > >> >> > > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 
>> > >> >> > > 'close',
>> > >> >> > > 'code', '
>> > >> >> > > fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 
>> > >> >> > > 'read',
>> > >> >> > > 'readline', '
>> > >> >> > > readlines', 'url']
>> > >> >> > > (Pdb)
>>
>> > >> >> > > I suppose the members with __*_ are methods; and the names 
>> > >> >> > > without the
>> > >> >> > > underbars are attributes (variables) (?).
>>
>> > >> >> > No, these are the names of all attributes and methods. read is a 
>> > >> >> > method,
>> > >> >> > for example.
>>
>> > >> >> right - I got it backwards.
>>
>> > >> >> > > Or maybe this isn't at all the right direction to take (maybe 
>> > >> >> > > there
>> > >> >> > > are much better modules to do this stuff).  Would be happy to 
>> > >> >> > > learn if
>> > >> >> > > that's the case (and if that gets the job done for me).
>>
>> > >> >> > The docs (http://docs.python.org/lib/module-urllib2.html) are 
>> > >> >> > pretty
>> > >> >> > clear on this:
>>
>> > >> >> > """
>> > >> >> > This function returns a file-like object with two additional 
>> > >> >> > methods:
>> > >> >> > """
>>
>> > >> >> > And then for file-like objects:
>>
>> > >> >> >http://docs.python.org/lib/bltin-file-objects.html
>>
>> > >> >> > """
>> > >> >> > read(   [size])
>> > >> >> >  Read at most size bytes from the file (less if the read hits 
>> > >> >> > EOF
>> > >> >> > before obtaining size

Re: seemingly simple list indexing problem

2008-07-28 Thread John Machin
On Jul 29, 8:10 am, John Krukoff <[EMAIL PROTECTED]> wrote:
> On Mon, 2008-07-28 at 16:24 -0500, Ervan Ensis wrote:
> > My programming skills are pretty rusty and I'm just learning Python so
> > this problem is giving me trouble.
>
> > I have a list like [108, 58, 68].  I want to return the sorted indices
> > of these items in the same order as the original list.  So I should
> > return [2, 0, 1]
>
> > For a list that's already in order, I'll just return the indices, i.e.
> > [56, 66, 76] should return [0, 1, 2]
>
> > Any help would be appreciated.
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> If your lists aren't so large that memory is an issue, this might be a
> good place for a variation of decorate, sort, undecorate.
>
> >>> listToSort = [ 108, 58, 68 ]
> >>> decorated = [ ( data, index ) for index, data in
>
> enumerate( listToSort ) ]>>> decorated
>
> [(108, 0), (58, 1), (68, 2)]>>> result = [ None, ] * len( listToSort )
> >>> for sortedIndex, ( ignoredValue, originalIndex ) in
>
> enumerate( sorted( decorated ) ):
> ... result[ originalIndex ] = sortedIndex
> ...>>> result
>
> [2, 0, 1]
>

Simpliciter:

>>> data = [99, 88, 77, 88, 66]
>>> [x[1] for x in sorted(zip(data, xrange(len(data]
[4, 2, 1, 3, 0]
>>>

Use case? Think data == database table, result == index ...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Attack a sacred Python Cow

2008-07-28 Thread Bruno Desthuilliers

Nikolaus Rath a écrit :

Michael Torrie <[EMAIL PROTECTED]> writes:


(snip)


In short, unlike what most of the implicit self advocates are
saying, it's not just a simple change to the python parser to do
this. It would require a change in the interpreter itself and how it
deals with classes.



Thats true. But out of curiosity: why is changing the interpreter such
a bad thing? (If we suppose for now that the change itself is a good
idea).


Because it would very seriously break a *lot* of code ?
--
http://mail.python.org/mailman/listinfo/python-list

Re: python lists and newline character

2008-07-28 Thread Gary Josack

Gary Herron wrote:

Support Desk wrote:


Hello all,

I am using os.popen to get a list returned of vpopmail 
users, something like this


 

x = os.popen('/home/vpopmail/bin/vuserinfo -n -D 
mydomain.com).readlines()


 

x returns a list, of usernames, and I am trying to append the 
usernames with the domain like so


 


for line in x:

print line + [EMAIL PROTECTED] + domain

 


but instead of getting

 


[EMAIL PROTECTED] 

 


im getting a newline character like:

user

@domain.com

User

@comain.com

User2

@domain.com

 

 

Is there some way I can get this list without the newline characters 
being added. or somehow remove the newline characters. Any help would 
be appreciated.




The problem has nothing to do with lists.  The readlines() function 
returns each line *with* its newline. To strip it off, use line.strip()


Gary Herron




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


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

Also os.popen is deprecated. You should probably learn subprocess.

Thanks,
Gary M. Josack
--
http://mail.python.org/mailman/listinfo/python-list

Re: How to figure out if the platform is 32bit or 64bit?

2008-07-28 Thread Gary Josack

Trent Mick wrote:

Manuel Vazquez Acosta wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Just test for maxint value:

from sys import maxint
if maxint >> 33:
print "more than 32 bits" # probably 64
else:
print "32 bits"


I believe that was already suggested in this thread. That test will 
just tell you if the Python *build* is 32-bit or 64-bit. If the answer 
is 32-bit, then that doesn't tell you if this is a 32-bit Python 
running on a 64-bit OS.


Trent


have you tried platform.architecture()?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Attack a sacred Python Cow

2008-07-28 Thread Bruno Desthuilliers

Derek Martin a écrit :

On Sun, Jul 27, 2008 at 09:39:26PM +0200, Bruno Desthuilliers wrote:

As for the latter part of #3, self (or some other variable) is
required in the parameter list of object methods,
It's actually the parameter list of the *function* that is used as the 
implementation of a method. Not quite the same thing. 


The idea that Python behaves this way is new to me.  For example, the
tutorials make no mention of it:

  http://docs.python.org/tut/node11.html#SECTION001130

The Python reference manual has very little to say about classes,
indeed.  If it's discussed there, it's buried somewhere I could not
easily find it.


Yeps, most of the doc didn't really follow Python's evolutions alas. But 
it's still documented - I've learned all this from the doc.


You'll find more details starting here:

http://www.python.org/doc/newstyle/

and a couple more stuff in the language specs part of the doc:

http://docs.python.org/ref/descriptors.html
http://docs.python.org/ref/descriptor-invocation.html



consistency mandates that the target object of the method is part of
the parameter list of the *function*, since that's how you make
objects availables to a function.


Fair enough, but I submit that this distinction is abstruse,


The distinction between class interface (the method call) and class 
implementation (the function called by the method) ?



and
poorly documented,


This is certainly true. Patches to the doc are welcome.


and also generally not something the average
application developer should want to or have to care about... 


I don't know what's an "average application developper", but as an 
application developper myself, I feel I have to care about the 
implementation of my programs, just like I feel I have to care about 
knowing enough about the languages I use to use them properly.



it's of
interest primarily to computer scientists and language enthusiasts.
The language should prefer to hide such details from the people using
it.


There I beg to disagree. Transparently exposing most of it's object 
model is a design choice, and is for a great part responsible for Python 
expressive power and flexibility. And all this is really part of the 
language - I mean, it's a public API, not an implementation detail. 
FWIW, I'm certainly not what you'd call a "computer scientist" (I left 
school at 16 and have absolutely no formal education in CS).


Anyway: "the language" (IOW: the language's designer) made a different 
choice, and I'm very grateful he did.



however when the method is *called*, it is omitted.
Certainly not. 


Seems not so certain to me...  We disagree, even after your careful
explanation.


You're of course (and hopefully) entitled the right to disagree !-)


 See below.


You need to lookup the corresponding attribute *on a given object*
to get the method. Whether you write

  some_object.some_method()

or

  some_function(some_object)

you still need to explicitely mention some_object.


But these two constructs are conceptually DIFFERENT,


Why so ?


whether or not
their implementation is the same or similar.  The first says that
some_method is defined within the name space of some_object.


The first says that you're sending the message "some_method" to 
some_object. Or, to express it in Python terminology, that you're 
looking up the name "some_method" on some_object, and try to call the 
object returned by the attribute lookup mechanism, whatever that object 
is (function, method, class or any other callable).


Now saying that it implies that "some_method is defined within the name 
space of some_object" depends on the definitions of 'defined', 'within' 
and 'namespace' (more on this below).



 The
second says that some_object is a parameter of some_function...


Yes. It also say that some_function knows enough about some_object to 
accept it as a parameter (or at least that the developper that passed 
some_object to some_function thought / expected it would be the case).


You know, the dotted notation ("obj.attrib") is, well, just a notation. 
It's by no mean necessary to OO. You could have a perfectly valid object 
system where the base notation is "some_message(some_object)" instead of 
being "some_object.some_message" - and FWIW, in Common Lisp - which BTW 
have one of the richer object systems around -, the syntax for method 
call is the same as the syntax for function call, IOW 
"(func_or_method_name object arg1 arg2 argN)".




Namespace != parameter!


Functions parameters are part of the namespace of the function body.

Please don't get me wrong : I'm not saying your point is moot, just 
suggesting another possible way to look at the whole thing.



To many people previously familiar with OO programming in other
languages (not just Java or C++), but not intimately familiar with
Python's implementation details,


It's actually not an implementation detail - it's part of the language spec.


the first also implies that

Re: Attack a sacred Python Cow

2008-07-28 Thread Ben Finney
Bruno Desthuilliers <[EMAIL PROTECTED]> writes:

> Boy, I don't know who you think you're talking to, but you're
> obviously out of luck here. I'm 41, married, our son is now a
> teenager, I have an happy social life, quite a lot of work, and no
> time to waste in the streets. And FWIW, name-calling won't buy you
> much here.

It has, at least, long ago bought him a place in my kill-file. Seeing
your side of the conversation, I can only confirm that decision as
correct.

-- 
 \   “bash awk grep perl sed, df du, du-du du-du, vi troff su fsck |
  `\ rm * halt LART LART LART!” —The Swedish BOFH, |
_o__)alt.sysadmin.recovery |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: Download excel file from web?

2008-07-28 Thread [EMAIL PROTECTED]
On Jul 28, 5:39 pm, MRAB <[EMAIL PROTECTED]> wrote:
> On Jul 29, 12:41 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jul 28, 4:20 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>
> > > On Mon, Jul 28, 2008 at 8:04 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
> > > wrote:
> > > > On Jul 28, 3:52 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> > > >> On Mon, Jul 28, 2008 at 7:43 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
> > > >> wrote:
> > > >> > On Jul 28, 3:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > > >> >> On Jul 28, 3:29 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> > > >> >> > [EMAIL PROTECTED] schrieb:
>
> > > >> >> > > On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> 
> > > >> >> > > wrote:
> > > >> >> > >> Hi - experienced programmer but this is my first Python 
> > > >> >> > >> program.
>
> > > >> >> > >> This URL will retrieve an excel spreadsheet containing (that 
> > > >> >> > >> day's)
> > > >> >> > >> msci stock index returns.
>
> > > >> >> > >>http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>
> > > >> >> > >> Want to write python to download and save the file.
>
> > > >> >> > >> So far I've arrived at this:
>
> > > >> >> > >> [quote]
> > > >> >> > >> # import pdb
> > > >> >> > >> import urllib2
> > > >> >> > >> from win32com.client import Dispatch
>
> > > >> >> > >> xlApp = Dispatch("Excel.Application")
>
> > > >> >> > >> # test 1
> > > >> >> > >> # xlApp.Workbooks.Add()
> > > >> >> > >> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
> > > >> >> > >> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
> > > >> >> > >> # xlBook = xlApp.ActiveWorkbook
> > > >> >> > >> # xlBook.SaveAs(Filename='C:\\test.xls')
>
> > > >> >> > >> # pdb.set_trace()
> > > >> >> > >> response = 
> > > >> >> > >> urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> > > >> >> > >> excel?
> > > >> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> > > >> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional')
> > > >> >> > >> # test 2 - returns check = False
> > > >> >> > >> check_for_data = 
> > > >> >> > >> urllib2.Request('http://www.mscibarra.com/webapp/
> > > >> >> > >> indexperf/excel?
> > > >> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> > > >> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>
> > > >> >> > >> xlApp = response.fp
> > > >> >> > >> print(response.fp.name)
> > > >> >> > >> print(xlApp.name)
> > > >> >> > >> xlApp.write
> > > >> >> > >> xlApp.Close
> > > >> >> > >> [/quote]
>
> > > >> >> > > Woops hit Send when I wanted Preview.  Looks like the html 
> > > >> >> > > [quote] tag
> > > >> >> > > doesn't work from groups.google.com (nice).
>
> > > >> >> > > Anway, in test 1 above, I determined how to instantiate an excel
> > > >> >> > > object; put some stuff in it; then save to disk.
>
> > > >> >> > > So, in theory, I'm retrieving my excel spreadsheet with
>
> > > >> >> > > response = urllib2.urlopen()
>
> > > >> >> > > Except what then do I do with this?
>
> > > >> >> > > Well for one read some of the urllib2 documentation and found 
> > > >> >> > > the
> > > >> >> > > Request class with the method has_data() on it.  It returns 
> > > >> >> > > False.
> > > >> >> > > Hmm that's not encouraging.
>
> > > >> >> > > I supposed the trick to understand what urllib2.urlopen is 
> > > >> >> > > returning
> > > >> >> > > to me; rummage around in there; and hopefully find my excel 
> > > >> >> > > file.
>
> > > >> >> > > I use pdb to debug.  This is interesting:
>
> > > >> >> > > (Pdb) dir(response)
> > > >> >> > > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 
> > > >> >> > > 'close',
> > > >> >> > > 'code', '
> > > >> >> > > fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 
> > > >> >> > > 'read',
> > > >> >> > > 'readline', '
> > > >> >> > > readlines', 'url']
> > > >> >> > > (Pdb)
>
> > > >> >> > > I suppose the members with __*_ are methods; and the names 
> > > >> >> > > without the
> > > >> >> > > underbars are attributes (variables) (?).
>
> > > >> >> > No, these are the names of all attributes and methods. read is a 
> > > >> >> > method,
> > > >> >> > for example.
>
> > > >> >> right - I got it backwards.
>
> > > >> >> > > Or maybe this isn't at all the right direction to take (maybe 
> > > >> >> > > there
> > > >> >> > > are much better modules to do this stuff).  Would be happy to 
> > > >> >> > > learn if
> > > >> >> > > that's the case (and if that gets the job done for me).
>
> > > >> >> > The docs (http://docs.python.org/lib/module-urllib2.html) are 
> > > >> >> > pretty
> > > >> >> > clear on this:
>
> > > >> >> > """
> > > >> >> > This function returns a file-like object with two additional 
> > > >> >> > methods:
> > > >> >> > """
>
> > > >> >> > And then for file-like objects:
>
> > > >> >> >http://docs.python.org/lib/bltin-file-objects.html
>
> > > >> >> > """
> > > >> >> > read(   [size])
> > > >> >> >      Read at 

Re: Download excel file from web?

2008-07-28 Thread MRAB
On Jul 29, 12:41 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Jul 28, 4:20 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Mon, Jul 28, 2008 at 8:04 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
> > wrote:
> > > On Jul 28, 3:52 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> > >> On Mon, Jul 28, 2008 at 7:43 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
> > >> wrote:
> > >> > On Jul 28, 3:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > >> >> On Jul 28, 3:29 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> > >> >> > [EMAIL PROTECTED] schrieb:
>
> > >> >> > > On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > >> >> > >> Hi - experienced programmer but this is my first Python program.
>
> > >> >> > >> This URL will retrieve an excel spreadsheet containing (that 
> > >> >> > >> day's)
> > >> >> > >> msci stock index returns.
>
> > >> >> > >>http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>
> > >> >> > >> Want to write python to download and save the file.
>
> > >> >> > >> So far I've arrived at this:
>
> > >> >> > >> [quote]
> > >> >> > >> # import pdb
> > >> >> > >> import urllib2
> > >> >> > >> from win32com.client import Dispatch
>
> > >> >> > >> xlApp = Dispatch("Excel.Application")
>
> > >> >> > >> # test 1
> > >> >> > >> # xlApp.Workbooks.Add()
> > >> >> > >> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
> > >> >> > >> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
> > >> >> > >> # xlBook = xlApp.ActiveWorkbook
> > >> >> > >> # xlBook.SaveAs(Filename='C:\\test.xls')
>
> > >> >> > >> # pdb.set_trace()
> > >> >> > >> response = 
> > >> >> > >> urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> > >> >> > >> excel?
> > >> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> > >> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional')
> > >> >> > >> # test 2 - returns check = False
> > >> >> > >> check_for_data = 
> > >> >> > >> urllib2.Request('http://www.mscibarra.com/webapp/
> > >> >> > >> indexperf/excel?
> > >> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> > >> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>
> > >> >> > >> xlApp = response.fp
> > >> >> > >> print(response.fp.name)
> > >> >> > >> print(xlApp.name)
> > >> >> > >> xlApp.write
> > >> >> > >> xlApp.Close
> > >> >> > >> [/quote]
>
> > >> >> > > Woops hit Send when I wanted Preview.  Looks like the html 
> > >> >> > > [quote] tag
> > >> >> > > doesn't work from groups.google.com (nice).
>
> > >> >> > > Anway, in test 1 above, I determined how to instantiate an excel
> > >> >> > > object; put some stuff in it; then save to disk.
>
> > >> >> > > So, in theory, I'm retrieving my excel spreadsheet with
>
> > >> >> > > response = urllib2.urlopen()
>
> > >> >> > > Except what then do I do with this?
>
> > >> >> > > Well for one read some of the urllib2 documentation and found the
> > >> >> > > Request class with the method has_data() on it.  It returns False.
> > >> >> > > Hmm that's not encouraging.
>
> > >> >> > > I supposed the trick to understand what urllib2.urlopen is 
> > >> >> > > returning
> > >> >> > > to me; rummage around in there; and hopefully find my excel file.
>
> > >> >> > > I use pdb to debug.  This is interesting:
>
> > >> >> > > (Pdb) dir(response)
> > >> >> > > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 
> > >> >> > > 'close',
> > >> >> > > 'code', '
> > >> >> > > fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 'read',
> > >> >> > > 'readline', '
> > >> >> > > readlines', 'url']
> > >> >> > > (Pdb)
>
> > >> >> > > I suppose the members with __*_ are methods; and the names 
> > >> >> > > without the
> > >> >> > > underbars are attributes (variables) (?).
>
> > >> >> > No, these are the names of all attributes and methods. read is a 
> > >> >> > method,
> > >> >> > for example.
>
> > >> >> right - I got it backwards.
>
> > >> >> > > Or maybe this isn't at all the right direction to take (maybe 
> > >> >> > > there
> > >> >> > > are much better modules to do this stuff).  Would be happy to 
> > >> >> > > learn if
> > >> >> > > that's the case (and if that gets the job done for me).
>
> > >> >> > The docs (http://docs.python.org/lib/module-urllib2.html) are pretty
> > >> >> > clear on this:
>
> > >> >> > """
> > >> >> > This function returns a file-like object with two additional 
> > >> >> > methods:
> > >> >> > """
>
> > >> >> > And then for file-like objects:
>
> > >> >> >http://docs.python.org/lib/bltin-file-objects.html
>
> > >> >> > """
> > >> >> > read(   [size])
> > >> >> >      Read at most size bytes from the file (less if the read hits 
> > >> >> > EOF
> > >> >> > before obtaining size bytes). If the size argument is negative or
> > >> >> > omitted, read all data until EOF is reached. The bytes are returned 
> > >> >> > as a
> > >> >> > string object. An empty string is returned when EOF is encountered
> > >> >> > immediately. (For cer

Re: like py2exe, but on a mac

2008-07-28 Thread William McBrine
On Mon, 28 Jul 2008 15:18:43 -0400, Kevin Walzer wrote:

> Add this call to your Python script somewhere (modify as needed):
> 
> try:
>  self.tk.call('console', 'hide')
>  except TclError:
>  pass

Ah, yes! Thanks.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: like py2exe, but on a mac

2008-07-28 Thread William McBrine
On Mon, 28 Jul 2008 21:09:10 +0200, Tommy Nordgren wrote:

> Try setting the Output popup menu to 'None'

That was the first thing I did.

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list


Re: seemingly simple list indexing problem

2008-07-28 Thread John Machin


Guilherme Polo wrote:

> It wasn't supposed to be the fastest solution, also, he didn't mention
> duplicated items.

He didn't need to. He explicitly said "list" (which permits
duplicates) and didn't mention a self-imposed uniqueness constraint.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-28 Thread Steven D'Aprano
On Tue, 29 Jul 2008 01:19:00 +0200, Anders J. Munch wrote:

> Steven D'Aprano wrote:
>> On Sun, 27 Jul 2008 23:45:26 -0700, Carl Banks wrote:
>> 
>>> I want something where "if x" will do but a simple explicit test
>>> won't.
>> 
>> Explicit tests aren't simple unless you know what type x is.
> 
> If you don't even know a duck-type for x, you have no business invoking
> any methods on that object.

Have you tried to make "if x" fail?

Pull open an interactive interpreter session and try. You might learn 
something.

 
> If you do know a duck-type for x, then you also know which explicit test
> to perform.
> 
>> Explicit tests are not necessarily simple for custom classes. Testing
>> for emptiness could be arbitrarily complex. That's why we have
>> __nonzero__, so you don't have to fill your code with complex
>> expressions like (say)
>> 
>> if len(x.method()[x.attribute]) > -1
>> 
>> Instead you write it once, in the __nonzero__ method, and never need to
>> think about it again.
> 
> Okay, so you have this interesting object property that you often need
> to test for, so you wrap the code for the test up in a method, because
> that way you only need to write the complex formula once.  I'm with you
> so far.  But then you decide to name the method "__nonzero__", instead
> of some nice descriptive name?
>   What's up with that?

Dude. Dude. Just... learn some Python before you embarrass yourself 
further.

http://www.python.org/doc/ref/customization.html




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


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-28 Thread Steven D'Aprano
On Mon, 28 Jul 2008 13:22:37 -0700, Carl Banks wrote:

> On Jul 28, 10:00 am, Steven D'Aprano <[EMAIL PROTECTED]
> cybersource.com.au> wrote:
>> Cutting to the crux of the discussion...
>>
>> On Sun, 27 Jul 2008 23:45:26 -0700, Carl Banks wrote:
>> > I want something where "if x" will do but a simple explicit test
>> > won't.
>>
>> Explicit tests aren't simple unless you know what type x is. If x could
>> be of any type, you can't write a simple test. Does x have a length? Is
>> it a number? Maybe it's a fixed-length circular length, and the length
>> is non-zero even when it's empty? Who knows? How many cases do you need
>> to consider?
> 
> Use case, please.  I'm asking for code, not arguments.  Please give me a
> piece of code where you can write "if x" that works but a simple
> explicit test won't.

I gave you a piece of code, actual code from one of my own projects. If 
you wouldn't accept that evidence then, why would you accept it now?

It isn't that explicit tests will fail, it is that explicit tests are 
more work for no benefit. You keep talking about "simple explicit tests", 
but it seems to me that you're missing something absolutely fundamental: 
"if x" is simpler than "if x!=0" and significantly simpler than "if len
(x)!=0". Even if you discount the evidence of the character lengths (4 
versus 7 versus 12) just use the dis module to see what those expressions 
are compiled into. Or use timeit to see the execution speed.

So I'm not really sure what your point is. Yes, for vast amounts of code, 
there's no *need* to write "if x". If x is always a number, you can 
replace it with "if x != 0" and it will still work. Big deal. I never 
said differently. But if I don't care what type x is, why should I write 
code that cares what type x is?

All you're doing is writing an expression that does more work than it 
needs to. Although the amount of work is trivial for built-ins, it's 
still more than necessary. But provided x is always the right sort of 
duck, your code will work. It will be longer, more verbose, slower, fail 
in unexpected ways if x is an unexpected type, and it goes against the 
spirit of duck-typing, but it will work.


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


RE: Getting python 2.4 dll

2008-07-28 Thread Delaney, Timothy (Tim)
Guillermo wrote:

> Hi there,
> 
> Is it possible to get a 2.4 dll of python for Windows easily? I need
> it to use python as scripting language for Vim.

http://www.python.org/

which leads you to:
http://www.python.org/download/

which leads you to:
http://www.python.org/download/releases/2.4.5/

which leads you to (for a binary release):
http://www.python.org/download/releases/2.4.4/

Further questions along this line should be directed to:
http://www.catb.org/~esr/faqs/smart-questions.html#before

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


Python parsing iTunes XML/COM

2008-07-28 Thread william tanksley
I'm trying to convert the URLs contained in iTunes' XML file into a
form comparable with the filenames returned by iTunes' COM interface.

I'm writing a podcast sorter in Python; I'm using iTunes under Windows
right now. iTunes' COM provides most of my data input and all of my
mp3/aac editing capabilities; the one thing I can't access through COM
is the Release Date, which is my primary sorting field. So I read
everything in through COM, then read all the release dates from the
iTunes XML file, then try to join the two together... But so far I
have zero success.

Is there _any_ way to match up tracks between iTunes COM and iTunes
XML? I've spent far too much effort on this. I'm not stuck on using
filenames, if that's a bad idea... But I haven't found anything else
that works, and filenames seem like an obvious solution.

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


Re: Download excel file from web?

2008-07-28 Thread [EMAIL PROTECTED]
On Jul 28, 4:20 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> On Mon, Jul 28, 2008 at 8:04 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > On Jul 28, 3:52 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> >> On Mon, Jul 28, 2008 at 7:43 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
> >> wrote:
> >> > On Jul 28, 3:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> >> >> On Jul 28, 3:29 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> >> >> > [EMAIL PROTECTED] schrieb:
>
> >> >> > > On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> >> >> > >> Hi - experienced programmer but this is my first Python program.
>
> >> >> > >> This URL will retrieve an excel spreadsheet containing (that day's)
> >> >> > >> msci stock index returns.
>
> >> >> > >>http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>
> >> >> > >> Want to write python to download and save the file.
>
> >> >> > >> So far I've arrived at this:
>
> >> >> > >> [quote]
> >> >> > >> # import pdb
> >> >> > >> import urllib2
> >> >> > >> from win32com.client import Dispatch
>
> >> >> > >> xlApp = Dispatch("Excel.Application")
>
> >> >> > >> # test 1
> >> >> > >> # xlApp.Workbooks.Add()
> >> >> > >> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
> >> >> > >> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
> >> >> > >> # xlBook = xlApp.ActiveWorkbook
> >> >> > >> # xlBook.SaveAs(Filename='C:\\test.xls')
>
> >> >> > >> # pdb.set_trace()
> >> >> > >> response = 
> >> >> > >> urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> >> >> > >> excel?
> >> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> >> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional')
> >> >> > >> # test 2 - returns check = False
> >> >> > >> check_for_data = urllib2.Request('http://www.mscibarra.com/webapp/
> >> >> > >> indexperf/excel?
> >> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> >> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>
> >> >> > >> xlApp = response.fp
> >> >> > >> print(response.fp.name)
> >> >> > >> print(xlApp.name)
> >> >> > >> xlApp.write
> >> >> > >> xlApp.Close
> >> >> > >> [/quote]
>
> >> >> > > Woops hit Send when I wanted Preview.  Looks like the html [quote] 
> >> >> > > tag
> >> >> > > doesn't work from groups.google.com (nice).
>
> >> >> > > Anway, in test 1 above, I determined how to instantiate an excel
> >> >> > > object; put some stuff in it; then save to disk.
>
> >> >> > > So, in theory, I'm retrieving my excel spreadsheet with
>
> >> >> > > response = urllib2.urlopen()
>
> >> >> > > Except what then do I do with this?
>
> >> >> > > Well for one read some of the urllib2 documentation and found the
> >> >> > > Request class with the method has_data() on it.  It returns False.
> >> >> > > Hmm that's not encouraging.
>
> >> >> > > I supposed the trick to understand what urllib2.urlopen is returning
> >> >> > > to me; rummage around in there; and hopefully find my excel file.
>
> >> >> > > I use pdb to debug.  This is interesting:
>
> >> >> > > (Pdb) dir(response)
> >> >> > > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 
> >> >> > > 'close',
> >> >> > > 'code', '
> >> >> > > fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 'read',
> >> >> > > 'readline', '
> >> >> > > readlines', 'url']
> >> >> > > (Pdb)
>
> >> >> > > I suppose the members with __*_ are methods; and the names without 
> >> >> > > the
> >> >> > > underbars are attributes (variables) (?).
>
> >> >> > No, these are the names of all attributes and methods. read is a 
> >> >> > method,
> >> >> > for example.
>
> >> >> right - I got it backwards.
>
> >> >> > > Or maybe this isn't at all the right direction to take (maybe there
> >> >> > > are much better modules to do this stuff).  Would be happy to learn 
> >> >> > > if
> >> >> > > that's the case (and if that gets the job done for me).
>
> >> >> > The docs (http://docs.python.org/lib/module-urllib2.html) are pretty
> >> >> > clear on this:
>
> >> >> > """
> >> >> > This function returns a file-like object with two additional methods:
> >> >> > """
>
> >> >> > And then for file-like objects:
>
> >> >> >http://docs.python.org/lib/bltin-file-objects.html
>
> >> >> > """
> >> >> > read(   [size])
> >> >> >      Read at most size bytes from the file (less if the read hits EOF
> >> >> > before obtaining size bytes). If the size argument is negative or
> >> >> > omitted, read all data until EOF is reached. The bytes are returned 
> >> >> > as a
> >> >> > string object. An empty string is returned when EOF is encountered
> >> >> > immediately. (For certain files, like ttys, it makes sense to continue
> >> >> > reading after an EOF is hit.) Note that this method may call the
> >> >> > underlying C function fread() more than once in an effort to acquire 
> >> >> > as
> >> >> > close to size bytes as possible. Also note that when in non-blocking
> >> >> > mode, less data than what was requested ma

Re: Tkinter fullscreen with Mac OS X

2008-07-28 Thread Guilherme Polo
On Mon, Jul 28, 2008 at 8:10 PM, C Martin <[EMAIL PROTECTED]> wrote:
> Is there a way to create a full screen app using Tkinter with Mac OS
> X?? On windows, this is relatively easy with overrideredirect(1).
> However, on the Mac, the top menu bar and dock are still displayed
> over the app. Is there a way to get rid of them?
>

You could try this, supposing tl is a toplevel:

tl.tk.call("::tk::unsupported::MacWindowStyle", "style", tl._w, "plain", "none")

and if you are using python with tk 8.5 or newer (unlikely):

tl.wm_attributes('-fullscreen', 1)

But I don't have a mac, so I can't say for sure if these solve your problem.

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



-- 
-- Guilherme H. Polo Goncalves
--
http://mail.python.org/mailman/listinfo/python-list


Re: derivative in numpy

2008-07-28 Thread Ken Starks

Ken Starks wrote:

[EMAIL PROTECTED] wrote:

Hi,

I am looking to do a simple derivative. I would expect such a function
to be available in numpy, but can't find it. I have written my own,
but just curious if anybody knows of such function in numpy.

Cheers,
 Kim

numpy and much more are wrapped together in 'sage' and you should get
the functionality you need there.

For a review, see:

http://vnoel.wordpress.com/2008/05/03/bye-matlab-hello-python-thanks-sage/


Sorry, the review isn't very useful. for something more focused on your
request, see:

http://www.sagemath.org/doc/tut/node13.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: seemingly simple list indexing problem

2008-07-28 Thread John Krukoff

On Mon, 2008-07-28 at 16:00 -0700, iu2 wrote:
> On Jul 29, 12:10 am, John Krukoff <[EMAIL PROTECTED]> wrote:
> > On Mon, 2008-07-28 at 16:24 -0500, Ervan Ensis wrote:
> > > My programming skills are pretty rusty and I'm just learning Python so
> > > this problem is giving me trouble.
> >
> > > I have a list like [108, 58, 68].  I want to return the sorted indices
> > > of these items in the same order as the original list.  So I should
> > > return [2, 0, 1]
> >
> > > For a list that's already in order, I'll just return the indices, i.e.
> > > [56, 66, 76] should return [0, 1, 2]
> >
> > > Any help would be appreciated.
> >
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
> >
> > If your lists aren't so large that memory is an issue, this might be a
> > good place for a variation of decorate, sort, undecorate.
> >
> > >>> listToSort = [ 108, 58, 68 ]
> > >>> decorated = [ ( data, index ) for index, data in
> >
> > enumerate( listToSort ) ]>>> decorated
> >
> > [(108, 0), (58, 1), (68, 2)]>>> result = [ None, ] * len( listToSort )
> > >>> for sortedIndex, ( ignoredValue, originalIndex ) in
> >
> > enumerate( sorted( decorated ) ):
> > ... result[ originalIndex ] = sortedIndex
> > ...>>> result
> >
> > [2, 0, 1]
> >
> > --
> > John Krukoff <[EMAIL PROTECTED]>
> > Land Title Guarantee Company
> 
> Inspired by your idea and the above one, here is another try:
> 
> >>> a0 = [108, 58, 68, 108, 58]
> >>> a1 = [(x, y) for x, y in enumerate(a0)]

You know this line is a no-op, right?

> >>> a1
> [(0, 108), (1, 58), (2, 68), (3, 108), (4, 58)]
> >>> a2 = sorted(a1, lambda x, y: cmp(x[1], y[1]))

If you're going to do the unpacking here for the sort, just use
enumerate directly. Since this is a simple case, should use the key
parameter instead of the cmp parameter for speed. Can also use the
operator module to avoid a bit of lambda overhead:

>>> import operator
>>> a2 = sorted( enumerate( a0 ), key = operator.itemgetter( 1 ) )

> >>> a2
> [(1, 58), (4, 58), (2, 68), (0, 108), (3, 108)]
> >>> a3 = [a2.index(x) for x in a1]
> >>> a3
> [3, 0, 2, 4, 1]
> 
> The idea is to make each item unique (by making it a tuple), and then
> apply the naive solution.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list

Using index is still kinda evil, due to the exponential time required
since you're rescanning half the list (on average) to find each index
value.

-- 
John Krukoff <[EMAIL PROTECTED]>
Land Title Guarantee Company

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


Re: derivative in numpy

2008-07-28 Thread Robert Kern

Gary Herron wrote:

[EMAIL PROTECTED] wrote:

Hi,

I am looking to do a simple derivative. I would expect such a function
to be available in numpy, but can't find it. I have written my own,
but just curious if anybody knows of such function in numpy.
  


Derivatives are a property of functions. Since numpy provides 
representations of arrays not functions, how would you expect this to work?


To be more concrete, what you you expect the derivative of
[ [ 1 2 ]
[ 3 4 ]
]
to be?

Or do you have in mind some array representation of the coefficients of 
a function of some pre-defined type - like a polynomial?


Typically, when people ask questions like this, they have a uniform, discretely 
sampled version of the function, and they want the 
(forward,central,backward)-difference approximation of the derivative.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Download excel file from web?

2008-07-28 Thread Guilherme Polo
On Mon, Jul 28, 2008 at 8:04 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On Jul 28, 3:52 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>> On Mon, Jul 28, 2008 at 7:43 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> > On Jul 28, 3:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> >> On Jul 28, 3:29 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>>
>> >> > [EMAIL PROTECTED] schrieb:
>>
>> >> > > On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> >> > >> Hi - experienced programmer but this is my first Python program.
>>
>> >> > >> This URL will retrieve an excel spreadsheet containing (that day's)
>> >> > >> msci stock index returns.
>>
>> >> > >>http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>>
>> >> > >> Want to write python to download and save the file.
>>
>> >> > >> So far I've arrived at this:
>>
>> >> > >> [quote]
>> >> > >> # import pdb
>> >> > >> import urllib2
>> >> > >> from win32com.client import Dispatch
>>
>> >> > >> xlApp = Dispatch("Excel.Application")
>>
>> >> > >> # test 1
>> >> > >> # xlApp.Workbooks.Add()
>> >> > >> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
>> >> > >> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
>> >> > >> # xlBook = xlApp.ActiveWorkbook
>> >> > >> # xlBook.SaveAs(Filename='C:\\test.xls')
>>
>> >> > >> # pdb.set_trace()
>> >> > >> response = 
>> >> > >> urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
>> >> > >> excel?
>> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
>> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional')
>> >> > >> # test 2 - returns check = False
>> >> > >> check_for_data = urllib2.Request('http://www.mscibarra.com/webapp/
>> >> > >> indexperf/excel?
>> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
>> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>>
>> >> > >> xlApp = response.fp
>> >> > >> print(response.fp.name)
>> >> > >> print(xlApp.name)
>> >> > >> xlApp.write
>> >> > >> xlApp.Close
>> >> > >> [/quote]
>>
>> >> > > Woops hit Send when I wanted Preview.  Looks like the html [quote] tag
>> >> > > doesn't work from groups.google.com (nice).
>>
>> >> > > Anway, in test 1 above, I determined how to instantiate an excel
>> >> > > object; put some stuff in it; then save to disk.
>>
>> >> > > So, in theory, I'm retrieving my excel spreadsheet with
>>
>> >> > > response = urllib2.urlopen()
>>
>> >> > > Except what then do I do with this?
>>
>> >> > > Well for one read some of the urllib2 documentation and found the
>> >> > > Request class with the method has_data() on it.  It returns False.
>> >> > > Hmm that's not encouraging.
>>
>> >> > > I supposed the trick to understand what urllib2.urlopen is returning
>> >> > > to me; rummage around in there; and hopefully find my excel file.
>>
>> >> > > I use pdb to debug.  This is interesting:
>>
>> >> > > (Pdb) dir(response)
>> >> > > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 'close',
>> >> > > 'code', '
>> >> > > fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 'read',
>> >> > > 'readline', '
>> >> > > readlines', 'url']
>> >> > > (Pdb)
>>
>> >> > > I suppose the members with __*_ are methods; and the names without the
>> >> > > underbars are attributes (variables) (?).
>>
>> >> > No, these are the names of all attributes and methods. read is a method,
>> >> > for example.
>>
>> >> right - I got it backwards.
>>
>> >> > > Or maybe this isn't at all the right direction to take (maybe there
>> >> > > are much better modules to do this stuff).  Would be happy to learn if
>> >> > > that's the case (and if that gets the job done for me).
>>
>> >> > The docs (http://docs.python.org/lib/module-urllib2.html) are pretty
>> >> > clear on this:
>>
>> >> > """
>> >> > This function returns a file-like object with two additional methods:
>> >> > """
>>
>> >> > And then for file-like objects:
>>
>> >> >http://docs.python.org/lib/bltin-file-objects.html
>>
>> >> > """
>> >> > read(   [size])
>> >> >  Read at most size bytes from the file (less if the read hits EOF
>> >> > before obtaining size bytes). If the size argument is negative or
>> >> > omitted, read all data until EOF is reached. The bytes are returned as a
>> >> > string object. An empty string is returned when EOF is encountered
>> >> > immediately. (For certain files, like ttys, it makes sense to continue
>> >> > reading after an EOF is hit.) Note that this method may call the
>> >> > underlying C function fread() more than once in an effort to acquire as
>> >> > close to size bytes as possible. Also note that when in non-blocking
>> >> > mode, less data than what was requested may be returned, even if no size
>> >> > parameter was given.
>> >> > """
>>
>> >> > Diez
>>
>> >> Just stumbled upon .read:
>>
>> >> response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
>> >> excel?
>> >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
>> >> +25%2C+2

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-28 Thread Anders J. Munch

Steven D'Aprano wrote:

On Sun, 27 Jul 2008 23:45:26 -0700, Carl Banks wrote:


I want something where "if x" will do but a simple explicit test won't.


Explicit tests aren't simple unless you know what type x is. 


If you don't even know a duck-type for x, you have no business invoking any 
methods on that object.


If you do know a duck-type for x, then you also know which explicit test to 
perform.

Explicit tests are not necessarily simple for custom classes. Testing for 
emptiness could be arbitrarily complex. That's why we have __nonzero__, 
so you don't have to fill your code with complex expressions like (say)


if len(x.method()[x.attribute]) > -1

Instead you write it once, in the __nonzero__ method, and never need to 
think about it again.


Okay, so you have this interesting object property that you often need to test 
for, so you wrap the code for the test up in a method, because that way you only 
need to write the complex formula once.  I'm with you so far.  But then you 
decide to name the method "__nonzero__", instead of some nice descriptive name? 
 What's up with that?


This is the kind of code I would write:
   class C:
  def attribute_is_nonnegative(self):
 return len(self.method()[self.attribute]) > -1
   ...
   c = get_a_C()
   if c.attribute_is_nonnegative():
  ...

Now suppose you were reading these last few lines and got to wondering if 
get_a_C might ever return None.


The answer is obviously no.  get_a_C must always return a C object or something 
compatible.  If not, it's a bug and an AttributeError will ensue.  The code 
tells you that.  By giving the method a name the intent of the test is perfectly 
documented.


In comparison, I gather you would write something like this:
   class C:
  def __nonzero__(self):
 return len(self.method()[self.attribute]) > -1
   ...
   c = get_a_C()
   if c:
  ...

Again, the question is, can get_a_C return None?  Well that's hard to say 
really.  It could be that "if c" is intended to test for None.  Or it could be 
intended to call C.__nonzero__.  Or it could be cleverly intended to test 
not-None and C.__nonzero__ at the same time.  It may be impossible to discern 
the writer's true intent.


Even if we find out that C.__nonzero__ is called, what was it that __nonzero__ 
did again?  Did it test for the queue being non-empty?  Did it test for the 
queue being not-full?  Did it test whether for the consumer thread is running? 
Did it test for if there are any threads blocked on the queue?  Better dig up 
the class C documentation and find out, because there is no single obvious 
interpretation of what is means for an object to evaluate to true.


"if x" is simple to type, but not so simple to read. "if x.namedPredicate()" is 
harder to type, but easier to read.  I prefer the latter because code is read 
more often than it is written.


regards,
Anders
--
http://mail.python.org/mailman/listinfo/python-list


Re: derivative in numpy

2008-07-28 Thread Ken Starks

[EMAIL PROTECTED] wrote:

Hi,

I am looking to do a simple derivative. I would expect such a function
to be available in numpy, but can't find it. I have written my own,
but just curious if anybody knows of such function in numpy.

Cheers,
 Kim

numpy and much more are wrapped together in 'sage' and you should get
the functionality you need there.

For a review, see:

http://vnoel.wordpress.com/2008/05/03/bye-matlab-hello-python-thanks-sage/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Download excel file from web?

2008-07-28 Thread [EMAIL PROTECTED]
On Jul 28, 4:04 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Jul 28, 3:52 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Mon, Jul 28, 2008 at 7:43 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
> > wrote:
> > > On Jul 28, 3:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > >> On Jul 28, 3:29 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> > >> > [EMAIL PROTECTED] schrieb:
>
> > >> > > On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > >> > >> Hi - experienced programmer but this is my first Python program.
>
> > >> > >> This URL will retrieve an excel spreadsheet containing (that day's)
> > >> > >> msci stock index returns.
>
> > >> > >>http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>
> > >> > >> Want to write python to download and save the file.
>
> > >> > >> So far I've arrived at this:
>
> > >> > >> [quote]
> > >> > >> # import pdb
> > >> > >> import urllib2
> > >> > >> from win32com.client import Dispatch
>
> > >> > >> xlApp = Dispatch("Excel.Application")
>
> > >> > >> # test 1
> > >> > >> # xlApp.Workbooks.Add()
> > >> > >> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
> > >> > >> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
> > >> > >> # xlBook = xlApp.ActiveWorkbook
> > >> > >> # xlBook.SaveAs(Filename='C:\\test.xls')
>
> > >> > >> # pdb.set_trace()
> > >> > >> response = 
> > >> > >> urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> > >> > >> excel?
> > >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> > >> > >> +25%2C+2008&export=Excel_IEIPerfRegional')
> > >> > >> # test 2 - returns check = False
> > >> > >> check_for_data = urllib2.Request('http://www.mscibarra.com/webapp/
> > >> > >> indexperf/excel?
> > >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> > >> > >> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>
> > >> > >> xlApp = response.fp
> > >> > >> print(response.fp.name)
> > >> > >> print(xlApp.name)
> > >> > >> xlApp.write
> > >> > >> xlApp.Close
> > >> > >> [/quote]
>
> > >> > > Woops hit Send when I wanted Preview.  Looks like the html [quote] 
> > >> > > tag
> > >> > > doesn't work from groups.google.com (nice).
>
> > >> > > Anway, in test 1 above, I determined how to instantiate an excel
> > >> > > object; put some stuff in it; then save to disk.
>
> > >> > > So, in theory, I'm retrieving my excel spreadsheet with
>
> > >> > > response = urllib2.urlopen()
>
> > >> > > Except what then do I do with this?
>
> > >> > > Well for one read some of the urllib2 documentation and found the
> > >> > > Request class with the method has_data() on it.  It returns False.
> > >> > > Hmm that's not encouraging.
>
> > >> > > I supposed the trick to understand what urllib2.urlopen is returning
> > >> > > to me; rummage around in there; and hopefully find my excel file.
>
> > >> > > I use pdb to debug.  This is interesting:
>
> > >> > > (Pdb) dir(response)
> > >> > > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 
> > >> > > 'close',
> > >> > > 'code', '
> > >> > > fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 'read',
> > >> > > 'readline', '
> > >> > > readlines', 'url']
> > >> > > (Pdb)
>
> > >> > > I suppose the members with __*_ are methods; and the names without 
> > >> > > the
> > >> > > underbars are attributes (variables) (?).
>
> > >> > No, these are the names of all attributes and methods. read is a 
> > >> > method,
> > >> > for example.
>
> > >> right - I got it backwards.
>
> > >> > > Or maybe this isn't at all the right direction to take (maybe there
> > >> > > are much better modules to do this stuff).  Would be happy to learn 
> > >> > > if
> > >> > > that's the case (and if that gets the job done for me).
>
> > >> > The docs (http://docs.python.org/lib/module-urllib2.html) are pretty
> > >> > clear on this:
>
> > >> > """
> > >> > This function returns a file-like object with two additional methods:
> > >> > """
>
> > >> > And then for file-like objects:
>
> > >> >http://docs.python.org/lib/bltin-file-objects.html
>
> > >> > """
> > >> > read(   [size])
> > >> >      Read at most size bytes from the file (less if the read hits EOF
> > >> > before obtaining size bytes). If the size argument is negative or
> > >> > omitted, read all data until EOF is reached. The bytes are returned as 
> > >> > a
> > >> > string object. An empty string is returned when EOF is encountered
> > >> > immediately. (For certain files, like ttys, it makes sense to continue
> > >> > reading after an EOF is hit.) Note that this method may call the
> > >> > underlying C function fread() more than once in an effort to acquire as
> > >> > close to size bytes as possible. Also note that when in non-blocking
> > >> > mode, less data than what was requested may be returned, even if no 
> > >> > size
> > >> > parameter was given.
> > >> > """
>
> > >> > Diez
>
> > >> Just stumbled upon .read:
>
> > >> response = urllib2.urlopen('http

Tkinter fullscreen with Mac OS X

2008-07-28 Thread C Martin
Is there a way to create a full screen app using Tkinter with Mac OS
X?? On windows, this is relatively easy with overrideredirect(1).
However, on the Mac, the top menu bar and dock are still displayed
over the app. Is there a way to get rid of them?

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


Re: seemingly simple list indexing problem

2008-07-28 Thread Raymond Hettinger
[Ervan Ensis]
> I have a list like [108, 58, 68].  I want to return
> the sorted indices of these items in the same order
> as the original list.  So I should return [2, 0, 1]


One solution is to think of the list indexes
being sorted according the their corresponding
values in the input array:

>>> s = [ 108, 58, 68 ]
>>> sorted(range(len(s)), key=s.__getitem__)
[1, 2, 0]


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


Re: Download excel file from web?

2008-07-28 Thread [EMAIL PROTECTED]
On Jul 28, 3:52 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> On Mon, Jul 28, 2008 at 7:43 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > On Jul 28, 3:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> >> On Jul 28, 3:29 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> >> > [EMAIL PROTECTED] schrieb:
>
> >> > > On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> >> > >> Hi - experienced programmer but this is my first Python program.
>
> >> > >> This URL will retrieve an excel spreadsheet containing (that day's)
> >> > >> msci stock index returns.
>
> >> > >>http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>
> >> > >> Want to write python to download and save the file.
>
> >> > >> So far I've arrived at this:
>
> >> > >> [quote]
> >> > >> # import pdb
> >> > >> import urllib2
> >> > >> from win32com.client import Dispatch
>
> >> > >> xlApp = Dispatch("Excel.Application")
>
> >> > >> # test 1
> >> > >> # xlApp.Workbooks.Add()
> >> > >> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
> >> > >> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
> >> > >> # xlBook = xlApp.ActiveWorkbook
> >> > >> # xlBook.SaveAs(Filename='C:\\test.xls')
>
> >> > >> # pdb.set_trace()
> >> > >> response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> >> > >> excel?
> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional')
> >> > >> # test 2 - returns check = False
> >> > >> check_for_data = urllib2.Request('http://www.mscibarra.com/webapp/
> >> > >> indexperf/excel?
> >> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> >> > >> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>
> >> > >> xlApp = response.fp
> >> > >> print(response.fp.name)
> >> > >> print(xlApp.name)
> >> > >> xlApp.write
> >> > >> xlApp.Close
> >> > >> [/quote]
>
> >> > > Woops hit Send when I wanted Preview.  Looks like the html [quote] tag
> >> > > doesn't work from groups.google.com (nice).
>
> >> > > Anway, in test 1 above, I determined how to instantiate an excel
> >> > > object; put some stuff in it; then save to disk.
>
> >> > > So, in theory, I'm retrieving my excel spreadsheet with
>
> >> > > response = urllib2.urlopen()
>
> >> > > Except what then do I do with this?
>
> >> > > Well for one read some of the urllib2 documentation and found the
> >> > > Request class with the method has_data() on it.  It returns False.
> >> > > Hmm that's not encouraging.
>
> >> > > I supposed the trick to understand what urllib2.urlopen is returning
> >> > > to me; rummage around in there; and hopefully find my excel file.
>
> >> > > I use pdb to debug.  This is interesting:
>
> >> > > (Pdb) dir(response)
> >> > > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 'close',
> >> > > 'code', '
> >> > > fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 'read',
> >> > > 'readline', '
> >> > > readlines', 'url']
> >> > > (Pdb)
>
> >> > > I suppose the members with __*_ are methods; and the names without the
> >> > > underbars are attributes (variables) (?).
>
> >> > No, these are the names of all attributes and methods. read is a method,
> >> > for example.
>
> >> right - I got it backwards.
>
> >> > > Or maybe this isn't at all the right direction to take (maybe there
> >> > > are much better modules to do this stuff).  Would be happy to learn if
> >> > > that's the case (and if that gets the job done for me).
>
> >> > The docs (http://docs.python.org/lib/module-urllib2.html) are pretty
> >> > clear on this:
>
> >> > """
> >> > This function returns a file-like object with two additional methods:
> >> > """
>
> >> > And then for file-like objects:
>
> >> >http://docs.python.org/lib/bltin-file-objects.html
>
> >> > """
> >> > read(   [size])
> >> >      Read at most size bytes from the file (less if the read hits EOF
> >> > before obtaining size bytes). If the size argument is negative or
> >> > omitted, read all data until EOF is reached. The bytes are returned as a
> >> > string object. An empty string is returned when EOF is encountered
> >> > immediately. (For certain files, like ttys, it makes sense to continue
> >> > reading after an EOF is hit.) Note that this method may call the
> >> > underlying C function fread() more than once in an effort to acquire as
> >> > close to size bytes as possible. Also note that when in non-blocking
> >> > mode, less data than what was requested may be returned, even if no size
> >> > parameter was given.
> >> > """
>
> >> > Diez
>
> >> Just stumbled upon .read:
>
> >> response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> >> excel?
> >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> >> +25%2C+2008&export=Excel_IEIPerfRegional').read
>
> >> Now the question is: what to do with this?  I'll look at the
> >> documentation that you point to.
>
> >> thanx - pat
>
> > Or rather (next iteration):
>
> > response = 

Re: seemingly simple list indexing problem

2008-07-28 Thread iu2
On Jul 29, 12:10 am, John Krukoff <[EMAIL PROTECTED]> wrote:
> On Mon, 2008-07-28 at 16:24 -0500, Ervan Ensis wrote:
> > My programming skills are pretty rusty and I'm just learning Python so
> > this problem is giving me trouble.
>
> > I have a list like [108, 58, 68].  I want to return the sorted indices
> > of these items in the same order as the original list.  So I should
> > return [2, 0, 1]
>
> > For a list that's already in order, I'll just return the indices, i.e.
> > [56, 66, 76] should return [0, 1, 2]
>
> > Any help would be appreciated.
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> If your lists aren't so large that memory is an issue, this might be a
> good place for a variation of decorate, sort, undecorate.
>
> >>> listToSort = [ 108, 58, 68 ]
> >>> decorated = [ ( data, index ) for index, data in
>
> enumerate( listToSort ) ]>>> decorated
>
> [(108, 0), (58, 1), (68, 2)]>>> result = [ None, ] * len( listToSort )
> >>> for sortedIndex, ( ignoredValue, originalIndex ) in
>
> enumerate( sorted( decorated ) ):
> ...     result[ originalIndex ] = sortedIndex
> ...>>> result
>
> [2, 0, 1]
>
> --
> John Krukoff <[EMAIL PROTECTED]>
> Land Title Guarantee Company

Inspired by your idea and the above one, here is another try:

>>> a0 = [108, 58, 68, 108, 58]
>>> a1 = [(x, y) for x, y in enumerate(a0)]
>>> a1
[(0, 108), (1, 58), (2, 68), (3, 108), (4, 58)]
>>> a2 = sorted(a1, lambda x, y: cmp(x[1], y[1]))
>>> a2
[(1, 58), (4, 58), (2, 68), (0, 108), (3, 108)]
>>> a3 = [a2.index(x) for x in a1]
>>> a3
[3, 0, 2, 4, 1]

The idea is to make each item unique (by making it a tuple), and then
apply the naive solution.

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


Re: Python Written in C?

2008-07-28 Thread VernM
On Jul 20, 3:50 pm, [EMAIL PROTECTED] wrote:
> I'm just learning about Python now and it sounds interesting. But I
> just read (on the Wiki page) that mainstream Python was written in C.
> That's what I was searching for: Python was written in what other
> language?
>
> See, my concern was something like: OK, if Python is so hot, then,
> hopefully someone is writing it in assembly language for each MPU chip
> out there. Otherwise, if, say, they've written it in C#, then it looks
> like the REAL, generally useful language to learn is C# and Python is
> akin to Visual Basic or something: a specialty languagewhereas
> REAL WORLD programmers who want to be generally useful go and learn
> C#.
>
> So I was suspecting the Python compiler or interpreter is written in a
> REAL language like C#. So, Wiki says it's written in C! It's almost as
> if it were an intentional trick...write your own, new language in an
> OLD, real world language that is passe. Compile it into executable
> modules of course, so it is a real, working compiler, alright. But the
> SOURCE is some old, high level language which no one wants to use
> anymore! So now you've got a hot new language package and no one can
> say "well, it is written in, the SOURCE code is written in, a REAL
> language." No, it's not! The source is some outdated language and
> compiler and no one is going to prefer learning THAT to learning your
> hot new language!
>
> I'm not dissing Python, here. Just noting that, if it is written in C,
> that throws a curve at me in trying to balance the value of learning
> Python vs. some other major language.

Thank you giveitawhril2...!!

I haven't had so much fun reading a thead in years. Hilarious
--
http://mail.python.org/mailman/listinfo/python-list


Re: interpreter vs. compiled

2008-07-28 Thread Fuzzyman
On Jul 27, 6:02 am, castironpi <[EMAIL PROTECTED]> wrote:
> On Jul 24, 11:04 pm, Tim Roberts <[EMAIL PROTECTED]> wrote:
>
>
>
> > castironpi <[EMAIL PROTECTED]> wrote:
>
> > >Compiling a program is different than running it.  A JIT compiler is a
> > >kind of compiler and it makes a compilation step.  I am saying that
> > >Python is not a compiler and in order to implement JIT, it would have
> > >to change that fact.
>
> > And I'm saying you are wrong.  There is NOTHING inherent in Python that
> > dictates that it be either compiled or interpreted.  That is simply an
> > implementation decision.  The CPython implementation happens to interpret.
> > The IronPython implementation compiles the intermediate language to native
> > machine language.
>
> > >> of Python that uses .NET.  In that case, the code *IS* JIT compiled to
> > >> assembly when the program starts.
>
> > >But still not the user's code, only the interpreter, which is running
> > >in assembly already anyway in CPython.
>
> > In CPython, yes.  In IronPython, no; the user's code is compiled into
> > machine language.  Both of them are "Python".
> > --
> > Tim Roberts, [EMAIL PROTECTED]
> > Providenza & Boekelheide, Inc.
>
> In CPython yes.  In IronPython yes:  the parts that are compiled into
> machine code are the interpreter, *not user's code*.  Without that
> step, the interpreter would be running on an interpreter, but that
> doesn't get the user's statement 'a= b+ 1' into registers-- it gets
> 'push, push, add, pop' into registers.

Well - in IronPython user code gets compiled to in memory assemblies
which can be JIT'ed.

Michael Foord
--
http://www.ironpythoninaction.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: derivative in numpy

2008-07-28 Thread Gary Herron

[EMAIL PROTECTED] wrote:

Hi,

I am looking to do a simple derivative. I would expect such a function
to be available in numpy, but can't find it. I have written my own,
but just curious if anybody knows of such function in numpy.
  


Derivatives are a property of functions. Since numpy provides 
representations of arrays not functions, how would you expect this to work?


To be more concrete, what you you expect the derivative of
[ [ 1 2 ]
[ 3 4 ]
]
to be?

Or do you have in mind some array representation of the coefficients of 
a function of some pre-defined type - like a polynomial?


Gary Herron


Cheers,
 Kim
--
http://mail.python.org/mailman/listinfo/python-list
  


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


Re: derivative in numpy

2008-07-28 Thread Robert Kern

[EMAIL PROTECTED] wrote:

Hi,

I am looking to do a simple derivative. I would expect such a function
to be available in numpy, but can't find it. I have written my own,
but just curious if anybody knows of such function in numpy.


numpy.diff() handles the discrete difference. All you need to do is supply the 
scaling factor(s) to interpret it as a derivative.


Again, numpy questions are best asked on the numpy mailing list.

  http://www.scipy.org/Mailing_Lists

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


ANN: PyCon UK Talks and Tutorials List Up

2008-07-28 Thread Fuzzyman
PyCon UK 2008 is the second PyCon event in the UK, and is being held
on 12th to 14th September at the Birmingham Conservatoire.

We have a bevy of national and international Python stars speaking as
well as a host of members of the Python community.

The conference starts with a day of tutorials on the Friday.  The
timetable for the tutorials day has now been published:

http://www.pyconuk.org/timetable.html

We have abstracts of currently accepted talks, tutorials and BOFs:

http://www.pyconuk.org/talk_abstracts.html

The early bird rate is still open (but not for too much longer):
http://www.pyconuk.org/booking.html

We are almost there with the schedule, the plenary sessions will
include Lightning talks as well as keynotes from Mark Shuttleworth and
Ted Leung.

We may be accepting a couple more talks if we can squeeze them in
somewhere. (If you are expecting to give a talk but have not given us
an abstract, then please give it to us ASAP)

Michael Foord and the other PyCon UK Organisers
--
http://mail.python.org/mailman/listinfo/python-list


Re: Download excel file from web?

2008-07-28 Thread Guilherme Polo
On Mon, Jul 28, 2008 at 7:43 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On Jul 28, 3:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> On Jul 28, 3:29 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>>
>>
>>
>> > [EMAIL PROTECTED] schrieb:
>>
>> > > On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> > >> Hi - experienced programmer but this is my first Python program.
>>
>> > >> This URL will retrieve an excel spreadsheet containing (that day's)
>> > >> msci stock index returns.
>>
>> > >>http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>>
>> > >> Want to write python to download and save the file.
>>
>> > >> So far I've arrived at this:
>>
>> > >> [quote]
>> > >> # import pdb
>> > >> import urllib2
>> > >> from win32com.client import Dispatch
>>
>> > >> xlApp = Dispatch("Excel.Application")
>>
>> > >> # test 1
>> > >> # xlApp.Workbooks.Add()
>> > >> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
>> > >> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
>> > >> # xlBook = xlApp.ActiveWorkbook
>> > >> # xlBook.SaveAs(Filename='C:\\test.xls')
>>
>> > >> # pdb.set_trace()
>> > >> response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
>> > >> excel?
>> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
>> > >> +25%2C+2008&export=Excel_IEIPerfRegional')
>> > >> # test 2 - returns check = False
>> > >> check_for_data = urllib2.Request('http://www.mscibarra.com/webapp/
>> > >> indexperf/excel?
>> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
>> > >> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>>
>> > >> xlApp = response.fp
>> > >> print(response.fp.name)
>> > >> print(xlApp.name)
>> > >> xlApp.write
>> > >> xlApp.Close
>> > >> [/quote]
>>
>> > > Woops hit Send when I wanted Preview.  Looks like the html [quote] tag
>> > > doesn't work from groups.google.com (nice).
>>
>> > > Anway, in test 1 above, I determined how to instantiate an excel
>> > > object; put some stuff in it; then save to disk.
>>
>> > > So, in theory, I'm retrieving my excel spreadsheet with
>>
>> > > response = urllib2.urlopen()
>>
>> > > Except what then do I do with this?
>>
>> > > Well for one read some of the urllib2 documentation and found the
>> > > Request class with the method has_data() on it.  It returns False.
>> > > Hmm that's not encouraging.
>>
>> > > I supposed the trick to understand what urllib2.urlopen is returning
>> > > to me; rummage around in there; and hopefully find my excel file.
>>
>> > > I use pdb to debug.  This is interesting:
>>
>> > > (Pdb) dir(response)
>> > > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 'close',
>> > > 'code', '
>> > > fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 'read',
>> > > 'readline', '
>> > > readlines', 'url']
>> > > (Pdb)
>>
>> > > I suppose the members with __*_ are methods; and the names without the
>> > > underbars are attributes (variables) (?).
>>
>> > No, these are the names of all attributes and methods. read is a method,
>> > for example.
>>
>> right - I got it backwards.
>>
>>
>>
>>
>>
>> > > Or maybe this isn't at all the right direction to take (maybe there
>> > > are much better modules to do this stuff).  Would be happy to learn if
>> > > that's the case (and if that gets the job done for me).
>>
>> > The docs (http://docs.python.org/lib/module-urllib2.html) are pretty
>> > clear on this:
>>
>> > """
>> > This function returns a file-like object with two additional methods:
>> > """
>>
>> > And then for file-like objects:
>>
>> >http://docs.python.org/lib/bltin-file-objects.html
>>
>> > """
>> > read(   [size])
>> >  Read at most size bytes from the file (less if the read hits EOF
>> > before obtaining size bytes). If the size argument is negative or
>> > omitted, read all data until EOF is reached. The bytes are returned as a
>> > string object. An empty string is returned when EOF is encountered
>> > immediately. (For certain files, like ttys, it makes sense to continue
>> > reading after an EOF is hit.) Note that this method may call the
>> > underlying C function fread() more than once in an effort to acquire as
>> > close to size bytes as possible. Also note that when in non-blocking
>> > mode, less data than what was requested may be returned, even if no size
>> > parameter was given.
>> > """
>>
>> > Diez
>>
>> Just stumbled upon .read:
>>
>> response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
>> excel?
>> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
>> +25%2C+2008&export=Excel_IEIPerfRegional').read
>>
>> Now the question is: what to do with this?  I'll look at the
>> documentation that you point to.
>>
>> thanx - pat
>
> Or rather (next iteration):
>
> response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> excel?
> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> +25%2C+2008&export=Excel_IEIPerfRegional').read(100)
>
> The file

Re: Download excel file from web?

2008-07-28 Thread [EMAIL PROTECTED]
On Jul 28, 3:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Jul 28, 3:29 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
>
>
> > [EMAIL PROTECTED] schrieb:
>
> > > On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > >> Hi - experienced programmer but this is my first Python program.
>
> > >> This URL will retrieve an excel spreadsheet containing (that day's)
> > >> msci stock index returns.
>
> > >>http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>
> > >> Want to write python to download and save the file.
>
> > >> So far I've arrived at this:
>
> > >> [quote]
> > >> # import pdb
> > >> import urllib2
> > >> from win32com.client import Dispatch
>
> > >> xlApp = Dispatch("Excel.Application")
>
> > >> # test 1
> > >> # xlApp.Workbooks.Add()
> > >> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
> > >> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
> > >> # xlBook = xlApp.ActiveWorkbook
> > >> # xlBook.SaveAs(Filename='C:\\test.xls')
>
> > >> # pdb.set_trace()
> > >> response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> > >> excel?
> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> > >> +25%2C+2008&export=Excel_IEIPerfRegional')
> > >> # test 2 - returns check = False
> > >> check_for_data = urllib2.Request('http://www.mscibarra.com/webapp/
> > >> indexperf/excel?
> > >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> > >> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>
> > >> xlApp = response.fp
> > >> print(response.fp.name)
> > >> print(xlApp.name)
> > >> xlApp.write
> > >> xlApp.Close
> > >> [/quote]
>
> > > Woops hit Send when I wanted Preview.  Looks like the html [quote] tag
> > > doesn't work from groups.google.com (nice).
>
> > > Anway, in test 1 above, I determined how to instantiate an excel
> > > object; put some stuff in it; then save to disk.
>
> > > So, in theory, I'm retrieving my excel spreadsheet with
>
> > > response = urllib2.urlopen()
>
> > > Except what then do I do with this?
>
> > > Well for one read some of the urllib2 documentation and found the
> > > Request class with the method has_data() on it.  It returns False.
> > > Hmm that's not encouraging.
>
> > > I supposed the trick to understand what urllib2.urlopen is returning
> > > to me; rummage around in there; and hopefully find my excel file.
>
> > > I use pdb to debug.  This is interesting:
>
> > > (Pdb) dir(response)
> > > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 'close',
> > > 'code', '
> > > fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 'read',
> > > 'readline', '
> > > readlines', 'url']
> > > (Pdb)
>
> > > I suppose the members with __*_ are methods; and the names without the
> > > underbars are attributes (variables) (?).
>
> > No, these are the names of all attributes and methods. read is a method,
> > for example.
>
> right - I got it backwards.
>
>
>
>
>
> > > Or maybe this isn't at all the right direction to take (maybe there
> > > are much better modules to do this stuff).  Would be happy to learn if
> > > that's the case (and if that gets the job done for me).
>
> > The docs (http://docs.python.org/lib/module-urllib2.html) are pretty
> > clear on this:
>
> > """
> > This function returns a file-like object with two additional methods:
> > """
>
> > And then for file-like objects:
>
> >http://docs.python.org/lib/bltin-file-objects.html
>
> > """
> > read(   [size])
> >      Read at most size bytes from the file (less if the read hits EOF
> > before obtaining size bytes). If the size argument is negative or
> > omitted, read all data until EOF is reached. The bytes are returned as a
> > string object. An empty string is returned when EOF is encountered
> > immediately. (For certain files, like ttys, it makes sense to continue
> > reading after an EOF is hit.) Note that this method may call the
> > underlying C function fread() more than once in an effort to acquire as
> > close to size bytes as possible. Also note that when in non-blocking
> > mode, less data than what was requested may be returned, even if no size
> > parameter was given.
> > """
>
> > Diez
>
> Just stumbled upon .read:
>
> response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> excel?
> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> +25%2C+2008&export=Excel_IEIPerfRegional').read
>
> Now the question is: what to do with this?  I'll look at the
> documentation that you point to.
>
> thanx - pat

Or rather (next iteration):

response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
excel?
priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
+25%2C+2008&export=Excel_IEIPerfRegional').read(100)

The file is generally something like 26 KB so specifying 1,000,000
seems like a good idea (first approximation).

And then when I do:

print(response)

I get a whole lot of garbage (and some non-garbage), so I know I'm
onto something.


Re: Is it allowed to use function results as default arguments ?

2008-07-28 Thread Guilherme Polo
On Mon, Jul 28, 2008 at 5:28 PM, Stef Mientki <[EMAIL PROTECTED]> wrote:
> hello,
>
> I've a perfect working procedure,
> at least as far I've tested it it works perfect.
>
> But I was just experimenting with inspect,
> and saw that the default argument was not parsed correctly.
>
> So I wonder if this is allowed:
>
> def Get_Relative_Path ( target, base=os.curdir ) :
>  ...
>
> As inspect returns the following:
>
> (['target', 'base'], None, None, ('.',))

Are you referring to the last item in the tuple above ? It is merely
listing the default values, it is not associating target to '.'. What
else would the tuple be if there is just base with a default value ?

>
> thanks,
> Stef Mientki
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
-- Guilherme H. Polo Goncalves
--
http://mail.python.org/mailman/listinfo/python-list


derivative in numpy

2008-07-28 Thread knielsen73
Hi,

I am looking to do a simple derivative. I would expect such a function
to be available in numpy, but can't find it. I have written my own,
but just curious if anybody knows of such function in numpy.

Cheers,
 Kim
--
http://mail.python.org/mailman/listinfo/python-list


Re: Download excel file from web?

2008-07-28 Thread [EMAIL PROTECTED]
On Jul 28, 3:29 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] schrieb:
>
>
>
> > On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> >> Hi - experienced programmer but this is my first Python program.
>
> >> This URL will retrieve an excel spreadsheet containing (that day's)
> >> msci stock index returns.
>
> >>http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>
> >> Want to write python to download and save the file.
>
> >> So far I've arrived at this:
>
> >> [quote]
> >> # import pdb
> >> import urllib2
> >> from win32com.client import Dispatch
>
> >> xlApp = Dispatch("Excel.Application")
>
> >> # test 1
> >> # xlApp.Workbooks.Add()
> >> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
> >> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
> >> # xlBook = xlApp.ActiveWorkbook
> >> # xlBook.SaveAs(Filename='C:\\test.xls')
>
> >> # pdb.set_trace()
> >> response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> >> excel?
> >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> >> +25%2C+2008&export=Excel_IEIPerfRegional')
> >> # test 2 - returns check = False
> >> check_for_data = urllib2.Request('http://www.mscibarra.com/webapp/
> >> indexperf/excel?
> >> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> >> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>
> >> xlApp = response.fp
> >> print(response.fp.name)
> >> print(xlApp.name)
> >> xlApp.write
> >> xlApp.Close
> >> [/quote]
>
> > Woops hit Send when I wanted Preview.  Looks like the html [quote] tag
> > doesn't work from groups.google.com (nice).
>
> > Anway, in test 1 above, I determined how to instantiate an excel
> > object; put some stuff in it; then save to disk.
>
> > So, in theory, I'm retrieving my excel spreadsheet with
>
> > response = urllib2.urlopen()
>
> > Except what then do I do with this?
>
> > Well for one read some of the urllib2 documentation and found the
> > Request class with the method has_data() on it.  It returns False.
> > Hmm that's not encouraging.
>
> > I supposed the trick to understand what urllib2.urlopen is returning
> > to me; rummage around in there; and hopefully find my excel file.
>
> > I use pdb to debug.  This is interesting:
>
> > (Pdb) dir(response)
> > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 'close',
> > 'code', '
> > fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 'read',
> > 'readline', '
> > readlines', 'url']
> > (Pdb)
>
> > I suppose the members with __*_ are methods; and the names without the
> > underbars are attributes (variables) (?).
>
> No, these are the names of all attributes and methods. read is a method,
> for example.

right - I got it backwards.

>
> > Or maybe this isn't at all the right direction to take (maybe there
> > are much better modules to do this stuff).  Would be happy to learn if
> > that's the case (and if that gets the job done for me).
>
> The docs (http://docs.python.org/lib/module-urllib2.html) are pretty
> clear on this:
>
> """
> This function returns a file-like object with two additional methods:
> """
>
> And then for file-like objects:
>
> http://docs.python.org/lib/bltin-file-objects.html
>
> """
> read(   [size])
>      Read at most size bytes from the file (less if the read hits EOF
> before obtaining size bytes). If the size argument is negative or
> omitted, read all data until EOF is reached. The bytes are returned as a
> string object. An empty string is returned when EOF is encountered
> immediately. (For certain files, like ttys, it makes sense to continue
> reading after an EOF is hit.) Note that this method may call the
> underlying C function fread() more than once in an effort to acquire as
> close to size bytes as possible. Also note that when in non-blocking
> mode, less data than what was requested may be returned, even if no size
> parameter was given.
> """
>
> Diez

Just stumbled upon .read:

response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
excel?
priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
+25%2C+2008&export=Excel_IEIPerfRegional').read

Now the question is: what to do with this?  I'll look at the
documentation that you point to.

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


Re: seemingly simple list indexing problem

2008-07-28 Thread Guilherme Polo
On Mon, Jul 28, 2008 at 7:00 PM, Gary Herron <[EMAIL PROTECTED]> wrote:
> Guilherme Polo wrote:
>>
>> On Mon, Jul 28, 2008 at 6:24 PM, Ervan Ensis <[EMAIL PROTECTED]>
>> wrote:
>>
>>>
>>> My programming skills are pretty rusty and I'm just learning Python so
>>> this
>>> problem is giving me trouble.
>>>
>>> I have a list like [108, 58, 68].  I want to return the sorted indices of
>>> these items in the same order as the original list.  So I should return
>>> [2,
>>> 0, 1]
>>>
>>
>> You could simply do this:
>>
>> a = [108, 58, 68]
>> b = sorted(a)
>> [b.index(c) for c in a]
>>
>
> Yuck.  Slow, and it fails if duplicate list elements exist.

It wasn't supposed to be the fastest solution, also, he didn't mention
duplicated items.

>
> Also...  This looks like a beginners programming assignment.Let's let
> him try it himself.  We can offer help rather than full solutions if he has
> specific Python questions.
>
>
>
>
>
>>
>>>
>>> For a list that's already in order, I'll just return the indices, i.e.
>>> [56,
>>> 66, 76] should return [0, 1, 2]
>>>
>>> Any help would be appreciated.
>>>
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>>
>>
>>
>>
>>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
-- Guilherme H. Polo Goncalves
--
http://mail.python.org/mailman/listinfo/python-list


Re: Download excel file from web?

2008-07-28 Thread Diez B. Roggisch

[EMAIL PROTECTED] schrieb:

On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

Hi - experienced programmer but this is my first Python program.

This URL will retrieve an excel spreadsheet containing (that day's)
msci stock index returns.

http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...

Want to write python to download and save the file.

So far I've arrived at this:

[quote]
# import pdb
import urllib2
from win32com.client import Dispatch

xlApp = Dispatch("Excel.Application")

# test 1
# xlApp.Workbooks.Add()
# xlApp.ActiveSheet.Cells(1,1).Value = 'A'
# xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
# xlBook = xlApp.ActiveWorkbook
# xlBook.SaveAs(Filename='C:\\test.xls')

# pdb.set_trace()
response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
excel?
priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
+25%2C+2008&export=Excel_IEIPerfRegional')
# test 2 - returns check = False
check_for_data = urllib2.Request('http://www.mscibarra.com/webapp/
indexperf/excel?
priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
+25%2C+2008&export=Excel_IEIPerfRegional').has_data()

xlApp = response.fp
print(response.fp.name)
print(xlApp.name)
xlApp.write
xlApp.Close
[/quote]


Woops hit Send when I wanted Preview.  Looks like the html [quote] tag
doesn't work from groups.google.com (nice).

Anway, in test 1 above, I determined how to instantiate an excel
object; put some stuff in it; then save to disk.

So, in theory, I'm retrieving my excel spreadsheet with

response = urllib2.urlopen()

Except what then do I do with this?

Well for one read some of the urllib2 documentation and found the
Request class with the method has_data() on it.  It returns False.
Hmm that's not encouraging.

I supposed the trick to understand what urllib2.urlopen is returning
to me; rummage around in there; and hopefully find my excel file.

I use pdb to debug.  This is interesting:

(Pdb) dir(response)
['__doc__', '__init__', '__iter__', '__module__', '__repr__', 'close',
'code', '
fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 'read',
'readline', '
readlines', 'url']
(Pdb)

I suppose the members with __*_ are methods; and the names without the
underbars are attributes (variables) (?).


No, these are the names of all attributes and methods. read is a method, 
for example.



Or maybe this isn't at all the right direction to take (maybe there
are much better modules to do this stuff).  Would be happy to learn if
that's the case (and if that gets the job done for me).



The docs (http://docs.python.org/lib/module-urllib2.html) are pretty 
clear on this:


"""
This function returns a file-like object with two additional methods:
"""


And then for file-like objects:

http://docs.python.org/lib/bltin-file-objects.html


"""
read(   [size])
Read at most size bytes from the file (less if the read hits EOF 
before obtaining size bytes). If the size argument is negative or 
omitted, read all data until EOF is reached. The bytes are returned as a 
string object. An empty string is returned when EOF is encountered 
immediately. (For certain files, like ttys, it makes sense to continue 
reading after an EOF is hit.) Note that this method may call the 
underlying C function fread() more than once in an effort to acquire as 
close to size bytes as possible. Also note that when in non-blocking 
mode, less data than what was requested may be returned, even if no size 
parameter was given.

"""

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


Re: seemingly simple list indexing problem

2008-07-28 Thread John Krukoff

On Mon, 2008-07-28 at 15:00 -0700, Gary Herron wrote:
> Guilherme Polo wrote:
> > On Mon, Jul 28, 2008 at 6:24 PM, Ervan Ensis <[EMAIL PROTECTED]> wrote:
> >   
> >> My programming skills are pretty rusty and I'm just learning Python so this
> >> problem is giving me trouble.
> >>
> >> I have a list like [108, 58, 68].  I want to return the sorted indices of
> >> these items in the same order as the original list.  So I should return [2,
> >> 0, 1]
> >> 
> >
> > You could simply do this:
> >
> > a = [108, 58, 68]
> > b = sorted(a)
> > [b.index(c) for c in a]
> >   
> 
> Yuck.  Slow, and it fails if duplicate list elements exist.
> 
> Also...  This looks like a beginners programming assignment.Let's 
> let him try it himself.  We can offer help rather than full solutions if 
> he has specific Python questions.
> 
> 
> 
> 
> 
> >   
> >> For a list that's already in order, I'll just return the indices, i.e. [56,
> >> 66, 76] should return [0, 1, 2]
> >>
> >> Any help would be appreciated.
> >>
> >> --
> >> http://mail.python.org/mailman/listinfo/python-list
> >>
> >> 
> >
> >
> >
> >   
> 
> --
> http://mail.python.org/mailman/listinfo/python-list

Sorry, problem was interesting to solve, so I may have jumped the gun. I
do wonder why OP was asking for this though, as now that you mention it
I can't think of a use case outside of a homework assignment.

-- 
John Krukoff <[EMAIL PROTECTED]>
Land Title Guarantee Company

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


Re: seemingly simple list indexing problem

2008-07-28 Thread John Krukoff
On Mon, 2008-07-28 at 16:24 -0500, Ervan Ensis wrote:
> My programming skills are pretty rusty and I'm just learning Python so
> this problem is giving me trouble.
> 
> I have a list like [108, 58, 68].  I want to return the sorted indices
> of these items in the same order as the original list.  So I should
> return [2, 0, 1]
> 
> For a list that's already in order, I'll just return the indices, i.e.
> [56, 66, 76] should return [0, 1, 2]
> 
> Any help would be appreciated.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list

If your lists aren't so large that memory is an issue, this might be a
good place for a variation of decorate, sort, undecorate.

>>> listToSort = [ 108, 58, 68 ]
>>> decorated = [ ( data, index ) for index, data in
enumerate( listToSort ) ]
>>> decorated
[(108, 0), (58, 1), (68, 2)]
>>> result = [ None, ] * len( listToSort )
>>> for sortedIndex, ( ignoredValue, originalIndex ) in
enumerate( sorted( decorated ) ):
... result[ originalIndex ] = sortedIndex
... 
>>> result
[2, 0, 1]

-- 
John Krukoff <[EMAIL PROTECTED]>
Land Title Guarantee Company

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


Re: Download excel file from web?

2008-07-28 Thread [EMAIL PROTECTED]
On Jul 28, 3:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hi - experienced programmer but this is my first Python program.
>
> This URL will retrieve an excel spreadsheet containing (that day's)
> msci stock index returns.
>
> http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&;...
>
> Want to write python to download and save the file.
>
> So far I've arrived at this:
>
> [quote]
> # import pdb
> import urllib2
> from win32com.client import Dispatch
>
> xlApp = Dispatch("Excel.Application")
>
> # test 1
> # xlApp.Workbooks.Add()
> # xlApp.ActiveSheet.Cells(1,1).Value = 'A'
> # xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
> # xlBook = xlApp.ActiveWorkbook
> # xlBook.SaveAs(Filename='C:\\test.xls')
>
> # pdb.set_trace()
> response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
> excel?
> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> +25%2C+2008&export=Excel_IEIPerfRegional')
> # test 2 - returns check = False
> check_for_data = urllib2.Request('http://www.mscibarra.com/webapp/
> indexperf/excel?
> priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
> +25%2C+2008&export=Excel_IEIPerfRegional').has_data()
>
> xlApp = response.fp
> print(response.fp.name)
> print(xlApp.name)
> xlApp.write
> xlApp.Close
> [/quote]

Woops hit Send when I wanted Preview.  Looks like the html [quote] tag
doesn't work from groups.google.com (nice).

Anway, in test 1 above, I determined how to instantiate an excel
object; put some stuff in it; then save to disk.

So, in theory, I'm retrieving my excel spreadsheet with

response = urllib2.urlopen()

Except what then do I do with this?

Well for one read some of the urllib2 documentation and found the
Request class with the method has_data() on it.  It returns False.
Hmm that's not encouraging.

I supposed the trick to understand what urllib2.urlopen is returning
to me; rummage around in there; and hopefully find my excel file.

I use pdb to debug.  This is interesting:

(Pdb) dir(response)
['__doc__', '__init__', '__iter__', '__module__', '__repr__', 'close',
'code', '
fileno', 'fp', 'geturl', 'headers', 'info', 'msg', 'next', 'read',
'readline', '
readlines', 'url']
(Pdb)

I suppose the members with __*_ are methods; and the names without the
underbars are attributes (variables) (?).

Or maybe this isn't at all the right direction to take (maybe there
are much better modules to do this stuff).  Would be happy to learn if
that's the case (and if that gets the job done for me).

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


Re: seemingly simple list indexing problem

2008-07-28 Thread John Krukoff

On Mon, 2008-07-28 at 18:40 -0300, Guilherme Polo wrote:
> On Mon, Jul 28, 2008 at 6:24 PM, Ervan Ensis <[EMAIL PROTECTED]> wrote:
> > My programming skills are pretty rusty and I'm just learning Python so this
> > problem is giving me trouble.
> >
> > I have a list like [108, 58, 68].  I want to return the sorted indices of
> > these items in the same order as the original list.  So I should return [2,
> > 0, 1]
> 
> You could simply do this:
> 
> a = [108, 58, 68]
> b = sorted(a)
> [b.index(c) for c in a]
> 
> >
> > For a list that's already in order, I'll just return the indices, i.e. [56,
> > 66, 76] should return [0, 1, 2]
> >
> > Any help would be appreciated.
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
> 
> 
> 

Which'll work fine, unless you end up with a repeated value such as:

a = [ 108, 58, 68, 108 ]

If you have to deal with that, would need a more complicated solution to
find the first free index slot of the available choices.

-- 
John Krukoff <[EMAIL PROTECTED]>
Land Title Guarantee Company

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


Download excel file from web?

2008-07-28 Thread [EMAIL PROTECTED]
Hi - experienced programmer but this is my first Python program.

This URL will retrieve an excel spreadsheet containing (that day's)
msci stock index returns.

http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul+25%2C+2008&export=Excel_IEIPerfRegional

Want to write python to download and save the file.

So far I've arrived at this:

[quote]
# import pdb
import urllib2
from win32com.client import Dispatch

xlApp = Dispatch("Excel.Application")

# test 1
# xlApp.Workbooks.Add()
# xlApp.ActiveSheet.Cells(1,1).Value = 'A'
# xlApp.ActiveWorkbook.ActiveSheet.Cells(2,1).Value = 'B'
# xlBook = xlApp.ActiveWorkbook
# xlBook.SaveAs(Filename='C:\\test.xls')


# pdb.set_trace()
response = urllib2.urlopen('http://www.mscibarra.com/webapp/indexperf/
excel?
priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
+25%2C+2008&export=Excel_IEIPerfRegional')
# test 2 - returns check = False
check_for_data = urllib2.Request('http://www.mscibarra.com/webapp/
indexperf/excel?
priceLevel=0&scope=0¤cy=15&style=C&size=36&market=1897&asOf=Jul
+25%2C+2008&export=Excel_IEIPerfRegional').has_data()

xlApp = response.fp
print(response.fp.name)
print(xlApp.name)
xlApp.write
xlApp.Close
[/quote]
--
http://mail.python.org/mailman/listinfo/python-list


Re: seemingly simple list indexing problem

2008-07-28 Thread Gary Herron

Guilherme Polo wrote:

On Mon, Jul 28, 2008 at 6:24 PM, Ervan Ensis <[EMAIL PROTECTED]> wrote:
  

My programming skills are pretty rusty and I'm just learning Python so this
problem is giving me trouble.

I have a list like [108, 58, 68].  I want to return the sorted indices of
these items in the same order as the original list.  So I should return [2,
0, 1]



You could simply do this:

a = [108, 58, 68]
b = sorted(a)
[b.index(c) for c in a]
  


Yuck.  Slow, and it fails if duplicate list elements exist.

Also...  This looks like a beginners programming assignment.Let's 
let him try it himself.  We can offer help rather than full solutions if 
he has specific Python questions.






  

For a list that's already in order, I'll just return the indices, i.e. [56,
66, 76] should return [0, 1, 2]

Any help would be appreciated.

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






  


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


Re: Is it allowed to use function results as default arguments ?

2008-07-28 Thread Simon Forman
On Jul 28, 1:28 pm, Stef Mientki <[EMAIL PROTECTED]> wrote:
> hello,
>
> I've a perfect working procedure,
> at least as far I've tested it it works perfect.
>
> But I was just experimenting with inspect,
> and saw that the default argument was not parsed correctly.
>
> So I wonder if this is allowed:
>
> def Get_Relative_Path ( target, base=os.curdir ) :
>   ...
>
> As inspect returns the following:
>
> (['target', 'base'], None, None, ('.',))
>
> thanks,
> Stef Mientki

os.curdir is '.' on many platforms.  What did you expect inspect to
show?

|>>> import os
|>>> os.curdir
'.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing VHDL with python, where to start.

2008-07-28 Thread Svenn Are Bjerkem
Hi again,

when I get far enough to parse the VHDL (which is not currently the
fact, but I have to look at the work coming up downstream) I will have
to put it into an internal data structure and then write some classes
to handle the MVC between whatever data I have and the PyQt4 widget
that is going to show the block diagram. I own the book "Rapig GUI
Programming with Python and Qt" by Mark Summerfield and try to read up
on the PyQt way of doing things as I try to make a plan for my
application. I have been looking for possible data structures with
google just to find out that most of the ideas are stored in
proceedings or to conferences or ieee papers not generally available
to me. Is anybody experienced with designing data structures willing
to share some ideas with me? Since I am using the open-source version
of PyQt4, any information will eventually be available to public (if
the app pass the planning stage) if that makes helping out any
easier: :-) There is already an app called Qucs that is running in
Qt-3 and being ported to Qt-4 that is written in C++, but I don't know
how wise it is to just reverse-engineering C++ classes and translate
them into python classes.

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


Re: seemingly simple list indexing problem

2008-07-28 Thread Guilherme Polo
On Mon, Jul 28, 2008 at 6:24 PM, Ervan Ensis <[EMAIL PROTECTED]> wrote:
> My programming skills are pretty rusty and I'm just learning Python so this
> problem is giving me trouble.
>
> I have a list like [108, 58, 68].  I want to return the sorted indices of
> these items in the same order as the original list.  So I should return [2,
> 0, 1]

You could simply do this:

a = [108, 58, 68]
b = sorted(a)
[b.index(c) for c in a]

>
> For a list that's already in order, I'll just return the indices, i.e. [56,
> 66, 76] should return [0, 1, 2]
>
> Any help would be appreciated.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
-- Guilherme H. Polo Goncalves
--
http://mail.python.org/mailman/listinfo/python-list


Re: Proxy server?

2008-07-28 Thread Diez B. Roggisch

Gary schrieb:

"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

Gary wrote:



For what?


A non-transparent proxy, for anonymity purposes only.



You can't make any TCP/IP communication run through a proxy, unless it's 
transparent.


HTTP (and maybe FTP, I personally don't know) have that built-in, and of 
course anything that builds upon them (SOAP, XMLRPC).



But e.g. CORBA or bittorrent or  don't support that.

You can try and install TOR or use it. It is a transparent proxy:

http://wiki.noreply.org/noreply/TheOnionRouter/TransparentProxy

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


seemingly simple list indexing problem

2008-07-28 Thread Ervan Ensis
My programming skills are pretty rusty and I'm just learning Python so this
problem is giving me trouble.

I have a list like [108, 58, 68].  I want to return the sorted indices of
these items in the same order as the original list.  So I should return [2,
0, 1]

For a list that's already in order, I'll just return the indices, i.e. [56,
66, 76] should return [0, 1, 2]

Any help would be appreciated.
--
http://mail.python.org/mailman/listinfo/python-list

Python-URL! - weekly Python news and links (Jul 28)

2008-07-28 Thread Gabriel Genellina
QOTW:  "Python's goals are to maximize opportunities for good
programming, which is quite different." - Bruno Desthuilliers, contrasting
Python with Java


Load and initialize dynamic plugins from a directory:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/ba8d361516403fdf/

Importing different versions of a module:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/9039a778e573893b/

Some details on the CPython VM implementation:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/d36bc1db8e64e18c/

"Real languages are written in C#, not decadent C" (or something
like that ...):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/355439b8fca5b1f6/

The different 64bits architectures supported by different Python
implementations:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b8bcb70ad78030dd/

Looking for a "scanf" replacement:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/26a24e5ec15f4088/

Python and tail-call optimization:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/25ff95177f537a16/

A long thread against the "Explicit is better than implicit" principle:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/a5fa8ff0ffadd6ee/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiats":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented RSS/RDF feeds available are
http://www.python.org/channews.rdf
http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi
http://python.de/backend.php
For more, see
http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all
The old Python "To-Do List" now lives principally in a
SourceForge reincarnation.
 

Re: Attack a sacred Python Cow

2008-07-28 Thread Bruno Desthuilliers

Russ P. a écrit :

On Jul 28, 4:23 am, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:

Russ P. a écrit :


(snip)


A bonus is that it becomes
clearer at the point of usage that ".data" is member data rather than
a local variable.

I totally disagree. The dot character is less obvious than the 'self.'
sequence, so your proposition is bad at least wrt/ readability (it's
IMHO bad for other reasons too but I won't continue beating that poor
dead horse...)


Man, you are one dense dude! Can I give you a bit of personal advice?
I suggest you quit advertising your denseness in public.


Thanks.


Letting "self" (or whatever the first argument was) be implied in
".cat" does absolutely *NOTHING* to change the internal workings of
the Python interpreter.


You probably have a way better knowledge of Python's compiler and 
interpreter than I do to assert such a thing. But if it's so easy, 
please provide a working patch.



It's a very simple idea that you insist on
making complicated. As I said, I could write a pre-processor myself to
implement it in less than a day.


Preprocessor are not a solution. Sorry.


As for "dot" being less obvious than "self.", no kidding?


Nope. I'm deadly serious.

(snip no-op argument and name-calling).


Your posts here are typical. I'm trying to make a suggestion to reduce
the clutter in Python code,


s/the clutter/what Russ P. decided to consider as clutter/


and you throw tomatoes mindlessly.


Oh, you don't stand people disagreing with you, that's it ?


You seem to think that being a "regular" on this newsgroup somehow
gives you special status.


Why so ? Because I answer to your proposition and not agree with  your 
arguments ??? C'mon, be serious, you have the right to post your 
proposition here, I have the right to post my reaction to your 
proposition, period. Grow up, boy.



I sure wish I had one tenth the time to
spend here that you have. But even if I did, I have far more important
work to do than to "hang out" on comp.lang.python all day every day.
Man, what a waste of a life. Well, I guess it keeps you off the
streets at least.


Boy, I don't know who you think you're talking to, but you're obviously 
out of luck here. I'm 41, married, our son is now a teenager, I have an 
happy social life, quite a lot of work, and no time to waste in the 
streets. And FWIW, name-calling won't buy you much here.



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


Re: Questions on 64 bit versions of Python

2008-07-28 Thread Martin v. Löwis
> I hadn't heard "Intel 64" before. That's a bit nervy, isn't it? Plus it 
> seems to conflict with their own use of "IA-64" (Intel Architecture 64) 
> for the Itanium (vs. "IA-32" for traditional x86).

Indeed. Microsoft Installer has an architecture string for the MSI file;
"Intel64" there means Itanium (and AMD64 can be denoted by either
"AMD64" or "x64"). This was from a time when Intel still told people
that the future of 64-bit computing is in Itanium (and architecturally,
I still think this would have been the right choice).

Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Protecting instance variables

2008-07-28 Thread Bruno Desthuilliers

Nikolaus Rath a écrit :

Hi,

Sorry for replying so late. Your MUA apparently messes up the
References:, so I saw you reply only now and by coincidence.

"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:

Nikolaus Rath schrieb:

Hello,

I am really surprised that I am asking this question on the mailing
list, but I really couldn't find it on python.org/doc.

Why is there no proper way to protect an instance variable from access
in derived classes?

I can perfectly understand the philosophy behind not protecting them
from access in external code ("protection by convention"), but isn't
it a major design flaw that when designing a derived class I first
have to study the base classes source code? Otherwise I may always
accidentally overwrite an instance variable used by the base class...

Here we go again...

http://groups.google.com/group/comp.lang.python/browse_thread/thread/188467d724b48b32/

To directly answer your question: that's what the __ (double
underscore) name mangling is for.



I understand that it is desirable not to completely hide instance
variables. But it seems silly to me that I should generally prefix
almost all my instance variables with two underscores.


Why on earth would you protect "almost all" your attributes ???


I am not so much concerned about data hiding, but about not
accidentally overwriting a variable of the class I'm inheriting from.

>

And, unless I misunderstood something, this is only possible if I'm
prefixing them with __.

How is this problem solved in practice?


Which "problem" ?-)

What your afraid of almost never happens. FWIW, it *never* happened to 
me in now 8+ years. And I almost never use __name_mangling_protection 
(I'd say about half a dozen times, and mostly because I was getting a 
bit paranoid on these occasions).



I probably don't have a
representative sample, but in the libraries that I have been using so
far, there were a lot of undocumented (in the sense of: not being part
of the public API) instance variables not prefixed with __. 


Oh, while we're at it: the convention for "protected" attributes (that 
is: not part of the API, but ok to override) is to use a single leading 
undescore.



I have
therefore started to first grep the source of all base classes
whenever I introduce a new variable in my derived class. Is that
really the way it's supposed to be? What if one of the base classes
introduces a new variable at a later point?


Well... Since Python is dynamicall typed, and since it has good support 
for composition/delegation, type hierarchies tends to be *way* much 
flatter than in Java or C++. So there's way less name collision hazards. 
As I said, what you fear just never happened to me so far, even in 
frameworks like Zope which is probably where you'll find the worst case 
of deep type hierarchies and multiple inheritance abuse in Python.


IOW : unless your code suddenly breaks in strange ways after you've 
added a new attribute (or renamed one), just don't worry.

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

Re: Protecting instance variables

2008-07-28 Thread Michael Mabin
What about __setattr__()?

On Mon, Jul 28, 2008 at 5:23 AM, Nikolaus Rath <[EMAIL PROTECTED]> wrote:

> Hi,
>
> Sorry for replying so late. Your MUA apparently messes up the
> References:, so I saw you reply only now and by coincidence.
>
> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> > Nikolaus Rath schrieb:
> >> Hello,
> >>
> >> I am really surprised that I am asking this question on the mailing
> >> list, but I really couldn't find it on python.org/doc.
> >>
> >> Why is there no proper way to protect an instance variable from access
> >> in derived classes?
> >>
> >> I can perfectly understand the philosophy behind not protecting them
> >> from access in external code ("protection by convention"), but isn't
> >> it a major design flaw that when designing a derived class I first
> >> have to study the base classes source code? Otherwise I may always
> >> accidentally overwrite an instance variable used by the base class...
> >
> > Here we go again...
> >
> >
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/188467d724b48b32/
> >
> > To directly answer your question: that's what the __ (double
> > underscore) name mangling is for.
>
>
> I understand that it is desirable not to completely hide instance
> variables. But it seems silly to me that I should generally prefix
> almost all my instance variables with two underscores.
>
> I am not so much concerned about data hiding, but about not
> accidentally overwriting a variable of the class I'm inheriting from.
> And, unless I misunderstood something, this is only possible if I'm
> prefixing them with __.
>
> How is this problem solved in practice? I probably don't have a
> representative sample, but in the libraries that I have been using so
> far, there were a lot of undocumented (in the sense of: not being part
> of the public API) instance variables not prefixed with __. I have
> therefore started to first grep the source of all base classes
> whenever I introduce a new variable in my derived class. Is that
> really the way it's supposed to be? What if one of the base classes
> introduces a new variable at a later point?
>
>
> Best,
>
>   -Nikolaus
>
> --
>  »It is not worth an intelligent man's time to be in the majority.
>  By definition, there are already enough people to do that.«
> -J.H. Hardy
>
>  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
>
> --
>  http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Running python scripts in a VB program

2008-07-28 Thread Zach Hobesh
Does anyone have any clue on how to embed python scripts in a visual basic
windows app?

Additionally, does anybody else feel like Visual Basic is ridiculously
confusing?

Any help is appreciated.

Thanks,

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

Re: multiple inheritance and __getattr__

2008-07-28 Thread Bruno Desthuilliers

Enrico a écrit :

Hi there,
I have the following situation (I tryed to minimize the code to concentrate
on the issue):


class A(object):

 def __getattr__(self, name):
  print 'A.__getattr__'
  if name == 'a': return 1
  raise AttributeError('%s not found in A' % name)


class B(object):

 def __getattr__(self, name):
  print 'B.__getattr__'
  if name == 'b': return 1
  raise AttributeError('%s not found in B' % name)

Both classes have a __getattr__ method.
Now I want to have a class that inherits from both so I write:


class C(B,A):

 pass

The problem arise when I try something like this:

c=C()
c.a

A.__getattr__
1

c.b

A.__getattr__

Traceback (most recent call last):
  File "", line 1, in 
c.b
  File "", line 5, in __getattr__
raise AttributeError('%s not found in A' % name)
AttributeError: b not found in A


That's what I would have expected.


I was expecting, after a fail in A.__getattr__,  a call to the __getattr__
method of B but it seems that after A.__getattr__ fails the exception stops
the flow.


Indeed. You explicitely raise, so the lookup stops here. You'd need to 
explicitely call on superclass instead to have B.__getattr__ called, ie:


class A(object):
def __getattr__(self, name):
if name == 'a':
return 1
return super(A, self).__getattr__(name)

class B(object):
def __getattr__(self, name):
if name == 'b':
return 2
return super(B, self).__getattr__(name)

class C(A, B):
pass

c = C()
c.a
=> 1
c.b
=> 2


So, if I did understand well, B.__getattr__ will be never called
"automatically".  I don't know if this has a reason, if it is a design choice
or what else, any explanation is welcome.

>

Since A and B are not written by me I can only work on C.


Really ? You know, Python is a *very* dynamic language. If A and B are 
ordinary Python classes (ie: not builtin types, not C extensions, etc), 
you can monkeypatch them. But that's not necessarily the best thing to 
do (it would require more work than your actual solution).



The solution that
comes to my mind is to define a __getattr__ also in C and write something
like:


class C(A,B):

 def __getattr__(self, name):
  try:
   return A.__getattr__(self, name)
  except AttributeError:
   return B.__getattr__(self, name)


or more generically:

class C(A, B):
def __getattr__(self, name):
for cls in type(self).__mro__[1:]:
try:
return cls.__getattr__(self, name)
except AttributeError:
pass
else:
raise AttributeError('blah blah')

You could also override __getattribute__, but then again, this wouldn't 
be better (more code, and possible performances loss).



A better solution is welcome.


If you don't have commit rights on the module(s) defining A and B, then 
your solution is probably the simplest thing to do.


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


Is it allowed to use function results as default arguments ?

2008-07-28 Thread Stef Mientki

hello,

I've a perfect working procedure,
at least as far I've tested it it works perfect.

But I was just experimenting with inspect,
and saw that the default argument was not parsed correctly.

So I wonder if this is allowed:

def Get_Relative_Path ( target, base=os.curdir ) :
 ...

As inspect returns the following:

(['target', 'base'], None, None, ('.',))

thanks,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-28 Thread Carl Banks
On Jul 28, 10:00 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> Cutting to the crux of the discussion...
>
> On Sun, 27 Jul 2008 23:45:26 -0700, Carl Banks wrote:
> > I want something where "if x" will do but a simple explicit test won't.
>
> Explicit tests aren't simple unless you know what type x is. If x could
> be of any type, you can't write a simple test. Does x have a length? Is
> it a number? Maybe it's a fixed-length circular length, and the length is
> non-zero even when it's empty? Who knows? How many cases do you need to
> consider?

Use case, please.  I'm asking for code, not arguments.  Please give me
a piece of code where you can write "if x" that works but a simple
explicit test won't.

(Note: I'm not asking you to prove that "if len(x)!=0" might fail for
some contrived, poorly-realized class you could write.  I already know
you can do that.)


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


xlrd: error open_workbook

2008-07-28 Thread Fabio Oikawa
Hello.

I am trying to open an .xls (excel) file using xlrd, but an error message
occurs when I open the workbook.

I can open any other .xls file made by myself (either by MS Excel 2003 SP3
in Windows Vista or by OpenOffice 2.0 in Debian) using the
*open_workbook*function:

wb = xlrd.open_workbook('myworkbook.xls')

but when I try to open a file from one specific site, I get the error
message:

In [2]: wb = xlrd.open_workbook('balanco.xls')

WARNING *** file size (81192) not 512 + multiple of sector size (512)
WARNING *** OLE2 inconsistency: SSCS size is 0 but SSAT size is non-zero
---
struct.error Traceback (most recent call
last)

/home/oikawa/DB/

/usr/lib/python2.4/site-packages/xlrd/__init__.py in open_workbook(filename,
logfile, verbos ity, pickleable, use_mmap, file_contents, encoding_override,
formatting_info)
380 bk.parse_globals()
381 else:
--> 382 bk.parse_globals()
383 bk.get_sheets()
384 bk.nsheets = len(bk._sheet_list)

/usr/lib/python2.4/site-packages/xlrd/__init__.py in parse_globals(self)
   1309 self.handle_name(data)
   1310 elif rc == XL_PALETTE:
-> 1311 self.handle_palette(data)
   1312 elif rc == XL_STYLE:
   1313 self.handle_style(data)

/usr/lib/python2.4/site-packages/xlrd/formatting.py in handle_palette(book,
data)
550 "PALETTE record with %d colours\n", n_colours)
551 fmt = ' 552 colours = unpack(fmt, data)
553 assert book.palette_record == [] # There should be only 1
PALETTE record
554 # a colour will be 0xbbggrr

error: unpack str size does not match format

I ran the xlrd in both Windows Vista / Python 2.5 and Debian / Python 2.4.4
and got the same problem, so I suppose there is something wrong with the
.xls files (which can be downloaded at www.fundamentus.com.br --> "Dados
Históricos" menu --> "Balancos em Excel" --> choose any company). However, I
need the files in order to create my database system. Actually I want to
build all companies' informations in a mySQL database, and the fastest and
easiest way I found is to download .xls files, to get the data using
xlrd-Python and to add them in the mySQL database. Any sugestions for both
questions? Thanks in advance.

Best regards,
Fabio Oikawa
--
http://mail.python.org/mailman/listinfo/python-list

Re: block/lambda

2008-07-28 Thread iu2
On Jul 28, 10:06 pm, iu2 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Playing with imitating lambdas and ruby blocks in Python, I came up
> with a very simple construct, for example:
>
> import compiler
>
> def dotimes(i, code):
>     for i in range(i):
>         exec code
>
> dotimes(5, '''
> for j in range(i):
>         print j,
> print
> ''', '', 'exec')
>
> This will print
> 0
> 0 1
> 0 1 2
> 0 1 2 3
>
> A more efficient code would probably be
>
> dotimes(5, compiler.compile('''
> for j in range(i):
>         print j,
> print
> ''', '', 'exec'))
>
> which is, to my understanding, exactly what a ruby block is.
>
> But the actual "discovery" here, is that the triple quote - ''' -
> makes a syntax for block passing. Having a code editor that keeps
> colorizing what's inside the quotes like a normal code would make it
> easier to maintain.
>
> Is it possible to grant Python another syntactic mark, similar to
> triple quotes, that will actually make the enclosed code a compiled
> code, or an anonymous function?
>
> I know that anonymous functions (long lambdas...) are not on the road
> map. But I ask this because, as I understand it, the triple quote
> actually presents a syntax for it.
> Isn't it actually a matter of taking the triple-quotes a little bit
> further?
>
> Thanks

There is a mistake in my first example, the code is, of course:
dotimes(5, '''
for j in range(i):
print j,
print
''')

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


block/lambda

2008-07-28 Thread iu2
Hi,

Playing with imitating lambdas and ruby blocks in Python, I came up
with a very simple construct, for example:

import compiler

def dotimes(i, code):
for i in range(i):
exec code

dotimes(5, '''
for j in range(i):
print j,
print
''', '', 'exec')

This will print
0
0 1
0 1 2
0 1 2 3

A more efficient code would probably be

dotimes(5, compiler.compile('''
for j in range(i):
print j,
print
''', '', 'exec'))

which is, to my understanding, exactly what a ruby block is.

But the actual "discovery" here, is that the triple quote - ''' -
makes a syntax for block passing. Having a code editor that keeps
colorizing what's inside the quotes like a normal code would make it
easier to maintain.

Is it possible to grant Python another syntactic mark, similar to
triple quotes, that will actually make the enclosed code a compiled
code, or an anonymous function?

I know that anonymous functions (long lambdas...) are not on the road
map. But I ask this because, as I understand it, the triple quote
actually presents a syntax for it.
Isn't it actually a matter of taking the triple-quotes a little bit
further?

Thanks

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


Re: how to upload files to "google code" filesection ?

2008-07-28 Thread Stef Mientki

Mike Driscoll wrote:

Stef,

  

Mike Driscoll wrote:


On Jul 26, 12:43 pm, Stef Mientki <[EMAIL PROTECTED]> wrote:
  

hello,

In a program I want to download (updated) files from google code (not

the svn section).
I could find a python script to upload files,
but not for downloading.

Anyone has a hint or a solution ?

thanks,

Stef Mientki


You should be able to use urllib to do that. The following link has a
recipe:
  
http://code.activestate.com/recipes/496685/
  

thanks Mike,

I already found an even simpler solution (that works)

filename, header = urllib.urlretrieve (url)



If you need to search Google Code, there's an API that appears to be
exposed through their gdata module.
  

Do you have perhaps a more specific link ?
I saw the Google API's, but its'quit large / complex, so I couldnt find
it there.

cheers,
Stef



Mike
  


I was looking at this page about Google Code Search:
http://code.google.com/apis/codesearch/

You should be able to use the API that's outlined there in conjunction
with the gdata module on this page:

http://code.google.com/p/gdata-python-client/

  

thanks Mike,
I'll take a look at those links.

cheers,
Stef

Mike

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


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


Re: QOTW [was Re: Attack a sacred Python Cow]

2008-07-28 Thread Russ P.
On Jul 28, 7:07 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sun, 27 Jul 2008 21:42:37 -0700, Russ P. wrote:
> >> +1 QOTW
>
> > Do you realize what an insult that is to everyone else who has posted
> > here in the past week?
>
> Actually I don't. I hadn't realised that when a person believes that
> somebody has made an especially clever, witty, insightful or fun remark,
> that's actually a put-down of all the other people whose remarks weren't
> quite as clever, witty, insightful or fun.
>
> But now that I've had this pointed out to me, why, I see insults
> everywhere! Tonight, my wife said to me that she liked my new shirt, so I
> replied "What's the matter, you think my trousers are ugly?"
>
> --
> Steven

That would all be true if the comment that was called "QOTW" was
indeed clever or, for that matter, true. It was neither.

The idea that Python does not try to discourage bad programming
practice is just plain wrong. Ask yourself why Python doesn't allow
assignment within a conditional test ("if x = 0"), for example. Or,
why it doesn't allow "i++" or "++i"? I'll leave it as an exercise for
the reader to give more examples.

Also, the whole idea of using indentation to define the logical
structure of the code is really a way to ensure that the indentation
structure is consistent with the logical structure. Now, is that a way
to "encourage good practice," or is it a way to "discourage bad
practice"? The notion that the two concepts are "very different" (as
the "QOTW" claimed) is just plain nonsense.
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to upload files to "google code" filesection ?

2008-07-28 Thread Mike Driscoll
Stef,

> Mike Driscoll wrote:
> > On Jul 26, 12:43 pm, Stef Mientki <[EMAIL PROTECTED]> wrote:
>
> >> hello,
>
> >> In a program I want to download (updated) files from google code (not
> >> the svn section).
> >> I could find a python script to upload files,
> >> but not for downloading.
>
> >> Anyone has a hint or a solution ?
>
> >> thanks,
> >> Stef Mientki
>
> > You should be able to use urllib to do that. The following link has a
> > recipe:
>
> >http://code.activestate.com/recipes/496685/
>
> thanks Mike,
>
> I already found an even simpler solution (that works)
>
>     filename, header = urllib.urlretrieve (url)
>
> > If you need to search Google Code, there's an API that appears to be
> > exposed through their gdata module.
>
> Do you have perhaps a more specific link ?
> I saw the Google API's, but its'quit large / complex, so I couldnt find
> it there.
>
> cheers,
> Stef
>
> > Mike

I was looking at this page about Google Code Search:
http://code.google.com/apis/codesearch/

You should be able to use the API that's outlined there in conjunction
with the gdata module on this page:

http://code.google.com/p/gdata-python-client/

Mike

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


Re: SimpleJson is slow .... is there any C Compiled version ?

2008-07-28 Thread Joshua Kugler
sanket wrote:

> Hello All,
> 
> I have created an API which fetches some data from the database.
> I am using simplejson to encode it and return it back.
> 
> Now the problem is that, this API is being called for millions of
> times in a sequence.
> I ran a profiler and saw that most of the time is consumed in encoding
> my database results in to json.
> So I was just wondering is there any C compiled version of simplejson
> is available?
> or any help regarding this issue would be appreciated.

simplejson does have a C module.  It is compiled automatically when
installed.  If you're installing on Windows, then it probably isn't getting
compiled.

j

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


Re: like py2exe, but on a mac

2008-07-28 Thread Kevin Walzer

William McBrine wrote:

On Mon, 28 Jul 2008 19:51:26 +0200, Tommy Nordgren wrote:


There is Platypus, a general open source program to wrap a script
in an Macintosh (GUI) Application.


Thanks. I tried Platypus, and it's close to what I want. But I still 
can't seem to get rid of the small "Console" window that pops up behind 
my Tkinter app.




That's not something that py2app can solve.

Add this call to your Python script somewhere (modify as needed):

   try:
self.tk.call('console', 'hide')
except TclError:
pass

HTH,
Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: like py2exe, but on a mac

2008-07-28 Thread Tommy Nordgren


On 28 jul 2008, at 20.22, William McBrine wrote:


On Mon, 28 Jul 2008 19:51:26 +0200, Tommy Nordgren wrote:


There is Platypus, a general open source program to wrap a script
in an Macintosh (GUI) Application.


Thanks. I tried Platypus, and it's close to what I want. But I still
can't seem to get rid of the small "Console" window that pops up  
behind

my Tkinter app.

--
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list

Try setting the Output popup menu to 'None'
--
What is a woman that you forsake her, and the hearth fire and the home  
acre,
to go with the old grey Widow Maker.  --Kipling, harp song of the Dane  
women

Tommy Nordgren
[EMAIL PROTECTED]



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


Re: Attack a sacred Python Cow

2008-07-28 Thread Russ P.
On Jul 28, 2:52 am, alex23 <[EMAIL PROTECTED]> wrote:
> On Jul 28, 3:07 pm, "Russ P." <[EMAIL PROTECTED]> wrote:
>
> > What was "suggested in rejected" on the thread you pointed me to was
> > not what I suggested. Not even close. Get it, genius?
>
> *sigh* Clearly I don't have better things to do right now than waste
> my time.
>
> You wrote:
> > So why not allow something like this?:
> > class MyClass:
> > def func( , xxx, yyy):
> >.xxx = xxx
> >local = .yyy
> > The "self" argument is replaced with nothing, but a comma is used as a
> > placeholder.
>
> Philip Eby suggested in the thread I linked to:
>
> > def .aMethod(arg1, arg2):
> > return .otherMethod(arg1*2+arg2)
> > In other words, 'self' here is uniformly replaced by an empty string.
>
> So you honestly see no similarity between your suggestion and the
> latter?
>
> Or do you seriously think that placing an errant comma in the argument
> list is somehow substantively different from placing a period before
> the function name?

Yes, in terms of Python syntax, it's completely different.

Forget the empty first argument. As I explained in other posts on this
thread, it is not even needed for my proposal. It was just a
distraction from the main idea.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Questions on 64 bit versions of Python

2008-07-28 Thread William McBrine
On Sun, 27 Jul 2008 20:31:07 +0200, Martin v. Löwis wrote:

> Originally, AMD called it x86-64, and later renamed it to AMD64. Intel
> originally implemented it under the name EM64T (for Extended Memory 64
> Technology), and now calls the architecture Intel 64.

I hadn't heard "Intel 64" before. That's a bit nervy, isn't it? Plus it 
seems to conflict with their own use of "IA-64" (Intel Architecture 64) 
for the Itanium (vs. "IA-32" for traditional x86).

-- 
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on
--
http://mail.python.org/mailman/listinfo/python-list

Re: Attack a sacred Python Cow

2008-07-28 Thread Russ P.
On Jul 28, 4:23 am, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> Russ P. a écrit :
>
>
>
> > On Jul 27, 3:11 pm, "Russ P." <[EMAIL PROTECTED]> wrote:
> >> On Jul 27, 12:39 pm, Bruno Desthuilliers
>
> >> <[EMAIL PROTECTED]> wrote:
> >>> Derek Martin a écrit :
>  On Sun, Jul 27, 2008 at 08:19:17AM +, Steven D'Aprano wrote:
> >> You take the name down to a single letter. As I suggested in an earlier
> >> post on this thread, why not take it down to zero letters?
> > The question isn't "why not", but "why". The status quo works well as it
> > is, even if it isn't perfect. Prove that implicit self is a good idea --
> > or at least prove that it is an idea worth considering.
>  Come on, this sounds like a schoolyard argument.  This comes down to a
>  matter of style, and as such, is impossible to prove.  It's largely a
>  question of individual preference.
>  That said, the argument in favor is rather simple:
>  1. This is an extremely common idiom in Python
>  2. It is completely unnecessary, and the language does not suffer for
> making it implicit
>  3. Making it implicit reduces typing, reduces opportunities for
> mistakes, and arguably increases consistency.
> >>> "arguably", indeed, cf below.
>  As for the latter part of #3, self (or some other variable) is
>  required in the parameter list of object methods,
> >>> It's actually the parameter list of the *function* that is used as the
> >>> implementation of a method. Not quite the same thing. And then,
> >>> consistency mandates that the target object of the method is part of the
> >>> parameter list of the *function*, since that's how you make objects
> >>> availables to a function.
>  however when the
>  method is *called*, it is omitted.
> >>> Certainly not. You need to lookup the corresponding attribute *on a
> >>> given object* to get the method. Whether you write
> >>>some_object.some_method()
> >>> or
> >>>some_function(some_object)
> >>> you still need to explicitely mention some_object.
>  It is implied, supplied by Python.
> >>> Neither. The target object is passed to the function by the method
> >>> object, which is itself returned by the __get__ method of function
> >>> objects, which is one possible application of the more general
> >>> descriptor protocol (the same protocol that is used for computed
> >>> attributes). IOW, there's nothing specific to 'methods' here, just the
> >>> use of two general features (functions and the descriptor protocol).
> >>> FWIW, you can write your own callable, and write it so it behave just
> >>> like a function here:
> >>> import types
> >>> class MyCallable(object):
> >>> def __call__(self, obj):
> >>> print "calling %s with %s" % (self, obj)
> >>> def __get__(self, instance, cls):
> >>> return types.MethodType(self.__call__, instance, cls)
> >>> class Foo(object):
> >>>  bar = MyCallable()
> >>> print Foo.bar
> >>> f = Foo()
> >>> f.bar()
>  Thus when an object method is called, it must be called with one fewer
>  arguments than those which are defined.   This can be confusing,
>  especially to new programmers.
> >>> This is confusing as long as you insist on saying that what you
> >>> "def"ined is a method - which is not the case.
>  It can also be argued that it makes the code less ugly, though again,
>  that's a matter of preference.
> > It's not enough to show that a change "isn't bad" -- you have to show
> > that it is actively good.
>  But he did... he pointed out that *it saves work*, without actually
>  being bad.  Benefit, without drawback.  Sounds good to me!
> > "Don't need to look at the method signature" is not an argument in 
> > favour
> > of implicit self.
>  Yes, actually, it is.
> >>> It isn't, since there's no "method signature" to look at !-)
>   If there is a well-defined feature of Python
>  which provides access to the object within itself,
> >>> The point is that you don't get access to the object "within itself".
> >>> You get access to an object *within a function*.
> >>> The fact that a function is defined within a class statement doesn't
> >>> imply any "magic", it just creates a function object, bind it to a name,
> >>> and make that object an attribute of the class. You have the very same
> >>> result by defining the function outside the class statement and binding
> >>> it within the class statement, by defining the function outside the
> >>> class and binding it to the class outside the class statement, by
> >>> binding the name to a lambda within the class statement etc...
>  then the
>  opportunities for mistakes when someone decides to use something else
>  are lessened.
> > You don't need to look at the method signature when you're using an
> > explicit self either.
>  That isn't necessarily true.  If you're using someone else's code, and
>  they didn't u

Re: how to upload files to "google code" filesection ?

2008-07-28 Thread Stef Mientki

Mike Driscoll wrote:

On Jul 26, 12:43 pm, Stef Mientki <[EMAIL PROTECTED]> wrote:
  

hello,

In a program I want to download (updated) files from google code (not
the svn section).
I could find a python script to upload files,
but not for downloading.

Anyone has a hint or a solution ?

thanks,
Stef Mientki



You should be able to use urllib to do that. The following link has a
recipe:

http://code.activestate.com/recipes/496685/
  

thanks Mike,

I already found an even simpler solution (that works)
  
   filename, header = urllib.urlretrieve (url)



If you need to search Google Code, there's an API that appears to be
exposed through their gdata module.
  

Do you have perhaps a more specific link ?
I saw the Google API's, but its'quit large / complex, so I couldnt find 
it there.


cheers,
Stef


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


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


Re: Where is the correct round() method? Use math.ceil

2008-07-28 Thread Maric Michaud
Le Monday 28 July 2008 02:35:08 Herman, vous avez écrit :
> Where is the correct round() method?
> Hello,
>
>  I need a round function that _always_ rounds to the higher integer if
>  the argument is equidistant between two integers. In Python 3.0, this
>  is not the advertised behavior of the built-in function round() as
>
>  seen below:
>  >>> round(0.5)
>
>  0
>
>  >>> round(1.5)
>
>  2
>
>  >>> round(2.5)
>
>  2

Hmm, I don't have the same result in python2.6, I suspect it's a floating 
point precision problem, try just to type "0.5" in the console to see the 
exact representation of this value on your system, it may be just over or 
just down by a small quantity.

On mine with 2.6 this typically give :

>>>[26]: 0.5
...[26]: 0.5

>>>[27]: 0.49
...[27]: 0.48999

>>>[29]: 0.51
...[29]: 0.51001

>>>[28]: 1.1
...[28]: 1.1001

>>>[35]: round(0.5)
...[35]: 1.0


-- 
_

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


Re: Proxy server?

2008-07-28 Thread Gary

"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Gary wrote:

> For what?

A non-transparent proxy, for anonymity purposes only.


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


  1   2   3   >