473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
Jul 18 '05 #1
4 1958
Hi !

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

@-salutations
--
Michel Claveau

Jul 18 '05 #2
|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?"""

Jul 18 '05 #3
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
Jul 18 '05 #4
Samuel Walters <sw*************@yahoo.com> wrote in message news:<pa****************************@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.
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mats | last post by:
Option Explicit does not work anymore.(?) If you put <%option explicit%> at the top of your pages (direktly after the language declaration) you should get an error for each undeclared variable....
1
by: Tim Marshall | last post by:
For class modules for forms, Option Explicit used to be a default declaration at the top of the form module. It isn't anymore. Should there be anything i need to worry about? This may not be...
2
by: Nils Emil P. Larsen | last post by:
Hello I have read about a C shared library which I want to use in my C program. (It's a library to encode/decode packets from/to a serial bus running with the SNAP-protocol). Unfortunatly...
1
by: ranges22 | last post by:
****************************************************************** I am compiling a librarry which has a .h file containing th following:...
1
by: petschy | last post by:
hello, i've run into an error when qualifying a copy ctor 'explicit'. the strange thing is that i get a compiler error only if the class is a template and declare the variable as X<Zx = y....
26
by: samjnaa | last post by:
Hello. Please tell me whether this feature request is sane (and not done before) for python so it can be posted to the python-dev mailing list. I should say first that I am not a professional...
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
1
by: ARC | last post by:
Ok, this is strange. I created a new database and imported all objects from the old program file. Form some reason, the option explicit statement is no longer showing in my code modules (and I...
11
by: =?UTF-8?Q?Filip_Gruszczy=C5=84ski?= | last post by:
Hello everyone! It is my first message on this list, therefore I would like to say hello to everyone. I am fourth year student of CS on the Univeristy of Warsaw and recently I have become very...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.