Code Monkey home page Code Monkey logo

pythonic.swift's Introduction

Pythonic.swift

Pythonic.swift is a Swift library implementating selected parts of Python's standard library and making them available to your Swift code.

import Pythonic allows you to write Python flavored code such as:

#!/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

See the test suite Pythonic-test.swift for more examples. Questions? Get in touch on Twitter @practicalswift.

Getting started

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

Contributing

Code contributions are more than welcome! This is the quick guide to contributing:

  1. Fork the project
  2. Implement function foo from the Python standard library
  3. Add a test case for foo in Pythonic-test.swift
  4. Make sure the test case passes in both Python and Swift by running make test
  5. Submit a pull request
  6. Repeat until we're done :-)

pythonic.swift's People

Contributors

practicalswift avatar hewigovens avatar

Watchers

James Cloos avatar david k. de jesus avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.