scheduling_list = scheduling_list.append(0) AttributeError: 'int' object has no attribute 'append'
时间: 2023-06-23 07:58:28 浏览: 45
这个错误的原因是你尝试将一个整数值(0)添加到一个整数对象(scheduling_list)中。整数类型是不可变类型,没有append()方法,因此你需要将scheduling_list定义为一个可以进行添加操作的可变类型,例如列表(list)或数组(array),然后再执行append()方法。请注意,你应该将scheduling_list定义为一个列表或数组,而不是一个整数。以下是一个示例代码:
```
scheduling_list = []
scheduling_list.append(0)
```
这将创建一个空列表,然后将0添加到列表中。
相关问题
def time_slice_scheduling(processes, time_slice): #时间片轮法 current_time = 0 ready_queue = processes.copy() while any(p.state != State.TERMINATED for p in ready_queue): processes_in_queue = len(ready_queue) current_process = ready_queue.pop(0) if current_process.state == State.TERMINATED: continue if current_process.state == State.NEW: current_process.state = State.RUNNING current_process.runtime = 0 current_process.start_time = current_time current_process.run(time_slice) current_time += time_slice if current_process.state == State.TERMINATED: current_process.end_time = current_time if current_process.state == State.RUNNING and current_process.rest_of_time > 0: ready_queue.append(current_process) if len(ready_queue) == processes_in_queue and current_process.rest_of_time > 0: ready_queue.append(current_process) return [p.end_time - p.start_time for p in processes],[(p.end_time - p.start_time) / p.cpu_time for p in processes],time_slice
这段代码是一个关于时间片轮法的实现,但是需要注意以下事项:
1. 代码中使用了 `State` 类型,但是没有给出其定义,需要确认其定义是否正确,否则代码会报错。
2. `ready_queue = processes.copy()` 将 `processes` 列表复制一遍,但是如果 `processes` 中的元素是对象,复制得到的只是对象的引用,需要确认是否符合需要。
3. `any(p.state != State.TERMINATED for p in ready_queue)` 用于判断是否还有进程未完成,需要确认代码中是否正确地修改了进程的状态。
4. `processes_in_queue = len(ready_queue)` 用于记录当前队列中的进程数,需要确认代码中是否正确地维护了进程队列。
5. `current_process = ready_queue.pop(0)` 用于从队列中取出下一个进程,需要确认代码中是否正确地维护了队列的顺序。
6. `current_process.run(time_slice)` 用于模拟进程运行,需要确认 `run()` 方法的实现是否正确。
7. `current_process.end_time = current_time` 用于记录进程结束时间,需要确认代码中是否正确地记录了时间信息。
8. `ready_queue.append(current_process)` 用于将进程重新加入队列,需要确认代码中是否正确地维护了队列的顺序。
9. `return [p.end_time - p.start_time for p in processes],[(p.end_time - p.start_time) / p.cpu_time for p in processes],time_slice` 返回了进程的运行时间和 CPU 利用率,需要确认代码中的计算是否正确。
以上是需要注意的事项,希望对你有所帮助。
从后端反的数据 go_url : "/Videonine?scheduling_id=52&muid=3" 取出scheduling_id=52
可以使用正则表达式来提取字符串中的scheduling_id,示例代码如下:
```python
import re
string = "/Videonine?scheduling_id=52&muid=3"
pattern = r"scheduling_id=(\d+)"
match = re.search(pattern, string)
if match:
scheduling_id = match.group(1)
print(scheduling_id)
else:
print("No match found.")
```
输出结果为:
```
52
```
这样就成功提取出了字符串中的scheduling_id。