Re: editing scripts on a mac

2007-04-29 Thread Arnaud Delobelle
On Apr 27, 5:37 pm, Tommy Grav <[EMAIL PROTECTED]> wrote:
[...]
> I think emacs is bundled with OS X and can be started in a terminal
> window with emacs. If you want a non-terminal editor Aquaemacs
> (http://aquamacs.org/) is available and easily installed on mac.

Personally I prefer Carbon Emacs:
http://homepage.mac.com/zenitani/emacs-e.html

--
Arnaud

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


Re: Memory addressing

2007-04-29 Thread Hendrik van Rooyen
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote:


> On Fri, 27 Apr 2007 16:07:57 -0700, castironpi wrote:
> 
> > That's what we need: a CopyMemory() routine.
> 
> What we _really_ need are Poke() and Peek() routines.
> 

Yeah right! - we also need macros, then an assembler johnny 
like me can hack his own syntax using only macros, peek
and poke...

And still claim he's writing programmes in python.

- Hendrik

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


While we're talking about annoyances

2007-04-29 Thread Steven D'Aprano
Am I the only one who finds that I'm writing more documentation than code?

I recently needed to write a function to generate a rank table from a
list. That is, a list of ranks, where the rank of an item is the position
it would be in if the list were sorted:

alist = list('defabc')
ranks = [3, 4, 5, 0, 1, 2]

To do that, I needed to generate an index table first. In the book
"Numerical Recipes in Pascal" by William Press et al there is a procedure
to generate an index table (46 lines of code) and one for a rank table
(five lines). 

In Python, my index function is four lines of code and my rank function is
five lines. I then wrote three more functions for verifying that my index
and rank tables were calculated correctly (17 more lines) and four more
lines to call doctest, giving a total of 30 lines of code.

I also have 93 lines of documentation, including doctests, or three
lines of documentation per line of code.

For those interested, here is how to generate an index table and rank
table in Python:


def index(sequence):
decorated = zip(sequence, xrange(len(sequence)))
decorated.sort()
return [idx for (value, idx) in decorated]

def rank(sequence):
table = [None] * len(sequence)
for j, idx in enumerate(index(sequence)):
table[idx] = j
return table


You can write your own damn documentation. *wink*



-- 
Steven.

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


Re: While we're talking about annoyances

2007-04-29 Thread GHUM
Steven,

> def index(sequence):
> decorated = zip(sequence, xrange(len(sequence)))
> decorated.sort()
> return [idx for (value, idx) in decorated]

would'nt that be equivalent code?

def index(sequence):
return [c for _,c  in sorted((b,a) for a, b in
enumerate(sequence))]

tested, gave same results. But worsens your doc2code ratio :)

Harald Armin Massa
--

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


Re: Tracebacks for `exec`ed code?

2007-04-29 Thread Martin v. Löwis
Adam Atlas schrieb:
> Is it possible to make more traceback information available for
> exceptions code dynamically run via `exec`? Normally it just says
> things like "File '', line 3, in ?", which is not very
> helpful. I'm looking for a way for it to show the line of source code
> below it, like it would for an exception in a physical file. Is this
> possible?

Yes. You will need to print the traceback yourself; see
traceback.print_tb for an example.

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


Re: Asynchronous XML-RPC client library?

2007-04-29 Thread Martin v. Löwis
Jarek Zgoda schrieb:
> Is there anything like that? Googling yields many articles on async
> servers, but virtually nothing on clients. I have to talk to remote in
> an environment that does not allow threads...

My recommendation would be to use xmlrpclib, and combine it with
the async framework that you currently use.

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


Re: While we're talking about annoyances

2007-04-29 Thread Michael Hoffman
GHUM wrote:
> Steven,
> 
>> def index(sequence):
>> decorated = zip(sequence, xrange(len(sequence)))
>> decorated.sort()
>> return [idx for (value, idx) in decorated]
> 
> would'nt that be equivalent code?
> 
> def index(sequence):
> return [c for _,c  in sorted((b,a) for a, b in
> enumerate(sequence))]

Or even these:

def index(sequence):
 return sorted(range(len(sequence)), key=sequence.__getitem__)

def rank(sequence):
 return sorted(range(len(sequence)),
   key=index(sequence).__getitem__)

Hint: if you find yourself using a decorate-sort-undecorate pattern, 
sorted(key=func) or sequence.sort(key=func) might be a better idea.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Asynchronous XML-RPC client library?

2007-04-29 Thread Jarek Zgoda
Martin v. Löwis napisał(a):

>> Is there anything like that? Googling yields many articles on async
>> servers, but virtually nothing on clients. I have to talk to remote in
>> an environment that does not allow threads...
> 
> My recommendation would be to use xmlrpclib, and combine it with
> the async framework that you currently use.

Found a recipe, finally. Not that it was easy and the weird thing is it
was posted to PyGTK list and I even replied to this post...

Here's the link to the code by Andrew Kuchling, for the impatient:
http://www.mail-archive.com/[EMAIL PROTECTED]/msg12971.html

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any Good tools to create CSV Files?

2007-04-29 Thread Bart Willems
Carsten Haese wrote:
> You mean something like the csv module that is part of Python's standard
> library?
> 
 import csv
 help(csv)

You have to admit, the module name is not really intuitive... :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Could zipfile module process the zip data in memory?

2007-04-29 Thread 人言落日是天涯,望极天涯不见家
I made a C/S network program, the client receive the zip file from the
server, and read the data into a variable. how could I process the
zipfile directly without saving it into file.
In the document of the zipfile module, I note that it mentions the
file-like object? what does it mean?

class ZipFile( file[, mode[, compression[, allowZip64]]])
 Open a ZIP file, where file can be either a path to a file (a
string) or a file-like object.

Thanks!

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


Re: I have a chance to do somting diffrent way not Python ?!

2007-04-29 Thread Bart Willems
anders wrote:
> So basicly i like advice about interac with os, compiler etc.
> Nice webblinks to read more
> and do/don't things.
Hello Anders,

OS Support for Windows in Python is excellent. I suggest you download 
the latest version, and don't forget to download Mark Hammond's win32 
library as well. Although it is mainly about COM support and you 
probably don't need it, it is always good to have.

After that, work your way through the tutorial. It should give you 
enough information to create the scripts that you need. I used the 
Manning book to learn Python, but I hear a lot of good stories over here 
from 'Python for dummies' as well.

The modules (included in the installation package) that you will need in 
your scripts are probably os, sys, and maybe some of the date modules.

I can't think of any "don'ts" - except maybe for the warning that you 
should not try to write java or c++ code in Python. So, if there is 
anything that seems to me missing, consider a different approach in your 
code (a good example is the switch statement...)

Best regards,
Bart
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner Ping program

2007-04-29 Thread Bjoern Schliessmann
Linus Cohen wrote:

> Actually the class ping bit is a placeholder. 

But why is it one? "ping" is something you do -- and not a "thing"
of which you could have several copies.

> I'm actually developing a module with python implementations of
> most standard network/internet tools such as telnet, tracert,
> whois etc. It will be called inettools, and the ping function is
> what I'm working on first. It should be a simple enough job to
> code in the features the Unix and DOS ping programs have(never
> stop, change size, change timeout).

IIRC, MS ping has no "never stop", you can only say "repeat 9
times".

Regards,


Björn

-- 
BOFH excuse #148:

Insert coin for new game

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


Re: While we're talking about annoyances

2007-04-29 Thread BJörn Lindqvist
On 4/29/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> To do that, I needed to generate an index table first. In the book
> "Numerical Recipes in Pascal" by William Press et al there is a procedure
> to generate an index table (46 lines of code) and one for a rank table
> (five lines).

51 lines total.

> In Python, my index function is four lines of code and my rank function is
> five lines. I then wrote three more functions for verifying that my index
> and rank tables were calculated correctly (17 more lines) and four more
> lines to call doctest, giving a total of 30 lines of code.

So 9 lines for Python, excluding tests.

> I also have 93 lines of documentation, including doctests, or three
> lines of documentation per line of code.

Then, without documentation, Python is roughly 560% (51/9) as
efficient as Pascal. But with documentation (assuming you need the
same amount of documentation for the Python code as the Pascal code),
(51 + 93)/(9 + 93) = 1.41 so only 141% as efficient as Pascal.

I wonder what that means? Maybe Python the language is approaching the
upper bound for how efficient an imperative programming language can
be? On the other hand, there seem to be some progress that could be
made to reduce the amount of work in writing documentation.
Documentation in Esperanto instead of English maybe?

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


Re: if __name__ == 'main': & passing an arg to a class object

2007-04-29 Thread Bart Willems
gtb wrote:
> appear at the end of many examples I see. Is this to cause a .class
> file to be generated?
This might be obvious, but no one else mentioned it: the Python 
interpreter cannot execute code that it hasn't compiled yet, which is 
why the "if __name__ ..." code is always at the end of the module - to 
guarantee that the entire file is scanned first.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Could zipfile module process the zip data in memory?

2007-04-29 Thread John Machin
On Apr 29, 9:15 pm, 人言落日是天涯,望极天涯不见家 <[EMAIL PROTECTED]> wrote:
> I made a C/S network program, the client receive the zip file from the
> server, and read the data into a variable. how could I process the
> zipfile directly without saving it into file.
> In the document of the zipfile module, I note that it mentions the
> file-like object? what does it mean?
>
> class ZipFile( file[, mode[, compression[, allowZip64]]])
>  Open a ZIP file, where file can be either a path to a file (a
> string) or a file-like object.
>

A file-like object is an object that is not a file object, but behaves
like a file object. Instead of keeping the data on disk, it will use
Python objects (e.g. str or maybe array.array) or malloc its own
memory. Have a look at the StringIO module (pure Python) and the
similar but faster cStringIO module.

Regards,
John




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

Re: Could zipfile module process the zip data in memory?

2007-04-29 Thread Daniel Nogradi
> I made a C/S network program, the client receive the zip file from the
> server, and read the data into a variable. how could I process the
> zipfile directly without saving it into file.
> In the document of the zipfile module, I note that it mentions the
> file-like object? what does it mean?
>
> class ZipFile( file[, mode[, compression[, allowZip64]]])
>  Open a ZIP file, where file can be either a path to a file (a
> string) or a file-like object.

Yes it is possible to process the content of the zipfile without
saving every file:

[untested]

from zipfile import ZipFile
from StringIO import StringIO

zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
for name in zipp.namelist( ):
content = zipp.read( name )
s = StringIO( )
s.write( content )
# now the file 'name' is in 's' (in memory)
# you can process it further
# 
s.close( )
zipp.close( )


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


Re: Could zipfile module process the zip data in memory?

2007-04-29 Thread 人言落日是天涯,望极天涯不见家
On Apr 29, 7:37 pm, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote:
> > I made a C/S network program, the client receive the zip file from the
> > server, and read the data into a variable. how could I process the
> > zipfile directly without saving it into file.
> > In the document of the zipfile module, I note that it mentions the
> > file-like object? what does it mean?
>
> > class ZipFile( file[, mode[, compression[, allowZip64]]])
> >          Open a ZIP file, where file can be either a path to a file (a
> > string) or a file-like object.
>
> Yes it is possible to process the content of the zipfile without
> saving every file:
>
> [untested]
>
>         from zipfile import ZipFile
>         from StringIO import StringIO
>
>         zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
>         for name in zipp.namelist( ):
>                 content = zipp.read( name )
>                 s = StringIO( )
>                 s.write( content )
>                 # now the file 'name' is in 's' (in memory)
>                 # you can process it further
>                 # 
>                 s.close( )
>         zipp.close( )
>
> HTH,
> Daniel
Thanks!
Maybe my poor english makes you confusion:-). The client receive the
zip file data from the server, and keep these data as a variable, not
as a file in harddisk. such as "zipFileData", but the first argument
of the "ZipFile" is filename. I would like to let the ZipFile() open
the file from "zipFileData" directly but not file in harddisk

zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
  ^ I don't have this file, all its data
is in a variable.

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

Re: While we're talking about annoyances

2007-04-29 Thread Ben Finney
"BJörn Lindqvist" <[EMAIL PROTECTED]> writes:

> On the other hand, there seem to be some progress that could be made
> to reduce the amount of work in writing documentation.
> Documentation in Esperanto instead of English maybe?

Lojban http://www.lojban.org/> is both easier to learn world-wide
than Euro-biased Esperanto, and computer-parseable. Seems a better[0]_
choice for computer documentation to me.


..  _[0] ignoring the fact that it's spoken by even fewer people than
 Esperanto.

-- 
 \ "The greater the artist, the greater the doubt; perfect |
  `\   confidence is granted to the less talented as a consolation |
_o__)prize."  -- Robert Hughes |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: My newbie annoyances so far

2007-04-29 Thread Bjoern Schliessmann
Steven D'Aprano wrote:

> There are bad programmers in every language, but RPL conditional
> blocks aren't the cause of them. Once you learn how RPL works, if
> statements work consistently and obviously (although maybe not to
> programmers who don't get RP notation).

ACK. What made me anwswer wasn't RPL (after all I use an RPN
calculator ;) ), but the statement that it were "more logic" than
Python's "classic" infix logic.
 
> In RPL, there are no expressions. RPL programs are constructed
> from data and commands, not expressions. So you shouldn't think of
> 
>  if  [else ]
> 
> as an expression. Think of it as a block, equivalent to the
> Python:
> 
> if garbage_can_full:
> fetch
> out
> garbage
> else:
> don't
> 
> except that you can write it as a single line. Newlines in RPL are
> just another sort of whitespace, with no special significance.
> 
> If the else clause is missing, then nothing is executed and
> processing simply continues past the end of the block.

That made it clear, thanks.
 
Regards,


Björn 

-- 
BOFH excuse #439:

Hot Java has gone cold

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


Re: Could zipfile module process the zip data in memory?

2007-04-29 Thread Daniel Nogradi
> > > I made a C/S network program, the client receive the zip file from the
> > > server, and read the data into a variable. how could I process the
> > > zipfile directly without saving it into file.
> > > In the document of the zipfile module, I note that it mentions the
> > > file-like object? what does it mean?
> >
> > > class ZipFile( file[, mode[, compression[, allowZip64]]])
> > >  Open a ZIP file, where file can be either a path to a file (a
> > > string) or a file-like object.
> >
> > Yes it is possible to process the content of the zipfile without
> > saving every file:
> >
> > [untested]
> >
> > from zipfile import ZipFile
> > from StringIO import StringIO
> >
> > zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
> > for name in zipp.namelist( ):
> > content = zipp.read( name )
> > s = StringIO( )
> > s.write( content )
> > # now the file 'name' is in 's' (in memory)
> > # you can process it further
> > # 
> > s.close( )
> > zipp.close( )
> >
> > HTH,
> > Daniel
> Thanks!
> Maybe my poor english makes you confusion:-). The client receive the
> zip file data from the server, and keep these data as a variable, not
> as a file in harddisk. such as "zipFileData", but the first argument
> of the "ZipFile" is filename. I would like to let the ZipFile() open
> the file from "zipFileData" directly but not file in harddisk
>
> zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
>   ^ I don't have this file, all its data
> is in a variable.

Well, as you correctly pointed out in your original post ZipFile can
receive a filename or a file-like object. If the zip archive data is
in zipFileData then you might do:

from StringIO import StringIO
from zipfile import ZipFile

data = StringIO( )
data.write( zipFileData )
data.close( )

zipp = ZipFile( data )
.


and continue in the same way as before.

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


Re: if __name__ == 'main': & passing an arg to a class object

2007-04-29 Thread John Machin
On Apr 29, 9:32 pm, Bart Willems <[EMAIL PROTECTED]> wrote:
> gtb wrote:
> > appear at the end of many examples I see. Is this to cause a .class
> > file to be generated?
>
> This might be obvious, but no one else mentioned it: the Python
> interpreter cannot execute code that it hasn't compiled yet, which is
> why the "if __name__ ..." code is always at the end of the module - to
> guarantee that the entire file is scanned first.

I make no claims about the following code; it is merely presented for
examination :-)

8< --- namemain.py ---
# code used both in import mode and script mode
def greet(whom):
print "Hello, %s" % whom
if __name__ == "__main__":
# code used only in script mode
import sys, namemain
tgt = sys.argv[1]
greet(tgt)
namemain.farewell(tgt)
else:
# code used only in import mode
def farewell(whom):
print "Goodbye, %s" % whom
8<--


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


Re: Could zipfile module process the zip data in memory?

2007-04-29 Thread Diez B. Roggisch
人言落日是天涯,望极天涯不见家 schrieb:
> On Apr 29, 7:37 pm, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote:
>>> I made a C/S network program, the client receive the zip file from the
>>> server, and read the data into a variable. how could I process the
>>> zipfile directly without saving it into file.
>>> In the document of the zipfile module, I note that it mentions the
>>> file-like object? what does it mean?
>>> class ZipFile( file[, mode[, compression[, allowZip64]]])
>>>  Open a ZIP file, where file can be either a path to a file (a
>>> string) or a file-like object.
>> Yes it is possible to process the content of the zipfile without
>> saving every file:
>>
>> [untested]
>>
>> from zipfile import ZipFile
>> from StringIO import StringIO
>>
>> zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
>> for name in zipp.namelist( ):
>> content = zipp.read( name )
>> s = StringIO( )
>> s.write( content )
>> # now the file 'name' is in 's' (in memory)
>> # you can process it further
>> # 
>> s.close( )
>> zipp.close( )
>>
>> HTH,
>> Daniel
> Thanks!
> Maybe my poor english makes you confusion:-). The client receive the
> zip file data from the server, and keep these data as a variable, not
> as a file in harddisk. such as "zipFileData", but the first argument
> of the "ZipFile" is filename. I would like to let the ZipFile() open
> the file from "zipFileData" directly but not file in harddisk
> 
> zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
>   ^ I don't have this file, all its data
> is in a variable.

You can use cStringIO for that as well. Read the module docs for it.

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

Re: Could zipfile module process the zip data in memory?

2007-04-29 Thread 人言落日是天涯,望极天涯不见家
On Apr 29, 7:37 pm, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote:
> > I made a C/S network program, the client receive the zip file from the
> > server, and read the data into a variable. how could I process the
> > zipfile directly without saving it into file.
> > In the document of the zipfile module, I note that it mentions the
> > file-like object? what does it mean?
>
> > class ZipFile( file[, mode[, compression[, allowZip64]]])
> >          Open a ZIP file, where file can be either a path to a file (a
> > string) or a file-like object.
>
> Yes it is possible to process the content of the zipfile without
> saving every file:
>
> [untested]
>
>         from zipfile import ZipFile
>         from StringIO import StringIO
>
>         zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
>         for name in zipp.namelist( ):
>                 content = zipp.read( name )
>                 s = StringIO( )
>                 s.write( content )
>                 # now the file 'name' is in 's' (in memory)
>                 # you can process it further
>                 # 
>                 s.close( )
>         zipp.close( )
>
> HTH,
> Daniel

OK, I see, thank you!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Could zipfile module process the zip data in memory?

2007-04-29 Thread 人言落日是天涯,望极天涯不见家
On Apr 29, 8:14 pm, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote:
> > > > I made a C/S network program, the client receive the zip file from the
> > > > server, and read the data into a variable. how could I process the
> > > > zipfile directly without saving it into file.
> > > > In the document of the zipfile module, I note that it mentions the
> > > > file-like object? what does it mean?
>
> > > > class ZipFile( file[, mode[, compression[, allowZip64]]])
> > > >          Open a ZIP file, where file can be either a path to a file (a
> > > > string) or a file-like object.
>
> > > Yes it is possible to process the content of the zipfile without
> > > saving every file:
>
> > > [untested]
>
> > >         from zipfile import ZipFile
> > >         from StringIO import StringIO
>
> > >         zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
> > >         for name in zipp.namelist( ):
> > >                 content = zipp.read( name )
> > >                 s = StringIO( )
> > >                 s.write( content )
> > >                 # now the file 'name' is in 's' (in memory)
> > >                 # you can process it further
> > >                 # 
> > >                 s.close( )
> > >         zipp.close( )
>
> > > HTH,
> > > Daniel
> > Thanks!
> > Maybe my poor english makes you confusion:-). The client receive the
> > zip file data from the server, and keep these data as a variable, not
> > as a file in harddisk. such as "zipFileData", but the first argument
> > of the "ZipFile" is filename. I would like to let the ZipFile() open
> > the file from "zipFileData" directly but not file in harddisk
>
> > zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
> >                               ^ I don't have this file, all its data
> > is in a variable.
>
> Well, as you correctly pointed out in your original post ZipFile can
> receive a filename or a file-like object. If the zip archive data is
> in zipFileData then you might do:
>
> from StringIO import StringIO
> from zipfile import ZipFile
>
> data = StringIO( )
> data.write( zipFileData )
> data.close( )
>
> zipp = ZipFile( data )
> .
>
> and continue in the same way as before.
>
> Daniel- Hide quoted text -
>
> - Show quoted text -

Thanks all of your kindly help!

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

Re: Could zipfile module process the zip data in memory?

2007-04-29 Thread John Machin
On Apr 29, 9:51 pm, 人言落日是天涯,望极天涯不见家 <[EMAIL PROTECTED]> wrote:
> On Apr 29, 7:37 pm, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote:
>
> > > I made a C/S network program, the client receive the zip file from the
> > > server, and read the data into a variable. how could I process the
> > > zipfile directly without saving it into file.
> > > In the document of the zipfile module, I note that it mentions the
> > > file-like object? what does it mean?
>
> > > class ZipFile( file[, mode[, compression[, allowZip64]]])
> > >  Open a ZIP file, where file can be either a path to a file (a
> > > string) or a file-like object.
>
> > Yes it is possible to process the content of the zipfile without
> > saving every file:
>
> > [untested]
>
> > from zipfile import ZipFile
> > from StringIO import StringIO
>
> > zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
> > for name in zipp.namelist( ):
> > content = zipp.read( name )
> > s = StringIO( )
> > s.write( content )
> > # now the file 'name' is in 's' (in memory)
> > # you can process it further
> > # 
> > s.close( )
> > zipp.close( )
>
> > HTH,
> > Daniel
>
> Thanks!
> Maybe my poor english makes you confusion:-). The client receive the
> zip file data from the server, and keep these data as a variable, not
> as a file in harddisk. such as "zipFileData", but the first argument
> of the "ZipFile" is filename. I would like to let the ZipFile() open
> the file from "zipFileData" directly but not file in harddisk
>
> zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
>   ^ I don't have this file, all its data
> is in a variable.

Try something like this:

from zipfile import ZipFile
from StringIO import StringIO
filelikeobj = StringIO(zipFileData)
zipp = ZipFile(filelikeobj, 'r')
for name in zipp.namelist():
# etc etc etc

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

Re: Could zipfile module process the zip data in memory?

2007-04-29 Thread John Machin
On Apr 29, 10:14 pm, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote:
> > > > I made a C/S network program, the client receive the zip file from the
> > > > server, and read the data into a variable. how could I process the
> > > > zipfile directly without saving it into file.
> > > > In the document of the zipfile module, I note that it mentions the
> > > > file-like object? what does it mean?
>
> > > > class ZipFile( file[, mode[, compression[, allowZip64]]])
> > > >  Open a ZIP file, where file can be either a path to a file (a
> > > > string) or a file-like object.
>
> > > Yes it is possible to process the content of the zipfile without
> > > saving every file:
>
> > > [untested]
>
> > > from zipfile import ZipFile
> > > from StringIO import StringIO
>
> > > zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
> > > for name in zipp.namelist( ):
> > > content = zipp.read( name )
> > > s = StringIO( )
> > > s.write( content )
> > > # now the file 'name' is in 's' (in memory)
> > > # you can process it further
> > > # 
> > > s.close( )
> > > zipp.close( )
>
> > > HTH,
> > > Daniel
> > Thanks!
> > Maybe my poor english makes you confusion:-). The client receive the
> > zip file data from the server, and keep these data as a variable, not
> > as a file in harddisk. such as "zipFileData", but the first argument
> > of the "ZipFile" is filename. I would like to let the ZipFile() open
> > the file from "zipFileData" directly but not file in harddisk
>
> > zipp = ZipFile( this_is_the_zip_file_from_your_server, 'r' )
> >   ^ I don't have this file, all its data
> > is in a variable.
>
> Well, as you correctly pointed out in your original post ZipFile can
> receive a filename or a file-like object. If the zip archive data is
> in zipFileData then you might do:
>
> from StringIO import StringIO
> from zipfile import ZipFile
>
> data = StringIO( )
> data.write( zipFileData )
> data.close( )

Even if that worked, it would be a long-winded way to do it. Please
contemplate the docs:

"""getvalue( )

Retrieve the entire contents of the ``file'' at any time before the
StringIO object's close() method is called.[snip note re mixing str &
unicode]

close( )

Free the memory buffer. """

The short working way is: """class StringIO( [buffer])

When a StringIO object is created, it can be initialized to an
existing string by passing the string to the constructor."""


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


Re: While we're talking about annoyances

2007-04-29 Thread Jarek Zgoda
Ben Finney napisał(a):

>> On the other hand, there seem to be some progress that could be made
>> to reduce the amount of work in writing documentation.
>> Documentation in Esperanto instead of English maybe?
> 
> Lojban http://www.lojban.org/> is both easier to learn world-wide
> than Euro-biased Esperanto, and computer-parseable. Seems a better[0]_
> choice for computer documentation to me.

German seems to be less "wordy" than English, despite the fact that most
of nouns is much longer. ;)

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Asynchronous XML-RPC client library?

2007-04-29 Thread Stefano Canepa
On 29 Apr, 07:11, Jarek Zgoda <[EMAIL PROTECTED]> wrote:
> Is there anything like that? Googling yields many articles on async
> servers, but virtually nothing on clients. I have to talk to remote in
> an environment that does not allow threads...
>
> --
> Jarek Zgodahttp://jpa.berlios.de/

Why don't you try twisted (http://www.twistedmatrix.com)

Bye
Stefano



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


Re: Numbers and truth values

2007-04-29 Thread Beliavsky
On Apr 28, 4:05 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
> John Nagle <[EMAIL PROTECTED]> wrote:
>
> >  I'd have to consider that a bug.
>
> >  Some very early FORTRAN compilers allowed you to redefine
> > integer constants:
>
> >   CALL SET(25,99)
> >   WRITE (6,100) 25
> >  100 FORMAT(I6)
>
> >   SUBROUTINE SET(IVAR, INEWVAL)
> >   IVAR = INEWVAL
>
> > would print
>
> >  99
>
> >  It was generally agreed by 1970 or so that this was a bad idea,
> > and was taken out of the language.
>
> It was still perfectly legal in the Fortran 1977 standard for a compiler
> to cause this effect, because the Fortran source you quote has
> *undefined behavior* -- the compiler doesn't have to diagnose this error
> and can cause any effects as a consequence.
>
> The point of Fortran is to let the compiler generate the fastest code it
> can, NOT to "tenderly hold your hand" lest scary bugs disturb your
> blessed and dreamy innocence.

The point of Fortran has been to make scientific programmers more
productive, and catching errors and producing fast programs are BOTH
ways of doing that. Compilers are judged on BOTH criteria:
speed: http://www.polyhedron.com/pb05/linux/f90bench_p4.html
diagnostics: http://www.polyhedron.com/pb05/linux/diagnose.html

If there is a compiler with great compile- and run-time debugging
capability with the right options turned on, and if the compiler also
produces optimally fast code with another set of options (or if
another compiler does this), isn't that the best of both worlds?

> If this has changed in the Fortran 1990 standard or later, then I can
> only say I'm happy I stopped using Fortran heavily before such standards
> became widespread in commonly available compilers -- by the late '90s,
> when I was still using _some_Fortran, it was Fortran '77, as that was
> the version that was widely available and well optimized.

I don't think the official status of such has changed -- it's still
illegal to change a constant and the compiler is still not required to
catch the error -- but compilers may be more likely to reject
such code as before, helping programmers spot errors. IMO that's a
good thing.

When is no longer using a language, one has the luxury of thinking
about it in an ideological rather than practical manner.

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


Re: Asynchronous XML-RPC client library?

2007-04-29 Thread Jarek Zgoda
Stefano Canepa napisał(a):

>> Is there anything like that? Googling yields many articles on async
>> servers, but virtually nothing on clients. I have to talk to remote in
>> an environment that does not allow threads...
> 
> Why don't you try twisted (http://www.twistedmatrix.com)

Because this is a small plugin to a larger application written in C and
I don't want to make such dependency. Twisted is just too large to be a
dependency for a ~500 LOC (including GUI code) plugin.

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SEO - Search Engine Optimization - Seo Consulting

2007-04-29 Thread Dom Robinson
In article <[EMAIL PROTECTED]>, "Alvin Bruney [MVP]"  says...
> Please don't spam this group
> 
A top-poster replies to a spammer. Now that world has truly gone mad(!)
-- 

Dom Robinson  Gamertag: DVDfever  email: dom at dvdfever dot co dot uk
/* http://DVDfever.co.uk (editor)
/* 1132 DVDs, 347 games, 314 CDs, 110 cinema films, 42 concerts, videos & news
/* antibodies, steve hillage, burning crusade, sega psp, norah jones, kylie
 New music charts - http://dvdfever.co.uk/music.shtml
   Youtube - http://www.youtube.com/profile?user=DVDfeverDom
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: While we're talking about annoyances

2007-04-29 Thread Arnaud Delobelle
On Apr 29, 11:46 am, Michael Hoffman <[EMAIL PROTECTED]> wrote:
> GHUM wrote:
> > Steven,
>
> >> def index(sequence):
> >> decorated = zip(sequence, xrange(len(sequence)))
> >> decorated.sort()
> >> return [idx for (value, idx) in decorated]
>
> > would'nt that be equivalent code?
>
> > def index(sequence):
> > return [c for _,c  in sorted((b,a) for a, b in
> > enumerate(sequence))]
>
> Or even these:
>
> def index(sequence):
>  return sorted(range(len(sequence)), key=sequence.__getitem__)
>
> def rank(sequence):
>  return sorted(range(len(sequence)),
>key=index(sequence).__getitem__)

Better still:

def rank(sequence):
return index(index(sequence))

:)
But really these two versions of rank are slower than the original one
(as sorting a list is O(nlogn) whereas filling a table with
precomputed values is O(n) ).

Anyway I would like to contribute my own index function:

def index(seq):
 return sum(sorted(map(list,enumerate(seq)), key=list.pop), [])

It's short and has the advantage of being self-documenting, which will
save Steven a lot of annoying typing I hope ;)  Who said Python
couldn't rival with perl?

--
Arnaud

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


Re: SEO - Search Engine Optimization - Seo Consulting

2007-04-29 Thread Spin Dryer
On Sat, 28 Apr 2007 21:21:39 -0400, ["Alvin Bruney [MVP]" ] said :-

>Please don't spam this group

Top posting and without removing the spamvertised site, you are as bad
as the spammer. Call yourself an MVP, that's a joke Slick.

Indeed the spam was not even seen by probably many servers until you
decided to reply.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: editing scripts on a mac

2007-04-29 Thread Adam Atlas
On Apr 27, 12:08 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> Now, frankly, I don't think this answer is correct, since I know OS X is
> a UNIX derivative, but I am loathe to involve a programming noob with vi
> or something similar. So I wondered if one of the c.l.py mac users could
> give brief instructions for firing up a visual text editor of some sort
> and saving a file somewhere it can easily be accessed from a terminal
> window (which I presume starts up in his home directory).

I strongly recommend TextMate (http://www.macromates.com/). It's not
free, but it rocks.

There's also TextWrangler (http://www.barebones.com/products/
textwrangler/), a free (as in beer) lite version of BBEdit, the most
venerable Mac text editor. I used to use BBEdit; it's quite excellent,
though TextMate feels a bit more modern and OS X-like.

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


Re: While we're talking about annoyances

2007-04-29 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> I recently needed to write a function to generate a rank table from a
> list. That is, a list of ranks, where the rank of an item is the position
> it would be in if the list were sorted:
> 
> alist = list('defabc')
> ranks = [3, 4, 5, 0, 1, 2]

fst = operator.itemgetter(0)   # these should be builtins...
snd = operator.itemgetter(1)

ranks=map(fst, sorted(enumerate(alist), key=snd))
-- 
http://mail.python.org/mailman/listinfo/python-list


Python ODBC

2007-04-29 Thread Harlin Seritt
Is there a Python odbc module that will work on Linux? I have a jdbc
connection to a DB2 server. I am looking hopefully for an open source
solution and not a commercial one.

Thanks,

Harlin

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


Re: While we're talking about annoyances

2007-04-29 Thread Arnaud Delobelle
On Apr 29, 5:33 pm, Paul Rubin  wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> writes:
> > I recently needed to write a function to generate a rank table from a
> > list. That is, a list of ranks, where the rank of an item is the position
> > it would be in if the list were sorted:
>
> > alist = list('defabc')
> > ranks = [3, 4, 5, 0, 1, 2]
>
> fst = operator.itemgetter(0)   # these should be builtins...
> snd = operator.itemgetter(1)
>
> ranks=map(fst, sorted(enumerate(alist), key=snd))

This is what the OP calls the index table, not the ranks table (both
are the same for the example above, but that's an unfortunate
coincidence...)

--
Arnaud

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


Free Windows Vista Download

2007-04-29 Thread Leisure . 207
http://freewindowsvista.blogspot.com/ - Get Windows Vista for Free

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


howto check is object a func, lambda-func or something else?

2007-04-29 Thread dmitrey
hi all,
howto check is object Arg1
- a func, lambda-func
- something else?

I tried callable(Arg1), but  callable(lambda-func) returnes False

Thx, D.

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


Re: howto check is object a func, lambda-func or something else?

2007-04-29 Thread Gregor Horvath
dmitrey schrieb:

> howto check is object Arg1
> - a func, lambda-func
> - something else?
> 
> I tried callable(Arg1), but  callable(lambda-func) returnes False

I don't understand your problem:

>>> callable(lambda:0)
True


Please post your relevant code.

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


Re: howto check is object a func, lambda-func or something else?

2007-04-29 Thread 7stud
On Apr 29, 11:19 am, dmitrey <[EMAIL PROTECTED]> wrote:
>
>  callable(lambda-func) returnes False
>

I'm not seeing that. Try this:

f = lambda x: x
print callable(f)

---output:--
True

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


Re: Video: Professor of Physics Phd at Cal Tech says: 911 Inside Job

2007-04-29 Thread gDog
On Apr 28, 2:50 pm, Major Quaternion Dirt Quantum
<[EMAIL PROTECTED]> wrote:
> here's a question that came-up recently,
> in battling with the controlled-demo advocates
> at teh Promenade:
>
> how is it that the metal was still molten,
> after weeks?

 snip...snip...snip...

I say it's time to bring in the Mythbusters!!  *That* will put and end
to all of this.
--greg

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


Re: Video: Professor of Physics Phd at Cal Tech says: 911 Inside Job

2007-04-29 Thread Gordon
On Thu, 26 Apr 2007 00:33:19 GMT, "Bill Habr"
<[EMAIL PROTECTED]> wrote:

>
><[EMAIL PROTECTED]> wrote in message
>news:[EMAIL PROTECTED]
>> Cal Tech is the ELITE of ELITE in physics.
>>
>> If Feynman were alive, he would point his finger straight at the 911
>> criminal operators, the yank bastards themselves ...
>>
>> http://www.911blogger.com/node/8101
>>
>> No self-respecting scientist should keep his mouth shut. Its a
>> fundamental challenge to the method of science, a detective work most
>> demanding of INTELLECTUAL HONESTY.
>>
>
>Isn't this the guy who has more conspiracy theories than Carter has pills?
>
>Whitewater, Vince Foster, moon landing hoax one week - we found a UFO on the 
>moon the
>next, Oklahoma City bombing, a new conspiracy every day ad nauseum?
>
Maybe the thread title is wrong. Should it perhaps read, "Video
Professor took a physic then spewed out some really stinky
stuff."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List objects are un-hashable

2007-04-29 Thread Andy
Thanks Michael and Ant.

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


Re: relative import broken?

2007-04-29 Thread Alan Isaac
"Alex Martelli" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> If you're running test1.py as your main module, then it's not part of a
> package, so the relative import should indeed fail as you mention.

So if I understand you,
 in a package, any module that I wish
to make available for execution as a script
(in the usual way, with a main function)
cannot have any relative imports.
Is this right?  What is the reason for
this restriction?  (And where is it
documented?)

Thank you,
Alan Isaac


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


Re: Python ODBC

2007-04-29 Thread Jorge Mazzonelli

For ODBC connections you can try pyODBC. I didn't test it on Linux but it is
said it works on both Windows and POSIX systems.
pyODBC--> pyodbc.sourceforge.net
The license is MIT License.

You can also have a look here:
http://sparcs.kaist.ac.kr/~tinuviel/python/database.html since it has
various links on python interfaces to several databases including DB2. It
contains also links to other ODBC packages for python.

Jorge


On 29 Apr 2007 09:34:13 -0700, Harlin Seritt <[EMAIL PROTECTED]> wrote:


Is there a Python odbc module that will work on Linux? I have a jdbc
connection to a DB2 server. I am looking hopefully for an open source
solution and not a commercial one.

Thanks,

Harlin

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

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

Re: howto check is object a func, lambda-func or something else?

2007-04-29 Thread dmitrey
Thank you, I have fixed the bug

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


Counting

2007-04-29 Thread Andy
Hi, the file below will print all the keywords in a file and also the
line # of the keyword. What I couldn't figure out is to count those
keywords per line. For example - "Line #1 has 3 keywords"

Can I do like -

total[j] = total[j] + numwords(k)
"Line number %d has %d keywords" % (j, total[j])

Seems sort of "illegal" in Python?



-
import keyword, sys, string, fileinput
def numwords(s):
list = string.split(s)
return len(list)

# Get the file name either from the command-line or the user
if len(sys.argv) != 2:
   name = raw_input("Enter the file name: ")
else:
   name = sys.argv[1]

inp = open(name,"r")
linelist = inp.readlines()
total, words,lines = 0, 0, 0

for i in range(len(linelist)):
line = linelist[i]
tempwords = line.split()
for k in tempwords:
if keyword.iskeyword(k):
total = total + numwords(k)
j = i + 1
print" The word * %s * belongs in line number: %d" % (k,
j)

print "Total keywords in this file are: %d" %(total)

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


exclusive shelve open

2007-04-29 Thread castironpi
I'm trying to be safe and make sure only one python instance opens the
shelf.  Any ideas?

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


Re: While we're talking about annoyances

2007-04-29 Thread Raymond Hettinger
[Steven D'Aprano]
> I recently needed to write a function to generate a rank table from a
> list. That is, a list of ranks, where the rank of an item is the position
> it would be in if the list were sorted:
>
> alist = list('defabc')
> ranks = [3, 4, 5, 0, 1, 2]
. . .
> def rank(sequence):
> table = [None] * len(sequence)
> for j, idx in enumerate(index(sequence)):
> table[idx] = j
> return table

FWIW, you can do ranking faster and more succinctly with the sorted()
builtin:

def rank(seq):
return sorted(range(len(seq)), key=seq.__getitem__)


Raymond

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


Re: mysql "rows affected"

2007-04-29 Thread Carl K
Dennis Lee Bieber wrote:
> On Thu, 26 Apr 2007 18:18:57 -0700, John Nagle <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
> 
>> Carl K wrote:
>>> using MySQLdb, I do cursor.execute("update...")
>>>
>>> How can I tell how many rows were affected ?
>>>
>>> Carl K
>>  cursor = db.cursor() # get cursor   
>>  cursor.execute(sqlstatement, argtuple) # do command
> 
>   According to the documentation, it may be possible to get the result
> with
> 
>   rws = cursor.execute(...)
> 
> 
> -=-=-=-=-=-=-
 help(cr.execute)
> Help on method execute in module MySQLdb.cursors:
> 
> execute(self, query, args=None) method of MySQLdb.cursors.Cursor
> instance
> Execute a query.
> 
> query -- string, query to execute on server
> args -- optional sequence or mapping, parameters to use with query.
> 
> Note: If args is a sequence, then %s must be used as the
> parameter placeholder in the query. If a mapping is used,
> %(key)s must be used as the placeholder.
> 
> Returns long integer rows affected, if any
> 
> -=-=-=-=-=-=-

hey look at that.  Thanks.

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


I can't inherit from "compiled" classes ?

2007-04-29 Thread Maxim Veksler
Hello list,

I'm trying to subclass socket and select, for both I get:
""" TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given) """, I don't
understand this error. Why would python try to pass 3 arguments (what
are they) ?

Googling for this error gave random results talking about try to
inherit a "Package" but socket is definitely a class,
(/usr/lib/python2.4/socket.py). Not sure about select thought.

I've did the following to receive the error:
"""
In [1]: import socket

In [2]: class PollingSocket(socket):
   ...: pass
   ...:
---
exceptions.TypeError Traceback (most
recent call last)

/home/hq4ever/

TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
"""


What am I breaking wrong?

Thank you,
Maxim.

-- 
Cheers,
Maxim Veksler

"Free as in Freedom" - Do u GNU ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I can't inherit from "compiled" classes ?

2007-04-29 Thread half . italian
On Apr 29, 12:48 pm, "Maxim Veksler" <[EMAIL PROTECTED]> wrote:
> Hello list,
>
> I'm trying to subclass socket and select, for both I get:
> """ TypeError: Error when calling the metaclass bases
> module.__init__() takes at most 2 arguments (3 given) """, I don't
> understand this error. Why would python try to pass 3 arguments (what
> are they) ?
>
> Googling for this error gave random results talking about try to
> inherit a "Package" but socket is definitely a class,
> (/usr/lib/python2.4/socket.py). Not sure about select thought.
>
> I've did the following to receive the error:
> """
> In [1]: import socket
>
> In [2]: class PollingSocket(socket):
>...: pass
>...:
> ---
> exceptions.TypeError Traceback (most
> recent call last)
>
> /home/hq4ever/
>
> TypeError: Error when calling the metaclass bases
> module.__init__() takes at most 2 arguments (3 given)
> """
>
> What am I breaking wrong?
>
> Thank you,
> Maxim.
>
> --
> Cheers,
> Maxim Veksler
>
> "Free as in Freedom" - Do u GNU ?

Try:

import socket

class PollingSocket(socket.socket):
pass

~Sean

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


Re: I can't inherit from "compiled" classes ?

2007-04-29 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Maxim Veksler
wrote:

> Hello list,
> 
> I'm trying to subclass socket and select, for both I get:
> """ TypeError: Error when calling the metaclass bases
> module.__init__() takes at most 2 arguments (3 given) """, I don't
> understand this error. Why would python try to pass 3 arguments (what
> are they) ?
> 
> Googling for this error gave random results talking about try to
> inherit a "Package" but socket is definitely a class,
> (/usr/lib/python2.4/socket.py). Not sure about select thought.
> 
> I've did the following to receive the error:
> """
> In [1]: import socket
> 
> In [2]: class PollingSocket(socket):
>...: pass
>...:
> ---
> exceptions.TypeError Traceback (most
> recent call last)
> 
> /home/hq4ever/
> 
> TypeError: Error when calling the metaclass bases
> module.__init__() takes at most 2 arguments (3 given)
> """
> 
> 
> What am I breaking wrong?

You are trying to subclass a module here, just like the error message
says.  The module contains a `socket` type:

In [3]: import socket

In [4]: type(socket)
Out[4]: 

In [5]: type(socket.socket)
Out[5]: 

`select.select()` is a function:

In [6]: import select

In [7]: type(select.select)
Out[7]: 

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Counting

2007-04-29 Thread James Stroud
Andy wrote:
> Hi, the file below will print all the keywords in a file and also the
> line # of the keyword. What I couldn't figure out is to count those
> keywords per line. For example - "Line #1 has 3 keywords"
> 
> Can I do like -
> 
> total[j] = total[j] + numwords(k)
> "Line number %d has %d keywords" % (j, total[j])
> 
> Seems sort of "illegal" in Python?
> 
> 
> 
> -
> import keyword, sys, string, fileinput
> def numwords(s):
> list = string.split(s)
> return len(list)
> 
> # Get the file name either from the command-line or the user
> if len(sys.argv) != 2:
>name = raw_input("Enter the file name: ")
> else:
>name = sys.argv[1]
> 
> inp = open(name,"r")
> linelist = inp.readlines()
> total, words,lines = 0, 0, 0
> 
> for i in range(len(linelist)):
> line = linelist[i]
> tempwords = line.split()
> for k in tempwords:
> if keyword.iskeyword(k):
> total = total + numwords(k)
> j = i + 1
> print" The word * %s * belongs in line number: %d" % (k,
> j)
> 
> print "Total keywords in this file are: %d" %(total)
> 

You probably want something that goes a little like this:

for i,line in enumerate(linelist):
   for k in line.split():
 if keyword.iskeyword(k):
   total += line.count(k)
   print "The word '%s' belongs in line num: %d" % (k, i+1)

print "Total keyords are: %d" % total

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


Re: exclusive shelve open

2007-04-29 Thread castironpi
On Apr 29, 2:12 pm, [EMAIL PROTECTED] wrote:
> I'm trying to be safe and make sure only one python instance opens the
> shelf.  Any ideas?

Using Windows.

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


Re: Counting

2007-04-29 Thread James Stroud
James Stroud wrote:
> Andy wrote:
>> Hi, the file below will print all the keywords in a file and also the
>> line # of the keyword. What I couldn't figure out is to count those
>> keywords per line. For example - "Line #1 has 3 keywords"
>>
>> Can I do like -
>>
>> total[j] = total[j] + numwords(k)
>> "Line number %d has %d keywords" % (j, total[j])
>>
>> Seems sort of "illegal" in Python?
>>
>>
>>
>> -
>> import keyword, sys, string, fileinput
>> def numwords(s):
>> list = string.split(s)
>> return len(list)
>>
>> # Get the file name either from the command-line or the user
>> if len(sys.argv) != 2:
>>name = raw_input("Enter the file name: ")
>> else:
>>name = sys.argv[1]
>>
>> inp = open(name,"r")
>> linelist = inp.readlines()
>> total, words,lines = 0, 0, 0
>>
>> for i in range(len(linelist)):
>> line = linelist[i]
>> tempwords = line.split()
>> for k in tempwords:
>> if keyword.iskeyword(k):
>> total = total + numwords(k)
>> j = i + 1
>> print" The word * %s * belongs in line number: %d" % (k,
>> j)
>>
>> print "Total keywords in this file are: %d" %(total)
>>
> 
> You probably want something that goes a little like this:
> 
> for i,line in enumerate(linelist):
>   for k in line.split():
> if keyword.iskeyword(k):
>   total += line.count(k)
>   print "The word '%s' belongs in line num: %d" % (k, i+1)
> 
> print "Total keyords are: %d" % total
> 
> James

Oops, that over-counts, I forgot to put a continue in. Also, keeping a 
cache of the split line will probably be faster.

for i,line in enumerate(linelist):
   line = line.split()
   for k in line:
 if keyword.iskeyword(k):
   total += line.count(k)
   print "The word '%s' belongs in line num: %d" % (k, i+1)
   continue

print "Total keyords are: %d" % total


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


Re: Counting

2007-04-29 Thread James Stroud
James Stroud wrote:
> James Stroud wrote:
>> Andy wrote:
>>> Hi, the file below will print all the keywords in a file and also the
>>> line # of the keyword. What I couldn't figure out is to count those
>>> keywords per line. For example - "Line #1 has 3 keywords"
>>>
>>> Can I do like -
>>>
>>> total[j] = total[j] + numwords(k)
>>> "Line number %d has %d keywords" % (j, total[j])
>>>
>>> Seems sort of "illegal" in Python?
>>>
>>>
>>>
>>> -
>>> import keyword, sys, string, fileinput
>>> def numwords(s):
>>> list = string.split(s)
>>> return len(list)
>>>
>>> # Get the file name either from the command-line or the user
>>> if len(sys.argv) != 2:
>>>name = raw_input("Enter the file name: ")
>>> else:
>>>name = sys.argv[1]
>>>
>>> inp = open(name,"r")
>>> linelist = inp.readlines()
>>> total, words,lines = 0, 0, 0
>>>
>>> for i in range(len(linelist)):
>>> line = linelist[i]
>>> tempwords = line.split()
>>> for k in tempwords:
>>> if keyword.iskeyword(k):
>>> total = total + numwords(k)
>>> j = i + 1
>>> print" The word * %s * belongs in line number: %d" % (k,
>>> j)
>>>
>>> print "Total keywords in this file are: %d" %(total)
>>>
>>
>> You probably want something that goes a little like this:
>>
>> for i,line in enumerate(linelist):
>>   for k in line.split():
>> if keyword.iskeyword(k):
>>   total += line.count(k)
>>   print "The word '%s' belongs in line num: %d" % (k, i+1)
>>
>> print "Total keyords are: %d" % total
>>
>> James
> 
> Oops, that over-counts, I forgot to put a continue in. Also, keeping a 
> cache of the split line will probably be faster.
> 
> for i,line in enumerate(linelist):
>   line = line.split()
>   for k in line:
> if keyword.iskeyword(k):
>   total += line.count(k)
>   print "The word '%s' belongs in line num: %d" % (k, i+1)
>   continue
> 
> print "Total keyords are: %d" % total
> 
> 
> James

I should really wait until I've had some coffee. Not continue, but break!


for i,line in enumerate(linelist):
   line = line.split()
   for k in line:
 if keyword.iskeyword(k):
   total += line.count(k)
   print "The word '%s' belongs in line num: %d" % (k, i+1)
   break

print "Total keyords are: %d" % total
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Counting

2007-04-29 Thread rockmode
That's a short, abridged version of my code :) But, what I want is to
count total# of keywords per line and print 'em. Rather than
printing :

The word 'and' belongs in line num: 1
The word 'del' belongs in line num: 1
The word 'from' belongs in line num: 1

I want to print " Line #1 has 3 keywords"

;)


> You probably want something that goes a little like this:
>
> for i,line in enumerate(linelist):
>for k in line.split():
>  if keyword.iskeyword(k):
>total += line.count(k)
>print "The word '%s' belongs in line num: %d" % (k, i+1)
>
> print "Total keyords are: %d" % total
>
> James


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


Re: Counting

2007-04-29 Thread castironpi
On Apr 29, 2:11 pm, Andy <[EMAIL PROTECTED]> wrote:
> Hi, the file below will print all the keywords in a file and also the
> line # of the keyword. What I couldn't figure out is to count those
> keywords per line. For example - "Line #1 has 3 keywords"
>
> Can I do like -
>
> total[j] = total[j] + numwords(k)
> "Line number %d has %d keywords" % (j, total[j])
>
> Seems sort of "illegal" in Python?
>
> -
> import keyword, sys, string, fileinput
> def numwords(s):
> list = string.split(s)
> return len(list)
>
> # Get the file name either from the command-line or the user
> if len(sys.argv) != 2:
>name = raw_input("Enter the file name: ")
> else:
>name = sys.argv[1]
>
> inp = open(name,"r")
> linelist = inp.readlines()
> total, words,lines = 0, 0, 0
>
> for i in range(len(linelist)):
> line = linelist[i]
> tempwords = line.split()
> for k in tempwords:
> if keyword.iskeyword(k):
> total = total + numwords(k)
> j = i + 1
> print" The word * %s * belongs in line number: %d" % (k,
> j)
>
> print "Total keywords in this file are: %d" %(total)

> tempwords = line.split()
> for k in tempwords:
   linec = 0
> if keyword.iskeyword(k):
> total = total + numwords(k)
> j = i + 1
   linec += 1
> print" The word * %s * belongs in line number: %d" % (k,
> j)
   print "%i characters in line" % linec

And less readably,

> tempwords = line.split()
> for k in tempwords:
   linec = j
> if keyword.iskeyword(k):
> total = total + numwords(k)
> j = i + 1
> print" The word * %s * belongs in line number: %d" % (k,
> j)
   print "%i characters in line" % ( j - linec )

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


Re: Any Good tools to create CSV Files?

2007-04-29 Thread Aahz
In article <[EMAIL PROTECTED]>,
Carsten Haese  <[EMAIL PROTECTED]> wrote:
>On Sat, 2007-04-28 at 18:55 -0700, johnny wrote:
>>
>> Any Good tools to create CSV Files?  ReportLab only creates pdf
>> files.  I need something to create CSV files.
>
>You mean something like the csv module that is part of Python's standard
>library?
>
 import csv

In all fairness, the csv module is new in Python 2.3, and I'm sure I'm
not the only person still using Python 2.2 for production.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings, 
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters 
are strings for other good reasons."  --Aahz
-- 
http://mail.python.org/mailman/listinfo/python-list


opening a new tab in opera does not work

2007-04-29 Thread solstice.dhiver
hi.
i am using python 2.5.1
when i run
import webbrowser
webbrowser.get('opera').open_new_tab("http://www.osnews.com";)
i got a True after the last command
but nothing happen at all in opera ! 

any one got that too ?

i use opera 9.20 
if i run in a command-line this
opera -remote 'openURL(http://osnews.com,new-page)'
it works

that's off-topic but when i run
webbrowser.get('konqueror').open_new_tab("http://www.osnews.com";)
it open a new tab in opera (yes !) because i have defined my default
webbrowser in kde to be opera(precisely opera -newpage)

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


Re: I can't inherit from "compiled" classes ?

2007-04-29 Thread Maxim Veksler
On 4/29/07, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> In <[EMAIL PROTECTED]>, Maxim Veksler
> wrote:
>
> > Hello list,
> >
> > I'm trying to subclass socket and select, for both I get:
> > """ TypeError: Error when calling the metaclass bases
> > module.__init__() takes at most 2 arguments (3 given) """, I don't
> > understand this error. Why would python try to pass 3 arguments (what
> > are they) ?
> >
> > Googling for this error gave random results talking about try to
> > inherit a "Package" but socket is definitely a class,
> > (/usr/lib/python2.4/socket.py). Not sure about select thought.
> >
> > I've did the following to receive the error:
> > """
> > In [1]: import socket
> >
> > In [2]: class PollingSocket(socket):
> >...: pass
> >...:
> > ---
> > exceptions.TypeError Traceback (most
> > recent call last)
> >
> > /home/hq4ever/
> >
> > TypeError: Error when calling the metaclass bases
> > module.__init__() takes at most 2 arguments (3 given)
> > """
> >
> >
> > What am I breaking wrong?
>
> You are trying to subclass a module here, just like the error message
> says.  The module contains a `socket` type:
>
> In [3]: import socket
>
> In [4]: type(socket)
> Out[4]: 
>
> In [5]: type(socket.socket)
> Out[5]: 
>

Great,
"""
from socket import socket
import select

class PollingSocket(socket):
   pass
"""

> `select.select()` is a function:
>
> In [6]: import select
>
> In [7]: type(select.select)
> Out[7]: 
>

I understand what you are saying, and at the same time don't
understand why it doesn't work. Isn't "everything an object" in
python? And if something is an object does it not implies it's an
instance of some class?

Does this mean I can't somehow make this work: """class
PollingSocket(socket.socket, select):""" ?

Thanks for the help,

> Ciao,
> Marc 'BlackJack' Rintsch

Maxim.


-- 
Cheers,
Maxim Veksler

"Free as in Freedom" - Do u GNU ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Counting

2007-04-29 Thread James Stroud
[EMAIL PROTECTED] wrote:
> That's a short, abridged version of my code :) But, what I want is to
> count total# of keywords per line and print 'em. Rather than
> printing :
> 
> The word 'and' belongs in line num: 1
> The word 'del' belongs in line num: 1
> The word 'from' belongs in line num: 1
> 
> I want to print " Line #1 has 3 keywords"
> 
> ;)
> 


I think it would be obvious how to write this:


for i,line in enumerate(linelist):
   line = line.split()
   for k in line:
 if keyword.iskeyword(k):
   c = line.count(k)
   total += line.count(k)
   print "Line #%d has %d keywords." % (i+1, c)
   break

print "Total keyords are: %d" % total
-- 
http://mail.python.org/mailman/listinfo/python-list


fastest way to find the intersection of n lists of sets

2007-04-29 Thread Prateek
I have 3 variable length lists of sets. I need to find the common
elements in each list (across sets) really really quickly.

Here is some sample code:

# Doesn't make sense to union the sets - we're going to do
intersections later anyway
l1 = reduce(operator.add, list(x) for x in l1)
l2 = reduce(operator.add, list(x) for x in l2)
l3 = reduce(operator.add, list(x) for x in l3)

# Should I do this in two steps? Maybe by intersecting the two
shortest lists first?
s = frozenset(l1) & frozenset(l2) & frozenset(l3)

I'm assuming frozensets are (somehow) quicker than sets because
they're immutable.

Any code suggestions? Maybe using something in the new fancy-schmancy
itertools module?

Thanks,
Prateek

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


help in debugging file.seek, file.read

2007-04-29 Thread Prateek
I have a wierd sort of problem.
I'm writing a bunch of sets to a file (each element is a fixed length
string).

I was originally using the built-in sets type but due to a processing
issue, I had to shift to a Python implementation (see
http://groups.google.com/group/comp.lang.python/browse_thread/thread/77e06005e897653c/12270083be9a67f6).
I'm using Raymond Hettinger's very graciously provided TransactionSet
recipe from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/511496

My old code was pretty speedy but the new code is quite slow and
according to some hotshot profiles it has nothing to do with the new
TransactionSet. *Some* of the file.seek and file.read calls
occasionally block for insane amounts (>10s) of time when reading no
more than 45 bytes of data from the file. So when I'm running load-
tests, this eventually happens like so:

Each i_id statement is the time taken for 100 successive commits.
Each RTH (Read Table Header) statement is the time taken for a single
read call for 45 bytes of data
# sz__TABLE_HEADER_FORMAT__ is 45
hdr = os.read(f.fileno(), sz__TABLE_HEADER_FORMAT__)
#hdr = f.read(sz__TABLE_HEADER_FORMAT__) # Tried this as well

Loading items...
i_id:  0 0.00003057861
i_id:  100 1.01557397842
i_id:  200 1.14013886452
i_id:  300 1.16142892838
i_id:  400 1.16356801987
i_id:  500 1.36410307884
i_id:  600 1.34421014786
i_id:  700 1.30385017395
i_id:  800 1.48079919815
i_id:  900 1.41147589684
RTH:  0.582525968552
RTH:  2.77490496635
i_id:  1000 5.16863512993
i_id:  1100 1.73725795746
i_id:  1200 1.56621193886
i_id:  1300 1.81338000298
i_id:  1400 1.69464302063
i_id:  1500 1.74725604057
i_id:  1600 2.3591946
i_id:  1700 1.85096788406
i_id:  1800 2.20518493652
i_id:  1900 1.94831299782
i_id:  2000 2.03350806236
i_id:  2100 2.32529306412
i_id:  2200 2.44498205185
RTH:  0.105868816376
i_id:  2300 3.65522289276
i_id:  2400 4.2119910717
i_id:  2500 4.21354198456
RTH:  0.115046024323
RTH:  0.122591972351
RTH:  2.88115119934
RTH:  10.5908679962
i_id:  2600 18.8498170376
i_id:  2700 2.42577004433
i_id:  2800 2.47392010689
i_id:  2900 2.88293218613

So I have no idea why this is happening (it is also happening with
seek operations).
Any guidance on how to debug this?

thanks,
Prateek

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


Re: Video: Professor of Physics Phd at Cal Tech says: 911 Inside Job

2007-04-29 Thread Mitchell Jones
In article <[EMAIL PROTECTED]>,
 War Office <[EMAIL PROTECTED]> wrote:

> On 28 abr, 14:15, Eric Gisse <[EMAIL PROTECTED]> wrote:
> > On Apr 24, 6:13 pm, [EMAIL PROTECTED] wrote:

[snip]

> > I love how folks like you ask for intellectual honesty when every
> > effort is made to ignore evidence that doesn't agree with your
> > presupposed findings.
> 
> Which evidence would that be? 

***{I'm not a fan of the Bush administration, and would not put it past 
them to carry out an event such as 911, to create an excuse to jettison 
the Constitution and Bill of Rights. What is certain in any case is 
that, in fact, the Bush administration has used the events of 911 as an 
excuse to toss out the Constitution and Bill of Rights. There are, 
however, at least three possible scenarios regarding 911 itself:

(1) The plane crashes were planned and executed by terrorists. The 
towers fell because of the impacts. Building 7 fell because of the 
impact of debris from the north tower.

(2) The plane crashes were planned and executed by the Bush 
administration. The towers fell because of the impacts. Building 7 fell 
because of the impact of debris from the north tower. 

(3) The plane crashes were planned and executed by the Bush 
administration. The towers fell because of the impacts, plus the effects 
of pre-planted demolition charges. Building 7 fell because of the impact 
of debris from the north tower, plus the effects of pre-planted 
explosive charges. 

I analyzed (3), above, in great detail a month or so back, in a 
sci.physics thread entitled "The amazing denial of what "conspiracy 
kooks" really means" If you are really interested in a reasoned 
response to those arguments, you can probably still find that thread on 
Google.

My conclusion at the time was that possibility (3), above, fails because 
pre-planted explosives are not needed to explain why the towers fell, or 
why building 7 fell. Possibilities (1) and (2), therefore, are all that 
remains.

This post is for informational purposes only, and is not to be taken as 
an indication that I am interesting in slogging my way through all this 
stuff again. Once is more than enough, and so I am killfiling this 
thread after making this post.

--Mitchell Jones}***

*
If I seem to be ignoring you, consider the possibility
that you are in my killfile. --MJ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interrupting ftplib.storbinary()

2007-04-29 Thread billiejoex
On 26 Apr, 16:29, Florian  Demmer <[EMAIL PROTECTED]> wrote:
> Hi!
>
> I have a number of ftp uploads running in parallel using
> ftplib.storbinary and threading and in case one of them fails I need
> to interrupt all the others (but not exit the program completely)...
> do you guys have an idea how i could implement the interruption as
> cleanly as possible?
>
> thanks!

You could interrupt the transfer by directly using the lower 'ftp-
data' socket instead of the storbinary() method.
Try the following code (not tested):


import ftplib

file = open('file.ext', 'r')
ftp = ftplib.FTP()
ftp.connect(host='127.0.0.1', port=21)
ftp.login(user='user', passwd='passwd')
conn = ftp.transfercmd('stor file.ext', rest=None)

# the 'shared' var. change it to
# 1 when you want to stop the transfer
stop = 0
while 1:
chunk = file.read(8192)
conn.sendall(chunk)
if not chunk:
print "finished"
break
elif stop:
print "stopped"
break
conn.close()
ftp.close()

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


Re: help in debugging file.seek, file.read

2007-04-29 Thread Prateek
Sorry, I forgot to mention - the RTH line only prints when the time
taken is > 0.1 second (so that I don't pollute the output with other
calls that complete normally)

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


Re: Video: Professor of Physics Phd at Cal Tech says: 911 Inside Job

2007-04-29 Thread Michael A. Terrell
Mitchell Jones wrote:

> If I seem to be ignoring you, consider the possibility
> that you are in my killfile. --MJ


   Ditto.


-- 
Service to my country? Been there, Done that, and I've got my DD214 to
prove it.
Member of DAV #85.

Michael A. Terrell
Central Florida
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any Good tools to create CSV Files?

2007-04-29 Thread Bart Willems
Aahz wrote:
> In all fairness, the csv module is new in Python 2.3, and I'm sure I'm
> not the only person still using Python 2.2 for production.
That is true, on the other hand, Reportlab is made for at least Python 
2.4, "although it will work with 2.3" - so he has 2.3 at least :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fastest way to find the intersection of n lists of sets

2007-04-29 Thread James Stroud
Prateek wrote:
> I have 3 variable length lists of sets. I need to find the common
> elements in each list (across sets) really really quickly.
> 
> Here is some sample code:
> 
> # Doesn't make sense to union the sets - we're going to do
> intersections later anyway
> l1 = reduce(operator.add, list(x) for x in l1)
> l2 = reduce(operator.add, list(x) for x in l2)
> l3 = reduce(operator.add, list(x) for x in l3)
> 
> # Should I do this in two steps? Maybe by intersecting the two
> shortest lists first?
> s = frozenset(l1) & frozenset(l2) & frozenset(l3)
> 
> I'm assuming frozensets are (somehow) quicker than sets because
> they're immutable.
> 
> Any code suggestions? Maybe using something in the new fancy-schmancy
> itertools module?
> 
> Thanks,
> Prateek
> 

I don't understand why you cast to list. I would propose:

lists_of_sets = [l1, l2, l3]

reduce(set.intersection, (reduce(set.union, x) for x in lists_of_sets))

Since this is simplest, I'm guessing it should be fastest because I'm 
also guessing that set impelmentation is as optimized as list--I think 
this would hold true especially for large sets with sparse overlap 
between lists. So it might be reasonable consider the content of your 
sets and lists and write your code based on the content or on assuming a 
particular composition.

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


Re: Beginner Ping program

2007-04-29 Thread Gabriel Genellina
En Sun, 29 Apr 2007 08:26:36 -0300, Bjoern Schliessmann  
<[EMAIL PROTECTED]> escribió:

> Linus Cohen wrote:
>> It will be called inettools, and the ping function is
>> what I'm working on first. It should be a simple enough job to
>> code in the features the Unix and DOS ping programs have(never
>> stop, change size, change timeout).
>
> IIRC, MS ping has no "never stop", you can only say "repeat 9
> times".

ping -t hostname

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


Re: exclusive shelve open

2007-04-29 Thread Gabriel Genellina
En Sun, 29 Apr 2007 17:13:42 -0300, <[EMAIL PROTECTED]> escribió:

> On Apr 29, 2:12 pm, [EMAIL PROTECTED] wrote:
>> I'm trying to be safe and make sure only one python instance opens the
>> shelf.  Any ideas?
> Using Windows.

Use the locking function in the msvcrt module to lock/unlock the file.  
Locking just the first byte is enough.

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


Re: fastest way to find the intersection of n lists of sets

2007-04-29 Thread John Nagle
James Stroud wrote:
> Prateek wrote:
> 
>> I have 3 variable length lists of sets. I need to find the common
>> elements in each list (across sets) really really quickly.
>>
>> Here is some sample code:
>>
>> # Doesn't make sense to union the sets - we're going to do
>> intersections later anyway
>> l1 = reduce(operator.add, list(x) for x in l1)
>> l2 = reduce(operator.add, list(x) for x in l2)
>> l3 = reduce(operator.add, list(x) for x in l3)
>>
>> # Should I do this in two steps? Maybe by intersecting the two
>> shortest lists first?
>> s = frozenset(l1) & frozenset(l2) & frozenset(l3)
>>
>> I'm assuming frozensets are (somehow) quicker than sets because
>> they're immutable.
>>
>> Any code suggestions? Maybe using something in the new fancy-schmancy
>> itertools module?
>>
>> Thanks,
>> Prateek
>>
> 
> I don't understand why you cast to list. I would propose:
> 
> lists_of_sets = [l1, l2, l3]
> 
> reduce(set.intersection, (reduce(set.union, x) for x in lists_of_sets))
> 
> Since this is simplest, I'm guessing it should be fastest because I'm 
> also guessing that set impelmentation is as optimized as list--I think 
> this would hold true especially for large sets with sparse overlap 
> between lists. So it might be reasonable consider the content of your 
> sets and lists and write your code based on the content or on assuming a 
> particular composition.

 Python sets are hashes, like dictionaries, not trees.  Intersection
is implemented by iterating over the smallest set and trying all its keys
on the other set.  The Python implementation compares the length of two
sets being intersected.  This is OK (it's about O(N log N), maybe better).

 For the above example, it's worth sorting lists_of_sets by the
length of the sets, and doing the short ones first.

 How big are the sets?  If they're small, but you have a lot of
them, you may be better off with a bit-set representation, then
using AND operations for intersection.  If they're huge (tens of millions
of entries), you might be better off doing sorts and merges on the
sets.

 When you ask questions like this, it's helpful to give some
background.  We don't know whether this is a homework assignment, or
some massive application that's slow and you need to fix it, even
if it requires heavy implementation effort.

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


Launching an independent Python program in a cross-platform way (including mac)

2007-04-29 Thread André
I would like to find out how I can launch an independent Python
program from existing one in a cross-platform way.  The result I am
after is that a new terminal window should open (for io independent of
the original script).

The following seems to work correctly under Ubuntu and Windows ... but
I haven't been able to find a way to make it work under Mac OS.

def exec_external(code, path):
"""execute code in an external process
currently works under:
* Windows NT (tested)
* GNOME (tested)  [January 2nd and 15th change untested]
This also needs to be implemented for OS X, KDE
and some form of linux fallback (xterm?)
"""
if os.name == 'nt':
current_dir = os.getcwd()
target_dir, fname = os.path.split(path)

filename = open(path, 'w')
filename.write(code)
filename.close()

if os.name == 'nt':
os.chdir(target_dir) # change dir so as to deal with paths
that
 # include spaces
Popen(["cmd.exe", ('/c start python %s'%fname)])
os.chdir(current_dir)
elif os.name == 'posix':
try:
os.spawnlp(os.P_NOWAIT, 'gnome-terminal', 'gnome-
terminal',
'-x', 'python', '%s'%path)
except:
raise NotImplementedError
else:
raise NotImplementedError
==
Any help would be greatly appreciated.

André

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


Re: fastest way to find the intersection of n lists of sets

2007-04-29 Thread Prateek
>  For the above example, it's worth sorting lists_of_sets by the
> length of the sets, and doing the short ones first.

Thanks. I thought so - I'm doing just that using a simple Decorate-
Sort-Undecorate idiom.

>  How big are the sets?  If they're small, but you have a lot of
> them, you may be better off with a bit-set representation, then
> using AND operations for intersection.  If they're huge (tens of millions
> of entries), you might be better off doing sorts and merges on the
> sets.

I have either 2 or 3 sets (never more) which can be arbitrarily large.
Most of them are small (between 0 and few elements - say less that 5).
A few will be megamonstrous ( > 100,000 items)

>  When you ask questions like this, it's helpful to give some
> background.  We don't know whether this is a homework assignment, or
> some massive application that's slow and you need to fix it, even
> if it requires heavy implementation effort.
>
Its definitely not a homework assignment - its part of a commercial
database query engine. Heavy implementation effort is no problem.

Prateek


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


Re: http pipelining

2007-04-29 Thread John J. Lee
Steve Holden <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] wrote:
> > Which python module is capable of  pipelining http requests?
> > (I know httplib can send mulitple requests per tcp connection, but in
> > a strictly serial way. )
> >
> Oops, sorry, you meant sending requests in parallel, right?
> 
> You'll need to use either urllib or urllib2 for the web, and the
> threading module is one way to run parallel requests. It's fairly easy
> to use as long as you keep your tasks properly isolated form each
> other.

No, he means "HTTP pipelining", which means sending multiple requests
down a single TCP connection, without waiting for the first response.

httplib's module-level docstring says (reformatted here):

"""
... The HTTPResponse class does not enforce this state machine, which
implies sophisticated clients may accelerate the request/response
pipeline. Caution should be taken, though: accelerating the states
beyond the above pattern may imply knowledge of the server's
connection-close behavior for certain requests. For example, it is
impossible to tell whether the server will close the connection UNTIL
the response headers have been read; this means that further requests
cannot be placed into the pipeline until it is known that the server
will NOT be closing the connection.
"""

So, sort-of-yes, if you know what you're doing and you're lucky.

Certainly urllib and urllib2 don't support pipelining.  There were
plans for a new HTTP client in Twisted with pipelining support, but I
don't know if that ever came about.  AFAIK not many libraries (in any
language) support it -- e.g. none of "Jakarta commons HTTPClient",
libwww-perl, and libcurl currently support it.  libwww (without the
"-perl") does claim to support it (I say "claim" merely because I
haven't used it or read the source -- no FUD intended).


Side note: As the OP mentions in a followup, by default firefox does
NOT do pipelining (to the disbelief of the people I told about this
when it came up in a previous job -- but I just tried running tcpdump
and indeed about:config seems to be telling the truth; fortunately, in
response to the limitations imposed by RFC 2616, somebody has
thoughtfully arranged for the speed of light to be fast enough for
this not to be a major problem when using websites on the other side
of the planet).  The firefox people say:

http://www.mozilla.org/support/firefox/tips#oth_pipelining

"""
Pipelining is an experimental feature, designed to improve page-load
performance, that is unfortunately not well supported by some web
servers and proxies.
"""

Instead of pipelining, it uses multiple connections (2 when I tried
it, which is the maximum RFC 2616 says SHOULD be used by a
"single-user client").  I didn't try IE, but apparently it has the
same behaviour (2 connections, no pipelining):

http://blogs.msdn.com/ie/archive/2005/04/11/407189.aspx


I wonder if the right economic pressures are there for SCTP ever to
get used for everyday web HTTP stuff...


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


Re: I can't inherit from "compiled" classes ?

2007-04-29 Thread Gabriel Genellina
En Sun, 29 Apr 2007 17:27:59 -0300, Maxim Veksler <[EMAIL PROTECTED]>  
escribió:

> On 4/29/07, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>>
> """
> from socket import socket
> import select
>
> class PollingSocket(socket):
>pass
> """
>
>> `select.select()` is a function:
>
> I understand what you are saying, and at the same time don't
> understand why it doesn't work. Isn't "everything an object" in
> python? And if something is an object does it not implies it's an
> instance of some class?

I'm not sure if your last statement is true now, and certainly it was not  
true before Python 2.2; there were objects that were not class instances  
(numbers, functions, by example). Maybe some objects still remain that are  
not instances of any class.
Anyway, "an object" and "a class" are not the same thing, and you can't  
use an arbitrary object when you actually need a class.

> Does this mean I can't somehow make this work: """class
> PollingSocket(socket.socket, select):""" ?

Those things inside () are called "base classes"; this is "class"  
inheritance; you create a new "class" inheriting from existing ones. That  
is, you cant inherit from select, because select is a function, not a  
class.

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


Re: Launching an independent Python program in a cross-platform way (including mac)

2007-04-29 Thread André
On Apr 29, 8:32 pm, André <[EMAIL PROTECTED]> wrote:
> I would like to find out how I can launch an independent Python
> program from existing one in a cross-platform way.  The result I am
> after is that a new terminal window should open (for io independent of
> the original script).
>
> The following seems to work correctly under Ubuntu and Windows ... but
> I haven't been able to find a way to make it work under Mac OS.
>

Forgot to add that there was an import as follows:

import os  # should have been obvious
from subprocess import Popen   # slightly less so


> def exec_external(code, path):
> """execute code in an external process
> currently works under:
> * Windows NT (tested)
> * GNOME (tested)  [January 2nd and 15th change untested]
> This also needs to be implemented for OS X, KDE
> and some form of linux fallback (xterm?)
> """
> if os.name == 'nt':
> current_dir = os.getcwd()
> target_dir, fname = os.path.split(path)
>
> filename = open(path, 'w')
> filename.write(code)
> filename.close()
>
> if os.name == 'nt':
> os.chdir(target_dir) # change dir so as to deal with paths
> that
>  # include spaces
> Popen(["cmd.exe", ('/c start python %s'%fname)])
> os.chdir(current_dir)
> elif os.name == 'posix':
> try:
> os.spawnlp(os.P_NOWAIT, 'gnome-terminal', 'gnome- terminal',
> '-x', 'python', '%s'%path)
> except:
> raise NotImplementedError
> else:
> raise NotImplementedError
> ==
> Any help would be greatly appreciated.
>
> André


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


Re: fastest way to find the intersection of n lists of sets

2007-04-29 Thread Prateek
On Apr 30, 3:48 am, James Stroud <[EMAIL PROTECTED]> wrote:
> Prateek wrote:
> > I have 3 variable length lists of sets. I need to find the common
> > elements in each list (across sets) really really quickly.
>
> > Here is some sample code:
>
> > # Doesn't make sense to union the sets - we're going to do
> > intersections later anyway
> > l1 = reduce(operator.add, list(x) for x in l1)
> > l2 = reduce(operator.add, list(x) for x in l2)
> > l3 = reduce(operator.add, list(x) for x in l3)
>
> > # Should I do this in two steps? Maybe by intersecting the two
> > shortest lists first?
> > s = frozenset(l1) & frozenset(l2) & frozenset(l3)
>
> > I'm assuming frozensets are (somehow) quicker than sets because
> > they're immutable.
>
> > Any code suggestions? Maybe using something in the new fancy-schmancy
> > itertools module?
>
> > Thanks,
> > Prateek
>
> I don't understand why you cast to list. I would propose:
>

The reason why I'm casting to a list first is because I found that
creating a long list which I convert to a set in a single operation is
faster (although probably less memory efficient - which I can deal
with) than doing all the unions.

Prateek

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


Re: Launching an independent Python program in a cross-platform way (including mac)

2007-04-29 Thread Prateek
On Apr 30, 4:32 am, André <[EMAIL PROTECTED]> wrote:
> I would like to find out how I can launch an independent Python
> program from existing one in a cross-platform way.  The result I am
> after is that a new terminal window should open (for io independent of
> the original script).
>
> The following seems to work correctly under Ubuntu and Windows ... but
> I haven't been able to find a way to make it work under Mac OS.
>
> def exec_external(code, path):
> """execute code in an external process
> currently works under:
> * Windows NT (tested)
> * GNOME (tested)  [January 2nd and 15th change untested]
> This also needs to be implemented for OS X, KDE
> and some form of linux fallback (xterm?)
> """
> if os.name == 'nt':
> current_dir = os.getcwd()
> target_dir, fname = os.path.split(path)
>
> filename = open(path, 'w')
> filename.write(code)
> filename.close()
>
> if os.name == 'nt':
> os.chdir(target_dir) # change dir so as to deal with paths
> that
>  # include spaces
> Popen(["cmd.exe", ('/c start python %s'%fname)])
> os.chdir(current_dir)
> elif os.name == 'posix':
> try:
> os.spawnlp(os.P_NOWAIT, 'gnome-terminal', 'gnome-
> terminal',
> '-x', 'python', '%s'%path)
> except:
> raise NotImplementedError
> else:
> raise NotImplementedError
> ==
> Any help would be greatly appreciated.
>
> André

Well,

You need to check sys.platform on the Mac instead of os.name.
os.name returns 'posix' on all *nix based systems. sys.platform
helpfully returns "darwin" on the Mac.

Not sure how to start Terminal. Here's what I got when I tried it:

>>> if sys.platform == "darwin": os.spawnlp(os.P_NOWAIT, 
>>> '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal')
9460
>>> 2007-04-30 05:19:59.255 [9460] No Info.plist file in application bundle or 
>>> no NSPrincipalClass in the Info.plist file, exiting

Maybe I'm just calling it wrong and you'll have more luck.

Prateek

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


Re: fastest way to find the intersection of n lists of sets

2007-04-29 Thread John Nagle
Prateek wrote:
>> For the above example, it's worth sorting lists_of_sets by the
>>length of the sets, and doing the short ones first.
> 
> 
> Thanks. I thought so - I'm doing just that using a simple Decorate-
> Sort-Undecorate idiom.
> 
> 
>> How big are the sets?  If they're small, but you have a lot of
>>them, you may be better off with a bit-set representation, then
>>using AND operations for intersection.  If they're huge (tens of millions
>>of entries), you might be better off doing sorts and merges on the
>>sets.
> 
> 
> I have either 2 or 3 sets (never more) which can be arbitrarily large.
> Most of them are small (between 0 and few elements - say less that 5).
> A few will be megamonstrous ( > 100,000 items)
> 
> 
>> When you ask questions like this, it's helpful to give some
>>background.  We don't know whether this is a homework assignment, or
>>some massive application that's slow and you need to fix it, even
>>if it requires heavy implementation effort.
>>
> 
> Its definitely not a homework assignment - its part of a commercial
> database query engine. Heavy implementation effort is no problem.
> 
> Prateek

If you're intersecting a set of 5 vs a set of 100,000, the
intersection time won't be the problem.  That's just five lookups.
It's building a set of 100,000 items that may be time consuming.

Does the big set stay around for a while, or do you have to pay
that cost on each query?

Those really aren't big data sets on modern machines.

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


Re: Numbers and truth values

2007-04-29 Thread Alex Martelli
Beliavsky <[EMAIL PROTECTED]> wrote:
...
> > If this has changed in the Fortran 1990 standard or later, then I can
> > only say I'm happy I stopped using Fortran heavily before such standards
> > became widespread in commonly available compilers -- by the late '90s,
> > when I was still using _some_Fortran, it was Fortran '77, as that was
> > the version that was widely available and well optimized.
> 
> I don't think the official status of such has changed -- it's still
> illegal to change a constant and the compiler is still not required to
> catch the error

Oh good -- I'm happy to hear that the original spirit IS still around.

> -- but compilers may be more likely to reject
> such code as before, helping programmers spot errors. IMO that's a
> good thing.

In general, as an engineer, I think that making tools more complicated
so that a single tool can serve multiple purposes is not necessarily a
win.  I do not want one pair of shoes that are designed to be excellent
for running AND for dancing AND for mountain hiking: I'd much rather
have three specialized pairs of shoes instead, one pair for running, one
for dancing, one for hiking.

Similarly, I'd rather have one tool to take presumably-correct sources
and generate great machine code from them, and separate tools to nitpick
the bejeezus out of the sources to make really sure they ARE indeed
perfectly correct from all viewpoints.  Two (or more) simple, fully
specialized tools make for a better toolbox than one complex,
multi-purpose one.  Few except engineers seem to understand this.

> When is no longer using a language, one has the luxury of thinking
> about it in an ideological rather than practical manner.

I thought about Fortran in exactly the same way when I was doing most of
my coding in it, and also using it to teach "numerical computing" in
university.  Most errors came (and still come) from people who just
don't understand the underlying mathematical nature and realities of
floating point (and numerical computations more generally), and I never
expected a compiler to magically start warning the user about "you're
using a very badly conditioned algorithm for this computation":-), the
one thing that would have really saved me a lot of time in my advisory
and teaching roles.  Exactly the same problems keep surfacing in
programs in Python and any other language too, barely veiled by today's
growing propensity for double-precision and wider-yet floats; offering a
rich library of functions is NOT a viable replacement for understanding
and approaching computation correctly (users will just call extremely
general library functions, rather than understand their problem's
specific "geometries" and address them appropriately).

(Let me offer one more plug for my favorite "book about programming
without a single line of code in it", Foreman Acton's "Real computing
made real", now out in a wonderfully cheap Dover edition: Acton makes
this case better than I've ever seen it made elsewhere, and offers many
excellent examples of how numerical computation SHOULD be done).


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


Re: Free Windows Vista Download

2007-04-29 Thread Alvin Bruney [MVP]
That's a misleading post, you should indicate that this is an evaluation 
copy.

-- 
Regards,
Alvin Bruney
--
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> http://freewindowsvista.blogspot.com/ - Get Windows Vista for Free
> 


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


Re: SEO - Search Engine Optimization - Seo Consulting

2007-04-29 Thread Alvin Bruney [MVP]
>Top posting
Did not. I replied to the message at the bottom of the thread.

>Call yourself an MVP, that's a joke Slick.
Yup, I do call myself an MVP, it's not a joke either.

-- 
Regards,
Alvin Bruney
--
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


"Spin Dryer" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Sat, 28 Apr 2007 21:21:39 -0400, ["Alvin Bruney [MVP]"  without an email address>] said :-
>
>>Please don't spam this group
>
> Top posting and without removing the spamvertised site, you are as bad
> as the spammer. Call yourself an MVP, that's a joke Slick.
>
> Indeed the spam was not even seen by probably many servers until you
> decided to reply. 


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


Re: relative import broken?

2007-04-29 Thread Alex Martelli
Alan Isaac <[EMAIL PROTECTED]> wrote:

> "Alex Martelli" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > If you're running test1.py as your main module, then it's not part of a
> > package, so the relative import should indeed fail as you mention.
> 
> So if I understand you,
>  in a package, any module that I wish
> to make available for execution as a script
> (in the usual way, with a main function)
> cannot have any relative imports.
> Is this right?  What is the reason for
> this restriction?  (And where is it
> documented?)

The most up-to-date documentation for import and from statements is at
 but it's still somewhat
incomplete -- it gives the grammar for relative imports, but does not
explain its semantics, nor, for that matter, any of the semantics of
pakages. The discussions about relative imports in particular are
recorded as PEP 328, while an old essay about the semantics of packages
is recorded at a link give on the docs page I mentioned.

Very simply, PEP 328 explains:
"""
Relative Imports and __name__

Relative imports use a module's __name__ attribute to determine that
module's position in the package hierarchy. If the module's name does
not contain any package information (e.g. it is set to '__main__') then
relative imports are resolved as if the module were a top level module,
regardless of where the module is actually located on the file system.
"""
and points to four discussion threads on python-dev which, after much
give and take, led to Guido picking these semantics.

To me, it makes sense: if a module is top-level, and thus not part of a
package (and __main__ in particular is always in that state), then
saying "import from the current package" has no well defined meaning,
because there IS no "current package".  Using __name__ rather than
__file__, in turn, makes a lot of sense, because a package's _logical_
structure is defined by its __path__, and need not coincide with any
_physical_ arrangement of directories.

If you have a better and sharper idea about how relative imports should
work in toplevel modules (those whose __name__ indicates they have NOT
been imported as part of a package, including __main__), feel free to
make a case for it on python-dev (python-list is fine for preliminary
discussions and brainstorming, but nothing will happen about any idea
until and unless it's taken to python-dev, survives the scathing barrage
of objections that strongly characterizes that mailing list, and finally
manages to convince Guido:-).


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


Re: SEO - Search Engine Optimization - Seo Consulting

2007-04-29 Thread Sherm Pendley
"Alvin Bruney [MVP]"  writes:

>>Top posting
> Did not. I replied to the message at the bottom of the thread.

Congratulations, you've now made a fool of yourself in public.

Top posting has nothing to do with where your reply is placed with
respect to other messages. Top posting is when you add your text
above the quoted material in your reply - as you did once again in
what I'm replying to.

When you open a book, do you start at the bottom of the page and
read up? I didn't think so.

>>Call yourself an MVP, that's a joke Slick.
> Yup, I do call myself an MVP, it's not a joke either.

It is when you don't have a clue.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any Good tools to create CSV Files?

2007-04-29 Thread John Machin
On 30/04/2007 6:29 AM, Aahz wrote:
> In article <[EMAIL PROTECTED]>,
> Carsten Haese  <[EMAIL PROTECTED]> wrote:
>> On Sat, 2007-04-28 at 18:55 -0700, johnny wrote:
>>> Any Good tools to create CSV Files?  ReportLab only creates pdf
>>> files.  I need something to create CSV files.
>> You mean something like the csv module that is part of Python's standard
>> library?
>>
> import csv
> 
> In all fairness, the csv module is new in Python 2.3, and I'm sure I'm
> not the only person still using Python 2.2 for production.

In all fairness to those making ironic comments, the OP has given no 
indication that he is bound to an old version of Python.

The Object-Craft csv extension module (ancestor of the Python csv 
module) has been available since October 2000. It still shows up in 
Google [it's the 3rd result if one searches for "python csv"] and has 
the source available for download -- there are even Windows binaries 
(.pyd) for Python 2.1 and 2.2.

In all fairness to the OP, perhaps he has never heard of search engines, 
or perhaps he has no ARPA^H^H^H^HInternet access.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fastest way to find the intersection of n lists of sets

2007-04-29 Thread Prateek
On Apr 30, 5:08 am, John Nagle <[EMAIL PROTECTED]> wrote:
> Prateek wrote:
> >> For the above example, it's worth sorting lists_of_sets by the
> >>length of the sets, and doing the short ones first.
>
> > Thanks. I thought so - I'm doing just that using a simple Decorate-
> > Sort-Undecorate idiom.
>
> >> How big are the sets?  If they're small, but you have a lot of
> >>them, you may be better off with a bit-set representation, then
> >>using AND operations for intersection.  If they're huge (tens of millions
> >>of entries), you might be better off doing sorts and merges on the
> >>sets.
>
> > I have either 2 or 3 sets (never more) which can be arbitrarily large.
> > Most of them are small (between 0 and few elements - say less that 5).
> > A few will be megamonstrous ( > 100,000 items)
>
> >> When you ask questions like this, it's helpful to give some
> >>background.  We don't know whether this is a homework assignment, or
> >>some massive application that's slow and you need to fix it, even
> >>if it requires heavy implementation effort.
>
> > Its definitely not a homework assignment - its part of a commercial
> > database query engine. Heavy implementation effort is no problem.
>
> > Prateek
>
> If you're intersecting a set of 5 vs a set of 100,000, the
> intersection time won't be the problem.  That's just five lookups.
> It's building a set of 100,000 items that may be time consuming.
>
> Does the big set stay around for a while, or do you have to pay
> that cost on each query?
>
> Those really aren't big data sets on modern machines.
>
> John Nagle

100,000 is an arbitrary number - that is potentially equivalent to the
number of unique cells in all tables of a typical database (thats the
best analogy I can come up with since this isn't a typical RDBMS).

The big set does stay around for a while - I've implemented an LRU
based caching algorithm on the code that does the I/O. Since the db is
transactioned, I keep one copy in the current transaction cache (which
is a simple dictionary) and one in the main read cache (LRU based)
(which obviously survives across transactions). Since the largest sets
also tend to be the most frequently used, this basically solves my I/O
caching issue.

My problem is that I had ugly code doing a lot of unnecessary list <->
set casting. Here is what I've got now:

from itertools import chain
ids1 = [...], ids2 = [...], ids3 = [...]
_efs = frozenset()
# dbx.get calls return sets
l1 = frozenset(chain(*[db1.get(x, _efs) for x in ids1])
l2 = frozenset(chain(*[db2.get(x, _efs) for x in ids2])
l3 = frozenset(chain(*[db3.get(x, _efs) for x in ids3])

decorated = [(len(x), x) for x in [l1, l2, l3]]
decorated.sort()
result = reduce(set.intersection, [x[1] for x in decorated])

What do you think?

Prateek

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


Get Mac OS X google Desktop 5 Free

2007-04-29 Thread Leisure . 208
http://macosxdesktop.blogspot.com/ - Mac OS X now compatible with
google desktop 5.

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


Re: help in debugging file.seek, file.read

2007-04-29 Thread Prateek
On Apr 30, 3:20 am, Prateek <[EMAIL PROTECTED]> wrote:
> Sorry, I forgot to mention - the RTH line only prints when the time
> taken is > 0.1 second (so that I don't pollute the output with other
> calls that complete normally)

I have some more information on this problem. Turns out the issue is
with buffer syncing.
I was already doing a flush operation on the file after every commit
(which flushes the user buffers).

I added an os.fsync call which fixed the erratic behavior. But the
code is still horribly slow... 122s vs around 100s (without the
fsync).
Since fsync flushes the kernel buffers, I'm assuming this has
something to do with my O/S (Mac OS 10.4.9 Intel - Mac Book Pro
2.33Ghz Core 2 Duo, 2GB RAM).

Can anybody help?

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


Re: SEO - Search Engine Optimization - Seo Consulting

2007-04-29 Thread Juan T. Llibre
re:
!>>>Top posting
!>> Did not. I replied to the message at the bottom of the thread.
!> Congratulations, you've now made a fool of yourself in public.

OK, cut it out.

Top or bottom posting is a user choice.
No need to flame someone for using either.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===
"Sherm Pendley" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> "Alvin Bruney [MVP]"  writes:
>
>>>Top posting
>> Did not. I replied to the message at the bottom of the thread.
>
> Congratulations, you've now made a fool of yourself in public.
>
> Top posting has nothing to do with where your reply is placed with
> respect to other messages. Top posting is when you add your text
> above the quoted material in your reply - as you did once again in
> what I'm replying to.
>
> When you open a book, do you start at the bottom of the page and
> read up? I didn't think so.
>
>>>Call yourself an MVP, that's a joke Slick.
>> Yup, I do call myself an MVP, it's not a joke either.
>
> It is when you don't have a clue.
>
> sherm--



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

Stopping pythoncom.PumpMessages in a windows service

2007-04-29 Thread Gheorghe Postelnicu
Hi,

I am trying to create a windows service that will process some
keyboard events. For that, i am trying to use pyHook and pythoncom,
which work great in a stand-alone application. However, when in a
service, the first problem I encounter is that the SvcStop part
doesn't seem to be responding. Any suggestions?

Thanks,
-- 
Gheorghe Postelnicu, PhD
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fastest way to find the intersection of n lists of sets

2007-04-29 Thread Paul Rubin
Prateek <[EMAIL PROTECTED]> writes:
> The big set does stay around for a while - I've implemented an LRU
> based caching algorithm on the code that does the I/O. Since the db is
> transactioned, I keep one copy in the current transaction cache (which
> is a simple dictionary) and one in the main read cache (LRU based)
> (which obviously survives across transactions). Since the largest sets
> also tend to be the most frequently used, this basically solves my I/O
> caching issue.

The best approach varies from instance to instance.  Some big
databases often will do stuff like statistically sample the sets from
a given query, try a few different strategies on the samples in order
to figure out which one works best on them, then use the apparent best
strategy on the full sets.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Counting

2007-04-29 Thread Andy
I pretty doubt about this - "c = line.count(k)" I might wanna recheck
on that.
-
I think it would be obvious how to write this:

for i,line in enumerate(linelist):
   line = line.split()
   for k in line:
 if keyword.iskeyword(k):
   c = line.count(k)
   total += line.count(k)
   print "Line #%d has %d keywords." % (i+1, c)
   break

print "Total keyords are: %d" % total

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


Re: Counting

2007-04-29 Thread Andy
James -

I pretty doubt about this - "c = line.count(k)" You might wanna
recheck on that.

I think it would be obvious how to write this:

for i,line in enumerate(linelist):
   line = line.split()
   for k in line:
 if keyword.iskeyword(k):
   c = line.count(k)
   total += line.count(k)
   print "Line #%d has %d keywords." % (i+1, c)
   break

print "Total keyords are: %d" % total


>
> I think it would be obvious how to write this:
>
> for i,line in enumerate(linelist):
>line = line.split()
>for k in line:
>  if keyword.iskeyword(k):
>c = line.count(k)
>total += line.count(k)
>print "Line #%d has %d keywords." % (i+1, c)
>break
>
> print "Total keyords are: %d" % total


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


Re: fastest way to find the intersection of n lists of sets

2007-04-29 Thread Alex Martelli
Prateek <[EMAIL PROTECTED]> wrote:

> >  For the above example, it's worth sorting lists_of_sets by the
> > length of the sets, and doing the short ones first.
> 
> Thanks. I thought so - I'm doing just that using a simple Decorate-
> Sort-Undecorate idiom.

Use, instead, the DSU that is now build into Python:

listofsets.sort(key=len)

this will be faster (as well as more readable &c) than programming your
own DSU, and is exactly the reason the key= parameter was added.

I also suggest avoiding reduce in favor of a simple explicit loop.


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


Beginner question on threads

2007-04-29 Thread Teresa Hardy

I have successfully made the threading work on a Window XP machine with quad
processors but now I am trying to pass some variables around and am fighting
with Lock()

I have searched through several different documents and forums, some of
which hint at problems with threading on Windows machines so I thought I
should ask...

Can I get use the .acquire() and .release()?
The thread dies unless I comment out these two commands. But I can't thread
unless I can control

ilock = threading.Lock()

ImgGrabber.ilock.aquire()
self.i_inthreads = ImgGrabber.i_temp
ImgGrabber.i_temp += 1
ImgGrabber.ilock.release()

Other details about what I am using
Python 2.4
modPython
Apache server

Hope that's enough info for somebody to give me a recommendation.

To the other beginners that are listening, here are the references I am
using to get this far...
http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf
Python How to Program by Deitel, Deitel, Liperi, and Wiedermann

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

Re: While we're talking about annoyances

2007-04-29 Thread Alex Martelli
Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
   ...
> > >> decorated.sort()
   ...
> > def index(sequence):
> >  return sorted(range(len(sequence)), key=sequence.__getitem__)
   ...
> But really these two versions of rank are slower than the original one
> (as sorting a list is O(nlogn) whereas filling a table with
> precomputed values is O(n) ).

Wrong, because the original one also had a sort step, of course, so it
was also, inevitably, O(N log N) -- I've quoted the .sort step above.

> Anyway I would like to contribute my own index function:
> 
> def index(seq):
>  return sum(sorted(map(list,enumerate(seq)), key=list.pop), [])
> 
> It's short and has the advantage of being self-documenting, which will
> save Steven a lot of annoying typing I hope ;)  Who said Python
> couldn't rival with perl?

sum is for summing NUMBERS -- using it on lists is O(N squared).

So, this solution is asymptotically VERY slow, as well as obfuscated.


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


  1   2   >