AllTradesJack
AllTradesJack

Reputation: 2882

Access a script's variables and functions in interpreter after runtime

So let's say I have a script script1. Is there a way to interact with script1's variables and functions like an interpreter after or during its runtime?

I'm using IDLE and Python 2.7, but I'm wondering if I could do this in any interpreter not just IDLE's.

Say in my script, get = requests.get("example.com"). I'd like to hit F5 or whatever to run my script, and then instead of the console unloading all of the variables from memory, I'd like to be able to access the same get variable.

Is this possible?

Upvotes: 2

Views: 239

Answers (2)

progalgo
progalgo

Reputation: 358

That's a serious question. You might need to consult this page:

https://docs.python.org/2/using/cmdline.html#miscellaneous-options

Note the -i option, it makes interpreter enter interactive mode after executing given script.

Upvotes: 1

mehdy
mehdy

Reputation: 3374

you can do like this:

#file : foo.py
import requests

def req():
    get = requests.get("example.com")
    return get

and then run the script from a console

import foo
get = foo.req()

Upvotes: 1

Related Questions