I generally use something like (assuming either x or y will always exist)
try:
import x as value
except ImportError:
import y as value
class A:
def foo(self):
# magic using value
A real world example
try:
import Tkinter as tk ## Python 2.x
except ImportError:
import tkinter as tk ## Python 3.x