Re: How to do this in Python?

2009-03-21 Thread JanC
Josh Holland wrote: > How people would write a kernel in Python? Like this: http://code.google.com/p/cleese/wiki/CleeseArchitecturehttp://code.google.com/p/cleese/ ? -- JanC -- http://mail.python.org/mailman/listinfo/python-list

Re: How to do this in Python?

2009-03-21 Thread Josh Holland
Sorry, I meant to write "How *many* people ..." -- Josh Holland http://joshh.co.uk madmartian on irc.freenode.net -- http://mail.python.org/mailman/listinfo/python-list

Re: How to do this in Python?

2009-03-21 Thread Grant Edwards
On 2009-03-21, Josh Holland wrote: > If you're referring to my reply (about his pseudocode looking > like C), I hope you realise that it was tongue-in-cheek. For > the record, I intend to learn C in the near future and know it > is a very powerful language. > How people would write a kernel in P

Re: How to do this in Python?

2009-03-21 Thread Josh Holland
On Tue, Mar 17, 2009 at 08:00:51PM -0500, Jim Garrison wrote: > There's always some "trollish" behavior in any comp.lang.* > group. Too many people treat languages as religions instead > of tools. They all have strengths and weaknesses :-) If you're referring to my reply (about his pseudocode loo

Re: How to do this in Python? - A "gotcha"

2009-03-19 Thread Scott David Daniels
bieff...@gmail.com wrote: On Mar 18, 6:06 pm, Jim Garrison wrote: S Arrowsmith wrote: Jim Garrison wrote: It's a shame the iter(o,sentinel) builtin does the comparison itself, instead of being defined as iter(callable,callable) where the second argument implements the termination test and r

Re: How to do this in Python? - A "gotcha"

2009-03-19 Thread bieffe62
On Mar 18, 6:06 pm, Jim Garrison wrote: > S Arrowsmith wrote: > > Jim Garrison   wrote: > >> It's a shame the iter(o,sentinel) builtin does the > >> comparison itself, instead of being defined as iter(callable,callable) > >> where the second argument implements the termination test and returns a >

Re: How to do this in Python?

2009-03-18 Thread Jervis Whitley
> What I was wondering > was whether a similar construct was considered for a while loop or even an > if clause, because then the above could be written like this: > >  if open(filename, 'rb') as f: >      while f.read(1000) as buf: >          # do something with 'buf' > see here, and the associat

Re: How to do this in Python?

2009-03-18 Thread afriere
On Mar 18, 3:05 pm, Grant Edwards wrote: > {snip] ... If it > only going to be used once, then just do the usual thing: > > f = open(...) > while True: >    buf = f.read() >    if not buf: break >    # whatever. > f.close() +1 That's the canonical way (maybe using "with ... as" nowadays). Surel

Re: How to do this in Python? - A "gotcha"

2009-03-18 Thread Luis Zarrabeitia
Quoting Jim Garrison : > Jim Garrison wrote: > > Luis Zarrabeitia wrote: > >> On Tuesday 17 March 2009 06:04:36 pm Jim Garrison wrote: > >> with open(filename, "rb") as f: > >> for buf in iter(lambda: f.read(1000),''): > >> do_something(buf) > > > > This is the most pythonic solution

Re: How to do this in Python? - A "gotcha"

2009-03-18 Thread andrew cooke
sorry, ignore that. hit send before thinking properly. > have you looked in operators? that might avoid the need for a class. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to do this in Python? - A "gotcha"

2009-03-18 Thread andrew cooke
have you looked in operators? that might avoid the need for a class. Jim Garrison wrote: > S Arrowsmith wrote: >> Jim Garrison wrote: >>> It's a shame the iter(o,sentinel) builtin does the >>> comparison itself, instead of being defined as iter(callable,callable) >>> where the second argument

Re: How to do this in Python? - A "gotcha"

2009-03-18 Thread Jim Garrison
S Arrowsmith wrote: Jim Garrison wrote: It's a shame the iter(o,sentinel) builtin does the comparison itself, instead of being defined as iter(callable,callable) where the second argument implements the termination test and returns a boolean. This would seem to add much more generality... is

Re: How to do this in Python? - A "gotcha"

2009-03-18 Thread S Arrowsmith
Jim Garrison wrote: >It's a shame the iter(o,sentinel) builtin does the >comparison itself, instead of being defined as iter(callable,callable) >where the second argument implements the termination test and returns a >boolean. This would seem to add much more generality... is >it worthy of a PEP

Re: How to do this in Python? - A "gotcha"

2009-03-18 Thread Jim Garrison
Andrii V. Mishkovskyi wrote: Just before you start writing a PEP, take a look at `takewhile' function in `itertools' module. ;) OK, after reading the itertools docs I'm not sure how to use it in this context. takewhile() requires a sequence, and turning f.read(bufsize) into an iterable require

Re: How to do this in Python? - A "gotcha"

2009-03-18 Thread Andrii V. Mishkovskyi
On Wed, Mar 18, 2009 at 5:51 PM, Jim Garrison wrote: > Jim Garrison wrote: >> >> Luis Zarrabeitia wrote: >>> >>> On Tuesday 17 March 2009 06:04:36 pm Jim Garrison wrote: >>> with open(filename, "rb") as f: >>>    for buf in iter(lambda: f.read(1000),''): >>>        do_something(buf) >> >> This is

Re: How to do this in Python? - A "gotcha"

2009-03-18 Thread Jim Garrison
Jim Garrison wrote: Luis Zarrabeitia wrote: On Tuesday 17 March 2009 06:04:36 pm Jim Garrison wrote: with open(filename, "rb") as f: for buf in iter(lambda: f.read(1000),''): do_something(buf) This is the most pythonic solution yet. Thanks to all the responders who took time to po

Re: How to do this in Python?

2009-03-18 Thread Mel
Jim Garrison wrote: > andrew cooke wrote: >> Jim Garrison wrote: >>> I'm an experienced C/Java/Perl developer learning Python. >>> What's the canonical Python way of implementing this pseudocode? [ ... ] >> but not doing much binary i/o >> myself, i suggest: >> >> with open(...) as f: >> while (

Re: How to do this in Python?

2009-03-18 Thread Jim Garrison
Luis Zarrabeitia wrote: On Tuesday 17 March 2009 06:04:36 pm Jim Garrison wrote: with open(filename, "rb") as f: for buf in iter(lambda: f.read(1000),''): do_something(buff) This is the most pythonic solution yet. Thanks to all the responders who took time to ponder this seemingly

Re: How to do this in Python?

2009-03-18 Thread Ulrich Eckhardt
Grant Edwards wrote: > with open(filename,"rb") as f: > while True: > buf = f.read(1) > if not buf: break > # do something The pattern with foo() as bar: # do something with bar is equivalent to bar = foo() if bar: # do something with bar except

Re: How to do this in Python?

2009-03-18 Thread Tim Chase
def chunk_file(fp, chunksize=1): s = fp.read(chunksize) while s: yield s s = fp.read(chunksize) Ah. That's the Pythonesque way I was looking for. That's not pythonic unless you really do need to use chumk_file() in a lot of places (IMO, more than 3 or 4). If it only

Re: How to do this in Python?

2009-03-18 Thread Hrvoje Niksic
Luis Zarrabeitia writes: > One could use this: > > with open(filename, "rb") as f: > for buf in iter(lambda: f.read(1000),''): > do_something(buff) This is by far the most pythonic solution, it uses the standard 'for' loop, and clearly marks the sentinel value. lambda may look stra

Re: How to do this in Python?

2009-03-18 Thread bieffe62
On Mar 18, 2:00 am, Jim Garrison wrote: >  I don't want "for line in f:" because binary > files don't necessarily have lines and I'm bulk processing > files potentially 100MB and larger.  Reading them one line > at a time would be highly inefficient. > > Thanks- Hide quoted text - > > - Show quot

Re: How to do this in Python?

2009-03-17 Thread Grant Edwards
On 2009-03-18, Grant Edwards wrote: > On 2009-03-17, Jim Garrison wrote: >> I'm an experienced C/Java/Perl developer learning Python. >> >> What's the canonical Python way of implementing this pseudocode? >> >> String buf >> File f >> while ((buf=f.read(1)).length() > 0) >>

Re: How to do this in Python?

2009-03-17 Thread Grant Edwards
On 2009-03-18, Jim Garrison wrote: > Tim Chase wrote: >>> Am I missing something basic, or is this the canonical way: >>> >>> with open(filename,"rb") as f: >>> buf = f.read(1) >>> while len(buf) > 0 >>> # do something >>> buf = f.read(1

Re: How to do this in Python?

2009-03-17 Thread Grant Edwards
On 2009-03-17, Jim Garrison wrote: > I'm an experienced C/Java/Perl developer learning Python. > > What's the canonical Python way of implementing this pseudocode? > > String buf > File f > while ((buf=f.read(1)).length() > 0) > { > do something > } > >

Re: How to do this in Python?

2009-03-17 Thread Terry Reedy
Jim Garrison wrote: Ah. That's the Pythonesque way I was looking for. I knew it would be a generator/iterator but haven't got the Python mindset down yet and haven't played with writing my own generator. I'm still trying to think in purely object- oriented terms where I would override __next_

Re: How to do this in Python?

2009-03-17 Thread MRAB
Jim Garrison wrote: [snip] Ah. That's the Pythonesque way I was looking for. > FYI, the correct word is "Pythonic". "Pythonesque" refers to Monty Python. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to do this in Python?

2009-03-17 Thread Jim Garrison
andrew cooke wrote: > Jim Garrison wrote: >> I'm an experienced C/Java/Perl developer learning Python. >> >> What's the canonical Python way of implementing this pseudocode? [snip] > > embarrassed by the other reply i have read, There's always some "trollish" behavior in any comp.lang.* group.

Re: How to do this in Python?

2009-03-17 Thread Jim Garrison
Tim Chase wrote: >> Am I missing something basic, or is this the canonical way: >> >> with open(filename,"rb") as f: >> buf = f.read(1) >> while len(buf) > 0 >> # do something >> buf = f.read(1) > > That will certainly do. Since read()

Re: How to do this in Python?

2009-03-17 Thread Armin
On Tuesday 17 March 2009 19:10:20 Josh Holland wrote: > On Tue, Mar 17, 2009 at 05:04:36PM -0500, Jim Garrison wrote: > > What's the canonical Python way of implementing this pseudocode? > > > > String buf > > File f > > while ((buf=f.read(1)).length() > 0) > > { > > d

Re: How to do this in Python?

2009-03-17 Thread Luis Zarrabeitia
On Tuesday 17 March 2009 06:04:36 pm Jim Garrison wrote: > > Am I missing something basic, or is this the canonical way: > > with open(filename,"rb") as f: > buf = f.read(1) > while len(buf) > 0 > # do something > buf = f.read(1) well, a

Re: How to do this in Python?

2009-03-17 Thread Matthew Woodcraft
Jim Garrison writes: > buf = f.read(1) > while len(buf) > 0 > # do something > buf = f.read(1) I think it's more usual to use a 'break' rather than duplicate the read. That is, something more like while True: buf = f.read(1)

Re: How to do this in Python?

2009-03-17 Thread Tim Chase
Am I missing something basic, or is this the canonical way: with open(filename,"rb") as f: buf = f.read(1) while len(buf) > 0 # do something buf = f.read(1) That will certainly do. Since read() should simply return a 0-length string

Re: How to do this in Python?

2009-03-17 Thread andrew cooke
Jim Garrison wrote: > I'm an experienced C/Java/Perl developer learning Python. > > What's the canonical Python way of implementing this pseudocode? > > String buf > File f > while ((buf=f.read(1)).length() > 0) > { > do something > } > > In other words,

Re: How to do this in Python?

2009-03-17 Thread Josh Holland
On Tue, Mar 17, 2009 at 05:04:36PM -0500, Jim Garrison wrote: > What's the canonical Python way of implementing this pseudocode? > > String buf > File f > while ((buf=f.read(1)).length() > 0) > { > do something > } That looks more like C than pseudocode to me.

How to do this in Python?

2009-03-17 Thread Jim Garrison
I'm an experienced C/Java/Perl developer learning Python. What's the canonical Python way of implementing this pseudocode? String buf File f while ((buf=f.read(1)).length() > 0) { do something } In other words, I want to read a potentially large file in 100

Re: How to do this in python with regular expressions

2007-05-27 Thread snorble
On May 25, 6:51 am, Jia Lu <[EMAIL PROTECTED]> wrote: > Hi all > > I'm trying to parsing html with re module. > > html = """ > > > > DATA1DATA2DATA3 HT>DATA4 > > > DATA5DATA6DATA7DATA8 > > > """ > > I want to get DATA1-8 from that string.(DATA maybe not english words.) > Can anyone tell me h

Re: How to do this in python with regular expressions

2007-05-25 Thread Mattia Gentilini
Thorsten Kampe ha scritto: >> I'm trying to parsing html with re module. > Just don't. Use an HTML parser like BeautifulSoup Or HTMLParser/htmllib. of course you can mix those and re, it'll be easier than re only. -- |\/|55: Mattia Gentilini e 55 = log2(che_palle_sta_storia) (by mezzo) |/_| ETI

Re: How to do this in python with regular expressions

2007-05-25 Thread Mattia Gentilini
Thorsten Kampe ha scritto: >> I'm trying to parsing html with re module. > Just don't. Use an HTML parser like BeautifulSoup Or HTMLParser/htmllib -- |\/|55: Mattia Gentilini e 55 = log2(che_palle_sta_storia) (by mezzo) |/_| ETICS project at CNAF, INFN, Bologna, Italy |\/| www.getfirefox.com ww

Re: How to do this in python with regular expressions

2007-05-25 Thread Thorsten Kampe
* Jia Lu (25 May 2007 04:51:35 -0700) > I'm trying to parsing html with re module. > [...] > Can anyone tell me how to do it with regular expression in python? Just don't. Use an HTML parser like BeautifulSoup -- http://mail.python.org/mailman/listinfo/python-list

How to do this in python with regular expressions

2007-05-25 Thread Jia Lu
Hi all I'm trying to parsing html with re module. html = """ DATA1DATA2DATA3DATA4 DATA5DATA6DATA7DATA8 """ I want to get DATA1-8 from that string.(DATA maybe not english words.) Can anyone tell me how to do it with regular expression in python? Thank you very much. -- http://mail.py

RE: Any idea how to do this in Python?

2006-10-17 Thread Matthew Warren
> On 17 Oct 2006 02:56:45 -0700, Lad <[EMAIL PROTECTED]> wrote: > > > > Dennis, > > Thank you for your reply > > You say: > > >Pretend you are the computer/application/etc. How would YOU > > > perform such a ranking? > > That is what I do not know , how to perform such ranking. > > Do you have any

Re: Any idea how to do this in Python?

2006-10-17 Thread Theerasak Photha
On 17 Oct 2006 02:56:45 -0700, Lad <[EMAIL PROTECTED]> wrote: > > Dennis, > Thank you for your reply > You say: > >Pretend you are the computer/application/etc. How would YOU > > perform such a ranking? > That is what I do not know , how to perform such ranking. > Do you have any idea? The detail

Re: Any idea how to do this in Python?

2006-10-17 Thread jmdeschamps
Lad wrote: > Dennis, > Thank you for your reply > You say: > >Pretend you are the computer/application/etc. How would YOU > > perform such a ranking? > That is what I do not know , how to perform such ranking. > Do you have any idea? > > Regards, > Lad. take a piece of paper to *play* the use-cas

Re: Any idea how to do this in Python?

2006-10-17 Thread Lad
Dennis, Thank you for your reply You say: >Pretend you are the computer/application/etc. How would YOU > perform such a ranking? That is what I do not know , how to perform such ranking. Do you have any idea? Regards, Lad. -- http://mail.python.org/mailman/listinfo/python-list

Any idea how to do this in Python?

2006-10-17 Thread Lad
In a web application users can post some information. I would like to link each posting with a "weight of importance" for a user, depending on a keywords in the posting. For example, I know that a user A is interested in Nokia mobiles while user B in Siemens mobiles. So, if a user A is signed, he w