Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT:</strong></p> <p>Ok, this is for your FIRST question. From what I understand, you are wanting a function that will return the number of cells in your table. This number does not include the names of people in the rows, and does not include the first row at all. If I understand correctly, then this should work:</p> <p>If table is:</p> <pre><code>Name,Gender,Age,Salary,Height Menny, M, 1, 1, 1 James, J, 2, 2, 2 Sami, S, 3, 3, 3 </code></pre> <p>Then number of cells is <code>'12'</code>... so:</p> <p>Example:</p> <pre><code>class Table: def __init__(self, path, sep): try: with open(path) as f: read_file = f.read() # will auto close the file after the read except: print "cannot create a table from this file" return self.table = read_file.split('\n') # self.table will make this easier self.table = [self.table[i].split(sep) for i in range(len(self.table))] # does the same as your for loop if len(self.table) &gt; 0: for i in range(len(self.table[0])): if self.table[0][i] in self.table[0][0:i]: raise ValueError row_names = [] for i in range(1,len(self.table)): if len(self.table[i]) != len(self.table[0]): raise ValueError if self.table[i][0] in row_names: raise ValueError row_names.append(self.table[i][0]) # now a function that could return the table length def get_num_cells(self): # essentially you sum each item in row[1:] for table[1:] return sum((sum(1 for i in range(1, len(self.table[0])))) for i in range(1,len(self.table))) </code></pre> <p>Using <code>self.table</code> will make this easier, as you don't have to include it in the other function args, as above in <code>get_num_cells</code>, I just used <code>self.table</code> without putting it in the args of the function.</p> <p>To call this function you would do the following:</p> <pre><code>app = Table(path, sep) app.get_num_cells() # this code would be placed at the end of your file, and not inside the class </code></pre> <p>Example:</p> <pre><code>class Table() __init__(self, path, sep): etc. etc.etc.etc. # now the code to create an instance of Table and call a method here like this app = Table(path, sep) # path would be a filepath "C:/etc./file.txt", and sep = "," etc. app.get_num_cells() </code></pre> <p>For your other questions, I am not entirely sure what you want yet, but if you write again in the comments for this, I will try. Please let me know if this works for you.</p>
    singulars
    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. 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