Datetime module - ValueError try/except won't work python 3
I have a programming homework assignment. Everything went smoothly until I reached a problem using Try/Except. If I type a valid datetime, the program will take it and it will move on, but if I use a valid datetime format, the exception won't react.
Here is my code:
import datetime
import csv
def get_stock_name(prompt,mode):
while True:
try:
return open(input(prompt) + ".csv")
except FileNotFoundError:
print("File not found. Please try again.")
except IOError:
print("There was an IOError opening the file. Please try again.")
def get_stock_date(prompt):
while True:
try:
return (input(prompt))
except TypeError:
print("Try again.")
except ValueError:
print("Try again.")
def get_stock_purchased(prompt):
while True:
try:
return (input(prompt))
except ValueError:
print("Try again.")
except TypeError:
print("try again.")
stock_name = get_stock_name("Enter the name of the file ==> ", "w")
stock_date = datetime.datetime.strptime(get_stock_date("Enter the stock purchase date ==> " , "%m/%d/%Y"))
stock_sold = datetime.datetime.strptime(get_stock_date("Enter the date you sold the stock ==>" , "%m/%d/%Y"))
stock_purchased = get_stock_purchased("How many stocks were purchased on start date ==>")
python function datetime try-except
|
show 4 more comments
I have a programming homework assignment. Everything went smoothly until I reached a problem using Try/Except. If I type a valid datetime, the program will take it and it will move on, but if I use a valid datetime format, the exception won't react.
Here is my code:
import datetime
import csv
def get_stock_name(prompt,mode):
while True:
try:
return open(input(prompt) + ".csv")
except FileNotFoundError:
print("File not found. Please try again.")
except IOError:
print("There was an IOError opening the file. Please try again.")
def get_stock_date(prompt):
while True:
try:
return (input(prompt))
except TypeError:
print("Try again.")
except ValueError:
print("Try again.")
def get_stock_purchased(prompt):
while True:
try:
return (input(prompt))
except ValueError:
print("Try again.")
except TypeError:
print("try again.")
stock_name = get_stock_name("Enter the name of the file ==> ", "w")
stock_date = datetime.datetime.strptime(get_stock_date("Enter the stock purchase date ==> " , "%m/%d/%Y"))
stock_sold = datetime.datetime.strptime(get_stock_date("Enter the date you sold the stock ==>" , "%m/%d/%Y"))
stock_purchased = get_stock_purchased("How many stocks were purchased on start date ==>")
python function datetime try-except
How could there be aTypeError
orValueError
if all you're doing isinput()
? And if it succeeds, it stops the function. I think you need to have another look atwhile
,return
, and possiblybreak
. Oh, and also at recursion. And saving references.
– TigerhawkT3
Apr 11 '16 at 4:26
The exception is raised in python 2? What do you input?
– tdelaney
Apr 11 '16 at 4:28
@TigerhawkT3 Thanks! And while I was messing around with it, it gave me two different errors (TypeError and ValueError) So that's why I made two exceptions.
– tokyolerd
Apr 11 '16 at 4:30
@tdelaney Python 3. If I input 5/10/2004 it will move on, but if I input anything else, It will give me a ValueError.
– tokyolerd
Apr 11 '16 at 4:31
Also, your parens are messed up - you're sending two arguments to the recursive call ofget_stock_date
and only one tostrptime
.
– TigerhawkT3
Apr 11 '16 at 4:32
|
show 4 more comments
I have a programming homework assignment. Everything went smoothly until I reached a problem using Try/Except. If I type a valid datetime, the program will take it and it will move on, but if I use a valid datetime format, the exception won't react.
Here is my code:
import datetime
import csv
def get_stock_name(prompt,mode):
while True:
try:
return open(input(prompt) + ".csv")
except FileNotFoundError:
print("File not found. Please try again.")
except IOError:
print("There was an IOError opening the file. Please try again.")
def get_stock_date(prompt):
while True:
try:
return (input(prompt))
except TypeError:
print("Try again.")
except ValueError:
print("Try again.")
def get_stock_purchased(prompt):
while True:
try:
return (input(prompt))
except ValueError:
print("Try again.")
except TypeError:
print("try again.")
stock_name = get_stock_name("Enter the name of the file ==> ", "w")
stock_date = datetime.datetime.strptime(get_stock_date("Enter the stock purchase date ==> " , "%m/%d/%Y"))
stock_sold = datetime.datetime.strptime(get_stock_date("Enter the date you sold the stock ==>" , "%m/%d/%Y"))
stock_purchased = get_stock_purchased("How many stocks were purchased on start date ==>")
python function datetime try-except
I have a programming homework assignment. Everything went smoothly until I reached a problem using Try/Except. If I type a valid datetime, the program will take it and it will move on, but if I use a valid datetime format, the exception won't react.
Here is my code:
import datetime
import csv
def get_stock_name(prompt,mode):
while True:
try:
return open(input(prompt) + ".csv")
except FileNotFoundError:
print("File not found. Please try again.")
except IOError:
print("There was an IOError opening the file. Please try again.")
def get_stock_date(prompt):
while True:
try:
return (input(prompt))
except TypeError:
print("Try again.")
except ValueError:
print("Try again.")
def get_stock_purchased(prompt):
while True:
try:
return (input(prompt))
except ValueError:
print("Try again.")
except TypeError:
print("try again.")
stock_name = get_stock_name("Enter the name of the file ==> ", "w")
stock_date = datetime.datetime.strptime(get_stock_date("Enter the stock purchase date ==> " , "%m/%d/%Y"))
stock_sold = datetime.datetime.strptime(get_stock_date("Enter the date you sold the stock ==>" , "%m/%d/%Y"))
stock_purchased = get_stock_purchased("How many stocks were purchased on start date ==>")
python function datetime try-except
python function datetime try-except
edited Apr 11 '16 at 4:38
tokyolerd
asked Apr 11 '16 at 4:22


tokyolerdtokyolerd
227
227
How could there be aTypeError
orValueError
if all you're doing isinput()
? And if it succeeds, it stops the function. I think you need to have another look atwhile
,return
, and possiblybreak
. Oh, and also at recursion. And saving references.
– TigerhawkT3
Apr 11 '16 at 4:26
The exception is raised in python 2? What do you input?
– tdelaney
Apr 11 '16 at 4:28
@TigerhawkT3 Thanks! And while I was messing around with it, it gave me two different errors (TypeError and ValueError) So that's why I made two exceptions.
– tokyolerd
Apr 11 '16 at 4:30
@tdelaney Python 3. If I input 5/10/2004 it will move on, but if I input anything else, It will give me a ValueError.
– tokyolerd
Apr 11 '16 at 4:31
Also, your parens are messed up - you're sending two arguments to the recursive call ofget_stock_date
and only one tostrptime
.
– TigerhawkT3
Apr 11 '16 at 4:32
|
show 4 more comments
How could there be aTypeError
orValueError
if all you're doing isinput()
? And if it succeeds, it stops the function. I think you need to have another look atwhile
,return
, and possiblybreak
. Oh, and also at recursion. And saving references.
– TigerhawkT3
Apr 11 '16 at 4:26
The exception is raised in python 2? What do you input?
– tdelaney
Apr 11 '16 at 4:28
@TigerhawkT3 Thanks! And while I was messing around with it, it gave me two different errors (TypeError and ValueError) So that's why I made two exceptions.
– tokyolerd
Apr 11 '16 at 4:30
@tdelaney Python 3. If I input 5/10/2004 it will move on, but if I input anything else, It will give me a ValueError.
– tokyolerd
Apr 11 '16 at 4:31
Also, your parens are messed up - you're sending two arguments to the recursive call ofget_stock_date
and only one tostrptime
.
– TigerhawkT3
Apr 11 '16 at 4:32
How could there be a
TypeError
or ValueError
if all you're doing is input()
? And if it succeeds, it stops the function. I think you need to have another look at while
, return
, and possibly break
. Oh, and also at recursion. And saving references.– TigerhawkT3
Apr 11 '16 at 4:26
How could there be a
TypeError
or ValueError
if all you're doing is input()
? And if it succeeds, it stops the function. I think you need to have another look at while
, return
, and possibly break
. Oh, and also at recursion. And saving references.– TigerhawkT3
Apr 11 '16 at 4:26
The exception is raised in python 2? What do you input?
– tdelaney
Apr 11 '16 at 4:28
The exception is raised in python 2? What do you input?
– tdelaney
Apr 11 '16 at 4:28
@TigerhawkT3 Thanks! And while I was messing around with it, it gave me two different errors (TypeError and ValueError) So that's why I made two exceptions.
– tokyolerd
Apr 11 '16 at 4:30
@TigerhawkT3 Thanks! And while I was messing around with it, it gave me two different errors (TypeError and ValueError) So that's why I made two exceptions.
– tokyolerd
Apr 11 '16 at 4:30
@tdelaney Python 3. If I input 5/10/2004 it will move on, but if I input anything else, It will give me a ValueError.
– tokyolerd
Apr 11 '16 at 4:31
@tdelaney Python 3. If I input 5/10/2004 it will move on, but if I input anything else, It will give me a ValueError.
– tokyolerd
Apr 11 '16 at 4:31
Also, your parens are messed up - you're sending two arguments to the recursive call of
get_stock_date
and only one to strptime
.– TigerhawkT3
Apr 11 '16 at 4:32
Also, your parens are messed up - you're sending two arguments to the recursive call of
get_stock_date
and only one to strptime
.– TigerhawkT3
Apr 11 '16 at 4:32
|
show 4 more comments
3 Answers
3
active
oldest
votes
To clarify Tigerhawk's initial comment: in order for the try-catch to handle TypeError or ValueError, you need to cast the input to datetime in the try statement.
import datetime
def get_stock_date(prompt):
while True:
try:
return datetime.datetime.strptime(input(prompt), "%m/%d/%Y")
except (ValueError, TypeError):
print("Try again.")
stock_date = get_stock_date("Enter the stock purchase date ==> ")
Additionally, your initial post had strange indentation that made it look like you were making a recursive call to get_stock_date, which caused confusion.
Lastly, you will need to use raw_input if you're using Python 2.
add a comment |
You currently have a loop that will immediately end the function and return a string in any situation I can think of off the top of my head, exceptions that (as just mentioned) I don't think will happen, a call to strptime
with the wrong number of arguments, and a recursive call to your function with the wrong number of arguments. And you never save or return a meaningful value. Maybe the recursive call just has wrong indentation? Anyway, you'll have to completely restructure your code, as most of it makes little sense:
import datetime
def get_stock_date(prompt):
while True:
d = input(prompt)
try:
d = datetime.datetime.strptime(d, "%m/%d/%Y")
except (ValueError, TypeError):
print("Try again.")
else:
return d
stock_date = get_stock_date("Enter the stock purchase date ==> ")
Thank you! I got a little confused with your explanation, but James kind of made it clearer.
– tokyolerd
Apr 11 '16 at 4:49
add a comment |
I think this is what you are looking for:
def get_stock_date(prompt):
try:
stock_date = datetime.datetime.strptime(prompt, "%m/%d/%Y")
return(stock_date)
except:
print("Try Again.")
prompt = input("Enter the stock purchase date ==> ")
get_stock_date(prompt)
get_stock_date(input("Enter the stock purchase date ==> " ))
You are converting the passedprompt
, which will fail, and then getting a new value with a bareinput()
call (without the "Enter the stock purchase..." prompt).
– TigerhawkT3
Apr 11 '16 at 4:56
Thanks. Yes, that was the idea. I wanted it to ask the user to enter a valid value.
– Shobeir
Apr 11 '16 at 5:18
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%2f36539814%2fdatetime-module-valueerror-try-except-wont-work-python-3%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
To clarify Tigerhawk's initial comment: in order for the try-catch to handle TypeError or ValueError, you need to cast the input to datetime in the try statement.
import datetime
def get_stock_date(prompt):
while True:
try:
return datetime.datetime.strptime(input(prompt), "%m/%d/%Y")
except (ValueError, TypeError):
print("Try again.")
stock_date = get_stock_date("Enter the stock purchase date ==> ")
Additionally, your initial post had strange indentation that made it look like you were making a recursive call to get_stock_date, which caused confusion.
Lastly, you will need to use raw_input if you're using Python 2.
add a comment |
To clarify Tigerhawk's initial comment: in order for the try-catch to handle TypeError or ValueError, you need to cast the input to datetime in the try statement.
import datetime
def get_stock_date(prompt):
while True:
try:
return datetime.datetime.strptime(input(prompt), "%m/%d/%Y")
except (ValueError, TypeError):
print("Try again.")
stock_date = get_stock_date("Enter the stock purchase date ==> ")
Additionally, your initial post had strange indentation that made it look like you were making a recursive call to get_stock_date, which caused confusion.
Lastly, you will need to use raw_input if you're using Python 2.
add a comment |
To clarify Tigerhawk's initial comment: in order for the try-catch to handle TypeError or ValueError, you need to cast the input to datetime in the try statement.
import datetime
def get_stock_date(prompt):
while True:
try:
return datetime.datetime.strptime(input(prompt), "%m/%d/%Y")
except (ValueError, TypeError):
print("Try again.")
stock_date = get_stock_date("Enter the stock purchase date ==> ")
Additionally, your initial post had strange indentation that made it look like you were making a recursive call to get_stock_date, which caused confusion.
Lastly, you will need to use raw_input if you're using Python 2.
To clarify Tigerhawk's initial comment: in order for the try-catch to handle TypeError or ValueError, you need to cast the input to datetime in the try statement.
import datetime
def get_stock_date(prompt):
while True:
try:
return datetime.datetime.strptime(input(prompt), "%m/%d/%Y")
except (ValueError, TypeError):
print("Try again.")
stock_date = get_stock_date("Enter the stock purchase date ==> ")
Additionally, your initial post had strange indentation that made it look like you were making a recursive call to get_stock_date, which caused confusion.
Lastly, you will need to use raw_input if you're using Python 2.
answered Apr 11 '16 at 4:46
James BuergerJames Buerger
1946
1946
add a comment |
add a comment |
You currently have a loop that will immediately end the function and return a string in any situation I can think of off the top of my head, exceptions that (as just mentioned) I don't think will happen, a call to strptime
with the wrong number of arguments, and a recursive call to your function with the wrong number of arguments. And you never save or return a meaningful value. Maybe the recursive call just has wrong indentation? Anyway, you'll have to completely restructure your code, as most of it makes little sense:
import datetime
def get_stock_date(prompt):
while True:
d = input(prompt)
try:
d = datetime.datetime.strptime(d, "%m/%d/%Y")
except (ValueError, TypeError):
print("Try again.")
else:
return d
stock_date = get_stock_date("Enter the stock purchase date ==> ")
Thank you! I got a little confused with your explanation, but James kind of made it clearer.
– tokyolerd
Apr 11 '16 at 4:49
add a comment |
You currently have a loop that will immediately end the function and return a string in any situation I can think of off the top of my head, exceptions that (as just mentioned) I don't think will happen, a call to strptime
with the wrong number of arguments, and a recursive call to your function with the wrong number of arguments. And you never save or return a meaningful value. Maybe the recursive call just has wrong indentation? Anyway, you'll have to completely restructure your code, as most of it makes little sense:
import datetime
def get_stock_date(prompt):
while True:
d = input(prompt)
try:
d = datetime.datetime.strptime(d, "%m/%d/%Y")
except (ValueError, TypeError):
print("Try again.")
else:
return d
stock_date = get_stock_date("Enter the stock purchase date ==> ")
Thank you! I got a little confused with your explanation, but James kind of made it clearer.
– tokyolerd
Apr 11 '16 at 4:49
add a comment |
You currently have a loop that will immediately end the function and return a string in any situation I can think of off the top of my head, exceptions that (as just mentioned) I don't think will happen, a call to strptime
with the wrong number of arguments, and a recursive call to your function with the wrong number of arguments. And you never save or return a meaningful value. Maybe the recursive call just has wrong indentation? Anyway, you'll have to completely restructure your code, as most of it makes little sense:
import datetime
def get_stock_date(prompt):
while True:
d = input(prompt)
try:
d = datetime.datetime.strptime(d, "%m/%d/%Y")
except (ValueError, TypeError):
print("Try again.")
else:
return d
stock_date = get_stock_date("Enter the stock purchase date ==> ")
You currently have a loop that will immediately end the function and return a string in any situation I can think of off the top of my head, exceptions that (as just mentioned) I don't think will happen, a call to strptime
with the wrong number of arguments, and a recursive call to your function with the wrong number of arguments. And you never save or return a meaningful value. Maybe the recursive call just has wrong indentation? Anyway, you'll have to completely restructure your code, as most of it makes little sense:
import datetime
def get_stock_date(prompt):
while True:
d = input(prompt)
try:
d = datetime.datetime.strptime(d, "%m/%d/%Y")
except (ValueError, TypeError):
print("Try again.")
else:
return d
stock_date = get_stock_date("Enter the stock purchase date ==> ")
answered Apr 11 '16 at 4:38


TigerhawkT3TigerhawkT3
39.7k53566
39.7k53566
Thank you! I got a little confused with your explanation, but James kind of made it clearer.
– tokyolerd
Apr 11 '16 at 4:49
add a comment |
Thank you! I got a little confused with your explanation, but James kind of made it clearer.
– tokyolerd
Apr 11 '16 at 4:49
Thank you! I got a little confused with your explanation, but James kind of made it clearer.
– tokyolerd
Apr 11 '16 at 4:49
Thank you! I got a little confused with your explanation, but James kind of made it clearer.
– tokyolerd
Apr 11 '16 at 4:49
add a comment |
I think this is what you are looking for:
def get_stock_date(prompt):
try:
stock_date = datetime.datetime.strptime(prompt, "%m/%d/%Y")
return(stock_date)
except:
print("Try Again.")
prompt = input("Enter the stock purchase date ==> ")
get_stock_date(prompt)
get_stock_date(input("Enter the stock purchase date ==> " ))
You are converting the passedprompt
, which will fail, and then getting a new value with a bareinput()
call (without the "Enter the stock purchase..." prompt).
– TigerhawkT3
Apr 11 '16 at 4:56
Thanks. Yes, that was the idea. I wanted it to ask the user to enter a valid value.
– Shobeir
Apr 11 '16 at 5:18
add a comment |
I think this is what you are looking for:
def get_stock_date(prompt):
try:
stock_date = datetime.datetime.strptime(prompt, "%m/%d/%Y")
return(stock_date)
except:
print("Try Again.")
prompt = input("Enter the stock purchase date ==> ")
get_stock_date(prompt)
get_stock_date(input("Enter the stock purchase date ==> " ))
You are converting the passedprompt
, which will fail, and then getting a new value with a bareinput()
call (without the "Enter the stock purchase..." prompt).
– TigerhawkT3
Apr 11 '16 at 4:56
Thanks. Yes, that was the idea. I wanted it to ask the user to enter a valid value.
– Shobeir
Apr 11 '16 at 5:18
add a comment |
I think this is what you are looking for:
def get_stock_date(prompt):
try:
stock_date = datetime.datetime.strptime(prompt, "%m/%d/%Y")
return(stock_date)
except:
print("Try Again.")
prompt = input("Enter the stock purchase date ==> ")
get_stock_date(prompt)
get_stock_date(input("Enter the stock purchase date ==> " ))
I think this is what you are looking for:
def get_stock_date(prompt):
try:
stock_date = datetime.datetime.strptime(prompt, "%m/%d/%Y")
return(stock_date)
except:
print("Try Again.")
prompt = input("Enter the stock purchase date ==> ")
get_stock_date(prompt)
get_stock_date(input("Enter the stock purchase date ==> " ))
edited Apr 11 '16 at 5:15
answered Apr 11 '16 at 4:45


ShobeirShobeir
977
977
You are converting the passedprompt
, which will fail, and then getting a new value with a bareinput()
call (without the "Enter the stock purchase..." prompt).
– TigerhawkT3
Apr 11 '16 at 4:56
Thanks. Yes, that was the idea. I wanted it to ask the user to enter a valid value.
– Shobeir
Apr 11 '16 at 5:18
add a comment |
You are converting the passedprompt
, which will fail, and then getting a new value with a bareinput()
call (without the "Enter the stock purchase..." prompt).
– TigerhawkT3
Apr 11 '16 at 4:56
Thanks. Yes, that was the idea. I wanted it to ask the user to enter a valid value.
– Shobeir
Apr 11 '16 at 5:18
You are converting the passed
prompt
, which will fail, and then getting a new value with a bare input()
call (without the "Enter the stock purchase..." prompt).– TigerhawkT3
Apr 11 '16 at 4:56
You are converting the passed
prompt
, which will fail, and then getting a new value with a bare input()
call (without the "Enter the stock purchase..." prompt).– TigerhawkT3
Apr 11 '16 at 4:56
Thanks. Yes, that was the idea. I wanted it to ask the user to enter a valid value.
– Shobeir
Apr 11 '16 at 5:18
Thanks. Yes, that was the idea. I wanted it to ask the user to enter a valid value.
– Shobeir
Apr 11 '16 at 5:18
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%2f36539814%2fdatetime-module-valueerror-try-except-wont-work-python-3%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
How could there be a
TypeError
orValueError
if all you're doing isinput()
? And if it succeeds, it stops the function. I think you need to have another look atwhile
,return
, and possiblybreak
. Oh, and also at recursion. And saving references.– TigerhawkT3
Apr 11 '16 at 4:26
The exception is raised in python 2? What do you input?
– tdelaney
Apr 11 '16 at 4:28
@TigerhawkT3 Thanks! And while I was messing around with it, it gave me two different errors (TypeError and ValueError) So that's why I made two exceptions.
– tokyolerd
Apr 11 '16 at 4:30
@tdelaney Python 3. If I input 5/10/2004 it will move on, but if I input anything else, It will give me a ValueError.
– tokyolerd
Apr 11 '16 at 4:31
Also, your parens are messed up - you're sending two arguments to the recursive call of
get_stock_date
and only one tostrptime
.– TigerhawkT3
Apr 11 '16 at 4:32