Re: Confused with methods

2005-02-08 Thread Antoon Pardon
Op 2005-02-07, Alex Martelli schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] wrote:

 Yes it is inconsistent with the rest of python. That you found
 a subset in which it is consistent doesn't change that.
 
 And what if you do:
 
   c = C()
   c.f = g
 
 
 The fact that a function in a class performs a lot of magic if
 it is called through an instance, that isn't performed otherwise,
 makes python inconsistent here. You may like the arrangement
 (and it isn't such a big deal IMO) but that doesn't make it consistent.

 Any descriptor (be it a function or otherwise) has its __get__ method
 called, when _accessed_ by attribute syntax, if and only if that
 descriptor is in a class.  _ALL_ of Python is perfectly consistent on
 this point, and if I didn't already know the kind of crazy and obviously
 false assertions that you post *QUITE* consistently, I would be
 astonished to see you claim otherwise.  Knowing your posts, this latest
 idiocy is perfectly par for the course.

No python is not consistent and your continuous repetion doesn't
make it so. To illustrate, here the following code:

class A:
  l = []
  def f(): pass

a = A()
print a.l is A.l
print a.f is A.f

which produces:

True
False



 A lot of magic is simply a stupid and imprecise way to describe the
 __get__ method gets called.

So what? That is an implementation detail. 

 Saying that any of this happens when the
 function is CALLED is a definitely more serious mistake, since it's
 absolutely obvious that the __get__ method is called when the function
 (or any other attribute) is *ACCESSED* -- the call operation (on
 whatever object __get__ returns) happens AFTERWARDS.

Fine, I was imprecise. But your harping on my impression doesn't
change the fact that python doesn't work consistent here.

 Why you, and a few other habitual trolls, keep lowering the signal to
 noise ratio of this newsgroup with your blatherings, I don't know;

Well you can think me a troll, I think you are a zealot who gets
overly defensive if the wrong people try to suggest python has
some failing.

 I'm
 sure this behavior must be giving you guys some kind of satisfaction.
 Whether the damage you do to the clarity of the issues, and to the
 understanding of newbies who are unfortunate enough to read and trust
 the many imprecise and/or utterly false assertions you keep making,

Look we are all people, we all are imprecise at moments, including you.
But when the wrong people get imprecise you get into a fit on how
these people are trolls and try to get python into a bad daylight
instead of trying to understand what they really are trying to say
and reacting to that and maybe in the mean time correcting the
imprecession.

In this case the way python accesses class functions from an instance
is not consistent with how python accesses other class attributes
from an instance. I know it is designed that way and I can understand
hwy it was done. But this inconsistency can be a stumbling block for
a newcomer and I think that explaining why the inconsistency is present
is a better option than declaring there is no inconsistency.

 with
 totally unjustified airs of competence, is part of your jollies, or just
 a side effect you don't care a whit about, I don't know either.  Guess
 I'll just killfile you for another month now -- wish MacSOUP had a
 simple way to to permanent killfiling, since it's pretty obvious by now
 that it's quite unlikely you'll even post anything worthwhile at all.

Well whether I post something that is worthwhile to you, can only be
decided by you. I sometimes have my doubts about you too.

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


Re: Big development in the GUI realm

2005-02-08 Thread Robert Kern
Francis Girard wrote:
[I wrote:]
In any case, he may be right, and the FSF, Trolltech, and you could all
be wrong. Your intention when you use the GPL may be moot if a judge
determines that the text itself and copyright law does not support your
interpretation.

I'm sorry to jump into this thread without any knowledge of these issues. I 
was just wondering if it did happen. Did some law court, over the past 
decade, had to make a decision about GPL on some real issue ? 
Not about this issue, I don't believe. There was some flap between MySQL 
AB and NuSphere Corporation concerning *static* linking, but that case 
was settled before the judge ruled on whether static linking creates a 
derivative work[1].

Larry Rosen's book _Open Source Licensing_ covers these issues (and 
their lack of case law) pretty thoroughly[2].

[1] http://www.mysql.com/news-and-events/press-release/release_2002_14.html
[2] http://www.rosenlaw.com/oslbook.htm
--
Robert Kern
[EMAIL PROTECTED]
In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Confused with methods

2005-02-08 Thread Alex Martelli
jfj [EMAIL PROTECTED] wrote:

 I just realized that I'm trolling.

I'm glad you're retracting your earlier assertion that There is no
trolling involved here.  Everybody can err, but to admit and apologize
takes character: may I offer my warmest handshake.

Back when I was a Python newbie (and identified as such even in the
Subject of my early posts) I had my ideas about how Python should
change, too: it should grow a '__contains__' special method to let a
container optimize membership tests (the `in' operator); it should have
a specialized iterator protocol, rather than always relying on indexing
for iteration; it should be possible to subclass builtin types, e.g.
dictionary; ... you can read all about it on google, including my
request to Please consider IMHO's to be liberally inserted in what
follows, of course!-).

It turned out that __contains__ was already in the plans (which I did
not know about): I had even guessed the *name*!  The iterator protocol
and subclassing builtin types took a bit longer to appear (and the
eventual name was __iter__ while my original idea was __enum__; and it's
still not fully possible insert a subclassed dict anywhere a dict may be
used) but eventually they did.

And yet for all of this I ended up in a flamewar with the timbot
anyway... it solved itself and we made friends, but still, I'm quite
familiar with the pickles a newbie can get into;-).


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


Re: Curses on Windows

2005-02-08 Thread Josef Meile
Hi Peter,
Last November I posted a message asking for advice on using simple
screen handling techniques under Windows.  Since then I have been
occupied with family / job /Christmas /living  and trying to
understand curses under linux (it works, seems very complex, sure I'm
missing something ...).  Only now am I returning to my original query.
One reply (in fact the only reply - thanks Tim Golden) suggested I
look at http://flangy.com/dev/python/curses/
There was a similar thread last month. See my reply for more links. I
haven't tested them, but they may help.
how to ncurses on win32 platform:
http://mail.python.org/pipermail/python-list/2005-January/262511.html
Just tried that and got the message
You don't have permission to access
/dev/python/curses/files/wcurses-0.1-py2.4.zip on this server.
Yes, I also have problems.
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: Subclassing cElementTree.Element

2005-02-08 Thread Fredrik Lundh
Kent Johnson wrote:

 Is it possible to subclass cElementTree.Element? I tried
   import cElementTree as et
   class Elt(et.Element):
  ...   pass
  ...
 Traceback (most recent call last):
   File stdin, line 1, in ?
 TypeError: Error when calling the metaclass bases
 cannot create 'builtin_function_or_method' instances

Nope.

This is by design; Elements are intended to be contained, not subclassed. (you
cannot subclass ElementTree Elements either; Element is a factory function, not
a class).

To solve the navigation issue, you could either use a dictionary that keeps 
track
of child-parent relations, or use a proxy wrapper.  Or see if you can structure 
your
code so you always work from parents (that's usually easier than you may think).

/F 



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


Re: Big development in the GUI realm

2005-02-08 Thread Fredrik Lundh
Robert Kern wrote:

 Believe me, I share your frustration every time this issue comes up. However, 
 I think it's best to 
 follow Robert Heinlein's maxim:

  Never attribute to malice what can adequately be explained by stupidity.

that's Hanlon, not Heinlein.  to be on the safe side, I won't attempt to
attribute your mistake to anything.

/F 



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


Re: variable declaration

2005-02-08 Thread Fredrik Lundh
Terry Reedy wrote:

At compile time (by which I mean when the Python bytecode is built)

 Compile time is when the def statement is executed

no, that's run time.  def is an executable statement, just like print, 
for,
assignments, import, etc.

the entire module is compiled (to bytecode) before any part of it is executed.
the compiler handles global and from __future__, everything else is done
at runtime.

/F 



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


Re: variable declaration

2005-02-08 Thread Nick Coghlan
Antoon Pardon wrote:ons already existing.
The compilor might generate a RESTORE instruction.
Whether it is done as a LOAD/STORE or a RESTORE, it has to perform the same work 
- check the name exists in the local namespace, and throw an exception if it 
doesn't. If it the name does exist, perform a normal store operation.

but the optimiser should 
eventually be able to do something to eliminate the performance penalty due to 
the technically unnecessary LOAD. I doubt it will be able to beat a STORE_FAST 
when it comes to trying to get a performance improvement, though :)

But maybe a RESTORE_FAST could.
STORE_FAST is set up to store a local as fast as is reasonably possible. The 
space for the local is preallocated in the fast locals C array. How is an 
instruction which does that *and something else* ever meant to be faster?

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


Re: variable declaration

2005-02-08 Thread Just
In article [EMAIL PROTECTED],
 Nick Coghlan [EMAIL PROTECTED] wrote:

 Antoon Pardon wrote:ons already existing.
  The compilor might generate a RESTORE instruction.
 
 Whether it is done as a LOAD/STORE or a RESTORE, it has to perform the same 
 work 
 - check the name exists in the local namespace, and throw an exception if it 
 doesn't. If it the name does exist, perform a normal store operation.

But the compiler would _know_ in which scope the variable was defined, 
no?

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


Re: variable declaration

2005-02-08 Thread Peter Otten
Fredrik Lundh wrote:

 executed. the compiler handles global and from __future__, everything
 else is done at runtime.

and __debug__, too, it seems:

 __debug__
False
 def f():
... if __debug__:
... global x
... x = 42
...
 f()
 x
Traceback (most recent call last):
  File stdin, line 1, in ?
NameError: name 'x' is not defined

Peter

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


Re: empty classes as c structs?

2005-02-08 Thread Nick Coghlan
Steven Bethard wrote:
I wonder if it would be worth adding a descriptor that gives a warning 
for usage from instances, e.g.:
Thinking about it some more, I realised that a class method approach means that 
'type(self).method(self,...)' still works as a way to spell the call in a 
polymorphism friendly way.

And if we're going to have to spell the call that way *anyway*. . .
So maybe it does make sense to simply say that all non-magic Bunch/namespace 
operations are implemented as class methods (and most magic methods are 
effectively treated as class methods when it comes to looking them).

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


Re: variable declaration

2005-02-08 Thread Duncan Booth
Brian van den Broek wrote:

 Can it then be further (truly :-) ) said that
 
 if False:
  # thousands of lines of code here
 
 would effect the structure of the function object's bytecode, but not 
 its behaviour when run? Or, at most, would cause a performance effect 
 due to the bytecode being bloated by thousands of line's worth of code 
 that would never get executed?
 

Yes, but that purely an implementation detail.

if 0:
   # thousands of lines of code here

has no effect at all on the bytecode, it it optimised out entirely. 'if 
False:' is not optimised out in Python 2.4 or earlier, but might be in 
later versions.

Now, to really get your brain hurting, see what this one does:

def hurts_my_brain(v):
if 0: # unlike Steve's eg, ensuring that the
global x  # nested block is never hit at runtime
x = v

I'll give you a clue, it's not the same as your:

def hurts_my_brain(v):
if False: # unlike Steve's eg, ensuring that the
global x  # nested block is never hit at runtime
x = v

So the global statement is a wart which isn't executed at runtime, but 
behaves differently when the bytecode it doesn't generate is optimised out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Learning Python - resources and ideas

2005-02-08 Thread [EMAIL PROTECTED] (Cody Houston)
Hi. What is the best way to learn Python? None of the local schools
near me teach any courses on the topic. Thanks.

--

Cody Houston
[EMAIL PROTECTED]

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


Re: AsciiDoc 6.0.0

2005-02-08 Thread Fuzzyman

Donnal Walter wrote:
 Stuart Rackham wrote:
  AsciiDoc
  
  AsciiDoc is an uncomplicated text document format for writing short
  documents, articles, books and UNIX man pages.
 
  AsciiDoc files can be translated to HTML (with or without
  stylesheets), DocBook (articles, books and refentry documents)
  and LinuxDoc using the asciidoc(1) command.

 Lately I've been thinking about using reStructuredText for creating
 simple web pages. Should I consider AsciiDoc as an alternative, and
if
 so, what are its advantages by comparison? Thanks.

 Donnal Walter

I've never used AsciiDoc - I've always found reST and docutils good
though :-)

Regards,

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

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


Re: Big development in the GUI realm

2005-02-08 Thread Fred Pacquier
Robert Kern [EMAIL PROTECTED] said :

 that's Hanlon, not Heinlein.  to be on the safe side, I won't attempt
 to attribute your mistake to anything.
 
 Fair enough. The only time I've seen it in dead-tree print was in 
 Heinlein's _Time Enough For Love_, unattributed to anyone else. 
 Googlespace seems to be not entirely sure whether Hanlon is real or
 is a corruption of Heinlein. Googling for quote attributions is a
 tricky proposition at best, though.
 
I don't know who Mr Hanlon is, but I've previously seen it attributed to 
Napoleon Buonaparte. Never been able to verify that either, though.

-- 
YAFAP : http://www.multimania.com/fredp/
-- 
http://mail.python.org/mailman/listinfo/python-list


Learning Python - resources and ideas

2005-02-08 Thread [EMAIL PROTECTED] (Cody Houston)
Hi. What is the best way to learn Python? None of the local schools
near me teach any courses on the topic. Thanks.

--

Cody Houston
[EMAIL PROTECTED]

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


Re: Big development in the GUI realm

2005-02-08 Thread Fredrik Lundh
Robert Kern wrote:

 Fair enough. The only time I've seen it in dead-tree print was in Heinlein's 
 _Time Enough For 
 Love_, unattributed to anyone else.

if that's true, it would seem that it predates the Hanlon reference by a
couple of years:

http://www.statusq.org/archives/2001/12/04

on the other hand, Google tells me that Time Enough For Love con-
tains a couple of other famous stupidity quotes, including:

Never underestimate the power of human stupidity

do you still have a copy of the book?  (preferrably a version printed
before 1980...)

/F 



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


Re: variable declaration

2005-02-08 Thread Nick Coghlan
Just wrote:
In article [EMAIL PROTECTED],
 Nick Coghlan [EMAIL PROTECTED] wrote:

Antoon Pardon wrote:ons already existing.
The compilor might generate a RESTORE instruction.
Whether it is done as a LOAD/STORE or a RESTORE, it has to perform the same 
work 
- check the name exists in the local namespace, and throw an exception if it 
doesn't. If it the name does exist, perform a normal store operation.

But the compiler would _know_ in which scope the variable was defined, 
no?
I wouldn't expect the behaviour of name rebinding to be any different from other 
forms of augmented assignment as far as the existence of the left-hand side goes.

Py def f():
...   x += 1
...
Py f()
Traceback (most recent call last):
  File stdin, line 1, in ?
  File stdin, line 2, in f
UnboundLocalError: local variable 'x' referenced before assignment
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: variable declaration

2005-02-08 Thread Nick Coghlan
Antoon Pardon wrote:
I have the impression you are looking at this too much from the view
of the current implementation where putting a an entry in
a directory is seen as an atomic operation.
Yes and no. I *am* looking at it from an implementation point of view, but 
dictionaries have nothing to do with the relevant part of the implementation.

The CPython *_FAST opcodes relate to functions' local variables. Behind the 
scenes they are implemented as integer indexing operations into a pre-sized C 
array. Operations don't come much faster than that :)

Could a rebinding operation *theoretically* be quicker for the other cases which 
involve a real dictionary (or something that looks like one)? Well, perhaps. 
Although I can't see how the rebinding operation would gain a benefit that a 
standard binding operation wouldn't gain if placed at the exact same point.

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


Re: variable declaration

2005-02-08 Thread Fredrik Lundh
Peter Otten wrote:

 executed. the compiler handles global and from __future__, everything
 else is done at runtime.

 and __debug__, too, it seems:

you left out the python -O line.

 __debug__
 False
 def f():
 ... if __debug__:
 ... global x
 ... x = 42
 ...
 f()
 x
 Traceback (most recent call last):
  File stdin, line 1, in ?
 NameError: name 'x' is not defined

yup, but unlike the two others, that's a CPython -O implementation issue.
(I'd say bug, in this case).

neither standard CPython (without -O) nor Jython behave this way.

/F 



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


Re: how to convert 4 bytes into a float ?

2005-02-08 Thread Alex Martelli
Jean-Baptiste PERIN [EMAIL PROTECTED] wrote:

 I read 4 bytes from a binary file.
 
 These bytes represent a floating point number (mantisse exponent form)
 
 How can I get a float from these bytes ?

See the docs for module struct, specifically the struct.unpack function,
if the float is in the binary format your machine expects (or possibly
that but with the wrong endianity).  If the float's binary format is
different from what your machine uses, you're in for a lot of painful
bit-twiddling.


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


Re: empty classes as c structs?

2005-02-08 Thread Nick Coghlan
Michael Spencer wrote:
Nick Coghlan wrote:
The other issue is that a namespace *is* a mutable object, so the 
default behaviour should be to make a copy

I don't follow this argument.  Why does mutability demand copy?  Given 
that somedict here is either a throwaway (in the classic bunch 
application ) or a dict that must be updated (the wrap-dict case), 
copying doesn't make much sense to me.

OTOH, dict.__init__(dict) copies.  h
As you noticed, it's a precedent from the other builtins and objects in the 
standard library. The mutable ones (dict, list, set, etc) all make a copy of 
whatever you pass in.

This is to allow easy copying of 
an existing namespace - 
Can't this be spelled namespace(somenamespace).__copy__()?
Again, as Steven mentioned, this is based on precedent from other objects in the 
interpreter. To get your own copy of a mutable type, you invoke the constructor 
with the original as the sole argument.

  for anything else, invoking vars() is easy enough.
If there is potential for confusion, I'd be tempted to disallow 
namespaces as an argument to update/__update__
Limiting confusion is why I decided to restrict the special-case of querying the 
__dict__ to instances of namespace. Again, as Steven pointed out, the semantics 
get screwed up when the object supplied is usable as a dictionary, but also has 
a __dict__ attribute.

For a namespace, the special case means that namespace(ns_obj) and 
namespace(vars(ns_obj)) have the same result. Just don't go creating a namespace 
subclass which provides a direct mapping interface to anything other than it's 
own __dict__ and expect to affect namespaces created using the normal 
constructor. I figure that limitation is obscure enough that we can live with it :)

For an arbitrary object, you can poke around in its __dict__ by doing:
  namespace.view(vars(obj))
We could use __add__, instead for combining namespaces
Update already let's us combine namespaces. To create a new object that merges 
two namespaces do:
  namespace.update(namespace(ns_1), ns_2)

Good idea.  The implementation ought to be tested against several 
plausible specializations.
One thing I'm going to drop is the ability to use an arbitrary class as a 
subrecord. I realised it screws up storage of classes and class instances which 
have a __dict__ attribute.

Instead, I'll change it so that the optional argument allows you to set some of 
the attributes.

I don't like the sound of that.  The whole point here - whether as 
Steven's nice straightforward bunch, as originally conceived, or the 
other cases you and I and others have been 'cluttering' the discussion 
with ;-)  is convenience, and readability.  If there are hoops to jump 
through to use it, then the benefit is quickly reduced to zero.
Yes, once I realised that the polymorphism friendly 'type(self).update(self, 
other)' works with a classmethod, I realised it made sense to go with Steven's 
classmethod approach.

I'll also revert to his *args based solution to the keyword argument problem, 
too.
Time to go play cricket, so I won't actually be posting any of the above changes 
tonight :)

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


re-entrancy question

2005-02-08 Thread apocalypznow
I have a program that instantiates some objects and runs a main loop. 
Before the main loop starts, I create a thread that listens to TCP 
connections on a port.  If any connections are made, and depending on 
the data, I call methods on some of those objects.

I am worried that calling methods on objects from outside the main loop, 
but that are also operated on in the main loop, could cause problems.

My questions:
1) is this safe?
2) what kind of problems could occur?
3) how do I safely handle this?
--
http://mail.python.org/mailman/listinfo/python-list


RE: re-entrancy question

2005-02-08 Thread Tim Golden
[apocalypznow]

| I have a program that instantiates some objects and runs a main loop. 
| Before the main loop starts, I create a thread that listens to TCP 
| connections on a port.  If any connections are made, and depending on 
| the data, I call methods on some of those objects.
| 
| I am worried that calling methods on objects from outside the 
| main loop, 
| but that are also operated on in the main loop, could cause problems.
| 
| My questions:
| 1) is this safe?
| 2) what kind of problems could occur?
| 3) how do I safely handle this?

No doubt there are more pertinent answers, but unless this is
a learning exercise, you'd be better off investigating Pyro:
http://pyro.sf.net

TJG

(And, thinking about it, even if this is a learning exercise)


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

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


variable declaration

2005-02-08 Thread Alexander Zatvornitskiy
Hi, Peter!

05 feb 2005 at 15:28, Peter Otten wrote:

  variable names. You have to move the code into a function, though: $
  cat epsilon.py ...skipped... $ pychecker epsilon.py epsilon.py:6:
  Local variable (epselon) not used Well, I can change it a little to
  pass this check. Just add print epselon line.

 PO You are now on a slippery slope. I'd rather think of ways to write my
 PO code in a way for it to succeed or at least fail in an obvious way.
Ok, fixed.
 PO I don't consider a scenario likely where you both misspell a name
 PO nearly as often as you write it correctly, and do that in a situation
 PO where the program enters an infinite loop instead of just complaining
 PO with an exception, which is by far the most likely reaction to a
 PO misspelt name.
Let say, you have variable or class field 'PowerOfGenerator', or 'lambda_k'.
You decide to rename it to 'ReactivePowerOfGenerator' or 'lambda_kx'. But, for
some reasons, you forget to do it everywhere, for example in function with
first lines like this:

  PowerOfGenerator=TakeFromSensor()
  if PowerOfGeneratorxxx:

  RecalcPower(PowerOfGenerator)
  PutToTheDatabase(PowerOfGenerator)
  
Here, python will not help you. The worst thing is that in such calculations
you often receive plausible results.

Another example. Let say you have variable PowerOfGenerator in your program.
But, it is only active power, so you have to (1)rename PowerOfGenerator to
ActivePowerOfGenerator, (2)calculate ReactivePowerOfGenerator, and (3)calculate
new PowerOfGenerator by formula
  PowerOfGenerator=sqrt(ReactivePowerOfGenerator**2+ActivePowerOfGenerator**2)
With var declarations, on step (1) you just rename PowerOfGenerator to
ActivePowerOfGenerator in the place of its declaration, and compile your
program. Compiler will show you all places where you have to rename variables.
After it, on step (3) you can safely and peacefully add new PowerOfGenerator
variable.

Of course, I am trying to use more short variable names, but its just an
example.

 PO Code not written is always errorfree, and in that spirit I'd rather
 PO strive to write the function more concisely as

 PO def loop2():
 PO s = 0
 PO for delta in range(10):
 PO s += delta
 PO print s

 PO This illustrates another problem with your approach: would you have
 PO to declare globals/builtins like range(), too?
if I understand you right, it can be done this way (with '~' instead of 'var'):
  ~s=0
  for ~delta in range(10)
s+=delta

[skip]

 PO I suggested pychecker more as a psychological bridge while you gain
 PO trust in the Python way of ensuring reliable programs, i. e. writing
 PO small and readable functions/classes that do one thing well and can
 PO easily be tested. Administrative overhead -- as well as excessive
 PO comments -- only serve to bury what is actually going on.

Your explanation is most non-religious in comparison with all others I see in
this newsgroup. Thank you, now I see that lack of var declarations is not
stupid oversight, but it may have reasons.
From the other side, I still think that optional var declaration is good idea,
for example in functions which are big and operate with tens of variables,
non-decomposable by their nature. Such functions occurs in some domains. And,
in situations like above.

 PO I guess that means no, not a good idea.

 PO On the other hand, taking all names used in a function and looking
 PO for similar ones, e. g. by calculating the Levenshtein distance,
 PO might be worthwhile...

Hmm, what is the Levenshtein distance between 'x1' and 'x2'? Or between kappa_i
and kappa_j? :)

Alexander, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An Ode To My Two Loves

2005-02-08 Thread Alex Martelli
Jorgen Grahn [EMAIL PROTECTED] wrote:

 I also notice I forget one language after doing another for a few weeks. And
 it's not just brackets and semicolons -- I also try to use one language's
 idioms in the other. People who /claim/ they have no trouble switching
 languages seem to have the same problem.

I don't find it a problem as long as the languages are simple and
well-separated.  Python and C are a good example: each is simple, and
each is pretty well-focused -- high-level vs low-level.

It's not necessarily easy if you're continuously going back and forth
between C++ and Java, for example -- in such a case, it seems to me that
transitioning into the proper mindset for each language may well be a
nonzero effort, since the languages aren't really all that simple, and
they have quite some overlap despite all the differences.

I have no experience with such switching between (say) Ruby and Python
-- both simple but vastly overlapping in scope.


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


Re: empty classes as c structs?

2005-02-08 Thread Alex Martelli
Nick Coghlan [EMAIL PROTECTED] wrote:

  We could use __add__, instead for combining namespaces
 
 Update already let's us combine namespaces. To create a new object that merges
 two namespaces do:
namespace.update(namespace(ns_1), ns_2)

One thing I'd like to see in namespaces is _chaining_ -- keeping each
namespace separate but having lookups proceed along the chain.  (The
best semantics for _bindings_ as opposed to lookups isn't clear though).


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


Re: how to convert 4 bytes into a float ?

2005-02-08 Thread Jean-Baptiste PERIN
Alex Martelli a écrit :
Jean-Baptiste PERIN [EMAIL PROTECTED] wrote:

I read 4 bytes from a binary file.
These bytes represent a floating point number (mantisse exponent form)
How can I get a float from these bytes ?

See the docs for module struct, specifically the struct.unpack function,
if the float is in the binary format your machine expects (or possibly
that but with the wrong endianity).  If the float's binary format is
different from what your machine uses, you're in for a lot of painful
bit-twiddling.
Alex
I'll have to handle Intel-PC, DEC-VAX and MIPS-SUN/SGI numbers
So I can't escape the painful bit-twiddling
Anyway, struct.unpack will undoubtedly be an incredibly valuable help
thank you very very very much ..
JiBé
--
http://mail.python.org/mailman/listinfo/python-list


Choosing the right parser for parsing C headers

2005-02-08 Thread Jean de Largentaye
Hi,

I need to parse a subset of C (a header file), and generate some unit
tests for the functions listed in it. I thus need to parse the code,
then rewrite function calls with wrong parameters. What I call shaking
the broken tree :)
I chose to make my UT-generator in Python 2.4. However, I am now
encountering problems in choosing the right parser for the job. I
struggle in choosing between the inappropriate, the out-of-date, the
alpha, or the too-big-for-the task...

So far I've indentified 9(!) potential candidates (Mostly taken from
the http://www.python.org/moin/LanguageParsing page) :

- Plex:
Only a lexical analyser as far as I understand. Kinda RE++, no syntax
processing
- ply:
Lex / Yacc for python! Tackle the Beast! Syntax processing looks
complex..
- Pyggy:
Lex / Yacc -styled too. More recent, but will a 0.4 version be good
enough?
- PyLR:
fast parser with core functions in C... hasn't moved since '97
- Pyparsing:
quick and easy parser... but I don't think it does more than lexical
analysis
- spark:
Here's some wood. Now build your house.
- yapps2 :
yapps2+ (I hesitate to call it yapps3):
chosen by http://www.python.org/sigs/parser-sig/towards-standard.html.
Is the choice up-to-date?
But will it do for parsing C?
- TPG (Toy Parser Generator):
looks cool
- ANTLR (latest version from Jan 28 produces Python code) :
Seems powerful and has a lot of support, but I don't want to have to
use an exterior Java tool. Furthermore, does it let me control what
happens at each stage easily, or does it just make me a compiler?

I've omitted these: shlex, kwparsing (webpage?), PyBison, Trap
(webpage?), DParser, and SimpleParse (I don't want the extra
dependancy).

I was hoping for a quick and easy choice, but got caught in the tar pit
of Too Much Information. Parsing is a large and complex field. As an
added handicap, I'm new to the dark minefield of parsers... I've had
some experience with Lex/Yacc, and have some knowledge of parser
theory, through a course on compilators. I am thus used to EBNF-style
grammar.
I was disappointed to see that Parser-SIG has died out.
Would you have any ideas on which parser is best suited for the task?

John

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


Re: Choosing the right parser for parsing C headers

2005-02-08 Thread Miki Tebeka
Hello Jean,

 - ply:
 Lex / Yacc for python! Tackle the Beast! Syntax processing looks
mini_c is a C compiler written using ply. You can just use it as is.
http://people.cs.uchicago.edu/~varmaa/mini_c/

HTH.
--

Miki Tebeka [EMAIL PROTECTED]
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing the right parser for parsing C headers

2005-02-08 Thread Thomas Heller
Jean  de Largentaye [EMAIL PROTECTED] writes:

 Hi,

 I need to parse a subset of C (a header file), and generate some unit
 tests for the functions listed in it. I thus need to parse the code,
 then rewrite function calls with wrong parameters. What I call shaking
 the broken tree :)

IMO, for parsing 'real-world' C header files, nothing can beat gccxml.

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


Re: Big development in the GUI realm

2005-02-08 Thread Joe
On Tue, 8 Feb 2005 10:01:51 +0100, Fredrik Lundh
[EMAIL PROTECTED] wrote:
except that if *you* set things up so the code is combined when run, *you* are
copying, distributing, and/or modifying the program in order to mix, include 
and/or
combine your work with the GPL:ed work.

if you leave all that to the user, you're clear.

Mmm... I'm not playing games here, no matter what some seem to think. 

It's obvious that the GPL doesn't say precisely whether it's OK to use
an _independent_ library or EXE, ie. a file that is physically
different from the calling EXE, as oppposed to either copy/pasting the
code as is into a program, or statically linking a library into an
EXE.

Until now, I understood the GPL to be a way to make sure no one stole
code (hence, no static linking or copy/pasting code), and with or
without giving back any change they made.

OTOH, I though it was OK to use the by code shipping whatever standard
binary file was downloaded from the project's site, ie. MYEXE.EXE
calling YOURCODE.DLL was OK, when this code was the standard version,
untampered, and clearly indicated as not the EXE's work (as shown by
the file name and version infos).

Hence, either the GPL was not precise enough, or TrollTech should use
a different license that specifically prohibits even using Qt through
dynamic linking.

Conclusion from what I read above: As of now, no court in any country
has settled this issue by specifying whether making use of a GPLed
program _in any way_ requires the calling program to be GPLed as well,
or if there are cases where the EXE can remain closed-source. I'm fine
with TT's intentions, though.

Joe
(no, I don't want whatever stuff I post on the Net to possibly bite me
years from now, hence the anonymous posting. Nothing personal.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Curses on Windows

2005-02-08 Thread Martin Miller
I just tried the flangy.com link and it appears to be OK now.

Martin


Peter wrote:
 ...
 One reply (in fact the only reply - thanks Tim Golden) suggested I
 look at http://flangy.com/dev/python/curses/

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


Re: Choosing the right parser for parsing C headers

2005-02-08 Thread Fredrik Lundh
Thomas Heller wrote:

 IMO, for parsing 'real-world' C header files, nothing can beat gccxml.

no free tool, at least.  if a budget is involved, I'd recommend checking
out the Edison Design Group stuff.

/F 



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


Re: how to convert 4 bytes into a float ?

2005-02-08 Thread Alex Martelli
Jean-Baptiste PERIN [EMAIL PROTECTED] wrote:

 I'll have to handle Intel-PC, DEC-VAX and MIPS-SUN/SGI numbers
 So I can't escape the painful bit-twiddling

I don't recall for sure (even though I did my thesis on a Vax, 25 years
ago!) but I think you _might_ be lucky -- VAX used the binary format
that became the IEEE standard, if I recall correctly.

Intel, MIPS, SUN and SGI surely did follow IEEE standards, endianity
apart, and you can correct for endianity with struct.unpack.

The problem would be there if you had, say, floats in old IBM 360/370
formats, or Cray's original formats, or the like...

 
 Anyway, struct.unpack will undoubtedly be an incredibly valuable help
 
 thank you very very very much ..

You're welcome!


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


Re: Problems with python and threads under Freebsd

2005-02-08 Thread Andrew MacIntyre
snacktime wrote:
After debugging this some more I narrowed it down to an encryption
function in pycrypto that is triggering the segfault.  I posted a bug
report.  Don't really know enough about threading to know whether it's
a python bug or a pycrypto bug, but I'll let someone else sort that
out now..
If you get bus errors, there's a possibility that you are running out of 
stack.

AFAIR, the default thread stack size for Posix builds is dependant on 
the threading implementation.  This can be overridden when building Python.

With each gcc version since 2.9, the size of stack frames for generated 
calls has increased.  If lowering the optimisation to -O or -Os when 
building Python improves the situation, I'd suggest pursuing this 
possibility further.

-
Andrew I MacIntyre These thoughts are mine alone...
E-mail: [EMAIL PROTECTED]  (pref) | Snail: PO Box 370
[EMAIL PROTECTED] (alt) |Belconnen ACT 2616
Web:http://www.andymac.org/   |Australia
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to convert 4 bytes into a float ?

2005-02-08 Thread Fredrik Lundh
Alex Martelli wrote:

 I don't recall for sure (even though I did my thesis on a Vax, 25 years
 ago!) but I think you _might_ be lucky -- VAX used the binary format
 that became the IEEE standard, if I recall correctly.

iirc, you have to swap bytes around.  the code on this page might
be helpful:

http://www.octave.org/octave-lists/archive/octave-sources.2004/msg00033.html

 The problem would be there if you had, say, floats in old IBM 360/370
 formats, or Cray's original formats, or the like...

here's a IBM 360 converter (at least that's what I think it is; the code is 
taken
from a PIL format converter for a format that uses IBM floats):

def ibm_f32s(c):
a = ord(c[0])  127
b = ord(c[3]) + (ord(c[2])8) + (ord(c[1])16)
v = pow(2.0, -24) * b * pow(16.0, a-64)
if ord(c[0])  127:
return -v
return v

many floating point formats are trivial variations on this theme.

/F 



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


Re: empty classes as c structs?

2005-02-08 Thread Carlos Ribeiro
On Tue, 8 Feb 2005 12:01:23 +0100, Alex Martelli [EMAIL PROTECTED] wrote:
 Nick Coghlan [EMAIL PROTECTED] wrote:
 
   We could use __add__, instead for combining namespaces
 
  Update already let's us combine namespaces. To create a new object that 
  merges
  two namespaces do:
 namespace.update(namespace(ns_1), ns_2)
 
 One thing I'd like to see in namespaces is _chaining_ -- keeping each
 namespace separate but having lookups proceed along the chain.  (The
 best semantics for _bindings_ as opposed to lookups isn't clear though).

Good point. The name 'namespace' kind of imples chaining, in the usual
Pythonic sense... But I feel that by splitting this into two types
(namespace  bunch) we may be making things overly complicated, and
losing some of the power of the argument. Again, just my $0.02 worth.

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: [EMAIL PROTECTED]
mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: User Identification

2005-02-08 Thread Fredrik Lundh
Bob Parnes wrote:

I have a python program on a server of an all-linux network. It needs to
 record the user name running it. Is there a way for the program to extract
 the name from the system without a separate log-in dialog?

how about:

 import getpass
 getpass.getuser()
'gromit'

/F 



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


Re: User Identification

2005-02-08 Thread Laszlo Zsolt Nagy
Bob Parnes wrote:
I have a python program on a server of an all-linux network. It needs to 
record the user name running it. Is there a way for the program to extract
the name from the system without a separate log-in dialog?

Bob Parnes
 

What about:
import os
username = os.getlogin()
Please see other functions at:
http://docs.python.org/lib/os-procinfo.html
Best,
  Laci 2.0

--
_
 Laszlo Nagy  web: http://designasign.biz
 IT Consultantmail: [EMAIL PROTECTED]
Python forever!
--
http://mail.python.org/mailman/listinfo/python-list


How to keep a module with the same name as a module it is importing from importing itself?

2005-02-08 Thread plb

All:

I am struggling with an import problem...

In my package, myapp, I have a module, logging.py.  That module,
naturally, imports the library module logging with an 'import logging'
statement.  However, when I use 'import myapp.logging' in my script,
the myapp.logging module tries to import itself rather than the library
logging module.

How can I prevent this from happening other than using a name that
doesn't conflict?

--PLB

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


Re: re-entrancy question

2005-02-08 Thread Valentino Volonghi aka Dialtone
Tim Golden [EMAIL PROTECTED] wrote:

 No doubt there are more pertinent answers, but unless this is
 a learning exercise, you'd be better off investigating Pyro:
 http://pyro.sf.net

AFAIK pyro is just a RPC implementation for python whereas Twisted is a
completely different beast that happens to have its own implementation
of RPC.

How would the OP be better investigating something different, that he
probably doesn't even need?

Your comment would be pertinent only if it considered Perspective Broker
against pyro, and I admit I don't know how they compare.

-- 
Valentino Volonghi aka Dialtone
Now Running MacOSX 10.3.7
Blog: http://vvolonghi.blogspot.com
http://weever.berlios.de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: User Identification

2005-02-08 Thread Laszlo Zsolt Nagy

how about:
 

import getpass
getpass.getuser()
   

'gromit'
 

Hmm, yours is better. It also works on Windows. :-)
I wonder why os.getuser() does not work in Windows - apparently there is 
a good implementation for Windows.

--
_
 Laszlo Nagy  web: http://designasign.biz
 IT Consultantmail: [EMAIL PROTECTED]
Python forever!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Big development in the GUI realm

2005-02-08 Thread Kent Johnson
Fredrik Lundh wrote:
Robert Kern wrote:

Fair enough. The only time I've seen it in dead-tree print was in Heinlein's _Time Enough For 
Love_, unattributed to anyone else.
Amazon.com search inside the book finds no hits for malice in this book.
http://www.amazon.com/gp/reader/0441810764/102-7636110-6481700?v=search-insidekeywords=malice

if that's true, it would seem that it predates the Hanlon reference by a
couple of years:
http://www.statusq.org/archives/2001/12/04
on the other hand, Google tells me that Time Enough For Love con-
tains a couple of other famous stupidity quotes, including:
Never underestimate the power of human stupidity
Search inside the book finds this *twice* in Time Enough For Love.
Kent
--
http://mail.python.org/mailman/listinfo/python-list


RE: re-entrancy question

2005-02-08 Thread Tim Golden
| Tim Golden [EMAIL PROTECTED] wrote:
| 
|  No doubt there are more pertinent answers, but unless this is
|  a learning exercise, you'd be better off investigating Pyro:
|  http://pyro.sf.net
| 
| AFAIK pyro is just a RPC implementation for python whereas 
| Twisted is a
| completely different beast that happens to have its own implementation
| of RPC.
| 
| How would the OP be better investigating something different, that he
| probably doesn't even need?
| 
| Your comment would be pertinent only if it considered 
| Perspective Broker
| against pyro, and I admit I don't know how they compare.


Here's the original post, quoted in its entirety:

quote
I have a program that instantiates some objects and runs a main loop. 
Before the main loop starts, I create a thread that listens to TCP 
connections on a port.  If any connections are made, and depending on 
the data, I call methods on some of those objects.

I am worried that calling methods on objects from outside the main loop, 
but that are also operated on in the main loop, could cause problems.

My questions:
1) is this safe?
2) what kind of problems could occur?
3) how do I safely handle this?
/quote

Now *where* is there any mention of Twisted, either in the original
post or in my reply? As I read it, the OP is doing something which
creates local objects (instances, whatever) and has them available
remotely. He's then -- justifiably -- concerned about possible
re-entrancy if more than one outside agent makes a connection on
his TCP port.

It seemed to me that this was -- approximately -- what Pyro does:
you created objects locally and listen on a TCP port for incoming
requests. Since Pyro's author has already solved a number of the
problems associated with doing this kind of thing, I thought it
might be helpful to point this out.

Tim


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

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


Re: python connect to server using SSH protocol

2005-02-08 Thread Laszlo Zsolt Nagy
[EMAIL PROTECTED] wrote:
How can python connect to server which use SSH protocol?
Is it easy since my python has to run third party vendor, write data,
read data inside the server (supercomputer).
 

In advance, I'm not sure if I understood your problem.  SSH is clearly a 
remote
shell. You will be able to execute other programs on the remote computer.
Is is suitable to use this:

child_stdin,child_stdout,child_stderr =  os.popen2('ssh -l my_username  
my_host')

On the other side, you can write an application that also uses 
stdin/stdout for communication.
Best,

  Laci 2.0
--
_
 Laszlo Nagy  web: http://designasign.biz
 IT Consultantmail: [EMAIL PROTECTED]
Python forever!
--
http://mail.python.org/mailman/listinfo/python-list


Handling import conflicts when module has the same name as a library module that it needs to import?

2005-02-08 Thread plb
All:

I am struggling with an import problem...

In my package, myapp, there is a module called logging. This module,
naturally, imports the standard library module logging.  However, when
I try 'import myapp.logging', the 'import logging' statement appears to
be finding the myapp.logging module instead of the one in the standard
library.

How can I ensure that my logging module doesn't try to import itself?

--PLB

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


Re: Synchronizing methods of a class

2005-02-08 Thread Diez B. Roggisch
 My Question:
 
 If I decorate these function references in __class__.__dict__, am I
 doing it only for my specific instance of that class or the base class
 as well?

A class is a class - so yes, all instances are affected. You might want to
think about metaclasses for decorating.
-- 
Regards,

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


Handling import conflicts when module has the same name as a library module that it needs to import?

2005-02-08 Thread plb
All:

I am struggling with an import problem...

In my package, myapp, there is a module called logging. This module,
naturally, imports the standard library module logging.  However, when
I try 'import myapp.logging', the 'import logging' statement appears to
be finding the myapp.logging module instead of the one in the standard
library.

How can I ensure that my logging module doesn't try to import itself?

--PLB

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


Re: python connect to server using SSH protocol

2005-02-08 Thread P
[EMAIL PROTECTED] wrote:
How can python connect to server which use SSH protocol?
Is it easy since my python has to run third party vendor, write data,
read data inside the server (supercomputer).
Any suggestion?
you can use popen around the ssh binary.
You man need the pty module if you want to deal with password prompts
If you want lower level control, use the twisted module.
--
Pádraig Brady - http://www.pixelbeat.org
--
--
http://mail.python.org/mailman/listinfo/python-list


Re: User Identification

2005-02-08 Thread Gerhard Haering
On Tue, Feb 08, 2005 at 12:29:48PM -, Bob Parnes wrote:
 I have a python program on a server of an all-linux network. It needs to 
 record the user name running it. Is there a way for the program to extract
 the name from the system without a separate log-in dialog?

os.environ[USER] for a start?

os.getuid() will give you the user id, but I don't know if Python has
methods to look up more information from that from /etc/passwd or
whereever from.

-- Gerhard


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

Re: How to keep a module with the same name as a module it is importing from importing itself?

2005-02-08 Thread Laszlo Zsolt Nagy

In my package, myapp, I have a module, logging.py.  That module,
naturally, imports the library module logging with an 'import logging'
statement.  However, when I use 'import myapp.logging' in my script,
the myapp.logging module tries to import itself rather than the library
logging module.
How can I prevent this from happening other than using a name that
doesn't conflict?
 

Did you try the built-in 'imp' module?
http://docs.python.org/lib/module-imp.html
I believe that 'load_module' is your very best friend. :-)
Another idea: rename your modules so they do not conflict with standard 
modules.
Best,

  Laci 2.0
--
_
 Laszlo Nagy  web: http://designasign.biz
 IT Consultantmail: [EMAIL PROTECTED]
Python forever!
--
http://mail.python.org/mailman/listinfo/python-list


Re: python connect to server using SSH protocol

2005-02-08 Thread Simon Anders
Hi
Laszlo Zsolt Nagy wrote:
[EMAIL PROTECTED] wrote:
How can python connect to server which use SSH protocol?
Is it easy since my python has to run third party vendor, write data,
read data inside the server (supercomputer).
 

In advance, I'm not sure if I understood your problem.  SSH is clearly a 
remote
shell. You will be able to execute other programs on the remote computer.
Is is suitable to use this:

child_stdin,child_stdout,child_stderr =  os.popen2('ssh -l my_username  
my_host')
This is what I was about to reply as well. But I did a short test 
program and encountered a problem:

import os
fi, foe = os.popen4 ('ssh dopey')
print fi, 'ls'
fi.close ()  # -- this is annoying
for line in foe:
   print line,
foe.close ()
The above connects to a server, passes the command 'ls', which is 
executed there, and prints the returned result.

However, reading from foe succeeds only if fin has been closed before. 
An fi.flush() seems to be not sufficient. But if one wants Python to 
interactivly communicate with some shell on a remote machine, it is 
inconvenient to have to close and reopen the connection all the time.

There should be a better way.
   Simon
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python as capable as Perl for sysadmin work?

2005-02-08 Thread Roy Smith
In article [EMAIL PROTECTED],
 John M. Gabriele [EMAIL PROTECTED] wrote:

 I recently posted this sort of question to the c.l.p.m but
 didn't get much of a response. I know a little Perl and a
 little Python, but master neither at the moment.
 
 I see that Python is a general purpose OO programming language
 that finds use among some system administrators, but my guess
 is that Perl is still more common in that area than Python.
 
 For sysadmin-related tasks, is Python as useful as Perl, or
 does it get clumsy when often dealing with the stuff admins
 deal with on a regular basis?
 
 At some point during some dingy job in the back boiler room
 of Unix, would you find yourself saying, geez, I'd wish I
 started this with Perl -- Python just isn't cutting it. ?
 
 Thanks,
 ---J

Given that Perl was *designed* for sysadmin work, it's not surprising that 
there are some features of it which make it very convenient to use in that 
arena.  For executing external commands, nothing really comes close to 
Perl's back-tick syntax.  For doing things like reading a sequence a files 
and filtering the combined contents with regular expressions, Perl is 
probably the tool that lets you do that in the most compact way.

As a general-purpose programming language, it sucks.  My personal opinion 
is that the general-purpose suckitude outweighs the domain-specific 
sysadmin convenience.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Big development in the GUI realm

2005-02-08 Thread Gabriel B.
  users.  For example, from their FAQ, it seems that no precompiled
  binaries will be provided.  Support for comercial compilers will not be
  built in, only for gcc (through Cygwin?).
 
 Isn't this just the same thing with a different spin. There was always
 an available distribution for linux for non-commercial use. Windows was
 always the problem. You still can't use it for windows without knowing
 how to compile the thing on windows.

Well, if it's GPLed, can't i simply compile it and distribute a GPLed
.DLL with the source code for everyone?
-- 
http://mail.python.org/mailman/listinfo/python-list


trolltech comitment (was:Big development in the GUI realm)

2005-02-08 Thread Gabriel B.
On Mon, 07 Feb 2005 20:56:44 -0800, Courageous [EMAIL PROTECTED] wrote:
 Follow the copyright holder's wishes.
 
 That's fair. After all, it's free, so they're doing you a damn
 big favor.

I'm terrible sorry to extend this topic even furter, but it's silly,
not to say dull to think like that.

in the first place, it's not that they're doing charity. they have
plans. if they release Qt under GPL for non-comercial use, it's
because they want to increase the user base and so be able to earn
money with the comercial fee later.

And if i'm going to write software for it, when there's plenty of
alternative that actualy works flawless under windows, why should i
stick with an option that i don't even know to wich extends i can use
the damn thing? What it they revoke this license? what it windows
longhorn has a non-backwardcompatible GDI API and a newer version of
Qt must be used, and that newer version does not have a gpl version?

If i'm going to commit to something, i like to know the lengths the
other side gona commit also.

What you said was like Hey! it's free food! who cares if it's
rotten? sorry, but it's just too homer simpson for me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python connect to server using SSH protocol

2005-02-08 Thread Laszlo Zsolt Nagy

import os
fi, foe = os.popen4 ('ssh dopey')
print fi, 'ls'
fi.close ()  # -- this is annoying
for line in foe:
   print line,
foe.close ()
The above connects to a server, passes the command 'ls', which is 
executed there, and prints the returned result.

However, reading from foe succeeds only if fin has been closed before. 
An fi.flush() seems to be not sufficient. 
Hmm. Is it possible to use ssh for simple port forwarding (-L option) 
and write a server program on the remote machine?


--
_
 Laszlo Nagy  web: http://designasign.biz
 IT Consultantmail: [EMAIL PROTECTED]
Python forever!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Big development in the GUI realm

2005-02-08 Thread Fredrik Lundh
Tim Churches wrote:

except that if *you* set things up so the code is combined when run, *you* are
copying, distributing, and/or modifying the program in order to mix, include 
and/or
combine your work with the GPL:ed work.

if you leave all that to the user, you're clear.

 Yes, that is what I, and others, have been saying, and doing, all along. Our 
 Mozilla Public 
 Licensed Python application imports (but contains no code from) a GPLed 
 third-party Python module 
 at runtime, but we don't distribute that module, we just tell users to obtain 
 it independently and 
 install it on their systems.

does your program work (in any way) without this module?

(relying on word games is a lousy legal strategy in most parts of the world)

 (Gee, I thought that word games were the entire basis of much legal endeavour 
 in most parts of the 
 world. Patent specifications in particular spring to mind.)

yeah, but you shouldn't base your entire game on a specific word play.

/F 



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


Re: PHP Embedded In Python

2005-02-08 Thread Keith

jdonnell wrote:
 I'm not sure exactly what your trying to do, but I use php and python
 together a lot. I usually call the python script from php with the
 passthru function like this:

 ?php
 $outputFromPy = passthru('/path/to/myScript.py');
 ?

I need to go the other direction.  I need to call php from within
python.  Thanks.

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


Re: Choosing the right parser for parsing C headers

2005-02-08 Thread Jean de Largentaye
That looks cool Roman, however, I'm behind a Corporate Firewall, is
there any chance you could send me a cvs snapshot?

John

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


Re: Curses on Windows

2005-02-08 Thread rzed
Martin Miller [EMAIL PROTECTED] wrote in 
news:[EMAIL PROTECTED]:

 I just tried the flangy.com link and it appears to be OK now.
 
 Martin
 
 
 Peter wrote:
 ...
 One reply (in fact the only reply - thanks Tim Golden) suggested I
 look at http://flangy.com/dev/python/curses/
 

But this one is still forbidden, at least for me:
http://flangy.com/dev/python/curses/files/wcurses-0.1-py2.4.zip

-- 
rzed

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


Re: [perl-python] text pattern matching, and expressiveness

2005-02-08 Thread Diez B. Roggisch
 He (XL) is a troll and admits it.  If only he would include that
 information up-front in his (IMO worthless) [perl-python] posts, it would
 save a lot of effort.

He does - all of his posts start with [perl-python]. Now the big question is
which community comes up with a better/nicer/shorter/whatever filter -
pythonistas or perljunkies.

-- 
Regards,

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


Loop in list.

2005-02-08 Thread Jim
Where did this type of structure come from:

mat = ['a' for i in range(3)]?

This will produce a list of three elements but
I don't see reference for it in any of the books.

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


Re: Loop in list.

2005-02-08 Thread Jeremy Jones
Jim wrote:
Where did this type of structure come from:
mat = ['a' for i in range(3)]?
This will produce a list of three elements but
I don't see reference for it in any of the books.
 

It's called a list comprehension and it appeared in Python 2.0.
http://www.amk.ca/python/2.0/index.html#SECTION00060

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


Re: Loop in list.

2005-02-08 Thread Fredrik Lundh
Jim [EMAIL PROTECTED] wrote:

 Where did this type of structure come from:

 mat = ['a' for i in range(3)]?

 This will produce a list of three elements but
 I don't see reference for it in any of the books.

it's called list comprehension, and was added in Python 2.0.

http://www.amk.ca/python/2.0/index.html#SECTION00060
http://docs.python.org/tut/node7.html#SECTION00714
http://docs.python.org/ref/lists.html

Python 2.4 introduces a variation called generator expressions:

http://www.python.org/doc/2.4/whatsnew/node4.html
http://www.python.org/peps/pep-0289.html
http://docs.python.org/ref/genexpr.html

/F 



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


Re: Basic file operation questions

2005-02-08 Thread Marc Huffnagle
When you read a file with that method, is there an implied close() call 
on the file?  I assume there is, but how is that handled?

Caleb Hattingh wrote:
Peter, that was very clear, thanks.

So not only is
for line in file(...):
  # do stuff
the most elegant, it is also the fastest. file.readlines() comes
close, but
is only viable for small files.

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


Re: Loop in list.

2005-02-08 Thread Diez B. Roggisch
Jim wrote:

 Where did this type of structure come from:
 
 mat = ['a' for i in range(3)]?
 
 This will produce a list of three elements but
 I don't see reference for it in any of the books.

Its called a list-comprehension. And as I don't know what books you mean, I
can't say if its covered there or not.

-- 
Regards,

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


Re: Loop in list.

2005-02-08 Thread Bill Mill
Jim,

That is called a list comprehension, and it is a feature which
appeared in python 2.3 (iirc). Thus if your books are about earlier
versions of python, list comprehensions will not be covered.

Check out the section of the tutorial about them at
http://docs.python.org/tut/node7.html#SECTION00714 .

Peace
Bill Mill
bill.mill at gmail.com


On Tue, 08 Feb 2005 06:50:08 -0800 (PST), Jim [EMAIL PROTECTED] wrote:
 Where did this type of structure come from:
 
 mat = ['a' for i in range(3)]?
 
 This will produce a list of three elements but
 I don't see reference for it in any of the books.
 
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Loop in list.

2005-02-08 Thread Simon Brunning
On Tue, 08 Feb 2005 06:50:31 -0800 (PST), Jim [EMAIL PROTECTED] wrote:
 Where did this type of structure come from:
 
 mat = ['a' for i in range(3)]?
 
 This will produce a list of three elements but
 I don't see reference for it in any of the books.

It's called a List Comprehension. There's a good historical reason
for the name, but you can be excused in not having looked under that
name in the index. See
http://www.amk.ca/python/2.0/index.html#SECTION00060
for details.

They *should* be mentioned in most books, provided that it's vaguely
recent and covers Python 2.0 or later.

List comps have a cool new little sister, generator expressions - see
http://www.brunningonline.net/simon/blog/archives/001025.html.

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


Re: Synchronizing methods of a class

2005-02-08 Thread Christopher De Vries
On Mon, Feb 07, 2005 at 11:57:02AM -0800, Keith Veleba wrote:
 Background:
 I'm working on a project where I have to do some serious
 multithreading. I've worked up a decorator in Python 2.3.4 to implement
 the lock semantics required for specific functions I want to
 synchronize:

I found Chris Liechti's example very helpful when working on a similar
project. See
http://groups-beta.google.com/group/comp.lang.python/msg/d647a830de39d1db
. Also, I strongly suggest using threading.RLock() objects instead of primitive
locks. With Rlocks one thread can acquire the same lock multiple times without
blocking. This is useful if one synchronized method calls another synchronized 
method.

 Obviously, my classes have to instantiate the _lock in __init__ in
 order for this to work.

The great thing about Chris's example is that the first time a synchronized
method is called a lock is instantiated, so you don't have to worry about this
step.

 Problem:
 
 When iterating through klass.__dict__.items() in the convenience
 method, I only get the instance variables of the class.  No functions.
 I've found a way to get the function list, by iterating through
 klass.__class__.__dict__ .

I'm not sure why klass.__dict__.items() isn't working for you. I tried a simple
example:

class simple(object):
def hello(self):
print Hello World

def methods(cls):
for name,value in cls.__dict__.items():
if callable(value):
print name

 methods(simple)
hello


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


in wxPython, how to minimize the window in absence of minimize button?

2005-02-08 Thread Erik Bethke
Hello All,

I now have a wx.NO_BORDER frame that I have written dragging code
for... I like my window this way as it looks sleeker and I am now
installing some image buttons.

Now I would like to create a new minimize button from an image, and
then capture that mouse down and cause it to minimize the window...

I can make buttons all day long, despite all of my googling I still
cannot figure out what method I should call with my minimize button...

Please help thank you,
-Erik

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


Efficient checksum calculating on lagre files

2005-02-08 Thread Ola Natvig
Hi all
Does anyone know of a fast way to calculate checksums for a large file. 
I need a way to generate ETag keys for a webserver, the ETag of large 
files are not realy nececary, but it would be nice if I could do it. I'm 
using the python hash function on the dynamic generated strings (like in 
page content) but on things like images I use the shutil's 
copyfileobject function and the hash of a fileobject's hash are it's 
handlers memmory address.

Does anyone know a python utility which is possible to use, perhaps 
something like the md5sum utility on *nix systems.

--
--
 Ola Natvig [EMAIL PROTECTED]
 infoSense AS / development
--
http://mail.python.org/mailman/listinfo/python-list


Re: in wxPython, how to minimize the window in absence of minimize button?

2005-02-08 Thread Erik Bethke
Damn,

I am dumb...

self.Iconize( True )

Sorry.

But a helpful tip is that the demo code *surrounding* the wxPython demo
is VERY useful, I never looked at that before!

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


Re: Loop in list.

2005-02-08 Thread Roy Smith
Jim [EMAIL PROTECTED] wrote:
Where did this type of structure come from:

mat = ['a' for i in range(3)]?

This will produce a list of three elements but
I don't see reference for it in any of the books.

It's a list comprehension.  Unfortunately, this is a bad example of
one, since a much simplier way of writing the same thing would be:

mat = ['a'] * 3

After several years of them being in the language, I'm still somewhat
up in the air about the wisdom of list comprehensions.  There is no
doubt that they're convenient and compact, but I think they make code
more difficult to read.  The functional programming folks will
certainly disagree, and I realize I'm probably in the minority on
this, but that's my opinion.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Zeus Programmers Editor V3.94

2005-02-08 Thread Richie Hindle

[Jussi]
 The latest release of the Zeus for Windows programmer's
 editor is now available.

[Gabriel]
 So is this mentioned here on the Python mailing list because Zeus was 
 written in Python, or is this just targeted spam for a commerical product?

From the features page:

 o Syntax highlighting for C\C++, Clipper, Cobol, Fortran, Java, Pascal, Perl, 
 Python, PHP, SQL etc 
 o Fully Scriptable using the Python, Lua or SmallC, VB Script, Java Script, 
 Ruby Script languages 
 o Integrated debugger supports the Java, Perl, Python and C# languages 

IMHO that makes it of general interest to Python programmers.  Whether or
not it's a commercial product seems irrelevant.  For myself, announcements
of Python-related products, whether free or commercial, are welcome here
(though python-announce / c.l.p.a might be a better place, from the point
of view of both readers and announcers).

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: Building Python with Tcl/Tk on Cygwin_NT-5.1

2005-02-08 Thread Dean N. Williams

Dear Jason,
   I installed Cygwin on another Windows XP platform, this time I 
selected ALL for the setup installation. Everything appears to have 
been install just fine, except for when I do the rebaseall command. I 
am receiving the following error messages when I do the rebaseall 
command at the prompt:

$ rebaseall
/usr/bin/rebaseall: line 70: [: too many arguments
/usr/bin/rebaseall: line 75: [: too many arguments
/usr/bin/rebaseall: line 94: $TmpFile: ambiguous redirect
cannot read /cygdrive/c/Documents
   On my laptop installation everything works just fine. What is the 
difference?

   Thanks in advance and best regards,
   Dean
Dean,
Please keep your replies on-list.
On Wed, Feb 02, 2005 at 05:14:21AM -0800, Dean N. Williams wrote:
 

I am trying to do the following according to your notes:
3. Due to issues with Cygwin's fork() and DLL base address conflicts,
one should rebase their Cygwin system to prevent fork() failures.  Use
the following procedure to rebase your system:
  a. install the Cygwin rebase package (if necessary)
  b. shutdown all Cygwin processes
  c. start bash (do not use rxvt)
  d. execute rebaseall (in the bash window)
I think this is why idle fails. So I did the above:
[Dean [EMAIL PROTECTED] ...ASD_work/bin]$ rebaseall
ReBaseImage (/usr/bin/cygexpat-0.dll) failed with last error = 6
What am I doing wrong here?
   

It appears you did not follow step b above.  Did you shutdown *all*
Cygwin processes include services?
Jason
 

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


Re: python connect to server using SSH protocol

2005-02-08 Thread Kartic

[EMAIL PROTECTED] wrote:
 How can python connect to server which use SSH protocol?
 Is it easy since my python has to run third party vendor, write data,
 read data inside the server (supercomputer).

 Any suggestion?

 Sincerely Yours,
 Pujo Aji

Pujo,

There are two Python oriented SSH solutions.
1. pyssh (pyssh.sf.net) which is a library for programmatically
controlling ssh.
2. Paramiko (http://www.lag.net/paramiko/) which are python bindings
for the SSH2 protocol.

I have used neither of these packages, so I am in no position to
recommend anything.

Of course, you have the usual popen() functions that you can use to
invoke SSH.

Thanks,
-Kartic

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


Re: Is Python as capable as Perl for sysadmin work?

2005-02-08 Thread Nick Vargish
John M. Gabriele [EMAIL PROTECTED] writes:

 At some point during some dingy job in the back boiler room
 of Unix, would you find yourself saying, geez, I'd wish I
 started this with Perl -- Python just isn't cutting it. ?

Sometimes I have to write a quick script in Perl because Python isn't
ubiquitous enough around here, and I often find myself thinking I
the opposite... Perl just isn't cutting it.

And I spent several years putting food on the table with Perl, so it's
not like I'm a noob with Perl.

Nick

-- 
#  sigmask  ||  0.2  ||  20030107  ||  public domain  ||  feed this to a python
print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?')
-- 
http://mail.python.org/mailman/listinfo/python-list


Returned mail: Data format error

2005-02-08 Thread 40adeff9 . 6fec5ad3
This message was undeliverable due to the following reason(s):

Your message could not be delivered because the destination computer was
not reachable within the allowed queue period. The amount of time
a message is queued before it is returned depends on local configura-
tion parameters.

Most likely there is a network problem that prevented delivery, but
it is also possible that the computer is turned off, or does not
have a mail system running right now.

Your message could not be delivered within 5 days:
Mail server 187.234.232.62 is not responding.

The following recipients could not receive this message:
python-list@python.org

Please reply to [EMAIL PROTECTED]
if you feel this message to be in error.

[Filename: TEXT.EXE, Content-Type: application/octet-stream]

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

Re: Learning Python - resources and ideas

2005-02-08 Thread Brian van den Broek
[EMAIL PROTECTED] (Cody Houston) said unto the world upon
2005-02-08 05:06:
Hi. What is the best way to learn Python? None of the local schools
near me teach any courses on the topic. Thanks.
--
Cody Houston
[EMAIL PROTECTED]
Hi Cody,
rec.photo.equipment.35mm? -- kind of an odd follow-up for a post to
com.lang.python.
First thing is to learn to ask better questions. It is a bit hard for
anyone to know what to say without knowing your background and level
of experience with computers and programming.
http://catb.org/~esr/faqs/smart-questions.html contains a lot of
very good advice on this.
As for actual learning resources, did you look at www.python.org at
all? (Or search the archives of this group?) The python site has a few
pages of links that speak directly to your question.
But, some concrete suggestions:
The most useful resources for me (I'm still learning, too) was the
Tutor list http://mail.python.org/mailman/listinfo/tutor.
A free book that starts very slow (it is aimed at high-school
students) is http://www.ibiblio.org/obp/thinkCSpy/
I started with that, until I had a bit of a sense of things (Python is
my first language since some BASIC quite some time ago). The Learning
Python helped a lot http://www.oreilly.com/catalog/lpython2/.
Best,
Brian vdB


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


Re: Efficient checksum calculating on lagre files

2005-02-08 Thread Michael Hoffman
Ola Natvig wrote:
Does anyone know of a fast way to calculate checksums for a large file. 
I need a way to generate ETag keys for a webserver, the ETag of large 
files are not realy nececary, but it would be nice if I could do it. I'm 
using the python hash function on the dynamic generated strings (like in 
page content) but on things like images I use the shutil's 
copyfileobject function and the hash of a fileobject's hash are it's 
handlers memmory address.

Does anyone know a python utility which is possible to use, perhaps 
something like the md5sum utility on *nix systems.
Is there a reason you can't use the sha module? Using a random large file I 
had
lying around:
sha.new(file(jdk-1_5_0-linux-i586.rpm).read()).hexdigest() # loads all into 
memory first
If you don't want to load the whole object into memory at once you can always 
call out to the sha1sum utility yourself as well.
 subprocess.Popen([sha1sum, .bashrc], 
stdout=subprocess.PIPE).communicate()[0].split()[0]
'5c59906733bf780c446ea290646709a14750eaad'
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: iterators instead of callbacks.

2005-02-08 Thread Michael Hoffman
Antoon Pardon wrote:
I'm thinking about the FTP-lib now where iterator equivallents of
 retrbinary and retrlines methods may be more easily usable then the
 current versions with a callback.
So I was wondering, are such transformations in the pipeline
somewhere?
Maybe that should be a Python 3.0 idea. I'm sure it would happen a lot 
sooner
if you submitted a patch implementing the behavior you want.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Effbot's SimpleXMLWriter fails when py2exe'd

2005-02-08 Thread Erik Bethke
Hello All,

So I have been using Effbot's XML stuff a lot!  And I have been using
py2exe, pygame and wxPython all mixed together...

I am getting this strange error log when writing XML files with his XML
writer.  It appears to be fouling up on the encoding, ONLY in the exe
version.  Runs fine and great as a python script.

What this does is leave the file hanging open...

I could write out the XML myself, but I would rather use his class...
any ideas why it broke?

Thank you,
-Erik

code snippet:
def SaveVocabTree( self ):
ElementTree( self.vocabXMLTree ).write(self.currentPath,
encoding='utf-8')

error log:
Traceback (most recent call last):
  File vocab.py, line 457, in OnAdd
  File vocab.py, line 483, in AddWord
  File vocab.py, line 494, in SaveVocabTree
  File elementtree\ElementTree.pyc, line 666, in write
  File elementtree\ElementTree.pyc, line 684, in _write
  File elementtree\ElementTree.pyc, line 754, in _encode
LookupError: unknown encoding: utf-8

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


Re: Is Python as capable as Perl for sysadmin work?

2005-02-08 Thread John M. Gabriele
Aahz wrote:
[snip]
Anyway.  Have you ever noticed how shell scripts keep getting longer?
Yup.
Ever notice how it gets harder to figure out what the heck any given
script's doing?
Yup.
 Well, that's where Python helps you out compared to
Perl.  Python can be a bit clumsier than Perl for dirt-simple tasks, but
you'll find that Python scales much better than Perl.
Check. Thanks Aahz. :)
--
-- remove zees if contacting via email --
--
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient checksum calculating on lagre files

2005-02-08 Thread TZOTZIOY
On Tue, 08 Feb 2005 16:13:43 +, rumours say that Robin Becker
[EMAIL PROTECTED] might have written:

Ola Natvig wrote:
 Hi all
 
 Does anyone know of a fast way to calculate checksums for a large file. 
 I need a way to generate ETag keys for a webserver, the ETag of large 
 files are not realy nececary, but it would be nice if I could do it. I'm 
 using the python hash function on the dynamic generated strings (like in 
 page content) but on things like images I use the shutil's 
 copyfileobject function and the hash of a fileobject's hash are it's 
 handlers memmory address.
 
 Does anyone know a python utility which is possible to use, perhaps 
 something like the md5sum utility on *nix systems.
 
 
well md5sum is usable on many systems. I run it on win32 and darwin.

[snip use of some md5sum.exe]

Why not use the md5 module?

The following md5sum.py is in use and tested, but not failproof.

|import sys, os, md5
|from glob import glob
|
|for arg in sys.argv[1:]:
|for filename in glob(arg):
|fp= file(filename, rb)
|md5sum= md5.new()
|while True:
|data= fp.read(65536)
|if not data: break
|md5sum.update(data)
|fp.close()
|print md5sum.hexdigest(), filename

It's fast enough, especially if you cache results.
-- 
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: python code with indention

2005-02-08 Thread Bernhard Herzog
Nick Vargish [EMAIL PROTECTED] writes:

 Xah Lee [EMAIL PROTECTED] writes:

 is it possible to write python code without any indentation?

 Not if Turing-completeness is something you desire.

It's possible to implement a turing machine with a single list
comprehension.  No indentation needed.

   Bernhard

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


Re: Effbot's SimpleXMLWriter fails when py2exe'd

2005-02-08 Thread Simon Brunning
On Tue, 08 Feb 2005 08:35:51 -0800 (PST), Erik  Bethke
[EMAIL PROTECTED] wrote:
 I am getting this strange error log when writing XML files with his XML
 writer.  It appears to be fouling up on the encoding, ONLY in the exe
 version.  Runs fine and great as a python script.

http://starship.python.net/crew/theller/moin.cgi/EncodingsAgain

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


Re: Effbot's SimpleXMLWriter fails when py2exe'd

2005-02-08 Thread Fredrik Lundh
Erik Bethke wrote:

 So I have been using Effbot's XML stuff a lot!  And I have been using
 py2exe, pygame and wxPython all mixed together...

 I am getting this strange error log when writing XML files with his XML
 writer.  It appears to be fouling up on the encoding, ONLY in the exe
 version.  Runs fine and great as a python script.

you need to explicitly tell py2exe to include the relevant encodings
(from the encodings package in the standard library).  adding a simple

import encodings.utf_8

to your script might help.  if not, see the following wiki page:

http://starship.python.net/crew/theller/moin.cgi/EncodingsAgain

/F 



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


pass named parameters to python

2005-02-08 Thread John Leslie
I am converting a korn shell script to python and want to be able to
pass named arguments into python e.g -firstparam -secondparam

Can this be done?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: graph visualisation

2005-02-08 Thread P
Alexander Zatvornitskiy wrote:
Hello, All!
I need routines for visualization of graphs, like this for Matlab:
You could output the dot language, parsed by graphviz
See: http://dkbza.org/pydot.html
Pdraig.
--
http://mail.python.org/mailman/listinfo/python-list


Re: pass named parameters to python

2005-02-08 Thread Duncan Booth
John Leslie wrote:

 I am converting a korn shell script to python and want to be able to
 pass named arguments into python e.g -firstparam -secondparam
 
 Can this be done?
 

See the module 'optparse'.
http://www.python.org/doc/current/lib/module-optparse.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: variable declaration

2005-02-08 Thread Brian van den Broek
Brian van den Broek said unto the world upon 2005-02-07 20:36:
Steve Holden said unto the world upon 2005-02-07 17:51:
SNIP
The reason global is a wart can clearly be seen in the following example:
  x = 3
  def f(tf, v):
 ...   if tf:
 ... global x
 ...   x = v
 ...
  f(0, 5)
  x
5
 
SNIP
Hi,
Steve's example makes my brain hurt. :-)
I'd appreciate it if someone could tell me if I am understanding the 
example correctly. (My grasp of the terminology and issues at play is a 
bit shaky.)
SNIP
Thanks for any confirmation of my understanding / rectification of same. 
Best,

Brian vdB
Thanks to everyone whose contributed to this sub-thread! I've learned 
a lot. :-)

And, for posterity, some one wrote me off-list to correct my claim
that in
if False:
# thousands of lines of code here
the thousands of lines would never get executed. Simplifying their 
example, they pointed out:

 False = 'evil trickery'
 if False:
... print 'Surprise!'
...
Surprise!

Which leads me naturally to the differences between 'if False:' and 
'if ):' that Duncan Booth pointed to. (Where'd I put the Tylenol.)

Thanks again to all,
Brian vdB
--
http://mail.python.org/mailman/listinfo/python-list


Python mail filter

2005-02-08 Thread Mailer
Hello, all,

Well, I need to write a mail filter in Python. The filter will be used in
shared web hosting environment, so the control over MTA configuration etc is
limited.

The basic premise, as I understand is this:

Read mail from stdin
Parse headers etc using rfc822 or email module
Process

# Now I need to do one of the following:

# Discard mail
# Pass through
# Forward to another account, possibly modifying the mail

Now that I have coded up some stuff, the first looks easy - mails are
getting lost. So the question is (may not be entirely specific to Python),
how do I achieve the other two?

Currently, I have set up a .forward that pipes the mail to my script. I can
verify that this works by dumping the contents to a file. If I write to
stdout, however, the mail is not delivered. That doesn't quite look right
either - it's probably too late for the MTA to pick up. What I want to do is
to pass the processed mail back to Postfix so it can deliver it to the
correct local mail box.

FYI, the setup is Sendmail/Postfix.

(P.S. I am very much aware of the existence of procmail, TMDA etc. My
requirements are very specific and requires integration with another
program, so I am only interested in getting a custom solution).

TIA,
Mika


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


Re: variable declaration

2005-02-08 Thread top
Alex Martelli wrote:
[snip]
 I disagree: compile time is when the compiler is running (for
example,
 the compiler is the component which diagnoses syntax errors, while
other
 errors are diagnosed ``at runtime'').
[snip]

That thing about syntax errors is news to me. I thought they were
caught at runtime, since you can catch them as exceptions, as in:

try: prijnt projnt
except SyntaxError: print See, it gets caught

If this happens at compile-time, I'd like to know how.
Thanks,
--
 - Alexandre

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


Re: variable declaration

2005-02-08 Thread Fredrik Lundh
top [EMAIL PROTECTED] wrote:

 That thing about syntax errors is news to me. I thought they were
 caught at runtime, since you can catch them as exceptions, as in:

 try: prijnt projnt
 except SyntaxError: print See, it gets caught

 If this happens at compile-time, I'd like to know how.

$ python sample.py
  File sample.py, line 1
try: prijnt projnt
 ^
SyntaxError: invalid syntax

/F 



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


Re: Efficient checksum calculating on lagre files

2005-02-08 Thread Nick Craig-Wood
Ola Natvig [EMAIL PROTECTED] wrote:
  Hi all
 
  Does anyone know of a fast way to calculate checksums for a large file. 
  I need a way to generate ETag keys for a webserver, the ETag of large 
  files are not realy nececary, but it would be nice if I could do it. I'm 
  using the python hash function on the dynamic generated strings (like in 
  page content) but on things like images I use the shutil's 
  copyfileobject function and the hash of a fileobject's hash are it's 
  handlers memmory address.
 
  Does anyone know a python utility which is possible to use, perhaps 
  something like the md5sum utility on *nix systems.

Here is an implementation of md5sum in python.  Its the same speed
give or take as md5sum itself.  This isn't suprising since md5sum is
dominated by CPU usage of the MD5 routine (in C in both cases) and/or
io (also in C).

I discarded the first run so both tests ran with large_file in the
cache.

$ time md5sum large_file
e7668fdc06b68fbf087a95ba888e8054  large_file

real0m1.046s
user0m0.946s
sys 0m0.071s

$ time python md5sum.py large_file
e7668fdc06b68fbf087a95ba888e8054  large_file

real0m1.033s
user0m0.926s
sys 0m0.108s

$ ls -l large_file
-rw-r--r--  1 ncw ncw 115933184 Jul  8  2004 large_file



Re-implementation of md5sum in python


import sys
import md5

def md5file(filename):
Return the hex digest of a file without loading it all into memory
fh = open(filename)
digest = md5.new()
while 1:
buf = fh.read(4096)
if buf == :
break
digest.update(buf)
fh.close()
return digest.hexdigest()

def md5sum(files):
for filename in files:
try:
print %s  %s % (md5file(filename), filename)
except IOError, e:
print  sys.stderr, Error on %s: %s % (filename, e)

if __name__ == __main__:
md5sum(sys.argv[1:])

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


Re: variable declaration

2005-02-08 Thread Alex Martelli
top [EMAIL PROTECTED] wrote:

 Alex Martelli wrote:
 [snip]
  I disagree: compile time is when the compiler is running (for
 example,
  the compiler is the component which diagnoses syntax errors, while
 other
  errors are diagnosed ``at runtime'').
 [snip]
 
 That thing about syntax errors is news to me. I thought they were
 caught at runtime, since you can catch them as exceptions, as in:
 
 try: prijnt projnt
 except SyntaxError: print See, it gets caught

Nope:

kallisti:~/cb alex$ cat a.py
try: prijnt projnt
except SyntaxError: print See, it gets caught

kallisti:~/cb alex$ python a.py 
  File a.py, line 1
try: prijnt projnt
 ^
SyntaxError: invalid syntax
kallisti:~/cb alex$ 

 If this happens at compile-time, I'd like to know how.

You can catch SyntaxError when it happens (e.g) on an explicit call to
the built-in function ``compile'', or, say:

 try: import a
... except SyntaxError: print caught!
... 
caught!

Here, the compilation of a.py (which has the error, see the cat above)
happens AFTER the try/except itself has been compiled, and while the try
clause is executing (compiling happens as part of import of a .py unless
the .pyc file is already there  updated); so the exception handler can
of course catch the exception.


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


turing machine in an LC (was: Xah Lee's stupid question #853,172)

2005-02-08 Thread Jeremy Bowers
On Tue, 08 Feb 2005 17:36:19 +0100, Bernhard Herzog wrote:

 Nick Vargish [EMAIL PROTECTED] writes:
 
 Xah Lee [EMAIL PROTECTED] writes:

 is it possible to write python code without any indentation?

 Not if Turing-completeness is something you desire.
 
 It's possible to implement a turing machine with a single list
 comprehension.  No indentation needed.

I had to think about it, it's an interesting, and I'm going to tentatively
disagree, because of the statement/expression dichotomy. Tentatively
because if somebody can answer these objections than I will happily change
my mind :-)

I can't figure out how to write a TM in a Python List Comprehension
without one of either variable binding (so we can store the last symbol
list and manipulate it in the next iteration) or recursive function (to
express the whole tape as a recursive function), both of which require
statements. I can figure out how to write a single state transition, but
in a single LC I can't figure out how to feed the new state into the next
iteration; the previous values generated in the LC are, to my knowledge,
not accessible to the LC as it is running. (If they are, I *think* that
would indeed be enough.)

I'm sure Haskell could do both, being a functional language, and I am
satisfied that it is probably possible in that language, as long as you
are resigned to creating a wasted list (which may not even matter in
Haskell). But I think you're screwed in Python with an LC.

However, hack hack hack, I think you could do this in Python 2.4 with a
*generator* comprehension and a couple of supporting lines of non-indented
code:

Python 2.4 (#1, Jan  2 2005, 22:17:50) 
[GCC 3.4.3  (Gentoo Linux 3.4.3, ssp-3.4.3-0, pie-8.7.6.6)] on linux2
Type help, copyright, credits or license for more information.
 import sys
 this = sys.modules[__name__]
 magicGenerator = (getattr(this, results)[-1] + 1 for x in range(5))
 results = [0] # you have to prime the state here
 results.extend(magicGenerator)
 results
[0, 1, 2, 3, 4, 5]
 

Now you *can* get at the previous state and write a state-transition
expression in perfectly legal Python.

What do you know, generator comprehensions are Turing Complete and list
comprehensions aren't. I wouldn't have expected that.

People caught using this technique in real code will be caught and forced
to code in Intercal for the rest of their lives.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Building Python with Tcl/Tk on Cygwin_NT-5.1

2005-02-08 Thread Jason Tishler
Dean,

On Tue, Feb 08, 2005 at 08:01:11AM -0800, Dean N. Williams wrote:
 $ rebaseall
 /usr/bin/rebaseall: line 70: [: too many arguments
 /usr/bin/rebaseall: line 75: [: too many arguments
 /usr/bin/rebaseall: line 94: $TmpFile: ambiguous redirect
 cannot read /cygdrive/c/Documents
 
 On my laptop installation everything works just fine. What is the
 difference?

The TMP and/or TEMP environment variables have at least two spaces in
them.

The easiest workaround is to execute rebaseall like the following:

$ TMP=/tmp rebaseall

Long term I will change rebaseall to deal better with spaces in shell
variables.

Jason

-- 
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: broke tkinter

2005-02-08 Thread wes weston
Philippe C. Martin wrote:
Hi,
I decided to clean my system and rebuild python from scratch.
I downloaded tk8.4.9, tcl8.4.9 and Python2-4.tar.bz2.
I installed tcl then tk using './configure --prefix=/usr'
tkcvs is now working OK
trying to compile python (configure = './configure --prefix=/usr', I get
this:
In file included
from /home/philippe/downloaded/Python-2.4/Modules/_tkinter.c:67:
/usr/include/tk.h:337: error: syntax error before CONST84
In file included from /usr/include/tk.h:1576,
from /home/philippe/downloaded/Python-2.4/Modules/_tkinter.c:67:
Any clue!
Regards,
Philippe

Phillipp,
   Might you be getting the wrong header file/tk version?
http://wiki.tcl.tk/3669  talks about it.
wes
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >