Re: SuSE 9.1: updating to python-2.4

2005-01-09 Thread Peter Maas
Torsten Mohr schrieb:
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?
I uninstalled 2.3.3 and compiled/installed 2.4 from source.
Now there is a problem: each time I change my system, SuSE tries
to reinstall 2.3.3 because of dependencies. I tried to mark
SuSE-Python as tabu (taboo?) but this it isn't stored. Not sure
if it is my fault or SuSE's. I'm too lazy to track it down.
Perhaps you can do a regular upgrade via FTP. I didn't try that.
--
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
--
http://mail.python.org/mailman/listinfo/python-list


Re: Speed revisited

2005-01-09 Thread Andrea Griffini
On 9 Jan 2005 16:03:34 -0800, "John Machin" <[EMAIL PROTECTED]>
wrote:

>My wild guess: Not a common use case. Double-ended queue is a special
>purpose structure.
>
>Note that the OP could have implemented the 3-tape update simulation
>efficiently by reading backwards i.e. del alist[-1]

Note that I was just trying to say that it's not obvious
that list insertion at the first element is O(n); because
there are "less naive" implementation that can do better.
For a lower level language O(n) is probably what 99% of
programmers indeed would expect, but for a VHLL like
python this is IMO not the case.

I remember when a few years ago working with PowerBuilder
(a RAD environment for client-server applications) to my
great surprise I found that even adding at the end of a
list was O(n) in that language... where is the line ?
After all "smart" reallocation is still a tradeoff (extra
"wasted" space traded for diminshed copying) ...

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


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
Steve Bethard wrote:
Robert Kern wrote: 
  def square(x):
  return x*x
  map(square, range(1000))
versus
  [x*x for x in range(1000)]
Hint: function calls are expensive.
$ python -m timeit -s "def square(x): return x*x" "map(square, range(1000))"
1000 loops, best of 3: 693 usec per loop
$ python -m timeit -s "[x*x for x in range(1000)]"
1000 loops, best of 3: 0.0505 usec per loop
Functions will often be complicated enought that inlining them is not
feasible.
True, true.  However, list comprehensions still seem to be comparable in 
speed (at least in Python 2.4):

$ python -m timeit -s "def f(x): return x*x" "[f(x) for x in xrange(1000)]"
1000 loops, best of 3: 686 usec per loop
$ python -m timeit -s "def f(x): return x*x" "map(f, xrange(1000))"
1000 loops, best of 3: 690 usec per loop
Presumably this is because the C code for the byte codes generated by a 
list comprehension isn't too far off of the C code in map.  I looked at 
bltinmodule.c for a bit, but I'm not ambitious enough to try verify this 
hypothesis. ;)

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


Re: Datetime module

2005-01-09 Thread Binu K S
The time module will do.
>>> import time
>>> time.ctime()
'Mon Jan 10 11:17:54 2005'

Use strftime if you need to format the time differently.
>>> time.strftime("%Y-%m-%d %H:%m:%S",time.localtime())
'2005-01-10 11:01:45'

On 9 Jan 2005 21:46:12 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I am writing a script that acts as an AIM bot [using twisted.IM's base
> scripts] and I want to add a logging feature. I got it to log who sends
> what to whom, but what I want to add is the date and time that the
> message was sent (or recieved by the bot), I tried to look at datetime
> on my own, and I couldn't get anything to work.
> Anyone know a simple way to get the current date and/or time?
> 
> Thanks!
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Steven Bethard
John Machin wrote:
Steven Bethard wrote:
Note that list comprehensions are also C-implemented, AFAIK.
Rather strange meaning attached to "C-implemented". The implementation
generates the code that would have been generated had you written out
the loop yourself, with a speed boost (compared with the fastest DIY
approach) from using a special-purpose opcode LIST_APPEND. See below.
Fair enough. ;)
So you basically replace the SETUP_LOOP, CALL_FUNCTION, POP_TOP and 
POP_BLOCK with a DUP_TOP and a LIST_APPEND.

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


Datetime module

2005-01-09 Thread rublind
I am writing a script that acts as an AIM bot [using twisted.IM's base
scripts] and I want to add a logging feature. I got it to log who sends
what to whom, but what I want to add is the date and time that the
message was sent (or recieved by the bot), I tried to look at datetime
on my own, and I couldn't get anything to work.
Anyone know a simple way to get the current date and/or time?

Thanks!

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


Re: else condition in list comprehension

2005-01-09 Thread It's me
> z = [i + (2, -2)[i % 2] for i in range(10)]

But then why would you want to use such feature?  Wouldn't that make the
code much harder to understand then simply:

z=[]
for i in range(10):
if  i%2:
z.append(i-2)
else:
z.append(i+2)

Or are we trying to write a book on "Puzzles in Python"?


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


Re: a new Perl/Python a day

2005-01-09 Thread Andy Gross
On Jan 10, 2005, at 12:11 AM, Scott Bryce wrote:
No. Perl may have some interesting idiosyncrasies, especially for a 
programmer with little or no Unix experience, but I find it neither 
frustrating, inane nor incompetent. The more I use it, the more I like 
it.
I don't see what UNIX experience has to do with it.  I have plenty of 
it, and still have to look at the documentation to remember that I need 
to type '$|' to turn buffering off.  Ditto for the rest of the perl 
line-noise syntax.

/arg

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


Re: Python Operating System???

2005-01-09 Thread Paul Rubin
Arich Chanachai <[EMAIL PROTECTED]> writes:
> >  And I think Pypy is currently set up to compile Python
> >into Pyrex and then run the Pyrex results through GCC.
> >
> But of course, who's going to argue that Pyrex produces "compiled
> Python"?  

Pyrex produces compiled Python in the same sense that asm produces
"compiled C".  PyPy contains a Python compiler which reads Python
source and produces Pyrex output.  The Pyrex output then gets compiled
by the Pyrex compiler and then the C compiler before ending up with
machine code.  There is nothing terribly bizarre about this kind of
compiler.  For example, Gnu Common Lisp compiles Lisp code into C,
then runs the C code through gcc.  For that matter, the Yacc/Bison
parser generators do something similiar.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Long strings as function parameters

2005-01-09 Thread Jeremy Bowers
On Sun, 09 Jan 2005 08:36:04 -0800, onlyonemc 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,
> -mark


Others have pointed out that there is no particular inefficient way to
pass a string.

However that only solves the immediate problem of passing. Once inside the
function you should be aware that all string operations that change the
string will create a new string, including slicing and such.

This may not be a problem if you are examining it in small chunks, but if
you routinely taking distinct multi-megabyte hunks out of it with slices,
you will be constructing and destructing a lot of strings.

I had thought there was an obvious class in the standard library to assist
with this, but I must have been wrong. I think you can load it as an array
from the array module (as long as it is an array of bytes and not an
encoding like UTF-8 or something), or you might be able to use the mmap
module if the string comes from a file. Both of those techniques can also
load the info directly from a file so there is only one copy needed.
(Wasn't there a "buffer" kind of class at one point, that you could slice
into and get something back that didn't make any copies of strings?)

Again, this is only an issue depending on usage, and you should probably
prototype it while ignoring these issues and see if it is fast enough. But
if it isn't, there are options.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a new Perl/Python a day

2005-01-09 Thread Scott Bryce
Bob Smith wrote:
Scott Bryce wrote:
Xah Lee wrote:
frustrated constantly by its inanities and incompetences.)

I don't see what this has to do with Perl.

You're joking, right?
No. Perl may have some interesting idiosyncrasies, especially for a 
programmer with little or no Unix experience, but I find it neither 
frustrating, inane nor incompetent. The more I use it, the more I like it.

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


Re: Python Operating System???

2005-01-09 Thread Arich Chanachai
Paul Rubin wrote:
Arich Chanachai <[EMAIL PROTECTED]> writes:
 

Yes, compiled Lisp.  There are Python compilers too.\
 

???  You mean like Pyrex or some such?  I wouldn't exactly call these
"Python" compilers, as that kind of obscures some underlying
(critical) facts.
   

Also psyco.
Directly to machine code how could anyone say this is not compiled 
Python.  I am right with you.  On the other hand however, its 
compilation occurs on-the-fly (JIT) and is no more compiled than Java.  
There is an argument either way.  I have heard of Java OSs in the works 
and possibly already existing...are these pure Java?

 And I think Pypy is currently set up to compile Python
into Pyrex and then run the Pyrex results through GCC.
 

But of course, who's going to argue that Pyrex produces "compiled 
Python"?  I expect many would beg to differ, and in fact might like to 
kiss your toes just for the mere pleasure of contradicting and arguing 
against any assertion that Pyrex produces "compiled Python".
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting rid of "self."

2005-01-09 Thread Jeremy Bowers
On Mon, 10 Jan 2005 01:51:07 +0100, BJÃrn Lindqvist wrote:
> This is promising, I'm content with whatever slowdowns necessary as long
> as I can prove those who say "you can't do it" wrong. :)

Since I think I'm the only person in this discussion that said anything
about what you can't do, be clear on what I said. You can't have both of
undeclared attributes on self and no use of "self", in particular to add
new attributes. 

This is, if you take the time to understand what I mean, trivially true;
*somewhere* you need to declare whether a var is local to the function or
an instance member. For me, I prefer the explicit "self" and getting rid
of "self" now leaves you with the need to declare member variables
*somehow*, which I don't consider progress. But no matter what other magic
Alex works, you're only going to get one or the other; it's impossible for
the compiler to divine what you mean otherwise.

My point here isn't that you "can't" hack together code to do something
like what you want, and it is certainly a valid exercise in plumbing the
depths of Python and learning. My point is that you'll have to pay a price
in other ways. You can't make self go away "for free". And that "can't" I
do mean.

(You weren't necessarily claiming you could. But I thought it still worth
saying; even if you weren't trying to remove "self" "for free", others
certainly would mean it.)

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


Re: Old Paranoia Game in Python

2005-01-09 Thread [EMAIL PROTECTED]

Paul McGuire wrote:
> <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> >
> > Aahz wrote:
> > > Trust the computer, the computer is your friend.
> >
> > However, the computer isn't a fuckin' mind reader.
> >
> > If you're going to post source code on the usenet, don't
> > have lines longer than 72 characters. Otherwise you'll
> > find your code has wrapped lines. This not only causes
> > syntax errors in your choose and print statements but
> > also fucks up the formatting of of printed paragraphs.
> >
> > Stupid human.
> >
>
> I copy-and-pasted to a file named para1.py, then wrote the
> following python script with pyparsing to fix the erroneous
> line breaks.
>
> -- Paul
>
> ===
> from pyparsing import *
>
> extraLineBreak = White(" ",exact=1) + LineEnd().suppress()
> text = file("para1.py").read()
> newtext = extraLineBreak.transformString(text)
> file("para2.py","w").write(newtext)
Damn, that was pretty neat! You learn something new every day.

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


Re: Python Operating System???

2005-01-09 Thread Paul Rubin
"Roose" <[EMAIL PROTECTED]> writes:
> Are you actually going to answer any of my questions?  Let's see
> this "JavaScript task scheduler" you have written!

I wrote it at a company and can't release it.  It ran inside a
browser.  There was nothing terribly amazing about it.  Obviously the
tasks it scheduled were not kernel tasks.  Do you know how Stackless
Python (with continuations) used to work?  That had task switching,
but those were not kernel tasks either.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Operating System???

2005-01-09 Thread Roose

"Paul Rubin"  wrote in message
news:[EMAIL PROTECTED]
> "Roose" <[EMAIL PROTECTED]> writes:
> > > I've written file systems in Python, and task schedulers in
> > > Javascript, and they were fine for their purposes
> >
> > Uh, not to be rude, but what are you talking about?  If I'm not mistaken
> > Javascript is that scripting language that runs inside a browser,
>
> Correct.
>
> > an application.  How are you going to save and restore CPU state in
> > Javascript, or even call assembly that does it in Javascript?  How
> > do you switch into kernel mode in Javascript?  We are on completely
> > different pages apparently.
>
> Correct.

Are you actually going to answer any of my questions?  Let's see this
"JavaScript task scheduler" you have written!  I'm calling bullshit on that,
seeing as you declined to say anything useful about it.  But I'm open to
learn anything.  Let's see it.  Until then I'm not sure I want to spend a
lot of energy arguing with you, because you're either pulling my leg or just
profoundly mistaken.


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


Re: Python Operating System???

2005-01-09 Thread Paul Rubin
Arich Chanachai <[EMAIL PROTECTED]> writes:
> >Yes, compiled Lisp.  There are Python compilers too.\
> >
> ???  You mean like Pyrex or some such?  I wouldn't exactly call these
> "Python" compilers, as that kind of obscures some underlying
> (critical) facts.

Also psyco.  And I think Pypy is currently set up to compile Python
into Pyrex and then run the Pyrex results through GCC.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Operating System???

2005-01-09 Thread Arich Chanachai
Paul Rubin wrote:
"Roose" <[EMAIL PROTECTED]> writes:
 

...
Upon reading back in the thread I see that you mean compiled Lisp,
no?  I was thinking that there would be a Lisp interpreter in a
kernel, which afaik doesn't exist.
   

Yes, compiled Lisp.  There are Python compilers too.\
 

???  You mean like Pyrex or some such?  I wouldn't exactly call these 
"Python" compilers, as that kind of obscures some underlying (critical) 
facts.

In any case, as I said before I don't think it is impossible, just a
poor engineering decision and I don't see the rationale behind it.
   

I don't see a convincing case against writing an OS even in
interpreted Python, though of course I'd want it to be compiled if
possible.
What do you think OS's do, that Python wouldn't be suitable for?  Your
examples of task switching and virtual memory are unconvincing.  Those
just require setting up some suitable tables and then calling a
low-level routine to poke some CPU registers.  File systems can be
more performance intensive, but again, in those, much of the cpu drain
can be relegated to low-level routines and the complexity can be
handled in Python.
 

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


Re: a new Perl/Python a day

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

XL> i'll cross post to comp.lang.perl.misc and comp.lang.python.
XL> If you spot mistakes, feel free to correct or discourse here.

Error #1:  crossposting to those two groups.  

(Error #2 is implying that you're a Perl expert, but someone else
already pointed that out.)

Charlton


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


Re: Old Paranoia Game in Python

2005-01-09 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> Aahz wrote:
> > Trust the computer, the computer is your friend.
>
> However, the computer isn't a fuckin' mind reader.
>
> If you're going to post source code on the usenet, don't
> have lines longer than 72 characters. Otherwise you'll
> find your code has wrapped lines. This not only causes
> syntax errors in your choose and print statements but
> also fucks up the formatting of of printed paragraphs.
>
> Stupid human.
>

I copy-and-pasted to a file named para1.py, then wrote the following python
script with pyparsing to fix the erroneous line breaks.

-- Paul

===
from pyparsing import *

extraLineBreak = White(" ",exact=1) + LineEnd().suppress()
text = file("para1.py").read()
newtext = extraLineBreak.transformString(text)
file("para2.py","w").write(newtext)


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


Re: Python Operating System???

2005-01-09 Thread Paul Rubin
"Roose" <[EMAIL PROTECTED]> writes:
> > I've written file systems in Python, and task schedulers in
> > Javascript, and they were fine for their purposes
> 
> Uh, not to be rude, but what are you talking about?  If I'm not mistaken
> Javascript is that scripting language that runs inside a browser, 

Correct.

> an application.  How are you going to save and restore CPU state in
> Javascript, or even call assembly that does it in Javascript?  How
> do you switch into kernel mode in Javascript?  We are on completely
> different pages apparently.

Correct.

> Upon reading back in the thread I see that you mean compiled Lisp,
> no?  I was thinking that there would be a Lisp interpreter in a
> kernel, which afaik doesn't exist.

Yes, compiled Lisp.  There are Python compilers too.

> In any case, as I said before I don't think it is impossible, just a
> poor engineering decision and I don't see the rationale behind it.

I don't see a convincing case against writing an OS even in
interpreted Python, though of course I'd want it to be compiled if
possible.

What do you think OS's do, that Python wouldn't be suitable for?  Your
examples of task switching and virtual memory are unconvincing.  Those
just require setting up some suitable tables and then calling a
low-level routine to poke some CPU registers.  File systems can be
more performance intensive, but again, in those, much of the cpu drain
can be relegated to low-level routines and the complexity can be
handled in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Operating System???

2005-01-09 Thread Roose
> I've written file systems in Python, and task schedulers in
> Javascript, and they were fine for their purposes

Uh, not to be rude, but what are you talking about?  If I'm not mistaken
Javascript is that scripting language that runs inside a browser, an
application.  How are you going to save and restore CPU state in Javascript,
or even call assembly that does it in Javascript?  How do you switch into
kernel mode in Javascript?  We are on completely different pages apparently.

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

Upon reading back in the thread I see that you mean compiled Lisp, no?  I
was thinking that there would be a Lisp interpreter in a kernel, which afaik
doesn't exist.  In any case, as I said before I don't think it is
impossible, just a poor engineering decision and I don't see the rationale
behind it.  Sure you can do anything for intellectual purposes and you'd
probably learn a lot, but the OP is looking for an easier way to write an
OS -- and that is not to write it in Python.



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


Re: a new Perl/Python a day

2005-01-09 Thread Bob Smith
Scott Bryce wrote:
Xah Lee wrote:
frustrated constantly by its inanities and incompetences.)
I don't see what this has to do with Perl.
You're joking, right?
--
http://mail.python.org/mailman/listinfo/python-list


Re: a new Perl/Python a day

2005-01-09 Thread James Stroud
On Sunday 09 January 2005 05:31 pm, Scott Bryce wrote:
> Xah Lee wrote:
> > frustrated constantly by its inanities and incompetences.)
>
> I don't see what this has to do with Perl.

On Sunday 09 January 2005 04:28 pm, Matt Garrish wrote:
> What language are you an expert at? It certainly isn't Perl.


Very dry humor indeed!


bob = [1,2,3,4]
carol = [bob,bob]
# not inane dereferencing
print carol[1][3]



$bob = [1,2,3,4] ;
$carol = [ $bob, $bob ] ;
# inane dereferencing
print "$carol->[1][3]\n" ;





-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
611 Charles E. Young Dr. S.
MBI 205, UCLA 951570
Los Angeles CA 90095-1570
http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Powerful CGI libraries for Python?

2005-01-09 Thread sam
Hi,
I m looking for a CGI libraries just  like perl's CGI.pm for Python.
From google, I found quite a few of CGI libraries already written for 
python. But I haven't had experience to try any of them in Python.

Can anyone share your Python CGI experience with me? Which library is 
better in terms of functionality and stability?

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


Re: python3: 'where' keyword

2005-01-09 Thread Paul Rubin
"Carl Banks" <[EMAIL PROTECTED]> writes:
> And a suite, be it a def statement, a where block, or whatever, belongs
> in a statement, not an expression.

So do you approve of the movement to get rid of the print statement?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please Contribute Python Documentation!

2005-01-09 Thread Kent Johnson
Aahz wrote:
In article <[EMAIL PROTECTED]>,
Tony Meyer <[EMAIL PROTECTED]> wrote:
I don't think I've seen such a statement before - the stuff I've seen
all indicates that one should be submitting proper LaTeX docs/patches.
If plain-text contributions are welcome, could this be added to the doc
about contributing to the docs?  (I suppose I could submit a patch, but
that seems overkill ).

It *is* in the docs now -- see the top of
http://www.python.org/doc/2.4/doc/doc.html
It's also spelled out pretty clearly in the "About this document" document you get by clicking on 
the link at the bottom of every page.

Kent
(This has been the official policy for some time, but you're right that
it wasn't earlier documented.  So I filed a bug report. ;-)  If you
think this still isn't enough, file another.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: a new Perl/Python a day

2005-01-09 Thread Scott Bryce
Xah Lee wrote:
frustrated constantly by its inanities and incompetences.)
I don't see what this has to do with Perl.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Speed revisited

2005-01-09 Thread Kent Johnson
Andrea Griffini wrote:
I've to admit that I also found strange that deleting the
first element from a list is not O(1) in python. My wild
guess was that the extra addition and normalization required
to have insertion in amortized O(1) and deletion in O(1) at
both ends of a random access sequence was going to have
basically a negligible cost for normal access (given the
overhead that is already present in python).
This was added to Python 2.4 as collections.deque
Kent
--
http://mail.python.org/mailman/listinfo/python-list


RE: Please Contribute Python Documentation!

2005-01-09 Thread Tony Meyer
> It *is* in the docs now -- see the top of
> http://www.python.org/doc/2.4/doc/doc.html

Oops.  I ought to have checked rather than going by memory (I suppose the
last time I looked 2.3 would have been current).  Thanks for correcting me!

=Tony.Meyer

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


Re: path to python file given module

2005-01-09 Thread Gene
It works now.
Thanks.

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


Re: path to python file given module

2005-01-09 Thread Steve Holden
Gene wrote:
that method doesn't seem to work as well on UNIX:
wla apocalypse[94] ~/filegen > ls
filegen.py  OLDwla_csv2objects.py   wlaclasses.py
filegen.pyc templates/  wlaclasses.pyc
gen_all_from_csv.py test.py*
wla apocalypse[95] ~/filegen > python

Use the module's __file__ attribute:
 >>> import Image
 >>> Image.__file__
'/usr/lib/python2.4/site-packages/PIL/Image.pyc'
 >>>
While this doesn't give you the source, it goves you enough to make a 
fair guess about where the source is likely to be, and a littel further 
manipulation should be able to confirm 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: python3: 'where' keyword

2005-01-09 Thread Carl Banks

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.


I couldn't disagree more.  I belive in the Zen of Python.  I believe
the Zen of Python is the major factor responsible for  Python's
success.  I believe that moving away from the Zen of Python will only
diminish the language.

And I think allowing a where statement inside in expression goes
against the Zen in so many ways it isn't even funny.

Beautiful is better than ugly.
Simple is better than complex.  (Note that simple means different
things to different people: for me, and I believe, for the Zen of
Python, it means simple for a human to understand.)
Flat is better than nested. (Seems to be the official Zen if effect
here.)
Readability counts. (Yes, if something's unreadable enough, I hope it's
not in the language, not merely that no one uses it.)
Special cases aren't special enough to break the rules.  (Heretofore,
Python has never had a nested block inside an expression; doing that
would make it a special case.)


I don't want Python to be LISP.  I don't think it's an admirable goal
for Python to strive to be like LISP for the sake of being like LISP,
or for the sake of being general or pure.  If Python borrows something
from LISP, it should be because that aspect of LISP supports the Zen of
Python.

If I wanted to use LISP, I'd be using LISP.  But I like my statements
and expressions distinct.  I like things that belong in statements to
stay in statements, and things that belong in expressions to stay in
expressions.

And a suite, be it a def statement, a where block, or whatever, belongs
in a statement, not an expression.



-- 
CARL BANKS

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


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Steve Holden
[EMAIL PROTECTED] wrote:
Steve Holden wrote:
No he didn't. I think you will find you are attributing Steven Bethard's 
comments to me.

[...]
The Numeric and Numarray Python modules have predefined ufunc's that
are essentially elemental functions with one or two arguments. It would
be nice if one could define new ufunc's using only Python code -- I
presume new ones can currently be added by writing C code.
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: path to python file given module

2005-01-09 Thread Kartic
That is because your module in not in a standard location that python
can find it in. It is not that inspect.getsourcefile() is not working.

Actually if you try reloading your filegen module after the os.chdir(),
you will see that import fails. If you copy your filegen directory to
the site-packages directory of python, you will get the complete path
of the module no matter where you are inside your script.

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


Re: Old Paranoia Game in Python

2005-01-09 Thread [EMAIL PROTECTED]

Aahz wrote:
> Trust the computer, the computer is your friend.

However, the computer isn't a fuckin' mind reader.

If you're going to post source code on the usenet, don't
have lines longer than 72 characters. Otherwise you'll
find your code has wrapped lines. This not only causes
syntax errors in your choose and print statements but
also fucks up the formatting of of printed paragraphs.

Stupid human.

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


Re: path to python file given module

2005-01-09 Thread Gene
that method doesn't seem to work as well on UNIX:

wla apocalypse[94] ~/filegen > ls
filegen.py  OLDwla_csv2objects.py   wlaclasses.py
filegen.pyc templates/  wlaclasses.pyc
gen_all_from_csv.py test.py*
wla apocalypse[95] ~/filegen > python
...
>>> import filegen, inspect
>>> inspect.getsourcefile(filegen)
'filegen.py'
>>> inspect.getsourcefile(filegen.Lecture)
'wlaclasses.py'
>>> import os
>>> os.chdir('..')
>>> inspect.getsourcefile(filegen)
>>> print inspect.getsourcefile(filegen)
None
>>> print inspect.getsourcefile(filegen.Lecture)
None

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


Re: Getting rid of "self."

2005-01-09 Thread BJörn Lindqvist
Thank you for your replies. It is very nice to see that a thread you
started is generating so much discussion, but please, I have read the
previous debates so I know all about what people think about self.
Spare the "you shouldn't do that" and "self is here to stay" replies
to the threads in which people are actually suggesting changing the
syntax. :)

I know the solution I presented is not working ideally, because you
have to use self to assign to instance attributes like "self.hi =
'baby'".

> Sean Ross:
> http://starship.python.net/crew/mwh/hacks/selfless.py

That's excellent! There is one small problem with the code though:

.class Hi(Selfless):
.__attrs__ = ["x"]
.def __init__(x):
.self.x = x

In this case, I think the Python interpreter should realise that the
parameter x shadows the attribute x. But the selfless code has
problems with that. I want it to work exactly like how the situation
is handled in Java and C++.

> Alex Martelli:
>> Björn Lindqvist:
>> 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

I have to get myself that book. 

> Alex Martelli:
> 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.

Which I believe means that the instance variables have to be declared
in the class? I am content with declaring them like the selfless
approach does:

__attrs__ = ["hi", "foo"]

It's not optimal because it would lead to some "name duplication" when
a class is __init__:ed.

.__attrs__ = ["hi", "foo"]
.def __init__(_hi, _foo):
.hi = _hi
.foo = _foo

I guess you can solve that adequately by using one of the recipes from
the Cookbook that automagically initialises an objects variable
depending on which variables was passed in the parameter list. Another
alternative would be not to declare the variables in an __attr__ list,
and instead let them be "declared" by having them initialised in the
__init__. I.e:

.def __init__(hi, foo):
.self.hi = hi
.self.foo = foo

When the metaclass then does it magic, it would go through the code of
the __init__ method, see the assignments to "self.hi" and "self.foo",
decide that "hi" and "foo" are attributes of the object and replace
"hi" and "foo" in all other methods with "self.hi" and "self.foo". The
downside is that it probably could never be foolproof against code
like this:

.def __init__(hi, foo):
.if hi:
.self.hi = hi
.else:
.self.foo = foo

But AFAIK, that example is a corner case and you shouldn't write such
code anyway. :)

> Alex Martelli:
> You do, however, need to nail down the specs.  What your 'magic' does
> is roughly the equivalent of a "from ... import *" (except it
> ...
> 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)

All names should be checked like this:
1. Is the name in the parameter list? If so, do not rebind it.
2. Is the name in the objects attribute list? If so, prepend "self."
3. Do stuff like normal.

Example:

.class Foo(Selfless):
.def __init__(x):
.print x
.self.x = x*2
.def meth():
.x = x + 10
.print x
.def meth2(x):
.print x
.print self.x
.self.x = x
.
.o = Foo(50)
.print o.x
.o.meth()
.o.meth2(12)
.print o.x

Outputs:
50
100
110
12
110
12

> Alex Martelli:
> 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,

This is promising, I'm content with whatever slowdowns necessary as
long as I can prove those who say "you can't do it" wrong. :) It seems
to me that it should be doable by having the metaclass that modifies
the class go through the class and bytecode-rewrite all its methods.
So there has to be a big slowdown when the class is created, but after
that, it should execute at pure Python speed? That doesn't seem to
hard, and pretty robust too since bytecode doesn't change so often.
And THEN I'll rewrite python-mode so that it syntax highlights member
attributes! It will be cool.

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


xml.sax._exceptions.SAXReaderNotAvailable

2005-01-09 Thread iwcook58
I am having a problem running py2exe on my computer.

When running the exe that has been generated by py2exe the following
error comes up.

C:\MyPython\dist>kirbyutils.exe kirby350.xml
Traceback (most recent call last):
File "kirbyutils.py", line 292, in ?
File "kirbyutils.py", line 261, in main
File "xml\sax\sax2exts.pyc", line 37, in make_parser
File "xml\sax\saxexts.pyc", line 77, in make_parser
xml.sax._exceptions.SAXReaderNotAvailable: No parsers found

I'm baffled.
I have searched google. There are lots of threads about
"xml.sax._exceptions.SAXReaderNotAvailable: No parsers found" but I do
not understand what is wrong.

There is thread
http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/4cb60885adde0cf3/f47d9aeaa584b8c6?q=xml.sax._exceptions.SAXReaderNotAvailable&_done=%2Fgroup%2Fcomp.lang.python%2Fsearch%3Fq%3Dxml.sax._exceptions.SAXReaderNotAvailable%26start%3D0%26scoring%3Dd%26&_doneTitle=Back+to+Search&&d#f47d9aeaa584b8c6

that made a suggestion or two basically to check xml has been
installed.

Here are my results..

C:\MyPython>\Python23\python.exe
Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml
>>> print xml

>>> import xml.dom
>>> print xml.dom

>>> import xml.dom.minidom
>>> print xml.dom.minidom

>>

I have installed pyxml and everything I can think of..

Setup.cmd is...
setup.py py2exe -i xml.sax.drivers2.drv_pyexpat -i
win32com.gen_py.*

Setup.py is...
# setup.py
from distutils.core import setup
import py2exe
setup(console=["kirbyutils.py"],
options = {"py2exe": {"packages": ["encodings"],
"dll_excludes":["mfc71.dll"]}} )


The imports in kirbyutils.py are
import os
import zipfileext
import zipfile
import sys
import xml.sax as sax
import xml.sax.handler
import fnmatch
import shutil
import binascii
import time
import filecmp




What am I missing??

Thanks in advance.


Ian Cook
(Freeware author of Kirby Alarm And Task Scheduler www.kirbyfooty.com)

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


Re: a new Perl/Python a day

2005-01-09 Thread Matt Garrish

"Xah Lee" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> i'm starting a yahoo group for learning python. Each day, a tip of
> python will be shown, with the perl equivalent. For those of you
> perlers who always wanted to learn python, this is suitable. (i started
> it because i always wanted to switch to python but too lazy and always
> falling back to a lang i am an expert at, but frustrated constantly by
> its inanities and incompetences.)
>

What language are you an expert at? It certainly isn't Perl.

Matt 


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


Re: Speed revisited

2005-01-09 Thread John Machin

Andrea Griffini wrote:
> On 9 Jan 2005 12:39:32 -0800, "John Machin" <[EMAIL PROTECTED]>
> wrote:
>
> >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.
>
> I've to admit that I also found strange that deleting the
> first element from a list is not O(1) in python. My wild
> guess was that the extra addition and normalization required
> to have insertion in amortized O(1) and deletion in O(1) at
> both ends of a random access sequence was going to have
> basically a negligible cost for normal access (given the
> overhead that is already present in python).
>
> But I'm sure this idea is too obvious for not having been
> proposed, and so there must reasons for refusing it
> (may be the cost to pay for random access once measured was
> found being far from negligible, or that the extra memory
> overhead per list - one int for remembering where the live
> data starts - was also going to be a problem).
>

My wild guess: Not a common use case. Double-ended queue is a special
purpose structure.

Note that the OP could have implemented the 3-tape update simulation
efficiently by reading backwards i.e. del alist[-1]


Suggested projects for you, in increasing order of difficulty:

1. Grab the source code (listobject.c) and report back on how you would
implement your proposal.
2. Convince folk that your implementation is faster and more robust and
has beter internal documentation than anything the timbot could ever
write.
3. Write a PEP that didn't cause a flamewar.


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


Re: Please Contribute Python Documentation!

2005-01-09 Thread Aahz
In article <[EMAIL PROTECTED]>,
Tony Meyer <[EMAIL PROTECTED]> wrote:
>
>I don't think I've seen such a statement before - the stuff I've seen
>all indicates that one should be submitting proper LaTeX docs/patches.
>If plain-text contributions are welcome, could this be added to the doc
>about contributing to the docs?  (I suppose I could submit a patch, but
>that seems overkill ).

It *is* in the docs now -- see the top of
http://www.python.org/doc/2.4/doc/doc.html

(This has been the official policy for some time, but you're right that
it wasn't earlier documented.  So I filed a bug report. ;-)  If you
think this still isn't enough, file another.)
-- 
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: vi and python

2005-01-09 Thread David Wilson
km wrote:
Is there a way to display inbuilt function syntax as the user starts typing a function name with 'Vi' editor in console mode? 
 

Hi there,
Unfortunately due to the highly dynamic nature of Python, this is 
difficult to do reliably. It is one benefit that static typing, to a 
certain extent, would bring to the language. Sadly we don't have that, 
yet. :)

David.
--
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:
>Aahz wrote:
>> In article <[EMAIL PROTECTED]>,
>> Lucas Raab  <[EMAIL PROTECTED]> wrote:
>>>Sean P. Kane wrote:

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!
>
>Well, I really meant "Secret Illuminati Eye-In-The-Pyramid(tm) Decoder 
>ring", but if you wanted to go in another direction...

Trust the computer, the computer is your friend.
-- 
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 beliavsky
Steve Holden wrote:
>>   def square(x):
>>   return x*x
>>   map(square, range(1000))

>> versus

>>   [x*x for x in range(1000)]

>> Hint: function calls are expensive.

>$ python -m timeit -s "def square(x): return x*x" "map(square,
range(1000))"
>1000 loops, best of 3: 693 usec per loop

>$ python -m timeit -s "[x*x for x in range(1000)]"
>1000 loops, best of 3: 0.0505 usec per loop

Functions will often be complicated enought that inlining them is not
feasible. In Fortran 95 one can define an elemental function that takes
an argument of any shape (scalar, vector, matrix etc.) but of a
specified type, returning a result of the same shape, so that one could
write

elemental function square(i) result(isq)
integer, intent(in) :: i
integer   :: isq
isq = i*i
end function square

and then

print*,square((/i,i=0,999/))

The Numeric and Numarray Python modules have predefined ufunc's that
are essentially elemental functions with one or two arguments. It would
be nice if one could define new ufunc's using only Python code -- I
presume new ones can currently be added by writing C code.

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


Re: path to python file given module

2005-01-09 Thread Kartic
Try this:;

>>> import filegen
>>> import inspect
>>> print inspect.getsourcefile(filegen.SomeClass)
'C:\\Python23\\Lib\\site-packages\\filegen\filegen.py'

Cheers,
--Kartic

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


path to python file given module

2005-01-09 Thread Gene
Is there a way to get a relative or absolute path to a python file once
it's been imported as a module?

For example, I type:
>>> import filegen

and I want a string that represents the path to filegen.py (either
relative to current working directory or the absolute path)

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


RE: Please Contribute Python Documentation!

2005-01-09 Thread Tony Meyer
> I'm changing the subject so that hopefully people who have 
> long ago tuned out the "Python evolution: Unease" subject 
> will read this note.

Worked for me :)  Two other pages that are probably of use to people
interested in this are:




These document the current (well, current when the wiki page was last
updated) state of various document patches, and list things that people have
noticed need work.  There's also a place for volunteers to put their name if
they are willing to provide module documentation, so that work isn't
duplicated.

(I don't know how up-to-date the latter one is.  I think the former is
reasonably so).

> You do not (repeat, *do not*) 
> need to install any tools to contribute content to the 
> documentation.  Just whip out your favorite text editor and 
> type plain old text.  There are plenty of us around who know 
> enough LaTeX to markup anything you contribute.  Don't let 
> lack of a specific set of tools be a barrier to contribution!

I don't think I've seen such a statement before - the stuff I've seen all
indicates that one should be submitting proper LaTeX docs/patches.  If
plain-text contributions are welcome, could this be added to the doc about
contributing to the docs?  (I suppose I could submit a patch, but that seems
overkill ).

> In either case, select "Documentation" as the category. There is 
> no need to assign it to anyone.  It will get seen shortly.  
> The correctness of a documentation fix is generally easier to 
> verify than that for a code fix, so they tend to get applied 
> pretty quickly.

Is it a mistake to attach a patch to a bug report?  Should it be a new patch
tracker instead?  I ask because I (ages ago) submitted documentation for
zipimport (it's linked from the ModulesThatNeedDocs page above) and although
it's been included on that wiki page and in discussion on python-dev about
missing documentation, it's never been looked at, AFAIK.  (If there are
problems, I'm happy to amend the patch, as the comment says).  This is
somewhat at odds with the "shortly" and "pretty quickly" <0.5 wink>.

=Tony.Meyer

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


Re: else condition in list comprehension

2005-01-09 Thread Reinhold Birkenfeld
Matteo Dell'Amico wrote:
> 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 could use
> 
> [(i-2, i+2)[bool(i%2 == 0)] for i in range(10)]
> 
> or, in a less general but shorter way
> 
> [(i+2, i-2)[i%2] for i in range(10)]
> 
> or even
> 
> [i%2 and i-2 or i+2 for i in range(10)]

One should note that the (cond and X or Y) construct only works if X can
never produce a false value (such as 0, "", []). In this example, it is
okay, but replace 2 with 1 and you will run into trouble for i = 1.

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


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread John Machin

Steven Bethard wrote:
> Note that list comprehensions are also C-implemented, AFAIK.

Rather strange meaning attached to "C-implemented". The implementation
generates the code that would have been generated had you written out
the loop yourself, with a speed boost (compared with the fastest DIY
approach) from using a special-purpose opcode LIST_APPEND. See below.

>>> def afunc(n):
...return [x*x for x in xrange(n)]
...
>>> afunc(3)
[0, 1, 4]
>>> import dis
>>> dis.dis(afunc)
2   0 BUILD_LIST   0
3 DUP_TOP
4 STORE_FAST   1 (_[1])
7 LOAD_GLOBAL  1 (xrange)
10 LOAD_FAST0 (n)
13 CALL_FUNCTION1
16 GET_ITER
>>   17 FOR_ITER17 (to 37)
20 STORE_FAST   2 (x)
23 LOAD_FAST1 (_[1])
26 LOAD_FAST2 (x)
29 LOAD_FAST2 (x)
32 BINARY_MULTIPLY
33 LIST_APPEND
34 JUMP_ABSOLUTE   17
>>   37 DELETE_FAST  1 (_[1])
40 RETURN_VALUE
>>> def bfunc(n):
...blist=[]; blapp=blist.append
...for x in xrange(n):
...   blapp(x*x)
...return blist
...
>>> bfunc(3)
[0, 1, 4]
>>> dis.dis(bfunc)
2   0 BUILD_LIST   0
3 STORE_FAST   3 (blist)
6 LOAD_FAST3 (blist)
9 LOAD_ATTR1 (append)
12 STORE_FAST   2 (blapp)

3  15 SETUP_LOOP  34 (to 52)
18 LOAD_GLOBAL  3 (xrange)
21 LOAD_FAST0 (n)
24 CALL_FUNCTION1
27 GET_ITER
>>   28 FOR_ITER20 (to 51)
31 STORE_FAST   1 (x)

4  34 LOAD_FAST2 (blapp)
37 LOAD_FAST1 (x)
40 LOAD_FAST1 (x)
43 BINARY_MULTIPLY
44 CALL_FUNCTION1
47 POP_TOP
48 JUMP_ABSOLUTE   28
>>   51 POP_BLOCK

5 >>   52 LOAD_FAST3 (blist)
55 RETURN_VALUE
>>>

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


Re: read numbers from file and covert to integer

2005-01-09 Thread beliavsky
If you have a file "ints.txt" with contents

10 20
30
40 50 60

You could read integers into a list with

ivec = []
for text in open("ints.txt","r"):
words = text.split()
for x in words:
ivec.append(int(x))
print ivec

If you know you want to read two integers into variables a,b from a
line you could write

a,b = int(words[0]),int(words[1])

Excuse me, but if your question is really so elementary that this post
answered it, you should probably read a book or tutorial.

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


Re: time module precision

2005-01-09 Thread Bengt Richter
On 9 Jan 2005 03:09:27 -0800, [EMAIL PROTECTED] wrote:
[...]
>
>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...
>
Microseconds is tough if you are going to give up control to a 
scheduling/dispatching
mechanism that works in milliseconds (e.g. 10ms normal slice on NT4), and where
badly written interrupt handling may cause significant latency hiccups. There's 
a reason
CD burners come with big buffers.

One question is if you are waiting for an event that causes and interrupt, or 
if you are guaranteeing
a delay to give something a chance to happen (e.g. like some pysical process 
like a sound echo)
so you can read a sensor interface at an appropriate time after starting some 
process,
or whether you're waiting for an event that originates in another thread 
running under ordinary
scheduling constraints.

If you want close time control under windows, you may have to write 
driver-level software
and/or raise priorities to real-time levels and make sure those things don't 
run very long before
blocking. I suspect that multimedia support stuff in windows might be useful 
for quasi-real-time
stuff, but I haven't used it. (I just seem to remember reading something about 
that in the MSDN docs,
but I am not sure. And too lazy to go back and look ;-)

Regards,
Bengt Richter
-- 
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 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
> ##
>

>
Khoa -

Thanks for supplying a little more information to go on.  The problem you
are struggling with has to do with pyparsing's handling or non-handling of
whitespace, which I'll admit takes some getting used to.

In general, pyparsing works its way through the input string, matching input
characters against the defined pattern. This gets a little tricky when
dealing with whitespace (which includes '\n' characters).  In particular,
restOfLine will read up to the next '\n', but will not go past it - AND
restOfLine will match an empty string.  So if you have a grammar that
includes repetition, such as OneOrMore(restOfLine), this will read up to the
next '\n', and then just keep matching forever.  This is just about the case
you have in your code, ZeroOrMore(BodyLine), in which BodyLine is
BodyLine = Group(nonHTTP + restOfLine)
You need to include something to consume the terminating '\n', which is the
purpose of the LineEnd() class.  Change BodyLine to
BodyLine = Group(nonHTTP + restOfLine + LineEnd())
and this will break the infinite looping that occurs at the end of the first
body line.  (If you like, use LineEnd.suppress(), to keep the '\n' tokens
from getting included with your other parsed data.)

Now there is one more problem - another infinite loop at the end of the
string.  By similar reasoning, it is resolved by changing
nonHTTP = ~Literal("HTTP/1.1")
to
nonHTTP = ~Literal("HTTP/1.1") + ~StringEnd()

After making those two changes, your program runs to completion on my
system.

Usually, when someone has some problems with this kind of "line-sensitive"
parsing, I recommend that they consider using pyparsing in a different
manner, or use some other technique.  For instance, you might use
pyparsing's scanString generator to match on the HTTP lines, as in

for toks,start,end in StatusLine.scanString(data):
print toks,toks[0].StatusCode, toks[0].ReasonPhrase
print start,end

which gives
[['HTTP/1.1', '200', ' OK']] 200  OK
0 15
[['HTTP/1.1', '400', ' Bad request']] 400  Bad request
66 90
[['HTTP/1.1', '500', ' Bad request']] 500  Bad request
142 166

If you need the intervening body text, you can use the start and end values
to extract it in slices from the input data string.

Or, since your data is reasonably well-formed, you could just use readlines,
or data.split('\n'), and find the HTTP lines using startswith().  While this
is a brute force approach, it will run certainly many times faster than
pyparsing.

In any event, best of luck using pyparsing, and write back if you have other
questions.

-- Paul


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


Re: use a file as a database, access rights

2005-01-09 Thread Steve Holden
Kartic wrote:
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?
Gadfly has been a very straightforwad installation for me. Of course the 
complexity of the access control will depend on the complexity of your 
application's requirements.

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: else condition in list comprehension

2005-01-09 Thread Dan Bishop
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 [sic] to be "i-2" if i%2 is not equal to 0?

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

In general, the expression "T if C is true, or F if C is false" can be
written as (F, T)[bool(C)].  (If you know that C will always be either
0 or 1, as is the case here, the "bool" is redundant.)

Unless, of course, either F or T has side effects.  For a side-effect
free expression, you can use (C and [T] or [F])[0] or one of the many
other ternary operator substitutes.  (Search for PEP 308.)

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


Re: Python serial data aquisition

2005-01-09 Thread Michael Fuhr
[EMAIL PROTECTED] (Flavio codeco coelho) writes:

> my hardware represents analog voltages as 12bit numbers. So, according
> to the manufacturer, this number will be stored in two bytes like
> this;
>  |-bits(1-8)---|
> Byte1: x  x   x   n1 n2 n3   n4   n5
> Byte2: x  n6 n7 n8 n9 n10 n11 n12
>
> where x is some other information, and nx are the digits of my number.

Is byte1 the high-order byte or the low-order byte?  Is n1 the
high-order bit or the low-order bit?  In my example below I'll
assume that byte1 and n1 are in the high-order positions.

> My problem is to how to recover my reading from these bytes, since
> pyserial gives me a character (string) from each byte...

You could convert the characters to their integer ASCII values with
ord() and perform bitwise operations on them.  For example, suppose
you have the following characters:

byte1 = '\xd2'  # 1101 0010
byte2 = '\xb5'  # 1011 0101

If byte1 is the high-order byte and n1 is the high-order bit, then
you need to mask off the upper three bits of byte1 (giving 0001 0010)
and the upper bit of byte2 (giving 0011 0101), then shift byte1 left 7
positions (not 8) and OR it with byte2 (giving 1001 0011 0101).

value = ((ord(byte1) & 0x1f) << 7) | (ord(byte2) & 0x7f)

If the actual byte and/or bit order is different then you'll have
to modify the expression, but this should at least give you ideas.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/
-- 
http://mail.python.org/mailman/listinfo/python-list


compiler version mismatch when building ext_modules with MSVC

2005-01-09 Thread Bo Peng
Dear list,
I was using autoconf/automake etc to build my python extension. Since 
distutil seems to be easier, I have switched to this method. However, 
when I build the module under windows, I am told that compiler version 
mismatch... I am using msvc 7 and python was build by msvc 6.0.

I am not sure why compiler version matters here since
1. if proceed by removing corresponding lines in distutil, the generated 
module works fine (as far as I can tell).

2. I am told that I can use minGW gcc ... Isn't mingw differ more with 
msvc6 than msvc7?

3. I was using msvc7 (automake etc, not distutil) and everything was 
fine. I was not even warned about potential problems.

Since there are many different Python out there (Official, ActivePython, 
Enthough), do I have to figure out which compiler they use to build my 
module for them? Currently, my MSVC7 built module works fine with all of 
them.

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


Python serial data aquisition

2005-01-09 Thread Flavio codeco coelho
Hi,

I am using pyserial to acquire data from an A/D converter plugged to
my serial port.

my hardware represents analog voltages as 12bit numbers. So, according
to the manufacturer, this number will be stored in two bytes like
this;
 |-bits(1-8)---|
Byte1: x  x   x   n1 n2 n3   n4   n5
Byte2: x  n6 n7 n8 n9 n10 n11 n12

where x is some other information, and nx are the digits of my number.

My problem is to how to recover my reading from these bytes, since
pyserial gives me a character (string) from each byte... I dont know
how to throw away the   unneeded bits and concatenate the remaining
bits to form a number...


Flávio Codeço Coelho
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speed revisited

2005-01-09 Thread Andrea Griffini
On 9 Jan 2005 12:39:32 -0800, "John Machin" <[EMAIL PROTECTED]>
wrote:

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

I've to admit that I also found strange that deleting the
first element from a list is not O(1) in python. My wild
guess was that the extra addition and normalization required
to have insertion in amortized O(1) and deletion in O(1) at
both ends of a random access sequence was going to have
basically a negligible cost for normal access (given the
overhead that is already present in python).

But I'm sure this idea is too obvious for not having been
proposed, and so there must reasons for refusing it
(may be the cost to pay for random access once measured was
found being far from negligible, or that the extra memory
overhead per list - one int for remembering where the live
data starts - was also going to be a problem).

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


Re: Guild of Python consultants?

2005-01-09 Thread Miklós P
"Peter Hansen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

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

> Which type do you mean?

Well, I consider myself  a consultant of the second kind. Using Python for
maths/stats (often meaning decision support systems) or science related
custom software is what I prefer to do .. But I also tend to enjoy
"firefighting" web projects because they pay well and they are never
boring.. rather on the contrary.. :-)

...and I second what you said in parenthesis.
So my interest follows.

Though one could surely have two divisions of a huge guild. :-))

Best,
  Miklós


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


Re: Python serial data aquisition

2005-01-09 Thread Steve Holden
Flavio codeco coelho wrote:
Hi,
I am using pyserial to acquire data from an A/D converter plugged to
my serial port.
my hardware represents analog voltages as 12bit numbers. So, according
to the manufacturer, this number will be stored in two bytes like
this;
 |-bits(1-8)---|
Byte1: x  x   x   n1 n2 n3   n4   n5
Byte2: x  n6 n7 n8 n9 n10 n11 n12
where x is some other information, and nx are the digits of my number.
My problem is to how to recover my reading from these bytes, since
pyserial gives me a character (string) from each byte... I dont know
how to throw away the   unneeded bits and concatenate the remaining
bits to form a number...
Flávio Codeço Coelho
Try something like (here I'm assuming that n12 is the least-significant 
bit) (untested):

((ord(byte1) & 31) << 7 ) + (ord(byte2) & 127)
This takes the rightmost five bits from the first byte's integer value, 
shifts them up seven bits, and then adds the rightmost seven bits of the 
second byte's integer value.

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 John Roth
"Andrey Tatarinov" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
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
This is fairly old. Note that the fastest version
uses the array module, and is quite comprehensible -
if you know the array module and how it works.
It doesn't use the map function.
John Roth
? 
--
http://mail.python.org/mailman/listinfo/python-list


RE: interpreter Py_Initialize/Py_Finalize mem leak?

2005-01-09 Thread Delaney, Timothy C (Timothy)
Roman Suzi wrote:

> In pure curiosity I tried to compile loop.c from Demo/embed
> and started it with 'print 2+2'. It seems, that both 2.3 and 2.4
> pythons have memory leaks in Py_Initialize/Py_Finalize calls.
> (That is, interpreter doesn't clean up well after itself).

What's your evidence for this (i.e. what are the symptoms)?

If you have a repeatable test case, please raise a bug report on
SourceForge.

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


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Steven Bethard
Robert Kern wrote:
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.
Some timings to verify this:
$ python -m timeit -s "def square(x): return x*x" "map(square, range(1000))"
1000 loops, best of 3: 693 usec per loop
$ python -m timeit -s "[x*x for x in range(1000)]"
1000 loops, best of 3: 0.0505 usec per loop
Note that list comprehensions are also C-implemented, AFAIK.
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Old Paranoia Game in Python

2005-01-09 Thread Lucas Raab
Aahz wrote:
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!
Well, I really meant "Secret Illuminati Eye-In-The-Pyramid(tm) Decoder 
ring", but if you wanted to go in another direction...
--
http://mail.python.org/mailman/listinfo/python-list


Re: else condition in list comprehension

2005-01-09 Thread Luis M. Gonzalez
Thank you guys!

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


Re: else condition in list comprehension

2005-01-09 Thread Matteo Dell'Amico
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 could use
[(i-2, i+2)[bool(i%2 == 0)] for i in range(10)]
or, in a less general but shorter way
[(i+2, i-2)[i%2] for i in range(10)]
or even
[i%2 and i-2 or i+2 for i in range(10)]
The "if" clause in comprehensions is used as a filter condition.
--
Ciao,
Matteo
--
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


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: '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: 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: 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, 

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


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


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


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

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


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


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


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


  1   2   >