I'm having a bit of fun with python creating classes and methods and stuff but I have one problem.
Say I have this code:
class Circle:
def __init__(self, radius):
self.radius = radius
def increaseR(self):
self.radius += 1
The code itself runs perfectly fine. But when I run the .py file, it runs it through the shell (I think that's what it's called), then it closes it. While I realize that this is completely normal to happen, I was wondering how I could keep it open so someone can toy around with the program and do stuff like:
c = Circle(1)
c.radius
c.increaseR
Basically play around with the class and get output from the shell. But it closes too fast, and I don't want to have to run it from my IDE every time (where the shell stays open).
Basically I want the shell to stay open and keep taking input from the user until you literally click the red x on the shell window.
Sorry if I sound dumb, I just started Python programmming.
Thank you!
Bella
Use the -i
option while opening your terminal. Just replace your_file.py
with the file you wish to execute.
python -i your_file.py
you may need this:
$ python -i your_source.py
you can also use -c to excecute code as parameter like this:
$ python -c "print 3*2"
6
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.