GitHub - hewigovens/Pythonic.swift: Pythonic tool-belt for Swift – a Swift implementation of selected parts of Python standard library.
Pythonic.swift is a Swift library implementating selected parts of Python's standard library and making them available to your Swift code.
#!/usr/bin/env xcrun swift -i -I .
import Pythonic
if re.search("^foo", "foobar") {
println(["foo", "bar", "zonk"].index("foo")) // 0
println(["foo", "bar", "zonk"].count("bar")) // 1
println(["foo", "bar", "zonk"].count("zoo")) // 0
}
if any(["foo", "bar", "zonk"]) {
println(chr(ord("a"))) // a
}
var strings = ["foo", "bar"]
println(":".join(strings)) // foo:bar
if strings {
println(strings[0]) // foo
}
if len(strings) == 2 {
println(strings[1].upper()) // BAR
println(strings[1].split("a")) // ["b", "r"]
}
var greeting = " hello pythonista "
if greeting.strip().startswith("hello") {
println(greeting.strip().title()) // Hello Pythonista
}
var numbers = [1, 2, 3, 4, 5]
println(sum(numbers)) // 15
println(max(numbers)) // 5
git clone https://github.com/practicalswift/Pythonic.swift.git
cd Pythonic.swift/src/
make
make test
mkdir my-pythonic-app/
cd my-pythonic-app/
cp ../Pythonic.swiftdoc ../Pythonic.swiftmodule ../libPythonic.dylib .
cat << EOF > my_pythonic_app.swift
#!/usr/bin/env xcrun swift -I . -i
import Pythonic
assert(" hello ".strip() == "hello")
println("This feels really.. Pythonic!")
EOF
chmod +x my_pythonic_app.swift
./my_pythonic_app.swift
Code contributions are more than welcome! This is the quick guide to contributing: