Why does the except: statement error

I am printing TagValuePLC and TagValueNum

But then why wouldn't these subsequent print statements show up?

		print "PLC=" + str(TagValuePLC)
		print "Num=" + str(TagValueNum)
		print "got here"

this seems strange

I tried this and it still works fine, it never goes past the if statement

# Grab tag values 
tagPaths = 'PLC_NUMBER','OUTPUT_NUMBER'
values = system.tag.readBlocking(tagPaths)
TagValuePLC = values[0].value
TagValueNum = values[1].value
print values
print "PLC=" + str(TagValuePLC)
print "Num=" + str(TagValueNum)
#continue if tag values valid
if TagValuePLC is not None and TagValueNum is not None:
	print "got here"
	
	#if negative add to overflow index to check at end
	if TagValuePLC <0 and TagValueNum <0 and TagValueNum < TagValuePLC:
		overflowIndex.append[index]
    
    #get input Number based on index value (ignore overflow till later)
	if index <= lastFixed:
		Input_Number = index/10
	else:
		Input_Number = 0
    
	updateString = "UPDATE TGMS_InputDBAction SET Output_PLC =  ?, Output_Number = ? OUTPUT DELETED.Output_PLC, DELETED.Output_Number WHERE UniqueActionID = ?"
	updateArgs = [TagValuePLC, TagValueNum, UniqueActionID] 
	insertString = "INSERT INTO TGMS_InputDBAction (ActionID, Input_PLC, Input_Number, Output_PLC, Output_Number) Values (?,?,?,?,?)"
	insertArgs = [index, PLC, Input_Number, TagValuePLC, TagValueNum]
	try:
		DBvalues = system.db.runPrepQuery(updateString, updateArgs, DB)
		DBValuePLC = DBvalues.getValueAt(0,0)
		DBValueNum = DBvalues.getValueAt(0,1)
		if DBValuePLC != TagValuePLC or DBValueNum != TagValueNum:
		    updatecount += 1
		    updated = 1
		    #set values to str for audit log
		    OldValue = "PLC-"+str(DBValuePLC)+" Num-"+ str(DBValueNum)
		    NewValue = "PLC-"+str(TagValuePLC)+" Num-"+ str(TagValueNum)
		    ColName = "Output PLC/Number Updated"

	except:
		print "I did get to the except"
		system.db.runPrepUpdate(insertString, insertArgs, DB)
		updatecount += 1
		updated = 1
	    #set values to str for audit log
		OldValue = "inserted row"
		NewValue = "PLC-"+str(TagValuePLC)+" Num-"+ str(TagValueNum)
		ColName = "Output PLC/Number Updated"
    
	if updated == 1:						#add entry to audit log		
	    auditQuery = "INSERT INTO TGMS_AuditInputAction (ModifiedUniqueActionID, OldValue, NewValue, ColumnChanged, TagPath) VALUES (?,?,?,?,?)"
	    auditArgs = UniqueActionID, OldValue, NewValue, ColName, basePath
	    system.db.runPrepUpdate(auditQuery, auditArgs, DB)			
	    updated = 0

output

[[null, Bad_NotFound("Path '[default]PLC_NUMBER' not found."), Tue Aug 29 16:51:45 EDT 2023 (1693342305436)], [null, Bad_NotFound("Path '[default]OUTPUT_NUMBER' not found."), Tue Aug 29 16:51:45 EDT 2023 (1693342305436)]]
PLC=None
Num=None

Undid all my Tab out spacing and redid it. Not sure where it was but something got messed up with indents.

Working now.

1 Like

I noticed that when I copied the script into my console, I had to redo the indentation. I'm surprised it would work for you as is, I couldn't even run it without fixing it.

Ah, yep, there's a mix of tabs and spaces in here...

which is odd since I NEVER use space. Silicon Valley (show) told me that space was BAD :slight_smile:

1 Like

For posterity, I'll point out that the editor does have a setting to show whitespace:

Admittedly, it was not my first thought for the root cause of the issue until I walked through it with Cody.

What we're preemptively thinking of as a "solution" is to add smarts to the code editor such that it warns on mixed tab and space indentation. It's technically allowed in Python 2, but should pretty much never be used and is even explicitly prevented in Python 3.

6 Likes

When is ignition upgrading python version?

Well, Jython 3 doesn't exist, so that's a pretty big impediment :slight_smile:

Basically: We'll take on the enormous pain of providing (one or more) replacements or alternatives to Jython 2 once a suitable alternative exists. There is no alternative that meets all public and private criteria available right now, though we're keeping a close eye on a few possibilities.

3 Likes