[Tutor] Another parsing question
kent37 at tds.net
Sat Mar 31 20:27:21 CEST 2007
Jay Mutter III wrote:
> I have the following that I am using to extract "numbers' from a file
> which yields the following
> [('1', '337', '912')]
> So what do i have above ? A list of tuples?
Yes, each line is a list containing one tuple containing three string
> How do I send the output to a file?
When you print, the values are automatically converted to strings by
calling str() on them. When you use p2.write(), this conversion is not
automatic, you have to do it yourself via
You can also tell the print statement to output to a file like this:
print >>p2, jay
> Is there a way to get the output as
> 1337912 instead of [('1', '337', '912')] ?
In : jay=[('1', '337', '912')]
jay is the tuple alone:
In : jay
Out: ('1', '337', '912')
Join the elements together using an empty string as the separator:
In : ''.join(jay)
More information about the Tutor