Python-Livecode Cheat Sheet

ADVERTISEMENT

Python-Livecode Cheat Sheet
Comments
Comments allow you to add explanations and annotations to your code.
# this is commented out
-- these
# are
// all
/* commented
out */
Variables
Variables are used to to store information, the stored value can be changed or accessed when
you need it.
var = "str"
local
tVar
var = 1
put
"str"
into
tVar
put
1
into
tVar
var["key"] = "val"
put
"val"
into
tVar["key"]
String Processing
These examples show how string values can be manipulated.
# General
// General
var = 'a' + var
put
"a"
before
tVar
var = var[1:]
delete
char
1
of
tVar
var.replace("_", "-")
replace
"_"
with
"-"
in
tVar
# Regex
// Regex
found = re.match('([0-9])', '1')
matchText("1", "([0-9])", tN)
is true
num = tMatch.group(1)
tN
is
1
for line in var:
filter
lines of
tVar
with regex
pattern
if re.match(pattern, line):
tPattern
filtered.push(line)
var = '\n'.join(filtered)
Custom Handlers
A custom handler is a function or command that you define yourself.
def foo(param):
function foo pParam
# return something
end foo
# foo(var)
// get foo(tVar)
command bar pParam
end bar
// bar 5

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 4