Re: Getting rid of "self."

2005-01-09 Thread Tim Roberts
BJörn Lindqvist <[EMAIL PROTECTED]> wrote:

>I think it would be cool if you could refer to instance variables
>without prefixing with "self." I know noone else thinks like me so
>Python will never be changed, but maybe you can already do it with
>Python today?
>
>.import sys
>.
>.def magic():
>.s = ""
>.for var in sys._getframe(1).f_locals["self"].__dict__:
>.s += var + " = self." + var + "\n"
>.return s
>.
>.class A:
>.def __init__(self):
>.self.hi = "yo"
>.
>.def meth(self):
>.exec(magic())
>.print hi
>.
>.a = A()
>.a.meth()
>
>It works! exec(magic()) does the needed hi = self.hi. 

Does it?

class A:
   def __init__(self):
   self.hi = "yo"

   def meth(self):
   exec(magic())
   print hi
   hi = "baby"
   print hi

   def other(self):
   exec(magic())
   print hi

a = A()
a.meth()
a.other()

That's way too fragile to be useful.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyparsing: how to negate a grammar

2005-01-09 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> I want to define a rule for a line that does NOT start with a given
> Literal. How do I do that? I try the following and my program just hang
> there:
>
> BodyLine = ~Literal("HTTP/1.1") + restOfLine
>
> Thanks,
> Khoa
>
Khoa -

pyparsing can be run in several modes, one of which tokenizes and extracts
data according to a given grammar, one of which scans for pattern matches,
and one which translates matched patterns into other patterns.  Its not
clear from your e-mail what you are trying to do.  There is nothing in your
statement that would cause Python to "just hang there", what else is your
program doing?

-- Paul



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


Re: The best way to do web apps with Python?

2005-01-09 Thread Ian Bicking
Steve Holden wrote:
More ways than you can shake a stick at, but nowadays you should 
consider using WSGI if you want your code to be portable across many 
frameworks. The Web SIG worked very hard last year on defining this 
gateway interface, with the intention that it should become widely 
available, and implementations are available now on environments as 
diverse as mod_python and CherryPy.

You can read about it in Philip Eby's excellent PEP at
  http://www.python.org/peps/pep-0333.html
WSGI isn't really something an application programmer can use; or at 
least it's not likely to be a very satisfying experience if they do. 
I'm optimistic that at some point most of the actively developed Python 
web frameworks we have now will be ported to WSGI.  Ultimately, I think 
WSGI should be something a more casual Python web programmer wouldn't 
even realize exists.

--
Ian Bicking  /  [EMAIL PROTECTED]  / http://blog.ianbicking.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Carlos Ribeiro
On Sun, 09 Jan 2005 15:54:08 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote:
> Here's another nice one if 'where' is added to compound statements as well:
> 
> @dbc(pre, post)
> def foo():
>pass
> where:
>def pre():
>  pass
>def post():
>  pass

Interesting. It solves some of the issues with chosing a clear syntax
for "design by contract" and other similar features that were being
debated lately. I also thought about his one:

! def foo(x=calculate_default_value()):
! pass
! where:
! def calculate_default_value():
! ...
! return 


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


Re: complex numbers

2005-01-09 Thread Jürgen Exner
[EMAIL PROTECTED] wrote:
> #python supports complex numbers.
[...]

So?

> # Perl doesn't support complex numbers. But there are packages that
> supports it.

The Math::Complex module is part of the standard installation already, no 
need for any "packages" (whatever that might be).
Did you check "perldoc Math::Complex"

NAME
Math::Complex - complex numbers and associated mathematical functions
[...]

jue 


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


Re: The best way to do web apps with Python?

2005-01-09 Thread Carlos Ribeiro
On Sat, 8 Jan 2005 21:11:49 +0800, worzel <[EMAIL PROTECTED]> wrote:
>  
> What is the best way to web developemnt with Python? Is there anything close
> to PHP style in-page script placement that can create and use other Python
> objects? I am not really interested in Zope (I believe that is more a CMS
> than anything else?) I am also looking for something a little more
> structured than a series of CGI Scripts. 
>   
> While on the topic - what is the expectataion of Python for this kind of
> stuff? Would one use Python for certain other things but turn to PHP for web
> apps - or would one use their Python skills in place of PHP? 

Check CherryPy - www.cherrypy.org. It's clean, light, and best of all,
includes its own webserver. You can publish a small site with almost
*no* configuration effort, and you have to write *very little code*.
It's also natively multi-threaded, and supports advanced stuff such as
gzip compression on the fly and XMLRPC.

Disclaimer: I'm a contributor to CherryPy, so I'm biased. But I had
evaluated both Karirgel and Quixote before settling up on CherryPy,
and I see no reason to change.

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


Re: unicode support

2005-01-09 Thread Jürgen Exner
[EMAIL PROTECTED] wrote:
> # -*- coding: utf-8 -*-
> # python supports unicode in source code by putting a coding
> declaration
> # as the first line.

So?

> In perl, support of unicode is very flaky. The language does not
> support it, but packages that changes behaviors of string handling (in
> its regex, for instance.)

Really? You may want to check your sources. They seem to be a little bit 
outdated, like several years old?

jue 


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


Re: curses is not imported under Linux (and Python 2.4)

2005-01-09 Thread Konrad Koller
Thanks for your hint.
>What Linux distro?
SuSE 9.1
>Is the Python version you're running one you compiled, one that shipped
>with the distro, or a 3rd party RPM?
compiled with Python-2.4.tar.bz2
>
>At a guess, I'd say you compiled it yourself and you don't have the
>ncurses development packages (providing the ncurses header files and
>static libs) installed.
see above, but I did not exclude anything, it was a totally normal
run.
I did the same installation of Python2.4 on a different computer with
Fedora2 and found there  the  _curses.so and  _curses_panel.so in
lib-dynload, which I missed in SuSE Linux, although under SuSE the
curses package was present in Lib. I don't understand this strange
behavior between the two installations.
After having the 2 mentioned static libs transfered from the "Fedora
computer"  to the the  "SuSE computer"  the curses worked fine under
SuSE linux

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


Re: The best way to do web apps with Python?

2005-01-09 Thread Jon Perez
worzel wrote:
What is the best way to web developemnt with Python? Is there anything 
close to PHP style in-page script placement that can create and use 
other Python objects? 
Spyce ( http://spyce.sf.net )  is what you're looking for.  I
was looking exactly for the same thing as you are - a PHP workalike -
and tried around half a dozen or so alternatives before I settled
upon Spyce as the best one.
If Spyce's [[ and ]] delimiters are not to your liking, you can
actually switch to using <% and %> without any problem.  Spyce
also handles the Python indent issue quite nicely and elegantly,
imo, while you can use the free and open source SciTE text editor
to separately syntax highlight Spyce source code + Javascript + HTML
very nicely (config file tweaking required).
what is the expectataion of Python for this kind of 
stuff? Would one use Python for certain other things but turn to PHP for 
web apps - or would one use their Python skills in place of PHP?
Python can be a full (and superior) replacement for PHP.  The only
caveat would be third party hosting support.
The following post by on the Spyce mailing list (by Andy of
Neotitans.com web development) explains why:
"One major roadblock to Spyce and other Python server side
technologies seeing acceptance on the scale of PHP is the
fact that mod_python deployment on 3rd party shared hosting
solutions is more complex and involved than mod_php.  Apparently,
security considerations mean that each mod_python user will need
to get their own instance of an Apache server acting as a proxy
behind a central instance of an Apache server (which is what's
responsible for accepting requests at the shared server's http port).
A per-shared user Spyce proxy server approach would likely be
more economical (of server resources) and more easily set up than
multiple mod_python-enabled Apache server instances.
If your hosting solution will permit you to have your own
long-running processes (afaik, most won't :-( ), and if they
are willing make the necessary httpd.conf mods to pass Spyce
page requests over to your own instance of the Spyce proxy
server or their .htaccess setup allows you to do that yourself,
then you're all set.
I'm also happy to report that Spyce CGI works great on any
hosting solution that supports CGI and has Python installed.
This means that virtually all Linux-based hosting solutions
(including those ultra-cheap shared server ones) will support
Spyce CGI.
It would seem that FastCGI support is probably the hardest to
come by."
--
http://mail.python.org/mailman/listinfo/python-list


Re: The best way to do web apps with Python?

2005-01-09 Thread Paul Rubin
Steve Holden <[EMAIL PROTECTED]> writes:
> You can read about it in Philip Eby's excellent PEP at
> 
>http://www.python.org/peps/pep-0333.html

I looked at this and I have the impression that it tries to do
something worthwhile, but I can't tell precisely what.  The "rationale
and goals" section explains good reasons why it doesn't do various
certain things.  What's not explained is what DOES it do.  The only
thing I can tell is that it connects to an abstracted web server, and
builds up what looks like traditional CGI variables from the incoming
requests.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Display Function Code Body?

2005-01-09 Thread Fernando Perez
Haibao Tang wrote:

> 
> Hail Python pals! I played with the R (http://r-project.cran.org) last
> night to do some statistics and it has an interactive session too, and
> I found a feature that is quite useful.

[...]

> # or any shallow function code from a file
 import calendar; disp(calendar.isleap)
> 
> def isleap(year):
> """Return 1 for leap years, 0 for non-leap years."""
> return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
> 
> 
> # surely the compiled function code cannot be displayed
 disp(blabla)
> 
> : internal/compiled function
> 
> 
> Can someone please point out how this can be achieved nicely. I've
> tried some text searching approach, too dirty I must say.
> Oh! Thank you ...

[~/tmp]> ipython
Python 2.3.4 (#1, Oct 26 2004, 16:42:40)
Type "copyright", "credits" or "license" for more information.

IPython 0.6.7_rc1 -- An enhanced Interactive Python.
?   -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help-> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import calendar

In [2]: calendar.isleap??
Type:   function
Base Class: 
String Form:
Namespace:  Interactive
File:   /usr/src/build/475206-i386/install/usr/lib/python2.3/calendar.py
Definition: calendar.isleap(year)
Source:
def isleap(year):
"""Return 1 for leap years, 0 for non-leap years."""
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)


Note that the source display won't work for interactively defined functions,
because their source is thrown away by the bytecode compiler.  There are
discussions of a PEP for adding a __source__ attribute to functions which would
solve this limitation, but that is still in the future.

Cheers,

f

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


Re: Pre/Postconditions with decorators

2005-01-09 Thread Stephen Thorne
On 08 Jan 2005 15:50:48 -0800, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> Stephen Thorne <[EMAIL PROTECTED]> writes:
> > Unresolved Problems:
> > 1) How do you handle duck types, i.e. a method that accepts StringIO,
> > cStringIO or any other object that has a .readlines(), .seek() and
> > .read() method?
> 
> That should really be done through having those classes inherit a
> file-operations mixin, or else through interfaces (which might get
> added to Python).
Working under the assumption we cannot change the existing standard library.

> > 2) How do you turn off the type checking for production code?
> 
> It should be left on.  Leaving it in for development and turning it
> off for production is like wearing a parachute during ground training
> and taking it off once you're in the air.
So we can't use this for a case where we have an extremely large list
then ;). Its an O(n) operation to just call a function that takes a
list of a specific type.

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


Re: python3: accessing the result of 'if'

2005-01-09 Thread Andrey Tatarinov
Carl Banks wrote:
As a compromise, howabout:
. if m > 20 where m=something():
. do_something_with(m)
That's good, but first idea was about 'where' block that contains any 
expressions, that we need, for example function definition. the syntax 
you proposed has same problems as 'lambda'.

The main problem here (as some would see it) is that you can't do
something this:
. if m > 20 where (def m(): a(); b()):
exactly
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pre/Postconditions with decorators

2005-01-09 Thread Paul Rubin
Stephen Thorne <[EMAIL PROTECTED]> writes:
> > It should be left on.  Leaving it in for development and turning it
> > off for production is like wearing a parachute during ground training
> > and taking it off once you're in the air.
> So we can't use this for a case where we have an extremely large list
> then ;). Its an O(n) operation to just call a function that takes a
> list of a specific type.

The condition should be enforced at the time whenever list itself is
mutated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
Peter Hansen wrote:
 >>> print words[3], words[5] where:
 >>> words = input.split()
- defining variables in "where" block would restrict their visibility 
to one expression
Then your example above doesn't work...  print takes a
sequence of expressions, not a tuple as you seem to think.
sorry, I used "expression" carelessly.
I mean that
>>> print words[3], words[5]
is a single expression
(and that would be in Python 3, when print would be subtituted with 
write()/writeln()).
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Alex Martelli
AdSR <[EMAIL PROTECTED]> wrote:

> I don't know haskell, but it looks SQL-ish to me (only by loose 

Indeed, the fact that many MANY more people are familiar with SQL than
with Haskell may be the strongest practical objection to this choice of
syntax sugar; the WHERE clause in an SQL SELECT has such wildly
different semantics from Haskell's "where" that it might engender huge
amounts of confusion.  I.e., reasoning by analogy with SQL only, one
might reasonably expect that minor syntax variations on:

print a, b where a = b

could mean roughly the same as "if a==b: print a, b", rather than
roughly the same as:

a = b
print a, b

I wonder if 'with', which GvR is already on record as wanting to
introduce in 3.0, might not be overloaded instead.


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


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
Paul Rubin wrote:
You mean I can't say
   # compute sqrt(2) + sqrt(3)
   x = (sqrt(a) where:
 a = 2.) \
   + sqrt (a) where:
   a = 3.
No, I'd prefer to not embed 'where' into expression.
--
http://mail.python.org/mailman/listinfo/python-list


Re: time module precision

2005-01-09 Thread janeaustine50
Tim Peters wrote:
[snip]
> Python's time.sleep() calls the Win32 API Sleep() function on
Windows.
>  All behavior is inherited from the latter.  See MS's docs:
>
>


Oh, after a short research, I found that time.sleep uses its customized
way of sleeping using "select".

http://groups.google.com/groups?threadm=ud7i1c9ck.fsf%40ctwd0143.fitlinxx.com

So I think its behaviour is more complicated than single MS Sleep call,
I suppose.

> In particular, MS Sleep() takes an integer argument, giving the
number
> of milliseconds to sleep.  Your 0.0001 case falls under the special
> Sleep(0) case due to truncation in float->int conversion.
>

Oh, I see.

> Also Google on
>
> sleep thread deviation
>
> to find an interesting CodeProject article quantifying behavior on
one
> particular tester's Windows box.  Also see an article it references
> for approaches to the question "how do I handle small intervals?"
> (short course:  you probably can't, unless we're willing to throw
> money at it).

Thanks for the references.

What I want to do is waiting(not busy-delaying) for a few tens to
hundreds of microseconds in some threads. The closet solution I got is
using windows QueryPerformanceCounter (in Python, time.clock) with busy
looping checking if we have past the target time. However, that makes
the cpu usage upto almost 100%.

So the problem (waiting tens to hundreds of us without busy looping)
still remains...

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


Re: python3: 'where' keyword

2005-01-09 Thread Paul Rubin
Nick Coghlan <[EMAIL PROTECTED]> writes:
> Trying to push it a level further (down to expressions) would, IMO, be
> a lot of effort for something which would hurt readability a lot.

I think we should just try to do things in a simple and general way
and not try to enforce readability.  For example, the
slightly-overcomplex code that I proposed might have been generated by
a macro, or even by a compiler from some other language.  No human
would ever have to look at it, so it doesn't matter whether it's
easily readable.  There's no reason to add needless constraints on the
language just to make writing ugly code difficult.  The main goal
should be to make writing clear code easy, not to worry about whether
someone might also write ugly code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ranting about the state of Python IDEs for Windows

2005-01-09 Thread Jussi Jumppanen
Carlos Ribeiro wrote:

> Oh well. A mailing list is not the most appropriate place for 
> rants (a blog is better), but it's still better than keeping 
> it for myself.
>
> I'm frustrated. My search for a good IDE to support my activities

Take a look at Zeus:   

http://www.zeusedit.com/lookmain.html

> doing development for Python in the Windows environment 

Zeus only runs on Windows.

> But it's all that I have -- a 500MHz PC with 64MB and Win98 SE. 

Zeus should run fine on this machine. If you added another stick
of 64MB it would run better :)

Jussi Jumppanen
Author of: Zeus for Windows (New version 3.93 out now)
"The C/C++, Cobol, Java, HTML, Python, PHP, Perl programmer's editor"
Home Page: http://www.zeusedit.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Nick Coghlan
Alex Martelli wrote:
I wonder if 'with', which GvR is already on record as wanting to
introduce in 3.0, might not be overloaded instead.
Perhaps we could steal 'using' from the rejected decorator syntax.
x = [f(x) for x in seq] using:
  def f(x):
return x * x
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
Nick Coghlan wrote:
Current:
  assignment_stmt ::= (target_list "=")+ expression_list
  augmented_assignment_stmt ::=target augop expression_list
New:
  assignment_stmt ::= (target_list "=")+ expression_list [where_clause]
  augmented_assignment_stmt ::=target augop expression_list 
[where_clause]
  where_clause ::= "where" ":" suite

So the expressions in existing compound statements (for, while, if, 
elif) would be out of luck. You could conceivably add the 'where' clause 
to the end of those as well, to give statement local variables that 
apply to the whole compound statement:
Nick, you're good at formalization, thanks again.
So it seems that people loved the idea of 'where' keyword, may be it's 
time to think about PEP draft? I appreciate any help (cause my english 
is not that good =)).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting rid of "self."

2005-01-09 Thread Alex Martelli
BJörn Lindqvist <[EMAIL PROTECTED]> wrote:

> I think it would be cool if you could refer to instance variables
> without prefixing with "self." I know noone else thinks like me so

Some do -- Kent Beck's excellent book on TDD-by-example has a specific
grouse against that in the chapter where he develops the unittest module
(in Python).  But that's how comes Kent is a _Smalltalk_ programmer
rather than a _Python_ programmer, see?-)

> Python will never be changed, but maybe you can already do it with
> Python today?

Sure.

> impressive in this case but much cooler when there is more instance
> variables around. But the solution is very ugly because you have to
> write exec(magic()) in every method. So I'm asking here if someone
> knows a better way, maybe using decorators or metaclasses or other
> black magic?

A decorator can entirely rewrite the bytecode (and more) of the method
it's munging, so it can do essentially anything that is doable on the
basis of information available at the time the decorator executes.  You
do, however, need to nail down the specs.  What your 'magic' does is
roughly the equivalent of a "from ... import *" (except it "imports", so
to speak, from a namespace that's not a module): it makes a local copy
of all names defined in the given namespace, and that's all.  The names
stay local, any rebinding of a name has no non-local effect whatsoever,
etc.  Is this indeed what you want -- just give a method this kind of
copies?  And still have to write self.x=23 for re-binding (without
effect on the local copy, note...)?  Or what else?

Then, you must decide whether this applies to all names the method
accesses (which aren't already local).  For example, if the method has a
statement such as:
x = len(y)
and does not otherwise as locals len nor y, does this mean
x = self.len(self.y)
or
x = len(self.y)
or
x = self.len(y)
or
x = len(y)
...?  I.e., which of the names len and y is meant to be a global or
builtin, which is meant to be an isntance variable?  The decorator must
know, because it needs to generate different bytecode.  Your approach,
injecting an exec statement in the method, makes the compiler punt: the
compiler knows, seeing 'exec', that it has no idea about which names are
locals or globals any more, so it generates horribly-slow code for
completely-general accesses instead of normal local-access-is-optimized
code.  Is that what you want to do -- slow all of your Python code down
by an order of magnitude in order to be able to avoid writing 'self.' in
a few cases?

If you can give totally complete specifications, I can tell you whether
your specs are doable (by a decorator, or other means), how, and at what
cost.  Without knowing your specs, I can't tell; I can _guess_ that the
answer is "probably doable" (as long as you're not demanding the code in
the decorator to be an oracle for the future, but are content to limit
it to information known when it runs; and as long as you don't care how
much you slow everything down) and most definitely not WORTH doing for
anything except mental gym.


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


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
Nick Coghlan wrote:
sorry, I used "expression" carelessly.
I mean that
 >>> print words[3], words[5]
is a single expression
(and that would be in Python 3, when print would be subtituted with 
write()/writeln()).
'statement' is the appropriate word in Python's grammar.
thanks )
And I don't think we'd actually have to wait for Python 3 for this, we'd 
just have to do the __future__ dance in order to introduce the new keyword.
resonable, I mentioned Python3 as something in not that near future, 
that'd be great to think of it earlier
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Alex Martelli
Nick Coghlan <[EMAIL PROTECTED]> wrote:

> Alex Martelli wrote:
> > I wonder if 'with', which GvR is already on record as wanting to
> > introduce in 3.0, might not be overloaded instead.
> 
> Perhaps we could steal 'using' from the rejected decorator syntax.
> 
> x = [f(x) for x in seq] using:
>def f(x):
>  return x * x

If 'with' is going to become a keyword anyway, I suspect that many,
Guido included, would see giving 'with' two distinct syntax roles as a
lower 'price' than introducing yet another keyword, as long of course as
no ambiguity results.  'import', for example, is happily reused for both
'import foo' and 'from foo import bar'.

In terms of readability I see nothing in it, either way, between 'with'
and 'using' (and 'where', were it not for the wildly different semantics
it has in SQL) -- e.g. your example seems to read just fine with any of
these keywords.

If the use Guido intends for 'with' is something like:

with aname:
.x = .y

meaning

aname.x = aname.y

then there would be no ambiguity between this use of with as a leading
keyword in the new statement, always followed by a name; and its use in
the "with clause", where it always comes after an expression and is
immediately followed by a colon.  I mean, no ambiguity for either the
parser or a human reader, I believe.

Once the AST-branch is folded back into the CVS head, playing around
with syntax should be much easier than today...


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


Re: Old Paranoia Game in Python

2005-01-09 Thread Paul Rubin
Oh cool, I sort of remember that game from back in the day.  I didn't
play it very much so never got very far in it.  I'll have to try your
version.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Nick Coghlan
Andrey Tatarinov wrote:
sorry, I used "expression" carelessly.
I mean that
 >>> print words[3], words[5]
is a single expression
(and that would be in Python 3, when print would be subtituted with 
write()/writeln()).
'statement' is the appropriate word in Python's grammar.
And I don't think we'd actually have to wait for Python 3 for this, we'd just 
have to do the __future__ dance in order to introduce the new keyword.

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


Re: Pre/Postconditions with decorators

2005-01-09 Thread rittersporn
Thank you very much for reminding me. I have been sloppy.
It should have said static type checking.

ciao

Skip Montanaro wrote:
> >> Eiffel (language) has both type checking and design by contract.
> >> Python lacks both.
>
> Actually, Python is strongly typed.  It's just dynamically instead of
> statically typed.
> 
> Skip

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


Re: python3: 'where' keyword

2005-01-09 Thread Nick Coghlan
Paul Rubin wrote:
Nick Coghlan <[EMAIL PROTECTED]> writes:
Trying to push it a level further (down to expressions) would, IMO, be
a lot of effort for something which would hurt readability a lot.

I think we should just try to do things in a simple and general way
and not try to enforce readability.
Trying to embed a suite in a Python expression is anything but simple, 
though :)
Attaching an optional local suite to every statement can actually be done quite 
cleanly (so long as the parser is up to the job).

Doing the substitutions on the whole statement using distinct names will work 
just as well as doing the substitutions directly on the subexpressions using 
duplicate names, and moves the 'unimportant' bits after the whole thing, instead 
of sprinkling them throughout the statement.

It seems a statement based approach would be:
  1. Easier to read
  2. Less work to implement
  3. Consistent with the rest of the language
  4. Works for any statements, including compound statements
The only disadvantage relative to expression local namespaces would be that you 
would still have to watch for namespace conflicts within the statement - and I 
have grave doubts about the structure of any statement which has that problem.

If statement local namespaces were pursued, I would see expression local 
namespaces as something which hurt readability a lot without providing any new 
functionality.

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


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
Paul Rubin wrote:
What would be the advantage of that over this?
. x = sqrt(a) + sqrt(b) where:
. a = 2.0
. b = 3.0
The idea of "where" is to allow re-using variable names instead of
having to keep track of which ones are in use.  I just tried to give a
very simple example of how you might do that more than once in a
statement.
then I'd write something like this:
x = a + b where:
a = sqrt(n) where:
n = 2.
b = sqrt(n) where:
n = 3.
--
http://mail.python.org/mailman/listinfo/python-list


Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-09 Thread Nick Coghlan
Andrey Tatarinov wrote:
So it seems that people loved the idea of 'where' keyword, may be it's 
time to think about PEP draft? I appreciate any help (cause my english 
is not that good =)).
There's certainly a PEP in the idea. Here's a summary of what we have so far in 
this thread in a PEPish format. Any reference implementation should definitely 
wait for the compiler upgrade to hit the main development branch in CVS though 
(or be based on ast-branch if someone gets inspired in the interim).

Cheers,
Nick.
Abstract

  The proposal is to add the capacity for statement local namespaces to Python. 
This allows a statement to be placed at the current scope, while the statement's 
'setup code' is indented after the statement::

   with:
  
  The main benefit is the avoidance of namespace pollution in the outer scope. 
Sections of the statement can be extracted and named in the statement's local 
namespace without any inadvertent side effects due to name conflicts.
  The second benefit is that it can improve readability by allow easy grouping 
of the setup code for a given expression (see the examples section)
  Thirdly, it provides full-fledged effectively anonymous functions (just 
define them in the statement's local namespace).
  The idea is inspired by Haskell's where clause, as posted to python-list by 
Andrey Tatarinov. Alex Martelli suggested using the 'with' keyword.

Grammar Change
--
Current::
  statement ::=stmt_list NEWLINE | compound_stmt
New::
  statement ::=(stmt_list NEWLINE | compound_stmt) [local_namespace]
  local_namespace ::= "with" ":" suite
Semantics
-
The code::
 with:
   
translates to::
def unique_name():


unique_name()
Assignment statements (including augmented assignment) require special handling. 
The original assignment statement is translated to a return statement in the 
inner scope::

   with:

translates to::
def unique_name():

return 
  unique_name()
Function and class definitions will also require special casing, so that the 
created function or class is returned from the inner-scope and the name bound 
correctly in the outer scope.

Note that calling locals() inside a statement with a local namespace will refer 
to the statement's locals, rather than those of the containing function.

Keyword Choice
--
  The original suggestion on python-list used the 'where' keyword. Alex 
Martelli pointed out that this could be misleading for anyone with expectations 
based on SQL's WHERE clause.
  He suggested 'with' as an alternative spelling, as 'with' is already planned 
as a keyword for Python3k. Even for with clauses associated with compound 
statements, there should be no ambiguity, given that the with statement will 
have an expression between it and the colon, while the with clause does not.

Open Issues
---
  Is it actually possible to make it work?
  Keyword choice
  Should the clause be allowed on any statement (as described), or restricted 
to ones where it "makes sense"?

Examples

# Statement local functions (from Andrey Tatarinov)
#   aka How to cope if lambda goes away :)
res = [ f(i) for i in objects ] with:
   def f(x):
   #do something
# Declaring properties (from Nick Coghlan)
class C(object):
   x = property(get, set) with:
   def get(self):
   pass
   def set(self, value):
   pass
# Design by contract (from Nick Coghlan)
@dbc(pre, post)
def foo():
  pass
with:
  def pre():
pass
  def post():
pass
# Singleton classes (from Paul Rubin)
C = C() with:
  class C:
pass
# Complex default values (from Carlos Ribeiro)
def f(x=default()):
  pass
with:
  def default():
pass
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


static compiled python modules

2005-01-09 Thread Thomas Linden

Hi,

I made a static version of my python modules (2.4), all modules were
build statically. The modules were linked into libpython2.4.a which
has ~ 8 MB then. The build process then links the python binary against
the libpython2.4.a, the resulting binary has ~ 5 MB afterwards (?).

The problem is, that python ignores several modules, it tries to load
the dynamic versions. E.g. if I do 'import math', it tells that it
cannot find a module 'math'. Of course there is no mathmodule.so
somewhere, because it is statically build-in. When I use 'nm' to take
a look at the python binary, I can find all functions exported by
the math module, so it is there, but python ignores it.

In contrast, for example the posix module works. Its also compiled in,
and doesn't exist as posixmodule.so.

How can I tell python to use the compiled in modules and not try to
load them from outside?



kind regards, Tom

-- 
 Thomas Linden   (http://www.daemon.de/)  tom at co dot daemon dot de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
Alex Martelli wrote:
Indeed, the fact that many MANY more people are familiar with SQL than
with Haskell may be the strongest practical objection to this choice of
syntax sugar; the WHERE clause in an SQL SELECT has such wildly
different semantics from Haskell's "where" that it might engender huge
amounts of confusion.  I.e., reasoning by analogy with SQL only, one
might reasonably expect that minor syntax variations on:
print a, b where a = b
could mean roughly the same as "if a==b: print a, b", rather than
hmm... SQL-ish associations are good too, if you think a little deeper 
then common post-effect of using SQL "where" keyword.

print a, b where a = b
means a==b in statement "print a, b"
roughly the same as:
a = b
print a, b
I wonder if 'with', which GvR is already on record as wanting to
introduce in 3.0, might not be overloaded instead.
using 'with', is some way unnatural for my point of view (may be because 
 translations of 'with' and 'where' into russian, are way different and 
'where' translation reads as natural language while 'with' does not).

I'd like to keep 'where' keyword for proposal, but semantics are more 
important, so in case I do not mind for other keyword.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting rid of "self."

2005-01-09 Thread John Roth
"Alex Martelli" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
BJörn Lindqvist <[EMAIL PROTECTED]> wrote:
I think it would be cool if you could refer to instance variables
without prefixing with "self." I know noone else thinks like me so
Some do -- Kent Beck's excellent book on TDD-by-example has a specific
grouse against that in the chapter where he develops the unittest module
(in Python).  But that's how comes Kent is a _Smalltalk_ programmer
rather than a _Python_ programmer, see?-)
And of course, the reason it's possible in Smalltalk but not in Python
is that Smalltalk requires the declaration of instance variables. Also
Smalltalk does not have things like module variables and builtins.
The interpreter knows exactly what every name references, which
isn't true in Python.
John Roth

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


Pygame and pyopengl with py2exe ?

2005-01-09 Thread Nyx42
Hi,
I have 2 programs which run without problems, but after building them with
py2exe, they don't work (program opens the window and closed it
immediately) 

First program (uses only pygame):
screen = pygame.display.set_mode((W_WIDTH_F, W_HEIGHT))
This line refuses to be compiled correctly. Why ?

Second program (pygame + pyopenGL):
Py2exe can't import OpenGL.GL and OpenGL.GLU :(

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


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
And about examples for usage "where" keyword
reading http://manatee.mojam.com/~skip/python/fastpython.html I 
understand that almost every example should use that keyword =)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pygame and pyopengl with py2exe ?

2005-01-09 Thread Andrey Tatarinov
Nyx42 wrote:
Second program (pygame + pyopenGL):
Py2exe can't import OpenGL.GL and OpenGL.GLU :(
about that, may be names of imports are generated in runtime, so you can 
try to specify them directly

options = {"py2exe": {"packages": ["OpenGL.GL","OpenGL.GLU"]}},
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python application extending, plugins

2005-01-09 Thread Kartic
John,

To achieve this, your application must define an API that third party
coders can use to extend your application.

How you define your API is upto you; there are no general "guidelines",
AFAIK. But if you want seamless extensibility, it entirely depends on
how elegantly you design the API for you application.

My approach has been to study other applications (python or otherwise)
that allow plug-ins to be written and get ideas.

You can may be look at SPE, Stani's Python Editor, as it allows
extending the app using plug-ins and there are some sample plug-ins. I
have also read some plugin-related articles at codeproject.com (VB and
C++).

The good thing about Python is its introspection that you can use to
detect the presence of certain functions in order to qualify as a
plug-in for your application. And you can use pycheck (pycheck.sf.net)
to check the plugin's python code before you load it into your
application's namespace.

Cheers!
--Kartic

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


Python3: on removing map, reduce, filter

2005-01-09 Thread Andrey Tatarinov
Hi.
How does GvR suggestions on removing map(), reduce(), filter() correlate 
with the following that he wrote himself (afaik):

http://www.python.org/doc/essays/list2str.html
?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Paul Rubin
Andrey Tatarinov <[EMAIL PROTECTED]> writes:
> How does GvR suggestions on removing map(), reduce(), filter()
> correlate with the following that he wrote himself (afaik):
> 
> http://www.python.org/doc/essays/list2str.html

I think that article was written before list comprehensions were added
to Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyparsing: how to negate a grammar

2005-01-09 Thread knguyen
Hi Paul,

I am trying to extract HTTP response codes  from a HTTP page send from
a web server.  Below is my test program. The program just hangs.

Thanks,
Khoa
##

#!/usr/bin/python

from pyparsing import   ParseException, Dict, CharsNotIn,
Group,Literal,Word,ZeroOrMore,OneOrMore,
Suppress,nums,alphas,alphanums,printables,restOfLine


data = """HTTP/1.1 200 OK
body line some text here
body line some text here
HTTP/1.1 400 Bad request
body line some text here
body line some text here

HTTP/1.1 500 Bad request
body line some text here
body line some text here
"""

print "="
print data
print "="

HTTPVersion = (Literal("HTTP/1.1")).setResultsName("HTTPVersion")
StatusCode = (Word(nums)).setResultsName("StatusCode")
ReasonPhrase = restOfLine.setResultsName("ReasonPhrase")
StatusLine = Group(HTTPVersion + StatusCode + ReasonPhrase)

nonHTTP = ~Literal("HTTP/1.1")
BodyLine = Group(nonHTTP + restOfLine)
Response = OneOrMore(StatusLine + ZeroOrMore(BodyLine))
respFields = Response.parseString(data)
print respFields

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


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Andrey Tatarinov
Paul Rubin wrote:
How does GvR suggestions on removing map(), reduce(), filter()
correlate with the following that he wrote himself (afaik):
http://www.python.org/doc/essays/list2str.html
I think that article was written before list comprehensions were added
to Python.
anyway list comprehensions are just syntaxic sugar for
>>> for var in list:
>>> smth = ...
>>> res.append(smth)
(is that correct?)
so there will be no speed gain, while map etc. are C-implemented
--
http://mail.python.org/mailman/listinfo/python-list


Re: Recent infoworld column

2005-01-09 Thread Michael Hoffman
Carlos Ribeiro wrote:
"""
When people talk about the heroes of open source, you tend to hear
such familiar names as Linus Torvalds, Larry Wall, Brendan Eich, Guido
van Rossum, Monty Widenius, Miguel de Icaza, and Rasmus Lerdorf...
"""
Of course, I had to look up who Rasmus Lerdorf was...
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: windows mem leak

2005-01-09 Thread Peter Hansen
Bob Smith wrote:
Attached is the code. Run it yourself and see. You too Peter. Be gentle 
with me, this was my first attempt with threads.
Thanks, Bob, and I will, but not before you answer some of my
questions.
I had good reasons to ask them, one of which is that I don't
feel like wasting my time if, for example, you are using an
older version of Python that *did* have a memory leak.
Python 2.2, for example, (if my memory serves me right) had
a leak in the first release which would have affected pretty
much all software which did network work.
The most important answers you can provide will be versions,
platform (pretty clearly Linux, but please confirm and give
version), and what "bombs" means and how you are measuring
the memory leak.
(I presume you're using a version of nmap that's compiled
for Windows XP then?  It's certainly not standard.  How have
you proven that it is not *that* program which is at fault?)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Installation

2005-01-09 Thread Peter Hansen
Simon John wrote:
I would say install on one machine, then just copy the C:\Python24
directory, but then you'd have to deal with the missing Registry
entries
That part is pretty trivial to automate as well.  Fredrik
Lundh has a useful utility on his web site that will do much
of what is required.  Google for his name and "python registry"
to find out more.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Operating System???

2005-01-09 Thread Arich Chanachai
John Roth wrote:
"jtauber" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

My experiment, Cleese, was making progress before I got distracted by
other things.

I should probably get back to it at some stage.

As my ex-wife was fond of saying, "I wish you'd have
told me it was impossible before I did it."

John Roth
Is that why she divorced you?
You will notice that tauber says he stopped working on Cleese due to 
"distraction" not a lack of progress or a notion of impending 
doom/"impossibility".


see http://cleese.sourceforge.net/
James Tauber
http://jtauber.com/blog/

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


Re: time module precision

2005-01-09 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
So the problem (waiting tens to hundreds of us without busy looping)
still remains...
That's actually not a "problem", it's your solution
to a problem.  Can you describe the _real_ problem, what
you are trying to do?  _Why_ do you want to wait such
brief amounts of time?
I ask as someone with fairly extensive background in
realtime software (which is basically what it sounds like
you are trying to write here), and I suspect that you are
either trying to achieve something that's not really possible
on Windows XP, or that you are simply doing something that
is entirely unnecessary, probably for good reasons but
with too little experience of the issues involved.  Can
you expand on your situation?
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: mysterious buggy behavior

2005-01-09 Thread Andrea Griffini
On 8 Jan 2005 20:40:37 -0800, [EMAIL PROTECTED] (Sean McIlroy)
wrote:

>def newGame():
>BOARD = [blank]*9
>for x in topButtons+midButtons+botButtons: x['text'] = ''

Do you know that "BOARD" here is a local variable and has nothing
to do with the global BOARD ? You can change that by doing either

 BOARD[:] = [blank]*9

or

 global BOARD
 BOARD = [blank]*9

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


Re: Python Operating System???

2005-01-09 Thread Arich Chanachai
Roose wrote:

It's a difference of degree, but an important difference.  I haven't looked
at Linux or Windows NT source, but my guess is the assembly used is just
small functions for accessing special CPU instructions for atomicity,
context switching, and the like.
I KNOW they don't have huge amounts of assembly simply because they run on
different architectures.
 

But are you really going to write a virtual memory system in Python?  Are
you going to write a file system, and a task scheduler in Python?  Are you
going to have people write device drivers in Python? 

Cleese!!
I'm not saying it
can't be done, but it would be a poor engineering decision, and the
rationale thus far seems to be "Python is cool, I like OSes, let's write a
whole OS in Python".  If that's not the case then let me know what your
rationale is.
 

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


Re: Python Operating System???

2005-01-09 Thread Arich Chanachai
Paul Rubin wrote:
...
OK, then give me an example of Lisp OS that runs on a PC.  I would like to
install it on my PC tomorrow.  Or maybe my Mac.  That was your whole point,
originally, that since it could be done in Lisp, why not Python?
   

Huh?  That's a non-sequitur, nothing prevents you from running Lisp on
your PC or Mac.  The same issues issues that apply to OS code, also
apply to user code.  The Lisp machine hardware wasn't needed only to
make the OS run fast.  The Lisp machine was developed so that people
could deploy large user-level applications written in Lisp, and the
hardware was there to support those applications.  And given such a
good Lisp environment, there was no reason to think of writing the OS
in anything other than Lisp.
In fact, the reason the Lisp machine died off was because general
purpose workstation hardware (and later, PC-class hardware) became
fast enough to run Lisp applications without needing special purpose
CPU's.  That same PC hardware speed is what makes it possible to run
user applications in Python.
 

So true, there was indeed a contextual reason for special hardware, and 
the context has since changed (dramatically).
--
http://mail.python.org/mailman/listinfo/python-list


raw sockets ? i need a python sniffer

2005-01-09 Thread ionel
on windows xp
well i got pylibpcap-0.4 but i can't compile it :(
i got python 2.4, visual studio 2003
when i run "setup.py build" i get this:

C:\Python24\lib\distutils\dist.py:222: UserWarning: 'licence' distribution optio
n is deprecated; use 'license'
 warnings.warn(msg)
running build
running build_py
running build_ext
building 'pcapcmodule' extension
Traceback (most recent call last):
 File "d:\_PRO\__11\lib\pylibpcap-0.4\pylibpcap-0.4\setup.py", line 104, in ?
   cmdclass = {'clean': pcapclean, 'build_ext':pcap_build_ext},
 File "C:\Python24\lib\distutils\core.py", line 149, in setup
   dist.run_commands()
 File "C:\Python24\lib\distutils\dist.py", line 946, in run_commands
   self.run_command(cmd)
 File "C:\Python24\lib\distutils\dist.py", line 966, in run_command
   cmd_obj.run()
 File "C:\Python24\lib\distutils\command\build.py", line 112, in run
   self.run_command(cmd_name)
 File "C:\Python24\lib\distutils\cmd.py", line 333, in run_command
   self.distribution.run_command(command)
 File "C:\Python24\lib\distutils\dist.py", line 966, in run_command
   cmd_obj.run()
 File "C:\Python24\lib\distutils\command\build_ext.py", line 279, in run
   self.build_extensions()
 File "C:\Python24\lib\distutils\command\build_ext.py", line 405, in build_exte
nsions
   self.build_extension(ext)
 File "C:\Python24\lib\distutils\command\build_ext.py", line 442, in build_exte
nsion
   sources = self.swig_sources(sources, ext)
TypeError: swig_sources() takes exactly 2 arguments (3 given)


any help please? :)

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


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Paul Rubin
Andrey Tatarinov <[EMAIL PROTECTED]> writes:
> anyway list comprehensions are just syntaxic sugar for
>  >>> for var in list:
>  >>> smth = ...
>  >>> res.append(smth)
> 
> (is that correct?)

I would expect lc's to work more like map does.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Robert Kern
Andrey Tatarinov wrote:
anyway list comprehensions are just syntaxic sugar for
 >>> for var in list:
 >>> smth = ...
 >>> res.append(smth)
(is that correct?)
so there will be no speed gain, while map etc. are C-implemented
It depends.
Try
  def square(x):
  return x*x
  map(square, range(1000))
versus
  [x*x for x in range(1000)]
Hint: function calls are expensive.
--
Robert Kern
[EMAIL PROTECTED]
"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


use a file as a database, access rights

2005-01-09 Thread Torsten Mohr
Hi,

i'd like to write a script that makes use of a database.

It would be great if the database would store all its data
in a file, that would be great for data exchange.

It would also be great if i could use SQL, as i have some
experience in that.

Also, i NEED access rights to certain parts of the database.
Several people should work on it and NEED to have different
access rights.


Can anybody give me some recommendations on what to use?


Thanks for any hints,
Torsten.

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


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Roman Suzi
On Sun, 9 Jan 2005, Paul Rubin wrote:

>Andrey Tatarinov <[EMAIL PROTECTED]> writes:

I hope there will be

from __past__ import functional_paradigma

in Python 3 ;-)

And, also, what is the best way to replace reduce() ?


Sincerely yours, Roman Suzi
-- 
[EMAIL PROTECTED] =\= My AI powered by GNU/Linux RedHat 7.3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Steve Holden
Alex Martelli wrote:
AdSR <[EMAIL PROTECTED]> wrote:

I don't know haskell, but it looks SQL-ish to me (only by loose 

Indeed, the fact that many MANY more people are familiar with SQL than
with Haskell may be the strongest practical objection to this choice of
syntax sugar; the WHERE clause in an SQL SELECT has such wildly
different semantics from Haskell's "where" that it might engender huge
amounts of confusion.  I.e., reasoning by analogy with SQL only, one
might reasonably expect that minor syntax variations on:
print a, b where a = b
could mean roughly the same as "if a==b: print a, b", rather than
roughly the same as:
a = b
print a, b
I wonder if 'with', which GvR is already on record as wanting to
introduce in 3.0, might not be overloaded instead.
IIRC the proposed meaning seems to be most closely related (in my own 
experience, annyway) to the use of "where" in BCPL (heavens, *that* was 
a long time ago). I never found that entirely natural either.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: accessing the result of 'if'

2005-01-09 Thread Steve Holden
Nick Coghlan wrote:
Carl Banks wrote:
What if the condition you wanted to test wasn't the same as the thing
you want to save?  In other words, how would you convert this?
. where:
. m = something()
. if m > 20:
. do_something_with(m)

Yeah, this problem eventually occurred to me as well. However, I think a 
little utility function can help solve it:

  def test(val, condition):
if condition(val):
  return val
 else:
  return None
  if test(something(), lambda x: x < 10) as m:
print "Case 1:", m
  elif test(something(), lambda x: x > 20) as m:
print "Case 2:", m
  else:
print "No case at all!"
If we were to use a where clause instead, it looks like:
  if test(something(), less_than(10)) as m:
print "Case 1:", m
  elif test(something(), more_than(20)) as m:
print "Case 2:", m
  else:
print "No case at all!"
  where:
def less_than(y):
  def lt(x):
return x < y
  return lt
def more_than(y):
  def gt(x):
return x > y
  return lt
This is an example of why I don't think where clauses would completely 
eliminate the utility of deferred expressions. Here's a version using my 
preferred syntax from the AlternateLambdaSyntax page:

  if test(something(), (def x < 10 from x)) as m:
print "Case 1:", m
  elif test(something(), (def x > 20 from x)) as m:
print "Case 2:", m
  else:
print "No case at all!"
Excuse me, these are supposed to be IMPROVEMENTS to Python?
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Installation

2005-01-09 Thread Steve Holden
Peter Hansen wrote:
Simon John wrote:
I would say install on one machine, then just copy the C:\Python24
directory, but then you'd have to deal with the missing Registry
entries

That part is pretty trivial to automate as well.  Fredrik
Lundh has a useful utility on his web site that will do much
of what is required.  Google for his name and "python registry"
to find out more.
Hmm, effbot.org seems to be down just now. Sure it'll be back soon, though.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Steve Holden
Andrey Tatarinov wrote:
Hi.
How does GvR suggestions on removing map(), reduce(), filter() correlate 
with the following that he wrote himself (afaik):

http://www.python.org/doc/essays/list2str.html
?
It promotes the sensible realization that when optimization is the goal 
code may well tend to get ugly, sometimes uglier than necessary. Note 
that the first version is completely straightforward and comprehensible.

And note that the summary in the conclusiogn BEGINS with "Rule number 
one: only optimize when there is a proven speed bottleneck", which seems 
to adequately imply that straightforward code is to be preferred unless 
speed requirements override that.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: use a file as a database, access rights

2005-01-09 Thread Steve Holden
Torsten Mohr wrote:
Hi,
i'd like to write a script that makes use of a database.
It would be great if the database would store all its data
in a file, that would be great for data exchange.
It would also be great if i could use SQL, as i have some
experience in that.
Also, i NEED access rights to certain parts of the database.
Several people should work on it and NEED to have different
access rights.
Can anybody give me some recommendations on what to use?

Sounds to me like you need to add a rights layer to gadfly.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: use a file as a database, access rights

2005-01-09 Thread Kartic
Torsten,

Please explain the environment you are planning to use - Operating
System, whether you have full control of the machine that runs the
database, how many users?.

If you are using Windows and if your needs are simple, you can use
Access as it has some simple access control that  can be setup.

Also, the part about "database would store all its data in a file" is
not very clear. Are you wanting to use a flat-file database and also
have security implemented in it?  If you are on linux/*BSD machine,
consider using a real database.

Fine access control can be implemented in your application (e.g. only
the creator of a record and his/her superiors can edit it, all others
view it)

Please send more details to receive useful recommendations.
Thanks,
--Kartic

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


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Andrey Tatarinov
Steve Holden wrote:
Andrey Tatarinov wrote:
Hi.
How does GvR suggestions on removing map(), reduce(), filter() 
correlate with the following that he wrote himself (afaik):

http://www.python.org/doc/essays/list2str.html
>
And note that the summary in the conclusiogn BEGINS with "Rule number 
one: only optimize when there is a proven speed bottleneck", which seems 
to adequately imply that straightforward code is to be preferred unless 
speed requirements override that.
My main question was: "how could be this advices applied, when map, 
reduce and filter would be removed?"

but earlier I got answers about speed of list comprehensions, though 
they need to be proved.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Old Paranoia Game in Python

2005-01-09 Thread Lucas Raab
Sean P. Kane wrote:
I ported the old (and long since removed) game from the bsd-game pacakge 
called, Paranoia, based on the old Paranoia role playing game from C to 
Python as a simple exercise in learning the language and pure late night 
boredom. Anyways, here it is for anyone looking for a few minutes of 
nostalgia. I may get around to posting this at 
http://homepage.mac.com/spkane/ or http://www.spkane.org/, but for now 
here it is. Improvements or corrections, welcome.

Thanks,
Sean

Equipment: Red Reflec Armour, Laser Pistol, Laser Barrel (red),
  Notebook & Stylus, Knife, Com Unit 1, Jump suit,
  Secret Illuminati Eye-In-The-Pyramid(tm) Decoder ring,
  Utility Belt & Pouches
=== 

The Illuminati really have infiltrated our society.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pygame and pyopengl with py2exe ?

2005-01-09 Thread Nyx42
Same problem: the window closes immediately. 

For the first program, I precise that the "pygame window" opens also. 

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


Re: use a file as a database, access rights

2005-01-09 Thread Kartic
Steve Holden wrote:


> Sounds to me like you need to add a rights layer to gadfly.


Aha...I did not consider that possibility. I have not gone indepth into
Gadfly...is that a straigtforward thing to implement?

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


Guild of Python consultants?

2005-01-09 Thread Miklós P
Hello freelancers out there,

Is there such a thing somewhere? Yes, I'm aware of the Python Business
Forum.  But I mean something specifically for (individual) consultants.
By searching on Google, I couldn't find a "virtual guild" of consultants who
try to make a living from Python and technologies built around it (like
Zope, Plone, etc.)
I'm thinking of providing mutual marketing help like a webring, passing info
about projects and clients, discussing business related issues and technical
issues in deploying Python in the enterprise, etc.

Any thoughts?

Best,
  Miklós
 ---
Jegenye 2001 Bt.
Egyedi szoftverkészítés, tanácsadás | Custom software development,
consulting
Magyarul: http://jegenye2001.parkhosting.com
In English: http://jegenye2001.parkhosting.com/en


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


Long strings as function parameters

2005-01-09 Thread onlyonemc
I would like to have functions that operate on long strings, 10-100 MB.
In C I would of course pass a pointer to the string for a quick
function call.  What is an efficient way to do this in python?
Cheers,
-mark

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


Re: Old Paranoia Game in Python

2005-01-09 Thread Aahz
In article <[EMAIL PROTECTED]>,
Lucas Raab  <[EMAIL PROTECTED]> wrote:
>Sean P. Kane wrote:
>>
>> I ported the old (and long since removed) game from the bsd-game pacakge 
>> called, Paranoia, based on the old Paranoia role playing game from C to 
>> Python as a simple exercise in learning the language and pure late night 
>> boredom. Anyways, here it is for anyone looking for a few minutes of 
>> nostalgia. I may get around to posting this at 
>> http://homepage.mac.com/spkane/ or http://www.spkane.org/, but for now 
>> here it is. Improvements or corrections, welcome.
>
>
>
>> Equipment: Red Reflec Armour, Laser Pistol, Laser Barrel (red),
>>   Notebook & Stylus, Knife, Com Unit 1, Jump suit,
>>   Secret Illuminati Eye-In-The-Pyramid(tm) Decoder ring,
>>   Utility Belt & Pouches
>> ===
>>  
>
>
>
>The Illuminati really have infiltrated our society.

Stay alert!
Trust no one!
Keep your laser handy!
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Robert Kern
Andrey Tatarinov wrote:
Steve Holden wrote:
Andrey Tatarinov wrote:
Hi.
How does GvR suggestions on removing map(), reduce(), filter() 
correlate with the following that he wrote himself (afaik):

http://www.python.org/doc/essays/list2str.html
 >
And note that the summary in the conclusiogn BEGINS with "Rule number 
one: only optimize when there is a proven speed bottleneck", which 
seems to adequately imply that straightforward code is to be preferred 
unless speed requirements override that.

My main question was: "how could be this advices applied, when map, 
reduce and filter would be removed?"
Since Python 3.0 is currently mythical and will involve a complete 
rewrite of the language and interpreter, I don't think that you should 
expect any optimization advice to carry over.

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


Re: Long strings as function parameters

2005-01-09 Thread Irmen de Jong
[EMAIL PROTECTED] wrote:
I would like to have functions that operate on long strings, 10-100 MB.
In C I would of course pass a pointer to the string for a quick
function call.  What is an efficient way to do this in python?
Err, just pass the string to the function?
In Python, all function arguments are passed by (object)reference.
So if you are afraid that Python passes your 50Mb string object
/by value/ (thus creating a copy): it doesn't.
--Irmen
--
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-09 Thread Anna

Jacek Generowicz wrote:
> "Anna" <[EMAIL PROTECTED]> writes:
>
> > Having taken some calculus (derivatives, limits, some integrals)
but
> > never even heard of lambda calculus, to me, lambda means absolutely
> > NOTHING. Less than nothing.
>
> And before you took calculus, the chances are that derivatives,
limits
> and integrals meant less than nothing to you.
>
> But now, I am quite sure, you know that in Python lambda is a keyword
> which creates anonymous functions. Now that you know what lambda
does,
> what's the problem with it? (It certainly doesn't mean "Less than
> nothing" to you now.)
>
> > So, I guess I don't like the word itself
>
> Fair enough. I guess there are people out there who might have a
> distaste for the word "class" or "def" or any of the other words
which
> are keywords in Python.
>
> > Every other word in Python has an obvious meaning.  lambda doesn't.
>
> Obvious to whom?
>
> The meaning of every word is obvious, once you have been taught it;
> and a complete mystery if you have not.
>
> What do you make of "seq[2:-2]"? It means "less than nothing" to the
> uninitiated. Just like lambda.

Actually - whether or not I understood the [2:-2] notation, knowing
nothing else,  the "seq" would clue me in that we're probably doing
something with sequences...

Personally, I like lambdas less than regular expressions (of which I'm
particularly UNfond but understand their usefulness at times). At least
with regular expressions - I know that the gibberish I need to decipher
(probably) has to do with text parsing... With class and def, I at
least have a *name* to start with - class Square pretty obviously is
going to have something to do with geometric shapes, I would hope (or
maybe with boring people...). def getfoo() tells me I'm the function is
likely to go elsewhere and get something. It's a *start*, a handle, to
deciphering whatever the following statements are doing. (Yes, I
realize that often class and function names suck - but more often than
not, they give *some* clue).

Whereas, with lambda - I have *nothing* to go on.  With lambdas, all I
know is that the programmer wanted to hide whatever it is the program
is doing behind the curtain... (at least that's the way it comes
across). So, not only is the word itself not descriptive of anything to
me - even knowing that it means "anonymous function" - the use of it
precludes descriptiveness, as compared to defining a function. IMHO,
YMMV, etc etc

Anna

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


Re: Long strings as function parameters

2005-01-09 Thread Dan Bishop
[EMAIL PROTECTED] wrote:
> I would like to have functions that operate on long strings, 10-100
MB.
> In C I would of course pass a pointer to the string for a quick
> function call.  What is an efficient way to do this in python?
> Cheers,

In Python, *every* expression is a pointer.  This fact is clearest when
you look a C-implemented Python functions (which have parameter types
and return types of PyObject*), or when using mutable types.

>>> class Spam:
...def __init__(self):
...   self.foo = 0
...
>>> x = Spam()
>>> y = x
>>> y.foo = 17
>>> x.foo
17

Compare this to the C code:

typedef struct {int foo;} Spam;
...
Spam *x, *y;
...
y = x;
y->foo = 17;
printf("%d\n", x->foo);

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


Re: use a file as a database, access rights

2005-01-09 Thread Torsten Mohr
Hi,

sorry for being unclear and thanks for your answers.

Yes, i'd like to use a flat-file database AND access rights.
One way i thought of would be to handle the access rights
in the script that i write.  But to let some other module
handle it would also be great.  If for example i could embed
some SQL database and tell it to store all its tables in
ONE FILE it would be quite easy to do.

I want to write that application cross-platform, at least
Win32 AND Linux.


Best regards,
Torsten.


> Torsten,
> 
> Please explain the environment you are planning to use - Operating
> System, whether you have full control of the machine that runs the
> database, how many users?.
> 
> If you are using Windows and if your needs are simple, you can use
> Access as it has some simple access control that  can be setup.
> 
> Also, the part about "database would store all its data in a file" is
> not very clear. Are you wanting to use a flat-file database and also
> have security implemented in it?  If you are on linux/*BSD machine,
> consider using a real database.
> 
> Fine access control can be implemented in your application (e.g. only
> the creator of a record and his/her superiors can edit it, all others
> view it)
> 
> Please send more details to receive useful recommendations.
> Thanks,
> --Kartic

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


Re: Recent infoworld column

2005-01-09 Thread Roger Binns

"Peter Hansen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Dwarf Electrician wrote:
>> from a long time listener...
>>
>> http://www.infoworld.com/article/04/12/30/01OPstrategic_1.html
>
> Kudos for Roger Binns!

It is a very nice article :-)  BitPim like many other projects is an
effort by several people, but what John did was entirely my code.
And of course that code wouldn't be possible without the various
components I had available to me which including Python and wxPython
as well as several others.

  http://bitpim.org/testhelp/credits.htm
  http://bitpim.org/testhelp/3rdparty.htm

You may also find a talk I gave at baypiggies in July 2004 of interest.

  http://bitpim.org/papers/baypiggies/

It covers the various issues in doing a "real world" Python application,
including packaging them up so they are indistinguishable from native
applications, accessing serial ports, USB and SWIG, threading, the GUIs
available and why I picked wxPython, Outlook and Evolution integration,
dealing with an undocumented binary protocol, user and programmer documentation,
secure remote access etc.

Roger 


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


Re: time module precision

2005-01-09 Thread Tim Peters
[Tim Peters]
>> Python's time.sleep() calls the Win32 API Sleep() function on
>> Windows. All behavior is inherited from the latter.  See MS's docs:
>>
>>
>> 

[EMAIL PROTECTED]
> Oh, after a short research, I found that time.sleep uses its customized
> way of sleeping using "select".
>
> [http://groups.google.com/groups?threadm=ud7i1c9ck.fsf%40ctwd0143.fitlinxx.com]
>
> So I think its behaviour is more complicated than single MS Sleep call,
> I suppose.

Sorry, the information you found is wrong, as a brief look at Python's
timemodule.c will confirm.  select() is used to implement time.sleep()
on Unixish boxes, but, contrary to the thread you found, it's not
possible to do that on Windows -- the Winsock select() requires at
least one of its socket-set arguments to be non-empty (see MS's
select() docs -- they're telling the truth too ).  Abusing
select() for "short sleeps" is an ugly (but effective) hack limited to
Unixish systems.

...
> What I want to do is waiting(not busy-delaying) for a few tens to
> hundreds of microseconds in some threads. The closet solution I got is
> using windows QueryPerformanceCounter (in Python, time.clock) with busy
> looping checking if we have past the target time. However, that makes
> the cpu usage upto almost 100%.
>
> So the problem (waiting tens to hundreds of us without busy looping)
> still remains...

I agree with Peter Hansen's reply here, so please respond to it. 
Windows is not a real-time OS, so what you want to do either cannot be
done on Windows, or you're approaching your actual problem (whatever
that may be) in a way that doesn't make good sense.
-- 
http://mail.python.org/mailman/listinfo/python-list


SuSE 9.1: updating to python-2.4

2005-01-09 Thread Torsten Mohr
Hi,

along with my distribution SuSE 9.1 came python 2.3.3.

I'd like to update to 2.4 now, is this an easy thing to do
or will lots of installed modules refuse to work then?

Is there an easy way to find out what i need to update?


Thanks for any hints,
Torsten.

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


Re: Pre/Postconditions with decorators

2005-01-09 Thread George Sakkis
"Stephen Thorne" <[EMAIL PROTECTED]> wrote:

> Unresolved Problems:
> 1) How do you handle duck types, i.e. a method that accepts StringIO,
> cStringIO or any other object that has a .readlines(), .seek() and
> .read() method?

I think the 'proper' way of checking duck types (among other things) is by 
defining appropriate
protocols; check pyProtocols (http://peak.telecommunity.com/PyProtocols.html) 
for details.

> 2) How do you turn off the type checking for production code?

Currently I don't, but that's easy to do if desired by checking __debug__ in 
the decorator and
return the passed function if it is false:

def params(**checkedArgs):
if not __debug__:
return lambda function: function
# else return a typechecked proxy of function
(...)


> Otherwise I quite like it. Please publish it somewhere.

Thanks. I'll post an entry on Vaults of Parnassus as soon as I publish it.

George


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


Re: Pre/Postconditions with decorators

2005-01-09 Thread Andrew Dalke
Paul Rubin wrote:
> [Type checking] should be left on.  Leaving it in for development
> and turning it off for production is like wearing a parachute
> during ground training and taking it off once you're in the air.

Why isn't it like practicing the trapeze with a net but
going without a net when performing for a big circus?

Why isn't it like using training wheels when learning to
ride bicycle but getting rid of them once you've got the
idea down?

Or like using a map when you get to a new city but gradually
stop as you know the place?

Fighting analogies with analogies :)

Andrew
[EMAIL PROTECTED]

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


Dr. Dobb's Python-URL! - weekly Python news and links (Jan 9)

2005-01-09 Thread Josiah Carlson
QOTW:  Jim Fulton: "[What's] duck typing?"
Andrew Koenig: "That's the Australian pronunciation of 'duct taping'."

"I'm thinking that the I-Ching is a vast untapped resource for programming
wisdom, plus it makes it funny." -- Mark Carter


Nick Coghlan brings up the 'lambdas are going away in 3.0' topic, which
has been discussed before:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/81e17b1d3ccba538

A user asks about a non-generator-based method for iteration using class
__iter__ and next() methods:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/6336a00ad217888a

Daniel Bickett asks about getting Twisted and wxPython working together,
and receives both a threaded and non-threaded version:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/73f1e7758225afc3

A question about iterating over floats...be careful!

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/1278866159ac4429

A Boogieman asks whether Python is easily learned and what can be done
with it.  Quick answer: yes, and anything you are capable of doing:
This Boogieman later asks about GUI toolkits:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/e67b776df72eb336

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/d502698b4adacd01

Erik Bethke writes Majong game after using Python for a month.  Ahh, will
the wonders of Python never cease?

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/6d710e35007f0f32

Kamilche asks about getting warnings when not calling a function, and gets
pointed to pychecker, something more of us should be using:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/dff810b7dacd247c

Are people allowed to build commercial applications in Python?  YES!

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/aa953388db68b196

Questions about asyncore brings up a web server in asyncore from _Python
Web Programming_, and a pointer to Twisted.  Alternatively, one could look
at the asynchat or smtpd modules in the standard library as sources of
inspiration:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/81360ec06013e36d


Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Brett Cannon continues the marvelous tradition established by 
Andrew Kuchling and Michael Hudson of intelligently summarizing
action on the python-dev mailing list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

The Python Business Forum "further[s] the interests of companies
that base their business on ... Python."
http://www.python-in-business.org

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlin

read numbers from file and covert to integer

2005-01-09 Thread Øystein Western
I got a file with a lot blocks of numbers that are strings. I'd like to read 
all
this numbers and convert them to numbers for futher compareation. How can I
convert all this numbers to integer? Do I have to put all numbers into a 
list?

regards
frengky


-- 
Organisation nr: 983063349
Frengky, Olsokveien 65,1727 Sarpsborg, Norway
Tel: +47 92611725
Fax: +47 69152017
Email: [EMAIL PROTECTED]
Web: www.frengky.no


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


Re: unicode support

2005-01-09 Thread Matt Garrish

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
# -*- coding: utf-8 -*-
# python supports unicode in source code by putting a coding
declaration
# as the first line.
print "look chinese chars: ?"

# Note, however, identifiers cannot use unicode chars.
# e.g. you cannot define a function with unicode char.

So why are you posting to a Perl newsgroup? You can "use utf8" if you want 
to write your Perl programs in utf-8 (though you should upgrade to 5.8 as 
well). Or is this your lame attempt at trolling at python group?

Matt 


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


Re: Python Installation

2005-01-09 Thread Peter Hansen
Steve Holden wrote:
Peter Hansen wrote:
Simon John wrote:
I would say install on one machine, then just copy the C:\Python24
directory, but then you'd have to deal with the missing Registry
entries

That part is pretty trivial to automate as well.  Fredrik
Lundh has a useful utility on his web site that will do much
of what is required.  Google for his name and "python registry"
to find out more.
Hmm, effbot.org seems to be down just now. Sure it'll be back soon, though.
Still down, but clicking on the second link in the result,
on the "cached" link, then on the "cached text only" link
in the header, will get the relevant source code for you.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: windows mem leak

2005-01-09 Thread Bob Smith
Peter Hansen wrote:
Bob Smith wrote:
Attached is the code. Run it yourself and see. You too Peter. Be 
gentle with me, this was my first attempt with threads.

Thanks, Bob, and I will, but not before you answer some of my
questions.
I had good reasons to ask them, one of which is that I don't
feel like wasting my time if, for example, you are using an
older version of Python that *did* have a memory leak.
2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)]
The most important answers you can provide will be versions,
platform (pretty clearly Linux, but please confirm and give
version), and what "bombs" means and how you are measuring
the memory leak.
WinXP Home, Service Pack 2, AMD 1400MHz proc, 256MB Ram
Debian Linux Testing (2.4.28 vanilla Kernel) 3GHz P4 proc, 1.5GB Ram
(I presume you're using a version of nmap that's compiled
for Windows XP then?
Yes, I am.
It's certainly not standard.
That's a matter of opinion. Nmap works fine on the WinXP machine.
How have
you proven that it is not *that* program which is at fault?)
I have not. All I know is that on WinXP, the program uses 100% CPU at 
times and consumes more Ram than is available (the page file grows to 
700 or 800MB). It runs OK for a few hours and then produces a 'not 
enough resources' error. And, the machine is generally unuserable. On 
Linux, it has no impact whatsoever on resources. Granted, the Linux 
machine is much more robust, but one wouldn't expect this great a 
difference. I can rewrite it so that it's pure Pyhton (no calling nmap) 
if you think that would be a good idea. Perhaps that would at least 
remove nmap from the equation.

I can run it if you like and take a screen shot of the error. You'll 
have to give me a few hours though ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Recent infoworld column

2005-01-09 Thread Stephen Waterbury
Roger Binns wrote:
You may also find a talk I gave at baypiggies in July 2004 of interest.
  http://bitpim.org/papers/baypiggies/
It covers the various issues in doing a "real world" Python application,
including packaging [etc -- lots of great stuff ...]
*Very* nice presentation -- THANKS!
Especially interesting to me because my project
uses wxPython and I'm always looking at the
rationales of other GUI projects for their
choices ... I agree with all your points!
Wrt event-driven vs. threading decision, I chose the
event-driven path (Twisted).  For non-GUI aspects
(e.g. services), it's awesome ... not as awesome
when the Twisted and wxPython event loops have to
co-exist.  :^/  I'm still hoping some guru will
come up with a better solution than the current
compromises (timer, etc.), but they are adequately
functional for now, for my purposes.
Although I probably won't use BitPim myself (I'm very
old-fashioned in my cell phone usage ;)  I admire your
concept and execution.
Cheers,
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Guild of Python consultants?

2005-01-09 Thread Peter Hansen
Miklós P wrote:
Hello freelancers out there,
Is there such a thing somewhere? Yes, I'm aware of the Python Business
Forum.  But I mean something specifically for (individual) consultants.
By searching on Google, I couldn't find a "virtual guild" of consultants who
try to make a living from Python and technologies built around it 
The term "consultant" means different things to different people,
unfortunately.
I know of many people for whom "consultant" is synonymous with
"contract programmer", meaning somebody who looks for temporary
positions at (usually) an hourly rate somewhat higher than what
a permanent employee gets (but without benefits), and who simply
joins a team as a regular member, doing whatever they are told.
Some have special expertise, many do not.
I also know of many people (myself included) who restrict the term
to those who have a deep expertise in one or more areas and who
look for projects where they can be brought in to apply that
expertise, usually by telling the customer what to do (or what
not to do any more, perhaps).  This sort of work can be hourly,
or quite often daily or even at a fixed price (say, for specialized
"emergency" troubleshooting, or for a design task).
There is obviously overlap between those two descriptions but,
in my experience, very little overlap between the sorts of work
which those two breeds of "consultants" actually want to perform.
(The second type will take on jobs that the former would take,
often grudgingly if work is scarce, while the former are rarely
qualified to take on the sort of work that interests the latter.)
As a result, I suspect that any organization that doesn't make it
clear which type of "consultant" is involved could cause a great
deal of confusion amongst its members and their clients.
Which type do you mean?
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Speed revisited

2005-01-09 Thread Bulba!
On 8 Jan 2005 18:25:56 -0800, "John Machin" <[EMAIL PROTECTED]>
wrote:


>> Both versions use local variables, etc. Both have their
>> lists initially sorted. Both essentially use a loop with
>> conditional for comparison,
>> then process the record in the
>> same way.
>
>"process the record in the same way"??? That's an interesting use of
>"same".

Meaning when the records with the same 'english' key is found, just
write the comparison result to the result file.

>> The overhead of second version is that it also
>> uses cmp() function and two additional integer
>> variables - that should not slow the program _so much_.

>> I have measured the run of snippet 2 with time checkpoints
>> written to a log (write time delta to log every 200 records),
>> even made a graph of time deltas in spreadsheet and in fact
>> snippet 2 seems after initial slowdown looks exactly linear,
>> like  that:
>>
>> ^ (time)
>> |
>> |  /---
>> | /
>> |/
>> ---> (# of records written)
>>
>> So yes, it would scale to big files.
>
>On your empirical evidence, as presented. However, do read on ...

>>However, why is it so
>> frigging slow?!

>Mainly, because you are (unnecessarily) deleting the first item of a
>list. This requires copying the remaining items. It is O(N), not O(1).
>You are doing this O(N) times, so the overall result is O(N**2). Your
>graph has no obvious explanation; after how many cycles does the speed
>become constant?

After some 2000 records. I was "tracking" it with printouts of
variables and initially the main loop was taking advantage of 
records being sorted, with the first condition (with keys
being equal) quickly writing the records into a file, and the 
further into the dataset, the greater the distance was between 
the beginning of the list where the record was sought to the
appropriate record, i.e. either o or n were becoming steadily 
higher. This could  explain linearity further down the path: the 
list is becoming gradually shorter, so the deletion times 
were decreasing linearly, but in the meantime the search time 
was linearly increasing. 

>Secondly, you are calling cmp() up to THREE times when once is enough.
>Didn't it occur to you that your last elif needed an else to finish it
>off, and the only possible action for the else suite was "assert
>False"?

Sure, but I was trying to make it shorter and absolutely clear
what I mean in this place (when people see the comparison in every
place, they see immediately what it was, they don't have to
recall the variable). Obviously I'd optimise it in practice. It
was supposed to be "proof of concept" rather than any working
code.

BTW, this particular example didn't work out, but I still found 
Python to be the most convenient language for prototyping, I 
wrote smth like five versions of this thing, just to learn
dictionaries, lists, sets, etc. In no other language I'd do
it so quickly.

>It would appear after reading your "snippet 2" a couple of times that
>you are trying to implement the old 3-tape update method.

Well, ahem, I admit you got me curious just how it would work
with tapes (never used them), so I was sort of  trying to simulate
that - it's just a bit weird undertaking, I did it rather to explore
the issue and try to learn smth rather than to get working code. 

Deleting the first item from a list was to be a convenient 
equivalent of forwarding the  reading head on the tape one 
record ahead, because I assumed that any deletion from the 
list was to take more or less the same time, just like reading 
heads on tapes were probably reading the records with similar 
speeds regardless of what length of tape was already read.

>It would also appear that you are assuming/hoping that there are never
>more than one instance of a phrase in either list.

Sure. Because using advice of Skip Montanaro I initially used sets 
to eliminate duplicates. It's just not shown for brevity. If the
keys are guaranteed to be unique, it makes it easier to think
about the algorithm. 

>You need something a little more like the following.

>Note that in your snippet2 it was not very obvious what you want to do
>in the case where a phrase is in "new" but not in "old", and vice versa
>-- under one circumstance (you haven't met "end of file") you do
>nothing but in the the other circumstance you do something but seem to
>have not only a polarity problem but also a copy-paste-edit problem.

What exactly is a "polarity problem"?

I concede that the code is rather contrived, but I didn't bother
to do smth like writing classes or functions that would simulate
a tape reader, so the result is rather ugly. I only posted it 
because I could not explain why it were so slow. 

> In
>the following code I have abstracted the real requirements as
>handle_XXX_unmatched()

Thanks, I'll have to try that out.



--
It's a man's life in a Python Programming Association.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: read numbers from file and covert to integer

2005-01-09 Thread Peter Hansen
Øystein Western wrote:
I got a file with a lot blocks of numbers that are strings. I'd like to read 
all
this numbers and convert them to numbers for futher compareation. How can I
convert all this numbers to integer? Do I have to put all numbers into a 
list?
It would help immensely if you could post some kind of
example of the sorts of data you are talking about,
perhaps a hex representation of the bytes (if it's
a binary file).  Otherwise we are just guessing how
you are using the terms "block", "number", "string",
and even "integer".
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: windows mem leak

2005-01-09 Thread Peter Hansen
Bob Smith wrote:
Peter Hansen wrote:
[snip details of Bob's platform]
WinXP Home, Service Pack 2, AMD 1400MHz proc, 256MB Ram
That's not really much RAM for a WinXP box.  Do you have
lots of physical memory available before running?
(I presume you're using a version of nmap that's compiled
for Windows XP then?
Yes, I am.
It's certainly not standard.
That's a matter of opinion. Nmap works fine on the WinXP machine.
Perhaps my use of "standard" was obscure, since it's definitely
not a matter of opinion, the way I intended it.  What I meant
was "nmap is certainly not included in the standard Win XP
distribution".
How have
you proven that it is not *that* program which is at fault?)
I have not. All I know is that on WinXP, the program uses 100% CPU at 
times and consumes more Ram than is available (the page file grows to 
700 or 800MB). It runs OK for a few hours and then produces a 'not 
enough resources' error. 
Is it certain that this memory is being consumed by the Python
process?  I could imagine, for example, there being dozens of
new processes spawned with os.system.  Does the Task Manager
back up the theory that this "python.exe" instance is the one
causing the trouble?  Presumably it should be clear even before
the machine grows unusable.  Note that you can select which
columns are shown in the "Processes" tab of the Task Manager
window, to get more detail on a given process.  (The Performance
Monitor found under Control Panel, Administrative Tools can
be even more useful and precise.)

And, the machine is generally unuserable. On 
Linux, it has no impact whatsoever on resources. Granted, the Linux 
machine is much more robust, but one wouldn't expect this great a 
difference. I can rewrite it so that it's pure Pyhton (no calling nmap) 
if you think that would be a good idea. Perhaps that would at least 
remove nmap from the equation.
A simpler test might be to change the nmap call to something
guaranteed benign, like a call to "dir", and try with that.
That's assuming you don't actually need the output of nmap
to reproduce the problem, which of course isn't sure.  Still,
it would be an easy test, and might show a problem elsewhere.
I can run it if you like and take a screen shot of the error. You'll 
have to give me a few hours though ;)
I trust that you are getting the error dialog you say you are. :-)
I have a feeling that the message by itself helps little, however,
and that you'll have to try a few different approaches to observe
the problem as it grows, via Task Manager or another tool, rather
than just trying to guess what happened after the machine is
already effective kaput.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Speed revisited

2005-01-09 Thread Bulba!
On Sat, 08 Jan 2005 17:57:30 -0700, Steven Bethard
<[EMAIL PROTECTED]> wrote:

>Note that Python lists are implemented basically as arrays, which means 
>that deleting an item from anywhere but the end of the list is O(n) 
>because all items in the list must be moved down to fill the hole.

Ouch...



--
I have come to kick ass, chew bubble gum and do the following:

from __future__ import py3k

And it doesn't work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "A Fundamental Turn Toward Concurrency in Software"

2005-01-09 Thread Jorgen Grahn
On 07 Jan 2005 13:48:41 -0800, Paul Rubin <> wrote:
> aurora <[EMAIL PROTECTED]> writes:
>> Just gone though an article via Slashdot titled "The Free Lunch Is
>> Over: A  Fundamental Turn Toward Concurrency in Software"
>> [http://www.gotw.ca/publications/concurrency-ddj.htm]. It argues that
>> the  continous CPU performance gain we've seen is finally over. And
>> that future  gain would primary be in the area of software concurrency
>> taking advantage  hyperthreading and multicore architectures.
> 
> Well, another gain could be had in making the software less wasteful
> of cpu cycles.
> 
> I'm a pretty experienced programmer by most people's standards but I
> see a lot of systems where I can't for the life of me figure out how
> they manage to be so slow.  It might be caused by environmental
> pollutants emanating from Redmond.

Yeah, and possibly by overuse of IPC mechanisms, gratituous threading et
cetera ...

Concurrency is hard and complex. I'd prefer to see it as rarely as possible.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: windows mem leak

2005-01-09 Thread Roel Schroeven
Bob Smith wrote:
Peter Hansen wrote:
How have
you proven that it is not *that* program which is at fault?)
It would surprise me: even if it consumes much CPU-time, memory and 
other resources, each instances returns all resources when it exits.

I have not. All I know is that on WinXP, the program uses 100% CPU at 
times and consumes more Ram than is available (the page file grows to 
700 or 800MB). It runs OK for a few hours and then produces a 'not 
enough resources' error. And, the machine is generally unuserable. On 
Linux, it has no impact whatsoever on resources. Granted, the Linux 
machine is much more robust, but one wouldn't expect this great a 
difference. I can rewrite it so that it's pure Pyhton (no calling nmap) 
if you think that would be a good idea. Perhaps that would at least 
remove nmap from the equation.
I wrote a very simple and small fake_nmap that just looks at the 
IP-address and prints "open", "closed" or "filtered" to stdout. When I 
run your python program (Python 2.4 on Windows XP, like you), the CPU is 
utilized 100% (about half of it goes to csrss.exe whatever that may be); 
about half of the CPU time is spent in the kernel. The system stays 
usable (at least for now, it's been running for about 5 minutes now), 
but memory use is increasing, slow but steadily.

The task manager shows, in addition to a number of fake_nmap.exe 
processes, a number of cmd.exe processes. I don't understand where these 
come from: I know os.system ()uses the shell, but isn't os.popen() 
supposed to open the process directly? It seems there are a lot more 
instances of cmd.exe than of fake_nmap.exe; no idea what that tells us.

Also, it takes quite some time before "256 threads running incl. main" 
is printed the first time, so I think the system needs all that time to 
create all the threads. It would be normal for memory use to keep 
increasing untill all threads are created, but I'm fairly certain memory 
use is still increasing now.

--
"Codito ergo sum"
Roel Schroeven
--
http://mail.python.org/mailman/listinfo/python-list


Re: printing line numbers for debugging purpose

2005-01-09 Thread python
Below is a function to get the current line number and file name.

/Jean Brouwers


-  # dashes added to preserve indentation.
-
- import traceback
-
- def caller(up=0):
- '''Get file name, line number, function name and
-source text of the caller's caller as 4-tuple:
-(file, line, func, text).
-
-The optional argument 'up' allows retrieval of
-a caller further back up into the call stack.
-
-Note, the source text may be None and function
-name may be '?' in the returned result.  In
-Python 2.3+ the file name may be an absolute
-path.
- '''
- try:  # just get a few frames
- f = traceback.extract_stack(limit=up+2)
- if f:
-return f[0]
- except:
- if __debug__:
-traceback.print_exc()
- pass
-  # running with psyco?
- return ('', 0, '', None)
- 
- 
- if __name__ == '__main__':
- print caller()
-

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


Re: unicode support

2005-01-09 Thread Charlton Wilbur
> "xah" == xah  <[EMAIL PROTECTED]> writes:

xah> python supports unicode in source
xah> code by putting a coding declaration as the first line.
 
[...]

xah> In perl, support of unicode is very flaky. The language does
xah> not support it, [...]

All:

Xah Lee is trolling.  (Whether he's *only* a troll, or a reasonable
person who occasionally trolls to amuse himself, is a matter of
perspective.)  Please note the inaccuracy of his comment on Perl and
the two newsgroups to which this message was posted before replying;
this is a clear case of "lets you and him fight."

Charlton


-- 
cwilbur at chromatico dot net
cwilbur at mac dot com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: windows mem leak

2005-01-09 Thread Peter Hansen
Roel Schroeven wrote:
Peter Hansen wrote:
How have
you proven that it is not *that* program which is at fault?)
It would surprise me: even if it consumes much CPU-time, memory and 
other resources, each instances returns all resources when it exits.
I agree with that statement, but you assume that the program *is*
exiting.  And your initial analysis with "fake_nmap" suggests
that, at least to the extent of having leftover cmd.exe's kicking
around, maybe it is not.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


else condition in list comprehension

2005-01-09 Thread Luis M. Gonzalez
Hi there,

I'd like to know if there is a way to add and else condition into a
list comprehension. I'm sure that I read somewhere an easy way to do
it, but I forgot it and now I can't find it...

for example:
z=[i+2 for i in range(10) if i%2==0]
what if I want i to be "i-2" if i%2 is not equal to 0?

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


Re: Speed revisited

2005-01-09 Thread John Machin
Bulba! wrote:
> On 8 Jan 2005 18:25:56 -0800, "John Machin" <[EMAIL PROTECTED]>
> wrote:
>
> >Secondly, you are calling cmp() up to THREE times when once is
enough.
> >Didn't it occur to you that your last elif needed an else to finish
it
> >off, and the only possible action for the else suite was "assert
> >False"?
>
> Sure, but I was trying to make it shorter and absolutely clear
> what I mean in this place (when people see the comparison in every
> place, they see immediately what it was, they don't have to
> recall the variable). Obviously I'd optimise it in practice. It
> was supposed to be "proof of concept" rather than any working
> code.

Three is shorter than one? See immediately? I have to disagree. People
would be more put off by looking at your overly-complicated comparison
three times and having to check character-by-character that it was
doing exactly the same thing each time (i.e. your copy/paste had
worked) than by "recalling" a sensibly-named variable like
"cmp_result".

>
> BTW, this particular example didn't work out, but I still found
> Python to be the most convenient language for prototyping, I
> wrote smth like five versions of this thing, just to learn
> dictionaries, lists, sets, etc. In no other language I'd do
> it so quickly.

NOW we're on the same bus.

>
> >It would appear after reading your "snippet 2" a couple of times
that
> >you are trying to implement the old 3-tape update method.
>
> Well, ahem, I admit you got me curious just how it would work
> with tapes (never used them), so I was sort of  trying to simulate
> that - it's just a bit weird undertaking, I did it rather to explore
> the issue and try to learn smth rather than to get working code.

The 3-tape technique is worth understanding, for handling datasets that
won't fit into memory. More generally, when learning, you *need* to get
working code out of your practice exercises. Otherwise what are you
learning? You don't want to wait until you have two 10GB datasets to
"diff" before you start on thinking through, implementing and testing
what to do on end-of-file.

>
> Deleting the first item from a list was to be a convenient
> equivalent of forwarding the  reading head on the tape one
> record ahead, because I assumed that any deletion from the
> list was to take more or less the same time, just like reading
> heads on tapes were probably reading the records with similar
> speeds regardless of what length of tape was already read.

A reasonable assumption; however if the reading stopped and restarted,
an inordinate amount of time was taken accelerating the drive up to
reading speed again. The idea was to keep the tape moving at all times.
This required techiques like double-buffering, plus neat clean brief
fast processing routines.

... but you mixed in moving the indexes (with e.g. o+=1) with confusing
results.

Deleting the first item of a list in this circumstance reminds me of
the old joke: "Q: How many members of military organisation X does it
take to paint the barracks? A: 201, 1 to hold the paint-brush and 200
to lift the barracks and rotate it."

Tip 1: Once you have data in memory, don't move it, move a pointer or
index over the parts you are inspecting.

Tip 2: Develop an abhorrence of deleting data.

>
> >It would also appear that you are assuming/hoping that there are
never
> >more than one instance of a phrase in either list.
>
> Sure. Because using advice of Skip Montanaro I initially used sets
> to eliminate duplicates.

I see two problems with your implementation of Skip's not-unreasonable
suggestion. One: You've made the exercise into a multi-pass algorithm.
Two: As I posted earlier, you need to get all the instances of the same
key together at the same time. Otherwise you get problems. Suppose you
have in each list, two translations apple -> polish1 and apple ->
polish2. How can you guarantee that you remove the same duplicate from
each list, if you remove duplicates independently from each list?

> It's just not shown for brevity.

Then say so. On the evidence, brevity was not a plausible explanation
for the absence. :-)

> If the
> keys are guaranteed to be unique, it makes it easier to think
> about the algorithm.

Unfortunately in the real world you can't just imagine the problems
away. Like I said, you have to think about the requirements first -- 9
cases of (0, 1, many) x (0, 1, many); what do you need to do? Then
think about an implementation.

>
> >Note that in your snippet2 it was not very obvious what you want to
do
> >in the case where a phrase is in "new" but not in "old", and vice
versa
> >-- under one circumstance (you haven't met "end of file") you do
> >nothing but in the the other circumstance you do something but seem
to
> >have not only a polarity problem but also a copy-paste-edit problem.
>
> What exactly is a "polarity problem"?

You appeared to be treating "old" like I would have expected you to
treat "new" and vice versa.

>
> I concede that the code is rather contrived, 

Re: windows mem leak

2005-01-09 Thread Roel Schroeven
Peter Hansen wrote:
Roel Schroeven wrote:
Peter Hansen wrote:
How have
you proven that it is not *that* program which is at fault?)

It would surprise me: even if it consumes much CPU-time, memory and 
other resources, each instances returns all resources when it exits.

I agree with that statement, but you assume that the program *is*
exiting.  And your initial analysis with "fake_nmap" suggests
that, at least to the extent of having leftover cmd.exe's kicking
around, maybe it is not.
I see. The number of cmd.exe's running was not *that* big though: about 
5-10 I would say. And their PID's kept changing.

I took a look with Process Explorer from sysinternals, which shows the 
processes as a tree instead of a simple list. Apparently each fake_nmap 
is a child of a cmd.exe, meaning that os.popen indead uses the shell to 
run processes. I wouldn't be surprise if cmd.exe would be the culprit here.

--
"Codito ergo sum"
Roel Schroeven
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Bengt Richter
On 09 Jan 2005 03:10:15 -0800, Paul Rubin  wrote:

>Nick Coghlan <[EMAIL PROTECTED]> writes:
>> Trying to push it a level further (down to expressions) would, IMO, be
>> a lot of effort for something which would hurt readability a lot.
>
>I think we should just try to do things in a simple and general way
>and not try to enforce readability.  For example, the
>slightly-overcomplex code that I proposed might have been generated by
>a macro, or even by a compiler from some other language.  No human
>would ever have to look at it, so it doesn't matter whether it's
>easily readable.  There's no reason to add needless constraints on the
>language just to make writing ugly code difficult.  The main goal
>should be to make writing clear code easy, not to worry about whether
>someone might also write ugly code.
+1 ;-)

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


Re: else condition in list comprehension

2005-01-09 Thread Reinhold Birkenfeld
Luis M. Gonzalez wrote:
> Hi there,
> 
> I'd like to know if there is a way to add and else condition into a
> list comprehension. I'm sure that I read somewhere an easy way to do
> it, but I forgot it and now I can't find it...
> 
> for example:
> z=[i+2 for i in range(10) if i%2==0]
> what if I want i to be "i-2" if i%2 is not equal to 0?

You'll have to add the condition at the front:

z = [(i+2, i-2)[i%2] for i in range(10)]

should do what you need.

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


Re: python3: accessing the result of 'if'

2005-01-09 Thread Bengt Richter
On Sat, 08 Jan 2005 18:30:25 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote:

>Carl Banks wrote:
>> Right.  But you know that as soon as you add this to simple
>> expressions, a bunch of people are going to come here whining about how
>> they don't get to use where with if-expressions.
So why shouldn't they get to?

>> 
>> Frankly, they might have a point here.  Although we have replacing
>> lambda expressions on our minds, I have in mind a different problem
>> that a where-statement would solve perfectly.  But it would have to be
>> used with an if-expression.
>
>I have a different suggestion for this.
>
>'as' is used for renaming in import statements. 'as' will be used for 
>exception 
>naming in Python 3k.
>
>So let's use it for expression naming in 'if' statements, too.
>
>if someregexp.match(s) as m:
>   # blah using m
>elif someotherregexp.match(s) as m:
>   # blah using m
>

If 'where: ...' were an expression suite ISTM you could write

 if m where: m = someregexp.match(s)  # same-line format
blah(m)
 elif m where:
m = someotherregexp(s) # indented suite format
blah(m) # dedent from where-suite starts elif-suite

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


  1   2   >