简体   繁体   中英

Python print without unicode character

How can I get rid of the unicode character u when printing. I am using 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 ] ) :

/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

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. Also, for printing stuff out normally, you would probably use print rather than pprint.

The newline character is \\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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM