Re: Convert (sorted) list of dics to nested list ?

2006-03-22 Thread Gerard Flanagan
[EMAIL PROTECTED] wrote: > Hi - I want to take something like ... > > lstIn = [] > lstIn.append({'COM_AUTOID': 1, 'PRG_AUTOID': 10, 'LEA_AUTOID': 1000}) > lstIn.append({'COM_AUTOID': 1, 'PRG_AUTOID': 11, 'LEA_AUTOID': 2000}) > lstIn.append({'COM_AUTOID': 1, 'PRG_AUTOID': 11, 'LEA_AUTOID': 2001}) >

Re: parsing downloaded mail via POP3

2006-03-22 Thread Gerard Flanagan
Kevin F wrote: > I have the following script: > > emails = [] > for msg in messagesInfo: > msgNum = int(msg.split()[0]) > msgSize = int(msg.split()[1]) > if(msgSize < 2): > message = server.retr(msgNum)[1] > Message = join(message, "\n") > ema

Re: overlapping sets

2006-03-24 Thread Gerard Flanagan
kpp9c wrote: > I have a question... and ... whew ... i am gonna be honest, i haven't > the slightest clue how to even start ... i am not sure if i used up all > my good will here or can take a mulligan.. i love to try to at least > post some lame broken code of my own at first... but like i said,

Re: overlapping sets

2006-03-24 Thread Gerard Flanagan
Gerard Flanagan wrote: > kpp9c wrote: > > > I have a question... and ... whew ... i am gonna be honest, i haven't > > the slightest clue how to even start ... i am not sure if i used up all > > my good will here or can take a mulligan.. i love to try to at least >

OT: unix newbie questions

2006-03-25 Thread Gerard Flanagan
Hello all Some basic unix questions which pure laziness prevents me from googling for. Anyone feeling charitable? I'm using FreeBSD 6.0: * To create an empty __init__.py file I do 'vim __init__.py' then immediately exit vim, is there a shell or vim command which will create an empty file without

Re: sending emails to a list of recipients

2006-03-25 Thread Gerard Flanagan
Kun wrote: > i have the following code: > > -- > import smtplib > > from email.MIMEText import MIMEText > fp = open('confirmation.txt', 'rb') > msg = MIMEText(fp.read()) > > From = '[EMAIL PROTECTED]' > > msg['Subject'] = 'Purchase Confirmation' > msg ['From'] = Fr

Re: a hobbyist's dilemma

2006-03-29 Thread Gerard Flanagan
John Salerno wrote: > Now that I've learned much of Python, I'm sort of stuck with what to do > with it. I'm not a professional programmer, so I don't really have a use > for Python now. But I really want to come up with some neat uses for it > (for fun, and so I don't just start forgetting it rig

Re: Doc suggestions (was: Why "class exceptions" are not deprecated?)

2006-03-30 Thread Gerard Flanagan
Fredrik Lundh wrote: > Ed Singleton wrote: > > > I'd suggest adding some sort of guidance page so that people know > > roughly what's expected. IE can they just add questions and comments > > into the text, hoping that someone more knowledgeable will sort it out > > (or delete it). > > I've added

ANN: htmlbuilder.py - another HTML generator

2006-03-30 Thread Gerard Flanagan
In the hope that it may be useful, a simple Html Generator: http://gflanagan.net/site/python/htmlbuilder/htmlbuilder.py It requires 'elementtree' : http://www.effbot.org/zone/element-index.htm Example: html = HtmlBuilder( doctype='strict') page = html.page('Test Page') page.comm

Re: ANN: htmlbuilder.py - another HTML generator

2006-03-30 Thread Gerard Flanagan
Gerard Flanagan wrote: > In the hope that it may be useful, a simple Html Generator: > > http://gflanagan.net/site/python/htmlbuilder/htmlbuilder.py > > It requires 'elementtree' : > http://www.effbot.org/zone/element-index.htm > > Example: > >

Re: any() and all() on empty list?

2006-03-31 Thread Gerard Flanagan
Steve R. Hastings wrote: > Therefore, I propose that all() should work as if it were written this way: > def all(S): > ret_val = False > > for x in S: > ret_val = True > if not x: > return False > > return ret_val > > Comments? Ant wrote: > all(list) simp

Re: Dice probability problem

2006-04-04 Thread Gerard Flanagan
Tomi Lindberg wrote: > > # A die with n faces > D = lambda n: [x+1 for x in range(n)] > That can be written: D = lambda n : range(1,n+1) Gerard -- http://mail.python.org/mailman/listinfo/python-list

Re: Receiving emails with attachments

2006-04-08 Thread Gerard Flanagan
[EMAIL PROTECTED] wrote: > Hi there, > > I'm new to Python, but know other scripting and programming languages. > I > want to develop a script which will receive emails with attachments > from my POP3 account, perform certain actions on it and email it back > to someone else. > > However, I'm not

Re: how to make a generator use the last yielded value when it regains control

2006-04-08 Thread Gerard Flanagan
John Salerno wrote: > Michael Spencer wrote: > > > itertools.groupby makes this very straightforward: > > I was considering this function, but then it seemed like it was only > used for determing consecutive numbers like 1, 2, 3 -- not consecutive > equivalent numbers like 1, 1, 1. But is that not

Re: Receiving emails with attachments

2006-04-09 Thread Gerard Flanagan
[EMAIL PROTECTED] wrote: > Gerard, > > I tried to run your code but my interpreter couldn't locate the > maildocument module. Is it included in Python standart library or > should I install it from other place? > > Thanks, > Tomer Sorry Tomer, I was just suggesting you read it through as an exam

Re: setting up mod_python handlers on a server?

2006-04-11 Thread Gerard Flanagan
John Salerno wrote: > I get this internal error message when I try to access a PSP page: > > "Invalid command 'PythonHandler', perhaps mis-spelled or defined by a > module not included in the server configuration" > > So it seems that mod_python is not fully configured yet to handled PSP > pages.

Re: turning python-cgi into an html output

2006-04-12 Thread Gerard Flanagan
Kun wrote: > i have a python cgi script that displays tables from a mysql database in > html. > > the problem is, i want to use excel's web query to pull this data and > the web query doesn't read .py files. > > thus i am wondering what is the easiest way to just turn my .py html > output into a .

Re: Iterating command switches from a data file - have a working solution but it seems inefficient

2006-04-13 Thread Gerard Flanagan
News wrote: > OT: I saw several references to "OP". What does this mean? It's a TOOTKA :-) You - The Original Post/Poster. Gerard -- http://mail.python.org/mailman/listinfo/python-list

Re: Should I learn Python instead?

2006-04-15 Thread Gerard Flanagan
fyleow wrote: > Hi guys, > > I'm a student/hobbyist programmer interested in creating a web project. > It's nothing too complicated, I would like to get data from an RSS > feed and store that into a database. I want my website to get the > information from the database and display parts of it dep

Re: filename of calling function?

2009-11-28 Thread Gerard Flanagan
Phlip wrote: Consider these two python modules: aa.py def a(): print '?' bb.py import aa def bb(): aa.a() bb() How do I make the print line emit the filename of bb.py? (It could be anything.) Possibly not very reliable in every situation (doctests, other pythons, ...) but this i

Re: Inheriting methods but over-riding docstrings

2010-01-16 Thread Gerard Flanagan
Steven D'Aprano wrote: I have a series of subclasses that inherit methods from a base class, but I'd like them to have their own individual docstrings. The obvious solution (other than copy-and-paste) is this: class Base(object): colour = "Blue" def parrot(self): """docstring

Re: Is there a command that returns the number of substrings in a string?

2009-10-26 Thread Gerard Flanagan
Peng Yu wrote: For example, the long string is 'abcabc' and the given string is 'abc', then 'abc' appears 2 times in 'abcabc'. Currently, I am calling 'find()' multiple times to figure out how many times a given string appears in a long string. I'm wondering if there is a function in python which

Re: Is there a command that returns the number of substrings in a string?

2009-10-27 Thread Gerard Flanagan
alex23 wrote: Gerard Flanagan wrote: def count(text, *args): Other than the ability to handle multiple substrings, you do realise you've effectively duplicated str.count()? I realise that calling this count function with a single argument would be functionally identical to ca

Re: Accessing a method from within its own code

2009-11-02 Thread Gerard Flanagan
Paddy O'Loughlin wrote: Hi, I was wondering if there was a shorthand way to get a reference to a method object from within that method's code. Take this code snippet as an example: import re class MyClass(object): def find_line(self, lines): if not hasattr(MyClass.do_work, "matche

Re: String prefix question

2009-11-09 Thread Gerard Flanagan
Alan Harris-Reid wrote: In the Python.org 3.1 documentation (section 20.4.6), there is a simple “Hello World” WSGI application which includes the following method... def hello_world_app(environ, start_response): status = b'200 OK' # HTTP Status headers = [(b'Content-type', b'text/plain; charset

Re: Common area of circles

2010-02-04 Thread Gerard Flanagan
On 2/4/2010 7:05 AM, Shashwat Anand wrote: I want to calculate areas. like for two circles (0, 0) and (0, 1) : the output is '1.228370' similarly my aim is to take 'n' co-ordinates, all of radius '1' and calculate the area common to all. The best I g

Re: Common area of circles

2010-02-04 Thread Gerard Flanagan
Gary Herron wrote: Gerard Flanagan wrote: A brute force approach - create a grid of small squares and calculate which squares are in all circles. I don't know whether it is any better than monte-carlo: That's just what the monte-carlo method is -- except the full family of m

Re: Modifying Class Object

2010-02-08 Thread Gerard Flanagan
Arnaud Delobelle wrote: "Alf P. Steinbach" writes: * Chris Rebert: On Sun, Feb 7, 2010 at 5:05 PM, T wrote: Ok, just looking for a sanity check here, or maybe something I'm missing. I have a class Test, for example: class Test: def __init__(self, param1, param2, param3): self.pa

Re: use strings to call functions

2010-02-08 Thread Gerard Flanagan
Klaus Neuner wrote: Hello, I am writing a program that analyzes files of different formats. I would like to use a function for each format. Obviously, functions can be mapped to file formats. E.g. like this: if file.endswith('xyz'): xyz(file) elif file.endswith('abc'): abc(file) ... Y

Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread Gerard Flanagan
david jensen wrote: ... and of course i screwed up my outcomes... that should read outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]] abstracting the given algorithm: def iterweights(N): d = 1.0/(N-1) for i in xrange(N): yield i*d, (N-1-i)*d def iterpart

Re: Dynamic Class Creation

2010-03-17 Thread Gerard Flanagan
Josh English wrote: Chris, Thanks. This worked for the attributes, but I think the tactic is still misleading. There are child elements I can't quite determine how to deal with: Analog Science Fiction and Fact Analog Science Fiction First Contact Hard Science Fiction

Re: first non-null element in a list, otherwise None

2010-09-02 Thread Gerard Flanagan
wheres pythonmonks wrote: This should be trivial: I am looking to extract the first non-None element in a list, and "None" otherwise. Here's one implementation: x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) print x 1 I thought maybe a generator expression would be better,

Re: list of tuples with dynamic change in position

2010-09-06 Thread Gerard Flanagan
sajuptpm wrote: I have a list of tuples l = [(('s','a'),(5,9)), (('u','w'),(9,2)), (('y','x'),(3,0))] and postion of values in the tuple change dynamicaly. I need a way to access correct value even if change in position. from itertools import starmap, izip, imap list(imap(dict, starmap(izip, d)

Re: list of tuples with dynamic change in position

2010-09-07 Thread Gerard Flanagan
On 7 Sep, 07:42, sajuptpm wrote: > More details > I have a list of tuples l = [((cpu_util,mem_util),(disk_util)), > ((cpu_util,mem_util),(disk_util))] > ie, l = [((30,50),(70)), ((50,20),(20))] > > l.sort(key=lambda x:(-x[0][0], x[1][0])) # sorting cpu_util asc and > disk_util desc > > suppose i c

<    1   2   3   4