简体   繁体   中英

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?

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM