ReleaseForge 0.5 - A SourceForge project release tool

2005-03-20 Thread [EMAIL PROTECTED]
What is ReleaseForge?  How silly of you to ask, but I shall satisfy
your silly curiosity nonetheless.

Are you a project administrator -or- release tech/engineer of at least
one SourceForge-based project?  If not, skip this message and don't
read further... ReleaseForge is not for you.

Still with me?  Then you must be responsible for file releases of one
or more SourceForge projects, either that, or, you're desperately in
need of a life since ReleaseForge is of no use to you.


ReleaseForge is a GUI application that offers many advantages to using
SourceForge's package release system:

- ReleaseForge allows you to quickly and effortlessly create a new
release of one of your SourceForge project packages.

- When creating a new release, you enter the release information
(version number, change log, release notes) and then specify the files
to include in the release.

- ReleaseForge guesses the type of file (.gz, .zip, .rpm, .exe, etc...)
for each of your files.

Once you are satisfied with the release, ReleaseForge does all of the
tedious work so that you don't have to:

- Contacts SourceForge and adds your new release to your project's
package.

- Uploads all of your files for the release to the SourceForge FTP
server.

- Uploads your release notes and change log.

- Automatically selects each of your uploaded files for inclusion in
your new release.

- Automatically applies the processor type and file type to each of
your files.

- If applicable, notifies monitoring users of the new release.

These are just some of the awesome ReleaseForge features, you can learn
more by checking out the ReleaseForge site at:

http://releaseforge.sourceforge.net

There is a FAQ and lots of pretty pictures of supermodels, err,
screenshots.  Either way, you'll be glad you visited the site, or not.

ReleaseForge is written in Python (version 2.3 or greater) and uses
PyQt for it's snazzy user interface.  

Phil

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

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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Mike Rovner
Paul Rubin wrote:
If the compiler can do some type inference, it can optimize out those
multiple calls pretty straightforwardly.
It can be tipped like that:
di = dict(int)
di.setdefault(0)
di[key] += 1
dl = dict(list)
dl.setdefault([])
dl.append(word)
dl.extend(mylist)
But the point is that if method not found in dict it delegated to 
container type specified in constructor.

It solves dict specialization without bloating dict class and is generic.
Mike
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Paul Rubin
Mike Rovner [EMAIL PROTECTED] writes:
 It can be tipped like that:
 
 di = dict(int)
 di.setdefault(0)
 di[key] += 1
...
 But the point is that if method not found in dict it delegated to
 container type specified in constructor.
 
 It solves dict specialization without bloating dict class and is generic.

Hey, I like that.  I'd let the default be an optional extra arg to the
constructor:

   di = dict(int, default=0)
   di[key] += 1

without the setdefault.  I might even add optional type checking:

  di = dict(int, default=0, typecheck=True)
  di[key] = 'foo'# raises TypeError
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Configure this group in email client

2005-03-20 Thread kiran
Try 62.181.3.13 (Global news server)
Also, check this thread
http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/df0f1bc9514bf353/3fe59b5daf26dc89?q=thunderbird#3fe59b5daf26dc89

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


Re: 1 + 2 = 3

2005-03-20 Thread Do Re Mi chel La Si Do
4


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


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

2005-03-20 Thread Bennie
Hi,
I have a problem with ZipFile.
It works okay untily I come across a file that is greater then 1Gb.
Then it exit with the error:
OverflowError: long int too large to convert to int
How can I fix this?
souce:
zip = zipfile.ZipFile(file, 'w')

for all in os.walk(os.getcwd()):
path = all[0]
for document in all[2]:
zipaccview.write(path + os.sep + document)
zip.close()
Bennie
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Duncan Booth
Raymond Hettinger wrote:

 The rationale is to replace the awkward and slow existing idioms for
 dictionary based accumulation:
 
 d[key] = d.get(key, 0) + qty
 d.setdefault(key, []).extend(values)
 

How about the alternative approach of allowing the user to override the 
action to be taken when accessing a non-existent key?

   d.defaultValue(0)

and the accumulation becomes:

   d[key] += 1

and:

   d.defaultValue(function=list)

would allow a safe:

  d[key].extend(values)

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


Re: wxPython vs. pyQt

2005-03-20 Thread Andrew E
Hans-Peter Jansen wrote:
..
While in PyQt world, I found these advantages:
 + conceptually vastly superior
 + powerful api/widgets/features
 + fast as hell due to the efficient binding of a quite efficient lib
 + cool tools, that are unicode/translation aware
 + very efficient programming environment/unbeatable productivity
While this sounds like the average sales talk, I will try to backup these
claims a bit:
 ..
I've been a wx user since around 1999 and overall I like it. It annoys 
me a *lot* sometimes, but as Qt was always prohibitively expensive for 
commercial development, it was the only real option.

The key question from my point of view is: can I write commercial 
sell-if-I-want-to applications using Qt? If it is GPL, then I guess the 
answer is 'no'?

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


Re: sound processing - avarage amplitude?

2005-03-20 Thread TZOTZIOY
On Sat, 19 Mar 2005 17:18:42 +0200, rumours say that Niklas Paro [EMAIL 
PROTECTED]
might have written:

Hello

I would need way to check the amplitude (over time) for a sound file in
python. I'm sure this can be done, for example the audioop.rms function
seems to be able return amplitude values. However, it would be really
great to get the results in dB, which does not seem to be the case.
Anyone who has more information about this, or a way to convert the
results? I've searched google but info about audioop seem to be quite
scarce. Also, does audioop function perfectly also for wave files? Also,
cross-platform solutions are of course preferred, but I'm running linux
(with oss).

audioop is platform independent.  You just might need to import wave also.

I've also looked somewhat into tkSnack (http://www.speech.kth.se/snack/)
which has a dBPowerSpectrum function which might be doing at least
partially what i want it to, however, the returned values are approx.
-100 ... which I find odd. The real, recorded sound was somewhere in
the 50-60dB range.

Where is your 0dB mark?  If it's at maximum amplitude (1), then any value
(except zero) can be expressed as (negative) dB by the following function:

def amp2dB(amplitude):
return 20*math.log(amplitude, 10)

If you're converting from the 0...32767 range of 16bit PCM files, first divide
the amplitude by 32767.0 and pass the result to amp2dB.

thanks in advance

Hope this helps.
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython vs. pyQt

2005-03-20 Thread Duncan Booth
Swaroop C H wrote:

 For those who don't know, Qt 4 on Windows will be available under GPL.
 So, you can write a (GPLed) app using Qt 4 and run it on Windows, Mac,
 Linux and even embedded!
 

Yes, but the FAQ implies to me that they really don't want to encourage
people to use the GPL: 

 Q: I want to dual license my software too! That means I can use the
 Open Source edition for development, right? 
  
 A: No. In order to write software that will be sold or licensed
 commercially, in addition to open source, all of your programmers will
 need a commercial license from the outset of the development phase. 
 
 If you use the Open Source edition of Qt, you can only publish the
 software under the GPL. Trolltech's commercial license terms do not
 allow you to develop any proprietary software using the Open Source
 edition. 

If I read this correctly, if you use the GPL version of QT to do any 
development work you can never release any of the code under anything other 
than the GPL, not even by retrospectively paying Trolltech all the license 
fees they would have been due for it to be a commercial development.

Also, if you have bought your commercial license, you cannot benefit from 
the pool of existing GPL code by approaching the original author and 
arranging to pay them for a non-GPL license for use within your product.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Matteo Dell'Amico
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)
They look as a special-case to me. They don't solve the problem for 
lists of sets or lists of deques for instance, not to mention other 
possible user-defined containers.

defaultdicts look to me as a solution that is more elegant and solves 
more problems. What is the problem with them?

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


Re: How two modules call functions defined in each other?

2005-03-20 Thread TZOTZIOY
On 19 Mar 2005 18:07:31 -0800, rumours say that Tian [EMAIL PROTECTED]
might have written:

I am python beginner, I have a question about the interdependence of
modules.

For example, when I have two modules:

module1.py
-
def plus(x):
  return add(x,1)


module2.py
-
def add(x,y):
  return x+y

def plus2(x):
  return plus(x)+1

How should I write import in both files?

In module1, import module2 and vice versa.  From moduleX, you access any
attribute (function or variable) of moduleY by using moduleY.attribute .

What about the global varibals? is there anything like extern keyword
in C?

There are no global variables in Python, only module-level attributes.  If by
global you mean the main program's (which is also a module) attributes, in your
other modules do a:

import __main__

and then access its attributes as __main__.attribute .  It's not generally a
good idea in Python, though, so you might like to explain what you need to do so
that we suggest alternate approaches.

or python has some other solutions?

Cheers!
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Reinhold Birkenfeld
Mike Rovner wrote:
 Paul Rubin wrote:
 
 If the compiler can do some type inference, it can optimize out those
 multiple calls pretty straightforwardly.
 
 It can be tipped like that:
 
 di = dict(int)
 di.setdefault(0)
 di[key] += 1

Interesting, but why do you need to give the int type to the constructor?

 dl = dict(list)
 dl.setdefault([])
 dl.append(word)
 dl.extend(mylist)

I don't quite understand that. Which dict item are you extending? Don't
you need something like

dl[key].append(word)

?

Anyway, using `setdefault' as the method name is quite confusing,
although yours is IMHO a much better behavior given the name ;)

So what about `setdefaultvalue'?

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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Reinhold Birkenfeld
John Machin wrote:
 Reinhold Birkenfeld wrote:
 John Machin wrote:
 Are you kidding? If you know what set and default means, you will
 be
 able to guess what setdefault means. Same goes for updateBy.

 
 No I'm not kidding -- people from some cultures have no difficulty at
 all in mentally splitting up words like setdefault or the German
 equivalent of Danubesteamnavigationcompany'sdirector'swife; others
 from other cultures where agglutinisation is not quite so rife will
 have extreme difficulty.

Okay - as I'm German I might be preoccupied on this matter wink

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


generating audio signals

2005-03-20 Thread nicke
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.

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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Reinhold Birkenfeld
George Sakkis wrote:
 -1 form me.

 I'm not very glad with both of them ( not a naming issue ) because i
 think that the dict type should offer only methods that apply to each
 dict whatever it contains. count() specializes to dict values that are
 addable and appendlist to those that are extendable. Why not
 subtractable, dividable or right-shiftable? Because of majority
 approval? I'm mot a speed fetishist and destroying the clarity of a
 very fundamental data structure for speedup rather arbitrary
 accumulations seems to be a bad idea. I would move this stuff in a
 subclass.

 Regards Kay
 
 +1 on this. The new suggested operations are meaningful for a subset of all 
 valid dicts, so they
 should not be part of the base dict API. If any version of this is approved, 
 it will clearly be an
 application of the practicality beats purity zen rule, and the 
 justification for applying it in
 this case instead of subclassing should better be pretty strong; so far I'm 
 not convinced though.

So, would the `setdefaultvalue' approach be more consistent in your eyes?

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


Re: How two modules call functions defined in each other?

2005-03-20 Thread Reinhold Birkenfeld
Tian wrote:
 I am python beginner, I have a question about the interdependence of
 modules.
 
 For example, when I have two modules:
 
 module1.py
 -
 def plus(x):
   return add(x,1)
 
 
 module2.py
 -
 def add(x,y):
   return x+y
 
 def plus2(x):
   return plus(x)+1
 
 
 How should I write import in both files?
 What about the global varibals? is there anything like extern keyword
 in C?
 or python has some other solutions?

Yes. Either define plus and add in module1 or define each one in a
separate module.

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


Re: generating audio signals

2005-03-20 Thread Alia Khouri
http://www.python.org/moin/PythonInMusic

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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Roose
 How about the alternative approach of allowing the user to override the
 action to be taken when accessing a non-existent key?

d.defaultValue(0)

I like this a lot.  It makes it more clear from the code what is going on,
rather than having to figure out what the name appendlist, count, tally,
whatever, is supposed to mean.  When you see the value you'll know.

It's more general, because you can support dictionaries and sets then as
well.

I think someone mentioned that it might be a problem to add another piece of
state to all dicts though.  I don't know enough about the internals to say
anything about this.

setdefault gets around this by having you pass in the value every time, so
it doesn't have to store it.  It's very similar, but somehow many times more
awkward.



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


simultaneous copy to multiple media

2005-03-20 Thread Claudio Grondi
I would like to save time copying the same file
(6 GByte) to various different target storage
media connected to the system via USB.

Is there a (Python or other) tool able to help me
to do this, so that I don't need to copy the
source file first to the first media, then to the
second, etc.?

Claudio


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


Re: simultaneous copy to multiple media

2005-03-20 Thread Swaroop C H
On Sun, 20 Mar 2005 11:41:10 -, Claudio Grondi
[EMAIL PROTECTED] wrote:
 I would like to save time copying the same file
 (6 GByte) to various different target storage
 media connected to the system via USB.
 
 Is there a (Python or other) tool able to help me
 to do this, so that I don't need to copy the
 source file first to the first media, then to the
 second, etc.?

If you are using *nix, maybe you can use the `tee` command[1] and
redirect the file to different places.

For example,

cat somefile | tee file1 | tee file2  file3

I haven't tried it out but it should work.

[1]: http://unixhelp.ed.ac.uk/CGI/man-cgi?tee

HTH,
-- 
Swaroop C H
Blog: http://www.swaroopch.info
Book: http://www.byteofpython.info
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-03-20 Thread TZOTZIOY
On Sun, 20 Mar 2005 10:44:06 +0100, rumours say that Bennie [EMAIL PROTECTED]
might have written:

Hi,

I have a problem with ZipFile.
It works okay untily I come across a file that is greater then 1Gb.
Then it exit with the error:
   OverflowError: long int too large to convert to int

How can I fix this?

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).

souce:
   zip = zipfile.ZipFile(file, 'w')
   
   for all in os.walk(os.getcwd()):
   path = all[0]
   for document in all[2]:
   zipaccview.write(path + os.sep + document)

   zip.close()

Can it be that you are creating a zip file that its total size exceeds the
limit?
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pre-PEP: Dictionary accumulator methods - typing initialising

2005-03-20 Thread Kay Schluehr
Duncan Booth wrote:
 Raymond Hettinger wrote:

  The rationale is to replace the awkward and slow existing idioms
for
  dictionary based accumulation:
 
  d[key] = d.get(key, 0) + qty
  d.setdefault(key, []).extend(values)
 

 How about the alternative approach of allowing the user to override
the
 action to be taken when accessing a non-existent key?

d.defaultValue(0)

 and the accumulation becomes:

d[key] += 1

 and:

d.defaultValue(function=list)

 would allow a safe:

   d[key].extend(values)

+0

The best suggestion up to now. But i find this premature because it
addresses only a special aspect of typing issues which should be
disussed together with Guidos type guard proposals in a broader
context. Besides this the suggestion though feeling pythonic is still
uneven.

Why do You set

d.defaultValue(0)
d.defaultValue(function=list)

but not

d.defaultValue(0)
d.defaultValue([])

?

And why not dict(type=int), dict(type=list) instead where default
values are instantiated during object creation? A consistent pythonic
handling of all types should be envisioned not some ad hoc solutions
that go deprecated two Python releases later.

Regards Kay

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


Re: simultaneous copy to multiple media

2005-03-20 Thread Jacek Trzmiel


Claudio Grondi wrote:
 
 I would like to save time copying the same file
 (6 GByte) to various different target storage
 media connected to the system via USB.
 
 Is there a (Python or other) tool able to help me
 to do this, so that I don't need to copy the
 source file first to the first media, then to the
 second, etc.?

Use 'tee' command from shell:
tee file /dest1/file /dest2/file

Or run two copies in parallel (one of them probably will read file from
cache):
cp file /dest1/file  cp file /dest2/file


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


Re: survey of modules to be added to stdlib

2005-03-20 Thread Alia Khouri
It would be amazing if you could add the feature to do combo package
installs like :

- a scientific python combo (which would include scipy, numarray,
Numpy, plotting libs, etc)

- an AI python combo(orange, constraint programming modules, agent
libs, etc)

- a game development python combo (pygame, pysonic, 3D libs, etc...)

- a musical python combo 


you get the idea (-;

AK

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


Re: Variable Variable

2005-03-20 Thread Kay Schluehr
 I'm going to make this explicit:  the PHP idiom is a defect.
 Yes, I know that's good style among top PHP practitioners,
 but, from all I know, it's simply a bad habit.  The advice to
 use a dictionary is on target.

I tried to like it the whole last hour ;-)

I reconstructed the formal structure of $$var from a PHP Web-tutorial
though i do not have any experience with the language.

This is what i got:

$   =
Name --- Var -- VarxString
  ||
   $  | #  |  $ o q' o proj2
  ||
  VV
Var - f --Var
  ||
  | #  |  =
  |V
  +- VarxString
=

In the diagram $ is an operator that creates a var from a name, = is an
operator that binds a string to a var and q' drops quotations from a
string to get an name. The function f is an implied isomorphism. It
represents the equivalence of $$a and $b, where $a = b.

Personally I could live with that, but the diagram is a bit special
because of the restriction of the = operation. I do not know if PHP
supports this operational view by enabling iterations: $a, $$a, $$$a
... ?

After all I can also live without that in Python...

Regards Kay

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


Re: Variable Variable

2005-03-20 Thread Diez B. Roggisch
 
 Personally I could live with that, but the diagram is a bit special
 because of the restriction of the = operation. I do not know if PHP
 supports this operational view by enabling iterations: $a, $$a, $$$a
 ... ?

It does. 
-- 
Regards,

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


Python scope is too complicated

2005-03-20 Thread Max
Yeah, I know. It's the price we pay for forsaking variable declarations. 
But for java programmers like me, Py's scoping is too complicated. 
Please explain what constitutes a block/namespace, and how to refer to 
variables outside of it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python scope is too complicated

2005-03-20 Thread TZOTZIOY
On Sun, 20 Mar 2005 13:53:34 +0200, rumours say that Max
[EMAIL PROTECTED] might have written:

Yeah, I know. It's the price we pay for forsaking variable declarations. 
But for java programmers like me, Py's scoping is too complicated. 
Please explain what constitutes a block/namespace, and how to refer to 
variables outside of it.

I presume you read 4.1 Naming and binding from Python reference manual.

What constitutes a block is answered in paragraph 2, for example.  Please come
back with confusing / missing information in that chapter giving us a chance to
improve the documentation.

Cheers!
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Max
Paul Rubin wrote:
Reinhold Birkenfeld [EMAIL PROTECTED] writes:
Any takers for tally()?
Well, as a non-native speaker, I had to look up this one in my
dictionary. That said, it may be bad luck on my side, but it may be that
this word is relatively uncommon and there are many others who would be
happier with increment.

It is sort of an uncommon word.  As a US English speaker I'd say it
sounds a bit old-fashioned, except when used idiomatically (let's
tally up the posts about accumulator messages) or in nonstandard
dialect (Hey mister tally man, tally me banana is a song about
working on plantations in Jamaica).  It may be more common in UK
English.  There's an expression tally-ho! which had something to do
with British fox hunts, but they don't have those any more.
Has anyone _not_ heard Jeff Probst say, I'll go tally the votes?!
:)
--Max
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python scope is too complicated

2005-03-20 Thread jfj
Max wrote:
Yeah, I know. It's the price we pay for forsaking variable declarations. 
But for java programmers like me, Py's scoping is too complicated. 
Please explain what constitutes a block/namespace, and how to refer to 
variables outside of it.

Some may disagree, but for me the easiest way to understand python's
scopes is this:
In Python, there are only two scopes.  The global and the local.
The global scope is a dictionary while the local, in the case of a
function is extremely fast.  There are no other scopes.  There are
no scopes in the nested statements inside code blocks and there are
no class scopes.  As a special case, nested function definitions
appear to be something like a nested scope, but in reallity this is
detected at compile-time and a strange feature called 'cell variables'
is used
In order to write to a global variable from a function, we have
to use:
global var
which notifies the compiler that assignment to 'var' does not make
a new local variable, but it modifies the global one (OT: wouldn't
global.var = 3 be nicer?).  On the other hand, if we just want to
read a global variable we don't have to say global var because
the compiler sees that there is no assignment to 'var' in the function
code and therefore intelligently concludes that it's about a global
one.
Generally, python sees everything as
exec code in global_dictionary, local_dictionary
In this case it uses the opcode LOAD_NAME which looks first in locals
and then in globals (and actually, then in __builtins__)
For functions it uses either LOAD_FAST for locals or LOAD_GLOBAL for
globals.
HTH
jfj
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.4 crashes when try to exit app and mulitple threads active

2005-03-20 Thread Maxwell Hammer
On Sat, 19 Mar 2005 22:35:39 -0500, Peter Hansen wrote:

 When you say only one thread running, did you mean only
 one monitor thread in addition to the main thread, or did
 you really mean only the main thread was active at this time?

I meant there was the main app and one thread. The problem
does not occur when there are no threads running and the app
has to exit.

 Also, are you doing something odd to terminate threads
 here, and could you have screwed things up yourself?
Very likely - it has happened before :-)

 The code in question is at the end of the MainThread's
 __exitfunc() method, and normally this would be executing
 only after all other threads had terminated, and should
 be safe.  It appears as though the _active dictionary that
 tracks threads has been modified by someone else.

That is what it looks like to me. It seems that the interpreter
is trying to delete a non-existant thread

 Can you post a small self-contained example that
 reproduces the problem?
This will be difficult to do...but perhaps if I give a summary:

def main():
...initialize/configure
...wait for certain events
...based on events launch appropriate thread as follows:

thread.start_new_thread(event_module.run, (StateValues, (job_parms)))
...

def event_module.run(StateValues, (job_parms)):
...initialize/configure
while (1):
Return = os.system(RunString)

if Shutdown flag exists:#thread detects here if needs 
to exit
save_job(parms)
cleanup_exit(message, exit_code)
if Return == 0: # SUCCESS
break
elif Return == 1:   # ERROR
... 
elif Return == 7:   # ERROR
...

def cleanup_exit(message, exit_code):
remove temp files
log message, etc
return

So at shutdown, any threads running save their state to a job file
then simply do a return.

Hope this helps...also I use command line apps to program like Nedit.

Know of any visual python debuggers? I know there is idle...
any others, better ones? 
Have you heard of eric python ide. Is it good? - it would have debug
capabilities but is dependent on many libraries I think.

thanks a lot.

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


Re: importing two modules with the same name

2005-03-20 Thread Francisco Borges
El Pitonero wrote:
  #- Main.py: your program
 import imp
 # load the third party module into sys.modules
 imp.load_source('A', '', open('C:\\A.py'))
 # load and execute your changes

Thanks a bunch for the hint. The imp module did take care of the job,
but just to mention load_source seems to be deprecated, so I used

fp, mpath, desc = imp.find_module('optparse',a)
s_opt = imp.load_module('std_optparse', fp, mpath, desc)

again, thanks for the help! 

Cheers,
Francisco

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


Overloaded Constructors?!?

2005-03-20 Thread andrea_gavana
 Hello NG,

   I am trying to port a useful class from wxWidgets (C++) to a pure 
Python/wxPython
implementation. In the C++ source code, a unique class is initialized with
2 different methods (???). This is what it seems to me. I have this 
declarations:

class wxFoldWindowItem
{
private:
wxWindow *_wnd;
int _type, _flags;
int _leftSpacing,
_rightSpacing,
_ySpacing;
int _lineWidth, _lineY;
wxColour _sepLineColour;

public:
enum
{
WINDOW = 0,
SEPARATOR
};

// wxWindow constructor. This initialises the class as a wxWindow type
wxFoldWindowItem(wxWindow *wnd, int flags = wxFPB_ALIGN_WIDTH, int ySpacing
= wxFPB_DEFAULT_YSPACING,
 int leftSpacing = wxFPB_DEFAULT_LEFTSPACING, int 
rightSpacing
= wxFPB_DEFAULT_RIGHTSPACING)
: _wnd(wnd)
, _type(WINDOW)
, _flags(flags)
, _leftSpacing(leftSpacing)
, _rightSpacing(rightSpacing)
, _ySpacing(ySpacing)
, _lineWidth(0)
, _lineY(0)
{
};

// separator constructor. This initialises the class as a separator
type
wxFoldWindowItem(int y, const wxColour lineColor = *wxBLACK, int ySpacing
= wxFPB_DEFAULT_YSPACING,
 int leftSpacing = wxFPB_DEFAULT_LEFTLINESPACING,
 int rightSpacing = wxFPB_DEFAULT_RIGHTLINESPACING)

: _wnd(0)
, _type(SEPARATOR)
, _flags(wxFPB_ALIGN_WIDTH)
, _leftSpacing(leftSpacing)
, _rightSpacing(rightSpacing)
, _ySpacing(ySpacing)
, _lineWidth(0)
, _lineY(y)
, _sepLineColour(lineColor)
{
};

The 2 different initializations refers to completely different objects (the
first one is a wx.Window, the second one is an horizontal line). Next, there
are a lot of functions that, depending on the variable _type, return properties
of the wx.Window or of the line. I would like to keep the same names for
classes/methods, so it would be useful to have the same class with 2 different
initializations.
Does anyone know if is there a way to achieve the same thing in Python/wxPython?
Someone else has talked about overloaded constructors, but I don't have
any idea on how to implement this kind of constructors in Python. Does
anyone have a small example of overloaded constructors in Python?
I have no idea... Or am I missing something obvious?

Thanks to you all.

Andrea.


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


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

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

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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Peter Hansen
Max wrote:
Has anyone _not_ heard Jeff Probst say, I'll go tally the votes?!
:)
Who is Jeff Probst?
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.4 crashes when try to exit app and mulitple threads active

2005-03-20 Thread Peter Hansen
Maxwell Hammer wrote:
On Sat, 19 Mar 2005 22:35:39 -0500, Peter Hansen wrote:
When you say only one thread running, did you mean only
one monitor thread in addition to the main thread, or did
you really mean only the main thread was active at this time?
I meant there was the main app and one thread. The problem
does not occur when there are no threads running and the app
has to exit.
Okay, but make sure you understand that it's not possible
to have no threads running unless your application has
already exited.  There is *always* at least the main thread.
I think you know that, but it's confusing when you keep
talking as though the main thread doesn't exist.
The code in question is at the end of the MainThread's
__exitfunc() method, and normally this would be executing
only after all other threads had terminated, and should
be safe.  It appears as though the _active dictionary that
tracks threads has been modified by someone else.
That is what it looks like to me. It seems that the interpreter
is trying to delete a non-existant thread
More than that, it's the MainThread in threading.py trying
to delete itself at exit, and that should always be possible
unless you've done Something Bad (or if this is indeed some
Python bug).
Can you post a small self-contained example that
reproduces the problem?
This will be difficult to do...but perhaps if I give a summary:
def main():
...initialize/configure
...wait for certain events
...based on events launch appropriate thread as follows:
thread.start_new_thread(event_module.run, (StateValues, (job_parms)))
...
Unfortunately, pseudo code like that is of little help.
It does, however, raise a question.  You are using the thread.py
module here, yet the exception is being generated as a result
of the MainThread object (that is created when you import
the threading.py module) trying to exit: how can it be that
threading.py is imported when you are using only the thread
module yourself?  Other code that you aren't aware of?  More
complexity than your snippets suggest?
You really need to reduce this down to a simple piece of code
that reproduces the problem if you hope to solve it.  Race
conditions are just about the hardest thing in the world to
troubleshoot, and while you could report a bug here, without
code to reproduce the chances of someone finding and fixing
it are just about nil.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyZeroConf Question

2005-03-20 Thread A.M. Kuchling
On Thu, 17 Mar 2005 14:48:03 -0800, 
djw [EMAIL PROTECTED] wrote:
 The list of printers is returned, but every call to getServiceInfo() in 
 the Listener objectresults in a timeout and None being returned.

I suggest compiling Apple's mDNSMonitor and looking at the sequence of
packets.  It seems that some Zeroconf services don't respond to the
.getServiceInfo() calls; maybe that's what's happening here.

 Also, at the end of the list, the code seems to hang.

That makes sense.  The threads that monitor Zeroconf aren't marked as
daemonic, so as long as they're running the main thread doesn't exist.  I've
hacked my copy of zeroconf.py to mark the threads as daemonic.

--amk

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


Re: raise takes a long time

2005-03-20 Thread TZOTZIOY
On Fri, 18 Mar 2005 12:04:02 +, rumours say that Robin Becker
[EMAIL PROTECTED] might have written:

I'm trying to get a handle on a real world problem related to raising an 
exception. This is in the reportlab SimpleDoctemplate class.

The following code takes a very long time (60 seconds) in Python 2.2, 2.3, 
2.4, 
but not in 2.1 (at least on windows).

raise LayoutError(Flowable %s too large on page %d % (f.identity(30), 
self.page))

Maybe this is dumb, but how long does the following take?

raise LayoutError, Flowable %s too large on page %d % (f.identity(30),
self.page)

However, the supposedly functionally identical code

ident = f.identity(30)
raise LayoutError(Flowable %s too large on page %d % (ident, self.page))

Let's not assume that f.identity(30) runs equally fast in the two cases (for any
obscure reasons).  Did you time it (ie get the time at the start and end of the
function)?

does not take a long time ( 1 second). The exception LayoutError is trivial
class LayoutError(Exception):
 pass

-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


[ann] fdups 0.15

2005-03-20 Thread Patrick Useldinger
I am happy to announce version 0.15 of fdups.
Changes in this version:

- ability to limit the number of file handles used
Download
=
To download, go to: http://www.homepages.lu/pu/fdups.html
What is fdups?
==
fdups is a Python program to detect duplicate files on locally mounted 
filesystems. Files are considered equal if their content is identical, 
regardless of their filename. Also, fdups is able to detect and ignore 
symbolic links and hard links, where available.

In contrast to similar programs, fdups does not rely on md5 sums or 
other hash functions to detect potentially identical files. Instead, it 
does a direct blockwise comparison and stops reading as soon as 
possible, thus reducing the file reads to a maximum.

fdups results can either be processed by a unix-type filter, or directly 
 by another python program.

Warning
===
fdups is BETA software. It is known not to produce false positives if 
the filesystem is static.
I am looking for additional beta-testers, as well as for somebody who 
would be able to implement hard-link detection on NTFS file systems.

All feedback is appreciated.
--
http://mail.python.org/mailman/listinfo/python-list


what is \s+ and \S+ means in re.compile?

2005-03-20 Thread sam
Hi,
I was confused by \s+ and \S+ in python.
The second one (\S+) is stand for matching all alphabets except for 
digit and space? How about the first one?

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


Re: Pre-PEP: Dictionary accumulator methods - typing initialising

2005-03-20 Thread Matteo Dell'Amico
Kay Schluehr wrote:
Why do You set
d.defaultValue(0)
d.defaultValue(function=list)
but not
d.defaultValue(0)
d.defaultValue([])
?
I think that's because you have to instantiate a different object for 
each different key. Otherwise, you would instantiate just one list as a 
default value for *all* default values. In other words, given:

class DefDict(dict):
def __init__(self, default):
self.default = default
def __getitem__(self, item):
try:
return dict.__getitem__(self, item)
except KeyError:
return self.default
you'll get
In [12]: d = DefDict([])
In [13]: d[42].extend(['foo'])
In [14]: d.default
Out[14]: ['foo']
In [15]: d[10].extend(['bar'])
In [16]: d.default
Out[16]: ['foo', 'bar']
In [17]: d[10]
Out[17]: ['foo', 'bar']
In [18]: d[10] is d.default
Out[18]: True
and this isn't what you really wanted.
By the way, to really work, I think that Duncan's proposal should create 
new objects when you try to access them, and to me it seems a bit 
counterintuitive. Nevertheless, I'm +0 on it.

And why not dict(type=int), dict(type=list) instead where default
values are instantiated during object creation? A consistent pythonic
handling of all types should be envisioned not some ad hoc solutions
that go deprecated two Python releases later.
I don't really understand you. What should 'type' return? A callable 
that returns a new default value? That's exactly what Duncan proposed 
with the function keyword argument.

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


Re: Simple account program

2005-03-20 Thread Igorati
I was looking at both the programs and I got Dennis Lee Bieber's code to
work, then I tried the imporvements from Chris Reberts code but was unable
to get it to run. It said EOL error. I took out got and tried to move it
around but it didn't take. I took the else code at the end so that other
keys cannot be entered. I also see at the begining you are defining what a
deposit and withdrawl is. Ironically our next assignment is to make this
program handle errors and try to implement a GUI. I'm going to use the GUI
feauture and see what I come up with. Thank you all for your help. I know I
will be coding proper some day in the future. 

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


Re: inline comparison

2005-03-20 Thread Diez B. Roggisch
 This is very bad to me, I will need to write some cumbersome syntax as
 follow:
 for d in self.data:
  m = self.macro_parser.match (d)) != None ):
  if (m == None):
 m_nat = self.a_parser.match (d)
 if (m_a == None):
m_rdr = self.b_parser.match (d)
if (m_b == None):
m_c = self.c_parser.match (d)
if (m_c == None):
   m_d = self.d_parser.match (d)
   if (m_d == None):
  m_e = self.e_parser.match (d)
  if (m_e == None):
   .


This has been discussed a zillion times on c.l.py - and various solutions
have been suggested, amongst these is something like this:

class Matcher:
def __init__(self, rex):
self.rex = rex

def match(self, data):
self.mo = self.rex.match(data)
return self.mo

Then you can use code like this:

m  = Matcher(...)

if m.match(some string):
print m.mo.groups()

And beside that: the code you gave above does _not_ look better if you could
inline the assignment, you still have the same hierarchy of if-statements.

If you really need that sort of dependent matching, there are better ways to
accomplish that in python:

for m, name in [self.macro_parser, self.a_parser, self.b_parser, ...]:
mo = m.match(data)
if mo:
   break



-- 
Regards,

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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Magnus Lie Hetland
In article [EMAIL PROTECTED], 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

Yes, yes, YES!

*Man*, this would be useful.

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

Woohoo! *Just* as useful.

I'd *definitely* use these.

Hot 100% sure about the names, though. (add() and append() seem like
more natural names -- but they may be confusing, considering their
other uses...)

+1 on both (possibly allowing for some naming discussion...)

-- 
Magnus Lie Hetland   Time flies like the wind. Fruit flies
http://hetland.org   like bananas. -- Groucho Marx
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread BJörn Lindqvist
I like count() and appendlist() or whatever they will be named. But I
have one question/idea:

Why does the methods have to be put in dict? Can't their be a subtype
of dict that includes those two methods? I.e.:

.histogram = counting_dict()
.for ch in text:
.histogram.count(ch)

Then maybe some more methods can be added tailor-mode for these two
types of dicts?:

.for ch in string.ascii_letters:
.print Frequency of %s = %d. % (ch, histogram.freq(ch))

Or something, you get the idea.

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


Re: [perl-python] a program to delete duplicate files

2005-03-20 Thread Claudio Grondi
 I'll post my version in a few days.
Have I missed something?
Where can I see your version?

Claudio


Xah Lee [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 here's a large exercise that uses what we built before.

 suppose you have tens of thousands of files in various directories.
 Some of these files are identical, but you don't know which ones are
 identical with which. Write a program that prints out which file are
 redundant copies.

 Here's the spec.
 --
 The program is to be used on the command line. Its arguments are one or
 more full paths of directories.

 perl del_dup.pl dir1

 prints the full paths of all files in dir1 that are duplicate.
 (including files in sub-directories) More specifically, if file A has
 duplicates, A's full path will be printed on a line, immediately
 followed the full paths of all other files that is a copy of A. These
 duplicates's full paths will be prefixed with rm  string. A empty
 line follows a group of duplicates.

 Here's a sample output.

 inPath/a.jpg
 rm inPath/b.jpg
 rm inPath/3/a.jpg
 rm inPath/hh/eu.jpg

 inPath/ou.jpg
 rm inPath/23/a.jpg
 rm inPath/hh33/eu.jpg

 order does not matter. (i.e. which file will not be rm  does not
 matter.)

 

 perl del_dup.pl dir1 dir2

 will do the same as above, except that duplicates within dir1 or dir2
 themselves not considered. That is, all files in dir1 are compared to
 all files in dir2. (including subdirectories) And, only files in dir2
 will have the rm  prefix.

 One way to understand this is to imagine lots of image files in both
 dir. One is certain that there are no duplicates within each dir
 themselves. (imagine that del_dup.pl has run on each already) Files in
 dir1 has already been categorized into sub directories by human. So
 that when there are duplicates among dir1 and dir2, one wants the
 version in dir2 to be deleted, leaving the organization in dir1 intact.

 perl del_dup.pl dir1 dir2 dir3 ...

 does the same as above, except files in later dir will have rm 
 first. So, if there are these identical files:

 dir2/a
 dir2/b
 dir4/c
 dir4/d

 the c and d will both have rm  prefix for sure. (which one has rm 
 in dir2 does not matter) Note, although dir2 doesn't compare files
 inside itself, but duplicates still may be implicitly found by indirect
 comparison. i.e. a==c, b==c, therefore a==b, even though a and b are
 never compared.


 --

 Write a Perl or Python version of the program.

 a absolute requirement in this problem is to minimize the number of
 comparison made between files. This is a part of the spec.

 feel free to write it however you want. I'll post my version in a few
 days.

 http://www.xahlee.org/perl-python/python.html

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



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


How to pass parameter when importing a module?

2005-03-20 Thread Bo Peng
Dear list,
What I would like to do is something like:
In myModule.py ( a wrapper module for different versions of the module),
  if lib == 'standard':
from myModule_std import *
  elsif lib == 'optimized'
from myModule_op import *
but I do not know how to pass variable lib to myModule.py to achieve the 
following effect:

   lib = 'standard'
   from myModule import * # actually import myModule_std
From what I have read, from  does not take any parameter. Maybe I 
should use environmental variables?

   os.putenv('lib', 'standard')
   from myModule import *
  myModule.py
  -
  import os
  lib = os.getenv('lib')
  ...
or use a separate module?
  param.py
  -
  para = {}
  def setParam(key, val):
para[key] = val
  main session
  
   import param
   param.setParam('lib','standard')
   from myModule import *
  in myModule.py
  --
  from param import para
  try:
lib = para['lib']
  except:
lib = 'standard'
  ...
Is there an established approach for this problem?
Many thanks in davance.
Bo
===
FULL STORY:
I have several modules all (SWIG) wrapped from the same C++ source code 
but with different compiling flags. For example,

  myModule_std  (standard module)
  myModule_op   (optimized, without error checking)
  ...
These modules are put directly under /.../site-packages . To load a 
module, I use, for example

  from myModule_op import *
This works fine until I need to write some helper functions for 
myModule_?? in another module myHelper.py since I do not know which 
myModule is being used

  from myModule?? import A,B
I find one solution
  # find out which module is being used
  import sys
  if 'myModule_op' in sys.modules.keys():
from myModule_op import A,B
  else:
from myModule_std import A,B
but not completely satisfied. Therefore, I am writing a 'wrapper' module 
myModule that can load one of the myModule_?? modules according to user 
supplied info.

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


Re: Variable Variable

2005-03-20 Thread Mike Gould
Premshree Pillai wrote:
On Sat, 19 Mar 2005 04:35:47 -0500, Leif K-Brooks [EMAIL PROTECTED] wrote:
Tanteauguri wrote:
Hi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=[a,b,c]
for i in pc:
   i = anyclass()
a.shutdown()
b.update()
Use a dictionary:
stuff = {}
pc = ['a', 'b', 'c']

I think what he wants to do is basically hold object names in a tuple
list, and then call the methods on those objects (while iterating or
whatever).

for i in pc:
stuff[i] = anyclass()
stuff['a'].shutdown()
stuff['b'].update()
--
http://mail.python.org/mailman/listinfo/python-list

Try this:
pc=[a,b,c]
for i in pc:
vars()[i] = anyclass()
a.shutdown()
b.update()
MikeG
--
http://mail.python.org/mailman/listinfo/python-list


Re: Variable Variable

2005-03-20 Thread MikeyG
Premshree Pillai wrote:
On Sat, 19 Mar 2005 04:35:47 -0500, Leif K-Brooks [EMAIL PROTECTED] wrote:
Tanteauguri wrote:
Hi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=[a,b,c]
for i in pc:
   i = anyclass()
a.shutdown()
b.update()
Use a dictionary:
stuff = {}
pc = ['a', 'b', 'c']

I think what he wants to do is basically hold object names in a tuple
list, and then call the methods on those objects (while iterating or
whatever).

for i in pc:
stuff[i] = anyclass()
stuff['a'].shutdown()
stuff['b'].update()
--
http://mail.python.org/mailman/listinfo/python-list

Try this:
pc=[a,b,c]
for i in pc:
vars()[i] = anyclass()
a.shutdown()
b.update()
MikeG
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Duncan Booth
Roose wrote:

 I think someone mentioned that it might be a problem to add another
 piece of state to all dicts though.  I don't know enough about the
 internals to say anything about this.
 
 setdefault gets around this by having you pass in the value every
 time, so it doesn't have to store it.  It's very similar, but somehow
 many times more awkward.
 

Another option with no storage overhead which goes part way to reducing
the awkwardness would be to provide a decorator class accessible through
dict. The decorator class would take a value or function to be used as
the default, but apart from __getitem__ would simply forward all other
methods through to the underlying dictionary. 

That gives you the ability to have not one default value for a
dictionary, but many different ones: you just decorate the dictionary
anywhere you need a default and use the underlying dictionary everywhere
else. 

Some code which demonstrates the principle rather than the
implementation. dictDefaultValue could be imagined as
dict.defaultValue, dictDefaultValue(d, ...) could be 
d.defaultValue(...) although the actual name used needs work:

 class dictDefaultValue(object):
def __init__(self, d, value=_marker, function=_marker):
self.__d = d
if value is _marker:
if function is _marker:
raise TypeError, expected either value or function 
argument
self.__dv = function
else:
def defaultValue():
return value
self.__dv = defaultValue

def __getattr__(self, name):
return getattr(self.__d, name)

def __getitem__(self, name):
try:
return self.__d[name]
except KeyError:
value = self.__dv()
self.__d[name] = value
return value

def __setitem__(self, name, value):
self.__d[name] = value


 d = {}
 accumulator = dictDefaultValue(d, 0)
 accumulator['a'] += 1
 aggregator = dictDefaultValue(d, function=list)
 aggregator['b'].append('hello')
 d
{'a': 1, 'b': ['hello']}
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Re: Hi Guys. First Time Poster

2005-03-20 Thread Gerrit Holl
Jeff Schwab wrote:
 sheldon279 wrote:
cut
 Wow, you sold me.
 
 Does this kinda scam really still work?

This kind of replies works to confuse spambayes.

Gerrit.

-- 
Weather in Twenthe, Netherlands 20/03 16:55:
9.0C   wind 4.0 m/s ENE (57 m above NAP)
-- 
In the councils of government, we must guard against the acquisition of
unwarranted influence, whether sought or unsought, by the
military-industrial complex. The potential for the disastrous rise of
misplaced power exists and will persist.
-Dwight David Eisenhower, January 17, 1961
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to pass parameter when importing a module?

2005-03-20 Thread Swaroop C H
On Sun, 20 Mar 2005 10:18:14 -0600, Bo Peng [EMAIL PROTECTED] wrote:
 What I would like to do is something like:
 In myModule.py ( a wrapper module for different versions of the module),
if lib == 'standard':
  from myModule_std import *
elsif lib == 'optimized'
  from myModule_op import *

Suggestion: Maybe you use builtin `__import__` to load a module ? Note
that in this way, you'll have to use the module name prefix.


-- 
Swaroop C H
Blog: http://www.swaroopch.info
Book: http://www.byteofpython.info
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: 2005 International Obfuscated Ruby Code Contest (IORCC)

2005-03-20 Thread Gerrit Holl
[EMAIL PROTECTED] wrote:
 IMMEDIATE RELEASE: Fri Mar 18 16:34:52 CST 2005
 LOCATION:  http://iorcc.dyndns.org/2005/press/031805.html
 ANNOUNCEMENT:  International Obfuscated Ruby Code Contest (IORCC)
Entry Deadline, Midnight on March 31st, 2005
 
 
 Dear Rubyists, Perlists, Shellists, Cists and Hackers,

What is this doing on comp.lang.python?

regards,
Gerrit Holl.

-- 
Weather in Twenthe, Netherlands 20/03 16:55:
9.0C   wind 4.0 m/s ENE (57 m above NAP)
-- 
In the councils of government, we must guard against the acquisition of
unwarranted influence, whether sought or unsought, by the
military-industrial complex. The potential for the disastrous rise of
misplaced power exists and will persist.
-Dwight David Eisenhower, January 17, 1961
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simultaneous copy to multiple media

2005-03-20 Thread Grant Edwards
On 2005-03-20, Claudio Grondi [EMAIL PROTECTED] wrote:

 Is there maybe a way to use a direct DMA
 transfer to multiple target destinations
 (I copy to drives connected via USB ports) ?

Sure, but you'll have to throw away your OS, and write a
program that runs on the bare metal.

 Can someone point me in the right direction?

I think they already did.

-- 
Grant Edwards   grante Yow!  I am NOT a nut
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


beeping portably

2005-03-20 Thread Jim
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.

Thanks,
Jim

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


Re: How to pass parameter when importing a module?

2005-03-20 Thread André Roberge
Bo Peng wrote:
Dear list,
What I would like to do is something like:
In myModule.py ( a wrapper module for different versions of the module),
  if lib == 'standard':
from myModule_std import *
  elsif lib == 'optimized'
from myModule_op import *
but I do not know how to pass variable lib to myModule.py to achieve the 
following effect:

How about this:
#= constants.py
lib = whatever   #assigned somewhere else
#= myModule.py
from constants import lib
etc.
André
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython vs. pyQt

2005-03-20 Thread John J. Lee
Andrew E [EMAIL PROTECTED] writes:

 Hans-Peter Jansen wrote:
  ..
  While in PyQt world, I found these advantages:
   + conceptually vastly superior
   + powerful api/widgets/features
   + fast as hell due to the efficient binding of a quite efficient lib
   + cool tools, that are unicode/translation aware
   + very efficient programming environment/unbeatable productivity
  While this sounds like the average sales talk, I will try to backup
  these
  claims a bit:
   ..
 
 I've been a wx user since around 1999 and overall I like it. It annoys
 me a *lot* sometimes, but as Qt was always prohibitively expensive for
 commercial development, it was the only real option.
 
 The key question from my point of view is: can I write commercial
 sell-if-I-want-to applications using Qt? If it is GPL, then I guess
 the answer is 'no'?

Yes, you can write commercial apps.  It's multi-licensed (commercial,
GPL, etc.): you get to pick the license(s) you want to use.  Read the
licenses.

PyQt's licensing follows Qt's very closely, so no real complications
there.  Note PyQt (including a Qt license for use only with PyQt) is
actually far cheaper than Qt alone (if you buy Blackadder).


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


Re: beeping portably

2005-03-20 Thread John J. Lee
Jim [EMAIL PROTECTED] writes:

 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.
[...]

PyGame?  If it's too big for you, you could always borrow code from it.


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


Re: Pre-PEP: Dictionary accumulator methods - typing initialising

2005-03-20 Thread Kay Schluehr
Matteo Dell'Amico wrote:
 Kay Schluehr wrote:

  Why do You set
 
  d.defaultValue(0)
  d.defaultValue(function=list)
 
  but not
 
  d.defaultValue(0)
  d.defaultValue([])
 
  ?

 I think that's because you have to instantiate a different object for

 each different key. Otherwise, you would instantiate just one list as
a
 default value for *all* default values.

Or the default value will be copied, which is not very hard either or
type(self._default)() will be called. This is all equivalent and it
does not matter ( except for performance reasons ) which way to go as
long only one is selected.

[...]

 By the way, to really work, I think that Duncan's proposal should
create
 new objects when you try to access them, and to me it seems a bit
 counterintuitive.

If the dict has a fixed semantics by applying defaultValue() and it
returns defaults instead of exceptions whenever a key is missing i.e.
behavioural invariance the client of the dict has nothing to worry
about, hasn't he?


  And why not dict(type=int), dict(type=list) instead where default
  values are instantiated during object creation? A consistent
pythonic
  handling of all types should be envisioned not some ad hoc
solutions
  that go deprecated two Python releases later.

 I don't really understand you. What should 'type' return?
 A callable
 that returns a new default value? That's exactly what Duncan proposed

 with the function keyword argument.

I suspect the proposal really makes sense only if the dict-values are
of the same type. Filling it with strings, custom objects and other
stuff and receiving 0 or [] or '' if a key is missing would be a
surprise - at least for me. Instantiating dict the way I proposed
indicates type-guards! This is the reason why I want to delay this
issue and discuss it in a broader context. But I'm also undecided.
Guidos Python-3000 musings are in danger to become vaporware. Now is
better then never... Therefore +0.

Regards Kay

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


For loop extended syntax

2005-03-20 Thread George Sakkis
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


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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Colin J. Williams
Paul Rubin wrote:
El Pitonero [EMAIL PROTECTED] writes:
What about no name at all for the scalar case:
a['hello'] += 1
a['bye'] -= 2

I like this despite the minor surprise that it works even when
a['hello'] is uninitialized.
+1
and if the value is a list:
a['hello']= [1, 2, 3]
a['hello']+= [4]# adding the brackets is a lot simpler than
  typing append or extend.
Any user is free to add his/her own subclass to handle defaults.
Colin W.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Roose
 Another option with no storage overhead which goes part way to reducing
 the awkwardness would be to provide a decorator class accessible through
 dict. The decorator class would take a value or function to be used as
 the default, but apart from __getitem__ would simply forward all other
 methods through to the underlying dictionary.

I'm not sure I like the decorator -- I would never use that flexibility to
have more than one default.  I can't come up with any reason to ever use
that.

I think it works best as a simple subclass:

class DefaultDict(dict):

  def __init__(self, default, *args, **kwargs):
dict.__init__(self, *args, **kwargs)
self.default = default

  def __getitem__(self, key):
return self.setdefault(key, copy.copy(self.default))

d = DefaultDict(0)
for x in [1, 3, 1, 2, 2, 3, 3, 3, 3]:
  d[x] += 1
pprint(d)

d = DefaultDict([])
for i, x in enumerate([1, 3, 1, 2, 2, 3, 3, 3, 3]):
  d[x].append(i)
pprint(d)

Output:

{1: 2, 2: 2, 3: 5}
{1: [0, 2], 2: [3, 4], 3: [1, 5, 6, 7, 8]}


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


Re: For loop extended syntax

2005-03-20 Thread Kay Schluehr
George Sakkis wrote:

 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)]


Looks very appealing, but what to do with

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

Should it raise an exception due to a pattern mismatch?

If not how should matching rules apply here?

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

If in doubt write a vector class that cares about the correct padding (
or more general and with geometric meaning: select the right hyperplane
) and enable to switch between different paddings. This solution is
both flexible and reusable.

Regards Kay

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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Jeremy Bowers
On Sat, 19 Mar 2005 20:07:40 -0800, Kay Schluehr wrote:
 It is bad OO design, George. I want to be a bit more become more
 specific on this and provide an example:

Having thought about this for a bit, I agree it is a powerful
counter-argument and in many other languages I'd consider this a total win.

But this is Python, and frankly, I've overridden dict more than once and
violated the Liskov substitution principle without thinking twice. (Once,
oh yes, but not twice.) Of course, all the code was under my control then.

I think the tipping point for me depends on how the interfaces in Python
are going to be implemented, which I haven't dug into. If the dict class
gets an interface definition, can I subclass from dict and cancel (or
some other term) the interface I inherited? 

If so, then this might still be OK, although if interfaces aren't going to
confuse newbies enough, wait 'till we try to explain that their code is
blowing up because they forgot to cancel their interface, and they
can't *really* pass their subclass in to something expecting a dict
interface. If you *can't* cancel or downgrade the interface, then I'd say
this argument is still good; dict should be kept minimal and this should
go in a subclass.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Building Time Based Bins

2005-03-20 Thread MCD
John Machin wrote:
 Are you (extremely) new to computer programming? Is this school
 homework?

Lol, yes, I am relatively new to programming... and very new to python.
I have experience working with loops, if thens, and boolean operations,
but I haven't worked with lists or array's as of yet... so this is my
first forray. This isn't homework, I'm long out of school. I've been
wanting to extend my programming abilities and I chose python as the
means to acheiving that goal... so far I really like it :-)

Thank you both for the code. I ended up working with John's because
it's a bit easier for me to get through. I very much appreciate the
code... it taught me quite a few things about how python converts
string's to integers and vice versa. I didn't expect to get thorugh it,
but after looking at it a bit, I did, and was able to modify it so that
I could work with my own files. Yeah!

The only question I have is in regards to being able to sum a field in
a bin. Using sum(hi) returns only the last value... I'm uncertain how
to cumulatively add up the values as the script runs through each line.
Any pointers?

Thank you again for all your help.
Marcus

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


Re: Pre-PEP: Dictionary accumulator methods - typing initialising

2005-03-20 Thread Matteo Dell'Amico
Kay Schluehr wrote:
I think that's because you have to instantiate a different object for
each different key. Otherwise, you would instantiate just one list as
a default value for *all* default values.
Or the default value will be copied, which is not very hard either or
type(self._default)() will be called. This is all equivalent and it
does not matter ( except for performance reasons ) which way to go as
long only one is selected.
I don't like it very much... it seems too implicit to be pythonic. Also, 
it won't work with non-copyable objects, and type(42)() = 0, and getting 
0 when the default is 42 looks very strange. I prefer the explicit give 
me a callable approach.

If the dict has a fixed semantics by applying defaultValue() and it
returns defaults instead of exceptions whenever a key is missing i.e.
behavioural invariance the client of the dict has nothing to worry
about, hasn't he?
For idioms like d[foo].append('blah') to work properly, you'd have to 
set the default value every time you access a variable. It can be really 
strange to fill up memory only by apparently accessing values.

I suspect the proposal really makes sense only if the dict-values are
of the same type. Filling it with strings, custom objects and other
stuff and receiving 0 or [] or '' if a key is missing would be a
surprise - at least for me. Instantiating dict the way I proposed
indicates type-guards! This is the reason why I want to delay this
issue and discuss it in a broader context. But I'm also undecided.
Guidos Python-3000 musings are in danger to become vaporware. Now is
better then never... Therefore +0.
Having duck-typing, we can have things that have common interface but no 
common type. For instance, iterables. I can imagine a list of iterables 
of different types, and a default value of maybe [] or set([]).

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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Alexander Schmolck
Beni Cherniavsky [EMAIL PROTECTED] writes:

 The relatively recent improvement of the dict constructor signature
 (``dict(foo=bar,...)``) obviously makes it impossible to just extend the
 constructor to ``dict(default=...)`` (or anything else for that matter) which
 would seem much less ad hoc. But why not use a classmethod (e.g.
 ``d=dict.withdefault(0)``) then?

 You mean giving a dictionary a default value at creation time, right?

Yes. But creating a defaultdict type with aliased content to the original
dict would also be fine by me.

 Such a dictionary could be used very easily, as in gaspPerl::

  foreach $word ( @words ) {
  $d{$word}++; # default of 0 assumed, simple code!
  }

 /gasp.  You would like to write::

  d = dict.withdefault(0)  # or something
  for word in words:
  d[word] += 1 # again, simple code!

 I agree that it's a good idea but I'm not sure the default should be specified
 at creation time.  The problem with that is that if you pass such a dictionary
 into an unsuspecting function, it will not behave like a normal dictionary.

Have you got a specific example in mind? 

Code that needlessly relies on exceptions for normal operation is rather
perverse IMO and I find it hard to think of other examples.

 Also, this will go awry if the default is a mutable object, like ``[]`` - you
 must create a new one at every access (or introduce a rule that the object is
 copied every time, which I dislike).

I think copying should on by default for objects that are mutable (and
explicitly selectable via ``.withdefault(bar,copy=False)``).

Python of course doesn't have an interface to query whether something is
mutable or not (maybe something that'll eventually be fixed), but hashable
might be a first approximation. If that's too dodgy, most commonly the value
will be a builtin type anyway, so copy by default with efficient
implementation (i.e. doing nothing) for ints, tuples etc. ought to work fine
in practice.

 And there are cases where in different points in the code operating on the
 same dictionary you need different default values.

The main problem here is that the obvious .setdefault is already taken to
misnome something else. Which I guess strengthens the point for some kind of
proxy object.

 So perhaps specifying the default at every point of use by creating a proxy is
 cleaner::

  d = {}
  for word in words:
  d.withdefault(0)[word] += 1
 Of course, you can always create the proxy once and still pass it into an
 unsuspecting function when that is actually what you mean.

Yup (I'd presumably prefer that second option for the above code).


 How should a dictionary with a default value behave (wheter inherently or a
 proxy)?

 - ``d.__getattr__(key)`` never raises KeyError for missing keys - instead it
returns the default value and stores the value as `d.setdefult()` does.
This is needed for make code like::

d.withdefault([])[key].append(foo)

to work - there is no call of `d.__setattr__()`, so `d.__getattr__()` must
have stored it.

I'm confused -- are you refering to __getitem__/__setitem__? Even then I don't
get what you mean: __getitem__ obviously works differently, but that would be
the whole point.


- `d.__setattr__()` and `d.__delattr__()` behave normally.

s/attr/item/ and agreed.


 - Should ``key in d`` return True for all keys?  

No. See below.

It is desiarable to have *some* way to know whether a key is really
present. But if it returns False for missing keys, code that checks ``key
in d`` will behave differently from normally equivallent code that uses
try..except. If we use the proxy interface, we can always check on the
original dictionary object, which removes the problem.

- ``d.has_key(key)`` must do whatever we decide ``key in d`` does.

  - What should ``d.get(key, [default])`` and ``d.setdefault(key, default)``
do?  There is a conflict between the default of `d` and the explicitly 
 given
default.  I think consistency is better and these should pretend that `key`
is always present.  But either way, there is a subtle problem here.

.setdefault ought to trump defaultdict's default. I feel that code that
operated without raising an KeyError on normal dicts should also operate the
same way on defaultdicts were possible. I'd also suspect that if you're
effectively desiring to override .setdefault's default you're up to something
dodgy.

 - Of course `iter(d)`, `d.items()` and the like should only see the keys
that are really present (the alternative inventing an infinite amount of
items out of the blue is clearly bogus).

 If the idea that the default should be specified in every operation (creating
 a proxy) is accepted, there is a simpler and more fool-proof solution: the
 ptoxy will not support anything except `__getitem__()` and `__setitem__()` at
 all.  Use the original dictionary for everything else.  This prevents subtle
 

Re: For loop extended syntax

2005-03-20 Thread Matteo Dell'Amico
George Sakkis 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 ?
How did you get the data in that format in the first place? It looks a 
bit strange to me. Wouldn't it be easier to fill in default values when 
you gather data as opposed to when you use it?

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


Re: simultaneous copy to multiple media

2005-03-20 Thread Claudio Grondi
means  your message, that you think, that
the consecutive copy is the fastest possible
method if using Windows 2000?

Claudio

Grant Edwards [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 On 2005-03-20, Claudio Grondi [EMAIL PROTECTED] wrote:

  Is there maybe a way to use a direct DMA
  transfer to multiple target destinations
  (I copy to drives connected via USB ports) ?

 Sure, but you'll have to throw away your OS, and write a
 program that runs on the bare metal.

  Can someone point me in the right direction?

 I think they already did.

 -- 
 Grant Edwards   grante Yow!  I am NOT a
nut
   at
visi.com


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


Changing the Keyboard output

2005-03-20 Thread Abdul Hafiz al-Muslim
Hi,
I am new to Python and still learning.

I am looking for a way to change the keyboard output within Tkinter - for
example, say I press p and I want to come out as t.

Could anyone point me in the right direction?

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


Re: For loop extended syntax

2005-03-20 Thread George Sakkis
Kay Schluehr [EMAIL PROTECTED] wrote:

 George Sakkis wrote:

  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)]
 

 Looks very appealing, but what to do with

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

 Should it raise an exception due to a pattern mismatch?

I didn't have in mind to generalize the syntax even more than the respective 
for function
signatures, therefore this would be syntax error:
SyntaxError: non-keyword arg after keyword arg

 If not how should matching rules apply here?

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

 If in doubt write a vector class that cares about the correct padding (
 or more general and with geometric meaning: select the right hyperplane
 ) and enable to switch between different paddings. This solution is
 both flexible and reusable.

 Regards Kay

This was just an example; I think the proposed functionality will be helpful in 
far more cases than
dealing with geometry or vectors, so I would prefer it to be supported by the 
language itself.

Regards,
George


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


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

2005-03-20 Thread bennie
Christos TZOTZIOY Georgiou wrote:
On Sun, 20 Mar 2005 10:44:06 +0100, rumours say that Bennie [EMAIL PROTECTED]
might have written:

Hi,
I have a problem with ZipFile.
It works okay untily I come across a file that is greater then 1Gb.
Then it exit with the error:
OverflowError: long int too large to convert to int
How can I fix this?

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).

souce:
zip = zipfile.ZipFile(file, 'w')

for all in os.walk(os.getcwd()):
path = all[0]
for document in all[2]:
zipaccview.write(path + os.sep + document)
	zip.close()

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


getting text from WinXP console

2005-03-20 Thread Chris Maloof
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Francis Girard
Hi,

I really do not like it. So -1 for me. Your two methods are very specialized 
whereas the dict type is very generic. Usually, when I see something like 
this in code, I can smell it's a patch to overcome some shortcomings on a 
previous design, thereby making the economy of re-designing. Simply said, 
that's bad programming.

After that patch to provide a solution for only two of the more common 
use-cases, you are nonetheless stucked with the old solution for all the 
other use-cases (what if the value type is another dictionary or some 
user-made class ?).

Here's an alternate solution which I think answers all of the problems you 
mentionned while being generic.

=== BEGIN SNAP

def update_or_another_great_name(self, key, createFunc, updtFunc):
  try:
self[key] = updtFunc(self[key])
  ## This is slow with Python = since the key has to be  searched 
  ## twice But the new built-in method just has to update the value the
  ## first time the key is found. Therefore speed should be ok.
return True
  except KeyError:
self[key] = createFunc()
return false

## Now your two specialized methods can be easily written as :

## A built-in should be provided for this (if not already proposed) :
def identical(val):
  return val

def count(self, key, qty=1):
  self.update_or_another_great_name(key, identical, 
partial(operator.add, qty))
  ## partial is coming from : http://www.python.org/peps/pep-0309.html
  ## Using only built-in function (assuming identical) as arguments makes it
  ## ok for speed (I guess).
  
def appendlist(self, key, *values):
  self.update_or_another_great_name(key, 
partial(list, values),
partial(ListType.extend, X = values))
  ## The first partial usage here is an abuse just to make sure that the
  ## list is not actually constructed before needed. It should work.
  ## The second usage is more uncertain as we need to bind the arguments from
  ## the right. Therefore I have to use the name of the parameter and I am not
  ## sure if there's one. As this list is very prolific, someone might have an
  ## idea on how to improve this.
  
=== END SNAP

By using only built-in constructs, this should be fast enough. Otherwise, 
optimizing these built-ins is a much more clean and sane way of thinking then 
messing the API with ad-hoc propositions.

Reviewing the problems you mention :

 The readability issues with the existing constructs are:

 * They are awkward to teach, create, read, and review.

The method update_or_another_great_name is easy to understand, I think. But it 
might not always be easy to use it efficiently with built-ins. But this is 
always the case. Recipees can be added to show how to efficiently use the 
method.

 * Their wording tends to hide the real meaning (accumulation).

Solved.

 * The meaning of setdefault() 's method name is not self-evident.

Solved.


 The performance issues with the existing constructs are:

 * They translate into many opcodes which slows them considerably.

I really don't know what will be the outcome of the solution I propose. I 
certainly do not know anything about how my Python code translates into 
opcodes.

 * The get() idiom requires two dictionary lookups of the same key.

Solved

 * The setdefault() idiom instantiates a new, empty list prior to every

Solved

 call. * That new list is often not needed and is immediately discarded.

Solved

 * The setdefault() idiom requires an attribute lookup for extend/append.

Solved

 * The setdefault() idiom makes two function calls.

Solved

And perhaps, what you say here is also true for your two special use-cases :

 For other
 uses, plain Python code suffices in terms of speed, clarity, and avoiding
 unnecessary instantiation of empty containers:

 if key not in d:
 d.key = {subkey:value}
 else:
 d[key][subkey] = value


Much better than adding special cases on a generic class. Special cases always 
demultiply and if we open the door 

Regards,

Francis Girard


Le samedi 19 Mars 2005 02:24, Raymond Hettinger a crit:
 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)

 The rationale is to replace the awkward and slow existing idioms for
 dictionary based accumulation:

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

 In simplest form, those two statements would now be coded more readably as:

d.count(key)
d.appendlist(key, value)

 In their multi-value forms, they would now be coded as:

   d.count(key, qty)
   d.appendlist(key, *values)

 The error 

Re: How to pass parameter when importing a module?

2005-03-20 Thread Serge Orlov
Bo Peng wrote:
 Dear list,

 What I would like to do is something like:

 In myModule.py ( a wrapper module for different versions of the
 module),
   if lib == 'standard':
 from myModule_std import *
   elsif lib == 'optimized'
 from myModule_op import *

 but I do not know how to pass variable lib to myModule.py to achieve
 the following effect:

lib = 'standard'
from myModule import * # actually import myModule_std

[snip]

Take a look at wxPython versioning:
http://wiki.wxpython.org/index.cgi/MultiVersionInstalls

The most simple usage looks like

  import wxversion
  wxversion.select(2.4)
  import wx
  Serge. 


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


Re: wxPython vs. pyQt

2005-03-20 Thread Andrew E
John J. Lee wrote:
The key question from my point of view is: can I write commercial
sell-if-I-want-to applications using Qt? If it is GPL, then I guess
the answer is 'no'?

Yes, you can write commercial apps.  It's multi-licensed (commercial,
GPL, etc.): you get to pick the license(s) you want to use.  Read the
licenses.
PyQt's licensing follows Qt's very closely, so no real complications
there.  Note PyQt (including a Qt license for use only with PyQt) is
actually far cheaper than Qt alone (if you buy Blackadder).
ok, thanks. I've just had a quick browse of the licence notes at the 
PyQt website.

I guess I meant: can I write commercial closed-source software *without 
paying anything for Qt - to which I sounds like the answer is 
definitely No :)

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


Re: For loop extended syntax

2005-03-20 Thread George Sakkis
Matteo Dell'Amico [EMAIL PROTECTED] wrote:

 George Sakkis 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 ?

 How did you get the data in that format in the first place? It looks a
 bit strange to me. Wouldn't it be easier to fill in default values when
 you gather data as opposed to when you use it?

Not always. Say for example that you're doing some 2D geometry stuff, and later 
you have to extend
it to 3D. In this case you may have to deal with both 2D and 3D objects, and 
map the former to the
latter when necessary.

George


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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Mike Rovner
Reinhold Birkenfeld wrote:
I don't quite understand that. Which dict item are you extending? Don't
you need something like
dl[key].append(word)
Rigth. It was just a typo on my part. Thanks for fixing.
Mike
--
http://mail.python.org/mailman/listinfo/python-list


Re: For loop extended syntax

2005-03-20 Thread Heiko Wundram
On Sunday 20 March 2005 20:47, George Sakkis wrote:
 Not always. Say for example that you're doing some 2D geometry stuff, and
 later you have to extend it to 3D. In this case you may have to deal with
 both 2D and 3D objects, and map the former to the latter when necessary.

But this rather sounds like you'd want an adaptor iterator, like the 
following:

 class AdaptPossible2D(object):
...   def __init__(self,data):
... self.data = data
...   def __iter__(self):
... for item in self.data:
...   if len(item) == 2:
... yield item+(0,)
...   else:
... yield item
...
 for x,y,z in AdaptPossible2D([(1,2),(1,2,3),(3,4)]):
...   print x,y,z
...
1 2 0
1 2 3
3 4 0

Using the above code makes it absolutely clear what you want, and doesn't need 
any new syntax which can be ambiguous like (x=0,y,z=0), etc. The above idiom 
also takes only constant extra space, as it doesn't duplicate the list during 
iteration.

-- 
--- Heiko.


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

Re: simultaneous copy to multiple media

2005-03-20 Thread Heiko Wundram
On Sunday 20 March 2005 17:16, Claudio Grondi wrote:
 Is there maybe a way to use a direct DMA
 transfer to multiple target destinations
 (I copy to drives connected via USB ports) ?

Think about what USB stands for. Then reconsider whether you'll ever have the 
chance of writing truly simultaneously to several devices connected via 
USB... And then, as an extra exercise, think about why it takes so long when 
several different jobs are done in parallel, writing to devices connected via 
USB.

Bus design... Don't they teach anything at uni these days? ;)

-- 
--- Heiko.


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

Re: How to pass parameter when importing a module?

2005-03-20 Thread Bo Peng

Take a look at wxPython versioning:
http://wiki.wxpython.org/index.cgi/MultiVersionInstalls
The most simple usage looks like
  import wxversion
  wxversion.select(2.4)
  import wx
  Serge. 

This is essentially my second method: using another module to set 
parameter for myModule. Since wxPython uses this method, I suppose this 
is the standard approach for this problem.

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


Re: Building Time Based Bins

2005-03-20 Thread MCD
Never mind about the summing... I learned that you can do this:

sumhi = 0
sumhi += hi

Cool!

Thanks again.

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


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

2005-03-20 Thread Jeff Epler
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 

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 = open(f, w)
f.seek ( 4 * 1024 * 1024 * 1024 - 1)
f.write(\0)
f.close()

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


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

Re: Changing the Keyboard output

2005-03-20 Thread Jeremy Bowers
On Sun, 20 Mar 2005 19:30:05 +, Abdul Hafiz al-Muslim wrote:

 Hi,
 I am new to Python and still learning.
 
 I am looking for a way to change the keyboard output within Tkinter - for
 example, say I press p and I want to come out as t.
 
 Could anyone point me in the right direction?

I'm pretty certain this is not possible in the general case.

One of my persistent pet peeves with GUI toolkits is that it is not
possible to insert your own arbitrary events into the toolkit and get the
toolkit to do *exactly* what it would have done if it had received that
event. While I believe Tk has a post event method, it only posts user
events, I do not think you can post system events.

This would completely change the testability and programmability of all
GUI toolkits, radically improving them for agile development... but that's
another rant.

Meanwhile, you've got two options, depending on what you are trying to
do, what platform you are on, and whether you control the target system.
You could actually re-map the keyboard, which all major OSs support,
although that may be too drastic. You could register two event handlers to
the same handling function, so that both p and t go to the same place.

Finally, if you're working with a Text widget, and you want a t to come
out when users press p, what you do is capture the p event (either by
registering p or Key), insert a t at the INSERT point, move the
INSERT event forward if you have to, and then cancel the key event by
returning break. Basically, you are implementing the keypress handler
manually. (To fully emulate the keypress, consider if you want to emulate
the behavior where a keypress destroys the highlighted range, in which
case you need to look at SEL too.) This is a pain, and there are a lot of
cases to cover, but it can be done.

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


Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Aahz
In article [EMAIL PROTECTED],
Michele Simionato [EMAIL PROTECTED] wrote:

I am surprised nobody suggested we put those two methods into a
separate module (say dictutils or even UserDict) as functions:

from dictutils import tally, listappend

tally(mydict, key)
listappend(mydict, key, value)

That seems like a reasonable compromise.
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code -- 
not in reams of trivial code that bores the reader to death.  --GvR
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simultaneous copy to multiple media

2005-03-20 Thread Rolf Zwart
Swaroop C H wrote:
[...]
If you are using *nix, maybe you can use the `tee` command[1] and
redirect the file to different places.
For example,
cat somefile | tee file1 | tee file2  file3
On Unixes I know, only 1 process is needed:
infile tee outfile1 outfile2 outfile3 ... /dev/null
It does work!
** Rolf
I haven't tried it out but it should work.
[1]: http://unixhelp.ed.ac.uk/CGI/man-cgi?tee
HTH,
--
http://mail.python.org/mailman/listinfo/python-list


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

2005-03-20 Thread Francis Girard
Hello M. Hartman,

It's a very big opportunity for me to find someone that both is a poet and 
knows something about programming.

First, please excuse my bad english ; I'm a french canadian.

I am dreaming to write a software to help french poets to write strict 
rigourous classical poetry. Since calssical poetry is somewhat mathematical, 
a lot of tasks can be automatised :

1- Counting the number of syllabs (pied in french) in a verse

2- Checking the rimes ; determining the strength of a rime

3- Checking compliance of a poem to a fixed pre-determined classical form (in 
french, we have distique, tercet, quatrain, quintain, sixain, huitain, 
dizain, triolet, vilanelle, rondeau, rondel, ballade, chant royal, sonnet, 
etc.)

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 ?

The first task of cutting sentences into syllabs (phonetically of course, not 
typographically) is already done. It's been difficult to get it right and to 
make it guess correctly with a very very high percentage. 

I can very well imagine that the next task is even more difficult. I need to 
translate text into phonems. Do you know some software that does it ? I guess 
that voice synthetisers that translates written text into spoken text must 
first translate the text into phonems. Right ? Do you know if there some way 
that I can re-use some sub-modules from these projects that will translate 
text into phonems ?

Regards,

Francis Girard

Le dimanche 20 Mars 2005 04:40, Charles Hartman a écrit :
 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?

 Charles Hartman
 Professor of English, Poet in Residence
 http://cherry.conncoll.edu/cohar
 http://villex.blogspot.com

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


Re: simultaneous copy to multiple media

2005-03-20 Thread Claudio Grondi
I don't know any deep details about USB, except that
I _know_ that it is a serial bus, but considering
following:

1) I can read/write 45 MByte/s from harddrive to harddrive
on the E-IDE bus (theoretically 100 MByte/s), so the
speed of the harddrive I read/write from/to is probably the
bottleneck.
2) if I understand it right, an USB controller is connected to
to the PCI bus and there can be many separate USB
controller on one PC
3) the theoreticall speed of USB (430 MByte/s?) is much
higher as the experienced 15 MByte/s, probably due to slow
controller on the side of the external storage media, so
maybe even on one USB line I will have the chance to
use it full capacity connecting many slow devices
(I can't imagine, that USB goes down with the speed to
the speed of the slowest component connected, does it?)
4) with 45 MByte/s I could theoretically simultaneously
supply three separate data streams to three USB
controller writing with 15 MByte/s each out to the
external storage media.
5) watching the low CPU usage while writing to USB
shows me, that CPU-time is not a problem.

I still see a chance of writing truly simultaneously to
several devices connected via USB.
Please let me know if I am wrong in any of the
points (1-5) or if my conclusion is based on
wrong assumptions or if I use a wrong way of
infering.

By the way: I was not thought about bus design at
university, so what I know about it is comes from
self-study :-).

Claudio
P.S. Your message appears in my Outlook Express
as one having no content, but an attachment, so I can't
read it directly.

 Is there maybe a way to use a direct DMA
 transfer to multiple target destinations
 (I copy to drives connected via USB ports) ?
Think about what USB stands for. Then reconsider whether you'll ever have
the
chance of writing truly simultaneously to several devices connected via
USB... And then, as an extra exercise, think about why it takes so long when
several different jobs are done in parallel, writing to devices connected
via
USB.
Bus design... Don't they teach anything at uni these days? ;)
-- 
--- Heiko.


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


Re: Text-to-speech

2005-03-20 Thread Steve Holden
Tim Churches wrote:
Charles Hartman wrote:
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?
Charles Hartman
Professor of English, Poet in Residence
http://cherry.conncoll.edu/cohar

No, but I do wonder how many other users of Python are
poets-in-residence, or indeed, published poets?
And congratulations on the release of Scandroid Version 1.0a (written in
Python) on 18.iii.05 (as you elegantly record it).
All this begs the question: Have any poems been written in Python
(similar to the well-known Perl Poetry (see
http://directory.google.com/Top/Computers/Programming/Languages/Perl/Poetry/
)?
Indeed, have any poems ever been written about Python - other than The
Zen of Python by Tim Peters? A limerick, even?
There once was a language called Python...
(which is pretty close to having three anapaestic left feet)
or more promisingly, rhyme-wise, but metrically rather worse :
There once was a mathematician named van Rossum...
Tim C
Of course this last suggestion clearly has the wrong meter for a good 
limerick. Not everyone knows the ingredients of a good limerick, which 
led to the following (which has been around in various forms since God 
was a lad):

There was a young man from Japan
Who never quite learned how to scan.
  He got on quite fine
  Until the last line
And then somehow he could never quite get the number of syllables 
right,or make it rhyme.

So, let's accept that the first line should scan correctly, that would 
make the following first lines acceptable:

A mathematician named Guido ...
The inventor of Python, called Guido ...
A mathematician (van Rossum) ...
Van Rossum, inventor of Python ...
Hopefully that will begin to get the idea across.
Since it's PyCon week, I will offer a prize of $100 to the best (in my 
opinion) limerick about Python posted to this list (with a Cc: to 
[EMAIL PROTECTED]) before midday on Friday. The prize money will be my 
own, so there are no other rules. I will post my judgment when the PyCon 
nonsense has died down a little, but the winner will be read before the 
entire PyCon audience. Get to it!

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Text-to-speech

2005-03-20 Thread jamesthiele . usenet
On some flavors of Windows you can use:
import pyTTS

tts = pyTTS.Create()
tts.Speak('This is the sound of my voice.')

On Mac OS X you can use:
import os

os.system(say 'This is the sound of my voice.')

You could write a wrapper that takes a string and checks to see which
OS you are on and executes the appropriate of the two above choices.
But you probably need something slicker, and I don't know what that
might be.

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


Limerick (was: Re: Text-to-speech)

2005-03-20 Thread Jeremy Bowers
On Sun, 20 Mar 2005 16:18:14 -0500, Steve Holden wrote:
 Since it's PyCon week, I will offer a prize of $100 to the best (in my 
 opinion) limerick about Python posted to this list (with a Cc: to 
 [EMAIL PROTECTED]) before midday on Friday. The prize money will be my 
 own, so there are no other rules. I will post my judgment when the PyCon 
 nonsense has died down a little, but the winner will be read before the 
 entire PyCon audience. Get to it!
 
 regards
   Steve

Practicality beats purity,
Errors should never pass silently.
Sparse is better than dense,
Flat is better than nest,
Beautiful is better than ugly.

No cc because A: I'm not really serious and B: Tim Peters would have to
get some credit for that. :-) Probably ought to add a C: While I think
that does mostly rhyme, it is pretty loose; not much source material to
work with.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For loop extended syntax

2005-03-20 Thread Heiko Wundram
Am Sonntag, 20. März 2005 22:22 schrieb George Sakkis:
 Once more, the 2D/3D example was just that, an example; my point was not to
 find a specific solution to a specific problem.

And my point being: it's simple enough to give a general recipe (which my 
example was) without extending Python's syntax, so why extend the syntax and 
not just use a solution derived from that recipe that's working now (and is 
backwards compatible at least to 2.3), and which is also clear in itself?

I'm not saying that your syntax looks strange or bad, but there are means 
to do what you want to do now, without cumbersome syntax or duplicating code, 
and as such I'm -1 on syntactic sugar (TOWTDI and all)...

Don't take this the wrong way, but I think introducing syntax is the wrong 
solution to a non-existant problem with the language.

-- 
--- Heiko.


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

Re: Text-to-speech

2005-03-20 Thread Charles Hartman
-- or . . . a guru named Guido / (Who monitors everything we do) /  
and ending with something about looking max in a Speedo, but  
fortunately it's not coming to me at the moment.

The closest I have an answer to your questions about Python and poetry  
(aside from the Scandroid) is a book called *Virtual Muse: Experiments  
in Computer Poetry* which Wesleyan published something close to ten  
years ago; I don't think it's out of print yet, but I don't keep good  
track. It was out of a casual remark there (about a very primitive  
program not even directly talked about in the boolk) that there came a  
casual remark from a reader last year which led to the Scandroid.

Charles Hartman
The time has come for someone to put his foot down; and that foot is  
me. --Animal House

On Mar 20, 2005, at 2:10 AM, Tim Churches wrote:
Charles Hartman wrote:
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?

Charles Hartman
Professor of English, Poet in Residence
http://cherry.conncoll.edu/cohar
No, but I do wonder how many other users of Python are
poets-in-residence, or indeed, published poets?
And congratulations on the release of Scandroid Version 1.0a (written  
in
Python) on 18.iii.05 (as you elegantly record it).

All this begs the question: Have any poems been written in Python
(similar to the well-known Perl Poetry (see
http://directory.google.com/Top/Computers/Programming/Languages/Perl/ 
Poetry/
)?

Indeed, have any poems ever been written about Python - other than The
Zen of Python by Tim Peters? A limerick, even?
There once was a language called Python...
(which is pretty close to having three anapaestic left feet)
or more promisingly, rhyme-wise, but metrically rather worse :
There once was a mathematician named van Rossum...
Tim C
--
http://mail.python.org/mailman/listinfo/python-list


Re: simultaneous copy to multiple media

2005-03-20 Thread Diez B. Roggisch
 2) if I understand it right, an USB controller is connected to
 to the PCI bus and there can be many separate USB
 controller on one PC

True.

 3) the theoreticall speed of USB (430 MByte/s?) is much
 higher as the experienced 15 MByte/s, probably due to slow
 controller on the side of the external storage media, so
 maybe even on one USB line I will have the chance to
 use it full capacity connecting many slow devices
 (I can't imagine, that USB goes down with the speed to
 the speed of the slowest component connected, does it?)

Nope. Or yes. Here comes into play why Heiko said think of what USB stands
for. While the devices appear to be responsive concurrently (the bus
arbitration and multiplexing/demultiplexing is tranparent to the user), it
still is  a serial bus, so at a given point in time you can only write to
_one_ device. And if that device is limited in its speed, you're doomed.
The only thing I could imagine is that if you send small bursts that don't
make the write cache full, it _might_ be possible to switch fast between
the devices and thus write the data faster, as the devices can try and
write the data to disk while the others are feeded. 

But I'm on no sure ground here with that assumption, and it certainly would
depend on how the usb-ata-controller deals with that. You said yourself
that you only had 15MB/sec, so it doesn't look to good.

To make this work would certainly be a deep lowlever driver hack and nowhere
in the scope of python per se.

 4) with 45 MByte/s I could theoretically simultaneously
 supply three separate data streams to three USB
 controller writing with 15 MByte/s each out to the
 external storage media.

That might be the case if you use three real separate controllers. But that
will depend on how the OS deals with these, if you really achieve the
theoretical throughoutput.

 5) watching the low CPU usage while writing to USB
 shows me, that CPU-time is not a problem.

That is certainly true - the bottleneck are the buses.

-- 
Regards,

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


Re: Python scope is too complicated

2005-03-20 Thread Dan Bishop
jfj wrote:
 Max wrote:
  Yeah, I know. It's the price we pay for forsaking variable
declarations.
  But for java programmers like me, Py's scoping is too complicated.
  Please explain what constitutes a block/namespace, and how to refer
to
  variables outside of it.


 Some may disagree, but for me the easiest way to understand python's
 scopes is this:

 In Python, there are only two scopes.  The global and the local.
 The global scope is a dictionary while the local, in the case of a
 function is extremely fast.  There are no other scopes.

This isn't true anymore, now that generator comprehensions have been
added to the language.

 x = 17
 sum(x for x in xrange(101))
5050
 x
17

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


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

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

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


Re: RotatingFileHandler and logging config file

2005-03-20 Thread Vinay Sajip
Rob Cranfill wrote:
NID (No, It Doesn't)  ;-)  but thanks anyway. To reiterate, the question 
is how to make RotatingFileHandler do a doRotate() on startup from a 
*config file*. No mention of that in what you point to.
I don't think that RotatingFileHandler *should* be configurable to do a 
doRollover() on startup. I would follow up the suggestion of using your 
own derived class. The config mechanism will allow you to instantiate 
custom handlers - you only have to take into account (as an earlier 
poster has indicated) how the evaluation of the handler class (and its 
constructor arguments) is performed.

BTW - constructor is not just for Java, but C++ too (not to mention C#).
Vinay Sajip
--
http://mail.python.org/mailman/listinfo/python-list


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

2005-03-20 Thread Charles Hartman
On Mar 20, 2005, at 4:10 PM, Francis Girard wrote:
Hello M. Hartman,
It's a very big opportunity for me to find someone that both is a poet 
and
knows something about programming.

First, please excuse my bad english ; I'm a french canadian.
My French is a great deal worse than your English; fear not.
I am dreaming to write a software to help french poets to write strict
rigourous classical poetry. Since calssical poetry is somewhat 
mathematical,
a lot of tasks can be automatised :

1- Counting the number of syllabs (pied in french) in a verse
2- Checking the rimes ; determining the strength of a rime
3- Checking compliance of a poem to a fixed pre-determined classical 
form (in
french, we have distique, tercet, quatrain, quintain, sixain, huitain,
dizain, triolet, vilanelle, rondeau, rondel, ballade, chant royal, 
sonnet,
etc.)

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 ?
That is a very deep question. (See below.)
What other features you think can make it usefull for a poet ?
The first task of cutting sentences into syllabs (phonetically of 
course, not
typographically) is already done. It's been difficult to get it right 
and to
make it guess correctly with a very very high percentage.

I can very well imagine that the next task is even more difficult. I 
need to
translate text into phonems. Do you know some software that does it ? 
I guess
that voice synthetisers that translates written text into spoken text 
must
first translate the text into phonems. Right ? Do you know if there 
some way
that I can re-use some sub-modules from these projects that will 
translate
text into phonems ?
The problems are hard ones. Getting reliable syllable divisions is, all 
by itself, a heart-breaker in English; I'm not sure whether harder or 
easier in French. (See the module syllables.py in the source code to my 
Scandroid program at the site listed below.)

Rhyme is harder -- I haven't yet tried it in English -- precisely 
because text-to-phoneme is very hard.

I haven't really worked with this, that is, with the sounds of speech 
(though I'm a musician as well as a poet), mostly because it's 
difficult. The projects in my *Virtual Muse: Experiments in Computer 
Poetry[1], for example, deal almost entirely with language as a 
typographical phenomenon. So does my Scandroid, even though the 
material it's working with is all aimed at and motivated by the 
auditory qualities of poetry.

I do imagine you're right that the text-to-speech people have worked 
out a lot of this. The trouble is that so far I haven't seen 
public-domain code for the guts of such a program, which is what you 
would need.

Interesting to think about which problems change between French and 
English and which do not.

Good luck -- keep me posted.
[1] This was published by Wesleyan Univ Press, what, nine years ago. 
Probably out of print. I do know where to get some copies.

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


Re: getting text from WinXP console

2005-03-20 Thread Chris Rebert (cybercobra)
You want the function raw_input().
Have you read the tutorial? I should have been covered there.

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


  1   2   >