ANN: Vancouver Python Workshop - keynote speakers announced

2006-05-19 Thread Brian Quinlan
What's New?
===

We are pleased to announce the keynote speakers for this year's
Vancouver Python Workshop: Guido van Rossum and Jim Hugunin.

Guido van Rossum (Google) is the inventor of Python and has managed its
growth and development for more than a decade. Guido was awarded the
Free Software Foundation Award in 2002 and Dr.Dobb's 1999 Excellence in
Programming Award. Today Guido works at Google, spending half of his
time on Python.

Jim Hugunin (Microsoft) is the creator of IronPython, Jython and Numeric
Python. IronPython is Python for the .NET platform and integrates Python
into Microsoft's .NET strategy. Jython is Python for the Java platform
and was the second production quality implementation of Python. Numeric
Python adapts Python to the needs of number crunching applications.
Today, Jim works at Microsoft where he helps them adapt the .NET runtime
to meet the needs of dynamic languages like Python.

About the Vancouver Python Workshop
===

The conference will begin with keynote addresses on August 4st. Further
talks (and tutorials for beginners) will take place on August 5th and
6th. The Vancouver Python Workshop is a community organized conference
designed for both the beginner and for the experienced Python programmer
with:

  * tutorials for beginning programmers
  * advanced lectures for Python experts
  * case studies of Python in action
  * after-hours social events
  * informative keynote speakers
  * tracks on multimedia, Web development, education and more

More information see: http://www.vanpyz.org/conference/
or contact Brian Quinlan at: [EMAIL PROTECTED]

Vancouver
=

In addition to the opportunity to learn and socialize with fellow
Pythonistas, the Vancouver Python Workshop also gives visitors the
opportunity to visit one of the most extraordinary cities in the world
(1). For more information about traveling to Vancouver, see:

http://www.vanpyz.org/conference/vancouver.html
http://www.tourismvancouver.com
http://en.wikipedia.org/wiki/Vancouver

Important dates
===

Talk proposals accepted: May 15th to June 15th
Early registration (discounted): May 22nd to June 30th
Normal registration: from July 1st
Keynotes: August 4th
Conference and tutorial dates: August 5th and 6th

(1) http://news.bbc.co.uk/2/hi/business/2299119.stm

Cheers,
Brian


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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Reminder: call for proposals Python Language and Libraries Track for Europython 2006

2006-05-19 Thread Samuele Pedroni
Registration for Europython (3-5 July) at CERN in Geneva is now open,
if you feel submitting a talk proposal there's still time until
the 31th of May.

If you want to talk about a library you developed, or you know well
and want to share your knowledge, or about how you are making the best
out of Python through inventive/elegant idioms and patterns (or if you
are a language guru willing to disseminate your wisdom),

you can submit a proposal for the Python Language and Libraries
track



A track about Python the Language, all batteries included. Talks about
the language, language evolution, patterns and idioms, implementations
(CPython, IronPython, Jython, PyPy ...) and implementation issues belong
to the track. So do talks about the standard library or interesting
3rd-party libraries (and frameworks), unless the gravitational pull of
other tracks is stronger.


The full call and submission links are at:

http://www.europython.org/sections/tracks_and_talks/call-for-proposals

Samuele Pedroni, Python Language and Libraries Track Chair

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


released: RPyC 2.60

2006-05-19 Thread sebulba
Remote Python Call (RPyC) 2.60 has been released.

changelog:
*  added: __version__ to the package (i.e., assert Rpyc.__version__
 (2,50))
* added deliver, the counterpart of obtain()
* deliver and obtain now support transfering functions
* added DeliveringNamespace
* added isproxy
* improvements to the isinstance/issubclass mechanism
* improved memory consumption with __slots__ to all objects
(proxies can be plentiful, so it's better to keep them small)
* fix: SecSocketConnection now raises LoginError instead of
tlslite's internal errors

see the release notes (on the website) for more info

home:
http://rpyc.wikispaces.com


-tomer

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: import woe

2006-05-19 Thread Serge Orlov
[EMAIL PROTECTED] wrote:
 hello,

 i have a problem.  i would like to import python files above and below
 my current directory.

 i'm working on /home/foo/bar/jar.py

 i would like to import /home/foo/car.py and
/home/foo/bar/far.py

 how can i do this?

$ cat ~/.bashrc
export PATH=/home/foo/:$PATH
$ cat /home/foo/application
#!/usr/bin/env python
import bar.jar
$ chmod +x /home/foo/application
$ cd /home/foo/bar
$ application
 all imports work fine ...

 ps: i want to scale, so i do not want to edit the python path

In what sense do you want to scale, working with multiple projects or
multiple versions of one project at the same time? Anyway you are to
quick to jump to conclusions, if you don't want to edit python path who
will do it for you? Python path won't appear out of thin air if your
file layout is not supported out of the box.

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


Re: number of different lines in a file

2006-05-19 Thread Fredrik Lundh
r.e.s. wrote:

 BTW, the first thing I tried was Fredrik Lundh's program:
 
 def number_distinct(fn):
  return len(set(s.strip() for s in open(fn)))
 
 which worked without the square brackets. Interesting that 
 omitting them doesn't seem to matter.

a for loop inside square brackets is a list comprehension, and the
result is a list.  if you use a list comprehension inside a function 
call, the full list is built *before* the function is called.  in this 
case, this would mean that the entire file would be read into memory 
before the set was constructed.

if you change the square brackets to ordinary parentheses, you get a 
generator expression instead:

 http://pyref.infogami.com/generator-expressions

the generator expression results in an iterator object that calculates 
the values one by one.  if you pass it to a function that expects an 
iterator, that function will end up running the for loop itself, and 
no extra storage is needed.  (in this case, you still need memory to 
hold the set, of course, so the difference between a list comprehension 
and a generator expression will only matter if you have lots of duplicates).

finally, a syntax shortcut lets you remove the parentheses if the 
generator expression is the only argument in a function call, as in the 
  above example.

/F

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


Re: newb: comapring two strings

2006-05-19 Thread Peter Otten
manstey wrote:

 Is there a clever way to see if two strings of the same length vary by
 only one character, and what the character is in both strings.
 
 E.g. str1=yaqtil str2=yaqtel
 
 they differ at str1[4] and the difference is ('i','e')
 
 But if there was str1=yiqtol and str2=yaqtel, I am not interested.
 
 can anyone suggest a simple way to do this?
 
 My next problem is, I have a list of 300,000+ words and I want to find
 every pair of such strings. I thought I would first sort on length of
 string, but how do I iterate through the following:

Not sure if it can handle 30 words, but here is something to play with.

import sys

def find_similars(words, lookup=None, dupes=None):
if lookup is None:
lookup = {}
if dupes is None:
dupes = set()
for word in words:
low_word = word.lower()
if low_word not in dupes:
dupes.add(low_word)
last = None
for i, c in enumerate(low_word):
if c == last: continue
key = low_word[:i], low_word[i+1:]
if key in lookup:
lookup[key].append(word)
else:
lookup[key] = [word]
last = c
return (group for group in lookup.itervalues() if len(group)  1)

def main():
import optparse
parser = optparse.OptionParser()
parser.usage +=  infile[s]
parser.add_option(-n, --limit, type=int, help=process at most
LIMIT words)
options, args = parser.parse_args()
if args:
words = (w.strip() for fn in args for w in open(fn))
else:
words = (w.strip() for w in sys.stdin)
if options.limit is not None:
from itertools import islice
words = islice(words, max_len)

for group in find_similars(words):
print  .join(sorted(group))

if __name__ == __main__:
main()
 
Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which is More Efficient?

2006-05-19 Thread Fredrik Lundh
Dustan wrote:

 Obviously it takes a geek to know you have to time it, as opposed to
 any other task you could be talking about.

wasn't the original question my program uses a lot of CPU, and I want 
to make it more efficient ?  what does a lot of CPU and more 
efficient mean to you, and how do you know that your program uses a 
lot of CPU ?

/F

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


Re: import woe

2006-05-19 Thread vaibhav
Hi bob,

1. decide the directory which will be your root folder containing foo
[/home/ROOT/foo/]

2. work out your directory structure relative to this root folder
 here it is -ROOT-foo-car.py
   -bar-far.py
   -bar-jar.py

3. add __init__.py file inside each folder containing a list variable
__all__ with contents as the name of the directories and classes
so foo folder should contain a file called __init__.py which has the
following contents
__all__ = ['bar','car']
and bar folder should contain a file called __init__.py which has the
following contents
__all__ = ['far','jar']

4. add the root folder to your sys.path
so your jar.py file should have the  following entries
from sys import path
path.append('../../../ROOT')

note: i prefer relative paths or make paths using os.getcwd
combinations in such situations, which makes the class more flexible.
you can also do this step where u configure/initialize

5. then you can import the classes you want in jar.py

from foo import car
from foo.bar import far

pls mail if u dont get it working/any doubts.  

-
vaibhav

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


Getting URL's

2006-05-19 Thread defcon8
How do I get all the URL's in a page?

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


Re: Getting URL's

2006-05-19 Thread Ju Hui
use 
htmlparser or regular expression

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


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-19 Thread PoD
On Thu, 18 May 2006 08:30:03 +, Duncan Booth wrote:

 PoD wrote:
 How many levels of indentation does 12 spaces indicate?
 It could be 1,2,3,4,6 or 12.  If you say it's 3 then you are
 _implying_ that each level is represented by 4 spaces.
 
 By reading the code I can see how many levels of indentation it
 represents. 
 
 How many levels of indentation is 3 tabs?  3 levels in any code that
 you will find in the wild.
 
 No. That is precisely the problem: there is code in the wild which
 contains mixed space and tab indentation, and any time that happens 3
 tabs could mean any number of indentations. 

I think it is universally accepted that mixed tabs and spaces is indeed
**EVIL**

I should have said any code using tabs exclusively.

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


Re: who can give me the detailed introduction of re modle?

2006-05-19 Thread Gary Herron
softwindow wrote:

the re module is too large and difficult to study

i need a detaild introduction.

  

That's not the kind of question that's likely to get a useful response 
from an all volunteer newsgroup community, even one with as friendly a 
reputations as this one.

Here's my suggestion:

Read the manual page at http://docs.python.org/lib/module-re.html, then 
try to apply it to a specific problem you'd like to solve with regular 
expressions. Any problems you run into at that point will be quite 
specific. If you list the problem you tried to solve, your solution 
attempt, and what failed, you will likely get lots of useful answers here.

But you have to take the first step. P.S. The re module is really not 
all *that* difficult.

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


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-19 Thread PoD
On Thu, 18 May 2006 10:33:58 +0200, Christophe wrote:

 PoD a écrit :
 On Wed, 17 May 2006 21:37:14 +0800, Andy Sy wrote:
 
 
If tabs are easily misunderstood, then they are a MISfeature
and they need to be removed.

From the Zen of Python:

Explicit is better than implicit...
In the face of ambiguity, refuse the temptation to guess...
Special cases aren't special enough to break the rules...
 
 
 Exactly.
 How many levels of indentation does 12 spaces indicate?
 It could be 1,2,3,4,6 or 12.  If you say it's 3 then you are _implying_
 that each level is represented by 4 spaces.
 
 Actually, who said you had to always use the same number of spaces to 
 indent ? 12 = 6 + 6 = 4 + 4 + 4 but also 12 = 2 + 10 = 1 + 1 + 3 + 3 + 4 :D

Thus supporting my assertion that space indenting is implicit not
explicit. Spaces are evil.

 
 How many levels of indentation is 3 tabs?  3 levels in any code that
 you will find in the wild.
 
 No, it could be 3 levels or 3 tabs per level or 2 tabs for the first
 level and 1 tab for the second ...

Could be but wouldn't be.

Maybe what Python should do (but never will given the obsession with using
spaces) is only allow one level of indentation increase per block so that

def foo():
TABTABreturn 'bar'

would return a syntax error

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


Re: Getting URL's

2006-05-19 Thread defcon8
Thanks

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


Re: Getting URL's

2006-05-19 Thread Paul McGuire
defcon8 [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 How do I get all the URL's in a page?


pyparsing comes with a simple example that does this, too.

-- Paul
Download pyparsing at http://sourceforge.net/projects/pyparsing


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


Re: Script to make Windows XP-readable ZIP file

2006-05-19 Thread John Bokma
softwindow [EMAIL PROTECTED] wrote:

 Carl Banks  is right

Did he write to check out:
http://groups.google.com/support/bin/answer.py?answer=14213 ?

Why didn't you do so?

-- 
John   MexIT: http://johnbokma.com/mexit/
   personal page:   http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: who can give me the detailed introduction of re modle?

2006-05-19 Thread vaibhav
easy and convenient way to get a good introduction for any module
[especially if ur stuck and dont have internet connectivity]:

1. start python interpreter
$ python

2. import the module and ask it for help :-)
 import re
 help(re)

-vaibhav

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


Re: who can give me the detailed introduction of re modle?

2006-05-19 Thread softwindow
thanks for your advice!

:)

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


Re: WTF? Printing unicode strings

2006-05-19 Thread Ron Garret
In article [EMAIL PROTECTED],
 Serge Orlov [EMAIL PROTECTED] wrote:

 Ron Garret wrote:
I'm using an OS X terminal to ssh to a Linux machine.
  
   In theory it should work out of the box. OS X terminal should set
   enviromental variable LANG=en_US.utf-8, then ssh should transfer this
   variable to Linux and python will know that your terminal is utf-8.
   Unfortunately AFAIK OS X terminal doesn't set that variable and most
   (all?) ssh clients don't transfer it between machines. As a workaround
   you can set that variable on linux yourself . This should work in the
   command line right away:
  
   LANG=en_US.utf-8 python -c print unichr(0xbd)
  
   Or put the following line in ~/.bashrc and logout/login
  
   export LANG=en_US.utf-8
 
  No joy.
 
  [EMAIL PROTECTED]:~$ LANG=en_US.utf-8 python -c print unichr(0xbd)
  Traceback (most recent call last):
File string, line 1, in ?
  UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in
  position 0: ordinal not in range(128)
  [EMAIL PROTECTED]:~$
 
 What version of python and what shell do you run? What the following
 commands print:
 
 python -V
 echo $SHELL
 $SHELL --version

[EMAIL PROTECTED]:~$ python -V
Python 2.3.4
[EMAIL PROTECTED]:~$ echo $SHELL
/bin/bash
[EMAIL PROTECTED]:~$ $SHELL --version
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
Copyright (C) 2002 Free Software Foundation, Inc.
[EMAIL PROTECTED]:~$
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-19 Thread Duncan Booth
PoD wrote:
 I think it is universally accepted that mixed tabs and spaces is indeed
 **EVIL**
 
 I should have said any code using tabs exclusively.
 
Can you point at any significant body of publically visible Python code 
which uses tabs exclusively? All of the Python projects I've ever been 
involved with use spaces only as a convention (although as I pointed out in 
my previous post, some with more success than others).

The problem with conventions such as 'tabs only' or 'space only' is that 
they only work if everyone sticks to the conventions, and it helps if the 
same conventions are in place everywhere (otherwise people forget when they 
switch from one project to another). Also, in the open source universe you 
are quite likely to pull in bits of code from other projects, and you don't 
want to either have to reformat it or to switch your editor settings for 
some files.

My experience of programming with either spaces or tabs has taught me 
that tabs are evil not for themselves, but simply because no matter how 
hard you try they always end up being mixed with spaces.

Do you know of any open-source projects which actually try to enforce a 
'tab only' convention for Python? I'd really like to see a similar scan 
over some 'tab only' code as I did over Plone to see whether they actually 
manage to remain 'pure'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter Dialog Management problems:

2006-05-19 Thread Eric Brunel
On Thu, 18 May 2006 11:52:54 -0400, Michael Yanowitz  
[EMAIL PROTECTED] wrote:
 Thanks.  That helped alot.

No problem.

 However it leaves a couple very minor problems which I think I can live
 with.
 1) It brings up an empty additional 'main window'.
I have tried using the Tkinter.NoDefaultRoot() option, but run into
other problems with other things not defined.
 NameError: global name '_default_root' is not defined
 Exception exceptions.AttributeError: IntVar instance has no attribute
 '_tk' in
  bound method IntVar.__del__ of Tkinter.IntVar instance at 0x009C7990
 ignored

 2) By deriving the 'dialog' from Tk, existing calls to self.pack() no
longer are valid, but they don't appear to be necessary.

   My only 'Tkinter tutorial' is what is included in Orielly's  
 Programming
 Python. Still looking for a good tutorial. I am not clear what the
 difference
 between Tk() and Toplevel() are. They seem totally interchangeable.

No, they're not! Never - and I mean *never* - create two instances of Tk  
in the same application! The Tk instance does not only represent the main  
window for the application, but also creates the underlying tcl  
interpreter. Creating two instances of Tk will then create two  
interpreters and you'll never know which one executes your commands,  
producing weird TclError's everywhere.

If you have a window which can be considered as the main window for your  
application - there is only one of it, it is always there and closing it  
means quitting the application -, then make it a sub-class of Tk. If you  
do not have such a window, use the following trick at the beginning of  
your application:

root = Tkinter.Tk()
root.withdraw()

This basically creates a main window and immediately hides it. All your  
other windows must be sub-classes of Toplevel. Calling the quit method of  
these windows should still quit the application, and calling the destroy  
method should only close the window.

As for tutorials, there are many; just see there:
http://tkinter.unpy.net/wiki/Tkinter
Apart from the one already given by Rony (which is more a reference than a  
tutorial), my favorite ones are:
- Stephen Ferg's Thinking in Tkinter -  
http://www.ferg.org/thinking_in_tkinter/index.html
- The one at http://doctormickey.com/python/index.html
- Gerard Swinnen's Apprendre a programmer avec Python (in French) -  
http://www.cifen.ulg.ac.be/inforef/swi/python.htm
At least, these ones avoid the confusion Frame/window usually found in  
many others: the first two don't use inheritance at all; only the last  
(the one in French) implements windows as sub-classes of Tk or Toplevel.  
Unfortunately, I don't know any english translation of it.

A last advice: if you want to do serious Tkinter, it really helps to know  
how the underlying tcl/tk layer works. So maybe you should learn at least  
the basics of tcl/tk. And if you do that, you will be able to use tcl/tk  
resources, such as:
http://www.tcl.tk/man/
which is the only documentation I ever need now...

HTH
-- 
python -c print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Complex evaluation bug

2006-05-19 Thread Christophe
Gary Herron a écrit :
 of wrote:
 
 a = 1+3j
 complex(str(a))

 Why does this not work ? It should
  

 Says who?
 By normal conventions in Python, str attempts only to make a nice 
 human readable representation.  The function repr is usually expected 
 to provide output that can be parsed back into the original object.  
 (Although for the  numeric complex type the two produce identical results.)
 
 Further, constructors are rarely expected to parse a string 
 representation to return an object.  The function eval is usually 
 expected to provide that functionality.
 
 So, putting them together, you could expect
eval(repr(a))
 to reproduce a, and in fact it does so.

Says who ?

Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.
  repr(1+3j)
'(1+3j)'
  complex(repr(1+3j))
Traceback (most recent call last):
   File stdin, line 1, in ?
ValueError: complex() arg is a malformed string
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-19 Thread Christophe
PoD a écrit :
 Maybe what Python should do (but never will given the obsession with using
 spaces) is only allow one level of indentation increase per block so that
 
 def foo():
 TABTABreturn 'bar'
 
 would return a syntax error

Which would make TAB mandatory for indentation. What about some 
freedom of choice ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting URL's

2006-05-19 Thread softwindow
it is difficult to get all URL's in a page
you can use sgmllib module to parse html files
can get the standard href .

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


Re: Complex evaluation bug

2006-05-19 Thread Fredrik Lundh
Christophe wrote:

 So, putting them together, you could expect
eval(repr(a))
 to reproduce a, and in fact it does so.
 
 Says who ?
 
 Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on 
 win32
 Type help, copyright, credits or license for more information.
   repr(1+3j)
 '(1+3j)'
   complex(repr(1+3j))
 Traceback (most recent call last):
File stdin, line 1, in ?
 ValueError: complex() arg is a malformed string
  

in what language is eval spelled complex ?

/F

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


Re: Complex evaluation bug

2006-05-19 Thread Christophe
Fredrik Lundh a écrit :
 Christophe wrote:
 
 So, putting them together, you could expect
eval(repr(a))
 to reproduce a, and in fact it does so.


 Says who ?

 Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] 
 on win32
 Type help, copyright, credits or license for more information.
   repr(1+3j)
 '(1+3j)'
   complex(repr(1+3j))
 Traceback (most recent call last):
File stdin, line 1, in ?
 ValueError: complex() arg is a malformed string
  
 
 
 in what language is eval spelled complex ?
 
 /F
 

Oups, I was too fast to read what was written. I though you only changed 
one of the terms ( str - repr ).

You'll note that repr and str produce the exact same result for complex. 
And also, I'm not sure using eval anywhere is a good idea so it probably 
doesn't help for what the OP wants to do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-19 Thread Sybren Stuvel
Duncan Booth enlightened us with:
 Can you point at any significant body of publically visible Python
 code which uses tabs exclusively?

Everything Python at http://www.stuvel.eu/software

 Also, in the open source universe you are quite likely to pull in
 bits of code from other projects, and you don't want to either have
 to reformat it or to switch your editor settings for some files.

If I grab a module, I just leave the module as is. If I grab a code
snippet, I always reformat it to my own style. That's very easy using
VIM's retab command.

 Do you know of any open-source projects which actually try to enforce a 
 'tab only' convention for Python?

My software is, although I'm still the only one working on them ;-)

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: who can give me the detailed introduction of re modle?

2006-05-19 Thread Simon Brunning
On 18 May 2006 22:50:24 -0700, softwindow [EMAIL PROTECTED] wrote:
 the re module is too large and difficult to study

 i need a detaild introduction.

http://gnosis.cx/publish/programming/regular_expressions.html

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Opensource vs Microsoft, Wat do you think about opensource?

2006-05-19 Thread Sybren Stuvel
Ben Finney enlightened us with:
 Please don't spam here to ask for discussion on another forum, on a
 tangentially related topic.

Hey, it's at least better than asking for a discussion on a
tangentially related topic _here_ ;-)

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie append() question

2006-05-19 Thread Sybren Stuvel
Brian Blazer enlightened us with:
 def getCurrentClasses():
  classes = []
  print 'Please enter the class name. When finished enter D.'
  while (c != D):

No need for the parentheses, and 'c' doesn't have a value yet. If you
add 'c=' before the while-loop, it should be fine.

  c = raw_input(Enter class name)
  if (c != D):

Here there is also no need for parentheses.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Segmenting a pickle stream without unpickling

2006-05-19 Thread Boris Borcic
Assuming that the items of my_stream share no content (they are
dumps of db cursor fetches), is there a simple way to do the
equivalent of

def pickles(my_stream) :
 from cPickle import load,dumps
 while 1 :
 yield dumps(load(my_stream))

without the overhead associated with unpickling objects
just to pickle them again ?

TIA, Boris Borcic
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: galaxql

2006-05-19 Thread Steve Holden
Further to my recent mention of galaxql as a SQL learning tool, I had 
the following feedback through holdenweb.com:

 Below is the result of your feedback form.  It was submitted by
 jari komppa ([EMAIL PROTECTED]) on Friday, May 19, 2006 at 00:07:53
 ---
 
 
 comments: Steve Holden wrote: Also I just discovered a shareware 
 application called galaxql.. 
  
 I'd like to note that it's not shareware - I'm not asking money for it. 
 Thanks for spreading the word =)
 
 ---
 
Aah, so I should have called it freeware? I believe it's not open 
source, but I may be incorrect there too - I just downloaded a Windows 
installer, which worked very smoothly. Sorry to be inaccurate. I am 
posting to python-list@python.org to correct the mistake. Please feel 
free to post there yourself to direct people to the Galaxql web site.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
-- 
http://mail.python.org/mailman/listinfo/python-list


ftplib.ftpcp(), undocumented function?

2006-05-19 Thread swordsp
Hi all,
I found this function recently when I read the source code of ftplib
module, I almost omit it at all and have tried to write it myself for
FXP work.
It seems exist long long ago, but never appeared  in any document,
anyone knows why?
Is its implementation broken or planed to be removed from standard
library?

--
Gong Li

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


Re: WTF? Printing unicode strings

2006-05-19 Thread Serge Orlov
Ron Garret wrote:
 In article [EMAIL PROTECTED],
  Serge Orlov [EMAIL PROTECTED] wrote:

  Ron Garret wrote:
 I'm using an OS X terminal to ssh to a Linux machine.
   
In theory it should work out of the box. OS X terminal should set
enviromental variable LANG=en_US.utf-8, then ssh should transfer this
variable to Linux and python will know that your terminal is utf-8.
Unfortunately AFAIK OS X terminal doesn't set that variable and most
(all?) ssh clients don't transfer it between machines. As a workaround
you can set that variable on linux yourself . This should work in the
command line right away:
   
LANG=en_US.utf-8 python -c print unichr(0xbd)
   
Or put the following line in ~/.bashrc and logout/login
   
export LANG=en_US.utf-8
  
   No joy.
  
   [EMAIL PROTECTED]:~$ LANG=en_US.utf-8 python -c print unichr(0xbd)
   Traceback (most recent call last):
 File string, line 1, in ?
   UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in
   position 0: ordinal not in range(128)
   [EMAIL PROTECTED]:~$
 
  What version of python and what shell do you run? What the following
  commands print:
 
  python -V
  echo $SHELL
  $SHELL --version

 [EMAIL PROTECTED]:~$ python -V
 Python 2.3.4
 [EMAIL PROTECTED]:~$ echo $SHELL
 /bin/bash
 [EMAIL PROTECTED]:~$ $SHELL --version
 GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
 Copyright (C) 2002 Free Software Foundation, Inc.
 [EMAIL PROTECTED]:~$

That's recent enough. I guess the distribution you're using set LC_*
variables for no good reason. Either unset all enviromental variables
starting with LC_ and set LANG variable or overide LC_CTYPE variable:

LC_CTYPE=en_US.utf-8 python -c print unichr(0xbd)

Should be working now :)

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


Re: Question about exausted iterators

2006-05-19 Thread Christophe
Terry Reedy a écrit :
 Christophe [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 
Instead of saying that all works as intended could you be a little
helpful and tell me why it was intended in such an obviously broken way
instead ?
 
 
 I answered both your explicit and implied questions in good faith.  But you 
 seem to be too attached to your pre-judgment to have benefited much, so I 
 won't waste my time and yours saying more.  Instead I suggest that you try 
 this:
 
 1. Write a specification for your an alternate, more complicated, iterator 
 protocol.

Specification : same as now except iterators raise once StopIteration 
and any subsequent call to next raises ExaustedIteratorError.

 2. Write a simple class with .next method that implements your 
 specification.

class ExaustedIteratorError(Exception):
 pass

class safe_iter(object):
 def __init__(self, seq):
 self.it = iter(seq)
 def __iter__(self):
 return self
 def next(self):
 try:
 return self.it.next()
 except StopIteration:
 del self.it
 raise
 except AttributeError:
 raise ExaustedIteratorError

 3. Test your class with your example.

  it = safe_iter(range(10))
  print list(it)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  print list(it)
Traceback (most recent call last):
   File safe_iter_test.py, line 20, in ?
 print list(it)
   File safe_iter_test.py, line 13, in next
 raise ExaustedIteratorError
__main__.ExaustedIteratorError

 4. Consider how you would persuade people to add the extra machinery 
 needed.

Well, the main reason for such change is and will always be to catch 
bugs. The fact is, using duct typing is something very common with the 
Python language. And as such, considering a lot of functions which take 
sequences as parameters work as well with an iterator instead, you can 
say that it's an application of duct typing.

The problem is of course the same as for cases. Even if those two objets 
( iterator and container ) look alike from a certain point of view, they 
have some fundamental differences.

So, we have quite a few functions which take freely either a container 
or an iterator, until someone changes that function a little. At that 
point there are three kind errors which happen :
- the function expected a sequence and tries to access it's [] operator 
which fails. Standard duct typing behaviour.
- the function uses the iterator more than once and so, sometimes it 
works without errors but produces an incorrect result.
- the function uses the iterator more than once but never exhausts it's 
values. Same result as above but much harder to catch.

In the sake of avoiding behaviour which lets obvious errors pass and 
produces incorrect results, I propose to change the standard behaviour 
of all the iterators in the standard Python. The change will be so that 
they refuse to be used anymore once they have been exausted. Thus it'll 
help catch the second class. The other procedure used to catch such bugs 
would require explicit typing of the function parameters but this is for 
some other proposal.

 5. Consider what you would do when people don't.

I'm already doing it. Cleaning up the code, changing parameters names 
around so that it is clear such parameter is an iterator and that other 
one is not, making some functions explicitly refuse iterators etc ... It 
should not that that last feature will be useful even without the 
exhausted iterator guard I propose.

 If you want, post a report on your experiment, and I will read it if I see 
 it.

I suppose I could add safe_iter to the builtins in my project and use it 
around. It would be easy to catch all usages of that one once we settle 
on something different then.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Segmenting a pickle stream without unpickling

2006-05-19 Thread Paul Rubin
Boris Borcic [EMAIL PROTECTED] writes:
 def pickles(my_stream) :
  from cPickle import load,dumps
  while 1 :
  yield dumps(load(my_stream))
 
 without the overhead associated with unpickling objects
 just to pickle them again ?

I think you'd have to write something special.  The unpickler parses
as it goes along, and all the dispatch actions build up objects.
You'd have to write a set of actions that just read past the
representations.  I think there's no way to know where an object ends
without parsing it, including parsing any objects nested inside it.

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


Specific performance question - Python vs. Java

2006-05-19 Thread reinsn
Hi,

I have got a specific question on performance: Is the overhead of
object creation in Python lower than in Java? I mean, I would argue, in
Java by object creation, the complete class is the model and all
methods and attributes are generated for the object.
In Python, methods and objects are only generated, if reached: so could
this represent a performance advantage for Python?

Thanks!

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


Re: Programming language productivity

2006-05-19 Thread malv
John Bokma wrote:
 Connelly Barnes [EMAIL PROTECTED] wrote:

  http://barnesc.blogspot.com/2006/05/programming-language-productivity.h
  tml

 C:3 hours to write the program, 5 hours to track down the memory leaks
 Java: 4 hours to write the program, 6 hours to get all the exception
   handling right
 C++   5 hours to write the program after reading Stroustrup for 6 hours

 Just kidding, of course.

 Also note that Python programmers write more lines/hour which they need to
 finish in the same time as Perl programmers :-D.

 --
 John   MexIT: http://johnbokma.com/mexit/
personal page:   http://johnbokma.com/
 Experienced programmer available: http://castleamber.com/
 Happy Customers: http://castleamber.com/testimonials.html
I am not shure whether your criterion is very valid. OK if you have to
write only one compact piece of code like in your example. Sometimes I
think that most python users fall within this category.

Once you get involved in larger projects, the dynamic nature of the
programming tool becomes much more important. I mean by this, the
ability to stop running code, modify or add to it and continue without
having to re-establish the state of the program. This may sound trivial
to many, but in major applications setting up the state again can take
a considerable processing time. Such feature should be available from
within the debugging tools.

In fact, languages like Smalltalk, Lisp and even VB offer this
possibility.
Ruby coming up strongly these days also has this dynamic reload
capability.
To sum up, I like Python very much but I don't understand how come this
basic flaw has not been taken care of. It is sufficient to search for
reload to see how many people have struggled with it over the years.
I hate the idea of having to take up Ruby to really find out how it
could serve me better in this most critical productivity area.

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


Re: Specific performance question - Python vs. Java

2006-05-19 Thread Diez B. Roggisch
reinsn wrote:

 Hi,
 
 I have got a specific question on performance: Is the overhead of
 object creation in Python lower than in Java? I mean, I would argue, in
 Java by object creation, the complete class is the model and all
 methods and attributes are generated for the object.
 In Python, methods and objects are only generated, if reached: so could
 this represent a performance advantage for Python?

No, this is a misunderstanding on your side. In all OO-languages, the code
(methods) are separated from the instance. Thus creating an object results
in memory allocation _only_ for the members of that object, not any
methods! In python, this boils down to a dictionary holding the members,
JAVA/C++ allocate whatever the class makes them to. 

So, no, no performance advantage.

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


calling python functions using variables

2006-05-19 Thread creo
Hi all!

this is a (relatively) newbie question


I am writing a shell in Python and I am facing a problem

The problem is, after taking the input from user, i have to execute the
command which is a python function

i invoke an 'ls' command like this
commands.ls()
where commands.py is a file in the same directory

what i want to do is
commands.VARIABLE()
where VARIABLE holds the name of the function which i want to execute
and depends on what the user has typed


what should i do to achieve that?

any help is appreciated

thank you

-creo


P.S. if you want me to clarify the question, please tell me so

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


Re: Windows Registry Dump

2006-05-19 Thread Dirk Hagemann
@Diez: I'm not trying to hack into somebody's computer - it is about
collecting data from my company's anti-virus-parent-server. And all the
information is only available in the registry (thanks Symantec...).

@Tim, olso and Fredrik: THANKS - I will have a closer look at these
modules.

regards
Dirk

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


Re: calling python functions using variables

2006-05-19 Thread Peter Otten
creo wrote:

 i invoke an 'ls' command like this
 commands.ls()
 where commands.py is a file in the same directory
 
 what i want to do is
 commands.VARIABLE()
 where VARIABLE holds the name of the function which i want to execute
 and depends on what the user has typed

You want

getattr(commands, VARIABLE)()

Peter

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


RE: Windows Registry Dump

2006-05-19 Thread Tim Golden
[Dirk Hagemann]

| @Diez: I'm not trying to hack into somebody's computer - it is about
| collecting data from my company's anti-virus-parent-server. 
| And all the
| information is only available in the registry (thanks Symantec...).
| 
| @Tim, olso and Fredrik: THANKS - I will have a closer look at these
| modules.

One thing occurred to me later, Dirk: are you trying to
get the conventional .reg dump file, ie something which
you could reload later into the same or another computer?
Or are you simply looking for a textual representation of
the registry for analysis etc.? From your comment above
it sounds like the latter.

Be aware, btw, if you go down the .reg route (the one
I suggested): the data in the files are UTF-16 encoded.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


how to read a list from python in C?

2006-05-19 Thread Lialie KingMax

Hi, all

I am writing a C extension with .Net.
Now I have a list of points, like [(0.0, 0.0), (2.0, 3.0), (random x,
random y)].
Is there a better way to translate it to an array than doing it one by one?

Thanks


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

Re: calling python functions using variables

2006-05-19 Thread Ben Finney
Peter Otten [EMAIL PROTECTED] writes:

 creo wrote:
  what i want to do is
  commands.VARIABLE()
  where VARIABLE holds the name of the function which i want to execute
  and depends on what the user has typed
 
 You want
 
 getattr(commands, VARIABLE)()

You'll also need to anticipate the situation where the value bound to
VARIABLE is not the name of an attribute in 'commands'.

Either deal with the resulting NameError exception (EAFP[0]) or test
first whether the attribute exists (LBYL[1]).

[0] Easier to Ask Forgiveness than Permission
[1] Look Before You Leap

-- 
 \   Our products just aren't engineered for security.  -- Brian |
  `\ Valentine, senior vice-president of Microsoft Windows |
_o__)  development |
Ben Finney

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


Re: who can give me the detailed introduction of re modle?

2006-05-19 Thread Kent Johnson
softwindow wrote:
 the re module is too large and difficult to study
 
 i need a detaild introduction.
 
http://www.amk.ca/python/howto/regex/

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


Python and Test Driven Development

2006-05-19 Thread Diego Torres Milano

			First part of a series of articles about Python and Test Driven Development can be found at http://dtmilano.blogspot.com/2006/05/python-and-test-driven-development.html.


These articles include some scripts to ease automatic test suite creation in Python.


Comments are gladly welcome.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Windows Registry Dump

2006-05-19 Thread Dirk Hagemann
Hi Tim!

I want to do some analysis (as always ;-) ) and for that reason I think
it's more practical to go trough a text-file. I can produce this
text-file also by right-click on the key (the  folder) in the registry
and select Export. There one can select Text-File and the place where
to save the text-file. This I want to be done by python automatically.

Dirk

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


RE: Windows Registry Dump

2006-05-19 Thread Tim Golden
[Dirk Hagemann]

| I want to do some analysis (as always ;-) ) and for that 
| reason I think
| it's more practical to go trough a text-file. I can produce this
| text-file also by right-click on the key (the  folder) in the registry
| and select Export. There one can select Text-File and the 
| place where
| to save the text-file. This I want to be done by python automatically.

Well, unless you want to go to the effort of recreating
the .reg file format, it's probably worth trying to call
regedit with a param or two:

http://www.windowsitlibrary.com/Content/237/2.html

suggests that something like:

regedit /e c:\temp\desktop.reg HKEY_CURRENT_USER\Control Panel\Desktop

will do the business. (And it worked for me a on a simple test run).

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: calling python functions using variables

2006-05-19 Thread bruno at modulix
Ben Finney wrote:
 Peter Otten [EMAIL PROTECTED] writes:
(snip)

You want
getattr(commands, VARIABLE)()
 
 You'll also need to anticipate the situation where the value bound to
 VARIABLE is not the name of an attribute in 'commands'.
 
 Either deal with the resulting NameError exception (EAFP[0])

try:
  getattr(commands, VARIABLE)()
except NameError:
  print  sys.stderr, Unknown command, VARIABLE

 or test
 first whether the attribute exists (LBYL[1]).

command = getattr(commands, VARIABLE, None)
if command is None:
  print  sys.stderr, Unknown command, VARIABLE
else:
  command()

I'd go for the first solution.

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: who can give me the detailed introduction of re modle?

2006-05-19 Thread bruno at modulix
softwindow wrote:
 the re module is too large and difficult to study

Too bad.

 i need a detaild introduction.

That's fine. Then write it. Or pay someone to do so.

Just for the record : that's the only answers you would have get on most
usenet groups. Hopefully, c.l.py is a very friendly and tolerant newsgroup.

Seriously, do yourself a favour, read this:
http://www.catb.org/~esr/faqs/smart-questions.html

HTH
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which is More Efficient?

2006-05-19 Thread Dustan

Fredrik Lundh wrote:
 Dustan wrote:

  Obviously it takes a geek to know you have to time it, as opposed to
  any other task you could be talking about.

 wasn't the original question my program uses a lot of CPU, and I want
 to make it more efficient ?  what does a lot of CPU and more
 efficient mean to you, and how do you know that your program uses a
 lot of CPU ?

The task manager says CPU Usage: 100% when the program is running,
and only when the program is running.

Efficiency is a measure of 2 things: CPU usage and time. If you measure
just time, you're not necessarily getting the efficiency.

 
 /F

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


Re: Which is More Efficient?

2006-05-19 Thread Dustan
Dustan wrote:
 Fredrik Lundh wrote:
  Dustan wrote:
 
   Obviously it takes a geek to know you have to time it, as opposed to
   any other task you could be talking about.
 
  wasn't the original question my program uses a lot of CPU, and I want
  to make it more efficient ?  what does a lot of CPU and more
  efficient mean to you, and how do you know that your program uses a
  lot of CPU ?

 The task manager says CPU Usage: 100% when the program is running,
 and only when the program is running.

 Efficiency is a measure of 2 things: CPU usage and time. If you measure
 just time, you're not necessarily getting the efficiency.

 
  /F

By the way, I've only been programming for a year or so (probably 18
months at the most). I'm sure that can't label me as a 'newbie', but at
least consider that before you criticize me like you did when I asked
about scientific notation.

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


Encode exception for chinese text

2006-05-19 Thread Vinayakc
Hi all,

I am new to python.

I have written one small application which reads data from xml file and
tries to encode data using apprpriate charset.
I am facing problem while encoding one chinese paragraph with charset
gb2312.

code is:

encoded_str = str_data.encode(gb2312)

The type of str_data is type 'unicode'

The exception is:

UnicodeEncodeError: 'gb2312' codec can't encode character u'\xa0' in
position 0: illegal multibyte sequence

Can anyone please give me direction to solve this isssue.

Regards,
Vinayakc

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


Re: Newbie append() question

2006-05-19 Thread Brian Blazer
Thanks guys.  Your solutions worked.

I'm still not sure why it was grabbing the prompt string though.

Thanks again,

Brian
[EMAIL PROTECTED]

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


Re: Encode exception for chinese text

2006-05-19 Thread swordsp
Are you sure all the characters in original text are in gb2312
charset?

Encoding with utf8 seems work for this character (u'\xa0'), but I
don't know if the result is correct.

Could you give a subset of str_data in unicode?

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


Re: WTF? Printing unicode strings

2006-05-19 Thread Serge Orlov
Serge Orlov wrote:
 Ron Garret wrote:
  In article [EMAIL PROTECTED],
   Serge Orlov [EMAIL PROTECTED] wrote:
 
   Ron Garret wrote:
  I'm using an OS X terminal to ssh to a Linux machine.

 In theory it should work out of the box. OS X terminal should set
 enviromental variable LANG=en_US.utf-8, then ssh should transfer this
 variable to Linux and python will know that your terminal is utf-8.
 Unfortunately AFAIK OS X terminal doesn't set that variable and most
 (all?) ssh clients don't transfer it between machines. As a workaround
 you can set that variable on linux yourself . This should work in the
 command line right away:

 LANG=en_US.utf-8 python -c print unichr(0xbd)

 Or put the following line in ~/.bashrc and logout/login

 export LANG=en_US.utf-8
   
No joy.
   
[EMAIL PROTECTED]:~$ LANG=en_US.utf-8 python -c print unichr(0xbd)
Traceback (most recent call last):
  File string, line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in
position 0: ordinal not in range(128)
[EMAIL PROTECTED]:~$
  
   What version of python and what shell do you run? What the following
   commands print:
  
   python -V
   echo $SHELL
   $SHELL --version
 
  [EMAIL PROTECTED]:~$ python -V
  Python 2.3.4
  [EMAIL PROTECTED]:~$ echo $SHELL
  /bin/bash
  [EMAIL PROTECTED]:~$ $SHELL --version
  GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
  Copyright (C) 2002 Free Software Foundation, Inc.
  [EMAIL PROTECTED]:~$

 That's recent enough. I guess the distribution you're using set LC_*
 variables for no good reason. Either unset all enviromental variables
 starting with LC_ and set LANG variable or overide LC_CTYPE variable:

 LC_CTYPE=en_US.utf-8 python -c print unichr(0xbd)

 Should be working now :)

I've pulled myself together and installed linux in vwware player.
Apparently there is another way linux distributors can screw up. I
chose debian 3.1 minimal network install and after answering all
installation questions I found that only ascii and latin-1 english
locales were installed:
$ locale -a
C
en_US
en_US.iso88591
POSIX

In 2006, I would expect utf-8 english locale to be present even in
minimal install. I had to edit /etc/locale.gen and run locale-gen as
root. After that python started to print unicode characters.

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


Re: Question about exausted iterators

2006-05-19 Thread [EMAIL PROTECTED]
Consider this example:

 X = range(5)
 Y = iter(X)
 Z = iter(Y)

As you can see, X is a container, and Y is an iterator.
They are simliar in that iter works on them both.

Cristoph claims that this causes confusion.
Why? Because iter doesn't have the same meaning for both of them.
For X it always returns an iterator that yields the same set of values.
For Y it returns an iterator yielding different values each time.

 Z = iter(Y)
 Z.next()
0
 Z = iter(Y)
 Z.next()
1

Most of the uses of iterators iterate all values until exaustion.
Given that, the first call to iter will mean the same for an iterator
and a container, but the second one won't.

Allow me to compare it to division in python 2.4
 4./2, 4/2
2.0, 2
 5./2, 5/2
2.5, 2

Division sometimes works the same for integers and reals, and sometimes
doesn't.
This caused consfusion and bugs, and that's why future Pythons will
change that.

But changing iter to have the same meaning for containers and
iterables is impossible.
You cannot, conceptually, reiterate an iterator.
So what Cristoph is suggesting - is to add an exception for the cases
in which iterators and collections behave differently.
Somewhat similar to this:

 4/2
2
 5/2
Traceback (most recent call last):
  File stdin, line 1, in ?
IntegerDivisionError: 5 does not divide by 2

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


Re: newb: comapring two strings

2006-05-19 Thread John Machin
 Use the levenshtein distance.

Given the constraint that the two strings are the same length, I'm
assuming (as other posters appear to have done) that vary by only one
character precludes insertion and deletion operations.

In that case, the problem can be solved in O(n) time by a simple loop
which counts the number of differences and notes the position of the
first (if any) difference. Any full-distance Levenshtein method that
does no pre-processing must take O(n**2) time. It is possible to take
advantage of the fact that the OP doesn't care about what the distance
is exactly if it is not 1; 0 is just as bad as 2, 3, 4, etc. In this
case it is possible to achieve O(n) time [ref. Ukkonen]. However (a)
one still needs to track where the difference arose (b) we are talking
about extreme overkill for the OP's problem.

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


memory error with zipfile module

2006-05-19 Thread Hari Sekhon
I do

import zipfile
zip=zipfile.ZipFile('d:\somepath\cdimage.zip')
zip.namelist()
['someimage.iso']

then either of the two:

A)   file('someimage.iso','w').write(zip.read('someimage.iso'))
or
B)   content=zip.read('someimage.iso')

but both result in the same error:

Traceback (most recent call last):
  File stdin, line 1, in ?
  File D:\u\Python24\lib\zipfile.py, line 357, in read
bytes = dc.decompress(bytes)
MemoryError

I thought python was supposed to handle memory for you?

The python zipfile module is obviously broken...


Any advise?

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


Re: Which is More Efficient?

2006-05-19 Thread Max Erickson
Dustan [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 
 The task manager says CPU Usage: 100% when the program is
 running, and only when the program is running.
 
 Efficiency is a measure of 2 things: CPU usage and time. If you
 measure just time, you're not necessarily getting the efficiency.
 

A lot of people, when they say 'uses a lot of CPU' are leaving off 
'time'. I.e., CPU usage is pretty much talked about in terms of 
cycles, which is roughly utilization*time. Profiling tools often 
report both clock time and cpu time. Cpu time is a rough analog for 
cycles, clock time is self explanatory.

max

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


Re: Encode exception for chinese text

2006-05-19 Thread Serge Orlov
Vinayakc wrote:
 Hi all,

 I am new to python.

 I have written one small application which reads data from xml file and
 tries to encode data using apprpriate charset.
 I am facing problem while encoding one chinese paragraph with charset
 gb2312.

 code is:

 encoded_str = str_data.encode(gb2312)

 The type of str_data is type 'unicode'

 The exception is:

 UnicodeEncodeError: 'gb2312' codec can't encode character u'\xa0' in
 position 0: illegal multibyte sequence

Hmm, this is 'no-break space' in the very beginning of the text. It
look suspiciously like a  plain text utf-8 signature which is 'zero
width no-break space'. If you strip the first character do you still
have encoding errors?

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


How to append to a dictionary

2006-05-19 Thread Harlin Seritt
I have some code here:

groups = {'IRISH' : 'green', 'AMERICAN' : 'blue'}

I want to add another key: 'ITALIAN' : 'orange'

How do I append this to 'groups'?

Thanks,

Harlin Seritt

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


Re: How to append to a dictionary

2006-05-19 Thread Tim Chase
 groups = {'IRISH' : 'green', 'AMERICAN' : 'blue'}
 
 I want to add another key: 'ITALIAN' : 'orange'
 
 How do I append this to 'groups'?

groups['ITALIAN'] = 'orange'

as described at

http://docs.python.org/tut/node7.html#SECTION00750

-tkc



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


Re: How to append to a dictionary

2006-05-19 Thread Sybren Stuvel
Harlin Seritt enlightened us with:
 I have some code here:

 groups = {'IRISH' : 'green', 'AMERICAN' : 'blue'}

 I want to add another key: 'ITALIAN' : 'orange'

 How do I append this to 'groups'?

groups['ITALIAN'] = 'orange'

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie append() question

2006-05-19 Thread Sybren Stuvel
Brian Blazer enlightened us with:
 I'm still not sure why it was grabbing the prompt string though.

Me neither. Try it in a standalone script instead of an interactive
session.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WTF? Printing unicode strings

2006-05-19 Thread Laurent Pointal
Ron Garret a écrit :
 In article [EMAIL PROTECTED],
  Fredrik Lundh [EMAIL PROTECTED] wrote:
 
 Ron Garret wrote:

 u'\xbd'
 u'\xbd'
 print _
 Traceback (most recent call last):
   File stdin, line 1, in ?
 UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in 
 position 0: ordinal not in range(128)
 so stdout on your machine is ascii, and you don't understand why you
 cannot print a non-ascii unicode character to it?  wtf?

 /F
 
 I forgot to mention:
 
 sys.getdefaultencoding()
 'utf-8'
 print u'\xbd'
 Traceback (most recent call last):
   File stdin, line 1, in ?
 UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in 
 position 0: ordinal not in range(128)

This is default encoding for evaluation of expressions in u...
strings, this has nothing to do with printing.

For the output encoding, see sys.stdout.encoding.

 import sys
 sys.stdout.encoding
'cp850'


A+

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


Re: who can give me the detailed introduction of re modle?

2006-05-19 Thread gene tani

softwindow wrote:
 the re module is too large and difficult to study

it's powerful, takes a little time to work with.  Make yourself aware
of the VERBOSE switch, RE debuggers in komodo and Wing, string
functions/methods and when you need a full parser, also

http://www.awaretek.com/tutorials.html#regular
http://en.wikibooks.org/wiki/Programming:Python_Strings
http://www.regexlib.com/Default.aspx
http://www.regular-expressions.info/python.html
http://www.unixreview.com/documents/s=2472/uni1037388368795/

http://diveintopython.org/regular_expressions/index.html#re.intro
 
 i need a detaild introduction.

You have everything you need

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


Re: memory error with zipfile module

2006-05-19 Thread Ganesan Rajagopal
 Hari Sekhon [EMAIL PROTECTED] writes:

 Traceback (most recent call last):
   File stdin, line 1, in ?
   File D:\u\Python24\lib\zipfile.py, line 357, in read
 bytes = dc.decompress(bytes)
 MemoryError

Looks like the .iso file is huge. Even if it's only a CD image (approx
650MB), reading it all into memory in a single string is not a good idea.

 The python zipfile module is obviously broken...

Indeed. I am surprised that there is no API that returns a file object.

Ganesan
-- 
Ganesan Rajagopal

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


problem with import autotest ...

2006-05-19 Thread bravegag
Hi all,

Please beware I am new to Python and have little experience with it.

I have a script that works just fine on linux but when I try to debug
from Windows using Eclipse and PyDEV plugin then it does not
work. The Python version is the same 2.3.x , and command line
is roughly the same.

from Unix:
mymodule.py my-params

From Windows (Eclipse)
python.exe mymodule.py my-params

The point is that from Linux the import autotest works as
intended i.e. just allow the importing module use some functions
but from Windows it autoruns itself just by importing it, I do not
get why or how?

From Windows it does:

Regression test.

This will find all modules whose name is test_* in the test
directory, and run them.  Various command line options provide
additional facilities

and then starts executing tests without ever getting to the main
of my module ...

Any clues?

TIA,
Best Regards,
Giovanni

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


Re: Encode exception for chinese text

2006-05-19 Thread Vinayakc
Yes serge, I have removed the first character but it is still giving
encoding exception.

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


Re: Encode exception for chinese text

2006-05-19 Thread John Machin
1. *By definition*, you can encode *any* Unicode string into utf-8.
Proves nothing.
2. \u00a0 [no-break space] has no equivalent in gb2312, nor in the
later gbk alias cp936. It does have an equivalent in the latest Chinese
encoding, gb18030.
3. gb2312 is outdated. It is not really an appropriate charset for
anything much these days. You need to check out what your requirements
really are. The unknowing will cheerfully use gb to mean one or more
of those, or to mean anything that's not big5 :-)
4. The slab of text you supplied is genuine unicode and encodes happily
into all those gb* charsets. It does *not* contain \u00a0.

I do hope some of this helps 

Cheers,
John

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

Python sqlite and regex.

2006-05-19 Thread Julien ARNOUX
Hi,
I'd like to use regular expressions in sqlite query, I using apsw module
but it doesn't work...Can you help me ?
My script:

import apsw
import re

path = 'db/db.db3'

#regexp function (extract from python-list discusion)
def regexp(expr, item):
reg = re.compile(expr)
return reg.match(item) is not None

con = apsw.Connection(path)
#create function
con.createscalarfunction(REGEXP, regexp)
cur = con.cursor()
#exampl
cur.execute(select foo from test where foo regex 'aa.[0-9]))

and the error is:

cur.execute('select foo from test where foo regex tata')
apsw.SQLError: SQLError: near regex: syntax error

Thanks



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


Re: memory error with zipfile module

2006-05-19 Thread bruno at modulix
Hari Sekhon wrote:
 I do
 
 import zipfile
 zip=zipfile.ZipFile('d:\somepath\cdimage.zip')
 zip.namelist()
 ['someimage.iso']
 
 then either of the two:
 
 A)   file('someimage.iso','w').write(zip.read('someimage.iso'))
 or
 B)   content=zip.read('someimage.iso')
 
 but both result in the same error:
 
 Traceback (most recent call last):
  File stdin, line 1, in ?
  File D:\u\Python24\lib\zipfile.py, line 357, in read
bytes = dc.decompress(bytes)
 MemoryError

otIs that the *full* traceback ?/ot

 I thought python was supposed to handle memory for you?

Err... This doesn't mean that it bypasses system's memory management.

http://pyref.infogami.com/MemoryError

http://mail.zope.org/pipermail/zope/2004-October/153882.html

MemoryError is raised by Python when an underlying (OS-level) allocation
fails.
(...)
Normally this would mean that you were out of even virtual memory
(swap), but it could also be a symptom of a libc bug, a bad RAM chip, etc.


What do you think will append if you try to allocate a huge block when
you've already eaten all available memory ? Do you really hope that
Python will give you extra ram for free ?-)

Please try this code:

import zipfile
zip=zipfile.ZipFile('d:\somepath\cdimage.zip')
info = zip.getinfo('someimage.iso')
csize = info.compress_size
fsize = info.file_size
print someimage compressed size is : %s % csize
print someimage real file  size is : %s % fsize
print 
So, knowing how zipfile.read() is actually implemented,
total needed ram is :  %s
 % (csize + fsize)

print Well... Do I have that much memory available ???


 The python zipfile module is obviously broken...

s/is obviously broken/could be improved to handle huge files/

Making such statements may not be the best way to make friends...

 Any advise?
Yes : Python is free software ('free' as in 'free speach' *and* as in
'free beer'), mostly written by benevolent contributors. So try and
improve the zipfile module by yourself, and submit your enhancements.
Then we all will be very grateful, and your name will be forever in the
Python Hall of Fame.

Or choose to behave as a whiny-whiny clueless luser making dumb
statements, and your name will be buried for a long long time in a lot
of killfiles.

It's up to you !-)

NB : If you go the first route, this may help:
http://www.python.org/doc/2.4.2/lib/module-zlib.html
with particular attention to the decompressobj.

HTH
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encode exception for chinese text

2006-05-19 Thread Serge Orlov
Vinayakc wrote:
 Yes serge, I have removed the first character but it is still giving
 encoding exception.

Then I guess this character was used as a poor man indentation tool at
least in the beginning of your text. It's up to you to decide what to
do with that character, you have several choices:

* edit source xml file to get rid of it
* remove it while you process your data
* replace it with ordinary space
* consider utf-8

Note, there are legitimate use cases for no-break space, for example
one million can be written like 1 000 000, where spaces are
non-breakable. This prevents the number to be broken by right margin
like this: 1 000
000

Keep that in mind when you remove or replace no-break space.

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


Re: CFLAGS are not taken into account properly

2006-05-19 Thread Toon Knapen
[EMAIL PROTECTED] wrote:
 Toon But some other (but 'similar') functionality is broken. Now I
 Toon succeeded in compiling python. But when using distutils (e.g. when
 Toon installing numarray using the setup.py), python will compile the
 Toon files using the '-xarch=v9' option but drops this option when
 Toon linking dynamic libraries (although I defined LDFLAGS=-xarch=v9
 Toon before configuring python).  Additionally python adds the option
 Toon '-xcode=pic32' to the compile-command which will compile my
 Toon numarray in 32bit instead of 64bit (while python itself is in
 Toon 64bit)
 
 That seems like a bug in distutils.  Can you submit a help ticket?
 
 Skip


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


Re: Encode exception for chinese text

2006-05-19 Thread Vinayakc
Hey Serge, john,

Thank you very much. I was really not aware of these facts. Anyways
this is happening only for one in millions so I can ignore this for
now. 

Thanks again,

Vinayakc

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


Re: Python sqlite and regex.

2006-05-19 Thread Dan Sommers
On Fri, 19 May 2006 14:47:10 +0200,
Julien ARNOUX [EMAIL PROTECTED] wrote:

 cur.execute(select foo from test where foo regex 'aa.[0-9]))

 and the error is:

 cur.execute('select foo from test where foo regex tata')
 apsw.SQLError: SQLError: near regex: syntax error

I think you're missing a closing quote on that regex; or perhaps that's
an extra closing parenthesis at the end.

Also, it's probably best to let the database module do any escaping you
may need.  For example:

fooregex = r'aa.[0-9]'
sql = 'select foo from test where foo regex %s'
cur.execute( sql, tuple( fooregex ) )

See the DP API spec for more information.

Regards,
Dan

-- 
Dan Sommers
http://www.tombstonezero.net/dan/
I wish people would die in alphabetical order. -- My wife, the genealogist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about exausted iterators

2006-05-19 Thread Mel Wilson
[EMAIL PROTECTED] wrote:
 Consider this example:
 
 X = range(5)
 Y = iter(X)
 Z = iter(Y)
 
 As you can see, X is a container, and Y is an iterator.
 They are simliar in that iter works on them both.
 
 Cristoph claims that this causes confusion.
 Why? Because iter doesn't have the same meaning for both of them.
 For X it always returns an iterator that yields the same set of values.
 For Y it returns an iterator yielding different values each time.

As an aside, perhaps iter(Y) should be returning a deeper 
copy of Y.  As it stands, I see 'Z=Y' giving the same effect:

  y=iter(x)
  z=iter(y)
  zip(y, z)
[(0, 1), (2, 3)]
  y=iter(x)
  z=y
  zip(y, z)
[(0, 1), (2, 3)]

[ ... ]

 But changing iter to have the same meaning for containers and
 iterables is impossible.
 You cannot, conceptually, reiterate an iterator.
 So what Cristoph is suggesting - is to add an exception for the cases
 in which iterators and collections behave differently.
 Somewhat similar to this:

But the end, raising StopIteration is not where the 
difference is.  The difference is in iter(some_object).

iter(some_container) creates a brand new iterator, standing 
at the starting line and ready to run.

iter(some_listiterator), it seems, just returns a reference 
to some_listiterator, with some of its history possibly 
behind it.

Iterators are used in the same syntactic places as general 
iterables, but especially once people start giving them 
names and handing them around, the real differences show up.

The short-range solution is Know What You're Doing.  Duck 
typing is a fine thing, but it works best for programmers 
who keep scrupulous track of their objects' types.

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


noob import question

2006-05-19 Thread Brian Blazer
OK, I have a very simple class here:

class Student:
 Defines the student class

 def __init__(self, lName, fName, mi):
 self.lName = lName
 self.fName = fName
 self.mi = mi

Then I have a small script that I am using as a test:

from Student import *

s1 = Student(Brian, Smith, N)

print s1.lName

This works as expected.  However, if I change the import statement to:
import Student

I get an error:
TypeError: 'module' object is not callable

I have tried to look up what is going on, but I have not found  
anything.  Would it be possible for someone to take a minute and give  
an explanation?

Thank you - your time is appreciated.

Brian
[EMAIL PROTECTED]




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


about py2exe, I installed it, but can't find py2exe.exe in my computer.

2006-05-19 Thread python
I installed it, but can't find py2exe.exe in my computer. why?
And , when I execute python setup.py py2exe under command line, it
prompt error:wrong command py2exe .

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


Re: noob import question

2006-05-19 Thread Iain King

Brian Blazer wrote:
 OK, I have a very simple class here:

 class Student:
  Defines the student class

  def __init__(self, lName, fName, mi):
  self.lName = lName
  self.fName = fName
  self.mi = mi

 Then I have a small script that I am using as a test:

 from Student import *

 s1 = Student(Brian, Smith, N)

 print s1.lName

 This works as expected.  However, if I change the import statement to:
 import Student

 I get an error:
 TypeError: 'module' object is not callable

 I have tried to look up what is going on, but I have not found
 anything.  Would it be possible for someone to take a minute and give
 an explanation?


I take it you are getting the error on the line
s1 = Student(Brian, Smith, N)

This is because when you use 'import Student', it loads the file
Student.py into a namespace called Student (unlike the 'from'
statement, which loads it into the main namespace).  to access anything
from your Student module, prepend with Student. , so your line becomes:
s1 = Student.Student(Brian, Smith, N)

Iain
 Thank you - your time is appreciated.
 
 Brian
 [EMAIL PROTECTED]

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


Re: noob import question

2006-05-19 Thread Diez B. Roggisch
 I have tried to look up what is going on, but I have not found
 anything.  Would it be possible for someone to take a minute and give
 an explanation?

The

from module import *|nameslist

syntax imports some or all names found in module into the current modules
namespace. Thus you can access your class.

But if you do 

import module

you only get module in your current namespace. So you need to access
anything inside module by prefixing the expression. In your case, it is

Student.Student

If you only write Student, that in fact is the MODULE Student, which
explains the error message.

Now while this sounds as if the from module import * syntax is the way to
go, you should refrain from that until you really know what you are doing
(and you currently _don't_ know), as this can introduce subtle and
difficult to debug bugs. If you don't want to write long module-names, you
can alias them:

import moduel-with-long-name as shortname


And it seems as if you have some JAVA-background, putting one class in one
file called the same as the class. Don't do that, it's a stupid restriction
in JAVA and should be avoided in PYTHON.

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


Re: noob import question

2006-05-19 Thread Brian Blazer
Thank you for your responses.  I had a feeling is had something to do  
with a namespace issue but I wasn't sure.

You are right, I do come from a Java background.  If it is poor form  
to name your class file the same as your class, can I ask what the  
standard is?

Thanks again,
Brian

On May 19, 2006, at 8:33 AM, Diez B. Roggisch wrote:

 I have tried to look up what is going on, but I have not found
 anything.  Would it be possible for someone to take a minute and give
 an explanation?

 The

 from module import *|nameslist

 syntax imports some or all names found in module into the current  
 modules
 namespace. Thus you can access your class.

 But if you do

 import module

 you only get module in your current namespace. So you need to access
 anything inside module by prefixing the expression. In your case,  
 it is

 Student.Student

 If you only write Student, that in fact is the MODULE Student, which
 explains the error message.

 Now while this sounds as if the from module import * syntax is  
 the way to
 go, you should refrain from that until you really know what you are  
 doing
 (and you currently _don't_ know), as this can introduce subtle and
 difficult to debug bugs. If you don't want to write long module- 
 names, you
 can alias them:

 import moduel-with-long-name as shortname


 And it seems as if you have some JAVA-background, putting one class  
 in one
 file called the same as the class. Don't do that, it's a stupid  
 restriction
 in JAVA and should be avoided in PYTHON.

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

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


Re: Programming language productivity

2006-05-19 Thread Harry George
malv [EMAIL PROTECTED] writes:

[snip]
 Once you get involved in larger projects, the dynamic nature of the
 programming tool becomes much more important. I mean by this, the
 ability to stop running code, modify or add to it and continue without
 having to re-establish the state of the program. This may sound trivial
 to many, but in major applications setting up the state again can take
 a considerable processing time. Such feature should be available from
 within the debugging tools.
 
 In fact, languages like Smalltalk, Lisp and even VB offer this
 possibility.
 Ruby coming up strongly these days also has this dynamic reload
 capability.
 To sum up, I like Python very much but I don't understand how come this
 basic flaw has not been taken care of. It is sufficient to search for
 reload to see how many people have struggled with it over the years.
 I hate the idea of having to take up Ruby to really find out how it
 could serve me better in this most critical productivity area.
 

What is major project?  

We have 50 people working on a project, over 5 years, in Python.  Much
of the regresison test can be done by rebuilding context in RAM (no
need to persist).  That is immediate (whole test suite runs in a few
seconds).  Sometimes we have to reestablish context by clearing the
database and then reloading objects from test_input XML files.  That
is slow (perhaps an over night job).  I've yet to experience a context
where language features are the rate limiting step.

On the other hand, I have definitely experienced language as a rate
limiting factor in a) peer code reviews, b) debugging, c) ramping up
new team members.  Python wins those battles everytime.

-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about py2exe, I installed it, but can't find py2exe.exe in my computer.

2006-05-19 Thread Fredrik Lundh
python wrote:

 I installed it, but can't find py2exe.exe in my computer. why?

why are you looking for an EXE file?  py2exe is a Python module, not an
application.

 And , when I execute python setup.py py2exe under command line, it
 prompt error:wrong command py2exe .

you're supposed to import py2exe into your setup file.  if you don't do that,
you'll get the above error message.

have you read the using py2exe section on this page:

http://www.py2exe.org/

?

/F 



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


released: RPyC 2.60

2006-05-19 Thread gangesmaster
Remote Python Call (RPyC) has been released. this release introduces
delivering objects, reducing memory consumption with __slots__, and
several other new/improved helper functions. see the release notes and
changelog (on the site) for more info.

home: 
http://rpyc.wikispaces.com


-tomer

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


Re: noob import question

2006-05-19 Thread Diez B. Roggisch
Brian Blazer wrote:

 Thank you for your responses.  I had a feeling is had something to do
 with a namespace issue but I wasn't sure.
 
 You are right, I do come from a Java background.  If it is poor form
 to name your class file the same as your class, can I ask what the
 standard is?

Consider python modules what packages are in JAVA - aggregations of related
classes. Only if your module grows to an unmanagable size, split it up into
two modules. 

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


Re: Which is More Efficient?

2006-05-19 Thread Fredrik Lundh
Dustan wrote:

 The task manager says CPU Usage: 100% when the program is running,
 and only when the program is running.

 Efficiency is a measure of 2 things: CPU usage and time. If you measure
 just time, you're not necessarily getting the efficiency.

are you for real?

/F 



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


Re: noob import question

2006-05-19 Thread PA

On May 19, 2006, at 15:33, Diez B. Roggisch wrote:

 And it seems as if you have some JAVA-background, putting one class in 
 one
 file called the same as the class. Don't do that, it's a stupid 
 restriction
 in JAVA and should be avoided in PYTHON.

Restrictive or not, what's so fundamentally devious in putting a class 
declaration in a separate file whose name is that of the declared class 
(class Queue - Queue.py)?

Sounds like a handy way of organizing your code, no?

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/

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


Re: Script to make Windows XP-readable ZIP file

2006-05-19 Thread Grant Edwards
On 2006-05-19, softwindow [EMAIL PROTECTED] wrote:

 Carl Banks  is right

That would be valuable information if we know what he was right
about.

-- 
Grant Edwards   grante Yow!  Bo Derek ruined
  at   my life!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calling python functions using variables

2006-05-19 Thread Grant Edwards
On 2006-05-19, bruno at modulix [EMAIL PROTECTED] wrote:

 Either deal with the resulting NameError exception (EAFP[0])

 try:
   getattr(commands, VARIABLE)()
 except NameError:
   print  sys.stderr, Unknown command, VARIABLE

 or test
 first whether the attribute exists (LBYL[1]).

 command = getattr(commands, VARIABLE, None)
 if command is None:
   print  sys.stderr, Unknown command, VARIABLE
 else:
   command()

 I'd go for the first solution.

Me too.  Assuming the user isn't clueless, the normal case is
where the command exists.  Write code for the normal case and
use the exception that occurs for exceptional cases.

-- 
Grant Edwards   grante Yow!  This PIZZA symbolizes
  at   my COMPLETE EMOTIONAL
   visi.comRECOVERY!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to read a list from python in C?

2006-05-19 Thread skip

Lialie I am writing a C extension with .Net.  Now I have a list of
Lialie points, like [(0.0, 0.0), (2.0, 3.0), (random x, random y)].
Lialie Is there a better way to translate it to an array than doing it
Lialie one by one?

Are you passing a list as an argument to one of the functions in your C
extension module?  If so, yup, you get the list argument and march through
it element-by-element, then march through those tuples.  For more detail on
argument handling in C, read here:

http://www.python.org/doc/api/arg-parsing.html

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


Re: noob import question

2006-05-19 Thread Fredrik Lundh
PA [EMAIL PROTECTED] wrote:

 Restrictive or not, what's so fundamentally devious in putting a class
 declaration in a separate file whose name is that of the declared class
 (class Queue - Queue.py)?

nothing.

 Sounds like a handy way of organizing your code, no?

sure, if you prefer to do things that way.

the Python style guide (PEP 8) used to recommend naming a module that con-
tains only one class (plus support factories and other functions) after the 
class,
but now recommends using other names for the module, to avoid confusion.

for some reason, some people seem to treat the latest edition of each PEP as
a divine truth, and all earlier editions as works of the devil.  I guess they 
reset
their brain before each svn update.

/F 



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


Re: python vs perl lines of code

2006-05-19 Thread Terry Hancock
Edward Elliott wrote:

For inquiries into real-world code, it's enough to
believe that I'm not lying

Yeah, well, this is the internet -- I've gotten emails trying to
sell me ex-soviet rocket-launchers and child porn.*

So I don't make assumptions about people without some kind
of evidence. There *are* plenty of bad guys out there, so
one learns both to have a thick skin and to rely on that which
is reasonably proven, rather than making casual assumptions
of good will.  That'd be like leaving your car in downtown LA
overnight with the doors unlocked.

Cheers,
Terry

*In the same email, no less.  This is of course an extreme
example, but there are *loads* of merely irritating behaviors
like trolling.

-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com


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


Re: noob import question

2006-05-19 Thread bruno at modulix
Brian Blazer wrote:
 OK, I have a very simple class here:
 
 class Student:

class Student(object):

 Defines the student class
 
 def __init__(self, lName, fName, mi):
 self.lName = lName
 self.fName = fName
 self.mi = mi

Do yourself a favour: use meaningful names.

 Then I have a small script that I am using as a test:
 
 from Student import *

So your module is named Student.py ? The common convention is to use
all_lower for modules, and CapNames for classes. BTW, unlike Java, the
common use is to group closely related classes and functions in a same
module.

 s1 = Student(Brian, Smith, N)
 
 print s1.lName
 
 This works as expected.  However, if I change the import statement to:
 import Student
 
 I get an error:
 TypeError: 'module' object is not callable

Of course. And that's one for the reason for naming modules all_lower
and classes CapNames.

With
 from Student import *

you import all the names (well... not all, read the doc about this)
defined in the module Student directly in the current namespace. So,
since the module Student contains the class Student, in this current
namespace, the name Student refers to the class Student.

With
  import Student

you import the module name Student in the current namespace. You can
then refer to names defined in module Student with the qualified name
module.name. So here, to refer to the class Student, you need to use the
qualified name Student.Student.

You wouldn't have such a confusion if your module was named students !-)


 I have tried to look up what is going on, but I have not found 
 anything.  

you could have done something like this:

import Student
print dir()
print dir(Student)
print type(Student)
del Student
from Student import *
print dir()
print dir(Student)
print type(Student)


Also, reading the doc migh help:
http://www.python.org/doc/2.4.2/tut/node8.html

HTH
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: memory error with zipfile module

2006-05-19 Thread [EMAIL PROTECTED]
Take a look at the pywin32 extension, which I believe has some lower
level memory allocation and file capabilities that might help you in
this situation.  If I'm completely wrong, someone please tell me XD.
Of course, you could just make the read() a step process, reading, O
lets say 8192 bytes at a time (could be bigger if u want), writes them
to the new file, and then reads the next portion. This will be slower
(not sure how much) than if you had some AMD X2 64 with 3 gigs of ram
and could just read the file all at once, but it should work.

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


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-19 Thread Dave Hansen
On 19 May 2006 07:18:03 GMT in comp.lang.python, Duncan Booth
[EMAIL PROTECTED] wrote:

[...]
My experience of programming with either spaces or tabs has taught me 
that tabs are evil not for themselves, but simply because no matter how 
hard you try they always end up being mixed with spaces.

That's been my experience as well.  At least on projects with more
than one programmer.  And more than once with single-programmer
projects where the programmer changed or updated his editor in the
middle...

Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the tostring and XML methods in ElementTree

2006-05-19 Thread Stefan Behnel
George Sakkis wrote:
 Fredrik Lundh wrote:
 
 [EMAIL PROTECTED] wrote:

 I wanted to see what would happen if one used the results of a tostring
 method as input into the XML method.  What I observed is this:
 a) beforeCtag.text is of type type 'str'
 b) beforeCtag.text when printed displays: I'm confused
 c) afterCtag.text is of type type 'unicode'
 d) afterCtag.text when printed displays: I?m confused
 the XML file format isn't a Python string serialization format, it's an XML 
 infoset
 serialization format.

 as stated in the documentation, ET always uses Unicode strings for text that
 contain non-ASCII characters.  for text that *only* contains ASCII, it may 
 use
 either Unicode strings or 8-bit strings, depending on the implementation.

 the behaviour if you're passing in non-ASCII text as 8-bit strings is 
 undefined
 (which means that you shouldn't do that; it's not portable).
 
 I was about to post a similar question when I found this thread.
 Fredrik, can you explain why this is not portable ?

Because there is no such things as a default encoding for 8-bit strings.


 I'm currently using
 (a variation of) the workaround below instead of ET.tostring and it
 works fine for me:
 
 def tostring(element, encoding=None):
 text = element.text
 if text:
 if not isinstance(text, basestring):
 text2 = str(text)
 elif isinstance(text, str) and encoding:
 text2 = text.decode(encoding)
 element.text = text2
 s = ET.tostring(element, encoding)
 element.text = text
 return s
 
 
 Why isn't this the standard behaviour ?


Because it wouldn't work. What if you wanted to serialize a different encoding
than that of the strings you put into the .text fields? How is ET supposed to
know what encoding your strings have? And how should it know that you didn't
happily mix various different byte encodings in your strings?

Use unicode, that works *and* is portable.

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


Re: [OT] noob import question

2006-05-19 Thread bruno at modulix
Brian Blazer wrote:
ot
please, dont top-post, and edit out irrelevant material
/ot

 You are right, I do come from a Java background.  

Then you may want to read this:
http://dirtsimple.org/2004/12/python-is-not-java.html

HTH
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   >