PyDev 0.9.8.4 released

2005-11-04 Thread Fabio Zadrozny
Hi All,

PyDev - Python IDE (Python Development Enviroment for Eclipse) version 
0.9.8.4 has been released.

Check the homepage (http://pydev.sourceforge.net/) for more details.

Details for Release: 0.9.8.4


Major highlights:


* The license was changed to EPL. It can be found at: 
http://www.opensource.org/licenses/eclipse-1.0.php
* Code-completion information is now saved in deltas instead of 
saving only at shutdown (being so, it does not loose information if it 
does not have a regular shut-down).



Others that are new and noteworthy:
-

* Added option for not using the smart-indent after opening brackets
* Some step-by-step instructions of how to get started with pydev 
have been contributed by Jack Trainor.
* Many bugfixes


Cheers,

Fabio

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
www.esss.com.br

PyDev - Python Development Enviroment for Eclipse
pydev.sf.net
pydev.blogspot.com



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

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Steve Holden schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
 Op 2005-11-03, Stefan Arentz schreef [EMAIL PROTECTED]:
 [...]
It is all according to how things have been in Python for a long time.
 
 Unsane behaviour for a long time is still unsane behaviour.
 
 As your continued contributions on this newsgroup so adequately 
 demonstrate :-).

 Sorry, I *couldn't* resist. You asked for it. It was hanging there (in a 
 containing namespace?) waiting to be posted. If I hadn't said it someone 
 else would have. And other justifications for what I hope doesn't seem 
 like too unpleasant a personal attack.

Well I would argue that a lot of the defenders of python are not
reacting very sane. My impression is that a lot of them react like
zealots, blindly devoted to the language, rather intollerant of
every criticism and prepared to defend anything as long as it happens
to be a current characteristic of the language and where any such
criticism sooner or later is met with something like: If you don't
like it, use a different language, as if only those who are 100%
perfectly happy with the language as it is, should use it.

The real issue here is that you should propery name class variables so
that there can't be any confusion about class or instance scope. I use
all uppercase identifiers for class variables for example.
 
 
 The fact that this can be regarded as unwise coding, doesn't imply
 it is sane behaviour of python. Variable shadowing happens. I don't
 consider it sane behaviour if the same reference in a line gets
 resolved in different name spaces
 
 Well I'm sure Guido will be happy to know you think his design is 
 insane. Now who's calling who names?

I'm not calling anyone names. I'm just pointing to one specific
behaviour in python and call that behaviour unsane. If you want
to interpret that as me calling his (entire) design insane, I
suggest you are two defensive with regards to python.

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-03, Steven D'Aprano schreef [EMAIL PROTECTED]:
 On Thu, 03 Nov 2005 04:30:09 -0800, Paul Rubin wrote:

 Steve Holden [EMAIL PROTECTED] writes:
  class A:
a = 1
  b = A()
  b.a += 2
  print b.a
  print A.a
  Which results in
  3
  1
 
 I don't suppose you'd care to enlighten us on what you'd regard as the
 superior outcome?
 
 class A:
   a = []
 b = A()
 b.append(3)
 print b.a
 print a.a
 
 Compare and contrast.


 I take it then that you believe that ints like 1 should be mutable like
 lists? Because that is what the suggested behaviour implies.

No it isn't.

One other way, to implement the += and likewise operators would be
something like the following.

Assume a getnsattr, which would work like getattr, but would also
return the namespace where the name was found. The implementation
of b.a += 2 could then be something like:

  ns, t = getnsattr(b, 'a')
  t = t + 2
  setattr(ns, 'a')


I'm not arguing that this is how it should be implemented. Just
showing the implication doesn't follow.

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-03, Steven D'Aprano schreef [EMAIL PROTECTED]:
 On Thu, 03 Nov 2005 12:53:37 +, Antoon Pardon wrote:

 I don't suppose you'd care to enlighten us on what you'd regard as the 
 superior outcome?
 
 No. I don't think a superior outcome is necessary to see that this is
 not sane behaviour. I don't care that much on how it gets fixed.

 It isn't broken, there is nothing to fix. The code does precisely what the
 inheritance model promises to do.

That is not a contra argument. Delivering what is promissed says nothing
about the sanity of what is promissed. It is even possible that a number
of things that are sane in itself, produce something unsane when
combined or in certain circumstances.

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Stefan Arentz
Antoon Pardon [EMAIL PROTECTED] writes:

...

  Ah yes. Well, good luck with that. You seem to have decided that it is not
  sane and who am I to argue with that. It depends on your state of mind :-)
 
 I can just say the opposite, that you seem to have decided that it is
 sane.

I have. I like the Python model.

  The model makes sense in my opinion. If you don't like it then there are
  plenty of other languages to choose from that have decided to implement
  things differently.
 
 And again this argument. Like it or leave it, as if one can't in general
 like the language, without being blind for a number of shortcomings.

Personally I don't see it as a shortcoming.

 It is this kind of recations that make me think a number of people is
 blindly devoted to the language to the point that any criticism of
 the language becomes intollerable.

No not at all. Just look at all the PEPs and the changes in the language
that have been made in the past. Python is very much community driven and
that shows in it's progress.

You on the other hand keep talking about emo things like 'sane' and
'madness' without giving any technical backing about these problems
that you are having with the language.

Snap out of that, make it a real discussion and maybe something good
will happen. Or not :-)

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


Re: Web automation with twill

2005-11-04 Thread Michele Simionato
BTW, O'Reilly just published an article of mines on twill:

http://www.onlamp.com/pub/a/python/2005/11/03/twill.html

Michele Simionato

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-03, Magnus Lycka schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
 There is no instance variable at that point. How can it add 2, to
 something that doesn't exist at the moment.

 Because 'a += 1' is only a shorthand for 'a = a + 1' if a is an
 immutable object? Anyway, the behaviour is well documented.

 http://docs.python.org/ref/augassign.html says:

 An augmented assignment expression like x += 1 can be rewritten as x = x 
 + 1 to achieve a similar, but not exactly equal effect. In the augmented 
 version, x is only evaluated once.

Then couldn't we expect that the namespace resolution is also done
only once?

I say that if the introduction on += like operators implied that the
same mentioning of a name would in some circumstances be resolved to
two different namespaces, then such an introduction would better have
not occured.

Would it be too much to ask that in a line like.

  x = x + 1.

both x's would resolve to the same namespace?

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-03, Magnus Lycka schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
 Op 2005-11-03, Steven D'Aprano schreef [EMAIL PROTECTED]:
 
 
There are two possible fixes, either by prohibiting instance variables
with the same name as class variables, which would allow any reference
to an instance of the class assign/read the value of the variable. Or
to only allow class variables to be accessed via the class name itself.

There is also a third fix: understand Python's OO model, especially
inheritance, so that normal behaviour no longer surprises you.
 
 
 No matter wat the OO model is, I don't think the following code
 exhibits sane behaviour:
 
 class A:
   a = 1
 
 b = A()
 b.a += 2
 print b.a
 print A.a
 
 Which results in
 
 3
 1

 On the other hand:

  class C:
 ... a = [1]
 ...
  b=C()
  b.a += [2]
  b.a
 [1, 2]
  C.a
 [1, 2]

 I can understand that Guido was a bit reluctant to introduce
 += etc into Python, and it's important to understand that they
 typically behave differently for immutable and mutable objects.

All fine by me. I won't be using python any less because of this,
because I use class variable very little and you can avoid this
problem by avoiding instance that shadow class variables and
always refer to class variables by class name.

But that doesn't mean we should consider this kind of behaviour
as it should be, just because it is in python.

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


Re: Cheapest pocket device to code python on

2005-11-04 Thread Sybren Stuvel
Devan L enlightened us with:
 I would not recommend trying to code on a handheld device. Small
 screen size and [usually] small keyboards make it
 less-than-practical. Stick with a laptop, or write it in a notebook,
 if you must.

Although it isn't the pinnacle of usability, I can program just fine
on my Sharp Zaurus C3000.

Having said that, a real PC is a lot nicer to work on. But then, if
you want to have a really portable programming thiny, the Zaurus is
great.

Not too cheap though.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


[no subject]

2005-11-04 Thread Terry Hancock
On Thursday 03 November 2005 07:28 am, venk wrote:
 Microsoft can create a competing version of Windows. TCP/IP became a
 standard long before Microsoft even acknowledged it's existence. So did
 ASCII, the IBM BIOS, and serial ports, to name just a few. Does the
 term
 ISO standard mean anything to you?
Regrettably, the assumption that ISO Standard = Open Standard seems
not to hold. I have found a number of ISO standards that are not
meaningfully open. I am still a little confused about why anyone
would do that.
Regarding whether Microsoft has committed a crime, I believe Tim Daneliuk
was attempting to draw the distinction between criminal and civil
offenses, and indeed, I do believe Microsoft has only ever been
indicted with the latter.  This is a pretty big distinction in the
US, I don't know how other countries characterize offenses.
For example, one of the big points about so-called software piracy
is that the recording and movie industry has been trying very hard
to conflate copyright violation with theft -- but the former is
only a civil offense, and the latter criminal. Big difference.
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com
-- 
http://mail.python.org/mailman/listinfo/python-list


[no subject]

2005-11-04 Thread Terry Hancock
On Thursday 03 November 2005 04:29 pm, Steven D'Aprano wrote:
 On Thu, 03 Nov 2005 14:56:44 -0500, Tim Daneliuk wrote:
 
  There is a difference between what is *illegal* and what constitutes
  a *crime*.
 
 Why thank you, you've really made my day. That's the funniest thing I've
 heard in months. Please, do tell, which brand of corn flakes was it that
 you got your law degree from?
No, he's absolutely right there. At least in the US legal system. A
civil violation is not a crime, only a criminal violation.
We have two major systems of law, criminal law and civil law.
Most of the crimes that Microsoft has been accused of are actually
civil law violations and are therefore not properly called crimes.
Generally, infringements on copyrights, contract violations, and
a wide variety of so-called white collar offenses are really
civil violations, and therefore not properly called crimes.
So, for example, illegally downloading a copyrighted movie from
the internet and giving it to your friends is a civil offense,
copyright infringement and NOT crime of piracy, despite
enormous propaganda budgets from the movie industry trying to
convince you otherwise.
This has nothing to do with exonerating Microsoft, though. It's
just splitting hairs.  And Microsoft itself has gotten on
the copyright infringement=piracy bandwagon, so if they are
called criminals by the conflation of the two concepts, then
they are merely being hoisted by their own petard, so I can't
feel any sympathy there.
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com
-- 
http://mail.python.org/mailman/listinfo/python-list


I Need Motivation Part 2

2005-11-04 Thread [EMAIL PROTECTED]
i m currently in a network (LAN). i started python because i heard 
that it has great ability for networking programs and/or scripts, but 
i m losing my motivation with python because there are sooo many 
modules, that i cant just learn them all, this deters from c or c++ in 
which there are only a limited number of header files. what loses my 
interest is that if i cant learn these modules, and there are lots and 
lots of python modules, how can i ever be a good enough 
programmer/scripter. 
-- 
 * Posted with NewsLeecher v3.0 Beta 7
 * http://www.newsleecher.com/?usenet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need Motivation

2005-11-04 Thread Martin P. Hellwig
[EMAIL PROTECTED] wrote:
 Martin P. Hellwig wrote:
 [EMAIL PROTECTED] wrote:
 I m not a python Expert or anythin
 i need help, i m losin my motivation to continue with python
 can anyone inspire me again.???
 Ooh that is easy, start learning other programming languages, you'll go
 back continuing with python very soon after that! ;-)
 It seems that many people switch to Ruby and never look back, some
 other go to haskell as well.
 
Yes that is also a possibility, however then the OP wouldn't wish to be 
motivated to continue pyhton :-)

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


Re: I Need Motivation Part 2

2005-11-04 Thread [EMAIL PROTECTED]

[EMAIL PROTECTED] wrote:
 i m currently in a network (LAN). i started python because i heard
 that it has great ability for networking programs and/or scripts, but
 i m losing my motivation with python because there are sooo many
 modules, that i cant just learn them all, this deters from c or c++ in
 which there are only a limited number of header files. what loses my
 interest is that if i cant learn these modules, and there are lots and
 lots of python modules, how can i ever be a good enough
 programmer/scripter.
Well, you better stick with python then. Forget about all those
modules, you would know what to use when the needs come up or ask by
then.

Python definitely has the momentum behind it for solving this kind of
real world problems and I would say the best overall
environment/language right now.

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-03, Steven D'Aprano schreef [EMAIL PROTECTED]:
 On Thu, 03 Nov 2005 13:35:35 +, Antoon Pardon wrote:

 Suppose I have code like this:
 
   for i in xrange(1,11):
 b.a = b.a + i
 
 Now the b.a on the right hand side refers to A.a the first time through
 the loop but not the next times. I don't think it is sane that which
 object is refered to depends on how many times you already went through
 the loop.

 Well, then you must think this code is *completely* insane too:

 py x = 0
 py for i in range(1, 5):
 ... x += i
 ... print id(x)
 ... 
 140838200
 140840184
 140843160
 140847128

 Look at that: the object which is referred to depends on how many times
 you've already been through the loop. How nuts is that?

It is each time the 'x' from the same name space. In the code above
the 'a' is not each time from the same namespace.

I also think you new very well what I meant.

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-03, Steven D'Aprano schreef [EMAIL PROTECTED]:
 On Thu, 03 Nov 2005 13:01:40 +, Antoon Pardon wrote:

 Seems perfectly sane to me. 

 What would you expect to get if you wrote b.a = b.a + 2?
 
 I would expect a result consistent with the fact that both times
 b.a would refer to the same object.

 class RedList(list):
 colour = red

 L = RedList(())

 What behaviour would you expect from len(L), given that L doesn't have a
 __len__ attribute?

Since AFAICT there is no single reference to the __len__ attribute that
will be resolved to two different namespace I don't see the relevance.

 Why do you expect
 b.a += 2 to give a different result?
 
 I didn't know I did.

 It seems to me that you do.

 You didn't appear to be objecting to a line like x = b.a assigning the
 value of 1 to x (although perhaps you do). If that was the case, then it
 is perfectly reasonable to expect b.a = x + 2 to store 3 into b.a, while
 leaving b.__class__.a untouched.

 Of course, if you object to inheritance, then you will object to x = b.a
 as well.

What I object to is that the mentioning of one instance gets resolved
to two different namespaces.

 Since ints are immutable objects, you shouldn't expect the value of b.a
 to be modified in place, and so there is an assignment to b.a, not A.a.
 
 You are now talking implementation details. I don't care about whatever
 explanation you give in terms of implementation details. I don't think
 it is sane that in a language multiple occurence of something like b.a
 in the same line can refer to different objects

 That's an implementation detail only in the sense that while condition
 is a loop is an implementation detail. It is a *design* detail.

 b is a name, and any reference to b (in the same namespace) will refer
 to the same object. At least until you rebind it to another object.

But some namespaces take great care not to allow a rebinding that would
result in the same name being resolved to a different namespace during
this namespace's lifetime.

 But b.a is not a name, it is an attribute lookup,

An other implementation detail. b.a is a name search of 'a' in the
namespace b.

 and by Python's rules of
 inheritance that lookup will look up attributes in the instance, the
 class, and finally any superclasses.

 If you persist in thinking of b.a as a name referring to a single object,
 of course you will be confused by the behaviour. But that's not what
 attribute lookup does.

 On the right hand side of an assignment, it will return the first existing
 of b.__dict__['a'] or b.__class__.__dict__['a']. On the left hand of an
 assignment, it will store into b.__dict__['a'].

That holly python does it this way, doesn't imply it is reasonable to
do it this way or that all consequences of doing it this way are
reasonable.

 I think it even less sane, if the same occurce of b.a refers to two
 different objects, like in b.a += 2

 Then it seems to me you have some serious design problems. Which would you
 prefer to happen?

 # Scenario 1
 # imaginary pseudo-Python code with no inheritance:
 class Paragraph:
 ls = '\n'  # line separator

 para = Paragraph()
 para.ls

= AttributeError - instance has no attribute 'ls'


 # Scenario 2
 # imaginary pseudo-Python code with special inheritance:
 class Paragraph:
 ls = '\n'  # line separator

 linux_para = Paragraph()
 windows_para = Paragraph()
 windows_para.ls = '\n\r'  # magically assigns to the class attribute
 linux_para.ls

= prints '\n\r'

 # Scenario 3
 # Python code with standard inheritance:
 class Paragraph:
 ls = '\n'  # line separator

 linux_para = Paragraph()
 windows_para = Paragraph()
 windows_para.ls = '\n\r'
 linux_para.ls

= prints '\n'


I don't see the relevance of these pieces of code. In none of them is
there an occurence of an attribute lookup of the same attribute that resolves
to different namespaces.

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-03, Mike Meyer schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] writes:
 What would you expect to get if you wrote b.a = b.a + 2?
 I would expect a result consistent with the fact that both times
 b.a would refer to the same object.

 Except they *don't*. This happens in any language that resolves
 references at run time.

Python doesn't resolve references at run time. If it did the following
should work.

a = 1
def f():
  a = a + 1

f()

But letting that aside. There is still a difference between resolving
reference at run time and having the same reference resolved twice
with each resolution a different result.

 Changing that would be changing a fundamental
 - and *important* - feature of Python. Arbitrary restrictions to
 prevent a single case of this from doing something people who aren't
 used to suvh behavior are kludges, and would constitute a wart on the
 language, pure and simple.

Python already has its warts. If you want to argue that fixing this
would make a bigger wart then the wart it is now. Fine I will accept
that.

 If you think this is bad, you should consider Jensen's device. It uses
 call-by-name, which Python doesn't have.

Actually, I would have thought it very interesting should python 
have provided some choice in parameter semantics.


 I think it even less sane, if the same occurce of b.a refers to two
 different objects, like in b.a += 2

 That's a wart in +=, nothing less. The fix to that is to remove +=
 from the language, but it's a bit late for that.

  mike

Well we agree that there is a wart somewhere.

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Steve Holden schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
 Op 2005-11-03, Stefan Arentz schreef [EMAIL PROTECTED]:
 
Antoon Pardon [EMAIL PROTECTED] writes:

...


No matter wat the OO model is, I don't think the following code
exhibits sane behaviour:

class A:
  a = 1

b = A()
b.a += 2
print b.a
print A.a

Which results in

3
1

I find it confusing at first, but I do understand what happens :-)

I understand what happens too, that doesn't make it sane behaviour.


But really, what should be done different here?

I don't care what should be different. But a line with only one
referent to an object in it, shouldn't be referring to two different
objects.

It doesn't.
 
 
 Yes it does. If the b.a refers to the instance variable, then an
 AttributeError should be raised, because the instance variable doesn't
 exist yet, so you can't add two to it.
 
 Excuse me. The statement

  a += 2

 causes a to refer to a different object after the assignment than it did 
 before. So does the statement

But the 'a' is both times in the same namespace.

  self.a += 2

In this case the 'a' is not necessarily both times in the same
name space.

 So why are you so concerned that the pre-assignment reference comes from 
 a different scope to the post-assignment reference? The fact remains 
 that after both assignments the rebound name can no longer (ever) be 
 used to refer to its former referent without a further rebinding taking 
 place.

I concerned with the a refering to different variables. A variable being
a name in a specific namespace.

 If the b.a refers to the class variable then two should be added to it.
 
 Wring, wring, wring. (Sorry, got that wrong :-)

 Neither happens instead we get some hybrid in which an instance varible
 is created that gets the value of class variable incrented by two.
 
 Yes. So does this mean you also have a problem with

  def f(x):
  x += 2

  g = 3
  print f(g)

 When the function call executes, the name x is bound to an object in the 
 call's containing scope. Is it then your contention that the augmented 
 assignment in the function should add two to that object, changing the 
 value of g?

Whether I have a problem with this specific behaviour or not is
irrelevant. In this case we have only one namespace with an 'x'.
So searching for 'x' will not result in different variables being
found.

 It doesn't, it simply proceeds along the lines of all Python assignments 
 and resolves the name as a reference to a specific object. It then 
 computes a new value from the referenced object and the augmented 
 assignment operator's right operand, and rebinds the name to the 
 newly-computed value.

 Please stop talking about variables.

No I think variable is the right term here. It refers to a name
in a specific namespace.

 Although augmented assignment operators have the *option* of updating 
 objects in place, surely not even you can require that they do so when 
 they are bound to an immutable object such as an integer.

No but I can require that the namespace to which a name is resolved,
doesn't change during the operation.

It doesn't touch the *class variable* A.a which is still 1.
 
 Why should it? Why, why, why? And gain, just for good measure, why? 
 Augmented assignment to a function argument doesn't modify the passed 
 object when immutable, and you have no problem with that (I know as I 
 write that this is just asking for trouble, and it will turn out that 
 you also find that behavior deeply controversial ...)

 
 But it accesses the class variable.
 
 Repeat after me: Python assignment binds values to names.

But not just to a name, it binds a name in a specific namespace.

 When I write

  class something:
  a = 1
  def __init__(self, val=None):
  if val:
  self.a += val

 then in the last statement the augmented assignment rebinds self.a 
 from the class variable to a newly-created instance variable. I am 
 of course using the word variable here in a Pythonic sense, rather 
 than in the sense that, say, a C programmer would use. In Python I 
 prefer to talk about binding names because talking of variables leads 
 people to expect that a name is bound to an area of memory whose value 
 is modified by assignment, but this is in fact not so.

 The initial access to self.a uses the defined name resolution order to 
 locate a value that was bound to the name a in class scope. So what? 
 This is a long-documented fact of Python life. It's *supposed* to be 
 that way, dammit.

That it is documented, doesn't make it sane behaviour. Otherwise
all companies had to do was to document there bugs.

In a line like b.a += 2, you only have one reference to a name
to be resolved in a spefied namespace (hierarchy). Since there
is only one reference I don't think it is sane that two resolutions
are done with two different variables as a result.

 I fail to understand why this is such a problem for 

Re: Class Variable Access and Assignment

2005-11-04 Thread Stefan Arentz
Antoon Pardon [EMAIL PROTECTED] writes:

...

 Would it be too much to ask that in a line like.
 
   x = x + 1.
 
 both x's would resolve to the same namespace?

This is starting to look more like a nagging contest than a real
discussion imo.

Consider changing the semantics of what you are proposing and
think about all those Python projects that will break because they
depend on the above behaviour and even take advantage of it.

So in short: yes, it would be too much to ask :-)

But, you can fix it in your own code. Simply make sure that your
class variables have different names or a prefix.

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Stefan Arentz
Antoon Pardon [EMAIL PROTECTED] writes:

 Op 2005-11-03, Mike Meyer schreef [EMAIL PROTECTED]:
  Antoon Pardon [EMAIL PROTECTED] writes:
  What would you expect to get if you wrote b.a = b.a + 2?
  I would expect a result consistent with the fact that both times
  b.a would refer to the same object.
 
  Except they *don't*. This happens in any language that resolves
  references at run time.
 
 Python doesn't resolve references at run time. If it did the following
 should work.
 
 a = 1
 def f():
   a = a + 1
 
 f()

No that has nothing to do with resolving things at runtime. Your example
does not work because the language is very specific about looking up
global variables. Your programming error, not Python's shortcoming.

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


Re: I Need Motivation Part 2

2005-11-04 Thread Sybren Stuvel
blahman ([EMAIL PROTECTED]) enlightened us with:
 i m losing my motivation with python because there are sooo many
 modules, that i cant just learn them all, this deters from c or c++
 in which there are only a limited number of header files.

There are over 2800 header files on my system in /usr/include. What do
you mean a limited number of header files?

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help converting some perl code to python

2005-11-04 Thread Sybren Stuvel
[EMAIL PROTECTED] enlightened us with:
 the problem is the '..' operator in perl. Is there any equivalent in
 python?  any suggestions ?

I have a suggestion: stop assuming we know perl, and explain what this
'..' operator does.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I Need Motivation Part 2

2005-11-04 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
 i m currently in a network (LAN). i started python because i heard 
 that it has great ability for networking programs and/or scripts, but 
 i m losing my motivation with python because there are sooo many 
 modules, that i cant just learn them all,

Why would you learn them all ? Learn the one you need when you need them
- jus don't forget to have a quick look at the existings modules before
reinventing the square wheel (I wrote a QD CSV parser before realinzing
there was a pretty good one in the stdlib... But what, my QD solution
took me laess than one hour to write and did what it had to do, so...)

 this deters from c or c++ in 
 which there are only a limited number of header files. 

In the stdlib, yes. Now there are thousands of librairies/frameworks
each reimplenting all the basic datastructure and algorithm (strings,
lists, hashtables, trees and the like), so you almost have to learn a
new language each time you use a new library.

 what loses my 
 interest is that if i cant learn these modules,

Once again : you don't have to.

 and there are lots and 
 lots of python modules, how can i ever be a good enough 
 programmer/scripter. 

Like everybody else: write programs. That's the only way to become a
programmer.

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


NLTK

2005-11-04 Thread Persi

Hi!

I´m beginning to useNLTK python libraries to make PLN (natural language processing). I have problems about how to do CFG (context free grammar) and about exactly what library I should use (ShiftReduce or ChartParser). I´d like to know if someone could help me. 

thanks
		Correo Yahoo!Comprueba qué es nuevo, aquíhttp://correo.yahoo.es-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Stefan Arentz schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] writes:

 ...

  Ah yes. Well, good luck with that. You seem to have decided that it is not
  sane and who am I to argue with that. It depends on your state of mind :-)
 
 I can just say the opposite, that you seem to have decided that it is
 sane.

 I have. I like the Python model.

Fine good for you.

  The model makes sense in my opinion. If you don't like it then there are
  plenty of other languages to choose from that have decided to implement
  things differently.
 
 And again this argument. Like it or leave it, as if one can't in general
 like the language, without being blind for a number of shortcomings.

 Personally I don't see it as a shortcoming.

Which isn't the point.

 It is this kind of recations that make me think a number of people is
 blindly devoted to the language to the point that any criticism of
 the language becomes intollerable.

 No not at all. Just look at all the PEPs and the changes in the language
 that have been made in the past. Python is very much community driven and
 that shows in it's progress.

 You on the other hand keep talking about emo things like 'sane' and
 'madness' without giving any technical backing about these problems
 that you are having with the language.

That you took those emotionally, is not my responsibility. Would you
prefered it, had I called it a wart? As far as I see it, any negative
comment on python is reacted to in pretty much the same way. So
don't blame it on me using emotional language.

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Paul Rubin
Stefan Arentz [EMAIL PROTECTED] writes:
  Would it be too much to ask that in a line like.
x = x + 1.
  both x's would resolve to the same namespace?
 ...
 Consider changing the semantics of what you are proposing and
 think about all those Python projects that will break because they
 depend on the above behaviour and even take advantage of it.

Are you seriously saying there's lots of Python projects that would
break if this particular weirdness were fixed?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-04 Thread Stefan Arentz
Paul Rubin http://[EMAIL PROTECTED] writes:

 Stefan Arentz [EMAIL PROTECTED] writes:
   Would it be too much to ask that in a line like.
 x = x + 1.
   both x's would resolve to the same namespace?
  ...
  Consider changing the semantics of what you are proposing and
  think about all those Python projects that will break because they
  depend on the above behaviour and even take advantage of it.
 
 Are you seriously saying there's lots of Python projects that would
 break if this particular weirdness were fixed?

I have no numbers of course. But, why is this a weirdness? 

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


Re: help converting some perl code to python

2005-11-04 Thread Ben Sizer
[EMAIL PROTECTED] wrote:
 the problem is the '..' operator in perl. Is there any equivalent in
 python?

I can't think of anything with a similar operation, to be honest. I'd
try using while loops which look out for the next section delimiter.

-- 
Ben Sizer.

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Magnus Lycka
Antoon Pardon wrote:
Because b.a += 2 expands to b.a = b.a + 2. Why would you want b.a =
something to correspond to b.__class__.a = something?
 
 
 That is an implemantation detail. The only answer that you are given
 means nothing more than: because it is implemented that way.

Something that is written in the language reference is not
an implementation detail. Every implementation that aims to
be Python must follow this. It's a design decision.

Whether you like it or not, you will find out that the behaviour
of Python is largely based on an idea of an underlying structure.
A lot of the syntax is basically just convenient ways to access
this structure, and there is a strong tradition to avoid magic.

The explicit use of self might be the most obvious example of that,
but you can find a lot of other things in Python that shows you
this, __dict__ for instance.

I agree that the behaviour you are questioning isn't completely
unsurprising for someone who stumbles over it the first time, but
considering how things work in Python classes, where the class
scope is searched if a name isn't found in the instance scope
(self.__dict__), any other solution would involve more magic, and
be more surprising to someone who actually knows what is going on.

It's possible that a oldie like me, who started coding Python in
1996 is just blind to the warts in Python by now, but no language
is perfect, and whatever design decisions you make, they will have
both positive and negative consequences.

I frankly don't understand what you are after Antoon. Just to
vent your frustrations? If you want to use Python in an effective
way, try to learn how to use the language that actually exists.

Asking questions in this forum is clearly a part of that, but
your confrontational style, and idea that everything that bothers
you is a language bug that needs to be fixed is not the most
constructive approach. I'm pretty sure that it doesn't really solve
your coding problems, instead it leads the discussion away from the
practical solutions.

If you really want to improve the Python language, your approach
is completely off target. First of all, this isn't really the right
forum for that, and secondly, improvements to Python requires a
lot of cooperation and substantial contributions of work, not just
complaints, even if you might have a point now and then.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-04 Thread Mike Meyer
Antoon Pardon [EMAIL PROTECTED] writes:
 Op 2005-11-03, Mike Meyer schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] writes:
 What would you expect to get if you wrote b.a = b.a + 2?
 I would expect a result consistent with the fact that both times
 b.a would refer to the same object.
 Except they *don't*. This happens in any language that resolves
 references at run time.
 Python doesn't resolve references at run time. If it did the following
 should work.

You left out a key word: all.

 a = 1
 def f():
   a = a + 1

 f()

If Python didn't resolve references at run time, the following
wouldn't work:

 def f():
...  global a
...  a = a + 1
... 
 a = 1
 f()
 

 But letting that aside. There is still a difference between resolving
 reference at run time and having the same reference resolved twice
 with each resolution a different result.

The second is a direct result of the first. The environment can change
between the references, so they resolve to different results.





 Changing that would be changing a fundamental
 - and *important* - feature of Python. Arbitrary restrictions to
 prevent a single case of this from doing something people who aren't
 used to suvh behavior are kludges, and would constitute a wart on the
 language, pure and simple.
 Python already has its warts. If you want to argue that fixing this
 would make a bigger wart then the wart it is now. Fine I will accept
 that.

I've already argued that the kludges suggested to solve this problem
create worse problems than this. This is a simple case of something
being unexpected to those used to less dynamic languages. The other
solutions break useful functionality, and require adding special cases
to the language - which aren't special enough to break the rules.

mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Most efficient way of storing 1024*1024 bits

2005-11-04 Thread Ben Sizer
Tom Anderson wrote:
 On Wed, 2 Nov 2005, Dan Bishop wrote:

  Tor Erik Sønvisen wrote:
 
  I need a time and space efficient way of storing up to 6 million bits.
 
  The most space-efficient way of storing bits is to use the bitwise
  operators on an array of bytes:

 Actually, no, it's to xor all the bits together and store them in a single
 boolean.

I'd use 'or' rather than 'xor'. The or operator is more likely to yield
a '1' at the end of it, and a 1 is narrower than a 0, obviously making
it more efficient to store.

-- 
Ben Sizer

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Mike Meyer

 Would it be too much to ask that in a line like.
 
   x = x + 1.
 
 both x's would resolve to the same namespace?

Yes. That's to much bondage for programmers who've become accustomed
to freedom. Explain why this should be illegal:

 class C:
...  def __getattr__(self, name):
...   x = 1
...   return locals()[name]
...  def __setattr__(self, name, value):
...   globals()[name] = value
... 
 o = C()
 o.x = o.x + 1
 x
2
 


mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-04 Thread Paul Rubin
Stefan Arentz [EMAIL PROTECTED] writes:
  Are you seriously saying there's lots of Python projects that would
  break if this particular weirdness were fixed?
 
 I have no numbers of course. But, why is this a weirdness? 

Do you seriously think the number is larger than zero?  Do you think
that's any good way to write code?

Examples of the weirdness have already been given.  My favorite is the
one where b.a is a list instead of an integer, in which case the class
variable gets updated instead of an instance variable getting created.
If you don't find the inconsistency to be weird, then ducky for you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Magnus Lycka schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
Because b.a += 2 expands to b.a = b.a + 2. Why would you want b.a =
something to correspond to b.__class__.a = something?
 
 
 That is an implemantation detail. The only answer that you are given
 means nothing more than: because it is implemented that way.

 Something that is written in the language reference is not
 an implementation detail. Every implementation that aims to
 be Python must follow this. It's a design decision.

I have looked and didn't find it in the language reference.

This is what I have found:

An augmented assignment expression like x += 1 can be rewritten
as x = x + 1 to achieve a similar, but not exactly equal effect.

I think one could argue that in the case of b.a += 1 and a
being a class variable that incrementing the class variable
was a similar effect in this case.

But I can be and maybe a more strict definition is available
that I looked over. Do happen to know one?

 Whether you like it or not, you will find out that the behaviour
 of Python is largely based on an idea of an underlying structure.
 A lot of the syntax is basically just convenient ways to access
 this structure, and there is a strong tradition to avoid magic.

Fine. I already wrote that if people think that changing this
behaviour would cause more problems than it solved or that
solving it would cause more problems than it is worth, I would
have no problem with that.

That doesn't change the fact that the current behaviour is
on occasions awkward or whatever you want to call it.

 The explicit use of self might be the most obvious example of that,
 but you can find a lot of other things in Python that shows you
 this, __dict__ for instance.

 I agree that the behaviour you are questioning isn't completely
 unsurprising for someone who stumbles over it the first time, but
 considering how things work in Python classes, where the class
 scope is searched if a name isn't found in the instance scope
 (self.__dict__), any other solution would involve more magic, and
 be more surprising to someone who actually knows what is going on.

It would be more suprising to someone depending on what is now
going on. I also find that people underestimate the magic that
is going on in python. But just because you are familiar with
the magic, doesn't make it less magic. IMO python shows its
history a little. 

 It's possible that a oldie like me, who started coding Python in
 1996 is just blind to the warts in Python by now, but no language
 is perfect, and whatever design decisions you make, they will have
 both positive and negative consequences.

I completely agree. Personnaly I find python has withstood
its changes remarkebly well and I find the design in general
still very consistent despite the changes it underwent.

 I frankly don't understand what you are after Antoon. Just to
 vent your frustrations? If you want to use Python in an effective
 way, try to learn how to use the language that actually exists.

I'm after nothing particular. The only thing I'm frustrated about
is the way in which some people seem willing to defend python
just because it is python. If the only reaction I would have
gotten would have been something like: Yeah that seems a bit
awkward but fixing this would break more than it would cure,
I would have left it as it is.

 Asking questions in this forum is clearly a part of that, but
 your confrontational style, and idea that everything that bothers
 you is a language bug that needs to be fixed is not the most
 constructive approach.

I have rarely indicated I wanted things to be fixed. Sure I would
like it if some things were different, but I recognize that there
are more important things that needs to be resolved.

Does that mean I shouldn't mention things that IMO could have been
better or that I should only mention them in the softest of
language that certainly can't be interpreted as emotional language.

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


how to compile c-extensions under WinXP?

2005-11-04 Thread severa
What should I do to be able to compile C-extensions (with python 2.4, 
winXP)? I get an error message, approximately The .NET Framework SDK 
needs to be installed; I tried to get something from the Microsoft web 
site, but maybe not the right version (or didn't set some variables), 
since the error remains. Could you please help me (it will need some 
patience with a computer newbie)?

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


Re: Most efficient way of storing 1024*1024 bits

2005-11-04 Thread Alex Stapleton

On 4 Nov 2005, at 10:26, Ben Sizer wrote:

 Tom Anderson wrote:

 On Wed, 2 Nov 2005, Dan Bishop wrote:


 Tor Erik Sønvisen wrote:


 I need a time and space efficient way of storing up to 6 million  
 bits.


 The most space-efficient way of storing bits is to use the bitwise
 operators on an array of bytes:


 Actually, no, it's to xor all the bits together and store them in  
 a single
 boolean.


 I'd use 'or' rather than 'xor'. The or operator is more likely to  
 yield
 a '1' at the end of it, and a 1 is narrower than a 0, obviously making
 it more efficient to store.

xahlee
Typical gas guzzling, SUV driving american logic. A would obviously  
use more POWER and hence INCREASE GLOBAL WARMING leading to the  
ultimate DEATH of EVERYBODY you know and LOVE!
/xahlee

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Mike Meyer schreef [EMAIL PROTECTED]:

 Would it be too much to ask that in a line like.
 
   x = x + 1.
 
 both x's would resolve to the same namespace?

 Yes. That's to much bondage for programmers who've become accustomed
 to freedom. Explain why this should be illegal:

 class C:
 ...  def __getattr__(self, name):
 ...   x = 1
 ...   return locals()[name]
 ...  def __setattr__(self, name, value):
 ...   globals()[name] = value
 ... 
 o = C()
 o.x = o.x + 1
 x
 2

I'll answer with a contra question.

Please explain why this is illegal.

x = 1
def f():
  x += 1

f()

IMO your example and mine are essentially the same issue. A name in one
namespace shadowing a name in a different namespace.

So please explain how the same kind of bondage is no problem in the
function but is too much for those who've become accustomed to
freedom in the case of objects with class variables?

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


Re: Python and Lotus Notes

2005-11-04 Thread Marco Aschwanden

The second line of your code is already a show stopper in my case:

 from win32com.client import Dispatch
session = Dispatch('Lotus.NotesSession')
session.Initialize('my_secret_passwort')

When started, ends:

File  
C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py,  
line 310, in RunScript
 exec codeObject in __main__.__dict__
   File C:\temp\notes_init.py, line 3, in ?
 session.Initialize('my_secret_passwort')
   File c:\Python24\lib\site-packages\win32com\client\dynamic.py, line  
489, in __getattr__
 raise AttributeError, %s.%s % (self._username_, attr)
AttributeError: Lotus.NotesSession.Initialize

It worked before though with Version 5.x of Notes. In Notes Version 6.X  
they introduced the session.Initialize() - that was the point, when I  
couldn't create an instance anymore. I found no hint on the net... Do you  
have any idea what is going wrong here?

Regards,
Marco

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Stefan Arentz schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] writes:

 Op 2005-11-03, Mike Meyer schreef [EMAIL PROTECTED]:
  Antoon Pardon [EMAIL PROTECTED] writes:
  What would you expect to get if you wrote b.a = b.a + 2?
  I would expect a result consistent with the fact that both times
  b.a would refer to the same object.
 
  Except they *don't*. This happens in any language that resolves
  references at run time.
 
 Python doesn't resolve references at run time. If it did the following
 should work.
 
 a = 1
 def f():
   a = a + 1
 
 f()

 No that has nothing to do with resolving things at runtime. Your example
 does not work because the language is very specific about looking up
 global variables. Your programming error, not Python's shortcoming.

It has nothing to do with global variables, the same thing happens
with nested scopes.

def f():
  a = 1
  def g():
a = a + 1

  g()

f()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-04 Thread Paul Rubin
Mike Meyer [EMAIL PROTECTED] writes:
 I've already argued that the kludges suggested to solve this problem
 create worse problems than this.

The most obvious solution is to permit (or even require) the
programmer to list the instance variables as part of the class
definition.  Anything not in the list is not an instance variable,
i.e. they don't get created dynamically.  That's what most other
languages I can think of do.  Some Python users incorrectly think this
is what __slots__ does, and try to use __slots__ that way.  That they
try to do that suggests that the approach makes some sense.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python is like COBOL! was: Re: Getting Python Accepted in my Organisation

2005-11-04 Thread Magnus Lycka
Steve Holden wrote:
 To put things into perspective, it's important to get beyond the very
 broad categories of programming languages. It's pointless to judge
 Python on the merits of Perl or AWK, just because a certain label is
 sometimes applied to all three. That would be like saying that Java
 is more or less like COBOL. (OO COBOL?)

 Quite. People have said exactly that, you know ;-)

Anyone else besides you? ;^)

Seriously, it really depends on what aspects of Java and COBOL
you compare. As you noted, COBOL is better in some ways...

   http://www.artima.com/weblogs/viewpost.jsp?thread=42242

Well, I've never coded a lot in either language, but I've worked
fairly intimately with COBOL and Java developers in some projects,
and my exposure to COBOL made me understand a lot about the bugs
that haunt mainframe systems. (I actually wrote a Python program
that generated COBOL and JCL for database export/import.)

It's one thing that it's so verbose: We had one architect who
wrote enough pseudo code and SQL statements to keep around 10
COBOL coders fully occupied (and we still had a team with as
many testers as coders, so it wasn't that the coders spent
half their time testing).

Still, the really distinguishing factor I saw in COBOL on
mainframes wasn't bloat, but this completely static world
view.

For other programmers, COBOL programmers appear as inhabitants
in flatland, who haven't discovered that there is actually a
third dimension. They still view memory as a punch card. They
constantly run into things like: We didn't think anyone could
possibly have more than 20 employments during a month, and it
turns out that his whole category has, but we've upped it to 30,
and that seems to work so far. As a non-COBOList, the natural
response is obviously to write code that works with any number
of employments, and doesn't allocate the same amount of memory
for those with one employment as for those with 25. In COBOL
this seems to be prohibitly complex in many cases. Heck, they
even determine the full size of files when they create them. We
had some special (probably very expensive) software system that
allowed us to dynamically allocate new space to files as data
was added, but that was considered black magic, that only a few
wizards understood.

 From this perspective, Java is much closer to Python than to COBOL.
Still, Python is more dynamic than Java. I'd say that going from
Java to Python is similar to going from COBOL to Java. Maybe scary
at first, but an eye-opener that makes you feel more powerful. A
bit like a journey to a foreign continent. I do think the step
from COBOL to Java is bigger then the step from Java to Python though.

In one way, COBOL and Python are the similar languages, and Java is
the odd one: While COBOL is archaic, and appears retarded for
modern programmers, it's easy to learn--at least if you haven't
programmed before... It was designed to be easy for non-programmers
to use. Python is a great newbie language. Java has tried to avoid
a lot of the traps of C/C++, but it's still much more difficult
to get started there, than with Python or COBOL.

COBOL has been very successful. It's still used a lot today, after
all these decades, and while it lacks a lot of the abstractions in
modern languages, it has for instance numeric types that don't give
the kinds of surprises that floats do.

While the perfect modern successor to COBOL would probably have some
features that are lacking in Python 2.x, I think we're pretty close.
With datetime and decimal, we have the fundamental types that were
missing before. OO is available but not forced upon us. The initial
threshold to become productive is low, but we won't hit the ceiling
as we evolve. Sure, there isn't full standardized support for all
things we need, such as message queueing systems or distributed
transactions, but that's not too hard to fix. There are C APIs...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learning multiple languages (question for general discussion)

2005-11-04 Thread Magnus Lycka
Alex Martelli wrote:
 Yes, but I haven't found knowing (and using) Python dampens my
 enthusiasms for learning new languages.

But you're more enthusiatic than most of us Alex. I wish
I could say the same, but I must admit that I only did
halfhearted attempts at learning new languages after Python.
I've looked a bit at most of the ones you mentioned, but
there was nothing that gave me the drive to really follow
it through. I've somehow become content in this regard.

This doesn't mean that I'm not evolving. I regularly program
in three languages (Python, C++ and SQL) and I must learn
new things the whole time to keep interested, whether it's
in the current problem domain, in architectural matters, in
regards to libraries or development tools or whatever. Now
it's Twisted for instance. Still, finding Python was a lot
like finding a permanent home (which doesn't exclude various
excursions, or prevent another move or two in this life.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Fork() and exec() dont work

2005-11-04 Thread [EMAIL PROTECTED]
i m using Windows XP, and by tomorrow i will have have fedora core 
installed too. the problem is, when i use these fork() and exec() my 
windows doesnt do anything, python gives an error about the module, 
the kind of error when u know u r wrong.

is it because these commands work on linux?

if so, is it better for me to stick with fedora for my python programs 
or use windows?
-- 
 * Posted with NewsLeecher v3.0 Beta 7
 * http://www.newsleecher.com/?usenet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Mike Meyer schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] writes:
 Op 2005-11-03, Mike Meyer schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] writes:
 What would you expect to get if you wrote b.a = b.a + 2?
 I would expect a result consistent with the fact that both times
 b.a would refer to the same object.
 Except they *don't*. This happens in any language that resolves
 references at run time.
 Python doesn't resolve references at run time. If it did the following
 should work.

 You left out a key word: all.

 a = 1
 def f():
   a = a + 1

 f()

 If Python didn't resolve references at run time, the following
 wouldn't work:

 def f():
 ...  global a
 ...  a = a + 1
 ... 
 a = 1
 f()
 

Why do you think so? I see nothing here that couldn't work with
a reference resolved during compile time.

 But letting that aside. There is still a difference between resolving
 reference at run time and having the same reference resolved twice
 with each resolution a different result.

 The second is a direct result of the first. The environment can change
 between the references, so they resolve to different results.

No the second is not a direct result of the first. Since there is
only one reference, I see nothing wrong with the environment
remebering the reference and reusing it if it needs the reference
a second time.

Take the code:

  lst[f()] += 1

Now let f be a function with a side effect, that in succession
produces the positive integers starting with one.

What do you think this should be equivallent to:

  t = f()
  lst[t] = lst[t] + 1

or

  lst[f()] = lst[f()] + 1

If you think the environment can change between references then I
suppose you prefer the second approach.

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


Re: Fork() and exec() dont work

2005-11-04 Thread [EMAIL PROTECTED]

fork( )

Fork a child process. Return 0 in the child, the child's process id in
the parent. Availability: (!!!) Unix (!!!). 


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


Re: I Need Motivation Part 2

2005-11-04 Thread Leif K-Brooks
Sybren Stuvel wrote:
 There are over 2800 header files on my system in /usr/include. What do
 you mean a limited number of header files?

I assume he's saying that the number is  ∞. (Of course, the same is
true of Python modules unless you use a special __import__ hook or
something...)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: help converting some perl code to python

2005-11-04 Thread Peter Otten
[EMAIL PROTECTED] wrote:

 i need help with converting a piece of perl code to python

 the problem is the '..' operator in perl. Is there any equivalent in
 python?

Here is a class that emulates the .. operator:

code
import sys
import re

start, files, end = map(re.escape, [[start], [files], [end]])

class Section(object):
def __init__(self, start, end):
self.start = re.compile(start).match
self.end = re.compile(end).match
self.inside = False
def __contains__(self, line):
result = self.inside
if result:
if self.end(line):
self.inside = False
else:
if self.start(line):
result = self.inside = True
return result

first = Section(start, files)
second = Section(files, end)
for line in sys.stdin:
line = line[:-1]
if line in first:
# your code
if line in second:
# your code
/code

However, the simpler

code
#untested
import sys

start, files, end = [start], [files], [end]
keys = set([start, files, end])

key = None
for line in sys.stdin:
line = line[:-1]
if line in keys:
key = line
elif key == start:
# your code
elif key == files:
# your code
/code

might work even better because 'your code' doesn't get to see the sections'
begin/end markers.

Peter

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Graham schreef [EMAIL PROTECTED]:
 Once again, many thanks, your explainations are very detailed and i
 think i'm in full understanding of the what/when/why of it all.

 And with further introspection i can see why its done this way from a
 language processing point of view rather than programming one. I also
 now realize that instance.classvarname is there so that you dont
 have to type instance.__class__.varname all the time.

You still have to if you want to change the class variable.

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


Re: how to compile c-extensions under WinXP?

2005-11-04 Thread Gerhard Häring
[EMAIL PROTECTED] wrote:
 What should I do to be able to compile C-extensions (with python 2.4, 
 winXP)? I get an error message, approximately The .NET Framework SDK 
 needs to be installed; I tried to get something from the Microsoft web 
 site, but maybe not the right version (or didn't set some variables), 
 since the error remains. Could you please help me (it will need some 
 patience with a computer newbie)?

I managed to do it with the instructions at

http://www.vrplumber.com/programming/mstoolkit/

-- Gerhard

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
On Fri, 04 Nov 2005 07:31:46 +, Antoon Pardon wrote:

 The model makes sense in my opinion. If you don't like it then there are
 plenty of other languages to choose from that have decided to implement
 things differently.
 
 And again this argument. Like it or leave it, as if one can't in general
 like the language, without being blind for a number of shortcomings.
 
 It is this kind of recations that make me think a number of people is
 blindly devoted to the language to the point that any criticism of
 the language becomes intollerable.

There are good usage cases for the current inheritance behaviour. I asked
before what usage case or cases you have for your desired behaviour, and
you haven't answered. Perhaps you missed the question? Perhaps you haven't
had a chance to reply yet? Or perhaps you have no usage case for the
behaviour you want.

Some things are a matter of taste: should CPython prefer  or != for not
equal? Some things are a matter of objective fact: should CPython use a
byte-code compiler and virtual machine, or a 1970s style interpreter that
interprets the source code directly?

The behaviour you are calling insane is partly a matter of taste, but it
is mostly a matter of objective fact. I believe that the standard
model for inheritance that you call insane is rational because it is
useful in far more potential and actual pieces of code than the behaviour
you prefer -- and the designers of (almost?) all OO languages seem to
agree with me.

The standard behaviour makes it easy for code to do the right thing in
more cases, without the developer taking any special steps, and in the
few cases where it doesn't do the right thing (e.g. when the behaviour you
want is for all instances to share state) it is easy to work around. By
contrast, the behaviour you want seems to be of very limited usefulness,
and it makes it difficult to do the expected thing in almost all cases,
and work-arounds are complex and easy to get wrong.

The standard behaviour makes it easy for objects to inherit state, and
easy for them to over-ride defaults. The behaviour(s) you and Graham want
have awkward side-effects: your proposed behaviour would mean that class
attributes would mask instance attributes, or vice versa, meaning that
the programmer would have to jump through hoops to get common types of
behaviour like inheriting state.

The behaviour you want would make it too easy to inadvertently have
instances share state. Normally we want instances to share behaviour but
have unique states -- you would change that. Why? If it is just a matter
of taste, you are welcome to your opinion. But you don't say that the
standard behaviour is ugly, you say it is insane, that is, irrational,
and that the behaviour you want is rational.

That's an objective claim: please explain what makes your behaviour more
rational than the standard behaviour. Is your behaviour more useful? Does
it make code easier to write? Does it result in more compact code? What
usage cases?

Or is it just a subjective judgement on your part that it would be neater?


-- 
Steven.

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


Re: Fork() and exec() dont work

2005-11-04 Thread Maciej Dziardziel
blahman ([EMAIL PROTECTED]) wrote:

 i m using Windows XP, and by tomorrow i will have have fedora core
 installed too. the problem is, when i use these fork() and exec() my
 windows doesnt do anything, python gives an error about the module,
 the kind of error when u know u r wrong.
 
 is it because these commands work on linux?

as documentation says:

fork(  )
 Fork a child process. Return 0 in the child, the child's process id in the
parent. Availability: Macintosh, Unix. 

 
 if so, is it better for me to stick with fedora for my python programs
 or use windows?

You can achive the same thing in windows by taking different approach,
but i would say that Linux is way more programmer-friendly (especially
Debian ;-)

-- 
Maciej Fiedzia Dziardziel (fiedzia (at) fiedzia (dot) prv (dot) pl)
www.fiedzia.prv.pl

When tempted to fight fire with fire, remember that the Fire Department   
   usually uses water.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-04 Thread Steve Holden
Antoon Pardon wrote:
 Op 2005-11-04, Steve Holden schreef [EMAIL PROTECTED]:
[...]
I suppose ultimately I'm just more pragmatic than you.
 
 
 It has nothing to do with being more pragmatic. Being pragmatic
 is about how you handle things with real life projects. It has
 little to do with the degree in which you agree with the design
 of the tool you have to work with. I would say I am more pragmatic
 than most defenders of python, because when it comes done to
 do my work, I just use python as best as I can, while a lot
 of people here seem to think that every little criticism I have
 is enough to go and look for a different language.
 
No, being pragmatic is to do with accepting what is rather than wasting 
time wishing it were otherwise, particularly when the insane behavior 
was actually a deliberate design choice. Which is why it doesn't work 
the same as non-local references in nested scopes.

 
Plus I started 
using Icon, whose assignment semantics are very similar, back in the 
1970's, so Python's way of doing things fits my brain quite nicely, 
thank you.
 
 
 So, people can probably say that about any language they started with.
 That a language suits a certain persons brain, may say more about
 the person than about the language.
 
I wasn't trying to make a point about the language. I was merely (and I 
thought charitably) trying to explain why I appear to be blind to the 
insanity you see all around you.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: how to compile c-extensions under WinXP?

2005-11-04 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 What should I do to be able to compile C-extensions (with python 2.4, 
 winXP)? I get an error message, approximately The .NET Framework SDK 
 needs to be installed; I tried to get something from the Microsoft web 
 site, but maybe not the right version (or didn't set some variables), 
 since the error remains. Could you please help me (it will need some 
 patience with a computer newbie)?
 
See

   http://www.vrplumber.com/programming/mstoolkit

and say thanks to Mike Farmer.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Steve Holden
Paul Rubin wrote:
 Stefan Arentz [EMAIL PROTECTED] writes:
 
Are you seriously saying there's lots of Python projects that would
break if this particular weirdness were fixed?

I have no numbers of course. But, why is this a weirdness? 
 
 
 Do you seriously think the number is larger than zero?  Do you think
 that's any good way to write code?
 
Well it would break the Medusa asyncore/asynchat-based server software, 
so I can confidently predict the number would be greater than zero, yes.

Several fine programmers have relied on the (documented) behavior, I 
suspect, as it's a convenient way to install per-instance defaults, for 
example.

 Examples of the weirdness have already been given.  My favorite is the
 one where b.a is a list instead of an integer, in which case the class
 variable gets updated instead of an instance variable getting created.
 If you don't find the inconsistency to be weird, then ducky for you.

Ho, hum.
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Steve Holden schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
 Op 2005-11-04, Steve Holden schreef [EMAIL PROTECTED]:
 [...]
I suppose ultimately I'm just more pragmatic than you.
 
 
 It has nothing to do with being more pragmatic. Being pragmatic
 is about how you handle things with real life projects. It has
 little to do with the degree in which you agree with the design
 of the tool you have to work with. I would say I am more pragmatic
 than most defenders of python, because when it comes done to
 do my work, I just use python as best as I can, while a lot
 of people here seem to think that every little criticism I have
 is enough to go and look for a different language.
 
 No, being pragmatic is to do with accepting what is rather than wasting 
 time wishing it were otherwise,

Just accepting what is, is not pragmatic. Not much progress would have
been made if we just accepted what is.

 particularly when the insane behavior 
 was actually a deliberate design choice. Which is why it doesn't work 
 the same as non-local references in nested scopes.

That b.a = b.a + 2

works as a result of a design choice, that I can accept.

But IMO b.a += 2, working as it does, is more the result of
earlier design and implementation decisions than it was
a deliberate design decision.

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


Re: Not Equal to Each Other?

2005-11-04 Thread ale . of . ginger
How do I 'define' set?  Is there something to include (like import
random)?

while (choice == 3) and len(set(cellboard[0:8]))==len(cellboard[0:8]):
# DEFINE TWO RANDOM VARIABLES (ONE FOR ARRAY, ONE FOR NUMBER
VALUE)
solvingrandom = random.randint(1,9)
cellboardrandom = random.randint(0,8)
set(cellboard[0:8])

# CHECK TO MAKE SURE THE RANDOMLY ASSIGNED CELL DOES NOT HAVE A
VALUE
if (cellboard[cellboardrandom] is not ('1' or '2' or '3' or '4'
or '5' or '6' or '7' or '8' or '9')):
cellboard[cellboardrandom] = solvingrandom

The above is my code (right now it will only work for the first row's
numbers).  Anything else I need to add?

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes:
 There are good usage cases for the current inheritance behaviour.

Can you name one?  Any code that relies on it seems extremely dangerous to me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Steven D'Aprano schreef [EMAIL PROTECTED]:
 On Fri, 04 Nov 2005 07:31:46 +, Antoon Pardon wrote:

 The model makes sense in my opinion. If you don't like it then there are
 plenty of other languages to choose from that have decided to implement
 things differently.
 
 And again this argument. Like it or leave it, as if one can't in general
 like the language, without being blind for a number of shortcomings.
 
 It is this kind of recations that make me think a number of people is
 blindly devoted to the language to the point that any criticism of
 the language becomes intollerable.

 There are good usage cases for the current inheritance behaviour. I asked
 before what usage case or cases you have for your desired behaviour, and
 you haven't answered. Perhaps you missed the question? Perhaps you haven't
 had a chance to reply yet? Or perhaps you have no usage case for the
 behaviour you want.

There are good use cases for a lot of things python doesn't provide.
There are good use cases for writable closures, but python doesn't
provide it, shrug, I can live with that. Use cases is a red herring
here.

 Some things are a matter of taste: should CPython prefer  or != for not
 equal? Some things are a matter of objective fact: should CPython use a
 byte-code compiler and virtual machine, or a 1970s style interpreter that
 interprets the source code directly?

 The behaviour you are calling insane is partly a matter of taste, but it
 is mostly a matter of objective fact. I believe that the standard
 model for inheritance that you call insane is rational because it is
 useful in far more potential and actual pieces of code than the behaviour
 you prefer -- and the designers of (almost?) all OO languages seem to
 agree with me.

I didn't call the model for inheritance insane.

 The standard behaviour makes it easy for code to do the right thing in
 more cases, without the developer taking any special steps, and in the
 few cases where it doesn't do the right thing (e.g. when the behaviour you
 want is for all instances to share state) it is easy to work around. By
 contrast, the behaviour you want seems to be of very limited usefulness,
 and it makes it difficult to do the expected thing in almost all cases,
 and work-arounds are complex and easy to get wrong.

Please don't make this about what I *want*. I don't want anything.
I just noted that one and the same reference can be processed
multiple times by the python machinery, resulting in that same
reference referencing differnt variables at the same time and
stated that that was unsane behaviour.

 The standard behaviour makes it easy for objects to inherit state, and
 easy for them to over-ride defaults. The behaviour(s) you and Graham want
 have awkward side-effects: your proposed behaviour would mean that class
 attributes would mask instance attributes, or vice versa, meaning that
 the programmer would have to jump through hoops to get common types of
 behaviour like inheriting state.

You don't know what I want. You only know that I have my criticism of
particular behaviour. You seem to have your idea about what the
alternative would be like, and project that to what I would want.

 The behaviour you want would make it too easy to inadvertently have
 instances share state. Normally we want instances to share behaviour but
 have unique states -- you would change that. Why? If it is just a matter
 of taste, you are welcome to your opinion. But you don't say that the
 standard behaviour is ugly, you say it is insane, that is, irrational,
 and that the behaviour you want is rational.

I called it unsane, not insane. I think I paid enough attention to never
use the word insane, yes I once used madness but that was after you
were already all over me for this.

Even should I have used the word insane, I used it for a lot less than
you are implying.

 That's an objective claim: please explain what makes your behaviour more
 rational than the standard behaviour. Is your behaviour more useful? Does
 it make code easier to write? Does it result in more compact code? What
 usage cases?

What my behaviour? I don't need to specify alternative behaviour in
order to judge specific behaviour.

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Magnus Lycka
Antoon Pardon wrote:
 Would it be too much to ask that in a line like.
 
   x = x + 1.
 
 both x's would resolve to the same namespace?

They always do Antoon. There is no such issue for
local (or global) varibles. The issue has to do
with c.x = c.x + 1. In this case it's clearly
designed and documented that this corresponds to:

setattr(c, 'x', getattr(c, 'x') + 1)

The result of these operations depends on e.g.
how the __setattr__ and __getattr__ methods in
the class in question are defined.

You need to understand that the dot-operaterator
always involves a lookup-operation that can be
implemented in various ways.

It's well defined that you can do things like:

  class Counter:
... c=0
... def __call__(self):
... self.c+=1
... def __str__(self):
... return str(self.c)
...
  c=Counter()
  c()
  print c
1
  c()
  print c
2
  class C5(Counter):
... c=5
...
  c5=C5()
  c5()
  print c5
6

Of course, you could design a language, say Pythoon
or Parthon, where this is illegal, and you force the
programmer to do something longer such as:

  class APCounter:
... c=0
... def __init__(self):
... self.c = self.__class__.c
... def __call__(self):
... self.c+=1
... def __str__(self):
... return str(self.c)
...

I don't see this as an improvement though...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Filepath string manipulation help

2005-11-04 Thread mjakowlew
Steve,

the os commands don't run through zope, it denies access to them to be
run at all through  the webserver. So in turn, I had to use a work
around to fix the IE problem. Also qwwee's suggestion to use:

 filepath.split('\\')[-1]

works well too. Zope is very finicky about running specific commands,
I'm sure this is due to security issues of running os commands through
a website/webserver.

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


Re: Not Equal to Each Other?

2005-11-04 Thread Juho Schultz
[EMAIL PROTECTED] wrote:
 How do I 'define' set?  Is there something to include (like import
 random)?
 
set is a built-in type in Python 2.4
If you use 2.3 you can use the sets module with import sets


 while (choice == 3) and len(set(cellboard[0:8]))==len(cellboard[0:8]):
 # DEFINE TWO RANDOM VARIABLES (ONE FOR ARRAY, ONE FOR NUMBER
 VALUE)
 solvingrandom = random.randint(1,9)
 cellboardrandom = random.randint(0,8)
 set(cellboard[0:8])
 
 # CHECK TO MAKE SURE THE RANDOMLY ASSIGNED CELL DOES NOT HAVE A
 VALUE
 if (cellboard[cellboardrandom] is not ('1' or '2' or '3' or '4'
 or '5' or '6' or '7' or '8' or '9')):
 cellboard[cellboardrandom] = solvingrandom
 
 The above is my code (right now it will only work for the first row's
 numbers).  Anything else I need to add?
 
Simplify your code a bit:

'2' is not ('1' or '2' or '3' or '4' or '5' or '6' or '7' or '8' or '9')
evaluates to True
'1' is not ('1' or '2' or '3' or '4' or '5' or '6' or '7' or '8' or '9')
evaluates to False
Somehow I do not believe you want that behavipur.

If cellboard contains characters, you could use:
if (cellboard[cellboardrandom] not in '123456789')

for integers, the following should work:
if not (1 = cellboard[cellboardrandom] = 9)

Using None to code empty cells, you could even have:
if (cellboard[cellboardrandom] is None)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Magnus Lycka schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
 Would it be too much to ask that in a line like.
 
   x = x + 1.
 
 both x's would resolve to the same namespace?

 They always do Antoon. There is no such issue for
 local (or global) varibles.

I meant those 'x' do be any general expression
that refers to an object. Like

  a.b[c.f] = a.b[c.f] + 1

 The issue has to do
 with c.x = c.x + 1. In this case it's clearly
 designed and documented that this corresponds to:

 setattr(c, 'x', getattr(c, 'x') + 1)

The issue is with c.x += 1

Sure I find the fact that the same reference two
times in the same line can reference variable
in two different namespaces ugly.

But that one single reference refers to two
variables in two different namespaces that is
IMO more than ugly.

Suppose I have the following:

class I:
  def __init__(self):
self.v = 0
  def __call__(self):
t = self.v
self.v += 1
return t

i = I()
lst = range(10)
lst[i()] += 20

Nobody seems to find that this should be treated
exactly the same as
lst[i()] = lst[i()] + 20

People seem to think since lst[i()] only occurs
once, it should be only refering to one entity.

Well I think the same kind of reasoning can apply
to c.x += 1.

 The result of these operations depends on e.g.
 how the __setattr__ and __getattr__ methods in
 the class in question are defined.

 You need to understand that the dot-operaterator
 always involves a lookup-operation that can be
 implemented in various ways.

But there is no reason that two dot-operator are
executed when only one dot-operator is in the text.

Just as there is no reason that two i() calls
should be made when only one call is in the text.

 It's well defined that you can do things like:

  class Counter:
 ... c=0
 ... def __call__(self):
 ... self.c+=1
 ... def __str__(self):
 ... return str(self.c)
 ...
  c=Counter()
  c()
  print c
 1
  c()
  print c
 2
  class C5(Counter):
 ... c=5
 ...
  c5=C5()
  c5()
  print c5
 6

 Of course, you could design a language, say Pythoon
 or Parthon, where this is illegal, and you force the
 programmer to do something longer such as:

  class APCounter:
 ... c=0
 ... def __init__(self):
 ... self.c = self.__class__.c
 ... def __call__(self):
 ... self.c+=1
 ... def __str__(self):
 ... return str(self.c)
 ...

 I don't see this as an improvement though...

Well I thought in python explicit was better than
implicit.

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


Re: XML DOM: XML/XHTML inside a text node

2005-11-04 Thread Walter Dörwald
[EMAIL PROTECTED] wrote:
 In my program, I get input from the user and insert it into an XHTML
 document.  Sometimes, this input will contain XHTML, but since I'm
 inserting it as a text node, xml.dom.minidom escapes the angle brackets
 ('' becomes 'lt;', '' becomes 'gt;').  I want to be able to
 override this behavior cleanly.  I know I could pipe the input through
 a SAX parser and create nodes to insert into the tree, but that seems
 kind of messy.  Is there a better way?

You could try version 2.13 of XIST (http://www.livinglogic.de/Python/xist)

Code looks like this:

from ll.xist.ns import html, specials

text = Number 1 ... the blarch/b

e = html.div(
html.h1(And now for something completely different),
html.p(specials.literal(text))
)
print e.asBytes()


This prints:
divh1And now for something completely different/h1pNumber 1 ... 
the blarch/b/p/div

I hope this is what you need.

Bye,
Walter Dörwald
-- 
http://mail.python.org/mailman/listinfo/python-list


ExpatError attributes

2005-11-04 Thread Daniel Nogradi
According to the documentation the xml.parsers.expat module provides the exception ExpatError and
this exception has 3 attributes, lineno, offset and code. I would like to use lineno, but can't.

ExpatError itself works, for example if I do

import sys
from xml.dom import minidom
from xml.parsers.expat import ExpatError

try:
 minidom.parse(my.xml)
except ExpatError:
 print 'The file my.xml is not well-formed.'


and then if the file my.xml is not well-formed, the program says so. Now I would like to tell the user
on which line the problem is in my.xml, and the attribute lineno is supposed to do just this. But if I have

import sys

from xml.dom import minidom

from xml.parsers.expat import ExpatError



try:

 minidom.parse(my.xml)

except ExpatError:

 print 'The file my.xml is not well-formed.'
 print 'And the problem is here: ', ExpatError.lineno

then I get an error message:

Traceback (most recent call last):
 File ./test, line 11, in ?
 print 'And the problem is here: ', ExpatError.lineno
AttributeError: class ExpatError has no attribute 'lineno'

So how can I access the line number on which an xml error occured?

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

Re: UART parity setting as mark or space (using Pyserial???)

2005-11-04 Thread Grant Edwards
On 2005-11-03, Petr Jakes [EMAIL PROTECTED] wrote:

 Using Pyserial it is possible to set the parity bit as ODD, EVEN or
 NONE.

Correct.  Those are the parity settings supported by pretty
much all platforms.

[...]

 Does anybody here knows some tricks how to set up the mark
 and space parity on the UART (using pyserial???),

What OS?  Mark and space parity are not supported by the Unix
termios API that is used to do serial port stuff.

 so I can simulate 9bit communication? (I know it sounds silly,
 but I would like to try to re-configure the UART parity before
 each byte transmission).

I suspect you're going to have to talk to the UART yourself to
do this.  

In addition to the problem with mark/space being unsupported,
you have to wait until each byte is completely sent (including
the parity bit) before changing the parity and loading the next
byte into the data register.  Many OSes drain functions are
notoriously inaccurate.

-- 
Grant Edwards   grante Yow!  Did I say I was a
  at   sardine? Or a bus???
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


strange sockets

2005-11-04 Thread Skink
Hi,

I'm preparing a python server that sends java classes and resources to
custom java class loader. In order to make it faster I don't want to use
URLClassLoader that uses HTTP protocol 1.0 and for each class/resource
creates own connection.
Instead I'd like to use raw sockets with simple protocol:

 - class loader sends a line terminated with \n with resource to get
 - python server reads that line, gets the file and sends back an
integer with file length and then the file itself
 - class loader reads a lenght integer and then reads the remainig data


The problem is when I try to read several files the first one is read
quite fast, but the rest is read 40 x slower. For example (time is in
seconds):

% python client.py client.py client.py client.py server.py server.py
init 0.00066089630127
client.py 0.000954866409302
client.py 0.0408389568329
client.py 0.0409188270569
server.py 0.0409059524536
server.py 0.0409259796143

what's wrong here?

thanks,
skink

client.py

import socket, sys, struct, time

HOST = 'localhost'
PORT = 8080
t1 = time.time()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
t2 = time.time()
print init, t2-t1
for arg in sys.argv[1:]:
t1 = time.time()
s.send(arg + \n)
len, = struct.unpack(!i, s.recv(4))
data = s.recv(len)
t2 = time.time()
print arg, t2-t1
s.close()


server.py

import socket, struct, binascii

HOST = ''
PORT = 8080
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
while 1:
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
f = conn.makefile()
while 1:
resource = f.readline().rstrip()
print [%s] % resource
if not resource:
break
data = open(resource, rb).read()
conn.sendall(struct.pack(!i, len(data)))
conn.sendall(data)
conn.close()

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Christopher Subich
Antoon Pardon wrote:
 Op 2005-11-03, Stefan Arentz schreef [EMAIL PROTECTED]:
The model makes sense in my opinion. If you don't like it then there are
plenty of other languages to choose from that have decided to implement
things differently.
 
 
 And again this argument. Like it or leave it, as if one can't in general
 like the language, without being blind for a number of shortcomings.
 
 It is this kind of recations that make me think a number of people is
 blindly devoted to the language to the point that any criticism of
 the language becomes intollerable.

No, it's just that a goodly number of people actually -like- the 
relatively simple conceputal model of Python.

Why /shouldn't/

 a.x = foo

correspond exactly to

 setattr(a,'x',foo) #?

Similarly, why shouldn't

 foo = a.x

correspond exactly to

 foo = getattr(a,'x') #?

With that in mind, the logical action for

 a.x = f(a.x)

is

 setattr(a,'x',f(a,'x')) #,

and since

 a.x += foo

is equal to

 a.x = A.__iadd__(a.x,foo) # (at least for new-style classes
  # that have __iadd__ defined.  Otherwise, it falls back on
  # __add__(self,other) to return a new object, making this
  # evern more clear),

why shouldn't this translate into

 setattr(a,'x',A.__iadd__(getattr(a,'x'),foo)) #?

Looking at it this way, it's obvious that the setattr and getattr may do 
different things, if the programmer understands that instances (can) 
look up object attributes, and (always) set instance attributes.  In 
fact, it is always the case (so far as I can quickly check) that += ends 
up setting an instance attribute.  Consider this code:

  class foo:
x = [5]
  a = foo()
  a += [6]
  a.x
[5,6]
  foo.x
[5,6]
  foo.x = [7]
  a.x
[5,6]

In truth, this all does make perfect sense -- if you consider class 
variables mostly good for setting defaults on instances.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-04 Thread Christopher Subich
Steven D'Aprano wrote:
 On Thu, 03 Nov 2005 14:13:13 +, Antoon Pardon wrote:
 
 
Fine, we have the code:

  b.a += 2

We found the class variable, because there is no instance variable,
then why is the class variable not incremented by two now?
 
 
 Because b.a += 2 expands to b.a = b.a + 2. Why would you want b.a =
 something to correspond to b.__class__.a = something?

Small correction, it expands to b.a = B.a.__class__.__iadd__(b.a,2), 
assuming all relevant quantities are defined.  For integers, you're 
perfectly right.
-- 
http://mail.python.org/mailman/listinfo/python-list


pycrypto rsa inverse of p modulo q

2005-11-04 Thread jt
Looking up into Crypto.PublicKey.RSA, I see there is a computed value
named u for which I can't see the use. The value of u is the
inverse of p modulo q, in the code:
obj.u = pubkey.inverse(obj.p, obj.q)
Can someone tell me where this value could be used in the RSA scheme?
(it is not used in the code anyway)

Thx,
-- 
jt

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


Re: __slots__ and class attributes

2005-11-04 Thread Ewald R. de Wit
Steven Bethard wrote:
 But why do you want a class level attribute with the same name as an 
 instance level attribute?  I would have written your class as:

 class A(object):
  __slots__ = ['value']
  def __init__(self, value=1):
  self.value = value

 where the default value you put in the class is simply expressed as a 
 default value to the __init__ parameter.

Thanks for your explanation. The reason why I was doing it was
to have class-level defaults, so that one can easily adjust how
new instances will be made. I'm doing it now with capitilized
class attribute names to avoid the name clash.

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


Re: I Need Motivation Part 2

2005-11-04 Thread projecktzero
[EMAIL PROTECTED] wrote:

 i m losing my motivation with python because there are sooo many
 modules

If you think Python has too many modules, then you better stay away
from Perl and CPAN. =)

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


Re: reading a config file

2005-11-04 Thread Larry Bates
When I need something like this I have employed the following:

[server_001]
blah = some server
destination=some destination

[server_002]
blah = some other server
destination=some other destination

[server_linux1]
blah = some other server
destination=some other destination


Then I do something like this:

import ConfigParser
INI=ConfigParser.ConfigParser()
INI.read(inifilename)
serversections=[x for x in INI.sections if x.startswith('server_')]
for serversection in serversections:
servername=serversection.split('_')[1]
#
# Code to operate on the servers here
#



Larry Bates


[EMAIL PROTECTED] wrote:
 hi
 i used ConfigParser to read a config file. I need the config file to
 have identical sections. ie :
 
 [server]
 blah = some server
 [destination]
 blah = some destination
 [end]
 end= ''
 
 [server]
 blah = some other server
 [destination]
 blah = some other destination
 [end]
 end=''
 
 and i need to check that every 'server' and 'destination' is followed
 by 'end'
 
 if i used the 'sections' method, it always show 'server' and
 'destination' and 'end'. how can i iterate all the sections. ie..
 
 for s in cfg.sections():
   do something...
 
 or is naming all the sections with different names is a better option?
 thanks
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ExpatError attributes

2005-11-04 Thread Fredrik Lundh
Daniel Nogradi wrote:

 According to the documentation the xml.parsers.expat module provides
 the exception ExpatError and this exception has 3 attributes, lineno, offset
 and code. I would like to use lineno, but can't.

 try:
 minidom.parse(my.xml)
 except ExpatError:
 print 'The file my.xml is not well-formed.'
 print 'And the problem is here: ', ExpatError.lineno

you're supposed to look at the exception instance, not the class
that defines it:

try:
minidom.parse(my.xml)
except ExpatError, v:
print 'The file my.xml is not well-formed.'
print 'And the problem is here: ', v.lineno

more here:

http://docs.python.org/tut/node10.html

/F 



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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Christopher Subich schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
 Op 2005-11-03, Stefan Arentz schreef [EMAIL PROTECTED]:
The model makes sense in my opinion. If you don't like it then there are
plenty of other languages to choose from that have decided to implement
things differently.
 
 
 And again this argument. Like it or leave it, as if one can't in general
 like the language, without being blind for a number of shortcomings.
 
 It is this kind of recations that make me think a number of people is
 blindly devoted to the language to the point that any criticism of
 the language becomes intollerable.

 No, it's just that a goodly number of people actually -like- the 
 relatively simple conceputal model of Python.

 Why /shouldn't/

 a.x = foo

 correspond exactly to

 setattr(a,'x',foo) #?

 Similarly, why shouldn't

 foo = a.x

 correspond exactly to

 foo = getattr(a,'x') #?

 With that in mind, the logical action for

 a.x = f(a.x)

 is

 setattr(a,'x',f(a,'x')) #,

 and since

 a.x += foo

 is equal to

 a.x = A.__iadd__(a.x,foo) # (at least for new-style classes
  # that have __iadd__ defined.  Otherwise, it falls back on
  # __add__(self,other) to return a new object, making this
  # evern more clear),

 why shouldn't this translate into

 setattr(a,'x',A.__iadd__(getattr(a,'x'),foo)) #?

Well maybe because as far as I understand the same kind of logic
can be applied to something like

lst[f()] += foo

In order to decide that this should be equivallent to

lst[f()] = lst[f()] + foo.

But that isn't the case.

So it seems applying augmented operators is not a matter of just
substituting straight translations to get the right result.


 Looking at it this way, it's obvious that the setattr and getattr may do 
 different things, if the programmer understands that instances (can) 
 look up object attributes, and (always) set instance attributes.  In 
 fact, it is always the case (so far as I can quickly check) that += ends 
 up setting an instance attribute.  Consider this code:

Looking at lists in a similar way, it would be obvious that the
__setitem__ and __getitem__ can do different things and so we
should expect lst[f()] += foo to behave exactly as lst[f()] = lst[f()] +
foo.

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


Threading- Stopping

2005-11-04 Thread Tuvas
Is there a way to stop a thread with some command like t.stop()? Or any
other neat way to get around it? Thanks!

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Antoon Pardon
Op 2005-11-04, Christopher Subich schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
 Op 2005-11-03, Stefan Arentz schreef [EMAIL PROTECTED]:
The model makes sense in my opinion. If you don't like it then there are
plenty of other languages to choose from that have decided to implement
things differently.
 
  class foo:
x = [5]
  a = foo()
  a += [6]
  a.x
 [5,6]
  foo.x
 [5,6]
  foo.x = [7]
  a.x
 [5,6]

 In truth, this all does make perfect sense -- if you consider class 
 variables mostly good for setting defaults on instances.

Except when your default is a list

class foo:
  x = [] # default

a = foo()
a.x += [3]

b = foo()
b.x

This results in [3]. So in this case using a class variable x to
provide a default empty list doesn't work out in combination
with augmented operators.

This however would work:

class foo:
  x = [] # default

a = foo()
a.x = a.x + [3]

b = foo()
b.x

This results in []

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
On Fri, 04 Nov 2005 09:03:56 +, Antoon Pardon wrote:

 Op 2005-11-03, Steven D'Aprano schreef [EMAIL PROTECTED]:
 On Thu, 03 Nov 2005 13:01:40 +, Antoon Pardon wrote:

 Seems perfectly sane to me. 

 What would you expect to get if you wrote b.a = b.a + 2?
 
 I would expect a result consistent with the fact that both times
 b.a would refer to the same object.

 class RedList(list):
 colour = red

 L = RedList(())

 What behaviour would you expect from len(L), given that L doesn't have a
 __len__ attribute?
 
 Since AFAICT there is no single reference to the __len__ attribute that
 will be resolved to two different namespace I don't see the relevance.

Compare:

b.a += 2

Before the assignment, instance b does not have an attribute a, so class
attribute a is accessed. You seem to be objecting to this inheritance.

len(L) = L.__len__()

Instance L also does not have an attribute __len__, so class attribute
__len__ is accessed. You don't appear to object to this inheritance.

Why object to one and not the other?

If you object to b.a resolving to b.__class__.a, why don't you object to
L.__len__ resolving to L.__class__.__len__ also?

Perhaps you don't object to that half of the problem. Perhaps you object
to the assignment: you expect that assigning to b.a should assign to
b.__class__.a instead.

Should assigning to L[0] assign to L.__class__[0] also, so that all
lists share not only the same behaviour, but also the same data?


[snip]
 
 b is a name, and any reference to b (in the same namespace) will refer
 to the same object. At least until you rebind it to another object.
 
 But some namespaces take great care not to allow a rebinding that would
 result in the same name being resolved to a different namespace during
 this namespace's lifetime.

And some take great care to allow such a rebinding, because that is the
right thing to do to make inheritance work correctly.


 But b.a is not a name, it is an attribute lookup,
 
 An other implementation detail. b.a is a name search of 'a' in the
 namespace b.

Factually incorrect. b.a is the name search for 'a' in the namespaces
[note plural] of b, b.__class__, and any superclasses of b, *in that order*.

Do you object to import searching multiple directories?

Why do you object to attribute resolution searching multiple namespaces?


[snip]
 I think it even less sane, if the same occurce of b.a refers to two
 different objects, like in b.a += 2

 Then it seems to me you have some serious design problems. Which would
 you prefer to happen?

 # Scenario 1
 # imaginary pseudo-Python code with no inheritance: class Paragraph:
 ls = '\n'  # line separator

 para = Paragraph()
 para.ls

= AttributeError - instance has no attribute 'ls'


 # Scenario 2
 # imaginary pseudo-Python code with special inheritance: 
 class Paragraph:
 ls = '\n'  # line separator

 linux_para = Paragraph()
 windows_para = Paragraph()
 windows_para.ls = '\n\r'  # magically assigns to the class attribute
 linux_para.ls

= prints '\n\r'

 # Scenario 3
 # Python code with standard inheritance: 
 class Paragraph:
 ls = '\n'  # line separator

 linux_para = Paragraph()
 windows_para = Paragraph()
 windows_para.ls = '\n\r'
 linux_para.ls

= prints '\n'


 I don't see the relevance of these pieces of code. In none of them is
 there an occurence of an attribute lookup of the same attribute that
 resolves to different namespaces.

Look a little more closely. In all three pieces of code, you have a
conflict between the class attribute 'ls' and an instance attribute 'ls'.

In the first scenario, that conflict is resolved by insisting that
instances explicitly define an attribute, in other words, by making
instance attribute ONLY search the instance namespace and not the class
namespace.

In the second scenario, that conflict is resolved by insisting that
instance.name assigns to instance.__class__.name, just as you asked for.

The third scenario is the way Python actually operates.



-- 
Steven.

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


Re: Web automation with twill

2005-11-04 Thread qwweeeit
Hi Michele,
I taught to be the smartest in town!
But when the experts take the field it is better that us newbies
retire in good order...
Thank you for your article and, with respect to Grig Gheorghiu
(another expert), I must apologize for having be a little rude.

I hadn't discovered in Internet your contributions because I
hardly read the first 10 hits of a search.
I need web automation also for that (in order to elaborate more search
results reducing then my help requests and mainly my useless posts).

By the way, are you aware that C. Titus Brown (twill's author)
tells peste e corna of Zope?
Bye.

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


How can I do this in Python?

2005-11-04 Thread Lad
Hi,
I have a web program and a user can have access to a page only after he
logged in.
So, the program comes with  a Login form and the user logins.But I do
not know how to return the user back to where he came from, after a
successful login.

Something like this:

PageWhereUserMustBeLogin UserSigned--

^-|


Thank you for help

L.

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Christopher Subich
Antoon Pardon wrote:
Since ints are immutable objects, you shouldn't expect the value of b.a
to be modified in place, and so there is an assignment to b.a, not A.a.
 
 
 You are now talking implementation details. I don't care about whatever
 explanation you give in terms of implementation details. I don't think
 it is sane that in a language multiple occurence of something like b.a
 in the same line can refer to different objects
 

This isn't an implementation detail; to leading order, anything that 
impacts the values of objects attached to names is a specification issue.

An implementation detail is something like when garbage collection 
actually happens; what happens to:

b.a += 2

is very much within the language specification.  Indeed, the language 
specification dictates that an instance variable b.a is created if one 
didn't exist before; this is true no matter if type(b.a) == int, or if 
b.a is some esoteric mutable object that just happens to define 
__iadd__(self,type(other) == int).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help converting some perl code to python

2005-11-04 Thread [EMAIL PROTECTED]
The '..' operator is the flip-flop operator in perl. (It is rarely
used.) It is exactly the same as the 'range' type operator. It returns
false until the first condition is met, then it returns true until the
last condition met, then it returns false.

You could create a flip-flop with a python closure (t_cond and f_cond
are functions that take a value and return True of False)

def make_flip_flop(t_cond, f_cond):
state = [False]
def flip_flop(val):
if state[0] and f_cond(val):
state[0] = False
elif not state[0] and t_cond(val):
state[0] = True
return state[0]
return flip_flop

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


Re: Web automation with twill

2005-11-04 Thread Michele Simionato
qwwwee:
 By the way, are you aware that C. Titus Brown (twill's author)
 tells peste e corna of Zope?

No, but I am not surprised.  I also say peste e corna of Zope ;)
In general I am an anti-frameworks guy (in good company with
many Pythonistas including Guido).

  Michele Simionato

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


Re: Class Variable Access and Assignment

2005-11-04 Thread Christopher Subich
Antoon Pardon wrote:
 Well I wonder. Would the following code be considered a name binding
 operation:
 
   b.a = 5

Try it, it's not.

Python 2.2.3 (#1, Nov 12 2004, 13:02:04)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-42)] on linux2
Type help, copyright, credits or license for more information.
  a
Traceback (most recent call last):
   File stdin, line 1, in ?
NameError: name 'a' is not defined
  b = object()
  b.a
Traceback (most recent call last):
   File stdin, line 1, in ?
AttributeError: 'object' object has no attribute 'a'

Once it's attached to an object, it's an attribute, not a base name. 
The distinction is subtle and possibly something that could (should?) be 
unified for Py3k, but in cases like this the distinction is important.
-- 
http://mail.python.org/mailman/listinfo/python-list


Shareware in Python

2005-11-04 Thread Ivan Sas
I want to create some shareware program in Python. Can I distribute
this program with
python24.dll file from Python 2.4.2?  I'm not sure if Python GPL
compatible license allowing for doing it.
Thanks,
Ivan Sas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I Need Motivation Part 2

2005-11-04 Thread Rocco Moretti
[EMAIL PROTECTED] wrote:
 i m losing my motivation with python because there are sooo many 
 modules, that i cant just learn them all, 

As other's have said, don't bother.

If you ever need to use a module that you don't know, just go to 
http://docs.python.org/lib/lib.html (easily accessable from the 
Documentation link on the Python Home page), or a local copy, and 
scrounge around.

I might suggest skimming it once, to see what is possible, but it isn't 
nessasary to learn it. -- Knowing that there is a Python module in the 
standard library to do CSV/Date manipulation/MD5/etc is sufficient. You 
don't even need to know what the module is called - a minute skimming 
the TOC will point you in the right direction.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learning multiple languages (question for general discussion)

2005-11-04 Thread Alex Martelli
Magnus Lycka [EMAIL PROTECTED] wrote:

 Alex Martelli wrote:
  Yes, but I haven't found knowing (and using) Python dampens my
  enthusiasms for learning new languages.
 
 But you're more enthusiatic than most of us Alex. I wish
 I could say the same, but I must admit that I only did
 halfhearted attempts at learning new languages after Python.
 I've looked a bit at most of the ones you mentioned, but
 there was nothing that gave me the drive to really follow
 it through. I've somehow become content in this regard.

I can't imagine NOT getting enthusiastic and stimulated by reading Van
Roy and Hariri's book -- it IS quite as good and readable as SICP.
Ruby's also blessed with good books (and the excellent Rails, too).


 This doesn't mean that I'm not evolving. I regularly program
 in three languages (Python, C++ and SQL) and I must learn
 new things the whole time to keep interested, whether it's
 in the current problem domain, in architectural matters, in
 regards to libraries or development tools or whatever. Now

I agree, languages are not the only thing worth learning -- they just
tend to be more fun (although big frameworks compete with them for this
distinction;-).  Knuth's latest work is always stimulating, too, even
though the new RISC MIX isn't particularly so;-).

 it's Twisted for instance. Still, finding Python was a lot
 like finding a permanent home (which doesn't exclude various
 excursions, or prevent another move or two in this life.)

Yes, good analogy, I think -- just the right mix of elegance and
practicality one would look for in one's home!-)


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


Re: Class Variable Access and Assignment

2005-11-04 Thread Magnus Lycka
Graham wrote:
 My question remains however, i suppose i'm not familiar with how this
 functions in
 other languages, but what is the common way of referring to a class
 variable.
 
 is class.var the norm?
 or instance.var the norm.

It's not always that easy, due to inheritance. You might want
the var defined in the class where a method you define now
is implemented (A.var if we're in a method defined in class A),
or you might want var in the class of the instance object
(which could be a subclass of A). You can get that through
self.__class__.var, so I guess you could always manage without
Python searching in the class scope after searching the instance
scope, if it wasn't for the problem below...

 I just seems to me that instance.var shouldn't defer to the class
 variable if
 an instance variable of the same name does not exists, it should, at
 least how i
 understand it raise an exception.

So, you want this:

  class A:
... def f(self):
... print 'Hello'
...
  a = A()
  a.f()
Traceback (most recent call last):
   File stdin, line 1, in ?
AttributeError: A instance has no attribute 'f'

A bit boring that we need to make method calls
with a.__class__.f(a) in your Python...

Python is more consistent than you have thought...
You know, it could be that we want to assign the
method to another variable, as in:

o = A()
o_f = o.f # This might look as I'm getting a normal
   # attribute, but f is a method
for i in range(gazillion):
 o_f() # This is slightly faster than o.f()

Or, we might want to do:
o.f=len
o.f('Hello')

Here, o.f is no longer a method in o's class hierarchy, but
it's still callable.

If you think about it, you'll understand that in such a dynamic
language as Python, there is no way that the interpreter can
know before lookup whether it will find a method or a simple
attribute. If it's going to look in different places depending
on what it will find when it has looked...we have a Catch 22.

Normal methods in Python are defined in the scope of the class,
and they are passed the instance object as their first argument
when they are called. The call (where the instance object is
implicitly called in case of a bound method) is something that
comes after the lookup, as you can see in the a_f() example.

Python is *very* dynamic. The behaviour of the class can change
after the instance has been created.

  class A:
... def f(self):
... print 'Hello'
...
  a = A()
  a.f()
Hello
  del A.f
  a.f()
Traceback (most recent call last):
   File stdin, line 1, in ?
AttributeError: A instance has no attribute 'f'

How would this work if 'a.f' doesn't cause a lookup in A if it's
missing in a? Do you want a.f to first search the instance a, then
the class A, and if it finds f in A, issue an AttributeError if it
turns out that f isn't a method?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cheapest pocket device to code python on

2005-11-04 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
 What is the cheapest/affordable pocket device that I can code python
 on? I think the closest I have seen is pocketpc from this page:

A used Fujitsu Lifebook running Linux and fairly large pockets? ;)

There is some version of Python running on Palms, but it's stripped
down, and I haven't tried it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-04 Thread Magnus Lycka
Antoon Pardon wrote:
   I have looked and didn't find it in the language reference.
 
 This is what I have found:
 
 An augmented assignment expression like x += 1 can be rewritten
 as x = x + 1 to achieve a similar, but not exactly equal effect.

It's just a little further down. I'll post the quote once more (but
this is the last time ;^):

For targets which are attribute references, the initial value is 
retrieved with a getattr() and the result is assigned with a setattr(). 
Notice that the two methods do not necessarily refer to the same 
variable. When getattr() refers to a class variable, setattr() still 
writes to an instance variable. For example:

class A:
 x = 3# class variable
a = A()
a.x += 1 # writes a.x as 4 leaving A.x as 3

I'd say it's documented...

 That doesn't change the fact that the current behaviour is
 on occasions awkward or whatever you want to call it.

I fear that this has to do with the way reality works. Perhaps
it's due to Gödel's incompleteness theorems... :)

Sure, Python has evolved and grown for about 15 years, and
backward compatibility has always been an issue, but the
management and development of Python is dynamic and fairly
open-minded. If there had been an obvious way to change this
in a way that solved more problems than it caused, I suspect
that change would have happened already.

 I also find that people underestimate the magic that
 is going on in python. But just because you are familiar with
 the magic, doesn't make it less magic. IMO python shows its
 history a little. 

If Guido would design a new language today, that was aiming at
the kind of tasks Python solves, I'm sure it wouldn't be identical
to the current Python. The languages I'm most experienced in besides
Python are C++ and SQL. Compared to those beasts, Python is a wonder
in clarity and consistency. I don't think a single vendor has managed
to fully implement the SQL standard, and it's known that the standard
contains bugs, inconsitencies and gaps, even though (or because) it's
been worked on for more than 20 years. The C++ spec is marginally
better. Of course, there isn't a formal specification for Python. I
don't know if the language reference is so complete that someone
could actually write another really compatible Python implementation
based on just the reference manual. Still the difference is drastic.
I suspect that only few people in the SQL standard committee fully
understand the spec (maybe C.J. Date and Hugh Darwen does) and all
the things happening under the hood in C++ is staggering, considering
that this language is really just a fancy assmbler that can't even
manage memory for the programmer!

 I'm after nothing particular. The only thing I'm frustrated about
 is the way in which some people seem willing to defend python
 just because it is python. If the only reaction I would have
 gotten would have been something like: Yeah that seems a bit
 awkward but fixing this would break more than it would cure,
 I would have left it as it is.

That's probably what most people think, but we're not entirely
rational. We're human. An emotional posting will probably attract
equally emotional responses.

 I have rarely indicated I wanted things to be fixed. Sure I would
 like it if some things were different, but I recognize that there
 are more important things that needs to be resolved.
 
 Does that mean I shouldn't mention things that IMO could have been
 better or that I should only mention them in the softest of
 language that certainly can't be interpreted as emotional language.

Personally, I want comp.lang.python to work as a way for me to learn
new things about Python, to get help if I'm stuck with something, and
as a way for me to inform others about Python stuff. It's also a part
of the Python community--an arena where I communicate with other
Pythonistas. This is something important for me, both professionally
and personally. I try to think an extra time before I post messages.
It this message meaningful? Does it add anything of value? Am I just
repeating what is already said? Is this message likely to have some
kind of positive impact or will it just be ignored? Might I hurt
someone? Am I building useful relationships?

When it works as it should, people you've never met before will buy
you beer or lunch when you happen to be in their neighbourhood. At
least they might come up to you and chat if you go to a Python
conference. They might also offer you jobs or contracts etc. This
is really nice and valuable. Something to handle with care.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Not Equal to Each Other?

2005-11-04 Thread [EMAIL PROTECTED]
  will I have to write that out for each number?

Not if you know how to use the 'for' statement. It will allow you to
iterate through the rows or columns or whatnot.

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


Re: Shareware in Python

2005-11-04 Thread David Wahler

Ivan Sas wrote:
 I want to create some shareware program in Python. Can I distribute
 this program with
 python24.dll file from Python 2.4.2?  I'm not sure if Python GPL
 compatible license allowing for doing it.
 Thanks,
 Ivan Sas

Python is distributed under its own license, not the GPL: see
http://www.python.org/2.4.2/license.html for details. I've just skimmed
it, and it looks like you're fine as long as you include the Python
license agreement and copyright notice.

-- David

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


Re: Threading- Stopping

2005-11-04 Thread David Wahler
Tuvas wrote:
 Is there a way to stop a thread with some command like t.stop()? Or any
 other neat way to get around it? Thanks!

Sadly, no. While Java and many other programming languages have an
interrupt() primitive, Python does not. You can approximate this by
using a global variable to tell the thread when to stop, for example:

shutdown = False

class MyThread(Thread):
def run(self):
while not shutdown:
# do whatever

def kill_thread():
shutdown = True

There's no general way to wake up a thread that's blocked--you have to
satisfy the condition that's causing it to block. If it's waiting for
input from a Queue, you have to push a dummy value down it to wake up
the thread and give it a chance to check the shutdown flag. If it's
blocking to do I/O, you'll have to use select() and provide a timeout
value to check the flag periodically.

-- David

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


Re: How can I do this in Python?

2005-11-04 Thread David Wahler
Lad wrote:
 Hi,
 I have a web program and a user can have access to a page only after he
 logged in.
 So, the program comes with  a Login form and the user logins.But I do
 not know how to return the user back to where he came from, after a
 successful login.

 Something like this:

 PageWhereUserMustBeLogin UserSigned--

 ^-|


 Thank you for help

 L.

You'll need to either use a hidden form field or check the HTTP
Referer header to determine the page the user was on. Then, just use
an HTTP redirect to send them back to that page.

Are you using a particular web application framework, or separate CGI
scripts?

-- David

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


Re: Cheapest pocket device to code python on

2005-11-04 Thread Cameron Laird
In article [EMAIL PROTECTED],
Sybren Stuvel  [EMAIL PROTECTED] wrote:
Devan L enlightened us with:
 I would not recommend trying to code on a handheld device. Small
 screen size and [usually] small keyboards make it
 less-than-practical. Stick with a laptop, or write it in a notebook,
 if you must.

Although it isn't the pinnacle of usability, I can program just fine
on my Sharp Zaurus C3000.

Having said that, a real PC is a lot nicer to work on. But then, if
you want to have a really portable programming thiny, the Zaurus is
great.

Not too cheap though.
.
.
.
A colleague who works with Tcl (for this purpose, think of it
as Python, except different) achieves stunning results with
his tiny PocketPC Magician.  For inspiration, see URL:
http://wiki.tcl.tk/HTC%20Magician .  Richard makes me want
such a device, even though I orient exceedingly strongly to
full-size keyboards.  Incidentally, the Samsung 730 is another
I'm considering.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML DOM: XML/XHTML inside a text node

2005-11-04 Thread uche . ogbuji

In my program, I get input from the user and insert it into an XHTML
document.  Sometimes, this input will contain XHTML, but since I'm
inserting it as a text node, xml.dom.minidom escapes the angle brackets
('' becomes 'lt;', '' becomes 'gt;').  I want to be able to
override this behavior cleanly.  I know I could pipe the input through
a SAX parser and create nodes to insert into the tree, but that seems
kind of messy.  Is there a better way?


Amara 1.1.6 supports inserting an XML fragment into a document or
element object.  Many short examples here:

http://copia.ogbuji.net/blog/2005-09-21/Dare_s_XLI

excerpt:

Adding a phone element as a child of the contact element'

contacts.xml_append_fragment('phone%s/phone'%'206-555-0168'

http://uche.ogbuji.net/tech/4suite/amara

--
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

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


exec behaviour

2005-11-04 Thread N. Pourcelot
Hello,
I can't understand some specific behaviour of the exec statment.

For example, say that I create such a class A :

class A:
 def __init__(self):
 self.n = 3
 self.m = None
 def h(self, ini):
 n = self.n
 m = self.m
 if ini: exec(def m(x): return n+x); self.m=m
 else: m(7)

Now :
obj = A()
obj.h(1)
obj.h(0)

I get :

Traceback (most recent call last):
   File input, line 1, in ?
   File input, line 9, in h
   File string, line 1, in m
NameError: global name 'n' is not defined

Now, suppose I would like to make exactly the same without exec :

class A:
 def __init__(self):
 self.n = 3
 self.m = None
 def h(self, ini):
 n = self.n
 m = self.m
 if ini:
 def m(x): return n+x
 self.m=m
 else: return m(7)

je lance :
obj = A()
obj.h(1)
obj.h(0)

This time, it works fine !!!

If I knew why the first doesn't work, and the second does, it would be a 
great help for me for my program...

Thank you very much !
-- 
http://mail.python.org/mailman/listinfo/python-list


how to open a windows folder?

2005-11-04 Thread Bell, Kevin
I'd love to be able to open up a windows folder, like c:\temp, so that
it pops up visually.  I know how to drill down into a directory, but I
can't figure out how to open one up on screen.  Would I have to make a
call to windows explorer in a similar way that I hit Excel with:

from win32com.client import Dispatch
Excel = Dispatch(Excel.Application)

Any clues?

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


RE: how to open a windows folder?

2005-11-04 Thread Tim Golden
[Bell, Kevin]

 I'd love to be able to open up a windows folder, 
 like c:\temp, so that it pops up visually.  
 I know how to drill down into a directory, but I
 can't figure out how to open one up on screen.  
 Would I have to make a call to windows explorer 
 in a similar way that I hit Excel with:

Ummm. I may have misunderstood you, but would
either of:

import os
os.startfile (c:/temp)

# or

import os
os.system (rexplorer c:\temp)

be what you wanted?

TJG


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

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


Re: how to open a windows folder?

2005-11-04 Thread Larry Bates
Not elegant but this works:

import os
os.system(r'start explorer.exe C:\temp')

-Larry Bates

Bell, Kevin wrote:
 I'd love to be able to open up a windows folder, like c:\temp, so that
 it pops up visually.  I know how to drill down into a directory, but I
 can't figure out how to open one up on screen.  Would I have to make a
 call to windows explorer in a similar way that I hit Excel with:
 
   from win32com.client import Dispatch
   Excel = Dispatch(Excel.Application)
 
 Any clues?
 

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


RE: how to open a windows folder? THANKS!

2005-11-04 Thread Bell, Kevin

import os
os.startfile (c:/temp)

That was painless and did the trick!

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


  1   2   3   >