[英]Python print without unicode character
How can I get rid of the unicode character u
when printing. 打印时如何摆脱Unicode字符
u
。 I am using python-2.6.6. 我正在使用python-2.6.6。 Using command :
使用命令:
pprint(complexdict["key1"][n]["subkey"][0].values())
and it prints something like the follwing : 它打印出如下内容:
[u'/data/dirA/myDir/NameofTheFile_1.tgz']
[u'/data/dirA/myDir/NameofTheFile_2.tgz']
[u'/data/dirA/myDir/NameofTheFile_3.tgz']
I am looking for a print out like this ( stripping out [u'
and ]
) : 我正在寻找这样的打印输出(去掉
[u'
和]
):
/data/dirA/myDir/NameofTheFile_1.tgz
/data/dirA/myDir/NameofTheFile_2.tgz
/data/dirA/myDir/NameofTheFile_3.tgz
Thanks for any suggestions... 感谢您的任何建议...
EDIT.... 编辑....
With the following, it works... 通过以下操作,它可以...
print complexdict["key1"][n]["subkey"][0].values()[0]
dict.values()
returns a list of values ... in this case there is only one so its dict.values()
返回值列表...在这种情况下,只有一个值,因此其
print complexdict["key1"][n]["subkey"][0].values()[0] #get first value ...
you can see this easily as 你可以很容易地看到
>>> some_item = [u'/data/dirA/myDir/NameofTheFile_1.tgz']
>>> print some_item
[u'/data/dirA/myDir/NameofTheFile_1.tgz']
>>> print some_item[0]
/data/dirA/myDir/NameofTheFile_1.tgz
If you want to print a list(*), with something of your choosing between the items, you would use join. 如果要打印列表(*),并在项目之间进行选择,则可以使用join。 Also, for printing stuff out normally, you would probably use print rather than pprint.
另外,为了正常打印出东西,您可能会使用print而不是pprint。
The newline character is \\n
. 换行符为
\\n
。 You might use something like: 您可能会使用类似:
print "\n".join(complexdict["key1"][n]["subkey"][0].values())
(*) complexdict["key1"][n]["subkey"][0]
is presumably a dict, so complexdict["key1"][n]["subkey"][0].values()
will return a list. (*)
complexdict["key1"][n]["subkey"][0]
可能是字典,因此complexdict["key1"][n]["subkey"][0].values()
将返回名单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.