Synopsis
Get a parameter value as a string.
Syntax
pget(paramfile, paramname)
Description
This function is essentially the same as the command-line version (see "ahelp tools pget"), although only one parameter can be accessed at a time.
The parameter value is always returned as a string by this function; the paramio library does contain functions - such as pgetb() and pgetd() - which will automatically convert the value into the requested datatype. The pquery() function may also be of interest.
The paramio module is not available by default; see "ahelp paramio" for information on loading the module.
Examples
Example 1
>>> punlearn("dmcopy") >>> ifile = pget("dmcopy", "infile") >>> clval = pget("dmcopy", "clobber") >>> if ifile == "": print("infile is empty!") infile is empty! >>> print(clval) no
Here we use pget() to find the current settings of the "infile" and "clobber" parameters of the "dmcopy" parameter file. Note that clval contains a string and not a boolean value; the pgetb() routine could have been used here instead.
Example 2
>>> punlearn("dmcopy") >>> fp = paramopen("dmcopy") >>> ifile = pget(fp, "infile") Input dataset/block specification (): in.fits >>> clval = pget(fp, "clobber") >>> paramclose(fp) >>> print(ifile) in.fits >>> print(clval) no
This example is similar to the first except that we use the return value of paramopen() to access the parameter file. If you make many paramio calls on a single parameter file then it is more efficient to use paramopen() than just using the name of the parameter file.
Since we did not supply a mode parameter for the paramopen() call, it defaults to "r" and so the paramater was prompted for when pget() was called.
Example 3
>>> punlearn("dmcopy") >>> fp = paramopen("dmcopy", "rH") >>> ifile = pget(fp, "infile") >>> paramclose(fp) >>> if ifile == "": print("infile is empty!") infile is empty!
By opening the parameter file with the mode set to "rH" we avoid the interactive prompt when pget() is called.