I am making a basic comand line program that does conversions in python and i want to add more conversions to it without scripting. so you can command the program something like

(you command the PC)     add new_conversion
(The PC ask)       name the new_conversion: *here you enter your function name*

then in the end you get a function like this:

def kiloMile(n, km):
    if type(n) != int:
            return "Error 1", "Unexpected variable."
    elif km == "k":
        mile = n * 0.621371
        return mile
    elif km == "m":
        kilometers = n * 1.60934
        return kilometers
        return "Error 1", "Unexpected variable."

is this posible to edit the program through the program.

thanks in advance

5 Years
Discussion Span
Last Post by ZZucker

It should be possible, but would anybody trust the program after a while?
I can see a dictionary with lambda functions, that can be pickled to save it.

Edited by Lardmeister


would anybody trust the program after a while?

It is just to add your own conversions I would say, otherwise i can create some sort of function that place all the custom conversions in a conf file.


i do this acctualy to practice my skills... and learn new stuf... Yes I do think the Dictionary aproach is way better byt I like to make my own stuff one in a while... You dont need to reinvent the wheel but you must build your own to understand the tools better


You need to save your updates and a dictionary is ideal to do this with. Python has module shelve to make a 'persistent to file' dictionary automatically. Very powerful stuff indeed!

Edited by ZZucker

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.