Re: nntplib: abstraction of threads

2005-01-17 Thread Rakesh

Steve Holden wrote:
> Werner Amann wrote:
>
> > Rakesh schrieb:
> >
> >
> >>What I want is to *group the messages belonging to each thread* .
> >
> >
> > Hello
> >
> > Why not sort with Message-ID and References?
> > Attention - it is a Newbie-Solution.
> >
> > import nntplib
> >
> > hamster = nntplib.NNTP('127.0.0.1', 119, 'user', 'pass')
> > resp, count, first, last, name = hamster.group('comp.lang.python')
> > resp, items = hamster.xover(first,last)
> >
> > start_dic = {}
> > re_dic = {}
> > numb = 1
> >
> > for id,subject,author,date,message_id,references,size,lines in
items:
> > if 'Re:' not in subject:
> > start_dic[subject] = (author, message_id)
> > else:
> > re_dic[numb] = (subject, author, references)
> > numb += 1
> >
> > resp = hamster.quit()
> >
> > for a in start_dic:
> > print a
> > print start_dic[a][0]
> > for b in re_dic:
> > if start_dic[a][1] in re_dic[b][2]:
> > print '|'
> > print ' ->', re_dic[b][0]
> > print '   ', re_dic[b][1]
> > print
> >
> Better still, do a Google search on "mail threading algorithm",
> implement the algorithm described in
>
>http://www.jwz.org/doc/threading.html

Thanks a lot for the link.

>
> and post your implementation back to the newsgroup :-)

Sure I would. I would definitely do the same.
I am a python newbie and am reading nntp spec (rfc) right now.
Once I get a working version I would definitely post the same.

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


how to print unicode structures?

2005-01-17 Thread Timothy Babytch
Imagine you have some list that looks like
('unicode', 'not-acii', 'russian') and contains characters not from 
acsii. or list of dicts, or dict of dicts.

how can I print it? not on by one, with "for" - but with just a simple 
print? My debugging would be MUCH simpler.

Now when I try print or pprint that variable I get a page full of
'\xe4\xeb\xa2\xa0\xe6\xe3\xaa\xe6\xe3\xaa' and so on.
I use Python 2.4, Fedora Linux, UTF-8 locale
--
http://mail.python.org/mailman/listinfo/python-list


Re: why are some types immutable?

2005-01-17 Thread Fredrik Lundh
Roy Smith wrote:

> But, in a nutshell, the biggest reason for immutable types (tuples and
> strings) is that this lets they be dictionary keys.

if you think that's the biggest reason, you haven't spent enough time working
on high-performance Python code and extensions (there's a reason why some
languages adopt a "you can only assign to a variable once" approach).

 



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


Re: (objects as) mutable dictionary keys

2005-01-17 Thread Antoon Pardon
Op 2005-01-14, Steve Holden schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>
>> Op 2005-01-14, Peter Maas schreef <[EMAIL PROTECTED]>:
>> 
>>>I have summarized the discussion about the usability of lists (and
>>>and other mutable types) as dictionary keys and put it into the
>>>Python wiki.URL: http://www.python.org/moin/DictionaryKeys.
>>>
>>>This summary might be used as a reference should the 'mutable
>>>dictionary keys' issue come up again in c.l.py.
>>>
>> 
>> I had a look and I think you should correct the followingr:
>> 
>>   Dictionary lookup with mutable types like lists is a source of
>>   unpleasant surprises for the programmer and therefore impossible in
>>   Python.
>> 
> Better, perhaps, to say:
>
>Dictionary lookup with mutable types like lists can be a
>source of unpleasant surprises for the programmer and
>therefore not recommended in Python.

IOW Python discourages mutable types in any type of container.

>> It is not impossible in Python. It may be discouraged but it is not
>> impossible since I have already done so.
>> 
> If I discouraged you from shooting yourself in the foot would you do 
> that too?

If I chose not to shoot my self in the foot, it wouldn't be because
you discouraged me. It would be because I heard good arguments.

What are good arguments or bad and how much weight they have depends
on the person and on the circumstances. So a simple rule like:
Never use a mutable as a key in a dictionary will sometimes not be
the best solution.

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


Re: from __future__ import decorators

2005-01-17 Thread Jacek Generowicz
Tim Roberts <[EMAIL PROTECTED]> writes:

> Jacek Generowicz <[EMAIL PROTECTED]> wrote:
> >
> >I have some code, which makes copious use of the @decorator syntax
> 
> I'm very curious to know what kind of application you are writing in which
> "copious use of the @decorator syntax" actually solved a problem
> productively.

An application in which, before python2.4, I used to have lots of code
that looked like

def somefun(...):
...
somefun = somedecorator(somefun)

:-)


It's not interesting to discuss what "somedecorator" actually
represents. But being able to see that the function is decorated right
next to the "def", as opposed to having to look beyond the end of the
definition certianly makes a significant difference to me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to print unicode structures?

2005-01-17 Thread Serge Orlov
Timothy Babytch wrote:
> Imagine you have some list that looks like
> ('unicode', 'not-acii', 'russian') and contains characters not from
> acsii. or list of dicts, or dict of dicts.
>
> how can I print it? not on by one, with "for" - but with just a simple
> print? My debugging would be MUCH simpler.

I think the best (in terms of time) way to do it is to copy pprint.py
to upprint.py and hack it.

>
> Now when I try print or pprint that variable I get a page full of
> '\xe4\xeb\xa2\xa0\xe6\xe3\xaa\xe6\xe3\xaa' and so on.

It looks like bytes, you should get rid of them as soon as possible. If you're 
not looking for speed hacks, as a rule of thumb you 
should convert bytes to unicode characters as soon as possible. When I try to 
print Russian characters I get unicode escapes (\u) 
not byte escapes (\x) like you:
>>> print unicode([u'ÁÂ×'])
[u'\u0430\u0431\u0432']

   Serge.


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


Re: what would you like to see in a 2nd edition Nutshell?

2005-01-17 Thread Steven Chan
I completely agree. I'm also waiting for an advanced Python/project
management book that helps folks out with large-scale projects.

And, for the 2nd edition, may I suggest:
- coverage of OptionParser module, which is more advanced than the
getopt module that you discuss on page 141.
- better Mac OS X application building coverage. Tell us how to build
double-clickable applications.

I wish I could ask for wxPython coverage (the whole chapter on tkinter
is useless to me), but I won't start a flame war here.

:: steve ::

Mariano Draghi wrote:
> Alex Martelli escribió:
> >
> > Yes, good point... I _do_ plan another book after I'm done with the
2nd
> > ed Nutshell, though ti will mostly be about Design Patterns and
> > development methods so may not meet your exact desires...
>
> Now I'm anxious! *that* is the book I'm waiting for :)
> I think the Python community really needs such a book; you have
plenty
> of books and articles and papers and resources on-line with (almost)
all
> the bits & pieces. But I really miss a book that focuses in the
> "Pythonic way" of project management, design patterns, development
> cycles, QA... something targeted to the enterprise.

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


Re: how to print unicode structures?

2005-01-17 Thread Serge Orlov
Serge Orlov wrote:
 print unicode([u'ÁÂ×'])
> [u'\u0430\u0431\u0432']
>
Oops, Outlook Express has screwed the encoding, one more evidence that printing 
unicode is hard :)
I hope this time, the message will be with real Russian characters instead of 
Latin ones.

  Serge. 


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


Einrichtung von de.comp.lang.python - Deine Stimme zählt!

2005-01-17 Thread Christian Helmbold
Hallo,
wenn du möchtest, dass die Gruppe news:de.comp.lang.python eingerichtet 
wird, bitte ich dich, deine Stimme dafür abzugeben. Du brauchst dazu nur 
 unten stehenden Wahlschein auszufüllen und an [EMAIL PROTECTED] zu 
schicken.

Weitere Einzelheiten zum Verfahren finden sich in 
news:de.admin.news.anncounce
<[EMAIL PROTECTED]>
sowie in news:de.admin.news.groups

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
 1. CfV (Aufruf zur Abstimmung)
   zur Einrichtung der Gruppe
de.comp.lang.pythonProgrammieren mit Python.
Charta
- --
In dieser Gruppe geht es um die Programmiersprache Python und alles,
was damit unmittelbar zusammenhängt (Installation, alternative
Implementierungen, externe Module etc.).
Status
- --
unmoderiert
Begründung
- --
In der Diskussion, die mit der Nachricht
<[EMAIL PROTECTED]> begann, wurde überwiegend Zustimmung
zu der Einrichtung geäußert.
Proponent
- -
Christian Helmbold <[EMAIL PROTECTED]>
Abstimmungsmodalitäten
- --
Wahlleiter:  Thomas Hochstein <[EMAIL PROTECTED]>
Abstimmadresse:  [EMAIL PROTECTED]
Abstimmungsende: Mit Ablauf des 13. Februar 2005 (MEZ)
Wahlschein:  Untenstehendes Formular ist zu verwenden. Möglich sind
 bei jedem Abstimmungspunkt JA, NEIN und ENTHALTUNG.
 Besonderer Hinweis
 --
 Die am 23.12.2004 begonnene Abstimmung über die Einrichtung
 der Gruppe de.comp.lang.python wurde am Abend desselben
 Tages vom Wahlleiter abgebrochen. Die damals abgegebenen
 Stimmen wurden verworfen und nicht gewertet.
 Mit diesem 1. CfV beginnt ein neues Abstimmungsverfahren;
 wer an der Abstimmung teilnehmen möchte, muß also jetzt
 (erneut) abstimmen, auch wenn er schon in dem ersten,
 abgebrochenen Verfahren eine Stimme abgegeben hat.
Es gelten die "Einrichtung von Usenet-Gruppen in de.*" in der bei
Beginn der Abstimmung gültigen Fassung, die in de.admin.infos und
unter  auch im WWW
veröffentlicht sind. Sie erläutern das Wahlverfahren detailliert und
sollten vor der ersten Teilnahme an einer Abstimmung gelesen werden.
Gezählt werden nur per E-Mail bei der Abstimmadresse eingegangene
Stimmen. Diese werden einzeln per E-Mail bestätigt. Das Ergebnis wird
nach dem Ende der Wahl veröffentlicht. Namen, E-Mail-Adresse und
Inhalt der Stimmabgabe aller Abstimmenden werden im Ergebnis genannt.
Mit Rücksicht auf das deutsche Datenschutzrecht ist daher die
gesonderte Zustimmung zur Speicherung und Veröffentlichung der
abgegebenen Stimme entsprechend Hinweis im Wahlschein nötig.
Auf die weiteren Hinweise auf  sei
verwiesen.
=-=-=-=-=-=-=-=- Alles vor dieser Zeile bitte loeschen =-=-=-=-=-=-=-=-
WAHLSCHEIN fuer Einrichtung der Gruppe de.comp.lang.python
Dein Realname, falls nicht im FROM-Header:
Wenn du keinen Real-Namen angibst, wird deine Stimme fuer
ungueltig erklaert werden.
Nr   [Deine Stimme]  Gruppe/Abstimmungsgegenstand

#1   []  Einrichtung von de.comp.lang.python
Zur Verarbeitung des Wahlscheines und inbesondere der Veroeffentlichung
des Ergebnisses ist deine Zustimmung zur Speicherung, Auswertung und
Veroeffentlichung deiner Stimmdaten (Name und E-Mail-Adresse in
Verbindung mit dem Stimmverhalten) im Rahmen dieses Verfahrens
erforderlich. Wenn du im Feld unterhalb dieses Absatzes "JA"
eintraegst, erklaerst du dich damit einverstanden. In allen anderen
Faellen wird der Wahlschein mit Ruecksicht auf das deutsche
Bundesdatenschutzgesetz verworfen und nicht gewertet.
#a   []  Datenschutzklausel - Zustimmung: Ich bin mit der
 Verarbeitung meiner Daten wie oben beschrieben
 einverstanden
=-=-=-=-=-=-=-=- Alles nach dieser Zeile bitte loeschen =-=-=-=-=-=-=-=-
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (GNU/Linux)
iQCVAwUBQerEb2FKEBFIVyalAQLUvAQAi/S0OSvwYnhkvvlCnYmhVLdi8D4XkMv4
oCYHzADyiNpLDNF3w1dszSL2uXeRuSoXOWd07xcTYS6MpQTWzri8BPyBYyW4Zywz
u46rkfDFTpwr5oLHP2Ss3OJr6rqY7zWL28o7bAYdemDd9GIg0vPt4AE8HXyhL5ud
CePdwFnaN3s=
=z5dB
-END PGP SIGNATURE-
Danke,
Christian
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to stop google from messing Python code

2005-01-17 Thread Fuzzyman

Fredrik Lundh wrote:
> Fuzzyman wrote:
>
> > I guess that most people use google to post to newsgroups is that
they
> > don't have nntp access. Telling htem to use a newsreader is
facetious
> > and unhelpful.
>
> if you have internet access, you have NNTP access.  gmane.org
provides access
> to more than 6,500 mailing lists via NNTP, including all relevant
Python forums.
>

Not if you're behind a censoring proxy that blocks everything except
http. This is a situation many people find themselves in.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

> 

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


Re: Static executable with shared modules

2005-01-17 Thread Rickard Lind
Martin v. Löwis wrote:
> I'm not what "build statically" means; if you talking about
> building a statically linked interpreter binary - then no,
> this is not possible. At a minimum, you need to link with -ldl,
> or else you cannot perform dlopen(3).
I'll be more specific: when I build python 2.3.4 on FreeBSD 4.9,
the interpreter binary is linked against three shared libraries: 
libutil.so.3, libm.so.2 and libc_r.so.4. Now, these libraries are
not present on the TARGET system (which is distinct from the build
system, but based on the same version of FreeBSD) so I add "-static"
to LDFLAGS. This produces an interpreter that runs on the target
system (no dependency on shared libc etc) but it also cannot load
modules compiled as shared libraries. Man page for dlopen(3) says
it is located in libc (and consquently there seems to be no libdl),
and anyway I'd expect to get a link error if the dl* functions were
not present. What I DO get is an ImportError exception.

At present I see no other option than to link the modules into the
interpreter which is very inconvenient since I'll have to rebuild
the every time a module changes :-(
/r
--
http://mail.python.org/mailman/listinfo/python-list


OCAMl a more natural extension language for python?

2005-01-17 Thread Jelle Feringa // EZCT / Paris
After reading about extending python with C/Fortran in the excellent Python
Scripting for Computational Science book by Hans Langtangen, I'm wondering
whether there's not a more pythonic way of extending python. And frankly I
think there is: OCAML

Fortunately there is already a project up and running allowing you to extend
python with OCAMl: http://pycaml.sourceforge.net/

Since I haven't got actual experience programming CAML I'd like to speculate
that OCAML would be a very pythonic way of extending python: its
open-source, object oriented, as fast as C, and ! garbage collecting!

Would making an effort integrating python & CAML not be very worthwhile?
I think an effort such as Joe Strouts python2c would be more relevant to a
language as CAMl since its conceptually more closer to python (how could you
automate programming memory allocation for instance)

So my question is: wouldn't there be some serious synergy in bringing python
& CAML closer together?

##of course this is speculation, I'm not informed well
##enough to make an educated guess

Interested in hearing your thoughts about this matter!

Cheers, Jelle.



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


Re: [perl-python] 20050116 defining a function

2005-01-17 Thread Fredrik Lundh
Ala Qumsieh wrote:

> > © my $n= @_[0];
>
> Do you ever test your code before making fun of yourself in front of millions?

this perl usability study is getting more and more interesting.  who
needs television?

 



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


Re: lambda

2005-01-17 Thread Antoon Pardon
Op 2005-01-14, Steve Holden schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>
>> Op 2005-01-13, hanz schreef <[EMAIL PROTECTED]>:
>> 
>>>Antoon Pardon wrote:
>>>
So if I have a call with an expression that takes more than
one line, I should assign the expression to a variable and
use the variable in the call?
>>>
>>>Yes, that's sometimes a good practice and can clarify
>>>the call.
>>>
>>>
But wait if I do that, people will tell me how bad that it
is, because it will keep a reference to the value which
will prevent the garbage collector from harvesting this
memory.
>>>
> Of course, unless that reference is in the global scope of the __main__ 
> module its lifetime will be transient anyway. If the reference is stored 
> in a function's local variable then unless its value is returned from 
> the function it will become available for garbage collection when the 
> function returns.
>
>>>Nobody will tell you that it's bad.
>> 
>> 
>> Sorry, someone already did. If I recall correctly it
>> was Alex Martelli.
>> 
> "A foolish consistency is the hobgoblin of little minds". Rules are made 
> to be broken.

Like only use immutables as dictionary keys.

> Besides which, if you don't understand the language 
> environment, rules alone will do you very little good. Try to focus a 
> little more on principles and a little less on minutiae.

And what are the difference between those two?

Sometimes I get the impression that everything is a principle until
one personnaly finds the need to break it. After that it is a rule.

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


Re: (objects as) mutable dictionary keys

2005-01-17 Thread Nick Coghlan
Antoon Pardon wrote:
What are good arguments or bad and how much weight they have depends
on the person and on the circumstances. So a simple rule like:
Never use a mutable as a key in a dictionary will sometimes not be
the best solution.
True - but I think a purely identity based dictionary *is* the solution for most 
such cases where the standard Python rule doesn't apply :)

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Executing a script created by the end user

2005-01-17 Thread Nick Coghlan
Craig Howard wrote:
I am working on a python project where an object will have a script that 
can be edited by the end user: object.script

If the script is a simple one with no functions, I can easily execute it 
using:
exec object.script
Take a look at the execfile builtin.
But if the object script is a bit more complicated, such as the example 
below, my approach does not  work:
Alternatively:
Py> exec """
... def main():
... hello1()
... hello2()
...
... def hello1():
... print 'hello1'
...
... def hello2():
... print 'hello2'
... """
Py> main()
hello1
hello2
'exec' is quite happy to deal with newlines and indenting.
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-17 Thread Martin MOKREJŠ
Hi,
 could someone tell me what all does and what all doesn't copy
references in python. I have found my script after reaching some
state and taking say 600MB, pushes it's internal dictionaries
to hard disk. The for loop consumes another 300MB (as gathered
by vmstat) to push the data to dictionaries, then releases
little bit less than 300MB and the program start to fill-up
again it's internal dictionaries, when "full" will do the
flush again ...
 The point here is, that this code takes a lot of extra memory.
I believe it's the references problem, and I remeber complains
of frineds facing same problem. I'm a newbie, yes, but don't
have this problem with Perl. OK, I want to improve my Pyhton
knowledge ... :-))

   def push_to_disk(self):
   _dict_on_disk_tuple = (None, self._dict_on_disk1, self._dict_on_disk2, 
self._dict_on_disk3, self._dict_on_disk4, self._dict_on_disk5, 
self._dict_on_disk6, self._dict_on_disk7, self._dict_on_disk8, 
self._dict_on_disk9, self._dict_on_disk10, self._dict_on_disk11, 
self._dict_on_disk12, self._dict_on_disk13, self._dict_on_disk14, 
self._dict_on_disk15, self._dict_on_disk16, self._dict_on_disk17, 
self._dict_on_disk18, self._dict_on_disk19, self._dict_on_disk20)
   _size = 0
   #
   # sizes of these tmpdicts range from 10-1 entries for each!
   for _tmpdict in (self._tmpdict1, self._tmpdict2, self._tmpdict3, 
self._tmpdict4, self._tmpdict5, self._tmpdict6, self._tmpdict7, self._tmpdict8, 
self._tmpdict9, self._tmpdict10, self._tmpdict11, self._tmpdict12, 
self._tmpdict13, self._tmpdict14, self._tmpdict15, self._tmpdict16, 
self._tmpdict17, self._tmpdict18, self._tmpdict19, self._tmpdict20):
   _size += 1
   if _tmpdict:
   _dict_on_disk = _dict_on_disk_tuple[_size]
   for _word, _value in _tmpdict.iteritems():
   try:
   _string = _dict_on_disk[_word]
   # I discard _a and _b, maybe _string.find(' ') combined 
with slice would do better?
   _abs_count, _a, _b, _expected_freq = _string.split()
   _abs_count = int(_abs_count).__add__(_value)
   _t = (str(_abs_count), '0', '0', '0')
   except KeyError:
   _t = (str(_value), '0', '0', '0')
   # this writes a copy to the dict, right?
   _dict_on_disk[_word] = ' '.join(_t)
   #
   # clear the temporary dictionaries in ourself
   # I think this works as expected and really does release memory
   #
   for _tmpdict in (self._tmpdict1, self._tmpdict2, self._tmpdict3, 
self._tmpdict4, self._tmpdict5, self._tmpdict6, self._tmpdict7, self._tmpdict8, 
self._tmpdict9, self._tmpdict10, self._tmpdict11, self._tmpdict12, 
self._tmpdict13, self._tmpdict14, self._tmpdict15, self._tmpdict16, 
self._tmpdict17, self._tmpdict18, self._tmpdict19, self._tmpdict20):
   _tmpdict.clear()

  The above routine doesn't release of the memory back when it
exits. 


  See, the loop takes 25 minutes already, and it's prolonging
as the program is in about 1/3 or 1/4 of the total input.
The rest of my code is fast in contrast to this (below 1 minute).
-rw---  1 mmokrejs users 257376256 Jan 17 11:38 diskdict12.db
-rw---  1 mmokrejs users 267157504 Jan 17 11:35 diskdict11.db
-rw---  1 mmokrejs users 266534912 Jan 17 11:28 diskdict10.db
-rw---  1 mmokrejs users 253149184 Jan 17 11:21 diskdict9.db
-rw---  1 mmokrejs users 250232832 Jan 17 11:14 diskdict8.db
-rw---  1 mmokrejs users 246349824 Jan 17 11:07 diskdict7.db
-rw---  1 mmokrejs users 19488 Jan 17 11:02 diskdict6.db
-rw---  1 mmokrejs users  66584576 Jan 17 10:59 diskdict5.db
-rw---  1 mmokrejs users   5750784 Jan 17 10:57 diskdict4.db
-rw---  1 mmokrejs users311296 Jan 17 10:57 diskdict3.db
-rw---  1 mmokrejs users 295895040 Jan 17 10:56 diskdict20.db
-rw---  1 mmokrejs users 293634048 Jan 17 10:49 diskdict19.db
-rw---  1 mmokrejs users 299892736 Jan 17 10:43 diskdict18.db
-rw---  1 mmokrejs users 272334848 Jan 17 10:36 diskdict17.db
-rw---  1 mmokrejs users 274825216 Jan 17 10:30 diskdict16.db
-rw---  1 mmokrejs users 273104896 Jan 17 10:23 diskdict15.db
-rw---  1 mmokrejs users 272678912 Jan 17 10:18 diskdict14.db
-rw---  1 mmokrejs users 260407296 Jan 17 10:13 diskdict13.db
   Some spoke about mmaped files. Could I take advantage of that
with bsddb module or bsddb?
   Is gdbm better in some ways? Recently you have said dictionary
operations are fast ... Once more. I want to turn of locking support.
I can make the values as strings of fixed size, if mmap() would be
available. The number of keys doesn't grow much in time, mostly
there are only updates.
   

Thaks for any ideas.
martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: OCAMl a more natural extension language for python?

2005-01-17 Thread Duncan Booth
Jelle Feringa // EZCT / Paris wrote:

> After reading about extending python with C/Fortran in the excellent
> Python Scripting for Computational Science book by Hans Langtangen,
> I'm wondering whether there's not a more pythonic way of extending
> python. And frankly I think there is: OCAML
> 

There is an even more pythonic way to extend (or embed) python. Have you 
looked at Pyrex?

http://nz.cosc.canterbury.ac.nz/~greg/python/Pyrex/
-- 
http://mail.python.org/mailman/listinfo/python-list


getting a class attribute using a keyword argument

2005-01-17 Thread Guy Robinson
Hello,
I have a list of class instances. I wish to get the appropriate class attribute 
in each class instance depending on a SINGLE keyword in the calling class.

How do I get the calling method to correctly recognise the keyword as a keyword 
and not a class attribute? See example code below (which doesn't work).

class tocall:
def __init__(self):
self.title = "test"
self.name = "name"
def callingmethod(self,**kw):
for key in kw:
  if tocall.key == kw[key]:
   return tocall.key
which should work as such(but doesn't):
print callmethod(title = "test")
print callmethod(name = "name")
Regards,
Guy
--
http://mail.python.org/mailman/listinfo/python-list


Re: getting a class attribute using a keyword argument

2005-01-17 Thread Nick Coghlan
Guy Robinson wrote:
Hello,
I have a list of class instances. I wish to get the appropriate class 
attribute in each class instance depending on a SINGLE keyword in the 
calling class.
Py> help(getattr)
Help on built-in function getattr in module __builtin__:
getattr(...)
getattr(object, name[, default]) -> value
Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.
When a default argument is given, it is returned when the attribute doesn't
exist; without it, an exception is raised in that case.
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


platform independent kbhit()

2005-01-17 Thread Hans Georg Krauthaeuser
Hey all,
this is probably a FAQ, but I didn't found the answer...
I use msvcrt.kbhit() to check for a user keyboard event on windows. But 
now, I would prefer to make the module independent from the platform 
used. I already know that I can use curses (on linux/unix) or Tkinter. 
Also, I  found this http://my.execpc.com/~geezer/software/kbhit.c C 
source that has a kbhit() and a getch() for linux/unix that I can SWIG 
to python.

Are there other (more simple, pure python, true platform independent) 
possibilities?

Best regards
Hans Georg Krauthaeuser
--
www.uni-magdeburg.de/krauthae
--
http://mail.python.org/mailman/listinfo/python-list


Re: import problems *newbie*

2005-01-17 Thread Steve Holden
Grig Gheorghiu wrote:
In my experience (as a tester), it is easier to deal with PYTHONPATH
than to add the my.pth file to the site-packages directory. The main
reason is that I have my custom packages and modules in a directory
tree that I deploy on many clients/servers/platforms/OS versions, some
running different versions of Python. I found that I solve my import
problems by adding one line to .bash_profile, which sets PYTHONPATH to
the parent directory of my custom directory tree. Or, on Windows, I add
an Environment variable, call it PYTHONPATH, and set it to the
necessary directory. The alternative would be to hunt for the
site-packages directory (of which there might be several) on all my
systems.
I guess it's a matter of taste in the end, but I do find the PYTHONPATH
approach more suitable for automation and scripting, particularly when
dealing with a large number of systems. 

Grig
In the long term it doesn't really matter: the fact that my suggestion 
to use a .pth file worked does leave me still wondering why a PYTHONPATH 
setting didn't.

The advantage of using a .pth file *in the site-packages directory* is 
that it only applies to the version that picks up that site-packages 
directory, while PYTHONPATH applies to any Python you happen to run. In 
the case of libraries this will lead to recompilation of the bytecode 
(.pyc) files each time a different-version interpreter is used to run 
the program.

Unless Skip Montanaro's ideas about directing bytecode files to specific 
locations are picked up, it would seem like a good idea to point out the 
desirability of using separate copies of Python module sources for 
different interpreters.

Anyway Mike, I'm glad you have a reliable solution to your problem.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: getting a class attribute using a keyword argument

2005-01-17 Thread [EMAIL PROTECTED]

Guy Robinson wrote:
> Hello,
>
> I have a list of class instances. I wish to get the appropriate class
attribute
> in each class instance depending on a SINGLE keyword in the calling
class.
>
> How do I get the calling method to correctly recognise the keyword as
a keyword
> and not a class attribute? See example code below (which doesn't
work).
>
> class tocall:
>  def __init__(self):
>  self.title = "test"
>   self.name = "name"
>
> def callingmethod(self,**kw):
>  for key in kw:
>if tocall.key == kw[key]:
> return tocall.key
>
> which should work as such(but doesn't):
>
> print callmethod(title = "test")
> print callmethod(name = "name")
>
> Regards,
>
> Guy
You probably want something like this:
class tocall:
def __init__(self):
self.title = "test"
self.name = "name"


x = tocall()

print getattr(x, 'title')
print getattr(x, 'name')
print getattr(x, 'bogus')

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


Re: lambda

2005-01-17 Thread Steve Holden
Antoon Pardon wrote:
[...]
"A foolish consistency is the hobgoblin of little minds". Rules are made 
to be broken.

Like only use immutables as dictionary keys.
Fair enough, but don;t go advising newbies to do this.

Besides which, if you don't understand the language 
environment, rules alone will do you very little good. Try to focus a 
little more on principles and a little less on minutiae.

And what are the difference between those two?
Sometimes I get the impression that everything is a principle until
one personnaly finds the need to break it. After that it is a rule.
Principle: "Ten angels can dance on the head of a pin".
Minutiae: "Well, if they'd all recently been on a diet and they hold on 
to each other very carefully you can get 10.3. I got eleven once by 
adding a hash function".

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: [perl-python] 20050117, filter, map

2005-01-17 Thread Steve Holden
Erik Max Francis wrote:
Steven Bethard wrote:
Is there any chance you could post these all as part of the same 
thread?That would be really nice for those of us who aren't 
interested -- then we could just ignore the thread...

You are looking for evidence of cluefulness where it seems unlikely to 
ever appear.
Or, better yet, not posting it at all.  He's got his mailing list, what 
does he need to post it here for?

As I may have mentioned before, egotism can be the only possible reason.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-17 Thread Duncan Booth
Martin MOKREJ© wrote:

> Hi,
>   could someone tell me what all does and what all doesn't copy
> references in python. I have found my script after reaching some
> state and taking say 600MB, pushes it's internal dictionaries
> to hard disk. The for loop consumes another 300MB (as gathered
> by vmstat) to push the data to dictionaries, then releases
> little bit less than 300MB and the program start to fill-up
> again it's internal dictionaries, when "full" will do the
> flush again ...

Almost anything you do copies references.

>  
>   The point here is, that this code takes a lot of extra memory.
> I believe it's the references problem, and I remeber complains
> of frineds facing same problem. I'm a newbie, yes, but don't
> have this problem with Perl. OK, I want to improve my Pyhton
> knowledge ... :-))
> 
> 
> 
> 

> 
> 
>The above routine doesn't release of the memory back when it
> exits. 
That's probably because there isn't any memory it can reasonable be 
expected to release. What memory would *you* expect it to release?

The member variables are all still accessible as member variables until you 
run your loop at the end to clear them, so no way could Python release 
them.

Some hints:

When posting code, try to post complete examples which actually work. I 
don't know what type the self._dict_on_diskXX variables are supposed to be. 
It makes a big difference if they are dictionaries (so you are trying to 
hold everything in memory at one time) or shelve.Shelf objects which would 
store the values on disc in a reasonably efficient manner.

Even if they are Shelf objects, I see no reason here why you have to 
process everything at once. Write a simple function which processes one 
tmpdict object into one dict_on_disk object and then closes the 
dict_on_disk object. If you want to compare results later then do that by 
reopening the dict_on_disk objects when you have deleted all the tmpdicts.

Extract out everything you want to do into a class which has at most one 
tmpdict and one dict_on_disk That way your code will be a lot easier to 
read.

Make your code more legible by using fewer underscores.

What on earth is the point of an explicit call to __add__? If Guido had 
meant us to use __add__ he woudn't have created '+'.

What is the purpose of dict_on_disk? Is it for humans to read the data? If 
not, then don't store everything as a string. Far better to just store a 
tuple of your values then you don't have to use split or cast the strings 
to integers. If you do want humans to read some final output then produce 
that separately from the working data files.

You split out 4 values from dict_on_disk and set three of them to 0. If 
that really what you meant or should you be preserving the previous values?

Here is some (untested) code which might help you:

import shelve

def push_to_disc(data, filename):
database = shelve.open(filename)
try:
for key in data:
if database.has_key(key):
count, a, b, expected = database[key]
database[key] = count+data[key], a, b, expected
else:
database[key] = data[key], 0, 0, 0
finally:
database.close()

data.clear()

Call that once for each input dictionary and your data will be written out 
to a disc file and the internal dictionary cleared without any great spike 
of memory use.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda

2005-01-17 Thread Antoon Pardon
Op 2005-01-17, Steve Holden schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
> [...]
>>>"A foolish consistency is the hobgoblin of little minds". Rules are made 
>>>to be broken.
>> 
>> 
>> Like only use immutables as dictionary keys.
>> 
> Fair enough, but don;t go advising newbies to do this.

How about something like this.

Because of the extra precautions one has to take when
using mutables as hash keys, we advise newbies
to stick with immutable keys until they have gathered
enough knowledge and experience to adequatly weight
the pro and cons of a mutable key solution against
an immutable key solution.

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


Re: [perl-python] 20050117, filter, map

2005-01-17 Thread Nick Coghlan
Steve Holden wrote:
As I may have mentioned before, egotism can be the only possible reason.
I'd merely figured it as a textbook case of trolling - attention seeking 
behaviour, most likely indicative of a lack of self-esteem, rather than the reverse.

Still, he does at least keep the [perl-python] mailing list tag, so automatic 
filtering isn't that difficult. It is an unfortunate shame that his 
consideration doesn't extend to removing the general Perl and Python discussion 
groups from his recipients list.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-17 Thread Steve Holden
Martin MOKREJŠ wrote:
Hi,
 could someone tell me what all does and what all doesn't copy
references in python. I have found my script after reaching some
state and taking say 600MB, pushes it's internal dictionaries
to hard disk. The for loop consumes another 300MB (as gathered
by vmstat) to push the data to dictionaries, then releases
little bit less than 300MB and the program start to fill-up
again it's internal dictionaries, when "full" will do the
flush again ...
 The point here is, that this code takes a lot of extra memory.
I believe it's the references problem, and I remeber complains
of frineds facing same problem. I'm a newbie, yes, but don't
have this problem with Perl. OK, I want to improve my Pyhton
knowledge ... :-))
Right ho! In fact I suspect you are still quite new to programming as a 
whole, for reasons that may become clear as we proceed.

   def push_to_disk(self):
   _dict_on_disk_tuple = (None, self._dict_on_disk1, 
self._dict_on_disk2, self._dict_on_disk3, self._dict_on_disk4, 
self._dict_on_disk5, self._dict_on_disk6, self._dict_on_disk7, 
self._dict_on_disk8, self._dict_on_disk9, self._dict_on_disk10, 
self._dict_on_disk11, self._dict_on_disk12, self._dict_on_disk13, 
self._dict_on_disk14, self._dict_on_disk15, self._dict_on_disk16, 
self._dict_on_disk17, self._dict_on_disk18, self._dict_on_disk19, 
self._dict_on_disk20)
It's a bit unfortunate that all those instance variables are global to 
the method, as it means we can't clearly see what you intend them to do. 
However ...

Whenever I see such code, it makes me suspect that the approach to the 
problem could be more subtle. It appears you have decided to partition 
your data into twenty chunks somehow. The algorithm is clearly not coded 
in a way that would make it easy to modify the number of chunks.

[Hint: by "easy" I mean modifying a statement that reads
chunks = 20
to read
chunks = 40
for example]. To avoid this, we might use (say) a list of temp edicts, 
for example (the length of this could easily then be parameterized as 
mentioned. So where (my psychic powers tell me) your __init__() method 
currently contains

self._dict_on_disk1 = something()
self._dict_on_disk2 = something()
...
self._dict_on_disk20 = something()
I would have written
self._disk_dicts = []
for i in range(20):
self._disk_dicts.append(something)
Than again, I probably have an advantage over you. I'm such a crappy 
typist I can guarantee I'd make at least six mistakes doing it your way :-)

   _size = 0
What with all these leading underscores I presume it must be VERY 
important to keep these object's instance variables private. Do you have 
a particular reason for that, or just general Perl-induced paranoia? :-)

   #
   # sizes of these tmpdicts range from 10-1 entries for each!
   for _tmpdict in (self._tmpdict1, self._tmpdict2, self._tmpdict3, 
self._tmpdict4, self._tmpdict5, self._tmpdict6, self._tmpdict7, 
self._tmpdict8, self._tmpdict9, self._tmpdict10, self._tmpdict11, 
self._tmpdict12, self._tmpdict13, self._tmpdict14, self._tmpdict15, 
self._tmpdict16, self._tmpdict17, self._tmpdict18, self._tmpdict19, 
self._tmpdict20):
   _size += 1
   if _tmpdict:
   _dict_on_disk = _dict_on_disk_tuple[_size]
   for _word, _value in _tmpdict.iteritems():
   try:
   _string = _dict_on_disk[_word]
   # I discard _a and _b, maybe _string.find(' ') 
combined with slice would do better?
   _abs_count, _a, _b, _expected_freq = _string.split()
   _abs_count = int(_abs_count).__add__(_value)
   _t = (str(_abs_count), '0', '0', '0')
   except KeyError:
   _t = (str(_value), '0', '0', '0')

   # this writes a copy to the dict, right?
   _dict_on_disk[_word] = ' '.join(_t)
   #
   # clear the temporary dictionaries in ourself
   # I think this works as expected and really does release memory
   #
   for _tmpdict in (self._tmpdict1, self._tmpdict2, self._tmpdict3, 
self._tmpdict4, self._tmpdict5, self._tmpdict6, self._tmpdict7, 
self._tmpdict8, self._tmpdict9, self._tmpdict10, self._tmpdict11, 
self._tmpdict12, self._tmpdict13, self._tmpdict14, self._tmpdict15, 
self._tmpdict16, self._tmpdict17, self._tmpdict18, self._tmpdict19, 
self._tmpdict20):
   _tmpdict.clear()

There you go again with that huge tuple. You just like typing, don't 
you? You already wrote that one out just above. Couldn't you have 
assigned it to a local variable?

By the way, remind me again of the reason for the leading None in the 
_dict_on_disk_tuple, would you?

The crucial misunderstanding here might be the meaning of "release 
memory". While clearing the dictionary will indeed remove references to 
the objects formerly contained therein, and thus (possibly) render those 
items su

Re: lambda

2005-01-17 Thread Steve Holden
Antoon Pardon wrote:
Op 2005-01-17, Steve Holden schreef <[EMAIL PROTECTED]>:
Antoon Pardon wrote:
[...]
"A foolish consistency is the hobgoblin of little minds". Rules are made 
to be broken.

Like only use immutables as dictionary keys.
Fair enough, but don;t go advising newbies to do this.

How about something like this.
Because of the extra precautions one has to take when
using mutables as hash keys, we advise newbies
to stick with immutable keys until they have gathered
enough knowledge and experience to adequatly weight
the pro and cons of a mutable key solution against
an immutable key solution.
There you go with the minutiae again. How about:
"Don't use mutables as hash keys"?
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-17 Thread Martin MOKREJŠ
Duncan Booth wrote:
Martin MOKREJ© wrote:

Hi,
 could someone tell me what all does and what all doesn't copy
references in python. I have found my script after reaching some
state and taking say 600MB, pushes it's internal dictionaries
to hard disk. The for loop consumes another 300MB (as gathered
by vmstat) to push the data to dictionaries, then releases
little bit less than 300MB and the program start to fill-up
again it's internal dictionaries, when "full" will do the
flush again ...

Almost anything you do copies references.

But what does this?:
x = 'x'
a = x[2:]
b = z + len(x)
dict[a] = b

 The point here is, that this code takes a lot of extra memory.
I believe it's the references problem, and I remeber complains
of frineds facing same problem. I'm a newbie, yes, but don't
have this problem with Perl. OK, I want to improve my Pyhton
knowledge ... :-))



  The above routine doesn't release of the memory back when it
exits. 
That's probably because there isn't any memory it can reasonable be 
expected to release. What memory would *you* expect it to release?
Thos 300MB, they get allocated/reserved when the posted loop get's
executed. When the loops exits, almost all is returned/deallocated.
Yes, almost. :(
The member variables are all still accessible as member variables until you 
run your loop at the end to clear them, so no way could Python release 
them.
OK, I wanted to know if there's some assignment using a reference,
which makes the internal garbage collector not to recycle the memory,
as, for example, the target dictionary still keeps reference to the temporary
dictionary.
Some hints:
When posting code, try to post complete examples which actually work. I 
don't know what type the self._dict_on_diskXX variables are supposed to be. 
It makes a big difference if they are dictionaries (so you are trying to 
hold everything in memory at one time) or shelve.Shelf objects which would 
store the values on disc in a reasonably efficient manner.
The self._dict_on_diskXX are bsddb files, self._tmpdictXX are builtin 
dictionaries.
Even if they are Shelf objects, I see no reason here why you have to 
I gathered from previous discussion it's faster to use bsddb directly,
so no shelve.
process everything at once. Write a simple function which processes one 
tmpdict object into one dict_on_disk object and then closes the
That's what I do, but in the for loop ...
dict_on_disk object. If you want to compare results later then do that by
OK, I got your point.
reopening the dict_on_disk objects when you have deleted all the tmpdicts.
That's what I do (not shown).
Extract out everything you want to do into a class which has at most one 
tmpdict and one dict_on_disk That way your code will be a lot easier to 
read.

Make your code more legible by using fewer underscores.
What on earth is the point of an explicit call to __add__? If Guido had 
meant us to use __add__ he woudn't have created '+'.
To invoke additon directly on the object. It's faster than letting
python to figure out that I sum up int() plus int(). It definitely
has helped a lot when using Decimal(a) + Decimal(b), where I got rid
of thousands of Decimal(__new__), __init__ and I think few other
methods of decimal as well - I think getcontext too. 

What is the purpose of dict_on_disk? Is it for humans to read the data? If 
not, then don't store everything as a string. Far better to just store a 
For humans is processed later.
tuple of your values then you don't have to use split or cast the strings 
bsddb creaps on me that I can store as a key or value only a string.
I'd love to store tuple.
import bsddb
_words1 = bsddb.btopen('db1.db', 'c')
_words1['a'] = 1
Traceback (most recent call last):
File "", line 1, in ?
File "/usr/lib/python2.3/bsddb/__init__.py", line 120, in __setitem__
  self.db[key] = value
TypeError: Key and Data values must be of type string or None.

How can I record a number then?

to integers. If you do want humans to read some final output then produce 
that separately from the working data files.

You split out 4 values from dict_on_disk and set three of them to 0. If 
that really what you meant or should you be preserving the previous values?
No, overwrite them, i.e. invalidate them. Originally I recorded only first,
but to compute the latter numbers is so expensive I have to store them.
As walking through the dictionaries is so slow, I gave up on an idea to
store just one, and a lot later in the program walk once again through the
dictionary and 'fix' it by computing missing values.
Here is some (untested) code which might help you:
import shelve
Why shelve? To have the ability to record tuple? Isn't it cheaper
to convert to string and back and write to bsddb compared to this overhead?
def push_to_disc(data, filename):
database = shelve.open(filename)
try:
for key in data:
if database.has_key(key):
count, a, b, expected = database[key]
database[key] = count+d

Re: (objects as) mutable dictionary keys

2005-01-17 Thread Peter Maas
Antoon Pardon schrieb:
  Dictionary lookup with mutable types like lists is a source of
  unpleasant surprises for the programmer and therefore impossible in
  Python.
It is not impossible in Python. It may be discouraged but it is not
impossible since I have already done so.
Wouldn't this raise a TypeError? Or did you wrap them with an object?
--
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
--
http://mail.python.org/mailman/listinfo/python-list


Re: OCAMl a more natural extension language for python?

2005-01-17 Thread Ville Vainio
> "Jelle" == Jelle Feringa // EZCT / Paris <[EMAIL PROTECTED]> writes:

Jelle> After reading about extending python with C/Fortran in the
Jelle> excellent Python Scripting for Computational Science book
Jelle> by Hans Langtangen, I'm wondering whether there's not a
Jelle> more pythonic way of extending python. And frankly I think
Jelle> there is: OCAML

For many tasks the point of "extending" python is to gain access to
libraries that have a C/C++ API. Extensions that merely provide a
faster way to do something are much rarer.

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (objects as) mutable dictionary keys

2005-01-17 Thread Just
In article <[EMAIL PROTECTED]>,
 Peter Maas <[EMAIL PROTECTED]> wrote:

> Antoon Pardon schrieb:
> >   Dictionary lookup with mutable types like lists is a source of
> >   unpleasant surprises for the programmer and therefore impossible in
> >   Python.
> > 
> > 
> > It is not impossible in Python.

Is too.

> > It may be discouraged but it is not
> > impossible since I have already done so.
> 
> Wouldn't this raise a TypeError? Or did you wrap them with an object?

He created a list subclass that redefines __hash__, so he cheated :).

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


Re: generator expressions: performance anomaly?

2005-01-17 Thread Raymond Hettinger
[Delaney, Timothy C]
> Nick's other suggestion - that genexps propagate __len__ - might
> still be interesting. Of course, it would only be applicable for
> unconditional genexps(i.e. no if clause).

Length transparency for iterators is not as general as one would expect.  I once
spent a good deal of effort exploring where it made sense, and I was surprised
to find that it only rarely works out.  Length transparency is an unexpectedly
thorny subject with many dead-ends which precludes a fully general solution such
as that proposed by Nick.

For a recap of my research, see the docstring for Lib/test/test_iterlen.py .


Raymond Hettinger


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


Re: Writing huge Sets() to disk

2005-01-17 Thread Martin MOKREJŠ
Steve Holden wrote:
Martin MOKREJŠ wrote:
Hi,
 could someone tell me what all does and what all doesn't copy
references in python. I have found my script after reaching some
state and taking say 600MB, pushes it's internal dictionaries
to hard disk. The for loop consumes another 300MB (as gathered
by vmstat) to push the data to dictionaries, then releases
little bit less than 300MB and the program start to fill-up
again it's internal dictionaries, when "full" will do the
flush again ...
 The point here is, that this code takes a lot of extra memory.
I believe it's the references problem, and I remeber complains
of frineds facing same problem. I'm a newbie, yes, but don't
have this problem with Perl. OK, I want to improve my Pyhton
knowledge ... :-))
Right ho! In fact I suspect you are still quite new to programming as a 
whole, for reasons that may become clear as we proceed.


   def push_to_disk(self):
   _dict_on_disk_tuple = (None, self._dict_on_disk1, 
self._dict_on_disk2, self._dict_on_disk3, self._dict_on_disk4, 
self._dict_on_disk5, self._dict_on_disk6, self._dict_on_disk7, 
self._dict_on_disk8, self._dict_on_disk9, self._dict_on_disk10, 
self._dict_on_disk11, self._dict_on_disk12, self._dict_on_disk13, 
self._dict_on_disk14, self._dict_on_disk15, self._dict_on_disk16, 
self._dict_on_disk17, self._dict_on_disk18, self._dict_on_disk19, 
self._dict_on_disk20)
The None above is there just as I didn't want to evaluate all the time
something like "x+1":
for x in _dict_on_disk_tuple:
   key = 
   newdict[x+1][key] = ...
This None doesn't hurt me, then x contains exactly the value I need several
times in the loop ...

It's a bit unfortunate that all those instance variables are global to 
the method, as it means we can't clearly see what you intend them to do. 
However ...

Whenever I see such code, it makes me suspect that the approach to the 
problem could be more subtle. It appears you have decided to partition 
your data into twenty chunks somehow. The algorithm is clearly not coded 
in a way that would make it easy to modify the number of chunks.
No, it's not, but that's not the speed problem, really. ;)
[Hint: by "easy" I mean modifying a statement that reads
chunks = 20
to read
chunks = 40
for example]. To avoid this, we might use (say) a list of temp edicts, 
for example (the length of this could easily then be parameterized as 
mentioned. So where (my psychic powers tell me) your __init__() method 
currently contains

self._dict_on_disk1 = something()
self._dict_on_disk2 = something()
...
self._dict_on_disk20 = something()
Almost. They are bsddb dictionary files.
I would have written
self._disk_dicts = []
for i in range(20):
self._disk_dicts.append(something)
Than again, I probably have an advantage over you. I'm such a crappy 
typist I can guarantee I'd make at least six mistakes doing it your way :-)
Originally I had this, I just to get of one small list. ;)

   _size = 0

What with all these leading underscores I presume it must be VERY 
important to keep these object's instance variables private. Do you have 
a particular reason for that, or just general Perl-induced paranoia? :-)
See below. ;)

   #
   # sizes of these tmpdicts range from 10-1 entries for each!
   for _tmpdict in (self._tmpdict1, self._tmpdict2, 
self._tmpdict3, self._tmpdict4, self._tmpdict5, self._tmpdict6, 
self._tmpdict7, self._tmpdict8, self._tmpdict9, self._tmpdict10, 
self._tmpdict11, self._tmpdict12, self._tmpdict13, self._tmpdict14, 
self._tmpdict15, self._tmpdict16, self._tmpdict17, self._tmpdict18, 
self._tmpdict19, self._tmpdict20):
   _size += 1
   if _tmpdict:
   _dict_on_disk = _dict_on_disk_tuple[_size]
   for _word, _value in _tmpdict.iteritems():
   try:
   _string = _dict_on_disk[_word]
   # I discard _a and _b, maybe _string.find(' ') 
combined with slice would do better?
   _abs_count, _a, _b, _expected_freq = 
_string.split()
   _abs_count = int(_abs_count).__add__(_value)
   _t = (str(_abs_count), '0', '0', '0')
   except KeyError:
   _t = (str(_value), '0', '0', '0')

   # this writes a copy to the dict, right?
   _dict_on_disk[_word] = ' '.join(_t)
   #
   # clear the temporary dictionaries in ourself
   # I think this works as expected and really does release memory
   #
   for _tmpdict in (self._tmpdict1, self._tmpdict2, 
self._tmpdict3, self._tmpdict4, self._tmpdict5, self._tmpdict6, 
self._tmpdict7, self._tmpdict8, self._tmpdict9, self._tmpdict10, 
self._tmpdict11, self._tmpdict12, self._tmpdict13, self._tmpdict14, 
self._tmpdict15, self._tmpdict16, self._tmpdict17, self._tmpdict18, 
self._tmpdict19, self._tmpdict20):
   _tmpdict.clear()

There you go again with that huge tuple.

Re: OCAMl a more natural extension language for python?

2005-01-17 Thread Do Re Mi chel La Si Do
Hi !

OCAML is very complementary at Python :

unreadable vs readable
functionnel vs procedural/POO/etc.
compiled vs interpreted (or compil JIT)
very fast vs mean velocity
hard to learn vs easy to easy to learn


Yes, OCAML is very complementary, too much, much too, complementary at
Python...

But, C is not complementary to Python (in the same state of mind).



And, what do you think of... Erlang ?


@-salutations
-- 
Michel Claveau






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


Re: lambda

2005-01-17 Thread Antoon Pardon
Op 2005-01-17, Steve Holden schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>
>> Op 2005-01-17, Steve Holden schreef <[EMAIL PROTECTED]>:
>> 
>>>Antoon Pardon wrote:
>>>[...]
>>>
>"A foolish consistency is the hobgoblin of little minds". Rules are made 
>to be broken.


Like only use immutables as dictionary keys.

>>>
>>>Fair enough, but don;t go advising newbies to do this.
>> 
>> 
>> How about something like this.
>> 
>> Because of the extra precautions one has to take when
>> using mutables as hash keys, we advise newbies
>> to stick with immutable keys until they have gathered
>> enough knowledge and experience to adequatly weight
>> the pro and cons of a mutable key solution against
>> an immutable key solution.
>> 
> There you go with the minutiae again. How about:
>
> "Don't use mutables as hash keys"?

That sounds too dogmatic to my ears. I also find it
too selective. The problem with mutables as dictionary
keys is not specific to dictionaries. Everywhere you
have mutables in a container, it is possible that
mutating the object in the container will cause
problem. Heck even using mutables as arguments can
cause trouble. Why else the specific advice against

  def foo(p = [])

type of arguments. So should we adopt the principles:

  Don't use mutables in containers

  Don't use mutables as default values for parameters

  Don't use mutables as arguments.

  Don't assign one mutable to an other.


I don't see a big difference between these principles
and the hash key principle, so in the end may be we
should just stick with the more general principle:

  Don't use mutables!


and be done with it.

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


Re: protecting the python code.

2005-01-17 Thread Andrey Tatarinov
nell wrote:
First the "10x in advance" means thanks in advance.
The main importance of protecting my code is to save headache of
customers that want to be smart and change it and then complain on bugs
also you can try to use py2exe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-17 Thread Duncan Booth
Martin MOKREJŠ wrote:

> Duncan Booth wrote:
>> Almost anything you do copies references.
> 
> 
> But what does this?:
> 
> x = 'x'

Copies a reference to the existing string 'x' and stores the new 
reference in the variable x. If its a global variable then this will 
involve creating a new reference to the existing string 'x' and storing 
both references in the globals() dictionary for the module.

> a = x[2:]

Creates a new string by slicing the one reference by x, then creates a new 
reference to the string and stores it in the variable 'a' (as above), then 
releases the first reference to the new string.

> b = z + len(x)

Creates a new reference to 'z'; creates a new reference to 'x', creates a 
new reference to 'len', calls the function (which involves creating and 
releasing a tuple), releases the references to 'len' and 'x', invokes the 
add operator, releases the reference to 'z', then creates a new reference 
to the result while storing it in the variable 'b'. The result of the 
addition could be a new object, or it may just be a new reference created 
to an existing object.

> dict[a] = b

If 'dict' is a variable of type 'dict' (and its a bad idea to use the type 
name as the variable name), then this creates new references to each of 'a' 
and 'b' and stores them in the object 'dict'.

As I said, almost everything you do involves creating and releasing 
references to existing objects.

>> 
>> The member variables are all still accessible as member variables
>> until you run your loop at the end to clear them, so no way could
>> Python release them.
> 
> OK, I wanted to know if there's some assignment using a reference,
> which makes the internal garbage collector not to recycle the memory,
> as, for example, the target dictionary still keeps reference to the
> temporary dictionary.
> 
So long as the object is still accessible it won't be free. You aren't 
making anything new reference the temporary dictionary, but so long as the 
old references are still there it can't free the memory.

>> 
>> Even if they are Shelf objects, I see no reason here why you have to 
> 
> I gathered from previous discussion it's faster to use bsddb directly,
> so no shelve.
> 
Until you know that speed of accessing the file is a problem, I would go 
for the simple to use solution. At present there is no evidence that the 
speed of accessing the file is going to be a problem: your problems seem to 
stem from excessive memory use which means that page faults are likely to 
swamp everything else as far as execution time is concerned.

>> What on earth is the point of an explicit call to __add__? If Guido
>> had meant us to use __add__ he woudn't have created '+'.
> 
> To invoke additon directly on the object. It's faster than letting
> python to figure out that I sum up int() plus int(). It definitely
> has helped a lot when using Decimal(a) + Decimal(b), where I got rid
> of thousands of Decimal(__new__), __init__ and I think few other
> methods of decimal as well - I think getcontext too. 
> 
The same point as above: it is most unlikely that these additions are going 
to make a noticeable difference to the running time, so leave them as easy 
to read additions until you have profiled the code and determined that they 
really are a hotspot that needs optimisiing. The less time you spend 
optimising prematurely, the sooner you get a program that meets your needs.

>> tuple of your values then you don't have to use split or cast the
>> strings 
> 
> bsddb creaps on me that I can store as a key or value only a string.
> I'd love to store tuple.
> 
 import bsddb
 _words1 = bsddb.btopen('db1.db', 'c')
 _words1['a'] = 1
> 
> Traceback (most recent call last):
>  File "", line 1, in ?
>  File "/usr/lib/python2.3/bsddb/__init__.py", line 120, in __setitem__
>self.db[key] = value
> TypeError: Key and Data values must be of type string or None.
> 

> 
> How can I record a number then?

Either by wrapping your database access in code which converts the values 
to/from string, or by using a package which already does that (such as 
shelve).

> 
> Can I use the mmap() feature on bsddb or any .db file? Most of the
> time I do updates, not inserts! I don't want to rewrite all the time
> 300MB file. I want to update it. What I do need for it? Know the
> maximal length of a string value keept in the .db file? Can I get rid
> of locking support in those huge files?

Dont worry about it, updates won't rewrite the entire file.

> 
> Definitely I can improve my algorithm. But I believe I'll always have
> to work with those huge files.

The point of using something like a bsddb file is that you get a system 
which will do the hard work for you of figuring out which bits to keep in 
memory and which bits to leave on disc. The sort of processing you showed, 
which updates the database in a random order but probably doesn't access 
every record should work well with a bsddb file.

The code you show is dumping th

Re: List problems in C code ported to Python

2005-01-17 Thread Lucas Raab
Grant Edwards wrote:
On 2005-01-16, Lucas Raab <[EMAIL PROTECTED]> wrote:

Please see both the Python and C code at 
http://home.earthlink.net/~lvraab. The two files are ENIGMA.C
and engima.py
 http://www.catb.org/~esr/faqs/smart-questions.html
I didn't expect to get bitched out just because I didn't
follow "protocol."

You didn't get "bitched out".  You did get some very sound
advice. You want help solving a problem, and there are ways you
can greatly increase the chances that you'll get help with your
problem.  After being told the best ways to get help, you
whined about it rather than following it.
Nobody owes you anything. 

Remember that.
[You're darned lucky somebody did take the time to go to your
web site and proof your code for you after your posting said in
effect "I'm too lazy to compose and post a precise question, so
go look at my program and fix it for me."]
Now, go back and read the smart questions reference.
Sorry about that. I had a bad day. First there was the migraine and then 
the fight with my significant other, so yesterday was not a good day. I 
apologize for what I said.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [perl-python] 20050117, filter, map

2005-01-17 Thread Martin Kissner
Steven Bethard wrote :
> Xah Lee wrote:
>> © Note: this post is from the Perl-Python
>> © a-day mailing list at
>> © http://groups.yahoo.com/group/perl-python/
>
> Is there any chance you could post these all as part of the same thread? 
>That would be really nice for those of us who aren't interested -- 
> then we could just ignore the thread...

I would appreciate that, too.
But I fear this person doesn't even read the comments on his unwanted
load.

I guess I'll scorefile the "Subject" of these postings, too, to get rid of
this.


-- 
Epur Si Muove (Gallileo Gallilei)
-- 
http://mail.python.org/mailman/listinfo/python-list


dynamic data types

2005-01-17 Thread Charlie
Hi,

The description of Python always mentions "very high level dynamic data
types". Now, I can't seem to find any examples of these (nothing
described with this term anyway). Is this simply refering to built-in
dynamic data structures such as lists and dictionaries, with a great
deal of operators defined on? Or is there something else meant by
"dynamic data types" in Python? 

Regards,

Charlie

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


Re: List problems in C code ported to Python

2005-01-17 Thread [EMAIL PROTECTED]
Lucas Raab wrote:
> I'm done porting the C code, but now when running the script I
> continually run into problems with lists. I tried appending and
> extending the lists, but with no avail. Any help is much appreciated
> Please see both the Python and C code at
> http://home.earthlink.net/~lvraab. The two files are ENIGMA.C and
engima.py
>
> TIA

You need something like a matrix too for this, if we combine this with
the
already posted idea of caching of 'ord' results you could go this way:

class matrix(object):
"""based on
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189971
"""
def __init__(self, *args):
from types import IntType, StringType

self.__data = []

if len(args) == 2 and type(args[0]) == IntType and type(args[1]
== IntType):
#args[0] = #rows, args[1] = #columns
for r in range(args[0]):
self.__data.append([])
for j in range(args[1]):
self.__data[r].append(0)
else:
for arg in args:
if type(arg) == StringType:
self.__data.append(map(ord, list(arg)))

def __repr__(self):
ret = ''
for r in self.__data:
ret = '%s\n%s' % (ret, r)

return ret

def __getitem__(self, (row, col)):
return self.__data[row][col]

def __setitem__(self, (row, col), value):
self.__data[row][col] = value



#setup rotor data
A = ord('A')
ref_rotor = map(ord, "YRUHQSLDPXNGOKMIEBFZCWVJAT")
print ref_rotor

data = matrix(8, 26)
for i in range(26):
data[(4, i)] = (ref_rotor[i] - A + 26) % 26
print data

step_data = (16,  4, 21,  9, 25) #steps at: q, e, v, j, z
order = range(3)
rotor = matrix("EKMFLGDQVZNTOWYHXUSPAIBRCJ",
"AJDKSIRUXBLHWTMCQGZNPYFVOE", \
"BDFHJLCPRTXVZNYEIWGAKMUSQO",
"ESOVPZJAYQUIRHXLNFTGKDCMWB", \
"VZBRGITYUPSDNHLXAWMJQOFECK")
step = range(3)
for i in range(1, 4):
step[i - 1] = step_data[order[i-1]]
for j in range(26):
data[(i, j)] = (rotor[(order[i-1], j)] - A + 26) % 26
print data

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


Re: Executing a script created by the end user

2005-01-17 Thread Fuzzyman
compile and eval is a good way to go.
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: dynamic data types

2005-01-17 Thread rbt
Charlie wrote:
Hi,
The description of Python always mentions "very high level dynamic data
types". Now, I can't seem to find any examples of these (nothing
described with this term anyway). Is this simply refering to built-in
dynamic data structures such as lists and dictionaries, with a great
deal of operators defined on? Or is there something else meant by
"dynamic data types" in Python? 

Regards,
Charlie
I've always thought of it like this... in C, we have to do something 
like this when declaring a variable:

int x = 0;
We had to specifically tell the language compiler that x is an integer. 
In Python, all we have to do is:

x = 0
The interpretor knows that x is an integer. We can also change the type 
like this:

str(x)
float(x)
long(x)
etc...
To me, this is why Python types are called dynamic. They are easy to 
setup and easy to modify when compared to older, more static languages.

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


Native widgets for Python

2005-01-17 Thread A. Klingenstein
Which other GUI library for Python other than wxpython has native 
widgets for MS Windows ?
I know there is MFC and GDI, but I want something easier to use than wx, 
not harder :)
wxpython has to problem that it handles much more like a C++ library 
than a Python one sometimes.

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


Re: Native widgets for Python

2005-01-17 Thread Stephen Thorne
there's someone writing 'dabo', which is apparently "wxpython but more python".

Stephen.


On Mon, 17 Jan 2005 15:13:07 +0100, A. Klingenstein <[EMAIL PROTECTED]> wrote:
> Which other GUI library for Python other than wxpython has native
> widgets for MS Windows ?
> I know there is MFC and GDI, but I want something easier to use than wx,
> not harder :)
> wxpython has to problem that it handles much more like a C++ library
> than a Python one sometimes.
> 
> Alex
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: OCAMl a more natural extension language for python?

2005-01-17 Thread Jelle Feringa // EZCT / Paris
H. Not familiar with erlang at all...

> Subject: Re: OCAMl a more natural extension language for python?
> 
> Hi !
> 
> OCAML is very complementary at Python :
> 
> unreadable vs readable

That's depending on how you compare; I find OCAML quite readable
compared to C / Fortran

> functionnel vs procedural/POO/etc.

OCAML is not a true functional language, its also OO

> compiled vs interpreted (or compil JIT)
> very fast vs mean velocity

What I'm looking for!

> hard to learn vs easy to easy to learn

Is it in comparison to C?

> Yes, OCAML is very complementary, too much, much too, complementary at
> Python...
> 
> But, C is not complementary to Python (in the same state of mind).

So some additional arguments to the hypotheses of OCAMl being a
natural extension language to Python?

Cheers,

Jelle.



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


Re: lambda

2005-01-17 Thread Just
In article <[EMAIL PROTECTED]>,
 Antoon Pardon <[EMAIL PROTECTED]> wrote:

> Op 2005-01-17, Steve Holden schreef <[EMAIL PROTECTED]>:

> > There you go with the minutiae again. How about:
> >
> > "Don't use mutables as hash keys"?
> 
> That sounds too dogmatic to my ears. I also find it
> too selective. The problem with mutables as dictionary
> keys is not specific to dictionaries. Everywhere you
> have mutables in a container, it is possible that
> mutating the object in the container will cause
> problem.

The main difference is: if you mutate a dict key you *always* have a 
problem. So don't do that. Mutating (say) a list item *only* is a 
problem if you (say) need that list to remain sorted. Lists don't 
magically remain sorted, so people generally sort it before they do some 
operation that expects a sorted list.

> Heck even using mutables as arguments can
> cause trouble. Why else the specific advice against
> 
>   def foo(p = [])
> 
> type of arguments. So should we adopt the principles:
> 
>   Don't use mutables in containers

Nonsense.

>   Don't use mutables as default values for parameters

That's good advice in general.

>   Don't use mutables as arguments.

Nonsense.

>   Don't assign one mutable to an other.

Nonsense. Some newbies get surprised by Python's assignment-doesn't-copy 
semantics, but it's such basic knowledge (as well as a useful feature) 
that I simply don't understand you saying this.

> I don't see a big difference between these principles
> and the hash key principle,

Than you haven't looked hard enough.

> so in the end may be we
> should just stick with the more general principle:
> 
>   Don't use mutables!
> 
> 
> and be done with it.

Ok, so you're indeed a troll.

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


Re: lambda

2005-01-17 Thread Steve Holden
Antoon Pardon wrote:
Op 2005-01-17, Steve Holden schreef <[EMAIL PROTECTED]>:
Antoon Pardon wrote:

Op 2005-01-17, Steve Holden schreef <[EMAIL PROTECTED]>:

Antoon Pardon wrote:
[...]

"A foolish consistency is the hobgoblin of little minds". Rules are made 
to be broken.

Like only use immutables as dictionary keys.
Fair enough, but don;t go advising newbies to do this.

How about something like this.
Because of the extra precautions one has to take when
using mutables as hash keys, we advise newbies
to stick with immutable keys until they have gathered
enough knowledge and experience to adequatly weight
the pro and cons of a mutable key solution against
an immutable key solution.
There you go with the minutiae again. How about:
"Don't use mutables as hash keys"?

That sounds too dogmatic to my ears. I also find it
too selective. The problem with mutables as dictionary
keys is not specific to dictionaries. Everywhere you
have mutables in a container, it is possible that
mutating the object in the container will cause
problem. Heck even using mutables as arguments can
cause trouble. Why else the specific advice against
  def foo(p = [])
type of arguments. So should we adopt the principles:
  Don't use mutables in containers
  Don't use mutables as default values for parameters
  Don't use mutables as arguments.
  Don't assign one mutable to an other.
I don't see a big difference between these principles
and the hash key principle, so in the end may be we
should just stick with the more general principle:
  Don't use mutables!
and be done with it.
http://redwing.hutman.net/~mreed/warriorshtm/tirelessrebutter.htm
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


PUG in Melbourne Australia?

2005-01-17 Thread Emiliano Molina
Does anyone here know if there is a Python Users Group in Melbourne 
Australia?

A google search shows an attempt to start one at meetups.com or 
something like that but it now seems defunct.
--
http://mail.python.org/mailman/listinfo/python-list


Re: OCAMl a more natural extension language for python?

2005-01-17 Thread beliavsky
Jelle Ferringa wrote:

>Since I haven't got actual experience programming CAML I'd like to
speculate
>that OCAML would be a very pythonic way of extending python: its
>open-source, object oriented, as fast as C, and ! garbage collecting!

The open source g95 Fortran 95 compiler is already usable and will be
officially released this year. Fortran and C are comparable in speed,
and if one uses allocatable arrays rather than pointers, memory leaks
should not occur. Fortran 2003 supports OOP with inheritance, and a few
F95 compilers already have this functionality.

>That's depending on how you compare; I find OCAML quite readable
compared to C / Fortran .

Have you ever used Fortran 90 or 95?

I don't use OCAML, so I looked at some OCAML code to multiply matrices
at
http://shootout.alioth.debian.org/benchmark.php?test=matrix&lang=ocaml&id=0&sort=cpu
from the Computer Language Shootout . To create a matrix the OCAML code
is

7 let mkmatrix rows cols =
8   let count = ref 1 and last_col = cols - 1
9   and m = Array.make_matrix rows cols 0 in
10   for i = 0 to rows - 1 do
11 let mi = m.(i) in
12 for j = 0 to last_col do mi.(j) <- !count; incr count done;
13   done;

In Python with Numeric it's just

x = zeros([nrow,ncol],Float)

and in Fortran 90/95 it's just

real, allocatable :: x(:,:)
allocate (x(nrow,ncol))

There appears not to be a built-in function for matrix multiplication
in OCAML. There is in Python with Numeric or Numarray or Fortran 90/95.
For problems where the main data structures are arrays, OCAML seems to
be considerably more low-level than Python with Numeric/Numarray or
Fortran 90/95. Also, there exists a vast computational infrastructure
in Fortran and C (see http://www.netlib.org). Does OCAML have this?

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


Re: lambda

2005-01-17 Thread Antoon Pardon
Op 2005-01-17, Just schreef <[EMAIL PROTECTED]>:
> In article <[EMAIL PROTECTED]>,
>  Antoon Pardon <[EMAIL PROTECTED]> wrote:
>
>> Op 2005-01-17, Steve Holden schreef <[EMAIL PROTECTED]>:
>
>> > There you go with the minutiae again. How about:
>> >
>> > "Don't use mutables as hash keys"?
>> 
>> That sounds too dogmatic to my ears. I also find it
>> too selective. The problem with mutables as dictionary
>> keys is not specific to dictionaries. Everywhere you
>> have mutables in a container, it is possible that
>> mutating the object in the container will cause
>> problem.
>
> The main difference is: if you mutate a dict key you *always* have a 
> problem. So don't do that. Mutating (say) a list item *only* is a 
> problem if you (say) need that list to remain sorted.

That is not true. It is a problem every time I expect the list
items to remain the same.

> Lists don't 
> magically remain sorted, so people generally sort it before they do some 
> operation that expects a sorted list.
>
>> Heck even using mutables as arguments can
>> cause trouble. Why else the specific advice against
>> 
>>   def foo(p = [])
>> 
>> type of arguments. So should we adopt the principles:
>> 
>>   Don't use mutables in containers
>
> Nonsense.
>
>>   Don't use mutables as default values for parameters
>
> That's good advice in general.
>
>>   Don't use mutables as arguments.
>
> Nonsense.
>
>>   Don't assign one mutable to an other.
>
> Nonsense. Some newbies get surprised by Python's assignment-doesn't-copy 
> semantics, but it's such basic knowledge (as well as a useful feature) 
> that I simply don't understand you saying this.

Well it is this same sematics that causes the problems with
mutable dictionary keys. If it is such basic knowledge then what
is the problem with mutable dictionary keys?

>> I don't see a big difference between these principles
>> and the hash key principle,
>
> Than you haven't looked hard enough.

All of these can get unexpected behaviour because of the
assignment-doesn't-copy semantics. The same semantics
that can cause problems if you work with mutable dictionary
keys.

>> so in the end may be we
>> should just stick with the more general principle:
>> 
>>   Don't use mutables!
>> 
>> and be done with it.
>
> Ok, so you're indeed a troll.

The problems with mutables as dictionary keys is just one
particulary case of the problems you can have when your
assignmentxs semantics just creates a new reference to the
same object. As such it is no different from the problem
of mutating one object and finding out this object was
also reference through an other name you expected to remain
the same or finding out this object was also in a list you
expected to remain stable etc.

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


Re: lambda

2005-01-17 Thread Antoon Pardon
Op 2005-01-17, Steve Holden schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>
>> I don't see a big difference between these principles
>> and the hash key principle, so in the end may be we
>> should just stick with the more general principle:
>> 
>>   Don't use mutables!
>> 
>> 
>> and be done with it.
>> 
> http://redwing.hutman.net/~mreed/warriorshtm/tirelessrebutter.htm
>
> regards
>   Steve

I you want to play it like this

http://redwing.hutman.net/~mreed/warriorshtm/crybaby.htm

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


[ANN] iCalendar package 0.9

2005-01-17 Thread Max M
I have written a package that can parse and generate files according to 
RFC 2445 (iCalender). That should be any file ending with .ics :-)

It is not quite polished yet, but fully functional, and choke full of 
doctest.

It does support the full spec and all datatypes and parameter values.
The Api is pretty stable, and will probably not change much.
I would like anybody interrested to give it a test drive before I finish 
it off and make it a 1.0.

http://www.mxm.dk/products/public/ical/
Any feedback would be welcome.
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list


Re: Native widgets for Python

2005-01-17 Thread Tim Heaney
Stephen Thorne <[EMAIL PROTECTED]> writes:
>
> there's someone writing 'dabo', which is apparently "wxpython but
> more python".

It looks like dabo uses, not replaces, wxPython

  http://dabodev.com/about
-- 
http://mail.python.org/mailman/listinfo/python-list


Employablity of python programmers

2005-01-17 Thread Mir Nazim
Hi,

Here I am once again to give a bit trouble.

I am at the verge of completing my graduation in computer sciences. I
will be graduating within 6-8 months. Now I am faced with the problems
of my career. I am in a fix what skill set I must choose to be safe as
far as job openings are concerned. I understand that skill set should
be that one like most but job is also important. I will try to achieve
a balance in both with the help of you advice.

I am currently developing in PHP as a freelance web developer. But I
want to move to python(for all it all cool reasons discussed a zillion
times on c.l.py) and wanted to know the job oportunites available to a
python programmer(I know these have been also discussed a zillion time
here but still..). I am living in India and would like to know about
employability of python programmers in India (I know that a few Indians
frequent c.l.py. Hello Sridhar, where are you).

I would also like to know that if the knowledge of any other language
will boost employability of a python programmer. As far as I see it,
the following combination are desirable.

1) C/C++ and Python.
2) Java and Python.
3) Pure Python.

Out of the three Java along with python seems to be straight forward
choice as far as employability is concerned. But I would like to know
the benifits which one is a better career choice to take out of these
three choices(other suggestions are welcome). For me choice three would
be better, not because I have only one language to learn. If I choose
choice three I could spend more time in learning different approaches
to develop the application and better master the library and frameworks
avaialble for python.

So what are the recomendations from your side. Please help.
Thanks
---
Mir Nazim.

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


Re: lambda

2005-01-17 Thread John Lenton
On Mon, Jan 17, 2005 at 11:41:20AM +, Antoon Pardon wrote:
> Op 2005-01-17, Steve Holden schreef <[EMAIL PROTECTED]>:
> > Antoon Pardon wrote:
> > [...]
> >>>"A foolish consistency is the hobgoblin of little minds". Rules are made 
> >>>to be broken.
> >> 
> >> 
> >> Like only use immutables as dictionary keys.
> >> 
> > Fair enough, but don;t go advising newbies to do this.
> 
> How about something like this.
> 
> Because of the extra precautions one has to take when
> using mutables as hash keys, we advise newbies
> to stick with immutable keys until they have gathered
> enough knowledge and experience to adequatly weight
> the pro and cons of a mutable key solution against
> an immutable key solution.

knowledgeable and experienced users know when to ignore the rules.

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
Una buena gran parte del arte del bien hablar consiste en saber mentir con
gracia.
-- Erasmo de Rotterdam. (1469-1536). 


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

Re: List problems in C code ported to Python

2005-01-17 Thread Grant Edwards
On 2005-01-17, Lucas Raab <[EMAIL PROTECTED]> wrote:

> Sorry about that. I had a bad day. First there was the
> migraine and then the fight with my significant other, so
> yesterday was not a good day. I apologize for what I said.

No worries.  As somebody else said, the best way to get help
solving problems is to post as small an example as possible
that exhibits the problem behavior.  This may take a bit of
effort, since problems sometimes go away when you try to
reproduce them in a small example (less than 50 lines or so).
If you can post a small example that doesn't do what you want
it to, I gaurantee that somebody will explain why it doesn't do
what you want and how to fix it.

-- 
Grant Edwards   grante Yow!  LOU GRANT froze
  at   my ASSETS!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Install Python 2.4 on Fedora 3 Core

2005-01-17 Thread Bill
I have less than a week experience on linux, so I am a new newbie.
Python 2.3 came preinstalled.  I installed version 2.4.  All seemed to
go well except it installed to usr/local?

1. Was it wrong to install when logged in as 'root'?  Does it make a
difference?

2. I looked in the package editor and there was no way to uninstall
2.3?  Should I?  If so, how can I?  If not,what are the problems, if
any, of having both.

Thank you for your help.

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


Re: Native widgets for Python

2005-01-17 Thread Steve Holden
Tim Heaney wrote:
Stephen Thorne <[EMAIL PROTECTED]> writes:
there's someone writing 'dabo', which is apparently "wxpython but
more python".

It looks like dabo uses, not replaces, wxPython
  http://dabodev.com/about
Actually I think it *layers* wxPython, with the intention of being able 
to replace wxPython with other GUI kits at a later date. So, there 
should be a simpler graphical API, but since I haven't yet done more 
than dabble (dabole?) with dabo I can't be sure.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: lambda

2005-01-17 Thread Just
In article <[EMAIL PROTECTED]>,
 Antoon Pardon <[EMAIL PROTECTED]> wrote:

> >> I don't see a big difference between these principles
> >> and the hash key principle,
> >
> > Than you haven't looked hard enough.
> 
> All of these can get unexpected behaviour because of the
> assignment-doesn't-copy semantics. The same semantics
> that can cause problems if you work with mutable dictionary
> keys.

Again, the difference is:

  1. assigning mutable objects *can* cause unexpected behavior
 (however, it's a useful feature, everyone using Python
 for longer than a day or two knows this, and then it's
 *expected* behavior.

  2. mutating dict keys *does* *always* cause problems.
 (unless you use an identity hash/cmp)

It's nonsense to forbid 1) since it's a useful feature. It's useful to 
forbid ("discourage") 2) since mutating dict keys is seldom useful (and 
when it is, Python lets you support it in your own objects).

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


Re: Install Python 2.4 on Fedora 3 Core

2005-01-17 Thread Fredrik Lundh
"Bill" <[EMAIL PROTECTED]> wrote:

> 2. I looked in the package editor and there was no way to uninstall
> 2.3?  Should I?  If so, how can I?  If not,what are the problems, if
> any, of having both.

if your OS comes with Python, there's a certain chance that it includes
utilities that rely on a specific Python version.  removing or replacing that
version is usually a rather bad idea.

having multiple Python installations on a machine is usually no problem
at all.

 



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


Re: List problems in C code ported to Python

2005-01-17 Thread Lucas Raab
Lucas Raab wrote:
I'm done porting the C code, but now when running the script I 
continually run into problems with lists. I tried appending and 
extending the lists, but with no avail. Any help is much appreciated 
Please see both the Python and C code at 
http://home.earthlink.net/~lvraab. The two files are ENIGMA.C and engima.py

TIA
OK, here's the Python code and the corresponding C code:
def init_mach():
import string
#setup rotor data
i=1
j=0
for j in j<26, j+1:
data[4],[j] = (ref_rotor[j] - 'A'+26) % 26

for i in i<4, i+1:
step[i-1] = step_data[order[i-1]]
for j in j<26, j+1:
data[i],[j] = (rotor[order[i-1]],[j]-'A'+26)%26
data[8-i],[data[i],[j]] = j
void
init_mach( void )
{
  int i, j;
  int ds;
  int u, v;
  /* setup rotor data */
  for (j=0;j<26;j++)
data[4][j] = ((int)ref_rotor[j]-'A'+26)%26;
  for (i=1;i<4;i++)
{
  step[i-1] = step_data[order[i-1]];
  for (j=0;j<26;j++)
{
  data[i][j] = ((int)(rotor[order[i-1]][j])-'A' + 26) % 26;
  data[8-i][data[i][j]] = j;
}
}
Now, do I need to start boning up on lists and how to use them or am I 
missing the bigger picture?? Again, for the complete code see 
http://home.earthlink.net/~lvraab. I'm not asking you to do it for me, 
just some pointers on going about this.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Native widgets for Python

2005-01-17 Thread Ed Leafe
On Jan 17, 2005, at 10:19 AM, Steve Holden wrote:
It looks like dabo uses, not replaces, wxPython
  http://dabodev.com/about
Actually I think it *layers* wxPython, with the intention of being 
able to replace wxPython with other GUI kits at a later date. So, 
there should be a simpler graphical API, but since I haven't yet done 
more than dabble (dabole?) with dabo I can't be sure.
	That's correct. We are basing the UI on wxPython initially, but 
wrapping wx for two reasons: to make it simpler to code UIs, and to 
make it possible to use other UI toolkits instead of wx. The first 
reason is by far the more important of the two, but an eventual goal 
for Dabo post-1.0 release (we're at 0.3 now!) will be to allow TkInter 
and other toolkits to be used as well.

 ___/
/
   __/
  /
 /
 Ed Leafe
 http://leafe.com/
 http://dabodev.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: lambda

2005-01-17 Thread Antoon Pardon
Op 2005-01-17, John Lenton schreef <[EMAIL PROTECTED]>:
>
>
> --vni90+aGYgRvsTuO
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
> Content-Transfer-Encoding: quoted-printable
>
> On Mon, Jan 17, 2005 at 11:41:20AM +, Antoon Pardon wrote:
>> Op 2005-01-17, Steve Holden schreef <[EMAIL PROTECTED]>:
>> > Antoon Pardon wrote:
>> > [...]
>> >>>"A foolish consistency is the hobgoblin of little minds". Rules are ma=
> de=20
>> >>>to be broken.
>> >>=20
>> >>=20
>> >> Like only use immutables as dictionary keys.
>> >>=20
>> > Fair enough, but don;t go advising newbies to do this.
>>=20
>> How about something like this.
>>=20
>> Because of the extra precautions one has to take when
>> using mutables as hash keys, we advise newbies
>> to stick with immutable keys until they have gathered
>> enough knowledge and experience to adequatly weight
>> the pro and cons of a mutable key solution against
>> an immutable key solution.
>
> knowledgeable and experienced users know when to ignore the rules.

Then why seems there to be so few acknowledgement that these rules
may indeed be broken by users. My experience is that anyone who suggests
so runs the risk of being branded a (python) heretic.

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


Re: Install Python 2.4 on Fedora 3 Core

2005-01-17 Thread rbt
Bill wrote:
I have less than a week experience on linux, so I am a new newbie.
Python 2.3 came preinstalled.  I installed version 2.4.  All seemed to
go well except it installed to usr/local?
1. Was it wrong to install when logged in as 'root'?  Does it make a
difference?
2. I looked in the package editor and there was no way to uninstall
2.3?  Should I?  If so, how can I?  If not,what are the problems, if
any, of having both.
Thank you for your help.
Bill,
/usr/local is the path on Unix systems where add-on software is 
traditionally installed. RH used to use Python heavily for many aspects 
of their RHL distribution. I suspect they still do this with Fedora. 
This is probably why the version of Python that came with Fedore cannot 
be removed (at least not easily).

It's OK to have the RH version and the latest Python.org version 
installed. You'll just have to specify the path to the version you wish 
to use when running your scripts like this:

/usr/local/python 
There are some more advanced things you could do and I suspect others 
will give you better advice. But all in all, you're OK.

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


Central New Jersey PIG Meeting -- Python Interest Group In Princeton PIG/IP

2005-01-17 Thread [EMAIL PROTECTED]
Central New Jersey PIG Meeting -- Python Interest Group In Princeton
PIG/IP

PIG/IP will hold its first meeting on Jan 19, 2005 at the Lawrenceville
Library (Room #3). Jon Fox will speak about Python's 2.4 release and
then open discussion about Python will be encouraged.

When:
Wednesday, January 19, 2005 at 7:00 PM

Where:
Mercer County Library Lawrenceville Branch
2751 Brunswick Pike
Lawrenceville, NJ 08648
882-9246
Map and directions at http://www.lugip.org/meeting/location/

For more information about this group
http://python.meetup.com/156/
or email 
Jon Fox at [EMAIL PROTECTED]

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


Re: lambda

2005-01-17 Thread Steve Holden
Antoon Pardon wrote:
Op 2005-01-17, Steve Holden schreef <[EMAIL PROTECTED]>:
Antoon Pardon wrote:

I don't see a big difference between these principles
and the hash key principle, so in the end may be we
should just stick with the more general principle:
 Don't use mutables!
and be done with it.
http://redwing.hutman.net/~mreed/warriorshtm/tirelessrebutter.htm
regards
 Steve

I you want to play it like this
http://redwing.hutman.net/~mreed/warriorshtm/crybaby.htm
Hey, I'm not crying, or trying to play it any particular way. It's a 
free Internet, and you are (more than) welcome to your opinions. 
Personally I'd say I'm actually more of a combination of 
http://redwing.hutman.net/~mreed/warriorshtm/diplomat.htm and 
http://redwing.hutman.net/~mreed/warriorshtm/evilclown.htm, with added 
touches of http://redwing.hutman.net/~mreed/warriorshtm/garble.htm and 
possibly http://redwing.hutman.net/~mreed/warriorshtm/toxicgranny.htm

Whereas I also detect touches of 
http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm in your 
posts. It must be nice to *never* be wrong :-). Your resemblance to 
http://redwing.hutman.net/~mreed/warriorshtm/filibuster.htm, however, 
makes me wish you could be right rather more succinctly.

Mostly, though, I was trying to say that I found your nitpicking 
insistence on terminological exactitude, even when giving advice to 
those new to the language, both inappropriate and tedious in the extreme.

Have a nice day :-)
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Integration with java (Jpype vs. JPE)

2005-01-17 Thread Istvan Albert
Cameron Laird wrote:
Someone really ought to include a couple of sentences to that effect
on the front page of http://jpype.sf.net/ >.
Now I remember visiting this site, but never understood how it
actually worked. Examples such as:
from jpype import *
startJVM("d:/tools/j2sdk/jre/bin/client/jvm.dll", "-ea")
java.lang.System.out.println("hello world")
shutdownJVM()
in three different versions are the only code examples
that to show "complete" working snippets. I'm still
clueless as to how would one say share a list between
python and java.
Istvan.
--
http://mail.python.org/mailman/listinfo/python-list


pychecker - sets.Set need to be overridden

2005-01-17 Thread Istvan Albert
Hello all,
if I have this code:
import sets
class Foo:
x = sets.Set()
then pychecker says:
test.py:4: Methods (__cmp__, __hash__) in sets.Set need to be overridden in a 
subclass
I don't get this message. What is it trying to say, and why?
Istvan.
--
http://mail.python.org/mailman/listinfo/python-list


Re: dynamic data types

2005-01-17 Thread beliavsky
rbt wrote:

>I've always thought of it like this... in C, we have to do something
>like this when declaring a variable:

>int x = 0;

>We had to specifically tell the language compiler that x is an
integer.
>In Python, all we have to do is:

>x = 0

>The interpretor knows that x is an integer. We can also change the
type
>like this:

>str(x)
>float(x)
>long(x)

Just to clarify, str(x) does not change x, but

x = str(x)

does. Probably rbt knows this. I wonder how often this feature should
be employed. In my Python programs, most variables keep the same type
throughout. This makes a code easier for me to understand, and this
constraint should facilitate translation of the code to a statically
typed language (perhaps even a variant of Python) in the future, if
necessary.

The ability to grow a list with "append" is a very convenient feature
of Python. The C++ vector is similar but stores elements of the same
type, whereas a Python list or tuple can store elements of different
types.

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


Re: strange note in fcntl docs

2005-01-17 Thread Skip Montanaro

John> In the fnctl docs for both python 2.3 and 2.4 there is a note at
John> the bottom that says

John> The os.open() function supports locking flags and is available on
John> a wider variety of platforms than the lockf() and flock()
John> functions, providing a more platform-independent file locking
John> facility.

John> however, in neither of those versions does os.open support any
John> kind of mysterious "locking flags", nor is there any reference in
John> os to any kind of locking magic (nor do any C open()s I know of
John> support any kind of locking semantics). The note seems bogus; am I
John> missing something, or should it be elided?

I could have sworn that os.open supported the O_SHLOCK and O_EXLOCK flags.
I'm pretty sure I've used them in the past, but don't see them now.  (They
aren't in 2.2 either.)

If you try this:

O_SHLOCK = 0x0010
O_EXLOCK = 0x0020

(those are the definitions on my Mac - YMMV) does

os.open("somefile", O_SHLOCK|)

work?

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


help with wxSlider & wxPython

2005-01-17 Thread Scott
I have the code below.  I have changed the background of the frame to
white, but I cannot get the wxSlider to not be the ugly gray color.
Can someone tell me how to change it to a transparent background (I
tried wxTRANSPARENT_WINDOW without success)?

import os
from wxPython.wx import *
ID_ABOUT=101
ID_EXIT=110
class MainWindow(wxFrame):
def __init__(self,parent,id,title):
wxFrame.__init__(self,parent,wxID_ANY, title, size = (
800,600),style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
#self.control = wxTextCtrl(self, 1, style=wxTE_MULTILINE)
wxStaticText(self, -1, "Distance to Move", (30, 40))
slider = wxSlider(self, 100, 25, 0, 3600, (30, 60), (400,
-1),wxSL_HORIZONTAL | wxSL_TOP | wxSL_AUTOTICKS | wxSL_LABELS |
wxTRANSPARENT_WINDOW)
slider.SetTickFreq(1, 1)
slider.SetValue(1800)
self.CreateStatusBar() # A StatusBar in the bottom of the
window
# Setting up the menu.
filemenu= wxMenu()
filemenu.Append(ID_ABOUT, "&About"," Version 001")
filemenu.AppendSeparator()
filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
# Creating the menubar.
menuBar = wxMenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the
MenuBar
self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame
content.
EVT_MENU(self, ID_ABOUT, self.OnAbout) # attach the menu-event
ID_ABOUT to the
EVT_MENU(self, ID_EXIT, self.OnExit)   # attach the menu-event
ID_EXIT to the
self.SetBackgroundColour(wxWHITE)
self.Show(true)
self.Center(wxBOTH)
def OnAbout(self,e):
d= wxMessageDialog( self, "test","About test", wxOK)
d.ShowModal() # Shows it
d.Destroy() # finally destroy it when finished.
def OnExit(self,e):
self.Close(true)  # Close the frame.
app = wxPySimpleApp()
frame = MainWindow(None, -1, "test")
app.MainLoop()

TIA,
Scott

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


Re: pychecker - sets.Set need to be overridden

2005-01-17 Thread [EMAIL PROTECTED]
mport sets

class Foo:
def __init__(self):
self.x = sets.Set()

x = Foo()
print x, getattr(x, 'x')

gives for me:
<__main__.Foo instance at 0x00C578A0> Set([])
on 2.4. on WinXP. What environment do you run in?

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


Re: pychecker - sets.Set need to be overridden

2005-01-17 Thread Istvan Albert
[EMAIL PROTECTED] wrote:
<__main__.Foo instance at 0x00C578A0> Set([])
on 2.4. on WinXP. What environment do you run in?
I'm running it on cygwin,
but still don't get it, why the warning?
Istvan.
--
http://mail.python.org/mailman/listinfo/python-list


Re: List problems in C code ported to Python

2005-01-17 Thread [EMAIL PROTECTED]
l = []
for i in range(2):
for j in range(2):
l[i],[j] = 0
print l

gives

Traceback (most recent call last):
File "C:\TEMP\test.py", line 75, in -toplevel-
l[i],[j] = 0
TypeError: unpack non-sequence
That's why your current code needs a matrix class.

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


Re: Integration with java (Jpype vs. JPE)

2005-01-17 Thread Jan Dries
Istvan Albert wrote:
Now I remember visiting this site, but never understood how it
actually worked. Examples such as:
from jpype import *
startJVM("d:/tools/j2sdk/jre/bin/client/jvm.dll", "-ea")
java.lang.System.out.println("hello world")
shutdownJVM()
in three different versions are the only code examples
that to show "complete" working snippets. I'm still
clueless as to how would one say share a list between
python and java.
A while ago there was a thread in c.l.p about using JPype to access JMS 
from within Python. IIRC someone then contributed a more elaborate real 
life example of how to do this. Search Google Groups for more details.

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


how to find site-packages path

2005-01-17 Thread Philippe C. Martin
Hi,

I am using my own install script for my software and am looking for a
flawless way to figure out where python, and more specifically
site-packages is installed.

Any clue ?

Regards,

Philippe



-- 
***
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
***

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


Re: pychecker - sets.Set need to be overridden

2005-01-17 Thread Peter Otten
Istvan Albert wrote:

> if I have this code:
> 
> import sets
> 
> class Foo:
>  x = sets.Set()
> 
> then pychecker says:
> 
> test.py:4: Methods (__cmp__, __hash__) in sets.Set need to be overridden
> in a subclass
> 
> I don't get this message. What is it trying to say, and why?

The minimal example is actually

import sets
sets.Set()

The Set class has implementations for __cmp__() and __hash__() that
unconditionally raise an exception. pychecker assumes that these methods
are "abstract", i. e. meant to be overriden by a subclass, and warns that
you are instantiating an abstract base class, while the intention of the
Set class author was to make Sets "uncomparable" and unhashable by
overriding the corresponding superclass methods.

Peter

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


Re: List problems in C code ported to Python

2005-01-17 Thread Grant Edwards
On 2005-01-17, Lucas Raab <[EMAIL PROTECTED]> wrote:

>  data[4][j] = ((int)ref_rotor[j]-'A'+26)%26;


>   data[4],[j] = (ref_rotor[j] - 'A'+26) % 26
   ^
The comma shouldn't be there.

 C: data[4][j]
Python: data[4][j]

> Now, do I need to start boning up on lists and how to use them

Sort of.  I think you mostly just need to sit down and
proofread your code.

I would also advise building your Python app in smaller steps.
Translate one function, and test it to make sure it works. Then
translate the next function and test it to make sure it works.
Then the next function, etc.

-- 
Grant Edwards   grante Yow!  My ELBOW is a remote
  at   FRENCH OUTPOST!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pychecker - sets.Set need to be overridden

2005-01-17 Thread [EMAIL PROTECTED]
I don't know pychecker, maybe there's something wrong with it as your
code seems valid to me.

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


Re: how to stop google from messing Python code

2005-01-17 Thread Fredrik Lundh
Fuzzyman wrote:

>> if you have internet access, you have NNTP access.  gmane.org provides access
>> to more than 6,500 mailing lists via NNTP, including all relevant Python 
>> forums.
>
> Not if you're behind a censoring proxy that blocks everything except
> http.  This is a situation many people find themselves in.

If you have HTTP-only access, you don't have Internet access.  But even if you
have HTTP-only access, you can use gmane's various web interfaces.  (Had you
visited the site, you'd known this already)

 



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


Re: List problems in C code ported to Python

2005-01-17 Thread [EMAIL PROTECTED]
>>> l = []
>>> for i in range(2):
for j in range(2):
l[i][j] = 'x'



Traceback (most recent call last):
File "", line 3, in -toplevel-
l[i][j] = 'x'
IndexError: list index out of range

So you still have to dimension the list before you can use it , eg like
>l = []
>for i in range(2):
>l.append([])
>for j in range(2):
>l[i].append(j)

then you do not get the indexerror, but I feel a class is what you need
here to make life easier and the program more readable

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


Re: directory bug on linux; workaround?

2005-01-17 Thread Ewald R. de Wit
Russell E. Owen wrote:
> It seems that the path was to a "fat" file partition and included a 
> directory name that was all uppercase. The directory was created, but 
> using lowercase. I'm not yet sure the version of python.
>
> The workaround for now is to not use fat file partitions. But I was 
> wondering if anyone had a better option?

You can mount the FAT partition with the 'shortname' argument, i.e.
put something like 

/dev/sda1 /usbkey auto 
umask=0,user,iocharset=iso8859-1,sync,kudzu,codepage=850,noauto,exec,users,shortname=winnt,check=s
 0 0

in your /etc/fstab

Btw, this is a general Linux problem and is not really related to
Python (it also happens when working with shells or filemanagers).

-- 
  --  Ewald

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


How to prevent the script from stopping before it should

2005-01-17 Thread python
I have a script that downloads some webpages.The problem is that,
sometimes, after I download few pages the script hangs( stops).
(But sometimes it finishes in an  excellent way ( to the end) and
download all the pages I want to)
I think the script stops if the internet connection to the server (from
where I download the pages) is rather poor.
Is there a solution how to prevent the script from hanging before all
pages are downloaded?

Thanks for help
Lad.

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


RE: How to prevent the script from stopping before it should

2005-01-17 Thread Batista, Facundo
Title: RE: How to prevent the script from stopping before it should





[EMAIL PROTECTED]


#- I have a script that downloads some webpages.The problem is that,
#- sometimes, after I download few pages the script hangs( stops).


What do you mean with "hangs"? 


It raises an error and quit? It just stops doing nothing? If the latter, what prints if you hit ctrl-c?


.    Facundo


Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/



  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



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

Re: platform independent kbhit()

2005-01-17 Thread Scott David Daniels
Hans Georg Krauthaeuser wrote:
I use msvcrt.kbhit() to check for a user keyboard event on windows. But 
now, I would prefer to make the module independent from the platform 
used. 
This is not in general possible; many machines do not have keyboards.
You can, perhaps, build one for yourself from a pair of implementations
or more.  Portable software seldom comes from adding one platform at a
time that the software works on.  Portable software comes from working
using only features common (or in rare circumstances available) on all
machines in your target set, and then adding enough tests to believe
the portability.  CPython starts with the C89-supported environment as
its base.  It tries hard to stick to that abstract machine.  I assume
Jython does a similar thing using Java VM semantics that it trusts will
be common across implementations.
> I already know that I can use curses (on linux/unix) or Tkinter.
Also, I  found this http://my.execpc.com/~geezer/software/kbhit.c C 
source that has a kbhit() and a getch() for linux/unix that I can SWIG 
to python.
Either of these might be a good basis for your personal "all machines I
care about" semantics.  If you use curses, make sure it doesn't impose
an extra constraint on all terminal access.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to prevent the script from stopping before it should

2005-01-17 Thread [EMAIL PROTECTED]
#import urllib, sys
#pages = ['http://www.python.org', 'http://xxx']
#for i in pages:
#   try:
#u = urllib.urlopen(i)
#print u.geturl()
#except Exception, e:
#print >> sys.stderr, '%s: %s' % (e.__class__.__name__, e)
will print an error if a page fails opening, rest opens fine

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


Re: PyChecker messages

2005-01-17 Thread Ben Sizer
But you could use a dict of return values, or even just assigning a
different return value in each if clause. The end result is that you
have a single well-defined exit point from the function, which is
generally considered to be preferable.

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


Re: Producer/consumer Queue "trick"

2005-01-17 Thread Evan Simpson
I should clarify up front that I may have given an overblown sense of 
how long the producer thread typically takes to generate a board; It's 
usually a few tenths of a second, up to a few seconds for especially 
fecund boards.

My concern was that even a few seconds is long enough for fifty requests 
to get piled up, and I was experiencing mysterious breakdowns where 
Apache was suddenly totally clogged up and taking *minutes* to respond.

Jeremy Bowers wrote:
Looking over your information about "how to play", my only guess is that
you're generating all possible words that may exist in the board, at the
time of board generation.
Yep.  I do this in order to minimize the cost of the most common request 
that WEBoggle handles, which is checking a submitted word to see whether 
it is a valid word on the board, a valid word not on the board, or an 
invalid word.  With the current code, this averages 1ms.

But it also looks like you score once at the end (as you have to anyhow in
order to cancel out words found by multiple people, according to the rules
of Boggle). 
WEBoggle is a little different than regular Boggle, in that your score 
is the plain sum of the scores for all of the words that you found, with 
no cancellation.  I'm planning to add a "vs." feature eventually that 
will involve cancellation, but even then I'll retain the immediate 
feedback upon guessing a word.

In addition, many players enjoy seeing the list of "Words not found by 
anyone".

(The other thing I can think of is that you are trying to verify that the
board contains some minimal number of words, in which case I submit that
boards with only 20-ish words is just part of the game :-) I've never sat
down and really studied the Boggle dice, but I've always expected/hoped
that there is at least one or two dice with all vowels; even so the odds
of no vowels are small and easily algorithmically discarded. )
Believe it or not, before I added code to filter them out, I was 
generating enough boards with *zero* valid words on them to get complaints.

Also, entirely separate plug, you may be interested in my XBLinJS project
Very nifty!  Well beyond my current needs, but good to know about.
Cheers,
Evan @ 4-am
--
http://mail.python.org/mailman/listinfo/python-list


Re: [perl-python] 20050116 defining a function

2005-01-17 Thread Xah Lee
errata:

* the variables in the perl section should be declared inside the
subroutine.
* the @_[0] should've been $_[0]

thanks for Dave Cross for pointing them out.

* the Mathematica Apply should be Select...
Xah
 [EMAIL PROTECTED]
 http://xahlee.org/PageTwo_dir/more.html

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


Re: how to find site-packages path

2005-01-17 Thread vincent wehren
Philippe C. Martin wrote:
Hi,
I am using my own install script for my software and am looking for a
flawless way to figure out where python, and more specifically
site-packages is installed.
You can take a look at how this is done in Lib/site.py.
Look for the bit of code that starts with
prefixes = [sys.prefix]
sitedir = None # make sure sitedir is initialized because of later 'del'
...
etc.
--
Vincent Wehren

Any clue ?
Regards,
Philippe

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


Re: Central New Jersey PIG Meeting -- Python Interest Group In Princeton PIG/IP

2005-01-17 Thread Jay Loden
Are visitors welcome?  I just happen to be in NJ, and I would like to attend 
my first PIG/IP Also, are you related in any way to LUG/IP?

-Jay

On Monday 17 January 2005 10:36, [EMAIL PROTECTED] wrote:
> Central New Jersey PIG Meeting -- Python Interest Group In Princeton
> PIG/IP
>
> PIG/IP will hold its first meeting on Jan 19, 2005 at the Lawrenceville
> Library (Room #3). Jon Fox will speak about Python's 2.4 release and
> then open discussion about Python will be encouraged.
>
> When:
> Wednesday, January 19, 2005 at 7:00 PM
>
> Where:
> Mercer County Library Lawrenceville Branch
> 2751 Brunswick Pike
> Lawrenceville, NJ 08648
> 882-9246
> Map and directions at http://www.lugip.org/meeting/location/
>
> For more information about this group
> http://python.meetup.com/156/
> or email
> Jon Fox at [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [perl-python] 20050117, filter, map

2005-01-17 Thread Xah Lee
erratum:

the Mathematica Apply should've been Select.
...

 Xah
 [EMAIL PROTECTED]
 http://xahlee.org/PageTwo_dir/more.html

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


Re: [perl-python] 20050117, filter, map

2005-01-17 Thread Xah Lee
erratum:

the Mathematica Apply should've been Select.
...

 Xah
 [EMAIL PROTECTED]
 http://xahlee.org/PageTwo_dir/more.html

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


Re: Producer/consumer Queue "trick"

2005-01-17 Thread Evan Simpson
Jon Perez wrote:
If the consumer and the producer are separate threads,
why does the consumer thread block when the producer
thread is generating a new board?  Or why does it
take forever for the producer thread to be pre-empted?
Also, I don't understand why the solution works.
How does sleeping for .001 seconds right after putting
a new board on the queue solve the problem?
I'm guessing at how things work, and may be totally wrong, but here's 
what I think happens:  In the Queue get() code, the consumer releases 
the 'fsema' lock. Directly or indirectly, this wakes up and hands 
control to the producer thread, which was blocked trying to acquire 
'fsema'. The sleep() hands control back to the scheduler immediately, 
which appears to wake up the consumer and let it get on with things.

It doesn't take "forever" for the producer to be preempted, just the 
normal preemption interval.  I was bothered, though,  by the idea of 
having it take even a few dozen milliseconds out of the middle of a 
request that's at most a millisecond or two away from finishing anyway.

Cheers,
Evan @ 4-am
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to prevent the script from stopping before it should

2005-01-17 Thread Steve Holden
[EMAIL PROTECTED] wrote:
#import urllib, sys
#pages = ['http://www.python.org', 'http://xxx']
#for i in pages:
#   try:
#u = urllib.urlopen(i)
#print u.geturl()
#except Exception, e:
#print >> sys.stderr, '%s: %s' % (e.__class__.__name__, e)
will print an error if a page fails opening, rest opens fine
More generally you may wish to use the timeout features of TCP sockets. 
These were introduced in Python 2.3, though Tim O'Malley's module 
"timeoutsocket" (which was the inspiration for the 2.3 upgrade) was 
available for earlier versions.

You will need to import the socket module and then call 
socket.setdefaulttimeout() to ensure that communication with 
non-responsive servers results in a socket exception that you can trap.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: strange note in fcntl docs

2005-01-17 Thread Skip Montanaro

Skip> I could have sworn that os.open supported the O_SHLOCK and
Skip> O_EXLOCK flags.

I submitted a patch to posixmodule.c for these:

http://python.org/sf/1103951

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


  1   2   >