Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

General

Python

Groovy

Code Block
repr(x)
Code Block
x.inspect(), x.dump()
Code Block
x.y if x else None
Code Block
x?.y
Code Block
"%(foo)s" % locals()
Code Block
"${foo}"

Lists

Python

Groovy

Code Block
not x
Code Block
!x
x.empty
Code Block
len(x)
Code Block
x.size()
Code Block
for item, idx in enumerate(x): ...
Code Block
x.eachWithIndex { item, idx -> ... }

Maps

Python

Groovy

Code Block
{}
Code Block
[:] // an empty map
Code Block
Depends:
d if used like:  for k in d:
list(d) if list needed
d[iter].keys() explicitly
Code Block
d.keySet()
Code Block
d.[iter]values()
Code Block
d.values()
Code Block
[k+1 for k in d]
Code Block
d.collect { k, v -> k+1 }
Code Block
d = dict(zip(k, v))
Code Block
k = 1..3
v = 'a'..'c'
d = [:]; k.eachWithIndex { it, i -> d[it] = v[i] }
println d // [1:"a", 2:"b", 3:"c"]

Ranges/Slices

Python

Groovy

Code Block
range(3)
Code Block
0..<3
Code Block
range(1, 3+1)
Code Block
1..3
Code Block
range(0, 10, 2)

not represented as a data type but you can use

Code Block
0.step(10, 2) {...}
Code Block
"abcdef"[3:]
Code Block
"abcdef"[3..-1]

Object access

Python

Groovy

Code Block
m = 'strip'; getattr(' ! ', m)()
Code Block
m = 'trim'; ' ! '."$m"()
Code Block
args = ('a', 2); 'abcabc'.find(*args)
Code Block
args = ['a', 2]; 'abcabc'.indexOf(*args)