Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7982581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:42:52+00:00 2026-06-04T10:42:52+00:00

with this python 2.7.3 (or 2.7.0) code I want to change the value of

  • 0

with this python 2.7.3 (or 2.7.0) code I want to change the value of the attribute “android:versionCode=’2′”, which has the namespace prefix “android”:

#!/usr/bin/python
from xml.etree.ElementTree import ElementTree, dump
import sys, os

# Problem here:
ElementTree.register_namespace("android", "http://schemas.android.com/apk/res/android")

tree = ElementTree()
tree.parse("AndroidManifest.xml")
root = tree.getroot()
root.attrib["{http://schemas.android.com/apk/res/android}versionCode"] = "3"

dump(tree)

When not using the line of code commented with “Problem here”, ElementTree is auto-naming the namespace alias for http://schemas.android.com/apk/res/android to “ns0” (resulting in “ns0:versionCode=’3′”.

Thus I’m using ElementTree.register_namespace to map the namespace url to the alias name “android”, which is documented here.

The error I get when I try to do this is:

AttributeError: type object 'ElementTree' has no attribute 'register_namespace'

Anybody knows why this is not working? This method should be available in python 2.7.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:42:53+00:00Added an answer on June 4, 2026 at 10:42 am

    register_namespace() is a function contained within the ElementTree module.
    It is not contained within the ElementTree class…

    An aside: Because of the confusion that is sometimes caused by doing so it is generally not recommended to use the same name for both module and class. But we are not about to break production code by renaming a widely used module now are we?

    You simply need to change your code:

    #!/usr/bin/python
    import xml.etree.ElementTree as ET # import entire module; use alias for clarity
    import sys, os
    
    # note that this is the *module*'s `register_namespace()` function
    ET.register_namespace("android", "http://schemas.android.com/apk/res/android")
    
    tree = ET.ElementTree() # instantiate an object of *class* `ElementTree`
    tree.parse("AndroidManifest.xml")
    root = tree.getroot()
    root.attrib["{http://schemas.android.com/apk/res/android}versionCode"] = "3"
    
    ET.dump(tree) # we use the *module*'s `dump()` function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was given this Python code that would calculate an MD5 value for any
/Users/smcho/Desktop/bracket/[10,20] directory has abc.txt, but when I run this Python code import glob import
I am trying to understand this simple hashlib code in Python that has been
i've got this snazzy python code: import subprocess value = subprocess.Popen([php,./php/php_runner.php],stdout=subprocess.PIPE); the problem is,
Consider this Python code for printing a list of comma separated values for element
This is my Python code - cursor.execute(UPDATE tasks SET task_owner=%s,task_remaining_hours=%s, task_impediments=%s,task_notes=%s WHERE task_id=%s, (new_task_owner,new_task_remaining_hours,new_task_impediments,
I've inherited some python code that contains a rather cryptic decorator. This decorator sets
I have this code in Python inputted = input(Enter in something: ) print(Input is
I ran into unbound method error in python with this code: import random class
Is there a way to write this C/C++ code in Python? a = (b

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.