2

I've a file .ods with 10 rows in each row a number from 0 to 9. I need to assert a certain value for each row like whether this number is even or odd. I wrote some code like this:

import pyexcel_ods as pe
from pyexcel_ods import save_data
from pyexcel_ods import get_data
file = pe.get_data("file.ods")
for row in range (1, 10):
    if (row == 2) or (row == 4) or (row == 0):  
        file.add_column = ["even"]      
        print ("well done")
sheet.update()
pe.save_data("file.ods", file)

It works well and prints two (well done) statements. But when I open the file after that I didn't find any update ( id doesn't write "even" in the file). How to write this value in certain column for the even numbers? It also deletes any cell with number 0 like in the two images attached:

Before running the script:

before running the script

After running the script:

here after running the script

Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
TAM.G
  • 85
  • 1
  • 9
  • your script in the question won't work. please run flake8 on it. – chfw May 05 '17 at 12:23
  • many thanks ,, i got it worked and this is what I've done import pyexcel_ods3 as pe from pyexcel_ods3 import save_data from pyexcel_ods3 import get_data file_name = "file.ods" sheet_name = "name of sheet" file = pe.get_data(file_name) sheet1 = file[sheet_name] for row in range(len(sheet1)): for col in range(len(sheet1[row])): print(sheet1[row][col], end=" ") print() ''' # change for row in range(len(sheet1)): if sheet1[row][0] % 2 == 0: sheet1[row].append("even") else: sheet1[row].append("odd") save_data(file_name, file) – TAM.G May 06 '17 at 10:31
  • @sardar Usama i got a notfication that you edited my question .. is it possible to edit others' questions ?!! – TAM.G Aug 26 '17 at 23:43
  • Once you reach 2k reputation, you can edit any question. With less than 2k, your edit will go in the review queue, if it gets approved, your edit will be applied. However, if you disagree with someone else' edit of your question, you can always edit back or improve it. Also please don't post an answer in the comments section. Post the answer as *an answer* with explanation of how it works. – Sardar Usama Aug 27 '17 at 10:43

0 Answers0