background preloader

Python fr:Préface

Python fr:Préface
You have seen how you can reuse code in your program by defining functions once. 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. 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' $ python module_using_sys.py The command line arguments are: module_using_sys.py we are arguments The PYTHONPATH is ['/tmp/py', # many entries here, not shown here '/Library/Python/2.7/site-packages', '/usr/local/lib/python2.7/site-packages'] How It Works 11.1. 11.2. 11.3. 11.4. 11.5.

Python | Le Mad Blog Vous êtes djangonautes ? Et vous n’avez pas encore acheté votre billet pour DjangoCon Europe ? Alors peut-être que vous ne le saviez pas. Après tout, même si on a essayé de faire un maximum de com sur le sujet, on n’en fait jamais assez et il est fort possible que vous soyez passé à coté. Donc, je vous refais un petit topo. 3 jours de confs du 13 au 15 mai et 2 jours de sprint le 16 et 17 mai. Mais surtout, surtout, ce ne sont pas trois jours de confs dans une simple salle de conf, aussi belle soit-elle. Non, ce sont trois jours de confs (et 2 jours de sprint) dans une île. Imaginez donc la scéne. Et puis après 10 minutes d’une aventureuse traversée, vous accosterez, tel Jim Hawkins, sur l’île des poneys ! Et puis on s’est dit que comme c’était sur une île, y il y avait donc des plages. En fait, la seule chose que l’on ne fournit pas, c’est la crème solaire. Bon après vous allez me dire que tout ça, c’est bien beau. Vous voulez comprendre à quoi sert App Loading ?

Learn Python in 10 minutes NOTE: If you would like some Python development done, my company, Stochastic Technologies, is available for consulting. 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 So, you want to learn the Python programming language but can't find a concise and yet full-featured tutorial. Properties Python is strongly typed (i.e. types are enforced), dynamically, implicitly typed (i.e. you don't have to declare variables), case sensitive (i.e. var and VAR are two different variables) and object-oriented (i.e. everything is an object). Getting help Help in Python is always available right in the interpreter. >>> help(5)Help on int object:(etc etc) >>> dir(5)['__abs__', '__add__', ...] >>> abs. Syntax Python has no mandatory statement termination characters and blocks are specified by indentation. Strings

The Official web2py Book I believe that the ability to easily build high quality web applications is of critical importance for the growth of a free and open society. This prevents the biggest players from monopolizing the flow of information. Hence I started the web2py project in 2007, primarily as a teaching tool with the goal of making web development easier, faster, and more secure. As a result, in 2011, web2py won the Bossie Award for best Open Source Development Software, and in 2012 it won the Technology of the Year award from InfoWorld. As you will learn in the following pages, web2py tries to lower the barrier of entry to web development by focusing on three main goals: Ease of use. Rapid development. Security. web2py is built from the user perspective and is constantly being optimized internally to become faster and leaner, whilst always maintaining backwards compatibility. web2py provides its users with the generous freedoms of the LGPL open source licence.

The "Invent with Python" Blog I frequently see a problem when people (especially techies) try to teach programming to someone (especially non-techies). 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. 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. 2. 3. I began learning BASIC in the third grade. 4. 5. Enough said.

Apprendre à programmer avec Python Un livre de Wikilivres. Ce livre a été rédigé par Gérard Swinnen qui le met à disposition sur son site personnel [archive] en licence GFDL. À faire... formater tous les chapitres selon le livre imprimé importer les captures d'écran [1] demander à l'auteur la licence des schémas intégrer les exercices éradiquer les {{todo}}lier les pages ( Non : attendre la spécification et l'implémentation de css3)établir l'indexétablir un glossaire Sommaire[modifier | modifier le wikitexte] Voir aussi[modifier | modifier le wikitexte] Programmation Python

Python beginner's mistakes Every Python programmer had to learn the language at one time, and started out as a beginner. 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. 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 This is a mistake that is almost unavoidable. Some notorious symptoms of "language X" code, and the languages that may cause them: The point here is not to slam the language that you're used to (although that is always fun ;-). This one requires some clarification. Some advice

19.13. xml.etree.ElementTree — The ElementTree XML API — Python v2.7.2 documentation The Element type is a flexible container object, designed to store hierarchical data structures in memory. The type can be described as a cross between a list and a dictionary. To create an element instance, use the Element constructor or the SubElement() factory function. The ElementTree class can be used to wrap an element structure, and convert it from and to XML. A C implementation of this API is available as xml.etree.cElementTree. See for tutorials and links to other docs. 19.7.1. This is a short tutorial for using xml.etree.ElementTree (ET in short). 19.7.1.1. XML is an inherently hierarchical data format, and the most natural way to represent it is with a tree. 19.7.1.2. We’ll be using the following XML document as the sample data for this section: <? We have a number of ways to import the data. import xml.etree.ElementTree as ETtree = ET.parse('country_data.xml')root = tree.getroot() Reading the data from a string: >>> root[0][1].text'2008' <? <?

The Django Book Karrigell/Home page Home page[edit] For the moment we'll ignore the CDs and begin writing the home page Create a new folder mycds in your Karrigell distribution, under the www folder. def index(): print "<h1>My CD collection</h1>" In your browser ask localhost/mycds/index.ks/index The extension "ks" (Karrigell Service) means that the script is a Python script where functions match urls : here, index.ks/index means that the function index() will send the data back to the browser In fact if you don't specify a function name, the index() function in the script will be run, so you could have asked localhost/mycds/index.ksand if you don't even specify a script name in a folder, the script called index will be run. Notice the print statement in the index() function. Adding a page counter[edit] The page counter will print the number of times that the page has been seen. Each time the page is reloaded, you will see the number of visits incremented by 1 A better page counter[edit] Use the built-in Session() function

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. Last Updated: 21 April 2012 Copyright NoticeForewordPrefaceContributor ListChapter 1 The way of the programChapter 2 Variables, expressions, and statementsChapter 3 FunctionsChapter 4 ConditionalsChapter 5 Fruitful functionsChapter 6 IterationChapter 7 StringsChapter 8 Case Study: CatchChapter 9 ListsChapter 10 Modules and filesChapter 11 Recursion and exceptionsChapter 12 DictionariesChapter 13 Classes and objectsChapter 14 Classes and functionsChapter 15 Classes and methodsChapter 16 Sets of ObjectsChapter 17 InheritanceChapter 18 Linked ListsChapter 19 StacksChapter 20 QueuesChapter 21 TreesAppendix A DebuggingAppendix B GASPAppendix c Configuring Ubuntu for Python DevelopmentAppendix D Customizing and Contributing to the BookGNU Free Document License Search Page © Copyright 2010, Jeffrey Elkner, Allen B.

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. 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. Running Python #! #!

Related: