This quick tutorial will get you up and running with Python Abseil. Please see the Programming Guides for details about specific modules.
PrerequisitesRunning the Abseil code within this tutorial requires the following:
pip
Note: this Quickstart uses Bazel as the official build system for Abseil, which is supported on most major platforms (Linux, Windows, MacOS, for example) and compilers. The Abseil source code assumes you are using Bazel and contains `BUILD.bazel` files for that purpose.
To install the Abseil Python package, simply run:
Or you can install from source via the instructions on github.
Creating and Running a ScriptHere’s an example hello.py
script that takes a user name and an optional integer specifying the number of times to print the greeting.
from absl import app
from absl import flags
FLAGS = flags.FLAGS
flags.DEFINE_string("name", None, "Your name.")
flags.DEFINE_integer("num_times", 1,
"Number of times to print greeting.")
# Required flag.
flags.mark_flag_as_required("name")
def main(argv):
del argv # Unused.
for i in range(0, FLAGS.num_times):
print('Hello, %s!' % FLAGS.name)
if __name__ == '__main__':
app.run(main)
Running with Bazel
Now you can build and run your script using Bazel. To do this, you will need a WORKSPACE
file (simply adding an empty file named WORKSPACE
in your Bazel base directory is fine for this exercise) and a BUILD
file with this build rule:
py_binary(
name = "hello",
deps = [],
srcs = ["hello.py"],
)
You can then build and run your target:
$ cd /WORKSPACE_ROOT/
$ bazel build :hello
..................
$ bazel-bin/hello --name=Daenerys
Hello, Daenerys!
Or alternatively you can run your application via a single run
command:
$ bazel run :hello -- --name=Daenerys
For more information about Bazel Python Build Rules, consult the Bazel Documentation for Python
What’s NextRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4