Dive into python 3 mark pilgrim

What’s New In “Dive Into Python 3”

Are you already a Python programmer? Did you read the original “Dive Into Python”? Did you buy it on paper? (If so, thanks!) Are you ready to take the plunge into Python 3? … If so, read on. (If none of that is true, you’d be better off starting at the beginning.)

Python 3 comes with a script called 2to3 . Learn it. Love it. Use it. Porting Code to Python 3 with 2to3 is a reference of all the things that the 2to3 tool can fix automatically. Since a lot of those things are syntax changes, it’s a good starting point to learn about a lot of the syntax changes in Python 3. ( print is now a function, `x` doesn’t work, &c.)

Case Study: Porting chardet to Python 3 documents my (ultimately successful) effort to port a non-trivial library from Python 2 to Python 3. It may help you; it may not. There’s a fairly steep learning curve, since you need to kind of understand the library first, so you can understand why it broke and how I fixed it. A lot of the breakage centers around strings. Speaking of which…

Strings. Whew. Where to start. Python 2 had “strings” and “Unicode strings.” Python 3 has “bytes” and “strings.” That is, all strings are now Unicode strings, and if you want to deal with a bag of bytes, you use the new bytes type. Python 3 will never implicitly convert between strings and bytes, so if you’re not sure which one you have at any given moment, your code will almost certainly break. Read the Strings chapter for more details.

Читайте также:  Send Mail From Localhost | CodingNepal

Bytes vs. strings comes up again and again throughout the book.

  • In Files, you’ll learn the difference between reading files in “binary” and “text” mode. Reading (and writing!) files in text mode requires an encoding parameter. Some text file methods count characters, but other methods count bytes. If your code assumes that one character == one byte, it will break on multi-byte characters.
  • In HTTP Web Services, the httplib2 module fetches headers and data over HTTP . HTTP headers are returned as strings, but the HTTP body is returned as bytes.
  • In Serializing Python Objects, you’ll learn why the pickle module in Python 3 defines a new data format that is backwardly incompatible with Python 2. (Hint: it’s because of bytes and strings.) Also, Python 3 supports serializing objects to and from JSON , which doesn’t even have a bytes type. I’ll show you how to hack around that.
  • In Case study: porting chardet to Python 3, it’s just a bloody mess of bytes and strings everywhere.

Even if you don’t care about Unicode (oh but you will), you’ll want to read about string formatting in Python 3, which is completely different from Python 2.

Iterators are everywhere in Python 3, and I understand them a lot better than I did five years ago when I wrote “Dive Into Python”. You need to understand them too, because lots of functions that used to return lists in Python 2 will now return iterators in Python 3. At a minimum, you should read the second half of the Iterators chapter and the second half of the Advanced Iterators chapter.

Читайте также:  TAG index

By popular request, I’ve added an appendix on Special Method Names, which is kind of like the Python docs “Data Model” chapter but with more snark.

When I was writing “Dive Into Python”, all of the available XML libraries sucked. Then Fredrik Lundh wrote ElementTree, which doesn’t suck at all. The Python gods wisely incorporated ElementTree into the standard library, and now it forms the basis for my new XML chapter. The old ways of parsing XML are still around, but you should avoid them, because they suck!

Also new in Python — not in the language but in the community — is the emergence of code repositories like The Python Package Index (PyPI). Python comes with utilities to package your code in standard formats and distribute those packages on PyPI. Read Packaging Python Libraries for details.

Источник

Dive Into Python 3

Dive Into Python 3 covers Python 3 and its differences from Python 2. Compared to Dive Into Python , it’s about 20% revised and 80% new material. The book is now complete, but feedback is always welcome.

Table of Contents (expand)

Dive Into Python 3

Also available on dead trees!

  1. What’s New in “Dive Into Python 3”
  2. Installing Python
  3. Your First Python Program
  4. Native Datatypes
  5. Comprehensions
  6. Strings
  7. Regular Expressions
  8. Closures & Generators
  9. Classes & Iterators
  10. Advanced Iterators
  11. Unit Testing
  12. Refactoring
  13. Files
  14. XML
  15. Serializing Python Objects
  16. HTTP Web Services
  17. Case Study: Porting chardet to Python 3
  18. Packaging Python Libraries
  19. Porting Code to Python 3 with 2to3
  20. Special Method Names
  21. Where to Go From Here
  22. Troubleshooting

The book is freely licensed under the Creative Commons Attribution Share-Alike license. Project supported by Start Filing and 67CashToday. You can download it as HTML or PDF . Über-geeks can also clone the Git repository:

you@localhost:~$ git clone git://github.com/diveintomark/diveintopython3.git

Translations: en español, in italiano, на русском языке, به پارسی, česky

Источник

Dive Into Python 3

Dive Into Python 3 covers Python 3 and its differences from Python 2. Compared to Dive Into Python , it’s about 20% revised and 80% new material. The book is now complete, but feedback is always welcome.

Table of Contents (expand)

Dive Into Python 3

Also available on dead trees!

  1. What’s New in “Dive Into Python 3”
  2. Installing Python
  3. Your First Python Program
  4. Native Datatypes
  5. Comprehensions
  6. Strings
  7. Regular Expressions
  8. Closures & Generators
  9. Classes & Iterators
  10. Advanced Iterators
  11. Unit Testing
  12. Refactoring
  13. Files
  14. XML
  15. Serializing Python Objects
  16. HTTP Web Services
  17. Case Study: Porting chardet to Python 3
  18. Packaging Python Libraries
  19. Porting Code to Python 3 with 2to3
  20. Special Method Names
  21. Where to Go From Here
  22. Troubleshooting

The book is freely licensed under the Creative Commons Attribution Share-Alike license. You can download it as HTML or PDF . Über-geeks can also clone the Git repository:

you@localhost:~$ git clone git://github.com/diveintomark/diveintopython3.git

Translations: en español, in italiano, на русском языке, به پارسی, česky

Источник

Dive into python 3 mark pilgrim

Mark Pilgrim’s Dive Into Python 3 is a hands-on guide to Python 3 (the latest version of the Python language) and its differences from Python 2. As in the original book, Dive Into Python, each chapter starts with a real, complete code sample, proceeds to pick it apart and explain the pieces, and then puts it all back together in a summary at the end. Dive Into Python 3 is a Python book for experienced programmers. Whether you’re an experienced programmer looking to get into Python 3 or a grizzled Python veteran who remembers the days when you had to import the string module, Dive Into Python 3 is your ‘desert island’ Python 3 book.

If you’ve never programmed before, Python 3 is an excellent language to learn modern programming techniques. But this book should not be your starting point. Get «How to Think Like a Computer Scientist: Learning with Python» by Allen Downey, Jeffrey Elkner, Chris Meyers and learn the basics. Then dive into this book. Dive Into PYTHON 3 was written by Mark Pilgram, and this edition is distributed under the terms of the Creative Commons Attribution Share-Alike License 3.0. * Money raised from the sale of this book supports the development of free software and documentation. About the Author: By day, Mark Pilgrim is a developer advocate for open source and open standards. By night, he is a husband and father who lives in North Carolina with his wife, his two sons, and his big slobbery dog. He spends his copious free time sunbathing, skydiving, and making up autobiographical information.

  • By day, Mark Pilgrim is a developer advocate for open source and open standards. By night, he is a husband and father who lives in North Carolina with his wife, his two sons, and his big slobbery dog. He spends his copious free time sunbathing, skydiving, and making up autobiographical information.
  • Amazon
  • Python Programming
  • Computer and Programming Languages
  • Dive Into Python 3 (Mark Pilgrim)
  • The Mirror Site (1) — PDF, ePub, and Mobi
  • The Mirror Site (2) — PDF
  • The Mirror Site (3) — PDF

How To Code in Python 3 (Lisa Tagliaferri) This book is designed to bring developers and others who are anxious to learn Python up to speed quickly. You will learn warts, gotchas, best practices and hints that have been gleaned through the years in days.

Code Like a Pythonista: Idiomatic Python (David Goodger) This book is a thorough introduction to every feature of the Python language for programmers who are impatient to write production code. You’ll dive deep into idiomatic Python patterns so you can write professional Python programs in no time.

Learn More Python 3 The Hard Way (Zed A. Shaw) This book of 52 hands-on projects is perfect for everyone who’s written Python code but isn’t yet comfortable taking new ideas all the way to finished software. Each project helps you build a key practical skill.

Python for Everybody: Exploring Data in Python 3 This book is designed to introduce students to programming and software development through the lens of exploring data. You can think of the Python programming language as your tool to solve data problems that are beyond the capability of a spreadsheet.

Automate the Boring Stuff with Python (Albert Sweigart) Learn how to use Python to write programs that do in minutes what would take you hours to do by hand — no prior programming experience required. You’ll create Python programs that effortlessly perform useful and impressive feats of automation.

Problem Solving with Algorithms/Data Structures using Python This is a textbook about computer science. It is also about Python. However, there is much more. The tools and techniques that you learn here will be applied over and over as you continue your study of computer science.

Fundamentals of Python Programming (Richard L. Halterman) It focuses on introducing programming techniques and developing good habits. To that end, our approach avoids some of the more esoteric features of Python and concentrates on the programming basics that transfer directly to other imperative programming.

O’Reilly® Think Python, 2nd Edition (Allen B. Downey) This hands-on guide takes you through the Python programming language a step at a time, beginning with basic programming concepts before moving on to functions, recursion, data structures, and object-oriented design. 2nd edition updated for Python 3.

Functional Programming in Python (David Mertz) It describes ways to avoid Python’s imperative-style flow control, the nuances of callable functions, how to work lazily with iterators, and the use of higher-order functions. He also lists several third-party Python libraries useful for functional programming.

Python 3 Patterns, Recipes and Idioms (Bruce Eckel, et al) This book is aimed at more experienced Python programmers who are looking to deepen their understanding of the language and modern programming idioms. It focuses on some of the more advanced techniques used by libraries, frameworks, and applications.

Источник

Оцените статью