Python Forum

Full Version: Code taking too much time to process
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(Nov-13-2020, 02:35 PM)DeaD_EyE Wrote: [ -> ]The notice to myself was to write CONSTANS in Code in upper case (PEP8). You weren't meant.

That you can't change the content in your Excel-File should be clear.
I guess its data you get from somewhere and you've no influence of the fields/naming.
This is in 99.999% the case. + missing and wrong Data + bugs in cell datatype format

If you work with openpyxl it should do automatic conversions to Python types.

But cells with explicit text format, which have strings like "false", "NONE", "none", "true" etc. are not converted into Boolean. You get this "Keywords" as str. I think this is what you want and need.

Hi i am not chaging the excel, i am reading it and at the same same interpreting the information to write a XML script with several decisions based of combinationes predifined by the costumer.


As some fileds may be "empty" i need to check always before doing any processing if it is None or not.

I am still testing the openpyxl, i am going to try




for row in worksheet2.iter_rows(min_row=Fila_LNBTS_TEMPLATE, min_col=IndexCol_WS2, max_row=Fila_LNBTS_TEMPLATE, max_col=MaxNumCol+1):
for cell in row:
ParameterValue_WS2 = cell.value

Instead:


for IndexCol_WS2 in range(IndexCol_WS2, MaxNumCol+1):
ParameterValue_WS2 = worksheet2.cell(row=FilaTemplateID, column=IndexCol_WS2).value
Please use the [code]your code[/code] tags.
Otherwise, whitespace is removed and all indentation is lost.

Depending on how your data is organized, you can iterate column wise or row wise.
If you've now dirty data or missing values, you can check them inside the loop and you can for example skip (continue statement in the for-loop) the row or coloumn to proceed with the next valid data.

The second inner loop is maybe not what you want.

Another assumption is, that cell.value return None, if the cell is empty. For text-fields it's wrong. I get empty strings back. But cells which are formatted as Decimal, you'll get a None back, if the field was empty.
Pages: 1 2