Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get all the variables that are in a module, but excluding the variables that are imported in that module

So here's the scene. I have a module as:

Filename A:

import a_local_module

item = [ 1, 2, 3]

Filename B:

import A

list_of_variables = dir(A)

The thing here is that now there is a list of variables from A and a_local_module. But I want to get the list of variables declared in file A and not from its import of a_local_module.

Also assuming that I don't know what the imports in file A are.

Is there a way to do this?

like image 703
ctrl-shift-esc Avatar asked Sep 06 '25 03:09

ctrl-shift-esc


1 Answers

Just import a_local_module yourself and compare:

import a_local_module as local
import A

variables = [k
    for k, v in vars(A).iteritems()
        if getatrr(local, k, object()) is v]
like image 141
zondo Avatar answered Sep 07 '25 16:09

zondo