Newbie Question - Breaking a Function into two Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag? The Ask Question Wizard is Live!Calling a function of a module by using its name (a string)How to merge two dictionaries in a single expression?How can I do a line break (line continuation) in Python?Convert two lists into a dictionary in PythonHow to flush output of print function?How to return multiple values from a function?Using global variables in a functionLimiting floats to two decimal pointsHow to make a chain of function decorators?How do I concatenate two lists in Python?
Should I discuss the type of campaign with my players?
String `!23` is replaced with `docker` in command line
How to react to hostile behavior from a senior developer?
Is there a problem creating Diff Backups every hour instead of Logs and DIffs?
What exactly is a "Meth" in Altered Carbon?
2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?
How do I stop a creek from eroding my steep embankment?
How to find all the available tools in mac terminal?
How widely used is the term Treppenwitz? Is it something that most Germans know?
prime numbers and expressing non-prime numbers
Why was the term "discrete" used in discrete logarithm?
How can I make names more distinctive without making them longer?
Storing hydrofluoric acid before the invention of plastics
What does this icon in iOS Stardew Valley mean?
Book where humans were engineered with genes from animal species to survive hostile planets
Why is my conclusion inconsistent with the van't Hoff equation?
Dating a Former Employee
At the end of Thor: Ragnarok why don't the Asgardians turn and head for the Bifrost as per their original plan?
Should I use a zero-interest credit card for a large one-time purchase?
Overriding an object in memory with placement new
Check which numbers satisfy the condition [A*B*C = A! + B! + C!]
If a contract sometimes uses the wrong name, is it still valid?
Is there a (better) way to access $wpdb results?
Why is "Consequences inflicted." not a sentence?
Newbie Question - Breaking a Function into two
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?
The Ask Question Wizard is Live!Calling a function of a module by using its name (a string)How to merge two dictionaries in a single expression?How can I do a line break (line continuation) in Python?Convert two lists into a dictionary in PythonHow to flush output of print function?How to return multiple values from a function?Using global variables in a functionLimiting floats to two decimal pointsHow to make a chain of function decorators?How do I concatenate two lists in Python?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
So I am new to python and I have a function that I need to break into two parts. Previously it was one function but after some advice from someone that knows way more than me, I was given the tip that my function did too much, and I need to break it down to two separate things; so here I am.
Below is the code broken into two parts.
I am wondering do I have to mention the pathlist
in both functions?
What this is supposed to do is check if the files exist and then if they do then run the second function to remove the actual directories.
def check_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
remove_directory(pathslist)
dirs_to_delete = [
'C:MyDirectoryPath1',
'C:MyDirectoryPath2',
'C:MyDirectoryPath3'
]
def remove_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
python python-3.x
|
show 1 more comment
So I am new to python and I have a function that I need to break into two parts. Previously it was one function but after some advice from someone that knows way more than me, I was given the tip that my function did too much, and I need to break it down to two separate things; so here I am.
Below is the code broken into two parts.
I am wondering do I have to mention the pathlist
in both functions?
What this is supposed to do is check if the files exist and then if they do then run the second function to remove the actual directories.
def check_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
remove_directory(pathslist)
dirs_to_delete = [
'C:MyDirectoryPath1',
'C:MyDirectoryPath2',
'C:MyDirectoryPath3'
]
def remove_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
python python-3.x
"Do I have to mention the pathlist in both functions?" If you want to perform operations on an input, you sure do.
– esqew
Mar 8 at 17:34
I guess I was second guessing it was able to pull and use the pathlist from the other function or do the directories need to be listed in both spots?
– Jason Lucas
Mar 8 at 17:35
The advice to break this up is vaguely bogus. You should certainly not have identical code in many places.
– tripleee
Mar 8 at 17:38
WhileM
is harmless, you should generally use double backslashes, forward slashes, or raw strings when passing around Windows file names.
– tripleee
Mar 8 at 17:44
@tripleee The advice to break up the code is good; I just don't think OP did it in the best way.
– thumbtackthief
Mar 11 at 13:39
|
show 1 more comment
So I am new to python and I have a function that I need to break into two parts. Previously it was one function but after some advice from someone that knows way more than me, I was given the tip that my function did too much, and I need to break it down to two separate things; so here I am.
Below is the code broken into two parts.
I am wondering do I have to mention the pathlist
in both functions?
What this is supposed to do is check if the files exist and then if they do then run the second function to remove the actual directories.
def check_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
remove_directory(pathslist)
dirs_to_delete = [
'C:MyDirectoryPath1',
'C:MyDirectoryPath2',
'C:MyDirectoryPath3'
]
def remove_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
python python-3.x
So I am new to python and I have a function that I need to break into two parts. Previously it was one function but after some advice from someone that knows way more than me, I was given the tip that my function did too much, and I need to break it down to two separate things; so here I am.
Below is the code broken into two parts.
I am wondering do I have to mention the pathlist
in both functions?
What this is supposed to do is check if the files exist and then if they do then run the second function to remove the actual directories.
def check_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
remove_directory(pathslist)
dirs_to_delete = [
'C:MyDirectoryPath1',
'C:MyDirectoryPath2',
'C:MyDirectoryPath3'
]
def remove_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
python python-3.x
python python-3.x
edited Mar 8 at 17:38
tripleee
96.5k14135191
96.5k14135191
asked Mar 8 at 17:32
Jason LucasJason Lucas
297
297
"Do I have to mention the pathlist in both functions?" If you want to perform operations on an input, you sure do.
– esqew
Mar 8 at 17:34
I guess I was second guessing it was able to pull and use the pathlist from the other function or do the directories need to be listed in both spots?
– Jason Lucas
Mar 8 at 17:35
The advice to break this up is vaguely bogus. You should certainly not have identical code in many places.
– tripleee
Mar 8 at 17:38
WhileM
is harmless, you should generally use double backslashes, forward slashes, or raw strings when passing around Windows file names.
– tripleee
Mar 8 at 17:44
@tripleee The advice to break up the code is good; I just don't think OP did it in the best way.
– thumbtackthief
Mar 11 at 13:39
|
show 1 more comment
"Do I have to mention the pathlist in both functions?" If you want to perform operations on an input, you sure do.
– esqew
Mar 8 at 17:34
I guess I was second guessing it was able to pull and use the pathlist from the other function or do the directories need to be listed in both spots?
– Jason Lucas
Mar 8 at 17:35
The advice to break this up is vaguely bogus. You should certainly not have identical code in many places.
– tripleee
Mar 8 at 17:38
WhileM
is harmless, you should generally use double backslashes, forward slashes, or raw strings when passing around Windows file names.
– tripleee
Mar 8 at 17:44
@tripleee The advice to break up the code is good; I just don't think OP did it in the best way.
– thumbtackthief
Mar 11 at 13:39
"Do I have to mention the pathlist in both functions?" If you want to perform operations on an input, you sure do.
– esqew
Mar 8 at 17:34
"Do I have to mention the pathlist in both functions?" If you want to perform operations on an input, you sure do.
– esqew
Mar 8 at 17:34
I guess I was second guessing it was able to pull and use the pathlist from the other function or do the directories need to be listed in both spots?
– Jason Lucas
Mar 8 at 17:35
I guess I was second guessing it was able to pull and use the pathlist from the other function or do the directories need to be listed in both spots?
– Jason Lucas
Mar 8 at 17:35
The advice to break this up is vaguely bogus. You should certainly not have identical code in many places.
– tripleee
Mar 8 at 17:38
The advice to break this up is vaguely bogus. You should certainly not have identical code in many places.
– tripleee
Mar 8 at 17:38
While
M
is harmless, you should generally use double backslashes, forward slashes, or raw strings when passing around Windows file names.– tripleee
Mar 8 at 17:44
While
M
is harmless, you should generally use double backslashes, forward slashes, or raw strings when passing around Windows file names.– tripleee
Mar 8 at 17:44
@tripleee The advice to break up the code is good; I just don't think OP did it in the best way.
– thumbtackthief
Mar 11 at 13:39
@tripleee The advice to break up the code is good; I just don't think OP did it in the best way.
– thumbtackthief
Mar 11 at 13:39
|
show 1 more comment
1 Answer
1
active
oldest
votes
Not exactly. If you are passing in the entire pathslist to remove_directory
, you're going to try to remove each one whether or not it exists, making your check_directory function unnecessary. I think what you mean is in your check_directory function to only pass the path that exists in to remove_directory:
def check_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
remove_directory(path)
dirs_to_delete = [
'C:MyDirectoryPath1',
'C:MyDirectoryPath2',
'C:MyDirectoryPath3'
]
def remove_directory(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
You may want to try writing a comment for every function you write describing what it does. The second you use the word "and" or an additional verb, that's a hint that you may be better off splitting the function into multiple parts (that's just a rule of thumb, not an absolute). In addition, you want to avoid repeating code--if you have the same lines of code in two separate functions, that's another hint that you need to rethink your design.
Edit: As pointed out in the comments, the way you've written it means that calling check_directory
will remove the directory if it exists. It seems reasonable to expect that someone would call check_directory
for reasons other than wanting to remove it, and you'd be better off having remove_directory
call check_directory
rather than the other way around:
def check_directory(path):
# returns true if path is an existing directory
return os.path.exists(path) and os.path.isdir(path)
def remove_directory(pathlist):
for path in pathlist:
if check_directory(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
3
I've upvoted because you're answering the direct question. A bit out of scope of the topic at hand, but the method namecheck_directory
becomes a bit mis-leading if this were to become part of a bigger project. Someone usingcheck_directory
might be curious to know why it's also deleting the directory they pass in. A better paradigm would be to callcheck_directory()
inremove_directory()
– esqew
Mar 8 at 17:38
@esqew That's a good point.
– thumbtackthief
Mar 8 at 17:39
@thumbtackthief - I edited my code but when calling the function i am getting a error - TypeError: check_directory() missing 1 required positional argument: 'path'
– Jason Lucas
Mar 8 at 19:30
@JasonLucas That means somewhere you're callingcheck_directory
without passing in an argument.
– thumbtackthief
Mar 8 at 19:54
to call the function "check_directory" to start checking for folders do i need to do anything other then check_directory()
– Jason Lucas
Mar 8 at 20:21
|
show 3 more comments
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%2f55068229%2fnewbie-question-breaking-a-function-into-two%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
Not exactly. If you are passing in the entire pathslist to remove_directory
, you're going to try to remove each one whether or not it exists, making your check_directory function unnecessary. I think what you mean is in your check_directory function to only pass the path that exists in to remove_directory:
def check_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
remove_directory(path)
dirs_to_delete = [
'C:MyDirectoryPath1',
'C:MyDirectoryPath2',
'C:MyDirectoryPath3'
]
def remove_directory(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
You may want to try writing a comment for every function you write describing what it does. The second you use the word "and" or an additional verb, that's a hint that you may be better off splitting the function into multiple parts (that's just a rule of thumb, not an absolute). In addition, you want to avoid repeating code--if you have the same lines of code in two separate functions, that's another hint that you need to rethink your design.
Edit: As pointed out in the comments, the way you've written it means that calling check_directory
will remove the directory if it exists. It seems reasonable to expect that someone would call check_directory
for reasons other than wanting to remove it, and you'd be better off having remove_directory
call check_directory
rather than the other way around:
def check_directory(path):
# returns true if path is an existing directory
return os.path.exists(path) and os.path.isdir(path)
def remove_directory(pathlist):
for path in pathlist:
if check_directory(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
3
I've upvoted because you're answering the direct question. A bit out of scope of the topic at hand, but the method namecheck_directory
becomes a bit mis-leading if this were to become part of a bigger project. Someone usingcheck_directory
might be curious to know why it's also deleting the directory they pass in. A better paradigm would be to callcheck_directory()
inremove_directory()
– esqew
Mar 8 at 17:38
@esqew That's a good point.
– thumbtackthief
Mar 8 at 17:39
@thumbtackthief - I edited my code but when calling the function i am getting a error - TypeError: check_directory() missing 1 required positional argument: 'path'
– Jason Lucas
Mar 8 at 19:30
@JasonLucas That means somewhere you're callingcheck_directory
without passing in an argument.
– thumbtackthief
Mar 8 at 19:54
to call the function "check_directory" to start checking for folders do i need to do anything other then check_directory()
– Jason Lucas
Mar 8 at 20:21
|
show 3 more comments
Not exactly. If you are passing in the entire pathslist to remove_directory
, you're going to try to remove each one whether or not it exists, making your check_directory function unnecessary. I think what you mean is in your check_directory function to only pass the path that exists in to remove_directory:
def check_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
remove_directory(path)
dirs_to_delete = [
'C:MyDirectoryPath1',
'C:MyDirectoryPath2',
'C:MyDirectoryPath3'
]
def remove_directory(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
You may want to try writing a comment for every function you write describing what it does. The second you use the word "and" or an additional verb, that's a hint that you may be better off splitting the function into multiple parts (that's just a rule of thumb, not an absolute). In addition, you want to avoid repeating code--if you have the same lines of code in two separate functions, that's another hint that you need to rethink your design.
Edit: As pointed out in the comments, the way you've written it means that calling check_directory
will remove the directory if it exists. It seems reasonable to expect that someone would call check_directory
for reasons other than wanting to remove it, and you'd be better off having remove_directory
call check_directory
rather than the other way around:
def check_directory(path):
# returns true if path is an existing directory
return os.path.exists(path) and os.path.isdir(path)
def remove_directory(pathlist):
for path in pathlist:
if check_directory(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
3
I've upvoted because you're answering the direct question. A bit out of scope of the topic at hand, but the method namecheck_directory
becomes a bit mis-leading if this were to become part of a bigger project. Someone usingcheck_directory
might be curious to know why it's also deleting the directory they pass in. A better paradigm would be to callcheck_directory()
inremove_directory()
– esqew
Mar 8 at 17:38
@esqew That's a good point.
– thumbtackthief
Mar 8 at 17:39
@thumbtackthief - I edited my code but when calling the function i am getting a error - TypeError: check_directory() missing 1 required positional argument: 'path'
– Jason Lucas
Mar 8 at 19:30
@JasonLucas That means somewhere you're callingcheck_directory
without passing in an argument.
– thumbtackthief
Mar 8 at 19:54
to call the function "check_directory" to start checking for folders do i need to do anything other then check_directory()
– Jason Lucas
Mar 8 at 20:21
|
show 3 more comments
Not exactly. If you are passing in the entire pathslist to remove_directory
, you're going to try to remove each one whether or not it exists, making your check_directory function unnecessary. I think what you mean is in your check_directory function to only pass the path that exists in to remove_directory:
def check_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
remove_directory(path)
dirs_to_delete = [
'C:MyDirectoryPath1',
'C:MyDirectoryPath2',
'C:MyDirectoryPath3'
]
def remove_directory(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
You may want to try writing a comment for every function you write describing what it does. The second you use the word "and" or an additional verb, that's a hint that you may be better off splitting the function into multiple parts (that's just a rule of thumb, not an absolute). In addition, you want to avoid repeating code--if you have the same lines of code in two separate functions, that's another hint that you need to rethink your design.
Edit: As pointed out in the comments, the way you've written it means that calling check_directory
will remove the directory if it exists. It seems reasonable to expect that someone would call check_directory
for reasons other than wanting to remove it, and you'd be better off having remove_directory
call check_directory
rather than the other way around:
def check_directory(path):
# returns true if path is an existing directory
return os.path.exists(path) and os.path.isdir(path)
def remove_directory(pathlist):
for path in pathlist:
if check_directory(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
Not exactly. If you are passing in the entire pathslist to remove_directory
, you're going to try to remove each one whether or not it exists, making your check_directory function unnecessary. I think what you mean is in your check_directory function to only pass the path that exists in to remove_directory:
def check_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
remove_directory(path)
dirs_to_delete = [
'C:MyDirectoryPath1',
'C:MyDirectoryPath2',
'C:MyDirectoryPath3'
]
def remove_directory(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
You may want to try writing a comment for every function you write describing what it does. The second you use the word "and" or an additional verb, that's a hint that you may be better off splitting the function into multiple parts (that's just a rule of thumb, not an absolute). In addition, you want to avoid repeating code--if you have the same lines of code in two separate functions, that's another hint that you need to rethink your design.
Edit: As pointed out in the comments, the way you've written it means that calling check_directory
will remove the directory if it exists. It seems reasonable to expect that someone would call check_directory
for reasons other than wanting to remove it, and you'd be better off having remove_directory
call check_directory
rather than the other way around:
def check_directory(path):
# returns true if path is an existing directory
return os.path.exists(path) and os.path.isdir(path)
def remove_directory(pathlist):
for path in pathlist:
if check_directory(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
edited Mar 11 at 13:49
answered Mar 8 at 17:36
thumbtackthiefthumbtackthief
2,67652763
2,67652763
3
I've upvoted because you're answering the direct question. A bit out of scope of the topic at hand, but the method namecheck_directory
becomes a bit mis-leading if this were to become part of a bigger project. Someone usingcheck_directory
might be curious to know why it's also deleting the directory they pass in. A better paradigm would be to callcheck_directory()
inremove_directory()
– esqew
Mar 8 at 17:38
@esqew That's a good point.
– thumbtackthief
Mar 8 at 17:39
@thumbtackthief - I edited my code but when calling the function i am getting a error - TypeError: check_directory() missing 1 required positional argument: 'path'
– Jason Lucas
Mar 8 at 19:30
@JasonLucas That means somewhere you're callingcheck_directory
without passing in an argument.
– thumbtackthief
Mar 8 at 19:54
to call the function "check_directory" to start checking for folders do i need to do anything other then check_directory()
– Jason Lucas
Mar 8 at 20:21
|
show 3 more comments
3
I've upvoted because you're answering the direct question. A bit out of scope of the topic at hand, but the method namecheck_directory
becomes a bit mis-leading if this were to become part of a bigger project. Someone usingcheck_directory
might be curious to know why it's also deleting the directory they pass in. A better paradigm would be to callcheck_directory()
inremove_directory()
– esqew
Mar 8 at 17:38
@esqew That's a good point.
– thumbtackthief
Mar 8 at 17:39
@thumbtackthief - I edited my code but when calling the function i am getting a error - TypeError: check_directory() missing 1 required positional argument: 'path'
– Jason Lucas
Mar 8 at 19:30
@JasonLucas That means somewhere you're callingcheck_directory
without passing in an argument.
– thumbtackthief
Mar 8 at 19:54
to call the function "check_directory" to start checking for folders do i need to do anything other then check_directory()
– Jason Lucas
Mar 8 at 20:21
3
3
I've upvoted because you're answering the direct question. A bit out of scope of the topic at hand, but the method name
check_directory
becomes a bit mis-leading if this were to become part of a bigger project. Someone using check_directory
might be curious to know why it's also deleting the directory they pass in. A better paradigm would be to call check_directory()
in remove_directory()
– esqew
Mar 8 at 17:38
I've upvoted because you're answering the direct question. A bit out of scope of the topic at hand, but the method name
check_directory
becomes a bit mis-leading if this were to become part of a bigger project. Someone using check_directory
might be curious to know why it's also deleting the directory they pass in. A better paradigm would be to call check_directory()
in remove_directory()
– esqew
Mar 8 at 17:38
@esqew That's a good point.
– thumbtackthief
Mar 8 at 17:39
@esqew That's a good point.
– thumbtackthief
Mar 8 at 17:39
@thumbtackthief - I edited my code but when calling the function i am getting a error - TypeError: check_directory() missing 1 required positional argument: 'path'
– Jason Lucas
Mar 8 at 19:30
@thumbtackthief - I edited my code but when calling the function i am getting a error - TypeError: check_directory() missing 1 required positional argument: 'path'
– Jason Lucas
Mar 8 at 19:30
@JasonLucas That means somewhere you're calling
check_directory
without passing in an argument.– thumbtackthief
Mar 8 at 19:54
@JasonLucas That means somewhere you're calling
check_directory
without passing in an argument.– thumbtackthief
Mar 8 at 19:54
to call the function "check_directory" to start checking for folders do i need to do anything other then check_directory()
– Jason Lucas
Mar 8 at 20:21
to call the function "check_directory" to start checking for folders do i need to do anything other then check_directory()
– Jason Lucas
Mar 8 at 20:21
|
show 3 more comments
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%2f55068229%2fnewbie-question-breaking-a-function-into-two%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
"Do I have to mention the pathlist in both functions?" If you want to perform operations on an input, you sure do.
– esqew
Mar 8 at 17:34
I guess I was second guessing it was able to pull and use the pathlist from the other function or do the directories need to be listed in both spots?
– Jason Lucas
Mar 8 at 17:35
The advice to break this up is vaguely bogus. You should certainly not have identical code in many places.
– tripleee
Mar 8 at 17:38
While
M
is harmless, you should generally use double backslashes, forward slashes, or raw strings when passing around Windows file names.– tripleee
Mar 8 at 17:44
@tripleee The advice to break up the code is good; I just don't think OP did it in the best way.
– thumbtackthief
Mar 11 at 13:39