background preloader

Python

Facebook Twitter

GUI Programming with Python: Python Tkinter Tutorial. Introduction We have often been asked: "Is there no Tk for Python?

GUI Programming with Python: Python Tkinter Tutorial

" or "Is Tkinter the same as Tk? " Of course, there is Tk for Python. Without Tk Python would be less attractive to many users. Tk is called Tkinter in Python, or to be precise, Tkinter is the Python interface for Tk. Tk was developed as a GUI extension for the Tcl scripting language by John Ousterhout. Tk provides the following widgets: Learning Python, 5th Edition. Be careful with exec and eval in Python. Written on Tuesday, February 1, 2011 One of the perceived features of a dynamic programming language like Python is the ability to execute code from a string.

Be careful with exec and eval in Python

In fact many people are under the impression that this is the main difference between something like Python and C#. That might have been true when the people compared Python to things like C. It's certainly not a necessarily a feature of the language itself. For instance Mono implements the compiler as a service and you can compile C# code at runtime, just like Python compiles code at runtime. Wait what. Command-line syntax: some basic concepts. I’ve been reading about parsers for command-line arguments lately, for example Plac.

Command-line syntax: some basic concepts

And, as Michele Simionato says: There is no want of command line arguments parsers in the Python world. The standard library alone contains three different modules: getopt (from the stone age), optparse (from Python 2.3) and argparse (from Python 2.7). How To Use Linux epoll with Python. Contents Introduction As of version 2.6, Python includes an API for accessing the Linux epoll library.

How To Use Linux epoll with Python

This article uses Python 3 examples to briefly demonstrate the API. S Guide to Network Programming. Using Internet Sockets Brian "Beej Jorgensen" Hall beej@beej.us Version 3.0.15 July 3, 2012 Copyright © 2012 Brian "Beej Jorgensen" Hall Contents 1. 1.1.

s Guide to Network Programming

Python Packaging. 14.1.

Python Packaging

Introduction There are two schools of thought when it comes to installing applications. The first, common to Windows and Mac OS X, is that applications should be self-contained, and their installation should not depend on anything else. This philosophy simplifies the management of applications: each application is its own standalone "appliance", and installing and removing them should not disturb the rest of the OS. If the application needs an uncommon library, that library is included in the application's distribution.

How to handle multiple inheritance of ABCs that implement each others abstract methods. Let's say I have two ABCs, NeedA and NeedB, that implement each others' abstract methods: class NeedA(metaclass=abc.ABCMeta): @abc.abstractmethod def need_A(self): pass def need_B(self): pass class NeedB(metaclass=abc.ABCMeta): @abc.abstractmethod def need_B(self): pass def need_A(self): pass Now, how do you create a subclass, through multiple inheritance, that inherits both ABCs such that their abstract method requirements are met by each other?

How to handle multiple inheritance of ABCs that implement each others abstract methods

You can't do the naive solution of inheriting both because whomever comes first in the inheritance chain will trigger a TypeError: class SubClass(NeedA, NeedB): pass SubClass() # Raises TypeError for NeedA.need_A not being implemented. The TypeError is triggered because NeedA.need_A() shadows NeedB.need_A(), preventing the abstract method from being implemented. Luckily it is easy to get around this:

Debugging in Python. As a programmer, one of the first things that you need for serious program development is a debugger.

Debugging in Python

Python has a debugger, which is available as a module called pdb (for “Python DeBugger”, naturally!). Unfortunately, most discussions of pdb are not very useful to a Python newbie — most are very terse and simply rehash the description of pdb in the Python library reference manual. The discussion that I have found most accessible is in the first four pages of Chapter 27 of the Python 2.1 Bible. Unicode for dummies – just use UTF-8. Revised 2012-03-18 — fixed a bad link, and removed an incorrect statement about the origin of the terms “big-endian” and “little-endian”.

Unicode for dummies – just use UTF-8

Commenting on my previous post about Unicode, an anonymous commentator noted that the usage of the BOM [the Unicode Byte Order Mark] with UTF-8 is strongly discouraged and really only a Microsoft-ism. It’s not used on Linux or Macs and just tends to get in the way of things. So it seems worth-while to talk a bit more about the BOM. And in the spirit of Beginners Introduction for Dummies Made Simple, let’s begin at the beginning: by distinguishing big and little from left and right. Completely Different — jesse noller - a blog. One of the cooler features that came with Python 2.5's release is the 'with' statement and the context manager protocol behind it.

Completely Different — jesse noller - a blog

I could make the argument that these two things alone make the upgrade to Python 2.5 more than compelling for those of you trapped in the dark ages of 2.4 or worse: 2.3! This is a reprint of an article I wrote for Python Magazine as a Completely Different column that was published in the July 2008 issue. Python Programming. Python Programming From Wikibooks, open books for an open world Jump to: navigation, search This book describes Python, an open-source general-purpose interpreted programming language available for a broad range of operating systems. There are currently three major implementations: the standard implementation written in C, Jython written in Java, and IronPython written in C# for the .NET environment. There are two common versions currently in use: 2.x and 3.x. Contents[edit] Think Python: How to Think Like a Computer Scientist. How to Think Like a Computer Scientist by Allen B.

Downey.

Frameworks and Libs

Start Programming with Python. Introduction to Python. This is the material which I use for teaching python to beginners. tld;dr: Very minimal explanation more code. Introduction to Programming with Python. Text Processing in Python (a book) A couple of you make donations each month (out of about a thousand of you reading the text each week). Tragedy of the commons and all that... but if some more of you would donate a few bucks, that would be great support of the author. In a community spirit (and with permission of my publisher), I am making my book available to the Python community. Minor corrections can be made to later printings, and at the least errata noted on this website.

Email me at <mertz@gnosis.cx> . A few caveats: (1) This stuff is copyrighted by AW (except the code samples which are released to the public domain). Test-Driven Web Development with Python. Test-Driven Development with Python Test-Driven Development with Python Harry Percival Gillian McGarvey Rebecca Demarest. The Art and Craft of Programming. Python Threads and the Global Interpreter Lock — jesse noller - a blog.

Python Practice Book. Python Module of the Week. Python Koans. (the eff-bot guide to) The Standard Python Library. Overviews (15) Python Scientific Lecture Notes. Python Programming. Snake Wrangling for Kids. Welcome to Problem Solving with Algorithms and Data Structures — Problem Solving with Algorithms and Data Structures. Code Like a Pythonista: Idiomatic Python. In this interactive tutorial, we'll cover many essential Python idioms and techniques in depth, adding immediately useful tools to your belt. There are 3 versions of this presentation: ©2006-2008, licensed under a Creative Commons Attribution/Share-Alike (BY-SA) license.

Generator Tricks for Systems Programmers. Generator Tricks for Systems Programmers Copyright (C) 2008David M. Presented at PyCon'08, March 13, 2008, Chicago, Illinois. Python Bibliotheca. Python Idioms. Welcome to Python for you and me. Python for Informatics : Exploring Information. Python for Fun. This collection is a presentation of several small Python programs. They are aimed at intermediate programmers; people who have studied Python and are fairly comfortable with basic recursion and object oriented techniques. Each program is very short, never more than a couple of pages and accompanied with a write-up. I have found Python to be an excellent language to express algorithms clearly. Some of the ideas here originated in other programs in other languages. But in most cases I developed code from scratch from just an outline of an idea. Full Stack Python. Deep Thoughts by Raymond Hettinger. If you aren’t wowed by Python’s super() builtin, chances are you don’t really know what it is capable of doing or how to use it effectively.

Much has been written about super() and much of that writing has been a failure. This article seeks to improve on the situation by: providing practical use casesgiving a clear mental model of how it worksshowing the tradecraft for getting it to work every timeconcrete advice for building classes that use super()favoring real examples over abstract ABCD diamond diagrams. Python and the Principle of Least Astonishment. Written on Saturday, July 9, 2011. A Curious Course on Coroutines and Concurrency. Copyright (C) 2009, All Rights ReservedDavid Presented at PyCon 2009, March 25, 2009. Related Tutorials. Dive Into Python 3. Dive Into Python. Non-Programmer's Tutorial for Python 2.6. Book.

Modeling Creativity. Scientific Python Lectures. Learning to program. Python Cookbook. Python 2.7 quick reference. Program Arcade Games With Python And Pygame. Welcome to Problem Solving with Algorithms and Data Structures — Problem Solving with Algorithms and Data Structures.

Porting to Python 3: An in-depth guide. Non-Programmer's Tutorial for Python 3. Python Ecosystem – An Introduction · mirnazim.org. Tutorial Part 2: Adding a JIT. Tutorial: Writing an Interpreter with PyPy, Part 1. Learn Python The Hard Way, 3rd Edition. Of Python and Road Maps (or the lack thereof) Interfaces or Abstract Base Classes? Python’s Innards: Introduction. 006: Introduction to Algorithms - Massachusetts Institute of Technology. S Python Class - Educational Materials. How to Think Like a Computer Scientist. The Hitchhiker’s Guide to Python! Hacking Secret Ciphers with Python. Making Games with Python & Pygame - Chapters. Invent Your Own Computer Games with Python - Chapters.

Hacking Secret Ciphers with Python - Chapters. Google Python Style Guide. Jesse Noller. Intermediate and Advanced Software Carpentry in Python. Learn Python The Hard Way, 3rd Edition. Style Guide for Python Code. A Byte of Python. Carl Groner > An Introduction to List Comprehensions in Python. Crash into Python. BeginnersGuide/Programmers. Python Interfaces are not Java Interfaces (dirtSimple.org) Hidden features of Python. Speed/PerformanceTips. Charming Python: Decorators make magic easy. A Beginner's Python Tutorial. A Guide to Python's Magic Methods « rafekettler.com.

Data Structures and Algorithms with Object-Oriented Design Patterns in Python.