Tuesday, March 27, 2018

Python : Exploring Objects similar to PowerShell

To be fair Python's REPL mode allows you to explore objects pretty easy. But since PowerShell has been my first language, I often tend to crib for similar experience.

P.S. - I do know that PowerShell language specs picked up quite many things from Python. Also, Python is my goto language on Linux platform as well.

So back to cribbing, I tend to miss most the exploring aspects of  PowerShell e.g. Get-Member and Format-* cmdlets until one day I sat down and wrote few functions in Python to give me a similar experience.

Getting Members

Enter GetMember.py, not a replacement for dir() in Python but this is more useful to me coming from PowerShell background.

Below is how I use it from my REPL, see that my function uses a package called Inspect and I use the GetMember function to inspect that itself :D

Format Object properties

Another thing which I most from PowerShell is that you can just pipe objects into Format-* cmdlet.

FormatList.py, not a hotshot function but gets work done.

See the usage below, makes life easy when you want to see the members (method and properties) on an object.

No comments:

Post a Comment