• Register

Modul s funkcijo globals()

+1 vote
93 views

Če kodo z ukazom:

def slovar():

return globals()

pokličen v ipython notebooku mi vrne slovar vrednosti od ipyton notebook.

Nato kodo shranim v kot modul (.py)

Če v ipyton notebooku uvozim modul in nato kličem funkcijo:

A = slovar()

mi vrne prazen slovar (najbrž vrne globals() od modula ki je {} ) in ne globals() od ipython noteook

Kako bi moral popraviti modul da vrne slovar globals() od notebooka in ne od modula?

asked May 19, 2015 by mitja str (130 points)
edited May 19, 2015 by janko.slavic

1 Answer

0 votes
Ne vem kaj želite narediti narediti z globals(), ampak nekako izgleda narobe. Globals se načeloma izogibajte.

Vseeno, tukaj je dokumentacija: https://docs.python.org/3.4/library/functions.html#globals

globals()
Return a dictionary representing the current global symbol table. This is always the dictionary of the current module (inside a function or method, this is the module where it is defined, not the module from which it is called).
answered May 19, 2015 by janko.slavic (74,450 points)
...