debugging VSC从文件中预加载包含重对象的会话,而不是在运行代码时创建它们

prdp8dxp  于 2022-12-13  发布在  其他
关注(0)|答案(1)|浏览(139)

In a general case, is there a way in VSC that each time we launch the debugger we pre-load the session with objects coming from a file? For example, dataframes? Because each time each launches it has no objects at all and needs the running code to start creating the objects.
So the challenge is when we already have some files on hard-drive with heavy objects, but when we launch the debugg I can't tell it to just pre-load those objects stored in those files, say dataframes or lists or connection objects or whatever.
To be more specific. If there's a python code that has two sections of code:

  1. Section 1: Code we know works perfectly and makes heavy calculations to create some objects
  2. Section 2: Code that takes those objects and performs operations. We want to debug this section. We also know no code line in this section interacts in any way with the code or stacks of Section1. It simply takes the objects created from section 1
    Example: Section 1 queries an enormous table and puts it as a dataframe, sorts it, filters, etc... Then Section 2 just needs that dataframe and makes some statistics.
    Is there a way that we just launch from section 2 and we load that dataframe we have stored in a csv? Or do we need to launch always from section 1, run the connection, get the dataframe from a query (which takes a lot of time) and then finally arrive to section 2 to start debugging?
    Note. I could just make a .py file having section 2 code, and hard-coding on it at the begging to just read the csv I have. But is there a fancier way to do this without having to make another .py file for debugging and manually writing code to it, and then debugging that .py file?
    The question is: Launch VSC python debugger telling it to load python objects from files in folders, rather than launching the session with no objects. Waiting for the code to create them
tkqqtvp1

tkqqtvp11#

在调试之前,无法将csv文件转换为python对象,因为所有的Python对象都在内存中。
如果您不想在代码中设置它们,我建议使用环境变量,并通过在launch.json中添加“env”来设置它。

相关问题