在Windows Server上运行时,出现“ unicode错误”,但在我的电脑上工作正常

时间:2018-12-14 19:09:08

标签: python python-3.x unicode

由于某些原因,当我在Windows Server 2016上运行python脚本时,收到错误df.sum %>% gather(stat, val) %>% separate(stat, into = c("var", "stat"), sep = "_") %>% spread(stat, val) %>% select(min, max, mean, first) # A tibble: 5 x 4 # min max mean first # <dbl> <dbl> <dbl> <dbl> #1 0.202 0.908 0.464 0.266 #2 0.0618 0.945 0.639 0.898 #3 0.177 0.770 0.445 0.206 #4 0.380 0.992 0.673 0.498 #5 0.126 0.935 0.438 0.935 df.sum %>% gather(stat, val) %>% separate(stat, into = c("var", "stat"), sep = "_") %>% spread(stat, val) %>% select(var, min, max, mean, first) # A tibble: 5 x 5 # var min max mean first # <chr> <dbl> <dbl> <dbl> <dbl> #1 X1Y 0.202 0.908 0.464 0.266 #2 X2Y 0.0618 0.945 0.639 0.898 #3 X3Y 0.177 0.770 0.445 0.206 #4 X4Y 0.380 0.992 0.673 0.498 #5 X5Y 0.126 0.935 0.438 0.935 。 在我的PC上,一切正常。

我用来执行程序的行:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

1 个答案:

答案 0 :(得分:1)

"c:\Users..."使用原始字符串。 \U在Python 3上开始Unicode转义序列,其中字符串是默认Unicode。

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