python中的转义问题,高手指点哈
例如:
ss = "E:\ALL\20100201_NEW\script\lib\core\core"
strs = ss.replace("\\", "/")
print strs
输出:
E:/ALL�0201_NEW/script/lib/core/core
它将"\2010" 变成"�"
再如:
ss = r"E:\ALL\20100201_NEW\script\lib\core\core"
这样没有问题,但是我现在路径是一个不确定的,也就是一个变量该如何做呢?
ss = "E:\\ALL\\20100201_NEW\\script\\lib\\core\\core"
LZ先看下默认编码是什么
Python code:
>>> import sys
>>> sys.getdefaultencoding()
'ascii'
>>> ss = "E:\ALL\20100201_NEW\script\lib\core\core"
>>> strs = ss.replace("\\", "/")
>>> strs
'E:/ALL\x8100201_NEW/script/lib/core/core'
再参考一下这个页面应该会有帮助
http://www.woodpecker.org.cn/diveintopython/xml_processing/unicode.html
期待完美解答~
作为变量输入是不需要转义的。。。。。
Python code:
Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more
相关问答:
请问下,我的是python2.5安装了PIL模块,然后编写程序打开本机上的一个图片时,为什么老出现错误呢,老是找不到图片,错误提示如下:File "C:\Python25\Lib\site-packages\PIL\Image.py", line 1888, in o ......
刚刚买了一本《Python核心编程》,开始学习python。大家多多指教
电子书就很多。。。
《Python核心编程》这书的第一版还是不错的,第二版很不咋的,真的。
个人的意见是:初学用《Dive in Python》, ......
python的PIL库自带的方法只能进行矩形的切割,如果我有了一个多边形各个顶点的坐标,如何对现有的图片按照这个多边形进行切割呢?
不一定要用PIL库,任何能实现这个功能的方法都行。
图片切割的js不是很多吗?
......
由于是初学,在些请教大家。
Python code:
from urllib import request
import struct
class csdn:
def __init__(self):
print ('Hello,this is a init')
def getContent(self,url) ......