python - 使用一个函数调用另一个函数
问题描述
我正在尝试使用该memory_profiler
软件包。下面的示例代码:
from memory_profiler import memory_usage
from time import sleep
def f():
# a function that with growing
# memory consumption
a = [0] * 1000
sleep(.1)
b = a * 100
sleep(.1)
c = b * 100
return a
mem_usage = memory_usage(f)
print('Memory usage (in chunks of .1 seconds): %s' % mem_usage)
print('Maximum memory usage: %s' % max(mem_usage))
我面临的问题是我想尝试的实际功能需要参数。
def my_func(df1, df2):
new_df = pd.concat([df1, df2])
return new_df
有没有办法创建一个运行我的真实函数的shell函数,以便我可以使用这个包?
def shell_function():
new_df = my_func(df1, df1)
return new_df
代码来自这篇文章的第二个答案:Tracking *maximum* memory usage by a Python function
解决方案
推荐阅读
- twig - 如何强制 symfony 表单只显示和接受正整数?
- flutter - BigQuery http post 请求 Dart/Flutter
- sql-server - 尝试连接到 localhost 时获取网络相关或特定于实例
- php - 代码在 wordpress 上什么也不显示:while (have_posts()) {the_post();?>
- maven - AEM - 保险库 -package filter.xml 查询
- asp.net - IIS 突然服务乱码 UTF-8
- c# - 反编译的 NewLateBinding 值
- javascript - Sequelize user.increment("somethings") 不更新值
- c# - 使用 C# serial.write 拉出任何 Arduino 引脚
- ionic-framework - 将 Ionic 5.0 升级到 5.3 命令