EOL - scanning single-quoted string

Ajay abra9823 at mail.usyd.edu.au
Wed Aug 4 09:33:19 EDT 2004


hi!

i got the escape character bit, but i still get an error
>>> str='/My Documents/um_ajay.xml'
>>> re.subn('/', '\\', str)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "c:\Python23\lib\sre.py", line 151, in subn
    return _compile(pattern, 0).subn(repl, string, count)
  File "c:\Python23\lib\sre.py", line 258, in _subx
    template = _compile_repl(template, pattern)
  File "c:\Python23\lib\sre.py", line 245, in _compile_repl
    raise error, v # invalid expression
sre_constants.error: bogus escape (end of line)

any ideas?

cheers

--
Ajay Brar,
CS Honours 2004
Smart Internet Technology Research Group


Quoting Gandalf <gandalf at geochemsource.com>:

>
>   Hi Ajay!
>
> The problem is that you must represent the backslash as '\\'. This is
> because a simple backslash opens an escape sequence.
> For example:
>
> '\n'  - this is new line
> '\t'   - this is TAB
> '\\'   - this is the backslash itself
>
> You should use this:
>
> re.subn('/', '\\', str)
>
> The other way is to use raw strings. You can read more about these
> things here:
>
> http://docs.python.org/ref/strings.html
>
> Best,
>
>   Laci 2.0
>
>
>
>
> Ajay wrote:
>
> >hi!
> >
> >I am developing an application for a pocket pc.
> >i have a small gui which allows users to select files using a file
> dialog
> >box. however the file, selected is represented as '/My Documents/test'
> >which when i try to open gives me an error.
> >so what i would like to do is replace '/' by the windows '\'
> >however when i try
> >str='/My Documents/test'
> >re.subn('/', '\', str)
> >
> >i get an error saying - SyntaxError: EOL while scanning single-quoted
> >string
> >
> >how can i replace the slashes.
> >
> >thanks
> >
> >cheers
> >
> >--
> >Ajay Brar,
> >CS Honours 2004
> >Smart Internet Technology Research Group
> >
> >
> >
> >
> >
> >----------------------------------------------------------------
> >This message was sent using IMP, the Internet Messaging Program.
> >
> >
>
>


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.



More information about the Python-list mailing list