我想用"'"
替換字符"u '"
,我在google上找到了解決方案。如何刪除u表示字符串是unicode
我這個版本的Python:
[email protected]:/media/DATA/prototi/prototypefin4$ python --version
Python 2.7.4
我嘗試更換和info:
strg = jsondict.replace("u'", "'")
print "\n\n\n\n\n\n\n\n\n\n\n"
print strg
print "\n\n\n\n\n\n\n"
而且我在CherryPy的服務器我有這樣的錯誤:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py", line 34, in __call__
return self.callable(*self.args, **self.kwargs)
File "web_editormy.py", line 585, in save_demo
strg = jsondict.replace("u'", "'")
AttributeError: 'dict' object has no attribute 'replace'
這是變量jsondict:
{u'demo_title': u'Demo title', u'proc1_script': u'script.sh parameters', u'inputp3_id': u'pepepe', u'outputp2_value': u'boh', u'demo_input_description': u'hola mundo', u'titleimg3': u'Gardens', u'outputp4_visible': u'on'}
而且我想既然我打印此變量的內容jsondict
到要刪除的文件的u
這個恐怖。 因此更令人欣慰的是,沒有這個u
爲什麼不能使用替換?
想念python的圖書館嗎?
這些都是我裝
# -*- coding: utf-8 -*-
import urllib
import hashlib
from datetime import datetime
from random import random
#################################################
import json
from StringIO import StringIO
import re
#################################################
from mako.template import Template
from mako.lookup import TemplateLookup
from mako.exceptions import RichTraceback
#################################################
import os, shutil
from lib import index_dict, http_redirect_303
import zipfile
import sys
######################3
import cherrypy
from cherrypy.lib.static import serve_file
from config import file_dict
我哪裏錯了?
'jsondict'是一本字典不是字符串 – TerryA
確定..還有一種可能性替換字符,因爲我不喜歡字符'u'' – user2559131
'u'不是字符串中的字符,'u'表示字符串是unicode。你是什麼意思,你不喜歡它? –