Re: bicycle repair man help

2007-06-27 Thread Rob Weir
On 6/24/07, Rustom Mody <[EMAIL PROTECTED]> wrote:
> Does someone know that when using bicycle repair man to refactor python code
> what exactly extract local variable means?

It means extracting a part (or all of) an expression and replacing it
with a sensibly-named local variable.

Shamelessly copied from c2:

> For example:
>
>  if ( (x==0) || ((y<17) && name == null) ) {
>..
>  }
>
> becomes:
>
>  final boolean outOfActiveAreal = (x==0) || ((y<17) && name == null) ;
>  if (outOfActiveAreal ) {
>..
>  }

Some more articles:

http://refactoring.com/catalog/introduceExplainingVariable.html and
http://c2.com/cgi-bin/wiki?IntroduceExplainingVariable have
discussions of them.

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


String formatting for complex writing systems

2007-06-27 Thread Andy
Hi guys,

I'm writing a piece of software for some Thai friend.  At the end it
is supposed to print on paper some report with tables of text and
numbers.  When I test it in English, the columns are aligned nicely,
but when he tests it with Thai data, the columns are all crooked.

The problem here is that in the Thai writing system some times two or
more characters together might take one single space, for example งิ
(u"\u0E07\u0E34").  This is why when I use something like u"%10s"
% ..., it just doesn't work as expected.

Is anybody aware of an alternative string format function that can
deal with this kind of writing properly?

Any suggestion is highly appreciated.  Thanks!
Andy

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

Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread Timofei Shatrov
On Wed, 27 Jun 2007 00:07:04 -, Twisted <[EMAIL PROTECTED]> tried to
confuse everyone with this message:

>"Stubbornly insisting on being odd" appears to be a particularly
>prevalent character flaw among the geeknoscenti.
>

Oh the irony.

-- 
|Don't believe this - you're not worthless  ,gr-.ru
|It's us against millions and we can't take them all... |  ue il   |
|But we can take them on!   | @ma  |
|   (A Wilhelm Scream - The Rip)|__|
-- 
http://mail.python.org/mailman/listinfo/python-list


XML from SQL result

2007-06-27 Thread Marcin Stępnicki
Hello.

I've skimmed through many Python&XML related books/articles but I am
unable to find anything that is similar to my problem - but it seems to
me that it should be common.

Anyway: I've got the SQL query which returns:

col1 | col2 | col3
-+--+-
  a  | a10  | b20
  a  | a10  | b30
  a  | a20  | b30

I need to generate the following:










  

Using Elementree it's not a problem when returned data is "flat", not
hierarchical. However, that's not the case.

Questions:

1) (I'll ask that on PostgreSQL group too) I use PostgreSQL. I understand
that in order to achieve what I want directly from RDBMS I need SQL/XML
language support which will be included in 8.3 which is not yet available.

2) Provided that I can't generate it from 1) should I take a deeper look
into Gnosis Utils? http://www.gnosis.cx/download/Gnosis_Utils.More/ ? 

3) I can generate series of select queries based on previous queries, but
I can't imagine there isn't a better solution.

Could you please clarify these for me? I'm a bit puzzled and frankly
don't know where to start. Even a single URL which explains it in detail is
greatly anticipated :).

Thank you for your time,
Marcin

-- 
| And Do What You Will be the challenge | http://apcoln.linuxpl.org
|So be it in love that harms none   | http://biznes.linux.pl
|   For this is the only commandment.   | http://www.juanperon.info
`---*  JID: [EMAIL PROTECTED] *---' http://www.naszedzieci.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String formatting for complex writing systems

2007-06-27 Thread Gabriel Genellina
En Wed, 27 Jun 2007 04:20:52 -0300, Andy <[EMAIL PROTECTED]> escribió:

> I'm writing a piece of software for some Thai friend.  At the end it
> is supposed to print on paper some report with tables of text and
> numbers.  When I test it in English, the columns are aligned nicely,
> but when he tests it with Thai data, the columns are all crooked.
>
> The problem here is that in the Thai writing system some times two or
> more characters together might take one single space, for example งิ
> (u"\u0E07\u0E34").  This is why when I use something like u"%10s"
> % ..., it just doesn't work as expected.
>
> Is anybody aware of an alternative string format function that can
> deal with this kind of writing properly?

The same thing happens even in English if you print using a proportional  
width font, a "W" is usually wider than an "i" or "l" letter.
You could use a reporting library or program (like ReportLab, generating  
PDF files), but perhaps the simplest approach is to generate an HTML page  
containing a table, and display and print it using your favorite browser.

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

Re: XML from SQL result

2007-06-27 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Marcin Stępnicki wrote:

> Anyway: I've got the SQL query which returns:
> 
> col1 | col2 | col3
> -+--+-
>   a  | a10  | b20
>   a  | a10  | b30
>   a  | a20  | b30
> 
> I need to generate the following:
> 
> 
>   
>   
>   
>   
> 
>   
>   
>   
>   
> 
> Using Elementree it's not a problem when returned data is "flat", not
> hierarchical. However, that's not the case.
> 
> Questions:
> 
> 1) (I'll ask that on PostgreSQL group too) I use PostgreSQL. I understand
> that in order to achieve what I want directly from RDBMS I need SQL/XML
> language support which will be included in 8.3 which is not yet available.

That question sounds more like a statement.  :-)

> 3) I can generate series of select queries based on previous queries, but
> I can't imagine there isn't a better solution.

If the data can be queried sorted like shown above, should be possible to
iterate over it and use `itertools.groupby` and
`elementtree.SimpleXMLWriter.XMLWriter` to generate the XML on the fly:

import sys
from itertools import groupby
from operator import itemgetter
from elementtree.SimpleXMLWriter import XMLWriter

first, second, third = map(itemgetter, xrange(3))

def main():
data = (('a', 'a10', 'b20'),
('a', 'a10', 'b30'),
('a', 'a20', 'b30'))

writer = XMLWriter(sys.stdout)
writer.start('document')
for value, rows in groupby(data, first):
writer.start('tag1', col1=value)
for value, rows in groupby(rows, second):
writer.start('tag2', col2=value)
for value in imap(third, rows):
writer.element('tag3', col3=value)
writer.end('tag2')
writer.end('tag1')
writer.end('document')

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: XML from SQL result

2007-06-27 Thread Stefan Behnel
Marcin Stępnicki wrote:
> I've skimmed through many Python&XML related books/articles but I am
> unable to find anything that is similar to my problem - but it seems to
> me that it should be common.
> 
> Anyway: I've got the SQL query which returns:
> 
> col1 | col2 | col3
> -+--+-
>   a  | a10  | b20
>   a  | a10  | b30
>   a  | a20  | b30
> 
> I need to generate the following:
> 
> 
>   
>   
>   
>   
> 
>   
>   
>   
>   

I'd use a two-step approach here. Collect the data in a dict of dicts, then
write it out into XML.

Something like this:

  c1d = {}
  for c1, c2, c3 in rows:
  c2d = c1d.get(c1)
  if c2d is None:
  c2d = c1d[c1] = {}
  c3_list = c2d.get(c2)
  if c3_list is None:
  c3d = c2d[c2] = []
  c3_list.append(c3)

  root = ET.Element("root") # in case "col1" has more than one value
  for c1, c2d in c1d.iteritems():
  el_c1 = ET.SubElement(root, "tag1", col1=c1)
  for c2, c3_list in c2d.iteritems():
  el_c2 = ET.SubElement(el_c1, "tag2", col2=c2)
  for c3 in c3_list:
  ET.SubElement(el_c2, "tag3", col3=c3)

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

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-27 Thread Douglas Woodrow
On Wed, 27 Jun 2007 01:45:44, Douglas Alan <[EMAIL PROTECTED]> wrote
>A chaque son gout

I apologise for this irrelevant interruption to the conversation, but 
this isn't the first time you've written that.

The word "chaque" is not a pronoun.

http://grammaire.reverso.net/index_alpha/Fiches/Fiche220.htm
-- 
Doug Woodrow

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-27 Thread Paul Rubin
Dennis Lee Bieber <[EMAIL PROTECTED]> writes:
>   What happens when two individuals release "libraries" using these
> proposed macros -- and have implement conflicting macros using the same
> identifiers -- and you try to use both libraries in one application?

Something like the current situation with Python web frameworks ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread Gian Uberto Lauri
> Long count = 12.19.14.7.16; tzolkin = 2 Cib; haab = 4 Tzec.
> I get words from the Allmighty Great Gnus that
> "T" == Twisted  <[EMAIL PROTECTED]> writes:

T> On Jun 26, 6:06 am, Gian Uberto Lauri <[EMAIL PROTECTED]>
T> wrote:
>> >> > HOW IN THE BLOODY HELL IS IT SUPPOSED TO OCCUR TO SOMEONE TO
>> >> ENTER > THEM, GIVEN THAT THEY HAVE TO DO SO TO REACH THE HELP
>> THAT >> WOULD TELL > THEM THOSE ARE THE KEYS TO REACH THE HELP?!
>> 
>> >> What's your problem ?
>> 
>> >> Ofcourse a mere program-consumer would not look what was being
>> >> installed on his/her system in the first place ...  So after
>> some >> trivial perusing what was installed and where : WOW Look,
>> MA !  >>  it's all there!
>> 
>> >> lpr /usr/local/share/emacs/21.3/etc/refcard.ps or your >>
>> install-dir^ ^ or your >>
>> version.^
>> 
n> So now we're expected to go on a filesystem fishing expedition
n> instead of just hit F1? One small step (backwards) for a man; one
n> giant leap (backwards) for mankind. :P

T> [snipping some thinly-veiled insults and irrelevancies throughout]

>> There's a program called find, not this intuitive but worth
>> learning
>> 
>> It could solve the problem from the root with something like
>> 
>> find / -name refcard.ps -exec lpr {} \; 2> /dev/null

T> Let me get this straight.

T> In this corner, we have just about every Windows application ever
T> developed. When a user needs help, a click on the "help" menu or
T> tap of the F1 key is all it takes to obtain some. Sometimes the
T> help is not of the greatest quality, but that is another issue we
T> won't concern ourselves with here.

Hmmm. I just activated the help  hitting F1... WOHA, it says that if I
press k after F1 I get the description of what that key does...

T> In the other corner, we have just about every Unix application ever
T> developed. When a user needs help, they may do such things as
T> manually explore the directories where the application was
T> installed

Ever heard about the man command ? Is the first thing you learn to
do... 

T> Or alternatively
T> it can just magically come to them as a divinely inspired insight,

If they are Windows user, I pity them, their brain could have been
damaged beyond repair.

They'll never  be blessed by  the idea that  programs can do  work for
them, and will bash restlessy their keyboard in antiquate sequences of
pre-automatic-controls  tasks (as  a  reference, take  a  look to  the
Metropolis movie)

T> or in a dream or a burning bush or stone tablets from heaven or
T> something, that something useful might happen if the unlikely
T> combination of symbols "find / -name refcard.ps -exec lpr {} \; 2>
T> /dev/null"

Nothing this divine. Just someone a bit more experienced than you are.

On the other  hand I never seen such thing like  a refcard, that's not
in the  standard documentation  system for such  a modern  toxic waste
like Word.

T> obviously never occur to them. Even if they knew the find tool and
T> its syntax, it would still have to somehow occur to them that
T> "refcard.ps" might be a useful search target.

Strange. I am *NOT* a native english speaker and I think my Q.I. tends
toward average from below, but refcard sound very useful to me, maybe
is short for "reference card" ?

T> came to shove, clicking Start->Search and putting in ".hlp" and
T> "C:\Program Files\Appname" would quickly find any help files.

I admit. find is less intuitive. But the stuff Windows comes with does
just that  and nothing more. It  will never suggest you  that the long
boring  task expecting  you can  be solved  in a  completely automatic
way with a little creative job.

T> most usually the help files would be named to end with
T> .hlp.

All, or  that impaired of  a O.S. could  not understand they  are help
files.

T> Moreover, once found, a quick double click and they're in a
T> hypertext browser viewing the help.

Emacs  help was  hypertextual  when Dr.  Watson  plagued Windowd  3.11
users...


T> Unless I miss my guess,
T> refcard.ps would require mucking about installing and configuring
T> Ghostscript and GSView,

Splash, large miss. 

You usually fire it to the local printer.

Uh, I  understand. A Windows user  could never have  shared its HP720c
printer... Windows printer driver aren't known to be smart.

Not an Emacs flaw.

T> enough. Trying to read anything serious and navigate in GSView is
T> no picnic either.

A refcard, my dear, is something that goes on an A4/Letter sheet and
NEEDS NOT to be hypertextual.

T> Reader *might* be able to do more with a .ps file

With a PS file you can do  just one thing, execute it. It's a program,
did you know ?

Ah, I never use Acroread. Xpdf does all the things really needed. 

Uh, I forget. For  Windows users getting a PDF out of  a PS or HTML or
ASCII is  not this easy unless  they get some  extra software (someone
ported CUPS to Windows ?). Again, not an Emacs fault.

T> On a Unix box, if you don't know exactly ho

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-27 Thread Paul Rubin
Douglas Alan <[EMAIL PROTECTED]> writes:
> > The thing is there was no standard way in Maclisp to write something
> > like Python's "count" function and map over it.  This could be done in
> > Scheme with streams, of course.
> 
> I'm not sure that you can blame MacLisp for not being object-oriented.
> The idea hadn't even been invented yet when MacLisp was implemented
> (unless you count Simula).  If someone went to make an OO version of
> MacLisp, I'm sure they'd get all this more or less right, and people
> have certainly implemented dialects of Lisp that are consistently OO.

count() has nothing to with OO, it's just the infinite stream 1,2,3,...
which can be implemented as a Scheme closure the obvious way.

> Right, but implementing generic reference-counted smart pointers is
> about a page of code in C++, and nearly every large C++ application
> I've seen uses such things.

That's because C++ has no GC.

> Gee, that's back to the future with 1975 Lisp technology.  Destructors
> are a much better model for dealing with such things (see not *all*
> good ideas come from Lisp -- a few come from C++) and I am dismayed
> that Python is deprecating their use in favor of explicit resource
> management.  Explicit resource management means needlessly verbose
> code and more opportunity for resource leaks.

And relying on refcounts to free a resource at a particular time is
precisely explicit resource management.  What if something makes a
copy of the pointer that you didn't keep track of?  The whole idea of
so-called smart pointers is to not have to keep track of them after
all.  Anything like destructors are not in the spirit of GC at all.
The idea of GC is to be invisible, so the language semantics can be
defined as if all objects stay around forever.  GC should only reclaim
something if there is no way to know that it is gone.  For stuff like
file handles, you can tell whether they are gone or not, for example
by trying to unmount the file system.  Therefore they should not be
managed by GC.

> Also, I'm not convinced that it has to be a huge performance hit.
> Some Lisp implementations had a 1,2,3, many (or something like that)
> reference-counter for reclaiming short-lived objects.  This bypassed
> the real GC and was considered a performance optimization.  (It was
> probably on a Lisp Machine, though, where they had special hardware to
> help.)

That is a common technique and it's usually done with just one bit.

> > because putting locks on the refcounts (someone tried in the late
> > 90's) to allow multi-cpu parallelism slows the interpreter to a crawl.
> 
> All due to the ref-counter?  I find this really hard to believe.
> People write multi-threaded code all the time in C++ and also use
> smart pointers at the same time.  I'm sure they have to be a bit
> careful, but they certainly don't require a GIL.

Heap allocation in C++ is a relatively heavyweight process that's used
sort of sparingly.  C++ code normally uses a combination of static
allocation (fixed objects and globals), stack allocation (automatic
variables), immediate values (fixnums), and (when necessary) heap
allocation.  In CPython, *everything* is on the heap, even small
integers, so saying "x = 3" has to bump the refcount for the integer 3.
There is a LOT more refcount bashing in CPython than there would be
in something like a Boost application.

> > Lisp may always be around in some tiny niche but its use as a
> > large-scale systems development language has stopped making sense.
> 
> It still makes perfect sense for AI research.  

I think most AI research is being done in other languages nowadays.
There are some legacy Lisp systems around and some die-hards but
I have the impression newer stuff is being done in ML or Haskell.

I personally use Emacs Lisp every day and I think Hedgehog Lisp (a
tiny functional Lisp dialect intended for embedded platforms like cell
phones--the runtime is just 20 kbytes) is a very cool piece of code.
But using CL for new, large system development just seems crazy today.

> Re Lisp, though, there used to be a joke (which turned out to be
> false), which went, "I don't know what the most popular programming
> language will be in 20 years, but it will be called 'Fortran'".  In
> reality, I don't know what the most popular language will be called 20
> years from now, but it will *be* Lisp.

Well, they say APL is a perfect crystal--if you add anything to it, it
becomes flaws; while Lisp is a ball of mud--you can throw in anything
you want and it's still Lisp.  However I don't believe for an instant
that large system development in 2027 will be done in anything like CL.

See:

  http://www.cs.princeton.edu/~dpw/popl/06/Tim-POPL.ppt
  http://www.st.cs.uni-sb.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf

(both are the same presentation, the links are the original Powerpoint
version and a pdf conversion) for a game developer discussing his
experiences with a 500 KLOC C++ program, describing where he thinks
thi

Organizing Python Representation at OSCON 2007

2007-06-27 Thread Jeff Rush
OSCON 2007 in Portland, Oregon from July 23-27 is fast approaching.  This is a 
professional conference that can give Python a lot of visibility in the IT 
world and draws a different crowd from our community-run conferences like  
PyCon.

There looks to be a good set of talks on the Python track, with several 
positioned to promote the use of Python by telling its story:

   - Code Like a Pythonista: Idiomatic Python
   - SQLAlchemy: Taming ORM with Python
   - Super-sizing YouTube
   - How to Write a Killer Sugar Activity
   - Exploiting Multicore Capabilities from Python
   - Python 3000
   - Programming for Everybody: CP4E
   - Coding with Dynamic Confidence

There also is the opportunity to reach out by holding Python 
birds-of-a-feather gatherings.  The Python community is a friendly group and 
face-to-face contact is important to convey the human aspect of Python.  BoFs 
can be scheduled by visiting the OSCON page:

   http://conferences.oreillynet.com/pub/w/58/bof.html

I will not be attending this year, so we need one or more who are willing to 
step forward and loosely organize a bit.  Let's discuss this on the Python 
advocacy mailing list and make it happen this year.

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

Jeff Rush
Python Advocacy Coordinator
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML from SQL result

2007-06-27 Thread Gabriel Genellina
En Wed, 27 Jun 2007 04:25:16 -0300, Marcin Stępnicki  
<[EMAIL PROTECTED]> escribió:

> I've skimmed through many Python&XML related books/articles but I am
> unable to find anything that is similar to my problem - but it seems to
> me that it should be common.
>
> Anyway: I've got the SQL query which returns:
>
> col1 | col2 | col3
> -+--+-
>   a  | a10  | b20
>   a  | a10  | b30
>   a  | a20  | b30
>
> I need to generate the following:
>
> 
>   
>   
>   
>   
>
>   
>   
>   
> 

That looks like a conventional report with totals and subtotals: while  
col1 is still the same, keep accumulating col2. While col1 and col2 are  
still the same, keep accumulating col3. Here, accumulating means "append  
item to current element".
If the number of columns is known in advance, you can nest some groupby  
calls:

 from itertools import groupby
def generate(rows):
   root = Element("xml")
   for col1,rows in groupby(rows, lambda row: row[0]):
 tag1 = SubElement(root, "tag1", col1=col1)
 for col2,rows in groupby(rows, lambda row: row[1]):
   tag2 = SubElement(tag1, "tag2", col2=col2)
   for col3,rows in groupby(rows, lambda row: row[2]):
 tag3 = SubElement(tag2, "tag3", col3=col3)
   return root
print tostring(generate(rows))

> Using Elementree it's not a problem when returned data is "flat", not
> hierarchical. However, that's not the case.

Uhm - ElementTree is designed precisely for a hierarchical structure (a  
"tree" :) )

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

Re: PyKQueue

2007-06-27 Thread Jean-Paul Calderone
On Tue, 26 Jun 2007 21:48:46 -0700, Adam Atlas <[EMAIL PROTECTED]> wrote:
>Does anyone have a copy of PyKQueue 2.0 around? The site it's supposed
>to be on (http://python-hpio.net/trac/wiki/PyKQueue) is down.
>
>--
>http://mail.python.org/mailman/listinfo/python-list
>

http://twistedmatrix.com/trac/browser/sandbox/foom/pykqueue
-- 
http://mail.python.org/mailman/listinfo/python-list


Searching for Python Talent !!

2007-06-27 Thread IT Recruiter
Hello friends!

I am looking for a GUI focused Python developer to help in Website
development with some wxpython experience...

It's very useful to have other programming languages and paradigms

About Client: Software house, fastest growing in the commercial market

This is a permanent role in London city, paying as per market rate for
the excellent candidate

About Me: I am a Resourcing Consultant specialist in recruiting for
Open Source Technologies.

Please do not hesitate to contact me or write me back!

Cheers,
Srini

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


Re: String formatting for complex writing systems

2007-06-27 Thread Leo Kislov
On Jun 27, 12:20 am, Andy <[EMAIL PROTECTED]> wrote:
> Hi guys,
>
> I'm writing a piece of software for some Thai friend.  At the end it
> is supposed to print on paper some report with tables of text and
> numbers.  When I test it in English, the columns are aligned nicely,
> but when he tests it with Thai data, the columns are all crooked.
>
> The problem here is that in the Thai writing system some times two or
> more characters together might take one single space, for example งิ
> (u"\u0E07\u0E34").  This is why when I use something like u"%10s"
> % ..., it just doesn't work as expected.
>
> Is anybody aware of an alternative string format function that can
> deal with this kind of writing properly?

In general case it's impossible to write such a function for many
unicode characters without feedback from rendering library.
Assuming you use *fixed* font for English and Thai the following
function will return how many columns your text will use:

from unicodedata import category
def columns(self, s):
return sum(1 for c in s if category(c) != 'Mn')

  -- Leo

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

Re: String formatting for complex writing systems

2007-06-27 Thread Leo Kislov
On Jun 27, 3:10 am, Leo Kislov <[EMAIL PROTECTED]> wrote:
> On Jun 27, 12:20 am, Andy <[EMAIL PROTECTED]> wrote:
>
> > Hi guys,
>
> > I'm writing a piece of software for some Thai friend.  At the end it
> > is supposed to print on paper some report with tables of text and
> > numbers.  When I test it in English, the columns are aligned nicely,
> > but when he tests it with Thai data, the columns are all crooked.
>
> > The problem here is that in the Thai writing system some times two or
> > more characters together might take one single space, for example งิ
> > (u"\u0E07\u0E34").  This is why when I use something like u"%10s"
> > % ..., it just doesn't work as expected.
>
> > Is anybody aware of an alternative string format function that can
> > deal with this kind of writing properly?
>
> In general case it's impossible to write such a function for many
> unicode characters without feedback from rendering library.
> Assuming you use *fixed* font for English and Thai the following
> function will return how many columns your text will use:
>
> from unicodedata import category
> def columns(self, s):
>     return sum(1 for c in s if category(c) != 'Mn')

That should of course be written as def columns(s). Need to learn to
proofread before posting :)

  -- Leo

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

import data.py using massive amounts of memory

2007-06-27 Thread Nick Craig-Wood
I've been dumping a database in a python code format (for use with
Python on S60 mobile phone actually) and I've noticed that it uses
absolutely tons of memory as compared to how much the data structure
actually needs once it is loaded in memory.

The programs below create a file (z.py) with a data structure in which
looks like this

-- z.py 
z = {
  0 : (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19),
  1 : (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20),
  2 : (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21),
[snip]
  998 : (998, 999, 1000, 1001, 1002, ..., 1012, 1013, 1014, 1015, 1016, 1017),
  999 : (999, 1000, 1001, 1002, 1003, ..., 1013, 1014, 1015, 1016, 1017, 1018),
}


Under python2.2-python2.4 "import z" uses 8 MB, whereas loading a
pickled dump of the file only takes 450kB.  This has been improved in
python2.5 so it only takes 2.2 MB.

$ python2.5 memory_usage.py 
Memory used to import is 2284 kB
Total size of repr(z) is  105215
Memory used to unpickle is 424 kB
Total size of repr(z) is  105215

$ python2.4 memory_usage.py 
Memory used to import is 8360 kB
Total size of repr(z) is  105215
Memory used to unpickle is 456 kB
Total size of repr(z) is  105215

$ python2.3 memory_usage.py 
Memory used to import is 8436 kB
Total size of repr(z) is  105215
Memory used to unpickle is 456 kB
Total size of repr(z) is  105215

$ python2.2 memory_usage.py 
Memory used to import is 8568 kB
Total size of repr(z) is  105215
Memory used to unpickle is 392 kB
Total size of repr(z) is  105215

$ python2.1 memory_usage.py 
Memory used to import is 10756 kB
Total size of repr(z) is  105215
Memory used to unpickle is 384 kB
Total size of repr(z) is  105215

Why does it take so much memory?  Is it some consequence of the way
the datastructure is parsed?

Note that once it has made the .pyc file the subsequent runs take even
less memory than the cpickle import.

S60 python is version 2.2.1. It doesn't have pickle unfortunately, but
it does have marshal and the datastructures I need are marshal-able so
that provides a good solution to my actual problem.

Save the two programs below with the names given to demonstrate the
problem.  Note that these use some linux-isms to measure the memory
used by the current process which will need to be adapted if you don't
run it on linux!

-- memory_usage.py -

import os
import sys
import re
from cPickle import dump

def memory():
"""Returns memory used (RSS) in kB"""
status = open("/proc/self/status").read()
match = re.search(r"(?m)^VmRSS:\s+(\d+)", status)
memory = 0
if match:
memory = int(match.group(1))
return memory

def write_file():
"""Write the file to be imported"""
fd = open("z.py", "w")
fd.write("z = {\n")
for i in xrange(1000):
fd.write("  %d : %r,\n" % (i, tuple(range(i,i+20
fd.write("}\n")
fd.close()

def main():
write_file()
before = memory()
from z import z
after = memory()
print "Memory used to import is %s kB" % (after-before)
print "Total size of repr(z) is ",len(repr(z))

# Save a pickled copy for later
dump(z, open("z.bin", "wb"))

# Run the next part
os.system("%s memory_usage1.py" % sys.executable)

if __name__ == "__main__":
main()

-- memory_usage1.py 

from memory_usage import memory
from cPickle import load

before = memory()
z = load(open("z.bin", "rb"))
after = memory()
print "Memory used to unpickle is %s kB" % (after-before)
print "Total size of repr(z) is ",len(repr(z))



-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread Bjorn Borud
["Kjetil S. Matheussen" <[EMAIL PROTECTED]>]
| 
| Did you expect something specific before starting to read that book?
| Thats a failure. SICP is a book you should read just for pure
| pleasure.

I was told by a lot of people I consider to be intelligent that this
book would change how I think about writing software.  it didn't.  I
didn't really know what to expect, but after reading it I did feel
that its importance was greatly exaggerated.

| >  these people seemed to be
| > completely disconnected from reality.
| 
| Please don't write things like that without backing it up with some
| reason.

well, for one, Scheme lacked proper libraries for doing everyday
things, so when I tried to use it I found myself writing a lot of
library code that I shouldn't have had to deal with.  but it is quite
long ago, so things might have changed since then.

-Bjørn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread Bjorn Borud
[Twisted <[EMAIL PROTECTED]>]
|
| Some people might say the same thing about emacs. A lot of unix tools
| even. "Stubbornly insisting on being odd" appears to be a particularly
| prevalent character flaw among the geeknoscenti.

I think you are missing the point.  you may find Emacs (and UNIX) to
be odd, and you consistently parade this around as a reason not to
even make an honest attempt at understanding how to use it (them).  if
the oddness still eclipses usefulness once you've made a proper
attempt at understanding a tool, then the oddness is a problem.  Emacs
(and UNIX) don't exhibit these characteristics for a great number of
people.

-Bjørn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: textmate and execute line

2007-06-27 Thread andrea
On 19 Giu, 14:20, andrea <[EMAIL PROTECTED]> wrote:
> Hi,
> I have the latest bundle for python (upgraded from svn) but I don't
> understand how execute line works..
>
> It only works if I play with arithmetic operations, something like
> this works:
> 2*2
> 4
>
> but for example trying to execute this line gives me this error, any
> help?
> x = 1; x + 1
>
> Traceback (most recent call last):
>   File "/tmp/temp_textmate.31Kc2h", line 19, in ?
> stdout.write(exc)
> TypeError: argument 1 must be string or read-only character buffer,
> not list
>
> Thanks a lot

Noone using textmate for python?

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


Rappresenting infinite

2007-06-27 Thread andrea

I would like to have a useful rappresentation of infinite, is there
already something??

I was thinking to something like this

class Inf(int):
"""numero infinito"""
def __init__(self,negative=False):
self.negative = negative
def __cmp__(self,y):
"""infinito maggiore di qualasiasi cosa"""
if self.negative:
return -1
else:
return 1
def __repr__(self):
"""docstring for __repr__"""
if self.negative:
return '-inf'
else:
return 'inf'
def __add__(self,y):
"""addizione con infinito"""
return self
def __mul__(self,y):
"""moltiplicazione"""
import types
if isinstance(y,types.IntType):
if y > 0:
return self
if y == 0:
return 'indefinito'
else:
return Inf(negative)


I'd like to be able to compare between any value and infinite always
getting the right result, and paying attention to the special cases
like
inf / inf => not determinate

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread Kjetil S. Matheussen


On Wed, 27 Jun 2007, Bjorn Borud wrote:

> | >  these people seemed to be
> | > completely disconnected from reality.
> |
> | Please don't write things like that without backing it up with some
> | reason.
>
> well, for one, Scheme lacked proper libraries for doing everyday
> things, so when I tried to use it I found myself writing a lot of
> library code that I shouldn't have had to deal with.  but it is quite
> long ago, so things might have changed since then.
>

Things have probably changed a little, but the stuff in SISC isn't 
specific for scheme, although a schemish language is used in the book.

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


Too many 'self' in python.That's a big flaw in this language.

2007-06-27 Thread [EMAIL PROTECTED]
HI
I'm currently using Python. I find that a instance variable must
confined with self,
for example:
class a:
def __init__(self):
self.aa=10
def bb(self):
print self.aa # See .if in c++,I could use aa to change that
variable

That's a big inconvenience in coding ,especially when you have lot of
variable
If you method need 10 variables ,you have to type "self" for 10 times
and that also makes your variable longer.

>From My point,I think this only help python interpreter to deside
where to look for.
Is there anyone know's how to make the interpreter find instance name
space first?
Or any way to make programmer's life easier?

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

Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread Twisted
On Jun 27, 4:18 am, Gian Uberto Lauri <[EMAIL PROTECTED]>
wrote:
[A very long, rambling, semi-coherent post]

> Strange. I am *NOT* a native english speaker and I think my Q.I. tends
> toward average from below...

That much is obvious.

> ...but refcard sound very useful to me, maybe is short for "reference card" ?

Yes, but you'd have to be some kind of clairvoyant to realize "I know!
I'll do a search for "refcard.ps" on the off chance someone happens to
have made a reference card, called it "refcard", and chose the
Postscript format to record it in!" out of the blue.

> I admit. find is less intuitive. But the stuff Windows comes with does
> just that  and nothing more. It  will never suggest you  that the long
> boring  task expecting  you can  be solved  in a  completely automatic
> way with a little creative job.

And with one little typo, it's hello Sorceror's Apprentice mode...

> Emacs  help was  hypertextual  when Dr.  Watson  plagued Windowd  3.11
> users...

Dr. Watson just plagued this WinXP user. Please don't mention Dr.
Watson again for a while, for the love of Christ.

> Splash, large miss.

This is usenet, not Battleship.

> You usually fire it to the local printer.

Yes, if you have one and care to blow through reams of paper and
gallons of ink every month by printing everything you encounter
instead of reading it on the expensive LCD monitor you got for such
purposes.

> T> enough. Trying to read anything serious and navigate in GSView is
> T> no picnic either.
>
> A refcard, my dear, is something that goes on an A4/Letter sheet and
> NEEDS NOT to be hypertextual.

I was being more general.

> With a PS file you can do  just one thing, execute it. It's a program,
> did you know ?

For which you need an interpreter. Such as Ghostscript. Which is a
pain to install and a bigger one to configure, even on Windoze.

> Uh, I forget. For  Windows users getting a PDF out of  a PS or HTML or
> ASCII is  not this easy unless  they get some  extra software (someone
> ported CUPS to Windows ?). Again, not an Emacs fault.

I wouldn't know CUPS if it dropped on my head. I think the same can be
said of most of the 3 or 4 non-expert unix users in the world.

> Stop guessing or all will know that all you know about Unix is that
> is a 4 letter word...

Yeah. Unix is a four-letter word alright.

> All the  computer screen is devoted  to your work,  the sheet provides
> some extra  "real estate" for the  help information, a  sort of double
> heading  display. All  you  need to  do  is turn  your  eyes from  the
> monitor, maybe  your eyes and  read the informations. It  coudl happen
> that you need to  flip the sheet. But you can keep  both your work and
> the help text  "ready at your fingertips", and  this is useful indeed:
> you read the  command keybinding, turn your eyes, type  it and see the
> result and/or continue your work.

One small step backwards for a man, one giant leap...

> About money.  Indeed ink/toner and  paper costs. Electricity  grows on
> the spark tree so aboundant in our forests...

This intrigues my younger brother. He wants to know how many moons are
in the sky and what color the sun is that your planet orbits. He's at
that phase where he's fascinated by astronauts, tales of alien worlds,
and things like that, you see...

> But PostScript printing on my  '80 Epson printwriter or my HP720c with
> a Unix  system with CUP is as  easy as opening a  browser, telling the
> system I have a HP720c plugged to the parallel port and voilà.

I'll bet. Something tells me the catch lies somewhere in "a Unix
system with CUP". Unless it's in "browser" instead. Something tells me
we're not talking about something that resembles Firefox and makes
navigation easy and intuitive here.

> In the  same time I got  an HP720c and  it come with no  other drivers
> than Mac and  Windows ones. I feared  I was SOL when I  readed of some
> guy that  wrote a small  program that was  able to convert  certain gs
> output to byte sequences good to pilot the HP720c.
>
> It was  *easy* to  put this  program in the  pipeline in  the "printer
> driver" script.
>
> And was *easy* insert a2ps to shoot plain text directly to the printer.

*Easy*. Maybe if you know all about the guts of how the printing
subsystem of the OS works. I doubt it's anything like that easy for
joe random who just wants to hit "print" and print the document
already and not have to spend ages learning about the internals of the
operating system first. In Windows, you plug it in and pick it from a
dialog (or use a disc that comes with the printer to do setup) and
print something. Voila! Out pops a document into the tray; no mess, no
fuss. Getting out your wrench and going at the plumbing shouldn't be
necessary; any more than I'd want to move into a new home and find I
needed to break out the tools and mess with the plumbing before the
toilet would flush or the kitchen tap spout water.

> Ah, you'll start  thinking that those who find  find syntax a

Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-27 Thread Bruno Desthuilliers
paul a écrit :
> Bruno Desthuilliers schrieb:
>> Stephen R Laniel a écrit :
>>> On Wed, Jun 20, 2007 at 09:41:09PM +0100, Michael Hoffman wrote:
 If you asked Java programmers why you couldn't turn *off* Java's 
 static type checking if you wanted to, you'd probably get a similar 
 response.
>>> Perhaps it would help for me to explain what I'd like.
>>>
>>> Under both Perl and Python, I've found myself
>>> having/wanting to write things like so:
>>>
>>> def my_func( int_arg, str_arg ):
>>> try:
>>> int_arg = int( int_arg )
>>> str_arg = str( str_arg )
>>> except ValueError:
>>> sys.stderr.write( "Args are not of the right type\n" )
>>> sys.exit(1)
>>>
>>
>> Just a question : what will happen if you get rid of the try/except 
>> block ?-)
>>
> The error will remain unnoticed

Err... cf below, I think you misunderstood me.

> and the argument might survive another 
> few function calls but eventually fails deep down somewhere with:
> 
> TypeError: cannot concatenate 'str' and 'list' objects
> 
> then you have to examine the traceback and hope the real error is 
> visible somewhere (an argument not conforming to the specification of 
> the function prototype, or the lack thereof).
> 

I asked about getting rid of the try/except - not about getting rid of 
the calls to int and str:

def my_func( int_arg, str_arg ):
  int_arg = int( int_arg )
  str_arg = str( str_arg )
  # now proceed...

Now, what will happen with this ?

And no, it's not type checking - it's duck typing at work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-27 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:

> I'm currently using Python. I find that a instance variable must
> confined with self,
> for example:
> class a:
> def __init__(self):
> self.aa=10
> def bb(self):
> print self.aa # See .if in c++,I could use aa to change that
> variable
> 
> That's a big inconvenience in coding ,especially when you have lot of
> variable
> If you method need 10 variables ,you have to type "self" for 10 times
> and that also makes your variable longer.
> 
>>From My point,I think this only help python interpreter to deside
> where to look for.
> Is there anyone know's how to make the interpreter find instance name
> space first?
> Or any way to make programmer's life easier?

Use a shorter name than `self` or an editor with auto completion.  If a
name in a function or method is local or global is decided at compile
time, not at run time.  So at least every assignment to an instance
attribute must have the ``self.`` in front or the compiler sees the name
as local to the method.  Changing this would slow down the interpreter
because every name has to be looked up in the instance dict every time to
decide if it's an attribute or a local name.

Another drawback of your proposed "magic" is that attributes can be
assigned, deleted or delegated dynamically at run time.  So your bare `aa`
name can change meaning from instance attribute to local name or vice
versa over the time.

You must have very compelling reasons to ask for changes that spare you
some keystrokes by the way.  Pythonistas usually don't like sacrificing
readability for fewer characters.  Most source code will be written once
but must be read and understood a couple of times, so it's more important
to have clear than short code.  With `self` in place you always know which
names are local and which are attributes.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-27 Thread Bruno Desthuilliers
harri a écrit :
> Bruno Desthuilliers wrote:
> [...]
>> It seems obvious from this that static typecheking would require
>> dropping all dynamism from Python - then turning it into another, very
>> different (and mostly useless as far as I'm concerned) language. IOW :
>> you can't have Python *and* static typechecks - both are mutually
>> exclusive. Hence my answer : if you want static typecheking, you'll have
>> to use another language - one way or another.
> 
> Well, static typing for me is usually the way to get the last speed
> required once the
> algorithmic improvements are exhausted.

Indeed - static typing is for compilers, not for programmers.

> The language Pyrex uses combines dynamic and static typing in a very
> useful manner.

Yes. But Pyrex is another language - and a much less dynamic one.

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


Re: Rappresenting infinite

2007-06-27 Thread Rob De Almeida
On Jun 27, 6:41 am, andrea <[EMAIL PROTECTED]> wrote:
> I would like to have a useful rappresentation of infinite, is there
> already something??

from numpy import inf

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-27 Thread Stephen R Laniel
On Wed, Jun 27, 2007 at 01:44:17PM +0200, Bruno Desthuilliers wrote:
> Indeed - static typing is for compilers, not for programmers.

When done well, static typing helps the programmer -- just
like writing good unit tests. It's not a magic bullet, but
it can help.

I'd like to point again to Mark-Jason Dominus's
explanation of how strong static typing can be done well:
http://perl.plover.com/yak/typing/notes.html

The example toward the end of how ML actually spots an
infinite loop at compile time seems to me to be "for
programmers" rather than "for compilers."

-- 
Stephen R. Laniel
[EMAIL PROTECTED]
Cell: +(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-27 Thread Neil Cerutti
On 2007-06-27, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> HI
> I'm currently using Python. I find that a instance variable must
> confined with self,
> for example:
> class a:
> def __init__(self):
> self.aa=10
> def bb(self):
> print self.aa # See .if in c++,I could use aa to change that
> variable
>
> That's a big inconvenience in coding ,especially when you have
> lot of variable If you method need 10 variables ,you have to
> type "self" for 10 times and that also makes your variable
> longer.

I recommend the discussion of this issue in the Python FAQ.

http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls

> From My point,I think this only help python interpreter to
> deside where to look for. Is there anyone know's how to make
> the interpreter find instance name space first? Or any way to
> make programmer's life easier?

Try thinking of "self." as a notation that provides vital
information to you, the programmer.

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


Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-27 Thread faulkner
On Jun 27, 7:02 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> HI
> I'm currently using Python. I find that a instance variable must
> confined with self,
> for example:
> class a:
> def __init__(self):
> self.aa=10
> def bb(self):
> print self.aa # See .if in c++,I could use aa to change that
> variable
>
> That's a big inconvenience in coding ,especially when you have lot of
> variable
> If you method need 10 variables ,you have to type "self" for 10 times
> and that also makes your variable longer.
>
> >From My point,I think this only help python interpreter to deside
>
> where to look for.
> Is there anyone know's how to make the interpreter find instance name
> space first?
> Or any way to make programmer's life easier?

http://www.voidspace.org.uk/python/weblog/arch_d7_2006_12_16.shtml#e584

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread Gian Uberto Lauri
> Long count = 12.19.14.7.16; tzolkin = 2 Cib; haab = 4 Tzec.
> I get words from the Allmighty Great Gnus that
> "T" == Twisted  <[EMAIL PROTECTED]> writes:

T> On Jun 27, 4:18 am, Gian Uberto Lauri <[EMAIL PROTECTED]>
T> wrote:
T> [A very long, rambling, semi-coherent post]

>> Strange. I am *NOT* a native english speaker and I think my
>> Q.I. tends toward average from below...

T> That much is obvious.

So, did  they never tell  you "never argue  with a fool,  people could
misjudge who the fool is" ? And you stille replied to my post ?

-- 
 /\   ___
/___/\_|_|\_|__|___Gian Uberto Lauri_
  //--\| | \|  |   Integralista GNUslamico
\/ e coltivatore diretto di Software

A Cesare avrei detto di scrivermi a [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread Timofei Shatrov
On Wed, 27 Jun 2007 11:04:39 -, Twisted <[EMAIL PROTECTED]> tried to
confuse everyone with this message:

>
>> With a PS file you can do  just one thing, execute it. It's a program,
>> did you know ?
>
>For which you need an interpreter. Such as Ghostscript. Which is a
>pain to install and a bigger one to configure, even on Windoze.
>

Lie. Ghostscript works out of the box on Windows.

-- 
|Don't believe this - you're not worthless  ,gr-.ru
|It's us against millions and we can't take them all... |  ue il   |
|But we can take them on!   | @ma  |
|   (A Wilhelm Scream - The Rip)|__|
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: popen and a long running process in a wx.python application

2007-06-27 Thread Doru Moisa

Mike, Ratko,

Thanks a lot guys, for the quick and prompt answers.

Doru


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


Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-27 Thread Roy Smith
faulkner <[EMAIL PROTECTED]> wrote:
> http://www.voidspace.org.uk/python/weblog/arch_d7_2006_12_16.shtml#e584

I looked the "Selfless Python" idea described there, and I think it's a 
REALLY bad idea.  It's a clever hack, but not something I would ever want 
to see used in production code.  Sure, it saves a little typing, but it 
invokes a lot of magic and the result is essentially a new language and 
everybody who uses this code in the future will have to scratch their heads 
and figure out what you did.

Programs get written once.  They get read and maintained forever, by 
generations of programmers who haven't even been hired by your company yet.  
Doing some clever magic to save a few keystrokes for the original 
programmer at the cost of sowing confusion for everybody else in the future 
is a bad tradeoff.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-27 Thread Roy Smith
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> Use a shorter name than `self` or an editor with auto completion.

Of the two, I'd strongly vote for the auto completion (assuming you feel 
the need to "solve" this problem at all).  The name "self" is so ingrained 
in most Python programmers minds, that it's almost a keyword.  Changing it 
to "this" or "s" or "me" will just make your program a little harder for 
other people to understand.

Changing it to "this" would be particularly perverse since it's not even 
any less typing.  In fact, on a standard keyboard, it's harder to type 
since it involves moving off the home row more :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread Bjorn Borud
["Kjetil S. Matheussen" <[EMAIL PROTECTED]>]
| 
| Things have probably changed a little, but the stuff in SISC isn't
| specific for scheme, although a schemish language is used in the book.

well, those are really two separate discussions:  Scheme and whether
SICP is an important book or not.

-Bjørn
-- 
http://mail.python.org/mailman/listinfo/python-list


idestudio

2007-06-27 Thread Ron Provost
Has anyone been able to download idestudio?  Any link I find on google is 
broken.

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

Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-27 Thread Paul Boddie
On 27 Jun, 14:02, Stephen R Laniel <[EMAIL PROTECTED]> wrote:
>
> I'd like to point again to Mark-Jason Dominus's
> explanation of how strong static typing can be done well:
> http://perl.plover.com/yak/typing/notes.html

What's interesting is that the author touches on explicit attribute
declarations in slide 37 - something which I think John Nagle
suggested recently, although apologies to John and the person in
question if it was someone else. Without actually declaring types for
those attributes, it's possible to make some potential efficiency
gains, and I think that interfaces (really clusters of attributes in
this case) can be deduced with only this information explicitly stated
by the programmer. Of course, you can also try whole program analysis
to get an idea of which instances have which attributes, too.
Certainly, there are lots of approaches available without writing type
names all over the place, as seems to be the fashion in certain
circles.

Paul

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-27 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 Paul Boddie <[EMAIL PROTECTED]> wrote:

> On 27 Jun, 14:02, Stephen R Laniel <[EMAIL PROTECTED]> wrote:
> >
> > I'd like to point again to Mark-Jason Dominus's
> > explanation of how strong static typing can be done well:
> > http://perl.plover.com/yak/typing/notes.html
> 
> What's interesting is that the author touches on explicit attribute
> declarations in slide 37 - something which I think John Nagle
> suggested recently, although apologies to John and the person in
> question if it was someone else. Without actually declaring types for
> those attributes, it's possible to make some potential efficiency
> gains, and I think that interfaces (really clusters of attributes in
> this case) can be deduced with only this information explicitly stated
> by the programmer. Of course, you can also try whole program analysis
> to get an idea of which instances have which attributes, too.
> Certainly, there are lots of approaches available without writing type
> names all over the place, as seems to be the fashion in certain
> circles.
> 
> Paul

Software type checking (static, dynamics, whatever) is for weenies.  Real 
men use hardware type checking.  Google "Burroughs B5000".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What was that web interaction library called again?

2007-06-27 Thread Stian Soiland
2007/6/26, Omer Khalid <[EMAIL PROTECTED]>:

> On the RESTFul web service, I would like to piggy pack my own question two
> is there a way to make the connection secure between two Restful service
> running on GNU/linux?

https?

-- 
Stian Søiland   Any society that would give up a little
Manchester, UK  liberty to gain a little security will
http://soiland.no/  deserve neither and lose both. [Franklin]
 =/\=
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-27 Thread Sion Arrowsmith
Neil Cerutti  <[EMAIL PROTECTED]> wrote:
>On 2007-06-27, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> From My point,I think this only help python interpreter to
>> deside where to look for. Is there anyone know's how to make
>> the interpreter find instance name space first? Or any way to
>> make programmer's life easier?
>Try thinking of "self." as a notation that provides vital
>information to you, the programmer.

And it provides even more vital information to *other* programmers
dealing with your code ("other" including "you in six months time").
I've just confused the socks off a cow-orker by writing in a C++
method kill(SIGTERM); -- confusion which would have been avoided if
I'd used an explicit this->kill(SIGTERM); . But amongst C++'s many
flaws, such disambiguation is frowned on as non-idiomatic. Explicit
self *is a good thing*.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-27 Thread Jorgen Bodde
I had the same feeling when I started, coming from a C++ background, I
forgot about self a lot, creating local copies of what should be an
assign to a class instance, or methods that could not be found because
I forgot 'self' .

Now I am 'kinda' used to it, as every language has some draw backs
(you can't please all). But, what about something in between like only
using the dot (.) for a shorter notation?

self.some_var = True

Could become:

.some_var = True

Which basically shows about the same thing, but you leave 'self' out
of the syntax. Ofcourse it should not be allowed to break a line
between the dot and the keywords, else Python would never know what to
do;

my_class()
.my_var = True

Should not be parsed the same as;

my_class().my_var = True

Just a suggestion. I am pretty happy with self, but I could settle for
a shorter version if possible.

- Jorgen


On 6/27/07, Roy Smith <[EMAIL PROTECTED]> wrote:
> Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> > Use a shorter name than `self` or an editor with auto completion.
>
> Of the two, I'd strongly vote for the auto completion (assuming you feel
> the need to "solve" this problem at all).  The name "self" is so ingrained
> in most Python programmers minds, that it's almost a keyword.  Changing it
> to "this" or "s" or "me" will just make your program a little harder for
> other people to understand.
>
> Changing it to "this" would be particularly perverse since it's not even
> any less typing.  In fact, on a standard keyboard, it's harder to type
> since it involves moving off the home row more :-)
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-27 Thread Bruno Desthuilliers
Stephen R Laniel a écrit :
> On Wed, Jun 27, 2007 at 01:44:17PM +0200, Bruno Desthuilliers wrote:
>> Indeed - static typing is for compilers, not for programmers.
> 
> When done well, static typing helps the programmer

The closer thing to "well done static typing" I know is type inference 
(à la O'Caml). And I don't find it that helpfull to the programmer - 
here again, it's mainly to allow compile-time optimizations.

(snip)
> The example toward the end of how ML actually spots an
> infinite loop at compile time seems to me to be "for
> programmers" rather than "for compilers."

It's been a long time since I last got into such a problem. Which BTW 
was very quickly spotted and fixed. Compared to what I would loose, I 
don't think this kind of "help" is so useful.

Stephen, you may not know yet, but Python is *dynamic*. This defeats 
almost all compile-time checking. Of what help would type inference be 
when you can dynamically add/remove/replace attributes (including 
methods and class) at runtime ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting importError: No module named _md5

2007-06-27 Thread jeffself
I'm running Python 2.5.1 which I'm getting from the MacPort package
system.  I just installed Django and tried to start up the Django
server and I got the following error:

ImportError: No module named _md5

I'm pretty sure this is a python problem, not Django problem. I'm
looking in the python2.5 directory and I see md5.py, md5.pyc and
md5.pyo files.

Any suggestions?

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-27 Thread Stephen R Laniel
On Wed, Jun 27, 2007 at 04:03:39PM +0200, Bruno Desthuilliers wrote:
> Stephen, you may not know yet, but Python is *dynamic*. This defeats 
> almost all compile-time checking. Of what help would type inference be 
> when you can dynamically add/remove/replace attributes (including 
> methods and class) at runtime ?

Heh. [Insert grimacing smile here]

People on here have been ... ahhh ... *generous* about
explaining that Python is dynamic, and hence that static
typing doesn't make sense. I've got it. I merely passed
along that MJD reference because you were making a point
about what static typing is for in general (i.e., not
specific to Python). I thought I'd give examples of how
languages other than Python use it to good effect, and not
just for compiler optimization.

Cheers,
Steve

-- 
Stephen R. Laniel
[EMAIL PROTECTED]
Cell: +(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-- 
http://mail.python.org/mailman/listinfo/python-list


Zip File Woes

2007-06-27 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm having a MASSIVE headache today with zip files, I had it working a while
ago but it all seems to have stopped in the past 30 minutes and I can't
figure out why.

 

I'm simply trying to write a function that will unzip a file, simple as
that. I've currently got this code:

 

Import zipfile

 

  zip = zipfile.ZipFile('Media/Media.zip', 'r')

  unzip(zip)

  zip.close()

 

def unzip(zip):

   for name in zip.namelist():

  newname = 'Media/%s' % (name)

  file(newname, 'wb').write(zip.read(name))

 

Now when I try and run this i get the following error message:

 

  File "/usr/lib/python2.4/zipfile.py", line 242, in _RealGetContents

raise BadZipfile, "File is not a zip file"

zipfile.BadZipfile: File is not a zip file

 

However, if I copy the zip file off the unit client onto my windows box and
unzip it and it works absolutely perfectly, all the files are extracted as I
would expect, which leads me to think the zip file is fine, and i must just
be missing something in my code.

 

Any ideas guys? I'm tearing my hair out here.

 

Rob

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

sort pygtk gtktreeview column containing dates

2007-06-27 Thread psaroudakis
Hello... I have been trying to sort a gtktreelist column that contains
dates in the following format:

eg: 01-Jan-1993
 12-Dec-1992 etc

i don't seem to be able to find any other solution than using dates in
the format "-MM-DD" which is something i am trying to avoid..

Is there something very trivial that I am missing/overlooking? any
suggestions?

Thanks,

Nik

Disclaimer: I am very new to Python and Pygtk

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


RE: Zip File Woes

2007-06-27 Thread Robert Rawlins - Think Blue
Just as an update guys:

 

Before my zip code featured below I have another piece of code that creates
the zip file from a binary string, like this:

 

  #f3 = open("Media/Media.zip", "wb")

  #f3.write(base64.decodestring(MediaBinary))

  #f3.close

 

Now, with that code commented out like that so the unzip code is running on
the file generated last time the code was run it works fine, but if I try
and unzip after the file has been freshly created I get that error, I've
even tried placing a 2 second sleep command in between them and still get
the problems.

 

Thanks guys,

 

Rob

 

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Robert Rawlins - Think Blue
Sent: 27 June 2007 15:10
To: python-list@python.org
Subject: Zip File Woes

 

Hello Guys,

 

I'm having a MASSIVE headache today with zip files, I had it working a while
ago but it all seems to have stopped in the past 30 minutes and I can't
figure out why.

 

I'm simply trying to write a function that will unzip a file, simple as
that. I've currently got this code:

 

Import zipfile

 

  zip = zipfile.ZipFile('Media/Media.zip', 'r')

  unzip(zip)

  zip.close()

 

def unzip(zip):

   for name in zip.namelist():

  newname = 'Media/%s' % (name)

  file(newname, 'wb').write(zip.read(name))

 

Now when I try and run this i get the following error message:

 

  File "/usr/lib/python2.4/zipfile.py", line 242, in _RealGetContents

raise BadZipfile, "File is not a zip file"

zipfile.BadZipfile: File is not a zip file

 

However, if I copy the zip file off the unit client onto my windows box and
unzip it and it works absolutely perfectly, all the files are extracted as I
would expect, which leads me to think the zip file is fine, and i must just
be missing something in my code.

 

Any ideas guys? I'm tearing my hair out here.

 

Rob

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

Re: urllib interpretation of URL with ".."

2007-06-27 Thread sergio
Gabriel Genellina wrote:

> En Tue, 26 Jun 2007 17:26:06 -0300, sergio <[EMAIL PROTECTED]>
> escribió:
> 
>> John Nagle wrote:
>>
>>>  In Python, of course, "urlparse.urlparse", which is
>>> the main function used to disassemble a URL, has no idea whether it's
>>> being used by a client or a server, so it, reasonably enough, takes
>>> option
>>> 1.
>>
> import urlparse
> base="http://somesite.com/level1/";
> path="../page.html"
> urlparse.urljoin(base,path)
>> 'http://somesite.com/page.html'
> base="http://somesite.com/";
> urlparse.urljoin(base,path)
>> 'http://somesite.com/../page.html'
>>
>> For me this is a bug and is very annoying because I can't simply trip ../
>> from path because base could have a level.
> 
> I'd say it's an annoyance, not a bug. Write your own urljoin function with
> your exact desired behavior - since all "meaningful" .. and . should have
> been already processed by urljoin, a simple url =
> url.replace("/../","/").replace("/./","/") may be enough.
> 

I had exactly the same though the solution is simply this:

urlparse.urljoin(base,path).replace("/../","/")


Many thanks,
--
Sérgio M. B. 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-27 Thread Andy Freeman
On Jun 27, 1:15 am, Paul Rubin  wrote:
> Dennis Lee Bieber <[EMAIL PROTECTED]> writes:
>
> >What happens when two individuals release "libraries" using these
> > proposed macros -- and have implement conflicting macros using the same
> > identifiers -- and you try to use both libraries in one application?
>
> Something like the current situation with Python web frameworks ;)

Actually, no.  For python, the most reasonable macro scope would be
the file, so different files in the same application could easily use
conflicting macros without any problems.


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


Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-27 Thread A.T.Hofkamp
On 2007-06-27, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> HI
> I'm currently using Python. I find that a instance variable must
> confined with self,
> for example:
> class a:
> def __init__(self):
> self.aa=10
> def bb(self):
> print self.aa # See .if in c++,I could use aa to change that
> variable

c++ is a much more static language (for example, you cannot create new fields
in your class at run time), so it can decide in advance what you mean.

In other words, it is a cost you pay for the increased flexibility. You may not
be using that flexibility, but it is there, and people use it.

> That's a big inconvenience in coding ,especially when you have lot of
> variable

I have switched from c++ to Python several years ago, and was surprised about
having to explicitly write 'self' each time. However, I never considered it "a
big inconvenience".
As years went by I have come to like the explicit notation in Python.


> Or any way to make programmer's life easier?

Others have already pointed out that leaving out 'self' is more bad than good.
I think they are right. In the past I also thought that Python was badly
designed, and until now, in the end it appeared that I was always in error.
[off-topic:
 I think that again now with the default implementation of the object.__eq__ and
  object.__hash__ methods. I believe these methods should not exist until the
  programmer explicitly defines them with a suitable notion of equivalence.

  Anybody have a good argument against that? :-)
]


Another suggestion may be to look at your code again, and check whether all
self's are really needed. In other words, can you improve your code by reducing
use of instance variables?
In Python, The "a=b" statement is extremely cheap, because you don't copy data.
Exploit that feature.

An alternative may be to copy a self variable into a local variable one and use
the local variable in the method. Another option may be to collect results in a
local variable first and then assign it to a self.X variable.

If you really have a lot of variables, are you sure that they should all be
seperate (flat) variables in one class, ie would it be possible to merge some
of them together in another object and have more structure in the variables?
(classes are much cheaper in Python than in c++ w.r.t. amount of code)


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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread Twisted
On Jun 27, 8:26 am, [EMAIL PROTECTED] (Timofei Shatrov) wrote:
> >For which you need an interpreter. Such as Ghostscript. Which is a
> >pain to install and a bigger one to configure, even on Windoze.
>
> Lie. Ghostscript works out of the box on Windows.

You're joking. First of all I am not a liar, and secondly, Ghostscript
and Ghostview are tricky to set up correctly. I know -- I've done it a
time or three. There's an arcane GUI configurator that isn't
exceptionally well designed, and once it's working it still wonks out
on maybe 1 in 10 .ps and .eps files you come across ... which is still
better than being able to view none of them, mind you. Nonetheless
there's a world of difference between the GS tools and say Adobe
Acrobat Reader in terms of setup and use; the latter you just run an
installer and then find a pdf to double-click; no other steps
necessary and it works every time. Of course, Adobe stuff is
proprietary, and acrord supports some types of evil DRM...

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-27 Thread Andy Freeman
On Jun 26, 10:03 am, Paul Rubin  wrote:
> > Map doesn't work on generators or iterators because they're not part
> > of the common lisp spec, but if someone implemented them as a library,
> > said library could easily include a map that handled them as well.
>
> Right, more scattered special purpose kludges instead of a powerful
> uniform interface.

Huh?  The interface could continue to be (map ...).

Python's for statement relies on the fact that python is mostly object
oriented and many of the predefined types have an iterator interface.
Lisp lists and vectors currently aren't objects and very few of the
predefined types have an iterator interface.

It's easy enough to get around the lack of objectness and add the
equivalent of an iterator iterface, in either language.  The fact that
lisp folks haven't bothered suggests that this isn't a big enough
issue.

The difference is that lisp users can easily define python-like for
while python folks have to wait for the implementation.

Syntax matters.


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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-27 Thread Chris Mellon
On 6/27/07, Andy Freeman <[EMAIL PROTECTED]> wrote:
> On Jun 26, 10:03 am, Paul Rubin  wrote:
> > > Map doesn't work on generators or iterators because they're not part
> > > of the common lisp spec, but if someone implemented them as a library,
> > > said library could easily include a map that handled them as well.
> >
> > Right, more scattered special purpose kludges instead of a powerful
> > uniform interface.
>
> Huh?  The interface could continue to be (map ...).
>
> Python's for statement relies on the fact that python is mostly object
> oriented and many of the predefined types have an iterator interface.
> Lisp lists and vectors currently aren't objects and very few of the
> predefined types have an iterator interface.
>
> It's easy enough to get around the lack of objectness and add the
> equivalent of an iterator iterface, in either language.  The fact that
> lisp folks haven't bothered suggests that this isn't a big enough
> issue.
>

Is this where I get to call Lispers Blub programmers, because they
can't see the clear benefit to a generic iteration interface?

> The difference is that lisp users can easily define python-like for
> while python folks have to wait for the implementation.
>

Yes, but Python already has it (so the wait time is 0), and the Lisp
user doesn't.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simplifying algebraic expressions

2007-06-27 Thread Alex Martelli
DavidM <[EMAIL PROTECTED]> wrote:
   ...
> Seems that I have to allow a 'punishment free' threshold of complexity,
> otherwise the population stagnates.

Sounds like you've hit on a good simulation of life: to get innovation,
you must be very tolerant of errors!-)


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


16bit hash

2007-06-27 Thread Robin Becker
Is the any way to get an efficient 16bit hash in python?
-- 
Robin Becker

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


Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-27 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:

> I'm currently using Python. 

How long have you been using Python?

> I find that a instance variable 
> must confined with self, for example:
> class a:
> def __init__(self):
> self.aa=10
> def bb(self):
> print self.aa # 
> See .if in c++,I could use aa to change that variable

Mh, strange, I personally like to use "this.a" in C++, to make clear
I use an instance variable.

> That's a big inconvenience in coding ,especially when you have lot
> of variable

NACK, see above.

> If you method need 10 variables ,you have to type "self" for 10 
> times and that also makes your variable longer.

Explicit is better than implicit.
 
> From My point,I think this only help python interpreter to deside
> where to look for.

IMHO, it's also a great hint for the programmer. With others' C++
code, I'm often confused what kinds of variables (global, instance,
static, ...) they access, it's also badly commented. If C++ forced
the programmer to write "this.var", the code would be
understandable with much less comments.

Regards,


Björn

-- 
BOFH excuse #13:

we're waiting for [the phone company] to fix that line

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-27 Thread Chris Mellon
On 6/27/07, Douglas Alan <[EMAIL PROTECTED]> wrote:
> Paul Rubin  writes:
>

> Gee, that's back to the future with 1975 Lisp technology.  Destructors
> are a much better model for dealing with such things (see not *all*
> good ideas come from Lisp -- a few come from C++) and I am dismayed
> that Python is deprecating their use in favor of explicit resource
> management.  Explicit resource management means needlessly verbose
> code and more opportunity for resource leaks.
>
> The C++ folks feel so strongly about this, that they refuse to provide
> "finally", and insist instead that you use destructors and RAII to do
> resource deallocation.  Personally, I think that's taking things a bit
> too far, but I'd rather it be that way than lose the usefulness of
> destructors and have to use "when" or "finally" to explicitly
> deallocate resources.
>

This totally misrepresents the case. The with statement and the
context manager is a superset of the RAII functionality. It doesn't
overload object lifetimes, rather it makes the intent (code execution
upon entrance and exit of a block) explicit. You use it in almost
exactly the same way you use RAII in C++ (creating new blocks as you
need new scopes), and it performs exactly the same function.

Nobody in their right mind has ever tried to get rid of explicit
resource management - explicit resource management is exactly what you
do every time you create an object, or you use RAII, or you open a
file. *Manual* memory management, where the tracking of references and
scopes is placed upon the programmer, is what people are trying to get
rid of and the with statement contributes to that goal, it doesn't
detract from it. Before the with statement, you could do the same
thing but you needed nested try/finally blocks and you had to
carefully keep track of the scopes, order of object creation, which
objects were created, all that. The with statement removes the manual,
error prone work from that and lets you more easily write your intent
- which is *precisely* explicit resource management.

RAII is a good technique, but don't get caught up on the
implementation details. The fact that it's implemented via stack
objects with ctors and dtors is a red herring. The significant feature
is that it's you've got explicit, predictable resource management with
(and this is the important bit) a guarantee that code will be called
in all cases of scope exit.

The with statement does exactly the same thing, but is actually
superior because

a) It doesn't tie the resource managment to object creation. This
means you can use, for example, with lock: instead of the C++ style
Locker(lock)

and

b) You can tell whether you exited with an exception, and what that
exception is, so you can take different actions based on error
conditions vs expected exit. This is a significant benefit, it allows
the application of context managers to cases where RAII is weak. For
example, controlling transactions.

> > Python object lifetimes are in fact NOT predictable because the ref
> > counting doesn't (and can't) pick up cyclic structure.
>
> Right, but that doesn't mean that 99.9% of the time, the programmer
> can't immediately tell that cycles aren't going to be an issue.
>
> I love having a *real* garbage collector, but I've also dealt with C++
> programs that are 100,000+ lines long and I wrote plenty of Python
> code before it had a real garbage collector, and I never had any
> problem with cyclic data structures causing leaks.  Cycles are really
> not all that common, and when they do occur, it's usually not very
> difficult to figure out where to add a few lines to a destructor to
> break the cycle.
>

They can occur in the most bizarre and unexpected places. To the point
where I suspect that the reality is simply that you never noticed your
cycles, not that they didn't exist.

> > And the refcounts are a performance pig in multithreaded code,
> > because of how often they have to be incremented and updated.
>
> I'm willing to pay the performance penalty to have the advantage of
> not having to use constructs like "when".
>

"with". And if you think you won't need it because python will get
"real" GC you're very confused about what GC does and how.

> Also, I'm not convinced that it has to be a huge performance hit.
> Some Lisp implementations had a 1,2,3, many (or something like that)
> reference-counter for reclaiming short-lived objects.  This bypassed
> the real GC and was considered a performance optimization.  (It was
> probably on a Lisp Machine, though, where they had special hardware to
> help.)
>
> > That's why CPython has the notorious GIL (a giant lock around the
> > whole interpreter that stops more than one interpreter thread from
> > being active at a time), because putting locks on the refcounts
> > (someone tried in the late 90's) to allow multi-cpu parallelism
> > slows the interpreter to a crawl.
>
> All due to the ref-counter?  I find this really hard to be

Re: import data.py using massive amounts of memory

2007-06-27 Thread GHUM

> Note that once it has made the .pyc file the subsequent runs take even
> less memory than the cpickle import.

Could that be the compiler compiling?

Without knowing to much details about that process, but from 2.4 to
2.5 the compiler was totally exchanged,  to AST.
That would explain the drop from 8Meg -> 2.2 Meg.

Harald



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


equality & comparison by default (was Re: Too many 'self' in python.That's a big flaw in this language.)

2007-06-27 Thread Alex Martelli
A.T.Hofkamp <[EMAIL PROTECTED]> wrote:

>  I think that again now with the default implementation of the
>  object.__eq__ and object.__hash__ methods. I believe these methods should
>  not exist until the programmer explicitly defines them with a suitable
>  notion of equivalence.
> 
>   Anybody have a good argument against that? :-)

It's very common and practical (though not ideologically pure!) to want
each instance of a class to "stand for itself", be equal only to itself:
this lets me place instances in a set, etc, without fuss.

I don't want, in order to get that often-useful behavior, to have to
code a lot of boilerplate such as
def __hash__(self): return hash(id(self))
and the like -- so, I like the fact that object does it for me.  I'd
have no objection if there were two "variants" of object (object itself
and politically_correct_object), inheriting from each other either way
'round, one of which kept the current practical approach while the other
made __hash__ and comparisons abstract.

In Python 3000, ordering comparisons will not exist by default (sigh, a
modest loss of practicality on the altar of purity -- ah well, saw it
coming, ever since complex numbers lost ordering comparisons), but
equality and hashing should remain just like now (yay!).


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


Re: Getting importError: No module named _md5

2007-06-27 Thread half . italian
On Jun 27, 7:04 am, jeffself <[EMAIL PROTECTED]> wrote:
> I'm running Python 2.5.1 which I'm getting from the MacPort package
> system.  I just installed Django and tried to start up the Django
> server and I got the following error:
>
> ImportError: No module named _md5
>
> I'm pretty sure this is a python problem, not Django problem. I'm
> looking in the python2.5 directory and I see md5.py, md5.pyc and
> md5.pyo files.
>
> Any suggestions?

Try to load the md5 module from the interactive prompt.  Are you using
the python version you expect?  Try starting up your previous version
of python and see if you get the same error.  Delete the MacPort
install and install from source.

My 2 cents.

~Sean

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread Matthias Buelow
Bjorn Borud wrote:

> I was told by a lot of people I consider to be intelligent that this
> book would change how I think about writing software.  it didn't.  I
> didn't really know what to expect, but after reading it I did feel
> that its importance was greatly exaggerated.

I think it's basically a course book, for some CS courses at MIT that it
was originally used with, and that's it. It's not superb but ok, as far
as "lecture notes" go, a bit pretentious and a bit idiosyncratic,
probably due to being targeted mainly at students visiting a particular
course of lectures. I don't think it's supposed to be a general "how to
learn good programming"-style book although I don't think you've wasted
time reading it.

F'up-to: c.l.lisp.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 16bit hash

2007-06-27 Thread Josiah Carlson
Robin Becker wrote:
> Is the any way to get an efficient 16bit hash in python?

hash(obj)&65535

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-27 Thread John Nagle
Bruno Desthuilliers wrote:
> harri a écrit :

> Indeed - static typing is for compilers, not for programmers.

 Actually, static typing is for detecting errors before the
program is run.

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-27 Thread John Nagle
Stephen R Laniel wrote:

> People on here have been ... ahhh ... *generous* about
> explaining that Python is dynamic, and hence that static
> typing doesn't make sense. I've got it. 

That's not really the issue.  There are languages with
no static typing, like Python, and there are languages with
fullly enforced static typing, like Java.  Both work.

PEP 3107 is static typing without enforcement, which is not a good thing.
It's one that's been tried, many times, as coding conventions.  Microsoft
code from the Windows 3.1 era was heavy on that sort of thing.
Remember "Hungarian notation"?  "LPSTR"?  Yes, that stuff.
Moving to C++ and strong typing was generally considered a major
improvement in the Windows world.

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


Re: Collections of non-arbitrary objects ?

2007-06-27 Thread walterbyrd
On Jun 26, 8:23 am, Bruno Desthuilliers  wrote:
> walterbyrda écrit :
>
> >> You do program carefully, don't you ?-)
>
> > I try. But things like typos are a normal part a life.
>
> So are they in any language. I fail to see much difference here.
>

For example: if I mis-type a variable name in C, the program will
probably not even compile. Whereas, with Python, the program will
probably run, but may give unexpected results.


> > Guido
> > must think python has a lot of room for improvement since he's
> > completely throwing out backward compatibility with python 3000.
>
> Not "completely throwing out". Just allowing *some* major breakages -
> the kind you usually get with each major release of other languages, but
> that Python managed to avoid as much as possible so far.

I don't know, but here is a direct quote from Guido's blog: "Python
3.0 will break backwards compatibility. Totally."

http://www.artima.com/weblogs/viewpost.jsp?thread=208549

>
> > It seems to me that tuple are essentially immutable lists.
>
> They are not (even if you can use them that way too). FWIW and IIRC,
> this is a FAQ.

A few posters here have stated that tuples are not just immutable but
when I compare lists, to tuples, I notice that both are ordered
collections of arbitrary objects, with the primary difference being
that list are mutable, and tuples are not. It seems to me that if a
list were immutable, it would be a tuple. That is the one big
difference.

Tuples have been compared to records/structures in other languages.
But, in general, I can not use a for loop to loop through the fields
in a record, and I can not sort those fields either.

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

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-27 Thread joswig
On Jun 27, 10:51 am, Paul Rubin  wrote:

> I personally use Emacs Lisp every day and I think Hedgehog Lisp (a
> tiny functional Lisp dialect intended for embedded platforms like cell
> phones--the runtime is just 20 kbytes) is a very cool piece of code.
> But using CL for new, large system development just seems crazy today.

It seems that many of the hardcore Lisp developers are busy developing
the core of new airline system software (pricing, reservation, ...)
in Common Lisp. It replaced already some mainframes...
Kind of crazy. I guess that counts as very large systems development.

There is sure also lots of Python involved, IIRC.


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


Reversing a string

2007-06-27 Thread Scott
Yeah I know strings == immutable, but question 1 in section 7.14 of "How to 
think like a computer Scientist" has me trying to reverse one.

I've come up with two things, one works almost like it should except that 
every traversal thru the string I've gotten it to repeat the "list" again. 
This is what it looks like:

[code]
>>>mylist = []
>>>def rev(x):
for char in x:
mylist.append(char)
mylist.reverse()
print mylist
[/code]

And the output that sorta works like it should, but threw a curveball, at me 
looks like this:
>>> rev("this is just a test")
['t']
['h', 't']
['i', 't', 'h']
['s', 'h', 't', 'i']
[' ', 'i', 't', 'h', 's']
['i', 's', 'h', 't', 'i', ' ']
['s', ' ', 'i', 't', 'h', 's', 'i']
[' ', 'i', 's', 'h', 't', 'i', ' ', 's']
['j', 's', ' ', 'i', 't', 'h', 's', 'i', ' ']
['u', ' ', 'i', 's', 'h', 't', 'i', ' ', 's', 'j']
['s', 'j', 's', ' ', 'i', 't', 'h', 's', 'i', ' ', 'u']
['t', 'u', ' ', 'i', 's', 'h', 't', 'i', ' ', 's', 'j', 's']
[' ', 's', 'j', 's', ' ', 'i', 't', 'h', 's', 'i', ' ', 'u', 't']
['a', 't', 'u', ' ', 'i', 's', 'h', 't', 'i', ' ', 's', 'j', 's', ' ']
[' ', ' ', 's', 'j', 's', ' ', 'i', 't', 'h', 's', 'i', ' ', 'u', 't', 'a']
['t', 'a', 't', 'u', ' ', 'i', 's', 'h', 't', 'i', ' ', 's', 'j', 's', ' ', 
' ']
['e', ' ', ' ', 's', 'j', 's', ' ', 'i', 't', 'h', 's', 'i', ' ', 'u', 't', 
'a', 't']
['s', 't', 'a', 't', 'u', ' ', 'i', 's', 'h', 't', 'i', ' ', 's', 'j', 's', 
' ', ' ', 'e']
['t', 'e', ' ', ' ', 's', 'j', 's', ' ', 'i', 't', 'h', 's', 'i', ' ', 'u', 
't', 'a', 't', 's']


So I figured maybe make it a generator (I'm not TO familiar with generators 
yet so don't laugh) which changed my code just a slight bit:

[code]
>>>mylist = []
>>>def rev(x):
for char in x:
mylist.append(char)
mylist.reverse()
yield mylist
[/code]

But even that threw me a curveball:
>>> rev("this is just a test")


So how on earth would be the best way to: Write a function that takes a 
string as an argument and outputs the letters backward, one per line.

It should look like the first char of every list in the top "working" code.

Any help woould be greatly apreciated, and a little bit of explaination as 
to why you did it the way you did would be more helpful than just the code.

Thanks in advance 


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


Re: Reversing a string

2007-06-27 Thread Will Maier
On Wed, Jun 27, 2007 at 12:53:36PM -0400, Scott wrote:
> So how on earth would be the best way to: Write a function that
> takes a string as an argument and outputs the letters backward,
> one per line.

>>> def rev(forward):
... backward = list(forward)
... backward.reverse()
... return ''.join(backward)
>>> rev("spam")
'maps'

list.reverse() changes the list in-place. Instead of iterating over
the items in the string sequence, you can just convert the input
string outright.

-- 

[Will [EMAIL PROTECTED]|http://www.lfod.us/]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reversing a string

2007-06-27 Thread Stefan Behnel
Scott wrote:
> So how on earth would be the best way to: Write a function that takes a 
> string as an argument and outputs the letters backward, one per line.

Homework?

Anyway, what about:

  for c in string[::-1]:
  print c


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


Re: Reversing a string

2007-06-27 Thread Diez B. Roggisch
Scott wrote:

> Yeah I know strings == immutable, but question 1 in section 7.14 of "How
> to think like a computer Scientist" has me trying to reverse one.
> 
> I've come up with two things, one works almost like it should except that
> every traversal thru the string I've gotten it to repeat the "list" again.
> This is what it looks like:
> 
> [code]
mylist = []
def rev(x):
> for char in x:
> mylist.append(char)
> mylist.reverse()
> print mylist
> [/code]



The reverse() is totally useless to apply each when appending each
character. Not only useless, but faulty: if you have a even number of
characters, your string won't be reversed.

All you need to do is this:

>>> x = "abcdefg"
>>> print "".join(reversed(x))
gfedcba


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


Re: 16bit hash

2007-06-27 Thread Robin Becker
Josiah Carlson wrote:
> Robin Becker wrote:
>> Is the any way to get an efficient 16bit hash in python?
> 
> hash(obj)&65535
> 
>   - Josiah
yes I thought of that, but cannot figure out if the internal hash really 
distributes the bits evenly. Particularly since it seems to treat integers etc 
as special cases

 >>> hash(1)
1
 >>> hash(2)
2
 >>> hash('1234')
1723328704
 >>>
-- 
Robin Becker

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


Re: Reversing a string

2007-06-27 Thread vbr

>  Původní zpráva 
> Od: Will Maier <[EMAIL PROTECTED]>
> Předmět: Re: Reversing a string
> Datum: 27.6.2007 19:08:40
> 
> On Wed, Jun 27, 2007 at 12:53:36PM -0400, Scott wrote:
> > So how on earth would be the best way to: Write a function that
> > takes a string as an argument and outputs the letters backward,
> > one per line.
> 
> >>> def rev(forward):
> ... backward = list(forward)
> ... backward.reverse()
> ... return ''.join(backward)
> >>> rev("spam")
> 'maps'
> 
> list.reverse() changes the list in-place. Instead of iterating over
> the items in the string sequence, you can just convert the input
> string outright.
> 
> -- 
> 
> [Will [EMAIL PROTECTED]|http://www.lfod.us/]
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 
> 

Or using string slice with negative step?

>>> "spam"[::-1]
'maps'

or one letter per line:

>>> print "\n".join("spam"[::-1])
m
a
p
s


Greetings,

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


Re: Collections of non-arbitrary objects ?

2007-06-27 Thread Steve Holden
walterbyrd wrote:
> On Jun 26, 8:23 am, Bruno Desthuilliers  [EMAIL PROTECTED]> wrote:
>> walterbyrda écrit :
>>
 You do program carefully, don't you ?-)
>>> I try. But things like typos are a normal part a life.
>> So are they in any language. I fail to see much difference here.
>>
> 
> For example: if I mis-type a variable name in C, the program will
> probably not even compile. Whereas, with Python, the program will
> probably run, but may give unexpected results.
> 
> 
>>> Guido
>>> must think python has a lot of room for improvement since he's
>>> completely throwing out backward compatibility with python 3000.
>> Not "completely throwing out". Just allowing *some* major breakages -
>> the kind you usually get with each major release of other languages, but
>> that Python managed to avoid as much as possible so far.
> 
> I don't know, but here is a direct quote from Guido's blog: "Python
> 3.0 will break backwards compatibility. Totally."
> 
By which he means he is not, for this one major release only, committed 
to maintaining backwards compatibility with previous versions (which was 
pretty good, though not perfect).

> http://www.artima.com/weblogs/viewpost.jsp?thread=208549
> 
>>> It seems to me that tuple are essentially immutable lists.
>> They are not (even if you can use them that way too). FWIW and IIRC,
>> this is a FAQ.
> 
> A few posters here have stated that tuples are not just immutable but
> when I compare lists, to tuples, I notice that both are ordered
> collections of arbitrary objects, with the primary difference being
> that list are mutable, and tuples are not. It seems to me that if a
> list were immutable, it would be a tuple. That is the one big
> difference.
> 
> Tuples have been compared to records/structures in other languages.
> But, in general, I can not use a for loop to loop through the fields
> in a record, and I can not sort those fields either.
> 
> 
Think of a tuple as an ordered collection. A given element's ordinal 
position indicates its semantics (meaning, significance), and generally 
it won't make sense to iterate over the elements of a tuple (though 
naturally that doesn't stop people, and neither does the interpreter).

Lists are intended for numbered "sets of things", and when all the 
"things" are of the same or closely-related types it's natural to 
iterate over them.

Those who don't "see the need" for tuples need not use them, and their 
programs probably won't be much worse as a result.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: 16bit hash

2007-06-27 Thread Nick Craig-Wood
Robin Becker <[EMAIL PROTECTED]> wrote:
>  Is the any way to get an efficient 16bit hash in python?

Here is a 32 bit crc of which you could use the bottom 16 bits as a 16
bit hash...

  >>> import binascii
  >>> binascii.crc32("hello world")
  222957957
  >>> crc = binascii.crc32("hello")
  >>> crc = binascii.crc32(" world", crc)
  >>> crc
  222957957
  >>> 

And in case you are wondering how fast it is...

  $ python -m timeit -s 's="."*1024*1024; from binascii import crc32' 'crc32(s)'
  100 loops, best of 3: 4.25 msec per loop

Which is 235 MB/s

Ignore the bit in the binascii docs which says "Since the algorithm is
designed for use as a checksum algorithm, it is not suitable for use
as a general hash algorithm".  Actually CRCs make pretty good hash
algorithms if you want something for making a hash table.  They make
very bad cryptographic hash generators since they are linear and thus
easily forgeable.  That said you aren't going to be doing any serious
crypto with only 16 bits.

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread Joel J. Adamson
Twisted <[EMAIL PROTECTED]> writes:

> On Jun 27, 8:26 am, [EMAIL PROTECTED] (Timofei Shatrov) wrote:
>> >For which you need an interpreter. Such as Ghostscript. Which is a
>> >pain to install and a bigger one to configure, even on Windoze.
>>
>> Lie. Ghostscript works out of the box on Windows.
>
> You're joking. First of all I am not a liar, and secondly, Ghostscript
> and Ghostview are tricky to set up correctly. I know -- I've done it a
> time or three. There's an arcane GUI configurator that isn't
> exceptionally well designed, and once it's working it still wonks out
> on maybe 1 in 10 .ps and .eps files you come across ...

It's become clear that you have a different conception of what
consitutes "working" software.

> better than being able to view none of them, mind you. Nonetheless
> there's a world of difference between the GS tools and say Adobe
> Acrobat Reader in terms of setup and use; the latter you just run an
> installer and then find a pdf to double-click; no other steps
> necessary and it works every time. Of course, Adobe stuff is
> proprietary, and acrord supports some types of evil DRM...

It's also become clear that you have a different conception of what
constitutes using a computer.

Joel

-- 
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA  02114
(617) 643-1432
(303) 880-3109

*Joel's guide to sending attachments:
1.  put all the files you want to send in a folder and archive the
folder using tar, then compress it with gzip or bzip2
2.  please send me .pdf, .html, or text in place of Word documents:
http://www.gnu.org/philosophy/sylvester-response.html

*Did you know there's a FREE alternative to using word processors?
http://www.edafe.org/latex/
http://en.wikipedia.org/wiki/LaTeX
http://nitens.org/taraborelli/latex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Collections of non-arbitrary objects ?

2007-06-27 Thread Paul Rubin
Steve Holden <[EMAIL PROTECTED]> writes:
> Think of a tuple as an ordered collection. A given element's ordinal
> position indicates its semantics (meaning, significance), and
> generally it won't make sense to iterate over the elements of a tuple
> (though naturally that doesn't stop people, and neither does the
> interpreter).

  def f(*a): ... 

is a fundamental language feature and really only makes sense in 
the context of iterating over tuples.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-27 Thread Douglas Alan
"Chris Mellon" <[EMAIL PROTECTED]> writes:

> Is this where I get to call Lispers Blub programmers, because they
> can't see the clear benefit to a generic iteration interface?

I think you overstate your case.  Lispers understand iteration
interfaces perfectly well, but tend to prefer mapping fuctions to
iteration because mapping functions are both easier to code (they are
basically equivalent to coding generators) and efficient (like
non-generator-implemented iterators).  The downside is that they are
not quite as flexible as iterators (which can be hard to code) and
generators, which are slow.

Lispers have long since understood how to write mapping function to
iterator converters using stack groups or continuations, but Common
Lisp never mandated stack groups or continuations for conforming
implementations.  Scheme, of course, has continuations, and there are
implementations of Common Lisp with stack groups.

>> The difference is that lisp users can easily define python-like for
>> while python folks have to wait for the implementation.

> Yes, but Python already has it (so the wait time is 0), and the Lisp
> user doesn't.

So do Lispers, provided that they use an implementation of Lisp that
has the aforementioned extensions to the standard.  If they don't,
they are the unfortunately prisoners of the standardizing committees.

And, I guarantee you, that if Python were specified by a standardizing
committee, it would suffer this very same fate.

Regarding there being way too many good but incompatible
implementations of Lisp -- I understand.  The very same thing has
caused Ruby to incredibly rapidly close the lead that Python has
traditionally had over Ruby.  There reason for this is that there are
too many good but incompatible Python web dev frameworks, and only one
good one for Ruby.  So, we see that while Lisp suffers from too much
of a good thing, so does Python, and that may be the death of it if
Ruby on Rails keeps barreling down on Python like a runaway train.

|>oug
-- 
http://mail.python.org/mailman/listinfo/python-list


Tabbed windows Support in Python

2007-06-27 Thread senthil arasu

Hi,
Currently iam implementing GUI Framework for supporting Tabbed windows to
render  different HTML Pages.
A row of tabs  facilitated for navigation of pages.

Iam expecting some classes like "QTabWidget" whick provided by Qt Libarary.
After starting my implementation i came to know Tkinter not supports tabbed
windows

is there anybody to help me  how to proceed further.


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

Re: Set builtin lookups

2007-06-27 Thread Steve Holden
Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, Evan Klitzke
> wrote:
> 
>> I have a question about the internal representation of sets in Python.
>> If I write some code like
>>
>> if x in some_list:
>> do_something()
>>
>> the lookup for the in statement is O(n), where n is the number of
>> elements in the list. Is this also true if I am using a set or are
>> sets represented by a hash table?
> 
> Sets are implemented as hash tables.
> 
> Ciao,
>   Marc 'BlackJack' Rintsch

More importantly, no, neither sets nor dictionaries have O(N) lookup 
costs. As an experiment or two can show.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Reversing a string

2007-06-27 Thread Terry Reedy

"Scott" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Yeah I know strings == immutable, but question 1 in section 7.14 of "How 
to
| think like a computer Scientist" has me trying to reverse one.

>>> 'this is a test'[::-1]
'tset a si siht' 



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


Re: Tabbed windows Support in Python

2007-06-27 Thread Bill Scherer
senthil arasu wrote:
> Hi,
> Currently iam implementing GUI Framework for supporting Tabbed
> windows to render  different HTML Pages.
> A row of tabs  facilitated for navigation of pages.
>  
> Iam expecting some classes like "QTabWidget" whick provided by Qt
> Libarary.
> After starting my implementation i came to know Tkinter not supports
> tabbed windows
>  
> is there anybody to help me  how to proceed further.

Python Mega Widgets, http://pmw.sourceforge.net , provides a tabbed
interface, specifically:

http://pmw.sourceforge.net/doc/NoteBook.html
>  
>  
> thanks in advance

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

Re: 16bit hash

2007-06-27 Thread Thomas Heller
Robin Becker schrieb:
> Josiah Carlson wrote:
>> Robin Becker wrote:
>>> Is the any way to get an efficient 16bit hash in python?
>> 
>> hash(obj)&65535
>> 
>>   - Josiah
> yes I thought of that, but cannot figure out if the internal hash really 
> distributes the bits evenly. Particularly since it seems to treat integers 
> etc 
> as special cases
> 
>  >>> hash(1)
> 1
>  >>> hash(2)
> 2
>  >>> hash('1234')
> 1723328704
>  >>>

I'm not sure if it helps in your case, but this is pretty nifty:

http://www.amk.ca/python/code/perfect-hash

Thomas

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


Re: Tabbed windows Support in Python

2007-06-27 Thread Peter Decker
On 6/27/07, senthil arasu <[EMAIL PROTECTED]> wrote:
> Hi,
> Currently iam implementing GUI Framework for supporting Tabbed windows to
> render  different HTML Pages.
> A row of tabs  facilitated for navigation of pages.
>
> Iam expecting some classes like "QTabWidget" whick provided by Qt Libarary.
> After starting my implementation i came to know Tkinter not supports tabbed
> windows
>
> is there anybody to help me  how to proceed further.

Do yourself a favor and start off right: use the Dabo framework for
your UI. You can get information about it at http://dabodev.com. You
can use their Class Designer to create your tabbed windows visually
instead of having to write code.

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reversing a string

2007-06-27 Thread Neil Cerutti
On 2007-06-27, Scott <[EMAIL PROTECTED]> wrote:
> Yeah I know strings == immutable, but question 1 in section
> 7.14 of "How to think like a computer Scientist" has me trying
> to reverse one.

No, it just wants to to print the characters in reverse, one per
line.

> I've come up with two things, one works almost like it should
> except that every traversal thru the string I've gotten it to
> repeat the "list" again. This is what it looks like:
>
mylist = []

That's bad. If you need to use a list in the rev function, you
should bind a new list to a local variable inside rev.

def rev(x):
> for char in x:
> mylist.append(char)
> mylist.reverse()
> print mylist

Here's an debugging exercise that you should try.

Please explain what you think each line in the above is supposed
to do. Pretend you are trying to convince me that the above
program works correctly. I bet you will see find your errors
right away as a result of this exercise.

> [/code]

> So I figured maybe make it a generator (I'm not TO familiar
> with generators yet so don't laugh) which changed my code just
> a slight bit:

Experimentation with stuff you don't fully understand is a great
way to learn, but not that useful for solving exercises. ;)

-- 
Neil Cerutti
This team is one execution away from being a very good basketball team. --Doc
Rivers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread [EMAIL PROTECTED]
In article <[EMAIL PROTECTED]>,
Twisted  <[EMAIL PROTECTED]> wrote:
> On Jun 25, 5:32 pm, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > To me it's similar to "memorizing" a phone number by dialing
> > it enough times that it makes its way into memory without
> > conscious effort.  I suspect that not everyone's brain works
> > this way, and some people have to look it up every time.
> > For those people, I can understand why something without a
> > GUI could be a painful experience.  "YMMV", maybe.
> 
> You'll be happy to know then that my opinion is that the phone system
> is archaic too. 

Happy?  Not especially.  Amused?  Yes.  One more, um, "eccentric"?
opinion, from someone with many of them.

[ snip ]

-- 
B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting importError: No module named _md5

2007-06-27 Thread jeffself
On Jun 27, 11:54 am, [EMAIL PROTECTED] wrote:
> On Jun 27, 7:04 am, jeffself <[EMAIL PROTECTED]> wrote:
>
> > I'm running Python 2.5.1 which I'm getting from the MacPort package
> > system.  I just installed Django and tried to start up the Django
> > server and I got the following error:
>
> > ImportError: No module named _md5
>
> > I'm pretty sure this is a python problem, not Django problem. I'm
> > looking in the python2.5 directory and I see md5.py, md5.pyc and
> > md5.pyo files.
>
> > Any suggestions?
>
> Try to load the md5 module from the interactive prompt.  Are you using
> the python version you expect?  Try starting up your previous version
> of python and see if you get the same error.  Delete the MacPort
> install and install from source.
>
> My 2 cents.
>
> ~Sean

I reinstalled Python from source and it worked.  Thanks!

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread [EMAIL PROTECTED]
In article <[EMAIL PROTECTED]>,
Twisted  <[EMAIL PROTECTED]> wrote:

[ snip ]

> I'm wondering if getting your head around unix arcana is also
> dependent on an iffy "knack" where you "get it" and somehow know where
> to look for documentation and problem fixes, despite everything having
> its own idiosyncratic way, and "get" some sort of workflow trick
> going, or you don't. 

Well   For me I think the crucial thing was having Unix experts
on tap when I was learning -- someone to answer my questions
patiently, and also to show me things I might not have found on
my own.  Some combination of Usenet groups and books might have
served the same purpose.

I find Windows and its tools as frustrating as you seem to find
Unix, but I strongly suspect that being shown the ropes by someone
who understands and likes the system would help a lot.  

> Personally, the thing I always found most
> irritating was the necessary frequent trips to the help. Even when the
> help was easy to use (itself rare) that's a load of additional task
> switching and crap. Of course, lots of the time the help was not easy
> to use. Man pages and anything else viewed on a console, for example
> -- generally you could not view it side by side with your work, but
> instead interrupt the work, view it, try to memorize the one next
> step, go back to your work, perform that next step, back to the help
> to memorize another step ... that has all the workflow of a backed-up
> sewer, yet until and unless the commands become second nature it's
> what you're typically forced to do without a proper GUI. 

[ I'm trying to imagine circumstances in which I would say "proper
GUI" and  not succeeding.  "Proper command line", now that
I say sometimes   :-)? ]

About not being able to view help side by side with one's work,
though    You probably haven't heard the joke about how a
window manager is a mechanism for having multiple xterms (terminal
windows) on the screen at the same time, and a mouse is a device
for selecting which one should have the focus?  Well, I like it.

[ snip ]

> Maybe the thing I really, REALLY deplore is simply having 99% of my
> attention forced to deal with the mechanics of the job and the
> mechanics of the help viewer and only 1% with the actual content of
> the job, instead of the other way around.

Exactly my experience of trying to use MS Office tools to do quick
edits under time pressure.  

-- 
B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.
-- 
http://mail.python.org/mailman/listinfo/python-list


Capturing stdout from a class method

2007-06-27 Thread Falcolas
I have a rather strange situation, and I'm not sure my brief
experience of Python will let me handle it properly.

The situation is this: I have a Java class "X" which I need to call in
a Jython script. The  output of "X" is sent to stdout using the java
call System.out. I need to capture this output, and preform tests on
it in the Jython script.

My first pass at a design involves two jython scripts. One (we'll call
it "Y") whose sole function is to instantiate and call "X", and die.
The second script will call "Y" using a method which captures stdout
to a pipe. The second script would then read the stdout from the pipe
and act accordingly.

Can anybody suggest a better way to handle this? The Java class, "X",
can not be modified for this test.

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


ANN: PyDAO - Python Hibernate-like Object-Relational Mapper

2007-06-27 Thread cieslak . dariusz
PyDAO is very thin object-relational mapper similar to Hibernate (but
much simpler). It's created to speed-up application development. It's
very simple, but powerful, based on POPO (Plain Old Python Objects).

  http://aplikacja.info/PyDAO.html

Main features:

 - can use any database that has DB-API interface (MySQLdb, psycopg
   tested)
 - can work without database at all (useful for early phases of
   development)
 - speeds up unit testing (dedicated in memory database)

What is not handled:

 - automatic scheme generation
 - separate query language
 - automated handling of associations (replaced by filtering by
   foreign keys)

Here's an example how to use PyDAO:

class User:
def __init__(self):
self.id = None
self.login = None
self.password = None

dao = pydao.InMemoryDao()

# filling database
user = User()
user.login = "user1"
user.password = "roh8OoPh"
dao.save(user)

# filtering based on example
userSearch = User()
userSearch.login = "user1"
userList = dao.list(userSearch)

# updating
user.password = "eew8Me8g"
dao.update(user)

Enjoy!

--
Dariusz Cieslak
http://aplikacja.info - custom software systems

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


Re: Zip File Woes

2007-06-27 Thread Jerry Hill
On 6/27/07, Robert Rawlins - Think Blue
<[EMAIL PROTECTED]> wrote:
>   zip = zipfile.ZipFile('Media/Media.zip', 'r')

Shouldn't you open this file in binary mode?  It shouldn't make any
difference on unix machines, but will possibly break under windows.
That may also explain why it works properly in one environment, and
not in another.

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-27 Thread [EMAIL PROTECTED]
In article <[EMAIL PROTECTED]>,
Gian Uberto Lauri  <[EMAIL PROTECTED]> wrote:
> > "n" == nebulous99  <[EMAIL PROTECTED]> writes:
> 
> n> On Jun 22, 6:32 pm, Cor Gest <[EMAIL PROTECTED]> wrote:
> >> > HOW IN THE BLOODY HELL IS IT SUPPOSED TO OCCUR TO SOMEONE TO
> >> ENTER > THEM, GIVEN THAT THEY HAVE TO DO SO TO REACH THE HELP THAT
> >> WOULD TELL > THEM THOSE ARE THE KEYS TO REACH THE HELP?!
> >> 
> >> What's your problem ?
> >> 
> >> Ofcourse a mere program-consumer would not look what was being
> >> installed on his/her system in the first place ...  So after some
> >> trivial perusing what was installed and where : WOW Look, MA !
> >>  it's all there!
> >> 
> >> lpr /usr/local/share/emacs/21.3/etc/refcard.ps or your
> >> install-dir^ ^ or your
> >> version.^
> 
> n> So now we're expected to go on a filesystem fishing expedition
> n> instead of just hit F1? One small step (backwards) for a man; one
> n> giant leap (backwards) for mankind. :P
> 
> Waring, possible ID TEN T detected!
> 
> There's a program called find, not this intuitive but worth learning
> 
> It could solve the problem from the root with something like
> 
> find / -name refcard.ps -exec lpr {} \; 2> /dev/null

Let's not make this any worse than it has to be   

If I wanted to find files that might have documentation on emacs,
I wouldn't look for filename refcard.ps; I'd try either

locate emacs

(Linux only AFAIK, won't find recently-added files because it
searches against a database usually rebuilt once a day)

or

find / -name "*emacs*" 


You are so right that "find" is worth learning, but I'm not sure
it's a tool I'd have mentioned in this particular discussion,
because it *does* take a bit of learning.  I wasn't surprised at
all that you got the reply you did.  :-)?

And as you mention downthread, any time you use "find" to execute
a command that might be costly (in terms of paper and ink in this
case), it's smart to first do a dry run to be sure the files it's
going to operate on are the ones you meant.

Whether "find" is better or worse than the GUI-based thing Windows
provides for searching for files   I guess this is really
not the time or place to rant about the puppy, is it?  (Yes,
I know you can make the animated character go away, something I
discovered just in time to avoid -- well, I'm not sure, but it
wouldn't have been good.)


[ snip ]

-- 
B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Capturing and sending keys {Esperanto}

2007-06-27 Thread Thomas Jollans
AJK wrote:
> Hello there!
> 
> I've been googleing yet, and suppose it's hopeless to try, but better
> ask it...
> 
> I want to write a program which turns Cx to Ĉ, cx to ĉ et al WHILE
> TYPING. (i.e. converting Esperanto x-system to real hats, for those
> who know about this.) Therefore I though will need to capture the last
> 2 typed characters (from any application), send a double backspace and
> after that send the correct letters (back to the same application)...
> 
> However, it seems inpossible to capture those letters, and maybe to
> send them too...

I'm not quite sure what you want to do. Is this in a Tkinter application
or somthing like that ? Do you want this to be hooked into some layer of
some operating system to work universally ? Which operating system ?

Thomas Jollans



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

Re: Capturing stdout from a class method

2007-06-27 Thread Thomas Jollans
Falcolas wrote:
> I have a rather strange situation, and I'm not sure my brief
> experience of Python will let me handle it properly.
> 
> The situation is this: I have a Java class "X" which I need to call in
> a Jython script. The  output of "X" is sent to stdout using the java
> call System.out. I need to capture this output, and preform tests on
> it in the Jython script.
> 
> My first pass at a design involves two jython scripts. One (we'll call
> it "Y") whose sole function is to instantiate and call "X", and die.
> The second script will call "Y" using a method which captures stdout
> to a pipe. The second script would then read the stdout from the pipe
> and act accordingly.
> 
> Can anybody suggest a better way to handle this? The Java class, "X",
> can not be modified for this test.

How about subprocess.Popen ? I'm thinking of something like this:

import subprocess

X_proc = subprocess.Popen(['java', 'Xstarter'])
for line in Xproc.stdout:
   # do funky stuff
   pass





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

Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-27 Thread John Roth
On Jun 27, 5:02 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> HI
> I'm currently using Python. I find that a instance variable must
> confined with self,
> for example:
> class a:
> def __init__(self):
> self.aa=10
> def bb(self):
> print self.aa # See .if in c++,I could use aa to change that
> variable
>
> That's a big inconvenience in coding ,especially when you have lot of
> variable
> If you method need 10 variables ,you have to type "self" for 10 times
> and that also makes your variable longer.
>
> >From My point,I think this only help python interpreter to deside
>
> where to look for.
> Is there anyone know's how to make the interpreter find instance name
> space first?
> Or any way to make programmer's life easier?


Guido has already said that this will not change in Python 3.0 See PEP
3099.

John Roth

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


Re: Return name of caller function?

2007-06-27 Thread Matthew Peter

--- Stephen R Laniel <[EMAIL PROTECTED]> wrote:

> On Mon, Jun 25, 2007 at 06:27:29PM -0700, Matthew Peter wrote:
> > For example, how do I get this to work?
> > 
> > def func():
> > print "This is", __?__
> > return __caller__
> > 
> > def echo():
> > print "This is ", __?__
> > return func()
> 
> inspect is your friend:
> http://docs.python.org/lib/inspect-stack.html
> 
> -- 
> Stephen R. Laniel
> [EMAIL PROTECTED]
> Cell: +(617) 308-5571
> http://laniels.org/
> PGP key: http://laniels.org/slaniel.key
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 


--- Stephen R Laniel <[EMAIL PROTECTED]> wrote:

> On Mon, Jun 25, 2007 at 06:27:29PM -0700, Matthew Peter wrote:
> > For example, how do I get this to work?
> > 
> > def func():
> > print "This is", __?__
> > return __caller__
> > 
> > def echo():
> > print "This is ", __?__
> > return func()
> 
> inspect is your friend:
> http://docs.python.org/lib/inspect-stack.html
> 
> -- 
> Stephen R. Laniel
> [EMAIL PROTECTED]
> Cell: +(617) 308-5571
> http://laniels.org/
> PGP key: http://laniels.org/slaniel.key
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 


Parsing the stack's tuple to get those attributes didn't feel reliable or 
pythonic.
I am likely overlooking something. Is there a brief example you could show me 
in the
context of using inspect to accomplish the goal I outlined above? The goal is 
using
a function and not a class. Thanks!


   

Yahoo! oneSearch: Finally, mobile search 
that gives answers, not web links. 
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Return name of caller function?

2007-06-27 Thread Stephen R Laniel
On Wed, Jun 27, 2007 at 01:25:14PM -0700, Matthew Peter wrote:
> Parsing the stack's tuple to get those attributes didn't feel reliable or 
> pythonic.
> I am likely overlooking something. Is there a brief example you could show me 
> in the
> context of using inspect to accomplish the goal I outlined above? The goal is 
> using
> a function and not a class. Thanks!

The code below doesn't do the trick for you?

#!/usr/bin/python
import inspect

def master():
print "I am the master"
slave()

def slave():
stack = inspect.stack()
caller = stack[1][3]
print "I am the slave; my caller was %s" % caller

def main():
master()

if __name__ == '__main__':
main()

-- 
Stephen R. Laniel
[EMAIL PROTECTED]
Cell: +(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Collections of non-arbitrary objects ?

2007-06-27 Thread Bruno Desthuilliers
walterbyrd a écrit :
> On Jun 26, 8:23 am, Bruno Desthuilliers  [EMAIL PROTECTED]> wrote:
> 
>>walterbyrda écrit :
>>
>>
You do program carefully, don't you ?-)
>>
>>>I try. But things like typos are a normal part a life.
>>
>>So are they in any language. I fail to see much difference here.
>>
> 
> 
> For example: if I mis-type a variable name in C, the program will
> probably not even compile.

It sometimes happens - but chances are low, for sure.

> Whereas, with Python, the program will
> probably run, but may give unexpected results.
> 
Yes, true. Well, in some cases. In one case, to be true: the use of the 
'=' operator. IIRC, any other use of an undefined symbol will raise an 
exception. But this has to do with how symbols are defined in Python 
(ie: the fact that binding => definition), and has nothing to do with 
static (compile-time) type checking.

> 
>>>Guido
>>>must think python has a lot of room for improvement since he's
>>>completely throwing out backward compatibility with python 3000.
>>
>>Not "completely throwing out". Just allowing *some* major breakages -
>>the kind you usually get with each major release of other languages, but
>>that Python managed to avoid as much as possible so far.
> 
> 
> I don't know, but here is a direct quote from Guido's blog: "Python
> 3.0 will break backwards compatibility. Totally."
> 
> http://www.artima.com/weblogs/viewpost.jsp?thread=208549

Please take it with a grain of the salt. This is mostly about getting 
rid of long-time deprecated features.

> 
>>>It seems to me that tuple are essentially immutable lists.
>>
>>They are not (even if you can use them that way too). FWIW and IIRC,
>>this is a FAQ.
> 
> A few posters here have stated that tuples are not just immutable but
> when I compare lists, to tuples, I notice that both are ordered
> collections of arbitrary objects, with the primary difference being
> that list are mutable, and tuples are not.

This is of course technically true. And you forgot to compare to sets, 
while we're at it. But the answer to your questions about tuples is not 
technical - it's about use case.

> It seems to me that if a
> list were immutable, it would be a tuple. That is the one big
> difference.
 >
> Tuples have been compared to records/structures in other languages.
> But, in general, I can not use a for loop to loop through the fields
> in a record, 

For which definition of "in general" ? I can do this with at least 
Python, PHP, Javascript, Ruby, and probably Java (IIRC).

> and I can not sort those fields either.

Did you try to sort a tuple ?

 >>> (1, "aaa").sort()
Traceback (most recent call last):
   File "", line 1, in ?
AttributeError: 'tuple' object has no attribute 'sort'




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


  1   2   >