Re: question about endswith()

2011-03-03 Thread Rafael Durán Castañeda
I think you want do this:

>>> files = ['file1.hdf', 'file2.hdf', 'file3.hdf5','file4.hdf']
>>> print(''.join(x for x in files if x.endswith('5')))
file3.hdf5
>>>

But if you need to use it later:

>>> file_hdf5 = [x for x in files if x.endswith('5')]
>>> file_hdf5
['file3.hdf5']
>>>


2011/3/4 Grant Edwards 

> On 2011-03-04, Matt Funk  wrote:
> > Hi Grant,
> > first of all sorry for the many typos in my previous email.
> >
> > To clarify, I have a python list full of file names called 'files'.
> > Every single filename has extension='.hdf' except for one file which has
> > an '.hdf5' extension. When i do (and yes, this is pasted):
> > for filename in files:
> > if (any(filename.endswith(x) for x in extensions)):
> > print filename
>
> I was unable to run that code:
>
> $ cat testit.py
>
> for filename in files:
> if (any(filename.endswith(x) for x in extensions)):
> print filename
>
> $ python testit.py
>
> Traceback (most recent call last):
>  File "testit.py", line 1, in 
>for filename in files:
> NameError: name 'files' is not defined
>
> > However, it will print all the files in list 'files' (that is all
> > files with file extension '.hdf'). My question is why it doesn't just
> > print the filename with extensions '.hdf5'?
>
> Dunno.  You didn't provide enough information for us to answer your
> question: the code you posted won't run and don't tell us what values
> you're using for any of the variables.
>
> Here's a piece of runnable code that I think does what you want:
>
> $ cat testit.py
> files = ["foo.bar", "foo.baz", "foo.bax"]
> extensions = [".baz",".spam",".eggs"]
>
> for filename in files:
> if (any(filename.endswith(x) for x in extensions)):
> print filename
>
> $ python testit.py
> foo.baz
>
> --
> Grant
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Communicating from Flash to Python

2011-03-03 Thread Godson Gera
You can use PyAMF http://pyamf.org

On Fri, Mar 4, 2011 at 3:31 AM, Victor Subervi wrote:

> Hi;
> I have an AS3 script that is supposed to communicate with a python script
> and I don't think it is. The python script is to email. How can I
> trouble-shoot this?
> Beno
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Thanks & Regards,
Godson Gera
VoIP Consultant India 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2to3 and maketrans

2011-03-03 Thread Martin v. Löwis
Am 04.03.2011 03:21, schrieb Dan Stromberg:
> 
> On Thu, Mar 3, 2011 at 3:46 PM, Martin v. Loewis  > wrote:
> 
> That depends on how you chose to represent text in 2.7.
> The recommended way for that (also with 3.x in mind)
> is that you should use Unicode strings to represent text.
> 
> 
> For application programming, I'm sure Unicode is usually preferable.
> 
> For systems programming, it's hard for me to imagine that unicode would
> normally be favored over bytes.

I think Greg Ewing was really talking about WxPython. For WxPython,
I would indeed recommend to represent text as Unicode, although
there may be backwards-compatibility concerns to support byte strings
in certain places as well.

Whether a GUI library is application programming or systems programming,
I don't know.

Regards,
Martin

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


Re: auto increment

2011-03-03 Thread Dan Stromberg
On Thu, Mar 3, 2011 at 9:07 PM, Chris Rebert  wrote:

> On Thu, Mar 3, 2011 at 9:05 PM, Dan Stromberg  wrote:
> > On Thu, Mar 3, 2011 at 8:48 PM, Chris Rebert  wrote:
> >> On Thu, Mar 3, 2011 at 8:41 PM, monkeys paw 
> wrote:
> >> > Does python have an analogy to c/perl incrementer?
> >> >
> >> > e.g.
> >> >
> >> > i = 0
> >> > i++
> >>
> >> i += 1
> >>
> >> If you're doing this for a list index, use enumerate() instead.
> >
> > There's been discussion of adding i++ to python, but it was felt that the
> > small number of saved keystrokes didn't justify the resulting bugs.  I
> > agree.
>
> Out of curiosity, what resulting bugs?
>
> Cheers,
> Chris
>

EG:

if debug:
   print 'This is the %dth issue' % i++
warble = i * 65521

Then warble gets a different value depending on whether you're in debug mode
or not, and the source of the problem can take a few glances to catch.

Also, just using an expression in a statement context is a little... odd.  I
know it's the norm in some languages, but I like it that Python maintains a
clear distinction.  But if you disallow using an expression in a statement
context, then the usefulness of i++ is dramatically decreased.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: auto increment

2011-03-03 Thread Chris Rebert
On Thu, Mar 3, 2011 at 9:05 PM, Dan Stromberg  wrote:
> On Thu, Mar 3, 2011 at 8:48 PM, Chris Rebert  wrote:
>> On Thu, Mar 3, 2011 at 8:41 PM, monkeys paw  wrote:
>> > Does python have an analogy to c/perl incrementer?
>> >
>> > e.g.
>> >
>> > i = 0
>> > i++
>>
>> i += 1
>>
>> If you're doing this for a list index, use enumerate() instead.
>
> There's been discussion of adding i++ to python, but it was felt that the
> small number of saved keystrokes didn't justify the resulting bugs.  I
> agree.

Out of curiosity, what resulting bugs?

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


Re: auto increment

2011-03-03 Thread Dan Stromberg
On Thu, Mar 3, 2011 at 8:48 PM, Chris Rebert  wrote:

> On Thu, Mar 3, 2011 at 8:41 PM, monkeys paw  wrote:
> > Does python have an analogy to c/perl incrementer?
> >
> > e.g.
> >
> > i = 0
> > i++
>
> i += 1
>
> If you're doing this for a list index, use enumerate() instead.
>

There's been discussion of adding i++ to python, but it was felt that the
small number of saved keystrokes didn't justify the resulting bugs.  I
agree.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: auto increment

2011-03-03 Thread Chris Rebert
On Thu, Mar 3, 2011 at 8:41 PM, monkeys paw  wrote:
> Does python have an analogy to c/perl incrementer?
>
> e.g.
>
> i = 0
> i++

i += 1

If you're doing this for a list index, use enumerate() instead.

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


auto increment

2011-03-03 Thread monkeys paw

Does python have an analogy to c/perl incrementer?

e.g.

i = 0
i++

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


Re: Need an example program that implements rpm -pql via import rpm

2011-03-03 Thread geremy condra
On Thu, Mar 3, 2011 at 7:24 PM, Steven W. Orr  wrote:
> I look everywhere but I couldn't find anything. Could someone please point
> me to a small example program that does an import rpm, takes an rpm file as
> an argument and gets the list of files contained in the file, the same as if
> I had used the commandline
>
> rpm -pql foo-1.23-4.i586.rpm
>
> Much appreciated.

#! /usr/bin/env python

import sys
import commands

if __name__ == "__main__":
rpm = sys.argv[1]
print commands.getoutput("rpm -pql %s" % rpm)


Input validation and help text left as an exercise for the reader.

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


Re: OT: Code Examples

2011-03-03 Thread Chris Jones
On Thu, Mar 03, 2011 at 02:29:54PM EST, Emile van Sebille wrote:
> On 3/1/2011 3:59 PM Chris Jones said...
>> On Tue, Mar 01, 2011 at 12:03:02PM EST, Emile van Sebille wrote:
 
>>> On 3/1/2011 12:43 AM Erik de Castro Lopo said...
>>
 Why Python?
>>>
>>> For me?  Because it's executable pseudocode
>>
>> Not for nothing, Emile.. hey.. you could end up with pseudo bugs and
>> pseudo headaches ..
>>
>
> Ah -- that's why there's Pseudoephedrine...
>
> :)

Ah yes..!! Excellent..!

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


Need an example program that implements rpm -pql via import rpm

2011-03-03 Thread Steven W. Orr
I look everywhere but I couldn't find anything. Could someone please point me to 
a small example program that does an import rpm, takes an rpm file as an 
argument and gets the list of files contained in the file, the same as if I had 
used the commandline


rpm -pql foo-1.23-4.i586.rpm

Much appreciated.

TIA

--
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Checking against NULL will be eliminated?

2011-03-03 Thread Carl Banks
On Mar 3, 7:12 pm, Carl Banks  wrote:
[snip]

Accidental post before I was done.  To complete the thought:

I actually can think of one indeterminate behavior in C (although it's
not certain whether this qualifies as interaction with the
environment):

int main(void) {
    int a;
    printf("%d\n",a);
return 0;
}

The C standard allows the memory a refers to to be uninitialized,
meaning that a's value is whatever previously existed in that memory
slot, which could be anything.

OTOH this program:

int main(void) {
    int a = 1;
a = a++;
printf("%d\n",a);
return 0;
}

is undefined, which I guess technically could mean that compiler could
output an indeterminate result, but I doubt there are any compilers
that won't output the same value every time it's run.


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


Re: Checking against NULL will be eliminated?

2011-03-03 Thread Carl Banks
On Mar 3, 5:16 am, Neil Cerutti  wrote:
> On 2011-03-03, Tom Zych  wrote:
>
> > Carl Banks wrote:
> >> Perl works deterministically and reliably.  In fact, pretty much every
> >> language works deterministically and reliably.  Total non-argument.
>
> > Well, yes. I think the real issue is, how many surprises are
> > waiting to pounce on the unwary developer. C is deterministic
> > and reliable, but full of surprises.
>
> Point of order, for expediency, C and C++ both include lots and
> lots of indeterminate stuff.

It's besides the point, but I'll bite.  Apart from interactions with
the environment (system timer and whatnot), when does C or C++ code
ever produce indeterminate behavior?

> A piece of specific C code can be
> totally deterministic, but the language is full of undefined
> corners.

C and C++ have plenty of behaviors that are undefined, implementation
defined, etc.  But that is not the same thing as indeterminate.
Determinate means when you compile/run the code it does the same thing
every time (more or less).  When run a program and it does one thing,
then you run it again and it does something else, it's indeterminate.

I actually can think of one indeterminate behavior in C (although it's
not certain whether this qualifies as interaction with the
environment):

int main(void) {
int a;
printf("%d\n",a);
}

The C standard allows the memory a refers to to be uninitialized,

OTOH this

int main(void) {
a = 1;
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2to3 and maketrans

2011-03-03 Thread Dan Stromberg
On Thu, Mar 3, 2011 at 3:46 PM, Martin v. Loewis  wrote:

> That depends on how you chose to represent text in 2.7.
> The recommended way for that (also with 3.x in mind)
> is that you should use Unicode strings to represent text.
>

For application programming, I'm sure Unicode is usually preferable.

For systems programming, it's hard for me to imagine that unicode would
normally be favored over bytes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: making a class callable

2011-03-03 Thread dude
On Mar 3, 6:07 pm, MRAB  wrote:
> On 04/03/2011 01:45, dude wrote:
>
>
>
> > I've been struggling with getting my class to behave the way I want
> > it.
>
> > I have python module called ohYeah.py, defined as follows...
> > #File Begin
> > class foo:
>
> >      def __init__(self, arg1):
> >          print arg1
> >          self.ohYeah = arg1
>
> >      def whatwhat(self):
> >          return self.ohYeah
> > #EOF
>
> > My goal is to be able to instantiate the class foo from another python
> > module, like so:
>
> > # Example Usage
> > f = foo("wow")
> > j = foo("amazing")
> > f.whatwhat()
> > wow
> > j.whatwhat()
> > amazing
> > #
>
> > However, I always get the "module not callable" error.  After entering
> > a "def __call__" method in class foo, still get the same problem.  Can
> > someone please point me in the right direction for being able to
> > achieve the Example Usage above?  I'm sure there is something trivial
> > I'm missing, but after digging around online for a day, I couldn't
> > find the missing piece.  Thanks in advance.
>
> How are you importing it?
>
> It should be something like:
>
>      from ohYeah import foo
>
> BTW, the recommendation is for class names to be CamelCase and modules
> names to be lowercase.

That was the problem.  I was using:
import ohYeah

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


Re: making a class callable

2011-03-03 Thread MRAB

On 04/03/2011 01:45, dude wrote:

I've been struggling with getting my class to behave the way I want
it.

I have python module called ohYeah.py, defined as follows...
#File Begin
class foo:

 def __init__(self, arg1):
 print arg1
 self.ohYeah = arg1

 def whatwhat(self):
 return self.ohYeah
#EOF

My goal is to be able to instantiate the class foo from another python
module, like so:

# Example Usage
f = foo("wow")
j = foo("amazing")
f.whatwhat()
wow
j.whatwhat()
amazing
#

However, I always get the "module not callable" error.  After entering
a "def __call__" method in class foo, still get the same problem.  Can
someone please point me in the right direction for being able to
achieve the Example Usage above?  I'm sure there is something trivial
I'm missing, but after digging around online for a day, I couldn't
find the missing piece.  Thanks in advance.


How are you importing it?

It should be something like:

from ohYeah import foo

BTW, the recommendation is for class names to be CamelCase and modules
names to be lowercase.
--
http://mail.python.org/mailman/listinfo/python-list


Re: making a class callable

2011-03-03 Thread Santoso Wijaya
Are you missing an import?

import ohYeah
f = ohYeah.foo('wow')
...

~/santa


On Thu, Mar 3, 2011 at 5:45 PM, dude  wrote:

> I've been struggling with getting my class to behave the way I want
> it.
>
> I have python module called ohYeah.py, defined as follows...
> #File Begin
> class foo:
>
>def __init__(self, arg1):
>print arg1
>self.ohYeah = arg1
>
>def whatwhat(self):
>return self.ohYeah
> #EOF
>
> My goal is to be able to instantiate the class foo from another python
> module, like so:
>
> # Example Usage
> f = foo("wow")
> j = foo("amazing")
> f.whatwhat()
> wow
> j.whatwhat()
> amazing
> #
>
> However, I always get the "module not callable" error.  After entering
> a "def __call__" method in class foo, still get the same problem.  Can
> someone please point me in the right direction for being able to
> achieve the Example Usage above?  I'm sure there is something trivial
> I'm missing, but after digging around online for a day, I couldn't
> find the missing piece.  Thanks in advance.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about endswith()

2011-03-03 Thread Grant Edwards
On 2011-03-04, Matt Funk  wrote:
> Hi Grant,
> first of all sorry for the many typos in my previous email.
>
> To clarify, I have a python list full of file names called 'files'.
> Every single filename has extension='.hdf' except for one file which has
> an '.hdf5' extension. When i do (and yes, this is pasted):
> for filename in files:
> if (any(filename.endswith(x) for x in extensions)):
> print filename

I was unable to run that code:

$ cat testit.py

for filename in files:
if (any(filename.endswith(x) for x in extensions)):
print filename

$ python testit.py

Traceback (most recent call last):
  File "testit.py", line 1, in 
for filename in files:
NameError: name 'files' is not defined

> However, it will print all the files in list 'files' (that is all
> files with file extension '.hdf'). My question is why it doesn't just
> print the filename with extensions '.hdf5'?

Dunno.  You didn't provide enough information for us to answer your
question: the code you posted won't run and don't tell us what values
you're using for any of the variables.

Here's a piece of runnable code that I think does what you want:

$ cat testit.py
files = ["foo.bar", "foo.baz", "foo.bax"]
extensions = [".baz",".spam",".eggs"]

for filename in files:
if (any(filename.endswith(x) for x in extensions)):
print filename

$ python testit.py
foo.baz

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


making a class callable

2011-03-03 Thread dude
I've been struggling with getting my class to behave the way I want
it.

I have python module called ohYeah.py, defined as follows...
#File Begin
class foo:

def __init__(self, arg1):
print arg1
self.ohYeah = arg1

def whatwhat(self):
return self.ohYeah
#EOF

My goal is to be able to instantiate the class foo from another python
module, like so:

# Example Usage
f = foo("wow")
j = foo("amazing")
f.whatwhat()
wow
j.whatwhat()
amazing
#

However, I always get the "module not callable" error.  After entering
a "def __call__" method in class foo, still get the same problem.  Can
someone please point me in the right direction for being able to
achieve the Example Usage above?  I'm sure there is something trivial
I'm missing, but after digging around online for a day, I couldn't
find the missing piece.  Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Maximum post data length

2011-03-03 Thread Tim Johnson
I am currently using python 2.6.
For years I have used my own cgilib module which in turn uses the
stand python cgi library module.

The implementation is : 
self.form = cgi.FieldStorage(keep_blank_values=1)

I'm looking for an approach that would enable both client- and
server-side validation without duplication or writing additional
scripting.

Here's one approach I am considering:
The form holds a hidden field with a "magic" name that can be read
both from the DOM on the client side and from the cgilib module on the
server side. The value for the field would be a json structure that
would have as the upper-level keys field names and values would be
in turn be json-like (dictionary) values.
Example 
 etc 

The kicker might be that I have one series of forms that have
hundreds of elements. I could end up with the value of
`validator.descriptors' being thousands of bytes long.

:)And don't bother to tell me that forms that large are nuts, you'd
be preaching to the long converted.

Does anyone know if the cgi module might choke on the size of a 
POST'ed field OR the total length of the posted form data?
POST method only.

And that is plan A (I have plans B and C)
Thanks
-- 
Tim 
tim at johnsons-web.com or akwebsoft.com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about endswith()

2011-03-03 Thread Ethan Furman

Matt Funk wrote:

Hi,
i have a list of files, some of which end with .hdf and one of them end
with hdf5. I want to filter the hdf5 file. Thereforei set extensions: hdf5
I try to filter as below:

>

-->if (any(filename.endswith(x) for x in extensions)):


What is extensions?  A string or a tuple?  I'm guessing a string, 
because then you're looking at:


--> filename.endswith(x) for x in 'hdf5'

which is the same as

--> filename.endswith('h') or filename.endswith('d') or
filename.endswith('f') or filename.endswith('5')

and then both .hdf and .hdf5 files will get matched.

Try making extensions a tuple.

Hope this helps, but if it doesn't, follow Grant's advice.

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


Re: question about endswith()

2011-03-03 Thread Matt Funk
Hi Grant,
first of all sorry for the many typos in my previous email.

To clarify, I have a python list full of file names called 'files'.
Every single filename has extension='.hdf' except for one file which has
an '.hdf5' extension. When i do (and yes, this is pasted):
for filename in files:
if (any(filename.endswith(x) for x in extensions)):
print filename

However, it will print all the files in list 'files' (that is all files
with file extension '.hdf'). My question is why it doesn't just print
the filename with extensions '.hdf5'?

thanks
matt

On 3/3/2011 4:50 PM, Grant Edwards wrote:
> On 2011-03-03, Matt Funk  wrote:
>
>> i have a list of files, some of which end with .hdf and one of them end
>> with hdf5. I want to filter the hdf5 file. Thereforei set extensions: hdf5
>> I try to filter as below:
>> if (any(filename.endswith(x) for x in extensions)):
>>
>> The problem is that i let's all files though rather than just the hdf5
>> file. Is there anything i am doing wrong?
> Yes, you are doing something wrong.
>
> But, in order for somebody to tell you what you're doing wrong, you'll
> have to post some actual, runnable code and tell us 1) what you
> expect it to do, 2) what you see it do.
>
> IMPORTANT: Do _not_ retype code, input or output into your posting. 
>Cut/paste both code and input/output into your posting.
>

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


Re: question about endswith()

2011-03-03 Thread Grant Edwards
On 2011-03-03, Matt Funk  wrote:

> i have a list of files, some of which end with .hdf and one of them end
> with hdf5. I want to filter the hdf5 file. Thereforei set extensions: hdf5
> I try to filter as below:
> if (any(filename.endswith(x) for x in extensions)):
>
> The problem is that i let's all files though rather than just the hdf5
> file. Is there anything i am doing wrong?

Yes, you are doing something wrong.

But, in order for somebody to tell you what you're doing wrong, you'll
have to post some actual, runnable code and tell us 1) what you
expect it to do, 2) what you see it do.

IMPORTANT: Do _not_ retype code, input or output into your posting. 
   Cut/paste both code and input/output into your posting.

-- 
Grant Edwards   grant.b.edwardsYow! How's it going in
  at   those MODULAR LOVE UNITS??
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2to3 and maketrans

2011-03-03 Thread Martin v. Loewis
Am 03.03.2011 07:58, schrieb Gregory Ewing:
> What is the recommended way to write code for 2.7 using
> maketrans() on text strings in such a way that it will
> convert correctly using 2to3?

That depends on how you chose to represent text in 2.7.
The recommended way for that (also with 3.x in mind)
is that you should use Unicode strings to represent text.

Now, unicode strings support translation tables mapping
Unicode ordinals to Unicode strings in both 2.x and 3.x,
so I suggest you just don't use maketrans at all.

To give an example,

print u"hallo".translate({97:u'e'})

works fine in 2.x, and will work fine in 3.x when put
through 2to3 (which will convert the print and the unicode
literals).

If you chose to represent strings as bytes in 2.x, the
answer will be different.

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


Re: Communicating from Flash to Python

2011-03-03 Thread Corey Richardson
On 03/03/2011 05:01 PM, Victor Subervi wrote:
> Hi;
> I have an AS3 script that is supposed to communicate with a python script
> and I don't think it is. The python script is to email.

How does Flash communicate with Python? Only thing I found at all was
Flash interfacing with a PHP script via a webpage, so are you trying to
use Python with the CGI to do this? If so, check out the actionscript
thing at [1] and just implement the server page with Python CGI instead
of PHP.

[1]
http://www.actionscript.org/resources/articles/82/1/Send-Email-via-Flash-and-PHP/Page1.html
-- 
Corey Richardson
-- 
http://mail.python.org/mailman/listinfo/python-list


question about endswith()

2011-03-03 Thread Matt Funk
Hi,
i have a list of files, some of which end with .hdf and one of them end
with hdf5. I want to filter the hdf5 file. Thereforei set extensions: hdf5
I try to filter as below:
if (any(filename.endswith(x) for x in extensions)):

The problem is that i let's all files though rather than just the hdf5
file. Is there anything i am doing wrong?

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


RE: subprocess running ant

2011-03-03 Thread Nobody
On Thu, 03 Mar 2011 13:27:34 -0500, Thom Hehl wrote:

> Actually, I just figured out the issue is that I need to run ant.bat
> instead of just ant. :(

Add shell=True to the Popen() call.


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


Communicating from Flash to Python

2011-03-03 Thread Victor Subervi
Hi;
I have an AS3 script that is supposed to communicate with a python script
and I don't think it is. The python script is to email. How can I
trouble-shoot this?
Beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pure python standard library and License

2011-03-03 Thread Terry Reedy

On 3/3/2011 11:39 AM, Markus Schaber wrote:

Hi,

We want to include IronPython in one of our products, including the pure
Python part of the python standard library. It seems that the IronPython
installer packagers simply copied the pure python part of the standard
library (the directory tree of .py files which is installed by cPython
and IronPython installers in the lib/ subdirectory) from cPython.

Now, this directory comes with a LICENSE.txt which contains a
conglomerate of several licenses, and for us (and our Lawyers), it is
not entirely clear which part of the license applies to the pure Python
part of the standard library, and which applies to other files (like the
Berkeley Database license).

Our current understanding is that all the .py files which do not contain
any explicit mentioning of a license are covered by the Python licenses
(the first three licenses of the LICENSE.txt), and that e. G. the
Berkeley Database License only applies to the bsddb module which is
implemented in C, and thus is currently neither included with nor usable
from IronPython.

Is there anyone who can confirm this interpretation?


Your interpretation seems reasonable, but only a paid lawyer (or 
ultimately a judge) can 'confirm' a legal interpretation. Sorry, we 
programmers generally hate the system.


That said, I suspect you or your lawyers are worrying too much. None of 
the licensors are looking to play gotcha and I do not know that there 
have been any court cases involving Python.



Maybe the LICENSE.txt should clarify somehow which of the licenses
applies to which part of the software.


I presume you are using some version of Python 2. In 3.2, the license 
file has the four general licenses (CWI, CNRI, BeOpen, PSF) in one 
section and 16 specific licenses related to various library modules 
(each identified) in another. There is no BSD license because bsddb in 
no longer included.


You could take the disappearance of the BD licence with the 
disappearance of the bsddb module as confirmation of your hypothesis;-).


--
Terry Jan Reedy

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


Re: 2to3 and maketrans

2011-03-03 Thread Dan Stromberg
On Wed, Mar 2, 2011 at 10:58 PM, Gregory Ewing
wrote:

> What is the recommended way to write code for 2.7 using
> maketrans() on text strings in such a way that it will
> convert correctly using 2to3?
>
> There seems to be two versions of maketrans in 3.x, one
> for text and one for bytes. Code that references
> string.maketrans ends up with the one for bytes, which
> is not what I want. But I can't write str.maketrans,
> because that doesn't exist in 2.x.
>
> So what am I supposed to do?
>

I've not tried maketrans, but I've been having some luck writing Python that
works, unchanged (not even run through 2to3), on both CPython 2.x (2.5, 2.6,
2.7), CPython 3.x (3.1, 3.2) and pypy (1.4.1 which does Python 2.5 and a
recent trunk that pretty much does Python 2.7).

For strings vs bytes, I've been finding that just using os.read and os.write
helps; on 2.x they do str, on 3.x they do bytes.

You can usually then just pass things around as str or bytes, unchanged,
depending on what your runtime prefers.  If you need an ordinal, you can use
isinstance and take the ord when you have a str of length 1 - otherwise
you've already got an ordinal.

The other main sticky point for str vs bytes this way is sometimes I need a
null string to express things nicely, but that can be done with the
following in 3.x:

''.encode('utf-8')

...without choking a 2.x parser (b'' blows up most, if not all, 2.x
parsers), but it's probably best to wrap that up in a scope (module?) of its
own rather than scattering it throughout your code.

Also, and this was a little surprising to me, if you build your modules with
Cython, you may find that you conveniently get C extension modules for 2.x
and 3.x from the same Cython code, with just a pair of recompiles (one from
Cython to C, one from C to binary) for each CPython you need to support.
And the performance benefit of Cython appears to be even greater on 3.x than
it was on 2.x (at least in my minimal testing).  There's a branch of Cython
in testing now that does generators, BTW, which has been working well for
me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking against NULL will be eliminated?

2011-03-03 Thread Terry Reedy

On 3/3/2011 10:39 AM, Jean-Paul Calderone wrote:


C and C++ have standards, and the standards describe what they don't
define.

Python has implementations.


Python also has standards, the language and library manuals.



The defined behavior is whatever the implementation does.


No, the defined behavior for a particular version of Python
is whatever the manuals for that version say.
Ambiguities are generally removed as discovered.
Some of the ambiguites have been pointed out by authors
of alternate implementations.

The docs have a few notes as to what is not defined or
what is behavior spedific to CPython, and therefore not
part of the *language* definition.
The intent is to have a rather complete definition.

Discrepancies between doc and implementation are bugs.
The usual resolution is a behavior change.


 Until someone changes it to do something else.


At which point the change is documented with a note as to when the 
change was made. But this is never intentionally done as casually as you 
imply. Contributions to improve test coverage so as to prevent 
unintended changes are welcome.


--
Terry Jan Reedy

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


Re: OT: Code Examples

2011-03-03 Thread Emile van Sebille

On 3/1/2011 3:59 PM Chris Jones said...

On Tue, Mar 01, 2011 at 12:03:02PM EST, Emile van Sebille wrote:

On 3/1/2011 12:43 AM Erik de Castro Lopo said...



Why Python?


For me?  Because it's executable pseudocode


Not for nothing, Emile.. hey.. you could end up with pseudo bugs and
pseudo headaches ..



Ah -- that's why there's Pseudoephedrine...

:)



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


Re: help with regex matching multiple %e

2011-03-03 Thread Matt Funk
Thanks,
works great.

matt

On 3/3/2011 10:53 AM, MRAB wrote:
> On 03/03/2011 17:33, maf...@nmsu.edu wrote:
>> Hi,
>>
>> i have a line that looks something like:
>> 2.234e+04 3.456e+02 7.234e+07 1.543e+04: some description
>>
>> I would like to extract all the numbers. From the python website i
>> got the
>> following expression for matching what in c is %e (i.e. scientific
>> format):
>> (see http://docs.python.org/library/re.html)
>> [-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?
>> And when i apply the pattern (using extra parenthesis around the whole
>> expression) it does match the first number in the line.
>>
>> Is there any way to repeat this pattern to get me all the numbers in the
>> line?
>> I though the following might work, but i doesn't:
>> ([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?){numToRepeat)
>>
> You're forgetting that the numbers are separated by a space.
>
>> Or will i have to split the line first, then iterate and the apply
>> the match?
>>
>> Any help is greatly appreciated.
>>
> Use re.findall to find all the matches.

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


Re: I'm happy with Python 2.5

2011-03-03 Thread Ian Kelly
On Sun, Feb 27, 2011 at 7:15 AM, n00m  wrote:
> http://www.spoj.pl/problems/TMUL/
>
> Python's "print a * b" gets Time Limit Exceeded.

If speed is the only thing you care about, then you can forget about
fretting over whether 2.5 or 3.1 is faster.  You're using the wrong
language to begin with.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess running ant

2011-03-03 Thread Chris Rebert
> From: MRAB
> On 03/03/2011 18:14, Thom Hehl wrote:
>> I am attempting to write a python script that will check out and build
>> our code, then deploy the executable. It will report any failures via
>> e-mail.
>>
>> To this end, I'm trying to run my ant build from inside of python. I
>> have tried the following:
>>
>> proc = subprocess.Popen(ant -version')
>>
>> proc = subprocess.Popen(call ant -version')
>>
>> These both generate:
>>
>> Traceback (most recent call last):
>> File "C:\Users\thom\Documents\workspace\autobuild\build.py", line 19,
> in
>> 
>> proc = subprocess.Popen('call ant -version')
>>
>> File "C:\Python32\lib\subprocess.py", line 736, in __init__
>> restore_signals, start_new_session)
>>
>> File "C:\Python32\lib\subprocess.py", line 946, in _execute_child
>> startupinfo)
>>
>> WindowsError: [Error 2] The system cannot find the file specified
>>
>> If I run python from the command prompt and generate this error, I
> turn
>> around immediately and run ant -version and it works fine, so it's not
> a
>> path issue.
>>
>> Please help?
>>
> Try passing the command line arguments as a list of strings:
>
>     proc = subprocess.Popen(['call', 'ant', '-version'])
>
> You might need to provide the full path of 'ant'.

On Thu, Mar 3, 2011 at 10:27 AM, Thom Hehl  wrote:
> Actually, I just figured out the issue is that I need to run ant.bat
> instead of just ant. :(
>
> This isn't going to work because I wanted to run something that would be
> system independent. So I found the runant.py and I'm trying to figure
> out how to call it.
>
> I tried import runant but it can't find the file. I tried reading the
> documentation, but it doesn't say how it builds the search path for
> imported items.

Yes it does:
http://docs.python.org/tutorial/modules.html#the-module-search-path
http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH

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


Re: subprocess running ant

2011-03-03 Thread Benjamin Kaplan
On Mar 3, 2011 1:19 PM, "Thom Hehl"  wrote:
>
> I am attempting to write a python script that will check out and build our
code, then deploy the executable. It will report any failures via e-mail.
>
>
>
> To this end, I’m trying to run my ant build from inside of python. I have
tried the following:
>
>
>
> proc = subprocess.Popen(ant -version')
>
> proc = subprocess.Popen(call ant -version')
>
>
>
> These both generate:
>
>
>
> Traceback (most recent call last):
>
>   File "C:\Users\thom\Documents\workspace\autobuild\build.py", line 19, in

>
> proc = subprocess.Popen('call ant -version')
>
>   File "C:\Python32\lib\subprocess.py", line 736, in __init__
>
> restore_signals, start_new_session)
>
>   File "C:\Python32\lib\subprocess.py", line 946, in _execute_child
>
> startupinfo)
>
> WindowsError: [Error 2] The system cannot find the file specified
>
>
>
> If I run python from the command prompt and generate this error, I turn
around immediately and run ant –version and it works fine, so it’s not a
path issue.
>
>
>
> Please help?
>
>

By default, suborocess just spawns a new processes. It does not go through
the shell, so you have no path. Try adding shell=true to the Popen call.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange occasional marshal error

2011-03-03 Thread Graham Stratton
On Mar 3, 6:04 pm, Guido van Rossum  wrote:
> This bug report doesn't mention the Python version nor the platform --
> it could in theory be a bug in the platform compiler or memory
> allocator.

I've seen the problem with 2.6 and 2.7, on RHEL 4 (possibly with a
custom kernel, I can't check at the moment).

> It would also be nice to provide the test program that
> reproduces the issue.

I'm working on trying to reproduce it without the proprietary code
that uses it, but so far haven't managed it. There are some custom C
extensions in the system where this is observed, but since the code is
single-threaded I don't think they can have any effect during
marshalling.

Thanks,

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


RE: subprocess running ant

2011-03-03 Thread Thom Hehl
Actually, I just figured out the issue is that I need to run ant.bat
instead of just ant. :(

This isn't going to work because I wanted to run something that would be
system independent. So I found the runant.py and I'm trying to figure
out how to call it.

I tried import runant but it can't find the file. I tried reading the
documentation, but it doesn't say how it builds the search path for
imported items.

Can someone tell me how I can run this script?

Thanks.

-Original Message-
From: python-list-bounces+thom=pointsix@python.org
[mailto:python-list-bounces+thom=pointsix@python.org] On Behalf Of
MRAB
Sent: Thursday, March 03, 2011 1:25 PM
To: python-list@python.org
Subject: Re: subprocess running ant

On 03/03/2011 18:14, Thom Hehl wrote:
> I am attempting to write a python script that will check out and build
> our code, then deploy the executable. It will report any failures via
> e-mail.
>
> To this end, I'm trying to run my ant build from inside of python. I
> have tried the following:
>
> proc = subprocess.Popen(ant -version')
>
> proc = subprocess.Popen(call ant -version')
>
> These both generate:
>
> Traceback (most recent call last):
>
> File "C:\Users\thom\Documents\workspace\autobuild\build.py", line 19,
in
> 
>
> proc = subprocess.Popen('call ant -version')
>
> File "C:\Python32\lib\subprocess.py", line 736, in __init__
>
> restore_signals, start_new_session)
>
> File "C:\Python32\lib\subprocess.py", line 946, in _execute_child
>
> startupinfo)
>
> WindowsError: [Error 2] The system cannot find the file specified
>
> If I run python from the command prompt and generate this error, I
turn
> around immediately and run ant -version and it works fine, so it's not
a
> path issue.
>
> Please help?
>
Try passing the command line arguments as a list of strings:

 proc = subprocess.Popen(['call', 'ant', '-version'])

You might need to provide the full path of 'ant'.
-- 
http://mail.python.org/mailman/listinfo/python-list

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


Re: subprocess running ant

2011-03-03 Thread MRAB

On 03/03/2011 18:14, Thom Hehl wrote:

I am attempting to write a python script that will check out and build
our code, then deploy the executable. It will report any failures via
e-mail.

To this end, I’m trying to run my ant build from inside of python. I
have tried the following:

proc = subprocess.Popen(ant -version')

proc = subprocess.Popen(call ant -version')

These both generate:

Traceback (most recent call last):

File "C:\Users\thom\Documents\workspace\autobuild\build.py", line 19, in


proc = subprocess.Popen('call ant -version')

File "C:\Python32\lib\subprocess.py", line 736, in __init__

restore_signals, start_new_session)

File "C:\Python32\lib\subprocess.py", line 946, in _execute_child

startupinfo)

WindowsError: [Error 2] The system cannot find the file specified

If I run python from the command prompt and generate this error, I turn
around immediately and run ant –version and it works fine, so it’s not a
path issue.

Please help?


Try passing the command line arguments as a list of strings:

proc = subprocess.Popen(['call', 'ant', '-version'])

You might need to provide the full path of 'ant'.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Playing WAV file with Python

2011-03-03 Thread Steven Howe

On 03/03/2011 01:32 AM, VGNU Linux wrote:



On Thu, Mar 3, 2011 at 1:54 PM, Chris Rebert > wrote:


On Thu, Mar 3, 2011 at 12:17 AM, VGNU Linux mailto:vgnuli...@gmail.com>> wrote:
> On Thu, Mar 3, 2011 at 1:26 PM, Chris Rebert mailto:c...@rebertia.com>> wrote:
>> On Tue, Mar 1, 2011 at 11:47 PM, VGNU Linux
mailto:vgnuli...@gmail.com>> wrote:
>> > How can I play WAV file in python without OS(like
Linux/Windows/MAC) on
>> > a
>> > device ?
>> > On Google I found lot of different solution but related to
OS's like
>> > winsound, ossaudiodev etc which are not useful.
>>
>> Do you mean you want your code to be cross-platform, or what?
>> "Without OS" is rather vague. What are you trying to accomplish?
>
> I will be using WAVE on embedded devices, and the device will
not have any
> OS's. So I am looking for modules which can play WAVE sound without
> underlying OS.

What implementation of Python are you going to use? I don't personally
know of any that can run on the "bare metal" without an OS.


I am planning to use python-on-a-chip(PyMite) which can be run without 
an OS therefore I am looking for a module/library which can play sound 
files.



Cheers,
Chris


As you wont be calling the OS via subprocess, which is about the only 
way to fire up some connect to the sound system, you probably should be 
talking about the pymite issues on the pymite group over at google about 
drivers (i.e. sound drivers), what data types (wav, mp3, ogg) they will 
take and how to pass data to a driver. The


nbed.AnalogOut looks intriguing. Perhaps you can spool a wav file to a port, 
attach the
analog out to an external amplifier.

http://groups.google.com/group/python-on-a-chip?pli=1

Also, perhaps you should be looking atArduino and audio projects.

http://www.ladyada.net/make/waveshield/




Good luck,

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


subprocess running ant

2011-03-03 Thread Thom Hehl
I am attempting to write a python script that will check out and build
our code, then deploy the executable. It will report any failures via
e-mail.

 

To this end, I'm trying to run my ant build from inside of python. I
have tried the following:

 

proc = subprocess.Popen(ant -version')

proc = subprocess.Popen(call ant -version')

 

These both generate:

 

Traceback (most recent call last):

  File "C:\Users\thom\Documents\workspace\autobuild\build.py", line 19,
in 

proc = subprocess.Popen('call ant -version')

  File "C:\Python32\lib\subprocess.py", line 736, in __init__

restore_signals, start_new_session)

  File "C:\Python32\lib\subprocess.py", line 946, in _execute_child

startupinfo)

WindowsError: [Error 2] The system cannot find the file specified

 

If I run python from the command prompt and generate this error, I turn
around immediately and run ant -version and it works fine, so it's not a
path issue.

 

Please help?

 

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


Re: [Python-Dev] Strange occasional marshal error

2011-03-03 Thread Guido van Rossum
On Thu, Mar 3, 2011 at 9:40 AM, MRAB  wrote:
> On 03/03/2011 15:09, Graham Stratton wrote:
>>
>> On Mar 2, 3:01 pm, Graham Stratton  wrote:
>>>
>>> We are using marshal for serialising objects before distributing them
>>> around the cluster, and extremely occasionally a corrupted marshal is
>>> produced. The current workaround is to serialise everything twice and
>>> check that the serialisations are the same. On the rare occasions that
>>> they are not, I have dumped the files for comparison. It turns out
>>> that there are a few positions within the serialisation where
>>> corruption tends to occur (these positions seem to be independent of
>>> the data of the size of the complete serialisation). These are:
>>>
>>> 4 bytes starting at 548867 (0x86003)
>>> 4 bytes starting at 4398083 (0x431c03)
>>> 4 bytes starting at 17595395 (0x10c7c03)
>>> 4 bytes starting at 19794819 (0x12e0b83)
>>> 4 bytes starting at 22269171 (0x153ccf3)
>>> 2 bytes starting at 25052819 (0x17e4693)
>>> 3 bytes starting at 28184419 (0x1ae0f63)
>>
>> I modified marshal.c to print when it extends the string used to write
>> the marshal to. This gave me these results:
>>
> s = marshal.dumps(list((i, str(i)) for i in range(140)))
>>
>> Resizing string from 50 to 1124 bytes
>> Resizing string from 1124 to 3272 bytes
>> Resizing string from 3272 to 7568 bytes
>> Resizing string from 7568 to 16160 bytes
>> Resizing string from 16160 to 33344 bytes
>> Resizing string from 33344 to 67712 bytes
>> Resizing string from 67712 to 136448 bytes
>> Resizing string from 136448 to 273920 bytes
>> Resizing string from 273920 to 548864 bytes
>> Resizing string from 548864 to 1098752 bytes
>> Resizing string from 1098752 to 2198528 bytes
>> Resizing string from 2198528 to 4398080 bytes
>> Resizing string from 4398080 to 8797184 bytes
>> Resizing string from 8797184 to 17595392 bytes
>> Resizing string from 17595392 to 19794816 bytes
>> Resizing string from 19794816 to 22269168 bytes
>> Resizing string from 22269168 to 25052814 bytes
>> Resizing string from 25052814 to 28184415 bytes
>> Resizing string from 28184415 to 31707466 bytes
>>
>> Every corruption point occurs exactly three bytes above an extension
>> point (rounded to the nearest word for the last two). This clearly
>> isn't a coincidence, but I can't see where there could be a problem.
>> I'd be grateful for any pointers.

This bug report doesn't mention the Python version nor the platform --
it could in theory be a bug in the platform compiler or memory
allocator. It would also be nice to provide the test program that
reproduces the issue. It would also be useful to start tracking it in
the issue tracker at bugs.python.org

Assuming it's 3.2, I would audit _PyBytes_Resize() and whatever it
uses -- if your hunch is right and there is a problem with resizing
that's where it's done.

> I haven't found the cause, but I have found something else I'm
> suspicious of in the source for Python 3.2.
>
> In marshal.c there's a function "w_object", and within that function is
> this:
>
>    else if (PyAnySet_CheckExact(v)) {
>        PyObject *value, *it;
>
>        if (PyObject_TypeCheck(v, &PySet_Type))
>            w_byte(TYPE_SET, p);
>        else
>            w_byte(TYPE_FROZENSET, p);
>
> "w_byte" is a macro which includes an if-statement, not a function.
> Doesn't it need some braces? (There's are braces in the other places
> they're needed.)

That macro looks fine to me; looking at the definition of w_byte() it
has matched if/else clauses:

#define w_byte(c, p) if (((p)->fp)) putc((c), (p)->fp); \
  else if ((p)->ptr != (p)->end) *(p)->ptr++ = (c); \
   else w_more(c, p)

Although traditionally, just to be sure, we've enclosed similar macros
inside do { ... } while (0). Also it would be nice to call out its
macro-status by renaming it to W_BYTE -- I suppose at one point in the
past it was a plain function...

-- 
--Guido van Rossum (python.org/~guido)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help with regex matching multiple %e

2011-03-03 Thread MRAB

On 03/03/2011 17:33, maf...@nmsu.edu wrote:

Hi,

i have a line that looks something like:
2.234e+04 3.456e+02 7.234e+07 1.543e+04: some description

I would like to extract all the numbers. From the python website i got the
following expression for matching what in c is %e (i.e. scientific
format):
(see http://docs.python.org/library/re.html)
[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?
And when i apply the pattern (using extra parenthesis around the whole
expression) it does match the first number in the line.

Is there any way to repeat this pattern to get me all the numbers in the
line?
I though the following might work, but i doesn't:
([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?){numToRepeat)


You're forgetting that the numbers are separated by a space.


Or will i have to split the line first, then iterate and the apply the match?

Any help is greatly appreciated.


Use re.findall to find all the matches.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Strange occasional marshal error

2011-03-03 Thread MRAB

On 03/03/2011 15:09, Graham Stratton wrote:

On Mar 2, 3:01 pm, Graham Stratton  wrote:

We are using marshal for serialising objects before distributing them
around the cluster, and extremely occasionally a corrupted marshal is
produced. The current workaround is to serialise everything twice and
check that the serialisations are the same. On the rare occasions that
they are not, I have dumped the files for comparison. It turns out
that there are a few positions within the serialisation where
corruption tends to occur (these positions seem to be independent of
the data of the size of the complete serialisation). These are:

4 bytes starting at 548867 (0x86003)
4 bytes starting at 4398083 (0x431c03)
4 bytes starting at 17595395 (0x10c7c03)
4 bytes starting at 19794819 (0x12e0b83)
4 bytes starting at 22269171 (0x153ccf3)
2 bytes starting at 25052819 (0x17e4693)
3 bytes starting at 28184419 (0x1ae0f63)


I modified marshal.c to print when it extends the string used to write
the marshal to. This gave me these results:


s = marshal.dumps(list((i, str(i)) for i in range(140)))

Resizing string from 50 to 1124 bytes
Resizing string from 1124 to 3272 bytes
Resizing string from 3272 to 7568 bytes
Resizing string from 7568 to 16160 bytes
Resizing string from 16160 to 33344 bytes
Resizing string from 33344 to 67712 bytes
Resizing string from 67712 to 136448 bytes
Resizing string from 136448 to 273920 bytes
Resizing string from 273920 to 548864 bytes
Resizing string from 548864 to 1098752 bytes
Resizing string from 1098752 to 2198528 bytes
Resizing string from 2198528 to 4398080 bytes
Resizing string from 4398080 to 8797184 bytes
Resizing string from 8797184 to 17595392 bytes
Resizing string from 17595392 to 19794816 bytes
Resizing string from 19794816 to 22269168 bytes
Resizing string from 22269168 to 25052814 bytes
Resizing string from 25052814 to 28184415 bytes
Resizing string from 28184415 to 31707466 bytes

Every corruption point occurs exactly three bytes above an extension
point (rounded to the nearest word for the last two). This clearly
isn't a coincidence, but I can't see where there could be a problem.
I'd be grateful for any pointers.


I haven't found the cause, but I have found something else I'm
suspicious of in the source for Python 3.2.

In marshal.c there's a function "w_object", and within that function is
this:

else if (PyAnySet_CheckExact(v)) {
PyObject *value, *it;

if (PyObject_TypeCheck(v, &PySet_Type))
w_byte(TYPE_SET, p);
else
w_byte(TYPE_FROZENSET, p);

"w_byte" is a macro which includes an if-statement, not a function.
Doesn't it need some braces? (There's are braces in the other places
they're needed.)
--
http://mail.python.org/mailman/listinfo/python-list


help with regex matching multiple %e

2011-03-03 Thread mafunk
Hi,

i have a line that looks something like:
2.234e+04 3.456e+02 7.234e+07 1.543e+04: some description

I would like to extract all the numbers. From the python website i got the
following expression for matching what in c is %e (i.e. scientific
format):
(see http://docs.python.org/library/re.html)
[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?
And when i apply the pattern (using extra parenthesis around the whole
expression) it does match the first number in the line.

Is there any way to repeat this pattern to get me all the numbers in the
line?
I though the following might work, but i doesn't:
([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?){numToRepeat)

Or will i have to split the line first, then iterate and the apply the match?

Any help is greatly appreciated.

thanks
matt

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


Re: Callbacks on program exiting/aborting

2011-03-03 Thread Grant Edwards
On 2011-03-03, Pengcheng Chen  wrote:

> What callback mechanisms can we use in Python? We have some device
> drivers are in Python and sometimes they crash. I'd like to do some
> cleanup before program abort/crash. Any suggestions?

http://docs.python.org/library/atexit.html

-- 
Grant Edwards   grant.b.edwardsYow! Yes, but will I
  at   see the EASTER BUNNY in
  gmail.comskintight leather at an
   IRON MAIDEN concert?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I'm happy with Python 2.5

2011-03-03 Thread Peter Parker

On 02/27/2011 09:27 AM, Tom Zych wrote:

n00m wrote:

Am I turmoiling your wishful thinking?
You may nourish it till the end of time.


Let us cease to nourish those fabled ones who dwell under bridges.



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


Pure python standard library and License

2011-03-03 Thread Markus Schaber
Hi,

 

We want to include IronPython in one of our products, including the pure
Python part of the python standard library. It seems that the IronPython
installer packagers simply copied the pure python part of the standard
library (the directory tree of .py files which is installed by cPython
and IronPython installers in the lib/ subdirectory) from cPython.

 

Now, this directory comes with a LICENSE.txt which contains a
conglomerate of several licenses, and for us (and our Lawyers), it is
not entirely clear which part of the license applies to the pure Python
part of the standard library, and which applies to other files (like the
Berkeley Database license).

 

Our current understanding is that all the .py files which do not contain
any explicit mentioning of a license are covered by the Python licenses
(the first three licenses of the LICENSE.txt), and that e. G. the
Berkeley Database License only applies to the bsddb module which is
implemented in C, and thus is currently neither included with nor usable
from IronPython.

 

Is there anyone who can confirm this interpretation?

 

Maybe the LICENSE.txt should clarify somehow which of the licenses
applies to which part of the software.

 

Best regards

Markus Schaber

___

We software Automation.

3S-Smart Software Solutions GmbH
Markus Schaber | Developer
Memminger Str. 151 | 87439 Kempten | Germany | Tel. +49-831-54031-0 |
Fax +49-831-54031-50

Email: m.scha...@3s-software.com   |
Web: http://www.3s-software.com  
CoDeSys internet forum: http://forum.3s-software.com
 
Download CoDeSys sample projects:
http://www.3s-software.com/index.shtml?sample_projects
 

Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner |
Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915 

 

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


Re: having both dynamic and static variables

2011-03-03 Thread Rafe Kettler
> Finally, Python 3 introduced type annotations, which are currently a
> feature looking for a reason.

By type annotations, do you mean function annotations (see PEP 3107,
http://www.python.org/dev/peps/pep-3107/)? Or is this some other
feature that I'm unaware of?

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


Callbacks on program exiting/aborting

2011-03-03 Thread Pengcheng Chen
Dear folks,

What callback mechanisms can we use in Python? We have some device drivers are 
in Python and sometimes they crash. I'd like to do some cleanup before program 
abort/crash. Any suggestions?

Thanks so much!
Pengcheng
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking against NULL will be eliminated?

2011-03-03 Thread Neil Cerutti
On 2011-03-03, Jean-Paul Calderone  wrote:
> On Mar 3, 8:16?am, Neil Cerutti  wrote:
>> On 2011-03-03, Tom Zych  wrote:
>>
>> > Carl Banks wrote:
>> >> Perl works deterministically and reliably. ?In fact, pretty much every
>> >> language works deterministically and reliably. ?Total non-argument.
>>
>> > Well, yes. I think the real issue is, how many surprises are
>> > waiting to pounce on the unwary developer. C is deterministic
>> > and reliable, but full of surprises.
>>
>> Point of order, for expediency, C and C++ both include lots and
>> lots of indeterminate stuff. A piece of specific C code can be
>> totally deterministic, but the language is full of undefined
>> corners.
>>
>> > Python is generally low in surprises. Using "if "
>> > is one place where you do have to think about unintended
>> > consequences.
>>
>> Python eschews undefined behavior.
>
> C and C++ have standards, and the standards describe what they
> don't define.
>
> Python has implementations.  The defined behavior is whatever
> the implementation does.  Until someone changes it to do
> something else.
>
> It's not much of a comparison.

In addition, you can tap into undefined behavior in Python, as
well, it's just harder. So what I should have said is that the
determinacy of a language is a degree, not an absolute. C is less
determinate than Python by design.

-- 
Neil Cerutti
"What we really can learn from this is that bad accounting can yield
immense imaginary profits." --Klepsacovic
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking against NULL will be eliminated?

2011-03-03 Thread Jean-Paul Calderone
On Mar 3, 8:16 am, Neil Cerutti  wrote:
> On 2011-03-03, Tom Zych  wrote:
>
> > Carl Banks wrote:
> >> Perl works deterministically and reliably.  In fact, pretty much every
> >> language works deterministically and reliably.  Total non-argument.
>
> > Well, yes. I think the real issue is, how many surprises are
> > waiting to pounce on the unwary developer. C is deterministic
> > and reliable, but full of surprises.
>
> Point of order, for expediency, C and C++ both include lots and
> lots of indeterminate stuff. A piece of specific C code can be
> totally deterministic, but the language is full of undefined
> corners.
>
> > Python is generally low in surprises. Using "if "
> > is one place where you do have to think about unintended
> > consequences.
>
> Python eschews undefined behavior.
>

C and C++ have standards, and the standards describe what they don't
define.

Python has implementations.  The defined behavior is whatever the
implementation does.  Until someone changes it to do something else.

It's not much of a comparison.

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


Re: Strange occasional marshal error

2011-03-03 Thread Tom Zych
On Thu, 03 Mar 2011 07:09 -0800, "Graham Stratton"
 wrote:
> Every corruption point occurs exactly three bytes above an extension
> point (rounded to the nearest word for the last two). This clearly
> isn't a coincidence, but I can't see where there could be a problem.
> I'd be grateful for any pointers.

The intermittency sounds like a race condition, doesn't it? It might
be worthwhile to look into the call that's extending the string and
see if it could affect other data. Maybe objects are getting shuffled
around? Don't put too much stock in this, I'm just speculating based
on a bug I had in a C program years ago. I have no idea how CPython
handles these things.

-- 
Tom Zych / freethin...@pobox.com
Quidquid latine dictum sit, altum viditur.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing numeric ranges

2011-03-03 Thread Seldon

On 02/25/2011 10:27 AM, Seldon wrote:

Hi all,
I have to convert integer ranges expressed in a popular "compact"
notation (e.g. 2, 5-7, 20-22, 41) to a the actual set of numbers (i.e.
2,5,7,20,21,22,41).

Is there any library for doing such kind of things or I have to write it
from scratch ?



In addition to the solutions given by others (thanks!), just for 
reference I paste below what I have written to solve my little problem: 
 comments are welcome !


---

# Define exceptions
class MalformedRangeListError(Exception): pass # raised if a string is\ 
not a valid numeric range list



def num_range_list_to_num_set(range_list, sep=','):
"""
Convert a numeric list of ranges to the set of numbers it represents.

@argument
range_list: a numeric list of ranges, as a string of values 
separated by `sep` (e.g. '1, 3-5, 7')


@argument:
sep: a string used as a separator in `range_list` (e.g. ',', ' ')

@return: the set represented by `range_list` (i.e. (1,3,4,5,7)).

"""

# if given an empty range list, the function should return the\ 
empty set

if range_list == '': return set()

import re
int_or_range = r'^([1-9]\d*)(?:-([1-9]\d*))?$' # match a single 
decimal number or a range of decimal numbers

r = re.compile(int_or_range)

# split the input string in a list of numbers and numeric ranges
l = range_list.split(sep)
result = set()
for s in l:
# check if the current string is a number or a valid numeric range
m = r.match(s)
if not m:
raise MalformedRangeListError, "Input string is not a valid 
numeric range-list"
matches = len(filter(lambda x:x, m.groups())) # how many 
regexp\ groups matched

first = m.group(1)
if matches == 2: # it's a range
if m.group(1) > m.group(2):
raise MalformedRangeListError, "Input string is not a\ 
valid numeric range-list"

last = m.group(2)
result.update(range(int(first), int(last)+1)) # current\ 
item is a range, so add the full numeric range to the result set

elif matches == 1: # it's a number
result.add(int(first)) # current item is a number, so just\ 
add it to the result set

else:
raise MalformedRangeListError, "Input string is not a valid 
numeric range-list"

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


Re: Strange occasional marshal error

2011-03-03 Thread Graham Stratton
On Mar 2, 3:01 pm, Graham Stratton  wrote:
> We are using marshal for serialising objects before distributing them
> around the cluster, and extremely occasionally a corrupted marshal is
> produced. The current workaround is to serialise everything twice and
> check that the serialisations are the same. On the rare occasions that
> they are not, I have dumped the files for comparison. It turns out
> that there are a few positions within the serialisation where
> corruption tends to occur (these positions seem to be independent of
> the data of the size of the complete serialisation). These are:
>
> 4 bytes starting at 548867 (0x86003)
> 4 bytes starting at 4398083 (0x431c03)
> 4 bytes starting at 17595395 (0x10c7c03)
> 4 bytes starting at 19794819 (0x12e0b83)
> 4 bytes starting at 22269171 (0x153ccf3)
> 2 bytes starting at 25052819 (0x17e4693)
> 3 bytes starting at 28184419 (0x1ae0f63)

I modified marshal.c to print when it extends the string used to write
the marshal to. This gave me these results:

>>> s = marshal.dumps(list((i, str(i)) for i in range(140)))
Resizing string from 50 to 1124 bytes
Resizing string from 1124 to 3272 bytes
Resizing string from 3272 to 7568 bytes
Resizing string from 7568 to 16160 bytes
Resizing string from 16160 to 33344 bytes
Resizing string from 33344 to 67712 bytes
Resizing string from 67712 to 136448 bytes
Resizing string from 136448 to 273920 bytes
Resizing string from 273920 to 548864 bytes
Resizing string from 548864 to 1098752 bytes
Resizing string from 1098752 to 2198528 bytes
Resizing string from 2198528 to 4398080 bytes
Resizing string from 4398080 to 8797184 bytes
Resizing string from 8797184 to 17595392 bytes
Resizing string from 17595392 to 19794816 bytes
Resizing string from 19794816 to 22269168 bytes
Resizing string from 22269168 to 25052814 bytes
Resizing string from 25052814 to 28184415 bytes
Resizing string from 28184415 to 31707466 bytes

Every corruption point occurs exactly three bytes above an extension
point (rounded to the nearest word for the last two). This clearly
isn't a coincidence, but I can't see where there could be a problem.
I'd be grateful for any pointers.

Thanks,

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


Re: having both dynamic and static variables

2011-03-03 Thread Westley Martínez
On Wed, 2011-03-02 at 19:45 -0800, Yingjie Lan wrote:
> Hi everyone,
> 
> Variables in Python are resolved dynamically at runtime, which comes at a 
> performance cost. However, a lot of times we don't need that feature. 
> Variables 
> can be determined at compile time, which should boost up speed. Therefore, I 
> wonder if it is a good idea to have static variables as well. So at compile 
> time, a variable is determined to be either static  or dynamic (the reference 
> of 
> a static varialbe is determined at compile time -- the namespace 
> implementation 
> will consist of two parts, a tuple for static variables and a dict for 
> dynamic 
> ones). The resolution can be done at the second pass of compilation. By 
> default, 
> variables are considered static. A variables is determined dynamic when: 1. 
> it 
> is declared dynamic; 2. it is not defined locally and the nearest namespace 
> has 
> it declared dynamic. A static variable can't be deleted, so a deleted 
> variable 
> must be a dynamic one: we can either enforce that the variable must be 
> explicitly declared or allow a del statement to implicitly declare a dynamic 
> variable.
> 
> Any thoughts?
> 
> Yingjie
> 
> 
> 
>   
I once used this obscure language called "C"; it did kind of what you're
talking about.

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


Re: A Short Question on list

2011-03-03 Thread Miki Tebeka
Have a look at reduce (http://docs.python.org/library/functions.html#reduce)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Short Question on list

2011-03-03 Thread Corey Richardson
On 03/03/2011 08:08 AM, joy99 wrote:
> Dear Group,
> If I have a list of elements, like,
> list=[1,2,3,4,5,..]
> now, if I want to multiply an increment of subset of the list each
> time,
> like,
> 
> elem1_list=list[0]
> elem2_list=list[1]
> elem3_list=list[2]
> elem4_list=list[3]

Why do you assign those to variables?

> As I was figuring out doing a for kind of iteration may not help
> exactly
> Can any one give some idea?

Are you looking for something like this?
>
# UNTESTED (Poor styling of variable names is noted)

def recursiveMultiply(l, r, product): # list, range (no shadowing)
if r <= 0:
return sum
product *= l[r]
recursiveMultiply(l, r - 1, product) # r must be decremented

subsetrange = 15
multiplysubset, elemlist = [], list(range(15)) # Works with Py2 and Py3

assert subset_range <= len(elemlist)

for i in range(subsetrange):
multiplysubset.append(recursiveMultiply(elemlist, i, 0))

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


Re: Checking against NULL will be eliminated?

2011-03-03 Thread Neil Cerutti
On 2011-03-03, Tom Zych  wrote:
> Carl Banks wrote:
>> Perl works deterministically and reliably.  In fact, pretty much every
>> language works deterministically and reliably.  Total non-argument.
>
> Well, yes. I think the real issue is, how many surprises are
> waiting to pounce on the unwary developer. C is deterministic
> and reliable, but full of surprises. 

Point of order, for expediency, C and C++ both include lots and
lots of indeterminate stuff. A piece of specific C code can be
totally deterministic, but the language is full of undefined
corners.

> Python is generally low in surprises. Using "if "
> is one place where you do have to think about unintended
> consequences.

Python eschews undefined behavior.

-- 
Neil Cerutti
"What we really can learn from this is that bad accounting can yield
immense imaginary profits." --Klepsacovic
-- 
http://mail.python.org/mailman/listinfo/python-list


A Short Question on list

2011-03-03 Thread joy99
Dear Group,
If I have a list of elements, like,
list=[1,2,3,4,5,..]
now, if I want to multiply an increment of subset of the list each
time,
like,

elem1_list=list[0]
elem2_list=list[1]
elem3_list=list[2]
elem4_list=list[3]

multiplysubset1=elem1_list*elem2_list
multiplysubset2=elem1_list*elem2_list
multiplysubset3=elem1_list*elem2_list*elem3_list
…….
………

As I was figuring out doing a for kind of iteration may not help
exactly
Can any one give some idea?

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


Re: builtin max() and weak ordering

2011-03-03 Thread Mark Dickinson
On Mar 3, 10:38 am, Stephen Evans  wrote:
> The CPython builtins min() and max() both return the first satisfactory 
> object found. This behaviour is undocumented. Examining the source in 
> bltinmodule.c shows that min() and max() both result in a call to min_max() 
> with Py_LT and Py_GT passed respectively.
>
> The behaviour of min() is correct. But with weak orderings of equivalent 
> objects, surely max() should be using Py_GE ? (the converse of Py_LT). Should 
> I be reporting a bug, submitting a patch, making feature request or 
> suggesting a documentation update ?

See:

http://bugs.python.org/issue9802

(and feel free to add comments to that issue).

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


Re: Anybody use web2py?

2011-03-03 Thread Abhinav Sood
We have built Radbox.me on web2py and it's amazing..

> On Saturday, December 19, 2009 1:42 AM AppRe Godeck wrote:

> Just curious if anybody prefers web2py over django, and visa versa. I
> know it is been discussed on a flame war level a lot. I am looking for a
> more intellectual reasoning behind using one or the other.


>> On Saturday, December 19, 2009 3:48 PM Yarko wrote:

>> Chevy or Ford?  (or whatever pair you prefer)
>> vi or emacs?
>> ...
>> 
>> These hold one aspect.
>> 
>> Hammer or a saw?
>> 
>> Hold (perhaps) another...
>> 
>> us.pycon.org, for example, uses both (in reality a mix of the above
>> argument sets, but at least evidence of the latter: different tools
>> for different problems).
>> 
>> From a rapid prototyping perspective, web2py is heavily data-table
>> efficient: that is, you can define a system, and all the app creation,
>> form generation and validation have defaults out of the box, and you
>> can have a "sense" of your data-centric structure in minutes.   The
>> same argument can go against ("how do I get it to do exactly what _I_
>> want it to, not what it wants to?") - that is, defaults hide things,
>> and  that has two edges...
>> 
>> From a layout/user interaction rapid prototyping perspective, web2py
>> is just entering the waters...
>> 
>> There is a steady growth of users, and (as you would expect for a
>> young framework), a lot of changes going on (although backward
>> compatiblity is a constant mantra when considering changes, that too
>> is a double-edged thing).
>> 
>> I find web2py useful, fast, and at times / in areas not as evolved /
>> flexible as I'd like.  BUT I could learn it quickly, and get to work
>> quickly.
>> 
>> I have taken an intro Django course (at a PyCon), have built a few
>> things with it (not nearly as many as I have w/ web2py), and I _can_
>> do things in it - so I will let someone else w/ django "miles" under
>> their belt speak their mind.
>> 
>> - Yarko


>>> On Saturday, December 19, 2009 3:51 PM Yarko wrote:

>>> Oh and one more thing: I find it dependable (not that snapshots do not
>>> have bugs, but that they are well defined, not "wild", and quickly
>>> fixed - and if you work around them, you can also depend on the system
>>> you have created).  FYI, it does the money/registration part of PyCon
>>> (past 2 years).


 On Saturday, December 19, 2009 6:32 PM mdipierro wrote:

 Of course I am the most biased person in the world on this topic but
 perhaps you want to hear my bias.
 
 A little bit of history... I thought a Django course at DePaul
 University and built a CMS for the United Nations in Django. I loved
 it. Then I also learned RoR. I found RoR more intuitive and better for
 rapid prototyping. I found Django much faster and more solid. I
 decided to build a proof of concept system that was somewhat in
 between Django and Rails with focus on 3 features: 1) easy to start
 with (no installation, no configuration, web based IDE, web based
 testing, debugging, and database interface); 2) enforce good practice
 (MVC, postbacks); 3) secure (escape all output, talk to database via
 DAL to present injections, server-side cookies with uuid session keys,
 role based access control with pluggable login methods, regex
 validation for all input including URLs).
 
 Originally it was a proof of concept, mostly suitable for teaching.
 Then lots of people helped to make it better and turn it into a
 production system. Now he had more than 50 contributors and a more
 than 20 companies that provide support.
 
 There are some distinctive features of web2py vs Django. Some love
 them, some hate hate them (mostly people who did not try them):
 
 - We promise backward compatibility. I do not accept patches that
 break it. It has been backward compatible for three years and I will
 enforce the copyright, if necessary, in order to ensure it for the
 future.
 
 - In web2py models and controllers are not modules. They are not
 imported. They are executed. This means you do not need to import
 basic web2py symbols. They are already defined in the environment that
 executes the models and controllers (like in Rails). This also means
 you do not need to restart the web server when you edit your app. You
 can import additional modules and you can define modules if you like.
 
 - You have a web based IDE with editor, some conflict resolution,
 Mercurial integration, ticketing system, web-based testing and
 debugging.
 
 - The Database Abstraction Layer (DAL) is closed to SQL than Dango ORM
 is. This means it does less for you (in particular about many 2 many)
 but it is more flaxible when it comes to complex joins, aggregates and
 nested selects.
 
 - The DAL supports out of the box SQLite, MySQL, PostgreSQL, MSSQL,
 Oracle, FireBird, FireBase, DB2, Informix, Ingres, an

builtin max() and weak ordering

2011-03-03 Thread Stephen Evans
The CPython builtins min() and max() both return the first satisfactory object 
found. This behaviour is undocumented. Examining the source in bltinmodule.c 
shows that min() and max() both result in a call to min_max() with Py_LT and 
Py_GT passed respectively.

The behaviour of min() is correct. But with weak orderings of equivalent 
objects, surely max() should be using Py_GE ? (the converse of Py_LT). Should I 
be reporting a bug, submitting a patch, making feature request or suggesting a 
documentation update ?

For a more mathematical consideration (not casual reading):

Stepanov, Alexander and Paul McJones. 2009. Elements of Programming. Addison 
Wesley. Pages 52-53

The code below demonstrates the issue. Using the total key gives the correct 
result. Using the weak key returns the "incorrect" result. Tested with Python 
2.7.1 and 3.1.2 (applies to 3.2)

Stephen Evans



from __future__ import print_function
from operator import attrgetter

class Pair():
def __init__(self, m0, m1):
self.m0, self.m1 = m0, m1

# rich comparisons are not used
def __lt__(self, other): raise NotImplementedError
def __le__(self, other): raise NotImplementedError
def __eq__(self, other): raise NotImplementedError
def __ne__(self, other): raise NotImplementedError
def __gt__(self, other): raise NotImplementedError
def __ge__(self, other): raise NotImplementedError

def __repr__(self):
"""repr() as a tuple"""
return repr((self.m0, self.m1))

@property
def total(self):
return (self.m0, self.m1)

@property
def weak(self):
return self.m0


def test():
"""
demonstrate the failure of the builtin max() to respect the original order
of equivalent objects.
"""
r = [ (0, 1), (0, 2) ]
r = [ Pair(*p) for p in r ]

# verify total and weak ordering
assert r == sorted(r, key=attrgetter('weak')) == sorted(r, 
key=attrgetter('total'))
print(r)

# from the sorted list
print(r[0], r[-1])

# using total ordering
print(min(r, key=attrgetter('total')), max(r, key=attrgetter('total')))

# using weak ordering, builtin_min and builtin_max functions in 
bltinmodule.c
#   min works as expected using Py_LT
#   max uses Py_GT rather than the converse of Py_LT (which would be Py_GE)
print(min(r, key=attrgetter('weak')), max(r, key=attrgetter('weak')))

test()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking against NULL will be eliminated?

2011-03-03 Thread Tom Zych
Carl Banks wrote:
> Perl works deterministically and reliably.  In fact, pretty much every
> language works deterministically and reliably.  Total non-argument.

Well, yes. I think the real issue is, how many surprises are
waiting to pounce on the unwary developer. C is deterministic
and reliable, but full of surprises. Python is generally low
in surprises. Using "if " is one place where you
do have to think about unintended consequences.

-- 
Tom Zych / freethin...@pobox.com
Q: I'm having problems with my Windows software. Will you help me?
A: Yes. Go to a DOS prompt and type "format c:". Any problems you are
   experiencing will cease within a few minutes. -- Hacker Howto
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking against NULL will be eliminated?

2011-03-03 Thread Carl Banks
On Mar 2, 3:46 pm, Steven D'Aprano  wrote:

> > Fortunately for me, I never trusted python's
> > complex, or should I say 'overloaded' Boolean usage.
>
> That's your loss. Just because you choose to not trust something which
> works deterministically and reliably, doesn't mean the rest of us
> shouldn't.

Perl works deterministically and reliably.  In fact, pretty much every
language works deterministically and reliably.  Total non-argument.


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


--------------> Web design in Chennai <--------------

2011-03-03 Thread tony player
Web Design in Chennai

**
   http://webdesignchennai.co.in/

**


Web Design Chennai offers Web Design in Chennai,website
designing,maintenance in chennai,Web Designing and development
Companies Chennai,web hosting in chennai,web site maintenance chennai.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking against NULL will be eliminated?

2011-03-03 Thread Jean-Michel Pichavant

Steven Howe wrote:


If an item is None: if ( type(x) == types.NoneType ):

Bye the way, the beauty of python is that "If an item is None" 
translates into "If item is None".


JM


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


Re: Checking against NULL will be eliminated?

2011-03-03 Thread Claudiu Popa
Hello,

Yes, root is an ElementTree Element.
Thank you for your answer!



-- 
Best regards,
 Claudiu   Popa

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


debugging segfaults in pythen PyQt (QWebview)

2011-03-03 Thread Gelonida
Hi,

I have a QWebview application, which segfaults rather often,
but not all the time.

I assume it is some kind of race condition when loading a certain web
page with quite some built in AJax.



How can I debug it?

The application crashes under Windows and under Linux.


I enabled already core dumps and am able to

start

gdb python.exe core

I guess the command "bt"
will be able to give m a backtrace of  the C program


Is there any way to obtain the related  backtrace of the python script?


I'm at a complete loss of what I am doing wrong in my script and would
hope to get at least some indication.


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


Re: Playing WAV file with Python

2011-03-03 Thread VGNU Linux
On Thu, Mar 3, 2011 at 1:54 PM, Chris Rebert  wrote:

> On Thu, Mar 3, 2011 at 12:17 AM, VGNU Linux  wrote:
> > On Thu, Mar 3, 2011 at 1:26 PM, Chris Rebert  wrote:
> >> On Tue, Mar 1, 2011 at 11:47 PM, VGNU Linux 
> wrote:
> >> > How can I play WAV file in python without OS(like Linux/Windows/MAC)
> on
> >> > a
> >> > device ?
> >> > On Google I found lot of different solution but related to OS's like
> >> > winsound, ossaudiodev etc which are not useful.
> >>
> >> Do you mean you want your code to be cross-platform, or what?
> >> "Without OS" is rather vague. What are you trying to accomplish?
> >
> > I will be using WAVE on embedded devices, and the device will not have
> any
> > OS's. So I am looking for modules which can play WAVE sound without
> > underlying OS.
>
> What implementation of Python are you going to use? I don't personally
> know of any that can run on the "bare metal" without an OS.
>

I am planning to use python-on-a-chip(PyMite) which can be run without an OS
therefore I am looking for a module/library which can play sound files.


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


Re: Playing WAV file with Python

2011-03-03 Thread Chris Rebert
On Thu, Mar 3, 2011 at 12:17 AM, VGNU Linux  wrote:
> On Thu, Mar 3, 2011 at 1:26 PM, Chris Rebert  wrote:
>> On Tue, Mar 1, 2011 at 11:47 PM, VGNU Linux  wrote:
>> > How can I play WAV file in python without OS(like Linux/Windows/MAC) on
>> > a
>> > device ?
>> > On Google I found lot of different solution but related to OS's like
>> > winsound, ossaudiodev etc which are not useful.
>>
>> Do you mean you want your code to be cross-platform, or what?
>> "Without OS" is rather vague. What are you trying to accomplish?
>
> I will be using WAVE on embedded devices, and the device will not have any
> OS's. So I am looking for modules which can play WAVE sound without
> underlying OS.

What implementation of Python are you going to use? I don't personally
know of any that can run on the "bare metal" without an OS.

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


Re: Python escape usage in django templates by GAE

2011-03-03 Thread Niklas RTZ
Wow, that really explains it superbly also pointing me to the right
place onwards. Many thanks Chris!

On Thu, Mar 3, 2011 at 8:11 AM, Chris Rebert  wrote:
> On Wed, Mar 2, 2011 at 11:50 PM, Niklasro  wrote:
>> Hi
>> I got problems with escape displaying like junk when upgrading from
>> django 0.96 to 1.2 with google app engine.
>> The code is
>>
>>     # let user choose authenticator
>>        for p in openIdProviders:
>>            p_name = p.split('.')[0] # take "AOL" from "AOL.com"
>>            p_url = p.lower()        # "AOL.com" -> "aol.com"
>>            loginmsg = loginmsg + '%s ' % ( #'','')
>>                   users.create_login_url(federated_identity=p_url),
>> p_name)
>>        loginmsg = loginmsg + '%s' %
>> ('login',_("Log in"))
>>
>> And the output is strange. View source show this:
>>
>> Add03 Mar
>>
>> Log inGoogle > href="google.com">Yahoo > href="google.com">MySpace > href="google.com">AOL > href="login">Log in
>>
>> 
>>
>> Can you make ad advice how to proceed? Many thanks,
>
> IIRC, at some point after v0.96, Django made
> HTML-character-entity-escaping of values in templates the default
> behavior; your code assumes the opposite, hence your excessive
> escaping problem. I'm sure there's a way to indicate that certain
> values should be treated literally and not get HTML-escaped.
>
> Check the transition docs / release notes, and/or try asking on the
> django-specific mailing list
> (http://groups.google.com/group/django-users )
> (You should probably ask there first with any future Django questions too.)
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Playing WAV file with Python

2011-03-03 Thread VGNU Linux
Hi,

On Thu, Mar 3, 2011 at 1:26 PM, Chris Rebert  wrote:

> On Tue, Mar 1, 2011 at 11:47 PM, VGNU Linux  wrote:
> > Hi All,
> > How can I play WAV file in python without OS(like Linux/Windows/MAC) on a
> > device ?
> > On Google I found lot of different solution but related to OS's like
> > winsound, ossaudiodev etc which are not useful.
>
> Do you mean you want your code to be cross-platform, or what?
> "Without OS" is rather vague. What are you trying to accomplish?
>

I will be using WAVE on embedded devices, and the device will not have any
OS's. So I am looking for modules which can play WAVE sound without
underlying OS.


> Regards,
> Chris
> --
> http://blog.rebertia.com


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


Re: Playing WAV file with Python

2011-03-03 Thread Matteo Landi
I imagine he is looking for a cross-platform solution: n this case, I guess the 
most suitable solution is pygame.

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


Re: Python escape usage in django templates by GAE

2011-03-03 Thread Chris Rebert
On Wed, Mar 2, 2011 at 11:50 PM, Niklasro  wrote:
> Hi
> I got problems with escape displaying like junk when upgrading from
> django 0.96 to 1.2 with google app engine.
> The code is
>
>     # let user choose authenticator
>        for p in openIdProviders:
>            p_name = p.split('.')[0] # take "AOL" from "AOL.com"
>            p_url = p.lower()        # "AOL.com" -> "aol.com"
>            loginmsg = loginmsg + '%s ' % ( #'','')
>                   users.create_login_url(federated_identity=p_url),
> p_name)
>        loginmsg = loginmsg + '%s' %
> ('login',_("Log in"))
>
> And the output is strange. View source show this:
>
> Add03 Mar
>
> Log inGoogle  href="google.com">Yahoo  href="google.com">MySpace  href="google.com">AOL  href="login">Log in
>
> 
>
> Can you make ad advice how to proceed? Many thanks,

IIRC, at some point after v0.96, Django made
HTML-character-entity-escaping of values in templates the default
behavior; your code assumes the opposite, hence your excessive
escaping problem. I'm sure there's a way to indicate that certain
values should be treated literally and not get HTML-escaped.

Check the transition docs / release notes, and/or try asking on the
django-specific mailing list
(http://groups.google.com/group/django-users )
(You should probably ask there first with any future Django questions too.)

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Playing WAV file with Python

2011-03-03 Thread Chris Rebert
On Tue, Mar 1, 2011 at 11:47 PM, VGNU Linux  wrote:
> Hi All,
> How can I play WAV file in python without OS(like Linux/Windows/MAC) on a
> device ?
> On Google I found lot of different solution but related to OS's like
> winsound, ossaudiodev etc which are not useful.

Do you mean you want your code to be cross-platform, or what?
"Without OS" is rather vague. What are you trying to accomplish?

Regards,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list