[Tutor] File reading

Danny Yoo dyoo at hashcollision.org
Thu Jun 19 03:24:50 CEST 2014


On Wed, Jun 18, 2014 at 6:08 PM, Umamaheshwar Rao
<mahesh.rao78 at gmail.com> wrote:
> Hi Experts,
>
> I have a file with below format
>


Can you describe the format a little more precisely?   You're giving
examples, which is wonderful.  But the examples are missing something.

What's the output you want to get here?  Imagine that you magically
have the program you want.  What would be the ideal structure of the
output you're extracting from this file?


I am guessing that if you have content of the form:

##############################################
## Some test data, which we'll treat as a file-like object by
## using StringIO:
from StringIO import StringIO

somefile = StringIO("""this is first file operation
x-1  "all the best"
x-2  "all the best 2 next line
         check this"
x-3  "last line"
""")
##############################################


then I think you're expecting this to be parsed as a key-value store,
something like this, maybe?

##############################################
{ "x-1" : "all the best",
  "x-2" : "all the best 2 next line\n         check this",
  "x-3" : "last line" }
##############################################

Can you confirm if this is the structure of the output you'd like to
see?  Please clarify.


You need to make your expectations a bit explicit.  By saying that you
want to extract everything between x-1 and x-2, there's a bit of
ambiguity there that I'd like to avoid   By just giving us the input
as an example, there are several kinds of output you might expect to
see.  We don't want to guess.


More information about the Tutor mailing list