mercredi 24 juin 2015

Import examples for testing (Python)

For the following problem I am unable to find an answer.
I have my program to do various stuff to graphs in one file. After my class definition and functions I have my basic structure of which functions to call on a pair of graphs.
Now I want to have different extra files with a pair of graphs in each to show different aspects of my program.
How do I get that file into my main program as if the code that is in the extra files was in my main program?
I know, it is a basic problem but I never dealt with this before.

For illustration:

class foo:
    def __init__(stuff)

    def plot(self):
        ...

    more stuff

# I want the following in an extra file #
# Two equal graphs

A = nx.Graph([(0, 1), (1, 2), (2, 3), (3, 7), (3, 4), (4, 5), (5, 6)])
B = nx.Graph([(0, 1), (1, 2), (2, 3), (3, 7), (3, 4), (4, 5), (5, 6)])
# That's it

x = foo(A, B)
x.plot

If I could also specify the file I want to load via command line, that would be even better.

Aucun commentaire:

Enregistrer un commentaire