Trying Python

Started by
3 comments, last by V-man 16 years ago
Hi, I'm trying to learn python From the looks of it, there is a if statement and at the end of the line there is a ":". But where does the "if" block end? In C++, a block starts with { and ends with } If you don't put the brackets, then only the line following the if is part of the block. Same problem for the part after the "else"

if(event==EVENT_EXPORT):
            # print self.mWhatExport
            if self.mWhatExport.val == 1:
                objects = Object.GetSelected()
                print "Exporting only selected"
            else:
                objects = self.mScene.getChildren()
                print "Exporting *ALL*"
            osg_export = OSGExport(self.mFilename.val, self.mScene, self.mLoopMode.val,              self.mMeshAnim.val, self.mFPS.val, objects)
            osg_export.export()
        if event==EVENT_DONE:
            self.ExitGUI()

Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Advertisement
Python's leading whitespace is significant.
if something:   will execute this line   and this line   and this linebut not this lineif something else:   again with the executing this lineelse:   else will execute this line   and this line   and this linebut not this line

You might want to check out a book or website like Dive Into Python. Learning just from reading code might be hard.
From what I know, Python uses the indentation itself to determine where control blocks start and end. So, when you are finished writing your if block, simply return to the lower level of indentation.
if condition:    condition_true_statement_1    condition_true_statement_2unconditional_statement


Note: I have not used Python much, this is mainly what I understand from others.
Blocks of code are indicated by indentation instead of being surrounded by '{' and '}'.

a = 1if a == 1:    print "A is 1"else:    print "A is not 1"

Quote:Original post by SiCrane
You might want to check out a book or website like Dive Into Python. Learning just from reading code might be hard.


Thanks.

I am trying to crash dive into it in order to write a script quickly.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement