UserWarning: Spaces are not permitted in the name. Converted to '_'
时间: 2023-12-27 14:05:17 浏览: 205
This warning message is indicating that a name was provided with spaces in it, which is not permitted in the current context. To prevent errors or unexpected behavior, the spaces were automatically converted to underscores. For example, if a user provided the name "John Doe" in a context where spaces are not allowed, it would be converted to "John_Doe".
相关问题
UserWarning: Spaces are not permitted in the name. Converted to '_' warnings.warn("Spaces are not permitted in the name. Converted to '_'")
这个警告是因为在定义决策变量和约束条件的时候,使用了带有空格的名称。PuLP 模块中不允许使用带有空格的名称,因此会将空格自动转换为下划线。
为了避免这个警告,可以将变量和约束条件的名称改成不带空格的形式。例如,将这行代码:
```python
x = LpVariable("一级检验员数量", 0)
```
改成:
```python
x = LpVariable("x", 0)
```
这样就不会产生警告了。
为什么python写代码中,明明名称已经用下划线表示,为什么还是会显示 UserWarning: Spaces are not permitted in the name. Converted to '_'
这是因为Python中不允许使用空格作为名称的一部分。所以,如果你在变量名、函数名或类名中使用空格,Python就会将其转换为下划线。当Python遇到这种情况时,它会弹出一个警告窗口,告诉你它已经将空格转换为下划线。
阅读全文