#NEWLINE# def resource_path( level = 2 ) : #NEWLINE# #INDENT# "Return a resource path calculated from the caller's stack.\n\n    " #NEWLINE# module = sys . _getframe ( level ) . f_globals . get ( '__name__' , '__main__' ) #NEWLINE# if ( module != '__main__' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return dirname ( getattr ( sys . modules . get ( module ) , '__file__' ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# for path in [ dirname ( sys . argv [ 0 ] ) , getcwd ( ) ] : #NEWLINE# #INDENT# if exists ( path ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# return path