Re: Python or PHP?

2005-04-24 Thread Ville Vainio
> "John" == John Bokma <[EMAIL PROTECTED]> writes:

John> Who told you Perl can't do exceptions?

Back when I learned (heh, I never 'really' learned, but knew enough to
write programs in it) perl, almost every function call was followed by

or die("blah");

i.e. the user had to check the error code. If the function would have
raised an exception instead, such check would be redundant because it
would never be executed.

In Python, all error conditions raise exceptions. If python
'supported' exceptions but standard library functions didn't raise
them, the feature would not be worth much.

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's do list comprehensions do that generator expressions don't?

2005-04-24 Thread Robert Kern
Steven Bethard wrote:
Robert Kern wrote:
Mike Meyer wrote:
Ok, we've added list comprehensions to the language, and seen that
they were good. We've added generator expressions to the language, and
seen that they were good as well.
I'm left a bit confused, though - when would I use a list comp instead
of a generator expression if I'm going to require 2.4 anyway?
Never. If you really need a list
list(x*x for x in xrange(10))
Not quite true.  If you discovered the unlikely scenario that the 
construction of a list from the generator expression was an efficiency 
bottleneck, you might choose a list comprehension -- they're slightly 
faster when you really do want a list:

$ python -m timeit "list(x*x for x in xrange(10))"
10 loops, best of 3: 6.54 usec per loop
$ python -m timeit "[x*x for x in xrange(10)]"
10 loops, best of 3: 5.08 usec per loop
Okay, okay, *almost* never.
However, I don't expect that speed relationship to hold past Python 2.4.
--
Robert Kern
[EMAIL PROTECTED]
"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


Re: What's do list comprehensions do that generator expressions don't?

2005-04-24 Thread Steven Bethard
Robert Kern wrote:
Mike Meyer wrote:
Ok, we've added list comprehensions to the language, and seen that
they were good. We've added generator expressions to the language, and
seen that they were good as well.
I'm left a bit confused, though - when would I use a list comp instead
of a generator expression if I'm going to require 2.4 anyway?
Never. If you really need a list
list(x*x for x in xrange(10))
Not quite true.  If you discovered the unlikely scenario that the 
construction of a list from the generator expression was an efficiency 
bottleneck, you might choose a list comprehension -- they're slightly 
faster when you really do want a list:

$ python -m timeit "list(x*x for x in xrange(10))"
10 loops, best of 3: 6.54 usec per loop
$ python -m timeit "[x*x for x in xrange(10)]"
10 loops, best of 3: 5.08 usec per loop
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Decorator pattern for new-style classes ?

2005-04-24 Thread Michele Simionato
I have no time for a long discussion, but the code should
speak for itself:

class Container(object):
def __init__(self, content):
self.content = content
def __str__(self):
return "" % self.content

class Wrapped(object):
def __init__(self, obj):
self._obj = obj
def __getattribute__(self, name):
obj = super(Wrapped, self).__getattribute__("_obj")
return getattr(obj, name)

w = Wrapped(Container("hello"))

print w.content
print w.__str__() # works
print w # does not work as you would expect, see bug report SF 729913

The discussion around the bug report is worth reading,

 Michele Simionato

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


Re: What's do list comprehensions do that generator expressions don't?

2005-04-24 Thread Robert Kern
Mike Meyer wrote:
Ok, we've added list comprehensions to the language, and seen that
they were good. We've added generator expressions to the language, and
seen that they were good as well.
I'm left a bit confused, though - when would I use a list comp instead
of a generator expression if I'm going to require 2.4 anyway?
Never. If you really need a list
list(x*x for x in xrange(10))
Sadly, we can't remove list comprehensions until 3.0.
--
Robert Kern
[EMAIL PROTECTED]
"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


What's do list comprehensions do that generator expressions don't?

2005-04-24 Thread Mike Meyer
Ok, we've added list comprehensions to the language, and seen that
they were good. We've added generator expressions to the language, and
seen that they were good as well.

I'm left a bit confused, though - when would I use a list comp instead
of a generator expression if I'm going to require 2.4 anyway?

   Thanks,
 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cross platform printing

2005-04-24 Thread Mike Meyer
"David Isaac" <[EMAIL PROTECTED]> writes:

>> Alan Isaac wrote:
> I meant something that application users on different platforms can print
> with, not something
> that they could coerce a platform into supporting given enough energy (e.g.,
> via Cygwin).
> The closest to an option so far seems to be to generate PDF and assume an
> application is available to print it.  Not beautiful.

What about generating some other image format? It does seem more
likely that the host OS will be able to handle, say GIF, than
PDF. In particular, Windows probably comes able to print GIF out of
the box, but not PDF. Then again, when I use Windows acrobat reader
gets installed fairly early, so I may have overlooked it.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-24 Thread Mike Meyer
John Bokma <[EMAIL PROTECTED]> writes:
> Mike Meyer wrote:
>> John Bokma <[EMAIL PROTECTED]> writes:
>>> Mike Meyer wrote:
 John Bokma <[EMAIL PROTECTED]> writes:
> Mike Meyer wrote:
>> Depends on the problem. If it's one of the things for which Python
>> has an obvious solution (sort a list; split a string on
>> whitespace; pull select list elements based on a criteria of some
>> kind; search a file for lines with a given word in them; etc.)
>> you'd get back the same answer from almost all of them.
> And what makes you doubt it would be different with Perl? :-D
 Perl's "There's more than one way to do it" attitude.
>>> There's doesn't mean that you have to use or know them all. I think 
>>> every language here and there more ways to do something. And at a 
>>> broader scope, e.g. a simple algorithm, it doesn't matter that much 
>>> anymore.
>> Except that, as I said elsewhere, that having more than one way to do
>> it bloats the language processor
> do you really think that for / foreach and things like if / unless bloat 
> a language processor? I think you take your "pure programming lanuage" 
> way to far, and really don't understand your choice of Python in your 
> crusade.

I don't think I take it to far. All my experience dealing with
languages that took the opposite tack (i.e. - Perl and Common LISP)
demonstrate that such things are a bad idea.

Python got chosen for this discussion for two reasons. One, we're
posting in comp.lang.python. Two, part of the Python philosophy -
which you can get by doing "import this" - is:

There should be one-- and preferably only one --obvious way to do it.

>> and increases the semantic load on
>> the programmer. The best the programmer can do, as you imply, is to
>> ignore the extraneous methods.
> I am curious of a list of extraneous methods in Perl (more about the 
> size by the way)

Methods isn't a very good word choice on my part, as it has to many
meanings. But saying "extraneous ways to do it" is a bit wordy. I
already gave you one such list, covering just the syntactic elements
of the language.

>> Then the poor programmer has to puzzle
>> over them every time they show up in someone else's code.
> A poorly skilled programmer has to puzzle about a lot of more things. Or 
> you think list comprehension (sp?) and all the tricks with it are clear? 
> or the and or trick? I just had a glance on Python, but what probably to 
> you is one clear path isn't clear to me yet. And I doubt that can all be 
> blamed on unpure new Python.

Correct - newbies have to puzzle about a lot of things. A good
language design won't add to that set of things without a good
reason. Adding features because you can is adding things to puzzle
about without a good reason.

List comprehensions are part of that "new, unpure python". They
duplicate functionality that was already in the language. Of course,
they are a lot clearer than what was there, and if Python were a
research language rather than a production language, map, filter and
lambda would be gone.

>> No, one I blew. One you still got wrong.
> Which one?

Faling to put in the parens that would have distinguished the argument
lists from the list of operators.

Actually, it's not clear the grep was right either. The return value
of grep (and map) isn't always the right thing. You have to force the
return value into a list context to get the right result. Oh
well. Just one more thing for the programmer to worry about.

>>> If I could have a peek at the Perl code you maintained I could tell
>>> you (often by just seeing 3-5 lines) the status of the programmer who
>>> wrote it :-)
>> So you'd either say you were wrong, or that my second contention was
>> right. Either one would be a bad side effect of TMTOWTDI.
> I am right, and you are wrong ;-)

In which case, I'm right in claiming that having more than one way to
do things fragments the community - which is *still* a bad thing for
the people writing the language.

>>> Quite some people have been "tweaking" CGI scripts
>>> Quite some people "know" PHP, and hence consider themselves Perl 
>>> programmers.
>> 
>> Quite right. Neither is in the set of Perl things I maintain.
>
> Does that matter? What matters is what are the skills and background of 
> the Perl programmer who wrote the code you maintain.

They all come from different backgrounds, which is why they all use
different subsets of the language. Having a language that makes such
division of the community easy is a *bad* thing. Look at the history
of LISP to see why.

 part of the grammar of the language, and are a recent addition. It's
 not clear how Python should evolve with them added to the language.
>>> More fat: so I would say: learn to live with it. I only see
>>> advantages. If you want a minimal set of operations, I recommend
>>> programming ARM assembly, and don't go beyond ARM3 :-D.
>> 
>> You could also say more bloat. It's not a good thing. I don't want a
>> minima

Re: Variables

2005-04-24 Thread Richard Blackwood
I thought I'd share a piece of the discussion a friend of mine is having 
with a mathematician/programmer on this issue of variables:

int foo = 5;
Is foo not a variable? Within the scope of that statement, foo can be 
no other value but 5. Is foo not a constant? Are constants and 
variables not mutually exclusive? But wait, what if I write:

Yes, foo, here, is a variable in the program.  In this case, it is a 
variable that has been given a value at the same time that it is 
declared. It can, within the program, be changed at any time, as you 
illustrate with the following example:
Yet what if my program is a mere two lines where foo does not change 
(the following code is in Python):

foo = 5
print foo
Does the fact that foo fails to change in the execution of the /entire/ 
program invalidate its status as a variable? Or is it merely the 
potential to change (as enforced by the respective compiler) that 
defines foo as a variable? In a program where my name-value-couple (foo) 
does not change values, am I to consider foo a constant? What are the 
consequences of doing otherwise?

In programming (i.e. versus math) is the concept of variable and 
constant dependent on how a compiler processes identifiers and values in 
a program, and the various restrictions imposed on programmers regarding 
how they can manipulate those identifiers and values? For example, in 
C/C++ one can actually define constants, but this has a strict meaning 
in the sense that the compiler forces you to give constants known (?) 
values within the code which are then immutable. if I write the 
following program (pseudo-code):

const X = 5
print X
Y = 5
print Y
The only thing that makes X any more of a constant than Y is the fact 
that X is treated by the compiler as a constant--- I cannot change X's 
value with additional code, but I can change Y's, I merely happened to 
chose not to. From this standpoint, the notion of variable and constant 
in programming is very much bound to the way the language treats each, 
the "can"s and "cannot"s imposed on the programmer by the respective 
language. In Python, the interpreter unambiguously knows nothing about 
constants, and as many would argue, nothing about variables either (only 
names and values/data/objects).

...
...

Is the definition of variable actually different between math and 
programming? And regardless, is the notion of variable so very 
ambiguous, even within each respective field?

Variable is the same in both contexts.  In a computer *program*, 
however, you can have statements such as "x = x+1" which is not 
appropriate in mathematics.  You need there to be understanding that 
within a computer a variable is treated as a place in the memory.  The 
statement "x=x+1" refers to the process of looking at what is in x, 
adding 1 to that value, and substituting that value back into the 
location in memory. ... 
Many would argue a more general definition of variable: variables are 
symbolic references to data/values which can change. One math text in my 
possession concurs with this programming definition by stating a 
variable to be a symbol replaceable by a value which can change. Another 
(Scott Foresman, UCSMP, 1993) writes that a variable is "a letter or 
other symbol that can be replaced by any numbers (or other objects)." Is 
the definition of a variable, particularly in math, so simple? Your 
definition (identical to Raphael A. Finkel's [1996]) implies that, in 
such languages such as Python where names (i.e. foo) are mapped to 
values, there are no variables. For example, when I write foo = 5 in 
Python, the interpreter will create an integer 5 in memory, a name foo 
(unless it already exists), and then bound the name foo to the value 
int(5). Foo is not a place in memory in this sense, but instead a 
reference, a pointer that can direct us to values/data stored in various 
memory locations. Where foo points to (and hence what value foo provides 
us) can change. This is not like in C where foo would be a place in 
memory. In C, if I write int foo = 5, a block of memory is allocated for 
values of foo and 5 is stored there. If I later write foo = 6, the 
contents of foo's memory block are overwritten with the integer 6. In 
this memory based sense, values in C are bound to names, whereas in 
Python names are bound to values. Is it only the former case which 
defines a variable? Many would argue yes. Foo in Python is merely a name 
which can be mapped to a value they would say. On the other hand, many 
would argue no. They would say that a variable is simply an abstract or 
concrete "place" to store data. In the case of Python and the foo 
example, they would argue that foo is a variable in an abstract sense, 
though indeed not so semantically. But what functional good does focus 
on such details provide?

I agree with both camps. However, I posit that perhaps foo *is* 
semantically a variable in the practical sense that it exists in memory 
as a store of a value--- not 5 a

ANN: Wing IDE 2.0.3 released

2005-04-24 Thread Wingware Announce
Hi,

I'm happy to announce the release of Wing IDE version 2.0.3, an
advanced development environment for the Python programming
language.

This is a free upgrade for Wing IDE 2.0 users.  The release can
be downloaded from:

http://wingware.com/downloads

Wing IDE provides powerful debugging, editing, code intelligence,
and search capabilities that reduce development and debugging
time, cut down on coding errors, and make it easier to understand
and navigate Python code.

Highlights of this release include:

* New keyboard personality for OS X
* Debugging support for 64-bit Linux versions of Python
* Editor performance improvements

A complete list of changes is available here:

http://wingware.com/pub/wingide/2.0.3/CHANGELOG.txt

This release is available for Windows, Linux, and Mac OS X, and
can be compiled from sources on *BSD, Solaris, and other Posix
operating systems.

For more information see:

Product Info:   http://wingware.com/products
Sales:  http://wingware.com/store/purchase
Upgrades:   http://wingware.com/store/upgrade
  
Sincerely,

Stephan Deibel

--
Wingware
Wing IDE for Python
Advancing Software Development

www.wingware.com



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


Re: Utah Python Users Group

2005-04-24 Thread Jim Hargrave
I'm a Computational Linguist just starting with Python. I personally 
would be very interested in a UT Python group.

Jim
lugal wrote:
Is anyone aware if there's a Utah-based Python User Group? If not, does
any else from Utah have any interest in forming a Utah-based Python
User Group?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Decent Win32All Documentation

2005-04-24 Thread Roger Binns

"Harlin Seritt" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Does anyone know of any decent documenation on Mark Hammond's win32all
> modules? I have tried looking at the documentation .chm file that comes
> with it, Python Programming On Win32 (OReilly book) and ActiveState's
> documentation and have found them all lacking -- yes I need it broken
> down to me.

I stringly recommend the platform sdk which includes documentation of
*ALL* Windows APIs, sample code etc.  It is very easily searchable.
win32all is a very thin wrapper over the underlying Windows API.

http://www.microsoft.com/msdownload/platformsdk/sdkupdate/

Roger 


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


Re: Is this a bug?

2005-04-24 Thread Grant Edwards
On 2005-04-25, Robert Kern <[EMAIL PROTECTED]> wrote:

>> I certainly don't see how.  Strings are immutable.  The old
>> object can't be modified in-place, so the "in-place" behavior
>> is moot.
>
> It's the left-hand-side, in this case a list, that gets modified 
> in-place. Whether the right-hand-side is mutable or not is irrelevant.

You're right.  I had things backwards in my head.

>> Your quote states quite clearly that the binary operation *is
>> the same* whether it's spelt a = a + b or a += b.  That is
>> simply not true for the example we're discussing.
>
> No, the quote says "with the exception of the possible
> in-place behavior, the binary operation performed by augmented
> assignment is the same as the normal binary operations." This
> is "in-place" behavior.  Badly designed "in-place" behavior,
> yes.

Right. The binary operation performed should be the same
regardless of whether it is done in place or not.  In this
case, the "in-place" behavior is completely different than the
other spelling.

> It's a mistake, but it's been in the wild too long to be changed. Thus, 
> it should be documented.

Life's like that, unfortunately.

-- 
Grant Edwards   grante Yow!  I'm RELIGIOUS!! I
  at   love a man with a
   visi.comHAIRPIECE!! Equip me with
   MISSILES!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this a bug?

2005-04-24 Thread Robert Kern
Grant Edwards wrote:
On 2005-04-25, Terry Reedy <[EMAIL PROTECTED]> wrote:
  According to the language reference,
An augmented assignment expression like x += 1 can be
rewritten as x = x + 1 to achieve a similar, but not
exactly equal effect. In the augmented version, x is only
evaluated once.
  I don't consider the two results you posted "similar".
It continues
"Also, when possible, the actual operation is performed in-place, meaning 
that rather than creating a new object and assigning that to the target, 
the old object is modified instead. ...Similarly, with the exception of the 
possible in-place behavior, the binary operation performed by augmented 
assignment is the same as the normal binary operations.
"
I take the behavior observed to be the exceptional in-place behavior 
referred to.

I certainly don't see how.  Strings are immutable.  The old
object can't be modified in-place, so the "in-place" behavior
is moot.
It's the left-hand-side, in this case a list, that gets modified 
in-place. Whether the right-hand-side is mutable or not is irrelevant.

In any case, the only difference is supposed to be whether a
new object is created or an existing object is modified.  The
two results shouldn't be completely different as shown by the
OP.  

Your quote states quite clearly that the binary operation *is
the same* whether it's spelt a = a + b or a += b.  That is
simply not true for the example we're discussing.
No, the quote says "with the exception of the possible in-place 
behavior, the binary operation performed by augmented assignment is the 
same as the normal binary operations." This is "in-place" behavior. 
Badly designed "in-place" behavior, yes.

But this could certainly be clearer.
I don't see how that statement has anything to do with the bug
at hand.
It's a mistake, but it's been in the wild too long to be changed. Thus, 
it should be documented.

--
Robert Kern
[EMAIL PROTECTED]
"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple tuples for one for statement

2005-04-24 Thread Daniel Cer
Harlin Seritt wrote:
I have three tuples of the same size: tup1, tup2, tup3
I'd like to do something like this:
for a,b,c in tup1, tup2, tup3:
   print a
   print b
   print c
Of course, you get an error when you try to run the pseudocode above.
What is the correct way to get this done?
For something like this, you can use izip from itertools to package 
things up.

e.g. a working version of the code you posted using izip would be:
import itertools
tup1 = (1, 2, 3)
tup2 = (4, 5, 6)
tup3 = (7, 8, 9)
for a,b,c in itertools.izip(tup1, tup2, tup3):
   print "a: %d b: %d c: %d" % (a, b, c)
This outputs:
a: 1 b: 4 c: 7
a: 2 b: 5 c: 8
a: 3 b: 6 c: 9
-Dan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple tuples for one for statement

2005-04-24 Thread Harlin Seritt
Thank you Mr. Stroud.

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


Re: Multiple tuples for one for statement

2005-04-24 Thread Kent Johnson
Harlin Seritt wrote:
I have three tuples of the same size: tup1, tup2, tup3
I'd like to do something like this:
for a,b,c in tup1, tup2, tup3:
   print a
   print b
   print c
Presuming that you want a,b,c to be corresponding entries from the three tuples, then zip() is your 
friend:
for a,b,c in zip(tup1, tup2, tup3):
  ...

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


Re: Multiple tuples for one for statement

2005-04-24 Thread Steven Bethard
Harlin Seritt wrote:
I have three tuples of the same size: tup1, tup2, tup3
I'd like to do something like this:
for a,b,c in tup1, tup2, tup3:
   print a
   print b
   print c
Of course, you get an error when you try to run the pseudocode above.
What is the correct way to get this done?
for a, b, c in zip(tup1, tup2, tup3):
print a
print b
print c
If your tuples become iterators, look into itertools.izip.
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple tuples for one for statement

2005-04-24 Thread James Stroud
for a,b,c in zip(tup1, tup2, tup3):
   print a
   print b
   print c
-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: opening new window in one window using Tkinter -- Help please

2005-04-24 Thread Clara
I've found the solution I must destroy the first window using
self.master.destroy(), but thanks anyway ^_^

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


Multiple tuples for one for statement

2005-04-24 Thread Harlin Seritt
I have three tuples of the same size: tup1, tup2, tup3

I'd like to do something like this:

for a,b,c in tup1, tup2, tup3:
   print a
   print b
   print c

Of course, you get an error when you try to run the pseudocode above.
What is the correct way to get this done?

Thanks,

Harlin

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


Re: Variables

2005-04-24 Thread Richard Blackwood
James Stroud wrote:
On Saturday 23 April 2005 10:25 pm, so sayeth Richard Blackwood:
 

Unfortunately that's not much of an option for me. We are working on a
project together so I am forced to either prove his notion incorrect or
I give in to his conception. *throws hands in air*
   

This is a communcication issue. You guys probably need a relationship couselor 
or something. I think you should both agree on a common vocabulary and use 
that. Usually the "bigger" individual makes the most concessions in these 
areas, but then the "bigger" individual is usually meant for greater 
callings.

James
 

*laugh* Intriguing suggestion...but what defines a "bigger" individual?
--
http://mail.python.org/mailman/listinfo/python-list


Re: cross platform printing

2005-04-24 Thread David Isaac
> Alan Isaac wrote:
> > What is the current best practice for cross platform printing of
PostScript
> > files from Python?

"Warren Postma" <[EMAIL PROTECTED]> wrote in
message news:[EMAIL PROTECTED]
> Well since printing postscript files on most Unix systems (probably
> including Mac OSX although I don't really know this for sure) is
> trivially easy, why not investigate using cygwin  on Windows and
> launching an "lpr" task from your python script that prints the given
> postscript file. Implementation time on Unix: 0 minutes, 0 seconds.
> Implementation time on Windows; the time it takes make a cygwin batch
> file that prints using ghostscript.

I meant something that application users on different platforms can print
with, not something
that they could coerce a platform into supporting given enough energy (e.g.,
via Cygwin).
The closest to an option so far seems to be to generate PDF and assume an
application is available to print it.  Not beautiful.

Alan Isaac


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


Re: Is this a bug?

2005-04-24 Thread Grant Edwards
On 2005-04-25, Terry Reedy <[EMAIL PROTECTED]> wrote:
>>According to the language reference,
>>
>>  An augmented assignment expression like x += 1 can be
>>  rewritten as x = x + 1 to achieve a similar, but not
>>  exactly equal effect. In the augmented version, x is only
>>  evaluated once.
>>
>>I don't consider the two results you posted "similar".
>
> It continues
> "Also, when possible, the actual operation is performed in-place, meaning 
> that rather than creating a new object and assigning that to the target, 
> the old object is modified instead. ...Similarly, with the exception of the 
> possible in-place behavior, the binary operation performed by augmented 
> assignment is the same as the normal binary operations.
> "
> I take the behavior observed to be the exceptional in-place behavior 
> referred to.

I certainly don't see how.  Strings are immutable.  The old
object can't be modified in-place, so the "in-place" behavior
is moot.

In any case, the only difference is supposed to be whether a
new object is created or an existing object is modified.  The
two results shouldn't be completely different as shown by the
OP.  

Your quote states quite clearly that the binary operation *is
the same* whether it's spelt a = a + b or a += b.  That is
simply not true for the example we're discussing.

> But this could certainly be clearer.

I don't see how that statement has anything to do with the bug
at hand.

-- 
Grant Edwards   grante Yow!  Oh my GOD -- the
  at   SUN just fell into YANKEE
   visi.comSTADIUM!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing data from URL

2005-04-24 Thread R. C. James Harlow
On Monday 25 April 2005 01:24, Harlin Seritt wrote:

> dat = urllib.urlopen(url, 'r').read()

Drop the 'r' - urlopen is posting the 'r' to the server, instead of doing what 
you mean, opening the file read-only.


pgpmZ2zcMs1bO.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Parsing data from URL

2005-04-24 Thread could ildg
I think it depends on the server

On 24 Apr 2005 17:24:18 -0700, Harlin Seritt <[EMAIL PROTECTED]> wrote:
> I am trying to do the following:
> 
> 
> 
> import urllib
> 
> url = 'http://www.website.com/file.shtml'
> dat = urllib.urlopen(url, 'r').read()
> print dat
> 
> When I do so, I get the following data:
> 
> 
> 
> 405 Method Not Allowed
> 
> Method Not Allowed
> The requested method POST is not allowed for the URL 
> 
> Apache/1.3.27 Server at website.com Port 80
> 
> 
> How can I make sure that I get the actual html data instead of the data
> from redirected URL?
> 
> thanks,
> 
> Harlin
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: pygtk and long running process

2005-04-24 Thread Daniel Cer
Daniel Cer wrote:
Robert wrote:
I have a command line app that can take up to 20 minutes to complete and
every minute or so updates it's status (spits it out to console).  I am
writing a front end for this app in python/gtk and was wondering what
command I use to a) invoke the command and b) how to capture it's out put
and for instance update a text box.

os.popen() will probably do what you want.
e.g.:
()
As for the latter part of (b)
I don't know much about pygtk, but I imagine you should be able to put 
the code that monitors the external program in a thread, and then 
whenever you get some new status information update the text box.

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


Re: Is this a bug?

2005-04-24 Thread Terry Reedy
>According to the language reference,
>
>  An augmented assignment expression like x += 1 can be
>  rewritten as x = x + 1 to achieve a similar, but not
>  exactly equal effect. In the augmented version, x is only
>  evaluated once.
>
>I don't consider the two results you posted "similar".

It continues
"Also, when possible, the actual operation is performed in-place, meaning 
that rather than creating a new object and assigning that to the target, 
the old object is modified instead. ...Similarly, with the exception of the 
possible in-place behavior, the binary operation performed by augmented 
assignment is the same as the normal binary operations.
"
I take the behavior observed to be the exceptional in-place behavior 
referred to.  But this could certainly be clearer.

Also, Lib Ref  2.3.6.4 Mutable Sequence Types could have a line added to 
the table specifying the the operation 's+=x' is the same as s.extend(x).

Terry J. Reedy



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


Re: pygtk and long running process

2005-04-24 Thread Daniel Cer
Robert wrote:
I have a command line app that can take up to 20 minutes to complete and
every minute or so updates it's status (spits it out to console).  I am
writing a front end for this app in python/gtk and was wondering what
command I use to a) invoke the command and b) how to capture it's out put
and for instance update a text box.
os.popen() will probably do what you want.
e.g.:
import os
some_external_command = "ls"
prog_output = os.popen(some_external_command)
for status_line in prog_output:
print status_line
-Dan
--
http://mail.python.org/mailman/listinfo/python-list


Re: HTML cleaner?

2005-04-24 Thread George Sakkis
Probably you're looking for Beautiful Soup:
http://www.crummy.com/software/BeautifulSoup/

George

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


Parsing data from URL

2005-04-24 Thread Harlin Seritt
I am trying to do the following:



import urllib

url = 'http://www.website.com/file.shtml'
dat = urllib.urlopen(url, 'r').read()
print dat

When I do so, I get the following data:



405 Method Not Allowed

Method Not Allowed
The requested method POST is not allowed for the URL 

Apache/1.3.27 Server at website.com Port 80


How can I make sure that I get the actual html data instead of the data
from redirected URL?

thanks,

Harlin

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


pygtk and long running process

2005-04-24 Thread Robert
Hi,

I have a command line app that can take up to 20 minutes to complete and
every minute or so updates it's status (spits it out to console).  I am
writing a front end for this app in python/gtk and was wondering what
command I use to a) invoke the command and b) how to capture it's out put
and for instance update a text box.

Regards,

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


Re: Decent Win32All Documentation

2005-04-24 Thread Harlin Seritt
Kartic,

Thanks for the help. It's good to get a different perspective on
something (i.e. MSDN, dir() etc).

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


Re: How to "generalize" a function?

2005-04-24 Thread Scott David Daniels
Alexander Schmolck wrote:
[1]  Best practice would be something like this (don't worry to much about it
 -- it just ensures the file is properly closed, even if something goes
 wrong):
confFile = None
try:
confFile = open(networkConf, 'w')
confFile.writelines(conf)
finally:
if confFile: confFile.close()
A clearer equivalent is:
confFile = open(networkConf, 'w')
try:
confFile.writelines(conf)
finally:
confFile.close()
You did not say whether you are looking to replace all, the first,
or the last occurrence of your search target.  Assuming you really
mean all lines and the first occurrence on those lines:
def replaces(source, search, replacement):
'''Replace first of search on lines with replacement'''
pat = re.compile(search)
for line in source:
yield re.sub(pat, replacement, line, 1)
And your application might go like:
input = open(networkConf, 'r')
part1 = replaces(input, 'address', 'ip')
part2 = replaces(part1, 'netmask', 'mask')
result = list(part2)
input.close()
output = open(networkConf, 'w')
try:
output.writelines(result)
finally:
output.close()
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


HTML cleaner?

2005-04-24 Thread Ivan Voras
Is there a HTML clean/tidy library or module written in pure python? I 
found mxTidy, but it's a interface to command-line tool.

What I'm searching is something that will accept a list of allowed tags 
and/or attributes and strip the rest from HTML string.

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


Re: How to "generalize" a function?

2005-04-24 Thread Michael Spencer
Thomas Köllmann wrote:
Hi, everybody!
I'm teaching myself Python, and I have no experience in programming
apart from some years of shell scripting. So, please bear with me.
These two funktions are part of an administrative script I've set
myself as a first lesson, and, as you will see, they're practically the same,
except for one variable. So I'd like to weld them together -- but I
can't find out how to.
def writeIP(ip):
""" IP schreiben """
regex = re.compile('(.*)address(.*)')
This is the only difference between the functions, isn't it?
So, instead of hardwiring 'address' or 'netmask' into the regexp template, you 
should insert it based on an argument passed to the function.  String 
interpolation works well here: e.g.,
 >>> '(.*)%s(.*)' % 'netmask'
 '(.*)netmask(.*)'
 >>>

confFile = open(networkConf, 'r')
conf = confFile.readlines()
confFile.close
Note, here you presumably mean confFile.close() i.e., you must supply the parens 
to call the function.

[snip]
I feel it should be possible to use something like
def writeFile(ip,keyword):
...
Indeed.  Use keyword as the argument to the string interpolation
 >>> regex = re.compile('(.*)%s(.*)' % keyword)
but how would I construct expressions like
netmaskLineNum = conf.index(netmaskLine)
I think these should work unchanged.  But it would be easier to read if you 
changed these names to be neutral to the application e.g., instead of 
netmaskLine, foundLine

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


Re: Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you are, nor if you are a church member, but are you saved? Are you sure you will go to Heaven when you die? GOOGLE·NEWSGROUP·POST·149

2005-04-24 Thread Please
Reports to [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED],
[EMAIL PROTECTED], [EMAIL PROTECTED]

And do not feed the troll!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to "generalize" a function?

2005-04-24 Thread Alexander Schmolck
Thomas Köllmann <[EMAIL PROTECTED]> writes:

> confFile.close

You want ``confFile.close()`` -- the above won't do anything [1].

'as


Footnotes: 
[1]  Best practice would be something like this (don't worry to much about it
 -- it just ensures the file is properly closed, even if something goes
 wrong):

confFile = None
try:
confFile = open(networkConf, 'w')
confFile.writelines(conf)
finally:
if confFile: confFile.close()






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


Re: How to "generalize" a function?

2005-04-24 Thread Dan Sommers
On Sun, 24 Apr 2005 23:40:22 +0200,
Thomas KÃllmann <[EMAIL PROTECTED]> wrote:

> Hi, everybody!
> I'm teaching myself Python, and I have no experience in programming
> apart from some years of shell scripting. So, please bear with me.

> These two funktions are part of an administrative script I've set
> myself as a first lesson, and, as you will see, they're practically
> the same, except for one variable. So I'd like to weld them together
> -- but I can't find out how to.

[ two very similar functions snipped ]


> I feel it should be possible to use something like

> def writeFile(ip,keyword):
> ...

Absolutely.

> but how would I construct expressions like

> netmaskLineNum = conf.index(netmaskLine)

> in that case (netmask being the keyword here)?

netmaskLineNum and addressLineNum are just names.  They may mean
something to you and to people who read your program, but they mean
nothing to Python.  So just use generic names:

for line in conf:
if regex.search( line )
theLine = line
theLineNum = conf.index( theLine )

etc.

HTH,
Dan

-- 
Dan Sommers

Îâ à Îâ à c = 1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting into Python, comming from Perl.

2005-04-24 Thread Steve Holden
Miguel Manso wrote:
Mike Meyer wrote:
Miguel Manso <[EMAIL PROTECTED]> writes:
 

I've tryed to use python some times but I get frustrated very quick. I
get myself many times needing to figure out how to loop through a
list, declare an associative array, checking how to pass named
parameters to functions, and simple things like that.
   

I went through some of those frustrations.
 

What I would like to know is if anyone had these problems and if you
can share that experience with me. I'm trying to minimize my
"frustration" :)
   

The thing is, the answers to all your questions are in the
documentation. You just need to know the Python names for things, and
not the Perl names. For instance, Python calls it's associative array
structure a dictionary, and a checking the documentation index for
dictionary turns up a link to the syntax for declaring one as
display/dictionary.
Read through the tutorial. Then look through some "interesting"
modules in the standard library to see how these things fit together.
   
 

I guess I'll just do that. I'll put the frustration in a bag, grab the 
documentation and try to figure it out.

Thanks all.
And, when the frustration returns, ask questions on c.l.py or the tutor 
list. By and large we don;t bite here, and the tutor list is 
particularly newbie-friendly, though with your Perl experience *that* 
may not be as appropriate.

regards
 Steve
--
Steve Holden+1 703 861 4237  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-24 Thread Mike Meyer
John Bokma <[EMAIL PROTECTED]> writes:

> Mike Meyer wrote:
>> John Bokma <[EMAIL PROTECTED]> writes:
>>> Mike Meyer wrote:
 Depends on the problem. If it's one of the things for which Python
 has an obvious solution (sort a list; split a string on whitespace;
 pull select list elements based on a criteria of some kind; search a
 file for lines with a given word in them; etc.) you'd get back the
 same answer from almost all of them.
>>> And what makes you doubt it would be different with Perl? :-D
>> Perl's "There's more than one way to do it" attitude.
> There's doesn't mean that you have to use or know them all. I think 
> every language here and there more ways to do something. And at a 
> broader scope, e.g. a simple algorithm, it doesn't matter that much 
> anymore.

Except that, as I said elsewhere, that having more than one way to do
it bloats the language processor and increases the semantic load on
the programmer. The best the programmer can do, as you imply, is to
ignore the extraneous methods. Then the poor programmer has to puzzle
over them every time they show up in someone else's code.

>>> ( sort @alist, split ' ', $astring, grep criteria, @list, etc )
>> In the one case where perl provides you two ways to do things, you
>> chose the one that doesn't solve the problem. You want map, not grep.
> You think? Please read perldoc -f grep (and map).

I did, and could have sworn that grep modifed the list in place. Mia
culpa.

>> You also chose the wrong way to do things globally, by leaving off the
>> optional parens on the function invocations. That makes the list a
>> PITA to parse,

> First of all, who cares? Not the programmer.

Of course the programmer doesn't care. They jyust have to deal with it
for the rather short development period. The *maintainer* cares,
though - as they have to deal with it for the life of the program.

> But I doubt if you are  correct; why is 
> OP PARAMETER, LIST
> a PITA to parse, and
> OP( PARAMETER, LIST )
> not? I would even say that the former is easier to parse, since there is 
> no need for checking the ( and ) (and matching them).

Look at the *context*. You wrote

word word, word word, word, word word, word, word.

Unless you know what the words mean, this is nearly impossible to
parse out into proper perl expressions. Putting in the parens makes
it:

word(word, word), word(word, word), word(word, word), word.

This is trivial to parse into perl expressions without having to know
the meaning of any of the words.

>> in that you have to know the number of arguments to
>> each function in order to parse the list you provided.
>
> It has been a while since I wrote a lexer, but uhm, you set up a rule?
>
> LIST := ITEM
> LIST := LIST,ITEM

Right. So is

item, item, item, item

one list or two seperated by an English-level comma?

> (I made up the syntax, but I guess it's clear)
>
>> Consider the python version:
>> 
>>  (alist.sort(), astring.split(), [x for x in alist if
>>  criteria(x)])
>
> ( told you it was grep ;-) )
>  
>> This list can be parsed by a machine. Given proper bindings for all
>> the variables, Python will turn it into a tuple.
>
> What makes you think a machine can not parse Perl? I didn't get a Larry 
> Wall with my version of Perl :-D 

What would it take to get Perl to parse the line you typed in?

>> N.B.: split(' ', $astring) is wrong as well. In this case, Perl
>> doesn't provide the right tool for the job; you have to build it from
>> parts.
> You either misread your own problem specifications, or you should read 
> perldoc -f split (near the end, it starts with "As a special case," )

No, I missed the wart hiding under the "special case". How, pray tell,
do you do the equivalent of Python's string.split(' ') in Perl?

>> And those trivial variations are enough that you chose the wrong
>> ones. And you're (by your own admission) an experienced Perl
>> programmer.
> And you don't even come close :-D.

No, one I blew. One you still got wrong.

>>> One could say (and should) that the regular expression thingy in Perl
>>> is a language on its own :-)
>> 
>> It is. For what Perl was designed for, having that be part of the
>> grammar of the language makes sense. For a general-purpose programming
>> language, I'm not so sure.
>
> Same could be said of floating point numbers, or complex numbers, or 
> lists, dictionaries, etc. etc.

Right. And for each of those, there are languages that don't have them
as a built in type.

>>> But you probably agree, that if speed is an issue, and the
>>> programmer's skills are not the issue, that the only thing one can do
>>> is code it in a different language (probably by another programmer).
>> 
>> I don't agree. The better alternative is to look for a faster
>> algorithm.
>
> "The programmer's skills are not the issue"

Good point. I should have skipped the whole thing, as the programmers
skills are *never* not the issue.

> [ skilled Perl programmers use similar or sa

Re: Python or PHP?

2005-04-24 Thread Steve Holden
Leif Biberg Kristensen wrote:
Leif K-Brooks skrev:

But Python's DB-API (the standard way to connect to an SQL database
from Python) makes escaping SQL strings automatic. You can do this:
cursor.execute('UPDATE foo SET bar=%s WHERE id=%s', ["foo'bar", 123])

So. I've been writing SQL queries in Python like this, using PostgreSQL
and psycopg:
cursor.execute("select * from foo where bar=%s" % baz)
Is that wrong, and how should I have been supposed to know that this is
bad syntax? No doc I have seen actually has told me so.
It's *wrong* for some value of "wrong" - it does potentially introduce a 
SQL injection vulnerability into your code.

Suppose I provide as input into the baz variable
1; drop table foo
Your statement then becomes
select * from foo where bar=1; drop table foo
which is clearly not such a good idea. More sophisticated attackes are 
possible, but this gives you the idea.

regards
 Steve
--
Steve Holden+1 703 861 4237  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting into Python, comming from Perl.

2005-04-24 Thread Ivan Voras
Mage wrote:
foo = dict()
or:
foo = {}
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-24 Thread Ville Vainio
> "John" == John Bokma <[EMAIL PROTECTED]> writes:

>> Nah, they aren't slow. They just have to worry about more things than
>> the Python developers.

John> Do you have references to this? I would love to see if
John> indeed 100 Python programmers do implement, say 5 CS tasks
John> faster compared to 100 Perl programmers, on average.

I am quite sure that given random sample of python and perl
programmers, the python programmers would be faster. Less thinking is
necessarily, no $ chars and generally less punctuation to worry about,
no error handling needed (exceptions take care of it automatically).

I would also venture to guess that random (adult) Python programmers
would be of higher skill level as far as programming in general goes
(know more languages, have a "good taste"...).

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


kickoff -- wikalong documentation for Python

2005-04-24 Thread Steve
I've kicked off wikalong documentation for Python by adding an example
program to the documentation for the HTMLParser module. See
http://python.org/doc/current/lib/module-HTMLParser.html

(Generally, I think most wikalong annotations won't take the form of
complete example programs, but this was an entry that I thought could
use one.)

For more information about Wikalong, see http://www.wikalong.org/.  If
you haven't played with Wikalong yet, I urge you to investigate it.
Wikalong basically allows you to annotate any URL.  With Wikalong and
the Python docs, Pythonistas can experiment with annotatable Python
documentation (and ride the leading edge of the Wikalong wave).

Thanks to Aahz for identifying http://python.org/doc/current/ as the
best candidate for official URL of the current version of the docs. For
more information, see the thread at
http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/96fb7f21014d7a16/430b6e32bd3c4a64?q=ferg+wikalong&rnum=1#430b6e32bd3c4a64

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


Re: Variables

2005-04-24 Thread Rocco Moretti
Richard Blackwood wrote:
Robert Kern wrote:
His problem is that he doesn't respect that technical terms can have 
different meanings in different fields and contexts. No authoritative 
reference can solve his problem for him. He's being overly pedantic 
about a field in which *he* is clearly not an authority. You can't 
convince such people, only ignore them.

Unfortunately that's not much of an option for me. We are working on a 
project together so I am forced to either prove his notion incorrect or 
I give in to his conception. *throws hands in air*
Why are *you* the one that his notion is incorrect? Why isn't he the one 
that has to prove *you* incorrect? Put forth the Wikipedia article, and 
then the ball is in his court to disprove the arguments therein with a 
more authoritative source. (At least this is my understanding of the 
common rules of debate.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Object oriented storage with validation (was: Re: Caching compiled regexps across sessions (was Re: Regular Expressions - Python vs Perl))

2005-04-24 Thread Ville Vainio
> "Ilpo" == Ilpo NyyssÃnen  writes:

Ilpo> Pickle doesn't have validation. I am not comfortable for
Ilpo> using it as storage format that should be reliable over
Ilpo> years when the program evolves. It also doesn't tell me if

That's why you should implement xml import/export mechanism and use
the xml file as the "canonical" data, while the pickle is only a cache
for the data.

Ilpo> How can it work automatically in separate module? Replacing
Ilpo> the re.compile with something sounds possible way of getting
Ilpo> the regexps, but how and where to store the compiled data?
Ilpo> Is there a way to put it to the byte code file?

Do what you already did - dump the regexp cache to a separate file. 

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bounding box on clusters in a 2D list

2005-04-24 Thread bearophileHUGS
[EMAIL PROTECTED]:
> hi Bearphile! That really gives me an idea.Thanks much for that. Yes
as
> you said the algorithm reaches a maximium recursion depth for larger
> sets i tried.

You can improve the little flood filling function, avoiding the "bad"
Python recursivity.


> Do you see where I am heading

Your problem still looks a bit ill defined to me (see Bengt Richter's
nested boxes case), but you can probably modify this part of my
connected():

.   freq = {}
.   for row in m:
. for e in row:
.   if e in freq:
. freq[e] += 1
.   else:
. freq[e] = 1

For the *values* of the freq dictionary you can use the 4 coordinates
of the bounding box of the key-specific cluster, that is updating its
far left, far right, etc. coordinates, with something like this:

box[e] = ( max(x, box[e][0]), min(x, box[e][1]), max(y, box[e][2]),
min(y, bbox[e][3] )

Or something faster/more correct. It's not difficult, I presume.
(connected() debug: if you want to keep the original matrix m, at the
end of the connected() you can set at 1 all its values different from
0.)

Bear hugs,
Bearophile

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


Re: Python or PHP?

2005-04-24 Thread Rocco Moretti
Roman Neuhauser wrote:
# [EMAIL PROTECTED] / 2005-04-23 15:53:17 +0200:
Lad wrote:

Is anyone capable of providing Python advantages over PHP if there are
any?
The irreverant would point you to 
http://www.python.org/doc/Humor.html#vowels

*I* wouldn't consider doing anything like that, though. 
check this: http://wiki.w4py.org/pythonvsphp.html
The comparison found there is biased, the author is a Python
partisan.
Yeah, as opposed to the completely unbiased opinions the OP expected to 
find on comp.lang.PYTHON
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bounding box on clusters in a 2D list

2005-04-24 Thread Bengt Richter
On 24 Apr 2005 09:44:49 -0700, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

>Richter,yes what I am looking for is for cluster with rectangular
>bounding boxes as you explained in the first figure.
>
Sorry, not your fault, but I'm still not clear on diagonal 
connection/separation.
E.g., (removing punctuation ;-) is this 3 boxes or do the top left and bottom 
right
connect at their touching corners and thus become bounded with a rectangle that 
then
also includes the little box at the top right?

  +---+   +---+
0 | 1   1 | 0 | 1 |
  |   |   +---+
0 | 1   1 | 0   0
  +---+?--+
0   0   0 ? 1   1 |
  |   |
0   0   0 | 0   1 |
  +---+

  +---+   +---+  +---+???+---+   +---+  
0 | 1   1 | 0 | 1 |0 | 1   1 | 0 | 1 | 0 | 1   1   0   1 |  
  |   |   +---+  |   |   +---+   |   |  
0 | 1   1 | 0   0  0 | 1   1 | 0   0 ? 0 | 1   1   0   0 |  
  +---+?--+ =>   |   +---+  =>   |   |  
0   0   0 ? 1   1 |0 | 0   0   1   1 | 0 | 0   0   1   1 |  
  |   |  |   |   |   |  
0   0   0 | 0   1 |0 | 0   0   0   1 | 0 | 0   0   0   1 |  
  +---+  +---+   +---+  

And what about nested boxes?

   +---+  
 0 | 1   1   1   1  1  |  
   |   |  
 0 | 1   0   0   0  1  |  
   |   +---+   |  
 0 | 1   0 | 1 | 0  1  |  
   |   +---+   |  
 0 | 1   0   0   0  1  |  
   |   |  
 0 | 1   1   1   1  1  |  
   +---+  

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


Re: Getting into Python, comming from Perl.

2005-04-24 Thread Miguel Manso




Mike Meyer wrote:

  Miguel Manso <[EMAIL PROTECTED]> writes:

  
  
I've tryed to use python some times but I get frustrated very quick. I
get myself many times needing to figure out how to loop through a
list, declare an associative array, checking how to pass named
parameters to functions, and simple things like that.

  
  
I went through some of those frustrations.

  
  
What I would like to know is if anyone had these problems and if you
can share that experience with me. I'm trying to minimize my
"frustration" :)

  
  
The thing is, the answers to all your questions are in the
documentation. You just need to know the Python names for things, and
not the Perl names. For instance, Python calls it's associative array
structure a dictionary, and a checking the documentation index for
dictionary turns up a link to the syntax for declaring one as
display/dictionary.

Read through the tutorial. Then look through some "interesting"
modules in the standard library to see how these things fit together.




I guess I'll just do that. I'll put the frustration in a bag, grab the
documentation and try to figure it out.

Thanks all.

-- 
Miguel Manso <[EMAIL PROTECTED]>

Amplitude Net
Net - Rua dos Salazares, 842
4100-442 Porto

Phone: +351 22 532 2000
Fax: +351 22 618 2157
Web: www.amplitudenet.pt



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

Re: Using Ming on Windows

2005-04-24 Thread Do Re Mi chel La Si Do
Hi !

You can to generate SWF (flash) files, with swfobjs.dll

See :
   http://bukoo.sourceforge.net
and
   http://www.angelfire.com/nt/teklord/swfexport.htm


I succeeded, therefore, it is easy...


Michel Claveau



 


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


Re: Variables

2005-04-24 Thread Jeremy Bowers
On Sat, 23 Apr 2005 22:45:14 -0400, Richard Blackwood wrote:
> Indeed, this language is math. My friend says that foo is a constant and
> necessarily not a variable. If I had written foo = raw_input(), he would
> say that foo is a variable. Which is perfectly fine except that he insists
> that since programming came from math, the concept of variable is
> necessarily the identical.

"The" concept? *snort* Your friend knows not of what he speaks.

Ask him if parallel lines cross. Then ask him if he has any right to get
snotty about terminology like that.

If he hasn't got far enough into math to understand why that question is
relevant, then he hasn't got far enough into math to opine on what a
"variable" is, anyhow. (By the way, if he says "no", and not "it depends
on your axiom choice", the same is true.)

(By math, are we talking *real* math like number theory or set theory,
something involving proofs, or high-school algebra that deals in numbers
and mere arithmetic? I rather suspect the latter, in which case you may
tell your friend y'all are so far out of your league you can't even tell
how far out you are. Nobody who has studied number theory or alternate
geometries or anything like real math could have this conversation, unless
they *really* missed the point of, well, everything they've done up to
that point...)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting into Python, comming from Perl.

2005-04-24 Thread Mike Meyer
Miguel Manso <[EMAIL PROTECTED]> writes:

> I've tryed to use python some times but I get frustrated very quick. I
> get myself many times needing to figure out how to loop through a
> list, declare an associative array, checking how to pass named
> parameters to functions, and simple things like that.

I went through some of those frustrations.

> What I would like to know is if anyone had these problems and if you
> can share that experience with me. I'm trying to minimize my
> "frustration" :)

The thing is, the answers to all your questions are in the
documentation. You just need to know the Python names for things, and
not the Perl names. For instance, Python calls it's associative array
structure a dictionary, and a checking the documentation index for
dictionary turns up a link to the syntax for declaring one as
display/dictionary.

Read through the tutorial. Then look through some "interesting"
modules in the standard library to see how these things fit together.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-24 Thread Bruno Desthuilliers
Lad a trollé :
Is anyone capable of providing Python advantages over PHP if there are
any?
Why don't you check by yourself ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-24 Thread Bruno Desthuilliers
Mage a écrit :
I can tell:
- python is more *pythonic* than php
Keyboard !-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is this a bug?

2005-04-24 Thread Michael Sparks
[EMAIL PROTECTED] wrote:

> when you use a = a + 'world'  python sees it as an error because of
> different type.
> 
> But when you use a += 'world'
> python will change the right into list (because a is a list). So when
> you're code become:
> a += 'world' # a += list('world')
> 
> It really helpful if you stick to use append instead of += when you
> operate list

This was part of a test case I expected to fail. I was surprised when it
passed. Passing caused a latent bug, which I fixed, and I'm preventing it's
re-occurrence by changing the way the test is written.

The value that was being updated is expected to be a _string_. However it
had the possibility of being a list of strings , *if* the code was not
making appropriate checks. The test was intended to detect that failure in
the code. The fact that f += foo succeeded where f = f + foo would fail
masked a bug. It was rewritten around moments after I discovered this, but
it struck me as rather odd.

Based on this comment from the language reference posted by Grant I'd
personally consider it to be a bug...

ÂÂ"AnÂaugmentedÂassignmentÂexpressionÂlikeÂxÂ+=Â1ÂcanÂbe
ÂÂrewrittenÂasÂxÂ=ÂxÂ+Â1ÂtoÂachieveÂaÂsimilar,ÂbutÂnot
ÂÂexactlyÂequalÂeffect.ÂInÂtheÂaugmentedÂversion,ÂxÂisÂonly
ÂÂevaluatedÂonce."

(I don't consider one operation succeeding and other other throwing an
exception to be similar effects)

Whilst I understand the explanations given (expected them as my post
indicated), the above comment is the one that clinches it for me.

(I also agree for example that it's good that extend takes any iterable for
example, but a PITA that += maps to extend)

That said, the bug reference mentioned above was closed with the leading
comment:

"""I think Guido said if he had it to do over, += would not be
able to take any iterable. However, that behavior has been
set in stone for several years now and it would be hard to
take away."""

   
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=848812&group_id=5470

I'm now wondering whether it should be posted as a bug, if it's not likely
to be solved short of Python 3000. (ie whether I should just consider it a
wart instead... :)

(If that's really the case I'd happily consider writing a doc patch as a
warning about the behaviour)


Michael.

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


Re: opening new window in one window using Tkinter -- Help please

2005-04-24 Thread Clara
since the file where i call the first window and the second window is
different,.If I put app.master.withdraw() there,...won't I get error
message that says; app is not defined as global or something like that?

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


Re: opening new window in one window using Tkinter -- Help please

2005-04-24 Thread Fredrik Lundh
"Clara" wrote:

> Well, but where do I call withdraw?

when you want the new window to appear, and the old one to
go away, of course.  something like this, perhaps?

  from mainmenu import FileManager
  app2 = FileManager(self.username.get())
  app2.master.title("File Manager")
  app2.master.maxsize("400,1500")
- app2.mainloop()
+ app.master.withdraw()





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


Re: opening new window in one window using Tkinter -- Help please

2005-04-24 Thread Clara
Forgive my ignorance, but where do I call withdraw?

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


Re: opening new window in one window using Tkinter -- Help please

2005-04-24 Thread Clara
Well, but where do I call withdraw?

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


Re: filename used by shelve

2005-04-24 Thread Fredrik Lundh
"Nemesis" <[EMAIL PROTECTED]> wrote:

> So the real filename may be different from the argument passed to
> "open". I have this problem, I want to delete (in some circustances) the
> file created by shelve.open, how can I know which is the name of this
> file (or files) ?

if you put the shelve in a subdirectory, and nuke the entire directory when
done, you don't have to know the names.

dbfile = "mydatabase"
if not os.path.isdir(dbfile):
os.makedirs(dbfile)
db = shelve.open(os.path.join(dbfile, "data"), ...)

...

db.close()
del db

...

shutil.rmtree(dbfile)





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


Re: when will the file be closed

2005-04-24 Thread Fredrik Lundh
"Mage" <[EMAIL PROTECTED]> wrote:

> The question is above: when will these file be closed?
>
> for s in file('/etc/passwd'):
> print s
>
> file('/home/mage/test.txt','w').write('foo')

when the interpreter gets around to it.

if you want to make sure that a file is closed at a given point in
your program, you have to close it yourself.

for more on this, read the fine manual:

http://docs.python.org/ref/objects.html





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


Re: opening new window in one window using Tkinter -- Help please

2005-04-24 Thread Fredrik Lundh
"Clara" wrote:

> I meant to write an application where there is a button in a window and
> when you click on the button, it will open a new window, but I want the
> first window to close, replaced by the second window.
> I open a login window and start the mainloop, when the user click on
> the login button, the __call__ function of VerifyProcessor is executed
> and it will call the new window which is the file manager window
> The thing is,.. I don't know how to exit the first mainloop and then
> display the second window...I even tried calling the mainloop again but
> a weird thing happens. I really need help because otherwise I'm stuck
> here and I can't complete my assignment. The following is my code:

you don't really have to start a new mainloop to create a new toplevel
window.  just call "withdraw" on first window, and create the second
(as a Toplevel), and Tkinter will take care of the rest.





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


Re: Getting into Python, comming from Perl.

2005-04-24 Thread Fredrik Lundh
Miguel Manso wrote:

> I've tryed to use python some times but I get frustrated very quick.  I
> get myself many times needing to figure out how to loop through a list,

http://docs.python.org/tut/node6.html#SECTION00620

> declare an associative array,

http://docs.python.org/tut/node7.html#SECTION00750

> checking how to pass named parameters to functions,

http://docs.python.org/tut/node6.html#SECTION00672

I suggest spending 30 minutes to read through chapters 1-7 of the tutorial
again.
(when you've tinkered a little more, read chapters 8-11).  getting a good
Python
book could also help.





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


when will the file be closed

2005-04-24 Thread Mage
   Hello,

The question is above: when will these file be closed?

for s in file('/etc/passwd'):
print s

file('/home/mage/test.txt','w').write('foo')

   Mage


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


Re: Getting into Python, comming from Perl.

2005-04-24 Thread Mage
Miguel Manso wrote:

>
>
> I've tryed to use python some times but I get frustrated very quick. I
> get myself many times needing to figure out how to loop through a
> list, declare an associative array, checking how to pass named
> parameters to functions, and simple things like that.

list = [3,5,9,11]
list.append(17)
for i in list:
print i

foo = dict()
foo['bar'] = 7
foo['trooll'] = 'green'

for k,v in foo.iteritems():
print k, v

def test(**args):
for key in args.keys():
print key, args[key]

test(a='apple', c='orange')

   Mage

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


filename used by shelve

2005-04-24 Thread Nemesis
In the python docs about shelve module I read:

-
 open( filename[,flag='c'[,protocol=None[,writeback=False[,binary=None)
Open a persistent dictionary. The filename specified is the base filename 
for the underlying database. As a side-effect, an extension may be
added to the filename and more than one file may be created.
-

So the real filename may be different from the argument passed to
"open". I have this problem, I want to delete (in some circustances) the
file created by shelve.open, how can I know which is the name of this
file (or files) ?

-- 
I'm not a complete idiot - several parts are missing.
 
 |\ |   |HomePage   : http://nem01.altervista.org
 | \|emesis |XPN (my nr): http://xpn.altervista.org

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


Re: Variables

2005-04-24 Thread Kirk Job Sluder
Richard Blackwood <[EMAIL PROTECTED]> writes:

> Bengt Richter wrote:
> 
> >Tell him in Python foo is a member of one set and 5 is a member of another,
> >and foo = 5 expresses the step of putting them into correspondence
> >to define a mapping, not declaring them equal.
> >
> Could I honestly argue this to him? From what basis do I argue that it
> is not an equation? In any event, he would likely (passionately)
> disagree considering his notion that programming is an off-shoot of
> math and thus at the fundamental level has identical concepts and
> rules. Believe it or not, he used to be a programmer. Back in the day
> (while I was getting my PhD in philosophy), he was a employed
> programmer using Cobol, Fortran, and other languages like that. Did
> his seemingly peculiar definition of variable exist at that time?

Because, this is shorthand that operates at quite a bit of a higher
level than the mathematical roots of a programming language.  Here is a
peek of what is going in when foo = 5 is evaluated.

create an anonymous int object
set the value of that object to 5 
create a symbol foo 
bind the location the anonymous object to symbol foo






> 
> >Even in math notation, ISTM important to distinguish between
> >a finger and what it may for the moment be pointing at.
> >
> >Regards,
> >Bengt Richter
> >
> 

-- 
Kirk Job-Sluder
"The square-jawed homunculi of Tommy Hilfinger ads make every day an
existential holocaust."  --Scary Go Round
-- 
http://mail.python.org/mailman/listinfo/python-list


opening new window in one window using Tkinter -- Help please

2005-04-24 Thread Clara
Hi,...
I meant to write an application where there is a button in a window and
when you click on the button, it will open a new window, but I want the
first window to close, replaced by the second window.
I open a login window and start the mainloop, when the user click on
the login button, the __call__ function of VerifyProcessor is executed
and it will call the new window which is the file manager window
The thing is,.. I don't know how to exit the first mainloop and then
display the second window...I even tried calling the mainloop again but
a weird thing happens. I really need help because otherwise I'm stuck
here and I can't complete my assignment. The following is my code:

from login import LoginMenu
app = LoginMenu()
app.master.title("Login Menu")
app.master.maxsize(300,200)
app.mainloop()
==
class LoginMenu(Frame):

def createWidgets(self):
 self.loginButton = Button(self, text='Login', command =
VerifyProcessor(self.x, self.y, self.msg, self.messageLabel) )

def __init__(self, master=None):
Frame.__init__(self, master)
self.grid(column=6, row=4)
self.createWidgets()

class VerifyProcessor:

def __init__(self, thename, thepass, msg, msglabel):
self.username = thename
self.password = thepass
self.msgVar = msg
self.msgLabel = msglabel

def __call__(self):
import md5
import dictionaryloader
found = 0
theDict = dictionaryloader.loadFrom("Dicttxt")
entries = theDict.items()
for theuser, thepass in entries:
if self.username.get() == theuser and
md5.new(self.password.get()).hexdigest() == thepass:
found=1
from mainmenu import FileManager
app2 = FileManager(self.username.get())
app2.master.title("File Manager")
app2.master.maxsize("400,1500")
app2.mainloop()
=
class FileManager(Frame):

def createWidgets(self, username):
   ...
def __init__(self, username, master=None):
Frame.__init__(self, master)
self.grid(column=6, row=6)
self.createWidgets(username)
==

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


Re: Getting into Python, comming from Perl.

2005-04-24 Thread Michael Soulier
On 4/24/05, Miguel Manso <[EMAIL PROTECTED]> wrote:
> I'm a programmer with 5 year of experience into Perl. I'm on that point
> where you resolve problems without thinking on HOW you'll do it with
> that language but only on the problem itself.

I code in perl and C all day. Python is a very nice escape for me.

> Since Perl 6 started I've been following it. The conclusion I have is
> they're making a whole new language and I'll have to learn it. This
> being said and, since I've to learn a new language, I've started
> thinking in a new language. I've noticed Python is getting more and more
> developers and many projects are being made.

Perl6 seems to be taking its best features from Python, so I'll just
cut through the middle-man. ;-)

> I've tryed to use python some times but I get frustrated very quick. I
> get myself many times needing to figure out how to loop through a list,
> declare an associative array, checking how to pass named parameters to
> functions, and simple things like that.
> 
> What I would like to know is if anyone had these problems and if you can
> share that experience with me. I'm trying to minimize my "frustration" :)

Sure, happens, but it happens with any new languages. Keep using it,
and you'll get over it.

Mike

-- 
Michael P. Soulier <[EMAIL PROTECTED]>
http://www.digitaltorque.ca
http://opag.ca  python -c 'import this'
--
http://mail.python.org/mailman/listinfo/python-list


Re: Variables

2005-04-24 Thread Kirk Job Sluder
Richard Blackwood <[EMAIL PROTECTED]> writes:

> Unfortunately that's not much of an option for me. We are working on a
> project together so I am forced to either prove his notion incorrect
> or I give in to his conception. *throws hands in air*

Well, one option is to give in to his conception and point out that if
you are working in python, foo=5 is neither a true constant or a
variable.  foo is an object reference pointing to an anonymous object
with the value 5.

Another way around it is to point out that while the use of the term
"variable" in this sense may not be technically correct in terms of
maths, it is the accepted jargon in the python community.  Other
programming communities may use different terms to describe values that
change and values that don't change.

A third way around this is to use this to your advantage and point out
that python does not have a mechanism for distinguishing varibles from
constants, so settle on some syntactic sugar to make the differences
clear in your code.  

-- 
Kirk Job-Sluder
"The square-jawed homunculi of Tommy Hilfinger ads make every day an
existential holocaust."  --Scary Go Round
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting into Python, comming from Perl.

2005-04-24 Thread Miguel Manso
Hi, list.
I'm into a psicological doubt that I would like to share with you 
(you'll know why later on this mail).

I'm a programmer with 5 year of experience into Perl. I'm on that point 
where you resolve problems without thinking on HOW you'll do it with 
that language but only on the problem itself.

Since Perl 6 started I've been following it. The conclusion I have is 
they're making a whole new language and I'll have to learn it. This 
being said and, since I've to learn a new language, I've started 
thinking in a new language. I've noticed Python is getting more and more 
developers and many projects are being made.

I've tryed to use python some times but I get frustrated very quick. I 
get myself many times needing to figure out how to loop through a list, 
declare an associative array, checking how to pass named parameters to 
functions, and simple things like that.

What I would like to know is if anyone had these problems and if you can 
share that experience with me. I'm trying to minimize my "frustration" :)

Thanks a lot.
--
Miguel Manso <[EMAIL PROTECTED]>

Amplitude Net
Net - Rua dos Salazares, 842
4100-442 Porto
Phone: +351 22 532 2000
Fax: +351 22 618 2157
Web: www.amplitudenet.pt

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


Re: Rudeness on this list [Re: rudeness was: Python licence again]

2005-04-24 Thread Ivan Van Laningham
Hi All--

James Stroud wrote:
> 
> On Sunday 24 April 2005 06:59 am, so sayeth François Pinard:
> > As seen from here, the Python mailing list quality has been degrading
> > significantly for the last half-year or so.
> 
> That's funny. That's exactly as long as I've been on this list. I wonder if
> the correlation is causal?
>

Nope.  I've been MIA 4 years, and the only difference I can see between
now and four years ago is that Tim, Guido, Barry & a couple of others
aren't here or don't participate very much.  It was a pretty nice list
then, it's a pretty nice list now, so I'm afraid I must disagree with
François.

Oh, and Gordon.  Don't see Gordon around.  Where's he?

Metta,
Ivan
--
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Variables

2005-04-24 Thread Kirk Job Sluder
Richard Blackwood <[EMAIL PROTECTED]> writes:

> Fantastic, wikipedia deals precisely with the difference between
> variables in mathematics versus programming. However, he would never
> trust a definition from such an "unreputable" source. If you have any
> other sources I might direct him to...he maintains that the notion of
> foo being a variable where it's value is known (versus unknown) is
> illogical.

The ways in which language is used between domains is rarely logical.

-- 
Kirk Job-Sluder
"The square-jawed homunculi of Tommy Hilfinger ads make every day an
existential holocaust."  --Scary Go Round
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Variables

2005-04-24 Thread James Stroud
On Saturday 23 April 2005 10:25 pm, so sayeth Richard Blackwood:
> Unfortunately that's not much of an option for me. We are working on a
> project together so I am forced to either prove his notion incorrect or
> I give in to his conception. *throws hands in air*

This is a communcication issue. You guys probably need a relationship couselor 
or something. I think you should both agree on a common vocabulary and use 
that. Usually the "bigger" individual makes the most concessions in these 
areas, but then the "bigger" individual is usually meant for greater 
callings.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Variables

2005-04-24 Thread Donn Cave
Quoth Mike Meyer <[EMAIL PROTECTED]>:
...
| He's right - programming is an offshoot of mathematics. It adds
| *dynamics* to the structures of mathematics. In mathematics, a
| construct (graph, function, mapping, set, whatever) is immutable. You
| can talk about things that change with time, but you do so with a
| function f(t) that describes the changes to the thing over time - and
| *that* function is immutable. You can say that it isn't time that's
| changing, but frobnitz, with the same function describing the change -
| and you get the same structures that you got with time.
|
| This change causes a fundamental change in the way practitioners
| *look* at objects. Which is visible as a change in the
| vocabulary. Yes, you can talk about programming with the vocabulary of
| mathematics. But that's like dancing about architecture (*).

There's a school of thought that holds this to be kind of an offshoot
of programming, too, albeit a dominant one at present.  In a "pure"
functional programming language like Haskell for example, the "="
operator is equational in about the same way as it is in mathematics.

Even Haskell's equivalent of "foo = raw_input()", the notation that
appears to create a variable is strictly bound to an underlying system
of functions and equations that preserves this equational property,
and maybe for the sake of harmony between mathematicians this system
could be applied to Python's semantics to show how it works in these
terms.  I guess it couldn't be done without some hand-waving, due to
non-functional structures like loops, but those are just details.

So here's a tiny Haskell example that reads a line from input and
prints it out with quotes around it:

   module Main (main) where
   main = do
   line <- getLine
   putStrLn (show line)

"main" is (=) a function that can be executed with that result.
This executability is a property of the "IO Monad", and this
function has that type -- main :: IO () -- but that's more than
we need to know for the present purposes.  The point is that
this "do" structure looks like a statement syntax, but it's
strictly equivalent to another more functional notation

   main = getLine >>= (\line -> putStrLn (show line))

Haskell's lambda syntax: \ arg -> expression.  You could read this
aloud as "bind getLine to a lambda function with one parameter ..."
and the result is a functional relation that can be executed.
Each step binds a function to a lamba that forms the entire rest
of the "do" block, not just the next step -- it's a nested sequence,
not a linear one.

So I'm proposing that Python's = operator is like Haskell's "<-",
and "foo = 5" is conceptually like "bind 5 to a lambda with one
argument "foo" implementing the rest of the procedure body."  The
confusion is not because foo needs to be so different, it's that
Python "=" is not at all math "=".

Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Variables

2005-04-24 Thread Kirk Job Sluder
Richard Blackwood <[EMAIL PROTECTED]> writes:

> Kent Johnson wrote:
> That is exactly how I feel about it. Foo is what it is. Variable, name
> bound to immutable value, etc., what we call it doesn't really change
> how I program, only how I communicate with other programmers (and
> mathematicians). Is the notion of variable not a fundamental concept
> in programming?  Surely there must be an unambiguous definition I can
> relay to him.

Well, if you want to be precise, in python Foo is a pointer that holds
the memory location of an object, that just happens to be int(5). Which
is one of the key differences between computer languages and
mathematics.  The value of a variable does not necessarily have meaning
as a number, but can be a character, string, or reference instead.  If I
say, foo = 'a', then in most cases I'm not really concerned about the
numeric sum of foo + 'b'.

But the argument at stake here is not technical, but linguistic.  If he
insists on imposing a definition from the domain of math onto the domain
of computer programming, then there is no point in continuing the
discussion about how the term "variable" is used in computer programming.  

-- 
Kirk Job-Sluder
"The square-jawed homunculi of Tommy Hilfinger ads make every day an
existential holocaust."  --Scary Go Round
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rudeness on this list [Re: rudeness was: Python licence again]

2005-04-24 Thread James Stroud
On Sunday 24 April 2005 06:59 am, so sayeth François Pinard:
> As seen from here, the Python mailing list quality has been degrading
> significantly for the last half-year or so.

That's funny. That's exactly as long as I've been on this list. I wonder if 
the correlation is causal?

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: [EVALUATION] - E03 - jamLang Evaluation Case Applied to Python

2005-04-24 Thread Ilias Lazaridis
Ilias Lazaridis wrote:
[EVALUATION] - E02 - Support for MinGW Open Source Compiler
http://groups-beta.google.com/group/comp.lang.python/msg/f5cd74aa26617f17
-
In comparison to the E02 thread, now a more practical one.
-
Here is a simple evaluation template (first part) which can be applied 
to the Python language:

http://lazaridis.com/case/lang/index.html
If you like, please post the most elegant solutions (either to sections 
or to the whole document).

I will collect the results and write them down in a document, which will 
compare python with other languages.

This document can serve as an flash-start (for people which simply like 
to take a look on python).

http://lazaridis.com/case/lang/python.html
the first result:
http://lazaridis.com/case/lang/python.html
You can see the ruby version here (which shows some limitations, which 
python can hopefully overcome):

http://lazaridis.com/case/lang/ruby.html
.
--
http://lazaridis.com
--
http://mail.python.org/mailman/listinfo/python-list


Awesome Directory

2005-04-24 Thread Anusha

Hello there,

Try visiting this well listed Directory on Computers and Internet! ...

Here is the link http://hi-fiweb.com/comp

Hoping to learn a lot from other group members.

Take care,
Kathy



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


Re: func_code vs. string problem

2005-04-24 Thread Filip Dreger

Uzytkownik "Steven Bethard" <[EMAIL PROTECTED]> napisal w 
wiadomosci news:[EMAIL PROTECTED]
> Any reason you can't define it like:
>
> class actor(object):
> def __init__(self):
> self.roles = []
> def act(self):
> for role_func in self.roles:
> role_func(self)
[snip]
> By importing actor, they have full access to the global namespace of 
> the actor.actor object, by simply accessing the actor module 
> attributes.
>
> So the issue here is really about full *local* namespace access.  Do 
> you really need *full* local namespace access?  Why isn't access to 
> the actor.actor instance sufficient?

!!! Yep, of course it is sufficient. Abondoning the obvious 
role_func() must have had some good reasons some time ago, but now I 
can not even remember them, probably they were not so important :-)
Thanks a million,
Filip 


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


Re: Bounding box on clusters in a 2D list

2005-04-24 Thread [EMAIL PROTECTED]
hi Bearphile! That really gives me an idea.Thanks much for that. Yes as
you said the algorithm reaches a maximium recursion depth for larger
sets i tried.I still have a question. if
m = [[0,0,0,0],[0,1,1,0,0],[0,0,1,0,0],[0,0,0,0]]

all it does is count the number of 1's and return us the number in that
cluster. But if I want the box to be considered as one cluster as
   [[0, 0, 0, 0, 0],
+-+
 [0,|1, 1,|0, 0],
 ||
 [0,|0, 1,|0, 0],
+-+
 [0, 0, 0, 0, 0]]


because it could be that the 0 in between the cluster of ones is a part
of the group.So the area of this boundingbox is 4 rather than 3. Do you
see where I am heading

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


Re: Using Ming on Windows

2005-04-24 Thread Philippe C. Martin
I never managed to link my python extensions (mingw .a) with python and
broke down and bought Visual/C++ as it is the compiler used by Python.

Yet some people seem to have managed:
http://uucode.com/texts/python-mingw/python-mingw.html

Regards,

Philippe



Jack Diederich wrote:

> On Sat, Apr 23, 2005 at 05:13:29PM -0300, Andr? Roberge wrote:
>> I tried to install Ming
>> (http://sourceforge.net/projects/ming/)
>> on Windows to use with Python *but*
>> I can't [/don't know how to] use "make" to install it.
>> 
>> Does anyone know where I could find a ready-made compiled
>> version for Windows to just "put in" my site-packages directory.
>> 
>> Any help would be appreciated.
>> 
> Ming seems to be abandoded/unsupported.  Use groups.google.com to
> find some hints on how to install it.  I've done it on linux, but
> never tried on windows (why would I?) and replied with some
> suggestions last time it came up on c.l.py
> 
> -jackdied

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


Re: Why is Python not supporting full derivation of built-in file class?

2005-04-24 Thread Jeff Epler
This issue was discussed in another recent python-list thread, called
"Writing to stdout and a log file".

My second post includes a patch to Python's "fileobject.c" that made the
code that started that thread work, but for reasons I mentioned in that
post I didn't want to push for inclusion of my patch.  I didn't check,
but it will probably allow your code to work too.

If you feel differently, then the thing to do is probably to submit the
patch plus a test case to the sf.net patch tracker for python
(sf.net/projects/python, click on "patches".  you'll need a sourceforge
account to submit the patch)

Jeff
PS I did allow the Python test suite to run to completion after I wrote
that message.  It didn't produce any failures or unexpected skips on my
platform.


pgppjD5SYuGFg.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Graphic editor within an MFC app. I have a wxPython prototype, that...

2005-04-24 Thread Philippe C. Martin
Does that mean you are using C++/C# and not Python ?

I also guess you do not wish MFC and wxWindows to coexist in the same .exe
as the reasons for conflict are many (GDI port, main event loop .)

Then do you simply wish to "map" your wxindows calls to equivalent MFC calls
with some kind of stub/glue?


Regards,

Philippe


F. GEIGER wrote:

> I have built a wxPython prototype of an app, that lets me place rectangles
> o a wxPanel, move them and change their size. How the rects are added
> and placed has to follow certain rules.
> 
> The final goal is to merge this "graphical editor" into a MFC app.
> Converting a standalone wxPython app into a wxWidget app ist not that
> complicated.
> 
> But how about merging it into a MFC app? Has anybody achieved that
> already?
> 
> All the functionality lies in my wxPanel-subclass "EditorWidget" and in
> the few widgets I can place on it. So it boils down to place that
> "EditorWidget" an a MFC-Panel. But what about the mainloops?
> 
> If that's not possibel at all, I'd consider getting an ActiveX that offers
> to me what I need. It does not need to be a full blown CAD ActiveX but
> should be customizeable. Does anyone know a source for such things?
> 
> Many thanks in advance and kind regards
> Franz GEIGER

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


Re: optparse: store callback return value

2005-04-24 Thread [EMAIL PROTECTED]
Callbacks are functions called when an optparse.OptionParser() object
has a callback option defined (don't know how to say this less obvious
sounding...) (they are documented in
http://docs.python.org/lib/optparse-option-callbacks.html)

Example (based on an example in the documentation):

this script:
-#!/usr/bin/env python
-import optparse
-def record_foo_seen(option, opt_str, value, parser):
-print 'saw foo'
-
-parser = optparse.OptionParser()
-parser.add_option("--foo", action="callback",
callback=record_foo_seen)
-(options, args) = parser.parse_args()
-
-print options, args

prints when executed with or without argument:
[EMAIL PROTECTED]:~$ ./test2.py --foo
saw foo
{} []
[EMAIL PROTECTED]:~$ ./test2.py
{} []
[EMAIL PROTECTED]:~$

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


Re: Bounding box on clusters in a 2D list

2005-04-24 Thread [EMAIL PROTECTED]
Richter,yes what I am looking for is for cluster with rectangular
bounding boxes as you explained in the first figure.

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


[OT] Graphic editor within an MFC app. I have a wxPython prototype, that...

2005-04-24 Thread F. GEIGER
I have built a wxPython prototype of an app, that lets me place rectangles
o a wxPanel, move them and change their size. How the rects are added
and placed has to follow certain rules.

The final goal is to merge this "graphical editor" into a MFC app.
Converting a standalone wxPython app into a wxWidget app ist not that
complicated. 

But how about merging it into a MFC app? Has anybody achieved that already?

All the functionality lies in my wxPanel-subclass "EditorWidget" and in
the few widgets I can place on it. So it boils down to place that
"EditorWidget" an a MFC-Panel. But what about the mainloops?

If that's not possibel at all, I'd consider getting an ActiveX that offers
to me what I need. It does not need to be a full blown CAD ActiveX but
should be customizeable. Does anyone know a source for such things?

Many thanks in advance and kind regards
Franz GEIGER

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


Re: Question on metaclasses

2005-04-24 Thread Reinhold Birkenfeld
Diez B. Roggisch wrote:
> Reinhold Birkenfeld wrote:
> 
>> Diez B. Roggisch wrote:
 class Foo(type):
 def __new__(cls, name, bases, dict):
 
 for k,v in [(k, v) for k,v in dict.items() if callable(v)]:
 cls.wrap(k,v,cls.get_directives(v), dict)
 
 return super(Foo, self).__new__(self, name, bases, dict)
>>> 
>>> There is a confusion of self and cls above - rename self with cls.
>> 
>> And remove the first argument to __new__.
> 
> Ehm, no, I don't think so. The code was copied and pasted from a working
> metaclass (at least I hope so...), and in the original code a underscore
> was used for the first argument. I've been following that bad habit for a
> while but recently started to be more following to the established
> conventions. So I rewrote that code on the fly. 

Oh yes. I forgot that __new__ is a staticmethod anyhow.

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


Re: postgresql modules and performance

2005-04-24 Thread Mage
Reinhold Birkenfeld wrote:

>
>Have you tried psycopg?
>  
>
Thank you. It did the fetchall()  in 11 secs and 13 secs with dictionary
creating. It's the fastest so far.

   Mage

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


Re: Unicode problems, yet again

2005-04-24 Thread "Martin v. Löwis"
Ivan Voras wrote:
> Sorry, that was just steam venting from my ears - I often get bitten by
> the "ordinal not in range(128)" error. :)

I think I'm glad to hear that. Errors should never pass silently, unless
explicitly silenced. When you get that error, it means there is a bug in
your code (just like a ValueError, a TypeError, or an IndexError). The
best way to deal with them is to fix them.

Now, the troubling part is clearly that you are getting *bitten* by
this specific error, and often so. I presume you get other kinds of
errors also often, but they don't bite :-) This suggests that you should
really try to understand what the error message is trying to tell so,
and what precisely the underlying error is.

For other errors, you have already come to an understanding what they
mean: NameError, ah, there must be a typo. AttributeError on None, ah,
forgot to check for a None result somewhere. ordinal not in range(128),
hmm, let's try different variations of the code and see which ones
work. This is going to continue biting you until you really understand
what it means.

The most "sane" mental model (and architecture) is one where you always
have Unicode strings in your code, and decode/encode only at system
interfaces (sockets, databases, ...). It turns out that the database
you use already follows this strategy (i.e. it decodes for you), so
you now only need to design the other interfaces so it is clear when
you have Unicode characters and when you have bytes.

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


Re: thread lock object.

2005-04-24 Thread Peter Hansen
Irmen de Jong wrote:
[EMAIL PROTECTED] wrote:
How can we make only one thread at a time be able to access and
increment i ?
Use a synchronization primitive such as a lock
(threading.Lock, threading.RLock)
But for simply incrementing a number (i+=1) this is not needed
because that operation cannot be interrupted by another thread,
as far as I know.
Most assuredly it can:
>>> def f():
...   global x
...   x += 1
...
>>> dis.dis(f)
  3   0 LOAD_GLOBAL  0 (x)
  3 LOAD_CONST   1 (1)
  6 INPLACE_ADD
...a context-change here can lead to incorrect results...
  7 STORE_GLOBAL 0 (x)
 10 LOAD_CONST   0 (None)
 13 RETURN_VALUE
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Handling lists

2005-04-24 Thread [EMAIL PROTECTED]
 That helps.Thanks much.

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


Re: Is this a bug?

2005-04-24 Thread Fredrik Lundh
Robert Kern wrote:

> It's consistent with using a.extend("world") which is what the += is
> sugar for.
>
> In [1]:a = ['hello']
>
> In [2]:a.extend("world")
>
> In [3]:a
> Out[3]:['hello', 'w', 'o', 'r', 'l', 'd']
>
> It's a *good* thing that .extend() takes any iterable without explicit
> conversion to a list. I think that it's just a minor annoyance that the
> behavior passes on to +=.

mapping += to extend is a design mistake (I guess someone got a
little carried away).





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


Re: Is this a bug?

2005-04-24 Thread Fredrik Lundh
"[EMAIL PROTECTED]" wrote:

> when you use a = a + 'world'  python sees it as an error because of
> different type.
>
> But when you use a += 'world'
> python will change the right into list (because a is a list).

"changing into a list" is a bit misleadning; to bit a bit more precise,
you may want to change that to

python will treat the right as a sequence





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


Re: Is this a bug?

2005-04-24 Thread [EMAIL PROTECTED]
check this site:
http://mail.python.org/pipermail/python-bugs-list/2003-November/021201.html

pujo

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


Re: Variables

2005-04-24 Thread T Väntänen
Richard Blackwood wrote:
To All:
   Folks, I need your help. I have a friend who claims that if I write:
foo = 5
then foo is NOT a variable, necessarily. If you guys can define for me 
what a variable is and what qualifications you have to back you, I can 
pass this along to, hopefully, convince him that foo is indeed a variable.

Thanks all!
Richard B.
For example in physics formula for falling object distance:
d = (1/2)*g*t^2
In physics (math) d and t are variables and g is a constant. When you 
start to calculate the distance you assign some values to the variables, 
you  cant touch the constant - thats the meaning of something being 
constant. Or is g constant or variable?

Math:
For example if we want to visualize the speed of the object from 0 to 10 
seconds we need to calculate some values to d/t graph. You do this:
t = 0, calculate d
t = 1, calculate d
...
t = 10, ...

In math you maybe call that t and d are constants, but those are 
constants only for one calculation.

Programming:
In python we'd do:
---
g = 9.81
for t in range(0, 11):
d = 0.5 * 9.81 * t
print 't=%s d=%s' %(t, d)
---
it prints out:
0: 0.0
1: 4.905
2: 9.81
3: 14.715
4: 19.62
5: 24.525
6: 29.43
7: 34.335
8: 39.24
9: 44.145
10: 49.05
Constant is "variable which value is same through the program 
execution", variable value can change. Knowing value of variable doesn't 
make it constant.

Vocabulary and notation varies. Electric engineers might talk about 
generator, in candyshop there are surely lots of wrappers, and both 
soldiers and surgeons plan and execute operations.

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


Re: Is this a bug?

2005-04-24 Thread Grant Edwards
On 2005-04-24, Michael Sparks <[EMAIL PROTECTED]> wrote:

 a=["hello"]
 a = a + "world"
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: can only concatenate list (not "str") to list

> However if we do this just slightly differently:
>
 a = ["hello"]
 a += "world"
 a
> ['hello', 'w', 'o', 'r', 'l', 'd']
>
> We get completely different behaviour. This strikes me as a bug - should I
> log it as one, or is there a good reason for this behaviour?

I think it's a bug regardless of the reason for the behavior: 

 1) It doesn't do what a reasonable user expects.

 2) It doesn't do what the documentation says it will.
According to the language reference,

  An augmented assignment expression like x += 1 can be
  rewritten as x = x + 1 to achieve a similar, but not
  exactly equal effect. In the augmented version, x is only
  evaluated once.

I don't consider the two results you posted "similar".
  
-- 
Grant Edwards   grante Yow!  TAILFINS!!...click...
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this a bug?

2005-04-24 Thread [EMAIL PROTECTED]
when you use a = a + 'world'  python sees it as an error because of
different type.

But when you use a += 'world'
python will change the right into list (because a is a list). So when
you're code become:
a += 'world' # a += list('world')

It really helpfull if you stick to use append instead of += when you
operate list

Pujo

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


  1   2   >