Don't understand why this TypeError: can only concatenate list (not “dict”) to list started occurring
I've used this code to help delete mass messages, but now for some reason it's not working.
Delete all messages from specific channel:
Traceback (most recent call last):
File "C:UserstestOneDriveDocumentsmass.py", line 33, in <module>
delete_all(auth_token, channel_id, username1, username2, get_all_messages(auth_token, channel_id))
File "C:UserstestOneDriveDocumentsmass.py", line 16, in get_all_messages
prev = prev + messages
TypeError: can only concatenate list (not "dict") to list
Code:
import json, requests, sys
print ("Delete all messages from specific channel")
username1 = "test"
username2 = "test#0001"
auth_token = "RWYFHyrtYRY.RYYR_jqj114452E"
channel_id = "345634345364"
delete_from_all_users = "False"
def get_all_messages(auth, id, last="", prev=):
if not last:
messages = json.loads(requests.get("http://canary.discordapp.com/api/v6/channels/" + id + "/messages", headers={"authorization": auth}, params={"limit": 100}).content)
else:
messages = json.loads(requests.get("http://canary.discordapp.com/api/v6/channels/" + id + "/messages", headers={"authorization": auth}, params={"before" : last, "limit" : 100}).content)
prev = prev + messages
if len(messages) < 100:
print ("Got to end of channel at " + str(len(prev)) + " messages")
return prev
else:
oldest = sorted(messages, key=lambda x: x["timestamp"], reverse=True)[-1]
return get_all_messages(auth, id, last=oldest["id"], prev=prev)
def delete_all(auth, id, user1, user2, messages):
print ("Trying to delete all messages in " + id + " from username " + user1)
for message in messages:
# print(message["author"]["username"])
if (message["author"]["username"] == user1):
requests.delete("http://canary.discordapp.com/api/v6/channels/" + id + "/messages/" + message["id"],headers={"authorization": auth})
print ("All messages were deleted")
delete_all(auth_token, channel_id, username1, username2, get_all_messages(auth_token, channel_id))
I'm not sure what changed. The script worked. I ran it again a month later, got this error.
python
add a comment |
I've used this code to help delete mass messages, but now for some reason it's not working.
Delete all messages from specific channel:
Traceback (most recent call last):
File "C:UserstestOneDriveDocumentsmass.py", line 33, in <module>
delete_all(auth_token, channel_id, username1, username2, get_all_messages(auth_token, channel_id))
File "C:UserstestOneDriveDocumentsmass.py", line 16, in get_all_messages
prev = prev + messages
TypeError: can only concatenate list (not "dict") to list
Code:
import json, requests, sys
print ("Delete all messages from specific channel")
username1 = "test"
username2 = "test#0001"
auth_token = "RWYFHyrtYRY.RYYR_jqj114452E"
channel_id = "345634345364"
delete_from_all_users = "False"
def get_all_messages(auth, id, last="", prev=):
if not last:
messages = json.loads(requests.get("http://canary.discordapp.com/api/v6/channels/" + id + "/messages", headers={"authorization": auth}, params={"limit": 100}).content)
else:
messages = json.loads(requests.get("http://canary.discordapp.com/api/v6/channels/" + id + "/messages", headers={"authorization": auth}, params={"before" : last, "limit" : 100}).content)
prev = prev + messages
if len(messages) < 100:
print ("Got to end of channel at " + str(len(prev)) + " messages")
return prev
else:
oldest = sorted(messages, key=lambda x: x["timestamp"], reverse=True)[-1]
return get_all_messages(auth, id, last=oldest["id"], prev=prev)
def delete_all(auth, id, user1, user2, messages):
print ("Trying to delete all messages in " + id + " from username " + user1)
for message in messages:
# print(message["author"]["username"])
if (message["author"]["username"] == user1):
requests.delete("http://canary.discordapp.com/api/v6/channels/" + id + "/messages/" + message["id"],headers={"authorization": auth})
print ("All messages were deleted")
delete_all(auth_token, channel_id, username1, username2, get_all_messages(auth_token, channel_id))
I'm not sure what changed. The script worked. I ran it again a month later, got this error.
python
The JSON endpoint must be returning a single JS object (translated to a python dict) rather than a JS array (translated to a python list)
– Aaron
Dec 30 '18 at 5:33
I'm actually quite new with this code. Would you be able to show an example?
– Kelsey Maria
Dec 30 '18 at 5:38
2
Quick note for the future -- use the{}
button, not the StackSnippet button, unless you're trying to generate an example that can be run in the browser (which is to say, snippets are only for HTML/JavaScript/CSS questions).
– Charles Duffy
Dec 30 '18 at 5:41
1
Side note: don't setprev
like this,def get_all_messages(auth, id, last="", prev=):
, as it evaluates the empty list once during the definition of the function. After that, the list will be non-empty on subsequent calls.
– torek
Dec 30 '18 at 5:45
BTW, you might want to inspect the output to see why it's no longer a list -- good chance you'd need to change other code too if the wire format was updated.
– Charles Duffy
Dec 30 '18 at 17:50
add a comment |
I've used this code to help delete mass messages, but now for some reason it's not working.
Delete all messages from specific channel:
Traceback (most recent call last):
File "C:UserstestOneDriveDocumentsmass.py", line 33, in <module>
delete_all(auth_token, channel_id, username1, username2, get_all_messages(auth_token, channel_id))
File "C:UserstestOneDriveDocumentsmass.py", line 16, in get_all_messages
prev = prev + messages
TypeError: can only concatenate list (not "dict") to list
Code:
import json, requests, sys
print ("Delete all messages from specific channel")
username1 = "test"
username2 = "test#0001"
auth_token = "RWYFHyrtYRY.RYYR_jqj114452E"
channel_id = "345634345364"
delete_from_all_users = "False"
def get_all_messages(auth, id, last="", prev=):
if not last:
messages = json.loads(requests.get("http://canary.discordapp.com/api/v6/channels/" + id + "/messages", headers={"authorization": auth}, params={"limit": 100}).content)
else:
messages = json.loads(requests.get("http://canary.discordapp.com/api/v6/channels/" + id + "/messages", headers={"authorization": auth}, params={"before" : last, "limit" : 100}).content)
prev = prev + messages
if len(messages) < 100:
print ("Got to end of channel at " + str(len(prev)) + " messages")
return prev
else:
oldest = sorted(messages, key=lambda x: x["timestamp"], reverse=True)[-1]
return get_all_messages(auth, id, last=oldest["id"], prev=prev)
def delete_all(auth, id, user1, user2, messages):
print ("Trying to delete all messages in " + id + " from username " + user1)
for message in messages:
# print(message["author"]["username"])
if (message["author"]["username"] == user1):
requests.delete("http://canary.discordapp.com/api/v6/channels/" + id + "/messages/" + message["id"],headers={"authorization": auth})
print ("All messages were deleted")
delete_all(auth_token, channel_id, username1, username2, get_all_messages(auth_token, channel_id))
I'm not sure what changed. The script worked. I ran it again a month later, got this error.
python
I've used this code to help delete mass messages, but now for some reason it's not working.
Delete all messages from specific channel:
Traceback (most recent call last):
File "C:UserstestOneDriveDocumentsmass.py", line 33, in <module>
delete_all(auth_token, channel_id, username1, username2, get_all_messages(auth_token, channel_id))
File "C:UserstestOneDriveDocumentsmass.py", line 16, in get_all_messages
prev = prev + messages
TypeError: can only concatenate list (not "dict") to list
Code:
import json, requests, sys
print ("Delete all messages from specific channel")
username1 = "test"
username2 = "test#0001"
auth_token = "RWYFHyrtYRY.RYYR_jqj114452E"
channel_id = "345634345364"
delete_from_all_users = "False"
def get_all_messages(auth, id, last="", prev=):
if not last:
messages = json.loads(requests.get("http://canary.discordapp.com/api/v6/channels/" + id + "/messages", headers={"authorization": auth}, params={"limit": 100}).content)
else:
messages = json.loads(requests.get("http://canary.discordapp.com/api/v6/channels/" + id + "/messages", headers={"authorization": auth}, params={"before" : last, "limit" : 100}).content)
prev = prev + messages
if len(messages) < 100:
print ("Got to end of channel at " + str(len(prev)) + " messages")
return prev
else:
oldest = sorted(messages, key=lambda x: x["timestamp"], reverse=True)[-1]
return get_all_messages(auth, id, last=oldest["id"], prev=prev)
def delete_all(auth, id, user1, user2, messages):
print ("Trying to delete all messages in " + id + " from username " + user1)
for message in messages:
# print(message["author"]["username"])
if (message["author"]["username"] == user1):
requests.delete("http://canary.discordapp.com/api/v6/channels/" + id + "/messages/" + message["id"],headers={"authorization": auth})
print ("All messages were deleted")
delete_all(auth_token, channel_id, username1, username2, get_all_messages(auth_token, channel_id))
I'm not sure what changed. The script worked. I ran it again a month later, got this error.
python
python
edited Dec 30 '18 at 9:39
martineau
67k989180
67k989180
asked Dec 30 '18 at 5:31
Kelsey MariaKelsey Maria
235
235
The JSON endpoint must be returning a single JS object (translated to a python dict) rather than a JS array (translated to a python list)
– Aaron
Dec 30 '18 at 5:33
I'm actually quite new with this code. Would you be able to show an example?
– Kelsey Maria
Dec 30 '18 at 5:38
2
Quick note for the future -- use the{}
button, not the StackSnippet button, unless you're trying to generate an example that can be run in the browser (which is to say, snippets are only for HTML/JavaScript/CSS questions).
– Charles Duffy
Dec 30 '18 at 5:41
1
Side note: don't setprev
like this,def get_all_messages(auth, id, last="", prev=):
, as it evaluates the empty list once during the definition of the function. After that, the list will be non-empty on subsequent calls.
– torek
Dec 30 '18 at 5:45
BTW, you might want to inspect the output to see why it's no longer a list -- good chance you'd need to change other code too if the wire format was updated.
– Charles Duffy
Dec 30 '18 at 17:50
add a comment |
The JSON endpoint must be returning a single JS object (translated to a python dict) rather than a JS array (translated to a python list)
– Aaron
Dec 30 '18 at 5:33
I'm actually quite new with this code. Would you be able to show an example?
– Kelsey Maria
Dec 30 '18 at 5:38
2
Quick note for the future -- use the{}
button, not the StackSnippet button, unless you're trying to generate an example that can be run in the browser (which is to say, snippets are only for HTML/JavaScript/CSS questions).
– Charles Duffy
Dec 30 '18 at 5:41
1
Side note: don't setprev
like this,def get_all_messages(auth, id, last="", prev=):
, as it evaluates the empty list once during the definition of the function. After that, the list will be non-empty on subsequent calls.
– torek
Dec 30 '18 at 5:45
BTW, you might want to inspect the output to see why it's no longer a list -- good chance you'd need to change other code too if the wire format was updated.
– Charles Duffy
Dec 30 '18 at 17:50
The JSON endpoint must be returning a single JS object (translated to a python dict) rather than a JS array (translated to a python list)
– Aaron
Dec 30 '18 at 5:33
The JSON endpoint must be returning a single JS object (translated to a python dict) rather than a JS array (translated to a python list)
– Aaron
Dec 30 '18 at 5:33
I'm actually quite new with this code. Would you be able to show an example?
– Kelsey Maria
Dec 30 '18 at 5:38
I'm actually quite new with this code. Would you be able to show an example?
– Kelsey Maria
Dec 30 '18 at 5:38
2
2
Quick note for the future -- use the
{}
button, not the StackSnippet button, unless you're trying to generate an example that can be run in the browser (which is to say, snippets are only for HTML/JavaScript/CSS questions).– Charles Duffy
Dec 30 '18 at 5:41
Quick note for the future -- use the
{}
button, not the StackSnippet button, unless you're trying to generate an example that can be run in the browser (which is to say, snippets are only for HTML/JavaScript/CSS questions).– Charles Duffy
Dec 30 '18 at 5:41
1
1
Side note: don't set
prev
like this, def get_all_messages(auth, id, last="", prev=):
, as it evaluates the empty list once during the definition of the function. After that, the list will be non-empty on subsequent calls.– torek
Dec 30 '18 at 5:45
Side note: don't set
prev
like this, def get_all_messages(auth, id, last="", prev=):
, as it evaluates the empty list once during the definition of the function. After that, the list will be non-empty on subsequent calls.– torek
Dec 30 '18 at 5:45
BTW, you might want to inspect the output to see why it's no longer a list -- good chance you'd need to change other code too if the wire format was updated.
– Charles Duffy
Dec 30 '18 at 17:50
BTW, you might want to inspect the output to see why it's no longer a list -- good chance you'd need to change other code too if the wire format was updated.
– Charles Duffy
Dec 30 '18 at 17:50
add a comment |
2 Answers
2
active
oldest
votes
If you want to keep the old behavior of having a flat list when the content received is itself a list, but also be able to append non-list received messages as individual items, consider:
if isinstance(messages, list):
prev.extend(messages)
else: # messages is not really a list!
prev.append(messages)
Otherwise, if you just want to append the newly-received batch of messages as a single item to your list no matter what, that would look like:
prev.append(messages)
You can only use +
with a list on the left-hand side if the thing on the right-hand side is also a list. The error message indicates that not to be the case here (the thing on the right-hand side, in the responses you're getting from the server today, is a dict and not a list).
add a comment |
messages
should be a list, in your case it's a dictionary concatenation should be list + list
If you need to append an int
or any other single element, you could always convert it into a single element list using or directly use
append
.
prev = prev + [messages]
OR
prev.append(messages)
append()
is going to be a bit faster -- not a huge difference, but it could add up in a tight loop (not likely to be the case in the current codebase, however, which is likely to be bottlenecked on network).
– Charles Duffy
Dec 30 '18 at 5:49
@Charles Oh! Is it. I did not know that. Thanks.
– Vishnudev
Dec 30 '18 at 5:50
See gist.github.com/charles-dyfis-net/… for some concrete benchmarks -- it's actually a much bigger difference than I expected. (Java's garbage collector plays a bunch of games to make transient objects that are only momentarily needed very cheap; it looks like Python doesn't do so as effectively, so the cost of creating all the single-item lists adds up).
– Charles Duffy
Dec 30 '18 at 5:56
You're not compelled to -- it adds something useful, I think; there's just also value to having this comment thread discussion so folks understand the practical limitations.
– Charles Duffy
Dec 30 '18 at 5:59
@CharlesDuffy These comments might help people like me.
– Vishnudev
Dec 30 '18 at 6:00
add a 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%2f53975494%2fdont-understand-why-this-typeerror-can-only-concatenate-list-not-dict-to-l%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to keep the old behavior of having a flat list when the content received is itself a list, but also be able to append non-list received messages as individual items, consider:
if isinstance(messages, list):
prev.extend(messages)
else: # messages is not really a list!
prev.append(messages)
Otherwise, if you just want to append the newly-received batch of messages as a single item to your list no matter what, that would look like:
prev.append(messages)
You can only use +
with a list on the left-hand side if the thing on the right-hand side is also a list. The error message indicates that not to be the case here (the thing on the right-hand side, in the responses you're getting from the server today, is a dict and not a list).
add a comment |
If you want to keep the old behavior of having a flat list when the content received is itself a list, but also be able to append non-list received messages as individual items, consider:
if isinstance(messages, list):
prev.extend(messages)
else: # messages is not really a list!
prev.append(messages)
Otherwise, if you just want to append the newly-received batch of messages as a single item to your list no matter what, that would look like:
prev.append(messages)
You can only use +
with a list on the left-hand side if the thing on the right-hand side is also a list. The error message indicates that not to be the case here (the thing on the right-hand side, in the responses you're getting from the server today, is a dict and not a list).
add a comment |
If you want to keep the old behavior of having a flat list when the content received is itself a list, but also be able to append non-list received messages as individual items, consider:
if isinstance(messages, list):
prev.extend(messages)
else: # messages is not really a list!
prev.append(messages)
Otherwise, if you just want to append the newly-received batch of messages as a single item to your list no matter what, that would look like:
prev.append(messages)
You can only use +
with a list on the left-hand side if the thing on the right-hand side is also a list. The error message indicates that not to be the case here (the thing on the right-hand side, in the responses you're getting from the server today, is a dict and not a list).
If you want to keep the old behavior of having a flat list when the content received is itself a list, but also be able to append non-list received messages as individual items, consider:
if isinstance(messages, list):
prev.extend(messages)
else: # messages is not really a list!
prev.append(messages)
Otherwise, if you just want to append the newly-received batch of messages as a single item to your list no matter what, that would look like:
prev.append(messages)
You can only use +
with a list on the left-hand side if the thing on the right-hand side is also a list. The error message indicates that not to be the case here (the thing on the right-hand side, in the responses you're getting from the server today, is a dict and not a list).
edited Dec 30 '18 at 17:54
answered Dec 30 '18 at 5:43
Charles DuffyCharles Duffy
175k25197252
175k25197252
add a comment |
add a comment |
messages
should be a list, in your case it's a dictionary concatenation should be list + list
If you need to append an int
or any other single element, you could always convert it into a single element list using or directly use
append
.
prev = prev + [messages]
OR
prev.append(messages)
append()
is going to be a bit faster -- not a huge difference, but it could add up in a tight loop (not likely to be the case in the current codebase, however, which is likely to be bottlenecked on network).
– Charles Duffy
Dec 30 '18 at 5:49
@Charles Oh! Is it. I did not know that. Thanks.
– Vishnudev
Dec 30 '18 at 5:50
See gist.github.com/charles-dyfis-net/… for some concrete benchmarks -- it's actually a much bigger difference than I expected. (Java's garbage collector plays a bunch of games to make transient objects that are only momentarily needed very cheap; it looks like Python doesn't do so as effectively, so the cost of creating all the single-item lists adds up).
– Charles Duffy
Dec 30 '18 at 5:56
You're not compelled to -- it adds something useful, I think; there's just also value to having this comment thread discussion so folks understand the practical limitations.
– Charles Duffy
Dec 30 '18 at 5:59
@CharlesDuffy These comments might help people like me.
– Vishnudev
Dec 30 '18 at 6:00
add a comment |
messages
should be a list, in your case it's a dictionary concatenation should be list + list
If you need to append an int
or any other single element, you could always convert it into a single element list using or directly use
append
.
prev = prev + [messages]
OR
prev.append(messages)
append()
is going to be a bit faster -- not a huge difference, but it could add up in a tight loop (not likely to be the case in the current codebase, however, which is likely to be bottlenecked on network).
– Charles Duffy
Dec 30 '18 at 5:49
@Charles Oh! Is it. I did not know that. Thanks.
– Vishnudev
Dec 30 '18 at 5:50
See gist.github.com/charles-dyfis-net/… for some concrete benchmarks -- it's actually a much bigger difference than I expected. (Java's garbage collector plays a bunch of games to make transient objects that are only momentarily needed very cheap; it looks like Python doesn't do so as effectively, so the cost of creating all the single-item lists adds up).
– Charles Duffy
Dec 30 '18 at 5:56
You're not compelled to -- it adds something useful, I think; there's just also value to having this comment thread discussion so folks understand the practical limitations.
– Charles Duffy
Dec 30 '18 at 5:59
@CharlesDuffy These comments might help people like me.
– Vishnudev
Dec 30 '18 at 6:00
add a comment |
messages
should be a list, in your case it's a dictionary concatenation should be list + list
If you need to append an int
or any other single element, you could always convert it into a single element list using or directly use
append
.
prev = prev + [messages]
OR
prev.append(messages)
messages
should be a list, in your case it's a dictionary concatenation should be list + list
If you need to append an int
or any other single element, you could always convert it into a single element list using or directly use
append
.
prev = prev + [messages]
OR
prev.append(messages)
edited Dec 30 '18 at 5:48
answered Dec 30 '18 at 5:42
VishnudevVishnudev
1,156517
1,156517
append()
is going to be a bit faster -- not a huge difference, but it could add up in a tight loop (not likely to be the case in the current codebase, however, which is likely to be bottlenecked on network).
– Charles Duffy
Dec 30 '18 at 5:49
@Charles Oh! Is it. I did not know that. Thanks.
– Vishnudev
Dec 30 '18 at 5:50
See gist.github.com/charles-dyfis-net/… for some concrete benchmarks -- it's actually a much bigger difference than I expected. (Java's garbage collector plays a bunch of games to make transient objects that are only momentarily needed very cheap; it looks like Python doesn't do so as effectively, so the cost of creating all the single-item lists adds up).
– Charles Duffy
Dec 30 '18 at 5:56
You're not compelled to -- it adds something useful, I think; there's just also value to having this comment thread discussion so folks understand the practical limitations.
– Charles Duffy
Dec 30 '18 at 5:59
@CharlesDuffy These comments might help people like me.
– Vishnudev
Dec 30 '18 at 6:00
add a comment |
append()
is going to be a bit faster -- not a huge difference, but it could add up in a tight loop (not likely to be the case in the current codebase, however, which is likely to be bottlenecked on network).
– Charles Duffy
Dec 30 '18 at 5:49
@Charles Oh! Is it. I did not know that. Thanks.
– Vishnudev
Dec 30 '18 at 5:50
See gist.github.com/charles-dyfis-net/… for some concrete benchmarks -- it's actually a much bigger difference than I expected. (Java's garbage collector plays a bunch of games to make transient objects that are only momentarily needed very cheap; it looks like Python doesn't do so as effectively, so the cost of creating all the single-item lists adds up).
– Charles Duffy
Dec 30 '18 at 5:56
You're not compelled to -- it adds something useful, I think; there's just also value to having this comment thread discussion so folks understand the practical limitations.
– Charles Duffy
Dec 30 '18 at 5:59
@CharlesDuffy These comments might help people like me.
– Vishnudev
Dec 30 '18 at 6:00
append()
is going to be a bit faster -- not a huge difference, but it could add up in a tight loop (not likely to be the case in the current codebase, however, which is likely to be bottlenecked on network).– Charles Duffy
Dec 30 '18 at 5:49
append()
is going to be a bit faster -- not a huge difference, but it could add up in a tight loop (not likely to be the case in the current codebase, however, which is likely to be bottlenecked on network).– Charles Duffy
Dec 30 '18 at 5:49
@Charles Oh! Is it. I did not know that. Thanks.
– Vishnudev
Dec 30 '18 at 5:50
@Charles Oh! Is it. I did not know that. Thanks.
– Vishnudev
Dec 30 '18 at 5:50
See gist.github.com/charles-dyfis-net/… for some concrete benchmarks -- it's actually a much bigger difference than I expected. (Java's garbage collector plays a bunch of games to make transient objects that are only momentarily needed very cheap; it looks like Python doesn't do so as effectively, so the cost of creating all the single-item lists adds up).
– Charles Duffy
Dec 30 '18 at 5:56
See gist.github.com/charles-dyfis-net/… for some concrete benchmarks -- it's actually a much bigger difference than I expected. (Java's garbage collector plays a bunch of games to make transient objects that are only momentarily needed very cheap; it looks like Python doesn't do so as effectively, so the cost of creating all the single-item lists adds up).
– Charles Duffy
Dec 30 '18 at 5:56
You're not compelled to -- it adds something useful, I think; there's just also value to having this comment thread discussion so folks understand the practical limitations.
– Charles Duffy
Dec 30 '18 at 5:59
You're not compelled to -- it adds something useful, I think; there's just also value to having this comment thread discussion so folks understand the practical limitations.
– Charles Duffy
Dec 30 '18 at 5:59
@CharlesDuffy These comments might help people like me.
– Vishnudev
Dec 30 '18 at 6:00
@CharlesDuffy These comments might help people like me.
– Vishnudev
Dec 30 '18 at 6:00
add a 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%2f53975494%2fdont-understand-why-this-typeerror-can-only-concatenate-list-not-dict-to-l%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
The JSON endpoint must be returning a single JS object (translated to a python dict) rather than a JS array (translated to a python list)
– Aaron
Dec 30 '18 at 5:33
I'm actually quite new with this code. Would you be able to show an example?
– Kelsey Maria
Dec 30 '18 at 5:38
2
Quick note for the future -- use the
{}
button, not the StackSnippet button, unless you're trying to generate an example that can be run in the browser (which is to say, snippets are only for HTML/JavaScript/CSS questions).– Charles Duffy
Dec 30 '18 at 5:41
1
Side note: don't set
prev
like this,def get_all_messages(auth, id, last="", prev=):
, as it evaluates the empty list once during the definition of the function. After that, the list will be non-empty on subsequent calls.– torek
Dec 30 '18 at 5:45
BTW, you might want to inspect the output to see why it's no longer a list -- good chance you'd need to change other code too if the wire format was updated.
– Charles Duffy
Dec 30 '18 at 17:50