[EMAIL PROTECTED] wrote:
> hi
> i have some output that returns a lines of tuples eg
>
> ('sometext1', 1421248118, 1, 'P ')
> ('sometext2', 1421248338, 2, 'S ')
> and so on
>
>
If the braces are always at the begining and at the end of the string,
you could also use:
>>> "('sometext1
[EMAIL PROTECTED] wrote:
> hi
> i have some output that returns a lines of tuples eg
>
> ('sometext1', 1421248118, 1, 'P ')
> ('sometext2', 1421248338, 2, 'S ')
> and so on
>
>
> I tried this
> re.sub(r" '() ",'',str(output)) but it only get rid of the ' and not
> the braces. I need to write
[EMAIL PROTECTED] wrote:
> i have some output that returns a lines of tuples eg
>
> ('sometext1', 1421248118, 1, 'P ')
> ('sometext2', 1421248338, 2, 'S ')
> and so on
>
>
> I tried this
> re.sub(r" '() ",'',str(output)) but it only get rid of the ' and not
> the braces. I need to write the
As mentioned in the thread, it makes sense to build the desired output
you want from the tuple, rather than converting the tuple to a string
and then doing replace operations on the string.
If you do want to go the replace route, you don't need the power of
regex substitutions for what you are
r=re.compile(r"(\(')|( '\))|'")print r.sub('',str(output))On 8 Feb 2006 18:35:01 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
hii have some output that returns a lines of tuples egtr('sometext1', 1421248118, 1, 'P ')('sometext2', 1421248338, 2, 'S ')and so onI tried thisre.sub(r" '() ",
', '.join(map(str,output))
--
http://mail.python.org/mailman/listinfo/python-list
hi
i have some output that returns a lines of tuples eg
('sometext1', 1421248118, 1, 'P ')
('sometext2', 1421248338, 2, 'S ')
and so on
I tried this
re.sub(r" '() ",'',str(output)) but it only get rid of the ' and not
the braces. I need to write the output to a file such that
sometext1, 142