Seeing "locals()" from imported function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?ISO-8859-1?Q?Luis_M._Gonz=E1lez?=

    Seeing "locals()" from imported function

    I apologize for this very basic question, but I can't understand how
    this works...
    I want to import a function from module B into my main script A, so
    this function can see and use the locals from A.

    For example:

    def auto():
    urls = ['/', 'index']
    for k,v in __main__.locals ().items(): # these "locals"
    are the ones of the main script
    if isinstance(v,ty pe) and k != 'index':
    urls.append('/%s' %k)
    urls.append(k)
    return tuple(urls)

    Of course this doesn't work...

    Any hint?

    Luis
Working...