Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identity Crisis! variable assignment using strftime fails comparison test. #54170

Closed
BillHawkes mannequin opened this issue Sep 27, 2010 · 3 comments
Closed

Identity Crisis! variable assignment using strftime fails comparison test. #54170

BillHawkes mannequin opened this issue Sep 27, 2010 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@BillHawkes
Copy link
Mannequin

BillHawkes mannequin commented Sep 27, 2010

BPO 9961

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2010-09-27.15:31:52.714>
created_at = <Date 2010-09-27.15:30:22.456>
labels = ['interpreter-core', 'type-bug', 'invalid']
title = 'Identity Crisis! variable assignment using strftime fails comparison test.'
updated_at = <Date 2010-09-28.08:18:26.694>
user = 'https://bugs.python.org/BillHawkes'

bugs.python.org fields:

activity = <Date 2010-09-28.08:18:26.694>
actor = 'BillHawkes'
assignee = 'none'
closed = True
closed_date = <Date 2010-09-27.15:31:52.714>
closer = 'exarkun'
components = ['Interpreter Core']
creation = <Date 2010-09-27.15:30:22.456>
creator = 'BillHawkes'
dependencies = []
files = []
hgrepos = []
issue_num = 9961
keywords = []
message_count = 3.0
messages = ['117449', '117450', '117509']
nosy_count = 2.0
nosy_names = ['exarkun', 'BillHawkes']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue9961'
versions = ['Python 3.1']

@BillHawkes
Copy link
Mannequin Author

BillHawkes mannequin commented Sep 27, 2010

See below. When variable assignment is used with strftime for the day of the week, it fails comparison checks for the days of the week. Even when using the str() function it still fails. Manual entry of variable assignment is required for a successful comparison. This pretty well defeats the purpose of computer programming (automation). There seems to be a real identity crisis here!

$ python3
Python 3.0rc1+ (py3k, Oct 28 2008, 09:23:29) 
[GCC 4.3.2] on linux2
>>> import time
>>> from datetime import date
>>> today = date.today()
>>> print("This line will always print")
This line will always print
>>> myday = today.fromordinal(today.toordinal() - 31)
>>> printthis = myday.strftime("%m-%d-%y. %d %b %Y is a %A on the %d day of %B.")
>>> print("%s" % printthis)
08-27-10. 27 Aug 2010 is a Friday on the 27 day of August.
>>> # dow is Day Of Week variable
... dow = myday.strftime("%A")
>>> chkval = dow
>>> dow is chkval
True
>>> print("dow is %s" % dow)
dow is Friday
>>> print("chkval is %s" % chkval)
chkval is Friday
>>> print("%s" % dow)
Friday
>>> print("%s" % chkval)
Friday
>>> dow is chkval
True
>>> if dow is 'Sunday':
...    cntbck = 0
... elif dow is 'Monday':
...    cntbck = 1
... elif dow is 'Tuesday':
...    cntbck = 2
... elif dow is 'Wednesday':
...    cntbck = 3
... elif dow is 'Thursday':
...    cntbck = 4
... elif dow is 'Friday':
...    cntbck = 5
... elif dow is 'Saturday':
...    cntbck = 6
... else:
...    cntbck = 'undefined'
...    print("What day is it? It is %s" % dow)
... 
What day is it? It is Friday
>>> print('finished with script')
finished with script
>>> dow is 'Friday'
False
>>> dow = 'Friday'
>>> dow is 'Friday'
True
>>> chkval
'Friday'
>>> dow
'Friday'
>>> chkval is dow
False
>>>  chkval is 'Friday'
False
>>> chkval
'Friday'
>>> chkval = str(chkval)
>>> chkval
'Friday'
>>> chkval is 'Friday'
False
>>> cntbck
'undefined'
>>>

@BillHawkes BillHawkes mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Sep 27, 2010
@exarkun
Copy link
Mannequin

exarkun mannequin commented Sep 27, 2010

You mistakenly used "is" for these comparisons, rather than "==". The strftime involvement is a red herring. The real problem is the use of an /identity/ comparison rather than an /equality/ comparison.

@exarkun exarkun mannequin closed this as completed Sep 27, 2010
@exarkun exarkun mannequin added the invalid label Sep 27, 2010
@BillHawkes
Copy link
Mannequin Author

BillHawkes mannequin commented Sep 28, 2010

Yes, it is working now. Thanks for the timely response.

In looking at the tutorial, the only "strings" used with boolean operators ("<" | ">" | "==" | ">=" | "<=" | "!=") were strings of the numeric variety. I saw no examples using words. I know the datetime module has a function for enumerating the days of the week, but it starts with Monday and ends with Sunday. I needed to start with Sunday and end with Saturday. The first thing I found for checking letter-filled strings was the "is" operator.

Perhaps a brief example of word comparisons in the tutorial would be useful. I know it would have helped me.

I can't say I have a clear understanding of the difference between the "is" and "==" operators, but I can accept that there apparently is some difference and there are situations where that difference matters. Again, thanks for the quick response.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants