Re: Problem with itertools.groupby.

2006-05-25 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > What am I doing wrong here? > import operator import itertools vals = [(1, 11), (2, 12), (3, 13), (4, 14), (5, 15), > ... (1, 16), (2, 17), (3, 18), (4, 19), (5, 20)] for k, g in itertools.groupby(iter(vals), operator.itemgetter(0)): > ... pr

Re: Go "help" the perl list instead Fredrik Lundh

2006-05-25 Thread A. Sinan Unur
D H <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > You obviously ignored that and invented some argument that he > posted with malicious intentions. That better describes most of > your thousands of annoying posts. I don't know what describes what you did. What is the point of bringing

Re: Multi-dimensional list initialization trouble

2006-05-25 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > Hello I found this very strange; is it a bug, is it a "feature", am I > being naughty or what? > foo = [[0, 0], [0, 0]] baz = [ [0]*2 ] * 2 >... > Why on earth does foo and baz behave differently?? This is a frequently made mistake. try also: >>> bumble = [[0

Re: Multi-dimensional list initialization trouble

2006-05-25 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Hello I found this very strange; is it a bug, is it a "feature", am I > being naughty or what? the repeat operator (*) creates a new list with references to the same inner objects, so you end up with a list containing multiple references to the same list. also see:

Re: Multi-dimensional list initialization trouble

2006-05-25 Thread trebucket
An expression like this creates a list of integers: >>> [0] * 2 [0, 0] But an expression like this creates list of references to the list named `foo': >>> foo = [0, 0] >>> baz = [foo] * 2 [foo, foo] So, setting baz[0][0] = 1, is really setting foo[0] = 1. There is only one instance of foo, but y

Re: Problem with itertools.groupby.

2006-05-25 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > What am I doing wrong here? > import operator import itertools vals = [(1, 11), (2, 12), (3, 13), (4, 14), (5, 15), > ... (1, 16), (2, 17), (3, 18), (4, 19), (5, 20)] for k, g in itertools.groupby(iter(vals), operator.itemgetter(0)): > ... p

Re: John Bokma harassment

2006-05-25 Thread Fred Gilham
Dale King <"DaleWKing [at]gmail [dot] com"> writes: > Therefore you do not have the "right" to do what you want with > Usenet. You have a responsibility to use Usenet in a way that benefits > the group as a whole (e.g. asking interesting questions that educate > others). ...or at least, in a way

Re: Problem with itertools.groupby.

2006-05-25 Thread Fredrik Lundh
> itertools only looks for changes to the key value (the one returned by > operator.itemgetter(0) in your case); it doesn't sort the list for you. > > this should work: > >for k, g in itertools.groupby(sorted(vals), operator.itemgetter(0)): > print k, [i for i in g] footnote: to turn

how to open password protected PDF's in Python

2006-05-25 Thread sonicpulse
Hello, I made a program that iterates through all the pdf's in a folder and opens them and prints them. However, all of these pdf's are password protected, so I have to manually type in the password many times. Is there any way to open a password-protected PDF with the password entered through py

__getattr__ and functions that don't exist

2006-05-25 Thread Erik Johnson
Maybe I just don't know the right special function, but what I am wanting to do is write something akin to a __getattr__ function so that when you try to call an object method that doesn't exist, it get's intercepted *along with it's argument*, in the same manner as __getattr__ intercepts attribut

Re: how to clear up a List in python?

2006-05-25 Thread vbgunz
> if you don't know how to do things, you don't need to post. > if you know why this is about the dumbest way to do what you're doing, > and you're posted this on purpose, you really need to grow up. If this was the case who then would post any questions? I not only made my post with the best of i

Re: __getattr__ and functions that don't exist

2006-05-25 Thread Nick Smallbone
Erik Johnson wrote: > Maybe I just don't know the right special function, but what I am wanting to > do is write something akin to a __getattr__ function so that when you try to > call an object method that doesn't exist, it get's intercepted *along with > it's argument*, in the same manner as __ge

Re: Go "help" the perl list instead Fredrik Lundh

2006-05-25 Thread Mirco Wahab
Thus spoke D H (on 2006-05-25 23:12): > Fredrik Lundh wrote: >> if you don't know how to do things, you don't need to post. > > He already posted ... Based on your Text, you can (in Perl, of course ;-) extract the Goedel-Number sequence (prime number sequence) of it: use Acme::Goedelize;

Re: Secure Pickle-like module

2006-05-25 Thread jiba
> There are a couple factual inaccuracies on the site that I'd like to clear up > first: > Trivial benchmarks put cerealizer and banana/jelly on the same level as far > as performance goes: > $ python -m timeit -s 'from cereal import dumps; L = ["Hello", " ", ("w", > "o", "r", "l", "d", ".")]' '

Re: [ANNOUNCE] Thirty-second release of PythonCAD now available

2006-05-25 Thread ziggy
In article <[EMAIL PROTECTED]>, "Art Haas" <[EMAIL PROTECTED]> wrote: > Hi. > > I'm pleased to announce the thirty-second development release of PythonCAD, > a CAD package for open-source software users. As the name implies, > PythonCAD is written entirely in Python. The goal of this project is

Re: Pyrex installation on windows XP: step-by-step guide

2006-05-25 Thread Jim Lewis
Thanks but now another problem :-( Examples in books show importing a global so why does below give: AttributeError: 'module' object has no attribute 'globalvar' primes.pyx: from run import globalvar def prime(int kmax): result = [run.globalvar] ... run.py: from primes import prime globalvar =

Re: how to clear up a List in python?

2006-05-25 Thread Fredrik Lundh
vbgunz wrote: >> if you don't know how to do things, you don't need to post. > > If this was the case who then would post any questions? you didn't post a question, you provided a ludicrously bad solution in response to a simple question. that's not a good way to promote Python. -- http://

Survey on open-source software for the desktop

2006-05-25 Thread Sender
I just submit the questionnaire to Digg, you can digg for it here: http://digg.com/software/Survey_on_open-source_software_for_the_desktop And if you want to fill out the questionnaire, here it is: http://freeonlinesurveys.com/rendersurvey.asp?sid=iegzi2sbv9j9g8h195091 Thanks for your contribut

Your message to slug awaits moderator approval

2006-05-25 Thread slug-bounces
Your mail to 'slug' with the subject Stolen document Is being held until the list moderator can review it for approval. The reason it is being held: SpamAssassin identified this message as possible spam (score 5.3) Either the message will get posted to the list, or you will receive not

Re: Python Programming Books?

2006-05-25 Thread Luis M. González
Free online resources for learning Python: To get started, I strongly suggest Josh Cogliati's "Non-Programmers Tutorial for Python" ( http://honors.montana.edu/~jjc/easytut/easytut/ ). I learned programming with this little tutorial, which is a very good introduction. After that, you could check

Re: how to clear up a List in python?

2006-05-25 Thread vbgunz
I will not try and stop helping others because you don't like my answers. I found a perfectly good way how not to do something that wasn't exactly wrong anyway. if you can take another persons honest attempt to help someone and twist it into something it is not, I can only suggest you look in the

Re: Anyone compiling Python 2.3 on an SCO OpenServer 5 box?

2006-05-25 Thread Aurelio Martin
Mike Kent wrote: > If anyone is successfully compiling Pyton 2.3 on an SCO OpenServer 5 > box, I'd appreciate hearing from you on how you managed to do it. So > far, I'm unable to get a python that doesn't coredump. > Hey, I remember trying to compile Python 1.5 on an SCO OpenServer 5 box back

Re: list comprehensions put non-names into namespaces!

2006-05-25 Thread Ben Cartwright
[EMAIL PROTECTED] wrote: > Lonnie> List comprehensions appear to store their temporary result in a > Lonnie> variable named "_[1]" (or presumably "_[2]", "_[3]" etc for > Lonnie> nested comprehensions) > > Known issue. Fixed in generator comprehensions. Dunno about plans to fix > it in li

Re: Anyone compiling Python 2.3 on an SCO OpenServer 5 box?

2006-05-25 Thread Mike Kent
I need to compile Python on OpenServer 5 because I need to 'freeze' our Python app, and running 'freeze' requires a working, compilable source installation of Python. -- http://mail.python.org/mailman/listinfo/python-list

Re: __getattr__ and functions that don't exist

2006-05-25 Thread Erik Johnson
Thanks for your reply, Nick. My first thought was "Ahhh, now I see. That's slick!", but after playing with this a bit... >>> class Foo: ... def __getattr__(self, attr): ... def intercepted(*args): ... print "%s%s" % (attr, args) ... return intercepted ... >>> f =

Re: how to clear up a List in python?

2006-05-25 Thread George Sakkis
vbgunz wrote: > I will not try and stop helping others because you don't like my > answers. I found a perfectly good way how not to do something that > wasn't exactly wrong anyway. if you can take another persons honest > attempt to help someone and twist it into something it is not, I can > only

Re: Use of lambda functions in OOP, any alternative?

2006-05-25 Thread Pablo
Oh! Thanx! Great! this is what i was looking for! :) Scott David Daniels ha escrito: > Pablo wrote: > > > Second solution: This is what i want, but... > > > > class Base(object): > > def __init__(self, attr): > > self._attr = attr > > def getattr(self): > > return self._at

Re: Python Programming Books?

2006-05-25 Thread John Bokma
"Luis M. González" <[EMAIL PROTECTED]> wrote: > Free online resources for learning Python: > > To get started, I strongly suggest Josh Cogliati's "Non-Programmers > Tutorial for Python" ( http://honors.montana.edu/~jjc/easytut/easytut/ > ). > I learned programming with this little tutorial, which

Creating instances of untrusted new-style classes

2006-05-25 Thread Devan L
Is there any safe way to create an instance of an untrusted class without consulting the class in any way? With old-style classes, I can recreate an instance from another one without worrying about malicious code (ignoring, for now, malicious code involving attribute access) as shown below. >>> im

Speed up this code?

2006-05-25 Thread aomighty
I'm creating a program to calculate all primes numbers in a range of 0 to n, where n is whatever the user wants it to be. I've worked out the algorithm and it works perfectly and is pretty fast, but the one thing seriously slowing down the program is the following code: def rmlist(original, deleti

Re: Speed up this code?

2006-05-25 Thread Ben Cartwright
[EMAIL PROTECTED] wrote: > I'm creating a program to calculate all primes numbers in a range of 0 > to n, where n is whatever the user wants it to be. I've worked out the > algorithm and it works perfectly and is pretty fast, but the one thing > seriously slowing down the program is the following c

Re: Speed up this code?

2006-05-25 Thread Tim Chase
> def rmlist(original, deletions): >return [i for i in original if i not in deletions] > > original will be a list of odd numbers and deletions will be numbers > that are not prime, thus this code will return all items in original > that are not in deletions. For n > 100,000 or so, the program

Re: Python Programming Books?

2006-05-25 Thread BartlebyScrivener
>> "Learning to Program" by Alan Gauld >> (http://www.freenetpages.co.uk/hp/alan.gauld/) The best by far, for a n00b, in my opinion. -- http://mail.python.org/mailman/listinfo/python-list

Re: Speed up this code?

2006-05-25 Thread Paul Rubin
[EMAIL PROTECTED] writes: > Does anybody know a faster way to do this? (finding the difference all > items in list a that are not in list b)? >>> a = [3, 7, 16, 1, 2, 19, 13, 4, 0, 8]# random.sample(range(20),10) >>> b = [15, 11, 7, 2, 0, 3, 9, 1, 12, 16] # similar >>> sorted(set

Re: __getattr__ and functions that don't exist

2006-05-25 Thread George Sakkis
Erik Johnson wrote: > Thanks for your reply, Nick. My first thought was "Ahhh, now I see. That's > slick!", but after playing with this a bit... > > >>> class Foo: > ... def __getattr__(self, attr): > ... def intercepted(*args): > ... print "%s%s" % (attr, args) > ...

Re: John Bokma harassment

2006-05-25 Thread Geoffrey Summerhayes
"John Bokma" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Geoffrey Summerhayes" <[EMAIL PROTECTED]> wrote: > >> After you kill Navarth, will it be nothing but gruff and deedle >> with a little wobbly to fill in the chinks? > > Comparing Navarth with Xah is a huge insult to Jack V

Re: John Bokma harassment

2006-05-25 Thread Dražen Gemić
Kay Schluehr wrote: > Sounds like me. In rare moments I believe that I'm not alone on usenet > but there are other people as well. I wanted to go to the doctor > because I believed I had a multiple personality but than I discovered > that the doctor was me too. That's bad, because all of you must

Re: Speed up this code?

2006-05-25 Thread aomighty
I got it working using difference() and sets, thanks all! 100,000 takes about 3 times the time of 10,000, which is what my math buddies told me I should be getting, rather than an exponential increase :). Thanks, all! -- http://mail.python.org/mailman/listinfo/python-list

OLAP and pivot tables

2006-05-25 Thread George Sakkis
After a brief search, I didn't find any python package related to OLAP and pivot tables. Did I miss anything ? To be more precise, I'm not so interested in a full-blown OLAP server with an RDBMS backend, but rather a pythonic API for constructing datacubes in memory, slicing and dicing them, drilli

Array?

2006-05-25 Thread Dr. Pastor
I need a row of 127 bytes that I will use as a circular buffer. Into the bytes (at unspecified times) a mark (0http://mail.python.org/mailman/listinfo/python-list

Re: __getattr__ and functions that don't exist

2006-05-25 Thread Ben Cartwright
Erik Johnson wrote: > Thanks for your reply, Nick. My first thought was "Ahhh, now I see. That's > slick!", but after playing with this a bit... > > >>> class Foo: > ... def __getattr__(self, attr): > ... def intercepted(*args): > ... print "%s%s" % (attr, args) > ...

Re: how to clear up a List in python?

2006-05-25 Thread vbgunz
> I guess Fredrik's message was more along the lines of ``don't try to > "help" others after a week or two toying with the language because you > might be offering disservice, despite your good intentions; leave this > to more experienced users``. The words might have been a bit harsher > but that'

OT: Navarth (was Re: John Bokma harassment)

2006-05-25 Thread John Bokma
"Geoffrey Summerhayes" <[EMAIL PROTECTED]> wrote: > > "John Bokma" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> "Geoffrey Summerhayes" <[EMAIL PROTECTED]> wrote: >> >>> After you kill Navarth, will it be nothing but gruff and deedle >>> with a little wobbly to fill in the chi

Re: Array?

2006-05-25 Thread George Sakkis
Dr. Pastor wrote: > I need a row of 127 bytes that I will use as a > circular buffer. Into the bytes (at unspecified times) > a mark (0 After some time the "buffer" will contain the last 127 marks > and a pointer will point the next "usable" byte. > What would be the Pythonic way to do the above?

monkeypatching NamedTemporaryFile

2006-05-25 Thread Jason Lunz
Is there a better way to do this? def QuietNamedTemporaryFile(**kwargs): ''' Return a NamedTemporaryFile that doesn't complain when its file has already been unlinked at __del__ time. ''' tf = tempfile.NamedTemporaryFile(**kwargs) def quiet_del(): try:

Re: Creating instances of untrusted new-style classes

2006-05-25 Thread Ben Finney
"Devan L" <[EMAIL PROTECTED]> writes: > Is there any safe way to create an instance of an untrusted class Why are you instantiating classes you don't trust? > without consulting the class in any way? If you don't "consult the class", how can the instance be created properly? -- \ "It's

genexp surprise (wart?)

2006-05-25 Thread Paul Rubin
I tried to code the Sieve of Erastosthenes with generators: def sieve_all(n = 100): # yield all primes up to n stream = iter(xrange(2, n)) while True: p = stream.next() yield p # filter out all multiples of p from stream s

Re: Creating instances of untrusted new-style classes

2006-05-25 Thread Devan L
Ben Finney wrote: > "Devan L" <[EMAIL PROTECTED]> writes: > > > Is there any safe way to create an instance of an untrusted class > > Why are you instantiating classes you don't trust? > > > without consulting the class in any way? > If you don't "consult the class", how can the instance be created

Re: Creating instances of untrusted new-style classes

2006-05-25 Thread Michael Spencer
Devan L wrote: > Is there any safe way to create an instance of an untrusted class > without consulting the class in any way? With old-style classes, I can > recreate an instance from another one without worrying about malicious > code (ignoring, for now, malicious code involving attribute access)

Re: Creating instances of untrusted new-style classes

2006-05-25 Thread Devan L
Michael Spencer wrote: > Devan L wrote: > > Is there any safe way to create an instance of an untrusted class > > without consulting the class in any way? With old-style classes, I can > > recreate an instance from another one without worrying about malicious > > code (ignoring, for now, malicious

Re: IronPython 1.0 Beta 7 Released

2006-05-25 Thread Ravi Teja
> > Also, IronPython cannot access CPython libraries. So it cannot be used > > as a drop-in replacement for CPython in most non-trivial apps. Python > > for .NET however allows you to both use both CPython and .NET > > libraries. > > It will be able to access the standard libraries, as long as they

Re: IronPython 1.0 Beta 7 Released

2006-05-25 Thread Ravi Teja
> Can you recommend a book or a link for a person learning Python on > Windows who does not yet know C# or .NET? Since Python is cross-platform, any Python book will do. If you need to do MS Windows specific programming (COM and OLE automation, Windows Services etc), you can use Mark Hammond's "Py

Re: genexp surprise (wart?)

2006-05-25 Thread Ben Cartwright
Paul Rubin wrote: > I tried to code the Sieve of Erastosthenes with generators: > > def sieve_all(n = 100): > # yield all primes up to n > stream = iter(xrange(2, n)) > while True: > p = stream.next() > yield p > # filter out all multi

Can any body help me

2006-05-25 Thread satish
how to write script for these 1.Given a test file containing lines of words such as (abc, abb, abd,abb, etc), write a script that prints, in order of frequency, how many times each word appears in the file. 2. Write a script running in an endless loop that pings an IP (specified on the command li

Re: can't figure out error: module has no attribute...

2006-05-25 Thread Tim Roberts
"Chris_147" <[EMAIL PROTECTED]> wrote: >Thanks for the reply. > >you are indeed right, they were included from different places. >from C:\Python24\Lib and D:\mydir > >But the strange thing is: >anywhere on C: the file from C:\Python24\Lib was included. >in D:\mydir the one from that directory >BUT

Re: genexp surprise (wart?)

2006-05-25 Thread Paul Rubin
"Ben Cartwright" <[EMAIL PROTECTED]> writes: > You do realize that you're creating a new level of generator nesting > with each iteration of the while loop, right? You will quickly hit the > maximum recursion limit. Try generating the first 1000 primes. Yes, I know about the generator nesting, t

Re: genexp surprise (wart?)

2006-05-25 Thread Paul Du Bois
The generator is in its own scope. For proof, try accessing q outside the generator. There are two possibilities. The first is that you don't know what closures are and are complaining that python has them. That would be amusingly ironic, but I'm guessing you do know (if you don't, google "make_ad

Re: genexp surprise (wart?)

2006-05-25 Thread Paul Rubin
Paul Rubin writes: > Yeah, it's just counterintuitive is all. I guess the natural way to > express this would have been with tail recursion instead of a while > loop. FWIW, here's a listcomp version: def s2(n=100): stream = range(2,n) while stream:

Re: Can any body help me

2006-05-25 Thread Sidd
1.Given a test file containing lines of words such as (abc, abb, abd,abb, etc), write a script that prints, in order of frequency, how many times each word appears in the file. Use dictionary datastructure in python and simple if-else statement. Its simple give it a try. -- http://mail.python.or

<    1   2