background preloader

Python

Facebook Twitter

Jython

Django. More stuff in Python. Parser webs python. 8.3. Extracción de datos de documentos HTML. Para extraer datos de documentos HTML derivaremos la clase SGMLParser y definiremos métodos para cada etiqueta o entidad que queramos capturar.

8.3. Extracción de datos de documentos HTML

El primer paso para extrar datos de un documento HTML es obtener un HTML . Si tiene algún documento en su disco duro, use las funciones de ficheros para leerlo, pero lo divertido empezará cuando lo usemos sobre HTML sacado directamente de páginas web. Ejemplo 8.6. Presentación de urllister.py Si aún no lo ha hecho, puede descargar éste ejemplo y otros usados en este libro. from sgmllib import SGMLParser class URLLister (SGMLParser): def reset (self): SGMLParser.reset(self) self.urls = [] def start_a (self, attrs): href = [v for k, v in attrs if k== 'href' ] if href: self.urls.extend(href) Ejemplo 8.7.

>>> import urllib, urllister >>> usock = urllib.urlopen( " ) >>> parser = urllister.URLLister() >>> parser.feed(usock.read()) PyGame – Event Handling. Introduction To continue further into my PyGame exploration articles and tutorials, I’ll try to come up with a complete Shmup game as example.

PyGame – Event Handling

I already covered Animated sprites and Parallax Scrolling in 2D games as a start you can look at the PyGame tutorials list page to see them all. The goal of this article is to combine what we have already learned into a single piece and add a new feature. For instance, this application will be featuring parallax background, animated sprites and we will add user inputs handling using PyGame’s events management. Credits As usual, I like to deserve credit where it’s due. Clouds Brushes by ~JavierZhXFighter by ~PrinzEugn Class evolution – The Fighter Like Parallax class inherited from our base AnimatedSprite class in the previous article, we will create a new Fighter class (inheriting from AnimatedSprite class) and add specific members to handle it’s particular behaviors. Let’s see some code first, I’ll go into explaining it just after. Beginning Python: From Novice to ... Sorting dictionaries by value in Python 2.4. Python Programming Tutorial - 1 - Installing Python.

Python Module of the Week. A Beautiful Soup Tutorial - #1. Beautiful Soup is: a PythonHTML/XML parser designed for quick turnaround projects like screen-scraping.

A Beautiful Soup Tutorial - #1

I’m finding it extremely useful as an aid for turning static HTML sites in to dynamic, database driven sites. For example, scraping the desired html data, dumping it into a CSV file, and importing it into MySQL. In this particular example, we have a bunch of header files, and some are followed by an unordered list full of links. I wanted to: Identify if a list was preceded by a header.If we found one, scrape the link, link text, identify if it is a local PDF file or external link, and if it’s an external link, grab the page title (for use in the link’s title text).If the link returned a 404 Error, make note, but don’t put it into the…CSV file, which will be created by the Python dictionary created in the previous steps.I also wrote a function that strips out new line characters – handy. You can see we have 3 link categories (based on the headers):

Programa como un Pythonista: Python Idiomático. Sorting a million 32-bit integers in 2MB of RAM using Python. Someone jokingly asked me how I would sort a million 32-bit integers in 2 megabytes of RAM, using Python.

Sorting a million 32-bit integers in 2MB of RAM using Python

Taking up the challenge, I leared something about buffered I/O. Obviously this is a joke question -- the data alone would take up 4 megabytes, assuming binary encoding! But there's a possible interpretation: given a file containing a million 32-bit integers, how would you sort them with minimal memory usage? This would have to be some kind of merge sort, where small chunks of the data are sorted in memory and written to a temporary file, and then the temporary files are merged into the eventual output area.

Pybackpack, haz copias de seguridad (backups) de tu sis. Baltazar 0.1. Python Perverso Net Managers. 18.1. subprocess — Subprocess management — Python v2.6.2 documentation. Execute a child program in a new process.

18.1. subprocess — Subprocess management — Python v2.6.2 documentation

On Unix, the class uses os.execvp()-like behavior to execute the child program. On Windows, the class uses the Windows CreateProcess() function. The arguments to Popen are as follows. HowTo/Sorting - PythonInfo Wiki. Original version by Andrew Dalke with a major update by Raymond Hettinger Python lists have a built-in sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list from an iterable.

HowTo/Sorting - PythonInfo Wiki

There are many ways to use them to sort data and there doesn't appear to be a single, central place in the various manuals describing them, so I'll do so here. Reader (1000+) Style Guide for Python Code. Code should be written in a way that does not disadvantage other implementations of Python (PyPy, Jython, IronPython, Cython, Psyco, and such).For example, do not rely on CPython's efficient implementation of in-place string concatenation for statements in the form a += b or a = a + b.

Style Guide for Python Code

This optimization is fragile even in CPython (it only works for some types) and isn't present at all in implementations that don't use refcounting. In performance sensitive parts of the library, the ''.join() form should be used instead. Python perverso. Beginning Python: from novice to ... Os — Miscellaneous operating system interfaces — Python v2.6.1 documentation. This module provides a portable way of using operating system dependent functionality.

os — Miscellaneous operating system interfaces — Python v2.6.1 documentation

If you just want to read or write a file see open(), if you want to manipulate paths, see the os.path module, and if you want to read all the lines in all the files on the command line see the fileinput module. For creating temporary files and directories see the tempfile module, and for high-level file and directory handling see the shutil module. Notes on the availability of these functions: Note All functions in this module raise OSError in the case of invalid or inaccessible file names and paths, or other arguments that have the correct type, but are not accepted by the operating system.

Web Python Tutorial. Programming Python. Python cookbook - Búsqueda de libros de Google. Python-no-muerde - Project Hosting on Google Code. Decorando con python (decoradores) The Python Language Reference — Python v2.6.2 documentation. Inmersión en Python. Profiling and Optimizing Python. By Jeremy Jones 12/15/2005 Most of the time, code that we write doesn't have to perform as fast as if we wrote it in C.

Profiling and Optimizing Python

Most of the time, the first pass at writing it is "fast enough" and we don't have to optimize--but there are times when a piece of code just has to meet a certain standard of performance. For those "it's gotta run like a scalded dog" moments, the Python profiler may lend some assistance. The Python standard library provides three libraries for performing code profiling: profile, hotshot, and timeit. The type of profiling performed in these modules involves tracing method and function calls and recording how long they took to run. profile provides detailed profiling information on all functions and methods in a code base, which are called at a specific runtime. hotshot is a replacement for the profile module. timeit provides less detailed profiling information for smaller pieces of code, where "less detailed" comprises overall execution time.

Simple Generators. Abstract This PEP introduces the concept of generators to Python, as well as a new statement used in conjunction with them, the "yield" statement.

Simple Generators

Motivation When a producer function has a hard enough job that it requires maintaining state between values produced, most programming languages offer no pleasant and efficient solution beyond adding a callback function to the producer's argument list, to be called with each value produced. For example, tokenize.py in the standard library takes this approach: the caller must pass a "tokeneater" function to tokenize(), called whenever tokenize() finds the next token. Bpython interpreter. Guía de estilo del código Python. AprendiendoPython - Lista de libros. Recetario - PyAr - Python Argentina. Radical Python. PyGame and Animated Sprites. An animated sprite is a serie of the same image slightly modified and displayed at a certain framerate per second.

Explosion Sprite sampled from Remastered Tyrian Graphics @ Lost Garden Sample 5 frames Sprite representation: ----------------------------------------- | 1 | 2 | 3 | 4 | 5 | | 16x16 | 16x16 | 16x16 | 16x16 | 16x16 | | | | | | | ----------------------------------------- For a given framerate set to 30fps : Cniehaus: Python class variables and code dupclication. Hello I am having a Python problem. I have two classes, both inheriting the class 'Animal'. I want a counter, that means Animal.count_of() should return the number of objects. Python Learning Foundation: Computer Programming for Everybody, Tutorials, Book Reviews, Code, and Fun, CP4E.

Easy One Click to Subscribe to Python411 on iTunes rss to subscibe to this podcast series Feedback on WebApp script: January 4, 2009 WebApps for Cell Phones: December 12, 2008 ShowMeDo: October 5, 2008. Yet another Python implementation of PEP 380 (yield from) Parsing data from the Web in Python - Program - Builder AU.

LIBRO Python No Muerde.