Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Modules are python files (*.py) that can be imported in a script. Packages are collections of modules within a single namespace. If you like, read up on the exact definitions here or here.

It can be handy to build your own package. For example: you have build a set of scripts for a specific project. Let's say Project X. For Project X you have written some scripts for

  • input of specific data (inputX.py)
  • output to a format the client specifically requested (outputX.py)
  • tailored plots (plotX.py)

To keep track of these functions for this project, you want to build a single package containing these functions. This can easily be achieved without leaving DeltaShell.

Writing a module

  1. Open DeltaShell
  2. In the Toolbox, create a new script in the upper 'Scripts' directory and name it 'outputX'
  3. Copy-paste the following dummy function and save the file:

    Code Block
    languagepy
    def dummyX():
        print "Hello World!"
  4. Create a new script called 'runfile'
  5. In runfile, we will import outputX and run the dummyX function:

    Code Block
    languagepy
    import outputX
    
    outputX.dummyx()

    In the Messages window, you will see the 'Hello World' output appear. We have imported 'outputX' as a module.

Writing a package

  1. To make a package, insert a new folder in the scripts folder and name it 'ProjectX:
    Image Added
  2. To move 'outputX' to the new 'ProjectX' package, right click on 'outputX' and select 'Open location with windows explorer'.
  3. In windows explorer, cut-paste outputX.py in the ProjectX directory. The directory structure should now look like this:

    Image Added
  4. To use the dummyX function, change the code in runfile.py to:
Code Block
languagepy
from ProjectX import outputX

outputX.dummyx()

 

Congratulations! You have written your own Python package with DeltaShell.

...

 

Info

Content by Label
showLabelsfalse
max5
spacesSobek
sortmodified
showSpacefalse
reversetrue
typepage
labelstutorial tut-scripting