PyLint syntax question

2006-11-29 Thread Brendon
Hi,

This may seem like a stupid question, but I'd like to know anyway.  How
do I used pylint's --ignore option to prevent it from looking at some
files?  The documentation says you have to use a base name.  What the
heck is a base name?

Are there any other ways to stop it looking at certain files?  At the
moment I'm trying to get it to avoid the ones that contain 'import wx'.


Thanks,
Brendon

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


Python dict as unicode

2010-11-24 Thread Brendon
Hi all,

I am trying to convert a dictionary to a unicode string and it fails
with an exception. I am awfully surprised but searching the web has
not turned up anything useful. I understand why the exception ocurrs,
but am not sure why this is the default behaviour of python and if
there is anything I can do to fix the problem.

I have a python dictionary:
d = { ..}

It contains both primitive and complex objects. I want a unicode
representation of that dict:
s = unicode(d)

Doing this I get an exception:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position
71: ordinal not in range(128)

Now, it seems that unicode(d) is the same as unicode(str(d)). I was
expecting there to be a __unicode__ method in the dictionary that in
turn calls unicode() on each of the keys/values in the dict, but
apparently not. Instead it seems to call the equivalent of str() on
each key/value and then after adding them together, calls unicode() on
the resulting string.

Is this really the default behaviour? If so is there any way around
it?

I am using python 2.6.6 on a Linux system.
-- 
http://mail.python.org/mailman/listinfo/python-list


[no subject]

2012-02-28 Thread Brendon Joyce

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


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

2006-08-09 Thread Brendon Towle
Slawomir Nowaczyk noted:#> Heck, whenever *is* it OK to use eval() then?eval is like optimisation. There are two rules:Rule 1: Do not use it.Rule 2 (for experts only): Do not use it (yet).So, that brings up a question I have. I have some code that goes out to a website, grabs stock data, and sends out some reports based on the data.Turns out that the website in question stores its data in the format of a Python list (http://quotes.nasdaq.com/quote.dll?page=nasdaq100, search the source for "var table_body"). So, the part of my code that extracts the data looks something like this:    START_MARKER = 'var table_body = '    END_MARKER = '];'    def extractStockData(data):    pos1 = data.find(START_MARKER)    pos2 = data.find(END_MARKER, pos1)    return eval(data[pos1+len(START_MARKER):END_MARKER])(I may have an off-by-one error in there somewhere -- 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
On 9 Aug 2006, at 11:04 AM, Chris Lambacher wrote:How is your data stored? (site was not loading for me).In the original source HTML, it's like this (I've deleted all but the beginning and the end of the list for clarity):var table_body = [["ATVI", "Activision, Inc.",12.75,0.15,1.19,2013762,0.04,"N","N"],["YHOO", "Yahoo! Inc.",27.7,0.26,0.95,6348884,0.21,"N","N"]];More sophisiticated situations (like nested lists) may require something like pyparsing.I could do that, or I could do something like 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 rewrite that?B.On Wed, Aug 09, 2006 at 10:23:49AM -0400, Brendon Towle wrote:    Slawomir Nowaczyk noted:     #> Heck, whenever *is* it OK to use eval() then?     eval is like optimisation. There are two rules:     Rule 1: Do not use it.     Rule 2 (for experts only): Do not use it (yet).   So, that brings up a question I have. I have some code that goes out to a   website, grabs stock data, and sends out some reports based on the data.   Turns out that the website in question stores its data in the format of a   Python list ([1]http://quotes.nasdaq.com/quote.dll?page=nasdaq100, search   the source for "var table_body"). So, the part of my code that extracts   the data looks something like this:       START_MARKER = 'var table_body = '       END_MARKER = '];'   def extractStockData(data):       pos1 = data.find(START_MARKER)       pos2 = data.find(END_MARKER, pos1)       return eval(data[pos1+len(START_MARKER):END_MARKER])   (I may have an off-by-one error in there somewhere -- this is from memory,   and the code actually works.)   My question is: what's the safe way to do this?   B.   --   Brendon Towle, PhD   Cognitive Scientist   +1-412-690-2442x127   Carnegie Learning, Inc.   The Cognitive Tutor Company ®   Helping over 375,000 students in 1000 school districts succeed in math.References   Visible links   1. http://quotes.nasdaq.com/quote.dll?page=nasdaq100  -- http://mail.python.org/mailman/listinfo/python-list  -- 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
On 9 Aug 2006, at 12:03 PM, [EMAIL PROTECTED] wrote:    Brendon> I could do that, or I could do something like the re.* trick    Brendon> mentioned by another poster. But, doesn't it offend anyone else    Brendon> that the only clean way to access functionality that's already    Brendon> in Python is to write long complicated Python code? Python    Brendon> already knows how to extract a list object from a string; why    Brendon> should I have to rewrite that?Doesn't bother me at all.  One, it's not actually Python code, it's_javascript_.  It's just serendipity that the table can be parsed as a Pythonlist.  Two, there's nothing to prevent the authors from changing theformatting in an incompatible way in the future.I think that these are actually the same reason, and can be safely ignored, because item 2 is true no matter what method I use to parse the data. Sure, it's serendipity, but that happens to be the hand I'm dealt at the moment; why not exploit the serendipity?  Three, it's completelyuntrusted input and shouldn't be fed to eval().  This is the crucial point, and the reason I asked the question to begin with.Lisp (which I'm used to) has the read-eval-print loop; I think that my confusion was because:1. Python's eval(X) is essentially the same as Lisp's (eval (read-from-string X)), not Lisp's (eval X) or Lisp's (read-from-string X);2. The '[' character that begins a list should actually be read as a function call, not a data delimiter. (Which, in the context of list comprehensions, makes a lot of sense as I think about it.)Four, it's not actuallycomplicated code (using the csv module would probably be simpler).I'll look into the csv module.And, it may not be complicated on an absolute scale, but Chris' re.* method turned one line of code into about 15; that's certainly a non-trivial increase in complexity.Five, you have to stop thinking of it a "listobject".  It's just a string of bytes which happens at this point in time tointersect with the definition of a Python list.  You're trying to wish itwas something that it's not.I must be confused here. If I call the following function:  eval('[1, 2, 3]')what does that function call return, if not a list object?Sure, the string isn't a list 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, 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-10 Thread Brendon Towle
Date: 9 Aug 2006 14:12:01 -0700From: "Simon Forman" <[EMAIL PROTECTED]>Subject: Re: Eval (was Re: Question about using python as a scripting	language)To: python-list@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset="iso-8859-1"Fredrik Lundh 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-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: 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 python as a scripting	language)To: python-list@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset="iso-8859-1"Fredrik Lundh posted a great piece of code to parse a subset of pythonsafely:http://groups.google.ca/group/comp.lang.python/browse_frm/thread/ 8e427c5e6da35c/a34397ba74892b4e This, as it turns out, was the most helpful pointer of them all --  thanks!Actually, I spoke too soon. (I should have known better -- always test first.) But:>>>import SafeEval as se>>>se.safeEval('[["AAPL", 35.5, 0.45],["YHOO", 75.68, 0.01]]')[['AAPL', 35.5, 0.45001], ['YHOO', 75.687, 0.01]]>>>se.safeEval('[["AAPL", 35.5, 0.45],["YHOO", 75.68, -0.01]]')SyntaxError: malformed _expression_ (-)Seems that parsing negative numbers is outside of the scope of this routine. Here's the source (which is Frederik's source with one minor renaming; I take no credit here); anyone have any ideas?B. start source import cStringIO, tokenize def sequence(next, token, end):    out = []    token = next()    while token[1] != end:        out.append(atom(next, token))        token = next()        if token[1] == "," or token[1] == ":":            token = next()    return out def atom(next, token):    if token[1] == "(":        return tuple(sequence(next, token, ")"))    elif token[1] == "[":        return sequence(next, token, "]")    elif token[1] == "{":        seq = sequence(next, token, "}")        res = {}        for i in range(0, len(seq), 2):            res[seq[i]] = seq[i+1]        return res    elif token[0] in (tokenize.STRING, tokenize.NUMBER):        return eval(token[1]) # safe use of eval!    raise SyntaxError("malformed _expression_ (%s)" % token[1]) def safeEval(source):    src = ""    src = ""    src = "" for token in src if token[0] is not tokenize.NL)    res = atom(src.next, src.next())    if src.next()[0] is not tokenize.ENDMARKER:        raise SyntaxError("bogus data after _expression_")    return res  end source  -- 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 the use of python as a scripting language)

2006-08-10 Thread Brendon Towle
Oops -- I missed the subject line on my last post.On 10 Aug 2006, at 9:41 AM, [EMAIL PROTECTED] wrote:    Brendon> Seems that parsing negative numbers is outside of the scope of    Brendon> this routine. Here's the source (which is Frederik's source    Brendon> with one minor renaming; I take no credit here); anyone have    Brendon> any ideas?Negative numbers are actually tokenized as a MINUS followed by a NUMBER:    % python    Python 2.5b2 (trunk:50921, Jul 28 2006, 20:21:50)     [GCC 4.0.0 (Apple Computer, Inc. build 5026)] on darwin    Type "help", "copyright", "credits" or "license" for more information. - 47     -47Try changing your atom function to detect a minus sign, remember that fact,then require the next token to be a number.While I appreciate the suggestion, this is exactly the route I don't want to take -- it essentially involves rewriting the Python parser/tokenizer, which has already been written and tested by people much more qualified than I. In fact, the code I was using (Frederik's code) has already been written and tested by people much more qualified than I, and it _still_ doesn't work.A shortcut occurs to me; maybe someone can tell me what's wrong with my reasoning here. It seems that any string that is unsafe to pass to eval() must involve a function call, and thus must contain an opening paren. Given that I know that the data I expect contains no parens, would 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 changed -- found a paren"    else:        return eval(data[pos1+len(START_MARKER):pos2+1])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 the use of python as a scripting language)

2006-08-10 Thread Brendon Towle
On 10 Aug 2006, at 10:46 AM, [EMAIL PROTECTED] wrote:    Brendon> A shortcut occurs to me; maybe someone can tell me what's wrong    Brendon> with my reasoning here. It seems that any string that is unsafe    Brendon> to pass to eval() must involve a function call, and thus must    Brendon> contain an opening paren. Given that I know that the data I    Brendon> expect contains no parens, would people expect this code to be    Brendon> safe:Unfortunately, no.  If I define a class which has properties, attributeassignment can involve arbitrary numbers of function calls.Oh yeah -- forgot about that. Thanks.But, how could you get that class into my eval() call? Unless I'm missing something (entirely possible -- as we've seen above, I already did), it seems that you have only two options:1. Get the code containing the class on my local machine, and import 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 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: List Splitting

2006-08-21 Thread Brendon Towle
Not the most elegant solution, perhaps, but:>>>t = [ "a", "b", "c", "n", "a", "a", "t", "t", "t" ]>>>outlist = []>>>for x in range(3):...    temp=[]...    for y in range(len(t)/3):...        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
Date: 25 Aug 2006 04:22:37 -0700From: "Paul Boddie" <[EMAIL PROTECTED]>Subject: Re: Consistency in PythonTo: python-list@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset="iso-8859-1"Paul McGuire wrote: But with mutators that return self, a client could write any of these:bx = Box().length(100).width(50).height(20)bx = Box().width(50).height(20).length(100)bx = Box().width(50).length(100).height(20)...etc...and the results are the same. This is very convenient, and I've often thought about doing such thingsin my own APIs, but there can sometimes be subtle problems introducedinto programs when you decide to change the nature of such a mutator,or if you have another type/class whose mutators are of a differentnature, such that the width method produces a new Box object (which isquite similar to what the questioner seemed to have in mind) instead ofmutating (or failing to mutate) the existing object.Indeed, it may be important to know whether you're creating new objectsor not, and without metadata the most convenient way to communicatethis is quite probably to define a rigid interface (after all, whyshould width or append return an object?) which cannot be implementedon immutable things.So, it's possible that the above answers the question I have and I'm just not clever enough to see the answer. But:I had a case where I wanted to extract and return the top N elements of a list (where "top" meant "smallest numeric value"; the alternative for "largest numeric value" is a trivial modification). To me, the obvious answer was:def topNElements(lst, n):    return lst.sort()[:n]But, of course, that fails with a TypeError, because lst.sort() returns None, which is not subscriptable. The function really needs to be:def topNElements(lst, n):    lst.sort()    return lst[:n]It gets worse if I want to include an invariant in the list before I sort it:def bogusTopNElementsWithInvariant(lst, n):    return lst.append(INVARIANT).sort()[:n]def topNElementsWithInvariant(lst, n)    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 ®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
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) maybe they had a working carriage return key ?Right. Now that we've got the "Frederik gets sarcastic with a relative Python newcomer" bit out of the way, is there an actual *answer* somewhere in the community? b) http://pyfaq.infogami.com/why-doesn-t-list-sort-return-the-sorted-list    (this also explains how to handle your specific use case)Well, I posted working code, so I thought it should have been obvious that I knew how to handle my use case, and was (am) looking for a language-design level answer as opposed to a working-code level answer. Besides, the article above (although useful *and* freshly modified) doesn't explain how to handle the use case I posted with append(), or the ones I didn't post with extend(), insert(), remove(), dict.update(), and a bunch of others I can't think of off the top of my head. c) in general, mutating *and* returning may be confusing; consider:      lst = [1, 2, 3]     for item in lst.reverse():         print item     ... some other code ...     for item in lst.reverse():         print itemI guess I have three responses to this. The first is that generations of Lisp programmers seem to have handled mutating *and* returning just fine for about the last 50 years; maybe it really isn't all that hard. ("Always know where your CONS cells are coming from." is pretty ingrained in my programming DNA; the Python analog isn't hard.)My second response is that if "... some other code ..." is so long and involved that you've forgotten that you already reversed lst, then your function probably needs to be refactored and/or rewritten.My third response is that it's *always* possible to shoot yourself in the foot. Protecting a naive user from one particular metatarsal projectile insertion at the expense of letting the power-user write more concise code seems a bad tradeoff to me -- but, I'm not involved with Python design, which brings me back to my original question above. Anyone? 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: sending emails using python

2006-09-07 Thread Brendon Towle

On Sep 7, 2006, at 3:50 AM, "sridhar"  
<[EMAIL PROTECTED]>wrote:


> iam having user account on an exchangeserver.
> with that can i send an email using python?
>
> if iam using the following code iam getting error
>
>
> fromAddress = '[EMAIL PROTECTED]'
> toAddress = '[EMAIL PROTECTED]'
> msg = "Subject: Hello\n\nThis is the body of the message."
> import smtplib
> server = smtplib.SMTP("hstmsg002",25)
> server.sendmail(fromAddress, toAddress, msg)
>
> error:
>
> Traceback (most recent call last):
>   File
> "C:\sridhar\Beginning_Python\Beginning_Python\Chapter16\tryitout 
> \InitialMailExample.py",
> line 5, in ?
> server = smtplib.SMTP("hstmsg002",25)
>   File "C:\Python24\lib\smtplib.py", line 244, in __init__
> (code, msg) = self.connect(host, port)
>   File "C:\Python24\lib\smtplib.py", line 307, in connect
> (code, msg) = self.getreply()
>   File "C:\Python24\lib\smtplib.py", line 351, in getreply
> raise SMTPServerDisconnected("Connection unexpectedly closed")
> SMTPServerDisconnected: Connection unexpectedly closed
>

I saw a similar error when I was not following the server's  
authentication protocol -- either failing to authenticate when it  
wanted it, or authenticating when it didn't want it. Here's the code  
I use -- tested on both an Exchange server and on Comcast's SMTP  
servers. It assumes some globals (in all caps) which you need to set  
first.

def emailGivenString(host=SMTP_HOST, fromAddr=FROM_ADDR,
  toAddr=TO_ADDR, subject='', body='', auth=False):
 server = smtplib.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 work, I second the previous suggestion of talking to  
the server admin.

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 enough to debug it.” – Brian W. Kernighan


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


Random Drawing Simulation -- performance issue

2006-09-12 Thread Brendon Towle
I need to simulate scenarios like the following: "You have a deck of  
3 orange cards, 5 yellow cards, and 2 blue cards. You draw a card,  
replace it, and repeat N times."

So, I wrote the following code, which works, but it seems quite slow  
to me. Can anyone point out some obvious thing that I'm doing  
inefficiently? Or, is this more or less as good as it gets?

For reference, my typical numbers look like this:

   2 <= len(population) <= 7
   4 <= len(mapping) <= 50
   10 <= count <= 100

B.


#!/usr/bin/env python

import random

def randomDrawing(count, population):
 """Simulates drawing  items from , with  
replacement.
 population is a list of lists: [[count1, type1], [count2,  
type2], ...]

 Typical examples:
 >>>randomDrawing(100, [[3, 'orange'], [5, 'yellow'], [2, 'blue']])
 [[28, 'orange'], [57, 'yellow'], [15, 'blue']]

 >>>randomDrawing(10, [[3, 'orange'], [5, 'yellow'], [2,  
'blue']])
 [[29923, 'orange'], [50208, 'yellow'], [19869, 'blue']]

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



-- 
Brendon Towle, PhD
Cognitive Scientist
+1-412-690-2442x127
Carnegie 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: 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 the following: "You have a deck of
>> 3 orange cards, 5 yellow cards, and 2 blue cards. You draw a card,
>> replace it, and repeat N times."
>>  [my original code snipped]
>
> I got nearly a 2x speed up with this variant:
>
> def randomDrawing3(count, population):
> res = [[0, item[1]] for item in population]
> mapping = []
> for i in xrange(len(population)):
> mapping.extend([i]*population[i][0])
>
> n = len(mapping)
> for i in xrange(count):
> index = int(n * random.random())
> res[mapping[index]][0] += 1
>
> return res

Excellent! For some reason, the speedup I get is only ~1.5x, but  
that's still non-trivial.

Thanks much for the pointer-

B.


-- 
Brendon Towle, PhD
Cognitive Scientist
+1-412-690-2442x127
Carnegie 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: Random Drawing Simulation -- performance issue

2006-09-13 Thread Brendon Towle
On 13 Sep 2006, at 1:01 AM, [EMAIL PROTECTED] wrote:

> Date: 12 Sep 2006 20:17:47 -0700
> From: Paul Rubin <http://[EMAIL PROTECTED]>
> Subject: Re: Random Drawing Simulation -- performance issue
> To: python-list@python.org
>
> "Travis E. Oliphant" <[EMAIL PROTECTED]> writes:
>>> I need to simulate scenarios like the following: "You have a deck of
>>> 3 orange cards, 5 yellow cards, and 2 blue cards. You draw a card,
>>> replace it, and repeat N times."
>>>
>> Thinking about the problem as drawing sample froms a discrete
>> distribution defined by the population might help.
>
> Is there some important reason you want to do this as a simulation?
> And is the real problem more complicated?  If you draw from the
> distribution 100,000 times with replacement and sum the results, per
> the Central Limit Theorem you'll get something very close to a normal
> distribution whose parameters you can determine analytically.  There
> is probably also some statistics formula to find the precise error.
> So you can replace the 100,000 draws with a single draw.

The real problem is not substantially more complicated. (The real  
code is, because it's embedded in a bunch of other stuff, but that's  
not the point.)

I guess the essential reason that I want to do it as a simulation,  
and not as a statistics formula, is that I'd like the code to be  
readable (and modifiable) by a programmer who doesn't have a  
statistics background. I could dredge up enough of my college stats  
to do as you suggest (although I might not enjoy it), but I don't  
think I want to make that a requirement.

On the other hand (quote somewhat snipped):

> Date: Tue, 12 Sep 2006 22:46:04 -0500
> From: Robert Kern <[EMAIL PROTECTED]>
> Subject: Re: Random Drawing Simulation -- performance issue
> To: python-list@python.org
>
> Along the lines of what you're trying to get at, the problem that  
> the OP is
> describing is one of sampling from a multinomial distribution.
>
> numpy has a function that will do the sampling for you:
>
> In [4]: numpy.random.multinomial?
> Docstring:
>  Multinomial distribution.
>
>  multinomial(n, pvals, size=None) -> random values
>
>  pvals 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, but this just might do the trick. Must ponder.

Thanks, everyone, for your helpful suggestions!

B.

-- 
Brendon Towle, PhD
Cognitive Scientist
+1-412-690-2442x127
Carnegie 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


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://mail.python.org/mailman/listinfo/python-list


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

2006-09-28 Thread Brendon Towle
Some of your Lisp translations are subtly off...


> Date: 28 Sep 2006 02:49:50 -0700
> From: "sturlamolden" <[EMAIL PROTECTED]>
> Subject: Re: Questions on Using Python to Teach Data Structures and
>   Algorithms
> To: python-list@python.org
>
> If you want to make a chained structure, then perhaps you know LISP?
> This is what the basic machinery of LISP looks like in Python:
>
> def cons(a,b)
>return [a,b]

should be:
 return [a].extend(b)

> def car(structure)
>return structure[0]
>
> def cdr(structure)
>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 enough to debug it.” – Brian W. Kernighan


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


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 Lisp translations are subtly off...
>
> Seems correct to me. Lisp lists are linked lists, not arrays.
>
>>
>>> Date: 28 Sep 2006 02:49:50 -0700
>>> From: "sturlamolden" <[EMAIL PROTECTED]>
>>> Subject: Re: Questions on Using Python to Teach Data Structures and
>>> Algorithms
>>> To: python-list@python.org
>>>
>>> If you want to make a chained structure, then perhaps you know LISP?
>>> This is what the basic machinery of LISP looks like in Python:
>>>
>>> def cons(a,b)
>>>return [a,b]
>>
>> should be:
>> return [a].extend(b)
>
> A Lisp cons is made of a reference to it's content and a reference to
> the rest of the list, so cons = lambda a, b : [a, b] seems the most
> straightforward translation.

Yes, a lisp cons is a pair of references as you describe. However,  
the following lisp call:

? (cons  )

returns a single level list, with  as its new first item, and  
the original contents of  as the remainder of the list. The  
OP's code doesn't do that; it returns a list of two items, with  
 as the second item.

To put it another way, the following code is always true in Lisp:

? (= (length (cons  )) (1+ (length )))

But the OP's code only allows that to be true when  is of  
length 1.


I suppose, of course, that you could claim that the following Lisp list:

   (1 2 3 4)

should translate into the following Python list:

   [1, [2, [3, [4

But, I think that's a bit silly.


>>> def car(structure)
>>>return structure[0]
>>>
>>> def cdr(structure)
>>>return structure[1]
>>
>> should be:
>> return structure[1:]
>
> idem.

I should have pointed out, of course, that the original definition of  
CDR was correct given the original (incorrect) definition of cons.

B.

-- 
Brendon Towle, PhD
Cognitive Scientist
+1-412-690-2442x127
Carnegie 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: Questions on Using Python to Teach Data Structures and Algorithms

2006-09-28 Thread Brendon Towle
On 28 Sep 2006, at 12:45 PM, [EMAIL PROTECTED] wrote:

> From: "MonkeeSage" <[EMAIL PROTECTED]>
> Subject: Re: Questions on Using Python to Teach Data Structures and
>   Algorithms
> To: python-list@python.org
>
> [snip]
> But Brendon's code also needs a correction: [a].extend(b) is wrong,
> because extend is in-place and returns None, and [a] is anonymous...it
> needs to be something like:
>
> def cons(a, b):
>   b.insert(0, a)
>   return b

Clearly, my Lisp is better than my Python; I stand corrected. (Brings  
back memories 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
Cognitive Scientist
+1-412-690-2442x127
Carnegie 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


Converting _node* to a Code object?

2007-03-31 Thread Brendon Costa
Hi All,

I have an application with an embedded python interpreter and i need to
get the embedded interpreter to "import" strangely named files as python
modules.

Anyhow the simple part of the question is:

How do i convert a _node* object returned from:
PyParser_SimpleParseStringFlagsFilename()

into a code object i can use as a module to import with:
PyImport_ExecCodeModule()


I cant seem to find any documentation about this. If you are wondering
why i want to do this, then you can read on and maybe there is a much
better way to achieve what i am after.



Thanks,
Brendon




- What i am trying to achieve -


Basically i want to "import" using the python C API a module from
various files which may have names that do not make valid python module
names.


In particular i have an embedded python interpreter that is used to
apply a number of operations on some data based on a user supplied
"suppressions file" (*.eds). This .eds file is just a python source file
designed only to be used from within this application.


Now the names of these suppression files usually matche that of a
library or application to which they will apply to. For example:

libstdc++.so.6.0.5 : has eds file: libstdc++.so.6.0.5.eds


Now i want to have my code import this eds file as a python module so
that i can then use it as any other standard python module. So i need to
separate the name of the module from the name of the file. I was
thinking for example for the above filename i would give it a module
name like:

libstdc___so_6_0_5

(The name is not important just that the above one is a valid module
name from what i understand and it is based on the original name)

So i have some random file:
/foo/bar/lib/libstdc++.so.6.0.5.eds

and i want to be able to import that as a module using the Python C API
so native python code can access the module like:

libstdc___so_6_0_5.PostCalculation()


If you have any better method of doing this, i would love to know what
it is.

Thanks in advance for any help,
Brendon.


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


Re: Converting _node* to a Code object?

2007-04-01 Thread Brendon Costa
Gabriel Genellina wrote:
> En Sun, 01 Apr 2007 01:35:59 -0300, Brendon Costa <[EMAIL PROTECTED]>  
> escribió:
> 
>> How do i convert a _node* object returned from:
>> PyParser_SimpleParseStringFlagsFilename()
>>
>> into a code object i can use as a module to import with:
>> PyImport_ExecCodeModule()
> 
> Using PyNode_Compile. But why don't you use Py_CompileXXX instead?
> And look into import.c, maybe there is something handy.
> 

Thanks for the pointer. I am not using Py_CompileXXX because i could
only find Py_CompileString... i could not find a file version of it
(Which i thought should exist).

My original email though i copied and pasted the wrong function into.
Instead of:
PyParser_SimpleParseStringFlagsFilename()

i meant to use:
PyParser_SimpleParseFileFlags()


Basically i will open a FILE* for the file requested, parse it and load
it into the module. Using this method i don't have to load its contents
first into a string to be compiled, but just get the python library to
parse directly from the file.

It all seems to work fine now. Thanks for the help.
Brendon.

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


Accessing shell output from HTTP

2009-03-29 Thread Brendon Wickham
Hi there,

I would like users of my web application to be able to download a backup
file of a database (using* *MySQL's *mysqldump* command).

My strategy is to use *zipfile* to create a zip file object (with the *
mysqldump* output as the contents of the zipped file) and then use *
sys.stdout* to send the zip file object to the user as a file for them
download.

The zipping bit and file delivery is all sorted. Getting the output from *
mysqldump* is my problem and I'm not even sure (given that I'm calling shell
via an HTTP thread/process) it is even possible.

This is as far as I've got:

import subprocess as sp
p1 = sp.Popen('mysqldump --opt
--user=[username]--password=[password]
[databasename]',stdout=sp.PIPE,shell=True)
backupfile=p1.communicate()[0]

If I type the above into a Python prompt and print *backupfile* I will get
the expected result, but when I'm going through CGI nothing is being
returned by communicate().

Is this possible? Or am I barking up the wrong tree?

Cheers,

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


Accessing shell output from HTTP

2009-03-30 Thread Brendon Wickham
Hi there,

I would like users of my web application to be able to download a backup
file of a database (using* *MySQL's *mysqldump* command).

My strategy is to use *zipfile* to create a zip file object (with the *
mysqldump* output as the contents of the zipped file) and then use *
sys.stdout* to send the zip file object to the user as a file for them
download.

The zipping bit and file delivery is all sorted. Getting the output from *
mysqldump* is my problem and I'm not even sure (given that, as I understand
it, it's an asynchronous call to shell via an HTTP thread) it is even
possible.

This is as far as I've got:

import subprocess as sp
p1 = sp.Popen('mysqldump --opt
--user=[username]--password=[password]
[databasename]',stdout=sp.PIPE,shell=True)
backupfile=p1.communicate()[0]

If I type the above into a Python prompt and print *backupfile* I will get
the expected result, but when I'm going through CGI (the script, called from
a web browser, is supposed to capture the output into the variable) nothing
is being returned by communicate().

Is this possible? Or am I barking up the wrong tree?

Cheers,

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


Re: python for loop

2009-03-31 Thread Brendon Wickham
Since when should a machine (that's what a computer is after all), be
forced to contort itself into something that is capable of reflecting
the laws of physical matter?

Better perhaps to look at it from another angle - it's
counter-intuitive to think that the digital should mirror the
analogue. The digital can *virtualise* the real world, but it doesn't
do that by *working like* the real world.

It's not theory, it's actually what it is.


2009/4/1 Lada Kugis :
> On Tue, 31 Mar 2009 19:29:56 -0700, Chris Rebert 
> wrote:
>
>
>>Sort of, but it's *really* not idiomatic. You'd have to declare the
>>arrays to be one longer than they actually are so that array[N] is a
>>valid index. And then you'd end up not using the true first element of
>>the array. Not to mention most library functions use 0-numbering, so
>>you'd have to work around that as well.
>>
>>So, it can be done, but you're going against the grain of the language.
>
> I use fortran libraries, so that is not a problem for me. I only make
> the change once, while transferring the elements ... uhmm, make that
> twice.
> I wrote in my other post, 0 is weird to me, I have model of solution
> on paper ... if I keep 0 then all comes out different. And while
> comparing, I always get them mixed up. That's why I always try to
> adapt it to the paper situation.
>
> Lada
>
>
>>
>>Cheers,
>>Chris
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: need to start a new project , can python do all that ?

2009-04-15 Thread Brendon Wickham
Python is a programming language, and like practically any programming
language it can do all those things. I'm not sure your requirements
are based on a full understanding of the implications. A "health care
center' cannot be made with a few "drag and drop", "plug and play"
modules that you manipulate within a GUI.

For example, importing pathology results: there is no international
standard for how such results should be formed. You will need to ask
the suppliers of the results to work out how they're going to give it
to you. And they will all be different. You will most likely need a
firm understanding of HL7 v2 and 3, XML, XSL (and probably web
services) etc.

In terms of cross platform, in the health context it's pointless being
anything other than a web application (IMHO).


Cheers,

Brendon


2009/4/15 Deep_Feelings :
> I want to start programming a new program (electronic health care
> center) in python and before start learning python i wanna make sure
> that python does have all the features i need to accomplish this
> project so i wanna ask you does python able to support these
> features :
>
> 1- cross platform (windows + linux)
> 2- mysql database access
> 3- 2D graphs (curves)
> 4- support of international languages
> 5- can access a scanner and input pictures from it.
>
> and possibly be able to import data from labratory machines (such as
> CBC machines) to automatically register patient investigations result
> into the system (not mandatory)
>
> so can python (with any freely available libraries) do all that and
> still be cross platform ?
>
> thankx in advance :)
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: What IDE support python 3.0.1 ?

2009-04-15 Thread Brendon Wickham
> On IDE's, I'm afraid I'm not going to be much help because I don't use
> them.  I prefer to use a decent editor (Emacs in my case, others have
> their own preferences) and run my scripts from the command line.  That
> said, IDLE (which comes packaged with Python) is a perfectly decent
> little IDE.  It's surprising how little you really need given the
> flexibility and immediacy of working with Python.
>

I agree, no IDE needed. Just don't use Notepad! I'm on Mac, so spoiled
for choice of text editors, but I'm sure there's one or 2 good uns if
you're on Windows.
--
http://mail.python.org/mailman/listinfo/python-list


How do i : Python Threads + KeyboardInterrupt exception

2008-06-18 Thread Brendon Costa
Hi all,

I have a small python project i am working on. Basically i always have
two threads. A "Read" thread that sits in a loop reading a line at a
time from some input (Usually stdin) and then generating events to be
processed and a "Proc" thread that processes incoming events from a
queue. There will be additional threads as well that asynchronously
insert events into the queue to be processed, but they are not a part
of this so i have omitted them.

What i want to know is: "What is the standard/best way of implementing
such a pattern that works in the presence of errors and particularly
with the KeyboardInterrupt exception?"

Some sample code is shown below. This code works as is, except in the
case where the "Proc" thread wants to initiate the exit of the
application.

For example:
* running the code below and pressing Ctrl + C works fine as the Read
thread is initiating the shutdown.
* running the code below and entering:
   pquit
   some other data
   

will cause oytput:

Processing: pquit
Proc: Initiating quit

and then it HANGS waiting for the Read thread to exit.

Some questions i have that are:
* KeyboardInterrupt exception seems to only be recieved by the main
thread. Is this ALWAYS the case across all UNIX + windows platforms
(not so worried about others)?
* Can i somehow get the Proc thread to force the Read thread to
generate a KeyboardInterrupt or somehow exit its blocking "for line in
fin:" call?


Thanks,
Brendon


--- SNIP ---
# Two or more threads
#
# proc : Is a processing thread that basically reads events from a
event queue and processes them
# read : Is a thread reading in a loop from stdin and generating
events for "proc"
# * : Other additional threads that may asynchronously add events to
the queue to be processed

import Queue
import threading
import sys

def Read(queue, fin, fout):
   ret = (1, 'Normal Exit')
   try:
  for line in fin:
 queue.put((0, line))
 #raise Exception("Blah")
 #raise "Blah"
   except KeyboardInterrupt:  ret = (1, 'KeyboardInterrupt')
   except Exception, e:   ret = (1, 'ERROR: ' + str(e))
   except:ret = (1, 'UNKNOWN-ERROR')

   # Notify Proc thread that we are exiting.
   queue.put(ret)
   print >>fout, 'Read: Initiating quit'


def Proc(queue, fout, ignore):
   quit = False
   while not quit:
  (evt_type, evt_data) = queue.get()

  if   evt_type == 0:
 print >>fout, 'Processing: ' + str(evt_data)
 if evt_data.startswith('pquit'):
print >>fout, 'Proc: Initiating quit'
quit = True

  elif evt_type == 1:
 print >>fout, 'Quit: ' + str(evt_data)
 quit = True

class MyThread(threading.Thread):
   def __init__(self, func, queue, file1, file2, *args, **kwds):
  threading.Thread.__init__(self, *args, **kwds)
  self.func = func
  self.queue = queue
  self.file1 = file1
  self.file2 = file2
  self.start()

   def run(self):
  return self.func(self.queue, self.file1, self.file2)


if __name__ == '__main__':
   queue = Queue.Queue()

   # Read thread is the main thread and seems to get the
KeyboardInterrupt exception.
   t = MyThread(Proc, queue, sys.stderr, None)
   Read(queue, sys.stdin, sys.stderr)

   # Read thread is NOT the main thread and never seems to get the
KeyboardInterrupt exception.
   # This doesnt work for that reason.
   #t = MyThread(Read, queue, sys.stdin, sys.stderr)
   #Proc(queue, sys.stderr, None)


   # @@@Brendon How do we notify the Read thread that they should
exit?
   # If the Read thread initiated the quit then all is fine.
   # If the Proc thread initiated the quit then i need to get the
Read
   # thread to exit too somehow. But it is currently blocking in a
read
   # on an input file.
   print >>sys.stderr, 'Joining thread.'
   t.join()

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


Re: How do i : Python Threads + KeyboardInterrupt exception

2008-06-18 Thread Brendon Costa
> I don't know the "standard" way, but perhaps you can get some ideas from
> this recent 
> thread:http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
>

I had a quick read through that thread. I think i will need some more
time to think about what they are saying in there though. They seem to
talking about killing a python thread kind of similar to the C
functions TerminateThread() in windows or pthread_cancel() on UNIX
which are not suitable for my purpose.


> You might try using the PyThreadState_SetAsyncExc function (from the
> Python C API) to inject a KeyboardInterrupt exception into the Read thread
> - but I don't know if it will work at all, the execution might be blocked
> waiting for an I/O call to complete, and never return to Python code...
>

Unfortunately that is the problem. It is blocking in a IO system call
and i want to force it to exit that with an error, hopefully causing a
Python exception. I looked at what you mentioned and it is described a
bit here too: http://sebulba.wikispaces.com/recipe+thread2

I really need a python mechanism for interrupting blocking system
calls.  have dealt with this sort of thing before in C/C++ on windows
and UNIX. For UNIX it is really a matter of sending a signal to the
process (SIGINTR), the main thread which is the only one in Python to
accept signals (others as i understand are masked) will get the signal
and and return with an EINTR breaking out of the blocking read
hopefully a python exception of Interrupted IO or KeyboardInterrupt.
Note that this only works for the one thread , but that is all i need.

For windows, it is possible to do a similar thing using:
GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0) with which behaves a bit
like a UNIX signal and i assume is what causes the KeyboardInterrupt
in the first place.

The problem i have is how do I achieve this in python?
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do i : Python Threads + KeyboardInterrupt exception

2008-06-18 Thread Brendon Costa
I tested this a bit more. My windows example was incorrect. It should
have used CTRL_C_EVENT. But even then, the problem is that the process
will also close the console window from which it was called because of
the 0. Also this requires that the process actually have a console and
is not a GUI application.

Is there some other method rather than a blocking "for line in fin:"
that i can use for reading from a file like device that plays nicely
with other threads asynchronously waking it up?

Sorry for all the posts. I am giving updates as i look further into
the problem.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do i : Python Threads + KeyboardInterrupt exception

2008-06-19 Thread Brendon Costa
I tested this a bit more. My windows example was incorrect. It should
have used CTRL_C_EVENT. But even then, the problem is that the process
will also close the console window from which it was called because of
the 0. Also this requires that the process actually have a console and
is not a GUI application.

Is there some other method rather than a blocking "for line in fin:"
that i can use for reading from a file like device that plays nicely
with other threads asynchronously waking it up?

Sorry for all the posts. I am giving updates as i look further into
the problem.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do i : Python Threads + KeyboardInterrupt exception

2008-06-19 Thread Brendon Costa
> If only the main thread can receive KeyboardInterrupt, is there any
> reason why you couldn't move the functionality of the Read thread into
> the main thread? It looks like it's not doing any work, just waiting
> for the Proc thread to finish.
>
> You could start the Proc thread, do the current Read thread
> functionality until the interrupt occurs, put the apporpriate message
> in the queue, and then wait for the Proc thread to finish.

It is already doing that. You will notice that the Proc() function is
called by a threading.Thread instance so Proc() is running in a
thread, but the Read() function is being called by the main thread
right after this. It DOES work with the Ctrl + C, but i can find no
way at all of closing down the script from within the Proc() thread.

The relevant bit of code is:
t = MyThread(Proc, queue, sys.stderr, None)
Read(queue, sys.stdin, sys.stderr)

In the end, the problem is that i am trying to multiplex IO and other
operations. In UNIX i would use select with the input file descriptor
and an anonymous pipe for the extra commands to achieve this without
any threads, but this script needs to run primarily on a windows box
and i would like to use it on UNIX too. I thought i could use threads
to achieve the IO Multiplexing in python, but it seems not or at least
not simply.

How do people usually manage IO multiplexing (not just using sockets)
cross platform in python?

I only need to multiplex two sources really:
* Input file or stdin
* A input event queue
   This will have messages injected from various locations: timers,
the processing thread itself, and possibly from a single GUI thread at
a later point in time.

Though i can foresee that at some point in the future i may also need
to multiplex those two above and some sockets (For a server with a few
clients).

I was thinking of looking at some asynchronous IO libraries for python
on Windows + UNIX, any suggestions (Must include more than just
sockets)?
--
http://mail.python.org/mailman/listinfo/python-list


Re: What do I do now?

2009-10-12 Thread Brendon Wickham
Speaking of itch, that's exactly the phrase Eric Steven Raymond uses
for the same purpose in his famous essay: "Cathedral and the Bazaar"
(http://www.catb.org/~esr/writings/cathedral-bazaar/). Someone
Something, you should read this essay first, before anything else.

Cheers,
Brendon

PS: I agree with Donn, it's a candy shop!

2009/10/12 Donn 
>
> Find an "itch" and either:
> 1. Find a project in that direction and try to join.
> 2. Start your own.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web development with Python 3.1

2009-10-25 Thread Brendon Wickham
>
> Anyway, for simple web programming, frameworks are not worth the
> hassle.  Just use the cgi module.
>
>
I can vouch for what Paul says. I started in Python 3 years ago, and I did
so with a web application (still working on it!). I'm using the cgi
approach, and it certainly teaches you the concepts. I fail to see how
starting with a framework is a good idea if you don't know how the
frameworks work (or what they're actually doing). It would be a bit like
doing a web page in Dreamw***er and thinking you understand HTML/CSS.

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


Re: Few questions on SOAP

2010-02-18 Thread Brendon Wickham
On 19 February 2010 08:07, Mark Lawrence  wrote:
> Muhammad Alkarouri wrote:
>>
>> Your question is borderline if not out of topic in this group. I will
>> make a few comments though.
>
> This might be a Python group, but threads often drift way off topic, which
> added to the language itself make this a great group to read.  If you don't
> like the way a thread goes, you can always skip it.


Perhaps...but he answered the question very well and with great, IMO, patience.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: integer >= 1 == True and integer.0 == False is bad, bad, bad!!!

2010-07-11 Thread Brendon Wickham
"i had once considered you one of the foremost intelligent minds
within this group. However, after your display within this thread i am
beginning to doubt my original beliefs of you."

"Oh ... grow a spine already, really. I can't help but thinking of the
spineless Robert Ford every time you open your mouth"

@rantingrick : these comments among others fail to meet the standard
of engagement expected of, and traditional to, this list. Take a
breath, get some sleep and come back with a level head and a civil
tongue. If you have any valid point to make at all, your attitude so
far has failed to make it credible, and nor will it enable you to
enlist supporters.
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting cookie "expires" value

2009-07-22 Thread Brendon Wickham
Hi there,

My web application uses a cookie to set/get a session id. This is
working fine. However, I'm unable to work out how to get the cookie
"expires" value.

Below is test code that replicates the problem. It creates a simple
web page and shows a cookie value if it's found, or creates a new one
(correctly setting the "expires" value) and indicates that it was
created:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#!/usr/bin/env python
import Cookie,os

def printHeader():
    print "Content-type: text/html\n"
    print "Cookie test"
    print ""

cookies=Cookie.SimpleCookie(os.environ.get('HTTP_COOKIE'))

if cookies.has_key('test'):
    #If cookie was found:
    printHeader()
    print "Found cookie:"

    #Get cookie:
    c = cookies.get('test')

    #Print its value:
    print "Value: %s" % c.value

    #Iterate through its items and print name/value:
    for k,v in c.items():
         print "%s=%s" % (k,v)

else:
    #Define cookie:
    cookies['test'] = "1234"
    cookies['test']['expires'] = 3600

    #Save cookie:
    print cookies['test']

    #Now print HTML:
    printHeader()

    print "Cookie created."

print ""
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


This is what I get if the cookie exists:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Found cookie:

Value: 1234
comment=
domain=
secure=
expires=
max-age=
version=
path=
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

As you can see, the cookie attributes are valueless. Can anyone help?
Am I missing something fundamental?

Cheers,

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


Re: IDE for python similar to visual basic

2009-09-11 Thread Brendon Wickham
>
>
> The interface really should be configurable by the user according to their
> needs. The code doesn't need to *know* the position or dimensions of
> a widget, or its label or colour or spacing, let alone dictate them.
>

Perhaps...but the user needs a framework in order to understand the
functions they find themselves in charge of once they've initiated a
program. As the designer, the programmer is best placed to provide
that framework, because they know, or they should know, what it is
(something I don't think can be taken for granted). Therefore,
fundamental decisions about the UI should be left to the programmer.
If customisation is possible, all well and good, but it should not be
the main goal of a UI. Usability principles should be.

> In most cases, the code shouldn't even get to dictate that specific
> widgets even exist. Rather, it should provide actions which can
> be bound to buttons, menu items and/or accelerators as the user chooses.
>

That would be an API.
-- 
http://mail.python.org/mailman/listinfo/python-list