我想用这个字符替换这个字符"u '"
,"'"
我在谷歌上找到了解决方案。
我有这个版本的python:
user@ubuntu:/media/DATA/prototi/prototypefin4$ python --version
Python 2.7.4
我尝试替换和信息:
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'}
我想删除这个恐怖的u
由于我将此变量的内容打印jsondict
到文件中。因此没有这个比较好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
我哪里错了?