How To Reduce Python Script Memory Usage

后端 未结 5 1100
庸人自扰
庸人自扰 2021-01-30 03:00

I have a very large python script, 200K, that I would like to use as little memory as possible. It looks something like:

# a lot of data structures
r = [34, 78,         


        
5条回答
  •  旧巷少年郎
    2021-01-30 03:21

    Moving functions around won't change your memory usage. As soon as you import that other module, it will define all the functions in the module. But functions don't take up much memory. Are they extremely repetitive, perhaps you can have less code by refactoring the functions?

    @eumiro's question is right: are you sure your script uses too much memory? How much memory does it use, and why is it too much?

提交回复
热议问题