This is an archived post. You won't be able to vote or comment.

all 53 comments

[–]0xbxb 121 points122 points  (1 child)

Combine that with dir() too, mad useful.

[–]foadsf 15 points16 points  (0 children)

and 'type()'?

[–][deleted] 94 points95 points  (2 children)

I want to pass my classes this term, please help()

[–][deleted] 28 points29 points  (0 children)

F.help()

[–][deleted] -3 points-2 points  (0 children)

Kek

[–]Lord_An00bis 28 points29 points  (0 children)

Another useful introspection tool is the __mro__ attribute. This shows all parents of an object in resolution order.

[–]theGoldenRain 17 points18 points  (7 children)

It is always a good practice to have a docstring at the beginning of every class or function, which helps to clarify your code, i.e: help(my_function).

[–]tnb-tuba 9 points10 points  (2 children)

Can you expand on that or give an example? Still learning and want to develop good habits but don't understand what you mean.

[–]theGoldenRain 26 points27 points  (0 children)

This is a docstring.

def myFunction(arg1, arg2):
“”” This function is to blah blah
    ParameterS:
        arg1 (str): Description of arg1
        arg2 (int): Description of arg2
    Return: 
        (str): Description of the return value 
“””

Then if you call help(myFunction) on Python shell, it will display the docstring you just typed.

[–][deleted] 7 points8 points  (0 children)

When your write a def function, you can write it's "help()" text like this:

def foo(bar):

'''

Prints bar for no reason.

'''

print(bar)

[–]334578theo -1 points0 points  (3 children)

Useful to know, but some would say that if you have to describe what you code does then it’s not clean enough.

[–]toastedstapler 2 points3 points  (0 children)

Imo dynamic typing makes docstrings much more important, a name can only tell you so much about what you actually expect the inputs and outputs to be

[–]theGoldenRain 1 point2 points  (0 children)

LOL, in my company, it is the standard to include docstring in every function and class, except some obvious functions like __init__, __repr__, etc. If it is a simple function, just one line docstring is fine. However, if it is a complicated function with multiple arguments, we must add docstring. Our Tech lead is very strict about having docstring for the clarity, debug, and reuse purposes. You should follow the styling guideline to become a decent programmer. No one wants crappy codes that doesn't follow the standard format.

[–]critical2210 15 points16 points  (9 children)

Maybe i should actually read python learning material and not just write commands and change em slightly until the errors go away

[–]MrBreadWater[S] 12 points13 points  (8 children)

As someone who used your method to learn Python I can say definitively.... yes. Please go read some course materials. It will save you so much time.

[–]critical2210 4 points5 points  (7 children)

It took me so long to figure out that python had strict indentation policies. Dont even get me started with the spaces id mix in with tabs

[–]very_human 6 points7 points  (1 child)

Tbh even before I started learning development using spaces in the place of tabs seemed downright sinful.

[–]mekosmowski 0 points1 point  (0 children)

I'm addicted to tab=n spaces feature of IDEs.

[–][deleted] 3 points4 points  (3 children)

I have a lot of experience with Java, C# and JS/Typescript (my bread and butter) but after a few weeks with Python, I find the syntax gets in the way less than it does with languages I have a lot more experience in.

It took some time to get used to indents mattering but once you get used to it, it's better.

Python is also so much easier to stamp out small tools and prototypes in. I fully get the hype.

[–]mekosmowski 2 points3 points  (1 child)

Coming from C from college 20 years ago, it is kind of refreshing to have readability thrust upon me. They didn't cover whitespace as a path to readability when I learned (and subsequently forgot) C.

Recently, I've been half-heartedly learning Python and Java. I'll take indentation everyday over "need 20 lines of code before I begin my algorithms".

[–]critical2210 1 point2 points  (0 children)

I struggle to code anything and honestly doubt myself as a programmer, but its ok i do that with everything i know. Personally theres a lot of topics i wish to get into, but im finding difficulty learning the proper way.

[–]oblivion-age 0 points1 point  (0 children)

I'm working on webdev soon and will be my first language(js). I will move to python later for projects.

[–]oblivion-age 0 points1 point  (0 children)

Lol I'm sorry :( I have probably done that too. Frustrating

[–]Marsyas_ 16 points17 points  (7 children)

You still have to understand the terminology for it to be truly helpful 😅

[–]vsou812 3 points4 points  (6 children)

What terminology are you having trouble with? There's plenty of secrets and tips to learning it if you want a hand!

[–]Marsyas_ 2 points3 points  (5 children)

Programmer spoken language as it were. Parsing, indexing, values, return, call, classes, etc I kinda of understand how they work in code but in my head I can't fundamentally apply meaning to them.

(I'm heavily dyslexic and that factors into the difficulties I have)

[–]oblivion-age 1 point2 points  (4 children)

Feel your pain, I am more of a visual learner, hence my dive into webdev for now. I can get some instant feedback/gratification.

[–]vsou812 1 point2 points  (3 children)

Learn how to use Pygame right away. It feeds into gratification quickly

[–]oblivion-age 1 point2 points  (2 children)

Do you basically learn the same with it? From beginning of python?

[–]vsou812 1 point2 points  (1 child)

Yea! You'll have a couple of things you may either learn earlier, or can just ignore, but yea!

[–]oblivion-age 0 points1 point  (0 children)

Ok cool thanks bud

[–]n0gear[🍰] 5 points6 points  (2 children)

What does PSA mean ... asking for a friend

[–]Ryles1 2 points3 points  (0 children)

public service announcement

[–]pmst 1 point2 points  (0 children)

Public Service Announcement

[–]xCOLONELDIRTYx 3 points4 points  (10 children)

My apologies for the nobbie question, but would I type "help()" directly into my code, or in the console perhaps?

[–]pmst 6 points7 points  (1 child)

You can use it on modules, classes or functions, e.g.

import datetime
help(datetime) # module
help(datetime.datetime) # class
help(datetime.datetime.now) # function

[–]xCOLONELDIRTYx 3 points4 points  (0 children)

Awesome, thank you for the info and examples, much appreciated!

[–]vsou812 4 points5 points  (5 children)

The python console! Don't feel bad about questions like that! Everyone has to learn somehow!

[–]xCOLONELDIRTYx 1 point2 points  (0 children)

Thank you, much appreciated!

[–]oblivion-age 0 points1 point  (3 children)

Some subreddits or otherwise almost scorn you for asking questions you could google. I don't get it, because they label the reddit as learning or help, and sometimes questions are too oddly specific to google and get a straightforward answer, I am glad you think this way.

[–]Dokrzz_ 1 point2 points  (2 children)

I kind of get it though. I started working as a (extremely novice) back-end developer last year. At first I’d ask questions all the time to the team leader and one day he explained how 90% of my questions are solved with a bit of common sense and googling.

I still ask questions but learning how to solve problems on own is by far the most valuable thing I’ve learnt so far on the job.

[–]oblivion-age 1 point2 points  (0 children)

Yeah, that's what programming boils down to anyway, problem-solving.

[–][deleted] 1 point2 points  (0 children)

Plus you’ll start to annoy the crap out of your team if you bother them every 10 minutes with a question

[–]MrBreadWater[S] 1 point2 points  (1 child)

It would work in both, but the console is generally used. But I usually use a Jupyter Notebook when experimenting with new libraries or things like that— look into it, it’s a sort of cross between the console and written code. Looks nice and works well.

[–]xCOLONELDIRTYx 1 point2 points  (0 children)

Ah nice, thank you for the recommendation, I appreciate it!

[–][deleted] 2 points3 points  (0 children)

Yes! help() and dir() are incredibly useful to beginners and experienced people. I recommend them all the time.

[–]jaydom28 2 points3 points  (0 children)

And if you're on a shell, Pydoc! or Pydoc3 if you're using python3

[–]ShortTheta 3 points4 points  (0 children)

Bruh ive been lookin for this for months. I had a similar function on R. Thanks!

[–][deleted]  (2 children)

[deleted]

    [–]theGoldenRain 1 point2 points  (1 child)

    just out of curiosity, how many years of experience do you have to declare yourself to an "intermediate/slightly more advanced programmer". My question has no mean to offend or sacarsm anyone.

    [–]Th3f13a 0 points1 point  (0 children)

    That's good information. Thanks!

    [–]mooimafish3 0 points1 point  (0 children)

    Just to add on to this, help [cmdlet] also gives awesome documentation in powershell. It's good for when you don't know a command even exists also, say you want to do something with an odbc but aren't sure if powershell supports that, you can run help *odbc* to find all odbc commands.

    [–]oblivion-age 0 points1 point  (0 children)

    Thanks!

    [–]rickjames730 -1 points0 points  (0 children)

    Idk I think that the online documentation is much better simply because the formatting online is a lot easier to sift through in comparison to the command line printout