Re: Dispatch with multiple inheritance

2006-07-19 Thread Michael Spencer
Michael J. Fromberger wrote: ... > > Of course, I could just bypass super, and explicitly invoke them as: > > C.__init__(self, ...) > D.__init__(self, ...) > > ... but that seems to me to defeat the purpose of having super in the > first place. As others have pointed out, super, is designe

Re: Optimizing Inner Loop Copy

2006-08-17 Thread Michael Spencer
Mark E. Fenner wrote: > > and the copy is taking the majority (42%) of my execution time. > So, I'd like to speed up my copy. I had an explicit copy method that did > what was needed and returned a new object, but this was quite a bit slower > than using the standard lib copy.copy(). > How are

Re: Optimizing Inner Loop Copy

2006-08-17 Thread Michael Spencer
Mark E. Fenner wrote: > Michael Spencer wrote: > >> Mark E. Fenner wrote: >> >>> and the copy is taking the majority (42%) of my execution time. >>> So, I'd like to speed up my copy. I had an explicit copy method that did >>> what was needed a

ANN compiler2 : Produce bytecode from Python 2.5 Abstract Syntax Trees

2006-10-19 Thread Michael Spencer
Announcing: compiler2 - For all you bytecode enthusiasts: 'compiler2' is an alternative to the standard library 'compiler' package, with several advantages. Improved pure-python compiler - Produces identical bytecode* to the built-in compile function for all /Lib and L

Re: ANN compiler2 : Produce bytecode from Python 2.5 Abstract Syntax Trees

2006-10-23 Thread Michael Spencer
Georg Brandl wrote: > Michael Spencer wrote: >> Announcing: compiler2 >> - >> >> For all you bytecode enthusiasts: 'compiler2' is an alternative to the >> standard >> library 'compiler' package, with several adva

Re: ANN compiler2 : Produce bytecode from Python 2.5 Abstract Syntax Trees

2006-10-24 Thread Michael Spencer
Paul Boddie wrote: > Martin v. Löwis wrote: ...The compiler package is largely unmaintained and >> was known to be broken (and perhaps still is). > > I don't agree entirely with the "broken" assessment. Although I'm not > chasing the latest language constructs, the AST construction part of > the p

Re: ANN compiler2 : Produce bytecode from Python 2.5 Abstract Syntax Trees

2006-10-24 Thread Michael Spencer
Martin v. Löwis wrote: > Georg Brandl schrieb: >> Perhaps you can bring up a discussion on python-dev about your improvements >> and how they could be integrated into the standard library... > > Let me second this. The compiler package is largely unmaintained and > was known to be broken (and perh

Re: How to identify generator/iterator objects?

2006-10-25 Thread Michael Spencer
Kenneth McDonald wrote: > I'm trying to write a 'flatten' generator which, when give a > generator/iterator that can yield iterators, generators, and other data > types, will 'flatten' everything so that it in turns yields stuff by > simply yielding the instances of other types, and recursively

Re: Running code on assignment/binding

2006-06-20 Thread Michael Spencer
David Hirschfield wrote: > Another deep python question...is it possible to have code run whenever > a particular object is assigned to a variable (bound to a variable)? > > So, for example, I want the string "assignment made" to print out > whenever my class "Test" is assigned to a variable: >

Re: Getting external name of passed variable

2006-06-20 Thread Michael Spencer
David Hirschfield wrote: > I'm not sure this is possible, but it sure would help me if I could do it. > > Can a function learn the name of the variable that the caller used to > pass it a value? For example: > > def test(x): > print x > > val = 100 > test(val) > > Is it possible for function

Remembering History in code.InteractiveConsole

2006-07-09 Thread Chris Spencer
I'd like to make code.InteractiveConsole function just like the normal Python console. However, when I try to use the arrow keys to recall command history, all I get is ^[[A^[[B. I've seen the example at http://docs.python.org/lib/readline-example.html but this doesn't seem to work at all, altho

Re: replace deepest level of nested list

2006-09-05 Thread Michael Spencer
David Isaac wrote: > Thanks to both Roberto and George. > I had considered the recursive solution > but was worried about its efficiency. > I had not seen how to implement the numpy > solution, which looks pretty nice. > > Thanks! > Alan > > You could also use pyarray, which mimics numpy's index

Re: Refactor a buffered class...

2006-09-06 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > Hello, > > i'm looking for this behaviour and i write a piece of code which works, > but it looks odd to me. can someone help me to refactor it ? > > i would like to walk across a list of items by series of N (N=3 below) > of these. i had explicit mark of end of a seque

Re: Refactor a buffered class...

2006-09-06 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > actually for the example i have used only one sentry condition by they > are more numerous and complex, also i need to work on a huge amount on > data (each word are a line with many features readed from a file) An open (text) file is a line-based iterator that can be fed

Re: Refactor a buffered class...

2006-09-06 Thread Michael Spencer
George Sakkis wrote: > Michael Spencer wrote: > >> Here's a small update to the generator that allows optional handling of the >> head >> and the tail: >> >> def chunker(s, chunk_size=3, sentry=".", keep_first = False, keep_last = >>

Re: Refactor a buffered class...

2006-09-07 Thread Michael Spencer
George Sakkis wrote: > Michael Spencer wrote: >> George Sakkis wrote: >>> Michael Spencer wrote: >>> >>>> def chunker(s, chunk_size=3, sentry=".", keep_first = False, keep_last = >>>> False): >>>> buffer=[] >

Re: Slicing / subsetting list in arbitrary fashion

2006-11-17 Thread Michael Spencer
Gregg Lind wrote: > I wish something like this was part of the standard python installation, > and didn't require one to use Numpy or Numarray. This sort of list > subsetting is useful in many, many contexts. > Many of numpy's multi-dimensional slicing and indexing operations are implemented

Re: Defining classes

2006-12-13 Thread Michael Spencer
Nick Maclaren wrote: > > Well, I am already doing that, and regretting the fact that Python > doesn't seem to allow a class instantiation to return a new class :-) > >>> class Fake(object): ... def __new__(cls): ... return 42 ... >>> Fake() 42 >>> "instantiation" (i.e.

Re: Iterating over several lists at once

2006-12-13 Thread Michael Spencer
John Henry wrote: > Carl Banks wrote: > >> The function can be extended to allow arbitrary arguments. Here's a >> non-minmal recursive version. >> >> def cartesian_product(*args): >> if len(args) > 1: >> for item in args[0]: >> for rest in cartesian_product(*args[1:]): >>

Re: python poetry?

2006-12-19 Thread Michael Spencer
BartlebyScrivener wrote: > Python pseudo code limericks anywhere? I wrote the following in response to Steve Holden's limerick challenge a couple of years ago: # run me or voice the alphanumeric tokens from itertools import repeat for feet in [3,3,2,2,3]: print " ".join("DA-DA-DUM"

Re: generating method names 'dynamically'

2006-01-26 Thread Michael Spencer
Daniel Nogradi wrote: ... > - database content --- > > Alice 25 > Bob 24 > > - program1.py - > > class klass: ... > > inst = klass() > > - program2.py --- > > import program1 > > # The code in klass above should be such that the following

Re: Using bytecode, not code objects

2006-01-29 Thread Michael Spencer
Fredrik Lundh wrote: > Fabiano Sidler wrote: > >> I'm looking for a way to compile python source to bytecode instead of >> code-objects. Is there a possibility to do that? The reason is: I want >> to store pure bytecode with no additional data. > > use marshal. > >> The second question is, there

Re: Print dict in sorted order

2006-01-29 Thread Michael Spencer
Raymond Hettinger wrote: >> from itertools import count, izip >> >> def dict2str(d, preferred_order = ['gid', 'type', 'parent', 'name']): >> last = len(preferred_order) >> rank = dict(izip(preferred_order, count())) >> pairs = d.items() >> pairs.sort(key=lambda (k,v): rank.get(k, (l

Re: Having Trouble with Scoping Rules

2006-01-30 Thread Michael Spencer
Charles Krug wrote: > List: > ... > # expensive Object Module > > _expensiveObject = None > def ExpensiveObject(): > > if not(_expensiveObject): > _expensiveObject = "A VERY Expensive object" > > return _expensiveObject > ... > I obviously missed some part of the scoping rules.

Re: Global variables, Classes, inheritance

2006-02-03 Thread Michael Spencer
DaveM wrote: > Although I've programmed for fun - on and off - since the mid 70's, I'm > definitely an OO (and specifically Python) beginner. > > My first question is about global variables. Are they, as I'm starting to > suspect, a sin against God or just best avoided? Having got my current > ap

what's wrong with my popen reasoning?

2006-02-05 Thread Rick Spencer
Hi all, I am very new to Python programming. I am writing a program to manage wireless connections, this is for GNOME on Linux. I present the user with a "connect" button. I want to handle the connection for them slightly different depending on whether or not the wireless access point they are try

Re: what's wrong with my popen reasoning?

2006-02-05 Thread Rick Spencer
On Sun, 05 Feb 2006 10:39:18 -0800, Rick Spencer wrote: >I just want to fire > off the command line utility (iwconfig) for connecting. In this case, I > want my program to wait until iwconfig is done before continuing on. I > figure that I could just write a line of code to read

Re: A __getattr__ for class methods?

2006-02-08 Thread Michael Spencer
Dylan Moreland wrote: > I'm trying to implement a bunch of class methods in an ORM object in > order to provide functionality similar to Rails' ActiveRecord. This > means that if I have an SQL table mapped to the class "Person" with > columns name, city, and email, I can have class methods such as:

Re: Pulling all n-sized combinations from a list

2006-02-08 Thread Michael Spencer
Swroteb wrote: > Paul Rubin wrote: >> I think the natural approach is to make a generator that yields a >> 5-tuple for each combination, and then have your application iterate >> over that generator. Here's my version: >> >> def comb(x,n): >> """Generate combinations of n items from li

Re: random playing soundfiles according to rating.

2006-02-08 Thread Michael Spencer
[EMAIL PROTECTED] wrote: ... > > But i am stuck on how to do a random chooser that works according to my > idea of choosing according to rating system. It seems to me to be a bit > different that just choosing a weighted choice like so: > ... > > And i am not sure i want to have to go through w

Re: two generators working in tandem

2006-02-11 Thread Michael Spencer
john peter wrote: > I'd like to write two generators: one is a min to max sequence number > generator that > rolls over to min again once the max is reached. the other is a generator > that cycles > through N (say, 12) labels. currently, i'm using these generators in nested > loops like >

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Michael Spencer
Rob Cowie wrote: > I'm having a bit of trouble with this so any help would be gratefully > recieved... > > After splitting up a url I have a string of the form > 'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be > preceeded by an operator if it is a '-', if it is preceded by n

Re: Sequences in list

2005-05-02 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > Hi All, > > I wonder could someone help me with this? > > What I want to do is search through a list of letters and look for > adjacent groups of letters that form sequences, not in the usual way of > matching say abc to another appearance later on in the list but to lo

Re: Sequences in list

2005-05-02 Thread Michael Spencer
Michael Spencer wrote: > > def compare_forms(sequence): > """test whether all groups of a sequence have the same form""" > for length in range(4,2,-1): # look for longest match first oops, make that range(4,1,-1) or, simply (4,3,2) Michael -

Re: Sequences in list

2005-05-03 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > Hi Michael, > > Thanks for a quick response, I appreciate it. I will have to get back > to you tomorrow, as I can't check what you've given me right now. I > presume the fact that you mention the word note in your code you have > realised that I'm trying to search for mu

Re: Sequences in list

2005-05-04 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > Your code will identify sequences in a list, but how to index them? I > have an idea, which seems ridiculously long-winded, but should work. > First, put the groups from the âmake_diffsâ function into a list > and do a search for the sequence identified from the > âcompa

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-04 Thread Michael Spencer
Martijn Pieters wrote: > Dan Christensen wrote: > >> Any hints for level 13? I know how to make a call, but don't know "who" >> to call. > > > I haven't figured this one out yet either. Rather frustrating really. > All the hints I've been given so far is to rmember the solution for > level 12.

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-04 Thread Michael Spencer
Martijn Pieters wrote: > Roel Schroeven wrote: > >> Unless Martijn Pieters here and mjpieters in the Python Challenge forum >> are two differen persons, you've found it in the meantime, haven't you? > > > Yup, I found it. How evil and devious. I found the hint without > Googling, BTW, but can se

Re: News/mail gateway problem? (was Re: UnicodeDecodeError )

2005-05-04 Thread Michael Spencer
John Machin wrote: > On Thu, 5 May 2005 13:00:32 +1200, Thomas Thomas <[EMAIL PROTECTED]> > wrote: > > >>Hi all, >> >>Forgot to mention I am using python 2.3 on windows. >> >> > > > This message (sent to python_list) would seem to be referencing a > previous posting/message -- but it's not show

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-04 Thread Michael Spencer
Dan Bishop wrote: > Martijn Pieters wrote: > >>Martijn Pieters wrote: >> >>>I haven't figured this one out yet either. Rather frustrating > > really. > >>>All the hints I've been given so far is to remember the solution > > for > >>>level 12. >> >>A, that was devious! I found it finally, h

Re: How "return" no return ?

2005-05-12 Thread Michael Spencer
Ximo wrote: > I am doing my own interpreter with the Python languaje. > > Do you understand me? > > > > "Fredrik Lundh" <[EMAIL PROTECTED]> escribió en el mensaje > news:[EMAIL PROTECTED] > >>"Ximo" wrote: >> >> >>>I am doing a interpret of lines and it show me a prompt, and I want if I >>>wr

Re: Safe eval, or how to get list from string

2005-05-13 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > I've to use ConfigParser. > > It returns values that are exactly in the config file, so get string > variables like: > int1 with quotes and characers: "42" > this is easy to convert to int: > realint = int(int1) > > I've read the tutorial, and the FAQ, and not sure if I

Re: metaclass that inherits a class of that metaclass?

2005-06-01 Thread Michael Spencer
ironfroggy wrote: > Hoping this isn't seeming too confusing, but I need to create a > metaclass and a class using that metaclass, such that one of the bases > of the metaclass is the class created with that metaclass. I can't > figure out a way to do this, even after trying to add the class as a >

Re: Performance Issues please help

2005-06-02 Thread Michael Spencer
PyPK wrote: > Yep that improved the speed by about 50% now it takes about 10 secs > instead of 24 seconds..Thanks much. I guess that is the best we could > do right.It would be really helpful if I could get it less than 5 > seconds. Any suggestions on that?? > Things to try: * in-lining the min a

Re: Performance Issues please help

2005-06-02 Thread Michael Spencer
Michael Spencer wrote: > def search1(m): > box = {} > for r,row in enumerate(m): > for c,e in enumerate(row): > try: > minc, minr, maxc, maxr = box[e] > box[e] = ( c < minc and c or minc, >

ElementTree Namespace Prefixes

2005-06-12 Thread Chris Spencer
, which it seems to do correctly for everything except namespace prefixes. The docs mention "proper" output can be achieved by using the Qname object, but they don't go into any detail. Any help is appreciated. Thanks, Chris Spencer -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get/set class attributes in Python

2005-06-12 Thread Chris Spencer
Kalle Anke wrote: > On Sun, 12 Jun 2005 13:59:27 +0200, deelan wrote > (in article <[EMAIL PROTECTED]>): > > void doSomething( data : SomeClass ){ ... } > > and I would be sure at compile time that I would only get SomeClass objects > as parameters into the method. Being an untyped language, Py

Re: ElementTree Namespace Prefixes

2005-06-12 Thread Chris Spencer
Andrew Dalke wrote: > On Sun, 12 Jun 2005 15:06:18 +, Chris Spencer wrote: > > >>Does anyone know how to make ElementTree preserve namespace prefixes in >>parsed xml files? > > > See the recent c.l.python thread titled "ElemenTree and namespaces&q

Re: How to get/set class attributes in Python

2005-06-12 Thread Chris Spencer
Bruno Desthuilliers wrote: > And *this* is highly unpythonic. And un-OO too, since it makes foo() > dependant on *class* Bar, when it should most probably be enough that it > only depends on (probably part of) the *interface* of class Bar. I was providing the original poster with a simple way t

Re: How to get/set class attributes in Python

2005-06-12 Thread Chris Spencer
Bruno Desthuilliers wrote: > Chris Spencer a écrit : > >> I was providing the original poster with a simple way to ensure >> appropriate type. > > > s/appropriate type/specific implementation/ > > Hint : the appropriate type for print &g

Re: How to get/set class attributes in Python

2005-06-12 Thread Chris Spencer
Peter Dembinski wrote: > Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > >>Nope. Python *is* typed. But it doesnt confuse implementation >>with semantic. > > > Python is typed. And its type system may look strange for anyone who > did only Java or C++ programming before :> Of course, in tha

Re: How to get/set class attributes in Python

2005-06-12 Thread Chris Spencer
Peter Dembinski wrote: > Chris Spencer <[EMAIL PROTECTED]> writes: > > >>Peter Dembinski wrote: >> >>Of course, in that Python is dynamically typed as opposed to the >>static typing of Java or C++. Please excuse my previous mis-wording :) > >

Re: searching for IDE

2005-06-12 Thread Chris Spencer
jean-marc wrote: > if you are familiar with eclipse, you could use the PyDev python > plugin. > > jm Thanks for that reference. I had been using SPE for my Python editing, but it's gone unmaintained as of late, so I've been looking for an alternative. Aside from an autocomplete bug (which I've

Re: Flatten a two-level list --> one liner?

2007-03-07 Thread Michael Spencer
Sergio Correia wrote: > spam = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] > > Into something like > eggs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] > > There are *no* special cases (no empty sub-lists). eggs = [i for j in spam for i in j] Michael -- http://mail.python.org/mailman/listinfo/

Re: Signed zeros: is this a bug?

2007-03-11 Thread Michael Spencer
Gabriel Genellina wrote: > > (I cannot find peephole.c on the source distribution for Python 2.5, but > you menctioned it on a previous message, and the comment above refers to > the peephole optimizer... where is it?) > The peephole optimizer is in compile.c - the entry point is optimize_c

Re: To count number of quadruplets with sum = 0

2007-03-15 Thread Michael Spencer
n00m wrote: > http://www.spoj.pl/problems/SUMFOUR/ > > 3 > 0 0 0 0 > 0 0 0 0 > -1 -1 1 1 > Answer for this input data is 33. > > My solution for the problem is > == > > import time > t = time.clock() > > q,w,e,r,sch,h = [],[],[

Re: challenge ?

2007-03-22 Thread Michael Spencer
alain wrote: > I have a problem I wonder if it has been solved before. > I have a dictionnary and I want the values in the dictionnary to be > annotated with the rank that would be obtained by sorting the values > > def annotate_with_rank(my_dict): > > return my_annotated_dict >

Re: manually implementing staticmethod()?

2007-03-28 Thread Michael Spencer
"7stud" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > Can someone show me how to manually implement staticmethod()? Here is > my latest attempt: > Raymond Hettinger can: http://users.rcn.com/python/download/Descriptor.htm#static-methods-and-class-methods

Re: Problem with filter()

2007-04-03 Thread Michael Spencer
Boudreau, Emile wrote: > Hey all, > So I'm trying to filter a list with the built-in function > filter(). My list looks something like this: > ['logs', 'rqp-8.2.104.0.dep', 'rqp-8.2.93.0.dep', > 'rqp-win32-app-8.2.96.0-inst.tar.gz', 'rqp-win32-app-8.2.96.0-inst.tar.gz'] > > Calling filte

Re: subclass of integers

2007-09-14 Thread Michael Spencer
Mark Morss wrote: > I would like to construct a class that includes both the integers and > None. I desire that if x and y are elements of this class, and both > are integers, then arithmetic operations between them, such as x+y, > return the same result as integer addition. However if either x o

Re: I could use some help making this Python code run faster using only Python code.

2007-09-20 Thread Michael Spencer
Python Maniac wrote: > I am new to Python however I would like some feedback from those who > know more about Python than I do at this time. > > def scrambleLine(line): > s = '' > for c in line: > s += chr(ord(c) | 0x80) > return s > > def descrambleLine(line): > s = '' >

Re: module confusion

2007-10-03 Thread Michael Spencer
+1 Subject line of the week (SLOTW) rjcarr wrote: > So my question is ... why are they [os.path and logging.handlers] different? [A] wrote: > Because you misspelled it. First, do a dir() on logging: [B] wrote: > No, he didn't... OP: logging is a package and logging.handlers is one module > in t

Re: Dynamically creating class properties

2007-10-04 Thread Michael Spencer
Karlo Lozovina wrote: > > Any idea how to do that with metaclasses and arbitrary long list of > attributes? I just started working with them, and it's driving me nuts :). > > Thanks for the help, > best regards. > Try implementing a property factory function before worrying about the metaclas

Re: Convert obejct string repr to actual object

2007-10-08 Thread Michael Spencer
Tor Erik Sønvisen wrote: > Hi, > > I've tried locating some code that can recreate an object from it's > string representation... > The object in question is really a dictionary containing other > dictionaries, lists, unicode strings, floats, ints, None, and > booleans. > > I don't want to use ev

Re: Overloading assignment operator

2007-01-29 Thread Michael Spencer
J. Clifford Dyer wrote: > I think that's the first time I've actually seen someone use a Monty > Python theme for a python example, and I must say, I like it. However, > "We are all out of Wensleydale." > > Cheers, > Cliff Oh, then you clearly don't waste nearly enough time on this newsgroup ;

Re: Python Source Code Beautifier

2007-02-27 Thread Michael Spencer
Franz Steinhaeusler wrote: > Use Spaces, size: 4 > detect mixed line ending > detect tabs mixed with space > trim trailing whitespaces. look at: tools/scripts/reindent.py > convert structs like: if (a > b): to if a > b: > fill in spaces, but not in functions between operators: > > a+=1 =>

Re: Interfaces to high-volume discussion forums

2007-11-30 Thread Michael Spencer
Ben Finney wrote: > > I'm not interested in learning some centralised web-application > interface, and far prefer the discussion forum to be available by a > standard *protocol*, that I can use my choice of *local client* > application with. > I agree: I use Thunderbird, and it works well. But

Re: Interfaces to high-volume discussion forums

2007-12-01 Thread Michael Spencer
Dennis Lee Bieber wrote: > On Fri, 30 Nov 2007 11:36:44 -0800, Michael Spencer >> >> Can anyone recommend a solution that also synchronizes post read status? If >> Google Reader or something like it handled NNTP, I imagine I'd use it to >> achieve >>

Re: converting to and from octal escaped UTF--8

2007-12-02 Thread Michael Spencer
Michael Goerz wrote: > Hi, > > I am writing unicode stings into a special text file that requires to > have non-ascii characters as as octal-escaped UTF-8 codes. > > For example, the letter "Í" (latin capital I with acute, code point 205) > would come out as "\303\215". > > I will also have to r

Re: Why Python 3?

2007-12-05 Thread Michael Spencer
Kay Schluehr wrote: > > This unexpected attack in his rear frightened him so much, that he > leaped forward with all his might: the horse's carcase dropped on the > ground, but in his place the wolf was in the harness, and I on my part > whipping him continually: we both arrived in full career saf

Re: Problem with generator expression and class definition

2007-12-07 Thread Michael Spencer
Terry Reedy wrote: > "Maric Michaud" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > |I faced a strange behavior with generator expression, which seems like a > bug, for both > | python 2.4 and 2.5 : > > Including the latest release (2.5.2)? > > | >>> class A : > | ... a = 1

Re: How does python build its AST

2007-12-07 Thread Michael Spencer
MonkeeSage wrote: > A quick question about how python parses a file into compiled > bytecode. Does it parse the whole file into AST first and then compile > the AST, or does it build and compile the AST on the fly as it reads > expressions? (If the former case, why can't functions be called before

Re: 5 queens

2007-12-22 Thread Michael Spencer
cf29 wrote: > Greetings, > > I designed in JavaScript a small program on my website called 5 > queens. .. Has anyone tried to do a such script? If anyone is > interested to help I can show what I've done so far. Tim Peters has a solution to 8 queens in test_generators in the standard library

Re: temporary scope change

2006-04-18 Thread Michael Spencer
Edward Elliott wrote: ... > > for x in list1: > i += 1 > # for y in list2: > print x * i > > and have the print line execute as part of the for x block. In other > words, I want the block with print to be in the scope of the for x loop. > But instead it raises a SyntaxError bec

Re: How to create a dictionary from a string?

2006-04-21 Thread Michael Spencer
Clodoaldo Pinto wrote: > Is there a simple way to build a dictionary from a string without using > eval()? > s = '{"a":1}' d = eval(s) d > {'a': 1} > > Regards, Clodoaldo Pinto > Here is a discussion about one way to do it: http://tinyurl.com/o8mmm HTH Michael -- http://mail.p

Re: String To Dict Problem

2006-04-21 Thread Michael Spencer
Clodoaldo Pinto wrote: > Michael Spencer wrote: > >> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469 > > Very nice work. It will be very useful. Thanks. > > Only a small problem when I try to evaluate this: > > safe_eval('True') > >

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-21 Thread Michael Spencer
Anthony Liu wrote: > I am at my wit's end. > > I want to generate a certain number of random numbers. > This is easy, I can repeatedly do uniform(0, 1) for > example. > > But, I want the random numbers just generated sum up > to 1 . > > I am not sure how to do this. Any idea? Thanks. > > __

Re: Classic class conversion

2006-04-24 Thread Michael Spencer
Kay Schluehr wrote: > Just reasoning about conversion of classic to new style classes ( > keeping deprecation of ClCl in Py3K in mind ) I wonder if there is a > metaclass that can be used to express the semantics of ClCl in terms of > new style classes? Intuitively I would expect that there is quit

Re: Editing a function in-memory and in-place

2006-04-27 Thread Michael Spencer
Ian Bicking wrote: > I got a puzzler for y'all. I want to allow the editing of functions > in-place. I won't go into the reason (it's for HTConsole -- > http://blog.ianbicking.org/introducing-htconsole.html), except that I > really want to edit it all in-process and in-memory. So I want the > id

Re: How to add columns to python arrays

2006-05-17 Thread Michael Spencer
Terry Reedy wrote: > "CC" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> I wanna compile a 6000x1000 array with python. The array starts from >> 'empty', each time I get a 6000 length list, I wanna add it to the >> exist array as a column vector. Is there any function to do so? >

Re: How to add columns to python arrays

2006-05-17 Thread Michael Spencer
Terry Reedy wrote: > "Michael Spencer" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> If you're just looking for a multi-dimensional array type, and don't need >> maximum speed or the vast range of array-processing that numpy offers,

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: Why does list have no 'get' method?

2008-02-07 Thread Michael Spencer
Wildemar Wildenburger wrote: > Arnaud Delobelle wrote: >> Personally, between >> >> * foo if foo else bar >> * foo or bar >> >> I prefer the second. Maybe it could be spelt >> >> * foo else bar ? >> > How about > > val = foo rather than bar > > If that is not clear and obvios, I don't know what i

Re: which one is more efficient

2008-02-08 Thread Michael Spencer
ki lo wrote: > I have type variable which may have been set to 'D' or 'E' > > Now, which one of following statements are more efficient > > if type =='D' or type == 'E': > > or > > if re.search("D|E", type): > > Please let me know because the function is going to called 10s of > millions of t

Re: sort functions in python

2008-02-08 Thread Michael Spencer
t3chn0n3rd wrote: > Do you think it is relatively easy to write sort algorithms such as > the common Bubble sort in Python as compared to other high level > programming langauges yes -- http://mail.python.org/mailman/listinfo/python-list

Re: [Py2exe-users] py2exe 0.6.9 released

2008-11-16 Thread Chris Spencer
After I "compile" my program with py2exe 0.6.9 with Python 2.6, I'm still getting the "Application Did Not Initialize Properly" error dialog whenever I run my code. What am I doing wrong? Note that py2exe 0.6.9 with Python 2.5 works just fine. Help! Chris. On Sat, 15 Nov 2008 23:21:15 -0800,

Re: having a function called after the constructor/__init__ is done

2009-03-16 Thread Michael Spencer
thomas.han...@gmail.com wrote: ... So any ideas on how to get a function called on an object just after __init__ is done executing? -- http://mail.python.org/mailman/listinfo/python-list Yes, you *can* use metaclasses - you need to override the type.__call__ method, which is what normally ca

Re: get rid of duplicate elements in list without set

2009-03-20 Thread Michael Spencer
Alexzive wrote: Hello there, I'd like to get the same result of set() but getting an indexable object. How to get this in an efficient way? Example using set A = [1, 2, 2 ,2 , 3 ,4] B= set(A) B = ([1, 2, 3, 4]) B[2] TypeError: unindexable object Many thanks, alex -- http://mail.python.org/m

Re: efficiently checking for string.maketrans conflicts?

2009-04-20 Thread Michael Spencer
Saketh wrote: Hi everyone: I'm using "translation" in the sense of string.maketrans here. I am trying to efficiently compare if two string translations "conflict" -- that is, either they differently translate the same letter, or they translate two different letters to the same one. ... Anoth

Re: generating random tuples in python

2009-04-22 Thread Michael Spencer
Robert Kern wrote: On 2009-04-20 23:04, per wrote: to be more formal by very different, i would be happy if they were maximally distant in ordinary euclidean space... so if you just plot the 3-tuples on x, y, z i want them to all be very different from each other. i realize this is obviously b

Re: efficiently checking for string.maketrans conflicts?

2009-04-22 Thread Michael Spencer
Saketh wrote: Thank you, Peter and Michael, for your solutions! I think that Michael's is what I was edging towards, but Peter's has demonstrated to me how efficient Python's set functions are. I have a lot more to learn about optimizing algorithms in Python... :) -- http://mail.python.org/mail

Re: list comprehension question

2009-04-30 Thread Michael Spencer
Ross wrote: If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to return a new list of each individual element in these tuples, I can do it with a nested for loop but when I try to do it using the list comprehension b = [j for j in i for i in a], my output is b = [5,5,5,6,6,6] inste

Re: reshape a list?

2006-03-06 Thread Michael Spencer
Robert Kern wrote: > KraftDiner wrote: >> I have a list that starts out as a two dimensional list >> I convert it to a 1D list by: >> >> b = sum(a, []) >> >> any idea how I can take be and convert it back to a 2D list? > > Alternatively, you could use real multidimensional arrays instead of fakin

Re: reshape an array?

2006-03-08 Thread Michael Spencer
KraftDiner wrote: > I have a 2D array. Say it is 10x10 and I want a 1D Array of 100 > elements... > What is the syntax? > > oneD = reshape(twoD, (100,1)) > or > oneD = reshape(twoD, (1,100)) > > One I guess is the transpose of the other but both seem to be > arrays of arrays... > > help?! > Us

Re: Best way to have a for-loop index?

2006-03-09 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > I write a lot of code that looks like this: > > for myElement, elementIndex in zip( elementList, > range(len(elementList))): > print "myElement ", myElement, " at index: ",elementIndex > > > My question is, is there a better, cleaner, or easier way to get at the >

Re: Dictionary project

2006-03-11 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > Hi All, > First, I hope this post isn't against list rules; if so, I'll take note in > the future. > > I'm working on a project for school (it's not homework; just for fun). > For it, I need to make a list of words, starting with 1 character in length, > up to 15 or so.

Re: Dictionary project

2006-03-11 Thread Michael Spencer
> [EMAIL PROTECTED] wrote: ... >> I'm working on a project for school (it's not homework; just for fun). >> For it, I need to make a list of words, starting with 1 character in length, >> up to 15 or so. >> It would look like: >> >> A B C d E F G ... Z Aa Ab Ac Ad Ae Aaa Aab Aac ... >> If there is

Re: Printable string for 'self'

2006-03-14 Thread Michael Spencer
Don Taylor wrote: > Is there a way to discover the original string form of the instance that > is represented by self in a method? > > For example, if I have: > > fred = C() > fred.meth(27) > > then I would like meth to be able to print something like: > > about to call meth(

Re: Newbie Class/Counter question

2006-03-14 Thread Michael Spencer
ProvoWallis wrote: > > My document looks like this > > A. Title Text > 1. Title Text > 1. Title Text > 1. Title Text > B. Title Text > 1. Title Text > 1. Title Text > > but I want to change the numbering of the second level to sequential > numbers like 1, 2, 3, etc. so my output would look like

Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-16 Thread Michael Spencer
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > >> The problem I'm trying to solve is. >> There is a 5x5 grid. >> You need to fit 5 queens on the board such that when placed there are >> three spots left that are not threatened by the queen. > > when you're done with your homework (?), you can

<    1   2   3   4   5   >