Forum Discussion

UnderTest's avatar
UnderTest
Occasional Contributor
8 years ago
Solved

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.

 

  • 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"]
    ...

2 Replies

  • baxatob's avatar
    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"]
    ...