Trying to make a shortcut through python
Question: Python 2.7

    
    
    from Tkinter import *
    import os
    
    class App:
        def __init__(self, master):
            self.frame = Frame(master)
            self.b = Button(self.frame, text = 'Open', command = self.openFile)
            self.b.grid(row = 1)
            self.frame.grid()
        def openFile(self):
            os.startfile("C:\Users\David\Desktop\minecraft.jar")
    
    root = Tk()
    app = App(root)
    root.mainloop()
    

using py2exe it shows this error and its not compiling: SyntaxError:
'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX
escape


Answer: You need to escape `\` in the following string literal. Otherwise, it is
recognized as unicode escape sequence.

    
    
    >>> "C:\Users\David\Desktop\minecraft.jar"
      File "<stdin>", line 1
    SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
    

Explicitly escape them:

    
    
    >>> "C:\\Users\\David\\Desktop\\minecraft.jar"
    'C:\\Users\\David\\Desktop\\minecraft.jar'
    

or use raw string literals:

    
    
    >>> r"C:\Users\David\Desktop\minecraft.jar"
    'C:\\Users\\David\\Desktop\\minecraft.jar'
    

BTW, Python 2.x does not raise the SyntaxError for the string literal
`"C:\Use..."` (unless you use `from __future__ import unicode_literals`).
Check if you're using Python 3.x when using py2exe.

