In Python; How do you skip an invalid value in a 'for loop'? -


I have the set for loop to read in an X and Y values. CCV, so far is so good.

However, the .csv is 65,000 lines long! And 2000 of them are only blank lines.

How do I ignore the loop / leave the blank rows and tell the next set of values?

I've been trying to use 'release' like this ... For lines in lines: the contents of each row are delimited with a comma, array = [x.strip () to delimit x in line.split (',')] if pos == "": proceed: #set up variables x = float (pos [0]) * 10000 y = float (pos [1]) * 10000 z = 0.0

But this does not work, whenever it first goes to the empty line it adds zero to the rest and I get this error Get message ...

  valueError: Empty string for float   

Before trying to import Python I tried to remove empty rows in Apple numbers, but apparently simply to remove blank lines Some a total ball-number pain.

I also tried to snatch all the blank variables before loop, but could not even get it to work.

Any sign will be highly appreciated, but please keep it simple! (I'm new to this stuff and the more esoteric code goes to my head).

Check the parity in pos is now a list that is a list You can check that the line itself is empty:

  for lines in lines: if line.strip () == "": # one to delimit the contents of each line In the line.split (',') for comma, [x.strip ()) if x.strip ()] # Make sure you have x and y if len (pos) & lt; 2: release # variable x = float (pos [0]) * 10000 y = float (pos [1]) * 10000 z = 0.0   

When adding condition to pos , we now release empty elements.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -