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. Advertising

  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. Advertising

  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. Advertising

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. Materialised

    Probably a Stupid Mistake

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

    stupid mistake?

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

    Stupid Website Mistake

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

    stupid, STUPID question!

    rincewind, Apr 19, 2009, in forum: HTML
    Replies:
    25
    Views:
    1,007
Loading...

Share This Page