4

I wrote this function as part of a scrolling panel I was trying to make in pygame. The function is part of a class called slot, which is a part of the panel class, slots being the bars on the panel containing strings or data. this method draws the slots to the screen, drawing only a part of a slot if the screen in in between slots. The if/elif/else syntax is tripping me up:

    def mydraw(self,my_pygame,scrn,panel_x,panel_y,scroll_at,window_size,virtual_size):
        if((self.y<(scrollat+window_size))or((self.e_y)>scrollat)):
            onscreensy = (self.y-scrollat)+panel_y
            onscreeney = onscreensy + self.dim_y
            """the top case"""
            if(onscreensy<panel_y):
                onscrnwidth = (onscreensy+self.dim_y)-panel_y
                onbitmapwidth = self.dim_y-onscrnwidth
                holder = self.bitmap.subsurface(0,onbitmapwidth-1,self.dim_x,onbitmapwidth-1)
                scrn.blit(holder,(panel_x,panel_y))
            """end top case"""
            """the normal case"""
            elif(onscreeney<(panel_y+window_size)):  #### right here ####
                scrn.blit(self.bitmap,(panel_x,onscreensy))
            """end normal case"""
            """the bottom case"""
            else:
                onscrnwidth = (panel_y+window_size)-self.y
                onbitmapwidth = self.dim_y-onscrnwidth
                holder = self.bitmap.subsurface(0,0,self.dim_x,onbitmapwidth-1)
                scrn.blit(holder,(panel_x,onscreensy))
            """end bottom case"""
        if(self.has_next==True):
            self.next.mydraw(my_pygame,scrn,panel_x,panel_y,scroll_at,window_size,virtual_size)

error:

me$ python testscrolling3.py
  File "testscrolling3.py", line 164
    elif(onscreeney<(panel_y+window_size)):
       ^
SyntaxError: invalid syntax
3
  • Please post the entire error message. Commented Feb 23, 2014 at 23:34
  • Show the full Error message so that we can see what type of error it is. Commented Feb 23, 2014 at 23:35
  • It's a syntax error at the elif because the strings are code at the same indent-level as the if. Commented Feb 23, 2014 at 23:37

2 Answers 2

5

Those are not comments. They are strings, and are normal executable statements (even if they don't actually do anything).

Comments in Python start with #.

Sign up to request clarification or add additional context in comments.

Comments

2

Just as @Daniel_Roseman pointed out, they are strings. They can be kept in the function. Actually they can do something (rather than doing nothing), consider the following example do_sth3(), where the string follows the function declaration is the docstring.

But if we want to kept them in the function, the indentation has to be correct. Compares: do_sth1() to do_sth2()

In [53]:

def do_sth1():
    if 1==1:
        print 'Ok'
    '''Comment goes here'''
    else:
        print 'Not Ok'
  File "<ipython-input-53-fada2ba2e658>", line 5
    else:
       ^
SyntaxError: invalid syntax


In [54]:

def do_sth2():
    if 1==1:
        print 'Ok'
        '''Comment goes here'''
    else:
        print 'Not Ok'
In [55]:

def do_sth3():
    '''usage: just a test function'''
    print 'Ok'
In [56]:

do_sth3.__doc__
Out[56]:
'usage: just a test function'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.