My stupid newbie mistake

Discussion in 'Python' started by Matt Feinstein, Apr 11, 2005.

  1. I named a file 'try.py' and then was stumped, for a while, when

    >>> import try


    gave a syntax error... So, how about a
    'YouAreUsingAReservedWordStupid' exception ?

    Matt Feinstein

    --
    There is no virtue in believing something that can be proved to be true.
     
    Matt Feinstein, Apr 11, 2005
    #1
    1. Advertisements

  2. Matt Feinstein

    Larry Bates Guest

    Because Python allows you to replace built-in methods with
    your own. Later you will find that this can be extremely
    powerful. You will stumble on this if you name a list 'list'
    a string 'str', integer 'int', float 'float', dictionary
    'dict', ... (at least I did <grin>).

    -Larry Bates

    Matt Feinstein wrote:
    > I named a file 'try.py' and then was stumped, for a while, when
    >
    >
    >>>>import try

    >
    >
    > gave a syntax error... So, how about a
    > 'YouAreUsingAReservedWordStupid' exception ?
    >
    > Matt Feinstein
    >
    > --
    > There is no virtue in believing something that can be proved to be true.
     
    Larry Bates, Apr 11, 2005
    #2
    1. Advertisements

  3. Matt Feinstein

    Peter Hansen Guest

    Larry Bates wrote:
    > Matt Feinstein wrote:
    >>>>>import try

    >>
    >>gave a syntax error... So, how about a
    >>'YouAreUsingAReservedWordStupid' exception ?

    >
    > Because Python allows you to replace built-in methods with
    > your own. Later you will find that this can be extremely
    > powerful.


    Powerful, but not involved in this case, since you
    can't redefine *keywords* such as 'try'.

    -Peter
     
    Peter Hansen, Apr 11, 2005
    #3
  4. Larry Bates wrote:

    > Because Python allows you to replace built-in methods with
    > your own. Later you will find that this can be extremely
    > powerful. You will stumble on this if you name a list 'list'
    > a string 'str', integer 'int', float 'float', dictionary
    > 'dict', ... (at least I did <grin>).


    try is a reserved word.

    list, str, int, float, dict are not reserved words. you can accidentally
    shadow built-in objects by using one of them for your own purposes
    (this may or may not matter), but it's not a syntax error.

    </F>
     
    Fredrik Lundh, Apr 11, 2005
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Qi4gQ2hlcm5pY2s=?=

    Newbie mistake or Custom Validator bug?

    =?Utf-8?B?Qi4gQ2hlcm5pY2s=?=, Feb 22, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    2,287
    =?Utf-8?B?Qi4gQ2hlcm5pY2s=?=
    Feb 23, 2006
  2. Materialised

    Probably a Stupid Mistake

    Materialised, Oct 22, 2004, in forum: C++
    Replies:
    6
    Views:
    607
    Ben Measures
    Oct 22, 2004
  3. Brandon McCombs
    Replies:
    4
    Views:
    766
    Richard Wheeldon
    Aug 28, 2006
  4. David Schwartz

    stupid mistake?

    David Schwartz, Sep 15, 2007, in forum: XML
    Replies:
    6
    Views:
    542
    Joseph Kesselman
    Sep 18, 2007
  5. javawizard

    Stupid Website Mistake

    javawizard, Nov 7, 2007, in forum: HTML
    Replies:
    3
    Views:
    513
    Travis Newbury
    Nov 8, 2007
  6. rincewind

    stupid, STUPID question!

    rincewind, Apr 19, 2009, in forum: HTML
    Replies:
    25
    Views:
    1,370
  7. dobest03
    Replies:
    7
    Views:
    376
  8. VICTOR GOLDBERG

    Interesting result of a newbie mistake

    VICTOR GOLDBERG, May 7, 2008, in forum: Ruby
    Replies:
    2
    Views:
    169
    kranthi reddy
    May 7, 2008
Loading...