View, append, write, or delete a file
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
I am just wondering if I need to refactor this code into smaller functions, or if it is OK as it is. I know that code should be as clean as possible, but I don't see a need to declare a new function every time I have more than 5 lines of code. Anyways please tell me what you think.
The code itself is used for file handling. It allows a user to create, append, read, or delete files. This is all based on user input.
def option_two():
#####################################################################
# Option 2, File Creation/Editing: #
# Asks the user what they would like to do #
# They can view, append, write, or delete a file #
#####################################################################
path_exists = bool
try:
USER_INPUT = int(input("""
What would you like to do?n
1)Read a file
2)Append to an existing file
3)Write to a new file
4)Delete a file
5)Go back/n
>>> """))
if USER_INPUT == 1:
#View a file
user_message(1)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
path_exists = check_path("//home//alpha//Desktop//0".format(USER_INPUT), path_exists)
if path_exists:
open_file("//home//alpha//Desktop//0".format(USER_INPUT))
else:
option_two()
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
path_exists = check_path(USER_INPUT, path_exists)
if path_exists:
open_file(USER_INPUT)
else:
option_two()
else:
print("Enter y or n only")
option_two()
return
elif USER_INPUT == 2:
#append to a file
user_message(2)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
path_exists = check_path("//home//alpha//Desktop//0".format(USER_INPUT), path_exists)
if path_exists:
append_file("//home//alpha//Desktop//0".format(USER_INPUT))
else:
option_two()
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
if path_exists:
append_file(USER_INPUT)
else:
option_two()
else:
print("Enter a y or n only")
option_two()
return
elif USER_INPUT == 3:
#Write a new file
user_message(3)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
write_file("//home//alpha//Desktop//0".format(USER_INPUT))
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
write_file(USER_INPUT)
else:
print("Enter a y or n only")
option_two()
return
elif USER_INPUT == 4:
#Delete a file
user_message(4)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
delete_path("//home//alpha//Desktop//0".format(USER_INPUT), path_exists)
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
delete_path(USER_INPUT, path_exists)
else:
print("Enter a y or n only")
option_two()
return
elif USER_INPUT == 5:
user_message(5)
print("Moving back to main")
return
except(ValueError):
print("Invalid input, try againnn")
option_two()
python python-3.x file
New contributor
add a comment |Â
up vote
3
down vote
favorite
I am just wondering if I need to refactor this code into smaller functions, or if it is OK as it is. I know that code should be as clean as possible, but I don't see a need to declare a new function every time I have more than 5 lines of code. Anyways please tell me what you think.
The code itself is used for file handling. It allows a user to create, append, read, or delete files. This is all based on user input.
def option_two():
#####################################################################
# Option 2, File Creation/Editing: #
# Asks the user what they would like to do #
# They can view, append, write, or delete a file #
#####################################################################
path_exists = bool
try:
USER_INPUT = int(input("""
What would you like to do?n
1)Read a file
2)Append to an existing file
3)Write to a new file
4)Delete a file
5)Go back/n
>>> """))
if USER_INPUT == 1:
#View a file
user_message(1)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
path_exists = check_path("//home//alpha//Desktop//0".format(USER_INPUT), path_exists)
if path_exists:
open_file("//home//alpha//Desktop//0".format(USER_INPUT))
else:
option_two()
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
path_exists = check_path(USER_INPUT, path_exists)
if path_exists:
open_file(USER_INPUT)
else:
option_two()
else:
print("Enter y or n only")
option_two()
return
elif USER_INPUT == 2:
#append to a file
user_message(2)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
path_exists = check_path("//home//alpha//Desktop//0".format(USER_INPUT), path_exists)
if path_exists:
append_file("//home//alpha//Desktop//0".format(USER_INPUT))
else:
option_two()
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
if path_exists:
append_file(USER_INPUT)
else:
option_two()
else:
print("Enter a y or n only")
option_two()
return
elif USER_INPUT == 3:
#Write a new file
user_message(3)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
write_file("//home//alpha//Desktop//0".format(USER_INPUT))
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
write_file(USER_INPUT)
else:
print("Enter a y or n only")
option_two()
return
elif USER_INPUT == 4:
#Delete a file
user_message(4)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
delete_path("//home//alpha//Desktop//0".format(USER_INPUT), path_exists)
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
delete_path(USER_INPUT, path_exists)
else:
print("Enter a y or n only")
option_two()
return
elif USER_INPUT == 5:
user_message(5)
print("Moving back to main")
return
except(ValueError):
print("Invalid input, try againnn")
option_two()
python python-3.x file
New contributor
This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. The current title states your concerns about the code; it needs an edit to simply state the task; see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
â Toby Speight
2 hours ago
1
@TobySpeight there are an abundance of comments in the code that state exactly what it is doing. My question was clear, should it be refactored into smaller chunks. I am looking for constructive criticism.
â Robotica
2 hours ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I am just wondering if I need to refactor this code into smaller functions, or if it is OK as it is. I know that code should be as clean as possible, but I don't see a need to declare a new function every time I have more than 5 lines of code. Anyways please tell me what you think.
The code itself is used for file handling. It allows a user to create, append, read, or delete files. This is all based on user input.
def option_two():
#####################################################################
# Option 2, File Creation/Editing: #
# Asks the user what they would like to do #
# They can view, append, write, or delete a file #
#####################################################################
path_exists = bool
try:
USER_INPUT = int(input("""
What would you like to do?n
1)Read a file
2)Append to an existing file
3)Write to a new file
4)Delete a file
5)Go back/n
>>> """))
if USER_INPUT == 1:
#View a file
user_message(1)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
path_exists = check_path("//home//alpha//Desktop//0".format(USER_INPUT), path_exists)
if path_exists:
open_file("//home//alpha//Desktop//0".format(USER_INPUT))
else:
option_two()
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
path_exists = check_path(USER_INPUT, path_exists)
if path_exists:
open_file(USER_INPUT)
else:
option_two()
else:
print("Enter y or n only")
option_two()
return
elif USER_INPUT == 2:
#append to a file
user_message(2)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
path_exists = check_path("//home//alpha//Desktop//0".format(USER_INPUT), path_exists)
if path_exists:
append_file("//home//alpha//Desktop//0".format(USER_INPUT))
else:
option_two()
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
if path_exists:
append_file(USER_INPUT)
else:
option_two()
else:
print("Enter a y or n only")
option_two()
return
elif USER_INPUT == 3:
#Write a new file
user_message(3)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
write_file("//home//alpha//Desktop//0".format(USER_INPUT))
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
write_file(USER_INPUT)
else:
print("Enter a y or n only")
option_two()
return
elif USER_INPUT == 4:
#Delete a file
user_message(4)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
delete_path("//home//alpha//Desktop//0".format(USER_INPUT), path_exists)
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
delete_path(USER_INPUT, path_exists)
else:
print("Enter a y or n only")
option_two()
return
elif USER_INPUT == 5:
user_message(5)
print("Moving back to main")
return
except(ValueError):
print("Invalid input, try againnn")
option_two()
python python-3.x file
New contributor
I am just wondering if I need to refactor this code into smaller functions, or if it is OK as it is. I know that code should be as clean as possible, but I don't see a need to declare a new function every time I have more than 5 lines of code. Anyways please tell me what you think.
The code itself is used for file handling. It allows a user to create, append, read, or delete files. This is all based on user input.
def option_two():
#####################################################################
# Option 2, File Creation/Editing: #
# Asks the user what they would like to do #
# They can view, append, write, or delete a file #
#####################################################################
path_exists = bool
try:
USER_INPUT = int(input("""
What would you like to do?n
1)Read a file
2)Append to an existing file
3)Write to a new file
4)Delete a file
5)Go back/n
>>> """))
if USER_INPUT == 1:
#View a file
user_message(1)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
path_exists = check_path("//home//alpha//Desktop//0".format(USER_INPUT), path_exists)
if path_exists:
open_file("//home//alpha//Desktop//0".format(USER_INPUT))
else:
option_two()
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
path_exists = check_path(USER_INPUT, path_exists)
if path_exists:
open_file(USER_INPUT)
else:
option_two()
else:
print("Enter y or n only")
option_two()
return
elif USER_INPUT == 2:
#append to a file
user_message(2)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
path_exists = check_path("//home//alpha//Desktop//0".format(USER_INPUT), path_exists)
if path_exists:
append_file("//home//alpha//Desktop//0".format(USER_INPUT))
else:
option_two()
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
if path_exists:
append_file(USER_INPUT)
else:
option_two()
else:
print("Enter a y or n only")
option_two()
return
elif USER_INPUT == 3:
#Write a new file
user_message(3)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
write_file("//home//alpha//Desktop//0".format(USER_INPUT))
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
write_file(USER_INPUT)
else:
print("Enter a y or n only")
option_two()
return
elif USER_INPUT == 4:
#Delete a file
user_message(4)
USER_INPUT = input("Is this file located on the desktop? y/n")
if USER_INPUT == "y":
USER_INPUT = input("What is the name of the file?")
delete_path("//home//alpha//Desktop//0".format(USER_INPUT), path_exists)
elif USER_INPUT == "n":
USER_INPUT = input("Enter the full path for the file")
delete_path(USER_INPUT, path_exists)
else:
print("Enter a y or n only")
option_two()
return
elif USER_INPUT == 5:
user_message(5)
print("Moving back to main")
return
except(ValueError):
print("Invalid input, try againnn")
option_two()
python python-3.x file
python python-3.x file
New contributor
New contributor
edited 1 hour ago
Graipher
21.2k43183
21.2k43183
New contributor
asked 2 hours ago
Robotica
235
235
New contributor
New contributor
This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. The current title states your concerns about the code; it needs an edit to simply state the task; see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
â Toby Speight
2 hours ago
1
@TobySpeight there are an abundance of comments in the code that state exactly what it is doing. My question was clear, should it be refactored into smaller chunks. I am looking for constructive criticism.
â Robotica
2 hours ago
add a comment |Â
This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. The current title states your concerns about the code; it needs an edit to simply state the task; see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
â Toby Speight
2 hours ago
1
@TobySpeight there are an abundance of comments in the code that state exactly what it is doing. My question was clear, should it be refactored into smaller chunks. I am looking for constructive criticism.
â Robotica
2 hours ago
This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. The current title states your concerns about the code; it needs an edit to simply state the task; see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
â Toby Speight
2 hours ago
This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. The current title states your concerns about the code; it needs an edit to simply state the task; see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
â Toby Speight
2 hours ago
1
1
@TobySpeight there are an abundance of comments in the code that state exactly what it is doing. My question was clear, should it be refactored into smaller chunks. I am looking for constructive criticism.
â Robotica
2 hours ago
@TobySpeight there are an abundance of comments in the code that state exactly what it is doing. My question was clear, should it be refactored into smaller chunks. I am looking for constructive criticism.
â Robotica
2 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
In my opinion this can be greatly simplified. First, there is no need for this to be a recursive function (which are seldom the best choice in Python due to the maximum recursion depth). Just make it an infinite loop.
Second, all of your options are almost the same. You ask if the file is on the desktop, then for the file name/path and then do something with that path. So, just define a function for that first part:
USERNAME = "alpha"
def ask_file_name():
user_input = input("Is this file located on the desktop? y/n")
if user_input.lower() == "y":
path = "/home//Desktop/"
return path.format(USERNAME, input("What is the name of the file?"))
return input("Enter the full path for the file")
Then your main function becomes rather short:
MENU = """
What would you like to do?
1)Read a file
2)Append to an existing file
3)Write to a new file
4)Delete a file
5)Go back/n
>>> """
def option_two():
"""Option 2, File Creation/Editing:
Asks the user what they would like to do
They can view, append, write, or delete a file
"""
while True:
try:
user_input = int(input(MENU))
except ValueError:
print("Invalid input, try againnn")
continue
user_message(user_input)
path = ask_file_name()
if user_input == 1:
#View a file
if check_path(path):
open_file(path)
else:
continue
elif user_input == 2:
#append to a file
if check_path(path):
append_file(path)
else:
continue
elif user_input == 3:
#Write a new file
write_file(path)
elif user_input == 4:
#Delete a file
delete_path(path)
print("Moving back to main")
return
Note that check_path
should work without having a boolean variable passed in and delete_path
should probably just call check_path
internally (or use try...except
).
I also changed your comment under the function definition to conform to Python's docstring convention.
Thanks for the good info. Idk why I didn't think about putting it in a loop. This isn't exactly related but I've never heard of a max recursion depth?
â Robotica
37 mins ago
@Robotica: Have a look here: stackoverflow.com/questions/3323001/⦠By default CPython stops after 1000 levels of recursion (which will be a bit hard to reach in a menu, but is not impossible...)
â Graipher
35 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
In my opinion this can be greatly simplified. First, there is no need for this to be a recursive function (which are seldom the best choice in Python due to the maximum recursion depth). Just make it an infinite loop.
Second, all of your options are almost the same. You ask if the file is on the desktop, then for the file name/path and then do something with that path. So, just define a function for that first part:
USERNAME = "alpha"
def ask_file_name():
user_input = input("Is this file located on the desktop? y/n")
if user_input.lower() == "y":
path = "/home//Desktop/"
return path.format(USERNAME, input("What is the name of the file?"))
return input("Enter the full path for the file")
Then your main function becomes rather short:
MENU = """
What would you like to do?
1)Read a file
2)Append to an existing file
3)Write to a new file
4)Delete a file
5)Go back/n
>>> """
def option_two():
"""Option 2, File Creation/Editing:
Asks the user what they would like to do
They can view, append, write, or delete a file
"""
while True:
try:
user_input = int(input(MENU))
except ValueError:
print("Invalid input, try againnn")
continue
user_message(user_input)
path = ask_file_name()
if user_input == 1:
#View a file
if check_path(path):
open_file(path)
else:
continue
elif user_input == 2:
#append to a file
if check_path(path):
append_file(path)
else:
continue
elif user_input == 3:
#Write a new file
write_file(path)
elif user_input == 4:
#Delete a file
delete_path(path)
print("Moving back to main")
return
Note that check_path
should work without having a boolean variable passed in and delete_path
should probably just call check_path
internally (or use try...except
).
I also changed your comment under the function definition to conform to Python's docstring convention.
Thanks for the good info. Idk why I didn't think about putting it in a loop. This isn't exactly related but I've never heard of a max recursion depth?
â Robotica
37 mins ago
@Robotica: Have a look here: stackoverflow.com/questions/3323001/⦠By default CPython stops after 1000 levels of recursion (which will be a bit hard to reach in a menu, but is not impossible...)
â Graipher
35 mins ago
add a comment |Â
up vote
3
down vote
accepted
In my opinion this can be greatly simplified. First, there is no need for this to be a recursive function (which are seldom the best choice in Python due to the maximum recursion depth). Just make it an infinite loop.
Second, all of your options are almost the same. You ask if the file is on the desktop, then for the file name/path and then do something with that path. So, just define a function for that first part:
USERNAME = "alpha"
def ask_file_name():
user_input = input("Is this file located on the desktop? y/n")
if user_input.lower() == "y":
path = "/home//Desktop/"
return path.format(USERNAME, input("What is the name of the file?"))
return input("Enter the full path for the file")
Then your main function becomes rather short:
MENU = """
What would you like to do?
1)Read a file
2)Append to an existing file
3)Write to a new file
4)Delete a file
5)Go back/n
>>> """
def option_two():
"""Option 2, File Creation/Editing:
Asks the user what they would like to do
They can view, append, write, or delete a file
"""
while True:
try:
user_input = int(input(MENU))
except ValueError:
print("Invalid input, try againnn")
continue
user_message(user_input)
path = ask_file_name()
if user_input == 1:
#View a file
if check_path(path):
open_file(path)
else:
continue
elif user_input == 2:
#append to a file
if check_path(path):
append_file(path)
else:
continue
elif user_input == 3:
#Write a new file
write_file(path)
elif user_input == 4:
#Delete a file
delete_path(path)
print("Moving back to main")
return
Note that check_path
should work without having a boolean variable passed in and delete_path
should probably just call check_path
internally (or use try...except
).
I also changed your comment under the function definition to conform to Python's docstring convention.
Thanks for the good info. Idk why I didn't think about putting it in a loop. This isn't exactly related but I've never heard of a max recursion depth?
â Robotica
37 mins ago
@Robotica: Have a look here: stackoverflow.com/questions/3323001/⦠By default CPython stops after 1000 levels of recursion (which will be a bit hard to reach in a menu, but is not impossible...)
â Graipher
35 mins ago
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
In my opinion this can be greatly simplified. First, there is no need for this to be a recursive function (which are seldom the best choice in Python due to the maximum recursion depth). Just make it an infinite loop.
Second, all of your options are almost the same. You ask if the file is on the desktop, then for the file name/path and then do something with that path. So, just define a function for that first part:
USERNAME = "alpha"
def ask_file_name():
user_input = input("Is this file located on the desktop? y/n")
if user_input.lower() == "y":
path = "/home//Desktop/"
return path.format(USERNAME, input("What is the name of the file?"))
return input("Enter the full path for the file")
Then your main function becomes rather short:
MENU = """
What would you like to do?
1)Read a file
2)Append to an existing file
3)Write to a new file
4)Delete a file
5)Go back/n
>>> """
def option_two():
"""Option 2, File Creation/Editing:
Asks the user what they would like to do
They can view, append, write, or delete a file
"""
while True:
try:
user_input = int(input(MENU))
except ValueError:
print("Invalid input, try againnn")
continue
user_message(user_input)
path = ask_file_name()
if user_input == 1:
#View a file
if check_path(path):
open_file(path)
else:
continue
elif user_input == 2:
#append to a file
if check_path(path):
append_file(path)
else:
continue
elif user_input == 3:
#Write a new file
write_file(path)
elif user_input == 4:
#Delete a file
delete_path(path)
print("Moving back to main")
return
Note that check_path
should work without having a boolean variable passed in and delete_path
should probably just call check_path
internally (or use try...except
).
I also changed your comment under the function definition to conform to Python's docstring convention.
In my opinion this can be greatly simplified. First, there is no need for this to be a recursive function (which are seldom the best choice in Python due to the maximum recursion depth). Just make it an infinite loop.
Second, all of your options are almost the same. You ask if the file is on the desktop, then for the file name/path and then do something with that path. So, just define a function for that first part:
USERNAME = "alpha"
def ask_file_name():
user_input = input("Is this file located on the desktop? y/n")
if user_input.lower() == "y":
path = "/home//Desktop/"
return path.format(USERNAME, input("What is the name of the file?"))
return input("Enter the full path for the file")
Then your main function becomes rather short:
MENU = """
What would you like to do?
1)Read a file
2)Append to an existing file
3)Write to a new file
4)Delete a file
5)Go back/n
>>> """
def option_two():
"""Option 2, File Creation/Editing:
Asks the user what they would like to do
They can view, append, write, or delete a file
"""
while True:
try:
user_input = int(input(MENU))
except ValueError:
print("Invalid input, try againnn")
continue
user_message(user_input)
path = ask_file_name()
if user_input == 1:
#View a file
if check_path(path):
open_file(path)
else:
continue
elif user_input == 2:
#append to a file
if check_path(path):
append_file(path)
else:
continue
elif user_input == 3:
#Write a new file
write_file(path)
elif user_input == 4:
#Delete a file
delete_path(path)
print("Moving back to main")
return
Note that check_path
should work without having a boolean variable passed in and delete_path
should probably just call check_path
internally (or use try...except
).
I also changed your comment under the function definition to conform to Python's docstring convention.
edited 38 mins ago
answered 46 mins ago
Graipher
21.2k43183
21.2k43183
Thanks for the good info. Idk why I didn't think about putting it in a loop. This isn't exactly related but I've never heard of a max recursion depth?
â Robotica
37 mins ago
@Robotica: Have a look here: stackoverflow.com/questions/3323001/⦠By default CPython stops after 1000 levels of recursion (which will be a bit hard to reach in a menu, but is not impossible...)
â Graipher
35 mins ago
add a comment |Â
Thanks for the good info. Idk why I didn't think about putting it in a loop. This isn't exactly related but I've never heard of a max recursion depth?
â Robotica
37 mins ago
@Robotica: Have a look here: stackoverflow.com/questions/3323001/⦠By default CPython stops after 1000 levels of recursion (which will be a bit hard to reach in a menu, but is not impossible...)
â Graipher
35 mins ago
Thanks for the good info. Idk why I didn't think about putting it in a loop. This isn't exactly related but I've never heard of a max recursion depth?
â Robotica
37 mins ago
Thanks for the good info. Idk why I didn't think about putting it in a loop. This isn't exactly related but I've never heard of a max recursion depth?
â Robotica
37 mins ago
@Robotica: Have a look here: stackoverflow.com/questions/3323001/⦠By default CPython stops after 1000 levels of recursion (which will be a bit hard to reach in a menu, but is not impossible...)
â Graipher
35 mins ago
@Robotica: Have a look here: stackoverflow.com/questions/3323001/⦠By default CPython stops after 1000 levels of recursion (which will be a bit hard to reach in a menu, but is not impossible...)
â Graipher
35 mins ago
add a comment |Â
Robotica is a new contributor. Be nice, and check out our Code of Conduct.
Robotica is a new contributor. Be nice, and check out our Code of Conduct.
Robotica is a new contributor. Be nice, and check out our Code of Conduct.
Robotica is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f203693%2fview-append-write-or-delete-a-file%23new-answer', 'question_page');
);
Post as a guest
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
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
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
This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. The current title states your concerns about the code; it needs an edit to simply state the task; see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
â Toby Speight
2 hours ago
1
@TobySpeight there are an abundance of comments in the code that state exactly what it is doing. My question was clear, should it be refactored into smaller chunks. I am looking for constructive criticism.
â Robotica
2 hours ago