开发者

invalid \x escape Module has no __module_name__ defined

开发者 https://www.devze.com 2023-04-07 00:59 出处:网络
when loading the following (or any python script for xchat version 2.8.9 on 64 bit windows 7): __module_name__ = \"test.py\"

when loading the following (or any python script for xchat version 2.8.9 on 64 bit windows 7):

__module_name__ = "test.py"
__module_version__ = "0.666"
__module_description__ = "I AM AN EXPERT PROGRAMMER"

import xchat, random, string, re

def test(word, word_eol, userdata):
    cmd = word[1]
    text = open("E:\\xpy\\nickslol.txt","r")
    for line in text:
        line =开发者_如何学Python line.rstrip("\r\n")
        xchat.command("%s %s" % (cmd, line))
xchat.hook_command("test", test)
[02:31:14]  ValueError: invalid \x escape
[02:31:14]  Module has no __module_name__ defined


Use raw strings for windows pathnames: r"E:\xpy\nickslol.txt"


It appears to be an error within xchat. The script works in the C drive, but not in subfolders.

IOError: [Errno 2] No such file or directory: 'C:\test\\startup.py'

Either the single or double backslash should not be there, depending on interpretation. They should definitely be consistent!


I recently came across this error. I'm far from an expert programmer, but I realized the problem is the \x in the string.

in python 2.7 (only version I tested)

x = 'C:\Users\xfolder\Desktop' # will give an "invalid \x escape"

x = 'C:\Users\\xfolder\Desktop' # will work properly (notice the stored value after)

I wish I could expand, but hopefully this is somewhat helpful.

0

精彩评论

暂无评论...
验证码 换一张
取 消