|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
Working with command-line arguments — the Python wayIn Python, it's very easy to work with command-line arguments. The arguments are stored in the list
Source codes:
As you can see, the source codes are almost identical. The magic is achieved with the import os ## Mimicking Python's ``sys`` module to some extent. ## ## To avoid confusion with the ``system`` module from the stdlib, ## it's called ``jsystem``, which stands for "jabba's system" module. # ####### # Types # # ####### type JabbaSys = tuple argv: seq[string] # ###### # Vars # # ###### proc getArgv(): seq[string] = result &= getAppFilename() for i in 1 .. paramCount(): result &= paramStr(i) var sys*: JabbaSys = ( argv: getArgv() ) ## Mimics Python's ``sys.argv``. It contains the file name and the parameters, ## just like in C or Python. ## ## ``sys.argv`` can be modified in Python, that's why it's a ``var``. Links
|
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |
||||||||