Eval (was Re: Question about using python as a scripting language)

2006-08-09 Thread Brendon Towle
this is from memory, and the code actually works.)My question is: what's the safe way to do this?B. -- Brendon Towle, PhDCognitive Scientist+1-412-690-2442x127Carnegie Learning, Inc.The Cognitive Tutor Company ®Helping over 375,000 students in 1000 school districts succeed in math. -- http://mail.python.org/mailman/listinfo/python-list

Re: Eval (was Re: Question about using python as a scripting language)

2006-08-09 Thread Brendon Towle
ke the re.* trick mentioned by another poster. But, doesn't it offend anyone else that the only clean way to access functionality that's already in Python is to write long complicated Python code? Python already knows how to extract a list object from a string; why should I have to rewr

Re: Eval (was Re: Question about using python as a scripting language)

2006-08-09 Thread Brendon Towle
t object; it's a string of bytes that happens to be syntactically identical to the definition of a list in python code. I was hoping for a clean and safe way to exploit that identical-ness; apparently, all the clean ways are unsafe, and all the safe ways are unclean.B. -- Brendon Towle,

Re: Eval (was Re: Question about using python as a scripting language)

2006-08-10 Thread Brendon Towle
posted a great piece of code to parse a subset of pythonsafely:http://groups.google.ca/group/comp.lang.python/browse_frm/thread/8e427c5e6da35c/a34397ba74892b4eThis, as it turns out, was the most helpful pointer of them all -- thanks!B. -- Brendon Towle, PhDCognitive Scientist+1-412-690-2442x127Carn

Re: Python-list Digest, Vol 35, Issue 160

2006-08-10 Thread Brendon Towle
Date: Thu, 10 Aug 2006 08:51:12 -0400From: Brendon Towle <[EMAIL PROTECTED]>Subject: Re: Eval (was Re: Question about using python as a scripting language) Date: 9 Aug 2006 14:12:01 -0700From: "Simon Forman" <[EMAIL PROTECTED]>Subject: Re: Eval (was Re: Question about using

Re: Eval (was Re: Question about the use of python as a scripting language)

2006-08-10 Thread Brendon Towle
ld people expect this code to be safe:START_MARKER = 'var table_body = 'END_MARKER = '];'    def extractStockData(data):    pos1 = data.find(START_MARKER)    pos2 = data.find(END_MARKER, pos1)    parenPos = data.find('(')    if parenPos >= 0:        raise "Data format cha

Re: Eval (was Re: Question about the use of python as a scripting language)

2006-08-10 Thread Brendon Towle
rt the class -- in this case, I'm screwed long before I call eval().2. Include it in the page I downloaded -- in this case, the function calls will be part of the string, and the data.pos('(') call will find them.Am I missing a third option? B.-- Brendon Towle, PhDCognitive Scient

Re: List Splitting

2006-08-21 Thread Brendon Towle
...        temp.append(t[3*y+x])...    outlist.append(temp)>>>outlist[['a', 'n', 't'], ['b', 'a', 't'], ['c', 'a', 't']] -- Brendon Towle, PhDCognitive Scientist+1-412-690-2442x127Carnegie Learning, Inc.The Cognitive Tutor Company ®Helping over 375,000 students in 1000 school districts succeed in math. -- http://mail.python.org/mailman/listinfo/python-list

Re: Consistency in Python

2006-08-25 Thread Brendon Towle
 lst.append(INVARIANT)    lst.sort()    return lst[:n]So, my question is: Someone obviously thought that it was wise and proper to require the longer versions that I write above. Why?B. -- Brendon Towle, PhDCognitive Scientist+1-412-690-2442x127Carnegie Learning, Inc.The Cognitive Tutor Company

Re: Consistency in Python

2006-08-25 Thread Brendon Towle
Message: 3 Date: Fri, 25 Aug 2006 15:28:46 +0200 From: "Fredrik Lundh" <[EMAIL PROTECTED]> Subject: Re: Consistency in Python Brendon Towle wrote: So, my question is: Someone obviously thought that it was wise and proper to require the longer versions that I write above. Why? a

Re: sending emails using python

2006-09-07 Thread Brendon Towle
lib.SMTP(host) if auth: server.login('username', 'password') outMessage = 'From: %s\rTo: %s\rSubject: %s\r%s' % (FROM_HEADER, TO_HEADER, subject, body) server.sendmail(fromAddr, toAddr, outMessage) If this doesn't wo

Random Drawing Simulation -- performance issue

2006-09-12 Thread Brendon Towle
""" res = [[0, item[1]] for item in population] mapping = [] for i in xrange(len(population)): mapping.extend([i]*population[i][0]) for i in xrange(count): index = random.choice(mapping) res[index][0] += 1 return res

Re: Random Drawing Simulation -- performance issue

2006-09-13 Thread Brendon Towle
On 12 Sep 2006, at 6:33 PM, [EMAIL PROTECTED] wrote: > Date: 12 Sep 2006 15:23:51 -0700 > From: "Simon Forman" <[EMAIL PROTECTED]> > Subject: Re: Random Drawing Simulation -- performance issue > > Brendon Towle wrote: >> I need to simulate scenarios like th

Re: Random Drawing Simulation -- performance issue

2006-09-13 Thread Brendon Towle
vals is a sequence of probabilities that should sum to 1 > (however, the > last element is always assumed to account for the remaining > probability > as long as sum(pvals[:-1]) <= 1). Here, I'm torn. I do want the code to be accessible to non-stats people

Python API to OS X Address Book?

2006-09-25 Thread Brendon Towle
Essentially, I'm looking for a Python equivalent to the ObjectiveC stuff that can be found at: http://developer.apple.com/documentation/UserExperience/Conceptual/AddressBook/index.html Google got me that far, but was not particularly helpful past that. Anyone have any pointers? B. -- http:

Re: Questions on Using Python to Teach Data Structures and Algorithms

2006-09-28 Thread Brendon Towle
return structure[1] should be: return structure[1:] B. -- Brendon Towle, Ph.D. <[EMAIL PROTECTED]> +1-412-362-1530 “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart

Re: Questions on Using Python to Teach Data Structures and Algorithms

2006-09-28 Thread Brendon Towle
On 28 Sep 2006, at 8:05 AM, [EMAIL PROTECTED] wrote: > From: Bruno Desthuilliers <[EMAIL PROTECTED]> > Subject: Re: Questions on Using Python to Teach Data Structures and > Algorithms > To: python-list@python.org > > Brendon Towle wrote: >> Some of your Li

Re: Questions on Using Python to Teach Data Structures and Algorithms

2006-09-28 Thread Brendon Towle
s of the "Why don't destructive sequence operations return the sequence?" thread.) I think I'd probably prefer: def cons(a,b): res = [a] res.extend(b) return res because cons is supposed to leave its second argument untouched. B. -- Brendon Towle, PhD Cog