Re: Two functionaly identical functions -> different results ??!

2008-11-19 Thread Chris Rebert
On Wed, Nov 19, 2008 at 11:24 PM, Barak, Ron <[EMAIL PROTECTED]> wrote:
> Hi Guys,
>
> I cannot see any difference between read1() and read2() below, and yet, one
> is okay, the other give an exception.
>
> In the first run, read2() is executed, and as expected, the text file is
> printed
>
> $ cat ./gzip_try.py
> import gzip
>
> FILE = "text_file.txt"
>
> def read2():
> try:
> fl = gzip.GzipFile(FILE, "r")
> print fl.read()
> except IOError:
> fl = open(FILE, "r")
> print fl.read()
>
> def read1():
> try:
> fl = gzip.GzipFile(FILE, "r")
> except IOError:
> fl = open(FILE, "r")
>
> print fl.read()
>
> read2()
> #read1()
>
> $ python ./gzip_try.py
> abc
> 123
>
> In the second run, read1() is executed, and an "IOError: Not a gzipped file"
> exception is thrown from the "print fl.read()" line of read1().
> This is baffling to me, as the try...except should have established that the
> file is a text and not gzip file !
>
> $ cat ./gzip_try.py
> import gzip
>
> FILE = "text_file.txt"
>
> def read2():
> try:
> fl = gzip.GzipFile(FILE, "r")
> print fl.read()
> except IOError:
> fl = open(FILE, "r")
> print fl.read()
>
> def read1():
> try:
> fl = gzip.GzipFile(FILE, "r")
> except IOError:
> fl = open(FILE, "r")
>
> print fl.read()
>
> #read2()
> read1()
>
> $ python ./gzip_try.py
> Traceback (most recent call last):
>   File "./gzip_try.py", line 22, in 
> read1()
>   File "./gzip_try.py", line 19, in read1
> print fl.read()
>   File "c:\Python25\lib\gzip.py", line 220, in read
> self._read(readsize)
>   File "c:\Python25\lib\gzip.py", line 263, in _read
> self._read_gzip_header()
>   File "c:\Python25\lib\gzip.py", line 164, in _read_gzip_header
> raise IOError, 'Not a gzipped file'
> IOError: Not a gzipped file
>
> $
>
> Can anyone explain why read1() throws an exception, while read2() behaves
> correctly ?

As I believe someone else pointed out recently in a extremely similar
thread, GzipFile apparently doesn't check that the underlying file is
actually in gzip format until the .read() call, hence why its
placement affects where the exception is thrown and thus how it's
handled. read2() has the .read() for the gzipped case within the
`try`, so the exception, if it's going to get thrown, is thrown there
and handled by the except. In contrast, read1() has the .read() call
outside the `try` and so the possible exception doesn't get caught.
IOW, putting the GzipFile() creation in a `try` is pointless in this
case as .read(), and not the initialization, throws the exception.

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com

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


RE: Why is try...except in my code not working (gzip/text files) ?

2008-11-19 Thread Barak, Ron
Thanks Gabriel,
Okay, I get it: I was under the impression that the format check would be done 
on the open.
Bye,
Ron.

-Original Message-
From: Gabriel Genellina [mailto:[EMAIL PROTECTED]
Sent: Thursday, November 20, 2008 02:06
To: python-list@python.org
Subject: Re: Why is try...except in my code not working (gzip/text files) ?

En Wed, 19 Nov 2008 13:25:03 -0200, Barak, Ron <[EMAIL PROTECTED]>
escribió:

> I need to read a file that is either a gzip or a text file (on both
> *nix and Windows).
> Since I didn't find a way to determine a file type, I thought of using
> the following:
>
> import gzip
>
> FILE = "../dpm/save_state-ssp8400-F0023209_080723-110131/top.1"
> #FILE =
> "../dpm/save_state-ssp8400-F0023209_080723-110131/var/log/sac.log.0.gz"
>
> try:
> file = gzip.GzipFile(FILE, "r") except IOError:
> file = open(FILE, "r")
>
> print file.read()
>
>
> Strangely, when FILE is a gzip file, all is fine.
> But, when FILE is a text file (as in the above code), I get the
> following:
>
> $ python ./gzip_try.py
> Traceback (most recent call last):
>   File "./gzip_try.py", line 11, in 
> print file.read()  <<<===
>   File "c:\Python25\lib\gzip.py", line 220, in read
> self._read(readsize)
>   File "c:\Python25\lib\gzip.py", line 263, in _read
> self._read_gzip_header()
>   File "c:\Python25\lib\gzip.py", line 164, in _read_gzip_header
> raise IOError, 'Not a gzipped file'
> IOError: Not a gzipped file
>
> Can you explain why the try...except in my code does not work ?
> Or, back to my original problem: how do I deal with a file whether
> it's a text file or a gzip file ?

Note *where* the exception is raised. Until something is actually read, no 
check is made for the file format.

--
Gabriel Genellina


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


DISNEY VISA CARD

2008-11-19 Thread MEGAL
DISNEY VISA CARD
http://www.disneyvisacards.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: sorting list of complex numbers

2008-11-19 Thread Terry Reedy

Paul Rubin wrote:

Terry Reedy <[EMAIL PROTECTED]> writes:

Do your tuple destructuring in the first statement in your body and
nothing will break.


Why get rid of a useful feature that unclutters code?


Because, as has been posted before, it is rarely used, it is 
replaceable, its presence interfered with adding a new signature option, 
and its removal uncluttered a bit the C code.




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


Two functionaly identical functions -> different results ??!

2008-11-19 Thread Barak, Ron
Hi Guys,

I cannot see any difference between read1() and read2() below, and yet, one is 
okay, the other give an exception.

In the first run, read2() is executed, and as expected, the text file is printed

$ cat ./gzip_try.py
import gzip

FILE = "text_file.txt"

def read2():
try:
fl = gzip.GzipFile(FILE, "r")
print fl.read()
except IOError:
fl = open(FILE, "r")
print fl.read()

def read1():
try:
fl = gzip.GzipFile(FILE, "r")
except IOError:
fl = open(FILE, "r")

print fl.read()

read2()
#read1()

$ python ./gzip_try.py
abc
123

In the second run, read1() is executed, and an "IOError: Not a gzipped file" 
exception is thrown from the "print fl.read()" line of read1().
This is baffling to me, as the try...except should have established that the 
file is a text and not gzip file !

$ cat ./gzip_try.py
import gzip

FILE = "text_file.txt"

def read2():
try:
fl = gzip.GzipFile(FILE, "r")
print fl.read()
except IOError:
fl = open(FILE, "r")
print fl.read()

def read1():
try:
fl = gzip.GzipFile(FILE, "r")
except IOError:
fl = open(FILE, "r")

print fl.read()

#read2()
read1()

$ python ./gzip_try.py
Traceback (most recent call last):
  File "./gzip_try.py", line 22, in 
read1()
  File "./gzip_try.py", line 19, in read1
print fl.read()
  File "c:\Python25\lib\gzip.py", line 220, in read
self._read(readsize)
  File "c:\Python25\lib\gzip.py", line 263, in _read
self._read_gzip_header()
  File "c:\Python25\lib\gzip.py", line 164, in _read_gzip_header
raise IOError, 'Not a gzipped file'
IOError: Not a gzipped file

$

Can anyone explain why read1() throws an exception, while read2() behaves 
correctly ?

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


Re: Module Structure/Import Design Problem

2008-11-19 Thread Arnaud Delobelle
Rafe <[EMAIL PROTECTED]> writes:

> Hi,
>
> I am in a situation where I feel I am being forced to abandon a clean
> module structure in favor of a large single module. If anyone can save
> my sanity here I would be forever grateful.
>
> My problem is that classes in several modules share a common base
> class which needs to implement a factory method to return instances of
> these same classes.
>
> An example to help illustrate what I mean:
> Lets say I have the following modules with the listed classes:
>  - baselib.py   with  BaseClass
>  - types.py   with  TypeA, ...
>  - special.py   with  SpecialTypeA, ...
>
> Which would be used a bit like this:
 type_a = any_type_instance.get_type("TypeA")
 special_type = type_a.get_type("SpecialTypeA")
>
>
> Again, I can get around this by dumping everything in to one module,
> but it muddies the organization of the package a bit. This seems like
> a problem that would come up a lot. Are there any design paradigms I
> can apply here?

It's not very clear what your problem is.  I guess your factory
functions are defined in baselib.py whereas types.py and special.py
import baselib, therefore you don't know how to make the factory
function aware of the types defined in special.py and types.py.

You can use cyclic import in many cases.

Or (better IMHO) you can make types register themselves with the factory
function (in which case it would have some state so it would make more
sense to make it a factory object).

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


[ANN] logilab-astng 0.17.4

2008-11-19 Thread Sylvain Thénault
Hi there!

Back from holidays, I finally took a few hours to fix a few bugs in
astng an publish a 0.17.4 release. It fixes some crashes, the "using
possibly undefined loop variable" false positive reported by Maarteen 
and Skip and add some support for python 2.5 relative imports. See
the ChangeLog or the version's page [1] for more details.

[1] http://www.logilab.org/project/logilab-astng/0.17.4

-- 
Sylvain Thénault   LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:   http://www.logilab.fr/services
Python et calcul scientifique:   http://www.logilab.fr/science

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


Re: Using eval, or something like it...

2008-11-19 Thread r0g
John Machin wrote:
> On Nov 20, 11:44 am, r0g <[EMAIL PROTECTED]> wrote:
>> Hi There,
>>
>> I know you can use eval to dynamically generate the name of a function
>> you may want to call. Can it (or some equivalent method) also be used to
>> do the same thing for the variables of a class e.g.
>>
>> class Foo():
>>   bar = 1
>>   gum = 2
>>
>> mylist = ['bar','gum']
>>
>> a = Foo()
>> for each in mylist:
>>   a.eval(each) = 999
>>
>> If so, what is the proper syntax/method for this.
> 
> You mention "variables of a class" but you then proceed to poke at an
> instance of the class. They are two different things. Which do you
> mean?
> 
> In any case, use the built-in function setattr to set attribute values
> for an object or for a class.
> 
> setattr(a, 'bar', 999) is equivalent to a.bar = 999
> setattr(Foo, 'bar', 456) is equivalent to Foo.bar = 456
> 
> Check out setattr (and getattr) in the docs.


The former i.e. the variables of an instance of a class. Thanks :-)

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


Re: Programming exercises/challenges

2008-11-19 Thread Arnaud Delobelle
Edwin <[EMAIL PROTECTED]> writes:

[...]
> a diary manager compatible with my Emacs diary file (sometimes I don't
> want to open Emacs for a quick note)

You mean that you sometimes don't have emacs open?

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


Re: help with comparison

2008-11-19 Thread Tim Roberts
tekion <[EMAIL PROTECTED]> wrote:
>
>Could some one take a look at the below code snipet which keep
>failing:
>
>import optparse
>p = optparse.OptionParser(description="script to do stuff",
>prog="myscript.py", )
>p.add_option("-c" "--compress", help="0 is noncompress")
>function1(options.compress)
>
>here's what the what function definition looks like:
>function1(zipfile) :
>if (zipfile == 1):
>   do stuff here with for compress file
>else
>   do stuff here
>
>when I call the script "myscript.py 1", the above test keeps falling
>to the else clause.  I am thinking the object zipfile is not the same
>as "1". Any thoughts as how I should test if the argument being pass
>in and parse by optparse is 1 or "0"?  Thanks.

There are many problems with this.  This is NOT your real code.  You're not
showing us the call to parse_args, so we can't see where the "options"
variable comes from, and the declaration of function1 is wrong.  When
asking a question like this, you should always include runnable code, to
make it easier for us to reproduce the problem.

However, I will assume that you have this:
options, args = p.parse_args()

Did you even TRY printing out "options" and "args" to make sure that they
contained what you expected?  If you had run even one or two experiments,
two things would become clear.

1. When you call "myscript.py 1", you are not providing a value for the
"-c" parameter.  The "1" goes into "args", and options.compress will ALWAYS
be None.  You would need to say "myscript.py -c 1"

2. Options are strings.  It's simple character manipulation.  So,
options.compress will NEVER be 1.  If you did "myscript.py -c 1", then
options.compress will be "1".  That's a string, not a number.

If what you really want is "present" vs "not present", then use this:

function1( options.compress )

def function1( zipfile=None ):
if zipfile:
# compress
else:
# do not compress

However, that will read "0" as true.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting fractional part from a float without using string operations

2008-11-19 Thread Chris Rebert
On Wed, Nov 19, 2008 at 10:01 PM, srinivasan srinivas
<[EMAIL PROTECTED]> wrote:
> Yes it works for most of the cases.  But it doesn't for the following case:
>
 str(abs(int(1234567.89)-1234567.89))
> '0.88999898'

Since you really care about significant figures here, have you
considered using decimal rather than float as, IIRC, it handles this
correctly?

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com

>
> Thanks,
> Srini
>
>
> - Original Message 
> From: Tino Wildenhain <[EMAIL PROTECTED]>
> To: srinivasan srinivas <[EMAIL PROTECTED]>
> Cc: Jeremiah Dodds <[EMAIL PROTECTED]>; python-list@python.org
> Sent: Wednesday, 19 November, 2008 7:33:46 PM
> Subject: Re: Getting fractional part from a float without using string 
> operations
>
> srinivasan srinivas wrote:
>> Yes. But it didn't give only the expected decimals.
>> For ex:
>>  >>> a = 1.23
>>  >>> abs(int(a) -a)
>> 0.22998
>>  I would like to get the result '0.23' only.
>
> well, thats what get stored internally - there
> is no way around it if you are using floating
> point numbers:
>
 0.23
> 0.23001
>
> but str() handles the rounding correctly:
>
 print 0.23
> 0.23
>
 print abs(int(a) -a)
> 0.23
>
> See also http://en.wikipedia.org/wiki/Floating_point
> for the problems with FP figures.
>
> Regards
> Tino
>
>
>
>  Get perfect Email ID for your Resume. Grab now 
> http://in.promos.yahoo.com/address
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple equates

2008-11-19 Thread Tim Roberts
jzakiya <[EMAIL PROTECTED]> wrote:
>
>I looked online and in books, but couldn't find a definitive answer to
>this.
>
>I have an array and set multiple elements to either True or False at
>one time.
>
>Question: Which way is faster (or does it matter)?

Answer: it does not matter.  This is premature optimization.  First, make
it work.  Then, figure out whether it is fast enough.  THEN, figure out
what's taking the most time.

I'd be very, very surprised if this was an important part of your run time.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Moving file on remote server: How?

2008-11-19 Thread MarkusJ_NZ
On Nov 20, 3:54 pm, alex23 <[EMAIL PROTECTED]> wrote:
> On Nov 20, 3:40 pm, MarkusJ_NZ <[EMAIL PROTECTED]> wrote:
>
> > Can someone please tell me if / how I can move a file between folders
> > on a remote server via FTP using Python.
>
> I'm assuming you're using ftplib?
>
> Try ftp.rename() (although I'm not in a position to test this...)

Hi Alex, thanks for your help
Markus
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting fractional part from a float without using string operations

2008-11-19 Thread srinivasan srinivas
Yes it works for most of the cases.  But it doesn't for the following case:

>>> str(abs(int(1234567.89)-1234567.89))
'0.88999898'

Thanks,
Srini


- Original Message 
From: Tino Wildenhain <[EMAIL PROTECTED]>
To: srinivasan srinivas <[EMAIL PROTECTED]>
Cc: Jeremiah Dodds <[EMAIL PROTECTED]>; python-list@python.org
Sent: Wednesday, 19 November, 2008 7:33:46 PM
Subject: Re: Getting fractional part from a float without using string 
operations

srinivasan srinivas wrote:
> Yes. But it didn't give only the expected decimals.
> For ex:
>  >>> a = 1.23
>  >>> abs(int(a) -a)
> 0.22998
>  I would like to get the result '0.23' only.

well, thats what get stored internally - there
is no way around it if you are using floating
point numbers:

>>> 0.23
0.23001

but str() handles the rounding correctly:

>>> print 0.23
0.23

>>> print abs(int(a) -a)
0.23

See also http://en.wikipedia.org/wiki/Floating_point
for the problems with FP figures.

Regards
Tino



  Get perfect Email ID for your Resume. Grab now 
http://in.promos.yahoo.com/address
--
http://mail.python.org/mailman/listinfo/python-list


Re: Moving file on remote server: How?

2008-11-19 Thread alex23
On Nov 20, 3:40 pm, MarkusJ_NZ <[EMAIL PROTECTED]> wrote:
> Can someone please tell me if / how I can move a file between folders
> on a remote server via FTP using Python.

I'm assuming you're using ftplib?

Try ftp.rename() (although I'm not in a position to test this...)
--
http://mail.python.org/mailman/listinfo/python-list


Moving file on remote server: How?

2008-11-19 Thread MarkusJ_NZ
Hi, I am using python to FTP into a remote server and copy a file to a
local machine.

After I have downloaded the file I would like to move the file on the
remote server to an archive directory.

Can someone please tell me if / how I can move a file between folders
on a remote server via FTP using Python.

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


Re: Finding the instance reference of an object

2008-11-19 Thread Douglas Alan
Joe Strout <[EMAIL PROTECTED]> writes:

>>   Q. What type of calling semantics do Python and Java use?
>>
>>   A. Call-by-sharing.
>
> Fair enough, but if the questioner then says "WTF is call-by-sharing,"
> we should answer "call-by-sharing is the term we prefer for call-by-
> value in the case where the value is an object reference (as is always
> the case in Python)."

Personally, I think that it is much preferable to leave
"call-by-value" completely out of any such discussion, as it provably
leads to a great deal of confusion and endless, pointless debate.
It's better to just start from a clean slate and explain how
call-by-sharing works, and to assert that it is quite different from
the calling semantics of languages such as C or Pascal or Fortran, so
the student must set aside any preconceptions about how argument
passing works.

Call-by-sharing is technically a type of call-by-value only for those
who are devotees of academic programming language zoology.  For
everyone else, call-by-sharing is its own beast.  One might point all
of this out in the discussion, however, if it will help the other
person understand.  You never know -- they might be a fan of academic
programming zoology.

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


Re: Exception difference 2.4 ==> 2.5

2008-11-19 Thread Ross Ridge
D'Arcy J.M. Cain <[EMAIL PROTECTED]> wrote:
>I managed to move everything into one test file and switched to the
>SimpleXMLRPCServer module but to no avail.  The new code is at
>ftp://ftp.druid.net/pub/distrib/test_2.5

It seems be this issue:

http://bugs.python.org/issue1739842

Your handler in the server thread correctly catches the RuntimeException
and converts into a Fault object which it returns.  Unfortunately,
xmlrpclib then throws an exception instead of marshalling the Fault
object.  Your server catches the exception and turns it into a 500
HTTP server error.  The client thread then throws a ProtocolError,
which is uncaught.

So exceptions are working fine in your test case, the problem is that
xmlrpclib.dumps() can't marshall xmlrpclib.Fault objects in 2.5.

Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  [EMAIL PROTECTED]
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
--
http://mail.python.org/mailman/listinfo/python-list


Re: help with comparison

2008-11-19 Thread George Sakkis
On Nov 19, 10:21 pm, tekion <[EMAIL PROTECTED]> wrote:
> Hi,
> Could some one take a look at the below code snipet which keep
> failing:
>
> import optparse
> p = optparse.OptionParser(description="script to do stuff",
> prog="myscript.py", )
> p.add_option("-c" "--compress", help="0 is noncompress")
> function1(options.compress)
>
> here's what the what function definition looks like:
> function1(zipfile) :
> if (zipfile == 1):
>    do stuff here with for compress file
> else
>    do stuff here
>
> when I call the script "myscript.py 1", the above test keeps falling
> to the else clause.  I am thinking the object zipfile is not the same
> as "1". Any thoughts as how I should test if the argument being pass
> in and parse by optparse is 1 or "0"?  Thanks.

1 (without quotes) is not the same as "1" (with quotes); the first is
an integer, the second a string. optparse returns strings by default,
so the easiest change would be to make the check 'if zipfile == "1"'.

Even better, since it's a boolean option, pass action="store_true" to
p.add_option(). The test then is reduced to "if zipfile" and the
program is to be called by "myscript.py -c". Read the docs [1] for
more details.

HTH,
George

[1] http://docs.python.org/library/optparse.html#standard-option-actions
--
http://mail.python.org/mailman/listinfo/python-list


Re: help with comparison

2008-11-19 Thread John Machin
On Nov 20, 2:21 pm, tekion <[EMAIL PROTECTED]> wrote:
> Hi,
> Could some one take a look at the below code snipet which keep
> failing:
>
> import optparse
> p = optparse.OptionParser(description="script to do stuff",
> prog="myscript.py", )
> p.add_option("-c" "--compress", help="0 is noncompress")
> function1(options.compress)
>
> here's what the what function definition looks like:
> function1(zipfile) :

Do some elementary debugging; insert here:
print type(zipfile), repr(zipfile)
print type(1), repr(1)
then work out for yourself what you should do next.

> if (zipfile == 1):
>    do stuff here with for compress file
> else
>    do stuff here
>
> when I call the script "myscript.py 1", the above test keeps falling
> to the else clause.  I am thinking the object zipfile is not the same
> as "1". Any thoughts as how I should test if the argument being pass
> in and parse by optparse is 1 or "0"?  Thanks.

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


Module Structure/Import Design Problem

2008-11-19 Thread Rafe
Hi,

I am in a situation where I feel I am being forced to abandon a clean
module structure in favor of a large single module. If anyone can save
my sanity here I would be forever grateful.

My problem is that classes in several modules share a common base
class which needs to implement a factory method to return instances of
these same classes.

An example to help illustrate what I mean:
Lets say I have the following modules with the listed classes:
 - baselib.py   with  BaseClass
 - types.py   with  TypeA, ...
 - special.py   with  SpecialTypeA, ...

Which would be used a bit like this:
>>> type_a = any_type_instance.get_type("TypeA")
>>> special_type = type_a.get_type("SpecialTypeA")


Again, I can get around this by dumping everything in to one module,
but it muddies the organization of the package a bit. This seems like
a problem that would come up a lot. Are there any design paradigms I
can apply here?

Cheers

- Rafe


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


[ANN]: circuits-1.0a2 released!

2008-11-19 Thread James Mills
Hi all,

I'm pleased to announce the release of circuits-1.0a2

Overview
==

circuits is an event-driven framework with a focus on Component
Software Architectures where System Functionality is defined in
Components. Components communicate with one another by propagating
events throughout the system. Each Component can react to events and
expose events to other parts of the system Components are able to
manage their own events and can also be linked to other Components.

circuits has a clean architecture and has no external dependencies on
any other library. It's simplistic design is unmatchable but yet
delivers a powerful framework for building large, scalable,
maintainable applications and systems. circuits was a core integral
part of the pymills library developed in 2006 and was partly inspired
by the Trac architecture.

Quick Examples


Hello World!


>>> from circuits.core import listener, Component, Event, Manager
>>>
>>> class Hello(Component):
...   @listener("hello")
...   def onHELLO(self):
...  print "Hello World!"
>>> manager = Manager()
>>> manager += Hello()
>>> manager.push(Event(), "hello")
>>> manager.flush()
Hello World!

Hello Web!
~~~

from circuits.lib.web import Server, Controller
class HelloWorld(Controller):
   def index(self):
  return "Hello World!"
server = Server(8000)
server += HelloWorld()
server.run()

Hello Web! (WSGI)


from circuits.lib.web import Application, Controller
class HelloWorld(Controller):
   def index(self):
  return "Hello World!"
application = Application()
application += HelloWorld()

Download circuits using easy_install or from here:
http://trac.softcircuit.com.au/circuits/downloads
or from the Python Package Index.

Please visit the circuits website for more information about circuits,
or to file bug reports or enhancements.

http://trac.softcircuit.com.au/circuits/

--JamesMills

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


help with comparison

2008-11-19 Thread tekion
Hi,
Could some one take a look at the below code snipet which keep
failing:

import optparse
p = optparse.OptionParser(description="script to do stuff",
prog="myscript.py", )
p.add_option("-c" "--compress", help="0 is noncompress")
function1(options.compress)

here's what the what function definition looks like:
function1(zipfile) :
if (zipfile == 1):
   do stuff here with for compress file
else
   do stuff here

when I call the script "myscript.py 1", the above test keeps falling
to the else clause.  I am thinking the object zipfile is not the same
as "1". Any thoughts as how I should test if the argument being pass
in and parse by optparse is 1 or "0"?  Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Quick nested loop syntax?

2008-11-19 Thread alex23
On Nov 20, 3:48 am, Johannes Bauer <[EMAIL PROTECTED]> wrote:
> a = { "a", "b", "c" }
> b = { 4, 9, 13}
> for (x, y) in someoperator(a, b):
>         print(x, y)
>
> which would print all tuples of
> "a", 4
> "a", 9
> "a", 13
> "b", 4
> "b", 9
> "b", 13
> "c", 4
> "c", 9
> "c", 13

If you're using a version of Python before 2.6, you could also use a
list comprehension:

>>> show = lambda *args: sys.stdout.write('%s\n' % args)
>>> [show((x,y)) for x in a for y in b]
('a', 4)
('a', 9)
('a', 13)
('b', 4)
('b', 9)
('b', 13)
('c', 4)
('c', 9)
('c', 13)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Exception difference 2.4 ==> 2.5

2008-11-19 Thread D'Arcy J.M. Cain
On Wed, 19 Nov 2008 17:08:13 -0500
Terry Reedy <[EMAIL PROTECTED]> wrote:
> > am running Python 2.5.2.  I was able to reduce the program to a
> > reasonably small version that exhibits the problem.  It is in two files
> > in ftp://ftp.druid.net/pub/distrib/Test_2.5.tgz including Fredrik
> > Lundh's simple XML-RPC server.  Just run the test program under 2.4,
> > 2.5 and 2.6 to see the difference.
> 
> Report it on the bugs.python.org and it might possibly get fixed.

OK but I still don't think that I have even zeroed in on the bug.  Even
the code I provided is pretty large and complex for a snippet meant to
identify the problem.

I managed to move everything into one test file and switched to the
SimpleXMLRPCServer module but to no avail.  The new code is at
ftp://ftp.druid.net/pub/distrib/test_2.5

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: sorting list of complex numbers

2008-11-19 Thread Paul Rubin
Terry Reedy <[EMAIL PROTECTED]> writes:
> >> Do your tuple destructuring in the first statement in your body and
> >> nothing will break.

Why get rid of a useful feature that unclutters code?

> > Unless you were using a lambda, which is quite useful as argument to
> > "sort".
> 
> So write a separate def statement.
> If you do not want to do that, don't run with 3.0.

You are advising avoiding downgrading from 2.5 to 3.0, which is maybe
the best plan for some users under the circumstances, but some of us
normally expect a new major release to be an upgrade rather than a
downgrade.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using eval, or something like it...

2008-11-19 Thread r0g
George Sakkis wrote:
> On Nov 19, 7:44 pm, r0g <[EMAIL PROTECTED]> wrote:
>> Hi There,
>>
>> I know you can use eval to dynamically generate the name of a function
>> you may want to call. Can it (or some equivalent method) also be used to
>> do the same thing for the variables of a class e.g.
>>
>> class Foo():
>>   bar = 1
>>   gum = 2
>>
>> mylist = ['bar','gum']
>>
>> a = Foo()
>> for each in mylist:
>>   a.eval(each) = 999
>>
>> If so, what is the proper syntax/method for this.
> 
> for each in mylist:
> setattr(a, each, 999)
> 
> 
> HTH,
> George

Thank you George!

Damn I love Python! :0D
--
http://mail.python.org/mailman/listinfo/python-list


Re: Optional parameter object re-used when instantiating multiple objects

2008-11-19 Thread Jeremiah Dodds
On Wed, Nov 19, 2008 at 8:58 PM, alex23 <[EMAIL PROTECTED]> wrote:

> On Nov 20, 10:14 am, Aaron Brady <[EMAIL PROTECTED]> wrote:
> > If you had a menu in a browser interface that had the items, say,
> > 'Stop' and 'Reload', what would you expect to happen if you clicked on
> > them?
>
> If you had a keyword called 'def', which defined functions, would you
> expect it to define said functions when it executed, or on each
> function call?
> --
> http://mail.python.org/mailman/listinfo/python-list
>


I think that most of the issue here stems from people not understanding the
"quirks" of "variable assignment" in python, not so much expecting the def
statement to get re-evaluated every time a function is called.

I'm willing to bet that people surprised by the behavior of def are also
surprised by:
a = [1,2,3]
b = a
b.append(4)
a
[1,2,3,4]

compared to:
a = 4
b = a
b = 5
a
4

This makes sense if you've read (and understood!) the docs, or if you're
familiar with other programming languages that have similar behavior, but a
lot of people learn python as a first language these days - and a lot of
those people learn it  largely by playing around, not by studying the
documentation. I can definitely see how the behavior could be confusing to a
newcomer.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Optional parameter object re-used when instantiating multiple objects

2008-11-19 Thread alex23
On Nov 20, 10:14 am, Aaron Brady <[EMAIL PROTECTED]> wrote:
> If you had a menu in a browser interface that had the items, say,
> 'Stop' and 'Reload', what would you expect to happen if you clicked on
> them?

If you had a keyword called 'def', which defined functions, would you
expect it to define said functions when it executed, or on each
function call?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Programming exercises/challenges

2008-11-19 Thread Edwin
On Nov 18, 6:39 pm, [EMAIL PROTECTED] wrote:
> Hi guys,
>
> I'm learning Python by teaching myself, and after going through several
> tutorials I feel like I've learned the basics. Since I'm not taking a
> class or anything, I've been doing challenges/programs to reinforce the
> material and improve my skills. I started out with stuff like "Guess my
> number" games, hangman, etc. and moved on to making poker and card
> games to work with classes. For GUIs I created games like minesweeper,
> and a GUI stock portfolio tracker. I am out of ideas and am looking 
> forprogrammingprojects, challenges, or programs that have helped you'll
> learn. I'm working on the project Euler problems, but I find that they
> don't really help myprogrammingskills; they are more math focused.
> Suggestions? What has been useful or interesting to you? I'd also
> welcome sources of textbook type problems, because the ones provided in
> tutorials tend to be repetitive.
>
> Thanks,
> Ben

I'm also learning Python by myself, downloading open ebooks, reading
tutorials, reading other people's code, etc. and in order to put my
knowledge into practice I've been writing small programs to solve my
everyday computer problems: a simple email client (because sometimes
it seems to me that email clients now have so many features and
preferences) that reads my fetchmailrc, a diary manager compatible
with my Emacs diary file (sometimes I don't want to open Emacs for a
quick note)... in general I try to solve problems related to my own
workflow.

I also try to play with some of my girlfriend's ideas on computer use:
she came up with an idea for a calculator with which she could easily
keep track of our bills (but found financial software a bit
complicated for simple tasks, once again, too many features and
preferences) so I started to code a small multi-touch app as
"intuitive" as possible (and still working on it).

What I'm saying is that I've found useful not to think about
programming itself but just think of it as a medium to solve my own
(common) problems.

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


Re: Using eval, or something like it...

2008-11-19 Thread John Machin
On Nov 20, 11:44 am, r0g <[EMAIL PROTECTED]> wrote:
> Hi There,
>
> I know you can use eval to dynamically generate the name of a function
> you may want to call. Can it (or some equivalent method) also be used to
> do the same thing for the variables of a class e.g.
>
> class Foo():
>   bar = 1
>   gum = 2
>
> mylist = ['bar','gum']
>
> a = Foo()
> for each in mylist:
>   a.eval(each) = 999
>
> If so, what is the proper syntax/method for this.

You mention "variables of a class" but you then proceed to poke at an
instance of the class. They are two different things. Which do you
mean?

In any case, use the built-in function setattr to set attribute values
for an object or for a class.

setattr(a, 'bar', 999) is equivalent to a.bar = 999
setattr(Foo, 'bar', 456) is equivalent to Foo.bar = 456

Check out setattr (and getattr) in the docs.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-19 Thread greg

Antoon Pardon wrote:


You are changing your argument. In a follow up you
made the point that call by value should be as it
was intended by the writers of the algol 60 report.


No, I was countering the argument that "call by value"
is short for "call by copying the value". I was pointing
out that the inventors of the term didn't use any such
words.

Arguing that their words were intended to imply copying,
as part of the essence of the idea, is making an even
bigger assumption about their intentions, IMO.

Rather it seems to me that the essence of the idea they
had in mind is that call-by-value is equivalent to
assignment.

Furthermore, I don't seem to be alone in coming to that
conclusion -- the designers of other dynamic languages
appear to be using the same logic when they describe
their parameter passing as call-by-value.

Here's an example from "The SNOBOL Programming Language",
2nd Edition, by R. E. Griswold, J. F. Poage and I. P.
Polonsky. On p. 15:

  Arguments are passed by value and may be arbitrarily
  complex expressions.

and later on p. 95:

  When a call to a programmer-defined function is made, the
  arguments to the call are evaluated first. Before execution
  of the procedure begins ... new values are assigned to these
  variables as follows: ... (2) the formal arguments are
  assigned their values.

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


Re: Using eval, or something like it...

2008-11-19 Thread George Sakkis
On Nov 19, 7:44 pm, r0g <[EMAIL PROTECTED]> wrote:
> Hi There,
>
> I know you can use eval to dynamically generate the name of a function
> you may want to call. Can it (or some equivalent method) also be used to
> do the same thing for the variables of a class e.g.
>
> class Foo():
>   bar = 1
>   gum = 2
>
> mylist = ['bar','gum']
>
> a = Foo()
> for each in mylist:
>   a.eval(each) = 999
>
> If so, what is the proper syntax/method for this.

for each in mylist:
setattr(a, each, 999)


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


Python / Debian package dependencies

2008-11-19 Thread Steven Samuel Cole
Hi all,

I am trying to build a debian package for my python modules using
stdeb and dpkg-buildpackage. The package building itself works, I also
managed to have an entry point created and I can use my python modules
on the Ubuntu virtual machine I use to test the package.

The problem is that my modules require the psycopg2 python package and
the entry point seems to require setuptools.
I can't figure out how to declare a dependency that actually results
in the dependency Debian packages being installed.
I tried adding these lines to setup.py:

requires = ['psycopg2', 'setuptools'],
requires = ['psycopg2 (>=0.1)', 'setuptools (>=0.1)'],
install_requires = ['psycopg2', 'setuptools'],
install_requires = ['psycopg2>=0.1', 'setuptools>=0.1'],

and then run stdeb_run_setup and dpkg-buildpackage -rfakeroot -uc -us
in the deb_dist/ folder created, but when I copy the
.deb file over to the virtual machine and do dpkg -i <.deb file>, none
of them would actually install psycopg2 and setuptools.

What am I doing wrong ? Am I actually somewhat on the right track or
am I doing complete nonsense ?

Thanks for your help!

Cheers,

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


Re: Using eval, or something like it...

2008-11-19 Thread James Mills
DON'T USE eval!

On Thu, Nov 20, 2008 at 10:44 AM, r0g <[EMAIL PROTECTED]> wrote:
> Hi There,
>
> I know you can use eval to dynamically generate the name of a function
> you may want to call. Can it (or some equivalent method) also be used to
> do the same thing for the variables of a class e.g.
>
> class Foo():
>  bar = 1
>  gum = 2
>
> mylist = ['bar','gum']
>
> a = Foo()
> for each in mylist:
>  a.eval(each) = 999
>
>
> If so, what is the proper syntax/method for this.
>
> Regards,
>
> Roger.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Using eval, or something like it...

2008-11-19 Thread r0g
Hi There,

I know you can use eval to dynamically generate the name of a function
you may want to call. Can it (or some equivalent method) also be used to
do the same thing for the variables of a class e.g.

class Foo():
  bar = 1
  gum = 2

mylist = ['bar','gum']

a = Foo()
for each in mylist:
  a.eval(each) = 999


If so, what is the proper syntax/method for this.

Regards,

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


Re: Finding the instance reference of an object

2008-11-19 Thread Aaron Brady
On Nov 19, 12:28 pm, Joe Strout <[EMAIL PROTECTED]> wrote:
> On Nov 19, 2008, at 11:05 AM, Douglas Alan wrote:
> > (2) It is also unarguably true that saying that Python or Java use
> >    "call-by-value", and saying nothing more is going to be profoundly
> >    confusing to anyone who is learning these languages.
>
> Perhaps (unless they've already learned this from one of the other  
> languages).

If they learn the bad definition first, we can't go back and change
it.  We can correct it for them for the future.  Don't appeal to hot-
shot authorities, like the ones that don't acknowledge that there were
already people using terms they hijacked for their own cult following.

> >   Q. What type of calling semantics do Python and Java use?
>
> >   A. Call-by-sharing.
>
> Fair enough, but if the questioner then says "WTF is call-by-sharing,"  
> we should answer "call-by-sharing is the term we prefer for call-by-
> value in the case where the value is an object reference (as is always  
> the case in Python)."

But if someone says, 'What is call-by-reference?', do you answer, 'C-b-
r is the term we prefer for call-by-value in the case where the value
is a variable reference'?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Optional parameter object re-used when instantiating multiple objects

2008-11-19 Thread Aaron Brady
On Nov 19, 12:05 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
>
>         I wouldn't expect a language like Ada to somehow re-evaluate a
> default argument on each call; why would I expect Python to do such?

Lots of people do.

If you had a menu in a browser interface that had the items, say,
'Stop' and 'Reload', what would you expect to happen if you clicked on
them?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is try...except in my code not working (gzip/text files) ?

2008-11-19 Thread Gabriel Genellina
En Wed, 19 Nov 2008 13:25:03 -0200, Barak, Ron <[EMAIL PROTECTED]>  
escribió:


I need to read a file that is either a gzip or a text file (on both *nix  
and Windows).
Since I didn't find a way to determine a file type, I thought of using  
the following:


import gzip

FILE = "../dpm/save_state-ssp8400-F0023209_080723-110131/top.1"
#FILE =  
"../dpm/save_state-ssp8400-F0023209_080723-110131/var/log/sac.log.0.gz"


try:
file = gzip.GzipFile(FILE, "r")
except IOError:
file = open(FILE, "r")

print file.read()


Strangely, when FILE is a gzip file, all is fine.
But, when FILE is a text file (as in the above code), I get the  
following:


$ python ./gzip_try.py
Traceback (most recent call last):
  File "./gzip_try.py", line 11, in 
print file.read()  <<<===
  File "c:\Python25\lib\gzip.py", line 220, in read
self._read(readsize)
  File "c:\Python25\lib\gzip.py", line 263, in _read
self._read_gzip_header()
  File "c:\Python25\lib\gzip.py", line 164, in _read_gzip_header
raise IOError, 'Not a gzipped file'
IOError: Not a gzipped file

Can you explain why the try...except in my code does not work ?
Or, back to my original problem: how do I deal with a file whether it's  
a text file or a gzip file ?


Note *where* the exception is raised. Until something is actually read, no  
check is made for the file format.


--
Gabriel Genellina

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


Re: how to acces the block inside of a context manager as sourcecode

2008-11-19 Thread Aaron Brady
See below.

On Nov 19, 8:02 am, Daniel <[EMAIL PROTECTED]> wrote:
> Hi Aaron,
>
> let me give you the reason for the context manager:
> I am driving handware with a python script, basically a data acquisition
> program which looks like this:
>
> with dataStore('measurement1.dat') as d:
>         magnet.setField(0)
>         r1=doExperiment(voltage=0.345, current=0.346, temperature=33)
>         magnet.setField(1)
>         r2=doExperiment(voltage=0.32423, current=0.3654, temperature=45)
>         d.append(r2-r1)
>
> the script does the measuring and the context manager stores the result
> (r1 and r2), at the end the result is printed.
>
> The source code serves as the documentation (it contains many parameters
> that need to be well documented), so I print the source code, cut it out
> and glue it into my lab notebook.
> Now I want to automate this process, i.e. the dataStore should print the
> sourcecode.
>
> Daniel
>
> > There isn't a solution in the general case, because strings can be
> > executed.  However, 'inspect.currentframe()' and
> > 'inspect.getsourcelines(object)' can handle some cases, and your idea
> > is (I believe) how getsourcelines works itself.  You can probably do
> > it without a context manager, e.g. 'print_next_lines( 5 )' or
> > 'print_prior_lines( 2 )', dedenting as needed.
>
>

Hi.  It is not the role of a 'dataStore' object in your object model,
which is why, ideally, you would separate those two functions.
However, if 'dataStore' always needs the printing functionality, you
could built it in for practical reasons.  That has the benefit that
you don't need to specify, such as 'print_next_lines( 5 )', how many
lines to print, since the context manager can count for you, and if
you add a line, you won't need to change to 'print_next_lines( 6 )'.
Lastly, you could use two con. managers, such as:

with printing:
  with dataStore('measurement1.dat') as d:
magnet.setField(0)

You may or may not find that relevant.

Here is some code and output:

import inspect
class CM( object ):
def __enter__(self):
self.startline= inspect.stack( )[ 1 ][ 0 ].f_lineno
def __exit__(self, exc_type, exc_value, traceback):
endline= inspect.stack( )[ 1 ][ 0 ].f_lineno
print self.startline, endline

with CM(): #line 9
a= 0
b= 1
c= 2

with CM(): #line 14
d= 3
e= 4

/Output:

9 12
14 16
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with writing a long line in a text file

2008-11-19 Thread John Machin
On Nov 20, 9:31 am, Joe Strout <[EMAIL PROTECTED]> wrote:
> On Nov 19, 2008, at 3:27 PM, Mohsen Akbari wrote:
>
> > I'm a newbie in python and I have this problem with the code that  
> > I'm writing. There is a very long line which I wish to output it to  
> > a text file.But when I do this, in the output file, the result  
> > appears in two lines.
>
> Appears that way where?  Using what tool to view it?
>
> My guess is that there is nothing wrong with the file, but that  
> whatever you're using to view it is simply displaying it as two lines  
> even though it is actually one.

Or the "line" contains an embedded newline.

The OP may like to insert some debug code just before he writes the
line:
   print line.find('\n'), len(line), repr(line)

and tell us how long is "very long".
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python image library issue: domain users cannot save files?

2008-11-19 Thread Gabriel Genellina
En Wed, 19 Nov 2008 13:43:07 -0200, [EMAIL PROTECTED]  
<[EMAIL PROTECTED]> escribió:



Has anyone try to use PIL in a windows domain environment? I am having
a permission issue. If I am a domain user, even I have the permission
to write a folder, when I tried to do simple things like Image.open
("foo.tif").save("bar.tif"), i am getting exception IOError ("0",
"Error"). I tried to set os.umask(0) before I saved the file but the
same exception threw. But If I am the same domain user with local
admin permission on a windows box, I have no problem with the same
script. Does anyone ever have the same situation and know a work
around for this? Thanks.


Try using the builtin open() function to create/read/write files. If you  
have the same issues then you can take away PIL from the question and  
concentrate on setting the proper permissions for the user running the  
script.


--
Gabriel Genellina

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


Re: Building musical chords starting from (a lot of) rules

2008-11-19 Thread Mr . SpOOn
I think I've found a nice way to represent and build chords. At least,
at the moment it satisfy me, maybe later I'll understand how it sucks.

I'm using two separate classes: one represent a chord and is
implemented as a set of Notes; the other represents the structure
(type) of the chord and is a set of Intervals.

I can build a chord in different ways, but the general idea is that I
need a root note and a structure.

The structure isn't bound to any particular chord, because it doesn't
contain notes, but just intervals. So I can have the structure of
minor chord, of a major chord and apply them to two different notes
and build my chords.

So what is important is just the parsing of the structure. The
structure will be a string: at the moment I'm considering it space
separated, so kind of: 'min 9 no5'

I split it in a list and start from the third. I check if there's a
no3, then if there's 'min' and I put a minor third. I do the same for
the fifth. Then the first element will be the main chord structure,
because it could be a 7, a 9, a 11, a 13 and so on. I have a
dictionary with this structures, in this way:

chord_structs = {'9': ['b7', '9'], '11': ., '13': .}

So if the element is in the dictionary, I add the intervals listed,
else I just add the element. That's the case of the 7, or 6 etc. Then
I'll add the rest of the structure.

This is not complete or perfect, neither explained so well, but that's
the main idea.

Thanks for the help :D
bye
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with writing a long line in a text file

2008-11-19 Thread Joe Strout

On Nov 19, 2008, at 3:27 PM, Mohsen Akbari wrote:

I'm a newbie in python and I have this problem with the code that  
I'm writing. There is a very long line which I wish to output it to  
a text file.But when I do this, in the output file, the result  
appears in two lines.


Appears that way where?  Using what tool to view it?

My guess is that there is nothing wrong with the file, but that  
whatever you're using to view it is simply displaying it as two lines  
even though it is actually one.


HTH,
- Joe



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


Problem with writing a long line in a text file

2008-11-19 Thread Mohsen Akbari
Dear guys,

I'm a newbie in python and I have this problem with the code that I'm
writing. There is a very long line which I wish to output it to a text
file.But when I do this, in the output file, the result appears in two
lines. I thought maybe that's because the maximum possible length of the
text file has been reached so I opened the file and I tried to put some
space at the end of the first line. It wasn't possible to do that for the
first line and the space was placed before the first character of the second
line. I kept pressing space bar to add more spaces and so the whole second
line was moved to the write till it exceeded the first line. I mean the
length of the second line became longer than the first line which means the
text file can accept longer lines.
As a second guess, I thought maybe I had '\n' somewhere in my input string
so I tried to check that by doing:
temp_ =  out_string.find('\n')
print temp_

The result was  -1 which I think means there is not '\n' in my output
string. Now I'm really confused and I don't know what to do. I really
appreciate it if somebody can help me out.

BTW, I'm using windows.

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


Re: 404 not found on for Python 2.6 Itanium

2008-11-19 Thread Terry Reedy

Jerry Hill wrote:

On Wed, Nov 19, 2008 at 4:12 PM, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:

Then why is there a link on the download site?

Where specifically did you spot that link? I can't see any.


I believe the link in question is on the page
http://www.python.org/download/ titled "Python 2.6 Windows Itanium
installer" with a link to
http://www.python.org/ftp/python/2.6/python-2.6.ia64.msi .  Clicking
on that link brings you to a 404 error page. 


That appears to have been fixed, by removing the erroneous link.


 There is no Itanium

install linked from the 2.6 release page
(http://www.python.org/download/releases/2.6/)



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


Re: Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-19 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> On Nov 18, 10:22 am, Steve Holden <[EMAIL PROTECTED]> wrote
> in thread "Python-URL! weekly Python news and links (Nov 17)":
>> [EMAIL PROTECTED] wrote:
>> [...]
>>> One of the reasons I would like to formulate a good
>>> model of an object's value and type is so that I could
>>> try to offer something better.  Responses like yours
>>> are significantly demotivating.
>> And yet you argue when people try to explain to you that objects don't
>> *have* values, objects *are* values. Objects have attributes, which are
>> references to other values. One of an object's attributes is its type.
> 
> I am sorry for arguing with you.  I hear you
> and others saying that the value (in the english
> language sense of value) of an object *is* the
> object.
> 
That's OK. I don't assume you are arguing to be difficult, but to cast
light on a dark area.

> But before I address that, I am a little confused
> by what you wrote above.  Quoting the PLR again,
> "Every object has an identity, a type and a value."
> I presumed "value" to include attributes.  Are you
> saying the correct statement in the PLR should have
> been, "Every object has an identity, attributes, and
> a value"?
> 
> The text below refers to identity, type and value
> per the PLR, but you can substitute "attributes"
> for type without affecting the logic.
> 
> Here is why I am having trouble accepting the
> explanations you and others have kindly offered
> me.  If values are objects then the words "object"
> and "value" are synonymous, yes?  Fine, I can see
> that could be a desirable thing.  Value is more
> natural than object for people coming to Python,
> for example.
> 
> But if you use the word value synonymously with
> object, then the PLR statement that "an object
> has identity, type, and value" is the same as "an
> object has identity, type, and itself".  We know
> the object is itself! That's tautological.  So
> what is the point of using the term value in the
> definition of "object"?  You can just say "an object
> has identity and type, and we will also use the word
> value as a synonmym for object."
> 
> Other than cosmetics, the word "value" serves no
> purpose and we can replace it with "object" wherever
> we use it.  E.g. "the result of evaluating an
> expression is a value.", "the result of evaluating
> an expression is an object".  If value is the same
> as object, then Python objects have only identity
> and type.
> 
> But you know that's not true.  The types of int(2)
> and int(3) are the same.  Is the difference in
> behavior of the two objects due to their different
> identities?!  Python knows the object at 0x260FF44
> is a "2" object, and the object at 0x260FD60 is a
> "3" solely by virtue of their addresses?
> 
> Of course not.
> I hope you see why I find the "value is object"
> to be an unacceptable explanation of Python
> objects.
> 
I now understand where your confusion arises, and I also have to accept
that integer types have a value that isn't formally available as an
attribute.

However, I don't personally see the need to go beyond the Python object
"2", since operations involving that value are not programmed in Python
but in the underlying implementation language.

>> You seem to be hunting for the ineffable
>> "primitive value" that has no other attributes.
>> Such a thing doesn't exist.
> 
> Sorry to argue again, but I explained (in a
> previous post) why I believe such a thing does
> exist.  Specifically, it is necessary to explain
> the difference between the objects int(2) and
> int(3).  Perhaps if you tell me exactly what
> fault you find with that previous explanation
> (in light of my problem with "values are objects"
> above), I could reevaluate my understanding.

I suppose I was thinking more of the compound values than the primitive
immutable type instances. I take your point that int(3) and int(2) do
indeed differ by virtue of having different values for some "hidden
attribute" that isn't available to the Python programmer.

Since the differences aren't directly addressable in Python, however, I
prefer to ignore them :)

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Designing superclasses so inherited methods return objects with same type as the instance.

2008-11-19 Thread Arnaud Delobelle
"Felix T." <[EMAIL PROTECTED]> writes:

> I have a class called Interval(type.ObjectType) that is supposed to
> mimic closed mathematical intervals. Right now, it has a lot of
> methods like this:
>
> def __add__(self,other):
> if type(other) in Numerical:
> return Interval(self.lower_bound+other, self.upper_bound
> +other)
> else:
> return Interval(self.lower_bound+other.lower_bound,
> self.upper_bound+other.upper_bound)
>
> that return new objects of the same type.
>
> The problem is that if this method is called by a subclass like
>
> class HalfOpen(Interval):
>   #new comparison methods
>   ...
> it returns an object with Interval (not HalfOpen) type.
>
>
> I either have to redefine methods like __add__ so that they return
> objects of the right type (even though the logic is the same) or find
> some way to redefine Interval's methods so they are more flexible.
> Right now, I am looking at:
>
> def __add__(self,other):
> if type(other) in Numerical:
> return self.__class__(self.lower_bound+other,
> self.upper_bound+other)
> else:
> return self.__class__(self.lower_bound+other.lower_bound,
> self.upper_bound+other.upper_bound)
>
> Is there a standard way to do this, or a better one?

You can use type(self) rather than self.__class__

But I wouldn't make HalfOpen descend from Interval as a half-open
interval is not a kind of closed interval.  Moreover you should have

 Interval(2, 3) + HalfOpen(5, 7) == HalfOpen(7, 10)

Your implementation will yield Interval(7, 10) if I understand
correctly.

I think if I implemented an Interval class I would have it something
like this:

class Interval:
def __init__(self, left, right, closed_left=True, closed_right=True):
...

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


Re: Exception difference 2.4 ==> 2.5

2008-11-19 Thread Terry Reedy

D'Arcy J.M. Cain wrote:


If true I hope that a new version is forthcoming on the 2.5 branch.

Yes, couple of weeks.
  I

am running Python 2.5.2.  I was able to reduce the program to a
reasonably small version that exhibits the problem.  It is in two files
in ftp://ftp.druid.net/pub/distrib/Test_2.5.tgz including Fredrik
Lundh's simple XML-RPC server.  Just run the test program under 2.4,
2.5 and 2.6 to see the difference.


Report it on the bugs.python.org and it might possibly get fixed.




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


F2PY: Access Fortran module data from multiple python module

2008-11-19 Thread Yann Vonder
Hi all,
Here is a description of what I am trying to implement using F2PY:
I have created two python extension modules using F2PY. The first extension
module (say fsubr1.so) contains a Fortran module (say "tmod") and a
subroutine (say "subr1") that modifies the data contained in "tmod". The
second extension module (fsubr2.so) contains the same Fortran module as
fsubr1.so (tmod), and a different subroutine ("subr2") that also modifies
the data contained in "tmod". I am hoping to be able to have fsubr1.so and
fsubr2.so share the content of "tmod," in a way that if a call is made, from
python, to "subr1", followed by a call to "subr2", both subroutine access
the same data contained in "tmod". Unfortunately, if I run the Python
script:

from fsubr1 import *
from fsubr2 import *

subr1()
print tmod.data
subr2()
print tmod.data

the data in "tmod" will be modified only by the subroutine contained in the
python module imported last, i.e. subr2 in this case.

Does anyone know how to go about this problem?
Any help/insight will be greatly appreciated.

Thanks,

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


Re: calling python scripts as a sub-process

2008-11-19 Thread Catherine Moroney

Dan Upton wrote:

On Wed, Nov 19, 2008 at 2:38 PM, Catherine Moroney
<[EMAIL PROTECTED]> wrote:

Dan Upton wrote:

On Wed, Nov 19, 2008 at 2:13 PM, Philip Semanchuk <[EMAIL PROTECTED]>
wrote:

On Nov 19, 2008, at 2:03 PM, Catherine Moroney wrote:


The command (stored as an array of strings) that I'm executing is:

['python ../src_python/Match1.py ',
'--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
'--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
'--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2'
",
"--use_textid='true '"]


[snip]


I get the error below.  Does anybody know what this error refers
to and what I'm doing wrong?  Is it even allowable to call another
script as a sub-process rather than calling it directly?

File "../src_python/Match4.py", line 24, in RunMatch4
 sub1 = subprocess.Popen(command1)
 File "/usr/lib64/python2.5/subprocess.py", line 593, in __init__
 errread, errwrite)
 File "/usr/lib64/python2.5/subprocess.py", line 1051, in _execute_child
 raise child_exception
OSError: [Errno 2] No such file or directory

Try supplying a fully-qualified path to your script, e.g.:
['python /home/catherine/src_python/Match1.py ',
'--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
'--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
'--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2'
",
"--use_textid='true '"]

I think when I came across this error, I added shell=True, e.g.

sub1 = subprocess.Popen(command, shell=True)

I added the shell=True and this time it got into Match1 (hurrah!),
but it then opened up an interactive python session, and didn't
complete until I manually typed 'exit' in the interactive session.

Match1 looks like:

if __name__ == "__main__":
<<< parse arguments >>>

   RunMatch1(file_ref, file_cmp, iblock_start, iblock_end, \
 nlinep, nsmpp, mindispx, maxdispx, mindispl,  \
 maxdispl, istep, chmetric, use_textid)

   exit()

where the routine RunMatch1 does all the actual processing.

How do I get Match1 to run and exit normally without opening up an
interactive session, when called as a subprocess from Match4?



Alternately, rather than using a list of arguments, have you tried
just using a string?  (Again, that's the way I do it and I haven't
been having any problems recently, although I'm running shell scripts
or binaries with arguments rather than trying to invoke python on a
script.)

command = "python ../src_python/Match1.py
--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf
--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf
--block_start=62 --block_end=62 --istep=16 --chmetric='M2'
--use_textid=true"

proc = subprocess.Popen(command, shell=True)


Thanks - that did the trick.  I just passed in one long string
and everything actually works.  Wow!  I had no idea if this was
even do-able.

This is so cool, and saves me a lot of code duplication.  I can
spawn off half a dozen jobs at once and then just wait for them
to finish.  It's great that python can function both as a
scripting language and also a full-blown programming language
at the same time.

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


Designing superclasses so inherited methods return objects with same type as the instance.

2008-11-19 Thread Felix T.
I have a class called Interval(type.ObjectType) that is supposed to
mimic closed mathematical intervals. Right now, it has a lot of
methods like this:

def __add__(self,other):
if type(other) in Numerical:
return Interval(self.lower_bound+other, self.upper_bound
+other)
else:
return Interval(self.lower_bound+other.lower_bound,
self.upper_bound+other.upper_bound)

that return new objects of the same type.

The problem is that if this method is called by a subclass like

class HalfOpen(Interval):
  #new comparison methods
  ...
it returns an object with Interval (not HalfOpen) type.


I either have to redefine methods like __add__ so that they return
objects of the right type (even though the logic is the same) or find
some way to redefine Interval's methods so they are more flexible.
Right now, I am looking at:

def __add__(self,other):
if type(other) in Numerical:
return self.__class__(self.lower_bound+other,
self.upper_bound+other)
else:
return self.__class__(self.lower_bound+other.lower_bound,
self.upper_bound+other.upper_bound)

Is there a standard way to do this, or a better one?

Thanks in advance,
Felix
--
http://mail.python.org/mailman/listinfo/python-list


Re: calling python scripts as a sub-process

2008-11-19 Thread Jeremy Sanders
Dan Upton wrote:

> I think when I came across this error, I added shell=True, e.g.
> 
> sub1 = subprocess.Popen(command, shell=True)

That's really papering over the bug. You need to have the parameters
separately, including the name of the program, separately in the list. You
need to remove any shell quoting you may use on the unix/dos command line.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
--
http://mail.python.org/mailman/listinfo/python-list


Re: calling python scripts as a sub-process

2008-11-19 Thread Jeremy Sanders
Catherine Moroney wrote:

> I have one script (Match1) that calls a Fortran executable as a
> sub-process, and I want to write another script (Match4) that
> spawns off several instances of Match1 in parallel and then waits
> until they all finish running.  The only way I can think of doing this
> is to call it as a sub-process, rather than directly.
> 
> I'm able to get Match1 working correctly in isolation, using the
> subprocess.Popen command, but calling an instance of Match1 as a
> subprocess spawned from Match4 isn't working.
> 
> The command (stored as an array of strings) that I'm executing is:
> 
> ['python ../src_python/Match1.py ',
> '--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
> '--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
> '--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2'
> ", "--use_textid='true '"]
> 

If you want to avoid going by the shell, and you *should* for security
reasons, you need to have each of your arguments separately in the list
without the shell quoting and extra spaces, i.e.

['python', '../src_python/Match1.py',
 '--file_ref=.hdf', '--file_cmp=.hdf',
 '--block_start=xx', '--block_end=62', '--istep=16', '--chmetric=M2',
 '--use_texid=true']

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting fractional part from a float without using string operations

2008-11-19 Thread John Machin
On Nov 20, 3:38 am, "Blind Anagram" <[EMAIL PROTECTED]> wrote:
> "MRAB" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
> On Nov 19, 1:44 pm, John Machin <[EMAIL PROTECTED]> wrote:
>
> > On Nov 20, 12:35 am, srinivasan srinivas <[EMAIL PROTECTED]>
> > wrote:
> > 
>
> > | >>> import math
> > | >>> num = 123.4567
> > | >>> math.modf(num)
> > | (0.456699789, 123.0)
>
> def frac(n):
>     return n - int(n)
>
> n % 1.0

| >>> n= -123.4567
| >>> n % 1.0
| 0.543300211
--
http://mail.python.org/mailman/listinfo/python-list


Re: 404 not found on for Python 2.6 Itanium

2008-11-19 Thread Martin v. Löwis

> Copied from the download page:

It would have helped if you had provided the URL instead. I didn't
recognize that you were talking about

http://www.python.org/download/

as I rarely ever view this page. On

http://www.python.org/download/releases/2.6/

no such link is included.

I have now deleted the link; thanks for pointing this problem out.

In any case, if you want Itanium binaries of Python, I recommend to
use 2.5.2, from

http://www.python.org/download/releases/2.5.2/

Regards,
Martin

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


Re: 404 not found on for Python 2.6 Itanium

2008-11-19 Thread Jerry Hill
On Wed, Nov 19, 2008 at 4:12 PM, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
>> Then why is there a link on the download site?
>
> Where specifically did you spot that link? I can't see any.

I believe the link in question is on the page
http://www.python.org/download/ titled "Python 2.6 Windows Itanium
installer" with a link to
http://www.python.org/ftp/python/2.6/python-2.6.ia64.msi .  Clicking
on that link brings you to a 404 error page.  There is no Itanium
install linked from the 2.6 release page
(http://www.python.org/download/releases/2.6/)

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


Re: 404 not found on for Python 2.6 Itanium

2008-11-19 Thread Benjamin Kaplan
On Wed, Nov 19, 2008 at 4:12 PM, "Martin v. Löwis" <[EMAIL PROTECTED]>wrote:

> > Then why is there a link on the download site?
>
> Where specifically did you spot that link? I can't see any.
>

Copied from the download page:

   -

   Python 2.6 compressed source
tarball(for
Linux, Unix or OS X)
   -

   Python 2.6 bzipped source
tarball(for
Linux, Unix or OS X, more compressed)
   - Python 2.6 Windows
installer

   (Windows binary -- does not include source)
-

   Python 2.6 Windows AMD64
installer(Windows
AMD64 binary -- does not include source)
   -

   *Python 2.6 Windows Itanium
installer(Windows
Itanium binary -- does not include source)
   *
   -

   Python 2.6 for Macintosh OS
X-- this
is a universal installer that runs native on both PPC and Intel
   Macs.



> > You are saying that
> > for python 2.6 forward, there is no plan to support a stock python for
> > IA64?  Is there any particular reason why this is so?
>
> Yes. It's too much effort to build, and too few users that actually
> use it. Users are still free to build it themselves, and to share
> the build with others.
>
> Regards,
> Martin
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython Crashes with basic example

2008-11-19 Thread Benjamin Kaplan
I looked up the error code- c005 is Microsoft's cryptic way of telling
you that you had a seg fault. You might want to ask this on the wxPython
mailing list (http://www.wxpython.org/maillist.php) since I'm pretty sure
it's an issue with wx.
On Wed, Nov 19, 2008 at 3:04 PM, Samuel Morhaim <[EMAIL PROTECTED]>wrote:

> thanks for the reply.
> I just tried from the shell and it does the same..I had this running
> before..  a few days ago I had to reformat my machine, I reinstalled
> everything.. and now its happening..
>
> Thanks anyway..
>
>
> On Wed, Nov 19, 2008 at 2:01 PM, Benjamin Kaplan <[EMAIL PROTECTED]
> > wrote:
>
>>
>>
>> On Wed, Nov 19, 2008 at 12:51 PM, Samuel Morhaim <
>> [EMAIL PROTECTED]> wrote:
>>
>>> Hi, I am trying to run the basic wxpython example as seen here
>>> http://www.zetcode.com/wxpython/firststeps/ and everytime i run it, it
>>> crashes python/wxpython .. meaning it doesnt close gracefully.
>>> The error I get is
>>>
>>> Problem signature:
>>>   Problem Event Name: APPCRASH
>>>   Application Name: pythonw.exe
>>>   Application Version: 0.0.0.0
>>>   Application Timestamp: 48e49638
>>>   Fault Module Name: comctl32.dll_unloaded
>>>   Fault Module Version: 0.0.0.0
>>>   Fault Module Timestamp: 4791a629
>>>   Exception Code: c005
>>>   Exception Offset: 72b35a6e
>>>   OS Version: 6.0.6001.2.1.0.256.1
>>>   Locale ID: 1033
>>>   Additional Information 1: fd00
>>>   Additional Information 2: ea6f5fe8924aaa756324d57f87834160
>>>   Additional Information 3: fd00
>>>   Additional Information 4: ea6f5fe8924aaa756324d57f87834160
>>>
>>> Read our privacy statement:
>>>   http://go.microsoft.com/fwlink/?linkid=50163&clcid=0x0409
>>>
>>>
>>>
>>> Any ideas? it is just a basic example..   running python 2.6, wxpython,
>>> executing via IDLE or eric or any other..
>>>
>>
>>
>> I don't have any idea what caused your problem since I don't use Windows,
>> but you shouldn't run wxPython apps from IDLE because of conflicting event
>> loops. I think you might also have problems with Eric. Try running the
>> script from the command line and see if that solves your problem.
>>
>>
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: 404 not found on for Python 2.6 Itanium

2008-11-19 Thread Martin v. Löwis
> Then why is there a link on the download site?

Where specifically did you spot that link? I can't see any.

> You are saying that
> for python 2.6 forward, there is no plan to support a stock python for
> IA64?  Is there any particular reason why this is so?

Yes. It's too much effort to build, and too few users that actually
use it. Users are still free to build it themselves, and to share
the build with others.

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


Re: Finding the instance reference of an object

2008-11-19 Thread Craig Allen
I've just come to the conclusion it's not possible to call functions
in python, to do so is undefined and indeterminate, like dividing by
zero.  Henceforth no calling functions for me as clearly it's the
devil's playground.
--
http://mail.python.org/mailman/listinfo/python-list


Eric IDE Autocomplete

2008-11-19 Thread Samuel Morhaim
If anyone is familiar with this editor, can you tell me how to enable
autocomplete and tooltips,  IDLE-style?I add the API thing, and
everything but it display a lot of methods that  dont make sense in the
context..
for example if i do

import sys
sys. <-- Ctrl Space..  I get a list of about 100 methods,  they all have
tooltip such as (Eric4.Plugins..)  I just want to get the list like IDLE...
anyone?

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


Re: Exception difference 2.4 ==> 2.5

2008-11-19 Thread D'Arcy J.M. Cain
On Wed, 19 Nov 2008 11:20:48 -0800
"Chris Rebert" <[EMAIL PROTECTED]> wrote:
> On Wed, Nov 19, 2008 at 8:24 AM, D'Arcy J.M. Cain <[EMAIL PROTECTED]> wrote:
> > Interesting.  I installed 2.6 and tried it.  My unit test still failed
> > but for a different reason that I will have to investigate but the
> > exceptions were handled correctly.  Does this suggest something to you?
> 
> I would wildly guess that you might have encountered a bug in Python
> that was since fixed. Hard to be sure though.

If true I hope that a new version is forthcoming on the 2.5 branch.  I
am running Python 2.5.2.  I was able to reduce the program to a
reasonably small version that exhibits the problem.  It is in two files
in ftp://ftp.druid.net/pub/distrib/Test_2.5.tgz including Fredrik
Lundh's simple XML-RPC server.  Just run the test program under 2.4,
2.5 and 2.6 to see the difference.

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: 404 not found on for Python 2.6 Itanium

2008-11-19 Thread nadiasvertex
Then why is there a link on the download site?  You are saying that
for python 2.6 forward, there is no plan to support a stock python for
IA64?  Is there any particular reason why this is so?

-={C}=-

Christian Heimes wrote:
> [EMAIL PROTECTED] wrote:
> > Anyone know where else I can download 2.6 for x64 windows?
>
> x64 is AMD64 aka X64_86 and not the Itanium version. Itanium is IA64. We
> don't build Python for IA64 anymore.
>
> Christian
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will MySQLdb, the Python shim, be supported for Python 2.6 or 3.x?

2008-11-19 Thread John Nagle

Alia Khouri wrote:

John Nagle wrote:

Whoever did the port somehow created a dependency on the
Intel math library, "libguide40.dll" and "libmmd.dll".  That shouldn't
be needed in the MySQL Python shim.  It's not freely distributable,
either; you have to buy the Intel C++ compiler to get it.  There are
versions of those DLLs available on the web, but they may or may not
be legitimate or current.


I'm aware of that, as I went through the same process, actually
discovered that dependency myself, and ended up having to use dlls off
the net. Eventhough I got this to work in the end, I ultimately found
that this isn't the only extension lib with 'issues', in 2.6 (numpy,
etc..) I finally ditched 2.6 for my app and reverted back to 2.5. My
recommendation is to do the same until things improve in extension
land.


   It's a weird dependency, too.  Extensions usually have to be built
with the same compiler as the Python core.  If someone built this extension with
the Intel C++ compiler for x86 (why else would it need "libguide40.dll" and 
"libmmd.dll"), there may be mixed-library compatibility problems.


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


Re: calling python scripts as a sub-process

2008-11-19 Thread Dan Upton
On Wed, Nov 19, 2008 at 2:38 PM, Catherine Moroney
<[EMAIL PROTECTED]> wrote:
> Dan Upton wrote:
>>
>> On Wed, Nov 19, 2008 at 2:13 PM, Philip Semanchuk <[EMAIL PROTECTED]>
>> wrote:
>>>
>>> On Nov 19, 2008, at 2:03 PM, Catherine Moroney wrote:
>>>
 The command (stored as an array of strings) that I'm executing is:

 ['python ../src_python/Match1.py ',
 '--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
 '--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
 '--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2'
 ",
 "--use_textid='true '"]

>>> [snip]
>>>
 I get the error below.  Does anybody know what this error refers
 to and what I'm doing wrong?  Is it even allowable to call another
 script as a sub-process rather than calling it directly?

 File "../src_python/Match4.py", line 24, in RunMatch4
  sub1 = subprocess.Popen(command1)
  File "/usr/lib64/python2.5/subprocess.py", line 593, in __init__
  errread, errwrite)
  File "/usr/lib64/python2.5/subprocess.py", line 1051, in _execute_child
  raise child_exception
 OSError: [Errno 2] No such file or directory
>>>
>>> Try supplying a fully-qualified path to your script, e.g.:
>>> ['python /home/catherine/src_python/Match1.py ',
>>> '--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
>>> '--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
>>> '--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2'
>>> ",
>>> "--use_textid='true '"]
>>
>> I think when I came across this error, I added shell=True, e.g.
>>
>> sub1 = subprocess.Popen(command, shell=True)
>
> I added the shell=True and this time it got into Match1 (hurrah!),
> but it then opened up an interactive python session, and didn't
> complete until I manually typed 'exit' in the interactive session.
>
> Match1 looks like:
>
> if __name__ == "__main__":
> <<< parse arguments >>>
>
>RunMatch1(file_ref, file_cmp, iblock_start, iblock_end, \
>  nlinep, nsmpp, mindispx, maxdispx, mindispl,  \
>  maxdispl, istep, chmetric, use_textid)
>
>exit()
>
> where the routine RunMatch1 does all the actual processing.
>
> How do I get Match1 to run and exit normally without opening up an
> interactive session, when called as a subprocess from Match4?
>

Alternately, rather than using a list of arguments, have you tried
just using a string?  (Again, that's the way I do it and I haven't
been having any problems recently, although I'm running shell scripts
or binaries with arguments rather than trying to invoke python on a
script.)

command = "python ../src_python/Match1.py
--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf
--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf
--block_start=62 --block_end=62 --istep=16 --chmetric='M2'
--use_textid=true"

proc = subprocess.Popen(command, shell=True)
--
http://mail.python.org/mailman/listinfo/python-list


Re: spam update

2008-11-19 Thread Grant Edwards
On 2008-11-19, Shawn Milochik <[EMAIL PROTECTED]> wrote:

> At the time there was a lot of chatter on the list about
> people "plonking" posts from Google Groups. That's "a"
> solution, if that's where the spam comes from, but it
> penalizes the legitimate users who don't subscribe to the
> mailing list.

Not really.  It doesn't penalize people like me who don't
subscribe to the list, but post from other (properly run)
Usenet servers. It does penalizes legitimate users who post
from Google Groups.  They've made the choice to use the same
posting conduit as spammers, and presumably they know the
consequences.

There are plenty of free Usenet servers out there, and if one
is not allowed NNTP access or can't figure out how to do
anything that's not presented via a web page, then one can
always post from gmane.org.

-- 
Grant Edwards   grante Yow! If elected, Zippy
  at   pledges to each and every
   visi.comAmerican a 55-year-old
   houseboy ...
--
http://mail.python.org/mailman/listinfo/python-list


Re: calling python scripts as a sub-process

2008-11-19 Thread Catherine Moroney

Dan Upton wrote:

On Wed, Nov 19, 2008 at 2:13 PM, Philip Semanchuk <[EMAIL PROTECTED]> wrote:

On Nov 19, 2008, at 2:03 PM, Catherine Moroney wrote:


The command (stored as an array of strings) that I'm executing is:

['python ../src_python/Match1.py ',
'--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
'--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
'--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2' ",
"--use_textid='true '"]


[snip]


I get the error below.  Does anybody know what this error refers
to and what I'm doing wrong?  Is it even allowable to call another
script as a sub-process rather than calling it directly?

File "../src_python/Match4.py", line 24, in RunMatch4
  sub1 = subprocess.Popen(command1)
 File "/usr/lib64/python2.5/subprocess.py", line 593, in __init__
  errread, errwrite)
 File "/usr/lib64/python2.5/subprocess.py", line 1051, in _execute_child
  raise child_exception
OSError: [Errno 2] No such file or directory

Try supplying a fully-qualified path to your script, e.g.:
['python /home/catherine/src_python/Match1.py ',
'--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
'--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
'--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2' ",
"--use_textid='true '"]


I think when I came across this error, I added shell=True, e.g.

sub1 = subprocess.Popen(command, shell=True)


I added the shell=True and this time it got into Match1 (hurrah!),
but it then opened up an interactive python session, and didn't
complete until I manually typed 'exit' in the interactive session.

Match1 looks like:

if __name__ == "__main__":
<<< parse arguments >>>

RunMatch1(file_ref, file_cmp, iblock_start, iblock_end, \
  nlinep, nsmpp, mindispx, maxdispx, mindispl,  \
  maxdispl, istep, chmetric, use_textid)

exit()

where the routine RunMatch1 does all the actual processing.

How do I get Match1 to run and exit normally without opening up an
interactive session, when called as a subprocess from Match4?

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


Re: calling python scripts as a sub-process

2008-11-19 Thread Catherine Moroney

I just tried that, and I get the same error.

Interestingly enough, a shorter (and incorrect) version
of the command works well enough so that it gets into the
Match1 code and does the argument check there.

The following code gets into Match1:

>>> command = ['python', '../src_python/Match1.py','--filex="xyz"']
>>> sub1 = subprocess.Popen(command)

whereas this doesn't even get to call Match1:

command = 
['python','/data/svn_workspace/cmm/sieglind/USC/EE569/tpaper/test/../src_python/Match1.py 
', '--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ', 
'--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ', 
'--block_start=62 ', '--block_end=62 ', '--istep=16 ', '--chmetric=M2 ', 
'--use_textid=true']


sub1 = subprocess.Popen(command)

Can anybody see a reason for why the abbreviated version works, and
the full-up one doesn't?

Catherine

Philip Semanchuk wrote:


On Nov 19, 2008, at 2:03 PM, Catherine Moroney wrote:


The command (stored as an array of strings) that I'm executing is:

['python ../src_python/Match1.py ', 
'--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ', 
'--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ', 
'--block_start=62 ', '--block_end=62 ', '--istep=16 ', 
"--chmetric='M2' ", "--use_textid='true '"]




[snip]



I get the error below.  Does anybody know what this error refers
to and what I'm doing wrong?  Is it even allowable to call another
script as a sub-process rather than calling it directly?

File "../src_python/Match4.py", line 24, in RunMatch4
   sub1 = subprocess.Popen(command1)
 File "/usr/lib64/python2.5/subprocess.py", line 593, in __init__
   errread, errwrite)
 File "/usr/lib64/python2.5/subprocess.py", line 1051, in _execute_child
   raise child_exception
OSError: [Errno 2] No such file or directory


Try supplying a fully-qualified path to your script, e.g.:
['python /home/catherine/src_python/Match1.py ', 
'--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ', 
'--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ', 
'--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2' 
", "--use_textid='true '"]





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


Re: spam update

2008-11-19 Thread Shawn Milochik
On Tue, Nov 18, 2008 at 11:23 AM,  <[EMAIL PROTECTED]> wrote:
> With some help from the python.org postmasters over the weekend I figured
> out why some seemingly obvious spam messages seem to be making it to the
> python-list@python.org mailing list.  Messages gatewayed from Usenet don't
> pass through the spam filters.  Mailman simply distributes them.  There is
> still no resolution, but at least I understand the cause now.  For now,
> mailing list users please be patient as we try to resolve this issue.
>
> Thanks,
>
> --
> Skip Montanaro - [EMAIL PROTECTED] - http://smontanaro.dyndns.org/
> --
> http://mail.python.org/mailman/listinfo/python-list
>

It's like the never-ending story. This exact explanation was given to
the list over six months ago (in April) , along with the message that
there's nothing that we can do about it. Actually, it's not the
"exact" explanation -- it was narrowed down to posts from Google
Groups, rather than Usenet in general.

At the time there was a lot of chatter on the list about people
"plonking" posts from Google Groups. That's "a" solution, if that's
where the spam comes from, but it penalizes the legitimate users who
don't subscribe to the mailing list.

Just for what it's worth. This is an ongoing problem (although it used
to be much worse), and it's a shame that we're going in circles.

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


Re: Optional parameter object re-used when instantiating multiple objects

2008-11-19 Thread George Sakkis
On Nov 19, 1:05 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:

> On Wed, 19 Nov 2008 05:41:57 -0800 (PST), Rick Giuly
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
>
>
> > (By "better" I mean that over many years of time programmers will be
> > more productive because the language will be learned a bit faster with
> > a fewer surprises - and still retain its power.)
>
>         Your opinion... I'm sure there are some libraries out there that
> rely upon the current behavior

That's a straw man; of course they rely on it since they can. The same
would be even more true if the opposite behavior was selected from the
beginning, many more libraries would rely on it instead of (ab)using
None as default.

>  -- not to mention the hit on processing
> speed.

That's the only argument that may worth some merit. It's interesting
though that C++, a language much more obsessed with performance, picks
the runtime semantics:

#include 
using namespace std;

int a = 1;

int f(int a) {
  cout << "f(" << a << ") called\n";
  return a;
}

int g(int x = f(a)) { return x; }

int main() {
  cout << g() << endl;
  a = 2;
  cout << g() << endl;
}

#= output ==
f(1) called
1
f(2) called
2

>         I wouldn't expect a language like Ada to somehow re-evaluate a
> default argument on each call; why would I expect Python to do such?

Again, non sequitur. Python is not Ada (neither is C++, which does the
expected thing in this case).

>         Besides, learning is good for one -- and having something like this
> in Python gives one an excuse to learn something about language
> implementation choices 
>
>         And what behavior do you expect from:
>
>
>
> >>> d1 = [ 1, 2 ]
> >>> def what(arg = d1):
> ...     print arg
>
> ...    
> >>> what()
> [1, 2]
> >>> d1 = ( 3.14159, 2.78)
> >>> what()
> [1, 2]
>
>         If one does reevaluation of the default on each call, the second
> call should be printing
>
> (3.14159, 2.78)
>
>
>
> >>> del d1
> >>> what()
> [1, 2]
>
>         And that sequence would result in an exception
>
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'd1' is not defined
>
>         Do you really want a "default" argument that changes value depending
> upon actions performed in the /surrounding/ scope?

Yes, the surrounding scope in this case is the global scope; changing
or deleting globals has by definition global reach. Regardless, how
common is this usage in real code ? I believe an order of magnitude
less than the need for fresh mutable objects.

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


Re: Exception difference 2.4 ==> 2.5

2008-11-19 Thread Chris Rebert
On Wed, Nov 19, 2008 at 8:24 AM, D'Arcy J.M. Cain <[EMAIL PROTECTED]> wrote:
> On Tue, 18 Nov 2008 22:33:35 -0800
> "Chris Rebert" <[EMAIL PROTECTED]> wrote:
>> What happens under Python 2.6?
>
> Interesting.  I installed 2.6 and tried it.  My unit test still failed
> but for a different reason that I will have to investigate but the
> exceptions were handled correctly.  Does this suggest something to you?

I would wildly guess that you might have encountered a bug in Python
that was since fixed. Hard to be sure though.

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com

>
> --
> D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
> http://www.druid.net/darcy/|  and a sheep voting on
> +1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: calling python scripts as a sub-process

2008-11-19 Thread Mike Driscoll
On Nov 19, 1:03 pm, Catherine Moroney
<[EMAIL PROTECTED]> wrote:
> I have one script (Match1) that calls a Fortran executable as a
> sub-process, and I want to write another script (Match4) that
> spawns off several instances of Match1 in parallel and then waits
> until they all finish running.  The only way I can think of doing this
> is to call it as a sub-process, rather than directly.
>
> I'm able to get Match1 working correctly in isolation, using the
> subprocess.Popen command, but calling an instance of Match1 as a
> subprocess spawned from Match4 isn't working.
>
> The command (stored as an array of strings) that I'm executing is:
>
> ['python ../src_python/Match1.py ',
> '--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
> '--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
> '--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2'
> ", "--use_textid='true '"]
>
> and I'm calling it as:
>
> sub1 = subprocess.Popen(command)
>
> I get the error below.  Does anybody know what this error refers
> to and what I'm doing wrong?  Is it even allowable to call another
> script as a sub-process rather than calling it directly?
>
>   File "../src_python/Match4.py", line 24, in RunMatch4
>      sub1 = subprocess.Popen(command1)
>    File "/usr/lib64/python2.5/subprocess.py", line 593, in __init__
>      errread, errwrite)
>    File "/usr/lib64/python2.5/subprocess.py", line 1051, in _execute_child
>      raise child_exception
> OSError: [Errno 2] No such file or directory
>
> Thanks for any help,
>
> Catherine

Try giving an absolute path to the python file rather than a relative
path. I don't think the subprocess module "knows" where to look
otherwise.

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


Re: calling python scripts as a sub-process

2008-11-19 Thread Dan Upton
On Wed, Nov 19, 2008 at 2:13 PM, Philip Semanchuk <[EMAIL PROTECTED]> wrote:
>
> On Nov 19, 2008, at 2:03 PM, Catherine Moroney wrote:
>
>> The command (stored as an array of strings) that I'm executing is:
>>
>> ['python ../src_python/Match1.py ',
>> '--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
>> '--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
>> '--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2' ",
>> "--use_textid='true '"]
>>
>
> [snip]
>
>>
>> I get the error below.  Does anybody know what this error refers
>> to and what I'm doing wrong?  Is it even allowable to call another
>> script as a sub-process rather than calling it directly?
>>
>> File "../src_python/Match4.py", line 24, in RunMatch4
>>   sub1 = subprocess.Popen(command1)
>>  File "/usr/lib64/python2.5/subprocess.py", line 593, in __init__
>>   errread, errwrite)
>>  File "/usr/lib64/python2.5/subprocess.py", line 1051, in _execute_child
>>   raise child_exception
>> OSError: [Errno 2] No such file or directory
>
> Try supplying a fully-qualified path to your script, e.g.:
> ['python /home/catherine/src_python/Match1.py ',
> '--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
> '--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
> '--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2' ",
> "--use_textid='true '"]

I think when I came across this error, I added shell=True, e.g.

sub1 = subprocess.Popen(command, shell=True)
--
http://mail.python.org/mailman/listinfo/python-list


Re: calling python scripts as a sub-process

2008-11-19 Thread Philip Semanchuk


On Nov 19, 2008, at 2:03 PM, Catherine Moroney wrote:


The command (stored as an array of strings) that I'm executing is:

['python ../src_python/Match1.py ', '-- 
file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',  
'--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf  
', '--block_start=62 ', '--block_end=62 ', '--istep=16 ', "-- 
chmetric='M2' ", "--use_textid='true '"]




[snip]



I get the error below.  Does anybody know what this error refers
to and what I'm doing wrong?  Is it even allowable to call another
script as a sub-process rather than calling it directly?

File "../src_python/Match4.py", line 24, in RunMatch4
   sub1 = subprocess.Popen(command1)
 File "/usr/lib64/python2.5/subprocess.py", line 593, in __init__
   errread, errwrite)
 File "/usr/lib64/python2.5/subprocess.py", line 1051, in  
_execute_child

   raise child_exception
OSError: [Errno 2] No such file or directory


Try supplying a fully-qualified path to your script, e.g.:
['python /home/catherine/src_python/Match1.py ', '-- 
file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ', '-- 
file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ', '-- 
block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2'  
", "--use_textid='true '"]




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


Re: Programming exercises/challenges

2008-11-19 Thread Stef Mientki

hi Ben,

[EMAIL PROTECTED] wrote:

Hi guys,

I'm learning Python by teaching myself, and after going through 
several tutorials I feel like I've learned the basics. Since I'm not 
taking a class or anything, I've been doing challenges/programs to 
reinforce the material and improve my skills. I started out with stuff 
like "Guess my number" games, hangman, etc. and moved on to making 
poker and card games to work with classes. For GUIs I created games 
like minesweeper, and a GUI stock portfolio tracker. I am out of ideas 
and am looking for programming projects, challenges, or programs that 
have helped you'll learn. I'm working on the project Euler problems, 
but I find that they don't really help my programming skills; they are 
more math focused. Suggestions? What has been useful or interesting to 
you? I'd also welcome sources of textbook type problems, because the 
ones provided in tutorials tend to be repetitive.


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


I'm working on an open source alternative for MatLab / LabView (math 
again ;-)

and there's still a lot to do
- (re-)design of the core engine (multi thread ?)
- implementation of webkit under wxPython
- integration of Scintilla and rpdb2
- Vpython integration under Linux / Mac (Windows works)
- something like Okular, but then platform independant
- integrating of data acquisition hardware, soundcard, National 
Instruments AD-converters, ...

here is a somewhat older version of my notes
 http://mientki.ruhosting.nl/data_www/pylab_works/pw_manual.pdf
all separate notes until now can be seen under the paragraph PyLab works 
here

 http://pic.flappie.nl


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


calling python scripts as a sub-process

2008-11-19 Thread Catherine Moroney
I have one script (Match1) that calls a Fortran executable as a 
sub-process, and I want to write another script (Match4) that

spawns off several instances of Match1 in parallel and then waits
until they all finish running.  The only way I can think of doing this
is to call it as a sub-process, rather than directly.

I'm able to get Match1 working correctly in isolation, using the
subprocess.Popen command, but calling an instance of Match1 as a
subprocess spawned from Match4 isn't working.

The command (stored as an array of strings) that I'm executing is:

['python ../src_python/Match1.py ', 
'--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ', 
'--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ', 
'--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2' 
", "--use_textid='true '"]


and I'm calling it as:

sub1 = subprocess.Popen(command)

I get the error below.  Does anybody know what this error refers
to and what I'm doing wrong?  Is it even allowable to call another
script as a sub-process rather than calling it directly?

 File "../src_python/Match4.py", line 24, in RunMatch4
sub1 = subprocess.Popen(command1)
  File "/usr/lib64/python2.5/subprocess.py", line 593, in __init__
errread, errwrite)
  File "/usr/lib64/python2.5/subprocess.py", line 1051, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

Thanks for any help,

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


Re: Avoiding local variable declarations?

2008-11-19 Thread Arnaud Delobelle
greg <[EMAIL PROTECTED]> writes:

> Arnaud Delobelle wrote:
>
>> Neutral element is correct.  But maybe its use is limited to
>> mathematicians in the english-speaking word.
>
> I've only ever seen "identity element" in English mathematics.
> "Neutral element" sounds like something my car's gearbox
> might have...

I was an academic mathematician for several years (although not a very
good one) and I can assure you that 'neutral element' is correct and
understood. 'Unit element' is another common synonym.

Unfortunately I can't find a reference in one of the few books in
English that I have at home.  Lang's "Algebra" does not seem to use the
term and it's the only undergraduate book I've got.  Wikipedia and other
internet sources cite 'neutral element' as a synonym to 'identity
element'.

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


GzipFile as a Context manager

2008-11-19 Thread Mikolai Fajer
Is there a reason that the gzip.GzipFile class does not have __enter__
and __exit__ methods that mimic those of the file object?  I expected
the following to work but it doesn't:

import gzip
with gzip.open('temp.gz', 'w') as fhandle:
gzip.write('Hello world.')

If there is no reason to avoid this behavior should I submit a bug
report and a subsequent patch?  Thanks!

-- 

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


Re: wxPython Crashes with basic example

2008-11-19 Thread Benjamin Kaplan
On Wed, Nov 19, 2008 at 12:51 PM, Samuel Morhaim
<[EMAIL PROTECTED]>wrote:

> Hi, I am trying to run the basic wxpython example as seen here
> http://www.zetcode.com/wxpython/firststeps/ and everytime i run it, it
> crashes python/wxpython .. meaning it doesnt close gracefully.
> The error I get is
>
> Problem signature:
>   Problem Event Name: APPCRASH
>   Application Name: pythonw.exe
>   Application Version: 0.0.0.0
>   Application Timestamp: 48e49638
>   Fault Module Name: comctl32.dll_unloaded
>   Fault Module Version: 0.0.0.0
>   Fault Module Timestamp: 4791a629
>   Exception Code: c005
>   Exception Offset: 72b35a6e
>   OS Version: 6.0.6001.2.1.0.256.1
>   Locale ID: 1033
>   Additional Information 1: fd00
>   Additional Information 2: ea6f5fe8924aaa756324d57f87834160
>   Additional Information 3: fd00
>   Additional Information 4: ea6f5fe8924aaa756324d57f87834160
>
> Read our privacy statement:
>   http://go.microsoft.com/fwlink/?linkid=50163&clcid=0x0409
>
>
>
> Any ideas? it is just a basic example..   running python 2.6, wxpython,
> executing via IDLE or eric or any other..
>


I don't have any idea what caused your problem since I don't use Windows,
but you shouldn't run wxPython apps from IDLE because of conflicting event
loops. I think you might also have problems with Eric. Try running the
script from the command line and see if that solves your problem.
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython BoxSizer

2008-11-19 Thread Mike Driscoll
On Nov 19, 12:22 pm, Jamie McQuay <[EMAIL PROTECTED]> wrote:
> > > FYI: There's a great wxPython mailing list too. Check it out 
> > > here:http://wxpython.org/maillist.php
>
> > thanks, i will take a look.
>
> Here is the answer i got from the mailing list (and it works)
>
> Try adding a spacer on both sides of text.
>
> i.e)
> box.AddStretchSpacer()
> box.Add(myText, 0, wx.ALIGN_CENTER)
> box.AddStretchSpacer()
>
> jamie

Yeah...I saw that on the wx list. I either had forgotten about that
method or never knew it existed. The wx.CENTER style should have
worked. Robin Dunn might explain it later. You can learn a lot from
the guys (and girls) on that list though.

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


Re: Quick nested loop syntax?

2008-11-19 Thread Vlastimil Brom
2008/11/19 Johannes Bauer <[EMAIL PROTECTED]>

> Hi group,
>
> if I remember correctly, wasn't there a way to quickly iterate through
> nested loops? Something like
>
> a = { "a", "b", "c" }
> b = { 4, 9, 13}
> for (x, y) in someoperator(a, b):
>print(x, y)
>
> which would print all tuples of
> "a", 4
> "a", 9
> "a", 13
> "b", 4
> "b", 9
> "b", 13
> "c", 4
> "c", 9
> "c", 13
>
> (not nececssarily in that order, of course).
>
> Thanks,
> Johannes
>
> --
>
If you are running the code in python 3, as suggested by the use of the set
literals, the mentioned itertools.product() is probably the straightforward
way.
Another possibility could be a nested generator expression (here using lists
- preserving the order):
>>> a = ["a", "b", "c"]
>>> b = [4, 9, 13]
>>> for item in ((ax, bx) for ax in a for bx in b): print item
...
('a', 4)
('a', 9)
('a', 13)
('b', 4)
('b', 9)
('b', 13)
('c', 4)
('c', 9)
('c', 13)
>>>
regards
   vbr
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the instance reference of an object

2008-11-19 Thread Joe Strout

On Nov 19, 2008, at 11:05 AM, Douglas Alan wrote:


Personally, I find this whole debate kind of silly, as it is based on
a completely fallacious either/or dichotomy.

(1) It is unarguably true that Python and Java use a type of
   call-by-value.  This follows from the standard definition of
   call-by-value, and common usage in, for example, the Scheme and
   Java communities, etc.


True.


(2) It is also unarguably true that saying that Python or Java use
   "call-by-value", and saying nothing more is going to be profoundly
   confusing to anyone who is learning these languages.


Perhaps (unless they've already learned this from one of the other  
languages).



Q. How do we generally solve this problem when speaking?

A. We invent more specific terms and then generally stick to the more
specific terms when the more general terms would be misleading.

I.e.,

  Q. What is Greg?

  A. Greg is a human being.

and

  Q. What type of calling semantics do Python and Java use?

  A. Call-by-sharing.


Fair enough, but if the questioner then says "WTF is call-by-sharing,"  
we should answer "call-by-sharing is the term we prefer for call-by- 
value in the case where the value is an object reference (as is always  
the case in Python)."



I assert that anyone who does not understand all of the above, is
helping to spread confusion.


I agree.

Best,
- Joe

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


Re: wxPython BoxSizer

2008-11-19 Thread Jamie McQuay

>
> > FYI: There's a great wxPython mailing list too. Check it out 
> > here:http://wxpython.org/maillist.php
>
> thanks, i will take a look.

Here is the answer i got from the mailing list (and it works)

Try adding a spacer on both sides of text.

i.e)
box.AddStretchSpacer()
box.Add(myText, 0, wx.ALIGN_CENTER)
box.AddStretchSpacer()

jamie

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


Re: Quick nested loop syntax?

2008-11-19 Thread Terry Reedy

Johannes Bauer wrote:

Hi group,

if I remember correctly, wasn't there a way to quickly iterate through
nested loops? Something like

a = { "a", "b", "c" }
b = { 4, 9, 13}
for (x, y) in someoperator(a, b):
print(x, y)


from itertools import product
a = { "a", "b", "c" }
b = { 4, 9, 13}
for (x, y) in product(a, b):
print(x, y)

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


Re: Finding the instance reference of an object

2008-11-19 Thread Douglas Alan
greg <[EMAIL PROTECTED]> writes:

> Steven D'Aprano wrote:

>> At least some sections of the Java community seem to prefer a
>> misleading and confusing use of the word "value" over clarity and
>> simplicity, but I for one do not agree with them.

> I don't see anything inherently confusing or misleading
> about it. Confusion only arises when some people jump up
> and say that it's wrong to use the terms that way, because
> it might cause confusion...

Personally, I find this whole debate kind of silly, as it is based on
a completely fallacious either/or dichotomy.

(1) It is unarguably true that Python and Java use a type of
call-by-value.  This follows from the standard definition of
call-by-value, and common usage in, for example, the Scheme and
Java communities, etc.

(2) It is also unarguably true that saying that Python or Java use
"call-by-value", and saying nothing more is going to be profoundly
confusing to anyone who is learning these languages.

It's like the difference between

   Q. What is a giraffe?

   A. A giraffe is a type of animal.

and

   Q. What is Greg?

   A. Greg is a type of animal.

In both cases, the answers are strictly correct, but in the second
case, the answer is also deeply misleading.

Q. How do we generally solve this problem when speaking?

A. We invent more specific terms and then generally stick to the more
specific terms when the more general terms would be misleading.

I.e.,

   Q. What is Greg?

   A. Greg is a human being.

and

   Q. What type of calling semantics do Python and Java use?

   A. Call-by-sharing.

I assert that anyone who does not understand all of the above, is
helping to spread confusion.

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


Re: Quick nested loop syntax?

2008-11-19 Thread Mark Dickinson
On Nov 19, 5:48 pm, Johannes Bauer <[EMAIL PROTECTED]> wrote:
> Hi group,
>
> if I remember correctly, wasn't there a way to quickly iterate through
> nested loops? Something like

Python 2.6 has itertools.product:

http://docs.python.org/library/itertools.html#itertools.product

If you don't have Python 2.6 available, then the documentation
above also contains (almost) equivalent Python code that might
work for you.

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


wxPython Crashes with basic example

2008-11-19 Thread Samuel Morhaim
Hi, I am trying to run the basic wxpython example as seen here
http://www.zetcode.com/wxpython/firststeps/ and everytime i run it, it
crashes python/wxpython .. meaning it doesnt close gracefully.
The error I get is

Problem signature:
  Problem Event Name: APPCRASH
  Application Name: pythonw.exe
  Application Version: 0.0.0.0
  Application Timestamp: 48e49638
  Fault Module Name: comctl32.dll_unloaded
  Fault Module Version: 0.0.0.0
  Fault Module Timestamp: 4791a629
  Exception Code: c005
  Exception Offset: 72b35a6e
  OS Version: 6.0.6001.2.1.0.256.1
  Locale ID: 1033
  Additional Information 1: fd00
  Additional Information 2: ea6f5fe8924aaa756324d57f87834160
  Additional Information 3: fd00
  Additional Information 4: ea6f5fe8924aaa756324d57f87834160

Read our privacy statement:
  http://go.microsoft.com/fwlink/?linkid=50163&clcid=0x0409



Any ideas? it is just a basic example..   running python 2.6, wxpython,
executing via IDLE or eric or any other..

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


Re: Possible bug in Tkinter for Python 2.6

2008-11-19 Thread Terry Reedy

Anton Vredegoor wrote:

On Wed, 19 Nov 2008 10:57:53 +0100
"Eric Brunel" <[EMAIL PROTECTED]> wrote:


I'm trying out Python 2.6 and I found what might be a bug in the
Tkinter module. How can I report it?


maybe here:
http://bugs.python.org/issue3774


The fix will be in 2.6.1, which might be in December.

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


Quick nested loop syntax?

2008-11-19 Thread Johannes Bauer
Hi group,

if I remember correctly, wasn't there a way to quickly iterate through
nested loops? Something like

a = { "a", "b", "c" }
b = { 4, 9, 13}
for (x, y) in someoperator(a, b):
print(x, y)

which would print all tuples of
"a", 4
"a", 9
"a", 13
"b", 4
"b", 9
"b", 13
"c", 4
"c", 9
"c", 13

(not nececssarily in that order, of course).

Thanks,
Johannes

-- 
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
 -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
 <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Inheriting frozenset gives bug if i overwrite __repr__ method

2008-11-19 Thread Mark Dickinson
On Nov 19, 4:23 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> Yep; looks like a bug in the set/frozenset implementation.

Thanks!  I was about to report this to bugs.python.org, but it
looks as though Raymond's been at the time machine again:

http://bugs.python.org/issue1721812

It's fixed in 3.0; backporting the fix to 2.x was deemed too risky.

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


Re: python vs smalltalk 80

2008-11-19 Thread George Sakkis
On Nov 19, 1:53 am, gavino <[EMAIL PROTECTED]> wrote:

> python vs smalltalk 80
>
> which is nicer?

Dunno but there's an interesting talk about this: 
http://www.youtube.com/watch?v=oHg5SJYRHA0

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


Re: XML -> Tab-delimited text file (using lxml)

2008-11-19 Thread Gibson
On Nov 19, 11:03 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
>
> Use iterparse() instead of parsing the file into memory completely.
>
> *stuff*
>
> Stefan

That worked wonders. Thanks a lot, Stefan.

So, iterparse() uses an iterate -> parse method instead of parse() and
iter()'s parse -> iterate method (if that makes any sense)?
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython BoxSizer

2008-11-19 Thread Jamie McQuay

>
> Try the style=wx.CENTER like this:
>
> box.Add(myText,0,wx.CENTER)

tried but i still get the same result.  The text is either at the top
of the panel (centered) or in the middle (on the left side).  If i
manually call CenterOnParent when the panel is resized it goes to the
center but i want to get the sizers to work correctly for this.

>
> FYI: There's a great wxPython mailing list too. Check it out 
> here:http://wxpython.org/maillist.php

thanks, i will take a look.

Jamie

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


python template: may help at starting a new script

2008-11-19 Thread Stephane Bulot
Hello,

I've created a python script template that I've been using for a while, but
that I improved recently.
This script is a class that you can inherit into your main class. In the
source package, you have a main template, a thread template, and two example
files.

If you are interested in this project, you can go to the
http://www.bulot.org/wiki/doku.php?id=projects:python:pytemplate and let me
know your feedbacks. If you use it, tell me how to improve, what to add,
what is wrong, what is good.
For your information, this script has not been tested on windows. Feel free
to patch it and give me your patches. I will introduce them into my project.

You will get some news on http://www.bulot.org .

Regards.

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


Re: PEP 324 error

2008-11-19 Thread Terry Reedy

Andrew wrote:

It appears PEP 324 is missing the part about check_call():

http://www.python.org/dev/peps/pep-0324/ ...

...


In the docstring of subprocess in python 2.5:

...


I don't know if check_call is going to be deprecated, but there still
appears to be a missing function. I'm not sure if this is the correct
way to report errors, but I think it's prudent to keep the
documentation comprehensive.


Comments about the text of a PEP should be directed to the PEP author, 
whose is the one who would edit it.


The definitive documentation of the subprocess module is, as usual, its 
section in the Library manual, as well as the docstring.  Those two 
should be in sync.  PEPs are design and development documents and are 
usually not revised once approved and implemented.


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


Re: Programming exercises/challenges

2008-11-19 Thread Mr . SpOOn
On Wed, Nov 19, 2008 at 3:41 PM, Philip Semanchuk <[EMAIL PROTECTED]> wrote:
> I'm not sure why you'd need to host the Python code anywhere other than your
> home computer. If you wanted to pull thousands of pages from a site like
> that, you'd need to respect their robots.txt file. Don't forget to look for
> a crawl-delay specification. Even if they don't specify one, you shouldn't
> let your bot hammer their servers at full speed -- give it a delay, let it
> run in the background, it might take you three days versus an hour to
> collect the data you need but that's not too big of deal in the service of
> good manners, is it?

Mmm, I didn't really mean the possibility to just host the code, but
to run. I mean, like server side code, so that my programs keep
running and updating, in my case, the RSS feed, without the need for
me to be online and run it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython BoxSizer

2008-11-19 Thread Mike Driscoll
Hi Jamie,

On Nov 19, 9:16 am, Jamie McQuay <[EMAIL PROTECTED]> wrote:
> Simple question, i just can't make it work.
>
> I need to center a StaticText component in its parent (Panel).  I want
> to do this with BoxSizer(s).
>
> if i use:
> box = wx.BoxSizer(wx.VERTICAL)   #or wx.HORIZONTAL
> box.Add(myText,0,wx.ALIGN_CENTER)
> parentPanel.Sizer = box
>
> i can get it to center either vertically or horizontally, but not both
> (i.e. the center).  I've tried myText.CenterOnParent but i need to
> handle to Size event to move the text when the panel is resized and i
> don't want to have to do this.
>
> thanks,
> Jamie

Try the style=wx.CENTER like this:

box.Add(myText,0,wx.CENTER)

FYI: There's a great wxPython mailing list too. Check it out here:
http://wxpython.org/maillist.php

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


Re: sorting list of complex numbers

2008-11-19 Thread Hrvoje Niksic
Terry Reedy <[EMAIL PROTECTED]> writes:

> Hrvoje Niksic wrote:
>> Terry Reedy <[EMAIL PROTECTED]> writes:
>>
>>> Do your tuple destructuring in the first statement in your body and
>>> nothing will break.
>>
>> Unless you were using a lambda, which is quite useful as argument to
>> "sort".
>
> So write a separate def statement.

That is a valid possibility, but loses the succinctness of a short
lambda.  Some uses of lambda+unpacking can also be replaced by
operator.itemgetter.

> If you do not want to do that, don't run with 3.0.

Tuple unpacking in parameters is a useful feature, but hardly reason
enough to abandon the future of the language.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Inheriting frozenset gives bug if i overwrite __repr__ method

2008-11-19 Thread Terry Reedy

srinivasan srinivas wrote:

Hi,
I am getting an error while executing the following snippet. If i comment out 
method __repr__ , it works fine.

class fs(frozenset):
def __new__(cls, *data):
data = sorted(data)
self = frozenset.__new__(cls, data)
self.__data = data
return self

def __repr__(self):
return "%s(%r)" % (self.__class__.__name__, self.__data)

a1 = fs(1,2,3)
a2 = fs(3,4,5)
print a1.difference(a2)

Error:
return "%s(%r)" % (self.__class__.__name__, self.__data)
AttributeError: 'fs' object has no attribute '_fs__data'

Please help me in fixing this.


When posting problems like this, please include the Python version.
If you ran this with 2.6, please run the following:

x = frozenset('abc')
y = frozenset('bcd')
z = x.difference(y)
print(id(x) != id(z))

This should print (True), but if 2.6 has a bug for frozenset similar one 
it has for bytearrays, it will print (False) and that would explain your 
error.


tjr

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


  1   2   >