Getting values from the excel file using Python
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2016
03:17 AM
11-22-2016
03:17 AM
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.
Solved! Go to Solution.
2 REPLIES 2
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2016
03:26 AM
11-22-2016
03:26 AM
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"]
...
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2016
04:51 AM
11-22-2016
04:51 AM
Many thanks @baxatob, it works!
