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;








-1















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










share|improve this question






















  • 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

















-1















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










share|improve this question






















  • 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













-1












-1








-1








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 15:55









userHGuserHG

13410




13410












  • 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
















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












1 Answer
1






active

oldest

votes


















4














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)





share|improve this answer























  • 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












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
);



);













draft saved

draft discarded


















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









4














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)





share|improve this answer























  • 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
















4














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)





share|improve this answer























  • 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














4












4








4







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)





share|improve this answer













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)






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 22 at 15:57









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 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


















  • 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

















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




















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript