Python Wiki
  • Python Wiki
  • PSF Wiki
  • Jython Wiki
    • Edit with CMS Use the web-based editor to create or edit wiki pages
    • Edit on GitHub Fork the repository and submit changes via pull request
/
  • Python Wiki
    • Archive
      • Aaronwatters
      • Admin
      • Andrew Kuchling
      • Asking For Help
      • Console
      • Email Sig
      • Etiennerobillard
      • Gis
      • Jam
      • Languages
      • Marc Andre Lemburg
      • Martinvonloewis
      • Pavloshevelo
      • Podcast
      • Powerpiano 17
      • Pythonconsulting
      • Pythonlibraryreference
      • Pythontraining
      • Yarko
      • Lwickjr
      • Techtonik
      • 2.x-vs-3.x-survey
      • API
      • API Extraction
      • Adapters and Interfaces Sprint
      • Adarshreddyash
      • Alexis Le Quoc
      • Anand B Pillai
      • Andybebad
      • Anthon van der Neut
      • Any GUI
      • APAC PyCon Wiki
      • App Engine
      • App Localization
      • App Logging
      • Application Frameworks
      • Application Infrastructure
      • Application Support Libraries
      • Applications
      • April Fools
      • Arabi CPython Books
      • Arithmo Graph
      • Arlington Sprint
      • Array Interface
      • Article Ideas
      • Ashley ZT
      • Ask Apache
      • Asking for Help
      • Asking for Help Template
      • At Aud iOS print
      • Attendee Notes
      • Attribute Based Syntax
      • Aug 2001 DB API 3 Strawman
      • Austin Python User Group
      • Auto XML RPC CGI
      • Auto XML RPC Server
      • Automated Refactoring Tools
      • BBR
      • BDFL
      • Base HTTP Server
      • Bazaar
      • Be Thon
      • Beginner Errors with Python Programming
      • Beginners Workshop
      • Berkeley DB
      • Better PyPI
      • Better Zope 2 Blob Support Sprint
      • Bharath venkatesh
      • Bicycle Repair Man
      • Bin Py
      • Birds of a Feather
      • Bit Arrays
      • Bit Manipulation
      • Bitwise Operators
      • Black Rose
      • Blaise Pascal
      • Boa Constructor
      • Boston Pig
      • Boulder Jam
      • Boulder Sprint
      • Box Model
      • Brain Storm
      • Brian Mc Enery
      • Bruger Indstillinger
      • Bug Tracking
      • Build an Intranet
      • Build PyQt4 Windows
      • Build Statically
      • Building Python with the free MS C Toolkit
      • Bundle Builder
      • Bv B 28 Aug
      • Bytes IO
      • Bytes Str
      • CAPI Cook Book
      • CJ
      • CLA
      • CLPython
      • Call for Paper 2011
      • Can I get a job with python?
      • Can Do
      • Canberra PUG
      • Castalian
      • Castelli Di Sabbia
      • Cat-tuong chu
      • Catalog Sig
      • catinsunshine
      • Cerca Pagina
      • CGI Scripts
      • Chaco
      • Chandler BOF
      • Chandler Sprint
      • Changements Récents
      • Charlottesville Python User Group
      • Cheese Shop
      • Cheese Shop Dev
      • Cheese Shop Tutorial
      • Cheetah
      • Chi Py
      • China Python User Group
      • Choice of Freebies
      • Choosing Database
      • Choosing GUI Toolkits
      • Chris at Lee
      • Chris Mc Donough
      • Chun Lin Zhang
      • Classic Structured Text
      • Cleanup URL Lib Project
      • Cleanup Urllib
      • Clear Silver
      • Client Side Web Cache
      • Climb Bo F
      • Cmd Module
      • Cobra
      • Code
      • Code Coverage
      • Code Discovery Use Cases
      • Code Tag
      • Codevisionz
      • Codice
      • Commandline Tools
      • Comment Based Syntax
      • Commercial Services
      • Common Ideas
      • Community
      • Community Job Boards
      • Comp Lang Python
      • Comparing Types
      • Complete SSL Support
      • Computer Camp Alexis
      • Con Text
      • Concatenation Test Code
      • Conceptual Roadmap
      • Config Obj
      • Configuration and Build Tools
      • Content Management Systems
      • Continuous Integration
      • Convention Howto
      • Cool Goose
      • Core Python
      • Core Dev Helper Tools
      • Core Development
      • Core Sprint
      • Courses
      • Crashing Python
      • Creating Buzz
      • Crusader
      • Cubic Temp
      • Curses Programming Links
      • Cvs to Svn
      • D Waldo Anderson
      • DB2
      • DC Python Nov 2010 Sprint
      • Da Liu Aus
      • Daniel Van Stone
      • Data Processing and Numerical Analysis
      • David Alan Foster
      • David Boddie Work
      • David Le Blanc
      • David M Patterson
      • David Mac Quigg
      • DB Obj
      • Dbus Examples
      • Dead Link
      • Dead Links
      • Debugging with Gdb
      • Decorator Pattern
      • Default Encoding
      • Delegation Event Model
      • Dependency Injection Pattern
      • Desert Py
      • Design Market Message
      • Desired Tracker Features
      • Deutsche Schlangen
      • Development Tools
      • Diacritical Editor
      • Diagrams
      • Dictionary Keys
      • Distribution Utilities
      • Dive Into Python
      • Divei Into Web
      • Diversity in Python
      • Diversity Statement Discussion
      • Dmitry S
      • Doc Sig
      • Doc Tools
      • Doc XML RPC Server
      • DocUtils BOF
      • DocUtils Sprint
      • Dopy
      • Dori
      • Doug
      • Dr Python
      • Dr Scheme
      • Draco
      • Dream Pie Feature Requests
      • Dream Pie Mac Support
      • Dubious Python
      • Duncan Mc Greggor
      • Dunder Alias
      • Durus
      • Dutch Python Books
      • Dvcs Comparison
      • EDAtools
      • EWDurbin
      • Early 2to 3 Migrations
      • Easy As Py
      • Edit Python Code Chinese
      • Editor Configuration Howto
      • Edu Python 2008
      • Edward Mokurai Cherlin
      • Eff Bot
      • Elections Workgroup Planning
      • Element Based Syntax
      • Element Tree
      • Em Py
      • Email SIG
      • Email Sig Sprint
      • Email Sprint
      • Embedded Python
      • Embeding PyQt Tutorial
      • Empty Subscript List PEP
      • Enfold Systems
      • Engineering Libraries
      • Enhanced PyPI
      • Enomalism
      • Enterprise Java Beans
      • Enthought Python
      • Entransit
      • Enumeration Programming
      • Environment Variables
      • Epy Doc
      • Erik Max Francis
      • Erik Van Blokland
      • Escaping HTML
      • Escaping XML
      • Esky
      • Executable Modules
      • Execution Scenar iOS
      • Extending the DB API
      • Extreme Programming
      • F2PY
      • Fabio
      • Find Side
      • Finite State Machine
      • Firebird
      • Fiscal Sponsorship
      • Flexible String Representation
      • Flourish 2011 Sprint
      • Flow Based Programming
      • For Loop
      • For Side
      • Form Encode
      • Format Reference
      • Forældreløse Sider
      • Frank Willison Award
      • Free Hosts
      • Free Memory
      • Free Software
      • Freeze
      • French Python Books
      • Frequently Rejected Ideas
      • From Function to Method
      • Function Wrappers
      • Functional Programming
      • Future Proof Python
      • Fx Py
      • Föräldrarlösa Sidor
      • GUI Programming in Python
      • Gadfly
      • General Libraries
      • German Python Books
      • Git
      • Git Svn Old
      • Global Interpreter Lock
      • Gm Py
      • Gnome Python
      • Gnu Emacs
      • Gnu Enterprise
      • Gnu Privacy Guard
      • Go Client Server
      • Google
      • Google Groups Python
      • Google Sprint
      • Google Sprint Py3k
      • Google Tips
      • Grako
      • Graphics and Images
      • Graphics BOF
      • Greek Python Books
      • Grok Sprint
      • Guido van Rossum
      • Guidovan Robot
      • GvR
      • Harvest Man
      • Health Care
      • Helping Python
      • Hidden Jewels
      • High Score
      • Higher Level Database Programming
      • Hjemmeside Skabelon
      • How do I keep a GUI alive during a long-running subprocess?
      • How Foss Conf Works
      • Hp Python Business Libraries
      • Humor
      • Hungarian Python Books
      • Hyper Toons
      • IPyKit
      • IPython
      • Idea Repository
      • If Statement with Value
      • Image Magick
      • Imp Module
      • Improving Lib Tests
      • InPyCon Design
      • In Their Own Words
      • Indonesia PUG
      • Infinite Filing Cabinet Open Space
      • Information Retrieval
      • Informix
      • Ingres
      • Initial Testing Plan
      • Inn and Conference Center
      • Integrating Python with Other Languages
      • Integration Lab
      • Inter Systems IRIS
      • Inter Wiki Map
      • Intermediate Conundrums
      • Intermediates Guide
      • International Python Conference
      • Internet Cafe
      • Internet Support
      • Intro to programming with Python and Tkinter
      • Inventory
      • iOS laves Tutorial
      • Iounchan
      • Irmen De Jong
      • Is there any tiny project or source for participation or reference
      • Italian Python Urlo Coordination
      • Italian Python Urlo Sources
      • Ivo
      • JAM
      • J Alan Brogan
      • JM
      • JOTWeb2
      • JPype
      • JZA
      • Jaguar
      • Jakarta PUG
      • Japanese Python Books
      • Java Data Objects
      • Je Xt
      • Jehovany
      • Jepp
      • Jim D
      • Jims PyCon Sprint Message
      • Jira Tracker
      • Jo Base
      • John MG
      • Jonathan Gardner PyQt Tutorial
      • Jons Python Modules
      • Just Another Pythoneer
      • Just Van Rossum
      • Jython
      • Jython Books
      • Jython Projects
      • Jython Sprint
      • Jython Success Stories
      • Jython Uses
      • Jürgen Hermann
      • KWWidgets
      • Ka Ping Yee
      • Kanis
      • Karrigell
      • Kategori Hjemmeside
      • Kategori Kategori
      • Keeping Lists in Dictionaries
      • Kesara
      • Key Error
      • Kirby Base
      • Kiwi
      • Kofiboadi
      • Komodo
      • L.I.S.A
      • LDLandis
      • Language Comparisons
      • Languages
      • Large Python Projects
      • Launchpad Tracker
      • Learn by Observation
      • Learn to Program
      • Learning Repertoire
      • Legacy Python Website
      • Leo Editor
      • Libraries
      • Library References Names
      • Lightning Talks
      • LinkedIn Python Individuals
      • LinkedIn Python Network
      • List of Interested Sprinters
      • List of Performance Related Patches
      • Lluis P 9
      • Lo Gix
      • Loading Modules Dynamically
      • Local Names Description
      • Localizing Chandler
      • Logging Package
      • Logic Tools
      • London Financial Python User Group
      • M2Crypto
      • MSS
      • Magyar Python
      • Mail Archiving Open Space
      • Mailing Lists and Newsgroups
      • Mailman 3 Sprint
      • Mailman with Google Groups
      • Manutenere Le Eccezioni
      • Marc Andre Lemburg
      • Martelli Bot
      • Mathai
      • Matplotlib Sprint
      • Matt D Mo
      • Md 5 Passwords
      • Melbourne PUG
      • Memento Pattern
      • Memory Usage Profiler
      • Mercurial
      • Meta Design Solutions
      • Meta Kit
      • Microsoft Access
      • Mid Summer
      • Middle Kit
      • Miguel González
      • Mini Dom
      • Minsk Python Meetup
      • Mirroring infrastructure
      • Missing from Documentation
      • Mod Python
      • Mod Python BOF
      • Modifiche Recenti
      • Modules As Plugins
      • Monta Vista
      • More Info
      • Most Popular Python Projects
      • Movable Python
      • Moving to Python from Perl
      • Mpl Mentors
      • Multi Line Lambda
      • Multi Line Strings in Doc Test
      • Multiple Dispatch
      • Myth Debunking
      • Naviga Il Sito
      • Navigation Site
      • Negros PUG
      • Netezza
      • Netflix Prize BOF
      • Networked Data
      • Networking Support
      • New Class vs Classic Class
      • New Users Group
      • Node Box
      • Non Commercial Hosting
      • Notebook Interface for Ipython
      • Num Array
      • OAuth2
      • ODBC
      • ODBCDrivers
      • OSPP
      • Object Manager Item
      • Ocean
      • One Laptop Per Child
      • Open Space
      • Open Embedded
      • Open Komodo
      • Open Source
      • Open Space
      • Open Space Sessions
      • Operator Hook
      • Opt Parse
      • Option Parsing
      • Organizations Using Python
      • Organizers Meetings Connection Details
      • Original Call for Trackers
      • Original Web Programming Classification
      • Other Commercial Hosts
      • Other Python Wikis
      • Out of Print Books
      • PATX
      • PEEPs
      • PEP 3107 Function Annotations Rehash
      • PSFInfrastructure
      • Package Popularity
      • Pallavi
      • Parallel Distutils
      • Parallel Processing
      • Parsing for Educational Linguistics
      • Past CPUG Meetups
      • Patch Triage
      • Path Class
      • Path Module
      • Path Module Tests
      • Pattern Programming
      • Patterns in Python
      • Paul Mc Guire
      • Paul Mc Nett
      • Pdb Improvments
      • Pdb Rc Idea
      • People Filter
      • PEP 382 Sprint
      • Perl Phrasebook
      • Persian Python Books
      • Persistence Tools
      • Philip
      • Php Phrasebook
      • Pickle
      • Pierre Alexandre SCHEMBRI
      • Plotly
      • Pmw
      • Podcast
      • Points and Rectangles
      • Polish Python Coders Group
      • Polish Python Books
      • Portable Python
      • Portuguese Python Books
      • Post Script
      • Power Piano 17
      • Pratul 1997
      • Praveen
      • Preferencias Del Usuario
      • Presentation Software
      • Presenter Sign Up
      • Previous Meeting on October 11 2007
      • Print As Function
      • Print Fails
      • Processo Programma
      • Programmatic
      • Project File and Directory Layout
      • Promoting Python BOF
      • Proposal for PyCon India
      • Proposal to Speed Up List Operations
      • Proxy Programming
      • PSF Materials
      • Publishing Python Modules
      • Pull Dom
      • Py Swallow Mail
      • Py2JS
      • PyACTS
      • PyAmazon
      • PyAnt
      • PyAr 2
      • PyAudio
      • PyBison
      • PyBrenda
      • PyCS
      • PyCell Studio
      • PyChart
      • PyChecker
      • PyChem
      • PyCore Ast Sprint
      • PyCore Sprint
      • PyCrust
      • PyDo
      • PyDS
      • PyDS Tool
      • PyDev
      • PyDoc
      • PyFit
      • PyFltk
      • PyGE
      • PyGSL
      • PyGUI
      • PyGd Chart
      • PyGd Module
      • PyGeo
      • PyGObject
      • PyGTK
      • PyGTK -ctypes
      • PyGTK 2 Tk
      • PyIMSL
      • PyIMSL Studio
      • PyInstaller
      • PyInterpreter
      • PyJaipur
      • Pyjamas
      • PyKDE
      • PyLaunchy
      • PyLint
      • PyLint-3k
      • PyLog
      • PyLucene
      • PyMat
      • PyMedia
      • PyMeld
      • PyMite
      • PyMy CMS BOF
      • PyObjectivec
      • PyOpenGL PyGame Open Space
      • PyPE
      • PyPerl
      • PyPerlish
      • PyPI Documentation Hosting
      • PyPI Implementations
      • PyPI Test Server
      • PyPort Midi
      • PyScripter
      • PySerial
      • PySide
      • PySimple GUI
      • PySnd Obj
      • PySoy
      • PyTable
      • PyTables
      • PyTextile
      • PyTrails
      • PyUi
      • PyUnit
      • PyWX
      • PyWeek
      • PyWiew
      • PyWin 32
      • Pyarmor
      • PyCon 2011 Sprint
      • PyCon India Checklist
      • PyCon Z 3 Sprint Questions
      • Pydotorg Redesign
      • Pyed Pyers
      • Pyjamas Desktop
      • Pypi package downloads statistics RSS
      • Pyro
      • Pythagorean Theorem
      • Python
      • Python 2.2.4
      • Python 2.3.1
      • Python Box
      • Python-2.0
      • Python-2.2
      • Python-2.3
      • Python 11
      • Python 12
      • Python 20 Critical Patches
      • Python 20 Frequently Asked Questions
      • Python 20 Misc Patches
      • Python 4 Delphi
      • Python and J 2 EE
      • Python and Parrot
      • Python Applications
      • Python Arabic Community
      • Python Asa First Language
      • Python Audio Material
      • Python Blog Software
      • Python Blogs
      • Python Bug Day
      • Python Business Forum
      • Python Business Forum BOF
      • Python Business Forum Open Space
      • Python Committer Guidelines
      • Python Consulting
      • Python Cook Book
      • Python Cook Book vs Active State Cook Book Discussion
      • Python Debuggers
      • Python Debugging Tools
      • Python Decorator Library
      • Python Decorator Proposals
      • Python Decorators
      • Python Dev Environments
      • Python Dev Wisdom
      • Python Developers
      • Python Developers on Twitter
      • Python Discussions
      • Python Distributions
      • Python Documentation
      • Python Dot Net Proposal
      • Python Enhancement Proposals
      • Python Federal Enterprise Architecture
      • Python for Arm Linux
      • Python for Operations Research
      • Python for Pocket PC
      • Python for Secretaries
      • Python for Security
      • Python for Systems Administration
      • Python Games
      • Python Glossary
      • Python Graph API
      • Python Graph Libraries
      • Python Humor
      • Python Imaging Library
      • Python Import Engine
      • Python in Education
      • Python in Web Page
      • Python Ina Tie
      • Python Info
      • Python Installed by Default
      • Python Jobs
      • Python Labs Python
      • Python Library Ref Template
      • Python Library Reference
      • Python Lore
      • Python Magick
      • Python Maputo
      • Python Med
      • Python Mug Signup
      • Python Notes
      • Python Org Website Redesign Open Space
      • Python Packaging Authorities
      • Python Packaging Terminology
      • Python Papers
      • Python Philosophy
      • Python Projects
      • Python Questions
      • Python Shells
      • pythonsites
      • Python Software Foundatio
      • Python Sound
      • Python Speakers
      • Python Style
      • Python Support
      • Python Testers
      • Python Testing Tools Taxonomy
      • Python Three Dot Oh
      • Python Training
      • Python Training Group
      • Python Tutor List
      • Python Urlo Week 30
      • Python Urlo Week 31
      • Python Urlo Week 32
      • Python Urlo Week 33
      • Python Urlo Week 34
      • Python User Group Dhaka
      • Python User Stories
      • Python vs C++
      • Python vs Haskell
      • Python vs Nice
      • Python vs Php
      • Python vs Ruby
      • Python Warts
      • Python Web Kit
      • Python Web Modules
      • Python Wiki Changes
      • Python Wiki Engines
      • Python Wiki Tasks
      • Python Wikipediabot
      • Python Win
      • Python Writers
      • Python XML
      • Python Zen Chinese Translate
      • Pythonware Python
      • Question Staticmethod
      • Question Type
      • RPM
      • RPM on Python 3
      • R PyC
      • Range Generator
      • Rdf Lib
      • Rdf Libraries
      • Reading HTML Forms
      • Recipe Template
      • Red Hat
      • Registrations Available
      • Regular Expression
      • Reinout Van Rees
      • Render Man
      • Representation Error
      • Response
      • Restricted Execution
      • Retrograde Orbit
      • Revised PyPI Categories
      • Richmond Python User Group
      • Roadmap
      • Ron Du Plain
      • Roundup
      • Routing
      • RSS Libraries
      • Russian Python Books
      • SAML
      • SAP DB
      • SIP
      • SOAP
      • SPE
      • Sachin deep
      • Sage Math
      • Salem Snakes
      • San Francisco
      • Sandbox
      • Sax
      • Schevo
      • School Tool
      • School Tool Sprint
      • Sci Te
      • Scientifi CPython
      • Screencasting
      • Scripting Java
      • Sea Pig
      • Secure Shell
      • See Gram Wrap
      • Semplici Programmi versione Italiana
      • Seneste Rettelser
      • Session Chair
      • Shadow Claw 20017
      • Shell Redirection Fails
      • Shell Run
      • Siac Nyse
      • Sim Py
      • Simple Todo
      • Singleton Programming
      • Site Navigering
      • Skeleton Builder Tools
      • Sketch
      • Skunk Web
      • Skype 4 Py
      • Slice Over Negatives
      • Smalltalk
      • Snake SQL
      • So You Wanna
      • Sorting Lists of Dictionaries
      • SourceForge
      • Spam Prevention
      • Spanish Python Books
      • Special Interest Groups
      • Special Interest Groups
      • Specialized Commercial Hosts
      • Specta Gen
      • Specta Reg
      • Spike^ekip S
      • Sponsor Offers
      • Spyce
      • Spycy Roll
      • SQLObject
      • Stackless Python
      • Standard Library Backports
      • Stani
      • Starlanes 2 Sprint
      • Starship Python
      • Starship Transfer
      • Starting Your Users Group
      • State Machine via Decorators
      • State Programming
      • Static Site Generator
      • Str is Not a String
      • Stream Reader
      • Stream Reader Writer
      • Stream Recoder
      • Stream Writer
      • String Formatting
      • Strong vs Weak Typing
      • Strukturerad Text
      • Subclassing Built in Types
      • Subclassing Dictionaries
      • Submitting Bugs
      • Sugar UI
      • Summit Lightning Talks
      • Summit Track Five
      • Summit Track Four
      • Summit Track One
      • Summit Track Three
      • Summit Track Two
      • Sybase
      • Sym Py
      • Syntax Reference
      • TACTIC
      • TODO
      • TOOWTDI
      • Tahoe Mentors
      • Talin
      • Talk Subjects
      • Talk Mistakes
      • TCP Communication
      • Template Loader API
      • Templating
      • Ten things people want to know about Python
      • Teradata
      • Test Harness Design
      • Test Oob
      • Test PyPI
      • Test Software
      • Texas Pythoneers!
      • Texas Pythoneers
      • Text Processing in Python
      • thanos
      • The Circle
      • Think SQL
      • Thread Programming
      • Tilfældig Side
      • Time Transitions Image
      • Tiny Python
      • Tips for in House User Groups
      • Title Contributors Discussion Template
      • Tix
      • Tk Zinc
      • Tkinter 3000
      • To M Korn
      • Tokison
      • Tokyo Pythonistas
      • Toolserver Framework for Python
      • Topically Organized PEP List
      • Tour Bus Stop
      • Trac Tracker
      • Tracking Source Location
      • Trouve Page
      • Tsering
      • Tucson Python User Group
      • Tuple Syntax
      • Tutorials on XML processing with Python
      • Type Error
      • UML
      • Ubuntu Install
      • UDP Communication
      • Ukrainian Python Books
      • Unicode
      • Unicode Decode Error
      • Unicode Encode Error
      • Unicode Encoding
      • Unicodeon Windows Extensions
      • Upgrading PostgreSQL
      • Use Python As an Interactive Shell
      • Usecases of Develop
      • Useful Modules
      • User Kit
      • Using Assertions Effectively
      • Using DB API with Postgres
      • Using Enumerate
      • Using Slots
      • VPython
      • VS2010
      • VS2012
      • Valley of the Sun Piggies
      • Vaults of Parnassus
      • Venom Package
      • Version Control
      • Vincent D Yu
      • Viper
      • Virtual Collaboratory BOF
      • Virtual Python
      • Visual wx
      • Voicent Simple Telephone Call API
      • Volunteer Signup
      • Volunteer Signup 2008
      • Volunteer Opportunities
      • Wanted…
      • Wareweb
      • Wasp
      • Wax
      • Web 2 Py
      • Web Accessibility
      • Web Application Framework Usability Testing Proposal
      • Web Applications
      • Web Browser Programming
      • Web Client Programming
      • Web Components
      • Web Janitorial Tasks
      • Web Kit
      • Web SIG Tasks
      • Web Servers
      • Web Services
      • Web Sig BOF
      • Web Solution Comparison
      • Web Stack
      • Web Standardisation
      • Web Test Paris Bear Sprint 2013
      • Webware
      • Webizing Python
      • Website Redesign Proposal
      • Webware Sprint
      • Weg Weiser
      • Well Known Python Programs
      • Western Punjabi Language
      • What applications that support ‘the application lifecycle’ are available to Python developers?
      • When I import Tkinter, Python exits. Why?
      • Where Do I Report This?
      • Which GUI is best for python?
      • Which IDE is good for Python
      • Why is Python a dynamic language and also a strongly typed language
      • Why is Python slower than the xxx language
      • Why separate sections by indentation instead of by brackets or ‘end’
      • Widget Construction Kit
      • Wiki Attack 2013
      • Wiki Editing Guidelines
      • Wiki Guidelines
      • Wiki Like Syntax
      • Wiki Sand Kasse
      • Wiki Sand Låda
      • Wiki Spam
      • Wiki Users
      • Wiki Wiki Webb
      • Winni PUG
      • Winnipug Buildout Presentation
      • Wishlist
      • With Statement and Open Gl
      • Working with Processes
      • Working with Time
      • Writing Exception Classes
      • WSGI Kit Sprint
      • wx Designer
      • wx Glade
      • Xia Q
      • XML Books
      • XML Databases
      • YAML
      • Yapps
      • Yarko
      • Yuvraj singh chawda
      • ZODB
      • Zero Price
      • Zerynth
      • Zodb Sprint
      • Zwj and Zwnj As Identifiers
      • akorn
      • albert
      • alexandersnitily
      • alexdzul
      • alireza.azimzadeh.alimp5
      • apug meeting 01-18-2007
      • apug meeting 10-12-2006
      • arrayschism
      • asql
      • avelino
      • beautiful soup
      • berkerpeksag
      • bhattnihar
      • boost 2epython
      • brad matera
      • bryanpham
      • bsd
      • buzhug
      • compile Python to C
      • content management system
      • cppyy
      • cseder
      • decimal
      • demianbrecht
      • demoergo
      • deployment
      • diceus
      • dvs1
      • egg
      • elena
      • elmer
      • erhansenlik
      • eric
      • evangelism support materials
      • fero14041
      • gflags
      • glob
      • gourneau
      • heromulder
      • higkoo
      • hmspy
      • houcine cherif
      • i Kaaro
      • j Edit
      • j Hep Work
      • jacdeh
      • jeromefreeman
      • jonclements
      • joseluiscastroc
      • junaid farooq
      • kaushik kaul
      • khao lek
      • la ellisabetta
      • limscoder
      • lwickjr
      • maki
      • mechanize
      • mjor1991
      • mleinart
      • monobot
      • moustafa.farhat
      • mssql Dataset
      • nose
      • osamakhn
      • oscarcp
      • paddy3118
      • patra-tm
      • peretto
      • primer arch patterns
      • pso
      • psyco
      • Py Bead
      • pykonik
      • pymug
      • pywarangal
      • re Structured Text
      • reverse chinese character in repr
      • ric Araujo
      • saikiran
      • sakthiganesh
      • satyag
      • setuptools
      • shravan
      • sip PQ
      • speed.python.org
      • ssteiner X
      • static analysis
      • static source analysis
      • sudip
      • sumit
      • sunpy
      • svaksha
      • systems administration
      • t2phage
      • techtonik
      • teng
      • tftp
      • theskumar
      • tk md5
      • tx Object ATK
      • usage stats
      • venster
      • vikas garg
      • vraniero
      • wangjun
      • warp
      • weave
      • wx Python Bo F
      • xuqingbai
      • yasserkhan
      • zkn365
      • Éric Araujo
      • РусскийПитон
    • Books & Publications
    • Community & User Groups
    • Conferences
    • Database Programming
    • Documentation
    • Editors & IDEs
    • Education
    • Getting Started
    • GUI Programming
    • Guides and How-Tos
    • Internationalization
    • Python Implementations
    • Infrastructure
    • Language Reference
    • Libraries & Tools
    • Multimedia & Games
    • Networking
    • Packaging
    • Performance
    • Platform-Specific
    • Python Software Foundation
    • Python 3 Migration
    • Scientific Computing
    • Security
    • Summer of Code
    • Sprints
    • Testing
    • Web Development
  • PSF Wiki
  • Jython Wiki
  • Contributing
  • People

On this page

  • Benefits of using a function instead of a statement
  • Guido’s own arguments
  • Getting there from here
  • Sample implementation
  • Code comparisons
  • Newline / No-newline
  • Iterating Iterables
  • Another Strawman
  • Another variant - `format` builtin
  • Displaying iterators
  • Scrap C-Style Formatting
  • Another idea
  • Yet Another Formatting Alternative
  • Extend String.Template?
psf/wiki 0 0
Edit this page
  1. Python Wiki /
  2. Python Wiki /
  3. Archive /
  4. Print As Function
View as Markdown Open in ChatGPT Open in Claude

Print As Function¶

Legacy Wiki Page

This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org.

This page discusses the benefits of replacing the current print{.backtick} statement with an equivalent builtin. The write{.backtick} and writeln{.backtick} functions presented below do everything the print{.backtick} statement does without requiring any hacking of the grammar, and also make a number of things significantly easier.

Guido has made it clear he wants to get rid of the print{.backtick} statement in Python3.0. This page considers why we would want to go that way, and how we can actually get there. It should be turned into a PEP eventually.

FYI: Python 3.0 has been released with a print function, and Python 2.6 has from __future__ import print_function{.backtick} to enable this on a per-module basis. Further discussion here is therefore quite futile. GvR.

Benefits of using a function instead of a statement¶

  • Extended call syntax provides better interaction with sequences

  • Keyword argument sep{.backtick} allows item separator to be changed easily and obviously

  • Keyword argument linesep{.backtick} could optionally allow line separator to be changed easily and obviously

  • Keyword argument stream{.backtick} allows easy and obvious redirection

  • The builtin can be replaced for application wide customisation (e.g. per-thread logging)

  • Interacts well with PEP 309’s partial function application, and the rest of Python’s ability to handle functions

    • BDFL comments:

      • don’t waste your time on sequence printing

      • I’m not excited about sep and linesep keyword args

      • add to benefits: easier transition to other function/method calls

      • if it were me, I’d use ‘to=’ or ‘file=’ rather than ‘stream=’ (too long)

Guido’s own arguments¶

There is a theoretical argument: print is the only application-level functionality that has a statement dedicated to it. Within Python’s world, syntax is generally used as a last resort, when something can’t be done without help from the compiler. Print doesn’t qualify for such an exception (quite the opposite actually).

But more important to me are my own experiences exploring the boundaries of print.

  • I quite often come to a point in the evolution of a program where I need to change all print statements into logging calls, or calls into some other I/O or UI library. If print were a function, this would be a straightforward string replacement; as it is, finding where to add the parentheses is often a pain (the end isn’t always on the same line

    as the start). It’s even worse if there are already “>>stream” options present. Trailing commas also make this more complicated than it needs to be.

  • Having special syntax puts up a much larger barrier for evolution of a feature. For examle, adding printf (or changing print to printf) is a much bigger deal now that print is a statement than if it had been a built-in function: trial implementations are much more work, there are only a few people who know how to modify Python’s bytecode compiler, etc. (Having printf() be a function and print remain a statement is of course a possibility, but only adds more confusion and makes printf() a second-class citizen, thereby proving my point.)

  • There is a distinct non-linearity in print’s ease of use once you decide that you don’t want to have spaces between items; you either have to switch to using sys.stdout.write(), or you have to collect all items in a string. This is not a simple transformation, consider what it takes to get rid of the spaces before the commas in this simple example:

    • print "x =", x, ", y =", y, ", z =", z

    If it was a built-in function, having a built-in companion function that did a similar thing without inserting spaces and adding a newline would be the logical thing to do (or adding keyword parameters to control that behavior; but I prefer a second function); but with only print as it currently stands, you’d have to switch to something like

    • print "x = " + str(x) + ", y = " + str(x) + ", z = " + str(z)

    or

    • print "x = %s, y = %s, z = %s" % (x, y, z)

    neither of which is very attractive. (And don’t tell me that the

    spaces are no big deal – they aren’t in this example, but they are in other situations.)

  • If it were a function, it would be much easier to replace it within

    one module (just def print(*args):...) or even throughout a program (e.g. by putting a different function in __builtin__.print). As it is, you can do this by writing a class with a write() method and assigning that to sys.stdout – that’s not bad, but definitely a much larger conceptual leap, and it works at a different level than print.

Summarizing, my main problems with print as a statement are the transformations – when print doesn’t cut it, you have to switch to something entirely different. If it were a function the switch would feel much smoother. I find that important: things that are conceptually related should be syntactically related (within the realm of common sense, as always).

Getting there from here¶

The example implementation below shows that creating a function with the desired behaviour is quite straightforward. However, calling the builtin print{.backtick} is a problem due to the fact that print{.backtick} is a reserved word in Python 2.x. Since the print{.backtick} statement will be around until Py3K allows us to break backwards compatibility, devising a transition plan that lets programmers ‘get ready early’ for the Py3K transition becomes a significant challenge.

If, on the other hand, the builtin has a different name, it is quite feasible to introduce it during the 2.x series. In PEP 3000, it is suggested that the print{.backtick} statement be replaced by two builtins: write{.backtick} and writeln{.backtick}. These names are used in the example below. By using alternative names, and providing the builtins in the 2.x series, it is possible to ‘future-proof’ code against the removal of the print{.backtick} statement in Py3k.

This technique of having two printing operations is not uncommon - Java has both print{.backtick} and println{.backtick} methods, and C# has Write{.backtick} and WriteLine{.backtick}. The main problem with the approach is that the writeln{.backtick} form will actually be more commonly used, but has the longer, less obvious name of the two proposed functions. This perception of relative use is based on a comparison of relative usage levels of the two current forms of the print{.backtick} statement (i.e., with and without the trailing comma) by some of the developers on python-dev.

  • [lwickjr: Why TWO functions? Why can’t we specify printFunc(....,"\n")?]

Some other names for the builtins which have been suggested are:

  • print{.backtick} - excellent name, but causes transition problems as described above

  • println{.backtick} - avoids the transition problems, reflects default behaviour of adding a line, matches Java method name

  • printline{.backtick} - alternative to println{.backtick}, that avoids the somewhat cryptic abbreviation

  • writeline{.backtick} - alternative to writeln{.backtick} that avoids the somewhat cryptic abbreviation

  • say{.backtick} - short alternative to println{.backtick} invented in Perl 6 (which uses print{.backtick} for no-newline output)

  • out{.backtick} - not a verb, and converting to it may be problematic due to shadowing by variable names

  • output{.backtick} - nice symmetry with input, but using the term as a verb is not typical

  • prnt{.backtick} - easily edited into print{.backtick} later on

  • write{.backtick} - decent name, but confusing when compared to write() method

  • display{.backtick} - Can be a verb or not. Idea from Scheme.

    • Maybe file-objects should have write(){.backtick}- and writeln(){.backtick}-methods similar to the built-in functions? – TS

    [lwickjr: don’t they already have something similar?]

Sample implementation¶

This is a Python 2.4 compatible sample implementation of the approach currently in PEP 3000. This version of writeln{.backtick} doesn’t provide a linesep{.backtick} keyword argument in order to keep things simple. Some other variations are covered further down this Wiki page.

   1 def write(*args, **kwds):
   2     """Functional replacement for the print statement
   3 
   4     This function does NOT automatically append a line separator (use writeln for that)
   5     """
   6 
   7     # Nothing to do if no positional arguments
   8     if not args:
   9         return
  10 
  11     def parse_kwds(sep=" ", stream=sys.stdout):
  12         """ Helper function to parse keyword arguments """
  13         return sep, stream
  14     sep, stream = parse_kwds(**kwds)
  15 
  16     # Perform the print operation without building the whole string
  17     stream.write(str(args[0]))
  18     for arg in args[1:]:
  19         stream.write(sep)
  20         stream.write(str(arg))
  21         
  22 def writeln(*args, **kwds):
  23     """Functional replacement for the print statement
  24 
  25     >>> writeln(1, 2, 3)
  26     1 2 3
  27     >>> writeln(1, 2, 3, sep='')
  28     123
  29     >>> writeln(1, 2, 3, sep=', ')
  30     1, 2, 3
  31     >>> import sys
  32     >>> writeln(1, 2, 3, stream=sys.stderr)
  33     1 2 3
  34     >>> writeln(*range(10))
  35     0 1 2 3 4 5 6 7 8 9
  36     >>> writeln(*(x*x for x in range(10)))
  37     0 1 4 9 16 25 36 49 64 81
  38     """
  39     # Perform the print operation without building the whole string
  40     write(*args, **kwds)
  41     write("\n", **kwds)

Code comparisons¶

These are some comparisons of current print{.backtick} statements with the equivalent code using the builtins write{.backtick} and writeln{.backtick}.

   1 # Standard printing
   2 print 1, 2, 3
   3 writeln(1, 2, 3)
   4 
   5 # Printing without any spaces
   6 print "%d%d%d" % (1, 2, 3)
   7 writeln(1, 2, 3, sep='')
   8 
   9 # Print as comma separated list
  10 print "%d, %d, %d" % (1, 2, 3)
  11 writeln(1, 2, 3, sep=', ')
  12 
  13 # Print without a trailing newline
  14 print 1, 2, 3,
  15 write(1, 2, 3)
  16 
  17 # Print to a different stream
  18 print >> sys.stderr, 1, 2, 3
  19 writeln(1, 2, 3, stream=sys.stderr)
  20 
  21 # Print a simple sequence
  22 print " ".join(map(str, range(10)))
  23 writeln(*range(10))
  24 
  25 # Print a generator expression
  26 print " ".join(str(x*x) for x in range(10))
  27 writeln(*(x*x for x in range(10)))

Newline / No-newline¶

Another possibility to deal with the newline / no-newline cases would be to have a single function which would take an extra keyword argument “linesep” or “end” (or perhaps some slight magic: an empty string as the last argument), so to print without newline, you would do

   1 # Print without a trailing newline
   2 print 1, 2, 3,
   3 writeln(1, 2, 3, end='')
   4 # or (shorthand)
   5 writeln(1, 2, 3, '')

The default case should be to insert a newline.

  • I quite like the single function idea (early versions of this Wiki page used only a single function), but giving it a good name is challenging. The version without the keyword argument is a definite non-starter, though, as there is far too much risk of quirky behaviour when printing a string variable which just happens to contain the empty string. - Alyssa Coghlan

    • BDFL comments: I definitely am not keen on the single function with keyword args. IMO all you need is a companion function that inserts no separator and no newline; the desired separators are then easily given explicitly. Oh, and you will never get away with using the final empty string to mean “no newline”. This would be very confusing for someone who printed a variable like so: print("The value is:", x) when the variable happens to be empty.

  • [lwickjr: I quite agree. Ugly, but explicit is better than implicit. Function with NO seperator and NO newline: +5 How about def printFunc(*args): print "".join(map(str, args))]

Iterating Iterables¶

Another potentially interesting improvement could be for the function to iterate all iterables, in order to be able to use generator expressions without having to use the star syntax and to avoid the creation of a temporary sequence. This would allow:

   1 # Print a generator expression
   2 print " ".join(str(x*x) for x in range(10))
   3 writeln(x*x for x in range(10))
   4 # Or optionally
   5 writeln((x*x for x in range(10)), iter=1)

This behaviour could be optionally triggered by a keyword argument “iter”. Another possibility would be to always do the iteration and to force the caller to str() the generator if he wants to print it without iteration (happens rarely).

  • Nailing down this kind of behaviour is trickier than one might think. The python-dev discussion of the Python 2.5 candidate library function itertools.walk goes over some of the potential problems. We’ve survived without fancy iterator handling in the print statement - let’s avoid adding anything we don’t have a demonstrated need for (the extended call syntax stuff comes ‘for free’ with the conversion to using a function). - Alyssa Coghlan

    • BDFL comments: bah. implicitly exhausting iterables has side effects, which is a bad idea for a print function. It would not be a good idea if commenting out a print() call changes the behavior of the program.

  • [lwickjr: How about this? Define repr(iterator) to return "<iteratorData>" and str(iterator)}} to return something like {{{" ".join([i for i in iterator])? -5]

Another Strawman¶

Here’s my own strawman implementation of write() and writef() using semantics I think are pretty useful. I’ll post to python-dev about the details. - Barry Warsaw

   1 import sys
   2 from string import Template
   3 
   4 class Separator:
   5     def __init__(self, sep):
   6         self.sep = sep
   7 
   8 SPACE = Separator(' ')
   9 EMPTY = Separator('')
  10 
  11 
  12 def writef(fmt, *args, **kws):
  13     if 'to' in kws:
  14         to = kws.get('to')
  15         del kws['to']
  16     else:
  17         to = sys.stdout
  18     if 'nl' in kws:
  19         nl = kws.get('nl')
  20         del kws['nl']
  21         if nl is True:
  22             nl = '\n'
  23         elif nl is False:
  24             nl = ''
  25     else:
  26         nl = '\n'
  27     if isinstance(fmt, Template):
  28         if args:
  29             raise TypeError('invalid positional arguments')
  30         s = fmt.substitute(kws)
  31     else:
  32         if kws:
  33             raise TypeError('invalid keyword arguments')
  34         s = fmt % args
  35     to.write(s)
  36     to.write(nl)
  37 
  38 
  39 def write(*args, **kws):
  40     if 'to' in kws:
  41         to = kws.get('to')
  42         del kws['to']
  43     else:
  44         to = sys.stdout
  45     if 'nl' in kws:
  46         nl = kws.get('nl')
  47         del kws['nl']
  48         if nl is True:
  49             nl = '\n'
  50         elif nl is False:
  51             nl = ''
  52     else:
  53         nl = '\n'
  54     if 'sep' in kws:
  55         sep = kws.get('sep')
  56         del kws['sep']
  57     else:
  58         sep = ' '
  59     if kws:
  60         raise TypeError('invalid keyword arguments')
  61     it = iter(args)
  62     # Suppress leading separator, but consume all Separator instances
  63     for s in it:
  64         if isinstance(s, Separator):
  65             sep = args[0].sep # Should this be s.sep?
  66         else:
  67             # Don't write a leading separator
  68             to.write(str(s))
  69             break
  70     for s in it:
  71         if isinstance(s, Separator):
  72             sep = s.sep
  73         else:
  74             to.write(sep)
  75             to.write(str(s))
  76     to.write(nl)
  77 
  78 
  79 obj = object()
  80 refs = sys.getrefcount(obj)
  81 
  82 write('obj:', obj, 'refs:', refs)
  83 write(Separator(': '), 'obj', obj,
  84       Separator(', '), 'refs',
  85       Separator(': '), refs,
  86       nl=False)
  87 write()
  88 
  89 writef('obj: %s, refs: %s', obj, refs)
  90 writef(Template('obj: $obj, refs: $refs, obj: $obj'),
  91        obj=obj, refs=refs,
  92        to=sys.stderr,
  93        nl=False)
  94 write()
  • For the code comparisons shown earlier, simply put write{.backtick} where writeln{.backtick} is currently used, and add the keyword argument nl=False{.backtick} for the no trailing newline case. I quite like this approach. - Alyssa Coghlan

    • BDFL comments: I like the write/writef parallel; would like it even more if it was print/printf. But please drop the Separator thing. The use case isn’t common enough to burden people with the possibility. Also, we need to spend more time researching the formatting language. (See a post in python-dev by Steven Bethard: “string formatting options and removing basestring.__mod__”.

  • [lwickjr: def printf(format, *args): print(format(format, *args))? This definition will actually work with print either a statement or function. Further, formatting and printing are seperate concepts and should not be tightly coupled.]

Another variant - `format` builtin¶

Barry’s writef{.backtick} builtin cuts down a little on the typing, but is somewhat inflexible in that it only supports string %{.backtick} or string.Template{.backtick} formatting when printing directly to a stream. It also causes problems by preventing the use of to{.backtick} or nl{.backtick} as keywords in the format string. A separate format{.backtick} builtin would deal with both of those problems, at the expense of some extra typing when using it. Such a builtin would also help with avoiding some of the tuple related quirks of the string mod operator, as well as making it easy to write code that supports both types of string formatting. The version below is based on Barry’s, but eliminates the Separator{.backtick} concept, and replaces writef{.backtick} with format{.backtick} - Alyssa Coghlan

   1 import sys
   2 from string import Template
   3 
   4 # Real implementation would avoid blocking use of 'fmt'
   5 # as an element of the formatting string
   6 def format(fmt, *args, **kws):
   7     if isinstance(fmt, Template):
   8         if args:
   9             raise TypeError('invalid positional arguments')
  10         s = fmt.substitute(kws)
  11     else:
  12         if kws:
  13             s = fmt % kws
  14         else:
  15             s = fmt % args
  16     return s
  17 
  18 
  19 def write(*args, **kws):
  20     if 'to' in kws:
  21         to = kws.get('to')
  22         del kws['to']
  23     else:
  24         to = sys.stdout
  25     if 'nl' in kws:
  26         nl = kws.get('nl')
  27         del kws['nl']
  28         if nl is True:
  29             nl = '\n'
  30         elif nl is False:
  31             nl = ''
  32     else:
  33         nl = '\n'
  34     if 'sep' in kws:
  35         sep = kws.get('sep')
  36         del kws['sep']
  37     else:
  38         sep = ' '
  39     if kws:
  40         raise TypeError('invalid keyword arguments')
  41     for s in args[:1]:
  42         to.write(str(s))
  43     for s in args[1:]:
  44         to.write(sep)
  45         to.write(str(s))
  46     to.write(nl)
  47 
  48 
  49 obj = object()
  50 refs = sys.getrefcount(obj)
  51 
  52 write('obj:', obj, 'refs:', refs)
  53 write('obj:', obj, 'refs:', refs, sep=', ', nl=False)
  54 write()
  55 
  56 write(format('obj: %s, refs: %s', obj, refs))
  57 write(format('obj: %(obj)s, refs: %(refs)s', obj=obj, refs=refs))
  58 write(format(Template('obj: $obj, refs: $refs, obj: $obj'),
  59               obj=obj, refs=refs),
  60        to=sys.stderr,
  61        nl=False)
  62 write()

Displaying iterators¶

I’m looking into an approach which adds explicit support for displaying iterators into the string mod operator. The intent is that "%''j" % (my_seq,){.backtick} will become roughly equivalent to ''.join(map(str, my_seq)){.backtick}. - Alyssa Coghlan

SF Patch #1281573 for anyone who wants to play with it. Only strings are supported so far (no Unicode), but it illustrates the concept quite well.

   1 # Print a simple sequence
   2 print " ".join(map(str, range(10)))
   3 print "%' 'j" % range(10)
   4 
   5 # Print a generator expression
   6 print " ".join(str(x*x) for x in range(10))
   7 print "%' 'j" % (x*x for x in range(10))
  • BDFL comments: again, please don’t do this.

  • [lwickjr: I prefer that repr() and str() be the Official Pythonic Way to decide which representation gets written. How about def printFunc(*args): print "".join(map(str, args)) and def writeFunc(*args): print "".join(map(repr, args))?]

Scrap C-Style Formatting¶

What’s one more strawman, right? :)“) My approach is tailor-made for gettext (although I’m no expert in gettext usage). Keywords become the default and positionals disappear completely.

>>> print('x = {x}, y = {y}, z = {z}', x=x, y=y, z=z)

There’s some redundancy in the the keyword arguments (unfortunately), but it helps insulate the format string from the code that uses it. It removes the problems of separator vs no separator It allows it to be self-documenting for the gettext translators, with no problems in reordering or reformatting. You could even give extra arguments that aren’t always used (but they wouldn’t be self-documenting I suppose).

Further options are using locals():

>>> print('x = {x}, y = {y}, z = {z}', **locals())

but only if you don’t mind exposing them (debatable). If you need something besides %s (the default) then go as follows:

>>> print('x = {r:x}, y = {f9.8:y}, z = {i:z}', x=x, y=y, z=z)

Or maybe even something that allows arbitrary arguments to be passed to the formatter. - Adam Olsen

Another idea¶

String formatting with %* is a bad idea, imho. Since python is anyway dynamic by nature, why not add built-in string evaluation, as in boo http://boo.codehaus.org. for example:

x = "lucy"
write("i love ${x}")

or

x = 7
write("the answer is ${x * 2}")

if strings (or a special flavor of string, say one marked with backticks*) allowed evaluation of expressions, code will never look like

print "x = ", x, "y = ", y

but rather

write("x = ${x}, y = ${y}")

which is much more readable and easier to maintain. imagine working with 20 ‘%s’ in a single string! it’s a disaster. even using the silly %(name) is bad, since you then have to fill a huge dict after your string.

(*) backticks: yes, backticks mean repr(), but did anyone ever hear of them? [lwickjr: I use them regularly.] i think they are depricated anyway. [lwickjr: Why?] adding a new built-in type, evalstr (“evaluating string”), marked by backticks, is very simple and almost completely backwards compatible. and it works not only in the context of printing output.

write(`hello ${os.getuid()}, the time now is ${time.asctime()}, and you are running on ${os.name}`)

true, it doesnt solve the write/writeln “problem”, and i must admit that print as a statement is a pretty useful feature (no parenthesis hassle), but adding evalstrings will make long format string possible and maintainable. plus, it gets us rid of the ugly writef or printf proposals.

Yet Another Formatting Alternative¶

There’s a few goals for any formatting scheme

  1. Inline naming (not off to the right somewhere)

  2. Expression arguments (obj.attr{.backtick} is common)

  3. Gettext swapout

  4. No repetition of names

  5. No explicit call to locals(){.backtick}

Our existing % formatting can do 2,3,4,5, but if you want 1 you instead get 1,3,4. My previous suggestion handles 1, but fails 4 miserably, as well as 5. My new suggestion handles all 5 goals simultaneously.

The full syntax is:

$"filler {name:expr formatter arguments} filler"

Most of that is optional. The most common way to use it would be:

$"filler {x} filler"
# Equivalent to...
$"filler {x:x str} filler"
# Equivalent to...
FormatString("filler {x str} filler", {'x': x})

A FormatString{.backtick} instance does not immediately evaluate. Instead, it waits until its __str__{.backtick} method is called, at which point the above example becomes:

"filler %s filler" % (str(fs.args['x']),)

Because of the lazy evaluation it is possible to use it for gettext.

def _(fs):
    return FormatString(localizedstrings(fs.format), fs.args)

Further options:

$"x = {:3}, y = {:42}"  # Names are ommited so numbers (positions) will be generated for them
$"f = {:1/3 float 10.5}"  # "f = %10.5f" % (1/3)
$foo  # Parse error!  $ is a string prefix, NOT an operator

Looking this over, the weakest link seems to be in the formatter aspects. It needs a way to specify an expression that happens after the initial evaluation, but after gettext has had a chance to replace the format string. Unfortunately I’m out of ideas so I’ll leave it be.

- Adam Olsen

Extend String.Template?¶

The basic idea would be to incorporate the functionality of the existing string.Template module as a built-in. The format prefix characters are stolen directly from Perl, which makes them both lightweight and familiar.

However, the current API is too cumbersome for “hello world” use. So we need to streamline it a bit.

The first part is getting rid of the need to explictly instantiate the String.Template() object. I suggest a new “string decorator”, similar to “r” and “u”, which indicates that the string is a template string. Lets assume that the prefix is “t” for “template” for now:

print t"Hello, $user!".substitute( user="Tim" )

The ‘t’ prefix should be usable in conjunction with the ‘r’, ‘u’, triple-quote and other string variations.

However, its still too wordy. We need to get rid of the .substitute(). One thought (which may not be workable) is to detect when the template is being coerced into a string by overloading __str__, which then automagically calls substitude using the local scope as the dictionary. (The hard part is getting the scope - because the coercion to string might be happening inside the print function. Perhaps the string can capture the scope pointer upon construction.)

Ideally, what we would then have is something similar to the Perl syntax:

print t"Hello, $user!"

- Talin

Previous
Previous Meeting on October 11 2007
Next
Print Fails

2026, Python Software Foundation

Made with Sphinx and Shibuya theme.