Perspective Button to write to Database INDENT errors?

Trying to setup a button to write to a MySQL database.

Though the post don’t show it the first line “def” is the only one that is not tabbed.

def runAction(self, event):
	"""
	Method that will run whenever the selected event fires.

	Arguments:
		self: A reference to the component that is invoking this function.
		event: An object that holds information about the selected event type
	"""
	DateV = system.date.now()
	idV = 1
	query = "UPDATE table SET date = ? WHERE id = ?"
	args = [DateV, idV]
     system.db.runPrepUpdate(query, args)

I then get:

Unable to run function “runAction(self, event)”, code could not be compiled.

org.python.core.PySyntaxError: SyntaxError: (“mismatched input ‘’ expecting INDENT”, (’’, 1, 27, ‘def runAction(self, event):\n’))

Tab all of your actual code in by one tab.
Extension functions, such as runAction, act as if you were defining a Python function - so the top line (def runAction) is the only line that should actually be at the minimum indent level. Your code should look like this:

def runAction(self, event):
"""
some docstring here
"""
	DateV = system.date.now()
	# the rest of your code

and not like this:

def runAction(self, event):
"""
some docstring here
"""
DateV = system.date.now()
# the rest of your code

It is, how do you comment code on the forum so it keeps the tabs etc?

Thanks.

I’m using the onActionPerformed but I had looked at the onClick mouse event at some point. :slight_smile: Only the default def runAction code was in it.

Would still like to know how to comment code in a post.

Put three backticks ``` before and after the code, on their own lines:

    ```
    code
    ```

(Or just use this icon: image )

Ok, thanks for the help.