Chandra X-Ray Observatory
	(CXC)
Skip to the navigation links
Last modified: December 2013

URL: http://cxc.harvard.edu/ciao/ahelp/paramio_pget.html
Jump to: Description · Examples · See Also


AHELP for CIAO 4.9

pget

Context: paramio

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.

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.

See Also

paramio
paccess, paramclose, paramio, paramopen, pgets, plist, pquery, pset, punlearn

Last modified: December 2013
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email:   cxchelp@head.cfa.harvard.edu Smithsonian Institution, Copyright © 1998-2017. All rights reserved.