Skip to content
Waldir Pimenta edited this page May 25, 2014 · 2 revisions

Page.namespace is a data member giving the namespace index of the page.

Typically, this is used to perform different actions depending on the namespace of the page. For example, this recursive function walks a category tree, making a list of all pages in it:

def allpagesin(category):
    result = list()
    for page in category:
        if page.namespace == 14:  # 14 is the category namespace
            result += allpagesin(page)
        else:
            result.append(page)
    return result

This page was originally imported from the old mwclient wiki at SourceForge. The imported version was dated from 00:57, 18 March 2012, and its only editor was Derrickcoetzee (@dcoetzee).