Part 2: Creating Modules for Juliar in Python

September 3, 2016 | Views: 2214

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATIONAlready a Member Login Here

This tutorial is continuation of Part 1: Creating Juliar Modules in Python.
If you have no idea what’s going on check out the previous part.


  • You must have read first part of tutorial
  • You must have PythonDevKit downloaded
  • You must be able to work your brain

In this tutorial we will learn about optionals and why and how they are supposed to be used.

Remember from the first tutorial: each command requires def name(content, optionals):

Well optionals are optionals, meaning that the user of module can specify any amount of optionals, or
the user can specify none. Either way, you must be able to figure out what the optionals are
and what to do with them.

In *Juliar * optionals are specified:
*commandname=optional_1,optional_2  content *
where optional_1 and optional_2 are optionals.

Again, user can specify 0 optionals or 20 optionals.
You, as a module developer, is responsible for handling such cases.
Let’s create a new module and call it “<b></b>”

Let’s open it and copy the following:
def hello(content,optionals):
return “I am “+content+” and my backpack contains “+optionals[0]

Let’s import it into Juliar by doing *import=py *
Let’s test it by doing *hello=pencil Andy *
It will output “I am Andy and my backpack contains pencil”

Let’s test it again by doing *hello Andy *
Oops…our program crashed (in the newer version this may just display a module error).

Why did this happen?
Well if you look at our command. We are using optionals. However, as we said before:
Optionals are Optional. So they might or might not be used.

Let’s fix it by checking size of optionals.
Let’s add this check to our current command

def hello(content,optionals):
        if(len(optionals) == 0):
                return “I am “+content
        return “I am “+content+” and my backpack contains “+optionals[0]
By checking the length, we make sure that if user has not specified any optionals they would not experience a crash or an error.

If you are not using optionals, then you must still keep optionals in the def, but there is no need to check for size.

Congratulations, you just got a yellow belt in creating *Juliar * modules in python.

More tutorials coming soon!

Share with Friends
Use Cybytes and
Tip the Author!
Share with Friends
Ready to share your knowledge and expertise?
Comment on This

You must be logged in to post a comment.

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Support Cybrary

Donate Here to Get This Month's Donor Badge


We recommend always using caution when following any link

Are you sure you want to continue?