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. My credentials: I am a resident of Montreal,father of two great kids, husband of one special woman,a full-time Python programmer,author of the Docutils project and reStructuredText,an editor of the Python Enhancement Proposals (or PEPs),an organizer of PyCon 2007, and chair of PyCon 2008,a member of the Python Software Foundation,a Director of the Foundation for the past year, and its Secretary. In the tutorial I presented at PyCon 2006 (called Text & Data Processing), I was surprised at the reaction to some techniques I used that I had thought were common knowledge. Many of you will have seen some of these techniques and idioms before. These are the guiding principles of Python, but are open to interpretation. import this
IntegratingPythonWithOtherLanguages [Hint: The idea is to create pages for the stuff, not just link it.] There a various tools which make it easier to bridge the gap between Python and C/C++: Pyrex - write your extension module on Python Cython -- Cython -- an improved version of Pyrex CXX - PyCXX - helper lib for writing Python extensions in C++ SCXX ctypes is a Python module allowing to create and manipulate C data types in Python. These can then be passed to C-functions loaded from dynamic link libraries. elmer - compile and run python code from C, as if it was written in C PicklingTools is a collection of libraries for exchanging Python Dictionaries between C++ and Python. weave - include C code lines in Python program ackward exposes parts of Python's standard library as idiomatic C++ C/C++ Binding Generators Tools to make C/C++ functions/methods accessible from Python by generating binding (Python extension or module) from header files. Articles Related See also to name a few.
For Beginners Welcome! Are you completely new to programming? If not then we presume you will be looking for information about why and how to get started with Python. Fortunately an experienced programmer in any programming language (whatever it may be) can pick up Python very quickly. It's also easy for beginners to use and learn, so jump in! Installing Python is generally easy, and nowadays many Linux and UNIX distributions include a recent Python. If you want to know whether a particular application, or a library with particular functionality, is available in Python there are a number of possible sources of information. If you have a question, it's a good idea to try the FAQ, which answers the most commonly asked questions about Python. If you want to help to develop Python, take a look at the developer area for further information.
Python - Quick Guide Python is a high-level, interpreted, interactive and object oriented-scripting language. Python is InterpretedPython is InteractivePython is Object-OrientedPython is Beginner's Language Python was developed by Guido van Rossum in the late eighties and early nineties at the National Research Institute for Mathematics and Computer Science in the Netherlands. Python's feature highlights include: Easy-to-learnEasy-to-readEasy-to-maintainA broad standard libraryInteractive ModePortableExtendableDatabasesGUI ProgrammingScalable The most up-to-date and current source code, binaries, documentation, news, etc. is available at the official website of Python: Python Official Website : You can download the Python documentation from the following site. Python Documentation Website : www.python.org/doc/ Interactive Mode Programming: Invoking the interpreter without passing a script file as a parameter brings up the following prompt: >>> print "Hello, Python!" Hello, Python! #! Example: #! #!
使用python抓取网页(以人人网新鲜事和团购网信息为例) 前一段时间写的小东西，一直没工夫把他系统写出来，今天眼睛疼，就写写吧~~(原来博主不蛋疼时也会更新博客的哈~) python抓取网页基础 python自己带有很多网络应用相关的模块，如：ftplib用于FTP相关操作，smtplib和poplib用于收发电子邮件等等，利用这些 模块自己写一个FTP软件或是邮件客户端类软件完全是可能的，我就简单的试过完全用python脚本收发邮件和操作自己的FTP服务器。当然，这都不是今 天的主角，我们今天要用到的几个模块是：urllib，urllib2，cookielib，BeautifulSoup，我们先来简单介绍下。 urllib和urllib2自然都是处理URL相关的操作，urllib可以从指定的URL下载文件，或是对一些字符串进行编码解码以使他们成为特定的 URL串，而urllib2则比urllib更2一点，哦不对，是更牛逼一点。 我们先来看看最简单的网页抓取，其实网页抓取就是将所要的网页源代码文件下载下来，然后对其分析以提取对自己有用的信息。 import urllibhtml_src = urllib.urlopen(' 这样就会打印出百度首页的HTML源码了，还是很easy的。 from BeautifulSoup import BeautifulSoupparser = BeautifulSoup(html_src) 这样，后续处理HTML源码的工作交给parser变量来负责就好，我们可以简单的调用parser的prettify函数来相对美观的显示源码， 可以看到这样就能看到中文字符了，因为BeautifulSoup能自动处理字符问题，并将返回结果都转化为Unicode编码格式。 抓取人人网的新鲜事 前面讲的是最简单的抓取情形了，但通常我们需要面对更复杂的情形，拿人人网来说，需要登录自己的账号才能显示新鲜事，这样我们就只能求助于更2一点 的urllib2模块了。 首先import我们需要的所有模块，然后使用urllib2模块的HTTPCookieProcessor搭建一个处理cookie的 Handler，传入cookielib模块的CookieJar函数作为参数，这个这个函数处理HTTP的cookie，简单地说，它从HTTP请求中 提取cookie，然后将其返回给HTTP响应。
Templating Templating, and in particular web templating is a way to represent data in different forms. These forms often (but not always) intended to be readable, even attractive, to a human audience. Frequently, templating solutions involve a document (the template) and data. Template usually looks much like the final output, with placeholders instead of actual data (or example data in simplified form), bears common style and visual elements. Templating Engines There are many, many different HTML/XML templating packages and modules for Python that provide different feature sets and syntaxes. The number of templating engines is so great because the mechanisms involved are pretty easy to write in Python, at least for a fairly basic template engine; this recipe from the Python Cookbook shows how easy it is. Engines using Value Substitution The simplest form of templating engine is that which merely substitutes values into a template in order to produce the final output. HTML Shorthand Processors
Eric Walstad's crew quarters on the Starship Hello World! I'm busilly tuning the hyper drive right now. Please have a seat and enjoy my spartan quarters or have a look at my business site: or the Django Critter that helps me write code at the speed of light. links I've found useful over the years of Python programmingPythonDive Into PythonCode Like a Pythonista: Idiomatic PythonBitManipulation - PythonInfo WikiCharming Python: Using state machinesCSV module ExamplesDebugging python c extensionsEpydocGnuplot.pyPython bindings to the Xapian search enginePython SidebarPython Standard LoggingSending email with PythonSingleton Mixin - singletonmixin.py The Borg patternThe Epytext Markup LanguageUsing Mix-ins with Python | Linux JournalXapian: DocumentationLearning to programByte of Python:Main Page - Text
The Python Tutorial Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms. The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python Web site, and may be freely distributed. The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation. The Python interpreter is easily extended with new functions and data types implemented in C or C++ (or other languages callable from C). This tutorial introduces the reader informally to the basic concepts and features of the Python language and system.
LIBSVM Tools This page provides some miscellaneous tools based on LIBSVM (and LIBLINEAR). Roughly they include Disclaimer: We do not take any responsibility on damage or other problems caused by using these software and data sets. Please download the zip file. Please download the zip file. Please download the zip file. T. You can use either MATLAB or Python. Welcome to PyBrain’s documentation! — PyBrain v0.3 documentation The documentation is build up in the following parts: first, there is the quickstart tutorial which aims at getting you started with PyBrain as quickly as possible. This is the right place for you if you just want get a feel for the library or if you never used PyBrain before. Although the quickstart uses supervised learning with neural networks as an example, this does not mean that that’s it. PyBrain is not only about supervised learning and neural networks. While the quickstart should be read sequentially, the tutorial chapters can mostly be read independently of each other. In case this does not suffice, we also have an API reference, the Module Index. If you want to develop for PyBrain and contribute, check out our guidelines in our wiki: If at any point the documentation does not suffice, you can always get help at the pybrain Google Group at Installation Quick answer:
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. From many years of programming these are some of my favorite programs. Many thanks to Paul Carduner and Jeff Elkner for their work on this page, especially for Paul's graphic of Psyltherin (apologies to Harry Potter) and to the teams behind reStructured text and Sphinx to which the web pages in this collection have been adapted. Chris Meyers
machine learning in Python "We use scikit-learn to support leading-edge basic research [...]" "I think it's the most well-designed ML package I've seen so far." "scikit-learn's ease-of-use, performance and overall variety of algorithms implemented has proved invaluable [...]." "For these tasks, we relied on the excellent scikit-learn package for Python." "The great benefit of scikit-learn is its fast learning curve [...]" "It allows us to do AWesome stuff we would not otherwise accomplish" "scikit-learn makes doing advanced analysis in Python accessible to anyone."