Jan-20-2018, 04:55 PM
hi,
i would like to ask how could i put a line of code that prints just user's declared variables in a function so it can be reused in a different scripts?
the code line is:
1. put the code line '[val for val in dir() if val.strip('__') == val]' in a separate function called 'u' - done
the 'u'-function looks like this:
3. open the 'ud.py' in the ide - done
4. open python3 interpreter of the ide in interactive mode - done
5. import 'ud.py' like a module 'ud' by:
6. declare some variable:
7. call the 'u'- function by:
8. the output - an empty list:
thanks in advance
i would like to ask how could i put a line of code that prints just user's declared variables in a function so it can be reused in a different scripts?
the code line is:
[val for val in dir() if val.strip('__') == val]this code line executed directly in to the interactive mode of the python3 interpreter ( of some ide ) works perfectly:
>>> [val for val in dir() if val.strip('__') == val] ['a']the problems begin when the following procedure has been executed in some ide.
1. put the code line '[val for val in dir() if val.strip('__') == val]' in a separate function called 'u' - done
the 'u'-function looks like this:
def u (): a = [val for val in dir() if val.strip('__') == val] return a2. put the function 'u' in a python-file called 'ud.py' - done
3. open the 'ud.py' in the ide - done
4. open python3 interpreter of the ide in interactive mode - done
5. import 'ud.py' like a module 'ud' by:
>>> import ud- done
6. declare some variable:
a = 'ggfhgfjhh'- done
7. call the 'u'- function by:
>>> ud.u()- done
8. the output - an empty list:
[ ]instead of
['a']how should i change the function 'u' so it can print just user's declared variables?
thanks in advance