简体   繁体   English

如何将参数从一个函数传递给另一个函数?

[英]How do you pass arguments from one function to another?

Sorry for the newbie question guys, but I'm relatively new to python. 对不起新手问题的家伙,但我对python相对较新。 I want to write a function that passes keyword and value arguments into another function: 我想编写一个将关键字和值参数传递给另一个函数的函数:

eg 例如

def function_that_passes_arguments(arguments):
    some_other_function(arguments)

so when I call the first function they are passed into the second... eg 所以当我调用第一个函数时,它们会被传递给第二个函数......例如

function_that_passes_arguments(arg1=1, arg2=2)

is effectively 是有效的

some_other_function(arg1=1, arg2=2)

The argument names will change so it is important that I pass both keyword and value from one function to another. 参数名称将更改,因此将关键字和值从一个函数传递到另一个函数非常重要。

Accept *args, **kwargs and pass those to the called function: 接受*args, **kwargs并将它们传递给被调用的函数:

def function_that_passes_arguments(*args, **kwargs):
    some_other_function(*args, **kwargs)

In both places you can also use regular arguments - the only requirement is that the * and ** arguments are the last ones. 在这两个地方你也可以使用常规参数 - 唯一的要求是***参数是最后一个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将参数传递给数组中的函数? - How do you pass arguments to a function within an array? 如何透明地将参数传递给python中的函数? - How do you transparently pass arguments through to a function in python? python:从一个函数传递多个参数到另一个函数 - python: pass multiple arguments from one function to another 如何在另一个 function 中传递带有 arguments 的 function? - How do I pass a function with arguments in another function? 如何传递给一个 function,它需要两个 arguments 一个列表中的一个元素以及另一个列表中的每个元素? - How to pass to a function that takes two arguments an element from one list together with each element of another list? 如何将可变长度参数传递给另一个函数的参数? - How do I pass variable length arguments to parameters of another function? Python 3:如何从另一个文件调用函数并将参数传递给该函数? - Python 3: How to call function from another file and pass arguments to that function ? 如何将命名参数传递给另一个函数需要的函数? - How do you pass a named parameter into a function that another function needs? 如何将命令行参数从一个python模块传递到另一个python模块 - How to pass command line arguments from one python module to another 如何将参数从服务器上的一个python脚本传递给另一个? - How to pass arguments from one python script on the server to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM