Python Forum
Why is the line crashing program when line is false?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is the line crashing program when line is false?
#1
You say if


if not pd.isna(row['personnel.offense']):
        personnel = row['personnel.offense'].split(',')
If the first line is false then the second line is not executed.
You are correct. But if the first line in two code series is false, I do not believe
the original programmer/analyst wanted the program to crash.

I believe she just wanted the next set of python code lines to be skipped. The code that counts the number of offensive players and where they are positioned.

If that is correct the program, should not crash. It should just skip the row and continue in the loop.

It does not do that. The program crashes. How to modify the code so that it executes what the programmer originally intended, not what is actually happening.

]You alluded to the fact the there might be a formatting problem in an earlier post. I think you are right. I just do not know how to fix.

I do not want to delete the whole row because it might contain information is the other cells that could make the prediction more accurate.o

Any help appreciated. Thanks in advance.

Respectfully,

ErnestTBass
Reply
#2
If this relates to your earlier post you prevent any code that uses personnel from running if you don't set personnel. This is a bad pattern:
if a:
   b = 5
c = b * 2
Cannot use b because b may not be defined or may have the wrong value.
This is better
if a:
   b = 5
   c = b * 2
else:
   c = someothervalue
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Βad Input on line 12 Azdaghost 5 1,320 Apr-19-2025, 10:22 PM
Last Post: Azdaghost
Question [SOLVED] [Beautiful Soup] Move line to top in HTML head? Winfried 0 309 Apr-13-2025, 05:50 AM
Last Post: Winfried
  Insert command line in script lif 4 1,035 Mar-24-2025, 10:30 PM
Last Post: lif
  Entry field random pull from list, each return own line Bear1981 6 848 Feb-25-2025, 06:09 AM
Last Post: Pedroski55
  How to revert back to a previous line from user input Sharkenn64u 2 1,028 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  Pandas - error when running Pycharm, but works on cmd line zxcv101 2 2,473 Sep-09-2024, 08:03 AM
Last Post: pinkang
  Simplest way to run external command line app with parameters? Winfried 2 1,329 Aug-19-2024, 03:11 PM
Last Post: snippsat
  Printing the code line number arbiel 6 1,679 Jun-30-2024, 08:01 AM
Last Post: arbiel
  How to add multi-line comment section? Winfried 2 1,395 Jun-04-2024, 07:24 AM
Last Post: Gribouillis
Information Is it possible to multi line a Basic Function Construct line statement? If so how? BrandonKastning 7 2,033 May-23-2024, 03:02 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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