# [Tutor] Puzzled again

Richard D. Moores rdmoores at gmail.com
Wed Aug 3 04:36:39 CEST 2011

```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
>>>

What solved the problem and what didn't:

This doesn't work:

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

Nor this:

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

But this does:

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

Thanks,

Dick Moores
```