I want to unparent an object with python I want to unparent an object.

I tried the following code

import bpy

selectedList = bpy.context.selected_objects
selectedList[0].removeParent()


However, the following error occurred and the parent could not be removed. 

AttributeError: 'Object' object has no attribute 'removeParent'
Error: Python script fail, look in the console for now...


How can I make a selected object have no parent?
Solution 1:

Assume you have an object in python obj:

Try obj.parent = None

None is a keyword refer to nothing. You assign the object parent to nothing is equivalent to remove parent.

Solution 2:

Directly modified data in object without operator can lead to some problem. You can clear the parent in your blender, and in info panel you should see the python command: bpy.ops.object.parent_clear(type='CLEAR')