- Where Developers Learn, Share, & Build Careers


Open a yaml file to read

Search the path stored in that path

will always be in the second row of the file

  Location: !! Python / Unicode '[path here]'   

The fastest way to do this is to object only:

  Line [28: -1]   

But it only works when you are absolutely sure that the line will actually be in that format - there is no difference in white space, etc. And of course you have to make sure that you have found the right line; If line 2 is a comment and line 3 is the real line, and you try to parse the comment on it, you will get the right part of the comment and it seems that this is a way.

A more robust and flexible solution might be to use a regexp:

  re.match (r ". * '(. *)' ', Line) .group (1)   

or:

  again match (r "Location: \ s !! Python / Unicode \ s' (. *) '', Q) .group (1)   

one ?? | e.t.c. What exactly do you want to use depends on the type of variety you want to allow, and what you want to protect from.

But in fact, if you want to parse YAML, why not just use a YAML parser?

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -