Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From the driver.py file, import the connections file as a module and pass the arguments you've parsed to the methods inside the module. Something like this:</p> <pre><code>#===inside driver.py=== import connections params = parseFile(sys.argv) #get parameters from the csv file that is passed to the command line connections.connect(params) #pass them to whatever method you need to call from connections </code></pre> <p><strong>EDIT:</strong> It sounds like you're not writing your code in a modular way. You should stop thinking about your code in terms of files, but instead think of them in terms of modules: bits and pieces of interchangeable code that you can use in many different places. The main flaw with your design that I see (forgive me if I didn't understand correctly) is that you're hard-coding a value inside the connections file that you use to create connection objects. I'm guessing this is what your code looks like (or at least captures the spirit of your code adequately):</p> <pre><code>#connections.py MY_SERVER = ??? #WHAT DO I SET THIS TO? class Connection: def __init__(self): self.server = MY_SERVER def connect(): connection = Connection() #create a new connection object </code></pre> <p>The above code is not designed well since you're defining a variable <code>MY_SERVER</code> that shouldn't be defined there in the first place! The connections class doesn't know or care what server it should use, it should work with any server. So where do you get the server variable? You pass it in via a constructor or a method. You could do something like this:</p> <pre><code>#connections.py class Connection: def __init__(self, server): self.server = server def connect(server): connection = Connection(server) #create a new connection object with the server passed to the method </code></pre> <p>With this design, the Connection object becomes much more flexible. It is basically saying "I am a connection object that can handle any server. If you want to use me, just tell me what server you want to use!". </p> <p>This way, in your drivers file you can first parse the server from your csv, and then simply call the method <code>connections.connect</code> by passing it the server you want! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload