A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2005-December/059219.html below:

[Python-Dev] Keep default comparisons - or add a second set?

[Python-Dev] Keep default comparisons - or add a second set? [Python-Dev] Keep default comparisons - or add a second set?Noam Raphael noamraph at gmail.com
Wed Dec 28 23:11:24 CET 2005
On 12/29/05, Robert Brewer <fumanchu at amor.org> wrote:
>
>  Just to keep myself sane...
>
>      def date_range(start=None, end=None):
>          if start == None:
>              start = datetime.date.today()
>          if end == None:
>              end = datetime.date.today()
>          return end - start
>
>  Are you saying the "if" statements will raise TypeError if start or end are
> dates? That would be a sad day for Python. Perhaps you're saying that there
> is a "meaningful comparison" between None and anything else, but please
> clarify if so.

Yes, I'm suggesting that they will raise a TypeError. Your example
shows that the change is not compatible with a lot of existing Python
code, which means that it's a Python 3000 thing. The following code
will continue to work:

    def date_range(start=None, end=None):
        if start is None:
            start = datetime.date.today()
        if end is None:
            end = datetime.date.today()
        return end - start

Using "is None" instead of "== None" is considered a better style even now.

Noam
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4