[Tutor] arrays and strings
Lloyd Kvam
pythontutor@venix.com
Wed, 08 May 2002 10:12:11 -0400
You don't really need #define with Python. C needs #define to avoid
unnecessary type restrictions.
In C
#define MAX_DAYS 31
provides a number that will work for most contexts while
int MAX_DAYS=31;
will only work in integer contexts.
Since Python's type processing is dynamic and supports type checking,
you can simply state:
MAX_DAYS = 31
and use MAX_DAYS whereever necessary. Effectively, it is a global, variable
and you want to avoid changing it. In practise you use it as a constant that
is defined in one place.
Erik Price wrote:
>
> On Wednesday, May 8, 2002, at 08:46 AM, wonderer@pakistanmail.com wrote:
>
>> I m sorry to bother u again but i just wanted to know if there is any
>> equivalent
>> of c-style #define in python
>> coz i m decalring a varianle globally in one file (util.py)and then
>> want to
>> access in another file named test.py but that gives me error as
>> NameError:"name"
>> not defined
>
>
> wonderer, fyi I CC'd this msg to the list b/c I'm no Python master, and
> hopefully someone else can come up with something constructive.
>
> From what I understand of Python, you would want to import "util.py" as
> a module into the script where you're trying to use the global variable,
> which means that the global variable is now "util.variablename" (I
> think). I have no experience with C, so I'm not sure if this is the
> same thing as #define (not sure what that is...)
>
> Good luck though.
>
>
> Erik
>
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice:
603-443-6155
fax:
801-459-9582