Re: Python IDE like NetBeans/Delphi IDE

2005-04-06 Thread Axel Straschil
Hello!

 WingIDE (commercial, slower than PythonWin but has many features)

You can use and reactivate a trial licence for WingIDE for a realy long
term, give it a try, i bought a licence last week and realy love it!

Lg,
AXEL.
-- 
Aber naja, ich bin eher der Forentyp. Wolfibolfi's outing in 
http://www.informatik-forum.at/showpost.php?p=206342postcount=10
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: specialdict module

2005-04-06 Thread Steven Bethard
Georg Brandl wrote:
Georg Brandl wrote:
Hello,
in follow-up to the recent dictionary accumulator thread, I wrote a
little module with several subclassed dicts.
Comments (e.g. makes it sense to use super), corrections, etc.? Is this
PEP material?
Docstrings, Documentation and test cases are to be provided later.
So, no further interest in this? Or should I write a PEP before?
I'd personally like to see a PEP.  It'd give people a chance to come up 
with some use cases that really justify adding such specialized dicts to 
the standard library.  The only use cases I can come up with would be 
better served by functions that take a sequence and produce a dict (e.g. 
by counting items or by grouping items into lists).  Once the dict is 
built, I usually have no more need for the default-specialized methods.

I'm sure there are some good use cases out there for such dicts, but 
before I get behind this, I wouldn't mind seeing a few of them. =)

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


Re: boring the reader to death (wasRe: Lambda: the Ultimate Design Flaw

2005-04-06 Thread Ville Vainio
 Sunnan == Sunnan  [EMAIL PROTECTED] writes:

Sunnan It's just that I'm having a hard time matching that quote
Sunnan to what I though python was about. I thought boring code
Sunnan was considered a virtue in python. (Explicit is better
Sunnan than implicit, sparse is better than dense.)

Boring code is code that numbs your senses with constant flow of
boilerplate crap, memory management and redundant type declarations
and general blah blah that you skip when you are trying to figure out
what a piece of code does. It's a code that you wish you could train a
monkey to write for you while you go for lunch. Think C++ or Java.

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


Re: boring the reader to death (wasRe: Lambda: the Ultimate DesignFlaw

2005-04-06 Thread Ville Vainio
 Sunnan == Sunnan  [EMAIL PROTECTED] writes:

Sunnan languages. I'm not sure whether I'd consider python
Sunnan particularly terse, though, but I don't know enough about
Sunnan it yet. (I've read a

Read up on list comprehensions and generator expressions. You'll see
the terse side of Python (and genexps look kinda poetic too ;-).

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


Re: Best editor?

2005-04-06 Thread Miki Tebeka
Hello ChinStrap,

 When not using the interactive prompt, what are you using? I keep
 hearing everyone say Emacs, but I can't understand it at all. I keep
 trying to learn and understand why so many seem to like it because I
 can't understand customization even without going through a hundred
 menus that might contain the thing I am looking for (or I could go
 learn another language just to customize!).
Emacs (or VIm in my case) takes time to learn. However when you start to
understand it and know you way around it'll do things no other editor will
do for you.

 Personally I like SciTE, it has everything I think a midweight editor
 should: code folding, proper python support, nice colors out of the
 box, hotkey access to compile (I'm sure emacs does this, but I couldn't
 figure out for the life of me how), etc.
If you're happy with SciTE stay with it.
 
 Opinions on what the best is? Or reading I could get to maybe sway me
 to Emacs (which has the major advantage of being on everyone's system).
Everyone has his/her/it own favorite editor. It's very individual, I'm
hooked on VIm while others won't touch it.

HTH.
--

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


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

Re: cross platform printing

2005-04-06 Thread Miki Tebeka
Hello David,

 Alan Isaac [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  I'd like to try personal financial management using Python.
  I just found PyCheckbook, but it does not support check printing.
  Is there a Python check printing application kicking around?
wxPython is a cross platfom UI framework which has printing support.
Maybe you can cook something.

HTH.
--

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


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

Re: Best editor?

2005-04-06 Thread Nicolay A. Vasiliev
Hello!
What do you think all about ActiveState Komodo?
Michael George Lerner wrote:
Aahz [EMAIL PROTECTED] wrote:
 

Use vim.  80% of the power of emacs at 20% of the learning curve.
   

A system administrator said this to me about unix a long time ago,
but it applies equally well to emacs:
Emacs is a great place to live, but I'd hate to visit.
-michael, an (x)emacs user
 


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


Re: Python Google Server

2005-04-06 Thread Fuzzyman

vegetax wrote:
 Fuzzyman wrote:

  Of course - sorry. Thanks for the fix. Out of interest - why are
you
  using this... just for curiosity, or is it helpful ?

 because is fun to surf on the google cache, =)

Ha - cool ! The bizarre thing is, that for me it's actually useful. I
doubt anyone else will be in the same situation though.

Best Regards,

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

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


How to detect windows shutdown

2005-04-06 Thread Austin
I wrote a program running on windows.
I put the link of the program in Start up folder and let it executed 
minimized.
Every time when I open the computer, my program will be running in system 
tray.

But if the user would like to shutdown the computer, the OS will show an 
error about exception.

At first, I think windows will terminate all processes when it shutdown.
So, if python has the way to dectect shutdown process, I can kill the 
process in advance.

Thanks a lot. 


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


Re: Best editor?

2005-04-06 Thread Ville Vainio
 Miki == Miki Tebeka [EMAIL PROTECTED] writes:

Miki Emacs (or VIm in my case) takes time to learn. However when
Miki you start to understand it and know you way around it'll do
Miki things no other editor will do for you.

Other editors also do stuff Emacs won't do. Code completion is a
killer feature and emacs sucks at it (yes, w/ Cedet too).

Emacs is pretty good for Python if you can't wait for something like
Eclipse+pydev to start (which is a good choice, and worth
learning). Emacs is not necessarily worth learning unless you are an
emacs user already. Emacs also looks so horrible in Linux that I tend
to go for Kate when I'm at home.

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


Re: A ClientForm Question

2005-04-06 Thread narke
John J. Lee wrote,

 See second bullet point under Why does .click()ing on a button not
work for me?.

Thanks for you advice. However, after read through the FAQs, I have not
managed to find a solution for my problem.  I belive my button is
coupled with some Java script which mess thing up and there is no a
easy solution.  Am I right?

-
narke

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


Re: Decorator Base Class: Needs improvement.

2005-04-06 Thread Bengt Richter
On Wed, 06 Apr 2005 02:31:05 GMT, Ron_Adam [EMAIL PROTECTED] wrote:

On Tue, 05 Apr 2005 19:38:38 -0400, Steve Holden [EMAIL PROTECTED]
wrote:


 
So what you are saying is that you would like to be able to use 
arbitrarily complex expressions after the :at sign, as long as they 
return a decorator? If so, you've been pronounced :-)

regards
  Steve

No not at all,  I never said that.  But.. ;-)


If we get into what I would like, as in my personal wish list, that's
a whole other topic. g


I would have preferred the @ symbol to be used as an inline assert
introducer.  Which would have allowed us to put debug code anywhere we
need.  Such as   @print total @.  Then I can switch on and off
debugging statements by setting __debug__ to True or False where ever
I need it.

And as far as decorators go.  I would of preferred a keyword, possibly
wrap, with a colon after it.  Something like this.

I don't understand your seeming fixation with wrappers and wrapping. That's not
the only use for decorators. See Raymond Hettinger's optimizing decorators
in the cookbook for instance. Decorators are something like metaclasses for 
functions,
with much more general possibilities than wrapping, IMO.


def function_name(x):
   return x 

wrap function_name:
   wrapper1()
   wrapper2()
   wrapper3()

A wrap command could more directly accomplish the wrapping, so that
def statements within def statements aren't needed. (Unless you
want'ed too for some reason.)
I think you'll have to show some convincing use cases showing a clear
advantage over current decoration coding if you want converts ;-)


And as far as arbitrary complex expressions go.. Actually I think that
it's quite possible to do as it is. ;-)
Yes and no. You can always write @deco and refer to an arbitrarily complex
callable deco ..., but the actual @-line expression has to abide by the 
language grammar,
and that does not allow arbitrary expressions. But it does provide enough rope.
E.g. see my most recent reply to El Pitonero.


But this is just a few of my current thoughts which may very well
change.  It's an ever changing list. g

I can see that ;-)

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


Re: Does IronPython indicate MS interest in dynamic languages?

2005-04-06 Thread Bengt Richter
On Tue, 05 Apr 2005 23:34:25 -0400, Thomas Gagne [EMAIL PROTECTED] wrote:

Cameron Laird wrote:
snip
 
 And now, for something completely different, I'll tender a
 personal view:  I think Mr. Gates and Python are actually
 destined to get along uncharacteristically well.  Roughly, I
 suspect the habits and motivations of the two are so skew,
 that the usual embrace and extend simply won't obtain.  I
 soberly expect IronPython to work out well for both Microsoft
 and Python.

The techweb.com article said something interesting.

 Python is an open-source dynamic language; dynamic languages enable 
 developers to produce applications more efficiently by reducing the amount 
 of complexity in the code they write, Jason Matusow, program manager of 
 Microsoft's Shared Source Initiative, writes on his blog. Microsoft's 
 IronPython project demonstrates the benefits of putting the Python dynamic 
 language on the .NET Common Language Runtime.

Assuming (I don't know for certain) that MS's PR approves all messages 
that leave the building, I'm wondering if this foray into dynamic 
languages doesn't signal something greater on MS' part.  While Sun and 
Java (and C# for the most part) have remained statically-typed, do you 
think IronPython might indicate a new direction for MS language development?

If there is to be an MSPython, how long 'til Mozilla FirePython? ;-)

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


Re: Best editor?

2005-04-06 Thread bruno modulix
[EMAIL PROTECTED] wrote:
On Tuesday 05 April 2005 11:22 am, ChinStrap wrote:
I keep hearing everyone say Emacs, but I can't understand it at all.

Both emacs and vi suffer from the fact that they can not be used by ordinary
humans. 
My my my... I'm sorry to learn I'm not an ordinary human :(
Thus, I recommend using either to impress your friends.
Err... most of my friend not being coders, they don't even have a clue 
about what are emacs and vim, so they're not really impressed. The other 
are coders and use either vim or emacs or both, so they're not really 
impressed either...

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


Re: Does IronPython indicate MS interest in dynamic languages?

2005-04-06 Thread Ola Natvig
Bengt Richter wrote:
If there is to be an MSPython, how long 'til Mozilla FirePython? ;-)
Regards,
Bengt Richter
'Reclaim your runtime'
I can't wait...
--
--
 Ola Natvig [EMAIL PROTECTED]
 infoSense AS / development
--
http://mail.python.org/mailman/listinfo/python-list


Establishing connection SSH

2005-04-06 Thread [EMAIL PROTECTED]
Hello all,

I have one computer and 1 server.
I have login and password.
The only way I can connect to server is using SSH protocol.
I usually use Winscp3 to connect to the server (by providing login and
password).
Now I would like to connect to the server directly using python code.
How can I establish connection ?
Can I run something in the server and take the result back?

Sincerely Yours,
Pujo

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


Re: Does IronPython indicate MS interest in dynamic languages?

2005-04-06 Thread Simon Brunning
On Apr 6, 2005 5:25 AM, Mike Rovner [EMAIL PROTECTED] wrote:
 Sun abandoned dynamic approach (Tcl) in favor of Java.

Sun appear to be very interested in dynamic languages these days:
http://www.tbray.org/ongoing/When/200x/2004/12/08/DynamicJava

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


Re: Web application toolkit recommendation?

2005-04-06 Thread quentel . pierre
You can also take a look at Karrigell
(http://karrigell.sourceforge.net). You can write pure Python scripts
or use a PHP-like syntax, and it is shipped with gadfly, an SQL engine,
and with KirbyBase, a database engine which uses a Pythonic syntax. As
for all the web frameworks, you can also work with the APIs available
for almost any database under the sun

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


Re: regexp weirdness (bug?)

2005-04-06 Thread Sergey Schetinin
it's line #159 here, but it did work! thanks. so it IS a bug?

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


Re: Class, object question.

2005-04-06 Thread harold fellermann
What I am wondering is if I have a 2nd init  or something similar to 
create a vector. Such as what follows and if I can how do I go about 
implementing it?

Class vector(point):
def __init___(self, point1, point2):
self.i = point2.get_x() - point1.get_x()
self.j = point2.get_y() - point1.get_y()
self.k =  point2.get_z() - point1.get_z()
def __init___(self, i, j, k):
self.i = i
self.j = j
self.k = k
That way I can define a vector either using 2 points or if I have the 
vector data itself?

Well, what you want to do -- polymorphism of function signatures -- can 
be
implemented like this:

class vector_1(point) :
	def __init__(self,*args) :
		if len(args) == 2 and isinstance(args[0],point) and 
isinstance(args[1],point) :
			self.i = args[0].get_x() - args[1].get_x()
			self.j = args[0].get_y() - args[1].get_y()
			self.k = args[0].get_z() - args[1].get_z()

elif len(args) == 3 :
self.i,self.j,self.k = args
else :
raise ValueError, wrong arguments for instance 
initialization
You can also find a nice implementation by Guido van Rossum using 
decorators
at Artima (look for multimethods).
However, I would prefer to avoid this sort of polymorphism because it 
only
obfuscates your code. IMHO, there should be exactly one clear way to 
initialize
an instance. Therefore, I suggest the provide a class method that 
serves as a
special instance factory:

class vector_2(point) :
def __init__(self,i,j,k) :
self.i = i
self.j = j
self.k = k
@classmethod
def difference(cls,point1,point2) :
return cls(
point1.get_x() - point2.get_x(),
point1.get_y() - point2.get_y(),
point1.get_z() - point2.get_z()
)
# how to use it:
point1 = Point(4,5,6)
point2 = Point(1,2,3)
vec = vector_2.difference(point1,point2)
I wonder, why your vector inherits from point though.
And of course, class is written lower case.
Cheers,
- harold -
--
Es ist schon längst alles gesagt worden --
aber noch nicht von jedem.
-- Karl Valentin
--
http://mail.python.org/mailman/listinfo/python-list


Re: boring the reader to death (wasRe: Lambda: the Ultimate DesignFlaw

2005-04-06 Thread Sunnan
Ville Vainio wrote:
Read up on list comprehensions and generator expressions. You'll see
the terse side of Python (and genexps look kinda poetic too ;-).
I am familiar with lc:s/genexps, I usually program in scheme which also 
has them (srfi-42).
They're very nice and I use them a lot.
--
http://mail.python.org/mailman/listinfo/python-list


THE GREATEST NEWS EVER !

2005-04-06 Thread Ron2005_010
 
http://www.print-it.blogspot.com  The Greatest News Ever!

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


Re: boring the reader to death (wasRe: Lambda: the Ultimate Design Flaw

2005-04-06 Thread Sunnan
Ville Vainio wrote:
Boring code is code that numbs your senses with constant flow of
boilerplate crap, memory management and redundant type declarations
and general blah blah that you skip when you are trying to figure out
what a piece of code does.
The python code I've read so far has looked like that. Not type 
declarations, but lng class declarations.

Also, Guido recently urged people to explicitly write recursions rather 
than to use reduce - which I thought was completely in line with what 
I've seen as python's goals: readability/understandability as more 
important than terseness/non-boringness.

 It's a code that you wish you could train a
monkey to write for you while you go for lunch. Think C++ or Java.
Oh, yes. C++ and Java can be super boring. C++ can also be pretty hard 
to understand - it's not all boilerplate.

I'm not saying Python is always boring (maybe I've just been in an 
easily bored mood when I've read Python stuff), and I'm not saying that 
boring is always bad.

Yesterday, I read some marketing prop describing a proprietary IDE 
(don't remember what language) as exciting, and I went Ugh, no 
thanks! Give me calm computing. And then I thought - wait: I just 
ranted about boringness on comp.lang.python. Can't boring and calm 
sometimes mean the same thing?
--
http://mail.python.org/mailman/listinfo/python-list


ignoring keywords on func. call

2005-04-06 Thread Brano Zarnovican
Hi !

If I define 'f' like this

def f(a):
  print a

then, the call with keywords

f(1, optional=2)

fails. I have to change 'f' to

def f(a, **kwrds):
  print a

to ignore optional parameters.

BUT..

Q: Can you call 'f' with keywords that will be
  ignored, without changing 'f's definition ?

I would like to avoid code like this:
k = {}
k['optional'] = 2
try:
  f(1, **k)
except TypeError:
  f(1)

Also, the problem is that I don't know if the TypeError
was caused by calling 'f' with keywords or somewhere
inside f.

You can also say that I need to specify optional parameters
on caller side (not called side).

BranoZ

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


Re: boring the reader to death (wasRe: Lambda: the Ultimate Design Flaw

2005-04-06 Thread Ville Vainio
 Sunnan == Sunnan  [EMAIL PROTECTED] writes:

Sunnan Ville Vainio wrote:

Sunnan Also, Guido recently urged people to explicitly write
Sunnan recursions rather than to use reduce - which I thought was
Sunnan completely in line with what I've seen as python's goals:
Sunnan readability/understandability as more important than
Sunnan terseness/non-boringness.

The problem w/ reduce is that it's not intuitive. You'll have to stop
to think what the code w/ reduce does - effectively converting it to a
normal loop (not recursion!) in your head. It's a net loss when you
compare it to just reading an explicit loop as written in code.

Sunnan Yesterday, I read some marketing prop describing a
Sunnan proprietary IDE (don't remember what language) as
Sunnan exciting, and I went Ugh, no thanks! Give me calm
Sunnan computing. And then I thought - wait: I just ranted about
Sunnan boringness on comp.lang.python. Can't boring and calm
Sunnan sometimes mean the same thing?

Not for me at least. 'Boring' implies a certain sense of frustration,
not getting anywhere and generally feeling like you are wasting your
time. Human attention is a limited resource, and being bored leads to
loss of attention.

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


Re: ignoring keywords on func. call

2005-04-06 Thread Fredrik Lundh
Brano Zarnovican wrote:

 Q: Can you call 'f' with keywords that will be
  ignored, without changing 'f's definition ?

no.

 I would like to avoid code like this:
 k = {}
 k['optional'] = 2
 try:
  f(1, **k)
 except TypeError:
  f(1)

why would you write code like this?  what's the use case?

 Also, the problem is that I don't know if the TypeError
 was caused by calling 'f' with keywords or somewhere
 inside f.

 You can also say that I need to specify optional parameters
 on caller side (not called side).

you can use reflection mechanisms to check the target function
signature, but I won't tell you how to do that until you show me
a reasonable use case ;-)

/F 



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


Re: regexp weirdness (bug?)

2005-04-06 Thread Fredrik Lundh
Sergey Schetinin wrote:

 it's line #159 here, but it did work! thanks. so it IS a bug?

sure looks like one.  please report it here:

http://sourceforge.net/tracker/?group_id=5470atid=105470

/F 



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


Re: Semi-newbie, rolling my own __deepcopy__

2005-04-06 Thread [EMAIL PROTECTED]
Michael Spencer wrote:
 [EMAIL PROTECTED] wrote:
[snip]
  Anyway, my present problem is that I want to make copies of
instances
  of my own custom classes.  I'm having a little trouble
understanding
  the process.  Not that I think that it matters -- but in case it
does,
  I'll tell you that I'm running Python 2.3.4 on a Win32 machine.
[snip]
 If you google for:
   python __deepcopy__ cookbook
 you will find a couple of examples of this method in use, among them:

 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/259179

  1  class deque(object):
  2
  3  def __init__(self, iterable=()):
  4  if not hasattr(self, 'data'):
  5  self.left = self.right = 0
  6  self.data = {}
  7  self.extend(iterable)

 [...snip methods...]

  8def __deepcopy__(self, memo={}):
  9from copy import deepcopy
 10result = self.__class__()
 11memo[id(self)] = result
 12result.__init__(deepcopy(tuple(self), memo))
 13return result

 HTH
 Michael

Hi, Michael,

I was indeed finding code like this in my web searches, though not this
particular example.  I'm glad that you cut out code that is irrelevant
to the deepcopy operation.  Still, I want to understand what is going
on here, and I don't.  I've numbered the lines in your example.

So, entering deepcopy, I encounter the first new concept (for me) on
line 10.  We obtain the class/type of self.  On line 11 we create a
dictionary item in memo, [id(self):type(self)].  So now I'm confused as
to the purpose of memo.  Why should it contain the ID of the *original*
object?

Things get even stranger for me on line 12.  Working from the inside of
the parentheses outward, an attempt is made to convert self to a tuple.
 Shouldn't this generate a TypeError when given a complex, non-iterable
item like the deque class?  I just tried running one of my programs,
which assigns the name x to one of my custom objects, and when I
execute tuple(x), a TypeError is what I get.

Anyway, I like what I think I see when you finally call __init__ for
the copied object, on lines 4-6.  If __deepcopy__ calls __init__, then
the new deque object should already have a data attribute.  So data
is only initialized if it doesn't already exist.

I do not understand whether the iterable variable, which appears on
lines 3 and 7, is relevant to the copying operation.  Line 12 calls
__init__ with a single argument, not two, so iterable should be
declared as an empty tuple.  Again I see what I think should generate a
TypeError on line 7, when an attempt is made to extend the non-sequence
object self with the iterable tuple.

Is there another section of the Python docs that will clarify all this
for me?  I got hung up on all the static, public, etc. declarations
in Java early on.  Python has taken me an awful lot farther, but
perhaps I'm hitting the conceptual wall again.

--
Rainforest laid low.
Wake up and smell the ozone,
Says man with chainsaw.
John J. Ladasky Jr., Ph.D.

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


Re: boring the reader to death (wasRe: Lambda: the Ultimate Design Flaw

2005-04-06 Thread Michele Simionato
Sunnan:

 The python code I've read so far has looked like that. Not  type
declarations, but lng class declarations.

What do you mean? Lots of repetitive
self.variable=variable in the __init__ method? Use of classes when
you would use closures? Or maybe you
are comparing with CLOS classes, which are pretty
slim, since the (multi)methods are defined outside
them?

  Michele Simionato

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


Re: ignoring keywords on func. call

2005-04-06 Thread Brano Zarnovican
  Q: Can you call 'f' with keywords that will be
   ignored, without changing 'f's definition ?

 no.

OK. Thank you for an answer.

 what's the use case?

I have extended the dict class, so that my __getitem__ accepts an
optional parameter

class MyTree(dict):

  def __getitem__(self, key, **k):
..

  def lookup(self, seq):
node = self
for k in seq:
  node = node.__getitem__(k, someoption=True)

lookup takes a sequence of keys to lookup in hierarchy
of Tree nodes. But I would like lookup to work also on objects
that are not subclasses of Tree. It has to work on any dict-like class.

If a user defines a custom class, he will intuitively define
__getitem__
like this:

def MyNode(??):
  def __getitem__(self, key):
..

I could check in 'lookup'

  if isinstance(node, Tree):
  node = node.__getitem__(k, someoption=True)
  else:
  node = node.__getitem__(k)

But it still doesn't guarantee that __getitem__ accepts keywords.
(What if somebody will extend the Tree class and overlook the
definition of __getitem__ and define a classic one)

BranoZ

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


how to parse system functions output

2005-04-06 Thread praba kar
Dear all,

  I want to parse the system functions output
but I couldn't do it. Kindly assist me in this
task.

eg) bytesused = os.system('du -sh /Users/enmail')
if I print this bytesused variable the output of
bytesused variable is the below

14M /Users/enmail
0

Now From this Output I want only '14M I cannot split
this output by space.  If anyone know regarding this
mail me ASAP

regards
Prabahar



Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
-- 
http://mail.python.org/mailman/listinfo/python-list


Harvestman install not working

2005-04-06 Thread python newbie
Hi, I previously had Harvestman installed and working okay, but somehow the
latest version won't install.

I have Python23 installed.

When I attempt to execute the py2exesetup.bat file (on Windows XP), I get:

--

E:\zips\internet\utilities\HarvestMan-1.4\HarvestMan-1.4.tar\HarvestMan-1.4\Harv
estManrem Batch file for creating py2exe executable for Harvestman
usage: install.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: install.py --help [cmd1 cmd2 ...]
   or: install.py --help-commands
   or: install.py cmd --help

error: option --force-imports not recognized
Press any key to continue . . .


--

Any suggestions?
 Thanks



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


Re: A ClientForm Question

2005-04-06 Thread Satchidanand Haridas
Hi,
ClientForm and Mechanize like tools do not execute javascript . You will 
normally have to do them manually in your python code itself. In your 
case, if you have a button, which (and I assume) executes some 
javascript code that sets some hidden variable and/or changes the 
'action' attribute of the form, you will have to change/assign those 
elements in your python code itself.

ClientForm and mechanize can get tedious to use when one has a lot of 
JavaScript functionality in the form.

Hope this answered your question... :-)
regards,
Satchit
narke wrote:
John J. Lee wrote,
 

See second bullet point under Why does .click()ing on a button not
   

work for me?.
Thanks for you advice. However, after read through the FAQs, I have not
managed to find a solution for my problem.  I belive my button is
coupled with some Java script which mess thing up and there is no a
easy solution.  Am I right?
-
narke
 

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


formatting file

2005-04-06 Thread SPJ
Hi,

I am new to python hence posing this question.
I have a file with the following format:

test11.1-1   installed
test11.1-1   update
test22.1-1   installed
test22.1-2   update

I want the file to be formatted in the following way:

test11.1-1   1.1-2
test22.1-1   2.1-2

How can I achieve this? I am stuck here.

Thanks in advance.
spj



__ 
Yahoo! Messenger 
Show us what our next emoticon should look like. Join the fun. 
http://www.advision.webevents.yahoo.com/emoticontest
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: check interpreter version before running script

2005-04-06 Thread rbt
Peter Otten wrote:
rbt wrote:

Is there a recommended or 'Best Practices' way of checking the version
of python before running scripts? I have scripts that use the os.walk()
feature (introduced in 2.3) and users running 2.2 who get errors.
Instead of telling them, 'Upgrade you Python Install, I'd like to use
sys.version or some other way of checking before running.

I like
import os
try:
os.walk
except AttributeError:
# implement fallback
No need to remember in which version the desired feature came to be.
Peter
Thanks for all the tips. I found this tip from Peter the best for my 
situation.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to detect windows shutdown

2005-04-06 Thread Larry Bates
Programs that start at boot, run until shutdown and run in
background all the time under Windows are good candidates
for being turned into Windows Services.  They respond to
shutdown commands properly and can be fine-grained scheduled
as well.  For tutorial pick of a copy of Python Programming
on Win32 (Hammond and Robinson) and use Mark Hammonds Python
Windows extension library.

Larry Bates


Austin wrote:
 I wrote a program running on windows.
 I put the link of the program in Start up folder and let it executed 
 minimized.
 Every time when I open the computer, my program will be running in system 
 tray.
 
 But if the user would like to shutdown the computer, the OS will show an 
 error about exception.
 
 At first, I think windows will terminate all processes when it shutdown.
 So, if python has the way to dectect shutdown process, I can kill the 
 process in advance.
 
 Thanks a lot. 
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Erroneous line number error in Py2.4.1 [Windows 2000+SP3]

2005-04-06 Thread Timo
For some reason Python 2.3.5 reports the error in the following program
correctly:

  File C:\Temp\problem.py, line 7
SyntaxError: unknown decode error

..whereas Python 2.4.1 reports an invalid line number:

  File C:\Temp\problem.py, line 2
SyntaxError: unknown decode error

- problem.py starts -
# -*- coding: ascii -*-


Foo bar


# Ä is not allowed in ascii coding
- problem.py ends -

Does anyone have a clue what is going on? Without the encoding
declaration both Python versions report the usual deprecation warning
(just like they should be doing).

My environment: Windows 2000 + SP3.

BR,
Timo

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


Re: Lambda: the Ultimate Design Flaw

2005-04-06 Thread François Pinard
[Aahz]

 [François]

 Many of us are using Python today, week after week, year long.  So
 let's be pragmatic.  Python is what it became and now is.  Let's not
 define it as a memory from the past nor as a futuristic dream.

 You're free to continue using 1.5.2.  [...]

Sure, of course.  Yet, our friendly argument is sliding away from was it
originally was.  The point was about not asserting in this forum that
Python has only one way to do it, because this is not true anymore.

The principle has been, it may be back in some distant future, but now
it is not.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


shebang in cross platform scripts

2005-04-06 Thread rbt
Haven't tested this on Windows yet... thought I'd ask here:
Does the line below have any negative impact on Windows machines? I 
develop and test mostly on Unix, but my scripts are often used on Win 
systems too.

#!/usr/bin/env python
Many thanks,
rbt
--
http://mail.python.org/mailman/listinfo/python-list


Re: authentication in zope server Python

2005-04-06 Thread Raghul
I'm sorry

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


Re: shebang in cross platform scripts

2005-04-06 Thread Simon Brunning
On Apr 6, 2005 2:37 PM, rbt [EMAIL PROTECTED] wrote:

 Does the line below have any negative impact on Windows machines? I
 develop and test mostly on Unix, but my scripts are often used on Win
 systems too.
 
 #!/usr/bin/env python

Nope. On Windows it's just a comment.

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


Re: shebang in cross platform scripts

2005-04-06 Thread Diez B. Roggisch
rbt wrote:

 
 Haven't tested this on Windows yet... thought I'd ask here:
 
 Does the line below have any negative impact on Windows machines? I
 develop and test mostly on Unix, but my scripts are often used on Win
 systems too.
 
 #!/usr/bin/env python

Thanks to the # being the comment sign in python, it will be silently
discarded by windows.

-- 
Regards,

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


Re: optparse and negative numbers as positional arguments

2005-04-06 Thread Tomi Silander
Grant Edwards wrote:
On 2005-04-05, Tomi Silander [EMAIL PROTECTED] wrote:

How is one supposed to give negative numbers as positional arguments 
when using optparse?
  ./mitvit.py -- -1.1
Thank you,
this works. I saw it in the source, but apparently did not properly pay 
attention; all the args after -- are considered positional if I read 
this right.

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


Re: shebang in cross platform scripts

2005-04-06 Thread Bill Mill
On Apr 6, 2005 9:37 AM, rbt [EMAIL PROTECTED] wrote:
 
 Haven't tested this on Windows yet... thought I'd ask here:
 
 Does the line below have any negative impact on Windows machines? I
 develop and test mostly on Unix, but my scripts are often used on Win
 systems too.
 
 #!/usr/bin/env python

What the others have said already is true, that it will be ignored on
windows, with one caveat. The shebang is interpreted by Apache if your
script is a CGI script. So, if your script is a CGI, you will need to
have a windows version and a nix version.

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to detect windows shutdown

2005-04-06 Thread Peter Hansen
Austin wrote:
I wrote a program running on windows.
I put the link of the program in Start up folder and let it executed 
minimized.
Every time when I open the computer, my program will be running in system 
tray.

But if the user would like to shutdown the computer, the OS will show an 
error about exception.
Important missing information:  is this a GUI program or
a console program, and if it's a GUI program, what framework
did you use to write it (wxPython, PyQt, other...)?  Also,
what is the exception that you got?  (Always report the
specific error: we can't guess what exception you got,
and the answer could well point directly to a cause that
is different than you think it is.)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Resticted mode still active (error?)

2005-04-06 Thread Max
I thought restricted mode had been removed from Python
but it seems to be active for Python 2.3.5 +.

I'm using the JEP product which allows integration
of Java with Python (see http://jepp.sourceforge.net) via
starting a Python interpreter in the same process as the
JVM.
This integrates with python via the C interface, allowing
the user to 'eval' python code (amongst other features).

It seems that since Python 2.3.5 any threads (using the
threading module) created via code that has been
evaluated through the jep.eval() interface (i.e.Python C
interface )are executed in restricted mode and cannot,
for example, create files. Code that is just evaled (i.e not
in a subthread) thread has no restrictions.

The error reported is:
IOError: file() constructor not accessible in restricted
mode

(see http://sourceforge.net/forum/forum.php?
thread_id=1247793forum_id=376782) - I've given a JEP
specific example here.

There seems to be a similar problem with mod_python
(see
http://www.modpython.org/pipermail/mod_python/2005-
January/017129.html)

Reading through the release notes for Python 2.3.5
I see:
Bug #754449: threading.Thread will no longer mask
exceptions raised during interpreter shutdown with
another exception caused by attempting to output the
initial exception. This fix also includes a backport of rev.
1.41 from HEAD.

This might be the problem as it seems to involve the
porting of 2.4 threading code back to the 2.3 tree.

The error output is:
Exception in thread Thread-1:
Traceback (most recent call last):
File C:\Python24\Lib\threading.py, line 442, in
__bootstrap
File string, line 5, in run
IOError: file() constructor not accessible in restricted
mode

2.4.1c1 (#63, Mar 10 2005, 10:36:41) [MSC v.1310 32
bit (Intel)]
Creating file from main thread...
Done
Creating file from sub thread...
Done

Has anyone got any ideas about this?

Thanks in advance,
Max


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


Re: how to parse system functions output

2005-04-06 Thread Peter Hansen
praba kar wrote:
eg) bytesused = os.system('du -sh /Users/enmail')
if I print this bytesused variable the output of
bytesused variable is the below
14M /Users/enmail
0
It's unlikely this is the contents of bytesused,
because os.system() does not return the output
of the program that is run, it returns only the
exit value.  (See the doc.)  The 14M ... part
is actually being printed by the du command
as it runs.  bytesused contains only the 0
that you show above.
Now From this Output I want only '14M I cannot split
this output by space.  If anyone know regarding this
mail me ASAP
You are looking for either os.popen() or the newer,
more flexible subprocess module (available in
Python 2.4).  Again, check the docs for details and
examples for both of these.
Basically you would do this:
result = os.popen('du -sh /Users/enmail').read()
# now parse result...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: formatting file

2005-04-06 Thread Peter Hansen
SPJ wrote:
I have a file with the following format:
test11.1-1   installed
test11.1-1   update
test22.1-1   installed
test22.1-2   update
I want the file to be formatted in the following way:
test11.1-1   1.1-2
test22.1-1   2.1-2
Please verify that you made an error about the second
version value for test1: the before (1.1-1) and
the after (1.1-2) values do not match.
Also, is it fair to assume the file is guaranteed
to contain even numbers of lines, always with both
an installed line and an update line, and that
the order is as shown above, etc...  in other words,
how robust does the solution need to be?
(You might also show a little bit of your own attempt,
if nothing else so we don't get the idea this is
homework that we're doing for you. :-) )
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Gnuplot.py and, _by far_, the weirdest thing I've ever seen on my computer

2005-04-06 Thread syd
Ok yall, here's my summary.  Thanks again for all the help.

Most importantly, upgrading to gnuplot-py 1.7 fixes this problem.

In gnuplot-py 1.6, this is the bottom line...

Does not fix:
Gnuplot.GnuplotOpts.prefer_fifo_data = 0

Fixes:
Gnuplot.GnuplotOpts.prefer_inline_data = 1

Fixes:  (placed between setting output and plot)
while 1:
  if os.path.isfile(myGraph.png):
break
  time.sleep(1)

As for matplotlib, I checked it out.  Looks amazing!  I really, really
like what demos I tried.

HOWEVER, I could not find a good way to do smoothing.  I like the
gnuplot bezier smoothing.  This wouldn't be the hardest thing in the
world to code, but I was a little disappointed.  If yall have any
ideas, bring em on!  :)

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


Re: formatting file

2005-04-06 Thread Steve Holden
SPJ wrote:
Hi,
I am new to python hence posing this question.
I have a file with the following format:
test11.1-1   installed
test11.1-1   update
test22.1-1   installed
test22.1-2   update
I want the file to be formatted in the following way:
test11.1-1   1.1-2
test22.1-1   2.1-2
How can I achieve this? I am stuck here.
I suspect you need to
  a) remove the error in your specification (should there
 not be a 1.1-2 somewhere in the input) and/or
  b) explain the exact intent in a little more detail -
 we aren't psychic, and while the problem may be very
 obvious to you, we aren't inside your head with it!
regards
 Steve
--
Steve Holden+1 703 861 4237  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


(no subject)

2005-04-06 Thread python-list-bounces+archive=mail-archive . com
#! rnews 4875
Newsgroups: comp.lang.python
Path: 
news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!attws2!ip.att.net!NetNews1!xyzzy!nntp
From: Harry George [EMAIL PROTECTED]
Subject: Re: Best editor?
X-Nntp-Posting-Host: cola2.ca.boeing.com
Content-Type: text/plain; charset=us-ascii
Message-ID: [EMAIL PROTECTED]
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3
Lines: 106
Sender: [EMAIL PROTECTED]
Organization: The Boeing Company
References: [EMAIL PROTECTED]
Mime-Version: 1.0
Date: Wed, 6 Apr 2005 14:22:57 GMT
Xref: news.xs4all.nl comp.lang.python:371122

ChinStrap [EMAIL PROTECTED] writes:

 When not using the interactive prompt, what are you using? I keep
 hearing everyone say Emacs, but I can't understand it at all. I keep
 trying to learn and understand why so many seem to like it because I
 can't understand customization even without going through a hundred
 menus that might contain the thing I am looking for (or I could go
 learn another language just to customize!).
 
 Personally I like SciTE, it has everything I think a midweight editor
 should: code folding, proper python support, nice colors out of the
 box, hotkey access to compile (I'm sure emacs does this, but I couldn't
 figure out for the life of me how), etc.
 
 Opinions on what the best is? Or reading I could get to maybe sway me
 to Emacs (which has the major advantage of being on everyone's system).
 

The key (as others have said) is to know your editor and be effective
with it.  As long as it can handle ASCII, does autoindent, and knows
tab-is-4-chars, then it is a viable choice.

Since you asked specifically about emacs, and whether or not it is
worthwhile...

I've used emacs for 15 years, and am still learning useful new tricks
at a rate of about one per 6 months.  But I've also found that the
essentials can be taught in a 2 hour session and mastered in about 2
weeks of use.  I've taught dozens of people using this Essential
Emacs approach.  

We find that emacs is for people who will be doing serious editing all
day long (e.g., programmers).  I like that comment from another
poster: Emacs is a good place to live, but I wouldn't want to visit
there.

For people who will just be editing an occassional file (and no python
code), we recommend notepad or nedit.

Now then, how do we use emacs?

1. Proper setup is essential.  Assuming you have python-mode.el and
.elc in emacs's program-modes dir, then your .emacs needs:

;---python---
(load python-mode)
(setq auto-mode-alist
  (cons '(\\.py$ . python-mode) auto-mode-alist))
(setq interpreter-mode-alist
  (cons '(python . python-mode)
interpreter-mode-alist))
(autoload 'python-mode python-mode Python editing mode. t)
(add-hook 'python-mode-hook 'turn-on-font-lock)
(setq python-mode-hook 'python-initialise)
(defun python-initialise ()
  (interactive)
  (setq default-tab-width 4)
  (setq indent-tabs-mode nil)
)


2. I almost never use the interactive prompt.  There are people here
who do, but as soon as the script is more than a couple lines long, it
takes longer to reenter the code (even copy-and-paste) than to
edit-save-run a dummy batch script.  When I'm doing Extreme
Programming with such people, I insist on using a stopwatch and
checking which approach is more efficient -- they usually come over to
my approach.

3. I run emacs with split windows:
a) Edit the working code
b) Edit the unittest code
c) Run a shell script, where I (re)run the go_test script by doing
alt-p ret

In another frame (same emacs process, different frame) I keep the
oracle (known good) and test outputs in split windows, and maybe do
ediff-buffers on them if the deltas are not obvious.   

For each module under consideration (view or edit), I use a separate
emacs process in a similar manner.  In normal work, that means 1-4
emacs processes running, each with its own shell and own test cycles.

4. Elsewhere I'm running emacs rmail all day, and run emacs gnus several
times a day (like now).

5. When I do Extreme Programming, the other author(s) tend to be using
emacs, vim, or nedit.  We don't let people use notepad for python
becuause it doesn't know proper formatting.  IDE's tend to want to own
the whole show, which makes cross-tool Extreme Programming a pain.

As long as the other programmers have set their editors for
auto-indention and tab-is-4-chars, then we get along fine.  [I do
notice a sizeable delay when vim people search for the appropriate
shell windows, instead of having them in a (joined-at-the-hip) split
window.  This has more to do with bookkeeping than with editors per
se, but it is a data point.]

6. On IDE's and code-completion: If you are going to be typing the
same thing over and over, why not use a function, or maybe code
generation?

-- 
[EMAIL PROTECTED]
6-6M21 BCA CompArch Design Engineering
Phone: (425) 294-4718
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: optparse and negative numbers as positional arguments

2005-04-06 Thread Grant Edwards
On 2005-04-06, Tomi Silander [EMAIL PROTECTED] wrote:
 Grant Edwards wrote:

 On 2005-04-05, Tomi Silander [EMAIL PROTECTED] wrote:

How is one supposed to give negative numbers as positional
arguments when using optparse?
 
   ./mitvit.py -- -1.1

 this works.

Yes, I know. :)

 I saw it in the source, but apparently did not properly pay
 attention; all the args after -- are considered positional
 if I read this right.

That's the way it's traditionally been done.  I just assumed
that optparse did it that way, and when I tried it with
optparse it seemed to work the same.  It's not mentioned in the
optparse documentation anywhere (it probably should be).

-- 
Grant Edwards   grante Yow!  .. are the STEWED
  at   PRUNES still in the HAIR
   visi.comDRYER?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Semi-newbie, rolling my own __deepcopy__

2005-04-06 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
Michael Spencer wrote:
[EMAIL PROTECTED] wrote:
[snip]
Anyway, my present problem is that I want to make copies of
instances
of my own custom classes.  I'm having a little trouble
understanding
the process.  Not that I think that it matters -- but in case it
does,
I'll tell you that I'm running Python 2.3.4 on a Win32 machine.
[snip]
If you google for:
 python __deepcopy__ cookbook
you will find a couple of examples of this method in use, among them:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/259179
1  class deque(object):
2
3  def __init__(self, iterable=()):
4  if not hasattr(self, 'data'):
5  self.left = self.right = 0
6  self.data = {}
7  self.extend(iterable)
[...snip methods...]
8def __deepcopy__(self, memo={}):
9from copy import deepcopy
10result = self.__class__()
11memo[id(self)] = result
12result.__init__(deepcopy(tuple(self), memo))
13return result
So, entering deepcopy, I encounter the first new concept (for me) on
line 10.  We obtain the class/type of self.  On line 11 we create a
dictionary item in memo, [id(self):type(self)].  So now I'm confused as
to the purpose of memo.  Why should it contain the ID of the *original*
object?
Note that you obtain *and then call* the class/type of self:
py i, s = 100, 'string'
py i.__class__, s.__class__
(type 'int', type 'str')
py i.__class__(), s.__class__()
(0, '')
So you've created a new object calling the constructor with no 
arguments.  So 'result' is a new instance of the class.

Things get even stranger for me on line 12.  Working from the inside of
the parentheses outward, an attempt is made to convert self to a tuple.
 Shouldn't this generate a TypeError when given a complex, non-iterable
item like the deque class?  I just tried running one of my programs,
which assigns the name x to one of my custom objects, and when I
execute tuple(x), a TypeError is what I get.
tuple(x) works on any object that defines __iter__:
py class C(object):
... def __iter__(self):
... yield 1
... yield 2
... yield 5
...
py tuple(C())
(1, 2, 5)
So line 12 is making a tuple of the values in the object, and then 
calling result's __init__ again, this time with (a deepcopied) tuple as 
an argument.  This adds the content to the previously uninitialized object.

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


Re: Resticted mode still active (error?)

2005-04-06 Thread Jeff Epler
Is there a script that causes this problem, without using mod_python or
jepp?  If so, please attach it to the sourceforge bug.
http://sourceforge.net/tracker/index.php?func=detailaid=1163563group_id=5470atid=105470


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

Re: formatting file

2005-04-06 Thread gry
SPJ wrote:
 I am new to python hence posing this question.
 I have a file with the following format:

 test11.1-1   installed
 test11.1-1   update
 test22.1-1   installed
 test22.1-2   update

 I want the file to be formatted in the following way:

 test11.1-1   1.1-2
 test22.1-1   2.1-2

For data that has a clear tree structure with keys, a quick solution
is often a dictionary, or dictionary of dictionaries.  The setdefault
idiom below is very handy for this sort of thing.  The test name
test1
is key to the top dict.  The operation update is the key to the sub
dictionary.  Setdefault returns the dict for the specified test, or a
new dict if there is none.

.d={}
.for line in open('tests.txt'):
.test,version,operation = l.split()
.d.setdefault(test,{})[operation] = version

.for test,d in d.items():
.print test, d['installed'], d['update']

[BWT, your given test data appears to have been
 wrong test11.1-1   update; please be careful not to waste
 people's time who try to help...]

-- George

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


Re: shebang in cross platform scripts

2005-04-06 Thread Ivan Van Laningham
Hi All--

Simon Brunning wrote:
 
 On Apr 6, 2005 2:37 PM, rbt [EMAIL PROTECTED] wrote:
 
  Does the line below have any negative impact on Windows machines? I
  develop and test mostly on Unix, but my scripts are often used on Win
  systems too.
 
  #!/usr/bin/env python
 
 Nope. On Windows it's just a comment.
 

It works fine using cygwin, uwin, mks and pdksh, all available for
Windows.  Google is your friend.

Symbolic links also work under uwin (don't know for sure about the
others).  That means you can install a link in /usr/bin to whereever
python lives, and expect #!/usr/bin/python to work just fine.

Metta,
Ivan
--
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: formatting file

2005-04-06 Thread Steven Bethard
SPJ wrote:
Hi,
I am new to python hence posing this question.
I have a file with the following format:
test11.1-1   installed
test11.1-1   update
test22.1-1   installed
test22.1-2   update
I want the file to be formatted in the following way:
test11.1-1   1.1-2
test22.1-1   2.1-2
How can I achieve this? I am stuck here.
py import itertools as it
py for line1, line2 in it.izip(f, f):
... line1, line2 = [line.split() for line in [line1, line2]]
... print '\t'.join(line1[:2] + line2[1:2])
...
test1   1.1-1   1.1-2
test2   2.1-1   2.1-2
where f is the file containing your data.  I assumed it looked like:
py import StringIO as strio
py f = strio.StringIO(\
... test11.1-1   installed
... test11.1-2   update
... test22.1-1   installed
... test22.1-2   update
... )
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: regexp weirdness (bug?)

2005-04-06 Thread Andr Malo
* Fredrik Lundh wrote:

 Sergey Schetinin wrote:
 
 it's line #159 here, but it did work! thanks. so it IS a bug?
 
 sure looks like one.  please report it here:
 
 http://sourceforge.net/tracker/?group_id=5470atid=105470

done :)

nd
-- 
Das Verhalten von Gates hatte mir bewiesen, dass ich auf ihn und seine
beiden Gefhrten nicht zu zhlen brauchte -- Karl May, Winnetou III

Im Westen was neues: http://pub.perlig.de/books.html#apache2
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best editor?

2005-04-06 Thread François Pinard
[Harry George]

 5. When I do Extreme Programming, the other author(s) tend to be using
 emacs, vim, or nedit. [...]

Speaking of, when everybody uses Emacs, there is a way for Emacs for
allowing many users, each on a different networked machine, all on the
very same buffer, simultaneously.  This sharing has been useful to us in
a number of occasions, and we had scripts for quickly initiating such
collaboration at any time (resolving `xauth' matters, for example).
Note that it requires a lot of confidence between the collaborating
users, as they all have extended powers on the editing session.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does IronPython indicate MS interest in dynamic languages?

2005-04-06 Thread Scott David Daniels
Bengt Richter wrote:
If there is to be an MSPython, how long 'til Mozilla FirePython? ;-)
Mexico has already designed the flag for that, I think.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda: the Ultimate Design Flaw

2005-04-06 Thread Scott David Daniels
Aahz wrote:
You just can't have your cake and eat it, too.
I've always wondered about this turn of phrase.  I seldom
eat a cake at one sitting.
-Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda: the Ultimate Design Flaw

2005-04-06 Thread Simon Brunning
On Apr 6, 2005 4:42 PM, Scott David Daniels [EMAIL PROTECTED] wrote:
 I've always wondered about this turn of phrase.  I seldom
 eat a cake at one sitting.

Clearly you're just not trying. ;-)

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


Re: Calling a Perl Module from Python

2005-04-06 Thread Swaroop C H
On Apr 6, 2005 8:23 AM, gf gf [EMAIL PROTECTED] wrote:
 I've recently made the switch.  Wow, is Python great!
 One thing which I haven't been able to do is replace
 Perl's great lib collection (HTML::Parser, for
 instance, can do a lot that Soup just can't).

You've just discovered the only limitation of Python (in my view) - it
doesn't have a module repository to rival CPAN.

AFAIK, there isn't any reliable way to call Perl modules from Python.


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


Re: Decorator Base Class: Needs improvement.

2005-04-06 Thread El Pitonero
Bengt Richter wrote:
 On 5 Apr 2005 19:28:55 -0700, El Pitonero [EMAIL PROTECTED]
wrote:

 Scott David Daniels wrote:
  Ron_Adam wrote:
   ...
 
   def tweakdoc(name):
   def decorator(function):
 function.__doc__ = 'Tweak(%s) %r' % (name, function.__doc__)
 return function
   return decorator
 
  What is confusing us about what you write is that you are
referring
 to
  tweakdoc as a decorator, when it is a function returning a
decorator.
 
 Decorator factory would be a shorter name for a function
returning a
 decorator.
 
 True, but tweakdoc doesn't have to be a function, so IMO we need a
better
 name for the @-line, unless you want to use many various specific
names
 like factory. E.g.,

There are two things:

(1) The tweadoc object in the example, which no doubt can be called a
decorator factory.

(2) The @-line, which you called a decorator expression and that's
fine with me. My preference would be something like the decorator
header. A more clear statement would be something like: a decorator
header expression or the expression in the decorator header, though
your proposed decorator expression would be clear enough, too.

I was addressing (1). You jumped in with (2), which I was aware of and
was not dissenting.

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


Re: Decorator Base Class: Needs improvement.

2005-04-06 Thread Scott David Daniels
Bengt Richter wrote:
@deco.one
 def foo(): pass
Ok, now what do you call this @-line? Freaky decorator factory invocation?
Decoratoriferous expression? ;-) 
This one has a certain je ne sais quoi ;-), but I'd call deco.one
the decorator function (since it _must_ evaluate to a function), and
if it needs more clarity, of your non-oderiferous proposals, I'd take:
Decorator expression for short? 
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: ignoring keywords on func. call

2005-04-06 Thread Peter Otten
Brano Zarnovican wrote:

 But it still doesn't guarantee that __getitem__ accepts keywords.
 (What if somebody will extend the Tree class and overlook the
 definition of __getitem__ and define a classic one)

I deem it more likely that that same somebody will not overlook it and dump
your Tree class altogether for not adhering to a sensible convention. Why
don't you just introduce a getitem_ex(self, key, all the options you like)
method and define __getitem__() in terms of that method? E. g.

def getitem_ex(self, key, some_option=None):
# ...

def __getitem__(self, key):
return self.getitem_ex(key, some_option=True)

Your docs could then recommend to override getitem_ex() instead of
__getitem__() and you and somebody would live happily ever after (*).

Peter

(*) or at least without calling each other names right from the start.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unittest vs py.test?

2005-04-06 Thread BJörn Lindqvist
py.test is awesome, but there is one slight flaw in it. It produces to
much output. All I want to see when all tests pass is All X passes
succeded! (or something similar). py.test's output can be
distracting.

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


Re: Calling a Perl Module from Python

2005-04-06 Thread jfj
Swaroop C H wrote:

AFAIK, there isn't any reliable way to call Perl modules from Python.

pyperl. pyperl. pyperl.
+10 on making this a standard module for embrace+extend reasons
*and* because perl is not that bad after all.
jf

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


Re: Best editor?

2005-04-06 Thread ChinStrap
Well I would be more than willing to learn Emacs if it does all these
things you speak of, but really I can't get started because the default
scheme is so friggin ugly it isn't funny.

Anyone want to send me a configuration setup with Python in mind, and
decent colors?

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


Re: HTML editor component?

2005-04-06 Thread Johan Lindberg
You could try the (very) simple HTML editor I use for my CM project. It
can only handle B, I, U and A, but then again, it was never meant to do
more. It's written in wxPython, based on Scintilla and can probably be
extended to fit your needs.

You can find it here:
http://sourceforge.net/project/showfiles.php?group_id=72786package_id=138707

BR
/Johan Lindberg

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


Re: Question about the Python Cookbook: How much of this is new?

2005-04-06 Thread Nick Vargish
Robert Kern [EMAIL PROTECTED] writes:

 So yeah, buy it.

Seconded. My copy arrived from ORA yesterday and I'm still giddy with
delight. Even if you have the first edition, the second includes a lot
of recipes that leverage or demonstrate the new features in 2.3 and
2.4. 

Nick 

-- 
# sigmask  (lambda deprecation version) 20041028 || feed this to a python
print ''.join([chr(ord(x)-1) for x in 'Ojdl!Wbshjti!=ojdlAwbshjti/psh?'])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Establishing connection SSH

2005-04-06 Thread Grig Gheorghiu
Try paramiko: http://www.lag.net/paramiko/

Grig

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


Re: unittest vs py.test?

2005-04-06 Thread Roy Smith
[EMAIL PROTECTED] wrote:
py.test is awesome, but there is one slight flaw in it. It produces to
much output. All I want to see when all tests pass is All X passes
succeded! (or something similar). py.test's output can be
distracting.

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


Re: boring the reader to death (wasRe: Lambda: the Ultimate Design Flaw

2005-04-06 Thread bruno modulix
Sunnan wrote:
Aahz wrote:
(snip)
print foo is, foo

Is the space added automatically? (Like awk does, if you add a comma.)
Yes. But you can also format it how you like:
  print foo is %s and that's a good news, my friends % foo
--
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for 
p in '[EMAIL PROTECTED]'.split('@')])
--
http://mail.python.org/mailman/listinfo/python-list


Using weakrefs instead of __del__

2005-04-06 Thread Rhamphoryncus
I know __del__ can't be relied on to do cleanup, so I'm thinking of
using a globally reachable weakref to do the job, like so:

import weakref

class Foo:
  def __init__(self, *args, **kwargs):
self.__realfoo = RealFoo(self, *args, **kwargs)
  def blah(self):
return self.__realfoo.blah()

class RealFoo:
  refs = set()
  def __init__(self, front):
self.refs.add(weakref.ref(front, self.cleanup))
  def blah(self):
print Blah!
  def cleanup(self, ref):
print Doing cleanup
self.refs.remove(ref)

Is there any reason why this wouldn't work?  Can it be used as a
general replacement for anything that needs __del__?  Even in Jython or
other alternative implementations?

Some issues I know about:
 * The weakref must be globally reachable (as I do with the above code)
to make sure it doesn't get deleted at the same time Foo does, because
python would not call the callback if that were the case.
 * I can't use any getattr tricks to wrap .blah() because Foo().blah()
would only use a  method bound to RealFoo, thus allowing Foo to be
deallocated and .cleanup() to be called before the method itself is.
Unfortunately my metaclass-fu is too weak to figure out something
without that problem.
 * I've no idea what will happen when the interpreter exits, but I
don't imagine it would matter much for most uses.

--
Adam Olsen, aka Rhamphoryncus

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


Re: shebang in cross platform scripts

2005-04-06 Thread Bill Mill
On Apr 6, 2005 11:06 AM, Ivan Van Laningham [EMAIL PROTECTED] wrote:
 Hi All--
 
 Simon Brunning wrote:
 
  On Apr 6, 2005 2:37 PM, rbt [EMAIL PROTECTED] wrote:
 
   Does the line below have any negative impact on Windows machines? I
   develop and test mostly on Unix, but my scripts are often used on Win
   systems too.
  
   #!/usr/bin/env python
 
  Nope. On Windows it's just a comment.
 
 
 It works fine using cygwin, uwin, mks and pdksh, all available for
 Windows.  Google is your friend.
 
 Symbolic links also work under uwin (don't know for sure about the
 others).  That means you can install a link in /usr/bin to whereever
 python lives, and expect #!/usr/bin/python to work just fine.

This works in cygwin as well; I didn't mention cygwin since the OP
seemed to be asking about windows distribution, but it's a good point.

Peace
Bill Mill
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with access to shared memory(W2K) / ORIGINALLY (win32) speedfan api control

2005-04-06 Thread Claudio Grondi
Background information:
-
in order to monitor mainboard sensory data
as fan speeds, temperatures, applications
like SpeedFan http://www.almico.com/speedfan.php
or MBM http://mbm.livewiredev.com/
can be used.
Both of the mentioned apps expose data got
from the hardware in a shared memory area.

The goal to achieve:
---
is to supervise the motherboard sensory
data from within a Python script

The approach:
---
access to the shared memory area
exposed by motherboard hardware
querying apps from Python script.

The problem:
-
the below listed script code returns
always same values, what
leads to the conclusion, that something
is going wrong.

Can anyone help?

Thanks in advance

Claudio

The code
-
  I use is provided also here:
 http://www.codecomments.com/Python/message430495.html
 http://mail.python.org/pipermail/python-list/2005-March/271853.html
(the mmap part of it doesn't work at all)

from ctypes import *

class Buffer(Structure):
  # just to see if any useful data can be acquired
  _fields_ = [
(Data0, c_longlong)
   ,(Data1, c_longlong)
   ,(Data2, c_longlong)
   ,(Data3, c_longlong)
   ,(Data4, c_longlong)
   ,(Data5, c_longlong)
   ,(Data6, c_longlong)
   ,(Data7, c_longlong)
   ,(Data8, c_longlong)
   ,(Data9, c_longlong)
   ,(DataA, c_longlong)
   ,(DataB, c_longlong)
   ,(DataC, c_longlong)
   ,(DataD, c_longlong)
   ,(DataE, c_longlong)
   ,(DataF, c_longlong)
  ]

szName = c_char_p(SFSharedMemory_ALM)  # SpeedFan
szName = c_char_p($M$B$M$5$S$D$)# MBM
# szName = c_char_p(blabla)  # not existing shared memory

FILE_MAP_ALL_ACCESS  = 0xF001F
FALSE = 0

hMapObject = windll.kernel32.OpenFileMappingA(
   FILE_MAP_ALL_ACCESS
  ,FALSE
  ,szName
)
if (hMapObject == 0):
  print Could not open file mapping object
  raise WinError()

pBuf = windll.kernel32.MapViewOfFile(
 hMapObject
,FILE_MAP_ALL_ACCESS
,0
,0
,0
)

  if (pBuf == 0):
print Could not map view of file
raise WinError()
  else:
print repr(pBuf)
print repr(hMapObject)

pBuf_str = cast(pBuf, c_char_p)
print repr(pBuf_str.value)
print repr(pBuf_str)

pBuf_buf = cast(pBuf, Buffer)
print
print
print repr(pBuf_buf)
print
print repr(pBuf_buf.Data0)
print repr(pBuf_buf.Data1)
print repr(pBuf_buf.Data2)
print repr(pBuf_buf.Data3)
print repr(pBuf_buf.Data4)
print repr(pBuf_buf.Data5)
print repr(pBuf_buf.Data6)
print repr(pBuf_buf.Data7)
print repr(pBuf_buf.Data8)
print repr(pBuf_buf.Data9)
print repr(pBuf_buf.DataA)
print repr(pBuf_buf.DataB)
print repr(pBuf_buf.DataC)
print repr(pBuf_buf.DataD)
print repr(pBuf_buf.DataE)
print repr(pBuf_buf.DataF)
  #:if/else (pBuf == 0)

windll.kernel32.UnmapViewOfFile(pBuf)
windll.kernel32.CloseHandle(hMapObject)

The output
--
is always the same:

13107200
80
''
c_char_p('')


__main__.Buffer object at 0x007E3570

13107200L
0L
0L
0L
0L
0L
0L
0L
0L
0L
0L
0L
0L
0L
0L
0L



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


richcmpfunc semantics

2005-04-06 Thread harold fellermann
Hi all,
I want to implement rich comparision in an extension class. Problem is 
I cannot
find good documentation of the richcmpfunc semantics. Given the 
signature

richcmpfunc compare(PyObject *,PyObject, int);
I supposed the two objects passed are the ones to be compared.
What is the meaning of the integer argument? Does it specify the kind
of comparision operator (e.g. __eq__ or __le__), and if so, how?
What is my richcmpfunc supposed to return? 0 or 1 indicating False or
True? What has to be done, if the function is invoked for an operator
I don't want to define?
Maybe there is some good documentation available, but I cannot find it.
So, any references or help is appreciated.
Cheers,
- harold -
--
Scientist are very good in answering the questions
they choose to answer.
-- Richard Alley
--
http://mail.python.org/mailman/listinfo/python-list


Re: (win32) speedfan api control

2005-04-06 Thread Claudio Grondi
I have got the specs for SpeedFan from
the SpeedFan author :-) ,
but ...
inbetween I found, that full specs of the
shared memory access to
fan speeds, board, CPU temperature data
are also exposed by the MBM application
  http://mbm.livewiredev.com
and already published online
(including C, VB, Delphi code examples).
but ...
I failed to get the data into
a Python script :-( .
For details see my other
Problem with access to shared memory(W2K) /
ORIGINALLY (win32) speedfan api control
posting.

Claudio


Almico [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 Claudio Grondi [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]...
  your script works ok on my W2K box :-).
 
  It makes me curious if I can get also the
  temperatures into Python script for
  further processing as easy as the setting
  of the checkbox is done? (I have not
  much experience with this kind of
  programming yet)
  May I ask how did you get the
  TJvXPCheckbox and the other
  values necessary to access the program
  GUI ? (as I can see, there is no source
  code of SpeedFan available) ?

 SpeedFan publishes a Shared Memory area. Drop SpeedFan's author (me
 :-)) an email to get its specs.


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


Re: formatting file

2005-04-06 Thread Peter Otten
SPJ wrote:

 test11.1-1   installed
 test11.1-1   update
 test22.1-1   installed
 test22.1-2   update
 
 I want the file to be formatted in the following way:
 
 test11.1-1   1.1-2
 test22.1-1   2.1-2

The following program expects a sorted input file:

import itertools
from operator import itemgetter

def pivot(infile, outfile, 
  getkey=itemgetter(0), getvalue=itemgetter(1), sep=\t):
if not hasattr(infile, read):
infile = file(infile)
if not hasattr(outfile, write):
outfile = file(outfile, w)

records = (line.split() for line in infile)
for key, items in itertools.groupby(records, getkey):
out_record = [key]
out_record.extend(getvalue(item) for item in items)
print  outfile, sep.join(out_record)

if __name__ == __main__:
import sys
infile, outfile = sys.argv[1:]
if infile == -: infile = sys.stdin
if outfile == -: outfile = sys.stdout
pivot(infile, outfile)

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


Re: Python Cookbook, 2'nd. Edition is published

2005-04-06 Thread Matteo Dell'Amico
Larry Bates wrote:
I received my copy on Friday (because I was a contributor).
I wanted to thank Alex, Anna, and David for taking the time to put
this together.  I think it is a GREAT resource, especially for
beginners.  This should be required reading for anyone that
is serous about learning Python.
+1.
The Python Cookbook is really great, and being included in the 
contributors, even if for a little tiny idea that got heavily 
refactored, feels wonderful. I'm really grateful to the python community.
--
Ciao,
Matteo
--
http://mail.python.org/mailman/listinfo/python-list


Re: Semi-newbie, rolling my own __deepcopy__

2005-04-06 Thread Michael Spencer
[EMAIL PROTECTED] wrote:
...
I see Steve Bethard has answered most of the points in your last eMail
On line 11 we create a
dictionary item in memo, [id(self):type(self)]...So now I'm confused as
to the purpose of memo.  Why should it contain the ID of the *original*
object?
No, you create memo[id(self):type(self)()] i.e., a mapping of the old object to 
a new object of the same type.  This new object does not yet contain the data of 
the old one, because you called its __init__ method with no arguments.

BTW, as I mentioned in a previous comment, I believe this would be more plainly 
written as type(self).__new__(), to emphasize that you are constructing the 
object without initializing it.  (There is a explanation of __new__'s behaviour 
at http://www.python.org/2.2/descrintro.html#__new__).  This works only for 
new-style classes (also explained in the same reference).  For old-style 
'classic' classes you would use new types.InstanceType

...
Is there another section of the Python docs that will clarify all this
for me?  I got hung up on all the static, public, etc. declarations
in Java early on.  Python has taken me an awful lot farther, but
perhaps I'm hitting the conceptual wall again.
I assume you have seen http://docs.python.org/lib/module-copy.html which 
explains this topic and, in particular, why the memo dict is passed around.

Hang in there.  It's not an easy topic, and this example contains several 
subtleties as you have discovered.

If you want further help, why not post the actual class you are working with, 
and your __deepcopy__ attempt.  It would be much easier to react to something 
concrete than a general howto.

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


Re: A ClientForm Question

2005-04-06 Thread John J. Lee
narke [EMAIL PROTECTED] writes:

 John J. Lee wrote,
 
  See second bullet point under Why does .click()ing on a button not
 work for me?.
 
 Thanks for you advice. However, after read through the FAQs, I have not
 managed to find a solution for my problem.  I belive my button is
 coupled with some Java script which mess thing up and there is no a
 easy solution.  Am I right?

Yes.


John

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


Re: how to parse system functions output

2005-04-06 Thread [EMAIL PROTECTED]
Or if you run 2.4 you can use subprocess

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


Re: Harvestman install not working

2005-04-06 Thread Anand
Hi

Latest version of py2exe does not support the option
--force-imports anymore I think. You can edit the .bat file to remove
that option. It should work.

-Anand

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


Re: Problem with access to shared memory(W2K) / ORIGINALLY (win32) speedfan api control

2005-04-06 Thread Thomas Heller
Claudio Grondi [EMAIL PROTECTED] writes:

 Background information:
 -
 in order to monitor mainboard sensory data
 as fan speeds, temperatures, applications
 like SpeedFan http://www.almico.com/speedfan.php
 or MBM http://mbm.livewiredev.com/
 can be used.
 Both of the mentioned apps expose data got
 from the hardware in a shared memory area.

 The goal to achieve:
 ---
 is to supervise the motherboard sensory
 data from within a Python script

 The approach:
 ---
 access to the shared memory area
 exposed by motherboard hardware
 querying apps from Python script.

For the mistake you made see below, hope that helps.

For the general way to solve this problem you should know that you can
access a shared memory area with a certain name also with Python's mmap
module, although that is probably not documented very good.  There was a
recipe posted a few days ago which showed different ways to acces shared
memory, with or without ctypes.

 The problem:
 -
 the below listed script code returns
 always same values, what
 leads to the conclusion, that something
 is going wrong.

 Can anyone help?

 Thanks in advance

 Claudio

 The code
 -
   I use is provided also here:
  http://www.codecomments.com/Python/message430495.html
  http://mail.python.org/pipermail/python-list/2005-March/271853.html
 (the mmap part of it doesn't work at all)

 from ctypes import *

 class Buffer(Structure):
   # just to see if any useful data can be acquired
   _fields_ = [
 (Data0, c_longlong)
,(Data1, c_longlong)
,(Data2, c_longlong)
,(Data3, c_longlong)
,(Data4, c_longlong)
,(Data5, c_longlong)
,(Data6, c_longlong)
,(Data7, c_longlong)
,(Data8, c_longlong)
,(Data9, c_longlong)
,(DataA, c_longlong)
,(DataB, c_longlong)
,(DataC, c_longlong)
,(DataD, c_longlong)
,(DataE, c_longlong)
,(DataF, c_longlong)
   ]

 szName = c_char_p(SFSharedMemory_ALM)  # SpeedFan
 szName = c_char_p($M$B$M$5$S$D$)# MBM
 # szName = c_char_p(blabla)  # not existing shared memory

 FILE_MAP_ALL_ACCESS  = 0xF001F
 FALSE = 0

 hMapObject = windll.kernel32.OpenFileMappingA(
FILE_MAP_ALL_ACCESS
   ,FALSE
   ,szName
 )
 if (hMapObject == 0):
   print Could not open file mapping object
   raise WinError()

 pBuf = windll.kernel32.MapViewOfFile(
  hMapObject
 ,FILE_MAP_ALL_ACCESS
 ,0
 ,0
 ,0
 )

   if (pBuf == 0):
 print Could not map view of file
 raise WinError()
   else:
 print repr(pBuf)
 print repr(hMapObject)

 pBuf_str = cast(pBuf, c_char_p)
 print repr(pBuf_str.value)
 print repr(pBuf_str)

 pBuf_buf = cast(pBuf, Buffer)
Here's the problem.  pBuf is a pointer to a Buffer structure, not the
buffer structure itself.
Something like
pBuf_buf = Buffer.from_address(pBuf)
may work.

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


Re: Semi-newbie, rolling my own __deepcopy__

2005-04-06 Thread Steven Bethard
Michael Spencer wrote:
BTW, as I mentioned in a previous comment, I believe this would be more 
plainly written as type(self).__new__(), to emphasize that you are 
constructing the object without initializing it.  (There is a 
explanation of __new__'s behaviour at 
http://www.python.org/2.2/descrintro.html#__new__).
There is also now documentation in the standard location:
http://docs.python.org/ref/customization.html
And just to clarify Michael's point here, writing this as __new__ means 
that __init__ is not called twice:

py class C(object):
... def __new__(cls):
... print '__new__'
... return super(C, cls).__new__(cls)
... def __init__(self):
... print '__init__'
...
py c = C()
__new__
__init__
py c2 = type(c)(); c2.__init__()
__new__
__init__
__init__
py c3 = type(c).__new__(C); c3.__init__()
__new__
__init__
But definitely check the docs for more information on __new__.  Some of 
the interworkings are kind of subtle.

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


Compiling extensions

2005-04-06 Thread ake
I would like to compile extensions usig distutils. is there a way to
set which compiler to use ?

I am using windows and VC++ 7.1 comp.

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


Re: Lambda: the Ultimate Design Flaw

2005-04-06 Thread John J. Lee
Simon Brunning [EMAIL PROTECTED] writes:

 On Apr 6, 2005 4:42 PM, Scott David Daniels [EMAIL PROTECTED] wrote:
  I've always wondered about this turn of phrase.  I seldom
  eat a cake at one sitting.
 
 Clearly you're just not trying. ;-)

:-)))


John

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


Re: Decorator Base Class: Needs improvement.

2005-04-06 Thread Ron_Adam
On Wed, 06 Apr 2005 08:10:22 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:

I don't understand your seeming fixation with wrappers and wrapping.

Fixated implies, I'm stuck on a single thing, but I'm not. I am
learning as I go, and exploring some possibilities as well.  :-)

 That's not
the only use for decorators. See Raymond Hettinger's optimizing decorators
in the cookbook for instance. 

Thanks, I'll look for it.  Is it in the new edition?  I haven't picked
it up yet.

Decorators are something like metaclasses for functions,
with much more general possibilities than wrapping, IMO.

I'm not sure I see the metaclass relation.  What more general things
can be done with Decorators, that can't be done with a wrapper?

Wrapping, and the @decorator expressions, interest me because I see a
lot of potential in it's use, and so I'm trying to learn them, and at
the same time, there are things about the @ expression that seems (to
me), that it's not the most practical way to do what it was intended
for.  

On the plus side, it's kind of cute with the little curly thing
propped up on top of the function. It's a neat trick that it does what
it does with a minimal amount of changes to the language by taking
advantage of pythons existing function perimeter and object passing
properties. It saves a bit of typing because we don't have to retype
the function name a few times.  (Several people have referred to it as
'sugar', and now I am starting to agree with that opinion.)

On the minus side, it's not intuitive to use.  It is attached to the
function definitions so they are limited, they can't be easily
unwrapped and rewrapped without redefining the function also.  The
recursive nature of stacked @ statements is not visible.

So my opinion of @ as a whole is currently: -1


I think you'll have to show some convincing use cases showing a clear
advantage over current decoration coding if you want converts ;-)

What about the following?  :-)

# Using this simple wrapper class:
class wrapper(object):
def __call__(self,x):
   # preprocess x
   x*=2 # Make a change so we can see it
   result = self.function(x)
   # postprocuess result
   return result

# A function to apply the wrapper:
def wrap(function,wrapper):
w = wrapper()
w.function = function
return w

# The function
def fn(x):
return x

print fn(5) # Before

# Wrapit.
fn = wrap(fn,wrapper)

print fn(5) # After

# Unwrap it.
fn = fn.function

print fn(5) # And back again

#prints
#5
#10
#5

It has several advantages over @ expression.  It doesn't need the
triple nested defines to get the function name and argument list, the
wrapper is simpler, It can be placed on a function and then removed,
when and where it's needed, instead of at the point where the function
is defined.

The following behaves more closely to the existing @ expression in
that it has the same nesting behavior for stacked wrappers.  

I'm looking into a way to do sequential non-nested stacked wrappers at
this point, where the output of one goes to the input of the next.
That can't be done currently with the @ decorator expression.

This stacks a list of 10 wrappers on 10 different functions and
reverses the order of the stack every other function. In this case
they are all the same, but they could all be differnt. 

Cheers,
Ron

#---start---
class wrapper(object):
def __call__(self,*x):
# preprocess
x = [x[0]+1,] 
print 'preprocess', x[0], self.args
# call function
result = self.function(*x)
# postprocess
result +=1
print 'postprocess', result, self.args
return result

def wrap(f,w,shape='forward'):
if shape=='reverse':
w.reverse()
for ww in w:
nw = wrapper()
try:
nw.args = ww[1]
except TypeError:
wf = ww[0]
nw.function = f
f = nw
return f

# Make a list of ten wrappers with an id number as an additional
# wrapper perimeter.
w = []
for n in xrange(10):
w.append((wrapper,n))

# Wrap 10 functions, 10 times, in reversing order.
def func0(x): return x
def func1(x): return x
def func2(x): return x
def func3(x): return x
def func4(x): return x
def func5(x): return x
def func6(x): return x
def func7(x): return x
def func8(x): return x
def func9(x): return x

func0 = wrap(func0,w)
func1 = wrap(func1,w,'reverse')
func2 = wrap(func2,w)
func3 = wrap(func3,w,'reverse')
func4 = wrap(func4,w)
func5 = wrap(func5,w,'reverse')
func6 = wrap(func6,w)
func7 = wrap(func7,w,'reverse')
func8 = wrap(func8,w)
func9 = wrap(func9,w,'reverse')

print func0(0)
print func1(0)
print func2(0)
print func3(0)
print func4(0)
print func5(0)
print func6(0)
print func7(0)
print func8(0)
print func9(0)

#--end--



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


Re: Best editor?

2005-04-06 Thread John J. Lee
François Pinard [EMAIL PROTECTED] writes:
[...]
 Overall, Vim is also cleaner than Emacs, and this pleases me.
[...]

Is this still true when comparing XEmacs vs. vim? (rather than GNU
Emacs vs. vim)  I've always used GNU Emacs, but I have got the
impression that XEmacs is (was?) cleaner in some ways.


John

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


Re: Calling a Perl Module from Python ( future direction of Python)

2005-04-06 Thread gf gf
Really!  That's a pity... Instead of trying to
recreate a repository the size of CPAN, a Python
interface to Perl modules is really called for.

Instead of fretting over decorator syntax and
lispiness, might I suggest that development efforts be
directed to this?  Developers, are you listening? 
Guido?

PS And I don't mean waiting for Perl 6 to condense...

--- Swaroop C H [EMAIL PROTECTED] wrote:

 On Apr 6, 2005 8:23 AM, gf gf
 [EMAIL PROTECTED] wrote:
  I've recently made the switch.  Wow, is Python
 great!
  One thing which I haven't been able to do is
 replace
  Perl's great lib collection (HTML::Parser, for
  instance, can do a lot that Soup just can't).
 
 You've just discovered the only limitation of Python
 (in my view) - it
 doesn't have a module repository to rival CPAN.
 
 AFAIK, there isn't any reliable way to call Perl
 modules from Python.
 
 
 -- 
 Swaroop C H
 Blog: http://www.swaroopch.info
 Book: http://www.byteofpython.info
 




__ 
Yahoo! Messenger 
Show us what our next emoticon should look like. Join the fun. 
http://www.advision.webevents.yahoo.com/emoticontest
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best editor?

2005-04-06 Thread John J. Lee
ChinStrap [EMAIL PROTECTED] writes:

 When not using the interactive prompt, what are you using? I keep
 hearing everyone say Emacs, but I can't understand it at all. I keep
 trying to learn and understand why so many seem to like it because I
 can't understand customization even without going through a hundred
 menus that might contain the thing I am looking for (or I could go
 learn another language just to customize!).
[...]
 Opinions on what the best is? Or reading I could get to maybe sway me
 to Emacs (which has the major advantage of being on everyone's system).

Two reasons I use emacs:

1. For any question Can I do X with emacs, the answer is almost
   always yes, use this code that's already written and working

2. I already know it ;-)

BTW, I use vi keybindings, and I imagine all other editors can do the
same (though perhaps not as well as viper, the emacs package that does
this -- see 1. above), so that's no reason in itself to use vim.


John

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


Re: Installing Python 2.4 on Linux

2005-04-06 Thread David Fraser
Edward Diener wrote:
I can install Python 2.4 on the Fedora 3 Linux system, but after I do a 
number of Linux utilities and commands, like yum, stop working because 
they were dependent on the Python 2.3 installation. What happens is that 
Python 2.4 replaces the /usr/bin/python module with the Python 2.4 
version. If I replace /usr/bin/python with the Python 2.3 version 
executable, which is still on my system, that all the aforesaid modules 
depend on, they start working again, but I can no longer execute 
modules, like IDLE, which was part of my Python 2.4 distribution.

What is the solution to this ? The operating system was installed with 
Python 2.3 and the development libraries but no tools, doc, or 
otherwise. I have installed Python 2.4 with all the RPMs and copied down 
the Python 2.4 documentation to my machine ( since python24-docs.rpm 
gives one very little ). I would naturally like to use Python 2.4 
without killing all the commands that depend on Python 2.3. No doubt 
these commands have their modules in the site libraries for Python 2.3. 
Of course I would love to update these dependencies to use Python 2.4 
but newer RPMs for these commands do not exist.

I do not know whether this is a Python problem or a Fedora 3 problem but 
I thought I would ask here first and see if anybody else had the same 
problem. I imagine the problem might exist on other Linux systems.
Actually the Fedora RPMS supplied on the Python website are fine:
http://www.python.org/2.4.1/rpms.html
Quoting from that page:
# Q) Is it safe to install these RPMs on a Red Hat system? Will they over-write 
the system python and cause problems with other Red Hat applications that 
expect a different version of Python?
# A) The RPMs that start with python2.4 are built to not interfere with the system 
Python. They install as /usr/bin/python2.4 and will not conflict with the system Python 
unless you are running on a system that ships the a version of Python which has the same 
major/minor number.
To invoke the interpreter with these packages, you will explicitly have to run python2.4. Note 
that all Python RPMs provided by Python.org and Red Hat provide a /usr/bin/python2.4 (or similar, 
with major/minor number), even if they also provide /usr/bin/python. So, yes, it should be safe.
Note that you may need to build and install a second copy of any packages which you need access to with the supplemental version of Python. You can build packages of these files for the Python 2.4 interpreters for packages which use Distutils, by using the command python2.4 setup.py bdist_rpm. 
This is by far the preferred way to install a different version of 
Python to the default version provided with a distribution, as you don't 
then conflict with packages that require the default version.

Also, it is better to do it like this using real packages than to rename 
files manually. I have used the above successfully on Fedora Core 3 (and 
other similar versions on other distro versions), if it doesn't work for 
you there is a source RPM available to rebuild from

Hope that helps
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best editor?

2005-04-06 Thread John J. Lee
Ville Vainio [EMAIL PROTECTED] writes:

  Miki == Miki Tebeka [EMAIL PROTECTED] writes:
 
 Miki Emacs (or VIm in my case) takes time to learn. However when
 Miki you start to understand it and know you way around it'll do
 Miki things no other editor will do for you.
 
 Other editors also do stuff Emacs won't do. Code completion is a
 killer feature and emacs sucks at it (yes, w/ Cedet too).
[...]

I thought that too, but then I bound dabbrev-expand to F4, and it
seems even better than 'proper' completion (for reducing keystrokes,
anyway).


John

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


number conversion

2005-04-06 Thread nicksjacobson
I'm writing a program to read in raw data from a WAV file, and write it
to an IT file.  I got this to work in C by reading the data into an
array of unsigned chars called RawDataAry, then converted it to
signed chars by doing the following:

signed char *CharAry = malloc(sizeof(signed char) * frames);
for (i = 0; i  input_frames; i++)
CharAry[i] = (signed char)(((signed short)WavDataAry[i]) - 128);

It worked.


But when I tried to do this kind of conversion in Python, I got an
OverflowError exception.

First I read the data into an array of unsigned chars:

fmt = str(chunklen) + 'B'
fmtsize = struct.calcsize(fmt)
rawdata = struct.unpack(fmt, s[:fmtsize])
rawdata = list(rawdata)

Then I tried to convert it:

charary = array.array('b')
charary.fromlist(rawdata)

This last line threw the OverflowError exception, OverflowError:
signed char is greater than maximum.

Is there a way to do this??  Thanks a lot in advance!!

--Nick

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


Re: Decorator Base Class: Needs improvement.

2005-04-06 Thread Steve Holden
Ron_Adam wrote:
On Wed, 06 Apr 2005 08:10:22 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:

I don't understand your seeming fixation with wrappers and wrapping.

Fixated implies, I'm stuck on a single thing, but I'm not. I am
learning as I go, and exploring some possibilities as well.  :-)

That's not
the only use for decorators. See Raymond Hettinger's optimizing decorators
in the cookbook for instance. 

Thanks, I'll look for it.  Is it in the new edition?  I haven't picked
it up yet.

Decorators are something like metaclasses for functions,
with much more general possibilities than wrapping, IMO.

I'm not sure I see the metaclass relation.  What more general things
can be done with Decorators, that can't be done with a wrapper?
Wrapping, and the @decorator expressions, interest me because I see a
lot of potential in it's use, and so I'm trying to learn them, and at
the same time, there are things about the @ expression that seems (to
me), that it's not the most practical way to do what it was intended
for.  

On the plus side, it's kind of cute with the little curly thing
propped up on top of the function. It's a neat trick that it does what
it does with a minimal amount of changes to the language by taking
advantage of pythons existing function perimeter and object passing
properties. It saves a bit of typing because we don't have to retype
the function name a few times.  (Several people have referred to it as
'sugar', and now I am starting to agree with that opinion.)
On the minus side, it's not intuitive to use.  It is attached to the
function definitions so they are limited, they can't be easily
unwrapped and rewrapped without redefining the function also.  The
recursive nature of stacked @ statements is not visible.
So my opinion of @ as a whole is currently: -1

I think you'll have to show some convincing use cases showing a clear
advantage over current decoration coding if you want converts ;-)

What about the following?  :-)
# Using this simple wrapper class:
class wrapper(object):
def __call__(self,x):
   # preprocess x
   x*=2 # Make a change so we can see it
   result = self.function(x)
   # postprocuess result
   return result
# A function to apply the wrapper:
def wrap(function,wrapper):
w = wrapper()
w.function = function
return w
# The function
def fn(x):
return x
print fn(5) # Before
# Wrapit.
fn = wrap(fn,wrapper)
print fn(5) # After
# Unwrap it.
fn = fn.function
print fn(5) # And back again
#prints
#5
#10
#5
It has several advantages over @ expression.  It doesn't need the
triple nested defines to get the function name and argument list, the
wrapper is simpler, It can be placed on a function and then removed,
when and where it's needed, instead of at the point where the function
is defined.
The following behaves more closely to the existing @ expression in
that it has the same nesting behavior for stacked wrappers.  

I'm looking into a way to do sequential non-nested stacked wrappers at
this point, where the output of one goes to the input of the next.
That can't be done currently with the @ decorator expression.
This stacks a list of 10 wrappers on 10 different functions and
reverses the order of the stack every other function. In this case
they are all the same, but they could all be differnt. 

Cheers,
Ron
#---start---
class wrapper(object):
def __call__(self,*x):
# preprocess
x = [x[0]+1,] 
print 'preprocess', x[0], self.args
# call function
result = self.function(*x)
# postprocess
result +=1
print 'postprocess', result, self.args
return result

def wrap(f,w,shape='forward'):
if shape=='reverse':
w.reverse()
for ww in w:
nw = wrapper()
try:
nw.args = ww[1]
except TypeError:
wf = ww[0]
nw.function = f
f = nw
return f
# Make a list of ten wrappers with an id number as an additional
# wrapper perimeter.
w = []
for n in xrange(10):
w.append((wrapper,n))

# Wrap 10 functions, 10 times, in reversing order.
def func0(x): return x
def func1(x): return x
def func2(x): return x
def func3(x): return x
def func4(x): return x
def func5(x): return x
def func6(x): return x
def func7(x): return x
def func8(x): return x
def func9(x): return x

func0 = wrap(func0,w)
func1 = wrap(func1,w,'reverse')
func2 = wrap(func2,w)
func3 = wrap(func3,w,'reverse')
func4 = wrap(func4,w)
func5 = wrap(func5,w,'reverse')
func6 = wrap(func6,w)
func7 = wrap(func7,w,'reverse')
func8 = wrap(func8,w)
func9 = wrap(func9,w,'reverse')
print func0(0)
print func1(0)
print func2(0)
print func3(0)
print func4(0)
print func5(0)
print func6(0)
print func7(0)
print func8(0)
print func9(0)
#--end--

I find I am still left asking the question why would anyone want to do 
that?.

The difference between a use case and an example is that a use case 
should demonstrate the solution of 

Re: Calling a Perl Module from Python ( future direction of Python)

2005-04-06 Thread Jeff Reavis
An interface to Perl already exists:

http://www.python.org/moin/PyPerl

-jjr

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


Python sleep doesn't work right in a loop?

2005-04-06 Thread ritterhaus
Just a simple bit of code to toggle between two state at intervals...

import time
for i in range(4):
print 'On'
time.sleep(1)
print 'Off'
time.sleep(1)

... SHOULD toggle On and Off four times with one-second pauses. When I
run this, the loop pauses the full eight seconds then prints the Ons
and Offs all at once. What's up with that?

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


Re: Python sleep doesn't work right in a loop?

2005-04-06 Thread [EMAIL PROTECTED]
For me it works fine. It seems that for you stdout is not flushed
correctly in your terminal. What kind of terminal are you writing to?

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


  1   2   >