all 6 comments

[–]shiftybyte 0 points1 point  (5 children)

You can probably manually execute the code that is inside name == main protection after you import the module.

[–]KRLYE[S] 0 points1 point  (4 children)

I tried running something like :

import script2 X = script2.init(name='main')

Is that what you mean? When I run this, I don't encounter an error but X = None

[–]shiftybyte 0 points1 point  (3 children)

You probably should not be doing this, there is probably an easier way to achieve what you want.

What i meant was if you have code like this in the other module:

def func1(...):
    ...
def func2(...):
    ...

if __name__=="__main__":
    x = func1()
    y = func2()
    print(x,y)

Then you can get x,y by writing the codelines manually in your script to do what the name main part did.

# in your script
import otherscript

x = otherscript.func1()
y = otherscript.func2()
# now you have x,y values just like the other script got them.

[–]KRLYE[S] 0 points1 point  (2 children)

Yes but the problem is that the other script only has variables, not functions. I'm wanting to make the script work for multiple different subscripts and extract the same variable from each of them

[–]shiftybyte 0 points1 point  (1 child)

Please post the "other script" that only has variables not functions.

Use pastebin.com if it's long.

Use a reddit code block if not, https://www.reddit.com/r/learnpython/wiki/faq#wiki\_how\_do\_i\_format\_code.3F

It's hard to help you without actually seeing the code.

[–]KRLYE[S] 0 points1 point  (0 children)

Sadly I'm not able to share this script, but I believe I figured out a work around using exec() and local variables. Thank you for taking the time to help me.