Skip to content

Syntax error in string (invalid escape \$) #141

Description

@kyrsjo

In the elegant wrapper where it calls csv2sdds, there is a warning about a bad escape sequence in a string.

Relevant code fragment:

    # convert CSV to SDDS (ascii for now)
    subprocess.call(CONFIG.elegant_exec + 'csv2sdds ' + tmpfile + ' ' + filename + 
                        ' -asciiOutput -columnData=name=x,type=double,units=m' +
                        ' -columnData=name=xp,type=double' + 
                        ' -columnData=name=y,type=double,units=m' + 
                        ' -columnData=name=yp,type=double' + 
                        ' -columnData=name=t,type=double,units=s' + 
                        ' -columnData=name=p,type=double,units=\"m\$be\$nc\"' +
                        ' -columnData=name=dt,type=double,units=s' +
                        ' -columnData=name=particleID,type=ulong64', shell=True)

Link to the relevant line:

' -columnData=name=p,type=double,units=\"m\$be\$nc\"' +

Warning:

abel/wrappers/elegant/elegant_wrapper.py:214
  /home/kyrsjo/code/ABEL/abel/wrappers/elegant/elegant_wrapper.py:214: SyntaxWarning: invalid escape sequence '\$'

I don't know if you want to output "$" or "$" so I haven't made a PR, however if the wanted output is "$" then using either a raw string or escaping the backslash as in \\$ should work; if the wanted output is $ then no escape should be needed.

Also note that when using single-quote strings, you shouldn't need to escape double quotes.

To avoid needing escapes, consider using raw strings when appropriate.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions