Making code more adaptable problem

I am trying to make my code easily adaptable for anyone else using the code.

In the example below, the idea is that if the person using the code does not want a certain stimulus shown in the experiment, all they have to do is set practice to ‘False’. If it is set to ‘True’, the stimulus will be shown.

‘practice’ will be at the top of the script.

My question is, is this pythonic? I feel like there is a better way to do this (or maybe I shouldn’t do it at all).

practice == True

if practice == True:
       stim.draw()

I wouldn’t worry about whether it is ‘pythonic’, which often seems a very subjective standard to me. Your code seems clear and readable, which is the main thing.

One suggestion: perhaps put practice in all caps, i.e. PRACTICE. This is a hint to Python programmers that this is a constant rather than a variable that might change throughout the script. i.e. it’s just a common or garden variable to Python, but this is a stylistic pointer to programmers to perhaps look at the top of the script for the initial definition and explanation of this constant.

1 Like

Thanks!

Great idea. I am just trying to make my code as readable and as understandable as possible at the moment, and ensuring that people know practice is a constant sounds like a good idea.

One more thing:

In your if statement, you can simply use if practice: instead of if practice == True: (it’s already a boolean). Doesn’t change the code but I find it more readable!

2 Likes

Thanks!

I didn’t realise you could do that in Python.

1 Like