I'd already asked for my code to be reviewed earlier here
Considering the suggestions put forth for that question, I spent a day and refactored my whole code. For those who have seen my previous question/code, could you you point out anything which I have as of yet not improved upon?
For everyone else, all I want to know is whether I am on the right track while programming in python. Could you please tell me if there is something unpythonic in my code? What parts are not written in the way "good Python code" is meant to be written? Here is a snippet I feel is not really good:
1. Taking input from user
This is in the main loop:
input_read=False if len(m)==4: X1,Y1,X2,Y2 = m # assigning final co-ordinates m= # empty the buffer input list input_read=True if not input_read: events=pygame.event.get() for event in events: if event.type == pygame.QUIT: # Quitting exit(0) if event.type == pygame.MOUSEBUTTONUP: pressed= False # get ready for next click if event.type == pygame.MOUSEBUTTONDOWN and not pressed: pressed=True if event.button==1: if len(m)==2: # add second click co-ordinates pos = pygame.mouse.get_pos() x = pos/80+1 y = pos/80+1 m.extend([x,y]) else: pos = pygame.mouse.get_pos() # add first click co-ordinates x = pos/80+1 y = pos/80+1 j=checkPositionToPieceDict((x,y)) # Checks that the first click has a piece if j: # of your colour and selects it. if j.colour==colour: selectedPiece=j m.extend([x,y])
Could you please just go through the code and tell me if this is how Python is written in the industry?