1、请给程序的每一行都增加一个print这一行的变量来调试debug
2、程序增加Debug神器pysnooper库来调试
代码语言:javascript复制# -*- coding: utf-8 -*-
"""
Created on Wed Jun 12 11:25:42 2024
@author: Administrator
"""
import pandas as pd
import pysnooper
def write_numbers_to_excel():
# 创建一个包含1到100的数字列表
numbers = list(range(1, 101))
print(f"Numbers: {numbers}") # 打印变量 numbers
# 将列表转换为DataFrame
df = pd.DataFrame(numbers, columns=['Number'])
print(f"DataFrame:n{df}") # 打印变量 df
# 将DataFrame写入Excel文件
output_path = 'numbers_1_to_100.xlsx' # 添加文件扩展名
print(f"Output path: {output_path}") # 打印变量 output_path
df.to_excel(output_path, index=False)
print("Excel file saved successfully") # 确认保存成功
write_numbers_to_excel()
我们很懒,不可能每一行代码都写print,让AI批量写,调试后再批量取消
代码语言:javascript复制runfile('C:/Users/Administrator/Desktop/调试2024.6.12.py', wdir='C:/Users/Administrator/Desktop')
Source path:... C:UsersAdministratorDesktop调试2024.6.12.py
11:29:08.813790 call 12 def write_numbers_to_excel():
11:29:08.814790 line 14 numbers = list(range(1, 101))
New var:....... numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
11:29:08.814790 line 17 df = pd.DataFrame(numbers, columns=['Number'])
New var:....... df = Number0 11 22 33 ... 9898 9999 100[100 rows x 1 columns]
11:29:08.814790 line 20 output_path = 'numbers_1_to_100.xlsx'
New var:....... output_path = 'numbers_1_to_100'
11:29:08.817789 line 21 df.to_excel(output_path, index=False)
11:29:08.820789 exception 21 df.to_excel(output_path, index=False)
Exception:..... ValueError: No engine for filetype: ''
Call ended by exception
Elapsed time: 00:00:00.011999
Traceback (most recent call last):
File d:UsersAdministratoranaconda3libsite-packagespandasioexcel_base.py:827 in __new__
engine = config.get_option(f"io.excel.{ext}.writer", silent=True)
File d:UsersAdministratoranaconda3libsite-packagespandas_configconfig.py:243 in __call__
return self.__func__(*args, **kwds)
File d:UsersAdministratoranaconda3libsite-packagespandas_configconfig.py:115 in _get_option
key = _get_single_key(pat, silent)
File d:UsersAdministratoranaconda3libsite-packagespandas_configconfig.py:101 in _get_single_key
raise OptionError(f"No such keys(s): {repr(pat)}")
OptionError: "No such keys(s): 'io.excel..writer'"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File ~Desktop调试2024.6.12.py:25
write_numbers_to_excel()
File d:UsersAdministratoranaconda3libsite-packagespysnoopertracer.py:305 in simple_wrapper
return function(*args, **kwargs)
File ~Desktop调试2024.6.12.py:21 in write_numbers_to_excel
df.to_excel(output_path, index=False)
File d:UsersAdministratoranaconda3libsite-packagespandascoregeneric.py:2284 in to_excel
formatter.write(
File d:UsersAdministratoranaconda3libsite-packagespandasioformatsexcel.py:834 in write
writer = ExcelWriter( # type: ignore[abstract]
File d:UsersAdministratoranaconda3libsite-packagespandasioexcel_base.py:831 in __new__
raise ValueError(f"No engine for filetype: '{ext}'") from err
ValueError: No engine for filetype: ''
代码语言:javascript复制import pandas as pd
import pysnooper
@pysnooper.snoop()
def write_numbers_to_excel():
# 创建一个包含1到100的数字列表
numbers = list(range(1, 101))
# 将列表转换为DataFrame
df = pd.DataFrame(numbers, columns=['Number'])
# 将DataFrame写入Excel文件
output_path = 'numbers_1_to_100.xlsx' # 添加 .xlsx 扩展名
df.to_excel(output_path, index=False)
print(f"Excel file saved to {output_path}")
write_numbers_to_excel()
代码语言:javascript复制runfile('C:/Users/Administrator/Desktop/调试2024.6.12.py', wdir='C:/Users/Administrator/Desktop')
Source path:... C:UsersAdministratorDesktop调试2024.6.12.py
11:29:08.813790 call 12 def write_numbers_to_excel():
11:29:08.814790 line 14 numbers = list(range(1, 101))
New var:....... numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
11:29:08.814790 line 17 df = pd.DataFrame(numbers, columns=['Number'])
New var:....... df = Number0 11 22 33 ... 9898 9999 100[100 rows x 1 columns]
11:29:08.814790 line 20 output_path = 'numbers_1_to_100.xlsx'
New var:....... output_path = 'numbers_1_to_100'
11:29:08.817789 line 21 df.to_excel(output_path, index=False)
11:29:08.820789 exception 21 df.to_excel(output_path, index=False)
Exception:..... ValueError: No engine for filetype: ''
Call ended by exception
Elapsed time: 00:00:00.011999
Traceback (most recent call last):