Jump to content
  • Advertisement
Sign in to follow this  
V-man

Trying Python

This topic is 3790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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()

Share this post


Link to post
Share on other sites
Advertisement
Python's leading whitespace is significant.

if something:
will execute this line
and this line
and this line
but not this line

if something else:
again with the executing this line
else:
else will execute this line
and this line
and this line
but 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.

Share this post


Link to post
Share on other sites
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_2
unconditional_statement



Note: I have not used Python much, this is mainly what I understand from others.

Share this post


Link to post
Share on other sites
Blocks of code are indicated by indentation instead of being surrounded by '{' and '}'.


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


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!