>733 2022-08-06 16:12 采纳率: 0%
浏览 210

运行python时报错, TypeError: cannot concatenate 'str' and 'NoneType' objects,如何解决?

运行py文件时报错, TypeError: cannot concatenate 'str' and 'NoneType' objects

问题相关代码
```def load_env_variable(variable, default, variable_type=int):
    """
    Loading environmental variables
    :param variable: name of the variable
    :param default: default value if the environmental variable is not defined within .env
    :param variable_type: form that the variable should take
    :return:
    """
    if variable in os.environ:
        if variable_type is int:
            return int(os.environ[variable])
        elif variable_type is float:
            return float(os.environ[variable])
        elif variable_type is str:
            return str(os.environ[variable])
        elif variable_type is bool:
            return bool(int(os.environ[variable]))
    else:
        return default


SUBMISSION = load_env_variable("SUBMISSION", default=None, variable_type=str)
os.system('echo "run="' + SUBMISSION)

运行结果及报错内容
Traceback (most recent call last):
  File "./settings.py", line 31, in <module>
    os.system('echo "run="' + SUBMISSION)
TypeError: cannot concatenate 'str' and 'NoneType' objects

  • 写回答

2条回答 默认 最新

  • 亖夕 新星创作者: python技术领域 2022-08-06 16:23
    关注

    img

    评论

报告相同问题?

问题事件

  • 创建了问题 8月6日