Ask a Question

Getting values from the excel file using Python

SOLVED
UnderTest
Occasional Contributor

Getting values from the excel file using Python

Hi,

 

I have an excel file with parameters under two columns.

Some cells contains no parameter (empty cells).

If value under Column1 is empty, I need the value under Column2.

 

I use:

 

 

testParams = []

while myFile.IsEOF() != True:

    if myFile.Value["Column1"] != "":
        value = myFile.Value["Column1"]
    else:
        value = myFile.Value["Column2"]

    testParams.append(value)
    myFile.Next()

 

 

But anyway I receive only the values under Column1: ["P1", "P2", None, None, None]

 

I expect T3, T4, T5 etc instead off None.

 

2 REPLIES 2
baxatob
Community Hero

Empty cell returns the None type value, however you are waiting for the empty string.

 

Try None instead of "" or do it more tricky:

 

while not myFile.IsEOF():
    value = myFile.Value["Column1"]
    value = value if value is not None else myFile.Value["Column2"]
...
UnderTest
Occasional Contributor

Many thanks @baxatob, it works!

cancel
Showing results for 
Search instead for 
Did you mean: