def fd(f):
 return ((hasattr(f, 'fileno') and f.fileno()) or f)

def fd ( f ) : return ( ( hasattr ( f , 'fileno' ) and f . fileno ( ) ) or f )
get a filedescriptor from something which could be a file or an fd .