How to handle exception in Python

Exception handling is about how to gracefully handle unexpected events when they happens. Python has a complete support for exception handling. You should use it whenever possible.

There are several exceptions are loaded into Python interpreter before script start to run. Those exceptions will be raised at many different places.

Basics to know about Python variable scope

Variable scope is about when and where a name is visible. Python's variable scope has a little difference from other languages.

Global scope is actually is the module scope, since every py file is a module. And the module itself is a namespace, in this namespace, any variable not defined inside indented block is global.

Parsing and Traversing DOM tree with BeautifulSoup

how to download a web page and parse it in Python. After the parsing, we will traverse the DOM tree. The Java ... something about HTML DOM in Python. And the package we will use is BeautifulSoup. BeautifulSoup ... is a Python module for parsing and traversing the XML document. [Step 1. Download page] Download ... uncompressed it, if it's not, just send the opened handle to constructor. [Step 2. Build the DOM tree

Python encoding problem when redirecting output to file

The encoding problem in Python is a mess. Without a very deep understanding of the the unicode stuff, you just can not fight against these weird encoding problem.

A Python script may works well when output on the terminal window, but broke when redirecting to a text file. I never encounter this kind of thing in PHP or other languages.

A Python script may works well when output on the terminal window, but broke when redirecting to a text file. I never encounter this kind of thing in PHP or other languages..

What is self in Python

The self in python is used to reference the object instance. Languages like C++ and Java have "this" keyword do the same thing. The difference is that in Python the self must be declared explicitly and the C++ , Java the this keyword is passed by default.

How to use yield keyword in Python

The yield keyword makes a function iterable, lets see a simple example.

Will output .

Install PyDev MyEclipse plugin

The PyDev plugin not work very well with old version eclipse. Both the update site and zip extract, just unable to create python project.

For me the eclipse3.8.2 is OK. Select Help -> Install New Software and add this URL.

What is __main__ in Python

The code snippet below is common in Python.

When you run the script standalone, the condition will be true, but when the module is imported by another script, the condition will be false, the __name__ will be the module name.

Stat words in source code with Python

Do you want to know which words occurs most times in your source code? Or how much times a word present in source code.

Suppose your code is managed by Git. Generate file list with the command

Python toString?

I write some code like this.

And get this error.

Previous Page 1 2 3 4 5 Next Page