Too Many if Statements?

2006-02-07 Thread slogging_away
Hi - I'm running Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310
32 bit (Intel)] on win32, and have a script that makes numerous checks
on text files, (configuration files), so discrepancies can be reported.
 The script works fine but it appears that I may have hit a wall with
'if' statements.

Due to the number of checks perfromed by the script on the text files,
(over 500), there are quite a few 'if' statements in the script, (over
1150).  It seems that it is at the point that when I add any additional
'if' statements the script will not run.  No error is produced - it
just returns to the python prompt much the same as when a successful
'Check Module' command is selected.  If I delete some other 'if'
statements the new ones work so it appears that it has hit a limit on
the number of 'if' statements.  This has stunted any further checks for
the script to make on the text files.

Hs anyone ever run into this sort of thing?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too Many if Statements?

2006-02-07 Thread slogging_away
I don't consider myself to be a seasoned programmer so if you mean
redesigning the script to make the checks and therefore reduce the
number of 'if' statements, I'm not sure if that can be done.  The
script needs to make numerous checks for the existence of particular
strings within the configuration file.  It also uses 'if' statements to
determine what type of file is being examined, etc.. If an error is
encounterd it writes warning messages to a master file.  I guess what I
am trying to say is that in order to make the many checks on the
configuration files I do not know of any other way than to check for
the existance of particular statements, (strings), and then report on
those if they are incorrect or missing - hence at least one 'if'
statement for every check. 

I appreciate the feedback though!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too Many if Statements?

2006-02-07 Thread slogging_away
Ah!  I see what you are saying snoe, (and most likely what bruno at
modulix was recommending).  That technique should provide a workaround
to the direct 'if' approach currently used and also offer some
modularity to the logic as well.

Thank you for pointing me in the right direction - I'll give it a go.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too Many if Statements?

2006-02-07 Thread slogging_away
Hmmm - good responses all around.  Thank you all for your valued
feedback.

Perhaps it's too may 'if' statements under the for XXX in range(x,x,x)
statement as most of the 'if' statements appear there.  It could be
something entirely else.  I'm afraid its a bug with Python, (if I try
and run it several times it keeps going to the IDLE console prompt and
it eventually crashes out of Python entirely).

Some useful suggestions were provided in terms of better design so that
may be my route at this point.  Thanks again for all of your help!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too Many if Statements?

2006-02-09 Thread slogging_away
Terry Reedy wrote:

> The OP did not specify whether all of his if-tests were sequential as in
> your test or if some were nested.  I vaguely remember there being an indent
> limit (40??).

Most of the if statements are nested.  Almost all of them fall under a
central 'for xxx in range(x,x,x)', (this is the statement that checks
thorugh each of the saved configuration files).   Under that 'for'
statment are the bulk of the 'if' statements - some nested and some not
- some also fall under other 'for' statements.  The indent level does
not exceed 10..

Delaney, Timothy (Tim) wrote:

> I'm pretty sure the OP has hit the python script line limit (32767?).

The script is 4903 lines long.

Slightly off topic; I am just a Network Engineer that can write some
code that accomplishes what I need to get done.  I'm learning something
new everyday but I am really blown away by the responses to this
thread.  I could not buy support this good.  Thanks for your responses.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too Many if Statements?

2006-02-09 Thread slogging_away
It appears it may not be a 'if' statment limitation at all.  This is
because I added another 800 element array in which to store the various
error messages generated when a configuration file error is deteceted
based on their severity level.  The simple addition of the array caused
the same symptom stated in the initial posting.  This additional array
was removed and the script performs as expected.  Adding it back in
cause it to not run - no error message - just a return to the >>> in
the IDLE console window much as if I had executed the 'Check Module'
command.

At this point I guess I'll find another way work around this issue via
some of the previously suggested methods , etc.  It appears to be a bug
as far as I can tell.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too Many if Statements?

2006-02-10 Thread slogging_away
bruno at modulix wrote:

> Looks like a memory problem then...

The system I am using has 2GB of memory, (unless you are syaing the
memory is faulty).

> Why storing error messages ? Why don't you just write'em out (be it to
> stdout or to a file) ?

I guess I could do that, (write them to a file as they are discovered).
Right now the error messages are stored in the array and then the the
array is scanned via, a for loop and the error messages are written to
several files in different formats based on the severity of the errors,
(on a per device basis, a per severity basis, etc.).  This keeps the
write statements to a minimum and in a central location of the script
instead of having several statements for each individual error message
spread throughout the script, (three write statements per error message
at over 500 error messages would be a significant change).

Not to complain but if I can't use arrays then thats a pretty
significant limitation.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too Many if Statements?

2006-02-10 Thread slogging_away
Magnus Lycka wrote:

> What happens if you run it from the command line instead
> of IDLE? After all, it might be some problem in IDLE involved
> here. Even if it doesn't work correctly outside IDLE, I was
> thinking that IDLE might swallow some kind of error message.

Excellent suggestion, (behold the power of the command line!).  I ran
two saved versions of the script that had produced the symptom
originally described.  The fist seemed to be caused by too many 'if'
statements, the second by adding another array, but both came up with
the same system error at the command prompt level shown here:

SystemError: com_backpatch: offset too large

This error is not produced with the IDLE console but is seen only when
executing from the command line.  I'll search around and see if I can
determine what this means and a possible fix.  Thanks for the
suggestion!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too Many if Statements?

2006-02-12 Thread slogging_away
Now that I know the root cause of the problem, I can write around it as
suggested by Steve Holden and Terry Reedy, (and others).  In fact, it
has helped me in a way as I am thinking not in terms of the easiest
solution, (read; the first one that comes to mind),  but more effcient
and cleaner ways to write a section of code to accomplish the same
objective. The key was identifying the root cause which was provided by
the error message seen only at the command line level and by
contibutors to this post.

Thanks again for everyone's suggestions and expertise.

-- 
http://mail.python.org/mailman/listinfo/python-list


Will Python Run On Microsoft Vista?

2007-02-05 Thread slogging_away
I know, I know - flame away but its not clear to me if Python will run
on a system running Microsoft Vista.  Is anyone successfully running
Python on Vista?  If so, is it what version of Python are you
running?  I'm ordering a new system and if Python won't work on Vista
then it will definately influence the OS selection.

Thanks in advance!

-- 
http://mail.python.org/mailman/listinfo/python-list