TypeError: 'NoneType' object is not iterable, while appending a list
I have a function which returns a list. But it has nothing to return. I want to handle the TypeError.
I have tried this:
def isLookingAround(lst):
res =
body =
for data in lst:
res += isLookingAt(normalize2(data))
body += isBodyDirection(normalize2(data))
if most_body == "front" or most_body == "backward":
if ('lookL' in res and 'lookR' in res):
return 'lookingAround'
elif most_body == "left" or most_body == "right":
if ('lookF' in res and 'lookB' in res):
return 'lookingAround'
Error:
Traceback (most recent call last):
File "action_detector.py", line 201, in <module>
write_labels(input_source, labels)
File "action_detector.py", line 179, in write_labels
for itr, word in enumerate(lbls):
TypeError: 'NoneType' object is not iterable
I am still getting the error with labels.append(detectors.isLookingAround(back_Data)) . I would appreciate your help.
python list
|
show 8 more comments
I have a function which returns a list. But it has nothing to return. I want to handle the TypeError.
I have tried this:
def isLookingAround(lst):
res =
body =
for data in lst:
res += isLookingAt(normalize2(data))
body += isBodyDirection(normalize2(data))
if most_body == "front" or most_body == "backward":
if ('lookL' in res and 'lookR' in res):
return 'lookingAround'
elif most_body == "left" or most_body == "right":
if ('lookF' in res and 'lookB' in res):
return 'lookingAround'
Error:
Traceback (most recent call last):
File "action_detector.py", line 201, in <module>
write_labels(input_source, labels)
File "action_detector.py", line 179, in write_labels
for itr, word in enumerate(lbls):
TypeError: 'NoneType' object is not iterable
I am still getting the error with labels.append(detectors.isLookingAround(back_Data)) . I would appreciate your help.
python list
@Jerry Understand, butl
is the list which is gonna get appended, and also it's empty, so maybe the OP has another list calledlist
(not a good name)
– U9-Forward
Nov 12 '18 at 5:44
1
I guess your issue coming fromdetectors.isLookingAround(back_Data)
– Rahul K P
Nov 12 '18 at 5:59
1
But the thing is that appendingNone
to a list does not generate an error. You will have to fixisLookingAround
itself. Or alternatively learn whenisLookingAround
gives the error so you can make sureback_Data
does not cause that error.
– Jerry
Nov 12 '18 at 6:06
1
@prb Sure. FWIW, maybe removing the current code would be better since the error is not raised here.
– Jerry
Nov 12 '18 at 6:32
1
Can you also include the full error? It's difficult to pinpoint where the error might be occurring because more functions are being used inisLookingAround
.
– Jerry
Nov 12 '18 at 6:58
|
show 8 more comments
I have a function which returns a list. But it has nothing to return. I want to handle the TypeError.
I have tried this:
def isLookingAround(lst):
res =
body =
for data in lst:
res += isLookingAt(normalize2(data))
body += isBodyDirection(normalize2(data))
if most_body == "front" or most_body == "backward":
if ('lookL' in res and 'lookR' in res):
return 'lookingAround'
elif most_body == "left" or most_body == "right":
if ('lookF' in res and 'lookB' in res):
return 'lookingAround'
Error:
Traceback (most recent call last):
File "action_detector.py", line 201, in <module>
write_labels(input_source, labels)
File "action_detector.py", line 179, in write_labels
for itr, word in enumerate(lbls):
TypeError: 'NoneType' object is not iterable
I am still getting the error with labels.append(detectors.isLookingAround(back_Data)) . I would appreciate your help.
python list
I have a function which returns a list. But it has nothing to return. I want to handle the TypeError.
I have tried this:
def isLookingAround(lst):
res =
body =
for data in lst:
res += isLookingAt(normalize2(data))
body += isBodyDirection(normalize2(data))
if most_body == "front" or most_body == "backward":
if ('lookL' in res and 'lookR' in res):
return 'lookingAround'
elif most_body == "left" or most_body == "right":
if ('lookF' in res and 'lookB' in res):
return 'lookingAround'
Error:
Traceback (most recent call last):
File "action_detector.py", line 201, in <module>
write_labels(input_source, labels)
File "action_detector.py", line 179, in write_labels
for itr, word in enumerate(lbls):
TypeError: 'NoneType' object is not iterable
I am still getting the error with labels.append(detectors.isLookingAround(back_Data)) . I would appreciate your help.
python list
python list
edited Nov 13 '18 at 7:09
asked Nov 12 '18 at 5:38
prb
9810
9810
@Jerry Understand, butl
is the list which is gonna get appended, and also it's empty, so maybe the OP has another list calledlist
(not a good name)
– U9-Forward
Nov 12 '18 at 5:44
1
I guess your issue coming fromdetectors.isLookingAround(back_Data)
– Rahul K P
Nov 12 '18 at 5:59
1
But the thing is that appendingNone
to a list does not generate an error. You will have to fixisLookingAround
itself. Or alternatively learn whenisLookingAround
gives the error so you can make sureback_Data
does not cause that error.
– Jerry
Nov 12 '18 at 6:06
1
@prb Sure. FWIW, maybe removing the current code would be better since the error is not raised here.
– Jerry
Nov 12 '18 at 6:32
1
Can you also include the full error? It's difficult to pinpoint where the error might be occurring because more functions are being used inisLookingAround
.
– Jerry
Nov 12 '18 at 6:58
|
show 8 more comments
@Jerry Understand, butl
is the list which is gonna get appended, and also it's empty, so maybe the OP has another list calledlist
(not a good name)
– U9-Forward
Nov 12 '18 at 5:44
1
I guess your issue coming fromdetectors.isLookingAround(back_Data)
– Rahul K P
Nov 12 '18 at 5:59
1
But the thing is that appendingNone
to a list does not generate an error. You will have to fixisLookingAround
itself. Or alternatively learn whenisLookingAround
gives the error so you can make sureback_Data
does not cause that error.
– Jerry
Nov 12 '18 at 6:06
1
@prb Sure. FWIW, maybe removing the current code would be better since the error is not raised here.
– Jerry
Nov 12 '18 at 6:32
1
Can you also include the full error? It's difficult to pinpoint where the error might be occurring because more functions are being used inisLookingAround
.
– Jerry
Nov 12 '18 at 6:58
@Jerry Understand, but
l
is the list which is gonna get appended, and also it's empty, so maybe the OP has another list called list
(not a good name)– U9-Forward
Nov 12 '18 at 5:44
@Jerry Understand, but
l
is the list which is gonna get appended, and also it's empty, so maybe the OP has another list called list
(not a good name)– U9-Forward
Nov 12 '18 at 5:44
1
1
I guess your issue coming from
detectors.isLookingAround(back_Data)
– Rahul K P
Nov 12 '18 at 5:59
I guess your issue coming from
detectors.isLookingAround(back_Data)
– Rahul K P
Nov 12 '18 at 5:59
1
1
But the thing is that appending
None
to a list does not generate an error. You will have to fix isLookingAround
itself. Or alternatively learn when isLookingAround
gives the error so you can make sure back_Data
does not cause that error.– Jerry
Nov 12 '18 at 6:06
But the thing is that appending
None
to a list does not generate an error. You will have to fix isLookingAround
itself. Or alternatively learn when isLookingAround
gives the error so you can make sure back_Data
does not cause that error.– Jerry
Nov 12 '18 at 6:06
1
1
@prb Sure. FWIW, maybe removing the current code would be better since the error is not raised here.
– Jerry
Nov 12 '18 at 6:32
@prb Sure. FWIW, maybe removing the current code would be better since the error is not raised here.
– Jerry
Nov 12 '18 at 6:32
1
1
Can you also include the full error? It's difficult to pinpoint where the error might be occurring because more functions are being used in
isLookingAround
.– Jerry
Nov 12 '18 at 6:58
Can you also include the full error? It's difficult to pinpoint where the error might be occurring because more functions are being used in
isLookingAround
.– Jerry
Nov 12 '18 at 6:58
|
show 8 more comments
2 Answers
2
active
oldest
votes
To check data is empty. you can use below code
if data:
l.append(data)
add a comment |
In order to handle the NoneType
exception, you can surround the statement within try-except
blocks.
For example, you can do something like,
try:
labels.append(detectors.isLookingAround(back_Data))
except TypeError:
# Do something. Like,
return
It will "catch" the error, and then you can handle it properly. However, the error seems to come from isLookingAround
method.
You can re-check that, and if you're unable to resolve it, post a new question, I guess.
I have already tried this. I am not able to handle it. Maybe there is a problem with the function
– prb
Nov 12 '18 at 6:06
1
Are you sure that the exception is occurring here? Maybe post a stacktrace here..
– MaJoR
Nov 12 '18 at 6:11
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%2f53256437%2ftypeerror-nonetype-object-is-not-iterable-while-appending-a-list%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
To check data is empty. you can use below code
if data:
l.append(data)
add a comment |
To check data is empty. you can use below code
if data:
l.append(data)
add a comment |
To check data is empty. you can use below code
if data:
l.append(data)
To check data is empty. you can use below code
if data:
l.append(data)
answered Nov 12 '18 at 5:41
Lijo Jose
638
638
add a comment |
add a comment |
In order to handle the NoneType
exception, you can surround the statement within try-except
blocks.
For example, you can do something like,
try:
labels.append(detectors.isLookingAround(back_Data))
except TypeError:
# Do something. Like,
return
It will "catch" the error, and then you can handle it properly. However, the error seems to come from isLookingAround
method.
You can re-check that, and if you're unable to resolve it, post a new question, I guess.
I have already tried this. I am not able to handle it. Maybe there is a problem with the function
– prb
Nov 12 '18 at 6:06
1
Are you sure that the exception is occurring here? Maybe post a stacktrace here..
– MaJoR
Nov 12 '18 at 6:11
add a comment |
In order to handle the NoneType
exception, you can surround the statement within try-except
blocks.
For example, you can do something like,
try:
labels.append(detectors.isLookingAround(back_Data))
except TypeError:
# Do something. Like,
return
It will "catch" the error, and then you can handle it properly. However, the error seems to come from isLookingAround
method.
You can re-check that, and if you're unable to resolve it, post a new question, I guess.
I have already tried this. I am not able to handle it. Maybe there is a problem with the function
– prb
Nov 12 '18 at 6:06
1
Are you sure that the exception is occurring here? Maybe post a stacktrace here..
– MaJoR
Nov 12 '18 at 6:11
add a comment |
In order to handle the NoneType
exception, you can surround the statement within try-except
blocks.
For example, you can do something like,
try:
labels.append(detectors.isLookingAround(back_Data))
except TypeError:
# Do something. Like,
return
It will "catch" the error, and then you can handle it properly. However, the error seems to come from isLookingAround
method.
You can re-check that, and if you're unable to resolve it, post a new question, I guess.
In order to handle the NoneType
exception, you can surround the statement within try-except
blocks.
For example, you can do something like,
try:
labels.append(detectors.isLookingAround(back_Data))
except TypeError:
# Do something. Like,
return
It will "catch" the error, and then you can handle it properly. However, the error seems to come from isLookingAround
method.
You can re-check that, and if you're unable to resolve it, post a new question, I guess.
answered Nov 12 '18 at 6:02
MaJoR
398111
398111
I have already tried this. I am not able to handle it. Maybe there is a problem with the function
– prb
Nov 12 '18 at 6:06
1
Are you sure that the exception is occurring here? Maybe post a stacktrace here..
– MaJoR
Nov 12 '18 at 6:11
add a comment |
I have already tried this. I am not able to handle it. Maybe there is a problem with the function
– prb
Nov 12 '18 at 6:06
1
Are you sure that the exception is occurring here? Maybe post a stacktrace here..
– MaJoR
Nov 12 '18 at 6:11
I have already tried this. I am not able to handle it. Maybe there is a problem with the function
– prb
Nov 12 '18 at 6:06
I have already tried this. I am not able to handle it. Maybe there is a problem with the function
– prb
Nov 12 '18 at 6:06
1
1
Are you sure that the exception is occurring here? Maybe post a stacktrace here..
– MaJoR
Nov 12 '18 at 6:11
Are you sure that the exception is occurring here? Maybe post a stacktrace here..
– MaJoR
Nov 12 '18 at 6:11
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53256437%2ftypeerror-nonetype-object-is-not-iterable-while-appending-a-list%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
@Jerry Understand, but
l
is the list which is gonna get appended, and also it's empty, so maybe the OP has another list calledlist
(not a good name)– U9-Forward
Nov 12 '18 at 5:44
1
I guess your issue coming from
detectors.isLookingAround(back_Data)
– Rahul K P
Nov 12 '18 at 5:59
1
But the thing is that appending
None
to a list does not generate an error. You will have to fixisLookingAround
itself. Or alternatively learn whenisLookingAround
gives the error so you can make sureback_Data
does not cause that error.– Jerry
Nov 12 '18 at 6:06
1
@prb Sure. FWIW, maybe removing the current code would be better since the error is not raised here.
– Jerry
Nov 12 '18 at 6:32
1
Can you also include the full error? It's difficult to pinpoint where the error might be occurring because more functions are being used in
isLookingAround
.– Jerry
Nov 12 '18 at 6:58