Posts: 4,647
Threads: 1,494
Joined: Sep 2016
i've been doing things like this to convert arguments or input numbers:
number = int(sys.argv[1])
now i have found a different way that is more fun though it needs more coding:
try:
number = eval(sys.argv[1])
except:
print('oops!')
error_count += 1
if you want the traceback info, don't use the try/except. then you don't have to calculate formulas to enter their values (though you might have to use quotes around many formulas for most command shells).
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
Aug-20-2018, 08:01 AM
(This post was last modified: Aug-20-2018, 08:14 AM by Skaperen.)
you can do that faster as a shell command. i won't be doing that on code that needs to run securely. it will be in code that runs with the credentials of who runs it. if you run it and do that, you'll only be doing it to yourself.
(Aug-20-2018, 06:39 AM)Gribouillis Wrote: Besides the questionable use of eval
, your code would improve by using a library to parse command line arguments, typically argparse
of one of its wrappers argh
or click
or others.
some of those libraries may be usable for some of my programs. most of my commands have unusual and/or non-standard command syntax. i have seen nothing that am able to use on eve half of my commands. my next program will have a syntax that uses both - and + and can even mix both sets of option within the same argument. and these options have specific influence on how the file names are tested as it goes. and, of course, error messages include argument context for user.
what are your questions about my use of eval()? am i calling it with credentials different than who types in that option? no!
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
@
buran i just wrote a script that takes Unicode code points in various forms and converts them to a UTF-8 octet stream output (in hex) i can give it numbers on the command or in the input. i could add numbers. or i can give it an expression like
range(0x400,0x440).
_
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.