Effective Python: 59 Specific Ways to Write Better Python by Brett Slatkin

By Brett Slatkin

It's effortless to begin writing code with Python: that's why the language is so immensely well known. notwithstanding, Python has distinctive strengths, charms, and expressivity that may be difficult to know first and foremost -- in addition to hidden pitfalls which can simply journey you up if you happen to aren't conscious of them. potent Python can help you harness the complete strength of Python to jot down particularly strong, effective, maintainable, and well-performing code. using the concise, scenario-driven variety pioneered in Scott Meyers's best-selling powerful C++, Brett Slatkin brings jointly fifty nine Python top practices, suggestions, shortcuts, and life like code examples from professional programmers.

Through life like examples, Slatkin uncovers little-known Python quirks, intricacies, and idioms that powerfully impression code habit and function. You'll find out how to select the best and potent strategy to accomplish key projects while a number of suggestions exist, and the way to put in writing code that's more uncomplicated to appreciate, hold, and improve.

Drawing on his deep realizing of Python's services, Slatkin bargains sensible recommendation for every significant sector of improvement with either Python 3.x and Python 2.x. assurance includes:

integrated modules
creation techniques
And more

Each part includes particular, actionable instructions geared up into goods, every one with rigorously worded suggestion supported via distinct technical arguments and illuminating examples. utilizing potent Python, you could systematically increase the entire Python code you write: now not by means of blindly following ideas or mimicking incomprehensible idioms, yet through gaining a deep realizing of the technical the reason why they make feel.

Show description

Read or Download Effective Python: 59 Specific Ways to Write Better Python (Effective Software Development Series) PDF

Best python books

Essential SQLAlchemy

Essential SQLAlchemy introduces a high-level open-source code library that makes it more uncomplicated for Python programmers to entry relational databases akin to Oracle, DB2, MySQL, PostgreSQL, and SQLite. SQLAlchemy has develop into more and more well known in view that its free up, however it nonetheless lacks sturdy offline documentation. This useful ebook fills the space, and since a developer wrote it, you get an aim examine SQLAlchemy's instruments instead of an advocate's description of the entire "cool" features.

SQLAlchemy contains either a database server-independent SQL expression language and an object-relational mapper (ORM) that permits you to map "plain previous Python objects" (POPOs) to database tables with out considerably altering your latest Python code. crucial SQLAlchemy demonstrates the way to use the library to create an easy database software, walks you thru basic queries, and explains the best way to use SQLAlchemy to connect with a number of databases at the same time with an analogous Metadata. you furthermore mght find out how to:

* Create customized varieties for use on your schema, and while it's important to take advantage of customized instead of integrated forms
* Run queries, updates, and deletes with SQLAlchemy's SQL expression language
* construct an item mapper with SQLAlchemy, and comprehend the diversities among this and lively list styles utilized in different ORMs
* Create items, keep them to a consultation, and flush them to the database
* Use SQLAlchemy to version item orientated inheritance
* offer a declarative, lively list trend to be used with SQLAlchemy utilizing the Elixir extension
* Use the SQLSoup extension to supply an automated metadata and item version according to database mirrored image

In addition, you'll find out how and whilst to exploit different extensions to SQLAlchemy, together with AssociationProxy, OrderingList, and more.

Essential SQLAlchemy is the much-needed advisor for each Python developer utilizing this code library. rather than a feature-by-feature documentation, this booklet takes an "essentials" method that offers you precisely what you want to turn into efficient with SQLAlchemy correct away.

Mastering Regular Expressions (3rd Edition)

Regular expressions are an exceptionally strong instrument for manipulating textual content and information. they're now typical good points in a variety of languages and well known instruments, together with Perl, Python, Ruby, Java, VB. web and C# (and any language utilizing the . internet Framework), personal home page, and MySQL.

if you happen to don't use normal expressions but, you'll find during this ebook a complete new global of mastery over your info. for those who already use them, you'll take pleasure in this book's unheard of aspect and breadth of insurance. in case you imagine you recognize all you want to find out about general expressions, this e-book is a beautiful eye-opener.

As this e-book exhibits, a command of standard expressions is a useful ability. standard expressions let you code complicated and refined textual content processing that you simply by no means imagined can be automatic. ordinary expressions can prevent time and aggravation. they are often used to craft based options to quite a lot of difficulties. as soon as you've mastered general expressions, they'll turn into a useful a part of your toolkit. you are going to ask yourself the way you ever received by means of with no them.

but regardless of their vast availability, flexibility, and extraordinary strength, commonplace expressions are often underutilized. but what's strength within the palms of a professional might be fraught with peril for the unwary. learning typical Expressions can assist you navigate the minefield to changing into a professional and assist you optimize your use of standard expressions.

studying commonplace Expressions, 3rd variation, now incorporates a complete bankruptcy dedicated to Hypertext Preprocessor and its strong and expressive suite of standard expression capabilities, as well as improved Hypertext Preprocessor assurance within the crucial "core" chapters. in addition, this version has been up-to-date all through to mirror advances in different languages, together with improved in-depth assurance of Sun's java. util. regex package deal, which has emerged because the common Java regex implementation. themes include:
* A comparability of beneficial properties between diverse types of many languages and instruments
* How the normal expression engine works
* Optimization (major discount rates on hand the following! )
* Matching simply what you will want, yet now not what you don't wish
* Sections and chapters on person languages

Written within the lucid, wonderful tone that makes a posh, dry subject turn into crystal-clear to programmers, and sprinkled with ideas to complicated real-world difficulties, studying average Expressions, 3rd version deals a wealth details so that you can positioned to rapid use.

Reviews of this re-creation and the second one edition:

"There isn't a greater (or extra priceless) ebook to be had on normal expressions. "

--Zak Greant, dealing with Director, eZ Systems

"A actual tour-de-force of a ebook which not just covers the mechanics of regexes in striking aspect but additionally talks approximately potency and using regexes in Perl, Java, and . internet. .. in the event you use average expressions as a part of your expert paintings (even when you have already got an excellent publication on no matter what language you're programming in) i'd strongly suggest this ebook to you. "

--Dr. Chris Brown, Linux Format

"The writer does a great activity top the reader from regex amateur to grasp. The booklet is intensely effortless to learn and chock choked with important and appropriate examples. .. typical expressions are useful instruments that each developer must have of their toolbox. learning usual Expressions is the definitive consultant to the topic, and a very good source that belongs on each programmer's bookshelf. Ten out of Ten Horseshoes. "

--Jason Menard, Java Ranch

Python Developer's Handbook

The Python Developer's guide is designed to reveal skilled builders to Python and its makes use of. starting with a short advent to the language and its syntax, the booklet strikes fast into extra complex programming issues, together with embedding Python, community programming, GUI toolkits, JPython, net improvement, Python/C API, and extra.

Python 201: Intermediate Python

Python 201 is the sequel to my first ebook, Python one hundred and one. in case you already be aware of the fundamentals of Python and now you must visit the following point, then this can be the e-book for you! This ebook is for intermediate point Python programmers basically. There will not be any newbie chapters the following. This booklet relies onPython three.

Additional resources for Effective Python: 59 Specific Ways to Write Better Python (Effective Software Development Series)

Sample text

If the format of the dates is not very strange, you can try the autodetection routines that specify the column that contains the date data. csv', parse_dates=[0]) fake_dataset Out: Date Temperature_city_1 Temperature_city_2 Which_destination 0 2014-09-10 80 32 40 1 1 2014-09-11 100 50 36 2 2 2014-09-12 102 55 46 1 3 2014-09-13 60 20 4 2014-09-14 60 NaN 32 3 5 2014-09-15 NaN 57 42 2 35 Temperature_city_3 3 Now, to get rid of the missing data that is indicated as NaN, replace them with a more meaningful number (let's say 50 Fahrenheit, for example).

In line [3], we use the magic function timeit to a Python assignment (x=100). The timeit function runs this instruction many times and stores the computational time needed to execute it. Finally, it prints the average time that was taken to run the Python function. We complete the overview with a list of all the possible IPython special functions by running the helper function quickref, as shown in line [4]. [ 14 ] Chapter 1 As you noticed, each time we use IPython, we have an input cell and optionally, an output cell, if there is something that has to be printed on stdout.

The pandas library offers similar functionality (and functions) to load MS Excel, HDFS, SQL, JSON, HTML, and Stata datasets. Since they're not used often, the understanding of how one can load and handle them is left to you, who can refer to the verbose documentation available on the website. A basic example on how to load an SQL table is available in the code that accompanies the book. Finally, pandas DataFrames can be created by merging series or other list-like data. '}) my_own_dataset Out: 0 Col1 Col2 Col3 Col4 0 1 1 Hello World!

Download PDF sample

Rated 4.37 of 5 – based on 9 votes