Wakefield's Daily Tips

Know your quotes

If I type:

url = “https://webaddress/?participant=” + expInfo[‘participant’]

and then I type

url = "http://webaddress/?participant=" + expInfo['participant']

and then I copy each one into a PsychoPy code component, the first will give a syntax error and the second will be fine.

The difference is that in the first line, the forum has converted my straight quotes (aka dumb) to curly quotes (aka smart). Curly quotes look nicer in text but do not work for code.

In Python you can use single or double quotes. The recommendation is to use single quotes around short text, but double around sentences, where the text itself might contain apostrophes for possessives or contractions. JavaScript is similar but must use double quotes within dictionaries. The Auto-JS translation in code components converts single quotes in Python to double in JavaScript.

2 Likes