python parsing question from a python newbie (though coding for 10 years)

holger krekel pyth at devel.trillke.net
Mon Feb 3 16:54:20 EST 2003


Alex Martelli wrote:
> Pat McGroin wrote:
> 
> > I need to take a string and parse\split\breakup the string into each
> > seperate character into an array.  The only part I don't know is how
> > to split into seperate chars, could someone please give me a quick 1
> > line of code answer?
> 
> If you truly want an array, you'll need two lines of code, because
> array is not a built-in, in Python -- you have to import it from
> the Python standard library.  So:
> 
> >>> import array
> >>> array.array('c','ciao')
> array('c', 'ciao')
> >>>
> 
> If, as is more likely, you want a list, not an array, then you
> do indeed need just one line:
> 
> >>> list('ciao')
> ['c', 'i', 'a', 'o']
> >>>

Or maybe Pat simply wants to do

    for c in 'ciao':
        # work on each character 

but doesn't know that both strings and unicode are viewed as
*sequences* of characters.   Isn't this feature great?  :-)

    holger


--
"We haven't had a flamewar in c.l.py for a few hours ..." 
(Aahz on c.l.py)






More information about the Python-list mailing list