Traits CLI Documentation

Size: px
Start display at page:

Download "Traits CLI Documentation"

Transcription

1 Traits CLI Documentation Release Takafumi Arakaki March 22, 2013

2

3 CONTENTS 1 Links 3 2 Installation 5 3 Dependencies 7 4 Sample 9 5 CLI base class 11 6 Utility functions 19 7 Change log v Python Module Index 23 i

4 ii

5 Traits CLI is based on Enthought s Traits library. Some benefits: Automatically set type (int/float/) of command line argument. Help string generation. Deep value configuration: e.g., --dict[ a ][ b ][ c ]=1 is equivalent to obj.dict[ a ][ b ][ c ] = 1 in Python code. Nested class configuration: e.g., --sub.attr=val is equivalent to obj.sub.attr = val in Python code. Parameter file support (ini/conf, json, yaml, etc.). Load parameter from file then set attribute. CONTENTS 1

6 2 CONTENTS

7 CHAPTER ONE LINKS Documentaions (at Read the Docs) Source code repository (at GitHub) Issue tracker (at GitHub) PyPI Travis CI 3

8 4 Chapter 1. Links

9 CHAPTER TWO INSTALLATION pip install traitscli 5

10 6 Chapter 2. Installation

11 CHAPTER THREE DEPENDENCIES traits argparse (for Python < 2.7) 7

12 8 Chapter 3. Dependencies

13 CHAPTER FOUR SAMPLE Source code: from traitscli import TraitsCLIBase from traits.api import Bool, Float, Int, Str, Enum class SampleCLI(TraitsCLIBase): Sample CLI using traitscli. Example:: %(prog)s --yes %(prog)s --string something %(prog)s --choice x # => obj.yes = True # => obj.string = string # => raise error (x is not in {a, b, c}) # These variables are configurable by command line option yes = Bool(desc= yes flag for sample CLI, config=true) no = Bool(True, config=true) fnum = Float(config=True) inum = Int(config=True) string = Str(config=True) choice = Enum([ a, b, c ], config=true) # You can have "internal" attributes which cannot be set via CLI. not_configurable_from_cli = Bool() def do_run(self): names = self.class_trait_names(config=true) width = max(map(len, names)) for na in names: print "{0:{1}} : {2!r}".format(na, width, getattr(self, na)) if name == main : # Run command line interface SampleCLI.cli() Example run: 9

14 $ python sample.py --help usage: sample.py [-h] [--choice {a,b,c}] [--fnum FNUM] [--inum INUM] [--no] [--string STRING] [--yes] Sample CLI using traitscli. Example:: sample.py --yes sample.py --string something sample.py --choice x # => obj.yes = True # => obj.string = string # => raise error (x is not in {a, b, c}) optional arguments: -h, --help show this help message and exit --choice {a,b,c} (default: a) --fnum FNUM (default: 0.0) --inum INUM (default: 0) --no (default: True) --string STRING (default: ) --yes yes flag for sample CLI (default: False) $ python sample.py --yes --choice a string : no : True fnum : 0.0 choice : a inum : 0 yes : True $ python sample.py --inum invalid_argument usage: sample.py [-h] [--choice {a,b,c}] [--fnum FNUM] [--inum INUM] [--no] [--string STRING] [--yes] sample.py: error: argument --inum: invalid int value: invalid_argument 10 Chapter 4. Sample

15 CHAPTER FIVE CLI BASE CLASS class traitscli.traitsclibase(**kwds) CLI generator base class. Usage. You will need to define: 1.Parameters (traits). When it has config=true metadata, it is configurable via command line argument. See: Defining Traits: Initialization and Validation section in Traits user manual. 2.do_run() method. This method gets no argument (except self ). Do whatever this class needs to do based on its attributes. cli() function sets attributes based on command line options and then call do_run() method. Examples To make class attribute configurable from command line options, set metadata config=true: int = Int(config=True) >>> obj = SampleCLI.cli([ --int, 1 ]) >>> obj.int 1 For dict and list type attribute, you can modify it using subscript access: dict = Dict(config=True) >>> obj = SampleCLI.cli([ --dict["k"], 1 ]) >>> obj.dict[ k ] 1 You don t need to quote string if dict/list attribute set its value trait to str-like trait: dict = Dict(value_trait=Str, config=true) >>> obj = SampleCLI.cli([ --dict["k"], unquoted string ]) >>> obj.dict[ k ] unquoted string >>> obj = SampleCLI.cli([ --dict["k"]=unquoted string ]) >>> obj.dict[ k ] unquoted string Attributes of nested class can be set using dot access: 11

16 >>> class SubObject(TraitsCLIBase): int = Int(config=True) # Here, args=() is required to initialize sub. sub = Instance(SubObject, args=(), config=true) >>> obj = SampleCLI.cli([ --sub.int, 1 ]) >>> obj.sub.int 1 Metadata for traits config [bool] If this metadata of an attribute is True, this attribute is configurable via CLI. configurable = Int(config=True) hidden = Int() >>> with hidestderr(): SampleCLI.cli([ --configurable, 1, --hidden, 2 ]) # hidden is not configurable, so it fails: Traceback (most recent call last): SystemExit: 2 >>> obj = SampleCLI.cli([ --configurable, 1 ]) >>> obj.configurable 1 >>> obj.hidden = 2 >>> obj.hidden 2 desc [string] Description of this attribute. Passed to help argument of ArgumentParser.add_argument. a = Int(desc= help string for attribute a, config=true) b = Float(desc= help string for attribute b, config=true) >>> SampleCLI.get_argparser().print_help() usage: [-h] [--a A] [--b B] optional arguments: -h, --help show this help message and exit --a A help string for attribute a (default: 0) --b B help string for attribute b (default: 0.0) cli_positional [bool] If True, corresponding command line argument is interpreted as a positional argument. int = Int(cli_positional=True, config=true) >>> obj = SampleCLI.cli([ 1 ]) # no --a here! >>> obj.int 1 cli_required [bool] Passed to required argument of ArgumentParser.add_argument int = Int(cli_required=True, config=true) 12 Chapter 5. CLI base class

17 >>> with hidestderr(): SampleCLI.cli([]) Traceback (most recent call last): SystemExit: 2 >>> obj = SampleCLI.cli([ --int, 1 ]) >>> obj.int 1 cli_metavar [str] Passed to metavar argument of ArgumentParser.add_argument int = Int(cli_metavar= NUM, config=true) >>> SampleCLI.get_argparser().print_help() usage: [-h] [--int NUM] optional arguments: -h, --help show this help message and exit --int NUM (default: 0) cli_paramfile [bool] This attribute has special meaning. When this metadata is True, this attribute indicate the path to parameter file The instance is first initialized using parameters defined in the parameter file, then command line arguments are used to override the parameters. Idioms int = Int(config=True) paramfile = Str(cli_paramfile=True, config=true) >>> import json >>> from tempfile import NamedTemporaryFile >>> param = { int : 1} >>> with NamedTemporaryFile(suffix=.json ) as f: json.dump(param, f) f.flush() obj = SampleCLI.cli([ --paramfile, f.name]) >>> obj.int 1 Get a dictionary containing configurable attributes. a = Int(0, config=true) b = Int(1, config=true) c = Int(2) >>> obj = SampleCLI() >>> obj.trait_get() == { a : 0, b : 1, c : 2} True >>> obj.trait_get(config=true) == { a : 0, b : 1} True Get a list of configurable attribute names. >>> names = SampleCLI.class_trait_names(config=True) >>> sorted(names) 13

18 [ a, b ] See Traits user manual for more information. Especially, Defining Traits: Initialization and Validation is useful to quickly glance traits API. Entry points classmethod cli(args=none) Call run() using command line arguments. When args is given, it is used instead of sys.argv[1:]. Essentially, the following two should do the same thing: $ python yourcli.py --alpha 1 >>> YourCLI.run(alpha=1) # doctest: +SKIP classmethod run(**kwds) Make an instance with args kwds and call do_run(). do_run() Actual implementation of run(). Child class must implement this method. API to access attributes classmethod config_traits(**metadata) Return configurable traits as a (possibly nested) dict. The returned dict can be nested if this class has Instance trait of TraitsCLIBase. flattendict() to get a flat dictionary with dotted keys. It is equivalent to cls.class_traits(config=true) if cls has no Instance trait. Use >>> class SubObject(TraitsCLIBase): int = Int(config=True) nonconfigurable = Int() int = Int(config=True) sub = Instance(SubObject, args=(), config=true) >>> traits = SampleCLI.config_traits() >>> traits { int : <traits.traits.ctrait at >, sub : { int : <traits.traits.ctrait at >}} >>> traits[ int ].trait_type <traits.trait_types.int object at > >>> traits[ sub ][ int ].trait_type <traits.trait_types.int object at > setattrs(attrs, only_configurable=false) Set attribute given a dictionary attrs. Keys of attrs can be dot-separated name (e.g., a.b.c). In this case, nested attribute will be set to its attribute. The values of attrs can be a dict. If the corresponding attribute is an instance of TraitsCLIBase, attributes of this instance is set using this dictionary. Otherwise, it will issue an error. 14 Chapter 5. CLI base class

19 >>> obj = TraitsCLIBase() >>> obj.b = TraitsCLIBase() >>> obj.setattrs({ a : 1, b : { c : 2}}) >>> obj.a 1 >>> obj.b.c 2 >>> obj.setattrs({ b.a : 111, b.c : 222}) >>> obj.b.a 111 >>> obj.b.c 222 >>> obj.setattrs({ x.a : 0}) Traceback (most recent call last): AttributeError: TraitsCLIBase object has no attribute x If only_configurable is True, attempt to set non-configurable attributes raises an error. a = Int(config=True) b = Int() >>> obj = SampleCLI() >>> obj.setattrs({ a : 1}, only_configurable=true) # This is OK. >>> obj.setattrs({ b : 1}, only_configurable=true) # This is not! Traceback (most recent call last): TraitsCLIAttributeError: Non-configurable key is given: b load_paramfile(path, only_configurable=true) Load attributes from parameter file at path. To support new parameter file, add a class-method called loader_{ext} where {ext} is the file extension of the parameter file. You can also redefine dispatch_paramfile_loader class-method to change how loader function is chosen. >>> from tempfile import NamedTemporaryFile int = Int(config=True) >>> obj = SampleCLI() >>> with NamedTemporaryFile(suffix=.json ) as f: f.write( {"int": 1} ) f.flush() obj.load_paramfile(f.name) >>> obj.int 1 You can use only_configurable=false to set non-configurable option. >>> obj = TraitsCLIBase() >>> with NamedTemporaryFile(suffix=.json ) as f: f.write( {"nonconfigurable": 1} ) f.flush() obj.load_paramfile(f.name, only_configurable=false) >>> obj.nonconfigurable 15

20 1 load_all_paramfiles() Load attributes from all parameter files set in paramfile attributes. Path of parameter file is defined by attributes whose metadata cli_paramfile is True. >>> from tempfile import NamedTemporaryFile >>> from contextlib import nested int = Int(config=True) str = Str(config=True) paramfiles = List(cli_paramfile=True, config=true) >>> obj = SampleCLI() >>> with nested(namedtemporaryfile(suffix=.json ), NamedTemporaryFile(suffix=.json )) as (f, g): f.write( {"int": 1} ) f.flush() g.write( {"str": "a"} ) g.flush() obj.paramfiles = [f.name, g.name] obj.load_all_paramfiles() >>> obj.int 1 >>> obj.str u a classmethod dispatch_paramfile_loader(path) Return an parameter file loader function based on path. This classmethod returns classmethod/staticmethod named laoder_{ext} where {ext} is the file extension of path. You can redefine this classmethod to change the dispatching behavior. Call signature of the loader function must be loader(path) where path is a string file path to the parameter file. static loader_json(path, _open=<built-in function open>) Load JSON file located at path. It is equivalent to json.load(open(path)). static loader_yaml(path, _open=<built-in function open>) Load YAML file located at path. It is equivalent to yaml.load(open(path)). You need PyYAML module to use this loader. static loader_yml(path, _open=<built-in function open>) Alias to loader_yaml(). classmethod loader_conf(path, _open=<built-in function open>) Load parameter from conf/ini file. As conf file has no type information, class traits will be used at load time. >>> class SubObject(TraitsCLIBase): c = Int(config=True) a = Int(config=True) b = Instance(SubObject, args=(), config=true) 16 Chapter 5. CLI base class

21 d = Instance(SubObject, args=(), config=true) cli_conf_root_section = root # this is default You can write options using dot-separated name. Use the section specified by cli_conf_root_section for top-level attributes. >>> from tempfile import NamedTemporaryFile >>> source = [root] a = 1 b.c = 2 >>> with NamedTemporaryFile() as f: f.write(source) f.flush() param = SampleCLI.loader_conf(f.name) >>> param == { a : 1, b.c : 2} True Options in sections other than cli_conf_root_section are prefixed by section name. >>> from tempfile import NamedTemporaryFile >>> source = [root] a = 1 [b] c = 2 [d] c = 3 >>> with NamedTemporaryFile() as f: f.write(source) f.flush() param = SampleCLI.loader_conf(f.name) >>> param == { a : 1, b.c : 2, d.c : 3} True classmethod loader_ini(path, _open=<built-in function open>) Alias to loader_conf(). cli_conf_root_section = root Root section name for conf/ini file loader (loader_conf()). Options in this section will not be prefixed by section name. static loader_py(path, _open=<built-in function open>) Load parameter from Python file located at path. >>> from tempfile import NamedTemporaryFile >>> source = a = 1 b = dict(c=2) _underscored_value_ = will_not_be_loaded >>> with NamedTemporaryFile() as f: f.write(source) f.flush() param = TraitsCLIBase.loader_py(f.name) >>> param == { a : 1, b : { c : 2}} True 17

22 Parser API ArgumentParser = <class argparse.argumentparser > Argument parser class/factory. This attribute must be a callable object which returns an instance of argparse.argumentparser or its subclass. classmethod get_argparser() Return an instance of ArgumentParser for this class. Parser options are set according to the configurable traits of this class. classmethod add_parser(parser, prefix= ) Call parser.add_argument based on class traits of cls. This classmethod is called from get_argparser(). 18 Chapter 5. CLI base class

23 CHAPTER SIX UTILITY FUNCTIONS traitscli.multi_command_cli(command_class_pairs, args=none, ArgumentParser=None) Launch CLI to call multiple classes. Usage: >>> class SampleBase(TraitsCLIBase): a = Int(config=True) def do_run(self): print "Running", print {0}(a={1!r}).format(self. class. name, self.a) >>> class SampleInit(SampleBase): pass >>> class SampleCheckout(SampleBase): pass >>> class SampleBranch(SampleBase): pass >>> obj = multi_command_cli( # CLI classes and subcommand names [( init, SampleInit), ( checkout, SampleCheckout), ( branch, SampleBranch), ], # Command line arguments [ init, --a, 1 ]) Running SampleInit(a=1) >>> isinstance(obj, SampleInit) # used CLI object is returned. True If ArgumentParser is not specified, ArgumentParser of the first class will be used. traitscli.flattendict(dct) Flatten dictionary using key concatenated by dot. >>> flattendict({ a : 1, b : 2}) == { a : 1, b : 2} True >>> flattendict({ a : 1, b : { c : 2}}) == { a : 1, b.c : 2} True 19

24 20 Chapter 6. Utility functions

25 CHAPTER SEVEN CHANGE LOG 7.1 v0.1 Classes which inherits HasTraits but does not inherit TraitsCLIBase also can be used as a configurable trait. 21

26 22 Chapter 7. Change log

27 PYTHON MODULE INDEX t traitscli, 1 23

traitlets Documentation

traitlets Documentation traitlets Documentation Release 4.3.2 The IPython Development Team Feb 23, 2017 Contents 1 Using Traitlets 3 1.1 Default values, and checking type and value............................... 3 1.2 observe..................................................

More information

traitlets Documentation

traitlets Documentation traitlets Documentation Release 5.0.0.dev The IPython Development Team Dec 08, 2017 Contents 1 Using Traitlets 3 1.1 Default values, and checking type and value............................... 3 1.2 observe..................................................

More information

Weights and Biases Documentation

Weights and Biases Documentation Weights and Biases Documentation Release 0.6.17 Weights and Biases Aug 13, 2018 Contents 1 Intro 1 2 Quickstart - Existing Project 3 3 Weights & Biases Run API 5 3.1 Saving run files..............................................

More information

pysharedutils Documentation

pysharedutils Documentation pysharedutils Documentation Release 0.5.0 Joel James August 07, 2017 Contents 1 pysharedutils 1 2 Indices and tables 13 i ii CHAPTER 1 pysharedutils pysharedutils is a convenient utility module which

More information

django-crucrudile Documentation

django-crucrudile Documentation django-crucrudile Documentation Release 0.9.1 Hugo Geoffroy (pstch) July 27, 2014 Contents 1 Installation 1 1.1 From Python package index....................................... 1 1.2 From source...............................................

More information

argcomplete Documentation

argcomplete Documentation argcomplete Documentation Release Andrey Kislyuk Nov 21, 2017 Contents 1 Installation 3 2 Synopsis 5 2.1 argcomplete.autocomplete(parser).................................... 5 3 Specifying completers

More information

argcomplete Documentation Andrey Kislyuk

argcomplete Documentation Andrey Kislyuk Andrey Kislyuk May 08, 2018 Contents 1 Installation 3 2 Synopsis 5 2.1 argcomplete.autocomplete(parser).................................... 5 3 Specifying completers 7 3.1 Readline-style completers........................................

More information

json-rpc Documentation

json-rpc Documentation json-rpc Documentation Release 1.11.0 Kirill Pavlov May 02, 2018 Contents 1 Features 3 2 Contents 5 2.1 Quickstart................................................ 5 2.2 Method dispatcher............................................

More information

Specter Documentation

Specter Documentation Specter Documentation Release 0.6.1 John Vrbanac Apr 09, 2017 Contents 1 Documentation 2 1.1 Using Specter............................................... 2 1.2 Writing Specter Tests..........................................

More information

Kaiso Documentation. Release 0.1-dev. onefinestay

Kaiso Documentation. Release 0.1-dev. onefinestay Kaiso Documentation Release 0.1-dev onefinestay Sep 27, 2017 Contents 1 Neo4j visualization style 3 2 Contents 5 2.1 API Reference.............................................. 5 3 Indices and tables

More information

yaml Documentation Release dev Anthon van der Neut

yaml Documentation Release dev Anthon van der Neut yaml Documentation Release dev Anthon van der Neut December 21, 2016 Contents 1 Overview 3 2 Installing 5 2.1 Optional requirements........................................ 5 3 Details 7 3.1 Indentation

More information

xmljson Documentation

xmljson Documentation xmljson Documentation Release 0.1.9 S Anand Aug 01, 2017 Contents 1 About 3 2 Convert data to XML 5 3 Convert XML to data 7 4 Conventions 9 5 Options 11 6 Installation 13 7 Roadmap 15 8 More information

More information

Confuse. Release 0.1.0

Confuse. Release 0.1.0 Confuse Release 0.1.0 July 02, 2016 Contents 1 Using Confuse 3 2 View Theory 5 3 Validation 7 4 Command-Line Options 9 5 Search Paths 11 6 Your Application Directory 13 7 Dynamic Updates 15 8 YAML Tweaks

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Generators Exceptions and IO Eric Kutschera University of Pennsylvania February 13, 2015 Eric Kutschera (University of Pennsylvania) CIS 192 February 13, 2015 1 / 24 Outline 1

More information

Watson - Events. Release 1.0.3

Watson - Events. Release 1.0.3 Watson - Events Release 1.0.3 Jan 15, 2018 Contents 1 Build Status 3 2 Installation 5 3 Testing 7 4 Contributing 9 5 Table of Contents 11 5.1 Usage................................................... 11

More information

traity Documentation Release Sean Ross-Ross

traity Documentation Release Sean Ross-Ross traity Documentation Release 0.0.1 Sean Ross-Ross August 16, 2016 Contents 1 Traity s API 3 1.1 Events.................................................. 3 1.2 Static Properties.............................................

More information

maya-cmds-help Documentation

maya-cmds-help Documentation maya-cmds-help Documentation Release Andres Weber May 28, 2017 Contents 1 1.1 Synopsis 3 1.1 1.1.1 Features.............................................. 3 2 1.2 Installation 5 2.1 1.2.1 Windows, etc............................................

More information

cursesmenu Documentation

cursesmenu Documentation cursesmenu Documentation Release 0.5.0 Author March 04, 2016 Contents 1 Installation 3 2 Usage 5 2.1 Getting a selection............................................ 6 3 API Reference 7 3.1 CursesMenu

More information

monolith Documentation

monolith Documentation monolith Documentation Release 0.3.3 Łukasz Balcerzak December 16, 2013 Contents 1 Usage 3 1.1 Execution manager............................................ 3 1.2 Creating commands...........................................

More information

Friday, 11 April 14. Advanced methods for creating decorators Graham Dumpleton PyCon US - April 2014

Friday, 11 April 14. Advanced methods for creating decorators Graham Dumpleton PyCon US - April 2014 Advanced methods for creating decorators Graham Dumpleton PyCon US - April 2014 Intermission Rant about the history of this talk and why this topic matters. Python decorator syntax @function_wrapper def

More information

Sage Reference Manual: Python technicalities

Sage Reference Manual: Python technicalities Sage Reference Manual: Python technicalities Release 8.1 The Sage Development Team Dec 09, 2017 CONTENTS 1 Various functions to debug Python internals 3 2 Variants of getattr() 5 3 Metaclasses for Cython

More information

Confire Documentation

Confire Documentation Confire Documentation Release 0.2.0 Benjamin Bengfort December 10, 2016 Contents 1 Features 3 2 Setup 5 3 Example Usage 7 4 Next Topics 9 5 About 17 Python Module Index 19 i ii Confire is a simple but

More information

At full speed with Python

At full speed with Python At full speed with Python João Ventura v0.1 Contents 1 Introduction 2 2 Installation 3 2.1 Installing on Windows............................ 3 2.2 Installing on macos............................. 5 2.3

More information

JSONRPC Documentation

JSONRPC Documentation JSONRPC Documentation Release 1.0 Edward Langley March 29, 2016 Contents 1 Getting Started 3 2 JSON-RPC Server 5 3 JSON-RPC Proxy 7 4 jsonrpc.jsonutil 9 5 Indices and tables 11 Python Module Index 13

More information

json2xls Documentation

json2xls Documentation json2xls Documentation Release 0.1.3c axiaoxin Aug 10, 2017 Contents 1 3 2 5 3 API 9 i ii json2xls Documentation, Release 0.1.3c jsonexceljsonexceljson jsonjsonurljsonjson Contents 1 json2xls Documentation,

More information

funcsigs Documentation

funcsigs Documentation funcsigs Documentation Release 0.4 Aaron Iles December 20, 2013 Contents i ii CHAPTER 1 The Funcsigs Package funcsigs is a backport of the PEP 362 function signature features from Python 3.3 s inspect

More information

Archan. Release 2.0.1

Archan. Release 2.0.1 Archan Release 2.0.1 Jul 30, 2018 Contents 1 Archan 1 1.1 Features.................................................. 1 1.2 Installation................................................ 1 1.3 Documentation..............................................

More information

Traits 4 User Manual. Release Enthought, Inc.

Traits 4 User Manual. Release Enthought, Inc. Traits 4 User Manual Release 4.4.0 Enthought, Inc. February 17, 2014 Contents i ii CHAPTER 1 User Reference 1.1 Traits 4 User Manual 1.1.1 Traits 4 User Manual Authors David C. Morrill, Janet M. Swisher

More information

helper Documentation Release Gavin M. Roy

helper Documentation Release Gavin M. Roy helper Documentation Release 2.1.0 Gavin M. Roy September 24, 2013 CONTENTS i ii helper is a command-line/daemon application wrapper package with the aim of creating a consistent and fast way to creating

More information

certbot-dns-rfc2136 Documentation

certbot-dns-rfc2136 Documentation certbot-dns-rfc2136 Documentation Release 0 Certbot Project Aug 29, 2018 Contents: 1 Named Arguments 3 2 Credentials 5 2.1 Sample BIND configuration....................................... 6 3 Examples

More information

Getting Started with TensorFlow : Part II

Getting Started with TensorFlow : Part II TensorFlow Workshop 2018 Getting Started with TensorFlow Part II : Monitoring Training and Validation Nick Winovich Department of Mathematics Purdue University July 2018 Outline 1 Monitored Training Sessions

More information

tappy Documentation Release 2.5 Matt Layman and contributors

tappy Documentation Release 2.5 Matt Layman and contributors tappy Documentation Release 2.5 Matt Layman and contributors Sep 15, 2018 Contents 1 Installation 3 2 Documentation 5 2.1 TAP Producers.............................................. 5 2.2 TAP Consumers.............................................

More information

Python Tips and Tricks

Python Tips and Tricks Tips and Tricks Stéphane Vialette LIGM, Université Paris-Est Marne-la-Vallée November 14, 2011 Stéphane Vialette (LIGM, Université Paris-Est Marne-la-Vallée) Tips and Tricks November 14, 2011 1 / 36 Lists

More information

django-dynamic-db-router Documentation

django-dynamic-db-router Documentation django-dynamic-db-router Documentation Release 0.1.1 Erik Swanson August 24, 2016 Contents 1 Table of Contents 3 1.1 Installation................................................ 3 1.2 Quickstart................................................

More information

halogen documentation

halogen documentation halogen documentation Release 1.3.5 Oleg Pidsadnyi, Paylogic International and others Apr 13, 2018 Contents 1 halogen 3 2 Schema 5 2.1 Serialization............................................... 5 2.2

More information

COMP519 Web Programming Lecture 21: Python (Part 5) Handouts

COMP519 Web Programming Lecture 21: Python (Part 5) Handouts COMP519 Web Programming Lecture 21: Python (Part 5) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Functions

More information

Project 6 Due 11:59:59pm Thu, Dec 10, 2015

Project 6 Due 11:59:59pm Thu, Dec 10, 2015 Project 6 Due 11:59:59pm Thu, Dec 10, 2015 Updates None yet. Introduction In this project, you will add a static type checking system to the Rube programming language. Recall the formal syntax for Rube

More information

flake8 Documentation Release Tarek Ziade

flake8 Documentation Release Tarek Ziade flake8 Documentation Release 2.5.5 Tarek Ziade June 14, 2016 Contents 1 QuickStart 3 2 Frequently Asked Questions 5 2.1 Why does flake8 pin the version of pep8?................................ 5 2.2 Is

More information

Connexion Documentation

Connexion Documentation Connexion Documentation Release 0.5 Zalando SE Nov 16, 2017 Contents 1 Quickstart 3 1.1 Prerequisites............................................... 3 1.2 Installing It................................................

More information

bottle-rest Release 0.5.0

bottle-rest Release 0.5.0 bottle-rest Release 0.5.0 February 18, 2017 Contents 1 API documentation 3 1.1 bottle_rest submodule.......................................... 3 2 What is it 5 2.1 REST in bottle..............................................

More information

redis-lua Documentation

redis-lua Documentation redis-lua Documentation Release 2.0.8 Julien Kauffmann October 12, 2016 Contents 1 Quick start 3 1.1 Step-by-step analysis........................................... 3 2 What s the magic at play here?

More information

What's New in Python 2.2

What's New in Python 2.2 What's New in Python 2.2 LinuxWorld - New York City - January 2002 Guido van Rossum Director of PythonLabs at Zope Corporation guido@python.org guido@zope.com Overview Appetizers Nested Scopes Int/Long

More information

1 Decorators. 2 Descriptors. 3 Static Variables. 4 Anonymous Classes. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers July 13, / 19

1 Decorators. 2 Descriptors. 3 Static Variables. 4 Anonymous Classes. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers July 13, / 19 1 Decorators 2 Descriptors 3 Static Variables 4 Anonymous Classes Sandeep Sadanandan (TU, Munich) Python For Fine Programmers July 13, 2009 1 / 19 Decorator Pattern In object-oriented programming, the

More information

Introduction to Python Part 2

Introduction to Python Part 2 Introduction to Python Part 2 v0.2 Brian Gregor Research Computing Services Information Services & Technology Tutorial Outline Part 2 Functions Tuples and dictionaries Modules numpy and matplotlib modules

More information

python-aspectlib Release 0.5.0

python-aspectlib Release 0.5.0 python-aspectlib 0.5.0 Release 0.5.0 March 17, 2014 Contents i ii aspectlib is an aspect-oriented programming, monkey-patch and decorators library. It is useful when changing behavior in existing code

More information

SCHEME INTERPRETER GUIDE 4

SCHEME INTERPRETER GUIDE 4 SCHEME INTERPRETER GUIDE 4 COMPUTER SCIENCE 61A July 28, 2014 1 Scheme Values Back in Python, we had all these objects (i.e. lists, tuples, strings, integers) which inherited from the superclass object.

More information

kvkit Documentation Release 0.1 Shuhao Wu

kvkit Documentation Release 0.1 Shuhao Wu kvkit Documentation Release 0.1 Shuhao Wu April 18, 2014 Contents 1 Introduction to KVKit 3 1.1 Simple Tutorial.............................................. 3 1.2 Indexes..................................................

More information

Kuyruk Documentation. Release 0. Cenk Altı

Kuyruk Documentation. Release 0. Cenk Altı Kuyruk Documentation Release 0 Cenk Altı Mar 07, 2018 Contents 1 About Kuyruk 3 2 User s Guide 5 3 API Reference 17 4 Indices and tables 21 Python Module Index 23 i ii Welcome to Kuyruk s documentation.

More information

edeposit.amqp.antivirus Release 1.0.1

edeposit.amqp.antivirus Release 1.0.1 edeposit.amqp.antivirus Release 1.0.1 February 05, 2015 Contents 1 Installation 3 1.1 Initialization............................................... 3 2 Usage 5 3 Content 7 3.1 Standalone script.............................................

More information

tolerance Documentation

tolerance Documentation tolerance Documentation Release Alisue Apr 1, 217 Contents 1 tolerance 1 1.1 Features.................................................. 1 1.2 Installation................................................

More information

Before we start looking at how we build abstract data types in Python, let's define some import terms and look at some real-world examples.

Before we start looking at how we build abstract data types in Python, let's define some import terms and look at some real-world examples. Exception Handling Python Built-in Exceptions Abstract Data Types You can use a Python tuple to combine two simple values into a compound value. In this case, we use a 2-element tuple whose first element

More information

Connexion Sqlalchemy Utils Documentation

Connexion Sqlalchemy Utils Documentation Connexion Sqlalchemy Utils Documentation Release 0.1.4 Michael Housh Apr 17, 2017 Contents 1 Connexion Sqlalchemy Utils 3 1.1 Features.................................................. 3 1.2 Running example

More information

drove.io Documentation

drove.io Documentation drove.io Documentation Release 0.1 Andrés J. Díaz November 20, 2014 Contents 1 Installation 3 2 Usage 5 3 Plugins 7 4 Reference 9 4.1 drove................................................... 9 4.2 drove.command.............................................

More information

python-json-patch Documentation

python-json-patch Documentation python-json-patch Documentation Release 1.21 Stefan Kögl Jan 16, 2018 Contents 1 Tutorial 3 1.1 Creating a Patch............................................. 3 1.2 Applying a Patch.............................................

More information

Discovering Descriptors

Discovering Descriptors Discovering Descriptors Mariano Anaya EuroPython - July 2017 rmariano rmarianoa def Learning about descriptors not only provides access to a larger toolset, it creates a deeper understanding of how Python

More information

web-transmute Documentation

web-transmute Documentation web-transmute Documentation Release 0.1 Yusuke Tsutsumi Dec 19, 2017 Contents 1 Writing transmute-compatible functions 3 1.1 Add function annotations for input type validation / documentation..................

More information

Introduction to Python

Introduction to Python Introduction to Python CB2-101 Introduction to Scientific Computing November 11 th, 2014 Emidio Capriotti http://biofold.org/emidio Division of Informatics Department of Pathology Python Python high-level

More information

pydocstyle Documentation

pydocstyle Documentation pydocstyle Documentation Release 1.0.0 Amir Rachum Oct 14, 2018 Contents 1 Quick Start 3 1.1 Usage................................................... 3 1.2 Error Codes................................................

More information

Traits 4 User Manual. Release dev96. Enthought, Inc.

Traits 4 User Manual. Release dev96. Enthought, Inc. Traits 4 User Manual Release 4.7.0.dev96 Enthought, Inc. August 01, 2018 Contents 1 User Reference 1 1.1 Traits 4 User Manual........................................... 1 1.1.1 Traits 4 User Manual......................................

More information

Python Working with files. May 4, 2017

Python Working with files. May 4, 2017 Python Working with files May 4, 2017 So far, everything we have done in Python was using in-memory operations. After closing the Python interpreter or after the script was done, all our input and output

More information

pygtrie Release Jul 03, 2017

pygtrie Release Jul 03, 2017 pygtrie Release Jul 03, 2017 Contents 1 Features 3 2 Installation 5 3 Upgrading from 0.9.x 7 4 Trie classes 9 5 PrefixSet class 19 6 Version History 21 Python Module Index 23 i ii Implementation of a

More information

g-pypi Documentation Release 0.3 Domen Kožar

g-pypi Documentation Release 0.3 Domen Kožar g-pypi Documentation Release 0.3 Domen Kožar January 20, 2014 Contents i ii Author Domen Kožar Source code Github.com source browser Bug tracker Github.com issues Generated January 20,

More information

CSE : Python Programming. Decorators. Announcements. The decorator pattern. The decorator pattern. The decorator pattern

CSE : Python Programming. Decorators. Announcements. The decorator pattern. The decorator pattern. The decorator pattern CSE 399-004: Python Programming Lecture 12: Decorators April 9, 200 http://www.seas.upenn.edu/~cse39904/ Announcements Projects (code and documentation) are due: April 20, 200 at pm There will be informal

More information

Class extension and. Exception handling. Genome 559

Class extension and. Exception handling. Genome 559 Class extension and Exception handling Genome 559 Review - classes 1) Class constructors - class myclass: def init (self, arg1, arg2): self.var1 = arg1 self.var2 = arg2 foo = myclass('student', 'teacher')

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Iterators, Generators, Exceptions & IO Raymond Yin University of Pennsylvania September 28, 2016 Raymond Yin (University of Pennsylvania) CIS 192 September 28, 2016 1 / 26 Outline

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Object Oriented Programming Harry Smith University of Pennsylvania February 15, 2016 Harry Smith (University of Pennsylvania) CIS 192 Lecture 5 February 15, 2016 1 / 26 Outline

More information

Uranium Documentation

Uranium Documentation Uranium Documentation Release 0.1 Yusuke Tsutsumi Jul 26, 2018 Contents 1 What is Uranium? 1 1.1 Installation................................................ 2 1.2 Tutorial..................................................

More information

Python Tips and Tricks

Python Tips and Tricks Tips and Tricks Stéphane Vialette LIGM, Université Paris-Est Marne-la-Vallée November 7, 2012 Stéphane Vialette (LIGM, Université Paris-Est Marne-la-Vallée) Tips and Tricks November 7, 2012 1 / 39 Lists

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Web Servers and Web APIs Eric Kutschera University of Pennsylvania March 6, 2015 Eric Kutschera (University of Pennsylvania) CIS 192 March 6, 2015 1 / 22 Outline 1 Web Servers

More information

Python State Machine Documentation

Python State Machine Documentation Python State Machine Documentation Release 0.6.2 Fernando Macedo Aug 25, 2017 Contents 1 Python State Machine 3 1.1 Getting started.............................................. 3 2 Installation 7 2.1

More information

python-aspectlib Release 0.4.1

python-aspectlib Release 0.4.1 python-aspectlib 0.4.1 Release 0.4.1 May 03, 2014 Contents i ii aspectlib is an aspect-oriented programming, monkey-patch and decorators library. It is useful when changing behavior in existing code is

More information

PyTrie Documentation. Release 0.3. George Sakkis

PyTrie Documentation. Release 0.3. George Sakkis PyTrie Documentation Release 0.3 George Sakkis Jun 05, 2017 Contents 1 Usage 3 2 Reference documentation 5 2.1 Classes.................................................. 5 2.2 Trie methods...............................................

More information

Python State Machine Documentation

Python State Machine Documentation Python State Machine Documentation Release 0.7.1 Fernando Macedo Jan 17, 2019 Contents 1 Python State Machine 3 1.1 Getting started.............................................. 3 2 Installation 9 2.1

More information

a declaration of class name, and a class docstring

a declaration of class name, and a class docstring Question 1. [10 marks] Implement a class that models a cash register in a store. This cash register will know what the HST tax rate is (charged on all sales, for simplicity), is able to make sales, and

More information

Recall. Key terms. Review. Encapsulation (by getters, setters, properties) OOP Features. CSC148 Intro. to Computer Science

Recall. Key terms. Review. Encapsulation (by getters, setters, properties) OOP Features. CSC148 Intro. to Computer Science CSC148 Intro. to Computer Science Lecture 3: designing classes, special methods, composition, inheritance, Stack, Sack Amir H. Chinaei, Summer 2016 Office Hours: R 10-12 BA4222 ahchinaei@cs.toronto.edu

More information

Not-So-Mini-Lecture 6. Modules & Scripts

Not-So-Mini-Lecture 6. Modules & Scripts Not-So-Mini-Lecture 6 Modules & Scripts Interactive Shell vs. Modules Launch in command line Type each line separately Python executes as you type Write in a code editor We use Atom Editor But anything

More information

dicompyler-core Documentation

dicompyler-core Documentation dicompyler-core Documentation Release 0.5.3 Aditya Panchal Nov 08, 2017 Contents 1 dicompyler-core 3 1.1 Other information............................................ 3 1.2 Dependencies...............................................

More information

Object-Oriented Python

Object-Oriented Python Object-Oriented Python Everything is an object. Every object has a value. a type. an identity. a namespace. CS105 Python def initstudent(student, eid): global A class is like a namespace. CS105 Python

More information

DSC 201: Data Analysis & Visualization

DSC 201: Data Analysis & Visualization DSC 201: Data Analysis & Visualization Classes Dr. David Koop Tuple, List, Dictionary, or Set? [1,2,"abc"] 2 Tuple, List, Dictionary, or Set? {"a", 1, 2} 3 Tuple, List, Dictionary, or Set? {} 4 Tuple,

More information

ejpiaj Documentation Release Marek Wywiał

ejpiaj Documentation Release Marek Wywiał ejpiaj Documentation Release 0.4.0 Marek Wywiał Mar 06, 2018 Contents 1 ejpiaj 3 1.1 License.................................................. 3 1.2 Features..................................................

More information

viki-fabric-helpers Documentation

viki-fabric-helpers Documentation viki-fabric-helpers Documentation Release 0.0.5 Viki Inc. July 04, 2014 Contents 1 Installation 3 1.1 Installation................................................ 3 2 Configuration 5 2.1 Configuration...............................................

More information

e24paymentpipe Documentation

e24paymentpipe Documentation e24paymentpipe Documentation Release 1.2.0 Burhan Khalid Oct 30, 2017 Contents 1 e24paymentpipe 3 1.1 Features.................................................. 3 1.2 Todo...................................................

More information

QtBinder Documentation

QtBinder Documentation QtBinder Documentation Release 0.2 Enthought, Inc. July 13, 2016 Contents 1 When do I use QtBinder over Traits UI? 3 2 Contents 5 2.1 Core Principles.............................................. 5 2.2

More information

Requests Mock Documentation

Requests Mock Documentation Requests Mock Documentation Release 1.5.1.dev4 Jamie Lennox Jun 16, 2018 Contents 1 Overview 3 2 Using the Mocker 5 2.1 Activation................................................ 5 2.2 Class Decorator.............................................

More information

Absent: Lecture 3 Page 1. def foo(a, b): a = 5 b[0] = 99

Absent: Lecture 3 Page 1. def foo(a, b): a = 5 b[0] = 99 1. A function is a procedural abstract (a named body of code to perform some action and return a resulting value). The syntax of a function definition is: def functionname([parameter [, parameter]*]):

More information

Baron Documentation. Release 0.6. Laurent Peuch

Baron Documentation. Release 0.6. Laurent Peuch Baron Documentation Release 0.6 Laurent Peuch Sep 23, 2018 Contents 1 Introduction 1 2 Github (code, bug tracker, etc.) 3 3 Installation 5 4 RedBaron 7 5 Basic usage 9 6 Table of content 11 6.1 Basic

More information

Avpy Documentation. Release sydh

Avpy Documentation. Release sydh Avpy Documentation Release 0.1.3 sydh May 01, 2016 Contents 1 Overview 1 2 Getting Help 3 3 Issues 5 4 Changes 7 5 Contributions 9 6 Indices and tables 11 6.1 Examples.................................................

More information

eventfd Documentation

eventfd Documentation eventfd Documentation Release 0.2 Aviv Palivoda March 01, 2016 Contents 1 Event Objects 3 2 EXAMPLES 5 3 Obtaining the Module 9 4 Development and Support 11 4.1 Release History..............................................

More information

Mercantile Documentation

Mercantile Documentation Mercantile Documentation Release 1.0.0 Sean C. Gillies Jun 11, 2018 Contents 1 Contents 3 1.1 Quick start................................................ 3 1.2 Installation................................................

More information

MyAnimeList Scraper. Release 0.3.0

MyAnimeList Scraper. Release 0.3.0 MyAnimeList Scraper Release 0.3.0 Mar 14, 2018 Contents 1 Overview 1 1.1 Installation & Usage........................................... 1 1.2 Development...............................................

More information

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017 Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Iterators, Generators, IO, and Exceptions Harry Smith University of Pennsylvania February 15, 2018 Harry Smith (University of Pennsylvania) CIS 192 Lecture 5 February 15, 2018

More information

Ensure Documentation. Release Andrey Kislyuk

Ensure Documentation. Release Andrey Kislyuk Ensure Documentation Release 0.0.1 Andrey Kislyuk Nov 06, 2018 Contents 1 Installation 3 2 Synopsis 5 2.1 Notes................................................... 5 2.2 Raising custom exceptions........................................

More information

Dodo Commands Documentation

Dodo Commands Documentation Dodo Commands Documentation Release 0.2.1 Maarten Nieber Apr 04, 2019 Contents 1 Goals of the Dodo Commands system 3 1.1 Provide a per-project environment.................................... 3 1.2 Single

More information

Porting Python 2 Code to Python 3 Release 2.7.6

Porting Python 2 Code to Python 3 Release 2.7.6 Porting Python 2 Code to Python 3 Release 2.7.6 Guido van Rossum Fred L. Drake, Jr., editor Contents November 10, 2013 Python Software Foundation Email: docs@python.org 1 Choosing a Strategy ii 1.1 Universal

More information

INTERPRETATION AND SCHEME LISTS 12

INTERPRETATION AND SCHEME LISTS 12 INTERPRETATION AND SCHEME LISTS 12 COMPUTER SCIENCE 61A July 26, 2012 1 Calculator Language We are beginning to dive into the realm of interpreting computer programs. To do so, we will examine a few new

More information

Objects CHAPTER 6. FIGURE 1. Concrete syntax for the P 3 subset of Python. (In addition to that of P 2.)

Objects CHAPTER 6. FIGURE 1. Concrete syntax for the P 3 subset of Python. (In addition to that of P 2.) CHAPTER 6 Objects The main ideas for this chapter are: objects and classes: objects are values that bundle together some data (attributes) and some functions (methods). Classes are values that describe

More information

DoJSON Documentation. Release Invenio collaboration

DoJSON Documentation. Release Invenio collaboration DoJSON Documentation Release 1.2.0 Invenio collaboration March 21, 2016 Contents 1 About 1 2 Installation 3 3 Documentation 5 4 Testing 7 5 Example 9 5.1 User s Guide...............................................

More information

pyprika Documentation

pyprika Documentation pyprika Documentation Release 1.0.0 Paul Kilgo February 16, 2014 Contents i ii Pyprika is a Python library for parsing and managing recipes. Its major features are: Support for recognizing a human-friendly

More information

1 Classes. 2 Exceptions. 3 Using Other Code. 4 Problems. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers May 16, / 19

1 Classes. 2 Exceptions. 3 Using Other Code. 4 Problems. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers May 16, / 19 1 Classes 2 Exceptions 3 Using Other Code 4 Problems Sandeep Sadanandan (TU, Munich) Python For Fine Programmers May 16, 2009 1 / 19 Start with an Example Python is object oriented Everything is an object

More information