String manipulation in scripts

I am wondering if I am loosing my mind? Cannot get this to work

[color=#0080FF]import app, system

keyCode = ‘020-250’ #system.tag.getTagValue(’[Client]Tracking/AccessCode’)

length = len(keyCode)
print “”
print “Keycode Length -”,length
if length < 9:
loop = 9 - length
print “Missing -”,loop
code = right(keycode, 3)

if length >= 9:
system.tag.writeToTag("[Client]Tracking/Timer_Enable", 1)
print “Key code -”,keyCode
print “Jump to app.KeyCode.code”
app.KeyCode.code(keyCode)[/color]

I am getting an error “NameError: name ‘right’ is not defined”. I thought you could user string manipulation in scripts not just expressions?

No, you can’t use any expression functions in the scripting language, they’re totally separate.

Try some of the python string manipulations available instead: docs.python.org/release/2.5.2/l … thods.html

Use Python’s slicing notation to cut up strings any way you want.

Here’s your code with proper string slice and logic:

import app, system
keyCode = '020-250' #system.tag.getTagValue('[Client]Tracking/AccessCode')
length = len(keyCode)
print ""
print "Keycode Length -",length
if length < 9:
	loop = 9 - length
	print "Missing -",loop
	#code = right(keycode, 3)
	code = keyCode[-3:]
else:
	system.tag.writeToTag("[Client]Tracking/Timer_Enable", 1)
	print "Key code -",keyCode
	print "Jump to app.KeyCode.code"
	app.KeyCode.code(keyCode)