Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
explicit variable declaration
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Luis Solís  
View profile  
 More options Jan 5 2004, 3:24 am
Newsgroups: comp.lang.python
From: "Luis Solís" <lso...@mu.intecsa-inarsa.es>
Date: Mon, 05 Jan 2004 08:23:56 GMT
Local: Mon, Jan 5 2004 3:23 am
Subject: explicit variable declaration
Hi
It is possible to declare some variables as int, long... ? , or something
like visual basic option explicit.
In some situations could be usefull.
Thanks

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michel Claveau/Hamster  
View profile  
 More options Jan 5 2004, 4:05 am
Newsgroups: comp.lang.python
From: "Michel Claveau/Hamster" <No.Spam...@No.Spam.mclaveau.No.Spam.com>
Date: Mon, 5 Jan 2004 10:07:58 +0100
Local: Mon, Jan 5 2004 4:07 am
Subject: Re: explicit variable declaration
Hi !

"Variable" is a bad word - beurk ! -   In Python there are ref-on-objects ;
it's without interest with declaration (explicit).

@-salutations
--
Michel Claveau


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Samuel Walters  
View profile  
 More options Jan 5 2004, 4:06 pm
Newsgroups: comp.lang.python
From: Samuel Walters <swalters_use...@yahoo.com>
Date: Mon, 05 Jan 2004 21:06:43 GMT
Local: Mon, Jan 5 2004 4:06 pm
Subject: Re: explicit variable declaration
|Thus Spake Luis Solís On the now historical date of Mon, 05 Jan 2004
08:23:56 +0000|

> Hi
> It is possible to declare some variables as int, long... ? , or something
> like visual basic option explicit.
> In some situations could be usefull.
> Thanks

Well, in python, that is left to programmer's discretion.
Once you get used to it, it's less of a hassle and danger zone than you'd
expect.

You can read GvR's (Our Benevolent Dictator For Life) thoughts
on contracts in python here:
http://www.artima.com/intv/pycontract.html

As a fallback, you can always use the isinstance() and type() functions to
check what type of variable you have on hand.

Generally, isinstance is what you want to use because it returns true for
subclasses.  If the subclass doesn't do everything you'd expect of it's
superclass, then either your or the subclass writer have broken their
contract.

If you absotively posolutely must know that a variable is a certain class,
not a subclass and nothing but the bona fide variable type you expected,
then use type().  This, however, is seldom the case because using type()
could prevent future programmers from extending your code.

If you want even more assurances, look into pylint and pychecker:
http://www.logilab.org/projects/pylint
http://pychecker.sourceforge.net/

HTH

Sam Walters.

p.s. The python-tutor list is probably a better place to ask questions
like this.  You're most likely to get helpful answers to questions about
the basics than you are here.

--
Never forget the halloween documents.
http://www.opensource.org/halloween/
""" Where will Microsoft try to drag you today?
    Do you really want to go there?"""


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Hansen  
View profile  
 More options Jan 5 2004, 5:30 pm
Newsgroups: comp.lang.python
From: Peter Hansen <pe...@engcorp.com>
Date: Mon, 05 Jan 2004 17:30:40 -0500
Local: Mon, Jan 5 2004 5:30 pm
Subject: Re: explicit variable declaration

Michel Claveau/Hamster wrote:

> Hi !

> "Variable" is a bad word - beurk ! -   In Python there are ref-on-objects ;
> it's without interest with declaration (explicit).

I'm not sure how helpful that is to a newbie, and in any case I've
been using Python for a reasonably long time now and I definitely
refer to those babies as variables.... with no ill effects to date.

-Peter


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Bishop  
View profile  
 More options Jan 8 2004, 1:17 am
Newsgroups: comp.lang.python
From: danb...@yahoo.com (Dan Bishop)
Date: 7 Jan 2004 22:17:53 -0800
Local: Thurs, Jan 8 2004 1:17 am
Subject: Re: explicit variable declaration

Samuel Walters <swalters_use...@yahoo.com> wrote in message <news:pan.2004.01.05.21.05.32.783610@yahoo.com>...
> |Thus Spake Luis Solís On the now historical date of Mon, 05 Jan 2004
> 08:23:56 +0000|

> > Hi
> > It is possible to declare some variables as int, long... ? , or something
> > like visual basic option explicit.
> > In some situations could be usefull.
> > Thanks

> Well, in python, that is left to programmer's discretion.
> Once you get used to it, it's less of a hassle and danger zone than you'd
> expect.

The main reason for this is that, in Python, using an unassigned
variable gives you a friendly NameError.  In BASIC, it implicitly
creates a new variable (with a value of zero) whether you wanted it to
or not.

...

> As a fallback, you can always use the isinstance() and type() functions to
> check what type of variable you have on hand.

Or more accurately, what type of *object* you have on hand.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »