Ready to help

Ready to help

Postby roseofsorrow » Thu Dec 24, 2009 8:55 pm

Name your problem with python and im ready to help.
roseofsorrow

Member
 
Posts: 5
Joined: Thu Dec 24, 2009 8:34 pm


Re: Ready to help

Postby chewanter » Fri Dec 25, 2009 12:30 am

Okay.

What's with the whitespace indicating syntax? I mean, really?
ImageImageImage
User avatar
chewanter

Member
 
Posts: 982
Joined: Fri Dec 19, 2008 10:19 am


Re: Ready to help

Postby roseofsorrow » Fri Jan 08, 2010 4:13 am

The white space is (in my opinion) a better way of indicating code and routes......


1| def cabbage():
2| print "This is a cabbage, when you call the cabbage this is printed"
3|
4| cabbage()


Notice the indent on the 2nd line. python reads that line and associates it with line 1. Line 1 also ends with a : that tells python to look for an indented line below. Because I don't want to call the function cabbage() inside its self because that would be useless. I drop a line (its just good practice) and without indentation call the function. Python will look for another indented line, then not finding one will go to line 4.

Sorry my reply took so long I have been studying for A-Level maths
roseofsorrow

Member
 
Posts: 5
Joined: Thu Dec 24, 2009 8:34 pm


Re: Ready to help

Postby Itachihro » Sat Jan 30, 2010 10:14 am

chewanter wrote:Okay.

What's with the whitespace indicating syntax? I mean, really?


Theres not really anything set, the only thing that matters is that code blocks (for example following a function definition) must be indented, and all parts of the same code block must have the same indention. Vertical whitespace doesn't matter, also it doesn't make a difference if you indent by 1, 4 or 4000 spaces (Standard is 4 spaces, but the interpreter doesn't really care. 4 Spaces just happen to be the number of spaces that looks best). It's strongly suggested NOT to use tabs, because they might be (scratch that- will very likely be) misinterpreted (though many python editors offer automatic conversion of tabs into spaces).
Itachihro

Member
 
Posts: 77
Joined: Sat Aug 01, 2009 11:41 am


Re: Ready to help

Postby chewanter » Sat Jan 30, 2010 2:50 pm

Itachihro wrote:
chewanter wrote:Okay.

What's with the whitespace indicating syntax? I mean, really?


Theres not really anything set, the only thing that matters is that code blocks (for example following a function definition) must be indented, and all parts of the same code block must have the same indention. Vertical whitespace doesn't matter, also it doesn't make a difference if you indent by 1, 4 or 4000 spaces (Standard is 4 spaces, but the interpreter doesn't really care. 4 Spaces just happen to be the number of spaces that looks best). It's strongly suggested NOT to use tabs, because they might be (scratch that- will very likely be) misinterpreted (though many python editors offer automatic conversion of tabs into spaces).

Brackets can't be misinterpreted.
ImageImageImage
User avatar
chewanter

Member
 
Posts: 982
Joined: Fri Dec 19, 2008 10:19 am


Re: Ready to help

Postby Itachihro » Sat Jan 30, 2010 5:09 pm

You sure? I try to keep my brackets with the same indention aswell if they are on multiple lines, but i've never tested wether it would work or not if i didn't indent them.
Itachihro

Member
 
Posts: 77
Joined: Sat Aug 01, 2009 11:41 am


Re: Ready to help

Postby chewanter » Sat Jan 30, 2010 5:35 pm

Itachihro wrote:You sure? I try to keep my brackets with the same indention aswell if they are on multiple lines, but i've never tested wether it would work or not if i didn't indent them.


My point is that in C and friends, you can indent or do whatever however you want to. Python forces their ways upon you.
ImageImageImage
User avatar
chewanter

Member
 
Posts: 982
Joined: Fri Dec 19, 2008 10:19 am


Re: Ready to help

Postby Itachihro » Mon Feb 01, 2010 3:31 pm

enforced structuring of code is IMO a good thing though.
Itachihro

Member
 
Posts: 77
Joined: Sat Aug 01, 2009 11:41 am


Re: Ready to help

Postby chewanter » Mon Feb 01, 2010 4:10 pm

Itachihro wrote:enforced structuring of code is IMO a good thing though.

Yes, brackets enforce it pretty well so that the compiler can easily parse it while the coders can write it however they want.
ImageImageImage
User avatar
chewanter

Member
 
Posts: 982
Joined: Fri Dec 19, 2008 10:19 am


Re: Ready to help

Postby Itachihro » Mon Feb 08, 2010 3:26 pm

This is less about the ability of the interpreter to parse brackets than about the readability. I've seen people writing whole functions in single lines in other languages, in Python you can't do that. The enforced structure of the code is very reasonable, it makes the code easier for others (and yourself) to read. I mean, don't write anything in a language for a month and then look at your code. You'll have a hard time understanding your own stuff as it is, you don't really have to make it harder by writing in weird structures. And the python indenting syntax is what is recommended standard in other languages anyways. anyone who writes code longer than 20 lines will be able to tell you that you should indent blocks- so Python forces you to do what you SHOULD do.
Itachihro

Member
 
Posts: 77
Joined: Sat Aug 01, 2009 11:41 am


Next

Return to Python

Who is online

Users browsing this forum: No registered users and 1 guest