如果我正在使用partial建立函数调用,是否有任何方法可以查询partial以查看是否已提供该函数的所有参数?例如,在下面的代码中,我可以将empty_partial
,partial_partial
和full_partial
传递给任何函数,这些函数仅在True
上返回full_partial
,表明是否提供了所有参数?
from functools import partial
def foo(bar, baz):
return bar + baz
empty_partial = partial(foo)
partial_partial = partial(empty_partial, bar=3)
full_partial = partial(partial_partial, baz=5)
print(full_partial())
# 8
如果我尝试调用空白部分,则会收到如下消息:
empty_partial = partial(foo)
empty_partial()
TypeError: foo() missing 2 required positional arguments: 'bar' and 'baz'
我在哪里得到此错误,如果我确实调用了它,那么它将丢失2个必需的参数(而不必尝试调用它并分析错误)?
答案 0 :(得分:2)
获取部分对象的签名,然后检查以确保<script src="https://shampouya.5gbfree.com/jquery1.9.0.min.js"></script>
<link rel="stylesheet" href="https://shampouya.5gbfree.com/ProductionPayrollHomeFlexslider.css" type="text/css" media="screen" />
<script defer src="https://shampouya.5gbfree.com/flexslider.js"></script>
<script defer src="https://shampouya.5gbfree.com/carousel.js"></script> <!--referred to as modernizr.js in the flexslider package-->
<link href='https://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet'>
<script type="text/javascript">
$(window).load(function() {
$('#carousel').flexslider({
animation: "slide",
controlNav: false,
animationLoop: false,
slideshow: false,
itemWidth: 210,
itemMargin: 5,
asNavFor: '#slider'
});
$('#slider').flexslider({
animation: "slide",
controlNav: false,
animationLoop: false,
slideshow: false,
sync: "#carousel"
});
});
</script>
<style>
.flex-nav-prev, .flex-nav-next{display: none;} /*hide the left and right arrows*/
#BackgroundContainer{
background-color: white;
height: 1180px;
background-size: cover;
}
.profile_container{
height: 163px;
width: 144px;
overflow: hidden;
display: inline-block;
vertical-align: top;
background-color: rgba(207, 232, 221, 0.6); /*light green almost transparent*/
margin-right: 10px;
margin-bottom: 10px;
border: 2px solid #99D1E0;
border-radius: 5px;
text-align: -webkit-center;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-ms-transition: all .3s ease;
-o-transition: all .3s ease;
}
.profile_container span{
display: block;
width: 123px;
margin-bottom: 5px;
text-align: center;
font-family: 'Comfortaa' !important;
font-weight: bold;
margin-right: auto;
margin-left: auto;
font-size: 11px;
}
.profile_container .employee_name{
line-height: 18px;
color: #395880;
font-size: 14px !important;
word-spacing: 120px;
width: 130px;
}
.profile_container .job_title{
line-height: 17px;
}
.pic_container{
height: 130px;
width: 124px;
border-radius: 150px;
position: relative;
margin-left: auto;
margin-right: auto;
margin-bottom: 16px;
overflow: hidden;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-ms-transition: all .3s ease;
-o-transition: all .3s ease;
}
.profile_pic{height: 160px;}
.Team_Container{margin-left: 10px; position: relative; z-index: 0;}
.Team_Container:hover{z-index: 1;}
.Team_Container div:hover{ /*when the user hovers over the profile-containing div*/
height: 343px;
background-color: rgba(176, 196, 222, 0.9) !important; /*purplish blue almost opaque*/
border-color: #7795BF !important;
box-shadow: 0px 8px 20px 1px grey;
}
.Team_Container div div:hover{height: 160px; background-color: aqua;} /*when the user hovers over the picture-containing inner div*/
.Team_Container_Row2{
position: absolute;
top: 193px;
}
.Team_Container_Row3{
position: absolute;
top: 373px;
}
.flexslider{
margin-top: 4px;
border: none !important; /*overrides the flexslider.css file style*/
}
.flex-viewport{width: 820px; height: 750px;}
.flex-active-slide{width: 820px;}
#slider{
background: none;
margin-bottom: 20px; /*overrides the flexslider.css file style*/
min-height: 370px; /*no longer necessary? this reserves height for the slider and makes sure that the blurb at the bottom stays there as the page loads*/
}
#carousel{
height: 40px;
width: 910px;
margin-right: 10px;
margin-bottom: 0px;
background-color: transparent;
}
#carousel li{
text-align: center;
}
#carousel span{
font-family: comfortaa;
color: #165D7A;
font-size: 20px;
line-height: 37px;
text-align: center;
}
.department_description_container{
width: 780px;
min-height: 90px;
vertical-align: middle;
border-radius: 10px;
background: linear-gradient(#DAE0E3, #C1D3DB);
border: solid 2px #7F9AAD;
padding: 10px;
margin-left: 10px;
top: 560px;
position: absolute;
z-index: 0;
}
#department_description{
font-family: comfortaa;
color: #304F5E;
font-size: 16px;
}
</style>
<div id="BackgroundContainer">
<br>
<div id="carousel" class="flexslider">
<ul class="slides">
<li><a href="#"><span>Department1</span></a></li>
<li><a href="#"><span>Department2</span></a></li>
</ul>
</div>
<div id="slider" class="flexslider">
<ul class="slides">
<li>
<div class="Team_Container" id="team1">
<div class="profile_container">
<div class="pic_container"></div>
<span class="employee_name">Person1 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container">
<div class="pic_container"></div>
<span class="employee_name">Person2 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container">
<div class="pic_container"></div>
<span class="employee_name">Person3 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container">
<div class="pic_container"></div>
<span class="employee_name">Person4 LastName</span> <br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container">
<div class="pic_container"></div>
<span class="employee_name">Person5 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
</div>
<div class="Team_Container Team_Container_Row2">
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person6 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person7 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person8 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person9 LastName</span> <br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person10 LastName</span> <br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
</div>
<div class="Team_Container Team_Container_Row3">
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person11 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person12 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person13 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
</div>
<div class="department_description_container">
<span id="department_description">Department 1 does X, Y, and Z.</span>
</div>
</li>
<li>
<div class="Team_Container" id="team1">
<div class="profile_container">
<div class="pic_container"></div>
<span class="employee_name">Person1 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container">
<div class="pic_container"></div>
<span class="employee_name">Person2 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container">
<div class="pic_container"></div>
<span class="employee_name">Person3 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container">
<div class="pic_container"></div>
<span class="employee_name">Person4 LastName</span> <br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container">
<div class="pic_container"></div>
<span class="employee_name">Person5 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
</div>
<div class="Team_Container Team_Container_Row2">
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person6 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person7 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person8 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person9 LastName</span> <br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
<div class="profile_container"><div class="pic_container"></div>
<span class="employee_name">Person10 LastName</span><br>
<span class="job_title">Job Position</span>
<span>Department</span>
</div>
</div>
<div class="department_description_container">
<span id="department_description">Department 2 does U, V, and W.</span>
</div>
</li>
</ul>
</div>
</div>
不会引发TypeError
signature.bind
应该可以解决问题(需要足够新的python以支持函数签名)