def popd():
 from twill import commands
 where = _dirstack.pop()
 os.chdir(where)
 print >>commands.OUT, ('popped back to directory "%s"' % (where,))
 commands.setglobal('__dir__', where)

def popd ( ) : from twill import commands where = _dirstack . pop ( ) os . chdir ( where ) print >> commands . OUT , ( 'popped back to directory "%s"' % ( where , ) ) commands . setglobal ( '__dir__' , where )
should behave like python2 .