前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >AI协助下菜鸟又变态的2种调试程序方法2024.6.12

AI协助下菜鸟又变态的2种调试程序方法2024.6.12

作者头像
用户7138673
发布2024-06-12 14:39:21
650
发布2024-06-12 14:39:21
举报
文章被收录于专栏:大大的小数据大大的小数据

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:\Users\Administrator\Desktop\调试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:\Users\Administrator\anaconda3\lib\site-packages\pandas\io\excel\_base.py:827 in __new__
    engine = config.get_option(f"io.excel.{ext}.writer", silent=True)

  File d:\Users\Administrator\anaconda3\lib\site-packages\pandas\_config\config.py:243 in __call__
    return self.__func__(*args, **kwds)

  File d:\Users\Administrator\anaconda3\lib\site-packages\pandas\_config\config.py:115 in _get_option
    key = _get_single_key(pat, silent)

  File d:\Users\Administrator\anaconda3\lib\site-packages\pandas\_config\config.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:\Users\Administrator\anaconda3\lib\site-packages\pysnooper\tracer.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:\Users\Administrator\anaconda3\lib\site-packages\pandas\core\generic.py:2284 in to_excel
    formatter.write(

  File d:\Users\Administrator\anaconda3\lib\site-packages\pandas\io\formats\excel.py:834 in write
    writer = ExcelWriter(  # type: ignore[abstract]

  File d:\Users\Administrator\anaconda3\lib\site-packages\pandas\io\excel\_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:\Users\Administrator\Desktop\调试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):
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2024-06-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 大大的小数据 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档