Skip to content
Advertisement

How to add aliases to an input dictionary?

Recently I started a project. My goal was it to have a script, which, once launched, could be able to control actions on the hosts computer if an instruction was send via email. (I wanted this so I could start tasks which take a long time to complete while I’m away from home)

I started programming and not long after I could send emails, receive emails and analyze their content and take actions responding to the content in the email.

I did this by using an input dictionary, which looked like this:

JavaScript

In total I have around 25 functions each with its own response. I replaced the actual code for the commands with simple print statements as they are not needed to understand or replicate my problem.

I then wanted to add aliases for the command, so for example you would be able to type “!ss” instead of “!screen”. I did achieve this using another line in the dictionary:

JavaScript

But I didn’t like this. It would fill up the whole dictionary if I did it for every alias I am planning to add and it would make my code very messy. Is there any way to define aliases for commands separately and still keep the dictionary clean and simple? I would desire something like this in a separate aliases.txt file:

JavaScript

If this is possible in python I would really appreciate to know!

Advertisement

Answer

You can use following solution:

JavaScript

aliases.json:

JavaScript

is that what you looking for?

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement