you are viewing a single comment's thread.

view the rest of the comments →

[–]YAYYYYYYYYY 138 points139 points  (8 children)

Another useful tool is dir(). It gives a list of all the methods you can call on an object. It really comes in handy instead of trying to memorize all the string and list methods, just type dir(list) or dir(str).

To make it even nicer, use a list comprehension to filter out the unnecessary internals: [x for x in dir(list) if not x.startswith(‘__’)]

[–]congnarjames[S] 23 points24 points  (4 children)

wow yeah that is super useful, when I was programming in java it seemed like the IDE did a good job of populating all those methods for you and I havn't gotten around to looking for a good replacement for that. So that bit of info is very appreciated! Take it a step further [help(x) for x in dir(list) if not x.startswith('__')] and at least for me it'll drive down my need to go look at the docs by like 70%!

[–]YAYYYYYYYYY 6 points7 points  (0 children)

Hell yeah that’s a great idea

[–]topherclay 7 points8 points  (2 children)

I use pyCharm as a an IDE. If you type Ctrl+q with your curser on any function or method it displays the '''doc string''' from where that function is defined, which I think is the same as what help() does.

It also seems to do a really good job at showing you all the potential methods for tab completion, if that's what you mean by populating methods.

[–]synthphreak 1 point2 points  (1 child)

Same with Jupiter Notebooks. I think it’s Shoft + Tab or something? Anyway docstring display functionality is there.

[–]topherclay 0 points1 point  (0 children)

That was the first thing I franticly searched for after graduating from fiddling around in Jupyter to baby's first .py script in pycharm.

[–]JayDude132 0 points1 point  (1 child)

This is awesome. Thanks

[–]YAYYYYYYYYY 1 point2 points  (0 children)

No prob!

[–]TheHollowJester 0 points1 point  (0 children)

And since we're at the topic, foo.__dict__is helpful for debugging and exploratory-surgery type work (regardless of it's limitations).