0

Im using IDLE as a python shell and i declare a class, ie:

>>> class Car(object):
    def __init__(self, model, year):
        self.model=model
        self.year=year

after a while (and a lot of code...) i want to check that class definition. Is there any COMMAND that i can see the class Car definition ?

can i re-edit it (in IDLE)?

chenchuk
  • 5,324
  • 4
  • 34
  • 41
  • You could print `locals()` or `globals()`. – Morgan Thrapp Oct 05 '15 at 18:46
  • 2
    These kinds of features aren't immediately visible in IDLE (short of calling `locals()` and `globals()` types of functions). You should select [a more fully-featured IDE](https://stackoverflow.com/questions/81584/what-ide-to-use-for-python) if you want those kinds of things. – Cory Kramer Oct 05 '15 at 18:47
  • Possible duplicate of [Viewing all defined variables](http://stackoverflow.com/questions/633127/viewing-all-defined-variables) – Leb Oct 05 '15 at 18:47
  • Thanks for your comments, but i think i didnt explain myself very well - so i re-edit the question. – chenchuk Oct 05 '15 at 19:04
  • @CoryKramer Please do not post disinformation. There are 2 ways to see and edit previous input. – Terry Jan Reedy Oct 07 '15 at 01:20

2 Answers2

0

In console - see The Python Tutorial - Modules - The dir() Function.

For the file open in IDLE - File->Class Browser. whoops, it only shows functions and classes, not global variables

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
0

Method 1. Use the 'history-previous' key, which defaults to Alt-P ('history-next' is Alt-N, replace 'Alt' with 'Control' for Mac). It retrieves previous statements in the history list. (Some consoles, including that on Windows, only retrieve physical lines.) This is described in the IDLE Help document under Python Shell Window - Command History. Your example:

>>> class Car(object):
    def __init__(self, model, year):
        self.model=model
        self.year=year

>>> a = 2
>>> class Car(object):
    def __init__(self, model, year):
        self._model=model
        self._year=year

>>> 

I retrieved the class definition by hitting Alt-P twice. After finishing editing, make sure to move the cursor to the end before hitting Enter.

Method 2. Scroll back up, select the text you want copied (it need not be a complete statement), hit Enter, and the selected text will be copied to the current input line.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52