New Book: Programming in Python 3 (Second Edition)

2009-10-01 Thread Mark Summerfield
Hi,

A new edition of my Python 3 book will be available in the U.S. next
month, and elsewhere in December or January:

"Programming in Python 3 (Second Edition):
A Complete Introduction to the Python Language"
ISBN 0321680561
http://www.qtrac.eu/py3book.html

The book is aimed at a wide audience, but assumes some programming
experience (not necessarily Python, not necessarily object-oriented).
It
teaches solid procedural style programming, then builds on that to
teach
solid object-oriented programming, and then goes on to more advanced
topics (e.g., including a nice way to create validated attributes by
combining class decorators with descriptors). But even newcomers to
Python 3 should be able to write useful (although small and basic)
programs after reading chapter 1, and then go on to create larger and
more sophisticated programs as they work through the chapters.

The book has been fully revised and updated and now covers Python 3.0
and 3.1, and has been extended with new chapters on debugging,
testing,
and profiling, and on parsing (including coverage of the PyParsing and
PLY modules), as well as a new section on coroutines in the advanced
chapter.

I was motivated to produce a second edition so soon after the first
because it seems to me that Python's core developers would rather
people
switched to the 3.1 series and bypass 3.0 altogether and I wanted to
support that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and lost files

2009-10-01 Thread lallous

Hello Timothy,

"Timothy W. Grove"  wrote in message 
news:mailman.726.1254378947.2807.python-l...@python.org...
Recently I purchased some software to recover some files which I had lost. 
(A python project, incidentally! Yes, I should have kept better backups!) 
They were nowhere to found in the file system, nor in the recycle bin, but 
this software was able to locate them and restore them. I was just 
wondering if there was a way using python to view and recover files from 
the hard drive which would otherwise remain lost forever?




To recover lost or deleted files you need a specialized tools (such as data 
recovery programs).
I don't see a way to recover files using python itself but perhaps using a 
data recovery program written in Python.


--
Elias 


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


Re: M2Crypto 0.20.1 won't build on Red Hat Linux

2009-10-01 Thread Heikki Toivonen
John Nagle wrote:
> M2Crypto, from
> 
> http://pypi.python.org/packages/source/M/M2Crypto/M2Crypto-0.20.1.tar.gz
> 
> won't build on Red Hat Linux / 386.  The error is
> 
> It's some incompatibility between Red Hat include file packaging and
> M2Crypto.

Yup, all Fedora Core-based systems actually.

> There was at one time a note on how to deal with this problem, but it's
> been deleted.  It's still in Google's cache, though.

Not deleted, but my hosting provider made some changes that put my blog
and a number of sites down, without advance notice, while I was on
vacation :( Blog is back up, so the URL works again:
http://www.heikkitoivonen.net/blog/2009/02/09/m2crypto-build-wrapper-for-fedora-core-based-distributions/

I've also added this to the FAQ:
http://chandlerproject.org/Projects/MeTooCrypto#Code

-- 
  Heikki Toivonen - http://heikkitoivonen.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Most "active" coroutine library project?

2009-10-01 Thread Hendrik van Rooyen
On Thursday, 1 October 2009 00:27:02 Rhodri James wrote:

> I was going to say, you want 256 bytes of RAM, you profligate
> so-and-so?  Here, have 32 bytes of data space and stop your
> whining :-)

My multi tasking is coming on nicely, but I am struggling a bit with the 
garbage collection.  The Trash bin gets a bit tight at times, so the extra 
bytes help a lot when I run more than 500 independent tasks.

:-)

- Hendrik


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


PyOpenGL and graphics card support

2009-10-01 Thread jefm
OpenGL newbie alert!!!

Do I need to do anything special to use OpenGL capabilities of my
graphics card ?
I have the impression PyOpenG is using the Windows emulation.

when I execute the following code:

print "glGetString - GL_VENDOR:  ", glGetString
(GL_VENDOR)
print "glGetString - GL_RENDERER:", glGetString
(GL_RENDERER)
print "glGetString - GL_SHADING_LANGUAGE_VERSION:", glGetString
(GL_SHADING_LANGUAGE_VERSION)
print "glGetString - GL_EXTENSIONS:  ", glGetString
(GL_EXTENSIONS)
print "gluGetString - GLU_VERSION:   ", gluGetString
(GLU_VERSION)
print "gluGetString - GLU_EXTENSIONS:", gluGetString
(GLU_EXTENSIONS)

I get the following results:
glGetString - GL_VENDOR:   None
glGetString - GL_RENDERER: None
glGetString - GL_SHADING_LANGUAGE_VERSION: None
glGetString - GL_EXTENSIONS:   None
gluGetString - GLU_VERSION:1.2.2.0 Microsoft
Corporation
gluGetString - GLU_EXTENSIONS:


I am using Python 2.6.2 and PyOpenGL3.0.1a3 on Windows 7 Enterprise
My graphics card is NVIDIA GeForce 9500 GT card
with driver date = 7/14/2009 and version = 8.15.11.9038
-- 
http://mail.python.org/mailman/listinfo/python-list


A new Internet-search website written in Python

2009-10-01 Thread hrg...@gmail.com
Dear Python-list subscribers,


The purpose of this email is to inform the Python-list mailing-list
subscribers of an Internet-search website that is run by software
written in Python.


The website has been in development for several months, and although
it is not in a very polished state as of now, its core functions, such
as categorizing search engines, are working, and hence it was decided
that its existence would be publicly announced.


The website allows its users to search the Internet using existing
search engines and search functions of existing websites, such as

- Google, Yahoo!, and Bing, for general-purpose web searches;
- search functions of Wikipedia and Dictionary.com, for searches
within specific referential works; and
- Google Images and the search function of YouTube, for multimedia-searches.

The examples mentioned above are a small portion of supported
engines/websites, and currently more than 100 are supported.


The website is currently accessible via the following address:

http://www.search-aggregator.com/


If you require help using the website, or encounter a problem with the
website, please send an e-mail to the following e-mail address:

hrg...@gmail.com

Help e-mails will be welcome, and problem reports will be appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyOpenGL and graphics card support

2009-10-01 Thread jefm
these are the imports I use:

from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A new Internet-search website written in Python

2009-10-01 Thread Paul Rubin
"hrg...@gmail.com"  writes:
> The purpose of this email is to inform the Python-list mailing-list
> subscribers of an Internet-search website that is run by software
> written in Python.

Is the software downloadable?  If not, why should anyone here care
what language it is written in?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A new Internet-search website written in Python

2009-10-01 Thread hrg...@gmail.com
On 10/1/09, Paul Rubin  wrote:
> "hrg...@gmail.com"  writes:
>> The purpose of this email is to inform the Python-list mailing-list
>> subscribers of an Internet-search website that is run by software
>> written in Python.
>
> Is the software downloadable?  If not, why should anyone here care
> what language it is written in?

Dear Paul,

I am afraid the software is currently not downloadable. But the fact
that it is written in Python might be of interest to some people, and
that was the reason for the sending of the previous e-mail.

By the way, I have noticed that the address in the "from" field in
your e-mail is set to "http://phr...@nospam.invalid";. Is this supposed
to imply that my previous e-mail is considered to be spam?

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


Unofficial Python GIS SIG

2009-10-01 Thread sean.gill...@gmail.com
There's growing interest among GIS users of Python for a discussion
group, so I've started an unofficial Python GIS SIG at:
http://groups.google.com/group/python-gis-sig. Please join if you're
interested in improving Python's GIS story. At any rate, the group
should (hopefully) reduce the number of GIS questions that get
mistakenly posted to Web-SIG ("GIS" is commonly known as "SIG" outside
the US/UK).

Regards,
--
Sean Gillies
Programmer
Institute for the Study of the Ancient World
New York University
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple if-else question

2009-10-01 Thread Sion Arrowsmith
MRAB   wrote:
>> [ for ... else ]
>The example that makes it clearest for me is searching through a list
>for a certain item and breaking out of the 'for' loop if I find it. If I
>get to the end of the list and still haven't broken out then I haven't
>found the item, and that's when the else statement takes effect:

What works for me is thinking about the while ... else construct
and comparing it to if ... else:

if x:
print "x is True"
else:
print "x is False"

while x:
print "x is True"
x -= 1 # or something
# A break here exits the loop with x True
else:
print "x is False"

then the step from while to for is obvious.

-- 
\S

   under construction

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


Re: Python and lost files

2009-10-01 Thread alex23
"Timothy W. Grove"  wrote:
> I was just wondering if there was a way using python to view and recover
> files from the hard drive which would otherwise remain lost forever?

I'm not familiar with any Python-based tools for data recovery, but
you might be interested in mercurial[1], which _is_ (primarily)
written in Python ;)

1: http://mercurial.selenic.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple if-else question

2009-10-01 Thread Olof Bjarnason
2009/10/1 Sion Arrowsmith :
> MRAB   wrote:
>>> [ for ... else ]
>>The example that makes it clearest for me is searching through a list
>>for a certain item and breaking out of the 'for' loop if I find it. If I
>>get to the end of the list and still haven't broken out then I haven't
>>found the item, and that's when the else statement takes effect:
>
> What works for me is thinking about the while ... else construct
> and comparing it to if ... else:
>
> if x:
>    print "x is True"
> else:
>    print "x is False"
>
> while x:
>    print "x is True"
>    x -= 1 # or something
>    # A break here exits the loop with x True
> else:
>    print "x is False"
>
> then the step from while to for is obvious.

Am I grokking for..else:

for i in range(10):
  if fn(i):
break
nobreak:  # let 'nobreak' mean 'else'
  print('break did not happen')

>
> --
> \S
>
>   under construction
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
twitter.com/olofb
olofb.wordpress.com
olofb.wordpress.com/tag/english
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python RPG Codebase

2009-10-01 Thread Jack Diederich
On Thu, Oct 1, 2009 at 1:22 AM, Lanny  wrote:
> I've been thinking about putting together a text based RPG written
> fully in Python, possibly expanding to a MUD system. I'd like to know
> if anyone feels any kind of need for this thing or if I'd be wasting
> my time, and also if anyone would be interested in participating,
> because of the highly modular nature of any RPG it should make for
> easy cooperation.

You might not be aware that twisted (the popular asynchronous TCP/IP
server) was started as a MUD project.  It grew to do many other things
but Gylph still hacks on his MUD code in fits and starts (interesting
stuff too, not your typical LPC/Mush/MOO/Diku codebase).  There are
also a couple pure-python MUD clients if you're into that kind of
thing.

I still follow this stuff in passing because I learned more in
undergrad hacking LPC than I did in my classes proper (probably
because I spent hundreds of hours in class but thousands of hours
writing LPC).

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


Re: unicode issue

2009-10-01 Thread Dave Angel

gentlestone wrote:

save in utf-8 the coding declaration also has to be utf-8



ok, I understand, but what's the problem? Unfortunately seems to be
the Python interactive
mode doesn't have unicode support. It recognize the latin-1 encoding
only.

So I have 2 options, how to write doctest:
1. Replace native charaters with their encoded representation like
u"\u017dabovit\xe1 zmie\u0161an\xe1 ka\u0161a" instead of u"Žabovitá
zmiešaná kaša"
2. Use latin-1 encoding, where the file is saved in utf-8

The first is bad because doctest is a great documenttion tool and it
is propably the main reason I use python. And something like
u"\u017dabovit\xe1 zmie\u0161an\xe1 ka\u0161a" is not a best
documentation style. But the tests work.

The second is bad, because the declaration is incorrect and if I use
it in Django model declaration for example I got bad data in the
application.

So what is the solution? Back to Java? :-)

  
Wait -- don't give up yet.  Since I'm one of the ones who (partially) 
steered you wrong, let me try to help.


Key variable here is how your text editor behaves.  Since I've never 
taken my (programming) text editor out of ASCII mode before this week, 
it took some experimenting (and more importantly a message from Piet on 
this thread) to make sense of things.  I think I now know how to make my 
own editor (Komodo IDE) behave in this environment, and you probably can 
do as well or better.  In fact, judging from your messages, you probably 
are doing much better on the editor front.


When I tried this morning to re-open that test file from yesterday, many 
of the characters were all messed up.  I was okay as long as the project 
was still open, but not today.  The editor itself apparently looks to 
that encoding declaration when it's deciding how to interpret the bytes 
on disk.


So I did the following, using Komodo IDE.  I created a new file in the 
project.  Before saving it, I used 
Edit->CurrentFileSettings->Properties->Encoding to set it to UTF-8.  
*NOW* I pasted the stuff from your email message.  And added the

#-*- coding: utf-8 -*-

as the second line of the file.   Notice it's *NOT* latin-1.

At this point I save and run the file, and it seems to work fine.

My guess is that I could set these as default settings in Komodo, if I 
were doing UTF-8 very often, and it would become painless.  I know I 
have certain stuff in my python template, and could add that encoding 
line as well.



Anyway, that gets us to the step of running the doctest.  The trick here 
seems to be that we need to define the docstring as a Unicode docstring 
to have it interpreted correctly.  Try adding the u in front of the 
triple quote as follows:


def downcode(name):
   u"""
   >>> downcode(u"Žabovitá zmiešaná kaša")
   u'Zabovita zmiesana kasa'
   """
   for key, value in _MAP.iteritems():
   name = name.replace(key, value)
   return name

Now, if the doctest passes, we seem to be in good shape.

There's another problem, that hopefully somebody else can help with.  
That's if doctest needs to report an error.  When I deliberately changed 
the "expect" string I get an error like the following.


UnicodeEncodeError: 'ascii' codec can't encode character u'\u017d' in 
position 1

50: ordinal not in range(128)

I get a similar error if running the -v option on doctest.   (Note that 
I do *NOT* get the error when running inside Komodo.  And what I've read 
implies that the same would be true if running inside IDLE.)  The 
problem is similar to the one you'd have doing a simple:


   print u"\u017d"

I think these are avoided if  sys.stdout.encoding (and maybe 
sys.stderr.encoding) are set to utf-8.  On my system they're set to 
None, which says to use "the system default encoding."  On my system 
that would be ASCII, so I get the error.  But perhaps yours is already 
something better.


I found links:  
http://drj11.wordpress.com/2007/05/14/python-how-is-sysstdoutencoding-chosen/

http://wiki.python.org/moin/PrintFails

http://lists.macromates.com/textmate/2008-June/025735.html
  which indicate you may want to try:  


set LC_CTYPE=en_GB.utf-8 python

at the command prompt before running python.  This could be system specific;  
it didn't work for me on XP.

The workaround that works for me (so far) is:

if __name__ == "__main__":
   import sys, codecs
   sys.stdout = codecs.getwriter('utf8')(sys.stdout)

   print u"Žabovitá zmiešaná kaša"
   import doctest
   doctest.testmod()

The codecs line tells python that stdout should use utf-8.  That doesn't make 
the characters look good on my console, but at least it avoids the errors.  I'm 
guessing that on my system I should use latin1 here instead of utf8.  But I 
don't want to confuse things.


HTH

DaveA

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


"cx_Freeze.freezer.ConfigError: no initscript named Console"

2009-10-01 Thread John

cx_freeze v4.01
Python 2.6
Ubuntu Jaunty

Following the example of 'cx-freeze hello.py', I'm getting the error
message below. I put all of the error keywords into google and found no
hits.

Some people in various posts have said to use Python 2.5 but a lot of my
code is using Python 2.6 features.

Can you telling what I'm doing wrong?

./cxfreeze hello.py
Traceback (most recent call last):
File "./cxfreeze", line 5, in 
main()
File "/root/cx_Freeze-4.1/cx_Freeze/main.py", line 178, in main
silent = options.silent)
File "/root/cx_Freeze-4.1/cx_Freeze/freezer.py", line 85, in __init__
self._VerifyConfiguration()
File "/root/cx_Freeze-4.1/cx_Freeze/freezer.py", line 325, in
_VerifyConfiguration
self._GetInitScriptFileName()
File "/root/cx_Freeze-4.1/cx_Freeze/freezer.py", line 246, in
_GetInitScriptFileName
raise ConfigError("no initscript named %s", name)
cx_Freeze.freezer.ConfigError: no initscript named Console
--
http://mail.python.org/mailman/listinfo/python-list


Re: A new Internet-search website written in Python

2009-10-01 Thread Chris Jones
On Thu, Oct 01, 2009 at 05:22:50AM EDT, hrg...@gmail.com wrote:
> On 10/1/09, Paul Rubin  wrote:

...

> By the way, I have noticed that the address in the "from" field in
> your e-mail is set to "http://phr...@nospam.invalid";. Is this supposed
> to imply that my previous e-mail is considered to be spam?

It just means that Paul Rubin is not giving out his email address.

Why he's adding insult to injury by cooking up a syntaxically malformed
address - notice the colon (":") - is anybody's guess, though.

cf. "Section 3.3 - Lexical Tokens" of this document:

http://www.ietf.org/rfc/rfc0822.txt

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


Re: ActivePython 3.1.1.2 vs Python 3.1.1 for OSX?

2009-10-01 Thread flebber
On Oct 1, 11:28 am, srid  wrote:
> On Sep 30, 4:51 pm, Robert Hicks  wrote:
>
> > I am just curious which I should use. I am going to start learning
> > Python soon. Are they comparable and I just do a "eenie meenie minie
> > moe"?
>
> ActivePython is essentially same as the installers from python.org -
> but it also comes with additional documentation and tutorials, such
> as:
>
> Python FAQs
> A snapshot of the Python Enhancement Proposals (PEPs) (For the most
> recent version, refer to the PEPs on python.org .)
> Dive Into Python (A tutorial for programmers)
> Non-Programmers Tutorial For Python
>
> http://docs.activestate.com/activepython/3.1/whatsincluded.html
>
> Also note that 2.6.x is probably the best bet if you are going to use
> some 3rd party libraries (after you learn the basics of Python) ..
> because 3.x does not have many of those libraries ported yet.
>
>  http://www.activestate.com/activepython/
>
> Further, early next week - a new release of ActivePython-2.6 will be
> made available that will include, for the first time, a new Python
> package manager (PyPM) from ActiveState that makes it easier to
> install packages from pypi.python.org(without having to compile them
> yourself). This is similar to PPM from ActivePerl.
>
> -srid

Thats awesome news.
-- 
http://mail.python.org/mailman/listinfo/python-list


hii

2009-10-01 Thread padmapriya sekaran
I have a problem in using interp from numpy for which i need 3 array.
my first array is
x = scipy.linspace(0.009,0.53,100)

and the other two array should be read from my file with 100x2 dimension
(file1_lines) but it is read as string instead of two columns

for line in file1_lines:
line = line.split()
xp = line[0]
yp = line[1]
y = scipy.interp(x,xp,yp)
if i code like this it takes only one value for xp and yp but 100 values for
x. i dont know what to do please help.

-- 
Padmapriya Sundrashekaran
Master Student
Life Science Informatics
University of Bonn.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python book

2009-10-01 Thread Greg
On Sep 30, 6:58 am, "lallous"  wrote:
> Hello
>
> Can anyone suggest a good book Python book for advancing from beginner
> level?
>
> (I started with Learning Python 3rd ed)
>
> Regards,
> Elias

Elias,
Try "Core Python Programming", 2nd Edition, by Wesley J. Chun.  I love
it!
Cheers,
Greg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python book

2009-10-01 Thread Banibrata Dutta
Asking about 'Python' book recommendation is something that always leads to
a near religious recommendation set. I have my favourites too, but would
recommend original poster to check the no. of reviews on Amazon, B&N etc.,
after collecting recommendations from this list, before finalizing on one.
-- 
http://mail.python.org/mailman/listinfo/python-list


cx_freeze problem on Ubuntu

2009-10-01 Thread John

Sorry if this might be a repost.  I'm having problems with my newsreader.

My system:

cx_freeze 4.1
Python 2.6
Ubuntu Jaunty

I downloaded the cx_freeze source code from 
http://cx-freeze.sourceforge.net/ into a directory.


I wrote a one line python program 'print( "hello world" )'

According to the instructions, all I have to do is this:

./cxfreeze hello.py

But I get this error:

./cxfreeze hello.py
Traceback (most recent call last):
File "./cxfreeze", line 5, in 
main()
File "/root/cx_Freeze-4.1/cx_Freeze/main.py", line 178, in main
silent = options.silent)
File "/root/cx_Freeze-4.1/cx_Freeze/freezer.py", line 85, in __init__
self._VerifyConfiguration()
File "/root/cx_Freeze-4.1/cx_Freeze/freezer.py", line 325, in
_VerifyConfiguration
self._GetInitScriptFileName()
File "/root/cx_Freeze-4.1/cx_Freeze/freezer.py", line 246, in
_GetInitScriptFileName
raise ConfigError("no initscript named %s", name)
cx_Freeze.freezer.ConfigError: no initscript named Console

From here: 
http://linux.softpedia.com/get/Programming/Assembler-Tools/cx-Freeze-8247.shtml 
the directions state:


Installation:

"Extract the archive into a directory. In order to build cx_Freeze you 
need to have gcc and Python development include files and libraries 
available. Run the following commands.


python MakeFrozenBases.py
python FreezePython.py --no-copy-deps FreezePython.py"

I can't find either of these Python programs and searching the Internet 
for clues was fruitless.


I thinking that I'm missing something that's painfully obvious.

As far as I can tell, no one else has ever posted this problem so I 
don't know what corrective actions to make.  I'd greatly appreciate any 
assistance.

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


Re: unicode issue

2009-10-01 Thread Hyuga
On Sep 30, 3:34 am, gentlestone  wrote:
> Why don't work this code on Python 2.6? Or how can I do this job?
>
> _MAP = {
>     # LATIN
>     u'À': 'A', u'Á': 'A', u'Â': 'A', u'Ã': 'A', u'Ä': 'A', u'Å': 'A',
> u'Æ': 'AE', u'Ç':'C',
>     u'È': 'E', u'É': 'E', u'Ê': 'E', u'Ë': 'E', u'Ì': 'I', u'Í': 'I',
> u'Î': 'I',
>     u'Ï': 'I', u'Ð': 'D', u'Ñ': 'N', u'Ò': 'O', u'Ó': 'O', u'Ô': 'O',
> u'Õ': 'O', u'Ö':'O',
>     u'Ő': 'O', u'Ø': 'O', u'Ù': 'U', u'Ú': 'U', u'Û': 'U', u'Ü': 'U',
> u'Ű': 'U',
>     u'Ý': 'Y', u'Þ': 'TH', u'ß': 'ss', u'à':'a', u'á':'a', u'â': 'a',
> u'ã': 'a', u'ä':'a',
>     u'å': 'a', u'æ': 'ae', u'ç': 'c', u'è': 'e', u'é': 'e', u'ê': 'e',
> u'ë': 'e',
>     u'ì': 'i', u'í': 'i', u'î': 'i', u'ï': 'i', u'ð': 'd', u'ñ': 'n',
> u'ò': 'o', u'ó':'o',
>     u'ô': 'o', u'õ': 'o', u'ö': 'o', u'ő': 'o', u'ø': 'o', u'ù': 'u',
> u'ú': 'u',
>     u'û': 'u', u'ü': 'u', u'ű': 'u', u'ý': 'y', u'þ': 'th', u'ÿ': 'y',
>     # LATIN_SYMBOLS
>     u'©':'(c)',
>     # GREEK
>     u'α':'a', u'β':'b', u'γ':'g', u'δ':'d', u'ε':'e', u'ζ':'z',
> u'η':'h', u'θ':'8',
>     u'ι':'i', u'κ':'k', u'λ':'l', u'μ':'m', u'ν':'n', u'ξ':'3',
> u'ο':'o', u'π':'p',
>     u'ρ':'r', u'σ':'s', u'τ':'t', u'υ':'y', u'φ':'f', u'χ':'x',
> u'ψ':'ps', u'ω':'w',
>     u'ά':'a', u'έ':'e', u'ί':'i', u'ό':'o', u'ύ':'y', u'ή':'h',
> u'ώ':'w', u'ς':'s',
>     u'ϊ':'i', u'ΰ':'y', u'ϋ':'y', u'ΐ':'i',
>     u'Α':'A', u'Β':'B', u'Γ':'G', u'Δ':'D', u'Ε':'E', u'Ζ':'Z',
> u'Η':'H', u'Θ':'8',
>     u'Ι':'I', u'Κ':'K', u'Λ':'L', u'Μ':'M', u'Ν':'N', u'Ξ':'3',
> u'Ο':'O', u'Π':'P',
>     u'Ρ':'R', u'Σ':'S', u'Τ':'T', u'Υ':'Y', u'Φ':'F', u'Χ':'X',
> u'Ψ':'PS', u'Ω':'W',
>     u'Ά':'A', u'Έ':'E', u'Ί':'I', u'Ό':'O', u'Ύ':'Y', u'Ή':'H',
> u'Ώ':'W', u'Ϊ':'I', u'Ϋ':'Y',
>     # TURKISH
>     u'ş':'s', u'Ş':'S', u'ı':'i', u'İ':'I', u'ç':'c', u'Ç':'C',
> u'ü':'u', u'Ü':'U',
>     u'ö':'o', u'Ö':'O', u'ğ':'g', u'Ğ':'G',
>     # RUSSIAN
>     u'а':'a', u'б':'b', u'в':'v', u'г':'g', u'д':'d', u'е':'e',
> u'ё':'yo', u'ж':'zh',
>     u'з':'z', u'и':'i', u'й':'j', u'к':'k', u'л':'l', u'м':'m',
> u'н':'n', u'о':'o',
>     u'п':'p', u'р':'r', u'с':'s', u'т':'t', u'у':'u', u'ф':'f',
> u'х':'h', u'ц':'c',
>     u'ч':'ch', u'ш':'sh', u'щ':'sh', u'ъ':'', u'ы':'y', u'ь':'',
> u'э':'e', u'ю':'yu', u'я':'ya',
>     u'А':'A', u'Б':'B', u'В':'V', u'Г':'G', u'Д':'D', u'Е':'E',
> u'Ё':'Yo', u'Ж':'Zh',
>     u'З':'Z', u'И':'I', u'Й':'J', u'К':'K', u'Л':'L', u'М':'M',
> u'Н':'N', u'О':'O',
>     u'П':'P', u'Р':'R', u'С':'S', u'Т':'T', u'У':'U', u'Ф':'F',
> u'Х':'H', u'Ц':'C',
>     u'Ч':'Ch', u'Ш':'Sh', u'Щ':'Sh', u'Ъ':'', u'Ы':'Y', u'Ь':'',
> u'Э':'E', u'Ю':'Yu', u'Я':'Ya',
>     # UKRAINIAN
>     u'Є':'Ye', u'І':'I', u'Ї':'Yi', u'Ґ':'G', u'є':'ye', u'і':'i',
> u'ї':'yi', u'ґ':'g',
>     # CZECH
>     u'č':'c', u'ď':'d', u'ě':'e', u'ň':'n', u'ř':'r', u'š':'s',
> u'ť':'t', u'ů':'u',
>     u'ž':'z', u'Č':'C', u'Ď':'D', u'Ě':'E', u'Ň':'N', u'Ř':'R',
> u'Š':'S', u'Ť':'T', u'Ů':'U', u'Ž':'Z',
>     # POLISH
>     u'ą':'a', u'ć':'c', u'ę':'e', u'ł':'l', u'ń':'n', u'ó':'o',
> u'ś':'s', u'ź':'z',
>     u'ż':'z', u'Ą':'A', u'Ć':'C', u'Ę':'e', u'Ł':'L', u'Ń':'N',
> u'Ó':'o', u'Ś':'S',
>     u'Ź':'Z', u'Ż':'Z',
>     # LATVIAN
>     u'ā':'a', u'č':'c', u'ē':'e', u'ģ':'g', u'ī':'i', u'ķ':'k',
> u'ļ':'l', u'ņ':'n',
>     u'š':'s', u'ū':'u', u'ž':'z', u'Ā':'A', u'Č':'C', u'Ē':'E',
> u'Ģ':'G', u'Ī':'i',
>     u'Ķ':'k', u'Ļ':'L', u'Ņ':'N', u'Š':'S', u'Ū':'u', u'Ž':'Z'
>
> }
>
> def downcode(name):
>     """
>     >>> downcode(u"Žabovitá zmiešaná kaša")
>     u'Zabovita zmiesana kasa'
>     """
>     for key, value in _MAP.iteritems():
>         name = name.replace(key, value)
>     return name

Though C Python is pretty optimized under the hood for this sort of
single-character replacement, this still seems pretty inefficient
since you're calling replace for every character you want to map.  I
think that a better approach might be something like:

def downcode(name):
return ''.join(_MAP.get(c, c) for c in name)

Or using string.translate:

import string
def downcode(name):
table = string.maketrans(
'ÀÁÂÃÄÅ...',
'AA...')
return name.translate(table)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python RPG Codebase

2009-10-01 Thread exarkun

On 05:46 am, jackd...@gmail.com wrote:
On Thu, Oct 1, 2009 at 1:22 AM, Lanny  
wrote:

I've been thinking about putting together a text based RPG written
fully in Python, possibly expanding to a MUD system. I'd like to know
if anyone feels any kind of need for this thing or if I'd be wasting
my time, and also if anyone would be interested in participating,
because of the highly modular nature of any RPG it should make for
easy cooperation.


You might not be aware that twisted (the popular asynchronous TCP/IP
server) was started as a MUD project.  It grew to do many other things
but Gylph still hacks on his MUD code in fits and starts (interesting
stuff too, not your typical LPC/Mush/MOO/Diku codebase).  There are
also a couple pure-python MUD clients if you're into that kind of
thing.

I still follow this stuff in passing because I learned more in
undergrad hacking LPC than I did in my classes proper (probably
because I spent hundreds of hours in class but thousands of hours
writing LPC).


This project's current home is 
.  Unfortunately, there's 
not much there. :)  I'm hoping to give a talk on Imaginary at PyCon next 
year.  Part of my preparation for that will be writing a lot more 
documentation, improving the web site, and generally making things 
friendlier towards newcomers.


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


Isaac Cipher impl. in python

2009-10-01 Thread pw_ ^
Hello,

I'm looking for an Isaac Cipher impl. in Python. If anyone has it,
please contact me.

Thanks,

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


Re: unicode issue

2009-10-01 Thread Walter Dörwald
On 01.10.09 16:09, Hyuga wrote:
> On Sep 30, 3:34 am, gentlestone  wrote:
>> Why don't work this code on Python 2.6? Or how can I do this job?
>>
>> _MAP = {
>> # LATIN
>> u'À': 'A', u'Á': 'A', u'Â': 'A', u'Ã': 'A', u'Ä': 'A', u'Å': 'A',
>> u'Æ': 'AE', u'Ç':'C',
>> u'È': 'E', u'É': 'E', u'Ê': 'E', u'Ë': 'E', u'Ì': 'I', u'Í': 'I',
>> u'Î': 'I',
>> u'Ï': 'I', u'Ð': 'D', u'Ñ': 'N', u'Ò': 'O', u'Ó': 'O', u'Ô': 'O',
>> u'Õ': 'O', u'Ö':'O',
>> u'Ő': 'O', u'Ø': 'O', u'Ù': 'U', u'Ú': 'U', u'Û': 'U', u'Ü': 'U',
>> u'Ű': 'U',
>> u'Ý': 'Y', u'Þ': 'TH', u'ß': 'ss', u'à':'a', u'á':'a', u'â': 'a',
>> u'ã': 'a', u'ä':'a',
>> u'å': 'a', u'æ': 'ae', u'ç': 'c', u'è': 'e', u'é': 'e', u'ê': 'e',
>> u'ë': 'e',
>> u'ì': 'i', u'í': 'i', u'î': 'i', u'ï': 'i', u'ð': 'd', u'ñ': 'n',
>> u'ò': 'o', u'ó':'o',
>> u'ô': 'o', u'õ': 'o', u'ö': 'o', u'ő': 'o', u'ø': 'o', u'ù': 'u',
>> u'ú': 'u',
>> u'û': 'u', u'ü': 'u', u'ű': 'u', u'ý': 'y', u'þ': 'th', u'ÿ': 'y',
>> # LATIN_SYMBOLS
>> u'©':'(c)',
>> # GREEK
>> u'α':'a', u'β':'b', u'γ':'g', u'δ':'d', u'ε':'e', u'ζ':'z',
>> u'η':'h', u'θ':'8',
>> u'ι':'i', u'κ':'k', u'λ':'l', u'μ':'m', u'ν':'n', u'ξ':'3',
>> u'ο':'o', u'π':'p',
>> u'ρ':'r', u'σ':'s', u'τ':'t', u'υ':'y', u'φ':'f', u'χ':'x',
>> u'ψ':'ps', u'ω':'w',
>> u'ά':'a', u'έ':'e', u'ί':'i', u'ό':'o', u'ύ':'y', u'ή':'h',
>> u'ώ':'w', u'ς':'s',
>> u'ϊ':'i', u'ΰ':'y', u'ϋ':'y', u'ΐ':'i',
>> u'Α':'A', u'Β':'B', u'Γ':'G', u'Δ':'D', u'Ε':'E', u'Ζ':'Z',
>> u'Η':'H', u'Θ':'8',
>> u'Ι':'I', u'Κ':'K', u'Λ':'L', u'Μ':'M', u'Ν':'N', u'Ξ':'3',
>> u'Ο':'O', u'Π':'P',
>> u'Ρ':'R', u'Σ':'S', u'Τ':'T', u'Υ':'Y', u'Φ':'F', u'Χ':'X',
>> u'Ψ':'PS', u'Ω':'W',
>> u'Ά':'A', u'Έ':'E', u'Ί':'I', u'Ό':'O', u'Ύ':'Y', u'Ή':'H',
>> u'Ώ':'W', u'Ϊ':'I', u'Ϋ':'Y',
>> # TURKISH
>> u'ş':'s', u'Ş':'S', u'ı':'i', u'İ':'I', u'ç':'c', u'Ç':'C',
>> u'ü':'u', u'Ü':'U',
>> u'ö':'o', u'Ö':'O', u'ğ':'g', u'Ğ':'G',
>> # RUSSIAN
>> u'а':'a', u'б':'b', u'в':'v', u'г':'g', u'д':'d', u'е':'e',
>> u'ё':'yo', u'ж':'zh',
>> u'з':'z', u'и':'i', u'й':'j', u'к':'k', u'л':'l', u'м':'m',
>> u'н':'n', u'о':'o',
>> u'п':'p', u'р':'r', u'с':'s', u'т':'t', u'у':'u', u'ф':'f',
>> u'х':'h', u'ц':'c',
>> u'ч':'ch', u'ш':'sh', u'щ':'sh', u'ъ':'', u'ы':'y', u'ь':'',
>> u'э':'e', u'ю':'yu', u'я':'ya',
>> u'А':'A', u'Б':'B', u'В':'V', u'Г':'G', u'Д':'D', u'Е':'E',
>> u'Ё':'Yo', u'Ж':'Zh',
>> u'З':'Z', u'И':'I', u'Й':'J', u'К':'K', u'Л':'L', u'М':'M',
>> u'Н':'N', u'О':'O',
>> u'П':'P', u'Р':'R', u'С':'S', u'Т':'T', u'У':'U', u'Ф':'F',
>> u'Х':'H', u'Ц':'C',
>> u'Ч':'Ch', u'Ш':'Sh', u'Щ':'Sh', u'Ъ':'', u'Ы':'Y', u'Ь':'',
>> u'Э':'E', u'Ю':'Yu', u'Я':'Ya',
>> # UKRAINIAN
>> u'Є':'Ye', u'І':'I', u'Ї':'Yi', u'Ґ':'G', u'є':'ye', u'і':'i',
>> u'ї':'yi', u'ґ':'g',
>> # CZECH
>> u'č':'c', u'ď':'d', u'ě':'e', u'ň':'n', u'ř':'r', u'š':'s',
>> u'ť':'t', u'ů':'u',
>> u'ž':'z', u'Č':'C', u'Ď':'D', u'Ě':'E', u'Ň':'N', u'Ř':'R',
>> u'Š':'S', u'Ť':'T', u'Ů':'U', u'Ž':'Z',
>> # POLISH
>> u'ą':'a', u'ć':'c', u'ę':'e', u'ł':'l', u'ń':'n', u'ó':'o',
>> u'ś':'s', u'ź':'z',
>> u'ż':'z', u'Ą':'A', u'Ć':'C', u'Ę':'e', u'Ł':'L', u'Ń':'N',
>> u'Ó':'o', u'Ś':'S',
>> u'Ź':'Z', u'Ż':'Z',
>> # LATVIAN
>> u'ā':'a', u'č':'c', u'ē':'e', u'ģ':'g', u'ī':'i', u'ķ':'k',
>> u'ļ':'l', u'ņ':'n',
>> u'š':'s', u'ū':'u', u'ž':'z', u'Ā':'A', u'Č':'C', u'Ē':'E',
>> u'Ģ':'G', u'Ī':'i',
>> u'Ķ':'k', u'Ļ':'L', u'Ņ':'N', u'Š':'S', u'Ū':'u', u'Ž':'Z'
>>
>> }
>>
>> def downcode(name):
>> """
>> >>> downcode(u"Žabovitá zmiešaná kaša")
>> u'Zabovita zmiesana kasa'
>> """
>> for key, value in _MAP.iteritems():
>> name = name.replace(key, value)
>> return name
> 
> Though C Python is pretty optimized under the hood for this sort of
> single-character replacement, this still seems pretty inefficient
> since you're calling replace for every character you want to map.  I
> think that a better approach might be something like:
> 
> def downcode(name):
> return ''.join(_MAP.get(c, c) for c in name)
> 
> Or using string.translate:
> 
> import string
> def downcode(name):
> table = string.maketrans(
> 'ÀÁÂÃÄÅ...',
> 'AA...')
> return name.translate(table)

Or even simpler:

import unicodedata

def downcode(name):
   return unicodedata.normalize("NFD", name)\
  .encode("ascii", "ignore")\
  .decode("ascii")

Servus,
   Walter
-- 
http://mail.python.org/mailman/listinfo/python-list


Pyserial non-standard baud rate

2009-10-01 Thread oyinbo55
Hello all: this is my first post. I hope I'm doing it right.
I have a digital multimeter that sends data through an RS232 interface
at 19230 baud. I would like to record and graph the output in Python.
Pyserial does not want me to set the baudrate at a non-standard value:

>>>ser=serial.Serial('/dev/ttyUSB0' ,baudrate = 19230, bytesize = 7, parity = 
>>>'N', stopbits = 1)
ValueError : Invalid baud rate : 19230

Using the standard 19200 baud results in gobbledegook from the
multimeter.

How can I connect to this device?

I am using Python 2.5.1 running on Ubuntu 4.2.3 using IDLE 1.2.2

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


Re: Pyserial non-standard baud rate

2009-10-01 Thread Richard Brodie

"oyinbo55"  wrote in message 
news:2feb36fc-106c-4d7c-a697-db59971dc...@a7g2000yqo.googlegroups.com...

> Using the standard 19200 baud results in gobbledegook from the
> multimeter.

You aren't going to notice a 0.1% clock skew within 1 byte.
Forget about the difference between 19200 and 19230.

If you have a scope handy, see what the output waveform
looks like, and check the timings. If not play around with
the rates, parity etc., until you find something that works. 


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


Re: unicode issue

2009-10-01 Thread Rami Chowdhury
On Thu, 01 Oct 2009 08:10:58 -0700, Walter Dörwald   
wrote:



On 01.10.09 16:09, Hyuga wrote:

On Sep 30, 3:34 am, gentlestone  wrote:

Why don't work this code on Python 2.6? Or how can I do this job?

[snip _MAP]

def downcode(name):
"""
>>> downcode(u"Žabovitá zmiešaná kaša")
u'Zabovita zmiesana kasa'
"""
for key, value in _MAP.iteritems():
name = name.replace(key, value)
return name


Though C Python is pretty optimized under the hood for this sort of
single-character replacement, this still seems pretty inefficient
since you're calling replace for every character you want to map.  I
think that a better approach might be something like:

def downcode(name):
return ''.join(_MAP.get(c, c) for c in name)

Or using string.translate:

import string
def downcode(name):
table = string.maketrans(
'ÀÁÂÃÄÅ...',
'AA...')
return name.translate(table)


Or even simpler:

import unicodedata

def downcode(name):
   return unicodedata.normalize("NFD", name)\
  .encode("ascii", "ignore")\
  .decode("ascii")

Servus,
   Walter


As I understand it, the "ignore" argument to str.encode *removes* the  
undecodable characters, rather than replacing them with an ASCII  
approximation. Is that correct? If so, wouldn't that rather defeat the  
purpose?


--
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: unicode issue

2009-10-01 Thread Walter Dörwald
On 01.10.09 17:50, Rami Chowdhury wrote:
> On Thu, 01 Oct 2009 08:10:58 -0700, Walter Dörwald
>  wrote:
> 
>> On 01.10.09 16:09, Hyuga wrote:
>>> On Sep 30, 3:34 am, gentlestone  wrote:
 Why don't work this code on Python 2.6? Or how can I do this job?

 [snip _MAP]

 def downcode(name):
 """
 >>> downcode(u"Žabovitá zmiešaná kaša")
 u'Zabovita zmiesana kasa'
 """
 for key, value in _MAP.iteritems():
 name = name.replace(key, value)
 return name
>>>
>>> Though C Python is pretty optimized under the hood for this sort of
>>> single-character replacement, this still seems pretty inefficient
>>> since you're calling replace for every character you want to map.  I
>>> think that a better approach might be something like:
>>>
>>> def downcode(name):
>>> return ''.join(_MAP.get(c, c) for c in name)
>>>
>>> Or using string.translate:
>>>
>>> import string
>>> def downcode(name):
>>> table = string.maketrans(
>>> 'ÀÁÂÃÄÅ...',
>>> 'AA...')
>>> return name.translate(table)
>>
>> Or even simpler:
>>
>> import unicodedata
>>
>> def downcode(name):
>>return unicodedata.normalize("NFD", name)\
>>   .encode("ascii", "ignore")\
>>   .decode("ascii")
>>
>> Servus,
>>Walter
> 
> As I understand it, the "ignore" argument to str.encode *removes* the
> undecodable characters, rather than replacing them with an ASCII
> approximation. Is that correct? If so, wouldn't that rather defeat the
> purpose?

Yes, but any accented characters have been split into the base character
and the combining accent via normalize() before, so only the accent gets
removed. Of course non-decomposable characters will be removed
completely, but it would be possible to replace

   .encode("ascii", "ignore").decode("ascii")

with something like this:

   u"".join(c for c in name if unicodedata.category(c) == "Mn")

Servus,
   Walter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode issue

2009-10-01 Thread Peter Otten
Rami Chowdhury wrote:

> On Thu, 01 Oct 2009 08:10:58 -0700, Walter Dörwald 
> wrote:
> 
>> On 01.10.09 16:09, Hyuga wrote:
>>> On Sep 30, 3:34 am, gentlestone  wrote:
 Why don't work this code on Python 2.6? Or how can I do this job?

 [snip _MAP]

 def downcode(name):
 """
 >>> downcode(u"Žabovitá zmiešaná kaša")
 u'Zabovita zmiesana kasa'
 """
 for key, value in _MAP.iteritems():
 name = name.replace(key, value)
 return name
>>>
>>> Though C Python is pretty optimized under the hood for this sort of
>>> single-character replacement, this still seems pretty inefficient
>>> since you're calling replace for every character you want to map.  I
>>> think that a better approach might be something like:
>>>
>>> def downcode(name):
>>> return ''.join(_MAP.get(c, c) for c in name)
>>>
>>> Or using string.translate:
>>>
>>> import string
>>> def downcode(name):
>>> table = string.maketrans(
>>> 'ÀÁÂÃÄÅ...',
>>> 'AA...')
>>> return name.translate(table)
>>
>> Or even simpler:
>>
>> import unicodedata
>>
>> def downcode(name):
>>return unicodedata.normalize("NFD", name)\
>>   .encode("ascii", "ignore")\
>>   .decode("ascii")
>>
>> Servus,
>>Walter
> 
> As I understand it, the "ignore" argument to str.encode *removes* the
> undecodable characters, rather than replacing them with an ASCII
> approximation. Is that correct? If so, wouldn't that rather defeat the
> purpose?

You didn't take the normalization step into your consideration. Example:

>>> import unicodedata
>>> s = u"Ä"
>>> unicodedata.normalize("NFD", s)
u'A\u0308'
>>> _.encode("ascii", "ignore")
'A'



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


Re: unicode issue

2009-10-01 Thread Rami Chowdhury
On Thu, 01 Oct 2009 09:03:38 -0700, Walter Dörwald   
wrote:


Yes, but any accented characters have been split into the base character
and the combining accent via normalize() before, so only the accent gets
removed. Of course non-decomposable characters will be removed
completely, but it would be possible to replace

   .encode("ascii", "ignore").decode("ascii")

with something like this:

   u"".join(c for c in name if unicodedata.category(c) == "Mn")

Servus,
   Walter


Thank you for the clarification!

--
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: emptying a list

2009-10-01 Thread Geoffrey Clements
"lallous"  wrote in message news:ha2htc$u9...@aioe.org...
> Hello
>
> What is faster when clearing a list?
>
> del L[:]
>
> or
>
> L = []
>

Oh, "L = []" definitely, on the basis that there are fewer characters to 
type.


http://docs.python.org/3.1/library/profile.html

-- 
Geoff 


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


Re: cx_freeze problem on Ubuntu

2009-10-01 Thread Jon Clements
On 1 Oct, 15:08, John  wrote:
> Sorry if this might be a repost.  I'm having problems with my newsreader.
>
> My system:
>
> cx_freeze 4.1
> Python 2.6
> Ubuntu Jaunty
>
> I downloaded the cx_freeze source code 
> fromhttp://cx-freeze.sourceforge.net/into a directory.
>
> I wrote a one line python program 'print( "hello world" )'
>
> According to the instructions, all I have to do is this:
>
> ./cxfreeze hello.py
>
> But I get this error:
>
> ./cxfreeze hello.py
> Traceback (most recent call last):
> File "./cxfreeze", line 5, in 
> main()
> File "/root/cx_Freeze-4.1/cx_Freeze/main.py", line 178, in main
> silent = options.silent)
> File "/root/cx_Freeze-4.1/cx_Freeze/freezer.py", line 85, in __init__
> self._VerifyConfiguration()
> File "/root/cx_Freeze-4.1/cx_Freeze/freezer.py", line 325, in
> _VerifyConfiguration
> self._GetInitScriptFileName()
> File "/root/cx_Freeze-4.1/cx_Freeze/freezer.py", line 246, in
> _GetInitScriptFileName
> raise ConfigError("no initscript named %s", name)
> cx_Freeze.freezer.ConfigError: no initscript named Console
>
>  From 
> here:http://linux.softpedia.com/get/Programming/Assembler-Tools/cx-Freeze-...
> the directions state:
>
> Installation:
>
> "Extract the archive into a directory. In order to build cx_Freeze you
> need to have gcc and Python development include files and libraries
> available. Run the following commands.
>
> python MakeFrozenBases.py
> python FreezePython.py --no-copy-deps FreezePython.py"
>
> I can't find either of these Python programs and searching the Internet
> for clues was fruitless.
>
> I thinking that I'm missing something that's painfully obvious.
>
> As far as I can tell, no one else has ever posted this problem so I
> don't know what corrective actions to make.  I'd greatly appreciate any
> assistance.

Firstly -- never used the library, hadn't even heard of it --
disclaimer over :)

Err, python 2.6 doesn't have print as a function by default. Have you
done a from __future__ import ?

def _GetInitScriptFileName(self, argsSource = None):
if argsSource is None:
argsSource = self
name = argsSource.initScript
if name is None:
if argsSource.copyDependentFiles:
name = "Console" ()
else:
name = "ConsoleKeepPath"
if sys.version_info[0] >= 3:
name += "3"
argsSource.initScript = self._GetFileName("initscripts", name)
if argsSource.initScript is None:
raise ConfigError("no initscript named %s", name)

Should be sufficient clues(),

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


Re: emptying a list

2009-10-01 Thread Jon Clements
On 1 Oct, 16:30, "lallous"  wrote:
> Hello
>
> What is faster when clearing a list?
>
> del L[:]
>
> or
>
> L = []
>
> --
> Elias

Does it really matter that much?

And you're really talking about two different things, which quite
often come up on this group.

Example follows:

>>> x = range(5)
>>> x = y
>>> print x, y
[1, 2, 3, 4] [1, 2, 3, 4]
>>> x = []
>>> print x, y
[] [1, 2, 3, 4]
>>> x = y
>>> print x, y
[1, 2, 3, 4] [1, 2, 3, 4]
>>> del x[:]
>>> print x, y
[] []

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


Re: PyOpenGL and graphics card support

2009-10-01 Thread Mike C. Fletcher
jefm wrote:
> these are the imports I use:
>
> from OpenGL.GL import *
> from OpenGL.GLUT import *
> from OpenGL.GLU import *
>   
PyOpenGL will use the default OpenGL renderer for your system, however,
before you have an OpenGL context (rendering window) the system can
report whatever the heck it wants to for the various values (in this
case looks like it is reporting the generic microsoft renderer until you
ask for a context).  Try this instead:

from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
resX,resY = (400,300 )

if __name__ == "__main__":
glutInit([])
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
glutInitWindowSize(resX, resY)
glutInitWindowPosition(0, 0)
window = glutCreateWindow("hello")

for name in
(GL_VENDOR,GL_RENDERER,GL_SHADING_LANGUAGE_VERSION,GL_EXTENSIONS):
print name,glGetString(name)
  
HTH,
Mike

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


Re: M2Crypto 0.20.1 won't build on Red Hat Linux

2009-10-01 Thread John Nagle

Heikki Toivonen wrote:

John Nagle wrote:

M2Crypto, from

http://pypi.python.org/packages/source/M/M2Crypto/M2Crypto-0.20.1.tar.gz

won't build on Red Hat Linux / 386.  The error is

It's some incompatibility between Red Hat include file packaging and
M2Crypto.


Yup, all Fedora Core-based systems actually.


I've also added this to the FAQ:
http://chandlerproject.org/Projects/MeTooCrypto#Code


   OK, did that.  The build is now failing with

-bash-3.1$ ./fedora-setup.sh build
running build
running build_py
creating build
...
building 'M2Crypto.__m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/usr/local/include/python2.5 -I/usr/include -includeall -o 
SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i

SWIG/_evp.i:9: Error: Unable to find 'openssl/opensslconf-i686.h'
SWIG/_ec.i:7: Error: Unable to find 'openssl/opensslconf-i686.h'
error: command 'swig' failed with exit status 1
-bash-3.1$


Installed OpenSSL is "OpenSSL 0.9.8a 11 Oct 2005", and it doesn't
have an "openssl/opensslconf-i686.h".  It has an "openssl/opensslconf-i386.h".

M2Crypto documentation says:
0.20.1:
* OpenSSL 0.9.7 or newer
  o Some optional new features will require OpenSSL 0.9.8 or newer

so that's current.

The problem, of course, is that using "uname -m" is asking the wrong question.
It prints "i686" on CPUs that are 64-bit capable, even when they are running
a 32-bit version of Linux.  This is running on a 64-bit capable server.

The right question is "uname --hardware-platform".  That returns "i386" if
running on something emulating a 386, even it it's 64-bit capable.

With that change, the build runs to completion and and the regression tests
mostly run.  Test failure occurred at:

==
FAIL: test_cipher_ok (tests.test_ssl.MiscSSLClientTestCase)
--
Traceback (most recent call last):
  File 
"/var/www/vhosts/sitetruth.com/private/downloads/M2Crypto/M2Crypto-0.20.1/tests/test_ssl.py", 
line 485, in test_cipher_ok

assert s.get_cipher().name() == 'AES128-SHA', s.get_cipher().name()
AssertionError: AES256-SHA

--
Ran 226 tests in 91.672s

Is 'AES128-SHA' a cypher that Fedora Core doesn't support, or what?


John Nagle

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


Q: sort's key and cmp parameters

2009-10-01 Thread kj


Challenge: to come up with a sorting task that cannot be achieved
by passing to the sort method (or sorted function) suitable values
for its key and reverse parameters, but instead *require* giving
a value to its cmp parameter.

For example,

from random import random
scrambled = some_list.sort(cmp=lambda x, y: cmp(random(), 0.5))

can be achieved (to a very good approximation at least) with

scrambled = some_list.sort(key=lambda x: random())

Is there a real-life sorting task that requires (or is far more
efficient with) cmp and can't be easily achieved with key and
reverse?

Many thanks in advance,

G.

P.S. I guess that, if sort is going to produce a non-trivial,
*consistent* order, a function CMP passed as the value of its cmp
parameter must satisfy the following properties:

0. CMP(x, y) must be non-zero for some elements x, y of the list; 
1. anti-symmetry: sign(CMP(x, y)) must be equal to -sign(CMP(y, x));
2. transitivity: if sign(CMP(x, y)) equals sign(CMP(y, z)), then
   sign(CMP(x, z)) must be equal to sign(CMP(x, y)).

In (1) and (2), sign() stands for the function

-1 if x  < 0
  sign(x) =  0 if x == 0
 1 if x  > 0

I suppose that all bets are off if these properties are not satisfied,
though the documentation does not make this entirely clear, as far
as I can tell.  (If I'm wrong about this alleged omission, please
point me to the part of the docs that I missed.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Q: sort's key and cmp parameters

2009-10-01 Thread Laszlo Nagy

Is this a homework?


Challenge: to come up with a sorting task that cannot be achieved
by passing to the sort method (or sorted function) suitable values
for its key and reverse parameters, but instead *require* giving
a value to its cmp parameter.
  
Let me put up this question: how do you define the difference between an 
object to be sorted in the list, and the passed "suitable value" that is 
used for finding the position for the object in the list. If the only 
difference is that they need to be different Python objects, then you 
can always use [x] instead of x. This value is perfectly suitable. ;-)


If you could give us somewhat stronger requirements regarding keys and 
objects, we may give you a different answer.


Best,

Laszlo


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


Re: Q: sort's key and cmp parameters

2009-10-01 Thread Peter Otten
kj wrote:

> Challenge: to come up with a sorting task that cannot be achieved
> by passing to the sort method (or sorted function) suitable values
> for its key and reverse parameters, but instead *require* giving
> a value to its cmp parameter.
> 
> For example,
> 
> from random import random
> scrambled = some_list.sort(cmp=lambda x, y: cmp(random(), 0.5))

The above violates the transitivity requirement as stated below. The result 
will have a bias.

> can be achieved (to a very good approximation at least) with
> 
> scrambled = some_list.sort(key=lambda x: random())
> 
> Is there a real-life sorting task that requires (or is far more
> efficient with) cmp and can't be easily achieved with key and
> reverse?

The core developers don't think there is one. list.sort() no longer supports 
the cmp parameter in 3.x.
 
> Many thanks in advance,
> 
> G.
> 
> P.S. I guess that, if sort is going to produce a non-trivial,
> *consistent* order, a function CMP passed as the value of its cmp
> parameter must satisfy the following properties:
> 
> 0. CMP(x, y) must be non-zero for some elements x, y of the list;
> 1. anti-symmetry: sign(CMP(x, y)) must be equal to -sign(CMP(y, x));
> 2. transitivity: if sign(CMP(x, y)) equals sign(CMP(y, z)), then
>sign(CMP(x, z)) must be equal to sign(CMP(x, y)).
> 
> In (1) and (2), sign() stands for the function
> 
> -1 if x  < 0
>   sign(x) =  0 if x == 0
>  1 if x  > 0
> 
> I suppose that all bets are off if these properties are not satisfied,
> though the documentation does not make this entirely clear, as far
> as I can tell.  (If I'm wrong about this alleged omission, please
> point me to the part of the docs that I missed.)


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


AJAX Widget Framework

2009-10-01 Thread Laszlo Nagy
I'm looking for an open source, AJAX based widget/windowing framework. 
Here is what I need:


- end user opens up a browser, points it to a URL, logs in
- on the server site, sits my application, creating a new session for 
each user that is logged in
- on the server site, I create windows(frames), put widgets on them, 
write event handlers etc. Just like with wx or pygtk.
- However, windows are created in the user's browser, and events are 
triggered by Javascript, and sent back to server through AJAX.

- the server side would be - of course - written in Python.

I was looking these projects:

http://www.uize.com/
http://pyjs.org/

There are many frameworks listed here which I did not check: 
http://internetmindmap.com/javascript_frameworks. I have no idea which 
has Python support, and probably there are only a few that worth looking 
at. I wonder if you could tell me which are the pros and contras for 
these frameworks. If there is a comparison available on the NET, 
pointing me to the right URL would help a lot.


The bottom line...

My main goal is to develop enterprise class OLTP database applications. 
I'll need grid widget to display data in tabular format, and I'll use 
events heavily for data manipulation, live search, tooltips etc. I'm 
familiar with wxWidgets, pygtk and other toolkits, but not with AJAX. I 
have never used a system like that.


Thank you,

  Laszlo

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


Re: Q: sort's key and cmp parameters

2009-10-01 Thread Laszlo Nagy



can be achieved (to a very good approximation at least) with

scrambled = some_list.sort(key=lambda x: random())

Is there a real-life sorting task that requires (or is far more
efficient with) cmp and can't be easily achieved with key and
reverse?



The core developers don't think there is one. list.sort() no longer supports 
the cmp parameter in 3.x.
  

LOL :-D

BTW if you really want to sort a list then you can. Using keys or 
values, it doesn't matter. The op's question has no practical usage. 
REALLY looks like a homework.


  L

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


Re: How different are a generator's send and next methods

2009-10-01 Thread Simon Forman
On Wed, Sep 30, 2009 at 4:24 PM, Andrey Fedorov  wrote:
> As far as I can tell, a generator's .next() is equivalent to .send(None). Is
> this true?

They are equivalent AFAIK.

> If so, [why] aren't they unified in a method with a single argument which 
> defaults
> to None?
> - Andrey

next() predates send().
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Q: sort's key and cmp parameters

2009-10-01 Thread Carsten Haese
kj wrote:
> 
> Challenge: to come up with a sorting task that cannot be achieved
> by passing to the sort method (or sorted function) suitable values
> for its key and reverse parameters, but instead *require* giving
> a value to its cmp parameter.

Such a task can't exist, because any arbitrary comparison function can
be transformed into a key function. The idea behind the transformation
is to construct wrapper objects that can compare themselves to other
wrapper objects by invoking the given comparison function on their
wrapped originals.

Google for "Hettinger cmp2key" if you want to see the code that does
this transformation.

HTH,

--
Carsten Haese
http://informixdb.sourceforge.net

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


Re: Q: sort's key and cmp parameters

2009-10-01 Thread Ethan Furman

Laszlo Nagy wrote:



can be achieved (to a very good approximation at least) with

scrambled = some_list.sort(key=lambda x: random())

Is there a real-life sorting task that requires (or is far more
efficient with) cmp and can't be easily achieved with key and
reverse?




The core developers don't think there is one. list.sort() no longer 
supports the cmp parameter in 3.x.
  


LOL :-D

BTW if you really want to sort a list then you can. Using keys or 
values, it doesn't matter. The op's question has no practical usage. 
REALLY looks like a homework.


  L



If it is, it's one he's contemplating giving his students.  :-D

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


Re: iterate over list while changing it

2009-10-01 Thread Simon Forman
On Wed, Sep 30, 2009 at 11:19 PM, Daniel Stutzbach
 wrote:
> On Thu, Sep 24, 2009 at 3:32 PM, Torsten Mohr  wrote:
>>
>> a = [1, 2, 3, 4, 5, 6]
>>
>> for i, x in enumerate(a):
>>    if x == 3:
>>        a.pop(i)
>>        continue
>>
>>    if x == 4:
>>        a.push(88)
>>
>>    print "i", i, "x", x
>>
>> I'd like to iterate over a list and change that list while iterating.
>> I'd still like to work on all items in that list, which is not happening
>> in the example above.
>
> I assume that by "a.push" you meant "a.append".
>
> I believe this will do what you want:
>
> a = [1, 2, 3, 4, 5, 6]
> i = 0
> while i < len(a):
>    x = a[i]
>    if x == 3:
>        a.pop(i)
>    i += 1
>        continue
>
>    if x == 4:
>        a.append(88)
>
>    print "i", i, "x", x
>    i += 1
>
> --
> Daniel Stutzbach, Ph.D.
> President, Stutzbach Enterprises, LLC
>


In the case of x == 3 when you remove an item from the list you should
not increment the index.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hii

2009-10-01 Thread Simon Forman
On Thu, Oct 1, 2009 at 7:55 AM, padmapriya sekaran  wrote:
> I have a problem in using interp from numpy for which i need 3 array.
> my first array is
> x = scipy.linspace(0.009,0.53,100)
>
> and the other two array should be read from my file with 100x2 dimension
> (file1_lines) but it is read as string instead of two columns
>
> for line in file1_lines:
>     line = line.split()
>         xp = line[0]
>         yp = line[1]
>     y = scipy.interp(x,xp,yp)
> if i code like this it takes only one value for xp and yp but 100 values for
> x. i dont know what to do please help.

It is difficult to say without a sample of the file data.  If you
would please provide some?


Also, once you are sure the lines are being split correctly, you can just say:
xp, yp = line.split()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Q: sort's key and cmp parameters

2009-10-01 Thread Paul Rubin
kj  writes:
> Is there a real-life sorting task that requires (or is far more
> efficient with) cmp and can't be easily achieved with key and
> reverse?

Yes, think of sorting tree structures where you have to recursively
compare them til you find an unequal pair of nodes.  To sort with
key=... you have to wrap a class instance around each tree, with
special comparison methods.  Blecch.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Q: sort's key and cmp parameters

2009-10-01 Thread Bearophile
Paul Rubin:

> Yes, think of sorting tree structures where you have to recursively
> compare them til you find an unequal pair of nodes.

That's cute. In what situations do you have to perform such kind of
sort?

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What does the list_folders() method of mailbox.Maildir actually ?do (if anything)?

2009-10-01 Thread Aahz
In article ,
  wrote:
>Tim Roberts  wrote:
>> tinn...@isbd.co.uk wrote:
>>>
>>>My maildir hierarchy is created by mutt which is a *very* standards
>>>compliant MUA, surely standard python libraries should work with
>>>standard maildirs not some wierd extension thereof.
>> 
>> The Maildir specification does not allow for subfolders.  That was added in
>> Maildir++, and the subfolder names start with a dot.  It's not a "wierd
>> extension thereof".
>
>No sub-folders within maildir folders but that's not what I was expecting.
>
>I was just expecting to be able to list my maildir mailboxes.

Now you know why *my* mutt uses mboxes.  ;-)
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Normal is what cuts off your sixth finger and your tail..."  --Siobhan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unofficial Python GIS SIG

2009-10-01 Thread Aahz
In article <2edb4c08-5853-4d21-9bcc-5895c4312...@l13g2000yqb.googlegroups.com>,
sean.gill...@gmail.com  wrote:
>
>There's growing interest among GIS users of Python for a discussion
>group, so I've started an unofficial Python GIS SIG at:
>http://groups.google.com/group/python-gis-sig. Please join if you're
>interested in improving Python's GIS story. At any rate, the group
>should (hopefully) reduce the number of GIS questions that get
>mistakenly posted to Web-SIG ("GIS" is commonly known as "SIG" outside
>the US/UK).

Any particular reason you didn't create a list @python.org?
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Normal is what cuts off your sixth finger and your tail..."  --Siobhan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Q: sort's key and cmp parameters

2009-10-01 Thread Duncan Booth
kj  wrote:

> Is there a real-life sorting task that requires (or is far more
> efficient with) cmp and can't be easily achieved with key and
> reverse?
> 
There is no sorting task that *requires* cmp. If all else fails you can 
define a key class to wrap the original wrapper such that comparing the 
keys simply calls the comparison function that you *would* have used.

This has been discussed before and if you google sufficiently you should 
find the code that has been posted to do exactly that.
-- 
http://mail.python.org/mailman/listinfo/python-list


accessing dictionary keys

2009-10-01 Thread Andreas Balogh

Hello,

when building a list of points like

points = [ ]
points.append((1, 2))
points.append((2, 3))

point = points[0]

eventually I'd like to access the tuple contents in a more descriptive 
way, for example:


print point.x, point.y

but instead I have to write (not very legible)

print point[0], point[1]

Note: I am using Python 2.5

Well, I can use a dictionary:

points.append({"x": 1, "y": 2})

When accessing values more typing is involved:

print point["x"], point["y"]

Or I can use a Bunch (see ActiveState cookbooks):
class Bunch:
def __init__(self, **kwds):
self.__dict__.update(kwds)

and do it like this:
points.append(Bunch(x=4, y=5))
print points[-1].x, points[-1].y

With the bunch at least all the quotes go away.

Is there any shortcut which allows to use point.x with a dictionary, or 
defining keys with tuples and lists?


Regards, Andreas

--
Andreas Balogh
baloand (at) gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: accessing dictionary keys

2009-10-01 Thread Carsten Haese
Andreas Balogh wrote:
> Hello,
> 
> when building a list of points like
> 
> points = [ ]
> points.append((1, 2))
> points.append((2, 3))
> 
> point = points[0]
> 
> eventually I'd like to access the tuple contents in a more descriptive
> way, for example:
> 
> print point.x, point.y

I'm not sure exactly what you're asking, but maybe the following code
will serve as a zeroth iteration toward the solution you seek:

py> class Point(object):
... def __init__(self, x, y):
... self.x = x
... self.y = y
...
py> points = []
py> points.append(Point(1, 2))
py> points.append(Point(2, 3))
py>
py> point = points[0]
py> print point.x, point.y
1 2

HTH,

--
Carsten Haese
http://informixdb.sourceforge.net

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


Re: accessing dictionary keys

2009-10-01 Thread Rami Chowdhury
On Thu, 01 Oct 2009 13:19:18 -0700, Andreas Balogh   
wrote:




Is there any shortcut which allows to use point.x with a dictionary, or  
defining keys with tuples and lists?


Regards, Andreas



It sounds like you want collections.namedtuple (Python 2.6 and up; recipe  
for Python 2.4 or 2.5 at http://code.activestate.com/recipes/500261/)?


HTH,
Rami

--
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: accessing dictionary keys

2009-10-01 Thread Jerry Hill
On Thu, Oct 1, 2009 at 4:19 PM, Andreas Balogh  wrote:
> Is there any shortcut which allows to use point.x with a dictionary, or
> defining keys with tuples and lists?

A namedtuple (introduced in python 2.6), acts like a tuple with named
fields.  Here's an example:

>>> from collections import namedtuple
>>> Point = namedtuple('Point', 'x y')
>>> points = []
>>> points.append(Point(1, 2))
>>> points
[Point(x=1, y=2)]
>>> points.append(Point(2, 3))
>>> points
[Point(x=1, y=2), Point(x=2, y=3)]
>>> points[0].x
1
>>> points[0].y
2
>>> points[0][0]
1
>>> points[0][1]
2
>>>

See http://docs.python.org/library/collections.html#collections.namedtuple
for more information.  I believe there is a recipe in the online
python cookbook that provides this same functionality for earlier
versions of python.

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


Re: Q: sort's key and cmp parameters

2009-10-01 Thread Raymond Hettinger
On Oct 1, 10:08 am, kj  wrote:
> Challenge: to come up with a sorting task that cannot be achieved
> by passing to the sort method (or sorted function) suitable values
> for its key and reverse parameters, but instead *require* giving
> a value to its cmp parameter.

If you're assuming a consistent sort-order (transitivity, not
evolving over time, etc), then the cmp method and key method
are mathematically equivalent (you could always do a compare
sort first, record the order produced, and assign the position
number as a key function):

# constructive proof of the existence of a key function
# corresponding to a given cmp function
tmplist = sorted(s, cmp=mycmp)
pos = dict(zip(map(id, tmplist), range(len(tmplist
result = sorted(s, key=lambda x: pos[id(x)])
assert tmplist == result

Given equivalence, what is really at stake is convenience.

If you're starting point is a cmp function (for instance,
asking a dating service member whether they prefer
mate x to mate y), then having to convert to a key function
can be inconvenient.

If you need to sort by an ascending primary key and a descending
secondary key, you may find it easiest to sort in two passes
(taking advantage of guaranteed sort stability):

sorted(s, key=secondary, reversed=True)
sorted(s, key=primary)

With a cmp function, the above could be achieved in a single pass:

def mycmp(x, y):
 p = cmp(primary(a), primary(b))
 return p if p else cmp(secondary(b), secondary(a))

sorted(s, cmp=mycmp)

Also, as Paul pointed-out, there are some structures such as tree
comparisons that may be challenging to express directly as a key
function.  As Carsten pointed-out, the cmp2key function allows
cmp functions to trivially (though indirectly) be recast as key
functions.

All that being said, for many everyday uses, a key function is
simpler to write and faster to run than a cmp function approach.


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


Re: Unofficial Python GIS SIG

2009-10-01 Thread seang
On Oct 1, 9:49 pm, a...@pythoncraft.com (Aahz) wrote:
> In article 
> <2edb4c08-5853-4d21-9bcc-5895c4312...@l13g2000yqb.googlegroups.com>,
>
> sean.gill...@gmail.com  wrote:
>
> >There's growing interest among GIS users of Python for a discussion
> >group, so I've started an unofficial Python GIS SIG at:
> >http://groups.google.com/group/python-gis-sig. Please join if you're
> >interested in improving Python's GIS story. At any rate, the group
> >should (hopefully) reduce the number of GIS questions that get
> >mistakenly posted to Web-SIG ("GIS" is commonly known as "SIG" outside
> >the US/UK).
>
> Any particular reason you didn't create a list @python.org?
> --
> Aahz (a...@pythoncraft.com)           <*>        http://www.pythoncraft.com/
>
> "Normal is what cuts off your sixth finger and your tail..."  --Siobhan

Only that I am not entirely sure this will take off and don't want to
leave python.org with a defunct list, and I'm unfamiliar with what's
involved with starting a list on python.org. A Google group seemed low
risk. There's fairly good sign-up so far. Am I alienating anybody by
not going with python.org?

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


Re: Q: sort's key and cmp parameters

2009-10-01 Thread kj
In  Raymond 
Hettinger  writes:



Thanks for an extremely helpful reply!

>If you need to sort by an ascending primary key and a descending
>secondary key, you may find it easiest to sort in two passes
>(taking advantage of guaranteed sort stability):

>sorted(s, key=secondary, reversed=3DTrue)
>sorted(s, key=primary)

In the special case where the value returned by secondary is
numeric, I suppose one could do this in one go with

  sorted(s, key=lambda x: (primary(x), -secondary(x)))

...but I can't think of a way to generalize this...

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


Re: Q: sort's key and cmp parameters

2009-10-01 Thread kj
In <7x1vln2bzh@ruckus.brouhaha.com> Paul Rubin 
 writes:

>kj  writes:
>> Is there a real-life sorting task that requires (or is far more
>> efficient with) cmp and can't be easily achieved with key and
>> reverse?

>Yes, think of sorting tree structures where you have to recursively
>compare them til you find an unequal pair of nodes.  To sort with
>key=... you have to wrap a class instance around each tree, with
>special comparison methods.  Blecch.


Good point.  This example convinces me that it was a bad idea to
get rid of cmp in Python 3, even if situations like this one are
rare.  With the cmp parameter as an option, coding this type of
sort was accessible even to those with a rudementary knowledge of
Python.  Now one needs to be pretty clever and pretty skilled with
Python to figure this one out...  Granted, anyone who needs to
perform such sorts is probably smart enough to handle the required
solution, but not necessarily very proficient with Python.  Besides,
why make something that was relatively straightforward before become
an exercise in cleverness?  I wonder what was gained by eliminating
the cmp option...

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


Looking for documentation tools

2009-10-01 Thread Esben von Buchwald

Hello. For documening my thesis project, i'm, looking for 2 things:


A GUI tool that allows me to enter descriptions, arguments, return 
values etc, for each function, class, etc. in some forms and then 
generates and inserts the correct comment syntax,  so pydoc can generate 
the documentation HTML. (preferrably for windows)


And a diagram tool that reverse engineers the used python modules and 
draws a class diagram with relations between the classes etc.?


Either as a standalone app or as something that generates graphviz 
scripts or similar.


I hope you guys have some suggestions?

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


Re: unicode issue

2009-10-01 Thread Neil Hodgson
Dave Angel:

> I know that the clipboard has type tags, but I haven't looked at them in
> so long that I forget what they look like.  For text, is it just ASCII
> and Unicode?  Or are there other possible encodings that the source and
> sink negotiate?

   The normal thing seen is that the clipboard differentiates between
Unicode text and locale-dependent 8 bit text. Depending on platform
Unicode text may be in UTF-8 (Linux) or UTF-16 (Windows). The encoding
of 8-bit text strings is not well defined and is normally assumed to be
compatible with whatever is currently in the document or the current
user interface encoding.

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


Re: Python and lost files

2009-10-01 Thread Carl Banks
On Sep 30, 11:35 pm, "Timothy W. Grove"  wrote:
> Recently I purchased some software to recover some files which I had
> lost. (A python project, incidentally! Yes, I should have kept better
> backups!) They were nowhere to found in the file system, nor in the
> recycle bin, but this software was able to locate them and restore them.

I could have used that yesterday, if it were able to work for a
network Samba drive.  (Yeah, not likely.)


> I was just wondering if there was a way using python to view and recover
> files from the hard drive which would otherwise remain lost forever?

Obviously, if that program was able to do it, it's possible.

On Unix-like OSes, and probably others, it's possible to read the raw
data on a disk the same way as you would read any file.  So Python can
do it without any system-level programming.  Recent versions (I think
2.6+) can use mmap, too, now that it supports an offset parameter.

I don't think you can do that in Windows, though.  I think you'd have
to use special system calls (via ctypes, for example).


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


Re: cx_freeze problem on Ubuntu

2009-10-01 Thread John

Jon Clements wrote:



Firstly -- never used the library, hadn't even heard of it --
disclaimer over :)

Err, python 2.6 doesn't have print as a function by default. Have you
done a from __future__ import ?

def _GetInitScriptFileName(self, argsSource = None):
if argsSource is None:
argsSource = self
name = argsSource.initScript
if name is None:
if argsSource.copyDependentFiles:
name = "Console" ()
else:
name = "ConsoleKeepPath"
if sys.version_info[0] >= 3:
name += "3"
argsSource.initScript = self._GetFileName("initscripts", name)
if argsSource.initScript is None:
raise ConfigError("no initscript named %s", name)

Should be sufficient clues(),

Cheers,
Jon


You wrote 'Firstly' which implies a 'Secondly' which you failed to add. 
 You lose -1 points.

You gained +1 points for your perspicacity to minutia.
You lose -2 points to help resolve the problem.

Life is all about gaining points, even if no one cares.

Cheers,

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


Re: Q: sort's key and cmp parameters

2009-10-01 Thread Paul Rubin
Duncan Booth  writes:
> > Is there a real-life sorting task that requires (or is far more
> > efficient with) cmp and can't be easily achieved with key and reverse?
> > 
> There is no sorting task that *requires* cmp. If all else fails you can 
> define a key class to wrap the original wrapper such that comparing the 
> keys simply calls the comparison function that you *would* have used.

I would count that as key being far less efficient, though still
giving the same result.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Q: sort's key and cmp parameters

2009-10-01 Thread Paul Rubin
Raymond Hettinger  writes:
> If you're assuming a consistent sort-order (transitivity, not
> evolving over time, etc), then the cmp method and key method
> are mathematically equivalent (you could always do a compare
> sort first, record the order produced, and assign the position
> number as a key function)

But that is an efficiency hit.

> If you're starting point is a cmp function (for instance,
> asking a dating service member whether they prefer
> mate x to mate y), then having to convert to a key function
> can be inconvenient.

Well, the issue there is that the comparison function may not be
transitive.  Maybe you really want a topological sort for that.

> All that being said, for many everyday uses, a key function is
> simpler to write and faster to run than a cmp function approach.

I still have never understood why cmp was removed.  Sure, key is more
convenient a lot (or maybe most) of the time, but it's not always.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Q: sort's key and cmp parameters

2009-10-01 Thread alex23
kj  wrote:
> This example convinces me that it was a bad idea to
> get rid of cmp in Python 3, even if situations like this one are
> rare.

It sounds like the entire point of this exercise was to get other
people to confirm your bias for you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial non-standard baud rate

2009-10-01 Thread oyinbo55
On Oct 1, 11:36 am, "Richard Brodie"  wrote:
> "oyinbo55"  wrote in message
>
> news:2feb36fc-106c-4d7c-a697-db59971dc...@a7g2000yqo.googlegroups.com...
>
> > Using the standard 19200 baud results in gobbledegook from the
> > multimeter.
>
> You aren't going to notice a 0.1% clock skew within 1 byte.
> Forget about the difference between 19200 and 19230.
>
> If you have a scope handy, see what the output waveform
> looks like, and check the timings. If not play around with
> the rates, parity etc., until you find something that works.

Thank you, Richard, you are absolutely right.  Looking back at the
documentation for the instrument, I found the following:

"The data format complies with JIS 7Bits-transmission code with a baud
rate of 19230. "

I had overlooked the JIS transmission code because I didn't know what
that meant.  (It is the Japanese Industrial Standard).  Changing my
script to display the data one character at a time, I found it was
sprinkled with escape characters that Japanese machines use to switch
from ASCII to Kanji characters and back.

Does Python have a module that will translate the data stream and
display normal ASCII characters?  The escape codes appear to alter the
values of the characters in some systematic way.

Thanks again for your help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Threaded GUI slowing method execution?

2009-10-01 Thread Aaron Hoover
I have a wx GUI application that connects to a serial port in a  
separate thread, reads from the port, and then is supposed to put the  
data it finds into a queue to be used by the main GUI thread.  
Generally speaking, it's working as expected.


However, one method (that's part of a library I've written to parse  
the packet structure of the data that's coming over the serial port)  
executes approximately 1000 times slower (50ms vs. 50us) when called  
from the serial management thread in the GUI as compared to calling  
the same function from within a command line Python script. I checked  
it by wrapping the call as follows in both cases  (GUI and command  
line script):


tic = time.time()

print time.time() - tic

All the thread is doing most of the time is sitting around checking  
the serial port for waiting data, reading it, and appending it to a  
list when it finds it. Then, in the same thread, the method that seems  
to be remarkably slow works its way through that list looking for  
packets of data and appending the packet payloads it finds to a queue  
to be handled in some way by the GUI.


My question is, what am I missing about either threading or the fact  
that this is running in a GUI that might explain such a huge slowdown.  
I'm sending data over the serial at a true rate of about 24k bytes per  
second, or approximately 2 packets per ms. Is it too much to ask to be  
able to process this data in realtime from within a GUI (I'm not  
talking about plotting or anything - just read it and find packets)?  
Like I said, the process pretty much runs in realtime from a command  
line script.


This packet parsing needs to happen continuously, so it seems calling  
join() to ensure it's not interrupted by the GUI thread, won't work.


Thanks in advance for your help.

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


Concurrent threads to pull web pages?

2009-10-01 Thread Gilles Ganault
Hello

I recently asked how to pull companies' ID from an SQLite database,
have multiple instances of a Python script download each company's web
page from a remote server, eg. www.acme.com/company.php?id=1, and use
regexes to extract some information from each page.

I need to run multiple instances to save time, since each page takes
about 10 seconds to be returned to the script/browser.

Since I've never written a multi-threaded Python script before, to
save time investigating, I was wondering if someone already had a
script that downloads web pages and save some information into a
database.

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


emptying a list

2009-10-01 Thread lallous

Hello

What is faster when clearing a list?

del L[:]

or

L = []

--
Elias 
--

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


Re: Concurrent threads to pull web pages?

2009-10-01 Thread exarkun

On 1 Oct, 09:28 am, nos...@nospam.com wrote:

Hello

I recently asked how to pull companies' ID from an SQLite 
database,

have multiple instances of a Python script download each company's web
page from a remote server, eg. www.acme.com/company.php?id=1, and use
regexes to extract some information from each page.

I need to run multiple instances to save time, since each page takes
about 10 seconds to be returned to the script/browser.

Since I've never written a multi-threaded Python script before, to
save time investigating, I was wondering if someone already had a
script that downloads web pages and save some information into a
database.


There's no need to use threads for this.  Have a look at Twisted:

 http://twistedmatrix.com/trac/

Here's an example of how to use the Twisted HTTP client:

 http://twistedmatrix.com/projects/web/documentation/examples/getpage.py

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


Re: emptying a list

2009-10-01 Thread Simon Forman
On Thu, Oct 1, 2009 at 11:30 AM, lallous  wrote:
> Hello
>
> What is faster when clearing a list?
>
> del L[:]
>
> or
>
> L = []
>
> --
> Elias
> --
> http://mail.python.org/mailman/listinfo/python-list
>

The first form actually clears the list, the second for just re-binds
the name 'L' to a new, empty list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Concurrent threads to pull web pages?

2009-10-01 Thread MRAB

Gilles Ganault wrote:

Hello

I recently asked how to pull companies' ID from an SQLite database,
have multiple instances of a Python script download each company's web
page from a remote server, eg. www.acme.com/company.php?id=1, and use
regexes to extract some information from each page.

I need to run multiple instances to save time, since each page takes
about 10 seconds to be returned to the script/browser.

Since I've never written a multi-threaded Python script before, to
save time investigating, I was wondering if someone already had a
script that downloads web pages and save some information into a
database.

Thank you for any tip.


You could put the URLs into a queue and have multiple worker threads
repeatedly get a URL from the queue, download the page, and then put the
page into another queue for processing by another extraction thread.
This post might help:

http://mail.python.org/pipermail/python-list/2009-September/195866.html

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


Re: Concurrent threads to pull web pages?

2009-10-01 Thread exarkun

On 01:36 am, k...@kyleterry.com wrote:

On Thu, Oct 1, 2009 at 6:33 PM,  wrote:

On 1 Oct, 09:28 am, nos...@nospam.com wrote:

Hello

   I recently asked how to pull companies' ID from an SQLite 
database,
have multiple instances of a Python script download each company's 
web

page from a remote server, eg. www.acme.com/company.php?id=1, and use
regexes to extract some information from each page.

I need to run multiple instances to save time, since each page takes
about 10 seconds to be returned to the script/browser.

Since I've never written a multi-threaded Python script before, to
save time investigating, I was wondering if someone already had a
script that downloads web pages and save some information into a
database.


There's no need to use threads for this.  Have a look at Twisted:

 http://twistedmatrix.com/trac/

Here's an example of how to use the Twisted HTTP client:

http://twistedmatrix.com/projects/web/documentation/examples/getpage.py


I don't think he was looking for a framework... Specifically a 
framework

that you work on.


He's free to use anything he likes.  I'm offering an option he may not 
have been aware of before.  It's okay.  It's great to have options.


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


Re: Q: sort's key and cmp parameters

2009-10-01 Thread kj
In  alex23 
 writes:

>kj  wrote:
>> This example convinces me that it was a bad idea to
>> get rid of cmp in Python 3, even if situations like this one are
>> rare.

>It sounds like the entire point of this exercise was to get other
>people to confirm your bias for you.

The only problem with this hypothesis is that my original bias was
exactly the opposite to the one you quote: when I sent my original
post I thought that cmp was in fact useless (after all I could not
think of a situation that required it or even made it preferable),
and was not even aware that it had been dropped in Python 3.  Paul
Rubin's post convinced me otherwise.

BTW, what's with this business of ascribing underhanded motives to
me?  Earlier some other clown alleged that that my original post
was homework???  WTF?

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


Re: Q: sort's key and cmp parameters

2009-10-01 Thread Paul Rubin
Bearophile  writes:
> > Yes, think of sorting tree structures where you have to recursively
> > compare them til you find an unequal pair of nodes.
> 
> That's cute. In what situations do you have to perform such kind of
> sort?

It came up in a search engine application I've been involved with.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and lost files

2009-10-01 Thread Grant Edwards
On 2009-10-01, Timothy W. Grove  wrote:

> Recently I purchased some software to recover some files which
> I had lost. (A python project, incidentally! Yes, I should
> have kept better backups!) They were nowhere to found in the
> file system, nor in the recycle bin, but this software was
> able to locate them and restore them.  I was just wondering if
> there was a way using python to view and recover files from
> the hard drive which would otherwise remain lost forever?

Yes, you could write a filesystem analysis and file recovery
program in Python.  [I guess that's what you were asking.]

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


Re: Pyserial non-standard baud rate

2009-10-01 Thread John Nagle

oyinbo55 wrote:

On Oct 1, 11:36 am, "Richard Brodie"  wrote:

"oyinbo55"  wrote in message

news:2feb36fc-106c-4d7c-a697-db59971dc...@a7g2000yqo.googlegroups.com...


Using the standard 19200 baud results in gobbledegook from the
multimeter.

You aren't going to notice a 0.1% clock skew within 1 byte.
Forget about the difference between 19200 and 19230.

If you have a scope handy, see what the output waveform
looks like, and check the timings. If not play around with
the rates, parity etc., until you find something that works.


Thank you, Richard, you are absolutely right.  Looking back at the
documentation for the instrument, I found the following:

"The data format complies with JIS 7Bits-transmission code with a baud
rate of 19230. "


   OK.  First off, 19200 baud should work.  19230 is a number which
comes from devices that use a 4MHz crystal for the clock and divide
by 208.  400 / 208 = 19230.769, which is as close as you can get
to 19200 baud given a 4MHz timing source.   Serial ports
can usually tolerate an error of about 1/4 a bit time, which is 2.5%.
Since you're running a little fast, I'd suggest sending 2 stop bits,
which guarantees the receiver can't gain on the transmitter during
long blocks sent at full speed.



I had overlooked the JIS transmission code because I didn't know what
that meant.  (It is the Japanese Industrial Standard).  Changing my
script to display the data one character at a time, I found it was
sprinkled with escape characters that Japanese machines use to switch
from ASCII to Kanji characters and back.

Does Python have a module that will translate the data stream and
display normal ASCII characters?  The escape codes appear to alter the
values of the characters in some systematic way.


   If you're really receiving content in Shift-JIS, you just need to
translate it into Unicode.  Python can do that.  See

http://www.velocityreviews.com/forums/t646242-251-shiftjis-to-unicode.html

Now you'll have Unicode strings that contain kanjii, which Python can process
just fine.

Printing kanjii in a terminal window is troublesome on some operating systems.
But it's possible to get everything working in Unicode, which will result in
kanjii text appearing.

Reading the Japanese may be a problem, although you can put the text through
Google Translate.

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


Re: Looking for documentation tools

2009-10-01 Thread TerryP
>
> A GUI tool that allows me to enter descriptions, arguments, return
> values etc, for each function, class, etc. in some forms and then
> generates and inserts the correct comment syntax,  so pydoc can generate
> the documentation HTML. (preferrably for windows)
>

Maybe I am a bastard, but personally I would consider such a tool, to
be a useless bit of dribble compared to writing decent doc strings and
comments within the code itself. Beyond that, might I suggest using
your favorite text editor and a bit of munged scripting?


> And a diagram tool that reverse engineers the used python modules and
> draws a class diagram with relations between the classes etc.?
>
> Either as a standalone app or as something that generates graphviz
> scripts or similar.
>

You might take a look at tools such as Umbrello and Gaphor. You might
also find this link helpful: http://en.wikipedia.org/wiki/List_of_UML_tools
-- 
http://mail.python.org/mailman/listinfo/python-list


Regular expression to structure HTML

2009-10-01 Thread 504cr...@gmail.com
I'm kind of new to regular expressions, and I've spent hours trying to
finesse a regular expression to build a substitution.

What I'd like to do is extract data elements from HTML and structure
them so that they can more readily be imported into a database.

No -- sorry -- I don't want to use BeautifulSoup (though I have for
other projects). Humor me, please -- I'd really like to see if this
can be done with just regular expressions.

Note that the output is referenced using named groups.

My challenge is successfully matching the HTML tags in between the
first table row, and the second table row.

I'd appreciate any suggestions to improve the approach.


rText = "8583New Horizon Technical Academy,
Inc #4Jefferson701149371Career Learning CenterJefferson70113"

rText = re.compile(r'()(?P\d+)()()()(?P[A-
Za-z0-9#\s\S\W]+)().+$').sub(r'LICENSE:\g|NAME:
\g\n', rText)

print rText

LICENSE:8583|NAME:New Horizon Technical Academy, Inc #4Jefferson701149371Career Learning Center|PARISH:Jefferson|ZIP:70113



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


Re: M2Crypto 0.20.1 won't build on Red Hat Linux

2009-10-01 Thread Heikki Toivonen
John Nagle wrote:
> The right question is "uname --hardware-platform".  That returns "i386" if
> running on something emulating a 386, even it it's 64-bit capable.

Thanks, I'll make a note that I'll need to clarify that part.

> With that change, the build runs to completion and and the regression tests
> mostly run.  Test failure occurred at:
> 
> ==
> FAIL: test_cipher_ok (tests.test_ssl.MiscSSLClientTestCase)
> --
> Traceback (most recent call last):
>   File
> "/var/www/vhosts/sitetruth.com/private/downloads/M2Crypto/M2Crypto-0.20.1/tests/test_ssl.py",
> line 485, in test_cipher_ok
> assert s.get_cipher().name() == 'AES128-SHA', s.get_cipher().name()
> AssertionError: AES256-SHA
> 
> --
> Ran 226 tests in 91.672s
> 
> Is 'AES128-SHA' a cypher that Fedora Core doesn't support, or what?

That seems strange. OpenSSL does allow fine tuning what ciphers to build
and operate with, but this is the first I hear AES128-SHA might not be
turned on anymore. And even stranger still is that the test is
explicitly asking for 128 yet it is getting 256 back. Could you rerun
the test again just to make sure you can repeat it, and if so, let me
know the fedora core, openssl, swig and python versions?

-- 
  Heikki Toivonen - http://heikkitoivonen.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: emptying a list

2009-10-01 Thread S.Selvam
On Thu, Oct 1, 2009 at 10:13 PM, Jon Clements  wrote:

> On 1 Oct, 16:30, "lallous"  wrote:
> > Hello
> >
> > What is faster when clearing a list?
> >
> > del L[:]
> >
> > or
> >
> > L = []
> >
> > --
> > Elias
>
> Does it really matter that much?
>
> And you're really talking about two different things, which quite
> often come up on this group.
>
> Example follows:
>
> >>> x = range(5)
> >>> x = y
>

Is n't it y=x ?

>>> print x, y
> [1, 2, 3, 4] [1, 2, 3, 4]
> >>> x = []
> >>> print x, y
> [] [1, 2, 3, 4]
> >>> x = y
> >>> print x, y
> [1, 2, 3, 4] [1, 2, 3, 4]
> >>> del x[:]
> >>> print x, y
> [] []
>
> Cheers,
> Jon.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Yours,
S.Selvam
-- 
http://mail.python.org/mailman/listinfo/python-list