1

I have been asked a question that I believe is due to a mix a quote marks however I cannot specifically say why this is so in the example below. I wondered if anyone has had a similar issue.

A small amount of code has been written (with the string being copied and pasted), which ends in a invalid syntax error message. e.g.

>>> for dataset in datasetList:
...     print dataset + " " + “Dataset”
...     
Parsing error SyntaxError: invalid syntax (line 2)

Above you can see there appears to be a mix of quote marks in terms of font but I cannot see why that is of importance as they are both double quotes.

Why can't the software interpret different fonts of the same keyboard symbol?

My responce to the user is to ensure all quote marks are consistent either ' or ".

To test I edited the code and it works without a syntax error...

>>> for dataset in datasetList:
...     print dataset+ " " + "Dataset"
...     
Culture Dataset
Assets Dataset
Pipes Dataset
Wells Dataset
AerialPhoto Dataset

I also tested using different styles of quote marks (e.g. ') to see if the issue was due to a mix of quote marks being used. I ended up with two successful excutions of the code:

>>> for dataset in datasetList:
...     print dataset, 'Dataset'
...     
Culture Dataset
Assets Dataset
Pipes Dataset
Wells Dataset
AerialPhoto Dataset

and

>>> for dataset in datasetList:
...     print dataset + ' ' + 'Dataset'
...     
Culture Dataset
Assets Dataset
Pipes Dataset
Wells Dataset
AerialPhoto Dataset

Interestingly this does not seem to be a problem when using subsequent versions of ArcGIS i.e. 10.2.2 and 10.3 but maybe this is a consequence of proper quotation marks being used as supposed to software handling this specific problem.

Has anyone else come across this problem and if so what is the reason for the computer not seeing " and ” as the same symbol?

1

My response to the user is to ensure all quote marks are consistent either ' or ".

That is the answer. But to explain the failing code you need to understand "the computer" is not having the problem, its your assumption that two things you name similarly are identical.

Try looking through Python's eyes, and see if your quotes are the same: https://stackoverflow.com/a/227472/4986638

TLDR: test using ord('"'), ord('“'), ord('”'), ord(''')

  • Thank you Clay I wasn't aware of the ord() function...this is very useful for the situation. – spk578 Jun 9 '15 at 14:23
1

Your question could also be: Why does code that I copied and pasted from (what I assume is) MS Word not work in my script? MS Word, and presumably other word processors, automatically converts " to “ or ” in order to make it look nice, just like it automatically capitalizes the first letter of a new sentence. But, as you've found out through some good thorough testing, just as D is a completely different character from d, so are " and “ different, or, for that matter “ and ”.

So, your advice is exactly correct: never use “ or ”, always use " and '. The corollary advice is this: never edit code in a word processor, always use a program built for code editing, like IDLE (very basic and comes with Python/ArcGIS), Notepad++ (works for many different languages), or PyScripter (specifically for Python).

1

“ and ” are not quotes in the normal sense. They are Unicode characters: http://www.fileformat.info/info/unicode/char/201c/index.htm http://www.fileformat.info/info/unicode/char/201d/index.htm

They cannot be used interchangeably with single and double quotes in Python. They often appear when copying and pasting out of Microsoft products as double quotes are converted in these products to these Unicode characters.

1

Note that Apple has recently changed the way OS X and TextEdit handles quotes. Simple copy paste operations can yield unreadable (for python) quotes. http://www.iclarified.com/38772/how-to-disable-curly-quotes-in-mac-os-x-mavericks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.