Re: EOL - scanning single-quoted string

Discussion in 'Python' started by Ajay, Aug 4, 2004.

  1. Ajay

    Ajay Guest

    hi!

    i got the escape character bit, but i still get an errorTraceback (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


     
    Ajay, Aug 4, 2004
    #1
    1. Advertisements

  2. Ah... regex quoting issues. The '\\' makes a single '\' appear in the
    string, but being a regex, a single '\' in a string is again interpreted
    as a backslash. You will either have to write '\\\\' or use a raw string,
    r'\\'. Raw strings pass backslashes untouched, so you only need to
    backslash it once for the regex.

    However, the best solution for your problem is not to use regexes, but to
    use the os.path module:
    'C:\\My Documents\\um_ajay.xml'

    normpath() 'tidies up' the path, a task which includes correcting path
    seperators, amoung other things. abspath() does the same thing as
    normpath(), but also resolves relative paths into absolute ones. Always
    look to os.path when doing anything involving paths; it probably has the
    function you want, and is portable across platforms.
     
    Christopher T King, Aug 4, 2004
    #2
    1. Advertisements

  3. Ajay

    Ajay Brar Guest

    thanks. works well now


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

    http://www.it.usyd.edu.au/~abrar1
     
    Ajay Brar, Aug 4, 2004
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.