Last modified: December 2013

Jump to: Description · Examples · See Also

AHELP for CIAO 4.15


Context: paramio


Set a parameter value.


pset(paramfile, parname, value)
pset(paramfile, dictionary)


This function is essentially the same as the command-line version (see "ahelp tools pset").

As with most of the paramio routines, the parameter file can be specified by either name or using the output of paramopen(). To set just one parameter value you use the three-argument form of pset(), namely:

pset(paramfile, parname, value)

To set the values of multiple parameters you use the two-argument form where the second argument is a Python dictionary, where the keys are the parameter names and their values are the new parameter values.

The paramio module is not available by default; see "ahelp paramio" for information on loading the module.


Example 1

>>> from paramio import *
>>> punlearn("dmcopy")
>>> pset("dmcopy", "infile", "in.fits")
>>> print(pget("dmcopy", "infile"))
>>> pset("dmcopy", "verbose", "3")
>>> print(pget("dmcopy", "verbose"))

Here we use the pset() function to set the "infile" and "verbose" parameters of "dmcopy". We then use pget() to check the values.

Note that the verbose value had to be given as a string; the pseti() routine should be used if the input value is an integer.

Example 2

>>> punlearn("dmcopy")
>>> pardict = { "infile": "in.fits", "outfile": "out.fits" }
>>> parfict["clobber"] = "yes"
>>> pset("dmcopy", pardict )
>>> print(pget("dmcopy", "infile"))
>>> print(pget("dmcopy", "outfile"))
>>> print(pget("dmcopy", "clobber"))

The pset() command can set multiple parameters for a tool at once by using a Python dictionary. The keys of the dictionary are the parameter names, and the stored values are used to set the parameter values.

Example 3

>>> punlearn("dmcopy")
>>> fp = paramopen("dmcopy")
>>> pset(fp, "verbose", "3")
>>> print(pget(fp, "verbose"))
>>> paramclose(fp)
>>> print(pget("dmcopy", "verbose"))

If pset() is called with the name of the parameter file, then it opens the file with a mode of "rwL" which means that the value will be stored in the file even if the parameter is a hidden one. This behaviour is shown in the first example when pset() is used to set the value of the "verbose" parameter.

However, in the current example we have used paramopen() to open the parameter file, and have done so with the mode set to "r" (the default value). Therefore the "verbose" parameter will only equal "3" whilst the parameter file is still open. Once it is closed all knowledge of changes to the parameter file are lost, which is why the final pget() call returns "0" instead of "3".

If the paramopen() call is changed to

fp = paramopen("dmcopy", "rwL")

then the final pget() call would display 3.

See Also

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