background preloader

Tutorials

Facebook Twitter

Computer Science Circles. Pythoneering. Python - Notes. You have seen how you can reuse code in your program by defining functions once.

Python - Notes

What if you wanted to reuse a number of functions in other programs that you write? As you might have guessed, the answer is modules. There are various methods of writing modules, but the simplest way is to create a file with a .py extension that contains functions and variables. Another method is to write the modules in the native language in which the Python interpreter itself was written. For example, you can write modules in the C programming language and when compiled, they can be used from your Python code when using the standard Python interpreter. A module can be imported by another program to make use of its functionality. Example (save as module_using_sys.py): import sys print('The command line arguments are:')for i in sys.argv: print i print '\n\nThe PYTHONPATH is', sys.path, '\n' How It Works First, we import the sys module using the import statement. Learn Python in 10 minutes. NOTE: If you would like some Python development done, my company, Stochastic Technologies, is available for consulting.

Learn Python in 10 minutes

This tutorial is available as a short ebook. The e-book features extra content from follow-up posts on various Python best practices, all in a convenient, self-contained format. All future updates are free for people who purchase it. Preliminary fluff. Learning to Program with Python. Here we will use the python programming language to make a game of hangman, starting from scratch, working on a Macintosh.

Learning to Program with Python

Python comes with OS X, so nothing special needs to be installed to follow along on your Mac. To use python on Windows, you can download and install python here. If you do not want to install python or you want to learn a newer and popular python-like language that runs in any modern browser, you can read Learning to Program with CoffeeScript, at davidbau.com/coffeescript. The CoffeeScript version of this tutorial adds examples using graphics and synchronization. It takes a couple hours to learn enough programming to make a simple game. We will learn about: Memory and naming Computer arithmetic Using and learning libraries How to make a program Input and output Loops and choices Connecting to the internet At the end we will have a game we can play. This page was originally posted at for teaching a small group of third-graders.

Learning with Python. Navigation How to Think Like a Computer Scientist¶ Learning with Python¶ 2nd Edition (Using Python 2.x) by Jeffrey Elkner, Allen B.

Learning with Python

Downey, and Chris Meyers Last Updated: 21 April 2012. Learn Python The Hard Way - Opinions. Invent Computer Games with Python. The "Invent with Python" Blog. I frequently see a problem when people (especially techies) try to teach programming to someone (especially non-techies).

The "Invent with Python" Blog

Many programming tutorials begin with basic programming principles: variables, loops, data types. This is both an obvious way to teach programming and almost certainly a wrong way to teach programming. It’s wrong because nobody wants to learn how to program. If you are teaching a class of adults who are paying with their own money for an education, then this is an appropriate and direct way to teach programming. It’s their money. But for the casually interested or schoolchildren with several activities competing for their attention, programming concepts like variables and loops and data types aren’t interesting in themselves. Here are my five pieces of advice to people who want to teach programming or create programming tutorials: 1.

But people can feel the limitations that these programs have. The Django Book. Python beginner's mistakes. Every Python programmer had to learn the language at one time, and started out as a beginner.

Python beginner's mistakes

Beginners make mistakes. This article highlights a few common mistakes, including some I made myself. Beginner's mistakes are not Python's fault, nor the beginner's. They're merely a result of misunderstanding the language. However, there is a difference between misunderstanding (often subtle) language features, vs misunderstanding the language as a whole, and what can (and cannot) be done with it. To put it another way, the mistakes in this article are often cases of "the wrong tool for the job", rather than coding errors or sneaky language traps. Mistake 1: trying to do low-level operations Python is sometimes described as a VHLL, a Very High-Level Language.

This doesn't mean that it isn't possible to do these things with Python; but it's probably just not the right language for these jobs. Mistake 2: writing "language X" code in Python.