Python-Livecode Cheat Sheet Page 3

ADVERTISEMENT

Operators
Operators are ways of combining values such as boolean values, numbers or strings, to
produce other values.
# Logical
// Logical
true and false == false
true and false is false
true or false == true
true or false is true
!false == true
not false is true
# String
// String
"foo" + "bar" == "foobar"
"foo"
&
"bar"
is
"foobar"
strs = ['foo','bar']
"foo"
&&
"bar"
is
"foo bar"
' '.join(strs) == "foo bar"
"str"
begins with
"st"
"str".startswith("st")
"str"
ends with
"g"
"str".endswith("g")
// Chunks
# Chunks
char
5
of
"str"
is
"n"
"str"[4:5] == "n"
item
3
of
"a,b,c"
is
"c"
word
1
of
"hi there"
is
"hi"
items = "a,b,c".split(",")
line
2
of
"a"
&
return
&
"b"
is
"b"
items[2] == "c"
// Compound chunks
words = "hi there".split(" ")
char
1
of item
1
of line
1
of
"a,b,c"
is
"a"
words[0] == "hi"
lines = "a\nb".split("\n")
lines[2] == "b"
lines = "a,b,c".split("\n")
items = lines[1].split(",")
items[1][0:1] == "a"
Files & Processes
These examples show how to read from and write to files and processes.
open(tPath).read()
get
url("file:/"
& tPath)
open(tPath).write("")
put
""
into
url("file:/"
& tPath)
process = subprocess.Popen([tProc],
open
process
tProc
stdout=subprocess.PIPE)
read
from process
tProc
for
5
while True:
close
process
tProc
process.wait()
data = process.stdout.read(5)
if data:
break

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 4