[Tutor] can this be done easerly

2010-08-30 Thread Roelof Wobben
Hello, For a exerise I made this one :" import string def extract_words(s): """ >>> extract_words('Now is the time! "Now", is the time? Yes, now.') ['now', 'is', 'the', 'time', 'now', 'is', 'the', 'time', 'yes', 'now'] >>> extract_words('she tried to curtsey as she

Re: [Tutor] can this be done easerly

2010-08-30 Thread Evert Rol
> For a exerise I made this one :" > > import string > def extract_words(s): > """ > >>> extract_words('Now is the time! "Now", is the time? Yes, now.') > ['now', 'is', 'the', 'time', 'now', 'is', 'the', 'time', 'yes', 'now'] > >>> extract_words('she tried to curtsey as she

Re: [Tutor] can this be done easerly

2010-08-30 Thread Roelof Wobben
> Subject: Re: [Tutor] can this be done easerly > From: evert@gmail.com > Date: Mon, 30 Aug 2010 12:04:08 +0200 > CC: tutor@python.org > To: rwob...@hotmail.com > > > For a exerise I made this one :" > > > > import string > > def extract_words(s): > > """ > > >>> extract_words('Now is th

Re: [Tutor] can this be done easerly

2010-08-30 Thread Alan Gauld
"Roelof Wobben" wrote import string I know your tutorial uses the string module but you really should get out of that habit. It will not work in the newer versions of Python and is less efficient that using the builtin methods. And invariably requires more typing! :-) def extract_words(s):

Re: [Tutor] can this be done easerly

2010-08-30 Thread Steven D'Aprano
On Mon, 30 Aug 2010 07:44:06 pm Roelof Wobben wrote: > Hello, > > > > For a exerise I made this one :" > > > > import string > > def extract_words(s): [...] > But now I wonder if this can be done more easerly ? def extract_words(s):     """     >>> extract_words('Now is the time!  "Now", is the

[Tutor] Conditional attribute access / key access

2010-08-30 Thread Knacktus
Hey everyone, I have a huge number of data items coming from a database. So far there're no restrictions about how to model the items. They can be dicts, objects of a custom class (preferable with __slots__) or namedTuple. Those items have references to each other using ids. Fresh from the d

Re: [Tutor] Conditional attribute access / key access

2010-08-30 Thread Francesco Loffredo
On 30/08/2010 16.44, Knacktus wrote: Hey everyone, I have a huge number of data items coming from a database. So far there're no restrictions about how to model the items. They can be dicts, objects of a custom class (preferable with __slots__) or namedTuple. Those items have references to each

Re: [Tutor] can this be done easerly

2010-08-30 Thread ALAN GAULD
> I tried your suggestion with strip and it looks like this : > import string You don't need this now > def extract_words(s): >word= "" You dont need this > s2=[] > s = string.lower(s) > s = s.replace( "--", " ") You probably don't need this either - just add '-' to the str

Re: [Tutor] Adding to a CSV file?

2010-08-30 Thread aeneas24
I checked out the csv module and got a little further along, but still can't quite figure out how to iterate line by line properly. # This shows that I'm reading the file in correctly: input_file=open("test-8-29-10.csv","rb") for row in input_file: print row MyWord,Category,Ct,CatCt !,A,29

Re: [Tutor] Adding to a CSV file?

2010-08-30 Thread Luke Paireepinart
On Mon, Aug 30, 2010 at 12:04 PM, wrote: > I checked out the csv module and got a little further along, but still can't > quite figure out how to iterate line by line properly. >  > # But when I try to add columns, I'm only filling in some static value. So > there's something wrong with my loopin

[Tutor] Help with Object Oriented Programming

2010-08-30 Thread Tino Dai
Hi Everybody, I'm beefing up my Object-Oriented Analysis and Design - getting the gaps in my knowledge filled in through the Head First OOAD book (http://headfirstlabs.com/books/hfooad/). That book focuses on Java - is there a comparable book for Python? I have already read the Alan Gauld'

Re: [Tutor] Conditional attribute access / key access

2010-08-30 Thread Knacktus
Am 30.08.2010 17:53, schrieb Francesco Loffredo: Two questions and one doubt for you: 1- How many "generations" do you want to keep in a single item (call it dictionary or list, or record, whatever)? I mean, what if some children have children too, and some of those have more children, etc ? The

Re: [Tutor] Help with Object Oriented Programming

2010-08-30 Thread Serdar Tumgoren
I haven't read it yet myself, but the below book just came out: http://www.amazon.com/Python-3-Object-Oriented-Programming/dp/1849511268/ref=cm_cr_pr_sims_t I'm not aware of any other book that focuses exclusively on OO in Python, though you'll find good intros to the topic in a number of the "cl

Re: [Tutor] Help with Object Oriented Programming

2010-08-30 Thread Knacktus
Am 30.08.2010 20:13, schrieb Tino Dai: Hi Everybody, I'm beefing up my Object-Oriented Analysis and Design - getting the gaps in my knowledge filled in through the Head First OOAD book (http://headfirstlabs.com/books/hfooad/). That book focuses on Java - is there a comparable book for

Re: [Tutor] can this be done easerly

2010-08-30 Thread ALAN GAULD
Ok, Looks like you need the replace() on anything that could be a separator... BTW. Did you see Steven's implementation? He used a list comprehension which is probably a little beyond your "comprehension" for now (sorry, I couldn't resist! :-) but can be translated easily back to an explicit loo

Re: [Tutor] Help with Object Oriented Programming

2010-08-30 Thread Knacktus
You could google for 1) Alex Martelli, Design Patterns He's a Pyton guru and there're some online talks (at Google and some conferences) about DP; a bit difficult to understand, well, he's guru ;-) 2) http://www.suttoncourtenay.org.uk/duncan/accu/pythonpatterns.html I like that one. Also, the

Re: [Tutor] Help with Object Oriented Programming

2010-08-30 Thread Alan Gauld
"Tino Dai" wrote I'm beefing up my Object-Oriented Analysis and Design - getting the gaps in my knowledge filled in through the Head First OOAD book I don't know it although I've seen a couple of others in the series. My recommendations for general OOAD books are: Timothy Budd - OOP

[Tutor] Newbie - regex question

2010-08-30 Thread Sam M
Hi Guys, I'd like remove contents between tags that matches pattern "WORD1" as follows: Change "stuff word1-emai...@domain.com more stuff word1-emai...@domain.com still more stuff word2-emai...@domain.com stuff after WORD2 word1-emai...@domain.com" To "stuff more stuff still more s

Re: [Tutor] Newbie - regex question

2010-08-30 Thread Hugo Arts
On Mon, Aug 30, 2010 at 10:52 PM, Sam M wrote: > Hi Guys, > > I'd like remove contents between tags that matches pattern "WORD1" > as follows: > > Change > "stuff word1-emai...@domain.com more stuff > word1-emai...@domain.com still more stuff > word2-emai...@domain.com stuff after WORD2 > word1-e

Re: [Tutor] Newbie - regex question

2010-08-30 Thread Serdar Tumgoren
To make a qualifier non-greedy, > simply add an asterix at its end: > > r'WORD1-.*?' > > Hugo explains this nicely, but I just wanted to make one minor correction -- the non-greedy qualifier is the question mark AFTER an the asterisk (which is what Hugo's code shows but I believe he accidentally

Re: [Tutor] Newbie - regex question

2010-08-30 Thread bob gailer
On 8/30/2010 4:52 PM, Sam M wrote: Hi Guys, I'd like remove contents between tags that matches pattern "WORD1" as follows: Change "stuff word1-emai...@domain.com more stuff word1-emai...@domain.com still more stuff word2-emai...@domain.com stuff after WORD2 word1-emai...@domain.com" To

Re: [Tutor] Newbie - regex question

2010-08-30 Thread Hugo Arts
On Tue, Aug 31, 2010 at 12:02 AM, Serdar Tumgoren wrote: >  To make a qualifier non-greedy, >> >> simply add an asterix at its end: >> >> r'WORD1-.*?' >> > > Hugo explains this nicely, but I just wanted to make one minor correction >  -- the non-greedy qualifier is the question mark AFTER an the a

Re: [Tutor] Newbie - regex question

2010-08-30 Thread Marc Tompkins
On Mon, Aug 30, 2010 at 2:56 PM, Hugo Arts wrote: > To solve, we have the non-greedy patterns. They eat not as much > possible, but as little as possible. To make a qualifier non-greedy, > simply add an asterix at its end: > > r'WORD1-.*?' > > I would also like to offer one small correction: an a

[Tutor] __new__ over __init__

2010-08-30 Thread Payal
Hi all, Can someone please give a very simple example of using __new__ wherein __init__ cannot be used? With warm regards, -Payal -- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman

Re: [Tutor] __new__ over __init__

2010-08-30 Thread Peter Otten
Payal wrote: > Can someone please give a very simple example of using __new__ wherein > __init__ cannot be used? Subclasses of immutable types, e. g. tuple: >>> class A(tuple): ... def __init__(self, a, b): ... pass ... >>> a = A(1,2) Traceback (most recent call last): File "",