[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Tabs v.s. spaces (was Re: Programming first steps.)



Tom wrote:
Do whitespace mistakes cause compile time errors? The frustrating thing about fortran was variable names that started with C could be interpreted as comments not indented correctly, which would just cause that line to be skipped. Integer literals not indented correctly could be interpreted as line numbers and would really cause havoc with computed gotos. I.e., they were as super-frustrating to debug as misspelled variable names in a declaration-less language, or the types of bizarre situtations you get into in C when you start overwriting memory.

Trust me, in Python were anything like that I would be right there with ya. It isn't. Someone else address your specific questions so I won't here. I just wanted to add that basically Python boils down to this:

    It's the code you should write without the braces and semicolons.

Seriously. Take a piece of code from Perl or C or PHP or any other language which has those constructs which is written properly (IE, human readable) then just remove the braces and semicolons and you have the basic equivolant of Python code. Granted the keywords and syntax are different but the idea is the same. It's just properly indented code without braces and semicolons. Here's an example that shows that nicely. Notice my argument lists on both calls to self.FileList.AppendItem():

    def Init_FileList(self):
        '''Setup the initial tree for the FileList view'''
        root_node = self.FileList.AddRoot('Mail dirs',-1,-1,NULL)
        for dir in vars.maildirs:
            dir_name = wxTreeItemData(dir)
            dir_node = self.FileList.AppendItem(root_node, dir, -1, -1,
                                                dir_name)
            try:
                for file in os.listdir(dir):
                    filepath = wxTreeItemData(dir + '/' + file)
                    if os.path.isfile(filepath.GetData()):
                        self.FileList.AppendItem(dir_node, file, -1, -1,
                                                 filepath)
            except OSError:
                self.err('Directory %s does not exist' % (dir))


--
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
       PGP Key: 8B6E99C5       | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------

Attachment: pgpylF_xifrC5.pgp
Description: PGP signature


Reply to: