Reputation: 11479
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]
Upvotes: 0
Views: 447
Reputation: 114038
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
Upvotes: 1
Reputation: 5919
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.
Upvotes: 0