Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python strict mode?

Reply
Thread Tools

Python strict mode?

 
 
Peng Yu
Guest
Posts: n/a
 
      09-13-2009
Hi,

Is there is a way to make python check the variables just as the
strict mode in perl. Would somebody let me know what is the python
equivalent to the perl strict mode?

Regards,
Peng
 
Reply With Quote
 
 
 
 
Andreas Waldenburger
Guest
Posts: n/a
 
      09-13-2009
On Sun, 13 Sep 2009 09:25:50 -0700 (PDT) Peng Yu <(E-Mail Removed)>
wrote:

> Is there is a way to make python check the variables just as the
> strict mode in perl.

Short answer: No.

Long answer: I'm guessing you want Python to complain when assigning to
a variable that has not been declared before. Since Python has no
declarations, you're plain out of luck.


> Would somebody let me know what is the python equivalent to the
> perl strict mode?
>

I don't know about any equivalents (but I wouldn't be surprised if
there were libraries for that somewhere).

You could write a class with a custom __setattr__() method that checks
for valid attribute names for that class (a list of strings given to
it's __init__() method). That way you could form several restricted
"namespaces" for variables simply as different instances of that class.

But in my opinion, it isn't worth it. You still don't get compile time
errors, which is probably the main reason to use strict mode.

Can you describe why you (think you) need this? Maybe there is a
more pythonic approach.

/W

--
INVALID? DE!

 
Reply With Quote
 
 
 
 
Patrick Sabin
Guest
Posts: n/a
 
      09-13-2009
> You could write a class with a custom __setattr__() method that checks
> for valid attribute names for that class (a list of strings given to
> it's __init__() method). That way you could form several restricted
> "namespaces" for variables simply as different instances of that class.
>


This can be easier accomplished using __slots__, e.g.:

>>> class X(object):

.... __slots__ = ['a']

> But in my opinion, it isn't worth it. You still don't get compile time
> errors, which is probably the main reason to use strict mode.


I agree.

- Patrick
 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      09-13-2009
Peng Yu wrote:
> Hi,
>
> Is there is a way to make python check the variables just as the
> strict mode in perl. Would somebody let me know what is the python
> equivalent to the perl strict mode?


3rd party code checkers like pylint, pychecker.

 
Reply With Quote
 
Carl Banks
Guest
Posts: n/a
 
      09-13-2009
On Sep 13, 9:25*am, Peng Yu <(E-Mail Removed)> wrote:
> Is there is a way to make python check the variables just as the
> strict mode in perl. Would somebody let me know what is the python
> equivalent to the perl strict mode?



I don't recommend using it, but see this post:

http://groups.google.com/group/comp....c3a97f6f?hl=en


Carl Banks
 
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
Validating Python - need doctype HTML strict PapaRandy Python 2 07-11-2006 08:09 PM
Strict priority for a system? Grue Cisco 4 05-05-2004 02:48 AM
What am I doing wrong when using "use strict" ? ed Perl 1 01-05-2004 01:22 PM
What does "fixup ftp STRICT" means in practice ? jarcar Cisco 1 12-05-2003 03:47 PM
How to turn Strict "off"? Andy Crawford ASP .Net 1 07-11-2003 01:50 PM



Advertisments