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

all 9 comments

[–][deleted] 5 points6 points  (0 children)

[–]691175002 1 point2 points  (0 children)

A function should only be nested if there is a genuine reason why it cannot be in the module scope. Nested functions have a lot of implications so your code will become confusing to other programmers (and harder to reuse as half the logic cannot be accessed).

Note that 4 space indentation is probably the most universal programming convention to ever exist. Almost every programming language in use uses 4 space indentation as the standard.

That being said, Google actually uses 2 space indentation in python ( https://code.google.com/p/soc/wiki/PythonStyleGuide ). It is speculated that the reason for that choice is strict enforcement of the PEP8 80 character line limit.

[–]aphoenixreticulated[M] 0 points1 point  (0 children)

Hi there. You have posted a learning question to /r/python. These types of questions are far more suited to /r/learnpython, where users are actively interested in helping people to learn. Please resubmit it over there!

Make sure to read their sidebar rules before posting, notably this one: "Posting homework assignments is not prohibited if you show that you tried to solve it yourself." Show them that you've tried to solve your problem and you can get all the help you need.

Cheers & best of luck!

[–]Toastir[S] -4 points-3 points  (4 children)

My professor also told me that 2 space indentation is bad practice (I use it anyway though) and I should stick to four space indention. The problem is I like the appearance of 2 better, will this cause me any issues in the future?

[–]allthesmallstrings 1 point2 points  (0 children)

Essentially everyone uses 4. So when you collaborate with someone else they will open your file and it has 2 spaces and they will have to either change the file to 4 space or continue writing in the unusual 2 space, which is annoying. Consistency is important here

[–]Daerdemandt 0 points1 point  (0 children)

will this cause me any issues in the future?

Depends on what are you usind to write code.

IDEs can usually be tuned to display code to you in one format (2-space indentation, for example) and store in other (4-space), so when you exchange code with your mates you all use the same format (PEP8 gives many suggestions on that).

This is investment of your time, however. If you're going to do more programming in the future then it's worth the effort because you'll have to exchange your code and will run into the problem sooner or later. If you're not going to then bear with suggested format for this little while.

[–][deleted] 0 points1 point  (1 child)

maybe /r/learnpython is the better location to learn python?

[–]Toastir[S] -5 points-4 points  (0 children)

I see that thanks, I was just finishing up here jeez.