Re: Variables

2005-04-23 Thread Robert Kern
Richard Blackwood wrote:
Bengt Richter wrote:
On Sat, 23 Apr 2005 22:45:14 -0400, Richard Blackwood 
<[EMAIL PROTECTED]> wrote:

 

Robert Kern wrote:
  

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.
  
None of us can do that unless you tell us what he thinks the word 
"variable" means. The terminology is a bit fluid. I suspect that 
your friend applying a somewhat restricted notion of "variable" that 
coincides with the behavior of variables in some other language.


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. This can not be true. For 
example, I may define foo as being a dictionary, but I can not do 
this within math because there is no concept of dictionaries within 
mathematics; yet foo is a variable, a name bound to a value which can 
change.
  

Maybe he doesn't know that foo = 5 in Python is not an equation as in 
math,
but a Python source language statement to be translated to a step in some
processing sequence.

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?
It's his responsibility to show that it *is* an equation.
x = x + 1
Equation? I think not.
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.
Okay, I take back my comment that this is not his field. I instead put 
forth the contention that he is a stark raving nutter. My qualifications 
to back me are that I cut my USENET teeth at talk.origins. I know my 
stark raving nutters.

Did his seemingly 
peculiar definition of variable exist at that time?
Oh, I'm sure *some* programming textbook from that time has tried to use 
such a definition and maintained the assertion that "programming is an 
off-shoot of math and thus at the fundamental level has identical 
concepts and rules." Both are rather naive, though, and the rest of the 
field has grown out of it. Your friend hasn't, it seems. Leave him to 
it, I say.

If you insist on convincing him, however, you can point him to Raphael 
Finkel's _Advanced Programming Language Design_[1], page 5 which defines 
"variables" as "named memory locations." In this formal context, what we 
often informally call "variables" in Python aren't. This is why we 
sometimes use the term "names" instead. In C, when I declare a variable, 
I also specify a piece of memory to which that name refers. When I 
assign a value to that variable, the value goes into that memory 
location. When I assign a new value there, I overwrite the data in that 
memory location with the new value. It doesn't work like that in Python. 
The name just points to the new object. No memory gets overwritten. Your 
friends other assertions suggest that this is not what he is talking 
about, though.

As always in terminology issues, what is correct depends on the 
conversation one is having. If I'm talking about a piece of Python code 
a colleague and I say, "so I put the value in a temporary variable--" 
and he says "No, it's not a variable, it's a name!", he has just 
volunteered for a severe beating. If I'm talking about comparative 
language design like Finkel is, the distinction is quite useful and no 
beatings need occur.

None of this has anything to do with the terminology as it is used in 
mathematics.

[1] http://www.nondot.org/sabre/Mirrored/AdvProgLangDesign/
--
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: Variables

2005-04-23 Thread Terry Reedy
>>In mathematics, the word 'variable' is generally an undefined meta-term 
>>that is *notorious* for having multiple possible meanings and shades of 
>>meaning.  One mathematician/linguist once claimed to have discerned 
>>somewhere around 15 different meanings and shades thereof. 
>>
> What is his/her name?

Wish I could remember but this was some decades ago.  But you should be 
able to think a few yourself.

Terry J. Reedy



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


Re: Variables

2005-04-23 Thread Ron
Richard Blackwood wrote:
He would argue strongly against your notion of variable. In the 
statement "foo = 5", foo is constant. He would thus argue that foo is a 
constant and not a variable (regardless of whether you change foo's 
value in subsequent statements).
Sounds like his mind is made up and you will probably not be able to 
persuade him otherwise.

But maybe this will help... or not. ;-)
Given a math equation...
x = 2y+3
x and y are clearly (most would agree) variables.  The value of each 
changes depending on the value of the other.

To solve the equation you set one variable to a value to find the other.
x = 2*y+3
y = 5
x = 2*5+3
x = 13
Do this again for other values... etc...
Would he agree that x, and y are variables even after a value is 
determined?  Or would he say that they become constants once you decide 
a value for one?

I think context is the deciding factor if this is a general discussion 
concerning math equations.  The above equation may be an equation of a 
line, or it may be the equation of a specific condition with two unknowns.

They may variables which may either have the value which is constant, a 
known value, an unknown value, or a range of values.

So given only "foo = 5" ...
In Python foo is a Name which is bound to the integer 5.  There are 
other way to describe it, but it all comes down to being symbols 
representing a concept.

(It could have been a randomly generated sequence with no meaning at all 
too!)

Without knowing the context of the discussion, that is all that we can 
say.  However if we were to agree that foo represents a concept that has 
an unchanging value in the context that it is used, then it is a 
constant, because we agreed that it is.  So it is determined by the 
meaning we agree (or decide for ourself) to give to the name "foo".

So what is the meaning of foo?  In general computer discussions foo is 
ever changing and represents an abstract object to be used and reused to 
describe a multitude of possibilities.  I would call that a variable.

 ;-)
Cheers,
Ron
--
http://mail.python.org/mailman/listinfo/python-list


Re: Variables

2005-04-23 Thread Richard Blackwood
Robert Kern wrote:
Richard Blackwood wrote:
Robert Kern wrote:

If you must, http://en.wikipedia.org/wiki/Variable
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.

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*
--
http://mail.python.org/mailman/listinfo/python-list


Re: Variables

2005-04-23 Thread Robert Kern
Richard Blackwood wrote:
Robert Kern wrote:

If you must, http://en.wikipedia.org/wiki/Variable
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.
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.

--
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: Variables

2005-04-23 Thread Richard Blackwood
Bengt Richter wrote:
On Sat, 23 Apr 2005 22:45:14 -0400, Richard Blackwood <[EMAIL PROTECTED]> wrote:
 

Robert Kern wrote:
   

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.
   

None of us can do that unless you tell us what he thinks the word 
"variable" means. The terminology is a bit fluid. I suspect that your 
friend applying a somewhat restricted notion of "variable" that 
coincides with the behavior of variables in some other language.

 

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. This can not be true. For example, I may 
define foo as being a dictionary, but I can not do this within math 
because there is no concept of dictionaries within mathematics; yet foo 
is a variable, a name bound to a value which can change.
   

Maybe he doesn't know that foo = 5 in Python is not an equation as in math,
but a Python source language statement to be translated to a step in some
processing sequence.
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?

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

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


Re: Variables

2005-04-23 Thread Bengt Richter
On Sat, 23 Apr 2005 22:45:14 -0400, Richard Blackwood <[EMAIL PROTECTED]> wrote:

>Robert Kern wrote:
>
>> 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.
>>
>>
>> None of us can do that unless you tell us what he thinks the word 
>> "variable" means. The terminology is a bit fluid. I suspect that your 
>> friend applying a somewhat restricted notion of "variable" that 
>> coincides with the behavior of variables in some other language.
>>
>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. This can not be true. For example, I may 
>define foo as being a dictionary, but I can not do this within math 
>because there is no concept of dictionaries within mathematics; yet foo 
>is a variable, a name bound to a value which can change.

Maybe he doesn't know that foo = 5 in Python is not an equation as in math,
but a Python source language statement to be translated to a step in some
processing sequence.

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.

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

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


Re: Variables

2005-04-23 Thread Richard Blackwood
Terry Reedy wrote:
"Richard Blackwood" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
 

Indeed, this language is math.
   

In mathematics, the word 'variable' is generally an undefined meta-term 
that is *notorious* for having multiple possible meanings and shades of 
meaning.  One mathematician/linguist once claimed to have discerned 
somewhere around 15 different meanings and shades thereof. 

What is his/her name?
--
http://mail.python.org/mailman/listinfo/python-list


Re: GUI woes

2005-04-23 Thread Roger Binns
"jeff elkins" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> under debian sid, I installed (via apt-get) the various wxpython stuff
> available.:
>
> libwxgtk2.4-python
> libwxgtk2.5.3-python
> python-opengl
> python-pythoncard
> python2.1-opengl
> python2.2-opengl
> python2.3-opengl
> python2.3-pythoncard
> pythoncard
> pythoncard-doc
> pythoncard-tools
> wx2.5-examples
> wxpython2.5.3
> wxwin2.4-examples

You have a mixture of different versions of wxPython in there.

> AttributeError: MyFrame instance has no attribute 'Bind'

Bind was introduced in wxPython 2.5.  Looks like you are
running against thr 2.4 library.

Roger 


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


Re: Variables

2005-04-23 Thread Terry Reedy

"Richard Blackwood" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Indeed, this language is math.

In mathematics, the word 'variable' is generally an undefined meta-term 
that is *notorious* for having multiple possible meanings and shades of 
meaning.  One mathematician/linguist once claimed to have discerned 
somewhere around 15 different meanings and shades thereof.  The context 
usually makes the particular meaning clear enough, at least to other 
mathematicians.  But the ambiguity sometimes disconcerting to students.

> My friend says that foo is a constant and necessarily not a variable.

'constant' is one of the possible meanings of 'variable'.  As is "Given 
that (3*x -2)/5 = 1, what is the value of the variable x".  Sometimes, 
whether a 'variable' actually 'varies' or not, is a matter of viewpoint. 
We may think of 'varying' as something that happens in time, whereas most 
math is timeless.

In any case, 'foo=5' can be followed, in Python, by 'foo="hopscotch" '.  So 
names (as opposed to objects) do not even have a type.  Also, in Python, 
'variable' is not a part of the official language description in the way it 
is for some other programming languages.

Terry J. Reedy





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


Re: Variables

2005-04-23 Thread Richard Blackwood
Dan Bishop wrote:
Richard Blackwood wrote:
 

Steven Bethard wrote:
   

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.
   

Then what does he say if you write:
foo = 5
foo = 6
 

...
 

He says that foo is a constant. At first it was a constant which
   

equaled
 

5, then it was a constant that equaled 6.
   

He must have a very unusual definition of "constant".
 

I believe he argues that foo existed as two separate constants. He also 
says that if I write:

foo = 6
foo = raw_input()
then foo first exists as a constant and then as a variable (because it 
can then be anything, any value that the user inputs).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Variables

2005-04-23 Thread Richard Blackwood
Mike Meyer wrote:
Richard Blackwood <[EMAIL PROTECTED]> writes:
 

Robert Kern wrote:
   

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.
   

None of us can do that unless you tell us what he thinks the word
"variable" means. The terminology is a bit fluid. I suspect that
your friend applying a somewhat restricted notion of "variable" that
coincides with the behavior of variables in some other language.
 

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. This can not be true. For
example, I may define foo as being a dictionary, but I can not do this
within math because there is no concept of dictionaries within
mathematics; yet foo is a variable, a name bound to a value which can
change.
   

Wrong on two counts.
First, new disciplines often redefine words to mean something
different than the disciplines they were derived from. Variable is a
good example of that. In math, a variable is a placeholder in an (a
system of) equation(s), and will have associated with it a (possibly
empty) set of values that satisfy the equation(s). 

Not merely a placeholder, right? A variable in math is a 'placeholder' 
for a dynamic value, one which can or does change. If one can graph the 
movement (change) of foo, foo is a variable within that scope. For example:

foo = 5
foo = 6
I can graph foo's movement/change. It can thus be considered a variable 
within mathematics. If I write:

foo = 5
I can graph this but it will merely be a static point, a constant. 
Constants are not variables because they do not change, they do not 
"vary" in content.

In programming, a
variable holds a value of some kind. As you point out, the value may
be complicated, in that it holds one or more objects.
 

Indeed.
In math, if you say "foo = 5", foo is a variable, with a single value
(5) that satisfies the equation. In Python, if you say "foo = 5", foo
is a variable, that currently references the value 5.
 

He would argue strongly against your notion of variable. In the 
statement "foo = 5", foo is constant. He would thus argue that foo is a 
constant and not a variable (regardless of whether you change foo's 
value in subsequent statements).

...
   
 

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


Re: Variables

2005-04-23 Thread Dan Bishop
Richard Blackwood wrote:
> Steven Bethard wrote:
>
> > 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.
> >
> >
> > Then what does he say if you write:
> >
> > foo = 5
> > foo = 6
...
> He says that foo is a constant. At first it was a constant which
equaled
> 5, then it was a constant that equaled 6.

He must have a very unusual definition of "constant".

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


Re: Variables

2005-04-23 Thread Richard Blackwood
Robert Kern wrote:
Richard Blackwood wrote:
Kent Johnson wrote:
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. 


Indeed, this language is math. My friend says that foo is a 
constant and necessarily not a variable. 


Well, we mostly talk Python here, not math. In Python, if you say
foo = 5
foo is a name bound to an immutable value.
If I had written foo = raw_input(), he would
say that foo is a variable. 


That's funny. foo is still a name bound to an immutable (string) 
value. foo is no more or less variable than it was with foo = 5.

Which is perfectly fine except that he
insists that since programming came from math, the concept of 
variable is necessarily the identical. This can not be true. For 
example, I may define foo as being a dictionary, but I can not do 
this within math because there is no concept of dictionaries within 
mathematics; yet foo is a variable, a name bound to a value which 
can change.


Sounds like you are having a stupid and meaningless argument with 
your friend. What you call foo won't change what it is. He should 
learn Python, then he would understand the true zen of foo.

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.

Why should there be? Different programming languages have different 
models. In C, a variable corresponds to a memory slot. In Python, it's 
a just a name that can be bound to an object.

If you must, http://en.wikipedia.org/wiki/Variable
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.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Variables

2005-04-23 Thread Mike Meyer
Richard Blackwood <[EMAIL PROTECTED]> writes:

> Robert Kern wrote:
>> 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.
>>
>> None of us can do that unless you tell us what he thinks the word
>> "variable" means. The terminology is a bit fluid. I suspect that
>> your friend applying a somewhat restricted notion of "variable" that
>> coincides with the behavior of variables in some other language.
>>
> 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. This can not be true. For
> example, I may define foo as being a dictionary, but I can not do this
> within math because there is no concept of dictionaries within
> mathematics; yet foo is a variable, a name bound to a value which can
> change.

Wrong on two counts.

First, new disciplines often redefine words to mean something
different than the disciplines they were derived from. Variable is a
good example of that. In math, a variable is a placeholder in an (a
system of) equation(s), and will have associated with it a (possibly
empty) set of values that satisfy the equation(s). In programming, a
variable holds a value of some kind. As you point out, the value may
be complicated, in that it holds one or more objects.

In math, if you say "foo = 5", foo is a variable, with a single value
(5) that satisfies the equation. In Python, if you say "foo = 5", foo
is a variable, that currently references the value 5.

What Python calls a "dictionary" math calls a "mapping", or sometimes
a "function" (though that usage is usually reserved for mappings
to/from numbers of some kind). A mapping is a relationship between
elements of two sets, pairing elements of the first set with elements
of the second set. In a Python dictionary, the first set is keys(), and the
second set is values(). In both cases, the pairing is unidirectional,
as picking an element from the first set (keys) selects a unique
element from the second set (values), but picking an element from the
second set (values) may pick more than one element from the first set
(keys). See http://www.answers.com/topic/function > for more
information.

Note that lists and tuples are both mappings, though in their case the
first set is restricted to the integers. If you check the Python
documentation, you'll see these three types (dictionaries, lists and
tuples) documented in a section called "Mapping Types".

  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: help with binary file io, perhaps with generators?

2005-04-23 Thread Terry Reedy

"Marcus Goldfish" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I need to write a "fast" file reader in python for binary files structured 
>as:
>
> … x[0] y[0] z[0] x[1] y[1] z[1]  …
>
> where c[k] is the k-th element from sequence c.  As mentioned, the
> file is binary -- spaces above are just for visualization.  Each
> element, c[k], is a 16-bit int.

You have a sequence of machine-format triples

>   (ii) how can I handle the 16-bit word aspect of the binary data?

that you want to unpack (see struct module) and unzip (your code).

>  I can assume I know the number of sequences in the file a priori.

Then you can pre-allocate x,y,z instead of growing them by appends:

x = n*[0]; ...

> Files are stored and processed on a
> WinXP machine (in case Endian-ness matters).

I believe struct module takes care of this.  Read its doc.

>   (i) should I use generators for iterating over the file?

If you will only ever unpack when you also unzip to separate lists, then 
you might put the unpack code in the inner loop of the unzip method.  If 
you think that you might someday directly process the file as a sequence of 
scaler triples without creating intermediate x,y,z lists, then you should 
factor out the file read/unpack as you are thinking.

>   (iii) ultimately, the data will need to be processed in chunks of
> M-values at a time... I assume this means I need some
> form of buffered io wrapper, but I'm not sure where to start
> with this.

I presume this means M triplets or 3*N values.
In any case, Python is ahead of you ;-).

>>>help(file.read)
read([size]) -> read at most size bytes, returned as a string.

If the size argument is negative or omitted, read until EOF is reached.

Terry J. Reedy




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


Re: Variables

2005-04-23 Thread Robert Kern
Richard Blackwood wrote:
Kent Johnson wrote:
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. 


Indeed, this language is math. My friend says that foo is a constant 
and necessarily not a variable. 

Well, we mostly talk Python here, not math. In Python, if you say
foo = 5
foo is a name bound to an immutable value.
If I had written foo = raw_input(), he would
say that foo is a variable. 

That's funny. foo is still a name bound to an immutable (string) 
value. foo is no more or less variable than it was with foo = 5.

Which is perfectly fine except that he
insists that since programming came from math, the concept of 
variable is necessarily the identical. This can not be true. For 
example, I may define foo as being a dictionary, but I can not do 
this within math because there is no concept of dictionaries within 
mathematics; yet foo is a variable, a name bound to a value which can 
change.

Sounds like you are having a stupid and meaningless argument with your 
friend. What you call foo won't change what it is. He should learn 
Python, then he would understand the true zen of foo.

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.
Why should there be? Different programming languages have different 
models. In C, a variable corresponds to a memory slot. In Python, it's a 
just a name that can be bound to an object.

If you must, http://en.wikipedia.org/wiki/Variable
--
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: Python or PHP?

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

> Mike Meyer wrote:
>
>> John Bokma <[EMAIL PROTECTED]> writes:
>> 
>>> Mike Meyer wrote:
>>>
 "Simon John" <[EMAIL PROTECTED]> writes:
 
> I still love Perl, it's a bit of an art form, as "there's more than
> one way to do it", whereas Python usually only allows one way to do
> it, which may or may not be a better mantra
 
 The Python mantra leads to 1) less programmer overhead, and 2) 
> faster
 improvements in the language.
 
 To be a Perl expert, you have to know which of the many ways to do
 various things is the fasted under what conditions.
>>>
>>> Why?
>> 
>> One of the stated conditions for more than one Perl position I've
>> looked at.
>
> That's weird, since some can differ between versions of Perl like for 
> example a map in a void context. And I am sure Python has now and then 
> improvements which make one operation suddenly 10% faster in a new 
> version.

The things is - it doesn't matter nearly as much in Python. Since
there's only one obvious way to do most simple things, that's the one
that most programmers will choose, and that's the one the developers
will worry about making faster.

> So it tells you a lot about the people providing the position ;-)

Yeah - they expect their people to be on top of such things. I've
never run across a Python position where knowing which of several ways
was faster was an important criterion - because there usually aren't
several ways.


 Having only one obvious way
>>> I doubt that too ;-)
>> Try programming in older Python for a while. You'll quit doubting it.
> Again I doubt that. I doubt that if I give 100 old Python programmers a 
> certain computer science problem I will see 100 exactly the same 
> solutions, which when benchmarked run equally fast.

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.

As I've said a number of times, this has changed lately as new
features have been added without removing their older counterparts.

 to do things means developers only have to
 worry about impact on that way when making improvements, which will
 speed them up.
>>> Yeah, Perl programmers are extremely slow ;-)
>> Nah, they aren't slow. They just have to worry about more things than
>> the Python developers.
> Do you have references to this? I would love to see if indeed 100 Python 
> programmers do implement, say 5 CS tasks faster compared to 100 Perl 
> programmers, on average.

I'm talking about the people developing the language, not the ones
developing in the language. And this is just my impression from
watching the developers lists.

>> If speed
>> is an issue, you should probably pick a different
>> algorithm. Well-written Python programs use the C-coded parts of
>> Python for the time-critical part of the code.
> Why are those time critical parts not written in Python ;-)

Because then they'd be slower. A good scripting environment has lots
of operations available that are coded at a low level. Since this code
is usually hand-tuned and optimized over time (like the dictionary
lookup or string operations in Python, or regular expressions in Perl
- I'm not sure about the RE library in Python), it may well be faster
than what you'd write in the low level language if you did it
yourself.

>>> Use the one that is the easiest to read and understand by yourself.
>>> That's how I program Perl, and that's how I am going to program 
> Python. 
>> The thing is, in Python there usually is one obvious way to do
>> things. That's changed in recent years as improvements have been added
>> without dropping the features they replaced so as not to break old
>> programs.
> I know to little about Python, especially about old Python, to have an 
> idea of what you mean. I only saw, quite recently, someones solution to 
> a problem that used 30 lines of Python, and I am sure I could have 
> written it in 3-4. And I doubt that's because he was using, or I was 
> thinking in, new Python
> :-D.

Just because there's only one obvious way to do things doesn't mean
it's obvious to everyone. Witness the recent spate of people asking
for "goto".

>>> An overloaded toolbox doesn't mean that if you have to hang a 
> painting
>>> on the wall that you have to think for 6 hours which tool you should
>>> use. You just take the one that does the job in a way you feel
>>> comfortable with. I know that the Perl mantra is often misunderstood,
>>> but in my experience only by people who have very little experience 
> with
>>> the language. 
>> The problem with using "the way you feel comfortable with" is that it
>> may not be comfortable for the maintainer - even if that's you six
>> months from now.
> After 5 years one gets comf

Re: Variables

2005-04-23 Thread Richard Blackwood
Kent Johnson wrote:
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. 

Indeed, this language is math. My friend says that foo is a constant 
and necessarily not a variable. 

Well, we mostly talk Python here, not math. In Python, if you say
foo = 5
foo is a name bound to an immutable value.
If I had written foo = raw_input(), he would
say that foo is a variable. 

That's funny. foo is still a name bound to an immutable (string) 
value. foo is no more or less variable than it was with foo = 5.

Which is perfectly fine except that he
insists that since programming came from math, the concept of 
variable is necessarily the identical. This can not be true. For 
example, I may define foo as being a dictionary, but I can not do 
this within math because there is no concept of dictionaries within 
mathematics; yet foo is a variable, a name bound to a value which can 
change.

Sounds like you are having a stupid and meaningless argument with your 
friend. What you call foo won't change what it is. He should learn 
Python, then he would understand the true zen of foo.
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.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Variables

2005-04-23 Thread Robert Kern
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. This can not be true. For example, I may 
define foo as being a dictionary, but I can not do this within math 
because there is no concept of dictionaries within mathematics; yet foo 
is a variable, a name bound to a value which can change.
Your friend needs to learn, and very quickly if he persists in 
inflicting his erroneous pedantry on other people, that technical terms 
have different meanings in different fields, even if one can imagine 
that one "came from" the other. Hell, even in the same field, it can 
mean different things. Ask him what "domain" means in mathematics. And 
check his answer[1].

While one could argue that using the term "variable" for Python names is 
 incorrect for good programming reasons, your friend's reasoning is 
ridiculous.

[1] http://mathworld.wolfram.com/Domain.html
--
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: Bounding box on clusters in a 2D list

2005-04-23 Thread Bengt Richter
On 23 Apr 2005 13:17:55 -0700, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

>If I have
>
>ex: x = [[1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0],
> [1,1,1,0,1,1,0,0,0,0,0,1,1,1,1,0,0,0],
> [1,1,1,0,1,1,1,0,1,1,0,1,1,1,0,0,0,0],
> [0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0]]
>what I want is a boundingbox over the region where we find clusters of
>1's.So for instance in the above list first 3 roes and colums have 1's
>so the area of that box is 3x3
>so my final array should have an array of approx areas of clusters of
>1's like
>area = [ 9,4 ]
Where does the 4 come from?

>Hope I am clear with my question.
>
Not quite clear on if "clusters" have to be rectangular and fill their bounding 
boxes
or whether

[[0, 0, 0, 0, 0],
+-+
 [0,|1, 1,|0, 0],
| |
 [0,|0, 1,|0, 0],
+-+
 [0, 0, 0, 0, 0]]

is a cluster with three 1's. Or indeed whether "bounding boxes" have to be 
rectangular.
I.e., what about diagonal clusters?
   ,__,
[[0, 0,|1,|0, 0],
 _/ _/   ,__, 
 [0,/1,/0, 0,|1],
  _/ _/_/ /
 [1,/0, 0,/1,/0],
_/ /
 [0, 0,/1,/0, 0]]

Or should that be
  +-+
[[|0, 0, 1, 0, 0|],
  | |
 [|0, 1, 0, 0, 1|],
  | |
 [|1, 0, 0, 1, 0|],
  | |
 [|0, 0, 1, 0, 0|]]
  +-+

since two 3x3 squares around the length-3 diagonals would overlap.

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


Re: Variables

2005-04-23 Thread Richard Blackwood
Steven Bethard wrote:
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.

Then what does he say if you write:
foo = 5
foo = 6
?
STeVe
He says that foo is a constant. At first it was a constant which equaled 
5, then it was a constant that equaled 6.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Variables

2005-04-23 Thread Kent Johnson
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. 

Indeed, this language is math. My friend says that foo is a constant and 
necessarily not a variable. 
Well, we mostly talk Python here, not math. In Python, if you say
foo = 5
foo is a name bound to an immutable value.
If I had written foo = raw_input(), he would
say that foo is a variable. 
That's funny. foo is still a name bound to an immutable (string) value. foo is no more or less 
variable than it was with foo = 5.

Which is perfectly fine except that he
insists that since programming came from math, the concept of variable 
is necessarily the identical. This can not be true. For example, I may 
define foo as being a dictionary, but I can not do this within math 
because there is no concept of dictionaries within mathematics; yet foo 
is a variable, a name bound to a value which can change.
Sounds like you are having a stupid and meaningless argument with your friend. What you call foo 
won't change what it is. He should learn Python, then he would understand the true zen of foo.

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


Re: Variables

2005-04-23 Thread Steven Bethard
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.
Then what does he say if you write:
foo = 5
foo = 6
?
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode problems, yet again

2005-04-23 Thread John Machin
On Sun, 24 Apr 2005 03:15:02 +0200, Ivan Voras
<[EMAIL PROTECTED]> wrote:

>I have a string fetched from database, in iso8859-2, with 8bit 
>characters,

"8bit characters"?? Maybe you did once, or you thought you did, but
what you have now is a Unicode string, and socket.write() is expecting
an ordinary string.

> and I'm trying to send it over the network, via a socket:
>
>   File "E:\Python24\lib\socket.py", line 249, in write
> data = str(data) # XXX Should really reject non-string non-buffers
>UnicodeEncodeError: 'ascii' codec can't encode character u'\u0161' in 
>position 123: ordinal not in range(128)

Like it says, you have passed it a *UNICODE* string that has u'\u0161'
(the small s with caron) at position 123.

>
>The other end knows it should expect this encoding, so how to send it?
>

If the other end wants an encoding, then you should *encode* it, like
this:


>>> us = u'\u0161'
>>> s = us.encode('iso8859_2')
>>> s
'\xb9'
>>> str(us)
Traceback (most recent call last):
  File "", line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0161' in
position 0: ordinal not in range(128)
>>> str(s)
'\xb9'
>>> # looks like socket.write() might be happier with this.

>(Does anyone else feel that python's unicode handling is, well... 
>suboptimal at least?)

Your posting gives no evidence for such a conclusion.


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


Re: Variables

2005-04-23 Thread Richard Blackwood
Robert Kern wrote:
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.

None of us can do that unless you tell us what he thinks the word 
"variable" means. The terminology is a bit fluid. I suspect that your 
friend applying a somewhat restricted notion of "variable" that 
coincides with the behavior of variables in some other language.

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. This can not be true. For example, I may 
define foo as being a dictionary, but I can not do this within math 
because there is no concept of dictionaries within mathematics; yet foo 
is a variable, a name bound to a value which can change.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Variables

2005-04-23 Thread Robert Kern
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.
None of us can do that unless you tell us what he thinks the word 
"variable" means. The terminology is a bit fluid. I suspect that your 
friend applying a somewhat restricted notion of "variable" that 
coincides with the behavior of variables in some other language.

--
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: Variables

2005-04-23 Thread Richard Blackwood
Indeed, but is it not a variable? Is a variable in programming not 
merely a name associated with a value (which can changed over the course 
of code execution)?

James Stroud wrote:
I think, strictly speaking, foo would be a "name" in python.
 

foo
   

Traceback (most recent call last):
 File "", line 1, in ?
NameError: name 'foo' is not defined

On Saturday 23 April 2005 07:20 pm, so sayeth Richard Blackwood:
 

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.
   

 

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


Re: Variables

2005-04-23 Thread James Stroud
I think, strictly speaking, foo would be a "name" in python.

>>> foo
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'foo' is not defined



On Saturday 23 April 2005 07:20 pm, so sayeth Richard Blackwood:
> 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.

-- 
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


Variables

2005-04-23 Thread Richard Blackwood
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.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode problems, yet again

2005-04-23 Thread Kent Johnson
Ivan Voras wrote:
I have a string fetched from database, in iso8859-2, with 8bit 
characters, and I'm trying to send it over the network, via a socket:

  File "E:\Python24\lib\socket.py", line 249, in write
data = str(data) # XXX Should really reject non-string non-buffers
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0161' in 
position 123: ordinal not in range(128)

The other end knows it should expect this encoding, so how to send it?
I think maybe the string from the database is a unicode string, not 8-bit. What happens if you write 
data.encode('iso8859-2') ?

(Does anyone else feel that python's unicode handling is, well... 
suboptimal at least?)
It can be confusing and surprising, yes. Suboptimal...well, I wouldn't want to say that I could do 
better...

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


help with binary file io, perhaps with generators?

2005-04-23 Thread Marcus Goldfish
I need to write a "fast" file reader in python for binary files structured as:

… x[0] y[0] z[0] x[1] y[1] z[1]  …

where c[k] is the k-th element from sequence c.  As mentioned, the
file is binary -- spaces above are just for visualization.  Each
element, c[k], is a 16-bit int.  I can assume I know the number of
sequences in the file a priori.  Files are stored and processed on a
WinXP machine (in case Endian-ness matters).

I'm looking for suggestions on how to tackle this problem, and how to
design my reader class.  Or if anyone has sample code: that would be
appreciated, too.  Some questions I have to start with:

   (i) should I use generators for iterating over the file?
   (ii) how can I handle the 16-bit word aspect of the binary data?
   (iii) ultimately, the data will need to be processed in chunks of
 M-values at a time... I assume this means I need some
 form of buffered io wrapper, but I'm not sure where to start
 with this.

Thanks!
Marcus

Ps -- this seems like a general stream processing problem… if anyone
can recommend good refs (web) on stream processing
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Unicode problems, yet again

2005-04-23 Thread Jp Calderone
On Sun, 24 Apr 2005 03:15:02 +0200, Ivan Voras <[EMAIL PROTECTED]> wrote:
I have a string fetched from database, in iso8859-2, with 8bit characters, 
and I'm trying to send it over the network, via a socket:
 You don't have a string fetched from a database, in iso-8859-2, alas.  
That is the root of the problem you're having.  What you have is a unicode 
string.
 It's easy to go from this to what you want (iso-8859-2 encoded string), 
fortunately.  Just call unicodeStr.encode('iso-8859-2') and write the result 
over the socket.
(Does anyone else feel that python's unicode handling is, well... suboptimal 
at least?)
 Hmm.  Not really.  The only problem I've found with it is misguided attempt to 
"do the right thing" by implicitly encoding unicode strings, and this isn't so 
much of a problem once you figure things out, because you can always do things explicitly 
and avoid invoking the implicit behavior.
 Jp
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Leif K-Brooks
Peter Ammon wrote:
I'm bewildered why you haven't mentioned magic quotes.  A one line 
change to the configuration file can render your PHP site almost 
entirely immune to SQL injection attacks.
PHP's magic quotes is one of the most poorly-designed features I can 
think of. Instead of magically escaping only strings which will actually 
be passed to a database (like Python's DB-API does), it escapes every 
string that comes from the user, meaning that strings which will be sent 
back to the user have to be manually unescaped.

Even worse, since it can be turned on and off, code which is designed 
for a magic_quotes=on environment will become seriously vulnerable when 
moved to an environment with magic_quotes on. Security-related features 
should never be toggleable!
--
http://mail.python.org/mailman/listinfo/python-list


Re: GUI woes

2005-04-23 Thread Kartic
The Great jeff elkins uttered these words on 4/23/2005 5:45 PM:
test.py crashes with the error below. Any clues?  

===
Running test.py: 

Traceback (most recent call last):
  File "./test.py", line 87, in ?
app = MyApp(0) # Create an instance of the application class
  File "/usr/lib/python2.3/site-packages/wxPython/wx.py", line 1951, in 
__init__
_wxStart(self.OnInit)
  File "./test.py", line 76, in OnInit
frame = MyFrame(None, -1, "This is a test")
  File "./test.py", line 26, in __init__
self.Bind(wx.EVT_SIZE, self.OnSize)
AttributeError: MyFrame instance has no attribute 'Bind'
Jeff - Could you please post your code?
From what you have posted it looks like your MyFrame class does not 
inherit from wx.Frame.

Your class should be defined like this:
class MyFrame(wx.Frame):
def __init__(self, parent, id, title, pos, size, style):
wx.Frame.__init__(self, parent, id, title, pos, size, style)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Show(True)
Thanks,
-Kartic
--
http://mail.python.org/mailman/listinfo/python-list


GUI woes

2005-04-23 Thread jeff elkins
Howdy,

This may not belong here, if so apologies...

I'm a python newbie, but have completed a console app that I'd like to run 
under X. Reading recent postings here, wxpython seemed a reasonable choice so 
under debian sid, I installed (via apt-get) the various wxpython stuff 
available.:

libwxgtk2.4-python 
libwxgtk2.5.3-python
python-opengl
python-pythoncard
python2.1-opengl 
python2.2-opengl 
python2.3-opengl 
python2.3-pythoncard
pythoncard 
pythoncard-doc
pythoncard-tools
wx2.5-examples
wxpython2.5.3 
wxwin2.4-examples

test.py crashes with the error below. Any clues?  

===

Running test.py: 

Traceback (most recent call last):
  File "./test.py", line 87, in ?
app = MyApp(0) # Create an instance of the application class
  File "/usr/lib/python2.3/site-packages/wxPython/wx.py", line 1951, in 
__init__
_wxStart(self.OnInit)
  File "./test.py", line 76, in OnInit
frame = MyFrame(None, -1, "This is a test")
  File "./test.py", line 26, in __init__
self.Bind(wx.EVT_SIZE, self.OnSize)
AttributeError: MyFrame instance has no attribute 'Bind'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

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

> Mike Meyer wrote:
>
>> "Simon John" <[EMAIL PROTECTED]> writes:
>> 
>>> I still love Perl, it's a bit of an art form, as "there's more than
>>> one way to do it", whereas Python usually only allows one way to do
>>> it, which may or may not be a better mantra
>> 
>> The Python mantra leads to 1) less programmer overhead, and 2) faster
>> improvements in the language.
>> 
>> To be a Perl expert, you have to know which of the many ways to do
>> various things is the fasted under what conditions.
>
> Why?

One of the stated conditions for more than one Perl position I've
looked at.

>> Python programmers
>> seldom have to worry about that - there's usually only one [obvious]
>> way to do things, so you just do it that way.
>
> I doubt that :-D. I have never seen a programming language that forced
> me in such a way :-D. 

I'd say you haven't seen a lot of languages - including Python. COBOL,
Eiffel, Rexx, Scheme, APL and a few others come to mind as "there's
usually only one way to do things". Python is one of them.

As a programmer, I find this very *freeing*. I can quite worrying
about implementation minutia - just do things the obvious way - and
worry instead about the "big picture"

>> Having only one obvious way
> I doubt that too ;-)

Try programming in older Python for a while. You'll quit doubting it.

>> to do things means developers only have to
>> worry about impact on that way when making improvements, which will
>> speed them up.
> Yeah, Perl programmers are extremely slow ;-)

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

>> The problem these days is that there are now multiple ways to do a
>> variety of things, because we have the "new, pythonic" way and the
>> "old, backwards-compatible way". So it's no longer clear which is the
>> fastest -
> In most cases, why worry? If speed is an issue you should probably have
> picked a different programming language in the first place (for that
> part of the code). 

You apparently haven't been programming in Python very long. If speed
is an issue, you should probably pick a different
algorithm. Well-written Python programs use the C-coded parts of
Python for the time-critical part of the code.

>> and in the case of generators versus list comprehensions,
>> it's not clear which you should be using. To bad.
> Use the one that is the easiest to read and understand by yourself.
> That's how I program Perl, and that's how I am going to program Python. 

The thing is, in Python there usually is one obvious way to do
things. That's changed in recent years as improvements have been added
without dropping the features they replaced so as not to break old
programs.

> An overloaded toolbox doesn't mean that if you have to hang a painting
> on the wall that you have to think for 6 hours which tool you should
> use. You just take the one that does the job in a way you feel
> comfortable with. I know that the Perl mantra is often misunderstood,
> but in my experience only by people who have very little experience with
> the language. 

The problem with using "the way you feel comfortable with" is that it
may not be comfortable for the maintainer - even if that's you six
months from now. My Perl evolved from very shell script like (lots of
backticks and passing around the full text of files) to one more
C-like as I used the language. That change was largely driven by
performance concerns as my understanding of the language grew.

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


Unicode problems, yet again

2005-04-23 Thread Ivan Voras
I have a string fetched from database, in iso8859-2, with 8bit 
characters, and I'm trying to send it over the network, via a socket:

  File "E:\Python24\lib\socket.py", line 249, in write
data = str(data) # XXX Should really reject non-string non-buffers
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0161' in 
position 123: ordinal not in range(128)

The other end knows it should expect this encoding, so how to send it?
(Does anyone else feel that python's unicode handling is, well... 
suboptimal at least?)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bounding box on clusters in a 2D list

2005-04-23 Thread bearophileHUGS
I hope this is what you need, sometimes understanding the question is
one of the hardest parts :-)

If you can use a graph data structure, you can create a graph, and then
you can find the lenght of all its connected components (indentations
reduced to 2 spaces):

. def mat2graph(g, m, good=None, w=1):
.   "Function docs..."
.   g.clear()
.   if m and isinstance(m, (list, tuple)):
. if good != None:
.   m = [[good(e) for e in row] for row in m]
. maxy = len(m)-1
. maxx = len(m[0])-1
. add = g.addBiArc
. for y, row in enumerate(m):
.   for x, e in enumerate(row):
. if e:
.   g.addNode((x,y)) # Necessary for isolated nodes.
.   if x>0 and m[y][x-1]: add( (x,y), (x-1,y), w=w)
.   if x0 and m[y-1][x]: add( (x,y), (x,y-1), w=w)
.   if yhttp://www.student.kuleuven.ac.be/~m0216922/CG/floodfill.html""";
. if c>=0 and c=0 and rhttp://www.codeproject.com/gdi/QuickFill.asp
I think Python PIL doesn't support flood fills, and I think doing it
with Numarray is slower, and it's useful only to reduce the used
memory.
This connected program is slow and raw, and it uses recursivity a lot,
so it can crash the interpreter. You can use a data structure to
implement the stack yourself, to speed this program up. But for small
matrices I think this connected is enough ^_^

Bear hugs,
Bearophile

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


Re: Python or PHP?

2005-04-23 Thread Peter Ammon
Leif K-Brooks wrote:
John Bokma wrote:
my $sort = $cgi->param( "sort" );
my $query = "SELECT * FROM table WHERE id=? ORDER BY $sort";

And the equivalent Python code:
cursor.execute('SELECT * FROM table WHERE id=%%s ORDER BY %s' % sort, 
[some_id])

You're right, of course, about being *able* to write code with SQL 
injection vulnerabilities in Python. But it's not even close to being as 
easy as in PHP.
I'm bewildered why you haven't mentioned magic quotes.  A one line 
change to the configuration file can render your PHP site almost 
entirely immune to SQL injection attacks.

-Peter
--
Pull out a splinter to reply.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using Ming on Windows

2005-04-23 Thread André Roberge
Colin J. Williams wrote:
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.

I installed MinGW on a Windows XP with no trouble.  One needs to install 
MSYS, as well as MinGW, since some modules (eg. make) are only available
in MSYS.

Currently, I am trying to build a package from source and have some 
unresolved problems.  Earlier I had tried to use the Borland 
commandline, without success.

Colin W.
MinGW is a minimalistic Gnu for Windows.
Ming is a Flash/swf library.
A.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using Ming on Windows

2005-04-23 Thread Colin J. Williams
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
I installed MinGW on a Windows XP with no trouble.  One needs to install 
MSYS, as well as MinGW, since some modules (eg. make) are only available
in MSYS.

Currently, I am trying to build a package from source and have some 
unresolved problems.  Earlier I had tried to use the Borland 
commandline, without success.

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


Re: Handling lists

2005-04-23 Thread Michael Spencer
[EMAIL PROTECTED] wrote:
...
list = [[10,11,12,13,14,78,79,80,81,300,301,308]]
how do I convert it so that I arrange them into bins  .
so If i hvae a set of consecutive numbers i would like to represent
them as a range in the list with max and min val of the range alone.
I shd get something like 
list = [[10,14],[78,81],[300,308]]


Mage:
Maybe:
list = [10,11,12,13,14,78,79,80,81,300,301,308]
new_list = []
start = 0
for i in range(1,len(list) + 1):
if i == len(list) or list[i] - list[i-1] <> 1:
new_list.append([list[start],list[i-1]])
start = i
print new_list
[EMAIL PROTECTED] wrote:
yes that makes sense.But the problem I am facing is  if list=
[300,301,303,305] I want to consider it as one cluster and include the
range as [300,305] so this is where I am missing the ranges.
so If the list has l = [300,301,302,308,401,402,403,408] i want to
include it as [[300,308],[401,408]].

Mage's solution meets the requirements that you initially stated of treating 
*consecutive* numbers as a group.  Now you also want to consider 
[300,301,303,305] as a cluster.

You need to specify your desired clustering rule, or alternatively specify ho 
many bins you want to create, but as an example, here is a naive approach, that 
could be adapted easily to other clustering rules and (a bit less easily) to 
target a certain number of bins

def lstcluster(lst):
# Separate neighbors that differ by more than the mean difference
lst.sort()
diffs = [(b-a, (a, b)) for a, b in zip(lst,lst[1:])]
mean_diff = sum(diff[0] for diff in diffs)/len(diffs)
breaks = [breaks for diff, breaks in diffs if diff > mean_diff]
groups = [lst[0]] + [i for x in breaks for i in x] + [lst[-1]]
igroups = iter(groups) # Pairing mechanism due to James Stroud
return [[i, igroups.next()] for i in igroups]
Note this is quite inefficient due to creating several intermediate lists.  But 
it's not worth optimizing yet, since I'm only guessing at your actual requirement.

lst0 = [10,11,12,13,14,78,79,80,81,300,301,308]
lst1 = [10,12,16,24,26,27,54,55,80,100, 105]
lst3 = [1,5,100,1000,1005,1009,1, 10010,10019]
 >>> lst0 = [10,11,12,13,14,78,79,80,81,300,301,308]
 >>> lst1 = [10,12,16,24,26,27,54,55,80,100, 105]
 >>> lst2 = [1,5,100,1000,1005,1009,1, 10010,10019]
 >>> lstcluster(lst0)
 [[10, 14], [78, 81], [300, 308]]
 >>> lstcluster(lst1)
 [[10, 27], [54, 55], [80, 80], [100, 105]]
 >>> lstcluster(lst2)
 [[1, 1009], [1, 10019]]
 >>>
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Leif Biberg Kristensen
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.
-- 
Leif Biberg Kristensen
http://solumslekt.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Leif K-Brooks
John Bokma wrote:
my $sort = $cgi->param( "sort" );
my $query = "SELECT * FROM table WHERE id=? ORDER BY $sort";
And the equivalent Python code:
cursor.execute('SELECT * FROM table WHERE id=%%s ORDER BY %s' % sort, 
[some_id])

You're right, of course, about being *able* to write code with SQL 
injection vulnerabilities in Python. But it's not even close to being as 
easy as in PHP.
--
http://mail.python.org/mailman/listinfo/python-list


Re: PDF Printing support from Python

2005-04-23 Thread Grant Edwards
On 2005-04-23, Mike Meyer <[EMAIL PROTECTED]> wrote:

>>> No, you don't. My print system does that, and I don't have
>>> acrobat installed. I have ghostscript installed, which
>>> includes pdf2ps - which handles this particular translation.
>>>
>>  Okay, so you've converted one page layout language
>> (PDF) to another (PS)... To actually print it you still need a
>> RIP. A PostScript laser printer has the RIP built-in, but
>> consumer level Windows printers do not have a PostScript RIP
>> -- and some printers don't even have their own specific RIP
>> built-in ("winprinters" put the RIP into the software driver
>> that runs on the Windows machine, rather than sending drawing
>> commands to the printer for rendering).
>
> RIP? That term is to generic for google to be much use.

Raster Image Processor.  It renders postscript into a raster
image at the proper image.

-- 
Grant Edwards   grante Yow!  If this is the DATING
  at   GAME I want to know your
   visi.comFAVORITE PLANET! Do I get
   th' MICROWAVE MOPED?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Leif K-Brooks
John Bokma wrote:
Not. Perl and Java use similar methods where one can specify place holders, 
and pass on the data unescaped. But still injection is possible.
How?
--
http://mail.python.org/mailman/listinfo/python-list


Re: PDF Printing support from Python

2005-04-23 Thread Mike Meyer
Dennis Lee Bieber <[EMAIL PROTECTED]> writes:

> On Fri, 22 Apr 2005 17:41:22 -0500, Mike Meyer <[EMAIL PROTECTED]> declaimed
> the following in comp.lang.python:
>
>> No, you don't. My print system does that, and I don't have acrobat
>> installed. I have ghostscript installed, which includes pdf2ps - which
>> handles this particular translation.
>>
>   Okay, so you've converted one page layout language (PDF) to
> another (PS)... To actually print it you still need a RIP. A PostScript
> laser printer has the RIP built-in, but consumer level Windows printers
> do not have a PostScript RIP -- and some printers don't even have their
> own specific RIP built-in ("winprinters" put the RIP into the software
> driver that runs on the Windows machine, rather than sending drawing
> commands to the printer for rendering).

RIP? That term is to generic for google to be much use.

If you're saying you need a tool to convert from PDF to whatever the
printer understands, you're right. You can't avoid that. On Unix, PS
is used as the "universal" printer language. Unix vendors selling
printers sold PS printers 20 years ago. That's when apsfilter showed
up on the scene, automatically converting everything to PS to send it
to the printer. (These days, magicfilter is a much better tool than
apsfilter, though it's harder to install). That's why a "competent"
printer installation these days will include ghostscript (or something
equivalent) to drive the printer, and why my primary printer speaks
PostScript.

I disagree with your description of WinPrinters. Those are printers to
stupid to handle flat ASCII, so your computer has to convert flat
ASCII files to postscript or some other graphics format before you can
print them. (This is where magicfilter beats apsfilter - apsfilter
converts ASCII to PS to graphics images, whereas magicfilter can pass
the text straight through. This has caused apsfilter to fail on some
systems where magicfilter would work like a charm).  Such printers
typically only come with drivers for Windows, and are completely
useless - unable to even print flat ASCII text - on other systems,
hence the moniker "WinPrinters". Non-winprinters can be used to print
flat ASCII without a driver of any kind. GhostScript now includes
graphics drivers for several winprinters.

The only way to have Python render PDF (or PS, or JPEG, or any other
graphics format) without a "driver" of some kind is to write the
driver in Python. That's a pretty silly thing to want to do. For one
thing, the performance will probably suck. For another, there are lots
of drivers already written that you can use.

The only thing better than writing it in Python is finding that
someone else has already written 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-23 Thread Mike Meyer
"Simon John" <[EMAIL PROTECTED]> writes:

> I still love Perl, it's a bit of an art form, as "there's more than one
> way to do it", whereas Python usually only allows one way to do it,
> which may or may not be a better mantra

The Python mantra leads to 1) less programmer overhead, and 2) faster
improvements in the language.

To be a Perl expert, you have to know which of the many ways to do
various things is the fasted under what conditions. Python programmers
seldom have to worry about that - there's usually only one [obvious]
way to do things, so you just do it that way.

Having only one obvious way to do things means developers only have to
worry about impact on that way when making improvements, which will
speed them up.

The problem these days is that there are now multiple ways to do a
variety of things, because we have the "new, pythonic" way and the
"old, backwards-compatible way". So it's no longer clear which is the
fastest - and in the case of generators versus list comprehensions,
it's not clear which you should be using. To bad.

   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: func_code vs. string problem

2005-04-23 Thread Steven Bethard
Filip Dreger wrote:
Uzytkownik "Steven Bethard" <[EMAIL PROTECTED]> napisal w 
wiadomosci news:[EMAIL PROTECTED]

See the documentation:
http://docs.python.org/ref/dynamic-features.html
"""The eval(), execfile(), and input() functions and the exec 
statement do not have access to the full environment for resolving 
names. Names may be resolved in the local and global namespaces of 
the caller. Free variables are not resolved in the nearest enclosing 
namespace, but in the global namespace."""
Thank you! I feel silly I have not found the piece of instruction 
myself. And even worse, as I still do not understand: if exec() 
resolves free bariable names in the global namespace, how come it 
works well with code in a string? Or with a code in a compiled string?
Well, probably the best thing to do is to check out what byte-code is 
generated in each case:

py> s = compile('print b', 'string', 'exec')
py> def f():
... print b
...
py> import dis
py> dis.dis(s)
  1   0 LOAD_NAME0 (b)
  3 PRINT_ITEM
  4 PRINT_NEWLINE
  5 LOAD_CONST   0 (None)
  8 RETURN_VALUE
py> dis.dis(f)
  2   0 LOAD_GLOBAL  0 (b)
  3 PRINT_ITEM
  4 PRINT_NEWLINE
  5 LOAD_CONST   0 (None)
  8 RETURN_VALUE
So, the code is basically identical, except that with the string, the 
code uses LOAD_NAME, while with the function, the code uses LOAD_GLOBAL. 
 Note that this is because Python can tell that b is not defined in the 
function, and so it assumes that is must be a global lookup.  Look what 
happens if I give f a parameter:

py> def f(b):
... print b
...
py> dis.dis(f)
  2   0 LOAD_FAST0 (b)
  3 PRINT_ITEM
  4 PRINT_NEWLINE
  5 LOAD_CONST   0 (None)
  8 RETURN_VALUE
Now f is using LOAD_FAST, which looks at the locals.  I believe the 
point of LOAD_GLOBAL and LOAD_FAST (instead of always using LOAD_NAME) 
is to increase performance in the common case, where exec is not used.

Seems like the documentation is being a little conservative -- it does 
look like some statements will do the lookup in the locals too...  If I 
was more confident about what goes on here, I'd probably try to file a 
documentation bug...

The manual says I can pass two dictionaries to exec, one for global 
namespace and one for local. But, strange as it seems, I could not get 
it to work. In the example I gave, changing exec f.func_code to exec 
f.func_code in globals(),locals() does not help a bit.
That's because, as the dis.dis output above shows, the function you've 
defined is only searching the global namespace.  So the locals() dict 
you pass won't ever be looked at.

[snip example using locals as globals]
I thought about that... I don't know why, but it seems wrong. Maybe 
the updating dictionaries is not very expensive, but there must be 
some better way. This code has a 'workaround - fixme' written all over 
it.
Yeah, I agree.  On the other hand, whenever I see exec, it has 
'workaround - fixme' written all over it too. ;)

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


Re: func_code vs. string problem

2005-04-23 Thread Filip Dreger
Uzytkownik "Steven Bethard" <[EMAIL PROTECTED]> napisal w 
wiadomosci news:[EMAIL PROTECTED]

> See the documentation:
>
> http://docs.python.org/ref/dynamic-features.html
>
> """The eval(), execfile(), and input() functions and the exec 
> statement do not have access to the full environment for resolving 
> names. Names may be resolved in the local and global namespaces of 
> the caller. Free variables are not resolved in the nearest enclosing 
> namespace, but in the global namespace."""

Thank you! I feel silly I have not found the piece of instruction 
myself. And even worse, as I still do not understand: if exec() 
resolves free bariable names in the global namespace, how come it 
works well with code in a string? Or with a code in a compiled string?

> Note the last sentence, which tells you that your free variable, 
> 'abc', will be resolved in the *global* namespace.  In your 
> particular problem, you can solve this by substituting your local 
> namespace for the global namespace.

This particular problem - sadly - is a simplified version of the real 
one. I need access to both: global and local namespaces, so this 
solution is not for me.
The manual says I can pass two dictionaries to exec, one for global 
namespace and one for local. But, strange as it seems, I could not get 
it to work. In the example I gave, changing exec f.func_code to exec 
f.func_code in globals(),locals() does not help a bit.

> One possible workaround might be:
>
> py> class foo:
> ... def test(self):
> ... print "ABC"
> ... def checkfunction(self):
> ... abc=10
> ... l = locals()
> ... l.update(globals())
> ... exec myfunction.func_code in l
> ... def checkstring(self):
> ... abc=10
> ... exec "print abc;self.test()"
> ...
> py> foo().checkfunction()
> __main__.foo
> 10
> ABC

I thought about that... I don't know why, but it seems wrong. Maybe 
the updating dictionaries is not very expensive, but there must be 
some better way. This code has a 'workaround - fixme' written all over 
it.
Up to now, each time I encountered such a workaroundish solution, it 
turned out Python has a cleaner way to do it. I sure hope this is also 
the case here :-).

> But I'd have to know what your real use case is to tell you whether 
> or not this is worth the trouble.  Why do you want to exec the 
> func_code anyway?  Why can't you just call the function?

I put the description in the other post. Perhaps it's jkust my design 
that's broken.
Thanks again.

regards,
Filip Dreger


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


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

2005-04-23 Thread Pierre Rouleau
Greetings,
I'm wondering why the >> operator does not use the write() method of a 
class derived from the built-in file class as in DerivedFile below.

In the following example:
- StringFile is just a file-like string accumulation class that can be 
used in place of a real file to accumulate strings that would otherwise 
be printed.  Works fine, can accumulate strings with the >> operator, 
but is not a true file.

- DelegatedFile is a new-style class, a true file class, which provides 
all the features of a real file through delegation.  It also works fine 
and can accumulate string with the >> operator.

- DerivedFile is a new-style class that is derived from file.  It 
behaves like a true file, but the >> operator does not call its write() 
method.  Why is that?

Is this related to the fact that on object from that class is seen as a 
file (as shown at the end of the code session below)?

Is this intended or is it a flaw in the language that is waiting to be 
fixed?

>>> import sys
>>> sys.ps2=' ... '; sys.ps1=' >>> '
 >>> def hello(stream=None):
 ... if stream is None:
 ... stream = sys.stdout
 ... print >> stream, "Bonjour!"
 ...
 >>> # Using a duck-typing to define a class
 ... # that behaves like a file for writing only.
 ... class StringFile:
 ... "A file-like object to accumulate strings"
 ... # print >> aStringFile works
 ... def __init__(self):
 ... self.strings = []
 ... def write(self, text):
 ... self.strings.append(text)
 ... def writelines(self, lines):
 ... self.strings.extend(lines)
 ...
 >>> # Using delegation to file to create a class that
 ... # extends the built-in file object.
 ... class DelegatedFile(object):
 ... "A file-like object to accumulate strings"
 ... # print >> aStringFile works
 ... def __init__(self, *args):
 ... self.strings = []
 ... self._file = file(*args)
 ... def __getattr__(self, name) :
 ... return getattr(self._file, name)
 ... def write(self, text):
 ... self.strings.append(text)
 ... self._file.write(text)
 ... def writelines(self, lines):
 ... self.strings.extend(lines)
 ... self._file.writelines(lines)
 ...
 >>> # Using derivation from file to create a class
 ... # that extends file. But has a flaw in the use of the >> operator!
 ... class DerivedFile(file):
 ... "A file object that accumulated written strings"
 ... # print >> a DerivedFile doe NOT work!
 ... def __init__(self, *args):
 ... self.strings = []
 ... file.__init__(self, *args)
 ... def write(self, text):
 ... self.strings.append(text)
 ... file.write(self, text)
 ... # super(DerivedFile, self).write(text)
 ... def writelines(self, lines):
 ... self.strings.extend(lines)
 ... file.writelines(self, lines)
 ... # super(DerivedFile, self).writelines(lines)
 ...
 >>> hello()
Bonjour!
 >>>
 >>> sf = StringFile()
 >>> hello(sf)
 >>> sf.strings
['Bonjour!', '\n']
 >>>
 >>> dg = DelegatedFile("temp.txt","w")
 >>> hello(dg)
 >>> dg.close()
 >>> dg.strings
['Bonjour!', '\n']
 >>> for line in file("temp.txt"): print line
 ...
Bonjour!
 >>> df = DerivedFile("temp2.txt","w")
 >>> hello(df)
 >>> df.close()
 >>> df.strings
[]
 >>> for line in file("temp2.txt"): print line
 ...
Bonjour!
 >>>
 >>> sf
<__main__.StringFile instance at 0x008D86C0>
 >>> dg
<__main__.DelegatedFile object at 0x008D50B0>
 >>> df

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


Re: func_code vs. string problem

2005-04-23 Thread Steven Bethard
Filip Dreger wrote:
If I had a magic function 'exec in current scope' I would implement it 
like this:

class actor:
  def __init__():
self.roles=[]
  def act():
for i in self.roles:
  exec i in current scope
then the roles would simply be functions defined in any importable 
file. For example creating an actor that logs each time it is called 
would be as simple as:

import actor
def log():
  self.counter+=1
  print "called %d times"%self.counter
a=actor.actor()
a.counter=0
a.roles.append(log)
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)
And then write your other modules like:
import actor
def log(self):
self.counter += 1
print "called %d times"%self.counter
a = actor.actor()
a.counter = 0
a.roles.append(log)
The only real difference here is that log is basically declared as an 
instance method.  So if you need to update actor.actor state, you simply 
modify the self object.

2. I need the roles to have full access to global and local namespace 
of the actor object (sometimes they have to change it, and sometimes 
they have to use some external modules) - the roles should work like 
plugins.
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?

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


Re: Python or PHP?

2005-04-23 Thread Leif K-Brooks
Mage wrote:
However one of the worst cases is the sql injection attack. And sql
injections must be handled neither by php nor by python but by the
programmer.
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])
And "foo'bar" will be implicitly escaped to whatever is appropriate for 
your database. How's that for Python handling SQL injection automatically?
--
http://mail.python.org/mailman/listinfo/python-list


Re: func_code vs. string problem

2005-04-23 Thread Filip Dreger

Uzytkownik "Steven Bethard" <[EMAIL PROTECTED]> napisal w 
wiadomosci news:[EMAIL PROTECTED]
> Filip Dreger wrote:
>> I am trying to find a way of executing functions without creating a 
>> nested scope, so they can share local and global namespace (even if 
>> they are declared in some other module).
>
> Why?  Can you explain what the use case is?

I have a large set of objects of a single class - 'actor'. They are 
created all at once, and they all live in a sort of container written 
in C. The methods of the functions are few and general. One of them is 
simply 'act()', that is called by the C program every X seconds (tics, 
whatever).
Each object can play 0..N roles, and the roles played by an object 
often change during its lifetime. The roles should be played in the 
act() method. Also, the roles should be defined in some simple way, 
and in an external python file (so adding/removing roles does not 
require recompiling of the parts embedded in C).

If I had a magic function 'exec in current scope' I would implement it 
like this:

class actor:
  def __init__():
self.roles=[]
  def act():
for i in self.roles:
  exec i in current scope

then the roles would simply be functions defined in any importable 
file. For example creating an actor that logs each time it is called 
would be as simple as:

import actor

def log():
  self.counter+=1
  print "called %d times"%self.counter

a=actor.actor()
a.counter=0
a.roles.append(log)

Let me recapitulate (is that the right English word?):
1. I need to keep the definitions of roles in a separate file (they 
can not simply be additional methods)
2. I need the roles to have full access to global and local namespace 
of the actor object (sometimes they have to change it, and sometimes 
they have to use some external modules) - the roles should work like 
plugins.
3. I guess I also need a fresh look at the problem. Maybe I am simply 
going the wrong way? I am more than willing to change my design, if 
someone shows me the light :-)

regards,
Filip Dreger 


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


Re: Handling lists

2005-04-23 Thread James Stroud
On Saturday 23 April 2005 12:50 pm, [EMAIL PROTECTED] wrote:
> I have a question on python lists.
> Suppose I have a 2D list
> list = [[10,11,12,13,14,78,79,80,81,300,301,308]]
> how do I convert it so that I arrange them into bins  .
> so If i hvae a set of consecutive numbers i would like to represent
> them as a range in the list with max and min val of the range alone.
> I shd get something like
> list = [[10,14],[78,81],[300,308]]



Here is an interesting way:

>>> a = iter([1,2,3,4])
>>> [(b,a.next()) for b in a]
[(1, 2), (3, 4)]

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: memory profiler?

2005-04-23 Thread John Reese
On Wed, 20 Apr 2005 23:06:51 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:
> John Reese wrote:
>> Is there a memory or heap profiler for python programs?  So that, for
>> example, if a program was bloating over time I could see how many of
>> each object there were and maybe even where the references were?
>
> The "gc" module has a variety of helpful features
> like that.
>
> -Peter

In particular, get_objects() and get_referrers().  Good point.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Ming on Windows

2005-04-23 Thread Jack Diederich
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: XML file parsing with SAX

2005-04-23 Thread Uche Ogbuji
On 4/23/05, Willem Ligtenberg <[EMAIL PROTECTED]> wrote:
> so that will be sax.handler.feature_external_ges = "false"

Yes.

> And it will work?

Honestly, I'm not sure.  It should, but I've found these edge cases a
bit hard to predict in  the Python built-in libs :-(

> But what about using a catalog? I am very new to python and XML...

Catalogs allow you to rewrite the IDs for entities and such.  So if
you had an XML file with an entity at a URL, but you were working
offline, you could use a catalog to "redirect" the entity to a copy on
your local filesystem.

Problem, now that I think of it, is that I'm not sure you can specify
an catalog in PySAX.  You might instead have to override the method
entityResolver in your handler (and be sure to ).  See the example in
listing 1 and and discussion here:

http://www.xml.com/pub/a/2005/03/02/pyxml.html

Good luck.

-- 
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Use CSS to display XML, part 2 -
http://www-128.ibm.com/developerworks/edu/x-dw-x-xmlcss2-i.html
XML Output with 4Suite & Amara -
http://www.xml.com/pub/a/2005/04/20/py-xml.htmlUse XSLT to prepare XML
for import into OpenOffice Calc -
http://www.ibm.com/developerworks/xml/library/x-oocalc/
Schema standardization for top-down semantic transparency -
http://www-128.ibm.com/developerworks/xml/library/x-think31.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: func_code vs. string problem

2005-04-23 Thread Steven Bethard
Filip Dreger wrote:
I am trying to find a way of executing functions without creating a 
nested scope, so they can share local and global namespace (even if 
they are declared in some other module).
Why?  Can you explain what the use case is?
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: func_code vs. string problem

2005-04-23 Thread Steven Bethard
Filip Dreger wrote:
Each function has a func_code property that is suposed to contain the 
pure bytecode of the function. All the context (including reference to 
relevant namespaces) is stored in different fields of the function 
object. Since 'exec' is able to execute any string or bytecode in the 
current scope, it would seem possible to execute code of any function 
in any namespace. But no matter how I tried, I could not do it. There 
must be something I am missing.
Here's what I do:(if anyone wants to help, I placed the source 
under http://www.bajobongo.net/foo.py - tested on Python 2.4.1)

1. I declare a function. In the next steps I will try to run its code 
from inside a class:

def myfunction():
   print abc
   self.test()
2. I declare a class foo, with two methods. The first one tries to 
reach some local variables from a string passed to exec. The other one 
tries to do the same from inside a bytecode (from myfunction). IMHE 
this should make no difference to 'exec' - [spoiler: it does].

class foo:
   def test(self):
  print "ABC"
   def checkfunction(self):
  abc=10
  exec myfunction.func_code
   def checkstring(self):
  abc=10
  exec "print abc;self.test()"
3. I test the both methods. Sadly, the 'checkfunction' fails to find 
the correct namespace (id does not see 'abc' nor 'self'). Adding 
things like:
"exec myfunction.func_code in globals(),locals()" does not help.

i=foo()
i.checkstring()
i.checkfunction()  # this throws exception; why???
See the documentation:
http://docs.python.org/ref/dynamic-features.html
"""The eval(), execfile(), and input() functions and the exec statement 
do not have access to the full environment for resolving names. Names 
may be resolved in the local and global namespaces of the caller. Free 
variables are not resolved in the nearest enclosing namespace, but in 
the global namespace."""

Note the last sentence, which tells you that your free variable, 'abc', 
will be resolved in the *global* namespace.  In your particular problem, 
you can solve this by substituting your local namespace for the global 
namespace:

py> def myfunction():
... print abc
... self.test()
...
py> class foo:
... def test(self):
... print "ABC"
... def checkfunction(self):
... abc=10
... exec myfunction.func_code in locals()
... def checkstring(self):
... abc=10
... exec "print abc;self.test()"
...
py> foo().checkstring()
10
ABC
py> foo().checkfunction()
10
ABC
But note that if your code actually needs access to any globals, it's 
out of luck:

py> def myfunction():
... print foo
... print abc
... self.test()
...
py> foo().checkfunction()
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 6, in checkfunction
  File "", line 2, in myfunction
NameError: global name 'foo' is not defined
One possible workaround might be:
py> class foo:
... def test(self):
... print "ABC"
... def checkfunction(self):
... abc=10
... l = locals()
... l.update(globals())
... exec myfunction.func_code in l
... def checkstring(self):
... abc=10
... exec "print abc;self.test()"
...
py> foo().checkfunction()
__main__.foo
10
ABC
But I'd have to know what your real use case is to tell you whether or 
not this is worth the trouble.  Why do you want to exec the func_code 
anyway?  Why can't you just call the function?

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


Re: Handling lists

2005-04-23 Thread [EMAIL PROTECTED]
yes that makes sense.But the problem I am facing is  if list=
[300,301,303,305] I want to consider it as one cluster and include the
range as [300,305] so this is where I am missing the ranges.
so If the list has l = [300,301,302,308,401,402,403,408] i want to
include it as [[300,308],[401,408]].

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


Re: XML file parsing with SAX

2005-04-23 Thread Willem Ligtenberg
I didn't make the XML file. And I don't like messing with other peoples
data. So I just want my SAX parser to ignore it. I can't help if other
people make it hard for me to read their xml file...

On Sat, 23 Apr 2005 13:48:49 -0600, Uche Ogbuji wrote:

> On Sat, 2005-04-23 at 15:20 +0200, Willem Ligtenberg wrote:
>> I decided to use SAX to parse my xml file.
>> But the parser crashes on:
>>   File "/usr/lib/python2.3/site-packages/_xmlplus/sax/handler.py", line 38, 
>> in fatalError
>> raise exception
>> xml.sax._exceptions.SAXParseException: NCBI_Entrezgene.dtd:8:0: error in 
>> processing external entity reference
>> 
>> This is caused by:
>> > "NCBI_Entrezgene.dtd">
>> 
>> If I remove it, it parses normally.
>> I've created my parser like this:
>> import sys
>> from xml.sax import make_parser
>> from handler import EntrezGeneHandler
>> 
>> fopen = open("mouse2.xml", "r")
>> ch = EntrezGeneHandler()
>> saxparser = make_parser()
>> saxparser.setContentHandler(ch)
>> saxparser.parse(fopen)
>> 
>> And the handler is:
>> from xml.sax import ContentHandler
>> 
>> class EntrezGeneHandler(ContentHandler):
>>  """
>>  A handler to deal with EntrezGene in XML
>>  """
>>  
>>  def startElement(self, name, attrs):
>>  print "Start element:", name
>> 
>> So it doesn't do much yet. And still it crashes...
>> How can I tell the parser not to look at the DOCTYPE declaration.
>> On a website:
>> http://www.devarticles.com/c/a/XML/Parsing-XML-with-SAX-and-Python/1/
>> it states that the SAX parsers are not validating, so this error shouldn't
>> even occur?
> 
> Just because it's not validating doesn't mean that the parser won't try
> to read the external entity.
> 
> Maybe you're looking for 
> 
> """
> feature_external_ges
> Value: "http://xml.org/sax/features/external-general-entities"; 
> true: Include all external general (text) entities. 
> false: Do not include external general entities. 
> access: (parsing) read-only; (not parsing) read/write
> """
> 
> Quote from:
> 
> http://docs.python.org/lib/module-xml.sax.handler.html
> 
> But you're on pretty shaky ground in any XML 1.x toolkit using a bogus
> DTDecl in this way.  Why go through the hassle?  Why not use a catalog,
> or remove the DTDecl?

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


Re: func_code vs. string problem

2005-04-23 Thread Filip Dreger
I came up with a simpler description of the problem.
It's all in the simple source:

# we define 'print b' in three different ways: as a string,
# a bytecode and a function
string="print b"
code=compile(string,'string','exec')
def function():
print b

# now we make functions that test if it is possible to execute 'print 
b'
# in some local scope

def execstring():
b=5
exec string

def execfunction():
b=5
exec function.func_code

def execcode():
b=5
exec code

execstring()   # works
execcode() # works
execfunction() # throws name error exception...

My problem is that both 'string' and 'code' are references to code 
objects, so they _should_ behave in the same way... I am close to 
giving up...
I am trying to find a way of executing functions without creating a 
nested scope, so they can share local and global namespace (even if 
they are declared in some other module). I _could_ turn them into 
strings and pass around as compiled objects, butthis would be very 
ugly. I am sure Python has some better, cleaner way to do this.

regards,
Filip Dreger 


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


Bounding box on clusters in a 2D list

2005-04-23 Thread [EMAIL PROTECTED]
If I have

ex: x = [[1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0],
 [1,1,1,0,1,1,0,0,0,0,0,1,1,1,1,0,0,0],
 [1,1,1,0,1,1,1,0,1,1,0,1,1,1,0,0,0,0],
 [0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0]]
what I want is a boundingbox over the region where we find clusters of
1's.So for instance in the above list first 3 roes and colums have 1's
so the area of that box is 3x3
so my final array should have an array of approx areas of clusters of
1's like
area = [ 9,4 ]
Hope I am clear with my question.

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


Re: Does numarray search for blas and lapack during installation?

2005-04-23 Thread RickMuller
IIRC, no. But the setup.py script is fairly easy to hack to link in
your own blas/lapack libraries.

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


Re: Python or PHP?

2005-04-23 Thread F. Petitjean
Le Sat, 23 Apr 2005 19:11:19 +0200, Fredrik Lundh a écrit :
> in PHP, good programmers are able to write bad programs without
> even noticing.

+1 QOTW

--- 
The use of COBOL cripples the mind; its teaching should, therefore, be
regarded as a criminal offense.
Dr. E.W. Dijkstra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Handling lists

2005-04-23 Thread Mage
[EMAIL PROTECTED] wrote:

>I have a question on python lists.
>Suppose I have a 2D list
>list = [[10,11,12,13,14,78,79,80,81,300,301,308]]
>how do I convert it so that I arrange them into bins  .
>so If i hvae a set of consecutive numbers i would like to represent
>them as a range in the list with max and min val of the range alone.
>I shd get something like 
>list = [[10,14],[78,81],[300,308]]
>
>  
>
Maybe:

list = [10,11,12,13,14,78,79,80,81,300,301,308]

new_list = []
start = 0
for i in range(1,len(list) + 1):
if i == len(list) or list[i] - list[i-1] <> 1:
new_list.append([list[start],list[i-1]])
start = i

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


Using Ming on Windows

2005-04-23 Thread André Roberge
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.
André
--
http://mail.python.org/mailman/listinfo/python-list


Handling lists

2005-04-23 Thread [EMAIL PROTECTED]
I have a question on python lists.
Suppose I have a 2D list
list = [[10,11,12,13,14,78,79,80,81,300,301,308]]
how do I convert it so that I arrange them into bins  .
so If i hvae a set of consecutive numbers i would like to represent
them as a range in the list with max and min val of the range alone.
I shd get something like 
list = [[10,14],[78,81],[300,308]]

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


Re: XML file parsing with SAX

2005-04-23 Thread Uche Ogbuji
On Sat, 2005-04-23 at 15:20 +0200, Willem Ligtenberg wrote:
> I decided to use SAX to parse my xml file.
> But the parser crashes on:
>   File "/usr/lib/python2.3/site-packages/_xmlplus/sax/handler.py", line 38, 
> in fatalError
> raise exception
> xml.sax._exceptions.SAXParseException: NCBI_Entrezgene.dtd:8:0: error in 
> processing external entity reference
> 
> This is caused by:
>  "NCBI_Entrezgene.dtd">
> 
> If I remove it, it parses normally.
> I've created my parser like this:
> import sys
> from xml.sax import make_parser
> from handler import EntrezGeneHandler
> 
> fopen = open("mouse2.xml", "r")
> ch = EntrezGeneHandler()
> saxparser = make_parser()
> saxparser.setContentHandler(ch)
> saxparser.parse(fopen)
> 
> And the handler is:
> from xml.sax import ContentHandler
> 
> class EntrezGeneHandler(ContentHandler):
>   """
>   A handler to deal with EntrezGene in XML
>   """
>   
>   def startElement(self, name, attrs):
>   print "Start element:", name
> 
> So it doesn't do much yet. And still it crashes...
> How can I tell the parser not to look at the DOCTYPE declaration.
> On a website:
> http://www.devarticles.com/c/a/XML/Parsing-XML-with-SAX-and-Python/1/
> it states that the SAX parsers are not validating, so this error shouldn't
> even occur?

Just because it's not validating doesn't mean that the parser won't try
to read the external entity.

Maybe you're looking for 

"""
feature_external_ges
Value: "http://xml.org/sax/features/external-general-entities"; 
true: Include all external general (text) entities. 
false: Do not include external general entities. 
access: (parsing) read-only; (not parsing) read/write
"""

Quote from:

http://docs.python.org/lib/module-xml.sax.handler.html

But you're on pretty shaky ground in any XML 1.x toolkit using a bogus
DTDecl in this way.  Why go through the hassle?  Why not use a catalog,
or remove the DTDecl?


-- 
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Use CSS to display XML, part 2 - 
http://www-128.ibm.com/developerworks/edu/x-dw-x-xmlcss2-i.html
XML Output with 4Suite & AMara - http://www.xml.com/pub/a/2005/04/20/py-xml.html
Use XSLT to prepare XML for import into OpenOffice Calc - 
http://www.ibm.com/developerworks/xml/library/x-oocalc/
Schema standardization for top-down semantic transparency - 
http://www-128.ibm.com/developerworks/xml/library/x-think31.html

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


python and Tile Studio

2005-04-23 Thread André Roberge
Has anyone used Python with Tile Studio to create games?
http://tilestudio.sourceforge.net/
André
--
http://mail.python.org/mailman/listinfo/python-list


Re: python modules in home dir

2005-04-23 Thread Uche Ogbuji
On Sat, 2005-04-16 at 08:12 -0600, Uche Ogbuji wrote:
> On Sat, 2005-04-09 at 14:09 -0700, dzieciou wrote:
> 
> > I'm new-comer in Python.
> > I want to install few Python modules (4Suite, RDFLib, Twisted and Racoon)
> > in my home directory, since Python installation is already installed in the
> > system
> > and I'm NOT its admin.
> > I cannot install pyvm (portable binary python machine) - have no such big
> > quota.
> > Any idea how can I solve it?
> 
> To install 4Suite in the home dir, use an incantation such as:
> 
> ./setup.py config --prefix=$HOME/lib
> ./setup.py install
> 
> Note: I expect you also installed Python in your home dir?

BTW, I expanded on this suggestion at:

http://copia.ogbuji.net/blog/2005-04-16/Installing


-- 
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Use CSS to display XML, part 2 - 
http://www-128.ibm.com/developerworks/edu/x-dw-x-xmlcss2-i.html
XML Output with 4Suite & AMara - http://www.xml.com/pub/a/2005/04/20/py-xml.html
Use XSLT to prepare XML for import into OpenOffice Calc - 
http://www.ibm.com/developerworks/xml/library/x-oocalc/
Schema standardization for top-down semantic transparency - 
http://www-128.ibm.com/developerworks/xml/library/x-think31.html

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


Re: Python or PHP?

2005-04-23 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2005-04-23 15:53:17 +0200:
> Lad wrote:
> 
> >Is anyone capable of providing Python advantages over PHP if there are
> >any?
>  
> I am also new to python but I use php for 4 years. I can tell:
> 
> - python is more *pythonic* than php
> - python has its own perfume
> http://www.1976.com.tw/image/trussardi_python_uomo.jpg  and it's nice.
> php doesn't have any smell
> - writing python programs you feel much better

No, *you* feel better. :)
 
> check this: http://wiki.w4py.org/pythonvsphp.html

The comparison found there is biased, the author is a Python
partisan.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Jeremy Bowers
On Sat, 23 Apr 2005 20:13:24 +0200, Mage wrote:
> Avoid them is easy with set_type($value,"integer") for integer values and
> correct escaping for strings.

"Avoiding buffer overflows in C is easy, as long as you check the buffers
each time."

The *existence* of a technique to avoid problems is not in question. The
problem is when the language makes it easier to *not* do the checks than
to do the checks. Any look at the real world shows that that pattern
causes trouble, and that clearly, the mere *existence* of a way to not get
in trouble is not sufficient in the general case.

Despite the fact that all you have to do to avoid cutting your finger off
with a saw is not stick your finger in the saw, most people, even
carpentry professionals, are going to want to use finger-guards and other
safety equipment. A programmer turning down such security protection
(without another good reason, which does happen), is being like the guy
too macho to use the finger guard; stupidity induced by arrogance, not
some one no longer using training wheels. Using PHP and futzing with SQL
directly is probably not a good enough reason, as surely PHP has safer
libraries available. (If not, my opinion of PHP goes down another notch.)

Data binding with something like SQLObject makes it *easier* to be secure
than insecure; barring an out-and-out bug in SQLObject (given the nature
of the requisite bug, it is extremely unlikely to have survived this
long), a programmer must go *way* out of their way to introduce the SQL
injection attacks that so plague PHP projects.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Mage
Fredrik Lundh wrote:

>
>sql injection?  what's your excuse for not using data binding?
>  
>
I am not sure I truly understand your question.
So far my own servers didn't get successful sql injection attack. I just
saw some on other sites and did one for demonstration.

Avoid them is easy with set_type($value,"integer") for integer values
and correct escaping for strings.

However, php programmers usually don't initialize their variables
because they don't have to do. They even turn off warnings and errors.
Our php errorlog at my full time working company is so huge I could cry.
We have php-copypasters.
I don't know anyone IRL who uses python. So I started to learn it.

   Mage


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


Re: PDF Printing support from Python

2005-04-23 Thread M.E.Farmer
> You're use of the word "driver" is one with which I'm not
> familiar.  But I don't really "do windows" so it's probably a
> Widnowism.
It is a windowism but not exclusively ;).
http://www.collaborium.org/onsite/romania/UTILS/Printing-HOWTO/winprinters.html

This is the first link I found that mentioned drivers, but the last
time I installed Linux-Mandrake I saw a document that went into detail
about CUPS and windows printing.
It seems that cups is available for windows( they also use the word
driver )
http://www.cups.org/windows/index.php
Ghostscript for windows available here
http://www.ghostscript.com/
http://www.cs.wisc.edu/~ghost/

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


Re: Python or PHP?

2005-04-23 Thread Fredrik Lundh
"Mage" wrote:

> I don't think so. Bad programmers are able to write bad programs in any
> language.

in PHP, good programmers are able to write bad programs without
even noticing.

(every successful server attack I've seen closely the last few years
have been through PHP.  it's totally without competition in this area)

> However one of the worst cases is the sql injection attack. And sql
> injections must be handled neither by php nor by python but by the
> programmer.

sql injection?  what's your excuse for not using data binding?





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


Re: Python Imaging Library and PyGTK - color image path?

2005-04-23 Thread Jeremy Bowers
On Sat, 23 Apr 2005 10:20:29 +0200, Fredrik Lundh wrote:
> which discusses draw_rgb_image and friends, and says that "if you can
> convert your PIL image to a  pixel data string or buffer object, you could
> use them to display the image".  here's some code that seems to do exactly
> that:
> 
> http://www.mail-archive.com/pygtk@daa.com.au/msg07167.html
> 
> (but maybe this is some kind of stupid "a bitmap isn't a pixmap isn't an
> image" thing?  if so, I suggest getting a modern windowing system ;-)

A varient; I was missing the gdk.pixbuf because I assumed that because
there was a gtk.pixbuf that I knew about, that I had all relevant data.
Were that the only pixbuf, that would be an atrocity. (Particularly odd
for GTK, the *Gimp* windowing toolkit.)

(It of course figures that was the google search; I think I tried
everything but that; "python imaging library" "pygtk" isn't anywhere near
as helpful, for instance.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Does numarray search for blas and lapack during installation?

2005-04-23 Thread Edward C. Jones
I have a PC with Debian sid installed. I install all my Python stuff in 
/usr/local. I just installed numarray 1.3.1. Blaslite and lapacklite 
were compiled. Did the installation process search for blas and lapack?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Simon John
I've been a PHP and Perl programmer (amongst others) for 10 years or
more now, and a Python coder for 3 or so.

I have come to hate PHP now, it's pseudo-OOP is awful, it's dog slow at
handling XML, it's so easy to use that most of the programmers I've had
contact with are very sloppy and do things like extract($_GET); or put
database usernames and passwords in index.php. I also have to agree
that php.net/manual seems to be the main reference that coders use -
which is not good if the comments are wrong!

Python seems to force you to write better code, maybe because of the
indentation, exception handling, proper OOP etc. Plus it's not so tied
into web stuff, in fact most of my Python programming is for the
desktop.

I still love Perl, it's a bit of an art form, as "there's more than one
way to do it", whereas Python usually only allows one way to do it,
which may or may not be a better mantra

I've come to allocate PHP the same standing as ASP, VB or Java - the
language is OK, but the programmers are usually crap.

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


Re: How to run Python in Windows w/o popping a DOS box?

2005-04-23 Thread Bengt Richter
On 22 Apr 2005 21:16:04 -0700, [EMAIL PROTECTED] wrote:

>>>I think of it like the ''.join semantics. The object knows best how
>to
>>>handle join (even if it looks wierd to some people). In the #! case,
>>>the program knows best how to start itself.
>
>>This I don't understand ;-)
>
>With  ','.join(['a','b','c'])You rely on what wants to join the
>sequence to handle the issue of joining rather than have the sequence
>understand joining. I think of it as the object knows best.
>
>I think of  #! as "the program knowing best" how to startup, rather
>than having to rely on something else to deal with it. I also like the
My point was that the "program" -- whether script or executable --
_is_ depending on something else, i.e., whatever is launching it
in an appropriate environment, and my real point was that the launcher
looks at the beginning of the file contents to check what to do, rather
than looking at separate file metadata. I am objecting to embeddeding
metadata in data. The convention of using a first #! line in scripts
as metadata and passing the whole script to whatever interpreter
means that the interpreters have to know to ignore the first line
--usually meaning the '#' is a comment line start. Or else it has
to be told with a command line option like python's -x to ignore
extraneous metadata. Carrying metadata in file names and extensions
is not better, just different, and brings a bag of problems, like
having no identifier for the data per se, just its various containers.

>text based simplicity and explictness. Just like text based "etc" files
>on unix versus the registry in windows. And, if you want you can add
>more power like use env variables in #!.
>It can be as simple or as powerful as you need, you can use whatever
>means you want to manage the #! line: text editors, other programs,
>etc.  It is data-centric, just like http, sql, file I/O rather than
>verb-centric (learn another whole set of methods to figure out how to
>change startup).
I don't disagree about the usefulness of various text data, I just
want to distinguish data from metadata and container identifiers
from data identifiers.
>
>hopefully I am making sense,
>
I think we were just looking a different aspects of the elephant ;-)

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


Re: Trouble Installing TTX/FontTools (asks for .NET FrameworkPackages)

2005-04-23 Thread Fredrik Lundh
Jesper Olsen wrote:

> > Apparently setup.py tries to compile a c file, which of course
> doesn't
> > work if there's no compiler.
>
> In fact it does not work even if there is a compiler - seems distutils
> has been broken in python2.4 (it works in python2.3).

distutils works just fine in 2.4.

but the standard Windows distribution of Python 2.4 is compiled with
a newer compiler.  if you don't have a compatible compiler on your
machine (or if the compiler isn't properly installed), setup won't be able
to build extensions for 2.4.





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


Re: Python or PHP?

2005-04-23 Thread Kirk Job Sluder
"Lad" <[EMAIL PROTECTED]> writes:

> Is anyone capable of providing Python advantages over PHP if there are
> any?
> Cheers,
> L.

PHP is strongly wedded to providing web-based content, while Python can
be used to build a large number of different types of applications.  

-- 
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


func_code vs. string problem

2005-04-23 Thread Filip Dreger
Each function has a func_code property that is suposed to contain the 
pure bytecode of the function. All the context (including reference to 
relevant namespaces) is stored in different fields of the function 
object. Since 'exec' is able to execute any string or bytecode in the 
current scope, it would seem possible to execute code of any function 
in any namespace. But no matter how I tried, I could not do it. There 
must be something I am missing.
Here's what I do:(if anyone wants to help, I placed the source 
under http://www.bajobongo.net/foo.py - tested on Python 2.4.1)

1. I declare a function. In the next steps I will try to run its code 
from inside a class:

def myfunction():
   print abc
   self.test()

2. I declare a class foo, with two methods. The first one tries to 
reach some local variables from a string passed to exec. The other one 
tries to do the same from inside a bytecode (from myfunction). IMHE 
this should make no difference to 'exec' - [spoiler: it does].

class foo:
   def test(self):
  print "ABC"
   def checkfunction(self):
  abc=10
  exec myfunction.func_code
   def checkstring(self):
  abc=10
  exec "print abc;self.test()"

3. I test the both methods. Sadly, the 'checkfunction' fails to find 
the correct namespace (id does not see 'abc' nor 'self'). Adding 
things like:
"exec myfunction.func_code in globals(),locals()" does not help.

i=foo()
i.checkstring()
i.checkfunction()  # this throws exception; why???

4. I try to find some help here, and hope to also gain better 
undesrtanding of how Python works :-)

Thanks for any suggestions,
regards,
Filip Dreger 


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


Re: Python or PHP?

2005-04-23 Thread Mage
Tim Tyler wrote:

>Mage <[EMAIL PROTECTED]> wrote or quoted:
>
>  
>
>>check this: http://wiki.w4py.org/pythonvsphp.html
>>
>>
>
>Good - but it hardly mentions the issue of security - which seems
>like a bit of a problem for PHP at the moment.
>  
>
I don't think so. Bad programmers are able to write bad programs in any
language. Maybe there are more bad php programmers than python
programmers and the 70% of the dynamic world wide web is copied from
user comments in the php.net/manual. However one of the worst cases is
the sql injection attack. And sql injections must be handled neither by
php nor by python but by the programmer.

I think a website or even a large portal is a well constructed database
with triggers and stored procedures and some "echo", "if", "foreach" and
"while" in the php code.

To me the advantage of python seems to come out when you deal with xml,
file handling or when you have to write a native server application for
your website. But I am so new here, others may say other things.

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


Re: XML parsing per record

2005-04-23 Thread Kent Johnson
Willem Ligtenberg wrote:
Is there an easy way, to couple data together. Because I have discoverd an
irritating feature in the xml file.
Sometimes this is a database reference:

UCSC


1234



And sometimes:

UCSC


1234



So I get a list database names and two! lists of ID's
And those two are in no way related. Is there an easy way to create a
dictionary like this DBname --> ID
If not, I still might need to revert to SAX... :(
None of your requirements sound particularly difficult to implement. If you would post a complete 
example of the data you want to parse and the data you would like to end up it would be easier to 
help you. The sample data you posted originally does not have many of the fields you want to extract 
and your example of what you want to end up with is not too clear either.

If you are having trouble with ElementTree I expect you will be completely lost with SAX, 
ElementTree is much easier to work with and cElementTree is very fast.

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


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread Bengt Richter
On 22 Apr 2005 20:45:55 -0700, "El Pitonero" <[EMAIL PROTECTED]> wrote:

>Bengt Richter wrote:
>> I still don't know what you are asking for, but here is a toy,
>> ...
>> But why not spend some time with the tutorials, so have a few more
>cards in your deck
>> before you try to play for real? ;-)
>
>Communication problem.
Indeed.

>
>All he wanted is automatic evaluation a la spreadsheet application.
>Just like in Microsoft Excel. That's all.
>
>There are many ways for implementing the requested feature. Here are
>two:
>
>(1) Push model: use event listeners. Register dependent quantities as
>event listeners of independent quantities. When an independent quantity
>is modified, fire off the event and update the dependent quantities.
>Excel uses the push model.
This is essentially what I was demonstrating with the namespace of FunArray,
showing object attribute namespace access as perhaps _the_ 'listening" hook
of Python -- which properties and overriding base class methods with
subclass methods etc. etc. all depend on.

FunArray 'listens' for named "spreadsheet cell" assignments to its namespace,
and it "listens" for a repr access to the "spreadsheet" as a whole, presenting
its status in terms of cell names and the formula value of the last cell 
entered.

Not conventional, but I wanted to stay as close to the OP's proposed
example interactive log (if that was what it was, which apparently it wasn't ;-)

This does also demonstrate that if you want to "listen" for apparent
assignments to bare names, AFAIK there is no way without byte code hackery
or using a trace hook, or just doing your own eval-print loop,
which is why I suggested the cmd module as a start.

of course, you could mess with displayhook to get what the OP originally
appeared to be asking for. E.g., this toy produces an interactive log
much like the OP specified:

 >>> class DH(object):
 ... def __init__(self):
 ... import math
 ... self.env = vars(math)
 ... self.env.update(vars(__builtins__))
 ... def evalstrex(self, s):
 ... for name in compile(s,'','eval').co_names:
 ... if type(self.env[name]) == str:
 ... self.env[name] = self.evalstrex(self.env[name])
 ... return eval(s, self.env)
 ... def __call__(self, o):
 ... if type(o)==str:
 ... self.env.update(globals())
 ... o = self.evalstrex(o)
 ... sys.__displayhook__(o)
 ...
 >>> import sys
 >>> sys.displayhook = DH()

Other than the quotes around the formula,

 >>> a = '[sin(x), cos(x)]'
 >>> x=0.0
 >>> a
 [0.0, 1.0]
 >>> x=1.0
 >>> a
 [0.8414709848078965, 0.54030230586813977]

looks a lot like

 """
 I'm looking for array of functions.
 Something like a=[ sin(x) , cos(x) ]

 >>> x=0.0
 >>> a
 [0, 1]
 >>> x=1.0
 >>> a
 ...

 of course it can be made by
 >>> def cratearray(x):
 ...   
 ...   return a
 a=createarray(1.0)

 but this isn't what i am asking for. something automized.
"""

Of course, this is not what the OP _really_ wanted ;-)

But it's kind of fun. Anything you type in quotes is evaluated
using available global bindings plus the ones in the math module
and __builtins__, and it's recursive, so if a name in the quoted
formula refers to another string (which must be a valid expression),
that is evaluated, and so on. This is "pull" based on interactive
display trigger ;-)

 >>> x='pi/6'
 >>> a
 [0.49994, 0.86602540378443871]

 >>> x='pi/6'
 >>> a
 [0.49994, 0.86602540378443871]
 >>> x = 'pi/y'
 >>> y=6
 >>> a
 [0.49994, 0.86602540378443871]
 >>> y=3
 >>> a
 [0.8660254037844386, 0.50011]

The display hook passes through non-strings, so you can box a string formula to 
see it:

 >>> [a]
 ['[sin(x), cos(x)]']
 >>> [x]
 ['pi/y']
 >>> [y]
 [3]


You could specify your spread sheet:

 >>> a1,a2,a3=100,200,'sum([a1,a2])'
 >>> a1,a2,a3
 (100, 200, 'sum([a1,a2])')
 >>> a1
 100
 >>> a2
 200
 >>> a3
 300

;-)

>
>(2) Pull model: lazy evaluation. Have some flag on whether an
>independent quantity has been changed. When evaluating a dependent
>quantity, survey its independent quantities recursively, and update the
>cached copies whereever necessary.
>
>Of course, combination of the two approaches is possible.
>
>For Python, metaclasses and/or decorators and/or properties may help.
>
>But functional languages are a more natural territory.
>

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


Re: Python licence again

2005-04-23 Thread Tim Tyler
fuzzylollipop <[EMAIL PROTECTED]> wrote or quoted:

> try spelling license correctly next time and heading the google
> suggestions that probably looked like "didn't you mean : Python License"

How do you spell license correctly?
-- 
__
 |im |yler  http://timtyler.org/  [EMAIL PROTECTED]  Remove lock to reply.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Tim Tyler
Mage <[EMAIL PROTECTED]> wrote or quoted:

> check this: http://wiki.w4py.org/pythonvsphp.html

Good - but it hardly mentions the issue of security - which seems
like a bit of a problem for PHP at the moment.
-- 
__
 |im |yler  http://timtyler.org/  [EMAIL PROTECTED]  Remove lock to reply.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble Installing TTX/FontTools (asks for .NET Framework Packages)

2005-04-23 Thread Jesper Olsen

weston wrote:
> This problem may be addressed here:
>
> http://sourceforge.net/mailarchive/message.php?msg_id=1702374
>
> Apparently setup.py tries to compile a c file, which of course
doesn't
> work if there's no compiler.

In fact it does not work even if there is a compiler - seems distutils
has been broken in python2.4 (it works in python2.3).

Jesper

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


Re: Python or PHP?

2005-04-23 Thread Diez B. Roggisch
> php doesn't have any smell

au contraire! I've seen many code smells in PHP.

http://c2.com/cgi/wiki?CodeSmell

--  
Regards,

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


Re: Python or PHP?

2005-04-23 Thread Ville Vainio
> "Leif" == Leif K-Brooks <[EMAIL PROTECTED]> writes:

Leif> Lad wrote:
>> Is anyone capable of providing Python advantages over PHP if there are
>> any?

Leif> Python is a programming language in more ways than simple Turing
Leif> completeness. PHP isn't.

+1 QOTW.

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


Re: Frog 1.4 (web log aka blogging server)

2005-04-23 Thread Irmen de Jong
limodou wrote:
great!
How about change the bbcode like editor to FCKeditor? I think
FCKeditor is much better, or make it as an optional editor which the
user could select it himself.
Isn't that pretty heavyweight for a blog?
I mean; Frog is not a CMS with which you write HTML pages...
Then again, it shouldn't be very hard to switch de default
formatting engine for another one, the code is already
somewhat prepared for this.
I'd say, give it a shot :)   Patches are gladly accepted.
(I'll put this as a nice-to-have on the list)
--Irmen

2005/4/23, Irmen de Jong <[EMAIL PROTECTED]>:
I've released a new version of Frog, a web log
aka blogging server written in 100% python.
[...]
--
http://mail.python.org/mailman/listinfo/python-list


Caching compiled regexps across sessions (was Re: Regular Expressions - Python vs Perl)

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

>> so you picked the wrong file format for the task, and the slowest

Ilpo> What would you recommend instead?

Ilpo> I have searched alternatives, but somehow I still find XML
Ilpo> the best there is. It is a standard format with standard
Ilpo> programming API.

Ilpo> I don't want to lose my calendar data. XML as a standard
Ilpo> format makes it easier to convert later to some other
Ilpo> format. As a textual format it is also readable as raw also
Ilpo> and this eases debugging.

Use pickle, perhaps, for optimal speed and code non-ugliness. You can
always use xml as import/export format, perhaps even dumping the db to
xml at the end of each day.

Ilpo> And my point is that the regular expression compilation can
Ilpo> be a problem in python. The current regular expression
Ilpo> engine is just unusable slow in short lived programs with a
Ilpo> bit bigger amount of regexps. And fixing it should not be
Ilpo> that hard: an easy improvement would be to add some kind of
Ilpo> storing mechanism for the compiled regexps. Are there any
Ilpo> reasons not to do this?

It should start life as a third-party module (perhaps written by you,
who knows :-). If it is deemed useful and clean enough, it could be
integrated w/ python proper. This is clearly something that should not
be in the python core, because the regexps themselves aren't there
either.

>> python has shipped with a fast XML parser since 2.1, or so.

Ilpo> With what features? validation? I really want a validating
Ilpo> parser with a DOM interface. (Or something better than DOM,
Ilpo> must be object oriented.)

Check out (coincidentally) Fredrik's elementtree:

http://effbot.org/zone/element-index.htm

Ilpo> I don't want to make my programs ugly (read: use some more
Ilpo> low level interface) and error prone (read: no validation)
Ilpo> to make them fast.

Why don't you use external validation on the created xml? Validating
it every time sounds like way too much like Javaic B&D to be fun
anymore. Pickle should serve you well, and would probably remove about
half of your code. "Do the simplest thing that could possibly work"
and all that.

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


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread Scott David Daniels
Mage wrote:
Scott David Daniels wrote:
See, the body of your anonymous function just looks for "the current
value of n" when it is _invoked_, not when it is _defined_.
The "lambda functions" was an unclear part of the tutorial I read.
Should I use them? Are they pythonic?
As far I see they are good only for type less a bit.
As for most python features which are not "dead obvious", you should
only use them where they they make the code clearer than it would be
without the use of that feature.  In this case, I was responding to
a particular use of lambda which, in fact, had a flaw that made the
code do something different from what it looked like it was doing.
I felt the distinction was clearer in the lambda form than it would
have been with "def-style" function definitions.  One of the reasons
the distinction came out was that there was no confusing naming of
"what this function means," only program structure.  In a real program
that is a hindrance.  In the case of pointing out a flaw, it makes
differences between two versions of some code more obvious.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread Harald Massa
Mage <[EMAIL PROTECTED]> wrote in news:mailman.2339.1114242211.1799.python-

> The "lambda functions" was an unclear part of the tutorial I read.
> Should I use them? Are they pythonic?
> As far I see they are good only for type less a bit.

And to obfusicate code. lambda is evil, do not play with it.

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


Re: PDF Printing support from Python

2005-04-23 Thread Grant Edwards
On 2005-04-23, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:

>> You're use of the word "driver" is one with which I'm not
>> familiar.  But I don't really "do windows" so it's probably a
>> Widnowism.
>
> It could be that he means that creating PDFs on windows is
> done using a fake printer that will produce the pdf when being
> printed to - and that fake printer is implemented as a driver.
>
> And traditionally in printing one often speaks of printer
> drivers - even if they are mere filters that can't be
> considered drivers in the kernel driver way.

I think it's the latter.  I believe he wants to know how to
print a PDF file without using any external programs (or
"drivers") like Acrobat Reader or ghostscript that understand
PDF.  AFAIK, the only way to do what he wants would be for him
to write a PDF engine in Python that renders PDF into whatever
raw format is understood by his printer.

-- 
Grant Edwards   grante Yow!  I'LL get it!! It's
  at   probably a FEW of my
   visi.comITALIAN GIRL-FRIENDS!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python callbacks & PyGILState_Release()

2005-04-23 Thread Randall Hopper
Thomas Heller:
 |>  Python -> C++ -> Python Callback
 |>
 |> (example attached) an exception raised in the callback doesn't make it back
 |> across C++ to Python.
...
 |> void callback_wrapper( void *user_data )
 |> {
 |>   // Acquire interpreter lock
 |>   PyGILState_STATE gstate = PyGILState_Ensure();
 |>   ...
 |>   // Call Python
 |>   pyresult = PyEval_CallObject( pyfunc, pyargs );
 |>   ...
 |
 |if (pyresult == NULL)
 |PyErr_Print();
 |
 |>   // Free interpreter lock
 |>   PyGILState_Release(gstate);
 |> }
 |
 |PyErr_Print() will do the 'right' thing?s.

Thanks for the reply.  However, this won't:

   a) Stop the main Python script, and
   b) Print the full stack trace (including Python and C++ SWIG wrapper)

Is there a clean way to save the full exception state in the callback
before the PyGILState_Release(), and restore it when we return across the
C++ wrapper?

If I knew what the proper "save" and "restore" exception state code bits
were, I could easily implement this with exception typemaps in SWIG.

Thanks,

Randall

P.S. Perhaps PyGILState_Release should take an argument instructing it to
exclude exception state when resetting the interpreter state back to its
original state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Mage
Lad wrote:

>Is anyone capable of providing Python advantages over PHP if there are
>any?
>  
>
I am also new to python but I use php for 4 years. I can tell:

- python is more *pythonic* than php
- python has its own perfume
http://www.1976.com.tw/image/trussardi_python_uomo.jpg  and it's nice.
php doesn't have any smell
- writing python programs you feel much better

check this: http://wiki.w4py.org/pythonvsphp.html

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


  1   2   >