NameError: undefined nested function in python Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory in Python?Does Python have a ternary conditional operator?How to get the current time in PythonUsing global variables in a functionHow to make a chain of function decorators?Does Python have a string 'contains' substring method?
What is /etc/mtab in Linux?
Why did C use the -> operator instead of reusing the . operator?
Multiple options vs single option UI
Map material from china not allowed to leave the country
What is this word supposed to be?
Did the Roman Empire have penal colonies?
std::is_constructible on incomplete types
Is there any hidden 'W' sound after 'comment' in : Comment est-elle?
Is accepting an invalid credit card number a security issue?
Israeli soda type drink
Why did Israel vote against lifting the American embargo on Cuba?
Are all CP/M-80 implementations binary compatible?
What if Force was not Mass times Acceleration?
A Paper Record is What I Hamper
How long after the last departure shall the airport stay open for an emergency return?
What is the least dense liquid under normal conditions?
As an international instructor, should I openly talk about my accent?
Will I lose my paid in full property
Married in secret, can marital status in passport be changed at a later date?
Does Feeblemind produce an ongoing magical effect that can be dispelled?
Economise space with floats
Protagonist's race is hidden - should I reveal it?
What's parked in Mil Moscow helicopter plant?
Where did Arya get these scars?
NameError: undefined nested function in python
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory in Python?Does Python have a ternary conditional operator?How to get the current time in PythonUsing global variables in a functionHow to make a chain of function decorators?Does Python have a string 'contains' substring method?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm a python beginner, I'm trying to reorganize my code, I have multiple nested functions
Here is my python code
def download_pkg(self):
(...)
def download_several_apps(self):
global inputFileName_download,listbox_input
if(listbox_input.size() == 0):
print("NO INPUT FILE")
elif(listbox_input.size() == 1):
print("filename :" + str(self.inputFileName_download))
with open(self.inputFileName_download, 'r') as f:
for line in f:
print(line)
download_pkg(line)
else:
print("Problem while downloading several apps")
I have this error :
NameError: name 'download_pkg' is not defined
How can I access this function ? Thank you
python
add a comment |
I'm a python beginner, I'm trying to reorganize my code, I have multiple nested functions
Here is my python code
def download_pkg(self):
(...)
def download_several_apps(self):
global inputFileName_download,listbox_input
if(listbox_input.size() == 0):
print("NO INPUT FILE")
elif(listbox_input.size() == 1):
print("filename :" + str(self.inputFileName_download))
with open(self.inputFileName_download, 'r') as f:
for line in f:
print(line)
download_pkg(line)
else:
print("Problem while downloading several apps")
I have this error :
NameError: name 'download_pkg' is not defined
How can I access this function ? Thank you
python
listbox_input
(or rather, itssize
attribute) should be an argument todownload_several_apps
, not a global;inputFileName_download
is already an instance attribute; you aren't using any global by that name (if one even exists).
– chepner
Mar 22 at 16:00
add a comment |
I'm a python beginner, I'm trying to reorganize my code, I have multiple nested functions
Here is my python code
def download_pkg(self):
(...)
def download_several_apps(self):
global inputFileName_download,listbox_input
if(listbox_input.size() == 0):
print("NO INPUT FILE")
elif(listbox_input.size() == 1):
print("filename :" + str(self.inputFileName_download))
with open(self.inputFileName_download, 'r') as f:
for line in f:
print(line)
download_pkg(line)
else:
print("Problem while downloading several apps")
I have this error :
NameError: name 'download_pkg' is not defined
How can I access this function ? Thank you
python
I'm a python beginner, I'm trying to reorganize my code, I have multiple nested functions
Here is my python code
def download_pkg(self):
(...)
def download_several_apps(self):
global inputFileName_download,listbox_input
if(listbox_input.size() == 0):
print("NO INPUT FILE")
elif(listbox_input.size() == 1):
print("filename :" + str(self.inputFileName_download))
with open(self.inputFileName_download, 'r') as f:
for line in f:
print(line)
download_pkg(line)
else:
print("Problem while downloading several apps")
I have this error :
NameError: name 'download_pkg' is not defined
How can I access this function ? Thank you
python
python
asked Mar 22 at 15:55
userHGuserHG
13410
13410
listbox_input
(or rather, itssize
attribute) should be an argument todownload_several_apps
, not a global;inputFileName_download
is already an instance attribute; you aren't using any global by that name (if one even exists).
– chepner
Mar 22 at 16:00
add a comment |
listbox_input
(or rather, itssize
attribute) should be an argument todownload_several_apps
, not a global;inputFileName_download
is already an instance attribute; you aren't using any global by that name (if one even exists).
– chepner
Mar 22 at 16:00
listbox_input
(or rather, its size
attribute) should be an argument to download_several_apps
, not a global; inputFileName_download
is already an instance attribute; you aren't using any global by that name (if one even exists).– chepner
Mar 22 at 16:00
listbox_input
(or rather, its size
attribute) should be an argument to download_several_apps
, not a global; inputFileName_download
is already an instance attribute; you aren't using any global by that name (if one even exists).– chepner
Mar 22 at 16:00
add a comment |
1 Answer
1
active
oldest
votes
You don't show it, but you're clearly in a class's methods, not top-level functions. So you need to call the method on an existing instance of the class. Luckily, you're an instance method yourself, so you have self
available to do so. Just change:
download_pkg(line)
to:
self.download_pkg(line)
ok I understand the proble, I have an other error : TypeError: download_pkg() takes 1 positional argument but 2 were given
– userHG
Mar 22 at 16:02
@userHG: You're the one who passed itline
. I have no idea what it's supposed to do withline
, but if it's supposed to take a (non-self
) argument, you'll need to receive an extra argument (aside fromself
) ondownload_pkg
.
– ShadowRanger
Mar 22 at 16:04
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%2f55303463%2fnameerror-undefined-nested-function-in-python%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
You don't show it, but you're clearly in a class's methods, not top-level functions. So you need to call the method on an existing instance of the class. Luckily, you're an instance method yourself, so you have self
available to do so. Just change:
download_pkg(line)
to:
self.download_pkg(line)
ok I understand the proble, I have an other error : TypeError: download_pkg() takes 1 positional argument but 2 were given
– userHG
Mar 22 at 16:02
@userHG: You're the one who passed itline
. I have no idea what it's supposed to do withline
, but if it's supposed to take a (non-self
) argument, you'll need to receive an extra argument (aside fromself
) ondownload_pkg
.
– ShadowRanger
Mar 22 at 16:04
add a comment |
You don't show it, but you're clearly in a class's methods, not top-level functions. So you need to call the method on an existing instance of the class. Luckily, you're an instance method yourself, so you have self
available to do so. Just change:
download_pkg(line)
to:
self.download_pkg(line)
ok I understand the proble, I have an other error : TypeError: download_pkg() takes 1 positional argument but 2 were given
– userHG
Mar 22 at 16:02
@userHG: You're the one who passed itline
. I have no idea what it's supposed to do withline
, but if it's supposed to take a (non-self
) argument, you'll need to receive an extra argument (aside fromself
) ondownload_pkg
.
– ShadowRanger
Mar 22 at 16:04
add a comment |
You don't show it, but you're clearly in a class's methods, not top-level functions. So you need to call the method on an existing instance of the class. Luckily, you're an instance method yourself, so you have self
available to do so. Just change:
download_pkg(line)
to:
self.download_pkg(line)
You don't show it, but you're clearly in a class's methods, not top-level functions. So you need to call the method on an existing instance of the class. Luckily, you're an instance method yourself, so you have self
available to do so. Just change:
download_pkg(line)
to:
self.download_pkg(line)
answered Mar 22 at 15:57
![](https://i.stack.imgur.com/7eBCp.jpg?s=32&g=1)
![](https://i.stack.imgur.com/7eBCp.jpg?s=32&g=1)
ShadowRangerShadowRanger
64.6k663102
64.6k663102
ok I understand the proble, I have an other error : TypeError: download_pkg() takes 1 positional argument but 2 were given
– userHG
Mar 22 at 16:02
@userHG: You're the one who passed itline
. I have no idea what it's supposed to do withline
, but if it's supposed to take a (non-self
) argument, you'll need to receive an extra argument (aside fromself
) ondownload_pkg
.
– ShadowRanger
Mar 22 at 16:04
add a comment |
ok I understand the proble, I have an other error : TypeError: download_pkg() takes 1 positional argument but 2 were given
– userHG
Mar 22 at 16:02
@userHG: You're the one who passed itline
. I have no idea what it's supposed to do withline
, but if it's supposed to take a (non-self
) argument, you'll need to receive an extra argument (aside fromself
) ondownload_pkg
.
– ShadowRanger
Mar 22 at 16:04
ok I understand the proble, I have an other error : TypeError: download_pkg() takes 1 positional argument but 2 were given
– userHG
Mar 22 at 16:02
ok I understand the proble, I have an other error : TypeError: download_pkg() takes 1 positional argument but 2 were given
– userHG
Mar 22 at 16:02
@userHG: You're the one who passed it
line
. I have no idea what it's supposed to do with line
, but if it's supposed to take a (non-self
) argument, you'll need to receive an extra argument (aside from self
) on download_pkg
.– ShadowRanger
Mar 22 at 16:04
@userHG: You're the one who passed it
line
. I have no idea what it's supposed to do with line
, but if it's supposed to take a (non-self
) argument, you'll need to receive an extra argument (aside from self
) on download_pkg
.– ShadowRanger
Mar 22 at 16:04
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%2f55303463%2fnameerror-undefined-nested-function-in-python%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
listbox_input
(or rather, itssize
attribute) should be an argument todownload_several_apps
, not a global;inputFileName_download
is already an instance attribute; you aren't using any global by that name (if one even exists).– chepner
Mar 22 at 16:00