[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: string / split method on ASCII code?

Tim Chase

3/12/2008 8:56:00 PM

> I have these annoying textilfes that are delimited by the ASCII char for <<
> (only its a single character) and >> (again a single character)
>
> Their codes are 174 and 175, respectively.
>
> My datafiles are in the moronic form
>
> X<<Y>>Z
>
> I need to split on those freaking characters. Any tips on how to make split
> work with these things?

If it were a single character, you could just use

s.split(chr(174))

However, since you need to split on multiple characters, you can use

import re
splitter_re = re.compile(chr(174) + '|' + chr(175))
for line in file(FILENAME):
parts = splitter_re.split(line)
do_something(parts)

and then go find a large blunt object with which to bludgeon the
creator of the file... :)

They aren't exactly ascii characters (0-127), but the above
should at least do the trick.

-tkc


4 Answers

Aaron Brady

3/12/2008 10:05:00 PM

0

>    import re
>    splitter_re = re.compile(chr(174) + '|' + chr(175))
>    for line in file(FILENAME):
>      parts = splitter_re.split(line)
>      do_something(parts)
>
> and then go find a large blunt object with which to bludgeon the
> creator of the file... :)

p>> creator= CreatorOfTheFile()
p>> creator.bludgeon
<bound method CreatorOfTheFile.bludgeon of <__main__.CreatorOfTheFile
object at [snip]>>
p>>

mr.rapidan

11/20/2011 1:19:00 PM

0

What do people think? Does it seem true that non-violent protest, which we hold dear as the proper agent for change, works great for civil rights evolution, for social change - when the goal is to bring the seed of consciousness to full-bloom in the normal folks who are standing in the way of human progress solely for cultural reasons. But when it comes to truly changing the economic power structure, non-violent protest is really just a way to sell more product.

avebury1

11/21/2011 5:42:00 PM

0

On Nov 20, 7:20 am, "dr.narcolepsy" <jmi...@gmail.com> wrote:
> On Sunday, November 20, 2011 2:06:57 AM UTC-5, aveb...@live.com wrote:
> >   I am REALLY becoming sick of the ignorance and complacency of
> > humanity.
> >  We have the right to assemble peaceably.
> >  Standing up for our rights, as defined in the Constitution as being
> > self evident, is not "hippie bullshit."
> >  I think we are coming dangerously close to a recreation of the French
> > revolution we're we chop the heads off of the elitist assholes.
> >  I'm ready to man the guillotine.
>
> Yes, this feeling seems to be brewing . . .  but, are you prepared to die, yourself, in pursuit of change? For unless you and others are, not much is going to change.  A few of the more articulate occupiers might get PR spots with "edgy" companies or non-profits . . .
>
> I've yet to see any politicians openly and eagerly court the occupiers & declare that they believe in and will represent their views in a head-on way.

We all die, but did anything change while we were here?

band beyond description

11/21/2011 6:03:00 PM

0

On 2011-11-21 23:41:39 +0600, avebury1@live.com said:

> On Nov 20, 7:20??am, "dr.narcolepsy" <jmi...@gmail.com> wrote:
>> On Sunday, November 20, 2011 2:06:57 AM UTC-5, aveb...@live.com wrote:
>>> ?? I am REALLY becoming sick of the ignorance and complacency of
>>> humanity.
>>> ??We have the right to assemble peaceably.
>>> ??Standing up for our rights, as defined in the Constitution as being
>>> self evident, is not "hippie bullshit."
>>> ??I think we are coming dangerously close to a recreation of the Frenc
> h
>>> revolution we're we chop the heads off of the elitist assholes.
>>> ??I'm ready to man the guillotine.
>>
>> Yes, this feeling seems to be brewing . . . ??but, are you prepared to d
> ie, yourself, in pursuit of change? For unless you and others are, not much
> is going to change. ??A few of the more articulate occupiers might get PR
> spots with "edgy" companies or non-profits . . .
>>
>> I've yet to see any politicians openly and eagerly court the occupiers &
> declare that they believe in and will represent their views in a head-on wa
> y.
>
> We all die, but did anything change while we were here?


well said. or: what footprints are we leaving on the planet?