Re: A Friday Python Programming Pearl: random sampling

2010-05-29 Thread Xavier Ho
On 29 May 2010 06:44, Mark Dickinson  wrote:

> But I was struck by its beauty and
> simplicity, and thought it deserved to be better known.
>

Wow, that took me at least 2 minutes to see its beauty as well. Nice find,
Mark. Thanks for sharing.

(Also, it's nice to see another SOer on Python-List as well!)

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


Py_single_input and the side-effects...

2010-05-29 Thread moerchendiser2k3
Hi at all,

I have a small problem with Py_single_input, that I dont really know
what it
actually does.

I created my own interactive interpreter loop and when I create
objects like

p = TestObject()

this instance is just deleted on Py_Finalize() even I delete the
entire console scope long time before. It seems that Py_single_input
stores the references somewhere else. Could anyone explain me a little
bit what is actually going on here?

Thanks a lot!
Cheers, moerchendiser2k3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Tkinter Programming by John Grayson

2010-05-29 Thread Pradeep B
On Fri, Jan 22, 2010 at 6:48 AM, Ethan Furman  wrote:
> Peter wrote:
>>
>> On Jan 15, 9:12 am, Kevin Walzer  wrote:

 On Jan 15, 6:24 am, Mark Roseman  wrote:
>
>  Peter  wrote:
>>
>> Besides, the book is mainly about using Python with Tkinter - and
>> Tkinter hasn't changed that much since 2000, so I believe it is just
>> as relevant today as it was back then.
>
> I'd say that Tkinter has substantially changed - with the introduction
> of the 'ttk' themed widgets.  I cover these in my tutorial
> athttp://www.tkdocs.com
>
>>> Another book I've found very helpful for learning Tkinter is Programming
>>> Python by Mark Lutz--a lot of coverage there of GUI development.
>>>
>>
>> Another possible consideration when choosing a GUI to learn Python -
>> will you want to print from within your GUI application?
>
> Excellent point.
>
> Many thanks to all who responded, especially for the reminder of the gui
> sections in Programming Python (forgot I had that book!).  I'll start by
> going over that again, and we'll see how confident I feel afterwards.  ;)
>
> ~Ethan~
> --
> http://mail.python.org/mailman/listinfo/python-list
>



Is printing from GUI still a 'not-happening' thing with Tkinter ? I
have just started learning it.



-- 

|_|0|_|
|_|_|0|
|0|0|0|

http://picasaweb.google.com/pradeepbpin
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter library reference

2010-05-29 Thread Pradeep B
Do we have a standard reference library for Tkinter available?

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


Creating a single list

2010-05-29 Thread Astley Le Jasper
This is probably a really silly question but, given the example code
at the bottom, how would I get a single list?

What I currently get is:

('id', 20, 'integer')
('companyname', 50, 'text')
[('focus', 30, 'text'), ('fiesta', 30, 'text'), ('mondeo', 30,
'text'), ('puma', 30, 'text')]
('contact', 50, 'text')
('email', 50, 'text')

what I would like is:

('id', 20, 'integer')
('companyname', 50, 'text')
('focus', 30, 'text'),
('fiesta', 30, 'text'),
('mondeo', 30, 'text'),
('puma', 30, 'text'),
('contact', 50, 'text')
('email', 50, 'text')

SAMPLE CODE>>>
def getproducts():
temp_list=[]
product_list=['focus','fiesta','mondeo','puma'] #usually this
would come from a db
for p in product_list:
temp_list.append((p,30,'text'))
return temp_list

def createlist():
column_title_list = (
("id",20,"integer"),
("companyname",50,"text"),
getproducts(),
("contact",50,"text"),
("email",50,"text"),
)
return column_title_list

for item in createlist():
print item
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a single list

2010-05-29 Thread Xavier Ho
On 29 May 2010 23:24, Astley Le Jasper  wrote:

> def createlist():
>column_title_list = (
>("id",20,"integer"),
>("companyname",50,"text"),
>getproducts(),
>("contact",50,"text"),
>("email",50,"text"),
>)
>return column_title_list
>

Note that you're creating a Tuple, not a List. They're not the same thing.

Try this:

   column_title_list = [
("id",20,"integer"),
("companyname",50,"text"),
("contact",50,"text"),
("email",50,"text"),
   ]

  # Insert into the list with slicing syntax.
   column_title_list[2:3} = getproduct()

This will not work with tuples, as they are immutable. Lists are.

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


Re: Creating a single list

2010-05-29 Thread Xavier Ho
>   # Insert into the list with slicing syntax.
>column_title_list[2:3} = getproduct()
>

Sorry, that should have been [2:3]. Typing a bit too fast.

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


Re: Python and Tkinter Programming by John Grayson

2010-05-29 Thread Kevin Walzer



Is printing from GUI still a 'not-happening' thing with Tkinter ? I
have just started learning it.


Tkinter doesn't wrap native printing API's. There are a few extensions 
that do it, but they are platform specific and not complete.


The usual ways of printing are like this:

1. If you're outputting data from the text widget, write that to a 
temporary text file and print via lpr.


2. If you're outputting data from the canvas, write that to a temporary 
postscript file and print via lpr.


This is on Unix/MacOS. Not sure what the equivalent API on Windows is.

--Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a single list

2010-05-29 Thread superpollo

Astley Le Jasper ha scritto:

This is probably a really silly question but, given the example code
at the bottom, how would I get a single list?

What I currently get is:

('id', 20, 'integer')
('companyname', 50, 'text')
[('focus', 30, 'text'), ('fiesta', 30, 'text'), ('mondeo', 30,
'text'), ('puma', 30, 'text')]
('contact', 50, 'text')
('email', 50, 'text')

what I would like is:

('id', 20, 'integer')
('companyname', 50, 'text')
('focus', 30, 'text'),
('fiesta', 30, 'text'),
('mondeo', 30, 'text'),
('puma', 30, 'text'),
('contact', 50, 'text')
('email', 50, 'text')

SAMPLE CODE>>>
def getproducts():
temp_list=[]
product_list=['focus','fiesta','mondeo','puma'] #usually this
would come from a db
for p in product_list:
temp_list.append((p,30,'text'))
return temp_list

def createlist():
column_title_list = (
("id",20,"integer"),
("companyname",50,"text"),
getproducts(),
("contact",50,"text"),
("email",50,"text"),
)
return column_title_list

for item in createlist():
print item


>>> def createlist():
... column_title_list = [
... ("id",20,"integer"),
... ("companyname",50,"text")]
... column_title_list += getproducts()
... column_title_list += [
... ("contact",50,"text"),
... ("email",50,"text")]
... return column_title_list
...
>>> for item in createlist():
... print item
...
('id', 20, 'integer')
('companyname', 50, 'text')
('focus', 30, 'text')
('fiesta', 30, 'text')
('mondeo', 30, 'text')
('puma', 30, 'text')
('contact', 50, 'text')
('email', 50, 'text')
>>>

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


Re: A Friday Python Programming Pearl: random sampling

2010-05-29 Thread Bryan
Mark Dickinson wrote:
> N.B.  I don't claim any originality for the algorithm; only for the
> implementation: the algorithm is based on an algorithm attributed to
> Robert Floyd, and appearing in Jon Bentley's 'Programming Pearls' book

Actually it is the sequel, /More Programming Pearls/.

> (though that algorithm produces a set, so doesn't worry about the
> ordering of the sample).

Bentley presents a version of the Floyd algorithm that provides random
order, but it requires a set data type with some idea of order, as in
"insert j in s after t". As Mark Dickinson's version uses a normal
dict(), which Bentley had already introduced under the name "associate
array", I'd say Mark's version is an improvement.


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


Help with Regexp, \b

2010-05-29 Thread andrew cooke

This is a bit embarassing, but I seem to be misunderstanding how \b
works in regexps.

Please can someone explain why the following fails:

from re import compile

p = compile(r'\bword\b')
m = p.match(' word ')
assert m

My understanding is that \b matches a space at the start or end of a
word, and that "word" is a word - http://docs.python.org/library/re.html

What am I missing here?  I suspect I am doing something very stupid.

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


Re: Help with Regexp, \b

2010-05-29 Thread Shashwat Anand
\b is NOT spaces

>>> p = re.compile(r'\sword\s')
>>> m = p.match(' word ')
>>> assert m
>>> m.group(0)
' word '
>>>


On Sat, May 29, 2010 at 8:34 PM, andrew cooke  wrote:

>
> This is a bit embarassing, but I seem to be misunderstanding how \b
> works in regexps.
>
> Please can someone explain why the following fails:
>
>from re import compile
>
>p = compile(r'\bword\b')
>m = p.match(' word ')
>assert m
>
> My understanding is that \b matches a space at the start or end of a
> word, and that "word" is a word - http://docs.python.org/library/re.html
>
> What am I missing here?  I suspect I am doing something very stupid.
>
> Thanks,
> Andrew
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with Regexp, \b

2010-05-29 Thread Duncan Booth
andrew cooke  wrote:

> Please can someone explain why the following fails:
> 
> from re import compile
> 
> p = compile(r'\bword\b')
> m = p.match(' word ')
> assert m
> 
> My understanding is that \b matches a space at the start or end of a
> word, and that "word" is a word - http://docs.python.org/library/re.html
> 
> What am I missing here?  I suspect I am doing something very stupid.
> 

You misunderstand what \b does: it doesn't match a space, it matches a 0 
length string on a boundary between a non-word and a word.

Try:

 p.match(' word ', 1).group(0)

and you'll see that you are only match the word, not the surrounding 
puctuation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with Regexp, \b

2010-05-29 Thread Shashwat Anand
Also what you are probably looking for is this I guess,

>>> p = re.compile(r'\bword\b')
>>> m = p.match('word word')
>>> assert m
>>> m.group(0)
'word'


On Sat, May 29, 2010 at 8:44 PM, Shashwat Anand wrote:

> \b is NOT spaces
>
> >>> p = re.compile(r'\sword\s')
> >>> m = p.match(' word ')
> >>> assert m
> >>> m.group(0)
> ' word '
> >>>
>
>
> On Sat, May 29, 2010 at 8:34 PM, andrew cooke  wrote:
>
>>
>> This is a bit embarassing, but I seem to be misunderstanding how \b
>> works in regexps.
>>
>> Please can someone explain why the following fails:
>>
>>from re import compile
>>
>>p = compile(r'\bword\b')
>>m = p.match(' word ')
>>assert m
>>
>> My understanding is that \b matches a space at the start or end of a
>> word, and that "word" is a word - http://docs.python.org/library/re.html
>>
>> What am I missing here?  I suspect I am doing something very stupid.
>>
>> Thanks,
>> Andrew
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter library reference

2010-05-29 Thread Godson Gera
Do you mean Tkinter API reference documentation ? If so, this is what I've
used years back http://www.nmt.edu/tcc/help/pubs/tkinter.pdf

you can also get some info from http://effbot.org/tkinterbook


On Sat, May 29, 2010 at 6:41 PM, Pradeep B  wrote:

> Do we have a standard reference library for Tkinter available?
>
> --
> Pradeep
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


Re: Help with Regexp, \b

2010-05-29 Thread andrew cooke
On May 29, 11:24 am, Duncan Booth 
wrote:
> andrew cooke  wrote:
> > Please can someone explain why the following fails:
>
> >         from re import compile
>
> >         p = compile(r'\bword\b')
> >         m = p.match(' word ')
> >         assert m
[...]
> You misunderstand what \b does: it doesn't match a space, it matches a 0
> length string on a boundary between a non-word and a word.
[...]

That's what I thought it did...  Then I read the docs and confused
"empty string" with "space"(!) and convinced myself otherwise.  I
think I am going senile.

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


Re: A Friday Python Programming Pearl: random sampling

2010-05-29 Thread Mark Dickinson
On May 29, 3:43 pm, Bryan  wrote:
> Mark Dickinson wrote:
> > N.B.  I don't claim any originality for the algorithm; only for the
> > implementation: the algorithm is based on an algorithm attributed to
> > Robert Floyd, and appearing in Jon Bentley's 'Programming Pearls' book
>
> Actually it is the sequel, /More Programming Pearls/.

Thanks for the correction.  I confess that I've yet to read either
book;  I'll have to try to track them down.

> > (though that algorithm produces a set, so doesn't worry about the
> > ordering of the sample).
>
> Bentley presents a version of the Floyd algorithm that provides random
> order, but it requires a set data type with some idea of order, as in
> "insert j in s after t".

Ah, nice.  The dict values, of course, exactly provide the necessary
idea of order, so I guess this amounts to pretty much the same thing.

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


Python vs. Fedora and CentOS

2010-05-29 Thread John Nagle

  The major Red Hat based Linux distros are still shipping with Python 2.4.
As a result, almost all hosting providers are running obsolete versions of
Python.

  The big problem seems to be that "cPanel" and "yum" still use older versions
of Python, and those programs are more important to distro builders than Python
itself.

  Is anybody trying to do something about this?

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


xrange issue 7721

2010-05-29 Thread Mark Lawrence
Sorry if this is the wrong ng/ml, but thought I'd better flag this up 
somewhere.


I've had an OverflowError using xrange with Python 2.6.5 on Windows. 
Googling got me to the subject line.


msg97928 gives a code snippet to overcome the limitations of xrange, 
allowing for negative steps, however it doesn't raise a ValueError for a 
zero step. msg99624 gives a docs change that has been implemented for 
V2.6, but this doesn't refer to the msg97928 code snippet, rather it 
refers to a one liner that only works for positive steps.  The docs for 
V2.7 haven't been changed at all.


Assuming that I am correct, can I create myself a login on the bugs 
tracker and re-open the issue to get this sorted?


Kindest regards.

Mark Lawrence.

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


Re: Python vs. Fedora and CentOS

2010-05-29 Thread Paul Rubin
John Nagle  writes:
>   The major Red Hat based Linux distros are still shipping with Python 2.4.

Fedora 12 ships with Python 2.6, I think.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Fedora and CentOS

2010-05-29 Thread Wesley Brooks
I've got Fedora 10 here with 2.5, and 11 at the office with 2.6.

On 29 May 2010 19:58, Paul Rubin  wrote:
> John Nagle  writes:
>>   The major Red Hat based Linux distros are still shipping with Python 2.4.
>
> Fedora 12 ships with Python 2.6, I think.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Fedora and CentOS

2010-05-29 Thread Philip Semanchuk


On May 29, 2010, at 2:58 PM, Paul Rubin wrote:


John Nagle  writes:
 The major Red Hat based Linux distros are still shipping with  
Python 2.4.


Fedora 12 ships with Python 2.6, I think.


Fedora has been shipping with Python 2.6 since F11 release in June of  
2009, and Python > 2.4 since F7 released in May 2007.


http://distrowatch.com/table.php?distribution=fedora


I think the OP is referring to RHEL (Enterprise Linux).


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


Re: Python vs. Fedora and CentOS

2010-05-29 Thread Mike Fedyk
On Sat, May 29, 2010 at 12:03 PM, Wesley Brooks  wrote:
> On 29 May 2010 19:58, Paul Rubin  wrote:
>> John Nagle  writes:
>>>   The major Red Hat based Linux distros are still shipping with Python 2.4.
>>
>> Fedora 12 ships with Python 2.6, I think.
>
> I've got Fedora 10 here with 2.5, and 11 at the office with 2.6.
>

And Fedora 13 that has 2.6 and 3.1.

And whatever slows down the upgrade treadmill is good IMO.  People
should not have to install the latest python just to use your app.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xrange issue 7721

2010-05-29 Thread Martin Manns
On Sat, 29 May 2010 19:46:28 +0100
Mark Lawrence  wrote:

> I've had an OverflowError using xrange with Python 2.6.5 on Windows. 
> Googling got me to the subject line.
> 
> msg97928 gives a code snippet to overcome the limitations of xrange, 
> allowing for negative steps, however it doesn't raise a ValueError
> for a zero step. msg99624 gives a docs change that has been
> implemented for V2.6, but this doesn't refer to the msg97928 code
> snippet, rather it refers to a one liner that only works for positive
> steps.  The docs for V2.7 haven't been changed at all.

Mark:

Thank you for posting.

2.7 is not affected by issue 7721 because itertools.islice behavior is
changed. Therefore, the original snippet should work in 2.7 (I have not
tested this).

I found the msg97928 code pretty obvious when seeing the snippet. 
If you disagree you may consider re-opening the issue.

Martin

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


Re: Free chapter about Python and databases (MySQL and SQLite)

2010-05-29 Thread John Bokma
Robinow  writes:

> 
> On May 28, 2010, at 10:05 PM, John Bokma  wrote:
>
>> Sebastian Bassi  writes:
>>
>>> On Fri, May 28, 2010 at 12:37 AM, John Bokma 
>>> wrote:
>>
>> Even if it's just a few bucks, it's still money saved [0]. On top of
>> that I think it's way better to point your audience to good books on
>> the
>> topic and skip the intro instead of doing a (half hearted IMO) attempt
>> at it yourself.
>>>
>>
> OK, John. What book do you recommend?

Since it's not clear on what topic in the book you want recommendations,
I do them all. Note that I only can recommend books I have either in my
possession or browsed through that are still on my wish list. I am not
new to programming, so the books listed under Python are not books for
beginners per se, except the Programming in Python 3, which is on top of
that one of the best learning a programming language books I've read (so
far).

Python:
   Programming in Python 3 /2nd edition/
 
 If you have some experience with programming:
   Dive into Python 2 (*)
   Dive into Python 3 (*)

 If you already have a book on learning Python and want a good extra
 reference:
   Python Essential Reference (4th edition)

Subversion: 
   Version Control with Subversion (O'Reilly) (*)

Database:
   The Definitive Guide to SQLite
   MySQL (4th Edition) by Paul Dubois

 I also strongly suggest to read 1 or 2 books by Joe Celko before
 you even start to make your own databases (wish I would had), for
 example:

   Data and Databases: Concepts in Practice (**)
   SQL Programming Style
   SQL for smarties

IMO Joe writes a bit "in your face" and calls a lot of people dumb, but
don't let that get in the way ;-).

I own also a copy of "MySQL cookbook" but haven't used it much. Still, I
recommend to browse this book if you already have book(s) on MySQL and
decide for yourself if it's something you want. In my experience most
cookbook books by O'Reilly are good or very good.

Can't recommend a good book on XML, I don't have one (***). I do have a
book on XSLT (XSLT 2.0, O'Reilly) which is IMO very good, and does have,
from the top of my head, a good XML introduction. Personally, I think
it's good that if you work with XML that at least you have some idea of
what XSLT is. Another XSLT book I have is XSLT 2.0 and XPath 2.0, but I
haven't used that very often yet.

(*) Also available as free download
(**) Based on my experience with the other excellent books by Celko
(***) A good book on XML would probably be 50 pages or less :-D.

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Fedora and CentOS

2010-05-29 Thread John Nagle

Philip Semanchuk wrote:


On May 29, 2010, at 2:58 PM, Paul Rubin wrote:


John Nagle  writes:
 The major Red Hat based Linux distros are still shipping with Python 
2.4.


Fedora 12 ships with Python 2.6, I think.


Fedora has been shipping with Python 2.6 since F11 release in June of 
2009, and Python > 2.4 since F7 released in May 2007.


http://distrowatch.com/table.php?distribution=fedora


The "enterprise ready" versions are much further behind.

http://distrowatch.com/table.php?distribution=centos
CentOS 5.5 (May 2010) - Python: 2.4.3

http://distrowatch.com/table.php?distribution=redhat
RHEL 5.5 (March 2010) - Python 2.4.3
RHEL 6-Beta - Python 2.6.2

However, if 2.6.2 is going into RHEL, the others will follow, and
that's probably the production Python on servers for the next few years.

John Nagle

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


Re: dbf files and indexes

2010-05-29 Thread Bryan
Christian Heimes wrote:

[D'Arcy J.M. Cain had written:]
> > SELECT * FROM NumberOfPets
> > WHERE name IN (SELECT name FROM CatLovers) OR
> >    name IN (SELECT name FROM DogLovers)
> > ORDER BY name;
>
> A good way is to use SQL with JOINs instead of horrible nested
> selects.

Do show us your join that makes D'Arcy's nested select horrible by
comparison.

> Although SQL is declarative, you shouldn't make the work of the query
> optimizer so hard.

You're not doing the query optimizer any favors. It can normalize the
query to the same thing either way, so we might as well write it to be
readable by people. I can read D'Arcy's at a glance.


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


tkinter function outout to text widget

2010-05-29 Thread Johan Lans
Hi
I'm totally new on python and I'm doing an assignement where I'm doing
a class that manipulates a text. The program is also supposed to have
a GUI, for which I have used tkinter.
So far I have entry widgets for file names and buttons, its all
working like I want it to.
What is missing is a way to output the changes to the text. I was
thinking that a text-widget would be suitable. Is there a reasonably
easy way to do this?
I tried inserting a string to the textwidget and letting the class
method change this string, but the inserted string isn't updated in
the text-widget.
Would be very happy for any hints.
-- 
http://mail.python.org/mailman/listinfo/python-list


PLAY CAR RACE GAMES

2010-05-29 Thread KAJAL AGARWAL
  PLAY  CAR  RACE GAMES:-

  PLAY CAR RACE GAMES ON MY WEB SITE

  AND ENJOY UR MIND FRESH  AND U CAN

  DOWN LOAD ALSO MY GAMES

  VISIT  http://andhraonlinegames.blogspot,com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter function outout to text widget

2010-05-29 Thread Alf P. Steinbach

* Johan Lans, on 29.05.2010 22:51:

Hi
I'm totally new on python and I'm doing an assignement where I'm doing
a class that manipulates a text. The program is also supposed to have
a GUI, for which I have used tkinter.
So far I have entry widgets for file names and buttons, its all
working like I want it to.
What is missing is a way to output the changes to the text. I was
thinking that a text-widget would be suitable. Is there a reasonably
easy way to do this?
I tried inserting a string to the textwidget and letting the class
method change this string, but the inserted string isn't updated in
the text-widget.


If that is a direct Python string, then you're not changing the string. Python 
strings are immutable. So, then you're at most changing which string a variable 
or attribute is referring to.


However, if it is some Tkinter thing (I seem to recall that Tkinter offers some 
automatic update magic via something-something), then I don't know.




Would be very happy for any hints.


Just update the widget whenever you change the text.


Cheers & hth.,

- Alf


--
blog at http://alfps.wordpress.com>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Fedora and CentOS

2010-05-29 Thread D'Arcy J.M. Cain
On Sat, 29 May 2010 11:43:29 -0700
John Nagle  wrote:
>The major Red Hat based Linux distros are still shipping with Python 2.4.
> 
>Is anybody trying to do something about this?

Other than not running Linux on our hosting server?  My ISP
(http://www.Vex.Net) runs FreeBSD.  Linux is for the desktop.

-- 
D'Arcy J.M. Cain  |  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: dbf files and indexes

2010-05-29 Thread D'Arcy J.M. Cain
On Sat, 29 May 2010 13:45:37 -0700 (PDT)
Bryan  wrote:
> You're not doing the query optimizer any favors. It can normalize the
> query to the same thing either way, so we might as well write it to be
> readable by people. I can read D'Arcy's at a glance.

Assuming that you are running a decent *cough* PostgreSQL *cough*
database engine.  Readable is good.  If you have a problem with your
queries chances are that reorganizing your data or adding proper
indexes will do more for you than contorted SQL will.

-- 
D'Arcy J.M. Cain  |  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: xrange issue 7721

2010-05-29 Thread Mark Lawrence

Hi Martin, thanks for the response, please see below.

On 29/05/2010 20:12, Martin Manns wrote:

On Sat, 29 May 2010 19:46:28 +0100
Mark Lawrence  wrote:


I've had an OverflowError using xrange with Python 2.6.5 on Windows.
Googling got me to the subject line.

msg97928 gives a code snippet to overcome the limitations of xrange,
allowing for negative steps, however it doesn't raise a ValueError
for a zero step. msg99624 gives a docs change that has been
implemented for V2.6, but this doesn't refer to the msg97928 code
snippet, rather it refers to a one liner that only works for positive
steps.  The docs for V2.7 haven't been changed at all.


Mark:

Thank you for posting.

2.7 is not affected by issue 7721 because itertools.islice behavior is
changed. Therefore, the original snippet should work in 2.7 (I have not
tested this).


From http://docs.python.org/dev/library/itertools.html
"Unlike regular slicing, islice()  does not support negative values for 
start, stop, or step."


Rule 1 of programming never assume anything, particularly wrt testing. I 
assume that you are ok with this. :) Dreadful I know :)




I found the msg97928 code pretty obvious when seeing the snippet.
If you disagree you may consider re-opening the issue.


Try running this on Python 2.6.5 in file irange.py

from itertools import takewhile, count

def irange(start, stop, step):
if step < 0:
cond = lambda x: x > stop
else:
cond = lambda x: x < stop
return takewhile(cond, (start + i * step for i in count()))

if __name__=='__main__':
for i in irange(0, 10, 0): print i

My output from the command line

c:\Users\Mark\python>irange
0
0
etc etc etc
I trust that you get my point regarding the failure to raise a 
ValueError :)  Or am I wearing my extremely stupid hat today?




Martin



Kindest regards.

Mark Lawrence.



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


Re: if, continuation and indentation

2010-05-29 Thread john
On May 28, 10:37 am, "Colin J. Williams" 
wrote:
> On 28-May-10 05:54 AM, Jonathan Hartley wrote:
>
> > On May 27, 1:57 pm, Jean-Michel Pichavant
> > wrote:
> >> HH wrote:
> >>> I have a question about best practices when it comes to line wrapping/
> >>> continuation and indentation, specifically in the case of an if
> >>> statement.
>
> >>> When I write an if statement with many conditions, I prefer to use a
> >>> parenthesis around the whole block and get the implicit continuation,
> >>> rather than ending each line with an escape character.  Thus, using
> >>> the example from the style guide (http://www.python.org/dev/peps/
> >>> pep-0008/) I would write:
>
> >>>      if (width == 0 and
> >>>          height == 0 and
> >>>          color == 'red' and
> >>>          emphasis == 'strong' or
> >>>          highlight>  100):
> >>>          raise ValueError("sorry, you lose")
>
> >>> The problem should be obvious -- it's not easy to see where the
> >>> conditional ends and the statement begins since they have the same
> >>> indentation.  Part of the problem, I suppose, is that Emacs indents
> >>> 'height' and the other lines in the conditional to 4 spaces (because
> >>> of the parenthesis).  How do people deal with this situation?
>
> >>> Thanks,
> >>> Henrik
>
> >> One possible solution
>
> >>      if (
> >>              width == 0 and
> >>              height == 0 and
> >>              color == 'red' and
> >>              emphasis == 'strong' or
> >>              highlight>  100
> >>         ):
> >>          raise ValueError("sorry, you lose")
>
> >> JM
>
> > I've always liked this, or even:
>
> >    if (
> >        width == 0 and
> >        height == 0 and
> >        color == 'red' and
> >        emphasis == 'strong' or
> >        highlight>  100
> >    ):
> >        raise ValueError("sorry, you lose")
>
> > but my co-workers have uniformly gone bananas whenever I try it.
>
> I liked:
>
> On 27-May-10 08:48 AM, Xavier Ho wrote:
>  > On 27 May 2010 22:22, HH  
> > wrote:
>
>  >
>  >         if (width == 0 and
>  >             height == 0 and
>  >             color == 'red' and
>  >             emphasis == 'strong' or
>  >             highlight > 100):
>  >             raise ValueError("sorry, you lose")
>  >
>  >
>  > I've gotta say - I've bumped into this problem before, and I'm sure many
>  > other have - this is a valid question. It just hasn't bothered me enough
>  > to ask...
>  >
>  > Correct me if I'm wrong, but I think the following is equivalent, and
>  > looks better. Although this won't fix all ugly cases in that problem..
>  >
>  > if (width, height, color, emphasis) == (0, 0, 'red', 'strong') or
>  > highlight > 100:
>  >      raise ValueError("sorry, you lose")
>  >
>  > Cheers,
>  > Xav
>
> but nobody commented.
>
> Colin W.

Colin:
Sure, you can do it that way.  IMO, though, the OP was  wrong, and so
is the PEP.  Source code is meant to communicate.  So it must transmit
the correct information to the computer; it also must inform your
coworkers.  That means that you have a responsibility to care what
they think, though you privately have your opinions.  Another reason
the PEP is faulty in this circumstance is that a misplaced backslash,
or a missing one, is easily found and fixed.  A misplaced parentheses,
or just one of a pair, will transform your source code into something
which may compile and then give faulty results:  a disaster.
So keep it simple, and make it legible.
Yours,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: if, continuation and indentation

2010-05-29 Thread Mark Lawrence

On 30/05/2010 01:23, john wrote:

On May 28, 10:37 am, "Colin J. Williams"
wrote:

On 28-May-10 05:54 AM, Jonathan Hartley wrote:


On May 27, 1:57 pm, Jean-Michel Pichavant
wrote:

HH wrote:

I have a question about best practices when it comes to line wrapping/
continuation and indentation, specifically in the case of an if
statement.



When I write an if statement with many conditions, I prefer to use a
parenthesis around the whole block and get the implicit continuation,
rather than ending each line with an escape character.  Thus, using
the example from the style guide (http://www.python.org/dev/peps/
pep-0008/) I would write:



  if (width == 0 and
  height == 0 and
  color == 'red' and
  emphasis == 'strong' or
  highlight>100):
  raise ValueError("sorry, you lose")



The problem should be obvious -- it's not easy to see where the
conditional ends and the statement begins since they have the same
indentation.  Part of the problem, I suppose, is that Emacs indents
'height' and the other lines in the conditional to 4 spaces (because
of the parenthesis).  How do people deal with this situation?



Thanks,
Henrik



One possible solution



  if (
  width == 0 and
  height == 0 and
  color == 'red' and
  emphasis == 'strong' or
  highlight>100
 ):
  raise ValueError("sorry, you lose")



JM



I've always liked this, or even:



if (
width == 0 and
height == 0 and
color == 'red' and
emphasis == 'strong' or
highlight>100
):
raise ValueError("sorry, you lose")



but my co-workers have uniformly gone bananas whenever I try it.


I liked:

On 27-May-10 08:48 AM, Xavier Ho wrote:
  >  On 27 May 2010 22:22, HH  > 
 wrote:

  >
  >   if (width == 0 and
  >   height == 0 and
  >   color == 'red' and
  >   emphasis == 'strong' or
  >   highlight>  100):
  >   raise ValueError("sorry, you lose")
  >
  >
  >  I've gotta say - I've bumped into this problem before, and I'm sure many
  >  other have - this is a valid question. It just hasn't bothered me enough
  >  to ask...
  >
  >  Correct me if I'm wrong, but I think the following is equivalent, and
  >  looks better. Although this won't fix all ugly cases in that problem..
  >
  >  if (width, height, color, emphasis) == (0, 0, 'red', 'strong') or
  >  highlight>  100:
  >raise ValueError("sorry, you lose")
  >
  >  Cheers,
  >  Xav

but nobody commented.

Colin W.


Colin:
Sure, you can do it that way.  IMO, though, the OP was  wrong, and so
is the PEP.  Source code is meant to communicate.  So it must transmit
the correct information to the computer; it also must inform your
coworkers.  That means that you have a responsibility to care what
they think, though you privately have your opinions.  Another reason
the PEP is faulty in this circumstance is that a misplaced backslash,
or a missing one, is easily found and fixed.  A misplaced parentheses,
or just one of a pair, will transform your source code into something
which may compile and then give faulty results:  a disaster.
So keep it simple, and make it legible.
Yours,
John


IMHO complete garbage, if your editor doesn't show misplaced or missing 
parenthesis by highlighting you're using the wrong editor :)


Regards.

Mark Lawrence.


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


GUI programs

2010-05-29 Thread jyoung79
Just curious if anyone would be willing to share their thoughts 
about different Python GUI programming modules.  I've been 
doing a bit of research and am trying to find something that:

1.  Is portable.  Would like to be able to send the module along 
with the main python file that would be able to run a GUI 
window.  Would be sending this to multiple machines.  
Currently I'd like it to work on OS X machines, but it'd be nice 
if it worked on Windows machines, etc.  Probably be using 
Python 2.5 or 2.6.

2.  Can show an image (that is zoomable) as well as add GUI 
controls like text fields, popup menues, etc. as well as send 
information back to the program from the text fields, etc.  
For now, I'm really looking for something that can display 
EPS (postscript) and PDF images.

In my research, here's some GUI modules/programs I've been 
looking at.  I haven't gone real in-depth with these, but did 
just a little testing:

1.  wxPython - This looks very good, although I'm not sure 
how to set up portability with this.  Other machines that would 
run the Python code probably wouldn't have the Developer 
Tools or wxPython installed.  I think I could use Py2App for 
OS X to create a Package App but I'm not real familiar with 
how that would all work.

2.  Pyglet - This is a pretty cool program.  I was able to display 
a window with an image… but I don't think it has GUI controls 
like text fields, drop down menues, etc.

3.  ImageMagick - This one looks cool but I can't figure out how 
to install it correctly on OS X (Snow Leopard).  Not sure if it would 
give me the GUI tools either.

4.  PyGui - This one looks very interesting.  Just found it last night 
so haven't looked at it too closely.  Looks like it needs PyObjC on 
the machine for OS X.  I'm assuming that comes pre-installed on 
Snow Leopard machines, but not sure about Leopard or Tiger 
machines.  Anyone have more info about this?

5.  NodeBox - This is an incredible application!  Don't think I can 
use it's libraries for what I'm wanting to do, but what a cool 
program!  I will definitely spend some time working with this!

6.  TkInter - Does this module come standard on all machines 
that have Python?  Haven't worked with this one much, but if I 
send Python code to other machines would TkInter work?

Would love to hear anyones thoughts about GUI programming 
and what they use.  Would also like to hear pros/cons with the 
different modules/apps.  

Thanks for looking at my questions.

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


Python vs. Fedora and CentOS

2010-05-29 Thread Someone Something
Redhat as always believed in (sorry if this offends anyone): "Use legacy
stuff that works, we don't really give a flying hoot if the rest of the
world has moved on"


 On Sat, May 29, 2010 at 6:55 PM, D'Arcy J.M. Cain  wrote:

> On Sat, 29 May 2010 11:43:29 -0700
> John Nagle  wrote:
> >The major Red Hat based Linux distros are still shipping with Python
> 2.4.
> >
> >Is anybody trying to do something about this?
>
> Other than not running Linux on our hosting server?  My ISP
> (http://www.Vex.Net) runs FreeBSD.  Linux is for the desktop.
>
> --
> D'Arcy J.M. Cain  |  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
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Fedora and CentOS

2010-05-29 Thread Benjamin Kaplan
And since they're "using legacy stuff that works" from 3 years ago (no
one upgrades major versions of software in a minor release- hence Win
XP SP3 still coming with IE 6), it's no wonder that they're still on
2.4.

On Sat, May 29, 2010 at 9:05 PM, Someone Something  wrote:
>
> Redhat as always believed in (sorry if this offends anyone): "Use legacy
> stuff that works, we don't really give a flying hoot if the rest of the
> world has moved on"
>
> On Sat, May 29, 2010 at 6:55 PM, D'Arcy J.M. Cain  wrote:
>>
>> On Sat, 29 May 2010 11:43:29 -0700
>> John Nagle  wrote:
>> >    The major Red Hat based Linux distros are still shipping with Python
>> > 2.4.
>> >
>> >    Is anybody trying to do something about this?
>>
>> Other than not running Linux on our hosting server?  My ISP
>> (http://www.Vex.Net) runs FreeBSD.  Linux is for the desktop.
>>
>> --
>> D'Arcy J.M. Cain          |  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
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Where does "make altinstall" put stuff?

2010-05-29 Thread John Nagle

  I know that one is supposed to use "make altinstall" to install
versions of Python that won't be the "primary" version.  But what
directory names does it use for packages and other support files?
Is this documented somewhere?

  I want to make sure that no part of the existing Python installation
on Fedora Core is overwritten by an "altinstall" of 2.6.

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


Re: if, continuation and indentation

2010-05-29 Thread Nathan Rice
I prefer to just break such things into multiple lines.  You're doing that
already anyhow, it's not much of a speed hit, and it makes exactly what
you're testing explicit.  If I break a statement onto multiple lines I only
use parenthesis, and that is as a last resort.  In my opinion there's almost
always some combination of variable assignments and lambda expressions that
uses fewer lines and is clearer.

is_correct_style = width == 0 and height == 0 and color == 'red'
if (is_correct_style and emphasis == 'strong') or highlight > 100:


On Sat, May 29, 2010 at 8:59 PM, Mark Lawrence wrote:

> On 30/05/2010 01:23, john wrote:
>
>> On May 28, 10:37 am, "Colin J. Williams"
>> wrote:
>>
>>> On 28-May-10 05:54 AM, Jonathan Hartley wrote:
>>>
>>>  On May 27, 1:57 pm, Jean-Michel Pichavant
 wrote:

> HH wrote:
>
>> I have a question about best practices when it comes to line wrapping/
>> continuation and indentation, specifically in the case of an if
>> statement.
>>
>
>>>  When I write an if statement with many conditions, I prefer to use a
>> parenthesis around the whole block and get the implicit continuation,
>> rather than ending each line with an escape character.  Thus, using
>> the example from the style guide (http://www.python.org/dev/peps/
>> pep-0008/) I would write:
>>
>
>>>   if (width == 0 and
>>  height == 0 and
>>  color == 'red' and
>>  emphasis == 'strong' or
>>  highlight>100):
>>  raise ValueError("sorry, you lose")
>>
>
>>>  The problem should be obvious -- it's not easy to see where the
>> conditional ends and the statement begins since they have the same
>> indentation.  Part of the problem, I suppose, is that Emacs indents
>> 'height' and the other lines in the conditional to 4 spaces (because
>> of the parenthesis).  How do people deal with this situation?
>>
>
>>>  Thanks,
>> Henrik
>>
>
>>>  One possible solution
>

>>>   if (
>  width == 0 and
>  height == 0 and
>  color == 'red' and
>  emphasis == 'strong' or
>  highlight>100
> ):
>  raise ValueError("sorry, you lose")
>

>>>  JM
>

>>>  I've always liked this, or even:

>>>
>>> if (
width == 0 and
height == 0 and
color == 'red' and
emphasis == 'strong' or
highlight>100
):
raise ValueError("sorry, you lose")

>>>
>>>  but my co-workers have uniformly gone bananas whenever I try it.

>>>
>>> I liked:
>>>
>>> On 27-May-10 08:48 AM, Xavier Ho wrote:
>>>  >  On 27 May 2010 22:22, HH  >> [email protected]>>  wrote:
>>>
>>>  >
>>>  >   if (width == 0 and
>>>  >   height == 0 and
>>>  >   color == 'red' and
>>>  >   emphasis == 'strong' or
>>>  >   highlight>  100):
>>>  >   raise ValueError("sorry, you lose")
>>>  >
>>>  >
>>>  >  I've gotta say - I've bumped into this problem before, and I'm sure
>>> many
>>>  >  other have - this is a valid question. It just hasn't bothered me
>>> enough
>>>  >  to ask...
>>>  >
>>>  >  Correct me if I'm wrong, but I think the following is equivalent, and
>>>  >  looks better. Although this won't fix all ugly cases in that
>>> problem..
>>>  >
>>>  >  if (width, height, color, emphasis) == (0, 0, 'red', 'strong') or
>>>  >  highlight>  100:
>>>  >raise ValueError("sorry, you lose")
>>>  >
>>>  >  Cheers,
>>>  >  Xav
>>>
>>> but nobody commented.
>>>
>>> Colin W.
>>>
>>
>> Colin:
>> Sure, you can do it that way.  IMO, though, the OP was  wrong, and so
>> is the PEP.  Source code is meant to communicate.  So it must transmit
>> the correct information to the computer; it also must inform your
>> coworkers.  That means that you have a responsibility to care what
>> they think, though you privately have your opinions.  Another reason
>> the PEP is faulty in this circumstance is that a misplaced backslash,
>> or a missing one, is easily found and fixed.  A misplaced parentheses,
>> or just one of a pair, will transform your source code into something
>> which may compile and then give faulty results:  a disaster.
>> So keep it simple, and make it legible.
>> Yours,
>> John
>>
>
> IMHO complete garbage, if your editor doesn't show misplaced or missing
> parenthesis by highlighting you're using the wrong editor :)
>
> Regards.
>
> Mark Lawrence.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where does "make altinstall" put stuff?

2010-05-29 Thread James Mills
On Sun, May 30, 2010 at 4:06 PM, John Nagle  wrote:
> I know that one is supposed to use "make altinstall" to install
> versions of Python that won't be the "primary" version.  But what
> directory names does it use for packages and other support files?
> Is this documented somewhere?
>
>  I want to make sure that no part of the existing Python installation
> on Fedora Core is overwritten by an "altinstall" of 2.6.

Check the generated Makefile (created by ./configure)

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


Re: Where does "make altinstall" put stuff?

2010-05-29 Thread casevh
On May 29, 11:06 pm, John Nagle  wrote:
>    I know that one is supposed to use "make altinstall" to install
> versions of Python that won't be the "primary" version.  But what
> directory names does it use for packages and other support files?
> Is this documented somewhere?
>
>    I want to make sure that no part of the existing Python installation
> on Fedora Core is overwritten by an "altinstall" of 2.6.
>
>                                 John Nagle

It's placed in the directory specified by --prefix. If --prefix is not
specified, /usr/local is used by default.

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


MySQLdb install vs. "setuptools"

2010-05-29 Thread John Nagle

   MySQLdb won't install as non-root on Python 2.6 because
its "setup.py" file requires "setuptools".  "setuptools",
unlike "distutils", isn't part of the Python 2.6 distribution.

   IMPORTANT PACKAGES SHOULD NOT USE "setuptools".  Use the
standard "distutils".  "setuptools" and "eggs" create more
problems than they solve.  "setuptools" has many built-in
assumptions about where things are supposed to be, and they're
usually wrong.

   There's an "ez_setup.py" available for MySQLdb.  This tries to obtain and
install "setuptools".  But it wants too many privileges just to do a "build":

  The following error occurred while trying to add or remove files in the
   installation directory:

[Errno 2] No such file or directory: 
'/usr/local/lib/python2.6/site-packages/test-easy-install-22015.write-test'


   That's because "setuptools" has a built-in ego trip of insisting that
it should be installed globally.  I'm running a freshly-built, but not
"installed" version of Python 2.6.  I'm trying to install a test version
of Python2.6 with some packages without running as root on a live server.

   It's not just MySQLdb that's broken by "setuptools".  See these
examples of other installation problems created by "setuptools":

http://blog.awarelabs.com/2008/installing-mysqldb-without-python-egg-problems/
http://mail.python.org/pipermail/pythonmac-sig/2009-March/021148.html
http://plone.org/documentation/error/permission-denied-python-eggs

   As soon as "setuptools" becomes involved, unnecessary headaches appear.
DO NOT USE SETUPTOOLS.  Either use "distutils", or go all the way and
provide a RPM for Linux and a .exe for Windows.

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