Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > My stupid newbie mistake

Reply
Thread Tools

My stupid newbie mistake

 
 
Matt Feinstein
Guest
Posts: n/a
 
      04-11-2005
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.
 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      04-11-2005
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.

 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      04-11-2005
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
 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      04-11-2005
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>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
stupid mistake? David Schwartz XML 6 09-18-2007 05:17 PM
HELP - stupid mistake on PIX Mike W. Cisco 4 03-01-2006 02:36 AM
Stupid question. Please, only stupid responders. If you're not sureif you're stupid, you probably aren't. =?ISO-8859-1?Q?R=F4g=EAr?= Computer Support 6 07-18-2005 05:11 AM
stupid stupid stupid kpg MCSE 17 11-26-2004 02:59 PM
Probably a Stupid Mistake Materialised C++ 6 10-22-2004 03:55 PM



Advertisments