Cargando…

Modern Python cookbook : the latest in modern Python recipes for the busy modern programmer /

The latest in modern Python recipes for the busy modern programmer About This Book • Develop succinct, expressive programs in Python • Learn the best practices and common idioms through carefully explained and structured recipes • Discover new ways to apply Python fo...

Descripción completa

Detalles Bibliográficos
Clasificación:Libro Electrónico
Autor principal: Lott, Steven F. (Autor)
Formato: Electrónico eBook
Idioma:Inglés
Publicado: Birmingham, UK : Packt Publishing, 2016.
Temas:
Acceso en línea:Texto completo (Requiere registro previo con correo institucional)
Tabla de Contenidos:
  • Cover
  • Title Page
  • Copyright
  • Credits
  • About the Author
  • About the Reviewers
  • www.PacktPub.com
  • Table of Contents
  • Preface
  • Chapter 1: Numbers, Strings, and Tuples
  • Introduction
  • Creating meaningful names and using variables
  • Getting ready
  • How to do it...
  • Choosing names wisely
  • Assigning names to objects
  • How it works...
  • There's more...
  • See also
  • Working with large and small integers
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Choosing between float, decimal, and fraction
  • Getting ready
  • How to do it...
  • Doing currency calculations
  • Fraction calculations
  • Floating-point approximations
  • Converting numbers from one type to another
  • How it works...
  • There's more...
  • See also
  • Choosing between true division and floor division
  • Getting ready
  • How to do it...
  • Doing floor division
  • Doing true division
  • Rational fraction calculations
  • How it works...
  • See also
  • Rewriting an immutable string
  • Getting ready
  • How to do it...
  • Slicing a piece of a string
  • Updating a string with a replacement
  • Making a string all lowercase
  • Removing extra punctuation marks
  • How it works...
  • There's more...
  • See also
  • String parsing with regular expressions
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Building complex strings with "template".format()
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Building complex strings from lists of characters
  • Getting ready
  • How to do it...
  • How it works...
  • There's more
  • See also
  • Using the Unicode characters that aren't on our keyboards
  • Getting ready
  • How to do it...
  • How it works...
  • See also
  • Encoding strings
  • creating ASCII and UTF-8 bytes
  • Getting ready
  • How to do it...
  • How it works...
  • See also
  • Decoding bytes
  • how to get proper characters from some bytes
  • Getting ready
  • How to do it..
  • How it works...
  • See also
  • Using tuples of items
  • Getting ready
  • How to do it...
  • Creating tuples
  • Extracting items from a tuple
  • How it works...
  • There's more
  • See also...
  • Chapter 2: Statements and Syntax
  • Introduction
  • Writing Python script and module files
  • syntax basics
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Writing long lines of code
  • Getting ready
  • How to do it...
  • Using backslash to break a long statement into logical lines
  • Using the () characters to break a long statement into sensible pieces
  • Using string literal concatenation
  • Assigning intermediate results to separate variables
  • How it works...
  • There's more...
  • See also
  • Including descriptions and documentation
  • Getting ready
  • How to do it...
  • Writing docstrings for scripts
  • Writing docstrings for library modules
  • How it works...
  • There's more...
  • See also
  • Writing better RST markup in docstrings
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • Using directives
  • Using inline markup
  • See also
  • Designing complex if...elif chains
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Designing a while statement which terminates properly
  • Getting ready
  • How to do it...
  • How it works...
  • See also
  • Avoiding a potential problem with break statements
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Leveraging the exception matching rules
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Avoiding a potential problem with an except: clause
  • Getting ready
  • How to do it...
  • How it works...
  • See also.
  • Chaining exceptions with the raise from statement
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Managing a context using the with statement
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Chapter 3: Function Definitions
  • Introduction
  • Designing functions with optional parameters
  • Getting ready
  • How to do it...
  • Particular to General Design
  • General to Particular design
  • How it works...
  • There's more...
  • See also
  • Using super flexible keyword parameters
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Forcing keyword-only arguments with the * separator
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Writing explicit types on function parameters
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Picking an order for parameters based on partial functions
  • Getting ready
  • How to do it...
  • Wrapping a function
  • Creating a partial function with keyword parameters
  • Creating a partial function with positional parameters
  • How it works...
  • There's more...
  • See also
  • Writing clear documentation strings with RST markup
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Designing recursive functions around Python's stack limits
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Writing reusable scripts with the script library switch
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Chapter 4: Built-in Data Structures
  • list, set, dict
  • Introduction
  • Choosing a data structure
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also.
  • Building lists
  • literals, appending, and comprehensions
  • Getting ready
  • How to do it...
  • Building a list with the append() method
  • Writing a list comprehension
  • Using the list function on a generator expression
  • How it works...
  • There's more...
  • Other ways to extend a list
  • See also
  • Slicing and dicing a list
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Deleting from a list
  • deleting, removing, popping, and filtering
  • Getting ready
  • How to do it...
  • Deleting items from a list
  • The remove() method
  • The pop() method
  • The filter() function
  • How it works...
  • There's more...
  • See also
  • Reversing a copy of a list
  • Getting ready
  • How to do it...
  • How it works...
  • See also
  • Using set methods and operators
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Removing items from a set
  • remove(), pop(), and difference
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Creating dictionaries
  • inserting and updating
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Removing from dictionaries
  • the pop() method and the del statement
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Controlling the order of dict keys
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Handling dictionaries and sets in doctest examples
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • Understanding variables, references, and assignment
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Making shallow and deep copies of objects
  • Getting ready
  • How to do it...
  • How it works...
  • See also
  • Avoiding mutable default values for function parameters.
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Chapter 5: User Inputs and Outputs
  • Introduction
  • Using features of the print() function
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Using input() and getpass() for user input
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • Input string parsing
  • Interaction via the cmd module
  • See also
  • Debugging with "format".format_map(vars())
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Using argparse to get command-line input
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Using cmd for creating command-line applications
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Using the OS environment settings
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Chapter 6: Basics of Classes and Objects
  • Introduction
  • Using a class to encapsulate data and processing
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Designing classes with lots of processing
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Designing classes with little unique processing
  • Getting ready
  • How to do it...
  • Stateless objects
  • Stateful objects with a new class
  • Stateful objects using an existing class
  • How it works...
  • There's more...
  • See also
  • Optimizing small objects with __slots__
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Using more sophisticated collections
  • Getting ready
  • How to do it...
  • How it works...
  • There's more...
  • See also
  • Extending a collection
  • a list that does statistics
  • Getting ready.