putting a sage program inside a loop with out modifying the indentation

160 Views Asked by At

I have written a simple program on sage, in which I will define a graph G at the beginning , and the program will return a matrix. now I want the program to return all such matrices corresponds to all trees of order 5. So basically I want to iterate the program over the list of all trees of order 5. But when I doing so, I need to change the indentation of each and every line of the program as I am putting all of them inside a loop. is there any way of getting rid of this problem, my program has more than 50 lines so it looks difficult to change the indentation . one thing I thought was using goto command, but I dont know how to use it.

Any suggestion would be appreciated.

Thanks a lot.

1

There are 1 best solutions below

1
On BEST ANSWER

This is a hard question to answer in its current state, as you are sparse on details. Perhaps you should make your Sage program a Python function so it's easy to reuse?

My suggestion would be that if your current code is

do stuff
do more stuff
for i in some_list:
    do even more stuff
now do something else

then you could make that a function.

def f():
    do stuff
    do more stuff
    for i in some_list:
        do even more stuff
    now do something else

and then in your new thing you can do

do something
x = f()
print result

That doesn't get around the indentation problem, but is better programming technique.

As to the indentation problem per se, this is just an editor issue. Python of any kind will have this. In the Sage notebook (and probably in the SageMath Cloud) there is a shortcut to indent everything one more indentation level, by highlighting and then using Tab; Shift+Tab should "dedent". If you are using an editor like Emacs in the command line, doubtless there is a way to do this as well. Good luck!