My stupid newbie mistake

M

Matt Feinstein

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

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

Matt Feinstein
 
L

Larry Bates

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
 
P

Peter Hansen

Larry said:
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
 
F

Fredrik Lundh

Larry said:
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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top