spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.32k stars 1.61k forks source link

Startup script for debugger #12795

Closed OverLordGoldDragon closed 4 years ago

OverLordGoldDragon commented 4 years ago

Is it possible to set one? I have functions useful for debugging that I placed in Preferences > IPython console > Startup > Run a file, but they're are undefined in ipdb>. Further, running debugger appears to undo the startup script; I can access functions before running debugger, but not after (unless I restart kernel).

I figure this isn't as simple due to debugger namespace scoping, so I suppose the question's rather whether there's a way to define global functions - but that IPython "forgets" the startup script after debugging remains unclear to me.

ccordoba12 commented 4 years ago

I think this is an idea worth exploring. @impact27, what do you think about it?

impact27 commented 4 years ago

Something like https://github.com/spyder-ide/spyder/pull/10542? I really like this PR :) I use it to load matplotlib and numpy in every frame I debug.

ccordoba12 commented 4 years ago

That's it! Sorry Quentin for not reviewing that one (I forgot about it). I'll merge it for sure for 4.2.0.

OverLordGoldDragon commented 4 years ago

@impact27 Sure looks like it, I look forward to it. My function of interest spares much typing in pretty-printing object attributes / lists:

def iprint(iterable):
    """Print iterable in a column"""
    if isinstance(iterable, dict):
        for k, v in iterable.items():
            print(k, '--', v)
    else:
        for x in iterable:
            print(x)

iprint(vars(obj))
iprint(dir(obj))
impact27 commented 4 years ago

@OverLordGoldDragon Do you know the Pbd pp command? https://docs.python.org/3/library/pdb.html#pdbcommand-pp . This might get you a similar result

OverLordGoldDragon commented 4 years ago

@impact27 Nice - this does the trick. Your PR's still worth pursuing though.