Re: [ANN] PPyGui emulator

2008-05-14 Thread Claudio Driussi

Stef Mientki wrote:


I've ran the first real world application through PPyGui-emulator,
so I think it's time to release the first version.
There's lot of room for improvements and a more beautiful layout.

PPyGui-emulator is build upon wxPython and released under BSD license.

For remarks, screen shots and downloads, see
http://oase.uci.kun.nl/~mientki/data_www/pylab_works/pp_intro.html


Wow! wonderful.
I was searching for it for debugging and easy development purposes,
screenshots sounds promising.

but the api.py link is broken.

Well the file is correctly at the server,
and indeed it downloads as nonsense ???
Is it not possible to just put a py-file on the server ??

Anyway, I've changed it into a zip file, and now everything works (at 
least at my place)


Yea, tried, it works like a charm even into winpdb debugger.

Very nice, many thanks
Claudio

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


[x for x in <> while <>]?

2008-05-14 Thread urikaluzhny
It seems that I rather frequently need a list or iterator of the form
[x for x in <> while <>]
And there is no one like this.
May be there is another short way to write it (not as a loop). Is
there?
Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: Nasty gotcha/bug in heapq.nlargest/nsmallest

2008-05-14 Thread Gabriel Genellina
En Wed, 14 May 2008 23:47:56 -0300, George Sakkis <[EMAIL PROTECTED]> escribió:

> I spent several hours debugging some bogus data results that turned
> out to be caused by the fact that heapq.nlargest doesn't respect rich
> comparisons:
>
> import heapq
> import random
>
> class X(object):
> def __init__(self, x): self.x=x
> def __repr__(self): return 'X(%s)' % self.x
> if True:
> # this succeeds
> def __cmp__(self, other): return cmp(self.x , other.x)
> else:
> # this fails
> def __lt__(self, other): return self.x < other.x
>
> s = [X(i) for i in range(10)]
> random.shuffle(s)
>
> s1 = heapq.nlargest(5, s)
> s2 = sorted(s, reverse=True)[:5]
> assert s1 == s2, (s,s1,s2)
>
> s1 = heapq.nsmallest(5, s)
> s2 = sorted(s)[:5]
> assert s1 == s2, (s,s1,s2)
>
>
> According to the docs, nlargest is equivalent to: "sorted(iterable,
> key=key, reverse=True)[:n]" and similarly for nsmallest. So that must
> be at least a documentation bug, if not an implementation one.

Your class is not properly defined. sorted() only uses < to compare items, but 
this fact is NOT documented as far as I can tell. So you are abusing this 
implementation detail by not defining the other comparison operators, and the X 
class has a rather strange behavior:

py> X(1) X(1)<=X(2)
False  # !!!
py> X(1)>X(2)
False
py> X(1)==X(1)
False  # !!!

If you write all the six rich comparison methods (__lt__, __le__, etc) nlargest 
and nsmallest work fine.
If your objects are fully comparable (like numbers; that is, given A and B, one 
and only one of these holds: AB) the easiest way is to write a 
helper function (like the old __cmp__) and implement the rich comparison 
methods using it. Those six methods could be defined in a mixin class.

-- 
Gabriel Genellina

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


Re: Passing functions around and executing

2008-05-14 Thread Arnaud Delobelle
alex23 <[EMAIL PROTECTED]> writes:

> On May 15, 10:53 am, PatrickMinnesota <[EMAIL PROTECTED]>
> wrote:
>> I have a bunch of functions.  I want to put them in a list.  Then I
>> want to pass that list into another function which does some setup and
>> then loops through the list of passed in functions and executes them.
>> Some of them need arguments passed in too.
>
> Hey Patrick,
>
> Is something like the following helpful?
>
 def fn1(): print 'fn1'
 def fn2(): print 'fn2'
 fn_list = [fn1, fn2]
 def process(fn_seq):
> ... # do set up here
> ... for fn in fn_list:
> ... fn()
>
 process(fn_list)
> fn1
> fn2
>
> The easiest way to extend this for optional argument passing would be
> to have each function accept keyword arguments, and then to pass a
> dictionary of arguments in to each:
>
Or you could wrap your functions in functools.partial:

def foo(n):
return 'x'*n

>>> from functools import partial
>>> foo10 = partial(foo, 10)
>>> print foo10()
xx

HTH

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


Re: Class Methods Vs Any Other Callable

2008-05-14 Thread Arnaud Delobelle
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:

> On 14 mai, 22:44, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
>> > On 14 mai, 19:45, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>> >> __new__ is a static method!
>>
>> > __new__ is a special-cased staticmethod that  1/ must not be declared
>> > as such and 2/ takes the class object as first args. As far as I'm
>> > concerned, it's semantically a classmethod.
>>
>> It's a static method!
>
> Sorry Arnaud, I probably didn't made it clear enough : I do know it is
> a staticmethod object. What I say is that
> 1/ it's special-cased since you don't *explicitely* declare it as a
> staticmethod
> 2/ it behaves just like a classmethod, since it takes the class as
> first argument.
>
> IOW, I'm talking about semantic, not implementation.

... and I was being facetious, not serious :)

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


Sanitised Newsgroup Feeds?

2008-05-14 Thread Paddy
Hi,
Does anyone do a sanitised newsgroup feed? Something like what mail
filters do for email?

It is getting tedious wading through the ads for 'cracks' & watches;
as well as the Xah cross-posted self-promotions, the wx-'its easier to
post than read the tutorial' annoyances and the castiro (human/Eliza?)
weirdnesses.
I guess that many would want to add the same things to their kill
file,  but it takes me three clicks to add anyone/any thread to it and
the c.l.p signal-to-noise is getting lower.

I'd like to thank the posters of the weekly summary - it's great and I
will continue to read it, but It is more fun reading and posting to
Python blog-posts via a Google Reader search, than it is c.l.p

Python popularity is a double-edged sword.

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


Another BeautifulSoup crash on bad HTML

2008-05-14 Thread John Nagle

   Can't really blame BeautifulSoup for this, but our crawler hit a page
("http://clagnut.com/privacy/";) with an out of range character escape:

𔃷

in this text:

 If you provide a name, email address and/or website and choose ‘Remember 
 me𔃷, these details will be stored as a cookie on your computer.


The author clearly meant "’", which is a single close quote.

The traceback as BeautifulSoup aborts:

SGMLParser.feed(self, markup or "")
File "/usr/local/lib/python2.5/sgmllib.py", line 99, in feed
self.goahead(0)
File "/usr/local/lib/python2.5/sgmllib.py", line 181, in goahead
self.handle_charref(name)
File "/var/www/vhosts/sitetruth.com/cgi-bin/sitetruth/BeautifulSoup.py", line 
1250, in handle_charref

data = unichr(int(ref))
ValueError: unichr() arg not in range(0x1) (narrow Python build)

   Another item in our ongoing saga of "What happens when you parse real-world
HTML".

   A try-block in handle_charref would be appropriate.

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


Re: generate all possible math expr of one term

2008-05-14 Thread Lew

[EMAIL PROTECTED] wrote:

 —Xah Lee, 2005


Blah, blah, blah.  Plonk.

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

Recommended way to POST with cookies?

2008-05-14 Thread Gilles Ganault
Hello

According to Google, there seems to be several tools available,
possibly deprecated, to download data from web pages by POSTing forms
and save cookies to maintain state.

I need to write a script under Windows with ActivePython 2.5.1.1  that
would do this:
1. Connect through a local proxy, so I can see the whole dialog
between the Python script and the web server
2. POST form variables
3. Save cookies sent by the server (session cookie to keep state)
4. Save received data into an SQLite file

Which tools would you recommend for this type of script?

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


Re: Accepting text input

2008-05-14 Thread Kam-Hung Soh

On Thu, 15 May 2008 12:36:29 +1000, Collin <[EMAIL PROTECTED]> wrote:


Kam-Hung Soh wrote:

On Wed, 14 May 2008 11:02:36 +1000, Collin <[EMAIL PROTECTED]> wrote:


Gabriel Genellina wrote:
En Mon, 12 May 2008 01:54:28 -0300, Collin <[EMAIL PROTECTED]>  
escribió:



Collin wrote:
I'm pretty new to Python, but this has really bugged me. I can't  
find a

way around it.


The problem is that, when I use raw_input("sajfasjdf") whatever, or
input("dsjfadsjfa"), you can only have numerical values as answers.

Any help would be appreciated. Thanks.


Oh, wow. I feel so stupid. Please disregard this message. <_<

 No need to apologize...


I read the error message just now a bit more carefully, and I tried
something. I tried defining "yes" as some random numerical value.  
Then

when I did:
(example code)

yes = 123123983 #some number
test = input("Test test test ")
if test == yes:
print "It worked."
else:
print "failed"

(example code off)

 The usual way for Python<3.0 is:
 answer = raw_input("Test test test ").lower()
if answer == "yes":
 ...
 The input() function evaluates user input as an expression: if he  
types 2+5 the input() function returns the integer 7. I would never  
use input() in a program - it's way too unsafe; use always raw_input  
instead.




If I use it like that, do I have to import anything to have the  
.lower() work? And if I do, what does the .lower() signify?

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

 You don't need to import any module to use ".lower()"; it is a method  
of a string.  raw_input() returns a string, so you can use methods of a  
string.

 Try the following statement to see what happens:
"ABCDE".lower()



So the .lower() string method is just to convert the string to lowercase  
letters so that you don't have to type a bunch of if - then statements  
in both cases, I'm assuming?

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



That's right.  If you normalize your input to all lower case or upper  
case, you make it easier to process user input.


Regards,

--
Kam-Hung Soh http://kamhungsoh.com/blog";>Software Salariman

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


Re: Class Methods Vs Any Other Callable

2008-05-14 Thread Ivan Illarionov
On Wed, 14 May 2008 09:21:10 -0700, vbgunz wrote:
> [...] 
> when you see
> one, what is the first thing that comes to mind? When you write one,
> what was the first thing on your mind? Other than "similar to static-
> methods", at what point will you be glad you used one? To sum it up,
> what is the best role for a class-method that does not turn your work
> into code-soup?

The first thing on my mind when I see a classmethod is that I may need a 
metaclass here.

class A(object):
@classmethod
def do_something_with_aclass(cls):
pass

@classmethod
def do_something_diffferent_with_aclass(cls):
pass

def do_something(self):
pass

is similar to:

class M(type):
def do_something_with_aclass(cls):
pass

def do_something_diffferent_with_aclass(cls):
pass

class A:
__metaclass__ = M

def do_something(self):
pass

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


Re: Running an interactive interpreter inside a python

2008-05-14 Thread Alan J. Salmoni
I'm not sure if this is exactly what you're after, but try looking
into the 'code' module.

It's fairly easy to make an interactive interpreter that runs within
your program. If you import your programs variables into
__main__.__dict__, you can have access to them which can be funky. You
can even override the showtraceback method to catch various exceptions
and do daft things like adding new methods to strings. I guess it
would even be possible to have the commands compared to a list of
commands and keywords to build a restricted interpreter, though how
secure this would be against a determined attack is another matter.

Alan

On May 15, 11:31 am, [EMAIL PROTECTED] (R. Bernstein) wrote:
> The next release of pydb will have the ability to go into ipython from
> inside the debugger. Sort of like how in ruby-debug you can go into
> irb :-)
>
> For ipython, this can be done pretty simply; there is an IPShellEmbed
> method which returns something you can call. But how could one do the
> same for the stock python interactive shell?
>
> To take this out of the realm of debugging. What you want to do is to
> write a python program that goes into the python interactive shell -
> without having to write your own a read/eval loop and deal with
> readline, continuation lines, etc.
>
> The solution should also allow
>  - variables/methods in the calling PYthon program to be visible
>in the shell
>  - variables set in the interactive (sub) shell should persist after the shell
>terminates, although this is a weaker requirement. POSIX subshells
>for example *don't* work this way.
>
> There has been much written about how to embed Python from C, so I
> suppose this may offer one way. And at worst, I could write
> a C extension which follows how C Python does this for itself.
>
> But is there a simpler way?
>
> Thanks.

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


Re: What's a call-tip to do?

2008-05-14 Thread Terry Reedy

"Raymond Hettinger" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
On May 14, 8:24 am, Tal Einat <[EMAIL PROTECTED]> wrote:
> I just ran into this. In IDLE (Python 2.5), the call-tip for
> itertools.count is:
> "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"

| My IDLE (1.2.2 running on Python 2.5.2) has the correct call-tip.

As does my 3.0 version. count([first_val]) -> count object 



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


Re: [off-topic] Usenet

2008-05-14 Thread Terry Reedy

"John Salerno" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| On Wed, 14 May 2008 12:58:12 -0400
| "Terry Reedy" <[EMAIL PROTECTED]> wrote:
|
| > gmane.comp.python.general
| >
| > which is where I am answering this from.  Works great.
|
| So that's the same as c.l.p.?

It is the same as python-list, which happens to be the same as c.l.p..
Gmane mirrors technical mailing lists, including over 200 under g.c.python.



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


Re: More fun with PyParsing - almost did it on my own..

2008-05-14 Thread Paul McGuire
On May 14, 6:07 pm, rh0dium <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I almost did my first pyparsing without help but here we go again.
> Let's start with my code.  The sample data is listed below.
>
> 
>
> x =  cells.parseString(data)
> print x[0].asDict()
>
> reveals
> {'pins': ([(['A', 'Input'], {'direction': [('Input', 1)], 'name':
> [('A', 0)]}), (['B', 'Input'], {'direction': [('Input', 1)], 'name':
> [('B', 0)]}), (['Y', 'Output'], {'direction': [('Output', 1)], 'name':
> [('Y', 0)]}), (['VDD', 'Inout', 'Power'], {'direction': [('Inout',
> 1)], 'name': [('VDD', 0)], 'signal': [('Power', 2)]}), (['VSS',
> 'Inout', 'Ground'], {'direction': [('Inout', 1)], 'name': [('VSS',
> 0)], 'signal': [('Ground', 2)]})], {}), 'name': 'AND2X1', 'library':
> 'stdcell130'}
>
> As you can see the Pins is all jacked up and I want is not that.  I
> want the following
>
> { 'name': 'AND2X1',
>   'library':'stdcell130'
>   'pins': [ { 'name': 'VSS', 'direction':'Inout', 'signal':'Ground'},
>              { 'name': 'VDD', 'direction':'Inout', 'signal':'Power'},
>              { 'name': 'A', 'direction':'Input' },
>              { 'name': 'B', 'direction':'Input' },
>              { 'name': 'Y', 'direction':'Output' } ]
>
> }
>
> What did I do wrong in my code..
>

Not a thing!  asDict() is just not very good at dumping out lists of
subdicts.  Look at the output when you iterate over the cells in x,
and the pins in each cell:

for cell in x:
print "Name:", cell["name"]
print "Library:", cell["library"]
print "Pins:"
for pin in cell["pins"]:
print pin.asDict()
print

Prints:

Name: AND2X1
Library: stdcell130
Pins:
{'direction': 'Input', 'name': 'A'}
{'direction': 'Input', 'name': 'B'}
{'direction': 'Output', 'name': 'Y'}
{'direction': 'Inout', 'name': 'VDD', 'signal': 'Power'}
{'direction': 'Inout', 'name': 'VSS', 'signal': 'Ground'}

Name: AND2X2
Library: stdcell130
Pins:
{'direction': 'Input', 'name': 'A'}
{'direction': 'Input', 'name': 'B'}
{'direction': 'Output', 'name': 'Y'}
{'direction': 'Inout', 'name': 'VDD', 'signal': 'Power'}
{'direction': 'Inout', 'name': 'VSS', 'signal': 'Ground'}


Now, here is a real trick.  Each pin has a unique name, and the
collection of pins can be used to define a dict using the pin names as
dynamically-defined keys.  You've laid all the ground work, all that
is needed is to define your sequence of OneOrMore(guts) as a dict
using the guts names as keys.  The only change needed is to wrap this
OneOrMore(guts) in a pyparsing Dict class - that is, change:

OneOrMore(guts).setResultsName("pins")

to:

Dict(OneOrMore(guts)).setResultsName("pins")

Now, if you iterate over each cell, you can dump out its structure:

for cell in x:
print cell.dump()
print

Prints:

['stdcell130', 'AND2X1', [['A', 'Input'], ['B', 'Input'], ['Y',
'Output'], ['VDD', 'Inout', 'Power'], ['VSS', 'Inout', 'Ground']]]
- library: stdcell130
- name: AND2X1
- pins: [['A', 'Input'], ['B', 'Input'], ['Y', 'Output'], ['VDD',
'Inout', 'Power'], ['VSS', 'Inout', 'Ground']]
  - A: Input
  - B: Input
  - VDD: ['Inout', 'Power']
- direction: Inout
- name: VDD
- signal: Power
  - VSS: ['Inout', 'Ground']
- direction: Inout
- name: VSS
- signal: Ground
  - Y: Output

['stdcell130', 'AND2X2', [['A', 'Input'], ['B', 'Input'], ['Y',
'Output'], ['VDD', 'Inout', 'Power'], ['VSS', 'Inout', 'Ground']]]
- library: stdcell130
- name: AND2X2
- pins: [['A', 'Input'], ['B', 'Input'], ['Y', 'Output'], ['VDD',
'Inout', 'Power'], ['VSS', 'Inout', 'Ground']]
  - A: Input
  - B: Input
  - VDD: ['Inout', 'Power']
- direction: Inout
- name: VDD
- signal: Power
  - VSS: ['Inout', 'Ground']
- direction: Inout
- name: VSS
- signal: Ground
  - Y: Output

To flesh out all fields of all pins, I suggest you add a default value
for the optional signal entry, and set the results name on the
Optional wrapper, not the quoted string.  Change:

+
Optional(quotedString.setParseAction(removeQuotes).setResultsName("signal"))

to:

+
Optional(quotedString.setParseAction(removeQuotes),default="").setResultsName("signal")

Now dump() called on each cell prints out:

['stdcell130', 'AND2X1', [['A', 'Input', ''], ['B', 'Input', ''],
['Y', 'Output', ''], ['VDD', 'Inout', 'Power'], ['VSS', 'Inout',
'Ground']]]
- library: stdcell130
- name: AND2X1
- pins: [['A', 'Input', ''], ['B', 'Input', ''], ['Y', 'Output', ''],
['VDD', 'Inout', 'Power'], ['VSS', 'Inout', 'Ground']]
  - A: ['Input', '']
- direction: Input
- name: A
- signal:
  - B: ['Input', '']
- direction: Input
- name: B
- signal:
  - VDD: ['Inout', 'Power']
- direction: Inout
- name: VDD
- signal: Power
  - VSS: ['Inout', 'Ground']
- direction: Inout
- name: VSS
- signal: Ground
  - Y: ['Output', '']
- direction: Output
- name: Y
- signal:

Power
Input
['stdcell130', 'AND2X2', [['A', 'Input', ''], ['B', 'Input', ''],
['Y', 'Output', ''], ['VDD', 'Inout', 'Power'], ['VS

Running an interactive interpreter inside a python

2008-05-14 Thread R. Bernstein
The next release of pydb will have the ability to go into ipython from
inside the debugger. Sort of like how in ruby-debug you can go into
irb :-)

For ipython, this can be done pretty simply; there is an IPShellEmbed
method which returns something you can call. But how could one do the
same for the stock python interactive shell?

To take this out of the realm of debugging. What you want to do is to
write a python program that goes into the python interactive shell -
without having to write your own a read/eval loop and deal with
readline, continuation lines, etc.

The solution should also allow
 - variables/methods in the calling PYthon program to be visible
   in the shell
 - variables set in the interactive (sub) shell should persist after the shell 
   terminates, although this is a weaker requirement. POSIX subshells
   for example *don't* work this way.

There has been much written about how to embed Python from C, so I
suppose this may offer one way. And at worst, I could write
a C extension which follows how C Python does this for itself.

But is there a simpler way?

Thanks.



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


Re: Passing functions around and executing

2008-05-14 Thread alex23
On May 15, 10:53 am, PatrickMinnesota <[EMAIL PROTECTED]>
wrote:
> I have a bunch of functions.  I want to put them in a list.  Then I
> want to pass that list into another function which does some setup and
> then loops through the list of passed in functions and executes them.
> Some of them need arguments passed in too.

Hey Patrick,

Is something like the following helpful?

>>> def fn1(): print 'fn1'
>>> def fn2(): print 'fn2'
>>> fn_list = [fn1, fn2]
>>> def process(fn_seq):
... # do set up here
... for fn in fn_list:
... fn()

>>> process(fn_list)
fn1
fn2

The easiest way to extend this for optional argument passing would be
to have each function accept keyword arguments, and then to pass a
dictionary of arguments in to each:

>>> def fn1(**kwargs): print 'fn1'
>>> def fn2(**kwargs): print 'fn2: x=%(x)s' % kwargs
>>> fn_list = [fn1, fn2]
>>> def process(fn_seq):
... x = 'hello'
... for fn in fn_list:
... fn(**locals())

>>> process(fn_list)
fn1
fn2: x=hello

You could replace 'process' with a list comprehension:

>>> args = dict(x='hello again')
>>> results = [f(**args) for f in fn_list]
fn1
fn2: x=hello again

Or use 'map':

>>> process = lambda f: f(**args)
>>> results = map(process, fn_list)
fn1
fn2: x=hello again

Sorry, I'm a little bored.

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


Re: Accepting text input

2008-05-14 Thread John Salerno
On Thu, 15 May 2008 02:36:29 GMT
Collin <[EMAIL PROTECTED]> wrote:

> So the .lower() string method is just to convert the string to lowercase 
> letters so that you don't have to type a bunch of if - then statements 
> in both cases, I'm assuming?

You can also type:

dir(str)

to get a list of all the methods you can call on a string object. If you see 
anything interesting, then type:

help(str.) # e.g. help(str.split)

to find out how it works. :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-14 Thread John Salerno
On Tue, 13 May 2008 06:25:27 -0700 (PDT)
Dave Parker <[EMAIL PROTECTED]> wrote:

> > I'm pretty generally interested, but where can print layout take you?
> 
> Not far, especially with books disappearing.  Our library says that
> these days, only 25% of their checkouts are books; the other 75% are
> DVDs, CDs, etc.

Sorry, but I must point out a logical flaw in this statement. Assuming your 
stats are even true, just because books are now only 25% of checkouts rather 
than, for example, 80%, doesn't necessarily imply that any less books are being 
checked out (i.e. "disappearing"). It can just as easily mean that *more* of 
the other things are being checked out while books remain the same.

Example:

Total number of items checked out:100
Total number of books checked out: 80
Percentage of books checked out:   80%

Total number of items checked out:320
Total number of books checked out: 80   # same as above
Percentage of books checked out:   25%
--
http://mail.python.org/mailman/listinfo/python-list


Nasty gotcha/bug in heapq.nlargest/nsmallest

2008-05-14 Thread George Sakkis
I spent several hours debugging some bogus data results that turned
out to be caused by the fact that heapq.nlargest doesn't respect rich
comparisons:

import heapq
import random

class X(object):
def __init__(self, x): self.x=x
def __repr__(self): return 'X(%s)' % self.x
if True:
# this succeeds
def __cmp__(self, other): return cmp(self.x , other.x)
else:
# this fails
def __lt__(self, other): return self.x < other.x

s = [X(i) for i in range(10)]
random.shuffle(s)

s1 = heapq.nlargest(5, s)
s2 = sorted(s, reverse=True)[:5]
assert s1 == s2, (s,s1,s2)

s1 = heapq.nsmallest(5, s)
s2 = sorted(s)[:5]
assert s1 == s2, (s,s1,s2)


According to the docs, nlargest is equivalent to: "sorted(iterable,
key=key, reverse=True)[:n]" and similarly for nsmallest. So that must
be at least a documentation bug, if not an implementation one.

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


Re: Accepting text input

2008-05-14 Thread Collin

Kam-Hung Soh wrote:

On Wed, 14 May 2008 11:02:36 +1000, Collin <[EMAIL PROTECTED]> wrote:


Gabriel Genellina wrote:
En Mon, 12 May 2008 01:54:28 -0300, Collin <[EMAIL PROTECTED]> 
escribió:



Collin wrote:
I'm pretty new to Python, but this has really bugged me. I can't 
find a

way around it.


The problem is that, when I use raw_input("sajfasjdf") whatever, or
input("dsjfadsjfa"), you can only have numerical values as answers.

Any help would be appreciated. Thanks.


Oh, wow. I feel so stupid. Please disregard this message. <_<

 No need to apologize...


I read the error message just now a bit more carefully, and I tried
something. I tried defining "yes" as some random numerical value. Then
when I did:
(example code)

yes = 123123983 #some number
test = input("Test test test ")
if test == yes:
print "It worked."
else:
print "failed"

(example code off)

 The usual way for Python<3.0 is:
 answer = raw_input("Test test test ").lower()
if answer == "yes":
 ...
 The input() function evaluates user input as an expression: if he 
types 2+5 the input() function returns the integer 7. I would never 
use input() in a program - it's way too unsafe; use always raw_input 
instead.




If I use it like that, do I have to import anything to have the 
.lower() work? And if I do, what does the .lower() signify?

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



You don't need to import any module to use ".lower()"; it is a method of 
a string.  raw_input() returns a string, so you can use methods of a 
string.


Try the following statement to see what happens:
"ABCDE".lower()



So the .lower() string method is just to convert the string to lowercase 
letters so that you don't have to type a bunch of if - then statements 
in both cases, I'm assuming?

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


Re: Python and Flaming Thunder

2008-05-14 Thread John Salerno
On Tue, 13 May 2008 08:24:35 -0700 (PDT)
Dave Parker <[EMAIL PROTECTED]> wrote:

> I think that many people will find that Flaming Thunder is easier to
> use and understand than Python

I respectfully disagree.

> Plus, me getting paid to work on Flaming Thunder is far more
> motivating than me not getting paid to work on Python.

That's truly disappointing.

> This weekend,
> Python users will still be debating how to fix awkwardnesses in the
> languages (such as FOR loops where you're just counting the loops and
> not referencing the loop variable) -- but Flaming Thunder users will
> be getting work done using the REPEAT n TIMES constructs that I'll be
> implementing.

FT seems like all "awkwardnesses" to me.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [off-topic] Usenet

2008-05-14 Thread John Salerno
On Wed, 14 May 2008 12:58:12 -0400
"Terry Reedy" <[EMAIL PROTECTED]> wrote:

> 
> "Duncan Booth" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> | I also recommend Gmane which provides a free news server for most mailing
> | lists: mailing lists are a lot more manageable when gatewayed into a news
> | server. If you just want to access comp.lang.python I think you'll find 
> the
> | mailing list to which it is connected is available for free on Gmane.
> 
> gmane.comp.python.general
> 
> which is where I am answering this from.  Works great. 

So that's the same as c.l.p.?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-14 Thread John Salerno
On Mon, 12 May 2008 16:39:25 -0700 (PDT)
Dave Parker <[EMAIL PROTECTED]> wrote:

> I've read that one of the design goals of Python was to create an easy-
> to-use English-like language.  That's also one of the design goals of
> Flaming Thunder at http://www.flamingthunder.com/  , which has proven
> easy enough for even elementary school students, even though it is
> designed for scientists, mathematicians and engineers.

What an interesting and weird language! :) But I have a question concerning 
something like this, from the website:


Flaming Thunder uses set statements for assignment:

Set x to "concrete".

Flaming Thunder does not abbreviate or cojoin common English words. For 
example, go and to are separate words:

Read commmand.  If command = "quit" then go to end.
-

There doesn't seem to be any consistency here. Why say:

set x to "concrete"

and then say:

if command = "quit"

Why are you using the "set...to..." terminology instead of the "=" for 
assignments, but then in an if test statement, you *do* use the "="???

Would it be valid to say:

x = "concrete"

or to say:

if command (is) set to "quit"

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


Re: Using the indent method

2008-05-14 Thread Mark Tolonen


"dj" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Hello All,

I am using elementtree to write an XML document and I am having a hard
time adding the correct indentation.
I have tried using the indent method, but I can not figure out how to
use it. Any suggestions.


Using the version of indent() found on 
http://effbot.org/zone/element-lib.htm:



from xml.etree import ElementTree as ET
x='stuff'
e=ET.fromstring(x)
ET.dump(e)

stuff

indent(e)
ET.dump(e)


 
 
 stuff
 
   
 


-Mark 


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


Re: Usenet

2008-05-14 Thread Henrique Dante de Almeida
Em Wed, 14 May 2008 10:01:40 -0700, castironpi escreveu:

> On May 14, 11:58 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> 
> Love them opticals.

 Testing. :-P


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

create window on panel

2008-05-14 Thread Jimmy
Hi, all

I have been trying to use wxPython to design a GUI that will be
displayed on the panel on the top of desktop. that is when the
program starts, it will dwell on the panel to display some dynamic
information.

can anyone tell me in wxPython how to do this? thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Passing functions around and executing

2008-05-14 Thread Patrick Mullen
Here's a quick dumb example, hope it helps:

def function1(a,b,c):
   print a,b,c
def function2(x):
   print x
def function3(y):
   print y+3

def executeall(list):
   print "setting up"
   for function,args in list:
  function(*args)   #Calls the function passing in the arguments

mylist = [[function1,(1,2,3)],[function2,("green",)],[function3,(5.5,)]]
executeall(mylist)

-
The hard part is the fact that you mentioned some arguments need to be
passed in, some of the time.  This kind of situation makes the most sense if
all of the functions take the same arguments (or no arguments).  Then you
could just do this:

def function1():
   print 1
def function2():
   print 2
def function3():
   print 3

def executeall(list):
   print "setting up"
   for function in list:
  function()

mylist = [function1,function2,function3]
executeall(mylist)
--
So you see, treating functions as regular objects and passing them around,
is as easy as not putting the call operator (parenthesis) to the right of
the function name.

print function   #Prints the representation of the function object
print function()  #Calls the function and then prints what the function
returns

Hope it helps.
--
http://mail.python.org/mailman/listinfo/python-list

Passing functions around and executing

2008-05-14 Thread PatrickMinnesota
I've been reading the docs and looking for an answer and seem stuck.
I'm either not looking in the right places or not understanding what
I'm reading.

I have a bunch of functions.  I want to put them in a list.  Then I
want to pass that list into another function which does some setup and
then loops through the list of passed in functions and executes them.
Some of them need arguments passed in too.

Can someone point me to where to read about this?  I know it's do-able
since it's basically doing something like a callback would do.

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


Re: I'm stuck in Python!

2008-05-14 Thread castironpi
On May 14, 1:06 pm, [EMAIL PROTECTED] wrote:
> On May 14, 1:02 pm, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > On May 14, 12:51 pm, [EMAIL PROTECTED] wrote:
>
> > > On May 14, 5:25 am, [EMAIL PROTECTED] wrote:
>
> > > > On May 14, 4:32 am, [EMAIL PROTECTED] wrote:
>
> > > > > On May 13, 9:55 pm, alex23 <[EMAIL PROTECTED]> wrote:
>
> > > > > > On May 14, 5:41 am, "inhahe" <[EMAIL PROTECTED]> wrote:
>
> > > > > > > "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> > > > > > > > You must be new here. It is an AS (Artificial Stupidity) 
> > > > > > > > trolling bot,
> > > > > > > > you can safely ignore its posts.
>
> > > > > > > How does it generate text?
>
> > > > > > My guess is by inhaling a lot of intoxicants.
>
> > > > > However you know what would be helpful?  If I could go to the right
> > > > > place to start the ring.
>
> > > > I have a slightly sinister role on stage.  Does anyone want to play?
>
> > > I'd stay on mutability for the world domination factor.  Fluent
> > > currency is buoyant currency; turn on a local clock, and someone gets
> > > some cubic verticals.
>
> > > Now if sense-reference is trading on the BDFL, I'm still holdingTron
> > > can pretty well win work.- Hide quoted text -
>
> > > - Show quoted text -
>
> > I have a self-referential on Pygame: it's a Hand Tool object.
> > Currently, it decays over time.  You said 'flip' in the newsgroup, and
> > 'check', 'cross', and 'mate'.  Now who jumps who?- Hide quoted text -
>
> > - Show quoted text -
>
> If Python can plot in to chess, andTronrings live, then why not group?

I am taking a cautious tack on this one: I'm starting mouse first,
self.x+= sin( radians( self.degrees ) ).
--
http://mail.python.org/mailman/listinfo/python-list


How to subclass file

2008-05-14 Thread Yves Dorfsman
I want to create a subclass of 'file' but need to open the file with os.open
(because I want to open it in exclusive mode), and need an additional method.

Because I need an additional method, I truly need a object of my sublass.
If I do something like

class myFile(file):

  def __new__(cls, filename):
import os
fd = os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_EXCL)
 
return os.fdoen(fd, 'w')

  def myMethod(self):
do_something


then x = myFile('somefilename') is of type file, not myFile, and therefore
does not have myMethod as a valid method.

Now if I try:

class myFile(file):

  def __new__(cls, filename):
import os
fd = os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_EXCL)

obj = file.__new__(cls)
 
return obj

  def myMethod(self):
do_something

Then it fails, because the 'file' constructor needs a filename. I can provide
the filename, but it will then try to re-open that file, and even if I did
manage to create an object file, how do I connect the file descriptor created
by os.open to my object ?


Thanks.


Yves.
http://www.SollerS.ca

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


Re: What's a call-tip to do?

2008-05-14 Thread Raymond Hettinger
On May 14, 8:24 am, Tal Einat <[EMAIL PROTECTED]> wrote:
> I just ran into this. In IDLE (Python 2.5), the call-tip for
> itertools.count is:
> "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"

My IDLE (1.2.2 running on Python 2.5.2) has the correct call-tip. I
don't know why yours is different.  Also, help(itertools.count) does
the right thing.

Raymond


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


suggestions on code structuring? (classes; gui, data, methods...)

2008-05-14 Thread Vlastimil Brom
Hi all;
I'd like to ask for suggestions regarding the appropriate structure of the
code of my app. It is a gui program (wxPython; wx.aui) displaying several
texts simultaneously. The user interface consists of multiple text widgets
and control panels for selecting the text parts and synchronising.
Basically the program reads several text files, analyses them, displays them
in the text controls and keeps track of some aditional indexing information
(used for synchronising the text with each other etc.

What would be an usual way of structuring the code? I tried to separate
distinct tasks to classes, but I am not sure, if this is the right way:
Currently I have a TextDB class containing the functions to parse the source
text, then it stores the resulting fulltext, the indexing data; it also
contains lookup methods for the text properties and also a display method
(expecting a gui widget to write into). There is one instance of this class
associated with each text.
Further there is an instance of a gui class (subclassing the wx.Panel -
TextCtrl and some basic controls) for each text; besides this there are also
panels with specific settings/selections of the individual texts. All this
is managed in a frame using wx.aui.AuiManager (the panes can be moved or
hidden, but in general, there might be over a dozen of panels used
simultaneously on the screen).

Now, what would be a standard approach to let the single instances
comunicate with each other? Is it usual, that the "data" instances are
created by the gui instances (or the main program class)? Or would
it be better to create an extra "dispatch" class communicating with the
others? (Here e.g. the user can select some text-property in the control
panel, this value is then checked in the respective TextDB instance; finally
the matching text part is shown in the text widget.)
Unfortunately, I couldn't find many relevant code examples or general
informations; actualy many tutorial etc. gui programs often have ratner few
classes, sometimes the only one.

Any suggestions, or references to some examples, concepts ... are much
appreciated;
thanks in advance;
  Vlasta
--
http://mail.python.org/mailman/listinfo/python-list

Re: Using file objects with elementtree

2008-05-14 Thread castironpi
On May 14, 5:41 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> dj schrieb:
>
> > Hello,
>
> > Rather then holding my XML document in memory before writing it to
> > disk, I want to create a file object that elementtree will write each
> > element to has it is created. Does any one know how to do that ?
>
> > Here is my code so, far:
>
> > fd = open("page.xml", "w")
> > tree.write( fd, encoding="iso-8859-1")
>
> > I know there's something I am doing wrong, but I just do not know
> > what.
>
> This isn't possible. How should ET handle the case that you add a
> child-node to a node that has been rendered already?
>
> What you could try is to serialize subtrees that are closed to a stream.
>
> Diez

What do we render?
--
http://mail.python.org/mailman/listinfo/python-list


generate all possible math expr of one term

2008-05-14 Thread [EMAIL PROTECTED]
Here's a example of Expressiveness of a Language.

The following is Mathematica code that generates all possible
equations of one term involving trig function. (tweak the funList and
nesting level to define what “all possible” means. if nesting level is
2, it takes about 20 minutes and returns a list of 2876 terms on a
2004 personal computer.

<< DiscreteMath`Combinatorica`
funList = {Sin, Tan, Power[#, -1] &};
Nest[Module[{li = #},
 (Union[#, SameTest -> (Module[{arg1 = #1, arg2 = #2},
   If[(*both expression contains both x and y*)
 And @@ (StringMatchQ[#, "*x*"] &&
 StringMatchQ[#, "*y*"]) &)@
 [EMAIL PROTECTED]) &) /@ {arg1, arg2})
 , SameQ[arg1, arg2 /. {x -> y, y -> x}],
 SameQ[arg1, arg2]]
   ] &)] &)@
   [EMAIL PROTECTED]@(Table[(Times @@ # &) /@ KSubsets[#, i], {i, 1,
   2}] &)@[EMAIL PROTECTED], [EMAIL PROTECTED] &, funList, li]}
 ] &, {x, y}, 1];
Select[%, ([EMAIL PROTECTED], "*x*"] &&
 [EMAIL PROTECTED], "*y*"]) &]

The problem is this: generate a list of all possible math expressions
using the following combination and rules:

• the math expression involves both x and y. (must have both present)
• you can use any of the 6 trig functions (you must, since the goal is
to create all possibilities)
• The binary operations you can use are multiply, divide. (no addition
or substraction, since that can make the result 2 terms)
• a sub-expression (such as x or y) can be replaced by a more
complicated one. (i.e. you can nest)

For example, these are first few items from the above code:

{1/(x^2*y^2), 1/(x*y^2), x/y^2, 1/(x*y), x/y, x^2/y, x*y, x^2*y,
x^2*y^2, Cos[x]/y^2, Cos[x]/y, Cos[x]/(x*y), (x*Cos[x])/y, y*Cos[x],
(y*Cos[x])/x, x*y*Cos[x], y^2*Cos[x], Cos[x]*Cos[y], Cot[x]/y^2,
Cot[x]/(x*y^2)}

For a gallery of selection plots of these equations, see
 http://xahlee.org/MathGraphicsGallery_dir/dense/dense1.html

The above i wrote in 2002. If there are requests, i'll translate the
above code into emacs lisp. The result lisp expression should match
Mathematica's, token for token. (the code make a lot use of nested
lambda and or apply and or map) If you are interested, you could
translate the above into lisp too, it's not difficult (though the
number of lines will increase maybe 10 fold. And if Common Lisp
doesn't have combinatorics library providing KSubsets, and also since
CL doesn't have Outer, so the above in CL might be few hundred lines).
(see here for a example of how to: 
http://xahlee.org/UnixResource_dir/writ/notations.html
)

PS as a after-thought, i decided to post this to perl, python, and
java too. This will take about the same number of lines in perl as in
Common Lisp. Probably llightly more in Python due to syntax. In Java,
it will be one million lines.

Gratuitous poem of the day:

in the climb to geekdom,
you have few rungs to catch,
before you see my ass.

 —Xah Lee, 2005

  Xah
  [EMAIL PROTECTED]
∑ http://xahlee.org/

☄

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

Re: I'm stuck in Python!

2008-05-14 Thread castironpi
On May 14, 6:28 pm, [EMAIL PROTECTED] wrote:
> On May 14, 1:22 pm, "Dan Upton" <[EMAIL PROTECTED]> wrote:
>
> > On Tue, May 13, 2008 at 10:55 PM, alex23 <[EMAIL PROTECTED]> wrote:
> > > On May 14, 5:41 am, "inhahe" <[EMAIL PROTECTED]> wrote:
> > >> "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> > >> > You must be new here. It is an AS (Artificial Stupidity) trolling bot,
> > >> > you can safely ignore its posts.
>
> > >> How does it generate text?
>
> > > My guess is by inhaling a lot of intoxicants.
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
>
> > I assumed his message with the subject "bytes1.shuffle()" from a few
> > days ago was a glimpse into his source code.  Or something like it.
>
> I am trying to select a color.  It's color select.py.  Any thoughts?

I was trying to select a font.  It was font select.py.  Why did I say
color?
--
http://mail.python.org/mailman/listinfo/python-list


Re: named tuple mutability

2008-05-14 Thread castironpi
On May 14, 6:21 pm, [EMAIL PROTECTED] wrote:
> On May 14, 12:41 pm, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
>
> > > Should tuples be named?
>
> > Yes.
>
> Good; they're named sequences.

Can anyone make sling-shots of words?  What's the splatter?
--
http://mail.python.org/mailman/listinfo/python-list


Re: I'm stuck in Python!

2008-05-14 Thread castironpi
On May 14, 1:22 pm, "Dan Upton" <[EMAIL PROTECTED]> wrote:
> On Tue, May 13, 2008 at 10:55 PM, alex23 <[EMAIL PROTECTED]> wrote:
> > On May 14, 5:41 am, "inhahe" <[EMAIL PROTECTED]> wrote:
> >> "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> >> > You must be new here. It is an AS (Artificial Stupidity) trolling bot,
> >> > you can safely ignore its posts.
>
> >> How does it generate text?
>
> > My guess is by inhaling a lot of intoxicants.
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> I assumed his message with the subject "bytes1.shuffle()" from a few
> days ago was a glimpse into his source code.  Or something like it.

I am trying to select a color.  It's color select.py.  Any thoughts?
--
http://mail.python.org/mailman/listinfo/python-list


Re: named tuple mutability

2008-05-14 Thread castironpi
On May 14, 12:41 pm, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> > Should tuples be named?
>
> Yes.

Good; they're named sequences.
--
http://mail.python.org/mailman/listinfo/python-list


Re: named tuple mutability

2008-05-14 Thread castironpi
On May 14, 5:28 pm, [EMAIL PROTECTED] wrote:
> On May 14, 5:01 pm, Ben Finney <[EMAIL PROTECTED]>
> wrote:
>
> > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> > > On 14 mai, 18:20, [EMAIL PROTECTED] wrote:
> > > > I'm concerned over the future of Python.  Should tuples be named?
>
> > > Obviously not, unless they should.
>
> > Clearly they should, unless not.
>
> > Ben Finney
>
> I have plenty of uses for them!

FOR INSTANCE!

def zoop_zoop_zoop( self ): pass
--
http://mail.python.org/mailman/listinfo/python-list


More fun with PyParsing - almost did it on my own..

2008-05-14 Thread rh0dium
Hi all,

I almost did my first pyparsing without help but here we go again.
Let's start with my code.  The sample data is listed below.

# This will gather the following ( "NamedPin" "PinDirection"
"OptionalSignal" )
guts = Group( LPAR.suppress() +
quotedString.setParseAction(removeQuotes).setResultsName("name") +
quotedString.setParseAction(removeQuotes).setResultsName("direction")
+
Optional(quotedString.setParseAction(removeQuotes).setResultsName("signal"))
+ RPAR.suppress())

# This will simply wrap the Cell Info around it
cell = Group( Literal("dbSetCellPortTypes").suppress() +
quotedString.setParseAction(removeQuotes).setResultsName("library") +
quotedString.setParseAction(removeQuotes).setResultsName("name") +
Literal("'").suppress() +  LPAR.suppress() +
OneOrMore(guts).setResultsName("pins") + RPAR.suppress() ) +
Literal("#f").suppress() | Literal("#t").suppress()

# This grabs many cells
cells = OneOrMore(cell)

OK and it sorta works if I do the following:

x =  cells.parseString(data)
print x[0].asDict()

reveals
{'pins': ([(['A', 'Input'], {'direction': [('Input', 1)], 'name':
[('A', 0)]}), (['B', 'Input'], {'direction': [('Input', 1)], 'name':
[('B', 0)]}), (['Y', 'Output'], {'direction': [('Output', 1)], 'name':
[('Y', 0)]}), (['VDD', 'Inout', 'Power'], {'direction': [('Inout',
1)], 'name': [('VDD', 0)], 'signal': [('Power', 2)]}), (['VSS',
'Inout', 'Ground'], {'direction': [('Inout', 1)], 'name': [('VSS',
0)], 'signal': [('Ground', 2)]})], {}), 'name': 'AND2X1', 'library':
'stdcell130'}

As you can see the Pins is all jacked up and I want is not that.  I
want the following

{ 'name': 'AND2X1',
  'library':'stdcell130'
  'pins': [ { 'name': 'VSS', 'direction':'Inout', 'signal':'Ground'},
 { 'name': 'VDD', 'direction':'Inout', 'signal':'Power'},
 { 'name': 'A', 'direction':'Input' },
 { 'name': 'B', 'direction':'Input' },
 { 'name': 'Y', 'direction':'Output' } ]
}

What did I do wrong in my code..

Thanks again!

   ]




I would expect my results to look like this:

But to get any info I must do this

print x[0].asDict()

which is not really what  want.
What I expect is this:
[


data = """dbSetCellPortTypes "stdcell130" "AND2X1" '(
  ("A" "Input" )
  ("B" "Input" )
  ("Y" "Output" )
  ("VDD" "Inout" "Power" )
  ("VSS" "Inout" "Ground" )
) #f
dbSetCellPortTypes "stdcell130" "AND2X2" '(
  ("A" "Input" )
  ("B" "Input" )
  ("Y" "Output" )
  ("VDD" "Inout" "Power" )
  ("VSS" "Inout" "Ground" )
) #f """
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-14 Thread MRAB
On May 14, 10:30 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> > Dave Parker schrieb:
> > > All of the calculators and textbooks that elementary school students
> > > use, use "^" for powers.
>
> I've never seen this symbol in textbooks. In textbooks, powers are
> written using superscript.
>
> >>  Just like Flaming Thunder does.  I haven't
> > > seen "**" for powers since FORTRAN.
>
> I haven't seen any language using '^' as the power operator so far -
> but I've seen quite a lot of them using it as the bitwise XOR operator.

BASIC and Comal use '^' as the power operator.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using file objects with elementtree

2008-05-14 Thread Diez B. Roggisch

dj schrieb:

Hello,

Rather then holding my XML document in memory before writing it to
disk, I want to create a file object that elementtree will write each
element to has it is created. Does any one know how to do that ?

Here is my code so, far:

fd = open("page.xml", "w")
tree.write( fd, encoding="iso-8859-1")

I know there's something I am doing wrong, but I just do not know
what.


This isn't possible. How should ET handle the case that you add a 
child-node to a node that has been rendered already?


What you could try is to serialize subtrees that are closed to a stream.


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


Re: Using file objects with elementtree

2008-05-14 Thread castironpi
On May 14, 3:09 pm, dj <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Rather then holding my XML document in memory before writing it to
> disk, I want to create a file object that elementtree will write each
> element to has it is created. Does any one know how to do that ?
>
> Here is my code so, far:
>
> fd = open("page.xml", "w")
> tree.write( fd, encoding="iso-8859-1")
>
> I know there's something I am doing wrong, but I just do not know
> what.

Sure.  Relational databases are more widely useful.  They're the
binary hold-on-disk for you-- a big XML file.
--
http://mail.python.org/mailman/listinfo/python-list


Re: named tuple mutability

2008-05-14 Thread castironpi
On May 14, 5:01 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> > On 14 mai, 18:20, [EMAIL PROTECTED] wrote:
> > > I'm concerned over the future of Python.  Should tuples be named?
>
> > Obviously not, unless they should.
>
> Clearly they should, unless not.
>
> Ben Finney

I have plenty of uses for them!
--
http://mail.python.org/mailman/listinfo/python-list


Re: named tuple mutability

2008-05-14 Thread Ben Finney
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:

> On 14 mai, 18:20, [EMAIL PROTECTED] wrote:
> > I'm concerned over the future of Python.  Should tuples be named?
> 
> Obviously not, unless they should.

Clearly they should, unless not.

-- 
 \   “It is seldom that liberty of any kind is lost all at |
  `\once.” —David Hume |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: What's a call-tip to do?

2008-05-14 Thread Terry Reedy

"Tal Einat" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Hi all,
|
| I just ran into this. In IDLE (Python 2.5), the call-tip for
| itertools.count is:
| "x.__init__(...) initializes x; see x.__class__.__doc__ for signature"
|
| That's itertools.count.__init__.__doc__, while itertools.count.__doc__
| is the informative doc-string ("DS" henceforth):
| """count([firstval]) --> count object
|
| Return a count object whose .next() method returns consecutive
| integers starting from zero or, if specified, from firstval."""
|
|
| That seems very counter-intuitive to me - I would expect the DS for
| __init__ to explain how to use the constructor.
|
| IDLE's call-tip module obviously thinks so as it prefers the __init__
| DS to the class's DS. IPython does the opposite as far as I can tell,
| when I enter 'itertools.count?' it shows the class's DS, but shows
| nothing for a custom class whose __init__ has a DS while the class
| itself does not.
|
| I'm wondering what a call-tip mechanism should do when a class and its
| __init__ both have a DS. I'd be willing to work up a patch for IDLE's
| call-tip module to work better in this regard, or for itertools and
| similar classes in the stdlib, if needed.

Perhap IDLE should be changed, but I am not sure.  After more discussion 
here, if any, this would be worth a tracker item. 



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


Re: Class Methods Vs Any Other Callable

2008-05-14 Thread [EMAIL PROTECTED]
On 14 mai, 22:44, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> > On 14 mai, 19:45, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> >> __new__ is a static method!
>
> > __new__ is a special-cased staticmethod that  1/ must not be declared
> > as such and 2/ takes the class object as first args. As far as I'm
> > concerned, it's semantically a classmethod.
>
> It's a static method!

Sorry Arnaud, I probably didn't made it clear enough : I do know it is
a staticmethod object. What I say is that
1/ it's special-cased since you don't *explicitely* declare it as a
staticmethod
2/ it behaves just like a classmethod, since it takes the class as
first argument.

IOW, I'm talking about semantic, not implementation.

> --
> Arnaud

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


Re: Class Methods Vs Any Other Callable

2008-05-14 Thread Carl Banks
On May 14, 12:21 pm, vbgunz <[EMAIL PROTECTED]> wrote:
> Other than the 2 reasons above (2 making more sense), what is a really
> good reason to pull out the class method. In other words, when you see
> one, what is the first thing that comes to mind? When you write one,
> what was the first thing on your mind? Other than "similar to static-
> methods", at what point will you be glad you used one? To sum it up,
> what is the best role for a class-method that does not turn your work
> into code-soup?


When classmethods are inherited, they are called with the class it was
invoked with, rather than the class they were defined in.  Try this
example:


class A(object):
@classmethod
def classname(cls):
print cls.__name__

@staticmethod
def staticname():
print "A"

class B(A):
pass

B.staticname()
B.classname()


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


Re: Python and Flaming Thunder

2008-05-14 Thread [EMAIL PROTECTED]
On 13 mai, 18:36, Dave Parker <[EMAIL PROTECTED]> wrote:
(snip)

> Also, in Python how do you assign a symbolic equation to a variable?
> Like this?
>
> QuadraticEquation = a*x^2 + b*x + c = 0

quadratic_equation = lambda x, b, c : a*(x**2) + b*x + c == 0

or if x, b and c are supposed to be captured from the current
namespace:

quadratic_equation = lambda : a*(x**2) + b*x + c == 0

> Set statements avoid the confusion of multiple equal signs when
> manipulating symbolic equations:

using '=' for assignement and '==' for equality test does the same
thing. And it's a very common pattern in programming languages.

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


Re: sys.excepthack...

2008-05-14 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>,
 Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:

> On Wed, 14 May 2008 15:47:18 -0500, "David C. Ullrich" <[EMAIL PROTECTED]> 
> wrote:
> > [snip]
> >
> >Came up with a ridiculous hack involving both sys.stderr
> >and sys.excepthook. Works exactly the way I want.
> >Seems ridiculous - what's the right way to do this?
> >
> > [snip]
> 
> Hi David,
> 
> Take a look at the traceback module.  The excepthook gets called with
> an exception type, instance, and traceback object.  The traceback module
> is good at turning these things into strings.

Thanks.

> Jean-Paul

-- 
David C. Ullrich
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-14 Thread [EMAIL PROTECTED]
> Dave Parker schrieb:

> > All of the calculators and textbooks that elementary school students
> > use, use "^" for powers.

I've never seen this symbol in textbooks. In textbooks, powers are
written using superscript.

>>  Just like Flaming Thunder does.  I haven't
> > seen "**" for powers since FORTRAN.

I haven't seen any language using '^' as the power operator so far -
but I've seen quite a lot of them using it as the bitwise XOR operator.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-14 Thread [EMAIL PROTECTED]
On 13 mai, 19:05, Dave Parker <[EMAIL PROTECTED]> wrote:
> > Just to support this statement: PHP runs an order of magnitude slower than
> > python. Yet a great deal (if not the majority) of dynamic sites out there
> > run under PHP. All of these are unhappy customers?
>
> The websites owners might not be unhappy, but lots of customers
> complain about slow websites, so if the market is competitive then
> eventually the PHP fad will die out.
>
Some of the slower websites I've seen where using Java - which is
supposedly way faster than Python. And even a static (pure HTML) web
site can become more than painfully slow if the server can't handle
the load, as anyone working in the field could tell you. But this is
obviously one more area where you are just totally clueless.

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


"indexed properties"...

2008-05-14 Thread David C. Ullrich
Having a hard time phrasing this in the form
of a question...

The other day I saw a thread where someone asked
about overrideable properties and nobody offered
the advice that properties are Bad. So maybe we've
got over that. I suppose properties could have 
Bad consequences if a user doesn't know they exist
and think that a certain property of an object is
just an ordinary attribute. But that applies to
almost any aspect of any language.

If a person comes from, say, Object Pascal (Delphi)
then properties are hard to live without. The
other day I decided I wanted what OP calls an
"indexed property" or "array property". Couldn't 
figure out how to make a _property_ behave that way.
So I read a little bit about descriptors, and a
few minutes later I had an indexedproperty thing
that works just like property, except it gives
an indexed property! This is just too cool.

Why? For example, a Matrix should have a row[n]
property allowing things like

m.row[0] = m.row[1] + m.row[2]

Ok, you could do _that_ by just making row
an ordinary list of Row objects. But then
you'd have to say

m.row[0] = Row([1,2,3])

where I want to be able to say

m.row[0] = [1,2,3]

and have the Row created automatically.

_Also_ with these indexed properties my Matrix
can have m.row[j] and m.col[k] that look exactly
the same to a client - we don't want to store a
list of rows internally and also store the same
data in a list of columns. Too cool.

Hmm, none of that's a valid excuse for a post here.
Um, right, here we go: Anyone see problems or
possible improvements with the implementation
of indexedproperty below?

"""indexed.py: "indexedproperty" works more or less
like "property" except it gives what in Object Pascal
would be an "indexed property". See the 
__name__="__main__" section below for a demo

"""

class WriteOnlyIP(Exception):
  def __str__(self): 
return """

indexed property is write-only

"""

class ReadOnlyIP(Exception):
  def __str__(self):
return """

indexed property is read-only

"""

class indexedproperty(object):
  def __init__(self, getitem=None, setitem=None):
self.getitem = getitem
self.setitem = setitem

  def __get__(self, obj, owner):
self.obj = obj
return self

  def __getitem__(self, index):
if self.getitem:
  return self.getitem(self.obj, index)
else:
  raise WriteOnlyIP

  def __setitem__(self, index, value):
if self.setitem:
  self.setitem(self.obj, index, value)
else:
  raise ReadOnlyIP


if __name__ == "__main__":

  class AClass(object):
def __init__(self):
  self.cells = [[0,0], [0,0]]

def SetCell(self, (row, col), value):
  self.cells[row][col] = value

def GetCell(self, (row, col)):
  return self.cells[row][col]

cell = indexedproperty(GetCell, SetCell)

  C = AClass()
  for row in range(2):
for col in range(2):
  C.cell[row, col] = "row: %s, col: %s" % (row, col)

  for row in range(2):
for col in range(2):
  print C.cell[row, col]

  C.cell[0,0], C.cell[1,1] = C.cell[1,1], C.cell[0,0]

  print "After  C.cell[0,0], C.cell[1,1] = C.cell[1,1], C.cell[0,0]:"

  for row in range(2):
for col in range(2):
  print C.cell[row, col]

-- 
David C. Ullrich
--
http://mail.python.org/mailman/listinfo/python-list


Re: sys.excepthack...

2008-05-14 Thread Jean-Paul Calderone

On Wed, 14 May 2008 15:47:18 -0500, "David C. Ullrich" <[EMAIL PROTECTED]> 
wrote:

[snip]

Came up with a ridiculous hack involving both sys.stderr
and sys.excepthook. Works exactly the way I want.
Seems ridiculous - what's the right way to do this?

[snip]


Hi David,

Take a look at the traceback module.  The excepthook gets called with
an exception type, instance, and traceback object.  The traceback module
is good at turning these things into strings.

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


Re: Python and Flaming Thunder

2008-05-14 Thread [EMAIL PROTECTED]
On 14 mai, 08:08, Lie <[EMAIL PROTECTED]> wrote:
> On May 14, 12:51 pm, Lie <[EMAIL PROTECTED]> wrote:
>
> > And your 8 by 8 cross compiler doesn't impress me at all, they're all
> > based on x86/IA-32 architecture which is quite similar, no PowerPC,
> > SPARC, ARM, no other CISC or RISC architecture. And your compiler is a
> > single language compiler instead of three dimensional compiler that
> > GCC is (cross platform, cross target platform, cross language).
>
> And to add, I also need to mention that Python doesn't need to be
> compiled at all,

No language needs compilation - it's an implementation problem, not a
language problem. Now all the Python's implementations I know do use
compilation (to byte-code).

> its py and pyo file is architecture independent.

True, but this is not strictly related to being compiled or not.


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


Re: HASH TABLES IN PYTHON

2008-05-14 Thread [EMAIL PROTECTED]
On 14 mai, 18:23, "Eduardo O. Padoan" <[EMAIL PROTECTED]>
wrote:
> On Wed, May 14, 2008 at 12:20 PM, Blubaugh, David A.
>
> <[EMAIL PROTECTED]> wrote:
> > To Whom It May Concern,
>
> > I was wondering if anyone has ever worked with hash tables within the Python
> > Programming language?

I wonder if anyone could do anything in Python *without* using hash
tables. 
--
http://mail.python.org/mailman/listinfo/python-list


sys.excepthack...

2008-05-14 Thread David C. Ullrich
Becoming a fan of wxPython, but I can't stand
what it does with error messsages (I can't find
a way to dismiss that window with the error message
from the keyboard. Seems to be anti-modal - the
key strokes that normally kill the active window
kill the main window (sitting behind the window
with the error message) instead. If the window
only had an OK button...)

So I want to pop up a modal dialog on error.

Tried setting sys.stderr to an object with a
write method that pops up a dialog. The problem
with that is write() gets called several times
per exception - I don't see how to get my new
sys.stderr object to figure out when it's time
to show the message.

So then I found sys.excepthook. The problem with
that was that I was too stoopid to figure out how
to get a readable error message from the parameters
passed to excepthook.

Came up with a ridiculous hack involving both sys.stderr
and sys.excepthook. Works exactly the way I want.
Seems ridiculous - what's the right way to do this?

Ridiculous_hack.py:

import sys
import wx

def hook(*args):
  try:
sys.__excepthook__(*args)
  finally:
printer.Show()

class ErrorDisplay:
  def __init__(self):
self.buffer = ''
  def write(self, text):
self.buffer = self.buffer + text

  def Show(self): 
  wx.MessageDialog(None, str(self.buffer), 
  'Error:',wx.OK).ShowModal()
  self.buffer = ''

printer = ErrorDisplay()
sys.stderr = printer
sys.excepthook = hook

-- 
David C. Ullrich
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-14 Thread J. Cliff Dyer
On Wed, 2008-05-14 at 13:27 -0700, [EMAIL PROTECTED] wrote:
> On 14 mai, 00:41, John Machin <[EMAIL PROTECTED]> wrote:
> (snip)
> > IIRC the idea was so that managers could write programs in English. It
> > failed because nobody could write a parser that would handle something
> > like "The bottom line is that the stakeholder group requires the
> > situation going forward to be such as to facilitate the variable known
> > as x to provide the same outcome when stimulated by dereferencing as the
> > variable known as y".
> 
> John, I usually don't agree much with both what you say and how you
> say it, but I must admit that this one is, well... just brillant !-)
> 
> (IOW: rofl, keyboard, and +1 QOTW)
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

Agreed.  Best.  Synonym.  EVAR.  

(I won't give away the fun by saying what it's a synonym for)

Cheers,
Cliff


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


Re: Class Methods Vs Any Other Callable

2008-05-14 Thread Arnaud Delobelle
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:

> On 14 mai, 19:45, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>> __new__ is a static method!
>
> __new__ is a special-cased staticmethod that  1/ must not be declared
> as such and 2/ takes the class object as first args. As far as I'm
> concerned, it's semantically a classmethod.

It's a static method!

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


Re: Class Methods Vs Any Other Callable

2008-05-14 Thread [EMAIL PROTECTED]
On 14 mai, 16:30, George Sakkis <[EMAIL PROTECTED]> wrote:
> On May 14, 10:19 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> > > An instance method works on the instance
> > > A Static method is basically a function nested within a class object
> > > A class method is overkill?
>
> > If anything, a static method is overkill. See it this way: *if* you for some
> > reason put a method into an enclosing context - isn't it worth having a
> > reference to that?
>
> My feeling exactly; these days I almost always use class methods
> instead of static. I vaguely remember seeing somewhere an example
> where a static method was the only (elegant) solution; neither a class
> method nor a plain function would do. I'll post it if I find it unless
> someone beats me to it.

No concrete example here but I surely remember having used
staticmethods in one case where I needed class-based polymorphic
dispatch and eventually implementation inheritance (to get a default
implementation)  for something that didn't required access to the
class object.



> George

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


Re: wxpython dialog - do something after ShowModal()?

2008-05-14 Thread David C. Ullrich
In article 
<[EMAIL PROTECTED]>,
 Iain King <[EMAIL PROTECTED]> wrote:

> Hi.  I have a modal dialog whcih has a "Browse..." button which pops
> up a file selector.  This all works fine, but the first thing the user
> has to do when they open the dialog is select a file, so I would like
> the dialog to automatically call the onBrowse function as soon as the
> dialog opens.  However, I don't know how to do this.
> 
> dlg.ShowModal()
> onBrowse()
> 
> obviously doesn't work, and neither does the reverse.  I was hoping
> that the dialog would throw some kind of "I have been shown" event,
> but it doesn't (as far as I can tell).  How do I make the dialog do
> something as soon as it's been shown?

It's too bad that you found an answer. You _shouldn't_ have your
dialog pop up a file-selection box as soon as it's shown! That's
not the way dialogs usually work, so you're going to confuse
people.

Instead, first pop up the file-selection box, and then pop up
the dialog (without the Browse button) to do whatever else it
does after you've got the filename.

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


Re: Class Methods Vs Any Other Callable

2008-05-14 Thread [EMAIL PROTECTED]
On 14 mai, 19:45, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> George Sakkis <[EMAIL PROTECTED]> writes:
> > On May 14, 10:19 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> >> > An instance method works on the instance
> >> > A Static method is basically a function nested within a class object
> >> > A class method is overkill?
>
> >> If anything, a static method is overkill. See it this way: *if* you for 
> >> some
> >> reason put a method into an enclosing context - isn't it worth having a
> >> reference to that?
>
> > My feeling exactly; these days I almost always use class methods
> > instead of static. I vaguely remember seeing somewhere an example
> > where a static method was the only (elegant) solution; neither a class
> > method nor a plain function would do. I'll post it if I find it unless
> > someone beats me to it.
>
> > George
>
> __new__ is a static method!

__new__ is a special-cased staticmethod that  1/ must not be declared
as such and 2/ takes the class object as first args. As far as I'm
concerned, it's semantically a classmethod.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Submitting data to HTTPS javascript

2008-05-14 Thread Laszlo Nagy

John Chandler wrote:
I am trying to write a script to test certain functionality of a 
website that requires users to login. The login page is simple, a few 
pictures and two text bars (one for username and one for password). I 
tried logging in with webbrowser, but that did not work because the 
page uses javascript. I also tried using win32com though I have no 
idea what I am doing. Any ideas?

- Use firefox :-)
- Install "LiveHTTPHeaders" http://livehttpheaders.mozdev.org/
- Open the plugin in one window and the website in another
- Enable "capture" in livehttpheaders (default)
- Login to the website
- Disable "capture" in livehttpheaders (default)
- Check the GET and POST requests in the capture log
- Try to send the same GET and POST requests from Python.
- Don't forget that most sites will also need cookies - you have to 
extract and send back cookies as needed


You do not need any GUI component for this job.

Other good things to have:

- Good knowledge of the "re" standard module, and regular expression syntax
- BeautifulSoup (especially ICanBelieveItIsBeautifulSoup...)

You might also check the "mechanoid" project. (I have never used it but 
it is said to be an automatized, controllable web browser???)


If anyone is interested, I can put up a python recipe that shows how to 
emulate a browser easily.


Best,

   Laszlo

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


Re: named tuple mutability

2008-05-14 Thread [EMAIL PROTECTED]
On 14 mai, 18:20, [EMAIL PROTECTED] wrote:
> I'm concerned over the future of Python.  Should tuples be named?

Obviously not, unless they should.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-14 Thread [EMAIL PROTECTED]
On 14 mai, 00:41, John Machin <[EMAIL PROTECTED]> wrote:
(snip)
> IIRC the idea was so that managers could write programs in English. It
> failed because nobody could write a parser that would handle something
> like "The bottom line is that the stakeholder group requires the
> situation going forward to be such as to facilitate the variable known
> as x to provide the same outcome when stimulated by dereferencing as the
> variable known as y".

John, I usually don't agree much with both what you say and how you
say it, but I must admit that this one is, well... just brillant !-)

(IOW: rofl, keyboard, and +1 QOTW)
--
http://mail.python.org/mailman/listinfo/python-list


enumerate() values starting at 1 vs. 0

2008-05-14 Thread python
Arnaud,

>> Is there any way to have enumerate() start at 1 vs. 0?
>>
>> The problem with starting at 0 is that many things in the real world
>> begin at 1 - like line numbers or labels in a list.

> I suppose you could redefine enumerate to support an optional argument:
> 
> from itertools import izip, count
> 
> def enumerate(iterable, start=0):
>  return izip(count(start), iterable)
> 
>  >>> list(enumerate('spam', 1))
> [(1, 's'), (2, 'p'), (3, 'a'), (4, 'm')]

Brilliant!! 

Thank you,
Malcolm
--
http://mail.python.org/mailman/listinfo/python-list


Using file objects with elementtree

2008-05-14 Thread dj
Hello,

Rather then holding my XML document in memory before writing it to
disk, I want to create a file object that elementtree will write each
element to has it is created. Does any one know how to do that ?

Here is my code so, far:

fd = open("page.xml", "w")
tree.write( fd, encoding="iso-8859-1")

I know there's something I am doing wrong, but I just do not know
what.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-14 Thread Luis Zarrabeitia
On Tuesday 13 May 2008 01:05:38 pm Dave Parker wrote:
> The websites owners might not be unhappy, but lots of customers
> complain about slow websites, so if the market is competitive then
> eventually the PHP fad will die out.

On my [modest] experience, bandwidth trumps code speed by a large fraction. My 
experience is tainted, though, with me living in Cuba and Cuba having almost 
no bandwidth available.

> For example, Slashdot recently interviewed a successful website in a
> competitive market -- online newspapers -- and found that to enhance
> customer happiness the New York Times uses hand-coded HTML.
>
> "He was asked how the Web site looks so consistently nice and polished
> no matter which browser or resolution is used to access it. His answer
> begins: 'It's our preference to use a text editor, like HomeSite,
> TextPad or TextMate, to "hand code" everything, rather than to use a
> wysiwyg (what you see is what you get) HTML and CSS authoring program,
> like Dreamweaver. We just find it yields better and faster results.'"

So, they edit the HTML code by hand. The interview explicitly mentions the 
features "consistently nice and polished", not "faster to compute". You can 
always throw more hardware when the problem is about speed. The real edge on 
your competitive marked should be the "consistently nice and polished", and 
neither python, nor [I hope] Flaming Thunder is going to help you with that.

> "Faster" wins in a competitive market, so if a programming language
> can't deliver "faster", it is a fad that will die out.

I find it more likely that the users are more concerned about how quickly the 
latest tidbit reaches your frontpage than with the extra few milisenconds 
achieved by switching the programming language or throwing another server in 
the cluster.


-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
--
http://mail.python.org/mailman/listinfo/python-list


Re: named tuple mutability

2008-05-14 Thread castironpi
On May 14, 1:04 pm, [EMAIL PROTECTED] wrote:
> On May 14, 12:41 pm, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
>
> > > Should tuples be named?
>
> > Yes.
>
> Not clearly should.  Sequences ought be.  If you're on the right time
> for both, can't the library hold the B?

On the web, you can.  Both data types can go in the docs... sorry for
the lunacy, I'm hacking.
--
http://mail.python.org/mailman/listinfo/python-list


Re: list.__len__() or len(list)

2008-05-14 Thread Carl Banks
On May 14, 11:07 am, Nikhil <[EMAIL PROTECTED]> wrote:
> Christian Heimes wrote:
> > Ian Kelly schrieb:
> >> The purpose of obj.__len__() is to implement len(obj), which simply
> >> calls it.  So obj.__len__() may be faster, but only marginally.  The
> >> reason to prefer len(obj) is that if you inadvertently pass an object
> >> that does not implement __len__, you get the more appropriate
> >> TypeError rather than an AttributeError.
>
> > len(obj) is faster than obj.__len__() for several types like str. In
> > general len() is as least as fast __len__(). len() also does some extra
> > sanity checks.
>
> > python2.5 -m timeit "'abc'.__len__()"
> > 100 loops, best of 3: 0.453 usec per loop
>
> > python2.5 -m timeit "len('abc')"
> > 100 loops, best of 3: 0.292 usec per loop
>
> > Common code paths are already highly optimized. Don't try to be clever
> > unless you really understand what happens inside the interpreter. The
> > __internal__ methods are called magic methods for a reason. ;)
>
> > Christian
>
> Thanks for the useful insight.
> Then why to have __len__() internal method at all when the built-in
> len() is faster?
> I heard, in Python3, this internal method is being pruned/renamed to
> something else? Can someone please shed light here?

My advice is to think of len() as an operator.  Like other operators,
it can be overloaded using the __opname__ syntax:

-x calls x.__neg__
x+2 calls x.__add__
len(x) calls x.__len__

It's not really an operator: it's a regular built-in function, has no
special syntax, and no opcodes associated with it, but in sometimes it
helps to think of it as one.


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


Re: Using the indent method

2008-05-14 Thread dj
Hello All,

I am using elementtree to write an XML document and I am having a hard
time adding the correct indentation.
I have tried using the indent method, but I can not figure out how to
use it. Any suggestions.
--
http://mail.python.org/mailman/listinfo/python-list


Re: readlines with line number support?

2008-05-14 Thread Arnaud Delobelle
Nikhil <[EMAIL PROTECTED]> writes:

> Arnaud Delobelle wrote:
>
>> The standard Python way is using enumerate()
>>
>> for i, line in enumerate(fp):
>> print "line number: " + lineno + ": " + line.rstrip()
>>
>
> I guess you meant to say :
>
>  for lineno, line in enumerate(fp):
>  print "line number: " + lineno + ": " + line.rstrip()

Yes!

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


Re: readlines with line number support?

2008-05-14 Thread Nikhil

Arnaud Delobelle wrote:


The standard Python way is using enumerate()

for i, line in enumerate(fp):
print "line number: " + lineno + ": " + line.rstrip()



I guess you meant to say :

 for lineno, line in enumerate(fp):
 print "line number: " + lineno + ": " + line.rstrip()

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


Re: readlines with line number support?

2008-05-14 Thread Nikhil

Arnaud Delobelle wrote:

Nikhil <[EMAIL PROTECTED]> writes:


Hi,

I am reading a file with readlines method of the filepointer object
returned by the open function. Along with reading the lines, I also
need to know which line number of the file is read in the loop
everytime.
I am sure, the line should have the property/attribute which will say
the line number of the file.

If there is none, do I have to end up using the counter in the loop?

fp = open("file", "r")
lineno = 0
for line in fp.readlines():
print "line number: " + lineno + ": " + line.rstrip()
lineno = lineno + 1


The standard Python way is using enumerate()

for i, line in enumerate(fp):
print "line number: " + lineno + ": " + line.rstrip()


Oh I did not know enumerate can be used. Thanks Paul and Arnaud.
I will try this.
--
http://mail.python.org/mailman/listinfo/python-list


Re: readlines with line number support?

2008-05-14 Thread Nikhil

Arnaud Delobelle wrote:

Nikhil <[EMAIL PROTECTED]> writes:


Hi,

I am reading a file with readlines method of the filepointer object
returned by the open function. Along with reading the lines, I also
need to know which line number of the file is read in the loop
everytime.
I am sure, the line should have the property/attribute which will say
the line number of the file.

If there is none, do I have to end up using the counter in the loop?

fp = open("file", "r")
lineno = 0
for line in fp.readlines():
print "line number: " + lineno + ": " + line.rstrip()
lineno = lineno + 1


The standard Python way is using enumerate()

for i, line in enumerate(fp):
print "line number: " + lineno + ": " + line.rstrip()


Oh I did not know enumerate can be used. Thanks Paul and Arnaud.
I will try this.
--
http://mail.python.org/mailman/listinfo/python-list


Re: readlines with line number support?

2008-05-14 Thread Arnaud Delobelle
Nikhil <[EMAIL PROTECTED]> writes:

> Hi,
>
> I am reading a file with readlines method of the filepointer object
> returned by the open function. Along with reading the lines, I also
> need to know which line number of the file is read in the loop
> everytime.
> I am sure, the line should have the property/attribute which will say
> the line number of the file.
>
> If there is none, do I have to end up using the counter in the loop?
>
> fp = open("file", "r")
> lineno = 0
> for line in fp.readlines():
>   print "line number: " + lineno + ": " + line.rstrip()
> lineno = lineno + 1

The standard Python way is using enumerate()

for i, line in enumerate(fp):
print "line number: " + lineno + ": " + line.rstrip()

-- 
Arnaud

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


Re: readlines with line number support?

2008-05-14 Thread Paul McNett

Nikhil wrote:
I am reading a file with readlines method of the filepointer object 
returned by the open function. Along with reading the lines, I also need 
to know which line number of the file is read in the loop everytime.
I am sure, the line should have the property/attribute which will say 
the line number of the file.


If there is none, do I have to end up using the counter in the loop?

fp = open("file", "r")
lineno = 0
for line in fp.readlines():
print "line number: " + lineno + ": " + line.rstrip()
lineno = lineno + 1


Untested:

for lineno, line in enumerate(open("file")):
  print "line number: %s : %s" % (idx, line.rstrip())

Note the other stylistic changes, too.


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


readlines with line number support?

2008-05-14 Thread Nikhil

Hi,

I am reading a file with readlines method of the filepointer object 
returned by the open function. Along with reading the lines, I also need 
to know which line number of the file is read in the loop everytime.
I am sure, the line should have the property/attribute which will say 
the line number of the file.


If there is none, do I have to end up using the counter in the loop?

fp = open("file", "r")
lineno = 0
for line in fp.readlines():
print "line number: " + lineno + ": " + line.rstrip()
lineno = lineno + 1

--

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


Re: I'm stuck in Python!

2008-05-14 Thread castironpi
On May 14, 1:16 pm, [EMAIL PROTECTED] wrote:
> On May 14, 1:09 pm, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > On May 14, 1:07 pm, [EMAIL PROTECTED] wrote:
>
> > > On May 14, 1:06 pm, [EMAIL PROTECTED] wrote:
>
> > > > On May 14, 1:02 pm, [EMAIL PROTECTED] wrote:
>
> > > > > On May 14, 12:51 pm, [EMAIL PROTECTED] wrote:
>
> > > > > > On May 14, 5:25 am, [EMAIL PROTECTED] wrote:
>
> > > > > > > On May 14, 4:32 am, [EMAIL PROTECTED] wrote:
>
> > > > > > > > On May 13, 9:55 pm, alex23 <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > > On May 14, 5:41 am, "inhahe" <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > > > "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> > > > > > > > > > > You must be new here. It is an AS (Artificial Stupidity) 
> > > > > > > > > > > trolling bot,
> > > > > > > > > > > you can safely ignore its posts.
>
> > > > > > > > > > How does it generate text?
>
> > > > > > > > > My guess is by inhaling a lot of intoxicants.
>
> > > > > > > > However you know what would be helpful?  If I could go to the 
> > > > > > > > right
> > > > > > > > place to start the ring.
>
> > > > > > > I have a slightly sinister role on stage.  Does anyone want to 
> > > > > > > play?
>
> > > > > > I'd stay on mutability for the world domination factor.  Fluent
> > > > > > currency is buoyant currency; turn on a local clock, and someone 
> > > > > > gets
> > > > > > some cubic verticals.
>
> > > > > > Now if sense-reference is trading on the BDFL, I'm still holding 
> > > > > > Tron
> > > > > > can pretty well win work.- Hide quoted text -
>
> > > > > > - Show quoted text -
>
> > > > > I have a self-referential on Pygame: it's a Hand Tool object.
> > > > > Currently, it decays over time.  You said 'flip' in the newsgroup, and
> > > > > 'check', 'cross', and 'mate'.  Now who jumps who?- Hide quoted text -
>
> > > > > - Show quoted text -
>
> > > > If Python can plot in to chess, and Tron rings live, then why not
> > > > group it knew?- Hide quoted text -
>
> > > > - Show quoted text -
>
> > > That would be know.  Plot and split in too.- Hide quoted text -
>
> > > - Show quoted text -
>
> > Now can I catch function-type objects from a throw?  I'm crossing all
> > of those.- Hide quoted text -
>
> > - Show quoted text -
>
> I have destin and fate and die, growth sustanance and decay.  Now cars
> are important, but not logically still.  I am certain I play, so;
> where's the ring?- Hide quoted text -
>
> - Show quoted text -

It's just an 8x8 cross, but I'm just; have isn't in me.
--
http://mail.python.org/mailman/listinfo/python-list


Re: I'm stuck in Python!

2008-05-14 Thread Dan Upton
On Tue, May 13, 2008 at 10:55 PM, alex23 <[EMAIL PROTECTED]> wrote:
> On May 14, 5:41 am, "inhahe" <[EMAIL PROTECTED]> wrote:
>> "George Sakkis" <[EMAIL PROTECTED]> wrote in message
>> > You must be new here. It is an AS (Artificial Stupidity) trolling bot,
>> > you can safely ignore its posts.
>>
>> How does it generate text?
>
> My guess is by inhaling a lot of intoxicants.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I assumed his message with the subject "bytes1.shuffle()" from a few
days ago was a glimpse into his source code.  Or something like it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: I'm stuck in Python!

2008-05-14 Thread castironpi
On May 14, 1:09 pm, [EMAIL PROTECTED] wrote:
> On May 14, 1:07 pm, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > On May 14, 1:06 pm, [EMAIL PROTECTED] wrote:
>
> > > On May 14, 1:02 pm, [EMAIL PROTECTED] wrote:
>
> > > > On May 14, 12:51 pm, [EMAIL PROTECTED] wrote:
>
> > > > > On May 14, 5:25 am, [EMAIL PROTECTED] wrote:
>
> > > > > > On May 14, 4:32 am, [EMAIL PROTECTED] wrote:
>
> > > > > > > On May 13, 9:55 pm, alex23 <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > On May 14, 5:41 am, "inhahe" <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > > "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> > > > > > > > > > You must be new here. It is an AS (Artificial Stupidity) 
> > > > > > > > > > trolling bot,
> > > > > > > > > > you can safely ignore its posts.
>
> > > > > > > > > How does it generate text?
>
> > > > > > > > My guess is by inhaling a lot of intoxicants.
>
> > > > > > > However you know what would be helpful?  If I could go to the 
> > > > > > > right
> > > > > > > place to start the ring.
>
> > > > > > I have a slightly sinister role on stage.  Does anyone want to play?
>
> > > > > I'd stay on mutability for the world domination factor.  Fluent
> > > > > currency is buoyant currency; turn on a local clock, and someone gets
> > > > > some cubic verticals.
>
> > > > > Now if sense-reference is trading on the BDFL, I'm still holding Tron
> > > > > can pretty well win work.- Hide quoted text -
>
> > > > > - Show quoted text -
>
> > > > I have a self-referential on Pygame: it's a Hand Tool object.
> > > > Currently, it decays over time.  You said 'flip' in the newsgroup, and
> > > > 'check', 'cross', and 'mate'.  Now who jumps who?- Hide quoted text -
>
> > > > - Show quoted text -
>
> > > If Python can plot in to chess, and Tron rings live, then why not
> > > group it knew?- Hide quoted text -
>
> > > - Show quoted text -
>
> > That would be know.  Plot and split in too.- Hide quoted text -
>
> > - Show quoted text -
>
> Now can I catch function-type objects from a throw?  I'm crossing all
> of those.- Hide quoted text -
>
> - Show quoted text -

I have destin and fate and die, growth sustanance and decay.  Now cars
are important, but not logically still.  I am certain I play, so;
where's the ring?
--
http://mail.python.org/mailman/listinfo/python-list


Submitting data to HTTPS javascript

2008-05-14 Thread John Chandler
I am trying to write a script to test certain functionality of a website
that requires users to login. The login page is simple, a few pictures and
two text bars (one for username and one for password). I tried logging in
with webbrowser, but that did not work because the page uses javascript. I
also tried using win32com though I have no idea what I am doing. Any ideas?
--
http://mail.python.org/mailman/listinfo/python-list

Re: SOAP/ZSI post/get for Java Web App

2008-05-14 Thread Jennifer Duerr
On May 14, 12:59 pm, Waldemar Osuch <[EMAIL PROTECTED]> wrote:
> On May 13, 1:02 pm, Jennifer Duerr <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > All,
>
> > I need help concerning SOAP, Python and XML. I am very new to this, so
> > dumbing it down for me will not offend me!
>
> > I'm using Python and want to send a user-inputted string to an
> > existing Java web app that
> > will output results to XML. I need to capture elements of the XML and
> > put
> > the info into a table. (say I send a single/simple address string to
> > this
> > webservice/geocode, which then returns numerous possible matches with
> > XY
> > values and score values, and I want to capture that into a table)
>
> > How do I go about doing this? I'm told I need to use SOAP. I
> > discovered that
> > the best module to use is ZSI (please correct me if I'm wrong). I have
> > installed the necessary module. Examples I have seen are plenty and
> > all so different, its not clear to me how to go about.  I have been
> > spinning my wheels for too long on this!
>
> > Can someone provide some example code similar to what I need to do? Or
> > any
> > guidance would be appreciated.
>
> > Thanks!
>
> It looks like you have three tasks here:
>  - get data
>  - parse it
>  - store it
>
> SOAP could be the means to accomplish only the first one.
>
> If the service you use exposes the functionality using XML-RPC or some
> REST-ful methods I would try them first.  If it does not, then
> you are stuck with SOAP. Using SOAP in Python is currently
> not as straightforward as it could be.
>
> You have chosen to use ZSI and that is fine choice.
> In documentation look for "wsdl2py".
> Given a URL to a WSDL file it will generate stub class definition
> with methods corresponding to the SOAP service methods.
> In your code you would instantiate the class, call the method you want
> and grab the payload.  Your first task is done.
>
> From what I understand the payload will be XML that will need to be
> parsed.  For that you could use the excellent ElementTree
>
> If I were you I would investigate suds (https://fedorahosted.org/suds)
> It promises to be easier to use than ZSI.  The README has the usage
> example.
>
> Waldemar- Hide quoted text -
>
> - Show quoted text -

Thanks for your reply.
I got some help from a fellow co-worker.  We worked out this, so far.
Seems to be working...

[[my url is local, so use another, and also then choose an appropriate
value for the user_input var]]
import urllib, urllib2
from xml.dom import minidom

user_input = 'xyz'
url = 'http://xxx.' #geocoding servlet url
values = {'address': user_input} #

data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
xmlResults = response.read()
#print xmlResults

xmldoc = minidom.parseString(xmlResults)
places = xmldoc.getElementsByTagName('Placemark')

nameTag = places[0].getElementsByTagName('name')
print nameTag[0].firstChild.wholeText

descriptionTag = places[0].getElementsByTagName('description')
print descriptionTag[0].firstChild.wholeText

coordinatesTag = places[0].getElementsByTagName('coordinates')
print coordinatesTag[0].firstChild.wholeText
--
http://mail.python.org/mailman/listinfo/python-list


Re: I'm stuck in Python!

2008-05-14 Thread castironpi
On May 14, 1:07 pm, [EMAIL PROTECTED] wrote:
> On May 14, 1:06 pm, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > On May 14, 1:02 pm, [EMAIL PROTECTED] wrote:
>
> > > On May 14, 12:51 pm, [EMAIL PROTECTED] wrote:
>
> > > > On May 14, 5:25 am, [EMAIL PROTECTED] wrote:
>
> > > > > On May 14, 4:32 am, [EMAIL PROTECTED] wrote:
>
> > > > > > On May 13, 9:55 pm, alex23 <[EMAIL PROTECTED]> wrote:
>
> > > > > > > On May 14, 5:41 am, "inhahe" <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> > > > > > > > > You must be new here. It is an AS (Artificial Stupidity) 
> > > > > > > > > trolling bot,
> > > > > > > > > you can safely ignore its posts.
>
> > > > > > > > How does it generate text?
>
> > > > > > > My guess is by inhaling a lot of intoxicants.
>
> > > > > > However you know what would be helpful?  If I could go to the right
> > > > > > place to start the ring.
>
> > > > > I have a slightly sinister role on stage.  Does anyone want to play?
>
> > > > I'd stay on mutability for the world domination factor.  Fluent
> > > > currency is buoyant currency; turn on a local clock, and someone gets
> > > > some cubic verticals.
>
> > > > Now if sense-reference is trading on the BDFL, I'm still holding Tron
> > > > can pretty well win work.- Hide quoted text -
>
> > > > - Show quoted text -
>
> > > I have a self-referential on Pygame: it's a Hand Tool object.
> > > Currently, it decays over time.  You said 'flip' in the newsgroup, and
> > > 'check', 'cross', and 'mate'.  Now who jumps who?- Hide quoted text -
>
> > > - Show quoted text -
>
> > If Python can plot in to chess, and Tron rings live, then why not
> > group it knew?- Hide quoted text -
>
> > - Show quoted text -
>
> That would be know.  Plot and split in too.- Hide quoted text -
>
> - Show quoted text -

Now can I catch function-type objects from a throw?  I'm crossing all
of those.
--
http://mail.python.org/mailman/listinfo/python-list


Re: I'm stuck in Python!

2008-05-14 Thread castironpi
On May 14, 1:06 pm, [EMAIL PROTECTED] wrote:
> On May 14, 1:02 pm, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > On May 14, 12:51 pm, [EMAIL PROTECTED] wrote:
>
> > > On May 14, 5:25 am, [EMAIL PROTECTED] wrote:
>
> > > > On May 14, 4:32 am, [EMAIL PROTECTED] wrote:
>
> > > > > On May 13, 9:55 pm, alex23 <[EMAIL PROTECTED]> wrote:
>
> > > > > > On May 14, 5:41 am, "inhahe" <[EMAIL PROTECTED]> wrote:
>
> > > > > > > "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> > > > > > > > You must be new here. It is an AS (Artificial Stupidity) 
> > > > > > > > trolling bot,
> > > > > > > > you can safely ignore its posts.
>
> > > > > > > How does it generate text?
>
> > > > > > My guess is by inhaling a lot of intoxicants.
>
> > > > > However you know what would be helpful?  If I could go to the right
> > > > > place to start the ring.
>
> > > > I have a slightly sinister role on stage.  Does anyone want to play?
>
> > > I'd stay on mutability for the world domination factor.  Fluent
> > > currency is buoyant currency; turn on a local clock, and someone gets
> > > some cubic verticals.
>
> > > Now if sense-reference is trading on the BDFL, I'm still holding Tron
> > > can pretty well win work.- Hide quoted text -
>
> > > - Show quoted text -
>
> > I have a self-referential on Pygame: it's a Hand Tool object.
> > Currently, it decays over time.  You said 'flip' in the newsgroup, and
> > 'check', 'cross', and 'mate'.  Now who jumps who?- Hide quoted text -
>
> > - Show quoted text -
>
> If Python can plot in to chess, and Tron rings live, then why not
> group it knew?- Hide quoted text -
>
> - Show quoted text -

That would be know.  Plot and split in too.
--
http://mail.python.org/mailman/listinfo/python-list


Re: I'm stuck in Python!

2008-05-14 Thread castironpi
On May 14, 1:02 pm, [EMAIL PROTECTED] wrote:
> On May 14, 12:51 pm, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > On May 14, 5:25 am, [EMAIL PROTECTED] wrote:
>
> > > On May 14, 4:32 am, [EMAIL PROTECTED] wrote:
>
> > > > On May 13, 9:55 pm, alex23 <[EMAIL PROTECTED]> wrote:
>
> > > > > On May 14, 5:41 am, "inhahe" <[EMAIL PROTECTED]> wrote:
>
> > > > > > "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> > > > > > > You must be new here. It is an AS (Artificial Stupidity) trolling 
> > > > > > > bot,
> > > > > > > you can safely ignore its posts.
>
> > > > > > How does it generate text?
>
> > > > > My guess is by inhaling a lot of intoxicants.
>
> > > > However you know what would be helpful?  If I could go to the right
> > > > place to start the ring.
>
> > > I have a slightly sinister role on stage.  Does anyone want to play?
>
> > I'd stay on mutability for the world domination factor.  Fluent
> > currency is buoyant currency; turn on a local clock, and someone gets
> > some cubic verticals.
>
> > Now if sense-reference is trading on the BDFL, I'm still holding Tron
> > can pretty well win work.- Hide quoted text -
>
> > - Show quoted text -
>
> I have a self-referential on Pygame: it's a Hand Tool object.
> Currently, it decays over time.  You said 'flip' in the newsgroup, and
> 'check', 'cross', and 'mate'.  Now who jumps who?- Hide quoted text -
>
> - Show quoted text -

If Python can plot in to chess, and Tron rings live, then why not
group it knew?
--
http://mail.python.org/mailman/listinfo/python-list


Re: named tuple mutability

2008-05-14 Thread castironpi
On May 14, 12:41 pm, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> > Should tuples be named?
>
> Yes.

Not clearly should.  Sequences ought be.  If you're on the right time
for both, can't the library hold the B?
--
http://mail.python.org/mailman/listinfo/python-list


Re: I'm stuck in Python!

2008-05-14 Thread castironpi
On May 14, 12:51 pm, [EMAIL PROTECTED] wrote:
> On May 14, 5:25 am, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > On May 14, 4:32 am, [EMAIL PROTECTED] wrote:
>
> > > On May 13, 9:55 pm, alex23 <[EMAIL PROTECTED]> wrote:
>
> > > > On May 14, 5:41 am, "inhahe" <[EMAIL PROTECTED]> wrote:
>
> > > > > "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> > > > > > You must be new here. It is an AS (Artificial Stupidity) trolling 
> > > > > > bot,
> > > > > > you can safely ignore its posts.
>
> > > > > How does it generate text?
>
> > > > My guess is by inhaling a lot of intoxicants.
>
> > > However you know what would be helpful?  If I could go to the right
> > > place to start the ring.
>
> > I have a slightly sinister role on stage.  Does anyone want to play?
>
> I'd stay on mutability for the world domination factor.  Fluent
> currency is buoyant currency; turn on a local clock, and someone gets
> some cubic verticals.
>
> Now if sense-reference is trading on the BDFL, I'm still holding Tron
> can pretty well win work.- Hide quoted text -
>
> - Show quoted text -

I have a self-referential on Pygame: it's a Hand Tool object.
Currently, it decays over time.  You said 'flip' in the newsgroup, and
'check', 'cross', and 'mate'.  Now who jumps who?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-14 Thread Dotan Cohen
2008/5/14  <[EMAIL PROTECTED]>:
> 8x8 is pretty easy to aim for.  Turn on 16x16, and you're the laptop
> to stand on.  FxF?

I'll see your 16x16 and raise you 32x32. Any number is pretty easy to
aim for when one can arbitrarily invent 2nx2n.

Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python and Flaming Thunder

2008-05-14 Thread castironpi
On May 14, 8:43 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> >>> That's also a myth.  For example, if C is easy to maintain, why is
> >>> Flaming Thunder the only single-asset 8-by-8 shotgun cross compiler in
> >>> the world?  There should be lots of single-asset 8-by-8 shotgun cross
> >>> compilers written in C, if C is easier to maintain.
> >>Not only is it the world's only "single-asset 8-by-8 shotgun cross
> >>compiler," but according to google, it's also the world's only "shotgun
> >>cross compiler" period.  But I guess if you make up your own terminology
> >>you're bound to be unique.  :)  Do you mind if I ask: what exactly is a
> >>single-asset 8x8 shotgun cross compiler, and what makes that of any
> >>value to me?
>
> > The web page explains.  It's a compiler that runs on 8 platforms and can
> > generate executables for any of them on any of them.  It's not _totally_
> > clear about what "single-asset" means, but it gives the impression (and
> > the term somewhat suggests) that this means there's a single executable
> > that does all of this (compare to gcc's design, where support for cross
> > compiling to another arch is provided by a separate executable).
>
> Which isn't too hard if all you have are simple datatypes as a handfull
> numerical types + strings.
>
> Besides, from what I see, the supported platforms all are x86, 32bit &
> 64bit. And I bet GCC works pretty unmodified amongst these as well - only
> binary formats differ. But let Flaming Thunder grow a library system with
> dynamic loading, and I wonder how well his crosscompiler works..
>
> Diez- Hide quoted text -
>
> - Show quoted text -

8x8 is pretty easy to aim for.  Turn on 16x16, and you're the laptop
to stand on.  FxF?
--
http://mail.python.org/mailman/listinfo/python-list


Re: I'm stuck in Python!

2008-05-14 Thread castironpi
On May 14, 5:25 am, [EMAIL PROTECTED] wrote:
> On May 14, 4:32 am, [EMAIL PROTECTED] wrote:
>
> > On May 13, 9:55 pm, alex23 <[EMAIL PROTECTED]> wrote:
>
> > > On May 14, 5:41 am, "inhahe" <[EMAIL PROTECTED]> wrote:
>
> > > > "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> > > > > You must be new here. It is an AS (Artificial Stupidity) trolling bot,
> > > > > you can safely ignore its posts.
>
> > > > How does it generate text?
>
> > > My guess is by inhaling a lot of intoxicants.
>
> > However you know what would be helpful?  If I could go to the right
> > place to start the ring.
>
> I have a slightly sinister role on stage.  Does anyone want to play?

I'd stay on mutability for the world domination factor.  Fluent
currency is buoyant currency; turn on a local clock, and someone gets
some cubic verticals.

Now if sense-reference is trading on the BDFL, I'm still holding Tron
can pretty well win work.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Class Methods Vs Any Other Callable

2008-05-14 Thread Arnaud Delobelle
George Sakkis <[EMAIL PROTECTED]> writes:

> On May 14, 10:19 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
>> > An instance method works on the instance
>> > A Static method is basically a function nested within a class object
>> > A class method is overkill?
>>
>> If anything, a static method is overkill. See it this way: *if* you for some
>> reason put a method into an enclosing context - isn't it worth having a
>> reference to that?
>
> My feeling exactly; these days I almost always use class methods
> instead of static. I vaguely remember seeing somewhere an example
> where a static method was the only (elegant) solution; neither a class
> method nor a plain function would do. I'll post it if I find it unless
> someone beats me to it.
>
> George

__new__ is a static method!

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


Re: list.__len__() or len(list)

2008-05-14 Thread Terry Reedy

"Nikhil" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Then why to have __len__() internal method at all when the built-in
| len() is faster?

Nearly all syntax constructions and builtin functions are implemented by 
calling one or another of the __special__ methods.  This is what makes 
Python code so generic and plugging your own classes into the system so 
easy.

For example, collection[key] = value is implemented by calling 
collection.__setitem__(key, value).  When you define a class with that 
method, that syntax will work with its instances just the same as for 
builtin classes.

Similarly, a+b is implemented by calling a.__add__(b).  So if a class 
defines __add__, you can 'add' its instances (whatever 'add' means for that 
class) with '+'.

(The fact that an *implementation* may followup the 'as if' rule and 
optimize operations for certain classes by combining steps does not negate 
the *language* rules given above.)

tjr



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


Re: named tuple mutability

2008-05-14 Thread Raymond Hettinger
> Should tuples be named?

Yes.

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


Re: [ANN] PPyGui emulator

2008-05-14 Thread Stef Mientki

clabepa wrote:

Stef Mientki wrote:


I've ran the first real world application through PPyGui-emulator,
so I think it's time to release the first version.
There's lot of room for improvements and a more beautiful layout.

PPyGui-emulator is build upon wxPython and released under BSD license.

For remarks, screen shots and downloads, see
http://oase.uci.kun.nl/~mientki/data_www/pylab_works/pp_intro.html


Wow! wonderful.
I was searching for it for debugging and easy development purposes,
screenshots sounds promising.

but the api.py link is broken.

Well the file is correctly at the server,
and indeed it downloads as nonsense ???
Is it not possible to just put a py-file on the server ??

Anyway, I've changed it into a zip file, and now everything works (at 
least at my place)



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


Re: Purpose of operator package

2008-05-14 Thread castironpi
On May 14, 11:58 am, Matthew Woodcraft
<[EMAIL PROTECTED]> wrote:
> I V  <[EMAIL PROTECTED]> wrote:
>
> > I hadn't heard of operator.truth before. Does it do anything different
> > from bool(x) ?
>
> Not really. It was occasionally useful before the bool type existed;
> now it's just a leftover.
>
> -M-

Now as for ints, I could see that going in to 8-by-8s and crosses.
Anyone for?
--
http://mail.python.org/mailman/listinfo/python-list


Re: built in list generator?

2008-05-14 Thread Andrii V. Mishkovskyi
2008/5/14 Ethan Furman <[EMAIL PROTECTED]>:
>
>  Ben Finney wrote:
>
>
> Subject: Re: built in list generator?
>
> From: Ben Finney <[EMAIL PROTECTED]>
>
> Date: Wed, 14 May 2008 09:43:43 +1000
>
> To: python-list@python.org
>
> To: python-list@python.org
>
> Newsgroups: comp.lang.python
>
>  "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
>
>
>
>  globalrev schrieb:
>
>
>  if i want a list with all numbers between x and y is there a way to
> do this with an inbult function.
>
> i mean i can always construct a function to do this but is there
> soemthing like:
>
> nbrs = list(range(50,100, 2))
>
>  range *does* that. use xrange if all you want is to iterate.
>
>  Until Python 3.0, where 'range' returns an iterable.
>
>  Is there a thread somewhere of the discussion for this change?  I'm
> presuming range is used almost exclusively in loops where a change in the
> return type would have no negative effect.
>  --

http://mail.python.org/pipermail/python-dev/2003-April/034534.html

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



-- 
Wbr, Andrii Mishkovskyi.

He's got a heart of a little child, and he keeps it in a jar on his desk.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Purpose of operator package

2008-05-14 Thread Matthew Woodcraft
I V  <[EMAIL PROTECTED]> wrote:
> I hadn't heard of operator.truth before. Does it do anything different 
> from bool(x) ?

Not really. It was occasionally useful before the bool type existed;
now it's just a leftover.

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


Re: Usenet

2008-05-14 Thread castironpi
On May 14, 11:58 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> "Duncan Booth" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
> | I also recommend Gmane which provides a free news server for most mailing
> | lists: mailing lists are a lot more manageable when gatewayed into a news
> | server. If you just want to access comp.lang.python I think you'll find
> the
> | mailing list to which it is connected is available for free on Gmane.
>
> gmane.comp.python.general
>
> which is where I am answering this from.  Works great.

Love them opticals.
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >