-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.swift
39 lines (29 loc) · 910 Bytes
/
main.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Swiftpy
initPython()
evalStatement("print 'hello world'")
let hello:PythonString = "hello python fuction"
let upperHello = hello.call("upper")
print(upperHello)
let defLeftPad = "def leftPad(str,len,fillchar):\n" +
" return str.rjust(len,fillchar)"
evalStatement(defLeftPad)
let leftPadStr:PythonString = "leftPad"
let n:PythonInt = 10
let fillChar:PythonString = "j"
let leftPadded = call("leftPad",args: leftPadStr, n, fillChar)
print(leftPadded)
let evalStr = eval("\"look! EVIL\"")
print(evalStr)
let addStr = eval("1 + 1")
print(addStr)
let defFoo = "class Foo:\n" +
" def __init__(self):\n" +
" self.bar = 'i am an ivar'"
evalStatement(defFoo)
let foo = eval("Foo()")
let bar = foo.attr("bar")
print(bar)
let newBarVal:PythonString = "i'm the new bar"
foo.setAttr("bar", value:newBarVal)
let newBar = foo.attr("bar")
print(newBar)