Recursive import: 'import' vs. 'from ... import ...'

Cyclic imports usually indicate design problems but in order to solve them you may write the import statement at the bottom like so:

def x1():
    print "x1"

def x2():
    print "x2"
    file2.y2()

from file2 import y2

Keep in mind it's a workaround. The reason from x import y doesn't work in case of cyclic imports is that when you reach the first from ... import ... you are passed to the second module and when the second module calls back the first, the interpreter realizes it's a never-ending cycle and continues with a partially imported module, which happens before you even define the functions meaning y2 doesn't exist yet.