Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the general case, this would be really, really hard. But we can see if they've made it any easier for us. We can read in a line and look at it:</p> <pre><code>In [31]: first_line = open("toyota.dot").readline() In [32]: print repr(first_line) ' 1\t958164\tTOYOTA MOTOR CORPORATION\tTOYOTA\tLAND CRUISER\t1994\t\t19941223\tN\t0\t0\tSERVICE BRAKES, HYDRAULIC:ANTILOCK\tARNOLD \tCA\tJT3DJ81W8R0\t19950103\t19950103\t\t\tABS SYSTEM FAILURE, AT 20MPH. TT\tEVOQ\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tV\t\n' </code></pre> <p>See all those <code>\t</code> symbols? We're in luck -- the columns are separated by tabs! So one way is to use the <code>.split()</code> method on the lines to break them into columns:</p> <pre><code>In [33]: first_line.split("\t") Out[33]: [' 1', '958164', 'TOYOTA MOTOR CORPORATION', 'TOYOTA', 'LAND CRUISER', '1994', [... etc ...] '\n'] </code></pre> <p>and we can then extract columns:</p> <pre><code>In [34]: first_line.split("\t")[11] Out[34]: 'SERVICE BRAKES, HYDRAULIC:ANTILOCK' In [35]: first_line.split("\t")[12] Out[35]: 'ARNOLD ' </code></pre> <p>and get rid of the spaces.</p> <pre><code>In [36]: first_line.split("\t")[12].strip() Out[36]: 'ARNOLD' </code></pre> <p>You can use the </p> <pre><code>with open("toyota.dot") as data: for line in data: parts = line.split("\t") </code></pre> <p>pattern to iterate over the lines, and the rest you should be able to piece together. </p> <p>[Aside: I'd actually use a <code>csv.reader</code> with <code>delimiter="\t"</code>, but that's probably a little beyond what the teacher is after.]</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    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