Python: How to remove symbol in dict?
I get a xml response which is in bytes and parsed by xmltodict as shown below. Since I need to further use the response, I want to eliminate all the '@' in the key. I have tried two way to remove the sign but still not working. Are there any method to remove sign in dict?
XML response (resp.text): {'HOLDING_QUERY_RESPONSE': OrderedDict([('@LOGIN_ID', '011'), ('@CLIENT_ID', '011'), ('@CHANNEL', 'MB'), ('@SESSION_KEY', '111'), ('RESULT', OrderedDict([('@STATUS', 'OK'), ('BUYING_POWER', '98’),( 'USD_BUYING_POWER', '12'), ('AVAILABLE_MKT_VAL', '110'), ('CASH_HOLDING', OrderedDict([('LINEITEM', [OrderedDict([('@CURRENCY_CODE', 'USD'), ('@AVAILABLE_BAL', '-233'), ('@CASH_BALANCE', '0.00'), ('@CASH_ON_HOLD', '0.00'), ('@UNSETTLED_CASH', '0.00'), ('@ACCRUED_INTEREST', '0.00'), ('@BUY_SOLD_CONSIDERATION', '-233'), ('@EX_RATE', '1'), ('@AVAILABLE_VAL', '6'), ('@AMT', '0.00'), ('@DUE_AMT', '0.00')]),…….)])])]))]))])}
First tried method. The error is dict object has no attribute 'iteritems()'. If I remove the '.iteritem()', it will show Value Error: too many value to unpack.
info = {key.replace('@',''): item for key, item in xmltodict.parse(resp.text).iteritems()}
print(info)
Second tried method is changed it to string first and then translate it back to dict. But, still it seems the dict has not translate to string by json.dumps.
info = json.dumps(resp.text)
info.replace('@','')
to_dict = json.loads(info)
print(to_dict)
python json xml response
add a comment |
I get a xml response which is in bytes and parsed by xmltodict as shown below. Since I need to further use the response, I want to eliminate all the '@' in the key. I have tried two way to remove the sign but still not working. Are there any method to remove sign in dict?
XML response (resp.text): {'HOLDING_QUERY_RESPONSE': OrderedDict([('@LOGIN_ID', '011'), ('@CLIENT_ID', '011'), ('@CHANNEL', 'MB'), ('@SESSION_KEY', '111'), ('RESULT', OrderedDict([('@STATUS', 'OK'), ('BUYING_POWER', '98’),( 'USD_BUYING_POWER', '12'), ('AVAILABLE_MKT_VAL', '110'), ('CASH_HOLDING', OrderedDict([('LINEITEM', [OrderedDict([('@CURRENCY_CODE', 'USD'), ('@AVAILABLE_BAL', '-233'), ('@CASH_BALANCE', '0.00'), ('@CASH_ON_HOLD', '0.00'), ('@UNSETTLED_CASH', '0.00'), ('@ACCRUED_INTEREST', '0.00'), ('@BUY_SOLD_CONSIDERATION', '-233'), ('@EX_RATE', '1'), ('@AVAILABLE_VAL', '6'), ('@AMT', '0.00'), ('@DUE_AMT', '0.00')]),…….)])])]))]))])}
First tried method. The error is dict object has no attribute 'iteritems()'. If I remove the '.iteritem()', it will show Value Error: too many value to unpack.
info = {key.replace('@',''): item for key, item in xmltodict.parse(resp.text).iteritems()}
print(info)
Second tried method is changed it to string first and then translate it back to dict. But, still it seems the dict has not translate to string by json.dumps.
info = json.dumps(resp.text)
info.replace('@','')
to_dict = json.loads(info)
print(to_dict)
python json xml response
2
Try.items()
instead of.iteritems()
. You might be using Python 3.
– Austin
Nov 24 '18 at 3:53
Thanks for your reply, Austin. I tried this before, but still showing dict object has no item() attribute.
– WILLIAM
Nov 24 '18 at 5:48
it'sitems()
.
– Austin
Nov 24 '18 at 5:49
info.replace('@','')
returns a new string, which you're ignoring, by the way
– cricket_007
Nov 25 '18 at 1:31
add a comment |
I get a xml response which is in bytes and parsed by xmltodict as shown below. Since I need to further use the response, I want to eliminate all the '@' in the key. I have tried two way to remove the sign but still not working. Are there any method to remove sign in dict?
XML response (resp.text): {'HOLDING_QUERY_RESPONSE': OrderedDict([('@LOGIN_ID', '011'), ('@CLIENT_ID', '011'), ('@CHANNEL', 'MB'), ('@SESSION_KEY', '111'), ('RESULT', OrderedDict([('@STATUS', 'OK'), ('BUYING_POWER', '98’),( 'USD_BUYING_POWER', '12'), ('AVAILABLE_MKT_VAL', '110'), ('CASH_HOLDING', OrderedDict([('LINEITEM', [OrderedDict([('@CURRENCY_CODE', 'USD'), ('@AVAILABLE_BAL', '-233'), ('@CASH_BALANCE', '0.00'), ('@CASH_ON_HOLD', '0.00'), ('@UNSETTLED_CASH', '0.00'), ('@ACCRUED_INTEREST', '0.00'), ('@BUY_SOLD_CONSIDERATION', '-233'), ('@EX_RATE', '1'), ('@AVAILABLE_VAL', '6'), ('@AMT', '0.00'), ('@DUE_AMT', '0.00')]),…….)])])]))]))])}
First tried method. The error is dict object has no attribute 'iteritems()'. If I remove the '.iteritem()', it will show Value Error: too many value to unpack.
info = {key.replace('@',''): item for key, item in xmltodict.parse(resp.text).iteritems()}
print(info)
Second tried method is changed it to string first and then translate it back to dict. But, still it seems the dict has not translate to string by json.dumps.
info = json.dumps(resp.text)
info.replace('@','')
to_dict = json.loads(info)
print(to_dict)
python json xml response
I get a xml response which is in bytes and parsed by xmltodict as shown below. Since I need to further use the response, I want to eliminate all the '@' in the key. I have tried two way to remove the sign but still not working. Are there any method to remove sign in dict?
XML response (resp.text): {'HOLDING_QUERY_RESPONSE': OrderedDict([('@LOGIN_ID', '011'), ('@CLIENT_ID', '011'), ('@CHANNEL', 'MB'), ('@SESSION_KEY', '111'), ('RESULT', OrderedDict([('@STATUS', 'OK'), ('BUYING_POWER', '98’),( 'USD_BUYING_POWER', '12'), ('AVAILABLE_MKT_VAL', '110'), ('CASH_HOLDING', OrderedDict([('LINEITEM', [OrderedDict([('@CURRENCY_CODE', 'USD'), ('@AVAILABLE_BAL', '-233'), ('@CASH_BALANCE', '0.00'), ('@CASH_ON_HOLD', '0.00'), ('@UNSETTLED_CASH', '0.00'), ('@ACCRUED_INTEREST', '0.00'), ('@BUY_SOLD_CONSIDERATION', '-233'), ('@EX_RATE', '1'), ('@AVAILABLE_VAL', '6'), ('@AMT', '0.00'), ('@DUE_AMT', '0.00')]),…….)])])]))]))])}
First tried method. The error is dict object has no attribute 'iteritems()'. If I remove the '.iteritem()', it will show Value Error: too many value to unpack.
info = {key.replace('@',''): item for key, item in xmltodict.parse(resp.text).iteritems()}
print(info)
Second tried method is changed it to string first and then translate it back to dict. But, still it seems the dict has not translate to string by json.dumps.
info = json.dumps(resp.text)
info.replace('@','')
to_dict = json.loads(info)
print(to_dict)
python json xml response
python json xml response
edited Nov 25 '18 at 1:19
WILLIAM
asked Nov 24 '18 at 3:51
WILLIAMWILLIAM
475
475
2
Try.items()
instead of.iteritems()
. You might be using Python 3.
– Austin
Nov 24 '18 at 3:53
Thanks for your reply, Austin. I tried this before, but still showing dict object has no item() attribute.
– WILLIAM
Nov 24 '18 at 5:48
it'sitems()
.
– Austin
Nov 24 '18 at 5:49
info.replace('@','')
returns a new string, which you're ignoring, by the way
– cricket_007
Nov 25 '18 at 1:31
add a comment |
2
Try.items()
instead of.iteritems()
. You might be using Python 3.
– Austin
Nov 24 '18 at 3:53
Thanks for your reply, Austin. I tried this before, but still showing dict object has no item() attribute.
– WILLIAM
Nov 24 '18 at 5:48
it'sitems()
.
– Austin
Nov 24 '18 at 5:49
info.replace('@','')
returns a new string, which you're ignoring, by the way
– cricket_007
Nov 25 '18 at 1:31
2
2
Try
.items()
instead of .iteritems()
. You might be using Python 3.– Austin
Nov 24 '18 at 3:53
Try
.items()
instead of .iteritems()
. You might be using Python 3.– Austin
Nov 24 '18 at 3:53
Thanks for your reply, Austin. I tried this before, but still showing dict object has no item() attribute.
– WILLIAM
Nov 24 '18 at 5:48
Thanks for your reply, Austin. I tried this before, but still showing dict object has no item() attribute.
– WILLIAM
Nov 24 '18 at 5:48
it's
items()
.– Austin
Nov 24 '18 at 5:49
it's
items()
.– Austin
Nov 24 '18 at 5:49
info.replace('@','')
returns a new string, which you're ignoring, by the way– cricket_007
Nov 25 '18 at 1:31
info.replace('@','')
returns a new string, which you're ignoring, by the way– cricket_007
Nov 25 '18 at 1:31
add a comment |
1 Answer
1
active
oldest
votes
Try this:
info = {key.replace('@',''): item for key, item in xmltodict.parse(resp.text).items()}
print(info)
As mentioned in the comments, xmltodict.parse
returns a dictionary, and in your case, you might be working with Python 3, so use the .items()
attribute to access the dictionary.
As an example:
d = ('@CASH', '0.00'), ('@INTEREST', '0.00'), ('@BUY', '-233'), ('@RATE', '1.000000'), ('@AVAILABLE', '6,228'), ('@AMT', '0.00')
info = {key.replace('@',''): item for key, item in d}
print(info)
>>
{'CASH': '0.00', 'INTEREST': '0.00', 'BUY': '-233', 'RATE': '1.000000', 'AVAILABLE': '6,228', 'AMT': '0.00'}
Updated question soution
Similarly, if it is a nested dictionary, you have to access the key you want to replace @
in its values, from your updated example, you should be able to access the nested dictionary with xmltodict.parse(resp.text)['HOLDING_QUERY_RESPONSE']
.
from collections import OrderedDict
#based on your updated data structure
d = OrderedDict([('@CASH', '0.00'), ('@INTEREST', '0.00'), ('@BUY', '-233'), ('@RATE', '1.000000'), ('@AVAILABLE', '6,228'), ('@AMT', '0.00')])
xml_response = {}
xml_response['HOLDING_QUERY_RESPONSE'] = d
xml_response
{'HOLDING_QUERY_RESPONSE': OrderedDict([('@CASH', '0.00'),
('@INTEREST', '0.00'),
('@BUY', '-233'),
('@RATE', '1.000000'),
('@AVAILABLE', '6,228'),
('@AMT', '0.00')])}
info = {key.replace('@',''):value for key, value in xml_response['HOLDING_QUERY_RESPONSE'].items()}
print(info)
Thanks, now the error is gone, but I found that the @ sign is still there.
– WILLIAM
Nov 24 '18 at 13:39
I added an example, it should work and its pretty straightforward. Are you accessing the right variables?
– BernardL
Nov 24 '18 at 16:13
I also edited the resp.text. Actually the dict is like this and have many layer. Does it affect the result of simply using the above code?
– WILLIAM
Nov 25 '18 at 1:21
@WILL this only works on the top level keys of the dictionary
– cricket_007
Nov 25 '18 at 1:30
I edited my answer based on the update, if any of the answers here solved your problem, kindly accept the best one as your answer.
– BernardL
Nov 25 '18 at 2:07
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455011%2fpython-how-to-remove-symbol-in-dict%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this:
info = {key.replace('@',''): item for key, item in xmltodict.parse(resp.text).items()}
print(info)
As mentioned in the comments, xmltodict.parse
returns a dictionary, and in your case, you might be working with Python 3, so use the .items()
attribute to access the dictionary.
As an example:
d = ('@CASH', '0.00'), ('@INTEREST', '0.00'), ('@BUY', '-233'), ('@RATE', '1.000000'), ('@AVAILABLE', '6,228'), ('@AMT', '0.00')
info = {key.replace('@',''): item for key, item in d}
print(info)
>>
{'CASH': '0.00', 'INTEREST': '0.00', 'BUY': '-233', 'RATE': '1.000000', 'AVAILABLE': '6,228', 'AMT': '0.00'}
Updated question soution
Similarly, if it is a nested dictionary, you have to access the key you want to replace @
in its values, from your updated example, you should be able to access the nested dictionary with xmltodict.parse(resp.text)['HOLDING_QUERY_RESPONSE']
.
from collections import OrderedDict
#based on your updated data structure
d = OrderedDict([('@CASH', '0.00'), ('@INTEREST', '0.00'), ('@BUY', '-233'), ('@RATE', '1.000000'), ('@AVAILABLE', '6,228'), ('@AMT', '0.00')])
xml_response = {}
xml_response['HOLDING_QUERY_RESPONSE'] = d
xml_response
{'HOLDING_QUERY_RESPONSE': OrderedDict([('@CASH', '0.00'),
('@INTEREST', '0.00'),
('@BUY', '-233'),
('@RATE', '1.000000'),
('@AVAILABLE', '6,228'),
('@AMT', '0.00')])}
info = {key.replace('@',''):value for key, value in xml_response['HOLDING_QUERY_RESPONSE'].items()}
print(info)
Thanks, now the error is gone, but I found that the @ sign is still there.
– WILLIAM
Nov 24 '18 at 13:39
I added an example, it should work and its pretty straightforward. Are you accessing the right variables?
– BernardL
Nov 24 '18 at 16:13
I also edited the resp.text. Actually the dict is like this and have many layer. Does it affect the result of simply using the above code?
– WILLIAM
Nov 25 '18 at 1:21
@WILL this only works on the top level keys of the dictionary
– cricket_007
Nov 25 '18 at 1:30
I edited my answer based on the update, if any of the answers here solved your problem, kindly accept the best one as your answer.
– BernardL
Nov 25 '18 at 2:07
|
show 1 more comment
Try this:
info = {key.replace('@',''): item for key, item in xmltodict.parse(resp.text).items()}
print(info)
As mentioned in the comments, xmltodict.parse
returns a dictionary, and in your case, you might be working with Python 3, so use the .items()
attribute to access the dictionary.
As an example:
d = ('@CASH', '0.00'), ('@INTEREST', '0.00'), ('@BUY', '-233'), ('@RATE', '1.000000'), ('@AVAILABLE', '6,228'), ('@AMT', '0.00')
info = {key.replace('@',''): item for key, item in d}
print(info)
>>
{'CASH': '0.00', 'INTEREST': '0.00', 'BUY': '-233', 'RATE': '1.000000', 'AVAILABLE': '6,228', 'AMT': '0.00'}
Updated question soution
Similarly, if it is a nested dictionary, you have to access the key you want to replace @
in its values, from your updated example, you should be able to access the nested dictionary with xmltodict.parse(resp.text)['HOLDING_QUERY_RESPONSE']
.
from collections import OrderedDict
#based on your updated data structure
d = OrderedDict([('@CASH', '0.00'), ('@INTEREST', '0.00'), ('@BUY', '-233'), ('@RATE', '1.000000'), ('@AVAILABLE', '6,228'), ('@AMT', '0.00')])
xml_response = {}
xml_response['HOLDING_QUERY_RESPONSE'] = d
xml_response
{'HOLDING_QUERY_RESPONSE': OrderedDict([('@CASH', '0.00'),
('@INTEREST', '0.00'),
('@BUY', '-233'),
('@RATE', '1.000000'),
('@AVAILABLE', '6,228'),
('@AMT', '0.00')])}
info = {key.replace('@',''):value for key, value in xml_response['HOLDING_QUERY_RESPONSE'].items()}
print(info)
Thanks, now the error is gone, but I found that the @ sign is still there.
– WILLIAM
Nov 24 '18 at 13:39
I added an example, it should work and its pretty straightforward. Are you accessing the right variables?
– BernardL
Nov 24 '18 at 16:13
I also edited the resp.text. Actually the dict is like this and have many layer. Does it affect the result of simply using the above code?
– WILLIAM
Nov 25 '18 at 1:21
@WILL this only works on the top level keys of the dictionary
– cricket_007
Nov 25 '18 at 1:30
I edited my answer based on the update, if any of the answers here solved your problem, kindly accept the best one as your answer.
– BernardL
Nov 25 '18 at 2:07
|
show 1 more comment
Try this:
info = {key.replace('@',''): item for key, item in xmltodict.parse(resp.text).items()}
print(info)
As mentioned in the comments, xmltodict.parse
returns a dictionary, and in your case, you might be working with Python 3, so use the .items()
attribute to access the dictionary.
As an example:
d = ('@CASH', '0.00'), ('@INTEREST', '0.00'), ('@BUY', '-233'), ('@RATE', '1.000000'), ('@AVAILABLE', '6,228'), ('@AMT', '0.00')
info = {key.replace('@',''): item for key, item in d}
print(info)
>>
{'CASH': '0.00', 'INTEREST': '0.00', 'BUY': '-233', 'RATE': '1.000000', 'AVAILABLE': '6,228', 'AMT': '0.00'}
Updated question soution
Similarly, if it is a nested dictionary, you have to access the key you want to replace @
in its values, from your updated example, you should be able to access the nested dictionary with xmltodict.parse(resp.text)['HOLDING_QUERY_RESPONSE']
.
from collections import OrderedDict
#based on your updated data structure
d = OrderedDict([('@CASH', '0.00'), ('@INTEREST', '0.00'), ('@BUY', '-233'), ('@RATE', '1.000000'), ('@AVAILABLE', '6,228'), ('@AMT', '0.00')])
xml_response = {}
xml_response['HOLDING_QUERY_RESPONSE'] = d
xml_response
{'HOLDING_QUERY_RESPONSE': OrderedDict([('@CASH', '0.00'),
('@INTEREST', '0.00'),
('@BUY', '-233'),
('@RATE', '1.000000'),
('@AVAILABLE', '6,228'),
('@AMT', '0.00')])}
info = {key.replace('@',''):value for key, value in xml_response['HOLDING_QUERY_RESPONSE'].items()}
print(info)
Try this:
info = {key.replace('@',''): item for key, item in xmltodict.parse(resp.text).items()}
print(info)
As mentioned in the comments, xmltodict.parse
returns a dictionary, and in your case, you might be working with Python 3, so use the .items()
attribute to access the dictionary.
As an example:
d = ('@CASH', '0.00'), ('@INTEREST', '0.00'), ('@BUY', '-233'), ('@RATE', '1.000000'), ('@AVAILABLE', '6,228'), ('@AMT', '0.00')
info = {key.replace('@',''): item for key, item in d}
print(info)
>>
{'CASH': '0.00', 'INTEREST': '0.00', 'BUY': '-233', 'RATE': '1.000000', 'AVAILABLE': '6,228', 'AMT': '0.00'}
Updated question soution
Similarly, if it is a nested dictionary, you have to access the key you want to replace @
in its values, from your updated example, you should be able to access the nested dictionary with xmltodict.parse(resp.text)['HOLDING_QUERY_RESPONSE']
.
from collections import OrderedDict
#based on your updated data structure
d = OrderedDict([('@CASH', '0.00'), ('@INTEREST', '0.00'), ('@BUY', '-233'), ('@RATE', '1.000000'), ('@AVAILABLE', '6,228'), ('@AMT', '0.00')])
xml_response = {}
xml_response['HOLDING_QUERY_RESPONSE'] = d
xml_response
{'HOLDING_QUERY_RESPONSE': OrderedDict([('@CASH', '0.00'),
('@INTEREST', '0.00'),
('@BUY', '-233'),
('@RATE', '1.000000'),
('@AVAILABLE', '6,228'),
('@AMT', '0.00')])}
info = {key.replace('@',''):value for key, value in xml_response['HOLDING_QUERY_RESPONSE'].items()}
print(info)
edited Nov 25 '18 at 2:06
answered Nov 24 '18 at 6:09
BernardLBernardL
2,37311130
2,37311130
Thanks, now the error is gone, but I found that the @ sign is still there.
– WILLIAM
Nov 24 '18 at 13:39
I added an example, it should work and its pretty straightforward. Are you accessing the right variables?
– BernardL
Nov 24 '18 at 16:13
I also edited the resp.text. Actually the dict is like this and have many layer. Does it affect the result of simply using the above code?
– WILLIAM
Nov 25 '18 at 1:21
@WILL this only works on the top level keys of the dictionary
– cricket_007
Nov 25 '18 at 1:30
I edited my answer based on the update, if any of the answers here solved your problem, kindly accept the best one as your answer.
– BernardL
Nov 25 '18 at 2:07
|
show 1 more comment
Thanks, now the error is gone, but I found that the @ sign is still there.
– WILLIAM
Nov 24 '18 at 13:39
I added an example, it should work and its pretty straightforward. Are you accessing the right variables?
– BernardL
Nov 24 '18 at 16:13
I also edited the resp.text. Actually the dict is like this and have many layer. Does it affect the result of simply using the above code?
– WILLIAM
Nov 25 '18 at 1:21
@WILL this only works on the top level keys of the dictionary
– cricket_007
Nov 25 '18 at 1:30
I edited my answer based on the update, if any of the answers here solved your problem, kindly accept the best one as your answer.
– BernardL
Nov 25 '18 at 2:07
Thanks, now the error is gone, but I found that the @ sign is still there.
– WILLIAM
Nov 24 '18 at 13:39
Thanks, now the error is gone, but I found that the @ sign is still there.
– WILLIAM
Nov 24 '18 at 13:39
I added an example, it should work and its pretty straightforward. Are you accessing the right variables?
– BernardL
Nov 24 '18 at 16:13
I added an example, it should work and its pretty straightforward. Are you accessing the right variables?
– BernardL
Nov 24 '18 at 16:13
I also edited the resp.text. Actually the dict is like this and have many layer. Does it affect the result of simply using the above code?
– WILLIAM
Nov 25 '18 at 1:21
I also edited the resp.text. Actually the dict is like this and have many layer. Does it affect the result of simply using the above code?
– WILLIAM
Nov 25 '18 at 1:21
@WILL this only works on the top level keys of the dictionary
– cricket_007
Nov 25 '18 at 1:30
@WILL this only works on the top level keys of the dictionary
– cricket_007
Nov 25 '18 at 1:30
I edited my answer based on the update, if any of the answers here solved your problem, kindly accept the best one as your answer.
– BernardL
Nov 25 '18 at 2:07
I edited my answer based on the update, if any of the answers here solved your problem, kindly accept the best one as your answer.
– BernardL
Nov 25 '18 at 2:07
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455011%2fpython-how-to-remove-symbol-in-dict%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Try
.items()
instead of.iteritems()
. You might be using Python 3.– Austin
Nov 24 '18 at 3:53
Thanks for your reply, Austin. I tried this before, but still showing dict object has no item() attribute.
– WILLIAM
Nov 24 '18 at 5:48
it's
items()
.– Austin
Nov 24 '18 at 5:49
info.replace('@','')
returns a new string, which you're ignoring, by the way– cricket_007
Nov 25 '18 at 1:31