We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,878 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Save input into script

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*
ect.

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
    else:
        return "Error 1", "Unexpected variable."

is this posible to edit the program through the program.

thanks in advance
LTJR

3
Contributors
5
Replies
8 Hours
Discussion Span
3 Months Ago
Last Updated
7
Views
longtomjr
Newbie Poster
23 posts since Feb 2013
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0

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.

Lardmeister
Posting Virtuoso
1,938 posts since Mar 2007
Reputation Points: 465
Solved Threads: 72
Skill Endorsements: 5

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.

longtomjr
Newbie Poster
23 posts since Feb 2013
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0
Lardmeister
Posting Virtuoso
1,938 posts since Mar 2007
Reputation Points: 465
Solved Threads: 72
Skill Endorsements: 5

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

longtomjr
Newbie Poster
23 posts since Feb 2013
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0

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!

ZZucker
Master Poster
780 posts since Jan 2008
Reputation Points: 342
Solved Threads: 60
Skill Endorsements: 1

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1028 seconds using 2.73MB