Re: What happened to __cmp__() in Python 3.x?

2009-08-17 Thread Xavier Ho
On Sun, Aug 16, 2009 at 10:33 PM, Mark Lawrence wrote:

>
> I wasn't discussing __cmp__, I was referring to the quote by Chris Rebert
> from the Python docs regarding the rich comparison methods, a discrepancy
> between the documentation and the implementation as noted in the link that I
> gave, and an indication that the issue raised on this discrepancy is still
> open.  As Terry Reedy has mentioned __lt__ elsewhere, you should be aware of
> the discrepancy, otherwise you could go charging off down the wrong track.
>  FWIW it was Terry who raised the issue 4395, I'm sure that he could explain
> the ramifications of it all far better than I ever could, so I'll sign out.


Oh, I see. Thanks for informing then. =)

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


Re: get the pause status from amarok 2.1

2009-08-17 Thread Sleepy Cabbage
On Sat, 15 Aug 2009 09:25:19 +, Sleepy Cabbage wrote:

> On Fri, 14 Aug 2009 12:55:07 +0200, Diez B. Roggisch wrote:
> 
>> Sleepy Cabbage schrieb:
>>> As the title says, I'm trying to find a way to get the pause status
>>> from amarok 2.1.
>>> 
>>> I'm running kubuntu 9.04 with kde 4.2.2, python 2.6.2.
>>> 
>>> Thanks in advance.
>> 
>> Not at my linux-system right now, but dcop and the respective
>> python-module should help.
>> 
>> Diez
> 
> Thanks for you reply Diez. i'm sure that kde4.2 now uses qdbus instead
> of dcop and not sure whether amarok has the qdbus org.kde.amarok /Player
> GetStatus as it returns the following: qdbus: I don't know how to
> display an argument of type '()'

'dbus --literal org.kde.amarok /Player 
org.freedesktop.MediaPlayer.GetStatus'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get the pause status from amarok 2.1

2009-08-17 Thread Sleepy Cabbage
On Mon, 17 Aug 2009 07:23:55 +, Sleepy Cabbage wrote:

> On Sat, 15 Aug 2009 09:25:19 +, Sleepy Cabbage wrote:
> 
>> On Fri, 14 Aug 2009 12:55:07 +0200, Diez B. Roggisch wrote:
>> 
>>> Sleepy Cabbage schrieb:
 As the title says, I'm trying to find a way to get the pause status
 from amarok 2.1.
 
 I'm running kubuntu 9.04 with kde 4.2.2, python 2.6.2.
 
 Thanks in advance.
>>> 
>>> Not at my linux-system right now, but dcop and the respective
>>> python-module should help.
>>> 
>>> Diez
>> 
>> Thanks for you reply Diez. i'm sure that kde4.2 now uses qdbus instead
>> of dcop and not sure whether amarok has the qdbus org.kde.amarok
>> /Player GetStatus as it returns the following: qdbus: I don't know how
>> to display an argument of type '()'
> 
> 'dbus --literal org.kde.amarok /Player
> org.freedesktop.MediaPlayer.GetStatus'

Ref my last post: This works!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python doc available in emacs info format?

2009-08-17 Thread Xah Lee
info format for Xah Lee writes:
> in programing elisp in emacs, i can press “Ctrl+h f” to lookup
> the doc for the function under cursor.   is there such facility
> when coding in perl, python, php?


 On Dec 11 2008, 6:56 am, Matthias  wrote:
> Yes, try C-h S (or similarly  S):

>  (info-lookup-symbol SYMBOL &optional MODE)  Display the
> definition of SYMBOL, as found in the relevant manual. When this
> command is called interactively, it reads SYMBOL from the
> minibuffer.

> Note that `the relevant manual' means an info file. With recent
> emacsen on an Ubuntu distro, python arrives with info files and
> everything is well configured. It also works with bash, latex, perl,
> scheme, elisp, awk, texinfo, makefile, libc, or any info file with an
> index.

I noticed that Matthias actually mentioned that info docs is available
and bundled out of the box on Ubuntu linux for many popular langs, as
of 2008-12.

Is that true? Where can i download these info files? As far as i know,
a little google search or official doc sites usually don't have a
download for info format.

I'm interested in getting current version doc for perl, python, php,
and ruby.

Thanks.

  Xah
∑ http://xahlee.org/

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


Re: zip codes

2009-08-17 Thread Aahz
In article <[email protected]>,
Shailen   wrote:
>
>Is there any Python module that helps with US and foreign zip-code
>lookups? I'm thinking of something that provides basic mappings of zip
>to cities, city to zips, etc. Since this kind of information is so
>often used for basic user-registration, I'm assuming functionality of
>this sort must be available for Python. Any suggestions will be much
>appreciated.

There's no module; you have to purchase the information and then massage
it yourself.
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"I saw `cout' being shifted "Hello world" times to the left and stopped
right there."  --Steve Gonedes
-- 
http://mail.python.org/mailman/listinfo/python-list


zip codes

2009-08-17 Thread Shailen
Is there any Python module that helps with US and foreign zip-code
lookups? I'm thinking of something that provides basic mappings of zip
to cities, city to zips, etc. Since this kind of information is so
often used for basic user-registration, I'm assuming functionality of
this sort must be available for Python. Any suggestions will be much
appreciated.

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


Re: Python- javascript

2009-08-17 Thread Michel Claveau - MVP
Hi!

If you are under Windows, you can drive IE, for indirect drive the web-pages. 
In this case, you can then interact with pages & the javascript's scripts 
included.

For more, see Pywin32, Pamie, Pxie, etc.

@-salutations
-- 
Michel Claveau 

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


Re: zip codes

2009-08-17 Thread Martin P. Hellwig

Shailen wrote:

Is there any Python module that helps with US and foreign zip-code
lookups? I'm thinking of something that provides basic mappings of zip
to cities, city to zips, etc. Since this kind of information is so
often used for basic user-registration, I'm assuming functionality of
this sort must be available for Python. Any suggestions will be much
appreciated.

There might be an associated can of worms here, for example in the 
Netherlands zip codes are actually copyrighted and require a license if 
you want to do something with them, on the other hand you get a nice SQL 
formatted db to use it. I don't know how this works in other countries 
but I imagine that it is likely to be generally the same.


--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: Xah's Edu Corner: The importance of syntax & notations.

2009-08-17 Thread John Nagle

Xah Lee wrote:

Xah's Edu Corner: The importance of syntax & notations.

http://www.stephenwolfram.com/publications/recent/mathml/mathml_abstract.html

this article should teach the coding sophomorons and computer
“science” idiotic authors who harbor the notion that syntax is not
important, picked up by all the elite i-reddit & twittering &  hacker
news am-hip dunces.


   Definitely read Wolfram's paper.  He and his people actually had
to solve the problem.

   Wolfram had to face up to the big problem - how do we input traditional
mathematics into a computer unambiguously.  Version 1 was Mathematica
FullForm, which is very wordy but clear, like Ada.  This worked, but
was too clunky.  After a few redesigns, they came up with what he
calls StandardForm, which is Mathematica's variant on what he calls
"TraditionalForm", or mathematics as currently written in textbooks.
The differences are subtle; the main one is that precedence is more
explicit, and a "double strike" convention is used to disambiguate
certain meta-symbols, like the "d" used in derivatives and "i" used
as sqrt(-1).

StandardForm is unambiguous.  TraditionalForm is not, as anyone who
spends too much time reading other people's math publications realizes.
Cleverly, the Mathematica people have been able to produce a set of
heuristics which, Wolfram claims, allows converting traditional form
into the unambiguous StandardForm, getting it right most of the time.
(I've been struggling to read a paper on machine learning which has some
non-standard operator precedence problems, and I wish the paper was in
StandardForm.)

   Wolfram would, I think, like to make "StandardForm" the standard for
publication, and in time, something like that will probably happen.
It's useful to be able to get math in and out of symbolic manipulation
systems.

   Anyway, read the paper.

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


Re: zip codes

2009-08-17 Thread Sjoerd Mullender
Martin P. Hellwig wrote:
> Shailen wrote:
>> Is there any Python module that helps with US and foreign zip-code
>> lookups? I'm thinking of something that provides basic mappings of zip
>> to cities, city to zips, etc. Since this kind of information is so
>> often used for basic user-registration, I'm assuming functionality of
>> this sort must be available for Python. Any suggestions will be much
>> appreciated.
>>
> There might be an associated can of worms here, for example in the
> Netherlands zip codes are actually copyrighted and require a license if
> you want to do something with them, on the other hand you get a nice SQL
> formatted db to use it. I don't know how this works in other countries
> but I imagine that it is likely to be generally the same.
> 

Also in The Netherlands, ZIP codes are much more fine-grained than in
some other countries: ZIP code plus house number together are sufficient
to uniquely identify an address.  I.e. you don't need the street name.
E.g., my work address has ZIP code 1098 XG and house number 123, so
together they indicate that I work at Science Park 123, Amsterdam.

In other words, a simple city <-> ZIP mapping is not sufficient.

-- 
Sjoerd Mullender



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to use python to get True Full Duplex on a Serial port?

2009-08-17 Thread Hendrik van Rooyen
On Sunday 16 August 2009 15:55:31 Grant Edwards wrote:
> On 2009-08-15, Hendrik van Rooyen  wrote:

> > I am still confused about pyserial and serial - I found serial
> > in my distribution library, (on the SuSe machine, not on the
> > 2.5 in Slackware) but I had to download pyserial.
>
> That's very interesting.  Is the pre-existing "serial" a
> version of pyserial that the packager had pre-installed or is
> it something else?  I didn't know any distributions shipped

I am not too sure now - when I looked in the packages directory over the 
weekend it was there.  But I am really not sure how it got there - I cannot 
recall downloading it myself, but that means nothing as I have been using 
this machine for a while now, so it is possible that I did it some time ago 
and forgotten about it, without ever using it.   Possible, but unlikely. I 
would like to think that if I downloaded it, I would have tried it, and then 
I would have remembered.

Sorry to be so vague.

Does this help?

h...@linuxbox:~> python
Python 2.5.1 (r251:54863, Dec  6 2008, 10:49:39)
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> dir(serial)
['EIGHTBITS', 'FCNTL', 'FIVEBITS', 'FileLike', 'PARITY_EVEN', 'PARITY_NAMES',
 'PARITY_NONE', 'PARITY_ODD', 'SEVENBITS', 'SIXBITS', 'STOPBITS_ONE', 
'STOPBITS_TWO', 'Serial', 'SerialBase', 'SerialException', 
'SerialTimeoutException',
 'TERMIOS', 'TIOCINQ', 'TIOCMBIC', 'TIOCMBIS', 'TIOCMGET', 'TIOCMSET', 
'TIOCM_CAR', 
'TIOCM_CD', 'TIOCM_CTS', 'TIOCM_DSR', 'TIOCM_DTR', 'TIOCM_DTR_str', 'TIOCM_RI', 
'TIOCM_RNG', 'TIOCM_RTS', 'TIOCM_RTS_str', 'TIOCM_zero_str', 'VERSION', 'XOFF', 
'XON',
 '__builtins__', '__doc__', '__file__', '__name__', '__path__', 'device', 
'errno', 'fcntl', 'os', 'plat', 
'portNotOpenError', 'select', 'serialposix', 'serialutil', 'string', 'struct', 
'sys', 'termios', 'writeTimeoutError']
>>> serial.VERSION
'1.27'

- Hendrik

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


Re: Xah's Edu Corner: The importance of syntax & notations.

2009-08-17 Thread Xah Lee
2009-08-17

On Aug 16, 10:32 pm, Xah Lee  wrote:
> Personally, particular interesting info i've learned is that, for all
> my trouble in the past decade expressing problems of traditional math
> notation, i learned from his article this single-phrase summary:
> “traditional math notation lacks a grammar”.

> The article is somewhat disappointing though. I was expecting he'd go
> into some details about the science of math notations, or, as he put
> it aptly: “linguistics of math notations”. However, he didn't touch
> the subject, except saying that it haven't been studied.

upon a more detailed reading of Stephen's article, i discovered some
errors.

On this page:
http://www.stephenwolfram.com/publications/recent/mathml/mathml2.html

he mentions the Plimpton 322 tablet. It is widely taught in math
history books, that this table is pythagorean triples.

On reading his article, i wanted to refresh my understanding of the
subject, so i looked up Wikipedia:
http://en.wikipedia.org/wiki/Plimpton_322

and behold!

apparantly, in recent academic publications, it is suggested that this
is not pythagorean triples, but rather: “a list of regular reciprocal
pairs”.

  Xah
∑ http://xahlee.org/

☄

On Aug 15, 10:54 pm, Xah Lee  wrote:
> Xah's Edu Corner: The importance of syntax & notations.

>http://www.stephenwolfram.com/publications/recent/mathml/mathml_abstr...

> this article should teach the coding sophomorons and computer
> “science” idiotic authors who harbor the notion that syntax is not
> important, picked up by all the elite i-reddit & twittering &  hacker
> news am-hip dunces.

> Further readings:

> • The TeX Pestilence
>  http://xahlee.org/cmaci/notation/TeX_pestilence.html

> • A Notation for Plane Geometry
>  http://xahlee.org/cmaci/notation/plane_geometry_notation.html

> • The Concepts and Confusions of Prefix, Infix, Postfix and Fully
> Nested Notations
>  http://xahlee.org/UnixResource_dir/writ/notations.html

> • The Problems of Traditional Math Notation
>  http://xahlee.org/cmaci/notation/trad_math_notation.html
-- 
http://mail.python.org/mailman/listinfo/python-list


XML parsing with python

2009-08-17 Thread inder
Hi All,

I am new to xml . I need to parse the xml file . After reading and
browsing on the web , I could get much help .

I guess SAX would be better suited for my requirement .

Could some juct provide me a sample python code so that I can execute
it and see how the parsing actually happens .

Lets say my xml file -


 

I,Robot
100
Isaac Asimov


Blade Runner
400
Philip K. Dick




Lord Of The Rings
2
Tolkien


XML-Schema Specification
5000
W3C




Aladin
150
Don't know





--

I need the output to be - (elements containing 'title' )

I,Robot
Blade Runner
Lord Of The Rings
XML-Schema Specification
Aladin


Your responses are greatly appreciated .


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


Re: GUI interface builder for python

2009-08-17 Thread Hendrik van Rooyen
On Monday 17 August 2009 07:59:02 l...@d@n wrote:
> Which is the best GUI interface builder with drag and drop
> capabilities.
> I am using Ubuntu GNU/Linux.
> Please help me.
> Thank you.

Have a look at Boa Constructor.

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


Re: XML parsing with python

2009-08-17 Thread Stefan Behnel
inder wrote:
> I am new to xml . I need to parse the xml file . After reading and
> browsing on the web , I could get much help .
> 
> I guess SAX would be better suited for my requirement .

That's a common misconception.


> Could some juct provide me a sample python code so that I can execute
> it and see how the parsing actually happens .
> 
> Lets say my xml file -
> 
> 
>   
> I,Robot
> 100
> Isaac Asimov
> 
> 
> Blade Runner
> 400
> Philip K. Dick
> 
> 
> 
> 
> Lord Of The Rings
> 2
> Tolkien
> 
> 
> XML-Schema Specification
> 5000
> W3C
> 
> 
> 
> 
> Aladin
> 150
> Don't know
> 
> 
> 
> 
> 
> --
> 
> I need the output to be - (elements containing 'title' )
> 
> I,Robot
> Blade Runner
> Lord Of The Rings
> XML-Schema Specification
> Aladin

Use the iterparse() function of the xml.etree.ElementTree package.

http://effbot.org/zone/element-iterparse.htm
http://codespeak.net/lxml/parsing.html#iterparse-and-iterwalk

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


Re: sub-list extraction, logical indexation

2009-08-17 Thread Diez B. Roggisch
Pierre wrote:

> Hello Everyone,
> 
> I would like to know if it is possible to extract a sub-list from a
> list ?
> 
> typically if :
> 
> L =[[1, 2, 3],[4, 5, 6],[3] ]
> 
> How to extract easily the elements 0 and 2 of L in order to get :
> 
> L2 =[[1, 2, 3],[3] ]
> 
> Moreover, I would like to know if it is possible to use logical
> indexation such that :
> 
> index = [ True, False, True]
> L2 = L
> 
> or usual indexation, something like
> index=[0, 2]
> L2 = L
> 
> I tried, but failed...
> Thanks for your help


index = [ True, False, True]
L2 = [v for i, v in enumerate(L) if index[i]]

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


Re: zip codes

2009-08-17 Thread MRAB

Sjoerd Mullender wrote:

Martin P. Hellwig wrote:

Shailen wrote:

Is there any Python module that helps with US and foreign zip-code
lookups? I'm thinking of something that provides basic mappings of zip
to cities, city to zips, etc. Since this kind of information is so
often used for basic user-registration, I'm assuming functionality of
this sort must be available for Python. Any suggestions will be much
appreciated.


There might be an associated can of worms here, for example in the
Netherlands zip codes are actually copyrighted and require a license if
you want to do something with them, on the other hand you get a nice SQL
formatted db to use it. I don't know how this works in other countries
but I imagine that it is likely to be generally the same.



Also in The Netherlands, ZIP codes are much more fine-grained than in
some other countries: ZIP code plus house number together are sufficient
to uniquely identify an address.  I.e. you don't need the street name.
E.g., my work address has ZIP code 1098 XG and house number 123, so
together they indicate that I work at Science Park 123, Amsterdam.

In other words, a simple city <-> ZIP mapping is not sufficient.


The same comment applies to UK postcodes, which are also alphanumeric.
My home postcode, for example, is shared with only 3 other houses, IIRC.
--
http://mail.python.org/mailman/listinfo/python-list


Re: sub-list extraction, logical indexation

2009-08-17 Thread MRAB

Diez B. Roggisch wrote:

Pierre wrote:


Hello Everyone,

I would like to know if it is possible to extract a sub-list from a
list ?

typically if :

L =[[1, 2, 3],[4, 5, 6],[3] ]

How to extract easily the elements 0 and 2 of L in order to get :

L2 =[[1, 2, 3],[3] ]

Moreover, I would like to know if it is possible to use logical
indexation such that :

index = [ True, False, True]
L2 = L

or usual indexation, something like
index=[0, 2]
L2 = L

I tried, but failed...
Thanks for your help



index = [ True, False, True]
L2 = [v for i, v in enumerate(L) if index[i]]


Or:

L =[[1, 2, 3],[4, 5, 6],[3] ]
index = [ True, False, True]

from itertools import izip
L2 = [v for i, v in izip(index, L) if i]

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


Uninstalling mac python2.5 to install python2.6

2009-08-17 Thread Farhan Sheikh


Dear all,

i originally had python2.5 on my mac at the univeristy and had to get  
2.6 to get NEST and pyNN to work together. however now as those are  
now installed, i had to install numpy.


As i installed numpy, it only installed its directories into the  
python2.5 folders and as i am new to to mac terminals i don't know how  
to change its directories to be installed into python2.6. my question  
is, do i have to uninstall python 2.5 so that only python2.6 is on the  
machine or is there a way to change the path so it saves into python2.5?


Thanking You

Farhan

--
Academic Excellence at the Heart of Scotland.
The University of Stirling is a charity registered in Scotland, 
number SC 011159.


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


Re: python doc available in emacs info format?

2009-08-17 Thread Colin S. Miller

Xah Lee wrote:

btw, is there still info format for python doc?

i feel kinda sad that emacs info format has pretty much been
deprecated over the past decade. About a decade ago, you still will
see now and then people asking for emacs info format of docs (was the
days of perl). Today, one don't hear of it.

Part of this is due to emacs cult problem. See:



Xah,

Please do not slag off a project if you want people to help;
it tends to put the goat up.

It is not "Emacs Info" format, it is FSF Info format.
There is a stand-alone program to read the Info documentation.
The program is called "info".



Ubuntu maintains a package search site, it is on
http://packages.ubuntu.com/

However, there seems to be no files named
python.*info   (regexp)

There is a
python-docutils package
which does contain information in several
other formats.

This package can be found either via the above site
or using "apt-cache search python-doc".


As "info" is a FSF format, all FSF produced programs
will provide documentation in this format. However Python
is not under the auspices of the FSF, so does not need to use
this format.


BTW,
HTML versions of INFO documentation can be generated by
info2html or info_to_html on them, or texi2html on the source.


Have a nice day,
Colin S. Miller



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


Re: wxFormBuilder finally supports wxPython

2009-08-17 Thread sturlamolden
On 16 Aug, 20:32, Nobody  wrote:

> Is there a reason to prefer code over XRC?

There is less boilerplate code required. E.g. event handlers are bound
in the GUI builder. You can access GUI objects as attributes of your
Python class. You don't need to request them from an xml. But apart
from that, XRC works well too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread exarkun

On 02:12 am, [email protected] wrote:

On Aug 16, 3:35�pm, sturlamolden  wrote:

On 16 Aug, 14:57, Dennis Lee Bieber  wrote:

>         Well, the alternative would be to have two keywords for 
looping: one
> for your "simple" incrementing integer loop, and another for a loop 
that

> operates over the elements of some collection type.

A compiler could easily recognise a statement like

� �for i in range(n):

as a simple integer loop.


It would be a simple to do if you were writing it for a different
langauge was a lot less dynamic than Python is.  It'd be quite a
complex hack to add it to CPython's compiler while maintaing the
current highly dynamic runtime semantics and backwards compatibility,
which is a design constraint of Python whether you like it or not.


In your other message, you said this wasn't a legitimate CPython 
complaint.  Here, you say that it would be a "complex hack" to implement 
this in CPython.  "complex hack" has negative connotations in my mind. 
This seems contradictory to me.


And all this complaining about an issue that can be worked around by
xrange instead of range.  Sheesh.


Sure.  The specific issue of range vs xrange is quite a small one. 
There is a slightly larger one regarding the flexibility (or relative 
lack thereof) of the CPython runtime, though.


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


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread exarkun

On 01:53 am, [email protected] wrote:

On Aug 16, 6:28�pm, [email protected] wrote:

On 01:23 am, [email protected] wrote:

>On Sun, Aug 16, 2009 at 6:35 PM, sturlamolden 
>wrote:

>>A compiler could easily recognise a statement like

>>� for i in range(n):

>>as a simple integer loop. In fact, Cython is able to do this.

>but special cases aren't special enough to break the rules.

Although I think PyPy also recognizes this case and makes it as
efficient as using xrange, and does so without breaking any rules.


PyPy uses a JIT compiler (which is still slower than CPython,
suggesting that perhaps they should have spent more time optimizing
the general case than optimizing for an easily avoided special case).


It's true that PyPy has a JIT compiler (which is still slower than 
CPython).  However, this isn't where the range speedup comes from.  The 
range optimization is handled specifically in the implementation of 
range (or possibly of list, or a combination of the two, I can't 
remember exactly).  It's effective even when the JIT compiler is 
disabled.



There *are* _some_ legitimate complaints to be made about the CPython
runtime. :)


This isn't one of them.

xrange has been part of Python for 10 years.

If there are any complaints to be made about this situation it's that
there are any 2.x learning materials anythere that continue to use
range() and not xrange() in this context.


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


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread exarkun

On 01:44 am, http wrote:

[email protected] writes:

Although I think PyPy also recognizes this case and makes it as
efficient as using xrange, and does so without breaking any rules.


How can pypy possibly know that the user hasn't assigned some other
value to "range"?


It doesn't really need to.  The optimization isn't applied when the 
compiler sees the name "range" being called.  It's applied after the 
object the default builtin name "range" is bound to is called.


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


Re: GUI interface builder for python

2009-08-17 Thread sturlamolden
On 16 Aug, 22:59, "l...@d@n"  wrote:
> Which is the best GUI interface builder with drag and drop
> capabilities.
> I am using Ubuntu GNU/Linux.
> Please help me.
> Thank you.

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


Re: GUI interface builder for python

2009-08-17 Thread sturlamolden
On 16 Aug, 22:59, "l...@d@n"  wrote:
> Which is the best GUI interface builder with drag and drop
> capabilities.
> I am using Ubuntu GNU/Linux.


PyGTK --> GLADE

xwPython --> wxFormBuilder

PyQt --> QtDesigner



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


Re: sub-list extraction, logical indexation

2009-08-17 Thread Vlastimil Brom
2009/8/17 MRAB :
> Diez B. Roggisch wrote:
>>
>> Pierre wrote:
>>
>>> Hello Everyone,
>>>
>>> I would like to know if it is possible to extract a sub-list from a
>>> list ?
>>>
>>> typically if :
>>>
>>> L =[[1, 2, 3],[4, 5, 6],[3] ]
>>>
>>> How to extract easily the elements 0 and 2 of L in order to get :
>>>
>>> L2 =[[1, 2, 3],[3] ]
>>>
>>> Moreover, I would like to know if it is possible to use logical
>>> indexation such that :
>>>
>>> index = [ True, False, True]
>>> L2 = L
>>>
>>> or usual indexation, something like
>>> index=[0, 2]
>>> L2 = L
>>>
>>> I tried, but failed...
>>> Thanks for your help
>>
>>
>> index = [ True, False, True]
>> L2 = [v for i, v in enumerate(L) if index[i]]
>>
> Or:
>
> L =[[1, 2, 3],[4, 5, 6],[3] ]
> index = [ True, False, True]
>
> from itertools import izip
> L2 = [v for i, v in izip(index, L) if i]
>
Or in python 3.1

>>> import itertools
>>> list(itertools.compress(data=[[1, 2, 3], [4, 5, 6], [3]], selectors=[True, 
>>> False, True]))
[[1, 2, 3], [3]]

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


Re: ignored test cases in unittest

2009-08-17 Thread David House
2009/8/16 Terry :
> Thanks for the solutions. I think the decorator idea is what I'm look
> for:-)

Note that the unittest module now supports the `skip' and
`expectedFailure' decorators, which seem to describe some of the
solutions here.

See 
http://docs.python.org/3.1/library/unittest.html#skipping-tests-and-expected-failures

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


Re: callable virtual method

2009-08-17 Thread Bruno Desthuilliers

Jean-Michel Pichavant a écrit :
(snip)

Sometimes the base is doing cool stuff but incomplete stuff which 
requires knowledge only hold by the sub class. In my case the interface 
is a high level interface for a software that can run on multiple 
hardware platforms. Only the sub class has knowledge on how to operate 
the hardware, but no matter the hardware it still produces the same effect.


Let's say I have 50 different hardwares, I'll have 50 sub classes of 
Interface with the 'start' method to define. It wouldn't be appropriate 
(OO programming)to write 50 times '_log.debug('Starting %s' % self)' in 
each child start method when the simple task of logging the call can be 
nicely handled by the base class.


Which is exactly one of the use cases for the Template Method pattern in 
traditional OO design.


For the record, Python can offer other solutions to this kind of problem 
- like a combination of decorators and metaclasses.


In the meantime, I must make sure  the user, who is not a python guru in 
this case, has implemented the start method for his hardware,


whether he has to implement the 'start' or '_start' method doesn't make 
any difference here.


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


Re: callable virtual method

2009-08-17 Thread Bruno Desthuilliers

Jean-Michel Pichavant a écrit :

Scott David Daniels wrote:

(snip)

But there _is_ one moment when you can check those things, then avoid
checking thereafter: object creation.  So you can complicate your
__init__ (or __new__) with those checks that make sure you instantiate
only fully defined subclasses:


That's something I'd rather do in a custom metaclass. But YMMV, of course...

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


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread sturlamolden
On 16 Aug, 19:12, Carl Banks  wrote:

> If you don't care about the dynamic stuff why don't you just use
> Cython?  Or quit complaining and just use xrange.

I think you are the only one complaining here.



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


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread MRAB

[email protected] wrote:

On 02:12 am, [email protected] wrote:

On Aug 16, 3:35�pm, sturlamolden  wrote:

On 16 Aug, 14:57, Dennis Lee Bieber  wrote:

> � � � � Well, the alternative would be to have two keywords for 
looping: one
> for your "simple" incrementing integer loop, and another for a loop 
that

> operates over the elements of some collection type.

A compiler could easily recognise a statement like

� �for i in range(n):

as a simple integer loop.


It would be a simple to do if you were writing it for a different
langauge was a lot less dynamic than Python is.  It'd be quite a
complex hack to add it to CPython's compiler while maintaing the
current highly dynamic runtime semantics and backwards compatibility,
which is a design constraint of Python whether you like it or not.


In your other message, you said this wasn't a legitimate CPython 
complaint.  Here, you say that it would be a "complex hack" to implement 
this in CPython.  "complex hack" has negative connotations in my mind. 
This seems contradictory to me.


And all this complaining about an issue that can be worked around by
xrange instead of range.  Sheesh.


Sure.  The specific issue of range vs xrange is quite a small one. There 
is a slightly larger one regarding the flexibility (or relative lack 
thereof) of the CPython runtime, though.



A possible solution would be to make 'range' return an instance of, say,
'RangeList', a subclass of list which would behave like 'list'
externally but create the list of values internally only when needed.
--
http://mail.python.org/mailman/listinfo/python-list


Re: zip codes

2009-08-17 Thread steven.oldner
On Aug 17, 5:21 am, MRAB  wrote:
> Sjoerd Mullender wrote:
> > Martin P. Hellwig wrote:
> >> Shailen wrote:
> >>> Is there any Python module that helps with US and foreign zip-code
> >>> lookups? I'm thinking of something that provides basic mappings of zip
> >>> to cities, city to zips, etc. Since this kind of information is so
> >>> often used for basic user-registration, I'm assuming functionality of
> >>> this sort must be available for Python. Any suggestions will be much
> >>> appreciated.
>
> >> There might be an associated can of worms here, for example in the
> >> Netherlands zip codes are actually copyrighted and require a license if
> >> you want to do something with them, on the other hand you get a nice SQL
> >> formatted db to use it. I don't know how this works in other countries
> >> but I imagine that it is likely to be generally the same.
>
> > Also in The Netherlands, ZIP codes are much more fine-grained than in
> > some other countries: ZIP code plus house number together are sufficient
> > to uniquely identify an address.  I.e. you don't need the street name.
> > E.g., my work address has ZIP code 1098 XG and house number 123, so
> > together they indicate that I work at Science Park 123, Amsterdam.
>
> > In other words, a simple city <-> ZIP mapping is not sufficient.
>
> The same comment applies to UK postcodes, which are also alphanumeric.
> My home postcode, for example, is shared with only 3 other houses, IIRC.- 
> Hide quoted text -
>
> - Show quoted text -

Google for Zip codes.  There are some free databases of codes, but
they are dated.  USPS and 3 party vendors sell zip code databases and
lists.  The USPS APIs are a joke.  They were going to charge me for
using them.

I ended up using a 2 year old database of ZIP codes for my needs.

Hope this helps!

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


Re: platform-specific overrides of functions and class methods (expanding on imputils demo code)

2009-08-17 Thread lkcl
thought that people might like to know: i found also that imputil, the
standard python module, was lacking the necessary complexity in being
a substitute for the standard __import__ function.

the additions required were very simple:

# note the addition of level=-1 which is ignored

def _import_hook(self, fqname, globals=None, locals=None,
fromlist=None,
   level=-1):

.

# Grrr, some people "import os.path" or do "from os.path
import ..."
if len(parts) == 2 and hasattr(top_module, parts[1]):
if fromlist:
return getattr(top_module, parts[1])
else:
return top_module

# assume that the module has already been imported,
# walk from top_module to find it.
mod = top_module

for k in parts[1:]:
if not hasattr(mod, k):
print "no mod", mod, k, parts
mod = None
break
mod = getattr(mod, k)

if mod:
return mod

# If the importer does not exist, then we have to bail. A
missing
# importer means that something else imported the module, and
we have
# no knowledge of how to get sub-modules out of the thing.
raise ImportError, 'No module named ' + fqname

it's the module-walking that's been added: going from the "top"
module, looking for an attribute of the split-parts.  this code makes
the assumption that if top module already exists, and it has a sub-
module, and that has a sub-sub-module, and that has a sub-sub-sub-
module etc. then it is perfectly reasonable to return that pre-
existing, already-imported [sub-]+ module as the return result.

the reason why this had to be added is because comtypes.gen.{some
module} auto-generator relies on it, and calls __import__ *direct*.

if somebody would like to add this to the python bugtracker, as a
contribution, that would be great.  alternatively, you might like to
have a word with the python developers to get them to remove the
censorship on my contributions.

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


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Stefan Behnel
Carl Banks wrote:
> On Aug 16, 3:35 pm, sturlamolden  wrote:
>> On 16 Aug, 14:57, Dennis Lee Bieber  wrote:
>>
>>> Well, the alternative would be to have two keywords for looping: one
>>> for your "simple" incrementing integer loop, and another for a loop that
>>> operates over the elements of some collection type.
>> A compiler could easily recognise a statement like
>>
>>for i in range(n):
>>
>> as a simple integer loop.
>> 
>> In fact, Cython is able to do this.
> 
> Cython can do this easily because it is a different language that is a
> lot less dynamic than Python.

Actually, Cython is able to do this because it knows the global scope of a
module. The only thing that this optimisation makes impossible when you
compile your module using Cython is to inject builtins into the module
namespace *after* the compilation, either by assigning module attributes or
by importing the module into a custom namespace.

Given that both use cases are extremely rare, it was decided that
optimisations like this are more important than the ability to redefine the
most common builtins (such as 'range' or 'enumerate'). So, in a way, Cython
really makes them "builtins".

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


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Steven D'Aprano
On Sun, 16 Aug 2009 15:35:26 -0700, sturlamolden wrote:

> On 16 Aug, 14:57, Dennis Lee Bieber  wrote:
> 
>>         Well, the alternative would be to have two keywords for
>>         looping: one
>> for your "simple" incrementing integer loop, and another for a loop
>> that operates over the elements of some collection type.
> 
> A compiler could easily recognise a statement like
> 
>for i in range(n):
> 
> as a simple integer loop. 

"Easily" huh? Would you like to put a small wager on that?

Here is an unedited copy-and-paste of the last few lines of an 
interactive Python session:

>>> for i in range(5):
... print i
...
0
1
2
Surprise!
4
>>> __builtins__.range is range
True


Can you determine how I did this? How would the compiler avoid this? If 
you can find a method for the compiler to avoid surprises like this, why 
do you think it would be valuable to add all that extra complexity to the 
language? (As opposed to an external tool like Cython.)



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


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Stefan Behnel
John Machin wrote:
> On Aug 17, 8:35 am, sturlamolden  wrote:
> 
>> A compiler could easily recognise a statement like
>>for i in range(n):
>> as a simple integer loop. In fact, Cython is able to do this.
> 
> Extremely easy, once users relinquish the right to replace built-in
> "range" with their own concoctions ...

Cython allows you to do that. You just have to do it inside the module. If
Cython determines that "range" refers the global builtin name, it will
enable the loop optimisation. If you assign anything to that global name
inside your module (even the range function itself), this will disable the
optimisation.

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


Re: ignored test cases in unittest

2009-08-17 Thread Terry Yin
On Aug 17, 8:23 pm, David House  wrote: > > Note that the
unittest module now supports the `skip' and > `expectedFailure' decorators,
which seem to describe some of the > solutions here. > > Seehttp://
docs.python.org/3.1/library/unittest.html#skipping-tests-and-e... > > -- >
-David Yes, indeed! I'm using 2.6 now. It seemed I need to copy untitest.py
from 3.1. But the docs.python.org is hell slow from where I am (China), not
even working except the title:-( br, Terry

On Mon, Aug 17, 2009 at 8:23 PM, David House  wrote:

> 2009/8/16 Terry :
> > Thanks for the solutions. I think the decorator idea is what I'm look
> > for:-)
>
> Note that the unittest module now supports the `skip' and
> `expectedFailure' decorators, which seem to describe some of the
> solutions here.
>
> See
> http://docs.python.org/3.1/library/unittest.html#skipping-tests-and-expected-failures
>
> --
> -David
>



-- 
-
Blog: http://terry-yinzhe.spaces.live.com/
twitter: http://twitter.com/terryyin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread David Robinow
On Sun, Aug 16, 2009 at 11:10 PM, Nobody wrote:
> Java also has iterators; it's more a case of people coming from C and BASIC.
>
> Although, some of those may have come *through* Java without abandoning
> old habits. You see the same thing with people coming from BASIC to C and
> writing:
>
>        #define NUM_DATES 50
>        int day[NUM_DATES], month[NUM_DATES], year[NUM_DATES];
>
> rather than defining a "struct".
>
> Sometimes referred to as "I know ten languages and can write in BASIC in
> all of them".

Ha, ha. I learned that pattern in Fortran. I confess to having written
code like that in C. I think I've gotten over it.
-- 
http://mail.python.org/mailman/listinfo/python-list


off topic: google groups sucks?

2009-08-17 Thread Aaron Watters
Just a note.  It seems that google groups is increasing the
sucks coefficient.

I search for things using "group search" for comp.lang.python
and I get no results even though I know there are results from
a few months or weeks ago.

What is the best alternative for this kind of trawling?  gmane?

With all the smart people working at google how can they
 up like this?

Inquiring minds want to know.

   -- Aaron Watters

===
Sisyphus got ripped.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: off topic: google groups sucks?

2009-08-17 Thread jkn
On Aug 17, 3:05 pm, Aaron Watters  wrote:
> Just a note.  It seems that google groups is increasing the
> sucks coefficient.
>
> I search for things using "group search" for comp.lang.python
> and I get no results even though I know there are results from
> a few months or weeks ago.

There seems to be a problem with Google Searching 'at the moment'. I
have seen it with other groups, but not noticed it to date on c.l.p.


http://groups.google.com/group/groupsknownissues/browse_thread/thread/d88d02f269a7d20d#

J^n
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: httplib incredibly slow :-(

2009-08-17 Thread Chris Withers

i3dmaster wrote:

Just wanted to check if you can try turning on the debug mode for
httplib and see if you can read a bit more debug info on where the
calls get hung. In your example, it would be conn.set_debuglevel(1)


I had a look through the code this debug level controls and I don't see 
any information that this provides which would help here...


Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: off topic: google groups sucks?

2009-08-17 Thread Stefan Behnel
jkn wrote:
> On Aug 17, 3:05 pm, Aaron Watters  wrote:
>> Just a note.  It seems that google groups is increasing the
>> sucks coefficient.
>>
>> I search for things using "group search" for comp.lang.python
>> and I get no results even though I know there are results from
>> a few months or weeks ago.
> 
> There seems to be a problem with Google Searching 'at the moment'. I
> have seen it with other groups, but not noticed it to date on c.l.p.
> 
> 
> http://groups.google.com/group/groupsknownissues/browse_thread/thread/d88d02f269a7d20d#

I noticed a problem with Google in general this weekend, not even related
to mailing lists. I can't remember getting similarly bad results from a web
search for years. Even trivial queries that worked for months returned
completely unrelated pages and lacked the "obvious" target page in the
result set.

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


Re: XML parsing with python

2009-08-17 Thread John Posner



Use the iterparse() function of the xml.etree.ElementTree package.

http://effbot.org/zone/element-iterparse.htm
http://codespeak.net/lxml/parsing.html#iterparse-and-iterwalk

Stefan
  


iterparse() is too big a hammer for this purpose, IMO. How about this:

 from xml.etree.ElementTree import ElementTree
 tree = ElementTree(None, "myfile.xml")
 for elem in tree.findall('//book/title'):
 print elem.text


-John

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


Re: zip codes

2009-08-17 Thread Nigel Rantor

MRAB wrote:

Sjoerd Mullender wrote:

Martin P. Hellwig wrote:

Shailen wrote:

Is there any Python module that helps with US and foreign zip-code
lookups? I'm thinking of something that provides basic mappings of zip
to cities, city to zips, etc. Since this kind of information is so
often used for basic user-registration, I'm assuming functionality of
this sort must be available for Python. Any suggestions will be much
appreciated.


There might be an associated can of worms here, for example in the
Netherlands zip codes are actually copyrighted and require a license if
you want to do something with them, on the other hand you get a nice SQL
formatted db to use it. I don't know how this works in other countries
but I imagine that it is likely to be generally the same.



Also in The Netherlands, ZIP codes are much more fine-grained than in
some other countries: ZIP code plus house number together are sufficient
to uniquely identify an address.  I.e. you don't need the street name.
E.g., my work address has ZIP code 1098 XG and house number 123, so
together they indicate that I work at Science Park 123, Amsterdam.

In other words, a simple city <-> ZIP mapping is not sufficient.


The same comment applies to UK postcodes, which are also alphanumeric.
My home postcode, for example, is shared with only 3 other houses, IIRC.


Kind of off-topic...but nevertheless...

Yes, the UK postcode database (PAF) can be bought from the Royal Mail 
for a fee.


The data cannot be copyright, but the version they maintain and 
distribute is.


As an aside, the PAF has finer grained information than simply the 
postal code, every letterbox in the UK has (or is meant to) a DPS 
(delivery point suffix), so that given a post code and DPS you can 
uniquely identify individual letterbox even when, for example, a house 
has been split into multiple flats.


So, nastily, you *can* identify individual letterboxes, but the Royal 
Mail does not publicise the fact, so you cannot actually look at a post 
code on a letter and determine the letterbox it is intended for.


Shame really.

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


Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Aahz
In article <461cc6f1-fc23-4bc7-a719-6f29babf8...@o15g2000yqm.googlegroups.com>,
Robert Dailey   wrote:
>
>It's a figure of speech. And besides, why would I want programming
>advice from a woman? lol. Thanks for the help.

Well, I'm sorry to see this, it means I was wrong about the lack of
sexism in the Python community.  I encourage anyone who wants to improve
the situation to join the new diversity list:

http://mail.python.org/mailman/listinfo/diversity
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"I saw `cout' being shifted "Hello world" times to the left and stopped
right there."  --Steve Gonedes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need cleanup advice for multiline string

2009-08-17 Thread Grant Edwards
On 2009-08-11, Bearophile  wrote:
> Robert Dailey:
>
>> This breaks the flow of scope. Would you guys solve this
>> problem by moving failMsg into global scope? Perhaps through
>> some other type of syntax?
>
> There are gals too here.

Straying a bit OT, but I find this particular issue rather
fascinating.

At least in the US, "guys" is now pretty much gender-neutral
according to my casual research (mostly just paying attention
to informal speach).

Oddly, it still seems to be masculine when singular. Though one
commonly hears a group of females addressed as "you guys" or
refered to as "those guys", one never hears a single female
referred to as "a guy" or "that guy".

It is a bit tricky, however, since a phrase like "a group of
guys" still seems to refer to just males since the word "guys"
in that case is being applied individually to a plurality of
persons rather being applied collectivelly to a single group --
if that makes any sense.

I've actually discussed this with a a number of female friends,
and they almost all thought the term "gals" was condescending
and actually preferred to be referred to collectively as
"guys".

-- 
Grant Edwards   grante Yow! You can't hurt me!!
  at   I have an ASSUMABLE
   visi.comMORTGAGE!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: off topic: google groups sucks?

2009-08-17 Thread Aaron Watters
On Aug 17, 10:05 am, Aaron Watters  wrote:
> Just a note.  It seems that google groups is increasing the
> sucks coefficient.

I'm having better luck now using the advanced search option
with queries like

   gadfly group:comp.lang.python

which become

   http://groups.google.com/groups/search?q=gadfly+group:comp.lang.python

The "search this group" feature still needs fixing, however.

  -- Aaron Watters

===
if you lined up all economists end to end
they'd still point in different directions.
   -- stolen from somewhere
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need cleanup advice for multiline string

2009-08-17 Thread Jean-Michel Pichavant

Grant Edwards wrote:

On 2009-08-11, Bearophile  wrote:
  

Robert Dailey:



This breaks the flow of scope. Would you guys solve this
problem by moving failMsg into global scope? Perhaps through
some other type of syntax?
  

There are gals too here.



Straying a bit OT, but I find this particular issue rather
fascinating.

At least in the US, "guys" is now pretty much gender-neutral
according to my casual research (mostly just paying attention
to informal speach).

Oddly, it still seems to be masculine when singular. Though one
commonly hears a group of females addressed as "you guys" or
refered to as "those guys", one never hears a single female
referred to as "a guy" or "that guy".

It is a bit tricky, however, since a phrase like "a group of
guys" still seems to refer to just males since the word "guys"
in that case is being applied individually to a plurality of
persons rather being applied collectivelly to a single group --
if that makes any sense.

I've actually discussed this with a a number of female friends,
and they almost all thought the term "gals" was condescending
and actually preferred to be referred to collectively as
"guys".

  
I'm no English native, but I already heard women/men referring to a 
group as "guys", no matter that group gender configuration. It's even 
used for group composed exclusively of women. Moreover it looks like a 
*very* friendly form, so there is really nothing to worry about it.


Forms like:
"Hi guys", "You guys should do something...", "Come on guys..." are very 
friendly and gender-neutral.


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


Re: Need cleanup advice for multiline string

2009-08-17 Thread Piet van Oostrum
> Simon Brunning  (SB) wrote:

>SB> 2009/8/11 Robert Dailey :
>>> On Aug 11, 3:40 pm, Bearophile  wrote:
 There are gals too here.
>>> 
>>> It's a figure of speech. And besides, why would I want programming
>>> advice from a woman? lol. Thanks for the help.

>SB> Give the attitudes still prevalent in our industry (cf
>SB>  and many more), I'm sorry to say that I
>SB> don't think this is funny.

seconded
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Ethan Furman

Emmanuel Surleau wrote:

Dr. Phillip M. Feldman wrote:



[snip]



def is_prime(n):
  for j in range(2,n):
 if (n % j) == 0: return False
  return True

It seems as though Python is actually expanding range(2,n) into a list of
numbers, even though this is incredibly wasteful of memory. There should
be a looping mechanism that generates the index variable values
incrementally as they are needed.



[snip]
>>

I will also observe that if you were to stop programming whatever
language you are more familiar with in Python, and start programming
Python in Python, you'll have an easier time of it.



I don't see what's particularly un-Pythonic with this code. Not using xrange() 
is a mistake, certainly, but it remains clear, easily understandable code 
which correctly demonstrates the naive algorithm for detecting whether n is a 
prime. It doesn't call for condescension



[snip]
>

Cheers,

Emm


My comment about programming Python in Python was geared more towards 
the subject line than the actual code, and the biases evident in his 
comments in both this thread and earlier ones.


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


Re: Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Jean-Michel Pichavant

Aahz wrote:

In article <461cc6f1-fc23-4bc7-a719-6f29babf8...@o15g2000yqm.googlegroups.com>,
Robert Dailey   wrote:
  

It's a figure of speech. And besides, why would I want programming
advice from a woman? lol. Thanks for the help.



Well, I'm sorry to see this, it means I was wrong about the lack of
sexism in the Python community.  I encourage anyone who wants to improve
the situation to join the new diversity list:

http://mail.python.org/mailman/listinfo/diversity
  
Are you suggesting this list reject part of the community regarding its 
sexual orientation, ethnicity, size, culture? If that was the case I'd 
like to know about it.
I would really want to know how you'd guess my gender (could be some 
clue somewhere), my sexual orientation, my religion and so on.

How can you reject someone regarding informations you don't have ?

That's the beauty of this mailing list, it has diversity, by design.
We even welcome people that mixes up joke with sexist aggression, not to 
mention how open minded we are :o)


Beside, the day you'll meet a real act of sexism in this list, please 
know that people talk and act on their own, do not assign their attitude 
to the whole community.
You'll know that Python is sexist the day you'll find the title 'No 
women allowed' on the python main document page.


JM

PS : Newbies are not welcome here !


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


Re: Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Rami Chowdhury
You'll know that Python is sexist the day you'll find the title 'No  
women allowed' on the python main document page.


Good God I hope you're being ironic.

On Mon, 17 Aug 2009 10:23:39 -0700, Jean-Michel Pichavant  
 wrote:



Aahz wrote:
In article  
<461cc6f1-fc23-4bc7-a719-6f29babf8...@o15g2000yqm.googlegroups.com>,

Robert Dailey   wrote:


It's a figure of speech. And besides, why would I want programming
advice from a woman? lol. Thanks for the help.



Well, I'm sorry to see this, it means I was wrong about the lack of
sexism in the Python community.  I encourage anyone who wants to improve
the situation to join the new diversity list:

http://mail.python.org/mailman/listinfo/diversity

Are you suggesting this list reject part of the community regarding its  
sexual orientation, ethnicity, size, culture? If that was the case I'd  
like to know about it.
I would really want to know how you'd guess my gender (could be some  
clue somewhere), my sexual orientation, my religion and so on.

How can you reject someone regarding informations you don't have ?

That's the beauty of this mailing list, it has diversity, by design.
We even welcome people that mixes up joke with sexist aggression, not to  
mention how open minded we are :o)


Beside, the day you'll meet a real act of sexism in this list, please  
know that people talk and act on their own, do not assign their attitude  
to the whole community.
You'll know that Python is sexist the day you'll find the title 'No  
women allowed' on the python main document page.


JM

PS : Newbies are not welcome here !






--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: flatten a list of list

2009-08-17 Thread Tim Cook
On Aug 16, 6:47 am, Terry  wrote:
> Hi,
>
> Is there a simple way (the pythonic way) to flatten a list of list?
> rather than my current solution:
>
> new_list=[]
> for l in list_of_list:
>     new_list.extend(l)
>
> or,
>
> new_list=reduce(lambda x,y:x.extend(y), list_of_list)
>
> br, Terry

Well, This is not simple but it is comprhensive in that it has to do
several things.  I am using it to decompose deeply nested lists from
Pyparsing output that may have strings in a variety of languages.
Performance wise I do not know how it stacks up against the other
examples but it works for me.  :-)

def flatten(x):
"""flatten(sequence) -> list

Returns a single, flat list which contains all elements retrieved
from the sequence and all recursively contained sub-sequences
(iterables). All strings are converted to unicode.

"""
result = []
for el in x:
#if isinstance(el, (list, tuple)):
if hasattr(el, "__iter__") and not isinstance(el, basestring):
result.extend(flatten(el))
else:
result.append(el)


# all strings must be unicode
rtnlist=[]
for x in result:
if isinstance(x,str):
# replace any brackets so Python doesn't think it's a list
and we still have a seperator.
x=x.replace('[','_')
x=x.replace(']','_')
try:
x=unicode(x, "utf8")  # need more decode types here
except UnicodeDecodeError:
x=unicode(x, "latin1")
except UnicodeDecodeError:
x=unicode(x,"iso-8859-1")
except UnicodeDecodeError:
x=unicode(x,"eucJP")

rtnlist.append(x)

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


Using a Callback Function - ftplib

2009-08-17 Thread seldan24
Hello,

I'm utterly confused by something which is most likely trivial.  I'm
attempting to connect to an FTP server, retrieve a list of files, and
store than in an array.  I.e.:

import ftplib

ftp = ftplib.FTP(server)
ftp.login(user, pass)
ftp.cwd(conf['testdir'])
ftp.retrlines('NLST ' + "testfile*.txt")
ftp.quit()

The above example works fine... and would return a list of any files
that match "testfile*.txt" to standard out.  The issue is I don't want
that to go to stdout, I'd rather capture them within an array so I can
retrieve them later.

If I try something like:

my_files = ftp.retrlines('NLST ' + "testfile*.txt")

Then, my_files, will just print out the return code of the FTP NLST
command.  I'm trying to get the file names themselves.  Now, I've read
through the ftplib module section of the Python documentation and it
says that, by default, the output goes to sys.stdout unless a callback
function is used.  Here is where I get utterly lost.  I can certainly
see the files being outputted to sys.stdout, but don't know how to
capture that output... i.e.

testfile1.txt
testfile2.txt
testfile3.txt

Will show to the screen, but I can't catch it!  I'm sure this is
trivial... any help would be greatly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: off topic: google groups sucks?

2009-08-17 Thread John Yeung
On Aug 17, 12:41 pm, Aaron Watters  wrote:
> I'm having better luck now using the advanced search option
> with queries like
>
>    gadfly group:comp.lang.python
>
> The "search this group" feature still needs fixing, however.

Thanks, Aaron, for confirming that it's not just me!  I've been
noticing spotty or missing results searching groups for a while now,
actually, to the point that I gave up trying.  Can't remember exactly
when it started, but I do remember that it used to work pretty well
and then suddenly got significantly worse.

Also, thanks for the tip of trying advanced searches.

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


Re: Using a Callback Function - ftplib

2009-08-17 Thread David
Il Mon, 17 Aug 2009 10:43:33 -0700 (PDT), seldan24 ha scritto:

> Hello,
> 
> I'm utterly confused by something which is most likely trivial.  I'm
> attempting to connect to an FTP server, retrieve a list of files, and
> store than in an array.  I.e.:
> 
> import ftplib
> 
> ftp = ftplib.FTP(server)
> ftp.login(user, pass)
> ftp.cwd(conf['testdir'])

Why bother with retrlines? Use the provided higer level fuctions:

remotefiles = []
ftp.dir(remotefiles.append)

or, if you prefer nlst

remotefiles = ftp.nlst()

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


Re: Using a Callback Function - ftplib

2009-08-17 Thread seldan24
On Aug 17, 1:51 pm, David <[email protected]> wrote:
> Il Mon, 17 Aug 2009 10:43:33 -0700 (PDT), seldan24 ha scritto:
>
> > Hello,
>
> > I'm utterly confused by something which is most likely trivial.  I'm
> > attempting to connect to an FTP server, retrieve a list of files, and
> > store than in an array.  I.e.:
>
> > import ftplib
>
> > ftp = ftplib.FTP(server)
> > ftp.login(user, pass)
> > ftp.cwd(conf['testdir'])
>
> Why bother with retrlines? Use the provided higer level fuctions:
>
> remotefiles = []
> ftp.dir(remotefiles.append)
>
> or, if you prefer nlst
>
> remotefiles = ftp.nlst()
>
> regards
> david

I didn't even notice the higher level methods.  I changed the
retrieval line to:

ftp.nlst("testfile*.txt")

This works great.  The result is even captured in an array.  I really
have no idea what the difference between a LIST and NLST is within
FTP.  Never delved that deep into it.  I did notice that an NLST will
return a specific FTP code if a file doesn't exist, whereas a LIST
doesn't.  So, I ended up using NLST as that'll generate an
ftplib.error_perm exception.  Based on if the job cares if a file is
not available or not (some do, some don't), I'll either exit, or
continue on with the file loop.

Anyway, thanks again, works perfectly, next time I'll try to scroll
down and read a bit more prior to posting!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Uninstalling mac python2.5 to install python2.6

2009-08-17 Thread Ned Deily
In article <[email protected]>,
 Farhan Sheikh  wrote:
> i originally had python2.5 on my mac at the univeristy and had to get  
> 2.6 to get NEST and pyNN to work together. however now as those are  
> now installed, i had to install numpy.
> 
> As i installed numpy, it only installed its directories into the  
> python2.5 folders and as i am new to to mac terminals i don't know how  
> to change its directories to be installed into python2.6. my question  
> is, do i have to uninstall python 2.5 so that only python2.6 is on the  
> machine or is there a way to change the path so it saves into python2.5?

There appears to be a NumPy installer image for Python 2.6 and OX 10.5 
here:

http://sourceforge.net/projects/numpy/files/

Multiple versions of python can co-exist on OS X.  You definitely should 
not remove the Apple-supplied python2.5 (linked to from /usr/bin/python) 
in 10.5.

-- 
 Ned Deily,
 [email protected]

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


Re: GUI interface builder for python

2009-08-17 Thread axl456
On Aug 17, 1:59 am, "l...@d@n"  wrote:
> Which is the best GUI interface builder with drag and drop
> capabilities.
> I am using Ubuntu GNU/Linux.
> Please help me.
> Thank you.

boa is really nice..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread Jon Harrop
Xah Lee wrote:
> On Aug 12, 12:15 pm, Raymond Hettinger  wrote:
>> * The reason for implementing the key= parameter had nothing to do
>> with limitations of Python's compiler.  Instead, it was inspired by
>> the
>> decorate-sort-undecorate pattern.
> 
> The decorate-sort-undecorate pattern is a compiler limitation, for
> most of today's langs. I'm not sure, but i think some of the fancy
> functional langs automatically detect such and optimize it away, to
> various degrees.

You mean people use that pattern as a fast alternative in languages where
user-defined functions are very slow, like Python and Mathematica?

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Carl Banks
On Aug 17, 4:40 am, [email protected] wrote:
> On 02:12 am, [email protected] wrote:
>
>
>
> >On Aug 16, 3:35 pm, sturlamolden  wrote:
> >>On 16 Aug, 14:57, Dennis Lee Bieber  wrote:
>
> >> >         Well, the alternative would be to have two keywords for
> >>looping: one
> >> > for your "simple" incrementing integer loop, and another for a loop
> >>that
> >> > operates over the elements of some collection type.
>
> >>A compiler could easily recognise a statement like
>
> >>   for i in range(n):
>
> >>as a simple integer loop.
>
> >It would be a simple to do if you were writing it for a different
> >langauge was a lot less dynamic than Python is.  It'd be quite a
> >complex hack to add it to CPython's compiler while maintaing the
> >current highly dynamic runtime semantics and backwards compatibility,
> >which is a design constraint of Python whether you like it or not.
>
> In your other message, you said this wasn't a legitimate CPython
> complaint.  Here, you say that it would be a "complex hack" to implement
> this in CPython.  "complex hack" has negative connotations in my mind.
> This seems contradictory to me.

Well, you missed the point, chief.

It's not a legitimate complaint because you can use xrange, you don't
need compiler magic to recognize and optimize range.


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


Embedding a python console inside a python application

2009-08-17 Thread Zorigaman
Hi,

I am starting an application in which I would like to have some
scripting functionality. It will obviously be done in Python. The
thing is that I would like my scripts to have access to the rest of
the application as an object it could manipulate.
I made some research and I found the code module, which allows to have
a Python interpreter inside an application, but I am not sure if I can
access to the "parent" which created this interpreter. A solution
could be to launch my application through an interpreter, but the
problem there is how to integrate it back into the GUI, redirecting
streams ?
Another option is the cmd module, but here, same problem, I am not
sure if can have access to my application's objects.
I am using PyQt with Python 2.6.1, I could switch to Python 3.0 if
necessary.
I am familiar with programming, but that's my first script-enabled
application, tell me if I am missing something obvious.

http://docs.python.org/library/code.html
http://docs.python.org/library/cmd.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread J�rgen Exner
Jon Harrop  wrote:
>Xah Lee wrote:
[...]

Please do not feed this well-known troll.

He is known to spew some remotely on-topic junk into a bunch of
unrelated NGs and to enjoy the ensuing confusion.

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


Re: XPath support?

2009-08-17 Thread kj
In  Kev Dwyer 
 writes:

>On Sun, 16 Aug 2009 20:29:15 +, kj wrote:

>> I'm looking for a XML parser that produces an object with full XPath
>> support.  What I've been using up to now, xml.etree.ElementTree, fails
>> to support Xpath predicates, as in "sp...@eggs='3']/ham".
>> 
>> What I'm trying to do is to read-in a large XML string, and parse it
>> into an object from which I can extract nodes matching selectors that
>> include such predicates.
>> 
>> Any suggestions would be greatly appreciated.
>> 
>> TIA!
>> 
>> kynn


>Have you tried lxml (http://codespeak.net/lxml/)?

Thanks!  (To Diez too!)

kynn

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


Data visualization in Python

2009-08-17 Thread kj



I'm looking for a good Python package for visualizing
scientific/statistical data.  (FWIW, the OS I'm interested in is
Mac OS X).

The users of this package will be experimental biologists with
little programming experience (but currently learning Python).

(I normally visualize data using R or Mathematica, but I don't want
to saddle these novices with the task of learning yet another
language.)

TIA!

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


Re: python doc available in emacs info format?

2009-08-17 Thread Bruce Stephens
"Colin S. Miller"  writes:

[...]

> Ubuntu maintains a package search site, it is on
> http://packages.ubuntu.com/
>
> However, there seems to be no files named
> python.*info   (regexp)

And yet there are info files in python2.5-doc:
.

[...]

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


Re: Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Paul Boddie
On 17 Aug, 19:23, Jean-Michel Pichavant 
wrote:
>
> Are you suggesting this list reject part of the community regarding its
> sexual orientation, ethnicity, size, culture? If that was the case I'd
> like to know about it.

Careful: you probably meant to write "rejects", not "reject". That
changes the meaning of what you've written somewhat.

> I would really want to know how you'd guess my gender (could be some
> clue somewhere), my sexual orientation, my religion and so on.
> How can you reject someone regarding informations you don't have ?

Well, everyone can of course hide their actual identity on the
Internet, but when someone references a group of people with a
juvenile remark (if we are being charitable about the matter), it has
nothing to do with guessing the characteristics of individuals. The
whole excuse that anonymity defends against insults and harassment is
a bit like saying that slinging mud at everyone is acceptable as long
as everyone is encouraged to do it and nobody is wearing their nicest
clothes. And unless your idea of a Python-related conference is
something close to a fancy-dress event with everyone "in character" -
which would obviously limit the effectiveness of such an event - you
presumably understand that there is a genuine need for continuity
between interactions on and off the Internet. This somewhat undermines
your argument.

> That's the beauty of this mailing list, it has diversity, by design.

An explanation is needed here for this not to sound like
conversational padding.

> We even welcome people that mixes up joke with sexist aggression, not to
> mention how open minded we are :o)

Well, jokes actually need an amusing side, regardless of how
"edgy" ("juvenile" is typically the more accurate term) the joke-
teller is trying to be, and that was completely absent from the remark
in question. There's little room for error in communication over a
medium like this one, as I pointed out with your opening sentence. And
much as it probably upsets the "unfettered free speech" advocates, we
should be able to assert that "sexist aggression" is not acceptable
behaviour amongst those who seek to participate in our community.

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


Re: Data visualization in Python

2009-08-17 Thread Grant Edwards
On 2009-08-17, kj  wrote:

> I'm looking for a good Python package for visualizing
> scientific/statistical data.  (FWIW, the OS I'm interested in
> is Mac OS X).

Both matplotlib and gnuplot-py can produce pretty good results
with a minimum of effort:

  http://matplotlib.sourceforge.net/
  http://gnuplot-py.sourceforge.net/  

I lean more towards gnuplot, but that's probably just a bias
from having used Gnuplot for 10+ years before learning Python.
Both matplotlib and gnuplot are basically 2D packages with some
3D features.
  
There's also a Python binding for VTK.  I found it a bit harder
to use for the stuff I did, but sophisticated 3D stuff it's
probably the winner:

  http://www.vtk.org/

[It also has the only Delaunay triangulation module (of the 3
that I tried) that worked reliably, but you probably don't care
about that.]
  
-- 
Grant Edwards   grante Yow! Let me do my TRIBUTE
  at   to FISHNET STOCKINGS ...
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Data visualization in Python

2009-08-17 Thread Grant Edwards
On 2009-08-17, Grant Edwards  wrote:
> On 2009-08-17, kj  wrote:
>
>> I'm looking for a good Python package for visualizing
>> scientific/statistical data.  (FWIW, the OS I'm interested in
>> is Mac OS X).
>
> Both matplotlib and gnuplot-py can produce pretty good results
> with a minimum of effort:

Oh, just in case you haven't found them, you might also be
interested in the SciPy and Scientific Python projects:

   http://www.scipy.org/

   http://sourcesup.cru.fr/projects/scientific-py/

Though they have deceptively similar names, they're two
separate projects.  Unfortunately, some rather promenent
documentation conflates the two.  For example,

  http://docs.python.org/3.1/tutorial/whatnow.html

refers to www.scipy.org as "the Scientific Python" project.

-- 
Grant Edwards   grante Yow! I hope the
  at   ``Eurythmics'' practice
   visi.combirth control ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread exarkun

On 06:32 pm, [email protected] wrote:

On Aug 17, 4:40�am, [email protected] wrote:

On 02:12 am, [email protected] wrote:



>On Aug 16, 3:35�pm, sturlamolden  wrote:
>>On 16 Aug, 14:57, Dennis Lee Bieber  wrote:

>> > � � � � Well, the alternative would be to have two keywords for
>>looping: one
>> > for your "simple" incrementing integer loop, and another for a 
loop

>>that
>> > operates over the elements of some collection type.

>>A compiler could easily recognise a statement like

>>� �for i in range(n):

>>as a simple integer loop.

>It would be a simple to do if you were writing it for a different
>langauge was a lot less dynamic than Python is. �It'd be quite a
>complex hack to add it to CPython's compiler while maintaing the
>current highly dynamic runtime semantics and backwards compatibility,
>which is a design constraint of Python whether you like it or not.

In your other message, you said this wasn't a legitimate CPython
complaint.  Here, you say that it would be a "complex hack" to 
implement

this in CPython. �"complex hack" has negative connotations in my mind.
This seems contradictory to me.


Well, you missed the point, chief.

It's not a legitimate complaint because you can use xrange, you don't
need compiler magic to recognize and optimize range.


There's a lot of things in Python that I don't strictly *need*.  That 
doesn't mean that they wouldn't be welcome if I could have them. 
Getting rid of the range/xrange dichotomy would improve things.  Yes, I 
can work around it until the runtime is good enough to let me think 
about an *interesting* problem instead.  That makes it a legitimate 
complaint in my eyes.  You're welcome to disagree, of course, but do you 
have an argument more compelling than the one you give here?  It seems 
to me one could use it to argue a lot of Python out of existence. 
Chief.  (Seriously, "chief"?  What are you going for?  It sounds like 
condescension to me; what's the point of that?  I hope I'm just 
misreading you.)


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


comparing XML files to eachother

2009-08-17 Thread David Brochu
I need to compare one xml document to another to see if the content matches.
Unfortunately, the formatting (spacing) and order of elements may change
between files from run to run. I have looked into xml dom minidom but can't
seem to find how to accomplish this. Does anyone know how I can do a compare
between two XML documents using the STL?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Carl Banks
On Aug 17, 12:41 pm, [email protected] wrote:
> There's a lot of things in Python that I don't strictly *need*.  That
> doesn't mean that they wouldn't be welcome if I could have them.
> Getting rid of the range/xrange dichotomy would improve things.  Yes, I
> can work around it until the runtime is good enough to let me think
> about an *interesting* problem instead.

You don't have to think about using xrange in a for loop, you just
always use it.

> That makes it a legitimate
> complaint in my eyes.  You're welcome to disagree, of course, but do you
> have an argument more compelling than the one you give here?

I am not arguing in favor of range/xrange, I am saying that it's silly
to complain that the compiler isn't a whole lot more complex than it
is just so it can implemnent a semantically-diconnected special case
just so that you can avoid typing an extra "x".  The cost doesn't even
remotely justify it.


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


Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Carl Banks
On Aug 17, 12:59 pm, Carl Banks  wrote:
> The cost doesn't even remotely justify it.

I mean, it doesn't even remotely justify the cost.

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


Re: zip codes

2009-08-17 Thread Piet van Oostrum
> Grant Edwards  (GE) wrote:

>GE> On 2009-08-16, Shailen  wrote:
>>> Thanks Martin and Aahz. Anyone know if zip code information is
>>> copyrighted for the US?

>GE> You can't copyright "information" as such.  Only concrete
>GE> expressions of information.  A particular publication
>GE> containing zip code information can be copyrighted.  The
>GE> underlying facts themselve cannot be.

But that doesn't help you if you need that information and the only way
to obtain it is from copyrighted sources.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Barcodes

2009-08-17 Thread Ronn Ross
My company needs a small inventory management app. Does python have any
libraries to help with reading and writing bar codes?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: off topic: google groups sucks?

2009-08-17 Thread Aaron Watters
On Aug 17, 1:44 pm, John Yeung  wrote:
> Thanks, Aaron, for confirming that it's not just me!

yea, unfortunately this kind of thing happens in monopolies
that have no viable competition anymore... Sometimes I begin
to suspect that I'm seeing the results that I should want
rather than the results I want.

(Lucene has this property
too -- you get the results the algorithm wants you to get,
rather than the results you want to get.)

-- Aaron Watters

===
In communism the future is certain,
but the past is ever changing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Data visualization in Python

2009-08-17 Thread jordilin
On 17 ago, 21:10, kj  wrote:
> I'm looking for a good Python package for visualizing
> scientific/statistical data.  (FWIW, the OS I'm interested in is
> Mac OS X).
>
> The users of this package will be experimental biologists with
> little programming experience (but currently learning Python).
>
> (I normally visualize data using R or Mathematica, but I don't want
> to saddle these novices with the task of learning yet another
> language.)
>
> TIA!
>
> kynn
Matplotlib is the one. There is Google Chart api which seems fairly
easy to understand and use thanks to pygooglechart bindings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Barcodes

2009-08-17 Thread Emile van Sebille

On 8/17/2009 1:18 PM Ronn Ross said...
My company needs a small inventory management app. Does python have any 
libraries to help with reading and writing bar codes?


I've written bar code apps and python really doesn't enter into that 
part of things.  Printers generally have bar code printing capabilities 
so you just send the right escape sequences and you get the bar codes. 
To read them, bar code readers scan and translate before sending the 
values through typically a keyboard wedge or serial port.


Emile

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


Strongly typed list

2009-08-17 Thread هاني الموصلي
Hello, I am using eclips for python and i am facing a problem. I have
many classes with many properties and want a list of objects from one
of my declared classes. The problem is:When i am accessing any item
from the list, the IDE does not know it's type because in python we do
not declare the variable with it's type, so there is no auto complete
and i have to go to the class to copy the attribute name. To make idea
more clear:

class AutomataBranch(object):
def __init__(selfparams):
self.Name="";
self.nodes=[];

class LanguageAutomata(object):
def __init__(selfparams):
self.cfgAutomata=[];#This has AutomaBranch Type
Now in any method in LanguageAutomata class if i wrote: cfgAutomata.
Then it wont give me the Name attribute Is there any solution for
that?
Perhaps of there is some thing like C# List
cfgAutomata such that the list wont accept items unless they are
AutomataBranch will be good.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Barcodes

2009-08-17 Thread Tim Chase

My company needs a small inventory management app. Does
python have any libraries to help with reading and writing
bar codes?


I've written bar code apps and python really doesn't enter
into that part of things.  Printers generally have bar code
printing capabilities so you just send the right escape
sequences and you get the bar codes. To read them, bar code
readers scan and translate before sending the values through
typically a keyboard wedge or serial port.


To add to what Emile mentions, most barcode readers present a 
keyboard-wedge interface, so that scanning a barcode merely 
appears as if you typed it at the keyboard (USB readers show up 
as a HID profile).  Often they'll have configuration barcodes 
that you can scan to tweak the profile (such as pressing , 
 or an arrow-key after sending the barcode; controlling beep 
tone & volume, etc).


For printing barcodes, you can use any number of solutions -- the 
most popular usually just involves installing a "barcode font" 
and then rendering text in that font to your desired output 
canvas.  I believe there are some native rendering solutions as 
well, but I've not investigated since the font method was more 
than sufficient for my wants.


-tkc



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


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread Paul Rubin
Jon Harrop  writes:
> You mean people use that pattern as a fast alternative in languages where
> user-defined functions are very slow, like Python and Mathematica?

It really doesn't matter whether the language is fast or slow--there
are going to be applications where calling the comparison function
multiple times per element is slower than calling it once per element
and storing the result.

Note the Haskell idiom (sortBy (compare`on`f) xs) is similar to DSU
but calls the comparison function multiple times.

Python 3.0 went overboard by actually removing the cmp argument and
requiring use of the key argument.  That requires various kludges if
the key is, say, a tree structure that has to be recursively compared
with another such structure.  Maybe then can bring back cmp someday.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need cleanup advice for multiline string

2009-08-17 Thread Carl Banks
On Aug 17, 10:03 am, Jean-Michel Pichavant 
wrote:
> I'm no English native, but I already heard women/men referring to a
> group as "guys", no matter that group gender configuration. It's even
> used for group composed exclusively of women. Moreover it looks like a
> *very* friendly form, so there is really nothing to worry about it.

I like how being very friendly means calling people after a guy who
tried to blow up the English Parliament.


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


Re: Strongly typed list

2009-08-17 Thread Fabio Zadrozny
> Hello, I am using eclips for python and i am facing a problem. I have
> many classes with many properties and want a list of objects from one
> of my declared classes. The problem is:When i am accessing any item
> from the list, the IDE does not know it's type because in python we do
> not declare the variable with it's type, so there is no auto complete
> and i have to go to the class to copy the attribute name. To make idea
> more clear:
>
> class AutomataBranch(object):
>    def __init__(selfparams):
>        self.Name="";
>        self.nodes=[];
>
> class LanguageAutomata(object):
>    def __init__(selfparams):
>        self.cfgAutomata=[];#This has AutomaBranch Type
> Now in any method in LanguageAutomata class if i wrote: cfgAutomata.
> Then it wont give me the Name attribute Is there any solution for
> that?
> Perhaps of there is some thing like C# List
> cfgAutomata such that the list wont accept items unless they are
> AutomataBranch will be good.


Hello,

Unfortunately, right now there is no way to gather that specific code
completion in pydev -- because of the dynamic nature of python, that
info is very hard to get.

Best Regards,

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


Re: Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Carl Banks
On Aug 17, 8:44 am, [email protected] (Aahz) wrote:
> In article 
> <461cc6f1-fc23-4bc7-a719-6f29babf8...@o15g2000yqm.googlegroups.com>,
> Robert Dailey   wrote:
>
>
>
> >It's a figure of speech. And besides, why would I want programming
> >advice from a woman? lol. Thanks for the help.
>
> Well, I'm sorry to see this, it means I was wrong about the lack of
> sexism in the Python community.

Oh come on, one newbie making an off-color joke is not any sort of
reflection of the community as a whole.

Anyway it's pretty naive to expect what is now a large community to
avoid bad eggs altogether.  Price you pay for popularity.


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


Re: python doc available in emacs info format?

2009-08-17 Thread Xah Lee
> Please do not slag off a project if you want people to help;
> it tends to put the goat up.

a healthy community needs both positive comment as well as negative to
grow.

emacs's user base has been rotting off from i estimate more than 50%
of programers to less that 1% today.

the particular observation about info doc in this thread is a specific
example.

You can help FSF and emacs to improve, by, for example, trying to help
it to evolve with the rapidly changing computing industry, In this
case, document formats, provided if you see some of my points as
valid. Or, at least consider this eroding awareness of the gnu info
format among average programers worth discussing. No disrespect to
you, but dismissing it as “troll” or similiar sentiment is not
helpful.

emacs community is too much cult and pride. FSF and its product the
GNU was highly successful in the 1980 and 1990s, with its gcc, emacs,
and slew of gnu version of unix tools. A significant part of the
reason is because these products at the time is truely better products
in comparison to existing ones, that there are almost no substitute.
Today, for many variety and complexity of reasons, almost none of this
is true, except possiblly a few such as gcc and GPG. The unix shells
ways and sed, awk, etc tools has largely been replaced by perl,
python, ruby etc, partly due to the changing nature of computing. For
GCC itself, and make, yacc, bison etc there are tens of competiting
products either commercial or open source. Then there's Java, with its
entire suite of tools and libs, and there are tens of truely quality
languages out there today other then the ones that GCC can handle.

emacs 23, although is fantastic to us emacs fans, but if you look
carefully at its feature list, most of it is widely in commericial
software about 10 years ago.

  Xah
∑ http://xahlee.org/

☄


On Aug 17, 4:32 am, "Colin S. Miller"  wrote:
> Xah Lee wrote:
> > btw, is there still info format for python doc?
>
> > i feel kinda sad that emacs info format has pretty much been
> > deprecated over the past decade. About a decade ago, you still will
> > see now and then people asking for emacs info format of docs (was the
> > days of perl). Today, one don't hear of it.
>
> > Part of this is due to emacs cult problem. See:
>
> Xah,
>
> Please do not slag off a project if you want people to help;
> it tends to put the goat up.
>
> It is not "Emacs Info" format, it is FSF Info format.
> There is a stand-alone program to read the Info documentation.
> The program is called "info".
>
> Ubuntu maintains a package search site, it is onhttp://packages.ubuntu.com/
>
> However, there seems to be no files named
> python.*info   (regexp)
>
> There is a
> python-docutils package
> which does contain information in several
> other formats.
>
> This package can be found either via the above site
> or using "apt-cache search python-doc".
>
> As "info" is a FSF format, all FSF produced programs
> will provide documentation in this format. However Python
> is not under the auspices of the FSF, so does not need to use
> this format.
>
> BTW,
> HTML versions of INFO documentation can be generated by
> info2html or info_to_html on them, or texi2html on the source.
>
> Have a nice day,
> Colin S. Miller
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Diversity in Python (was Re: Need cleanup advice for multiline string)

2009-08-17 Thread Chris Rebert
On Mon, Aug 17, 2009 at 2:12 PM, Carl Banks wrote:
> On Aug 17, 8:44 am, [email protected] (Aahz) wrote:
>> In article 
>> <461cc6f1-fc23-4bc7-a719-6f29babf8...@o15g2000yqm.googlegroups.com>,
>> Robert Dailey   wrote:
>> >It's a figure of speech. And besides, why would I want programming
>> >advice from a woman? lol. Thanks for the help.
>>
>> Well, I'm sorry to see this, it means I was wrong about the lack of
>> sexism in the Python community.
>
> Oh come on, one newbie making an off-color joke is not any sort of
> reflection of the community as a whole.
>
> Anyway it's pretty naive to expect what is now a large community to
> avoid bad eggs altogether.  Price you pay for popularity.

Agreed on both points, but the lack of any reprimanding for making
said inappropriate joke /would/ reflect badly on the community.
Fortunately, said person's behavior has now been condemned by virtue
of this thread; it's a step in the right direction.

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


Re: Need cleanup advice for multiline string

2009-08-17 Thread MRAB

Carl Banks wrote:

On Aug 17, 10:03 am, Jean-Michel Pichavant 
wrote:

I'm no English native, but I already heard women/men referring to a
group as "guys", no matter that group gender configuration. It's even
used for group composed exclusively of women. Moreover it looks like a
*very* friendly form, so there is really nothing to worry about it.


I like how being very friendly means calling people after a guy who
tried to blow up the English Parliament.


Guy Fawkes adopted the name Guido while fighting for the Spanish in the
Low Countries:

http://en.wikipedia.org/wiki/Guy_Fawkes

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


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread Nathan Keel
Jon Harrop wrote:

> Xah Lee wrote:
>> On Aug 12, 12:15 pm, Raymond Hettinger  wrote:
>>> * The reason for implementing the key= parameter had nothing to do
>>> with limitations of Python's compiler.  Instead, it was inspired by
>>> the
>>> decorate-sort-undecorate pattern.
>> 
>> The decorate-sort-undecorate pattern is a compiler limitation, for
>> most of today's langs. I'm not sure, but i think some of the fancy
>> functional langs automatically detect such and optimize it away, to
>> various degrees.
> 
> You mean people use that pattern as a fast alternative in languages
> where user-defined functions are very slow, like Python and
> Mathematica?
> 


Do not give this "Xah Lee" idiot any attention. This asshole posts only
self-serving nonsense, because he thinks it makes him sound important
(when in reality, he is absolutely clueless).  This idiot always cross
posts to 5 or more different groups that have nothing to do with his
attempts to impress people (which always fail).  He's incredibly
arrogant, yet incredibly clueless.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding a python console inside a python application

2009-08-17 Thread Zorigaman
On 17 août, 20:46, Zorigaman  wrote:
> Hi,
>
> I am starting an application in which I would like to have some
> scripting functionality. It will obviously be done in Python. The
> thing is that I would like my scripts to have access to the rest of
> the application as an object it could manipulate.
> I made some research and I found the code module, which allows to have
> a Python interpreter inside an application, but I am not sure if I can
> access to the "parent" which created this interpreter. A solution
> could be to launch my application through an interpreter, but the
> problem there is how to integrate it back into the GUI, redirecting
> streams ?
> Another option is the cmd module, but here, same problem, I am not
> sure if can have access to my application's objects.
> I am using PyQt with Python 2.6.1, I could switch to Python 3.0 if
> necessary.
> I am familiar with programming, but that's my first script-enabled
> application, tell me if I am missing something obvious.
>
> http://docs.python.org/library/code.htmlhttp://docs.python.org/library/cmd.html

D'oh. The code module offers exactly what I need, you can specify
object in the interpreter's constructor. D'oh.
-- 
http://mail.python.org/mailman/listinfo/python-list


Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Gilles Ganault
Hello,

I need to convert DD MM  dates into the MySQL-friendly
-MM-DD, and translate the month name from literal French to its
numeric equivalent (eg. "Janvier" into "01").

Here's an example:

SELECT dateinscription, dateconnexion FROM membres LIMIT 1;
26 Mai 2007|17 Août 2009 - 09h20

I'd like to update the row into "2007-05-26" and "2009-08-17 09:20",
respectively.

What is the best way to do this in Python?

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


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread Raymond Hettinger
[Xah Lee]
> This part i don't particular agree:
>
> > * The reason for implementing the key= parameter had nothing to do
> > with limitations of Python's compiler.  Instead, it was inspired by
> > the
> > decorate-sort-undecorate pattern.
>
> The decorate-sort-undecorate pattern is a compiler limitation, for
> most of today's langs. I'm not sure, but i think some of the fancy
> functional langs automatically detect such and optimize it away, to
> various degrees.
>
> ... my criticism is usually written in a style catered to irritate a
> particular class of coder i call tech geekers (they think of themselfs
> with their idiotic term “hackers”). So, parts are exaggerated. It'd be
> more clear to say, that the reason for python's “key”, and as a
> “solution” or need of the decorate-sort-undecorate issue, can be
> attributed to the current state of the art of popular imperative
> language's compilers (induced by such lang's semantics).

I'm not following you here.  If you're saying that it is possible
for a compiler to automatically transform a cmp argument into
a key argument, transforming O(n log n) calls into O(n) calls, then
I don't see how that could be done (a cmp argument can be a C function
that is not introspectable or an arbitrarily complex python function
that may be difficult to analyze and transform programmatically).

The key function was introduced as a simpler way for programmers
to write the commonly used decorate-sort-undecorate pattern --
compiler
limitations had nothing to do with it.

In general, key functions are not a terribly new or inflexible
concept.
The SORT BY clauses in SQL are an example.

That being said, it is a fair criticism of Python's compiler that it
does not do much in the way of optimizations.  It does a handful of
basic peephole optimizations but that is about it.  Other languages
like Haskell fair better in this regard.


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


Re: Splitting a string into substrings of equal size

2009-08-17 Thread Gregor Lingl

Simon Forman schrieb:

On Aug 14, 8:22 pm, candide  wrote:

Suppose you need to split a string into substrings of a given size (except
possibly the last substring). I make the hypothesis the first slice is at the
end of the string.
A typical example is provided by formatting a decimal string with thousands
separator.

What is the pythonic way to do this ?


...

Thanks


FWIW:

def chunks(s, length=3):
stop = len(s)
start = stop - length
while start > 0:
yield s[start:stop]
stop, start = start, start - length
yield s[:stop]


s = '1234567890'
print ','.join(reversed(list(chunks(s
# prints '1,234,567,890'


or:

>>> def chunks(s, length=3):
i, j = 0, len(s) % length or length
while i < len(s):
yield s[i:j]
i, j = j, j + length

>>> print(','.join(list(chunks(s
1,234,567,890
>>> print(','.join(list(chunks(s,2
12,34,56,78,90
>>> print(','.join(list(chunks(s,4
12,3456,7890

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


Re: Need cleanup advice for multiline string

2009-08-17 Thread Ben Finney
Robert Dailey  writes:

> On Aug 11, 3:40 pm, Bearophile  wrote:
> > Robert Dailey:
> > > This breaks the flow of scope. Would you guys solve this
> > > problem by […]

> > There are gals too here.
>
> It's a figure of speech.

Indeed. When I use the term “guys” as a form of address, it's intended
to be gender-neutral.

> And besides, why would I want programming advice from a woman? lol.

No, that's not worth any laughter, especially because there are still
too many people who seriously think that way. It's totally unacceptable.
Please don't promote sexist garbage like that here.

-- 
 \“With Lisp or Forth, a master programmer has unlimited power |
  `\ and expressiveness. With Python, even a regular guy can reach |
_o__)   for the stars.” —Raymond Hettinger |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode

2009-08-17 Thread Jason Earl
Xah Lee  writes:

> Fresh out of the oven:
>
> • How to use and setup Emacs's whitespace-mode
>   http://xahlee.org/emacs/whitespace-mode.html
>
>   Xah
> ∑ http://xahlee.org/

Xah,

I disagree with you about the usefulness of whitespace-mode's defaults,
and I certainly disagree with the need to use profanity on your usenet
post on the subject, but it is hard to argue against your
whitespace-mode.html page.  Very well done.

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


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Jonathan Gardner
On Aug 17, 3:26 pm, Gilles Ganault  wrote:
> Hello,
>
>         I need to convert DD MM  dates into the MySQL-friendly
> -MM-DD, and translate the month name from literal French to its
> numeric equivalent (eg. "Janvier" into "01").
>
> Here's an example:
>
> SELECT dateinscription, dateconnexion FROM membres LIMIT 1;
> 26 Mai 2007|17 Août 2009 - 09h20
>
> I'd like to update the row into "2007-05-26" and "2009-08-17 09:20",
> respectively.
>
> What is the best way to do this in Python?
>
> Thank you.

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


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Che M
On Aug 17, 6:26 pm, Gilles Ganault  wrote:
> Hello,
>
>         I need to convert DD MM  dates into the MySQL-friendly
> -MM-DD, and translate the month name from literal French to its
> numeric equivalent (eg. "Janvier" into "01").
>
> Here's an example:
>
> SELECT dateinscription, dateconnexion FROM membres LIMIT 1;
> 26 Mai 2007|17 Août 2009 - 09h20
>
> I'd like to update the row into "2007-05-26" and "2009-08-17 09:20",
> respectively.
>
> What is the best way to do this in Python?
>
> Thank you.

Likely this is not the best way, but I would do, for
the first one (and the same idea for the second):

def convert(date):
frenchdict = {'Mai':'May'} #etc...
day = mystring[:2]
month = frenchdict[ mystring[3:6] ]
year = mystring[7:11]
newdate = year+'-'+month+'-'+day
print 'newdate is ', newdate

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


Re: Need cleanup advice for multiline string

2009-08-17 Thread John Machin
On Aug 12, 6:52 am, Robert Dailey  wrote:
> On Aug 11, 3:40 pm, Bearophile  wrote:
>
> > Robert Dailey:
>
> > > This breaks the flow of scope. Would you guys solve this
> > > problem by moving failMsg into global scope?
> > > Perhaps through some other type of syntax?
>
> > There are gals too here.
> > This may help:http://docs.python.org/library/textwrap.html#textwrap.dedent
>
> > Bye,
> > bearophile
>
> It's a figure of speech. And besides, why would I want programming
> advice from a woman? lol. Thanks for the help.

Please consider having an attitude transplant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Jonathan Gardner
On Aug 17, 3:26 pm, Gilles Ganault  wrote:
>         I need to convert DD MM  dates into the MySQL-friendly
> -MM-DD, and translate the month name from literal French to its
> numeric equivalent (eg. "Janvier" into "01").
>
> Here's an example:
>
> SELECT dateinscription, dateconnexion FROM membres LIMIT 1;
> 26 Mai 2007|17 Août 2009 - 09h20
>
> I'd like to update the row into "2007-05-26" and "2009-08-17 09:20",
> respectively.
>
> What is the best way to do this in Python?
>

Unfortunately, there isn't any string to date parsers in the built-
ins. Not to worry, though, since writing your own is easy, especially
if you use regular expressions from the re module. I suggest using an
RE such as:

r"(?P\d+)\s+(?P\w+)\s+(?P\d+)"

If you want to translate month names to month numbers, then you need
some sort of dict to do so. Unfortunately, there isn't a terrific
standard for this, so your best bet is to put it in some file
somewhere, or even hard-code it in your code. (Month names won't
change over the lifetime of your program, so it's reasonable to put
them in your code somewhere.)

month_names_to_numbers = {
'jan':1, ... }

Once you have the year, month, and date, formatting it is trivial with
the built-in formatter.

"%04d-%02d%02d %02d:%02d" % (year, month, date, hour, minute)

The variety of date formats out there have prevented a universal,
clean solution to this problem. Until we all start sticking to the
same conventions, we will always have to write code to translate dates
from one format to another.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strongly typed list

2009-08-17 Thread Jonathan Gardner
On Aug 17, 2:19 pm, هاني الموصلي  wrote:
> Please could you lead me to a way or a good IDE that makes developing
> huge projects in python more easier than what i found.Now i am using
> eclips. Actually it is very hard to remember all my classes methods
> and attributes or copy and paste them each time.
> Thanks very much for your interest
> Hani Almousli.

You're relying on your IDE too much. You should rely on the code and
on your own notes. Your project should never get big because there is
no reason to throw in a bunch of useless code.

Think of the simplest way to get your job done. Then write that in
pseudo-code. Finally, run it in Python to see if it actually works.
You may be surprised with how far that will get you.

If you are having problems remembering the attributes and methods of
your instances, you are probably using too many attributes and
methods, their names are too long, or you have too many arguments to
each method. Keep the interfaces between parts as simple as possible.

If you still have a big project, then break it up into several
smaller, re-usable, and independent modules. Keep the interfaces as
simple as possible, and never write code that does anything but Duck-
Typing.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >