Re: Python becoming less Lisp-like

2005-03-21 Thread Antoon Pardon
Op 2005-03-18, Jeff Shannon schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
 Op 2005-03-16, Jeff Shannon schreef [EMAIL PROTECTED]:
 
Bruno Desthuilliers wrote:

- if x is a class attribute of class A and a is an instance of A, 
a.x=anyvalue create a new instance attribute x instead of modifying A.x

This is very consistent with the way that binding a name in any scope 
will shadow any bindings of that name in higher scopes.  It is the 
same principle by which one is able to use the same name for a 
function-local variable that is used for a global variable, without 
destroying that global variable.  [...]
 
 Not entirely. The equivallent is imposible in function scope.
 If function scope would work exactly equivallent as the
 above the following should work 
 
 a = 42
 def f():
   a = a + 1
   print a
 print a
 
 And the result should be:
 
 43
 42
 

 I'd still say that the name binding rules are very consistent.  The 
 name lookup rules are a little different (as they *should* be for 
 class/instance attributes),

Why should they? 

 and that's why there's a different net 
 effect (UnboundLocalError) as shown in your example.  I'd say, 
 however, that if there's a special case here it's with the 
 function-local variables, not the class/instance attributes.

Which is the special case and which is the normal case is not
that important here. The fact is that they behave different,
so you can't claim it is very consistent.

I'm getting the impression that 'consistent' just means:
that is how python works, on this newsgroup.

 It's the 
 optimizations to the function-local namespace which prevent 
 transparent re-binding of global names.  And given that the 
 function-local namespace is by far the most heavily used, and the 
 relative utility (and wisdom) of using globals in this way, this is a 
 case where the benefit of the special case is well worth the cost of 
 its slight inconsistency.

I find it odd that you start by saying you still find them very
consistent and here state there is a slight inconsistency.

It seems we mean different things with very consistent

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


Re: Text-to-speech

2005-03-21 Thread Miki Tebeka
Hello Charles,

 Does anyone know of a cross-platform (OSX and Windows at least) library 
 for text-to-speech? I know  there's an OSX API, and probably also for 
 Windows. I know PyTTS exists, but it seems to talk only to the Windows 
 engine. I'd like to write a single Python module to handle this on both 
 platforms, but I guess I'm asking too much -- it's too hardware 
 dependent, I suppose. Any hints?
Maybe you can bind Festival
(http://www.cstr.ed.ac.uk/projects/festival/download.html) with SWIG.

HTH.
--

Miki Tebeka [EMAIL PROTECTED]
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys



pgpPzYcyektit.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

missing? dictionary methods

2005-03-21 Thread Antoon Pardon
Well at least I find them missing.

For the moment I frequently come across the following cases.

1) Two files, each with key-value pairs for the same dictionary.
However it is an error if the second file contains a key that
was not in the first file.

In treating the second file I miss a 'set' method.
dct.set(key, value) would be equivallent to dct[key] = value,
except that it would raise a KeyError if the key wasn't
already in the dictionary.


2) One file with key-value pairs. However it is an error
if a key is duplicated in the file.

In treating such files I miss a 'make' method.
dct.make(key, value) would be equivallent to dct[key] = value.
except that it would raise a KeyError if the key was
already in the dictionary.


What do other people think about this?

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


Re: simultaneous copy to multiple media

2005-03-21 Thread Claudio Grondi
 Try this:
   http://mastermind.com.pl/multicopy/

 This is small tool I've wrote, that does use large memory buffers with
 asynchronous I/O to copy file.

Thank you!
This (with a drawback of blocking the entire system) does it!
( dzieñ dobry i dziêkujê za t± konstruktywn± odpowied¼
na moje pytanie )

At least I know, that it works and you explain how it works,
so I am now quite sure, that it will be also possible to have
a Python tool which does the same thing.
This way the discussion going towards driver hacking for
the USB access was in my case just the wrong way, but
anyway, thanks also for that to the contributors, because it
sharpened my understanding of USB.

Here my current test results on my Windows 2000 system
with a 2.8 GHz P4 CPU and two 5 1/4 IDE-USB 2.0 casings
(I have got from http://www.computeruniverse.net/ a German
online shop, article no.: 90052509)
by the way:
  does someone know an IDE-USB case able
  to perform data transfer faster than the
  max. 20 MByte/s I experience with one of my
  another IDE-USB 5 1/4 casings?
?
) :
Single file copy:
  USB-1 to USB-2 = 11 MB/s, max. 70% CPU
  USB-2 to USB-1 = 11 MB/s, max. 70% CPU
  E-IDE to USB-1 = 12 MB/s, max. 70% CPU (first  time)
  E-IDE to USB-1 = 13 MB/s, max. 70% CPU (second time same file)
  E-IDE to E-IDE  = max. 45 MB/s  (two physical drives)

Simultaneous file copy:
  USB-1 to USB-2 =  5 MB/s
  USB-2 to USB-1 =  7 MB/s
   ---
   12 MB/s, max. 80% CPU

Simultaneous file copy using
http://mastermind.com.pl/multicopy/release/1.0.0/multicopy.exe :
  E-IDE to USB-1 = 10 MB/s
  E-IDE to USB-2 = 10 MB/s
   ---
   20 MB/s, unknown CPU load (1)

(1) work with the PC during copying not possible,
  system hangs from 5 to 15 seconds between
  e.g. displaying current system time (with
Windows clock).

From my point of view this thread has reached
its end (I have a solution I can live with), except if
someone would like to contribute or point to a
better multicopy.exe which does not block the system
or best to contribute or point to a _Python_ script or
module which is able to find out the optimal buffer
size for copying on the
current system (and the best way of copying files),
so that after this information is saved in an .INI file
the tool is best adopted to the system it works on.

I am quite sure, that there is a perfect ready-to-use
solution out there (up to now I just only failed to find
one by Googling, e.g. the tee.exe provided by
http://unxutils.sourceforge.net/ doesn't work with
large files at all), so please don't hesitate to provide
it, so, that I don't need to reinvent the wheel.

Claudio

Jacek Trzmiel [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]

 Claudio Grondi wrote:
  I am on a Widows 2000 box using the NTFS file system.
  Both up to now suggested approaches as
  - tee.exe (where I used the http://david.tribble.com/dos/tee.exe
  DOS-port with redirecting stdout to NULL) and
  - parallel copy (hoping caching does the job) are by far
  slower than the consecutive copy:
single copy speed 12-15 MByte/s
  which gives effectively
6-7 MByte/s,
tee.exe or twice copy in parallel
1-3 MByte/s.
 
  Any other suggestions except writing an own
  optimised version of tee.exe

 Try this:
   http://mastermind.com.pl/multicopy/

 This is small tool I've wrote, that does use large memory buffers with
 asynchronous I/O to copy file.

 Following command:
   multicopy c:\testfile d:\testfile e:\testfile f:\testfile
 will copy c:\testfile to d, e and f disks.

 With four separate IDE disks I can copy file at about 30MB/s, which
 means 120MB/s total I/O.  You can give it a try, but I don't know if it
 will work fast with USB drives.

 HTH,
 sc0rp.


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


Re: Python becoming less Lisp-like

2005-03-21 Thread Antoon Pardon
Op 2005-03-18, Bengt Richter schreef [EMAIL PROTECTED]:

 [ ... ]

 BTW, I would like a re-assign or find-and-rebind operation spelled := which 
 would
 make x := 123 mean look for x as if to read its value in a right hand side 
 expression,
 (except do not look into __builtins__) and wherever found, rebind to 123 -- 
 and if not found,
 raise an exception.

 I think var := 'something' would be a useful substitute for the idiom of
 var[0] = 'something' and be unambiguous.

 := as an operator could combine like op= if desired, so we could write
 var +:= some.long.expression[that].you('do')**not.want.to.type.twice
 instead of
 _ = some.long.expression[that].you('do')**not.want.to.type.twice
 var +:= _  # meaning var := var + _
 or such.

Well you have my support for this. But I have the impression this
differs from the previous time you came up with a similar idea.
If IRC your previous proposal limited the search to the local
scope, making a := b equivallent to something like a; a = b.

I must say I like your current idea better.

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


Re: missing? dictionary methods

2005-03-21 Thread George Sakkis
Antoon Pardon [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Well at least I find them missing.

 For the moment I frequently come across the following cases.

 1) Two files, each with key-value pairs for the same dictionary.
 However it is an error if the second file contains a key that
 was not in the first file.

 In treating the second file I miss a 'set' method.
 dct.set(key, value) would be equivallent to dct[key] = value,
 except that it would raise a KeyError if the key wasn't
 already in the dictionary.


 2) One file with key-value pairs. However it is an error
 if a key is duplicated in the file.

 In treating such files I miss a 'make' method.
 dct.make(key, value) would be equivallent to dct[key] = value.
 except that it would raise a KeyError if the key was
 already in the dictionary.


 What do other people think about this?

 -- 
 Antoon Pardon

+1

I'm sure I've needed and implemented this functionality in the past, but it was 
simple enough to
even think of extracting them into functions/methods. In contrast to the recent 
pre-PEP about dict
accumulating methods, set() and make() (or whatever they might be called) are 
meaningful for all
dicts, so they're good candidates for being added to the base dict class.

As for naming, I would suggest reset() instead of set(), to emphasize that the 
key must be there.
make() is ok; other candidates could be add() or put().

George


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


Please help for Python programming

2005-03-21 Thread yy0127
I don't know why i entered the below code and it will miss some
records.
Anyone can help me???

users = {}
users1 = {}


while 1:
user, serviceType, msgType, inOut, date, time, numBytes =
aLog.GetNextMessage()
fullmsg = serviceType + | + msgType + | + inOut
bytemsg = user +   + serviceType +   + msgType +   + inOut +  
+ numBytes

user1 = user

msgDict = {}
byteDict = {}

print bytemsg   # 53 records in source file
msgDict = users[user]   # get the cum statistics for this user
byteDict = users1[user1]
print bytemsg   # 50 records in source file

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


Re: how can I put a 1Gb file in a zipfile??

2005-03-21 Thread Bengt Richter
On Sun, 20 Mar 2005 14:17:20 -0600, Jeff Epler [EMAIL PROTECTED] wrote:


--liOOAslEiF7prFVr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

The limits of ZIP files according to the folks who make info-zip:
http://www.info-zip.org/pub/infozip/FAQ.html#limits

 statistic limit
number of files65,536
uncompressed size of a single file   4 GB
compressed size of a single file 4 GB
total size of archive  256 TB
maximum path/filename length64 KB=20

I had no trouble creating a zip file from a 4GB file filled with '\0'
bytes:
$ python bennie.py
$ ls -ls test.zip big
  12 -rw-rw-r--  1 jepler jepler 4294967296 Mar 20 14:11 big
4084 -rw-rw-r--  1 jepler jepler4174545 Mar 20 14:14 test.zip

I'm using Python 2.3.3 on Fedora Core 2.
#
# bennie.py
def make_4gb_file(f):
f =3D open(f, w)
f.seek ( 4 * 1024 * 1024 * 1024 - 1)
f.write(\0)
f.close()

Not quite OT[?]:
This makes me think there ought to be a way of making at least python's builtin 
open see virtual file system objects,
analogous to StringIO creating file objects.

If we had a mountvfs('/some/unix/and/or/maybe/win/style/path/vfs', 
vfsclass(some, args, if_desired))
which would result in that 
open(/some/unix/and/or/maybe/win/style/path/vfs/morepath/filename.ext', mode)
(where vfsclass(some, args, if_desired) = vsfclass_intance) would call
vfsclass_instance.open('morepath.filename.ext', mode) which could then return 
an object that could support
file operations like returning 4gb of virtually read-by-read-method data, or 
otherwise acting like an open file
object of a real file system that python programs and library function using 
open and file would find
if given the mounted path. Subdirectories could be fixed for starters, but 
virtualizing subdirectory creation
etc would be possible if you intercepted the right interface calls and 
implemented it in the vfs.

This would let you define a virtual file in place of the real file above, and 
also would allow a lot of transparent
testing of file-using software that takes paths and file names, not open file 
objects.

Of course you can't affect what the underlying os sees without getting into its 
file system machinery, but
being able to mount virtual file systems into what os.open sees would cover a 
lot of ground ISTM. One
could argue pro and con about supporting virtual mounts into both unix and 
windows-style paths.

import zipfile
z =3D zipfile.ZipFile(/tmp/test.zip, w, zipfile.ZIP_DEFLATED)
make_4gb_file(/tmp/big)
z.write(/tmp/big)
z.close()
#

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


Re: generating audio signals

2005-03-21 Thread Bengt Richter
On Sun, 20 Mar 2005 12:25:22 +0200, nicke [EMAIL PROTECTED] wrote:

I'm running linux and would like to generate specific frequencies and
play them(in OSS) or alternatively save them as wav files, how should I
accomplish this? Using python to play and generate is not strictly
necessary, as long as I can invoke the command from python.
I know for example xmms can do this, but I want a command-line only solution.

Perhaps
http://docs.python.org/lib/module-wave.html
will help. I used it to create an echo effect toy for my grandson by reading 
existing .wav sound effect
files and adding delayed reduced-aplitude feeback to itself and writing another 
file. Parameters were
distance in feet to a reflecting wall (assuming 1000 ft/sec sound speed ;-) and 
relection volume factor.

Not hard. Maybe make yourself a little utility first that will show you the 
specs for any .wav file (i.e.,
sampling frequency, bytes per sample, channels, etc.) I don't recall at the 
moment whether you have to
deal with signed or offset amplitude values, but it won't be hard.

This won't play the sounds though.

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


Re: HTML editor component?

2005-03-21 Thread Fuzzyman

skol wrote:
 Is there any HTML WYSIWYG editor component available for
 Python/wxPython? Thanks.

I can reccomend Kupu as a javascript one. http://kupu.oscom.org

A WYSIWYG HTML editor is a full blown application - so I'd be surprised
(pleasantly) to see one available as a component.

Regards,

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

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


(,) Do You Want To Know For Sure You Are Going To Heaven?

2005-03-21 Thread Ron038548
http://www.want-to-be-sure.blogspot.com  Click On Link

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


Re: IconvCodec, UTF-32 P4 ?

2005-03-21 Thread Serge Orlov
Do Re Mi chel La Si Do wrote:
 Hi !

 Iconvcodec was good, for to work with UTF-32, with Python 2.3
 But, which tool, for the same use, with Python 2.4  ?
 Thanks for suggestions.

Do you mean it's impossible to build iconvcodec anymore?

  Serge.

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


Re: Please help for Python programming

2005-03-21 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 I don't know why i entered the below code and it will miss some
 records.
 Anyone can help me???

Sorry, my mindreading brain extension is at the service right now, so I
can't guess what that piece of syntactically incorrect code is supposed to
do and what error message it produces.

Until you come up with a more detailed error description, I'll have a good
read at

http://www.catb.org/~esr/faqs/smart-questions.html


Which I suggest you read too.

-- 
Regards,

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


Re: beeping portably

2005-03-21 Thread Bengt Richter
On 20 Mar 2005 09:03:25 -0800, Jim [EMAIL PROTECTED] wrote:

Hello,

I'd like to emit beeps.  The twists are that (1) I hope to have control
over the frequency of the beeps and their duration and (2) I'd like the
solution to be portable across Linux, Windows, and OS X.

I've done some searching of this group and the solutions that people
have offered in the past seem not to satisfy both points. For instance,
that I can tell, \a or curses.beep() doesn't give you control over
the frequency or duration.  I also looked at wxWindows but there were
warnings about the MMedia module (status is unclear) that made me
leery.

for windows, I think it's
http://docs.python.org/lib/module-winsound.html
but I don't know if there's a corresponding *nix module.
Or maybe you can make one just writing to some /dev/somethingorother,
and conditionally set up the appropriate thing for limited
platform-appropriateness if not independence.

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


Re: beeping portably

2005-03-21 Thread Diez B. Roggisch
Jim wrote:

 Hello,
 
 I'd like to emit beeps.  The twists are that (1) I hope to have control
 over the frequency of the beeps and their duration and (2) I'd like the
 solution to be portable across Linux, Windows, and OS X.
 
 I've done some searching of this group and the solutions that people
 have offered in the past seem not to satisfy both points. For instance,
 that I can tell, \a or curses.beep() doesn't give you control over
 the frequency or duration.  I also looked at wxWindows but there were
 warnings about the MMedia module (status is unclear) that made me
 leery.

Maybe pygame helps? You can play sound with it, and the sdl abstracts from
directx and whatever linux uses. 

-- 
Regards,

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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-21 Thread haraldarminmassa
Raymond,

I am +1 for both suggestions, tally and appendlist. 

Extended:
 
 Also, in all of my code base, I've not run across a single opportunity to use
 something like unionset().  This is surprising because I'm the set() author 
 and
 frequently use set based algorithms.Your example was a good one and I can
 also image a graph represented as a dictionary of sets.  Still, I don't mind
 writing out the plain Python for this one if it only comes up once in a blue
 moon.

I am more than sure you are right about this. But, please keep in mind
that you and we all have come very, very accustomed to using lists for
everything and the kitchen sink in Python.

Lists where there from the beginning of Python, and even before the
birth of Python; very powerfull, well implemented and theoretically
well founded datastructures - I heared there is a whole language based
on list processing. *pun intended*

sets on the other hand --- I know, in mathematics they have a deep,
long history. But in programming? Yeah, in SQL and ABAP/4 basically
you are doing set operations on every join. But its rather uncommon to
call it set.

With 2.3 Python grew a set module. And, in ONLY ONE revision it got
promoted to a buildin type - a honour only those who read c.l.p.d.
regualary can value correctly.

And sets are SO NATURALLY for a lot of problems ... I never thought of
replacing my  list in dict constructs with sets before, BUT 
there are 90% of problem domains where order is not important, AND
fast membership testing is a unique sales point.

So please for best impressions: let us have a look at our code, where
we use the
dict.setdefault(key,[]).append() idiom, where it could be replaced to
a better effectivity with dict.setdefault(key,set()).add()

If it is less than 60%, forget it. If it is more 

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


Re: IconvCodec, UTF-32 P4 ?

2005-03-21 Thread Do Re Mi chel La Si Do
re-Hi


When I look  http://cjkpython.i18n.org  I found only binaries for P2.1, P2.2 
 P2.3  (I am on windows)

If I run the P2.3's version, on my Python 2.4 config, the package said that 
he don't found Python2.3.

And, I don't have compiler for work with source.
If benefactor of humanity has do a binary for windows/Python 2.4,  they 
would be fabulous.


Thanks

Michel Claveau



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


Re: missing? dictionary methods

2005-03-21 Thread Robert Kern
Antoon Pardon wrote:
Well at least I find them missing.
For the moment I frequently come across the following cases.
1) Two files, each with key-value pairs for the same dictionary.
However it is an error if the second file contains a key that
was not in the first file.
In treating the second file I miss a 'set' method.
dct.set(key, value) would be equivallent to dct[key] = value,
except that it would raise a KeyError if the key wasn't
already in the dictionary.
2) One file with key-value pairs. However it is an error
if a key is duplicated in the file.
In treating such files I miss a 'make' method.
dct.make(key, value) would be equivallent to dct[key] = value.
except that it would raise a KeyError if the key was
already in the dictionary.
What do other people think about this?
def safeset(dct, key, value):
if key not in dct:
raise KeyError(key)
else:
dct[key] = value
def make(dct, key, value):
if key in dct:
raise KeyError('%r already in dict' % key)
else:
dct[key] = value
I don't see a good reason to make these built in to dict type.
--
Robert Kern
[EMAIL PROTECTED]
In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to create an object instance from a string??

2005-03-21 Thread Do Re Mi chel La Si Do
Hi !

Finally, it's the best solution.

Michel Claveau 


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


Re: Python scope is too complicated

2005-03-21 Thread jfj
Dan Bishop wrote:

x = 17
sum(x for x in xrange(101))
5050
x
17
Your example with generator expressions is interesting.
Even more interesting is:
def foo(x):
 y= (i for i in x)
 return y
From the disassembly it seems that the generator is a code object but
'x' is not a cell variable. WTF?  How do I disassemble the generator?
Must look into this
[ list comprehensions are different because they expand to inlined 
bytecode ]

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


UTF Questions

2005-03-21 Thread Fuzzyman
I have a couple of questions about the UTF encodings.

The codecs module has constants definded for the UTF32 encoding, yet
this encoding isn't supported as a standard encoding. Why isn't it
supported ?

It possibly has something to do with my next question. I know that
unicode has (recently?) been expanded to include new character sets.
This means that the latest unicode standard can't be fully supported
with 2 bytes per character. As far as I know though, Python doesn't
(yet) support the extended version of unicode anyway ? Am I correct ?

Best Reagrds,

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

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


Re: Question about string.printable and non-printable characters

2005-03-21 Thread Sibylle Koczian
Michael Hoffman schrieb:
string.printable is a least-common denominator ASCII set. You can certainly
make it string.printable + aeioun (replacing the ASCII letters with their
accented versions in your codeset of course).
There is something I don't understand about string.printable: on the one 
hand the library reference says This is a combination of digits, 
letters, punctuation, and whitespace. The value of string.letters is 
locale-dependent, so string.printable should change as well after 
calling locale.setlocale(). But it doesn't.

But you could always call locale.setlocale() and afterwards combine your 
printable string yourself.

--
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
Tel.: (0821) 598-2400, Fax : (0821) 598-2410
e-mail : [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: missing? dictionary methods

2005-03-21 Thread Antoon Pardon
Op 2005-03-21, Robert Kern schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
 Well at least I find them missing.
 
 For the moment I frequently come across the following cases.
 
 1) Two files, each with key-value pairs for the same dictionary.
 However it is an error if the second file contains a key that
 was not in the first file.
 
 In treating the second file I miss a 'set' method.
 dct.set(key, value) would be equivallent to dct[key] = value,
 except that it would raise a KeyError if the key wasn't
 already in the dictionary.
 
 
 2) One file with key-value pairs. However it is an error
 if a key is duplicated in the file.
 
 In treating such files I miss a 'make' method.
 dct.make(key, value) would be equivallent to dct[key] = value.
 except that it would raise a KeyError if the key was
 already in the dictionary.
 
 
 What do other people think about this?

 def safeset(dct, key, value):
  if key not in dct:
  raise KeyError(key)
  else:
  dct[key] = value

 def make(dct, key, value):
  if key in dct:
  raise KeyError('%r already in dict' % key)
  else:
  dct[key] = value

 I don't see a good reason to make these built in to dict type.


I would say the same reason that we have get. There is no
reason to have a builtin get it is easily implemented
like this:

  def get(dct, key, default):

try:
  return dct[key]
except KeyError:
  return default


I would go even so far that there is more reason to have a built-in
safeset and make, than there is a reason to have a built-in get.

The reason is that a python implementation of safeset and make,
will mean two accesses in the dictionary, once for the test and
once for the assignment. This double access could be eliminated
with a built-in. The get on the other hand does only one dictionary
access, so having it implemeted in python is a lesser burden.

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


Re: Text-to-speech

2005-03-21 Thread Charles Hartman

Maybe you can bind Festival
(http://www.cstr.ed.ac.uk/projects/festival/download.html) with SWIG.
Presumably somebody could; at this point it's well beyond me. But thank 
you for the suggestion.

Charles Hartman
http://cherry.conncoll.edu/cohar
--
http://mail.python.org/mailman/listinfo/python-list


Re: Text-to-speech

2005-03-21 Thread Martin Franklin
Charles Hartman wrote:

Maybe you can bind Festival
(http://www.cstr.ed.ac.uk/projects/festival/download.html) with SWIG.

Presumably somebody could; at this point it's well beyond me. But thank 
you for the suggestion.

Charles Hartman
http://cherry.conncoll.edu/cohar
There is tkfestival http://ludios.org/programs/tkfestival that uses
expect to control festival, I assume it has a very easy to use CLI
and would be simple to make use of pexpect to control festival from
python in the same way.
Martin

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


Constructor class problem

2005-03-21 Thread Wolfgang
Hi,
I am a newbie and have to modify some python moduls.
I get the followin error:
TypeError: __init__() takes exactly 3 arguments (2 given)

Here the code snippet:
class gXconv:
def __init__(self, pathValue):
self.pathValue=pathValue
self.__sections = {}
self.__spalten = {}
self.labelfiles=[]
etc.

call:
try:
gx=gXconv.gXconv(gXconfPath)
except gXconv.gXconvertError, msg: 
print msg
sys.exit(1)

Hoping for hints.
Wolfgang
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lowest hassle Python web server?

2005-03-21 Thread Neil Benn
snip
- Does threading cause any more of a hassle in Python than Java?
snip
 

Hello,
   From the python docs, it states that the threading design is loosely 
based upon the java module.  Certainly, coming from Java I had little 
trouble getting used to python threading.  However heres some gotchyas :

- The thing to beware of there is something in Python called the GIL.  
Read up about that before you start threading stuff - this will explain 
to you why there is no volatile keyword - this got me confused at first.
- There is no synchronize keyword, instead you have to use locks which 
can be obtained from the threading module
- There are no methods such as wait on an object (there is an event 
object you can get to call wait upon - again threading)
- The handy concurrent stuff which has been introduced in J2SE5.0 
mainly isn't in python - through you do get Queues in Python (maybe 
more, I dunno?)

   The GIL thing makes it easier to do threading with Python (there are 
disadvantages to the GIL but I won't get into that here - if you're 
interested read through the history on this group) but it's still 
threading so beware!

Cheers,
Neil
--
Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 46
D-01307
Dresden
Germany
Tel : +49 (0)351 4173 154
e-mail : [EMAIL PROTECTED]
Cenix Website : http://www.cenix-bioscience.com
--
http://mail.python.org/mailman/listinfo/python-list


xmlrpc with Python and large datases

2005-03-21 Thread writeson
Hi all,

I helped one of my co-workers put together an XMLRPC Python script that
allowed him to get database data from remote machines. This was done
because the source of the data could be Oracle on a Sun/Solaris
machine, and MySQL on our linux machines. Doing the script in Python
allowed him to gather the date with a general purpose API and just send
over some SQL queries.

Since then he's run into a problem. If he sends a query that gets a
very large recordset from the database the script fails and it vaguely
reports about a broken pipe, which I'm guessing is a problem with the
network connection. Has anyone else seen this use XMLRPC and Python and
large amounts of data being returned via XMLRPC? And if so, is there a
solution?

Thanks,
Doug

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


Re: getting text from WinXP console

2005-03-21 Thread Jeff Schwab
Lucas Raab wrote:
Chris Maloof wrote:
Hello,
Does anyone know how I can read the ASCII text from a console window
(from another application) in WinXP?  It doesn't sound like a major
operation, but although I can find the window via pywin32, I haven't
been able to do anything with it.  I'd really just like to get the
window text into a string.
By console window, I mean the sort of thing that comes up when you
run command (although this particular one is for the game NetHack).
Thanks,
Chris

If you're looking to do this from Python then do python appname.py  
output.txt only without the quotes. AFAIK, this only works on Windows. 
Correct me if it works from Linux or another OS.
It works on Unix. :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Constructor class problem

2005-03-21 Thread Diez B. Roggisch
Wolfgang wrote:

 Hi,
 I am a newbie and have to modify some python moduls.
 I get the followin error:
 TypeError: __init__() takes exactly 3 arguments (2 given)
 
 Here the code snippet:
 class gXconv:
 def __init__(self, pathValue):
 self.pathValue=pathValue
 self.__sections = {}
 self.__spalten = {}
 self.labelfiles=[]
 etc.
 
 call:
 try:
 gx=gXconv.gXconv(gXconfPath)
 except gXconv.gXconvertError, msg:
 print msg
 sys.exit(1)


That error can't appear in the above code - is the line in the stacktrace
amongst the shown ones? I doubt it. 

The error means that you tried to call a function with less arguments than
it expected. As in __init__ the first argument is implicit on creation of
an object, the above errormessage indicates that there is an __init__
of the form

class Foo:
def __init__(self, arg1, arg2)
   pass

called like this

Foo(bar)

But as the only constructor you show _has_ only one additional argument
besides self and line 

gx=gXconv.gXconv(gXconfPath)

shows that you called it properly, the error must come from somewhere else.

-- 
Regards,

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


Re: xmlrpc with Python and large datases

2005-03-21 Thread Duncan Booth
writeson wrote:

 Since then he's run into a problem. If he sends a query that gets a
 very large recordset from the database the script fails and it vaguely
 reports about a broken pipe, which I'm guessing is a problem with the
 network connection. Has anyone else seen this use XMLRPC and Python and
 large amounts of data being returned via XMLRPC? And if so, is there a
 solution?
 
Most web servers have a configurable limit on the size of data sent to the 
server for a single request. It sounds as though you may be exceeding this. 
Check what setting has been used on your web server.

If it is Apache then look at the limitrequestbody parameter, it is 
unlimited by default, but advisable to set a limit to deter certain types 
of DoS attack.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting text from WinXP console

2005-03-21 Thread Lucas Raab
Chris Maloof wrote:
Hello,
Does anyone know how I can read the ASCII text from a console window
(from another application) in WinXP?  It doesn't sound like a major
operation, but although I can find the window via pywin32, I haven't
been able to do anything with it.  I'd really just like to get the
window text into a string.
By console window, I mean the sort of thing that comes up when you
run command (although this particular one is for the game NetHack).
Thanks,
Chris
If you're looking to do this from Python then do python appname.py  
output.txt only without the quotes. AFAIK, this only works on Windows. 
Correct me if it works from Linux or another OS.

--
--
Lucas Raab
lvraab located at earthlink.net
dotpyFE located at gmail.com
AIM:Phoenix11890
MSN:[EMAIL PROTECTED]
IRC:lvraab
ICQ:324767918
Yahoo:  Phoenix11890
--
http://mail.python.org/mailman/listinfo/python-list


Re: missing? dictionary methods

2005-03-21 Thread Robert Kern
Antoon Pardon wrote:
I would say the same reason that we have get. There is no
reason to have a builtin get it is easily implemented
like this:
  def get(dct, key, default):
try:
  return dct[key]
except KeyError:
  return default
I would go even so far that there is more reason to have a built-in
safeset and make, than there is a reason to have a built-in get.

The reason is that a python implementation of safeset and make,
will mean two accesses in the dictionary, once for the test and
once for the assignment. This double access could be eliminated
with a built-in. The get on the other hand does only one dictionary
access, so having it implemeted in python is a lesser burden.
That's not true; they're on more or less the same level 
computation-wise. try:...except... doesn't relieve the burden; it's 
expensive.

For me, the issue boils down to how often such constructs are used. I 
don't think that I've ever run into use cases for safeset() and make(). 
dct.get(key, default) comes up *a lot*, and in places where speed can 
matter. Searching through the standard library can give you an idea how 
often.

--
Robert Kern
[EMAIL PROTECTED]
In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


Re: FAQ 1.7.3 : How can I have modules that mutually import each other

2005-03-21 Thread david . tolpin

 Needs??? Sorry to be blunt, but this is an intrinsically ludicrous
 concept, in *any* language. The whole idea of modules is (wait for
it)
 modularity. A imports B which imports A is an utter nonsense.


There is such a thing called 'recursion'. Self-recursion is when
function x calls itself to execute the same action on a partial result
of its previous invocation. This technique is a natural expression of
what such ugly constructs as for and while  are for in some programming
languages. Indirect recusion is when function x calls y, and function y
calls x. It is often happens in state automata.

A static equivalent of indirect recursion is dependencies between
declarations, when declaration x depends on y, and declaration y
depends on x. Imagine a design
of a literate programming environment, where both documentation and
text are structured, and either can contain the other. A natural design
for that is to have two modules, one implementing the parser for
documentation, the other implementing the parser for code, each
referencing the other so that both parsers can call each other when
they need to switch context.

In a well-designed programming language, circular intermodule
dependencies are normal, because this is a natural high-level
abstraction to express such relations. Because of primitive
implementation of modular system in Python, circular dependencies are
not possible, and things which are normally done automatically in a
higher-level language, need to be coded manually in Python.

In particular, to bypass this deficiency of Python for a problem
similar to one described above, one has to define base classes for each
of the two parsers, and make the implementations depend on the other
implementation's base class, not on itself, thus splitting the
interface and the implementation where it is not only unnecessary but
outright wrong if clean design is taken into consideration.

I'd wish a cleaner and more consistent implementation of packages
existed in Python; but unfortunately too many things in current Python
are far from being on the level a modern programming language (such as
Common Lisp, for example) demands.

David Tolpin
http://davidashen.net/

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


Problem installing Python in Win98se

2005-03-21 Thread Prescott, A.
 Hi, 

I want to install Python on my Windows 98se system, but although I followed the 
instructions carefully, it won't run. 

Here's a copy of the Web instructions I followed, from Python.org: 

Starting with the Python 2.4 releases the Windows Python installer is being 
distributed as a Microsoft Installer (.msi) file. To use this, the Windows 
system must support Microsoft Installer 2.0. Just save the installer file 
python-2.4.msi to your local machine, then double-click python-2.4.msi to find 
out if your machine supports MSI. If it doesn't, you'll need to install 
Microsoft Installer first. Many other packages (such as Word and Office) also 
include MSI, so you may already have it on your system. If not, you can 
download it freely from Microsoft for Windows 95, 98 and Me 

The installer I downloaded from Microsoft and ran is called InstMsiA.exe. That 
seemed to install fine, but the .msi file still won't run.

Any ideas what I'm doing wrong?

Thanks in advance,

Andy

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

webGobbler update

2005-03-21 Thread [EMAIL PROTECTED]
The beta 10 of webGobbler is available for download.
http://sebsauvage.net/python/webgobbler/

Amongst the changes, the Windows screensaver now works,
although it still misses a configuration GUI.


I also created a non-technical page for webGobbler, the gallery:
http://sebsauvage.net/webgobbler/

I will continue to fuel this gallery with new pictures on occasions.



Enjoy.   :-)

--
Sébastien SAUVAGE
''.join([chr(ord(c)+4) for c in 'oa^o]qr]caoa^o]qr]ca*jap'])

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


Re: missing? dictionary methods

2005-03-21 Thread Antoon Pardon
Op 2005-03-21, Robert Kern schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:

 I would say the same reason that we have get. There is no
 reason to have a builtin get it is easily implemented
 like this:
 
   def get(dct, key, default):
 
 try:
   return dct[key]
 except KeyError:
   return default
 
 
 I would go even so far that there is more reason to have a built-in
 safeset and make, than there is a reason to have a built-in get.
 
 The reason is that a python implementation of safeset and make,
 will mean two accesses in the dictionary, once for the test and
 once for the assignment. This double access could be eliminated
 with a built-in. The get on the other hand does only one dictionary
 access, so having it implemeted in python is a lesser burden.

 That's not true; they're on more or less the same level 
 computation-wise. try:...except... doesn't relieve the burden; it's 
 expensive.

I have always heard that try: ... except is relatively inexpensive
in python. Particularly if there is no exception raised.

 For me, the issue boils down to how often such constructs are used. I 
 don't think that I've ever run into use cases for safeset() and make(). 

 dct.get(key, default) comes up *a lot*, and in places where speed can 
 matter. Searching through the standard library can give you an idea how 
 often.

It is always hard to compare the popularity/usefullness of two things when
one is already implemented and the other is not. IME it is not that
uncommon to know in some part of the code that the keys you use should
already be in the dictionary or contrary that you know the key should
not already be in the dictionary.

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


Re: For loop extended syntax

2005-03-21 Thread Ron
On Sun, 20 Mar 2005 13:16:37 -0500, George Sakkis
[EMAIL PROTECTED] wrote:

I'm sure there must have been a past thread about this topic but I don't know 
how to find it: How
about extending the for X in syntax so that X can include default 
arguments ? This would be very
useful for list/generator comprehensions, for example being able to write 
something like:

[x*y-z for (x,y,z=0) in (1,2,3), (4,5), (6,7,8)]

instead of the less elegant explicit loop version that has to check for the 
length of each sequence.
What do you think ?

George


How would this examples work?

for x=5,y,z in (123),(4,5),(6,7,8,9)

Would the x default over ride the first value?
Should, the 4 element in the third tuple be dropped without an error?


A  general reusable function might be something like this:

def formatlistofargs(arglist, nargs=1, defvalue=0):
returnvalues = []
for i in arglist:
ii = list(i)
while len(ii)nargs:
ii.append(defvalue)
ii=ii[:nargs]
returnvalues.append(ii)
return returnvalues

for x,y,z in formatlistofargs(((1,2,3),(3,4),(5,6,7,8)),3):
print x,y,z


Ron

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


Re: how can I put a 1Gb file in a zipfile??

2005-03-21 Thread RM
From what I understand, Winzip uses their own proprietary version of a
Zip format.  That means that you will only be able open those archives
with Winzip. (IOW, you are locked in)

I think someone mentioned having developed a Python module for the 7zip
fomat, but I may be wrong.  In any case, you could simply write a
wrapper over the command line version of 7zip and your problem would be
solved.  There is a Linux version as well.
(http://p7zip.sourceforge.net/)


bennie wrote:
 Christos TZOTZIOY Georgiou wrote:
  AFAIR there is a 4GiB (or 2GiB) size limit applying both to files
added to zip
  and to the total size of the zip file.  This limit comes from the
zip file
  specification (32 bit offsets).
  Can it be that you are creating a zip file that its total size
exceeds the
  limit?
 That is possible.
 But with Winzip program it can.
 How come that is with ZipFile not works

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


Re: PyPI errors?

2005-03-21 Thread A.M. Kuchling
On Mon, 21 Mar 2005 04:24:16 + (UTC), 
Daniel Yoo [EMAIL PROTECTED] wrote:
 Does anyone know why PyPI's doesn't like my PKG-INFO file?  Here's
 what I have:

The PyPI code is being modified at the PyCon sprints; clearly this is a bug 
that was introduced yesterday.  I expect it'll get fixed today.

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


Re: Getting directory size

2005-03-21 Thread Peter Hansen
francisl wrote:
How can we get a full directory size (sum of all his data)?
like when we type `du -sh mydir`
Because os.path.getsize('mydir') only give the size of the directory 
physical representation on the disk.
os.popen('du -sh mydir') would be one approach.
The harder way is to use os.walk('mydir') to scan all
files in all subdirectories, and use os.stat() or
os.path.getsize() to add up the sizes of each file.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: missing? dictionary methods

2005-03-21 Thread Ron
On 21 Mar 2005 08:21:40 GMT, Antoon Pardon [EMAIL PROTECTED]
wrote:

Well at least I find them missing.

For the moment I frequently come across the following cases.

1) Two files, each with key-value pairs for the same dictionary.
However it is an error if the second file contains a key that
was not in the first file.

In treating the second file I miss a 'set' method.
dct.set(key, value) would be equivallent to dct[key] = value,
except that it would raise a KeyError if the key wasn't
already in the dictionary.


2) One file with key-value pairs. However it is an error
if a key is duplicated in the file.

In treating such files I miss a 'make' method.
dct.make(key, value) would be equivallent to dct[key] = value.
except that it would raise a KeyError if the key was
already in the dictionary.


What do other people think about this?


There is a has_key(k) method that helps with these.

Adding these wouldn't be that hard and it can apply to all
dictionaries with any data.  

class newdict(dict):
def new_key( self, key, value):
if self.has_key(key):
raise KeyError, 'key already exists'
else:
self[key]=value
def set_key( self, key, value):
if self.has_key(key):
self[key]=value
else:
raise KeyError, 'key does not exist'

d = newdict()
for x in list('abc'):
d[x]=x
print d
d.new_key('z', 'z')
d.set_key('a', 'b')
print d

Which is faster?  (has_key()) or (key in keys())?


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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-21 Thread AndrewN
Raymond Hettinger wrote:
 I would like to get everyone's thoughts on two new dictionary
methods:

 def count(self, value, qty=1):
 try:
 self[key] += qty
 except KeyError:
 self[key] = qty

 def appendlist(self, key, *values):
 try:
 self[key].extend(values)
 except KeyError:
 self[key] = list(values)


-0.9

Not impressed, they feel too specific for being builtin dictionary
methods and give the impression of just trying to save a few lines here
and there. I don't feel the names convey the functionality of the
methods either.

I know there's the speed argument but I'd rather not have these on the
dict at all.

+0.1

I sort of feel a slight need for this. But where would you stop? What
if people decrement lots? what if next there's a need for division? How
would you determine how you add the item to the key if it already
exists? In a general way:

mydict.set(key, value=None, default=None, how=operator.setitem)

This feels slightly better as it's not tied down to what sort of item
you're setting. But:

 for word in words:
 mydict.set(word, 1, 0, operator.add)

I dunno, feels a bit verbose maybe.

 The setdefault() method would continue to exist but would likely not
make it
 into Py3.0.

I agree that setdefault is wart though.

And for dict.default = value:

(Quoth RON):

With a preset default mode, it then becomes possible to
inadvertently
create default values that will cause problems without knowing it.  So
then we have to remember to change the setdefault value to None or
null to avoid problems.  Ouch!

Agreed, -1 there then.

 PROBLEMS BEING SOLVED
 -

 The readability issues with the existing constructs are:

 * They are awkward to teach, create, read, and review.
 * Their wording tends to hide the real meaning (accumulation).
 * The meaning of setdefault() 's method name is not self-evident.

I feel this only really applies for setdefault (which I wouldn't be
sorry to see the back of). And your examples:

d[key] = d.get(key, 0) + qty
d.setdefault(key, []).extend(values)

Would better be written in a long-handed fashion anyway as per the
implementations were suggested:

try:
d[key] += qty
except KeyError:
d[key] = 0

Yeah, yeah, I know, speed. But not like this. Sorry.

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


Re: UTF Questions

2005-03-21 Thread Serge Orlov
Fuzzyman wrote:
 I have a couple of questions about the UTF encodings.

 The codecs module has constants definded for the UTF32 encoding, yet
 this encoding isn't supported as a standard encoding. Why isn't it
 supported ?

Probably because there is little demand for it. The most widespread
unicode encodings are utf-8 and utf-16


 It possibly has something to do with my next question. I know that
 unicode has (recently?) been expanded to include new character sets.
 This means that the latest unicode standard can't be fully supported
 with 2 bytes per character. As far as I know though, Python doesn't
 (yet) support the extended version of unicode anyway ? Am I correct ?

Python does support them. PEP 261 has the answers for your questions.

  Serge.

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


Re: IconvCodec, UTF-32 P4 ?

2005-03-21 Thread News M Claveau /Hamster-P
Hi !

Thanks

My e-mail : [EMAIL PROTECTED]

@-salutations
-- 
Michel Claveau



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


Save passwords in scripts

2005-03-21 Thread Florian Lindner
Hello,
I've a scripts that allows limited manipulation of a database to users. This
script of course needs to save a password for the database connection. The
users, on the other hand need read permission on the script in order to
execute it but should not be able to read out the password.
What is the common way to solve this problem?

My current way is to allow the users to execute the script with sudo while
not having read permission when acting as a ordinary user. But I don't like
this solutions and consider it very ugly.

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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-21 Thread Michele Simionato
FWIW, here is my take on the defaultdict approach:

def defaultdict(defaultfactory, dictclass=dict):
class defdict(dictclass):
def __getitem__(self, key):
try:
return super(defdict, self).__getitem__(key)
except KeyError:
return self.setdefault(key, defaultfactory())
return defdict

d = defaultdict(int)()
d[x] += 1
d[x] += 1
d[y] += 1
print d

d = defaultdict(list)()
d[x].append(1)
d[x].append(2)
d[y].append(1)
print d

  Michele Simionato

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


Re: spaces in re.compile()

2005-03-21 Thread AndrewN
 d = re.compile(' \d{3}\.\d{3}\.\d{3} ')
 d.findall(' 123.345.678 ')
[' 123.345.678 ']

Works for me.

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


Re: spaces in re.compile()

2005-03-21 Thread rbt
AndrewN wrote:
d = re.compile(' \d{3}\.\d{3}\.\d{3} ')
d.findall(' 123.345.678 ')
[' 123.345.678 ']
Works for me.
Yes, you're correct. That works if there is a space at the front and 
back. However, place '123.345.678' in a file by itself and it doesn't work.

What I'm trying to avoid is something like this '1234.345.6789' Notice 
the 4 chars in the first and last part? findall gets '234.345.678' and 
returns positive... I thought that by requiring spaces I could avoid 
matches such as this, but I was wrong. How can I get what I'm looking 
for w/o getting the other stuff as well?
--
http://mail.python.org/mailman/listinfo/python-list


(,) Do You Want To Know For Sure You Are Going To Heaven?

2005-03-21 Thread Ron038548
http://www.want-to-be-sure.blogspot.com  Click On Link

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


Re: Please help for Python programming

2005-03-21 Thread bruno modulix
[EMAIL PROTECTED] wrote:
I don't know why i entered the below code 
And we don't know either !-)
and it will miss some
records.
Anyone can help me???
If you hope to get some useful help, it would be a good idea to follow 
Diez's advice (see other post in this thread)

users = {}
users1 = {} 

while 1:
Unless there is a break somewhere in the following code (I can't find 
one...), this is an endless loop. But you know this, don't you ?

user, serviceType, msgType, inOut, date, time, numBytes =
aLog.GetNextMessage()
fullmsg = serviceType + | + msgType + | + inOut
tip : use string formating instead (string concatenations are to be 
avoided in Python), ie:
fullmsg = %s | %s | %s % (serviceType, msgType, inOut)

bytemsg = user +   + serviceType +   + msgType +   + inOut +  
+ numBytes
idem
user1 = user
msgDict = {}
byteDict = {}
This re-initialises both dicts on each iteration. Is this really what 
you want ?
		print bytemsg		# 53 records in source file
Here you have an obvious indentation problem. This code *cannot* run.
Take care of not mixing tabs and spaces (tip: configure you editor to 
only use spaces)

		msgDict = users[user]	# get the cum statistics for this user
Given the above binding of 'users' as an empty dict, this should raise a 
KeyError. It's also overwriting the previous binding of msgDict.

		byteDict = users1[user1]
idem. Also, you don't need to bind 2 different names to the same value 
to use this value as key in 2 different dicts. Here you could as well 
use user for both dicts, since user and user1 are bound to the same value.

print bytemsg   # 50 records in source file
In addition to Diez's reading advice, here are some that are more 
specific to code-related questions:

1/ paste code, dont re-type it
... this avoid stupid typos
2/ post running code
... if the code is so obviously broked that it cannot even compile|run, 
readers will have to fix it first - which they'll probably won't do. 
Even if they do, they may not fix it the right way. Everyone's losing 
its time...

3/ post the smallest possible bit of code that exhibit your problem
... no one's going to [read 3000 lines of code | install 30 gigabytes of 
third part libs | etc...] just to help you. Moreover, quite often, one 
finds the bug while reducing the problematic code to it's smallest possible.

And one last: don't forget to put your bullet-proof jacket on before 
reading the answers !-) (well, c.l.py is probably one of the friendliest 
groups on usenet, but still, this is usenet).

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


Wikipedia - conversion of in SQL database stored data to HTML

2005-03-21 Thread Claudio Grondi
Is there an already available script/tool able to
extract records and generate proper HTML
code out of the data stored in the Wikipedia
SQL data base?
e.g.
 converting all occurences of
  [[xxx|yyy]] to a href=xxxyyy/a
etc.
Or even better a script/tool able to generate
and write to the disk all the HTML files
if given the MMDDD_cur_table.sql
data, so that the Wikipedia content
becomes available on local computer
without running a server?

By the way:
has someone succeeded in installation of
a local Wikipedia server? As I remember the
problem caused me to fail on this was that
mySQL server was not able to handle a
database larger than 2 GByte
(the english part of current data and
usually the ..._old_table.sql exceed
this size).

Claudio


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


python-dev Summary for 2005-03-01 through 2005-03-15

2005-03-21 Thread Brett C.
[The HTML version of this Summary is available at
http://www.python.org/dev/summary/2005-03-01_2005-03-15.html]

=
Summary Announcements
=
-
Second to last summary for me
-
Just a reminder, after this Summary there is only one more left for me to 
write.  After that Tim Lesher, Tony Meyer, and Steven Bethard will be taking over.

-
See you at PyCon!
-
PyCon_ is practically upon us!  If you are going to be there, great!  Please 
feel free to say hello if you run into me (will be at the sprints and the 
conference Wednesday and Thursday; skipping Friday to see a friend).  Always 
happy to stop-and-chat.

.. _PyCon: http://www.pycon.org/

2.4.1 should be out soon

Python 2.4c2 has now been released.  Assuming no major issues come up, 2.4 
final will be out March 29; day after PyCon.

But in order to make sure no issues come up, we need the code to be tested! 
Please get the code and run the regression tests.  If you are on a UNIX system 
it is as easy as running ``make test`` (``make testall`` is even better).  The 
tests can also be run on non-UNIX systems; see 
http://docs.python.org/lib/regrtest.html on how.

=
Summaries
=
--
2.4 should be out soon
--
Python 2.4.1c1 was releaseed, but enough bugs were found and subsequently fixed 
that c2 release will occur before 2.4 final comes out.

Contributing threads:
  - `2.4.1c1 March 10th, 2.4.1 March 17th 
http://mail.python.org/pipermail/python-dev/2005-March/051832.html`__
  - `BRANCH FREEZE for 2.4.1rc1,  UTC, 2005-03-10 
http://mail.python.org/pipermail/python-dev/2005-March/051929.html`__
  - `branch release24-maint is unfrozen, 2.4.1rc2? 
http://mail.python.org/pipermail/python-dev/2005-March/052017.html`__
  - `os.access and Unicode 
http://mail.python.org/pipermail/python-dev/2005-March/051906.html`__
  - `RELEASED Python 2.4.1, release candidate 1 
http://mail.python.org/pipermail/python-dev/2005-March/051992.html`__
  - `distutils fix for building Zope against Python 2.4.1c1 
http://mail.python.org/pipermail/python-dev/2005-March/052068.html`__
  - `Python2.4.1c1 and win32com 
http://mail.python.org/pipermail/python-dev/2005-March/052080.html`__
  - `Open issues for 2.4.1 
http://mail.python.org/pipermail/python-dev/2005-March/052099.html`__

---
Getting state of all threads in interpreter
---
Florent Guillaume wrote some code for Zope that returned the current state of 
all threads in the interpreter, regardless of whether they were hung or not. 
Tim Peters suggested someone write up some code so that this could be made 
available in Python itself.

Fazal Majid has volunteered to implement this.
Contributing threads:
  - `Useful thread project for 2.5? 
http://mail.python.org/pipermail/python-dev/2005-March/051856.html`__

-
No new features in micro releases
-
A bug in os.access() not allowing Unicode strings triggered the discussion of 
whether it was a bugfix to repair the issue or a new feature.  In the end it 
was decided it was a bugfix.  But the point was specified that micro releases 
should never have any new feature, no matter how small.

Contributing threads:
  - `[Python-checkins] python/dist/src/Modules ossaudiodev.c, 1.35, 1.36 
http://mail.python.org/pipermail/python-dev/2005-March/051889.html`__
  - `No new features 
http://mail.python.org/pipermail/python-dev/2005-March/051919.html`__
  - `os.access and Unicode 
http://mail.python.org/pipermail/python-dev/2005-March/051906.html`__
  - `rationale for the no-new-features approach 
http://mail.python.org/pipermail/python-dev/2005-March/051930.html`__

-
Python wins Jolt Productivity Award
-
Python was runner-up in the `15th annual Jolt Awards`_ in the category of 
Languages and Development Environments, being given the Productivity Award. 
 Python is now award-winning.  =)

.. _15th annual Jolt Awards: 
http://www.sdmagazine.com/jolts/15th_jolt_finalists.html

Contributing threads:
  - `FWD: SD MAgazine.com - Jolt Awards Winners 
http://mail.python.org/pipermail/python-dev/2005-March/052008.html`__
  - `Python 2.4 won the Jolt productivity award last night 
http://mail.python.org/pipermail/python-dev/2005-March/052246.html`__

--
New built-ins: any() and all()
--
Python 2.5 gains two new built-ins: any(), which returns True if the iterable 
passed to it contains any true items, and all(), which returns True if all the 
items in the iterable passed to it are true.

Contributing threads:
  - `Adding any() and all() 
http://mail.python.org/pipermail/python-dev/2005-March/052010.html`__


Re: spaces in re.compile()

2005-03-21 Thread Jeff Epler
Maybe you want r'\b'.  From 'pydoc sre':
\b   Matches the empty string, but only at the start or end of a word.


import re
r = re.compile( r'\btest\b' )
print r.findall(testy)
print r.findall( testy )
print r.findall( test )
print r.findall(test)


pgps8PNW4uDgh.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

spaces in re.compile()

2005-03-21 Thread rbt
Is it possible to use spaces in a re.compile()?
For example, I want to make sure one space exists right before this 
string and right after it:

re.compile ('\d{3,3}\.\d{3,3}\.\d{3,3}\.\d{3,3}')
I've tried this, but it didn't work:
re.compile (' \d{3,3}\.\d{3,3}\.\d{3,3}\.\d{3,3} ')
Any ideas?
--
http://mail.python.org/mailman/listinfo/python-list


Re: exec src in {}, {} strangeness

2005-03-21 Thread Stefan Seefeld
Do Re Mi chel La Si Do wrote:
Hi !
Try :
exec f in globals(),locals()
or
exec(f,globals(),locals())
or
exec f in globals(),globals()
or
exec(f,globals(),globals())
Indeed, using 'globals()' and 'locals()' works. However,
both report the same underlaying object, which is a bit
confusing. (Under what circumstances does 'locals()' return
not the same object as 'globals()' ?)
The problem appears to be that
exec f in a, b
where a and b are distinct dictionaries, does not look up
symbols in 'a' when in local scope.
I filed a bug report (#1167300).
Regards,
Stefan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Software for Poets (Was: Re: Text-to-speech)

2005-03-21 Thread Francis Girard
This is about poetry. I think the next reply should be done privately unless 
someone else is interested in it.

Hi,

Le dimanche 20 Mars 2005 23:04, Paul Rubin a écrit :
 Francis Girard [EMAIL PROTECTED] writes:
  4- Propose a synonym that will fit in a verse, i.e. with the right amount
  of syllabs
 
  5- Suggest a missing word or expression in a verse by applying the
  Shannon text generation principle
  ...
  First, do you think it may be a useful tool ?
  What other features you think can make it usefull for a poet ?

 I'm skeptical of this notion.  You can think of writing a poem as
 building up a tree structure where there's a root idea you're trying
 to express, branches in the choices of images/comparisons/etc. that
 you use to express the idea, and leaves that are the actual words in
 the poem.  Rhyme means that a left-to-right traversal of the leaves
 (i.e. reading the words) results in a pattern with a certain
 structure.  You're proposing a tool that helps explore the search
 space in the nodes near the bottom level of the tree, to find words
 with the right characteristics.

 I think the constraint of rhyme and meter is best served by widening
 the search space at the upper levels of the tree and not the lower
 levels.  That is, if you've got an image and you don't find rhyming
 words for it with easy natural diction, a computerized search for more
 and more obscure words to express that image in rhyme is the last
 thing you want.  

Absolutly right.

 Rather, you want to discard the image and choose a 
 different one to express the idea.  That means seeking more images by 
 mentally revisiting and staying inside the emotion at the center of
 poem, a much more difficult thing to do than solving the mere math
 problem of finding a string of rhyming words with similar semantics to
 a non-rhyming sequence that you already have.  

Again, right. Your description comes very close to my own experience of 
writing poems and I never read something as clear as what I'm reading here. 
Poetry practice is described most of the time in poetic terms just like 
religion is described in religious terms. And one has to impregnate himself 
with these words to, little by little, gain some understanding of it. Your 
description proves that it is possible to describe it otherwise. I am truly 
marvelled.

The question is : how do you discard the image to choose another one ? How 
this process takes place ? I observed myself while writing a poem (I, myself, 
may not be good example since I am certainly not a good poet) and discovered 
that it is while playing with the words, trying to find the right one, with 
the right number of syllabs, that I discover a new image, and re-write the 
whole verse, even re-arranging the whole strophe or poem. My goal with the 
two last tasks (4 and 5) was to help the poor guy struggling with the words, 
not to produce the correct final verse, but only to help him in one of the 
phase of his writing.

 But when you find the
 right image, the words and rhythm fall into place without additional
 effort.


I don't believe much in this. Poetry and writing in general is work, work, 
work and more work.

 This is why writing good poems is hard, and is also why the results of
 doing it well is powerful.  I don't think it can be programmed into a
 computer using any current notions.

Again right. My goal, of course, is not to substitute the poet by a computer. 
Only help him in some of his mechanical tasks.

Regards

Francis Girard

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


Re: exec src in {}, {} strangeness

2005-03-21 Thread Peter Hansen
Stefan Seefeld wrote:
Indeed, using 'globals()' and 'locals()' works. However,
both report the same underlaying object, which is a bit
confusing. (Under what circumstances does 'locals()' return
not the same object as 'globals()' ?)
When you aren't at the interactive prompt...  there are
no locals there, so locals() just maps through to globals().
(Probably this applies to all code at the module level,
as oppsed to code inside any callable, but I haven't
verified... you can easily enough.)
Does this information invalidate your bug report?
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: simultaneous copy to multiple media

2005-03-21 Thread Jacek Trzmiel

  This is small tool I've wrote, that does use large memory buffers with
  asynchronous I/O to copy file.

Claudio Grondi wrote:
 Thank you!
 This (with a drawback of blocking the entire system) does it!
 ( dzie dobry i dzikuj za t konstruktywn odpowied
 na moje pytanie )

:)

 From my point of view this thread has reached
 its end (I have a solution I can live with), except if
 someone would like to contribute or point to a
 better multicopy.exe which does not block the system

Symptoms (high cpu usage, unresponsive system) look similar to situation
when you try to read/write as fast as possible from/to IDE drive running
in PIO mode.  I think that it's either USB driver problem, or inherent
design flaw in USB (anyone?).  

Anyway, I've added buffersize and sleeptime options to multicopy, so you
may try to throttle it down.  Download it here:
  http://mastermind.com.pl/multicopy/

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


Re: Save passwords in scripts

2005-03-21 Thread Peter Hansen
Florian Lindner wrote:
I've a scripts that allows limited manipulation of a database to users. This
script of course needs to save a password for the database connection. The
users, on the other hand need read permission on the script in order to
execute it but should not be able to read out the password.
What is the common way to solve this problem?
The common way is to do something ill-conceived and insecure.
The correct approach is to use a secure technique that
does not involve storing the passwords themselves, but
instead storing a hash version of them (e.g. MD5 or SHA),
or by requiring the users to enter their passwords at
the time the information is required.
My current way is to allow the users to execute the script with sudo while
not having read permission when acting as a ordinary user. But I don't like
this solutions and consider it very ugly.
Storing passwords in the clear is always ugly and
insecure.  Think about the situation where a user
(unwisely) picks a password that he also uses for,
say, his online banking.  If the password is stored
in the clear, then anyone with root access can see
it and even if you trust all your administrators,
or are the only admin yourself, it's still not a
good idea to let an admin see a user's password.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


pyopengl and py2exe

2005-03-21 Thread Kirill Kuvaldin

Hello All!

My program in python uses PyOpenGL and I need to convert it to a
standalone windows executable file.

Following to these instructions 
(http://pyopengl.sourceforge.net/documentation/py2exe.html) I've put
PyOpenGL package to a directory where my program was placed.
and run the script:
 setup.py py2exe --excludes=OpenGL

but it prints such error messages:
...
*** copy extensions ***
copying C:\Python23\DLLs\_sre.pyd - C:\cg\dist
*** copy dlls ***
copying C:\Python23\w9xpopen.exe - C:\cg\dist
copying C:\WINNT\system32\python23.dll - C:\cg\dist
setting sys.winver for 'C:\cg\dist\python23.dll' to 'py2exe samples'
copying C:\Python23\lib\site-packages\py2exe\run.exe - C:\cg\dist\hello.exe
The following modules appear to be missing
['OpenGL.GL', 'OpenGL.GLE', 'OpenGL.GLUT']

?

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


Re: Text-to-speech

2005-03-21 Thread Brian van den Broek
Paul McGuire said unto the world upon 2005-03-21 03:10:
How about a clerihew instead of a limerick?
Guido van Rossum
Had an idea most awesome.
When he lost track of his braces,
Just replaced them with spaces.
-- Paul McGuire
Hi all,
that's pretty good, Paul.
However, I must insist that you both cease and desist.
Your Allusion to the computational instructional language Python,
through the inclusion of 'brace' (and its derivative forms) and
'space' (and its derivative forms) in a rhyming couplet in a comedic
verse, while quite amusing, is a clear violation of my Intellectual
Property. My Intellectual Property rights are attested to by my extant
prior art http://tinyurl.com/4bu3n, the patent application pending 
before the Patent Office of The Republic of Freedonia covering same, 
and Darl McBride's say-so.

Having drafted a patent application covering the use of 'space' and
'brace' in poetic contexts, I saw no good reason to stop there. Hence,
the pending patent application also covers both the use of braces and
whitespace as delimiters (block or otherwise) in any language or set 
of instructions, (natural, computational or otherwise artificial). So, 
I must also demand that you, and the rest of the Python community 
immediately cease and desist from producing any instructions, in any 
language, which employ either of these syntactic constructs to 
represent either structure or relations of logical dependency.

Please do note that I make no claim to 'ENDSUB' and like constructs;
insofar as my Intellectual Property rights are concerned, you are free
to employ such constructs, in any linguistic expression, including,
but not limited to, provision of instruction and poetic expression,
regardless of context or language in which they are employed.
A formal statement of my position shall be forthcoming from my
solicitors, the illustrious firm of Dewey, Cheatem,  Howe. I am
optimistic that we will be able to arrive at licencing terms both fair
and equitable.
I remain your most faithful servant,
Brian vdB
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python becoming less Lisp-like

2005-03-21 Thread Jeff Shannon
Antoon Pardon wrote:
Op 2005-03-18, Jeff Shannon schreef [EMAIL PROTECTED]:
I find it odd that you start by saying you still find them very
consistent and here state there is a slight inconsistency.
I said that the way that binding a name on a class instance always 
creates an instance attribute regardless of the presence of a 
similarly-named class attribute is consistent with the way that name 
binding works in any scope.  This is true.  Binding of a name within a 
function-local scope works the same way -- bindings are always created 
within the narrowest scope unless something is explicitly done to 
force other behavior.

You pointed out a case in which class/instance attributes behave 
slightly differently than local/global names do, and I agree with you 
that there is a difference in behavior there.  However, that 
difference is in the way that bare names are resolved into 
local/global references, and *not* in the way that name binding works. 
 The name binding rules are consistent; the inconsistency is in name 
*lookups*, and is a case of strong optimization of the standard case 
affecting the behavior of an unusual (and strongly discouraged) case. 
 There is a slight inconsistency in something *other* than what the 
O.P. was complaining about being inconsistent; I'm recognizing that 
inconsistency at the same time as I'm attempting to point out that the 
other inconsistency really *is* consistent.  (I'm also pointing out 
that this name-lookup inconsistency is a good example of practicality 
beats purity, because the value of the optimization is, IMO, much 
greater than the cost of the inconsistency.)

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


Re: Python limericks (was Re: Text-to-speech)

2005-03-21 Thread Scott David Daniels
Tim Churches wrote:
...
My first attempt (which does not scan properly):
A Dutch mathematician most prophetic,
Did invent a language, name herpetic.
  With design quite intelligent,
  And syntax mostly elegant,
Big ideas could be made non-hypothetic.
To improve the scan:
  A mathematician, prophetic,
  invented a language, herpetic.
decidedly brilliant,
syntacticly elegant,
  Made ideas far less hypothetic.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: exec src in {}, {} strangeness

2005-03-21 Thread Stefan Seefeld
Peter Hansen wrote:
Stefan Seefeld wrote:
Indeed, using 'globals()' and 'locals()' works. However,
both report the same underlaying object, which is a bit
confusing. (Under what circumstances does 'locals()' return
not the same object as 'globals()' ?)

When you aren't at the interactive prompt...  there are
no locals there, so locals() just maps through to globals().
(Probably this applies to all code at the module level,
as oppsed to code inside any callable, but I haven't
verified... you can easily enough.)
Does this information invalidate your bug report?
No, but that's possibly only because I don't (yet) understand
the implications of what you are saying.
Is there anything wrong with 'exec source in a, b' where
a and b are distinc originally empty dictionaries ? Again,
my test code was
class Foo: pass
class Bar:
  foo = Foo
and it appears as if 'Foo' was added to 'a', but when evaluating
'foo = Foo' the interpreter only looked in 'b', not 'a'.
Thanks,
Stefan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Save passwords in scripts

2005-03-21 Thread Florian Lindner
Peter Hansen wrote:

 Florian Lindner wrote:
 I've a scripts that allows limited manipulation of a database to users.
 This script of course needs to save a password for the database
 connection. The users, on the other hand need read permission on the
 script in order to execute it but should not be able to read out the
 password. What is the common way to solve this problem?
 
 The common way is to do something ill-conceived and insecure.
 
 The correct approach is to use a secure technique that
 does not involve storing the passwords themselves, but
 instead storing a hash version of them (e.g. MD5 or SHA),
 or by requiring the users to enter their passwords at
 the time the information is required.

Hashes could not work, since I need to give the password to a DB server. My
script is the client, not the server. It does not check passwords supplied
by the users, just use the hard-coded password to connect to the DB server.
 
 My current way is to allow the users to execute the script with sudo
 while not having read permission when acting as a ordinary user. But I
 don't like this solutions and consider it very ugly.
 
 Storing passwords in the clear is always ugly and
 insecure.  Think about the situation where a user
 (unwisely) picks a password that he also uses for,
 say, his online banking.  If the password is stored
 in the clear, then anyone with root access can see
 it and even if you trust all your administrators,
 or are the only admin yourself, it's still not a
 good idea to let an admin see a user's password.

It's not a users password. It's a password of a db user which owns several
system tables and the users should be able to manipulate them in a
constrained manner.

I fully agree with you. That's why I'm looking for a better, more secure
solution.

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


Re: remove strings from source

2005-03-21 Thread qwweeeit
I am in debt with you of an answer on  my solution in removing
literal strings...
I apologize not to have followed your suggestions but I am just
learning Python, and your approach was too difficult for me!
I've already developed the cross reference tool, and for that I
identified two types of literals (the standard one  which I named in
general s~ and the multi-line or triple quoted strins, which I called
m~).

You can see a step in my appproach to the solution in an answer to
Fredrik Lundh
http://groups.google.it/groups?q=qwweeeithl=itlr=group=comp.lang.python.*selm=2ab23d7a.0503190647.2c15c281%40posting.google.comrnum=2

After that I have almost completed the application, and better than
explanations you can see the result (a small extract).

052 PROGNAME: PROGNAME = sys.argv[0]
053   AUTHOR: AUTHOR = us~.encode(s~)
054  VERSION: VERSION = s~
056 URL_BASE: URL_BASE = s~
057  OUTPUT_HTML: OUTPUT_HTML = s~   etc...

The cross references are mainly useful for variables, but I use them
also for Python reserved words, to learn the language and also classes
and functions.

For small applications there is no need for my toool, but with a
source of almost 1 Mb... (like Pysol).
Excuse if I don't go deeper in my solution for removing strings, but
it is so standard that there is nothing to learn ...

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


Re: getting text from WinXP console

2005-03-21 Thread Lucas Raab
Jeff Schwab wrote:
Lucas Raab wrote:
Chris Maloof wrote:
Hello,
Does anyone know how I can read the ASCII text from a console window
(from another application) in WinXP?  It doesn't sound like a major
operation, but although I can find the window via pywin32, I haven't
been able to do anything with it.  I'd really just like to get the
window text into a string.
By console window, I mean the sort of thing that comes up when you
run command (although this particular one is for the game NetHack).
Thanks,
Chris

If you're looking to do this from Python then do python appname.py 
 output.txt only without the quotes. AFAIK, this only works on 
Windows. Correct me if it works from Linux or another OS.

It works on Unix. :)
Alright. Thanks, I wasn't sure.
--
--
Lucas Raab
lvraab located at earthlink.net
dotpyFE located at gmail.com
AIM:Phoenix11890
MSN:[EMAIL PROTECTED]
IRC:lvraab
ICQ:324767918
Yahoo:  Phoenix11890
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting directory size

2005-03-21 Thread Graham Fawcett
Peter Hansen wrote:
 francisl wrote:
  How can we get a full directory size (sum of all his data)?
  like when we type `du -sh mydir`
 
  Because os.path.getsize('mydir') only give the size of the
directory
  physical representation on the disk.

 os.popen('du -sh mydir') would be one approach.

 The harder way is to use os.walk('mydir') to scan all
 files in all subdirectories, and use os.stat() or
 os.path.getsize() to add up the sizes of each file.

With Orendorff's path module, this becomes a two-liner:

from path import path
dir_size = sum([f.size for f in path('mydir').walkfiles()])

With Python 2.4 genexps, you don't even need the square brackets...

http://www.jorendorff.com/articles/python/path/

Shoulda-been-added-to-the-standard-library'ly yours,

-- Graham

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


Re: exec src in {}, {} strangeness

2005-03-21 Thread Bernhard Herzog
Stefan Seefeld [EMAIL PROTECTED] writes:

 Is there anything wrong with 'exec source in a, b' where
 a and b are distinc originally empty dictionaries ? Again,
 my test code was

 class Foo: pass
 class Bar:
foo = Foo

 and it appears as if 'Foo' was added to 'a', but when evaluating
 'foo = Foo' the interpreter only looked in 'b', not 'a'.

No, it's the other way round.  Foo is added in b since bindings are done
in the local scope.  Your case is a bit more complicated, though.
Here's what I think happens:

class Foo is bound in b, the locals dictionary, so there is no reference
to Foo in the globals dictionary.  The body of class B is executed with
it's own new locals dictionary.  That locals dictionary will effectively
be turned into Bar.__dict__ when the class object is created.

When foo = Foo is executed, Foo is first looked up in that new locals
dictionary.  That fails, so it's also looked up in the globals
dictionary a.  That fails as well because Foo was bound in b.  The final
lookup in the builtins also fails, and thus you get an exception.


   Bernhard

-- 
Intevation GmbH http://intevation.de/
Skencil   http://skencil.org/
Thuban  http://thuban.intevation.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exec src in {}, {} strangeness

2005-03-21 Thread Stefan Seefeld
Bernhard Herzog wrote:
Stefan Seefeld [EMAIL PROTECTED] writes:

Is there anything wrong with 'exec source in a, b' where
a and b are distinc originally empty dictionaries ? Again,
my test code was
class Foo: pass
class Bar:
  foo = Foo
and it appears as if 'Foo' was added to 'a', but when evaluating
'foo = Foo' the interpreter only looked in 'b', not 'a'.

No, it's the other way round.  Foo is added in b since bindings are done
in the local scope.  Your case is a bit more complicated, though.
Here's what I think happens:
class Foo is bound in b, the locals dictionary, so there is no reference
to Foo in the globals dictionary.  The body of class B is executed with
it's own new locals dictionary.  That locals dictionary will effectively
be turned into Bar.__dict__ when the class object is created.
When foo = Foo is executed, Foo is first looked up in that new locals
dictionary.  That fails, so it's also looked up in the globals
dictionary a.  That fails as well because Foo was bound in b.  The final
lookup in the builtins also fails, and thus you get an exception.
Thanks for the explanation ! I'm still unable to make a conclusion:
What is wrong ? Am I doing something stupid (I did try various things
such as inserting __builtin__ into the dictionary, etc.) ?
Or is that really a bug ?
Thanks,
Stefan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wikipedia - conversion of in SQL database stored data to HTML

2005-03-21 Thread Leif K-Brooks
Claudio Grondi wrote:
Is there an already available script/tool able to extract records and
generate proper HTML code out of the data stored in the Wikipedia SQL
data base?
They're not in Python, but there are a couple of tools available here:
http://tinyurl.com/692pt.
By the way: has someone succeeded in installation of a local
Wikipedia server?
I loaded all of the Wikipedia data into a local MySQL server a while
back without any problems. I haven't attempted to run Mediawiki on top
of that, but I don't see why that wouldn't work.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [ann] fdups 0.15

2005-03-21 Thread P
Patrick Useldinger wrote:
I am happy to announce version 0.15 of fdups.
Cool. For reference have a look at:
http://www.pixelbeat.org/fslint/
Pádraig.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting directory size

2005-03-21 Thread P
francisl wrote:
How can we get a full directory size (sum of all his data)?
like when we type `du -sh mydir`
Because os.path.getsize('mydir') only give the size of the directory 
physical representation on the disk.
Have a look at:
http://www.pixelbeat.org/scripts/dutop
Pádraig.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Save passwords in scripts

2005-03-21 Thread Esben Pedersen
Florian Lindner wrote:
Hello,
I've a scripts that allows limited manipulation of a database to users. This
script of course needs to save a password for the database connection. The
users, on the other hand need read permission on the script in order to
execute it but should not be able to read out the password.
What is the common way to solve this problem?
My current way is to allow the users to execute the script with sudo while
not having read permission when acting as a ordinary user. But I don't like
this solutions and consider it very ugly.
Thanks,
Florian
Which DB? afaik postgre has user-level authentication which means you 
don't even need a password.

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


Re: getting text from WinXP console

2005-03-21 Thread Cappy2112
If you re-direct the output to a file, then you won't see it on the
console at all, unless the program writes to stderr separately.

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


Re: getting text from WinXP console

2005-03-21 Thread Cappy2112

Are you the one who is launching the Nethack program, or is it already
running, and you ar e trying to capture the text after Nethack is
launched ?

If you are launching it you can try using one of the python popen()
calls to redirect the screen output to your python program.

I havne't doen this myself, but I've seen this suggested to many people
who have asked a similar question.

Also- you can try posting a message to the Python Tutor- as well as
googling for python popen, to look for examples.


Another alternative, is to use the tee.exe unix util (ported to wn32)
which will duplicate screen I/O to a file, or some other place.

Try googling for unix utilities win32 -or similar combinations of
these words.

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


Re: spaces in re.compile()

2005-03-21 Thread rbt
Jeff Epler wrote:
Maybe you want r'\b'.  From 'pydoc sre':
\b   Matches the empty string, but only at the start or end of a word.
import re
r = re.compile( r'\btest\b' )
print r.findall(testy)
print r.findall( testy )
print r.findall( test )
print r.findall(test)
That works great. Thanks for the tip!
--
http://mail.python.org/mailman/listinfo/python-list


Re: generating audio signals

2005-03-21 Thread Cappy2112
Maybe make yourself a little utility first that will show you the
specs for any .wav file (i.e.,
sampling frequency, bytes per sample, channels, etc.)

You can do this with one function call - wave.Wave_read.getparams()
import wave
wave.open(filename,b)
wave.Wave_read.getparams()

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


Re: missing? dictionary methods

2005-03-21 Thread Terry Reedy

Antoon Pardon [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 For the moment I frequently come across the following cases.

 1) Two files, each with key-value pairs for the same dictionary.
 However it is an error if the second file contains a key that
 was not in the first file.

 In treating the second file I miss a 'set' method.
 dct.set(key, value) would be equivallent to dct[key] = value,
 except that it would raise a KeyError if the key wasn't
 already in the dictionary.


 2) One file with key-value pairs. However it is an error
 if a key is duplicated in the file.

 In treating such files I miss a 'make' method.
 dct.make(key, value) would be equivallent to dct[key] = value.
 except that it would raise a KeyError if the key was
 already in the dictionary.


 What do other people think about this?

To me, one of the major problems with OOP is that there are an unbounded 
number of functions that we can think of to operate on a date structure and 
thus a continual pressure to turn functions into methods and thus 
indefinitely expand a data structure class.  And whatever is the least used 
current method, there will always be candidates which are arguably at least 
or almost as useful.  And the addition of one method will be seen as reason 
to add another, and another, and another.  I was almost opposed to .get for 
this reason.  I think dict has about enough 'basic' methods.

So, without suppost from many people, your two examples strike me as fairly 
specialized usages best written, as easily done, as Python functions.

Terry J. Reedy



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


Re: Please help for Python programming

2005-03-21 Thread Terry Reedy
This is what I see (minus the ' '):

 while 1:
 user, serviceType, msgType, inOut, date, time, numBytes =
 aLog.GetNextMessage()
[etc]

Advice: use spaces, not tabs, to indent posted code (some readers discard 
tabs).  Don't use google groups to post code (it deletes initial spaces and 
won't, apparently, fix this bug).  Use news.gmane.org group 
gmane.comp.python.genral instead (I believe they also have web interface in 
addition to newsreader interface).  If you really, really must post thru 
google, prefix lines with char such as '|', even tho this kill cut and 
pastability.

Terry J. Reedy



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


Re: Save passwords in scripts

2005-03-21 Thread Paul Rubin
Florian Lindner [EMAIL PROTECTED] writes:
 I've a scripts that allows limited manipulation of a database to users. This
 script of course needs to save a password for the database connection. The
 users, on the other hand need read permission on the script in order to
 execute it but should not be able to read out the password.
 What is the common way to solve this problem?
 
 My current way is to allow the users to execute the script with sudo while
 not having read permission when acting as a ordinary user. But I don't like
 this solutions and consider it very ugly.

There's not a one-size-fits-all answer.  A bunch of possibilities:

- Just have execute permission on the script, not read permission

- If the database server and client are running on the same machine,
use a unix-domain socket instead of a tcp socket, and modify the
server to check that only a specific uid is running the client (you
can do this check with an ancillary message on the socket).  Then use
sudo to get the client to run as that user.  You can then leave read
permission enabled on the script.

- sort of similar: have a separate process running that knows the
password (administrator enters it at startup time).  That process
listens on a unix socket and checks the ID of the client.  It reveals
the password to authorized clients, i.e. your readable script running
under sudo.  This keeps the password from ever being stored on disk.

- Modify the script itself to run as a long-running service instead of
as something that gets started and restarted all the time.  Have an
admin start it and type the password into it at startup time.  Users
then connect to it (maybe with a web browser) and send it commands.

- Move the user operations from the script to server side database
procedures that do their own validity checking.  Then you don't need a
password.

- Run the script on a machine where users can't run arbitrary programs
other than the script.  Set up the db server to not accept any
connections other than from that machine.

Etc. etc., you get the idea.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python limericks (was Re: Text-to-speech)

2005-03-21 Thread Paul Rubin
Scott David Daniels [EMAIL PROTECTED] writes:
A mathematician, prophetic,
invented a language, herpetic.
  decidedly brilliant,
  syntacticly elegant,

syntactically elegant,
with features intelligent

Made ideas far less hypothetic.

Made writing new code copasetic.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python 2.4 (Windows) Binaries of SciPy

2005-03-21 Thread Srijit Kumar Bhadra
Hello,
I have posted a similar message in SciPy mailing list. I hope it is ok
to also post it here.

I am looking for Python 2.4 Binaries (Windows)of SciPy. Are there any
plans to upload Python 2.4 binaries?

Best Regards,
/Srijit

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


Re: getting text from WinXP console

2005-03-21 Thread Jeff Shannon
Lucas Raab wrote:
Chris Maloof wrote:
Does anyone know how I can read the ASCII text from a console window
(from another application) in WinXP?  It doesn't sound like a major
operation, but although I can find the window via pywin32, I haven't
been able to do anything with it.  I'd really just like to get the
window text into a string.
By console window, I mean the sort of thing that comes up when you
run command (although this particular one is for the game NetHack).
If you're looking to do this from Python then do python appname.py  
output.txt only without the quotes. AFAIK, this only works on Windows. 
Correct me if it works from Linux or another OS.
It works in *nix (and probably other OSes as well) to the same extent 
that it works in Windows.  However, it does *not* do what the OP was 
asking for -- it captures the (console-mode) output of appname.py into 
a file, but the OP (as I understand it) wanted to have appname.py 
capture the already-displayed console output of someotherapp.exe.

Unless I'm seriously mistaken, the only way that this will be possible 
is if there's a Win32 API call that will give the correct information. 
 This might be possible to find in the MSDN documentation, if it 
exists, but I suspect that it probably doesn't.

Actually, there's probably a second way -- capture the window image as 
a bitmap, and then run OCR software on it.  I'm not sure how well most 
OCR software will deal with ASCII graphics, though -- they tend to be 
optimized for reading real text (i.e. words in an actual language).

If it's permissible for the capturing program to start the application 
whose output is to be captured, then it may be possible to work as a 
proxy -- the capture app would pass (almost) all input to the child 
app and then retrieve the child app's output (and probably perform the 
actual display on-screen).  This won't let you capture the text of an 
arbitrary window, though, and would probably be pretty fragile.

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


Re: Python scope is too complicated

2005-03-21 Thread Terry Reedy

jfj [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 def foo(x):
  y= (i for i in x)
  return y

 From the disassembly it seems that the generator is a code object

What is type(foo([1,2,3])) ?

 but 'x' is not a cell variable. WTF?

As I understand it, the object 'x' binds to is immediately used to create 
the generator object.  The local name is just a dummy that is not part of 
the result.  I believe that the above is equivalent to

def foo(x):
  def _(z):
for i in z: yield i
  return  _(x)

although I suspect that the implementation builds the generator more 
directly.

Terry J. Reedy



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


Re: xmlrpc with Python and large datases

2005-03-21 Thread writeson
Duncan,

Thanks for the reply. We are running this on an Apache server on the
linux box, and an iPlanet4.1 server on the solaris machines. However,
both these servers are strictly 'inside' the firewall. I checked the
apache configuration and there is no limitrequestbody parameter in the
file at all. So I'm assuming from what you've said that our
configuration would be unlimited. However, I will test that by
inserting limitrequestbody and setting it to 0 for unlimited to see if
that changes things.

Thanks,
Doug

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


Re: Sending hex number as is

2005-03-21 Thread Irmen de Jong
[EMAIL PROTECTED] wrote:
 This question may be ased before, but I couldn't find the answer
 searching the archive.
 
 Basically, I just want to send a hex number from one machine to the
 next:
 
 for example
 
 msg = Length is 
 n = '\x81'
 msg += n
 sock.send(msg)
 
 The problem is n's value is not fixed. For example,
 
 msg = Length is 
 n = len(somestring)
 msg += n  # This won't work of course, since n is int
 
 How do I send this msg + n?
 
 Thanks,
 Khoa
 

Just send the number as a string?
(and parse it to an int again on the other side)

Or investigate the struct and/or pickle modules.

Alternatively, depending on the broader scope of what
you are doing, investigate a proper IPC library such
as Pyro.


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


PIGIP Meeting tonight -- Python Interest Group In Princeton

2005-03-21 Thread [EMAIL PROTECTED]
PIGIP will hold it's March meeting tonight at 7pm at the Lawrenceville
Public Library.
Anyone in Central New Jersey, USA interested in the Python Programming
Language is invited to attend.

We will be reviewing the Python tutorial (Chapters 6,7,and 8), and open
discussion about Python use will be encouraged. Light refreshments will
be served at the meeting.

For more information visit http://www.pigip.org

-- Jon Fox

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


Re: Text-to-speech

2005-03-21 Thread Paul McGuire
Brian,

Having reviewed your Cease and Desist petition, I'm afraid I must
dispute some or all of your claims:

1. Your citation of prior art has one or more significant defects:
a. In your citation, brace is clearly rhymed with whitespace, not
space.  The broad concept of whitespace is substantially different
from the specific term spaces: whitespace encompasses all
white-printing characters, including tabs, formfeeds, and carriage
returns, as well as space characters.  In the more general field of
publishing, whitespace also includes page margins, paragraph breaks,
and block indentations for embedded quotes or subsections.  In my
submission, spaces is specifically intended to narrowly refer to the
character defined in ISO 8879 as ASCII code 32.  Especially, I did
*not* intend to include reference to the ISO 8879 ASCII code 9
character, or tab.
b. Prior art predates your citation, see Guido van Rossum's post
[marketing-python] How About a Slogan or Tagline?, at
http://wingware.com/pipermail/marketing-python/2002-March/003851.html,
which includes several notable references to derivative forms of
brace and space.
2. As the Python language's most salient feature is its usage of spaces
for program structuring, as opposed to use of enclosing brace
characters in related scripting languages (Tcl, Perl) and compiled
languages (C, C++, Java, C#), the juxtaposition of brace and space
in any poetic construct is obvious, and this obviousness further erodes
your IP claim.
3. I think my poem was funnier - lost track of his braces (humorous
allusion to suspenders) is a knee-slapper! (Perl before swine was
cute, but it's not new.)

Still, I am open to negotiation - would you be interested in
cross-licensing my patent pending rhyming of van Rossum and
awesome?

Regards,
-- Paul

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


Re: Sending hex number as is

2005-03-21 Thread Grant Edwards
On 2005-03-21, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 msg = Length is 
 n = '\x81'
 msg += n
 sock.send(msg)

 The problem is n's value is not fixed. For example,

 msg = Length is 
 n = len(somestring)
 msg += n  # This won't work of course, since n is int

 How do I send this msg + n?

n = 0x81
msg = Length is  + chr(n)

That only works for hex numbers than can be properly encoded
as a character in the default encoding.

See the struct module for a more general solution.

-- 
Grant Edwards   grante Yow!  There's a lot of BIG
  at   MONEY in MISERY if you have
   visi.coman AGENT!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pre-PEP: Dictionary accumulator methods

2005-03-21 Thread George Sakkis
Michele Simionato [EMAIL PROTECTED] wrote:

 FWIW, here is my take on the defaultdict approach:

 def defaultdict(defaultfactory, dictclass=dict):
 class defdict(dictclass):
 def __getitem__(self, key):
 try:
 return super(defdict, self).__getitem__(key)
 except KeyError:
 return self.setdefault(key, defaultfactory())
 return defdict

 d = defaultdict(int)()
 d[x] += 1
 d[x] += 1
 d[y] += 1
 print d

 d = defaultdict(list)()
 d[x].append(1)
 d[x].append(2)
 d[y].append(1)
 print d

   Michele Simionato


Best solution so far. If it wasn't for the really bad decision to add the 
dict(**kwargs)
constructor, I'd love to see something like
d = dict(valType=int)
d[x] += 1

George


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


Re: wxPython vs. pyQt

2005-03-21 Thread [EMAIL PROTECTED]
since I'm developing in Tkinter, I'm intrigued by your comment that:
It allowed me to do things in hours,
which literally took weeks with tkinter, 

please elaborate!

Cheers
S

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


Re: For loop extended syntax

2005-03-21 Thread Jeff Shannon
George Sakkis wrote:
A generalization of the 'for .. in' syntax that would handle 
 extra arguments the same way as functions would be:
for (x,y,z=0,*rest) in (1,2,3), (3,4), (5,6,7,8):
 print x, y, z, rest
I'd love to see this in python one day; it is pretty obvious what
 it would do for anyone familiar with function argument tuples.
Let's all keep in mind that for...in... is using standard tuple 
unpacking rules (you're getting the next tuple from a list of tuples, 
and then unpacking that tuple), so what is really being proposed are 
extensions to tuple unpacking.  (Making this work in the context of a 
for loop but not work in other tuple-unpacking situations would create 
inconsistency.)

Function arguments are *not* (in general) a case of tuple unpacking, 
on the other hand, so the parallels between function arguments and for 
loop control-variable tuples are not so straightforward as is being 
claimed.

There may be valid arguments in favor of enhancing tuple unpacking in 
this way (indeed, I believe I recall a thread or two on this subject), 
but it's important to consider the general consequences, not just the 
single aspect of for-loop usage.

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


Re: Text-to-speech

2005-03-21 Thread Bill Mill
On 21 Mar 2005 12:47:07 -0800, Paul McGuire [EMAIL PROTECTED] wrote:
 Brian,
 
 Having reviewed your Cease and Desist petition, I'm afraid I must
 dispute some or all of your claims:
 
 1. Your citation of prior art has one or more significant defects:
 a. In your citation, brace is clearly rhymed with whitespace, not
 space.  The broad concept of whitespace is substantially different
 from the specific term spaces: whitespace encompasses all
 white-printing characters, including tabs, formfeeds, and carriage
 returns, as well as space characters.  In the more general field of
 publishing, whitespace also includes page margins, paragraph breaks,
 and block indentations for embedded quotes or subsections.  In my
 submission, spaces is specifically intended to narrowly refer to the
 character defined in ISO 8879 as ASCII code 32.  Especially, I did
 *not* intend to include reference to the ISO 8879 ASCII code 9
 character, or tab.
 b. Prior art predates your citation, see Guido van Rossum's post
 [marketing-python] How About a Slogan or Tagline?, at
 http://wingware.com/pipermail/marketing-python/2002-March/003851.html,
 which includes several notable references to derivative forms of
 brace and space.
 2. As the Python language's most salient feature is its usage of spaces
 for program structuring, as opposed to use of enclosing brace
 characters in related scripting languages (Tcl, Perl) and compiled
 languages (C, C++, Java, C#), the juxtaposition of brace and space
 in any poetic construct is obvious, and this obviousness further erodes
 your IP claim.
 3. I think my poem was funnier - lost track of his braces (humorous
 allusion to suspenders) is a knee-slapper! (Perl before swine was
 cute, but it's not new.)
 
 Still, I am open to negotiation - would you be interested in
 cross-licensing my patent pending rhyming of van Rossum and
 awesome?
 

T'were two coders in c.l.p
Who liked to argue legally
About copyright
All day and night,
Just to prove their inanity
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sending hex number as is

2005-03-21 Thread Terry Reedy

[EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Basically, I just want to send a hex number from one machine to the
 next:

'Hex number' is not completely clear.  Do you want to send the number in 
binary form or in text form.  Text form is much easier and more dependable, 
so should be prefered unless you have a good reason for binary.  When 
sending a text string, you still have a choice between decimal and other 
representations.  Again, decimal is easier and more dependable, and 
therefore prefered, unless the receiving end really demands otherwise.

msg = 'The length is %s' % len(something)

Terry J. Reedy



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


Re: Wikipedia - conversion of in SQL database stored data to HTML

2005-03-21 Thread Claudio Grondi

http://tinyurl.com/692pt redirects (if not just down) to
http://en.wikipedia.org/wiki/Wikipedia:Database_download#Static_HTML_tree_dumps_for_mirroring_or_CD_distribution

I see from this page only one tool (not a couple) which is available
to download and use:

http://www.tommasoconforti.com/ the home of Wiki2static

Wiki2static (version 0.61, 02th Aug 2004)
http://www.tommasoconforti.com/wiki/wiki2static.tar.gz
is a Perl script to convert a Wikipedia SQL dump
into an html tree suitable for offline browsing or CD distribution.

I failed to find any documentation, so was forced to play
directly with the script settings myself:

  $main_prefix = u:/WikiMedia-Static-HTML/;
  $wiki_language = pl;

and running (in the current directory of the script):
\ wiki2static.pl Q:\WikiMedia-MySQL-Dump\pl\20040727_cur_table.sql
to test the script on a file with small (112 MByte)
size of the SQL dump .

The script is running now for over half an hour
and has created yet 1.555 folders and
generated 527 files with a total size of  6 MBytes
consuming only 16 seconds of CPU time.
I estimate the time until the script is ready to appr.
6 hours for a 100 MByte file, which gives 120 hours
for a 2 GByte file of the english dump ...

Any further hints? What am I doing wrong?

(There are now 1.627 folders and 1.307 files with
a total size of 15.6 MB after one hour runtime and
consumption of 20 seconds CPU time even if
I increased the priority of the process to high
on my W2K box running perl 5.8.3 half an hour
ago)

Claudio
P.S.
 I loaded all of the Wikipedia data into a local MySQL server a while
 back without any problems.
What was the size of the dump file imported to
the MySQL database? Importing only the current
version which was a while back smaller
than 2 GByte (skipping the history dump)
causes no problems with MySQL.

Leif K-Brooks [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 Claudio Grondi wrote:
  Is there an already available script/tool able to extract records and
  generate proper HTML code out of the data stored in the Wikipedia SQL
  data base?

 They're not in Python, but there are a couple of tools available here:
 http://tinyurl.com/692pt.

  By the way: has someone succeeded in installation of a local
  Wikipedia server?

 I loaded all of the Wikipedia data into a local MySQL server a while
 back without any problems. I haven't attempted to run Mediawiki on top
 of that, but I don't see why that wouldn't work.


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


Re: PyGTK and pyexe

2005-03-21 Thread Viktor
I succeeded :)))

And the winner is:



from distutils.core import setup
import py2exe

opts = {
py2exe: {
includes: [pango, atk, gobject, gtk,gtk.glade],
dll_excludes: [iconv.dll, intl.dll,
libatk-1.0-0.dll, libgdk_pixbuf-2.0-0.dll,
libgdk-win32-2.0-0.dll, libglib-2.0-0.dll,
libgmodule-2.0-0.dll, libgobject-2.0-0.dll,
libgthread-2.0-0.dll, libgtk-win32-2.0-0.dll,
libpango-1.0-0.dll, libpangowin32-1.0-0.dll,
libxml2, libglade-2.0-0, zlib1]
}
}

setup(
name = PyGTKTest,
description = PyGTK Test Application,
version = 0.1,
windows = [{script: test.py, icon_resources: [(1,
test.ico)]}],
options=opts,
data_files=[(, [test.glade])]
)

...

Py2exe reports an error if I try to use --force (the command doesn't
exist), so I use only:

python setup.py py2exe --exclude
gobject,glib,gtk,glade,pango,atk,libglade,xml2,zlib

After that I make a new directory, say MyApp, copy the entire content
of
the GTK folder (I'm using the GTK Runtime Enviroment from
gladewin32.sourceforge.net) in MyApp, and then copy the content of the
dist folder into MyApp\bin.

Now I can uninstall GTK Runtime Enviroment, and Python, and it works
:).

But it's pretty big, what files can I remove? (OK, I know... locales,
man
pages, examples :), but what more - it's still  20 MB?)

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


Re: PyGTK and pyexe

2005-03-21 Thread Tom Cocagne
  I remember removing the locales and all of the documentation. Beyond that
I can't remember. If your app falls under the common case of running on
machines with ample disk space, I wouldn't worry too much about the size.
WinZip does a pretty good job of shrinking my distribution file to a
managable size for network transfer.

 Tom

Viktor wrote:

 I succeeded :)))
 
 And the winner is:
 
 
 
 from distutils.core import setup
 import py2exe
 
 opts = {
 py2exe: {
 includes: [pango, atk, gobject, gtk,gtk.glade],
 dll_excludes: [iconv.dll, intl.dll,
 libatk-1.0-0.dll, libgdk_pixbuf-2.0-0.dll,
 libgdk-win32-2.0-0.dll, libglib-2.0-0.dll,
 libgmodule-2.0-0.dll, libgobject-2.0-0.dll,
 libgthread-2.0-0.dll, libgtk-win32-2.0-0.dll,
 libpango-1.0-0.dll, libpangowin32-1.0-0.dll,
 libxml2, libglade-2.0-0, zlib1]
 }
 }
 
 setup(
 name = PyGTKTest,
 description = PyGTK Test Application,
 version = 0.1,
 windows = [{script: test.py, icon_resources: [(1,
 test.ico)]}],
 options=opts,
 data_files=[(, [test.glade])]
 )
 
 ...
 
 Py2exe reports an error if I try to use --force (the command doesn't
 exist), so I use only:
 
 python setup.py py2exe --exclude
 gobject,glib,gtk,glade,pango,atk,libglade,xml2,zlib
 
 After that I make a new directory, say MyApp, copy the entire content
 of
 the GTK folder (I'm using the GTK Runtime Enviroment from
 gladewin32.sourceforge.net) in MyApp, and then copy the content of the
 dist folder into MyApp\bin.
 
 Now I can uninstall GTK Runtime Enviroment, and Python, and it works
 :).
 
 But it's pretty big, what files can I remove? (OK, I know... locales,
 man
 pages, examples :), but what more - it's still  20 MB?)

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


Python 2.4 | 7.3 The for statement

2005-03-21 Thread brainsucker
Hi My name is Juan Carlos Rodrigo, and I love Python.
It is the most impressive and usefull language that
I have ever seen.

I am studing, at http://www.uoc.edu, an Information
Technology Postgraduate. And I have programmed some
REXX applications in my past Jobs (So I love python,
no more ENDS).

** Reposting from Python-Dev with some more comments.

888888

Python 2.4 | 7.3 The for statement:
---

 for_stmt ::= for target_list in expression_list :
  suite [else : suite]


New for statement:
--

for_stmt ::= for target_list in expression_list
 [ and expression ] :
  suite [else : suite]

  ** If the expression evaluates to False before
 entering the for, jump else.
  ** If the expression is evaluated to False after
 the first iteration, break.


So ¿What we can do with this new for?,
and ¿It is going to avoid line exceed?:

My second remark is that our intellectual powers are rather
geared to master static relations and that our powers to
visualize processes evolving in time are relatively poorly
developed. [1]


It is easier if we see it beforehand:
-

leave = False
alist = [1,2,3,3,4,5,6,7,8,9]
for item in alist and not leave:
 if item is 1: leave = True


Avoiding code exceed:
-

a = 1
b = 2
c = 3
alist = [1,2,3,4,5,6,7,8,9]
for item in alist and a  2 and b  3 and c  4:
 if item == 3: a += 1
 if item == 2: b += 1
 if item == 1: c += 1
print %d %d %d % (a,b,c)
# three lines off (25% less on breaks)


Other features and the else:


alist = [1,2,3]
enter = False
if list[0] == 4:
 enter = True
for item in alist and enter:
 print item
else:
 print No account


The real problem:
-

The exercise to translate an arbitrary flow diagram more or
less mechanically into a jump-less one, however, is not to be
recommended. [1]

Ok, it's not recommended, at large, but Python should make it possible,
and then the people will choose.


[1] Go To Statement Considered Harmful
Edsger W. Dijkstra
http://www.acm.org/classics/oct95/

PD: Your work is impressive, thanks.

888888

+++ Andrew Koenig wrote:

 for_stmt ::= for target_list in expression_list
  [ and expression ] :
   suite [else : suite]

 It can't work.  The expression_list could be just a variable, as
could the
 expression, in which case you get

 for target_list in variable and variable :

Considering that your for definition is not correct.

 and, of course

   variable and variable

 is already an expression.  So it's ambiguous.

No my definition has no ambiguity in it and your idea does
not work as you think, because is not an expression as you
incorrectly wrote out, is an expression_list:

 leave = True
 l = [1,2,3,4]
 form item in l and leave:
  File stdin, line 1
form item in l and leave:

And your example what really does is iterating over the
expression_list (BTW: and cannot be used as you point out):

 leave = True
 l = [1,2,3,4]
 for item in l, leave:
... print item
...
[1, 2, 3, 4]
True


+++ Nick Coghlan wrote:

 Interesting idea, but not really needed given the
 existence of the break statement:

 for item in alist:
   if item is 1:
 break

Well Nick the point here is to have the possibility
to leave for loops without using the break statement,
and of course use breaks too.


+++ Nick Coghlan wrote:

 All non-sequential control structures are merely constrained ways of
 using goto (the underlying machine code will devolve into conditional

 and unconditional branches and jumps - i.e. goto's).

No doubt Nick, but were are programming on a very, very high level
language.

  
 'break' is a highly constrained form of goto and a fundamental part
 of structured programming (as is 'continue')

Well you are expressing it better than I am.

 I used to share your sentiment regarding break and continue -
 experience (especially Python experience) has convinced me otherwise.

 Python embraces the concept of breaking out of a loop to the point
 that it even has an 'else' clause on loop structures that is executed

 only if the loop is exited naturally rather than via a break
statement.

And It will be better with by for breaking possibilities.

 Regardless of whether you personally choose to use break and
 continue, the existence of those statements is the main reason
 that the addition of a flag condition to for loops is highly
 unlikely.

¿Why is that C has both break, continue and in for breaking
capabilities?

Thanks for your comments.

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


  1   2   >