Python Forum
Code taking too much time to process
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code taking too much time to process
#11
(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
Reply
#12
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Process finished with exit code 137 (interrupted by signal 9: SIGKILL) erdemath 2 9,540 Apr-18-2022, 08:40 PM
Last Post: erdemath
  Speed up code with second process help samuelbachorik 0 1,411 Sep-04-2021, 09:31 AM
Last Post: samuelbachorik
  Assistance with running a few lines of code at an EXACT time nethatar 5 3,253 Feb-24-2021, 10:43 PM
Last Post: nilamo
  Stumped by my own code (ratio & epoch-time calculation). MvGulik 2 2,139 Dec-30-2020, 12:04 AM
Last Post: MvGulik
  What is the run time complexity of this code and please explain? samlee916 2 2,298 Nov-06-2020, 02:37 PM
Last Post: deanhystad
  process finished with exit code -1073741819 (0xC0000005) GMCobraz 8 5,411 Sep-01-2020, 08:19 AM
Last Post: GMCobraz
  The count variable is giving me a hard time in this code D4isyy 2 1,969 Aug-09-2020, 10:32 PM
Last Post: bowlofred
  Having a hard time combining two parts of code. Coozeki 6 3,090 May-10-2020, 06:50 AM
Last Post: Coozeki
  kill thread or process asap, even during time.sleep nanok66 4 2,932 Apr-29-2020, 10:13 AM
Last Post: nanok66
  How to avoid open and save a url every time I run code davidm 4 2,651 Mar-03-2020, 10:37 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020