[Tutor] Puzzled again
Dave Angel
d at davea.name
Wed Aug 3 06:59:51 CEST 2011
On 08/02/2011 10:36 PM, Richard D. Moores wrote:
> Puzzled again. Why the error. Line 36 is the line just above "import
> os.path". I have many other functions in mycalc.py with examples
> formatted exactly the same way.
>
> def convertPath(path):
> """
> Given a path with backslashes, return that path with forward slashes.
>
> By Steven D'Aprano 07/31/2011 on Tutor list
> >>> path = r'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf'
> >>> convertPath(path)
> 'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf'
> """
> import os.path
> separator = os.path.sep
> if separator != '/':
> path = path.replace(os.path.sep, '/')
> return path
>
>>>> from mycalc import convertPath
> Traceback (most recent call last):
> File "<string>", line 36, in<fragment>
> Syntax Error: """: c:\Python32\lib\site-packages\mycalc.py, line 36-1
>>>> def convertPath(path):
>>>> """
>>>> Given a path with backslashes, return that path with forward slashes.
>>>>
>>>> By Steven D'Aprano 07/31/2011 on Tutor list
>>>> >>> path = r'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf'
>>>> >>> convertPath(path)
>>>> 'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf'
>>>> """
>>>> import os.path
>>>> separator = os.path.sep
>>>> if separator != '/':
>>>> path = path.replace(os.path.sep, '/')
When I paste that from your email into a file and run Python 2.7 on it,
it behaves fine with no errors. That's in Linux.
But the easiest explanation is that you perhaps used a funny character
for your triple-quotes. And when you retyped them on a new line, you
typed regular ones.
For example, I've seen that sort of thing when someone wrote code in a
Windows word processor that had "smart quotes."
--
DaveA
More information about the Tutor
mailing list