import io


def scalar_to_param(gmpl_param_name, param_value, isstringio=True):
    """
    Convert a scalar to a GMPL representation of a parameter.

    :param gmpl_param_name: name for resulting GMPL param value
    :type gmpl_param_name: str
    :param param_value:
    :param isstringio: True (default) to return StringIO object, False to return string
    :return: GMPL dat code for scalar parameter either as a StringIO object or a string.
    :rtype: StringIO or str

    Example:

     scalar_to_param('n_prds_per_day', 48) -->  'param n_prds_per_day :=  48;'
    """

    param = 'param ' + gmpl_param_name + ' :=  ' + str(param_value) + ';\n'
    if isstringio:
        param_out = io.StringIO()
        param_out.write(param)
        return param_out.getvalue()
    else:
        return param