Note that there are some explanatory texts on larger screens.

plurals
  1. POReading data from specially formatted text file
    primarykey
    data
    text
    <p>I am using this method, kindly suggested by Ashwini Chaudhary, to assign data to a dictionary from a text file that is in a specific format.</p> <pre><code>keys = map(str.strip, next(f).split('Key\t')[1].split('\t')) words = map(str.strip, next(f).split('Word\t')[1].split('\t')) </code></pre> <p>The text file has the row title followed by values, separated by a <code>\t</code> character.</p> <p>Example 1:</p> <pre><code>Key a 1 b 2 c 3 d 4 Word as box cow dig </code></pre> <p>How would I change my code not to read all the lines in a file, but only specific ones? Extra Lines which I do not want to read should just be ignored:</p> <p>Example 2 - ignore <code>LineHere</code> and <code>OrHere</code> rows:</p> <pre><code>LineHere w x y z Key a 1 b 2 c 3 d 4 OrHere 00 01 10 11 Word as box cow dig </code></pre> <p>Or if I wanted to have the possibility of reading a line titled 'Word' XOR 'Letter', whichever one happens to be in the file. So the code to scan Examples 1 or 2 would also be valid for:</p> <p>Example 3 - I want to read <code>Key</code> and <code>Letter</code> lines:</p> <pre><code>LineHere w x y z Key a 1 b 2 c 3 d 4 OrHere 00 01 10 11 Letter A B C D </code></pre> <p>Please feel free to comment with question criticisms and I'll be happy to rephrase/clarify the question.</p> <p>As a reference, the precursor <a href="https://stackoverflow.com/questions/17431108/what-is-the-most-efficient-way-to-match-keys-from-a-dictionary-to-data-in-text-f">question</a> is linked here</p> <p>Many thanks,</p> <p>Alex</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload