我在某种程度上坚持逻辑思维.
我将比较这两个州的日期:
都包括假期
我如何检查本月/日的学期?
current_month = datetime.datetime.now().month
current_year = datetime.datetime.now().year
current_day = datetime.datetime.now().day
if current_month>=10 and current_day>=15:
#winter semester
Run Code Online (Sandbox Code Playgroud)
但我在某种程度上做得太乱了.是否有任何python库用于我的问题的日期比较?
我从Python开始,但我真的是基于C/C++,所以对我的思考有点不同.我正在使用嵌入的东西,我需要使用字节.例如,我在我的C代码中有我的typedef:u8,s8(unsigned char,signed char)和类似的u16,s16.但是我如何在Python中使用这个想法.例如,我需要得到项目的总和,0xF0 + 0xAA我想得到的0x9A不是0x19A存在一些模块吗?
我有投入s1,s2,s3.我只有在它们确实存在时才需要连接它们.
我做了:
s1 = s1.strip()
s2 = s2.strip()
s3 = s3.strip()
if s1 and s2 and s3:
input = s1 + ' ' + s2 + ' ' + s3
if s1 and s2:
input = s1 + ' ' + s2
if s1 and s3:
input = s1 + ' ' + s3
if s2 and s3:
input = s2 + ' ' + s3
....
...
Run Code Online (Sandbox Code Playgroud)
我不想要test ( white space ) …
我有一个关注和取消关注按钮.当然,当您单击"关注"按钮时,应显示取消关注按钮.单击"关注"按钮时,应显示"取消关注"按钮.
截至目前,当您点击"关注"时,数据库会更新,"关注"按钮消失,并显示"取消关注"按钮.问题是,如果我再次点击"取消关注"按钮,则没有任何反应.即使我放了一个console.log('test'); 在脚本的顶部,没有任何作用.这是我的代码:
使用Javascript:
$(document).ready(function(){
console.log('test');
$('.follow').click(function(){
console.log('yes');
var userid = $(this).attr("id");
var dataString = 'id='+ userid ;
var self = this;
$.ajax({
type: "POST",
url: "/ajax/follow",
data: dataString,
success: function(result) {
var json = $.parseJSON(result);
$(self).remove();
$('#followButton').append(
$('<a href="#" class="button unfollow" id="unfollow_'+ json +'">- unfollow</a>')
);
}
});
});
$('.unfollow').click(function(){
console.log('no');
var id = $(this).attr("id");
var dataString = 'id='+ id ;
var self = this;
$.ajax({
type: "POST",
url: "/ajax/unfollow",
data: dataString,
success: function(result) {
$(self).remove();
$('#followButton').append(
$('<a href="#" …Run Code Online (Sandbox Code Playgroud) 我有
<table class="prodtable">
<tr>
<td></td>
<td>
<input class="editok" value="2" />
</td>
<td>
<input name="prodnumber" value="1" />
<i></i>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
而这个js
$('.prodtable').on('blur','.editok',function(){
var neuanzahl = $(this).val();
$(this).parent('td').text(neuanzahl);//<-- till here works fine
$(this).parent('td').next().find('input').val(neuanzahl);//<-- from here, failure
$(this).parent('td').next().find('i').addClass('icon-pencil');
});
Run Code Online (Sandbox Code Playgroud)
在editok被动态插入的输入,这就是为什么我设置从父表的处理程序.
我的问题是,在模糊事件中,给定输入的值应放在下一个输入中,该输入位于下一个td带有名称的输入中,prodnumger并且<i>应该获取该类icon-pencil.
我现在想要1个小时,真可惜......没有一个成功.我在这做错了什么?
对不起愚蠢的问题首先.
我得到一个相同类型的用户输入列表,如:
<input name="booknames" type="text">
<input name="booknames" type="text">
<input name="booknames" type="text">
Run Code Online (Sandbox Code Playgroud)
并在viws中:
if request.POST.getlist('booknames'):
print 'yes'
else:
print 'no'
Run Code Online (Sandbox Code Playgroud)
即使没有用户输入,我也会得到yes.我打印清单,我得到的[u'']是空的.
我错过了什么吗?
我想找到
f = "[[[someword_1234]]]"
Run Code Online (Sandbox Code Playgroud)
内
s = "weifjwieufh weifuwiefuhw ejfwi eujfh iwueh fiwe [[[someword_1234]]]"
Run Code Online (Sandbox Code Playgroud)
但三方someword_1234括号内的文字可以改变.所以我做不到:
s.find(f)
Run Code Online (Sandbox Code Playgroud)
我怎么能接近这个?
第一个是有意义的,但第二个应该是2,不应该吗?
>>> 1 + 3 if 2>1 else 1
4
>>> 1 + 3 if 2>3 else 1
1
Run Code Online (Sandbox Code Playgroud)
然而,
>>> r = 3 if 2>3 else 1
>>> r
1
Run Code Online (Sandbox Code Playgroud)
为什么它表现不同,或者我错过了什么?
UPDATE
我想
1 + "3 if 2>3 else 1"
Run Code Online (Sandbox Code Playgroud)
将是1 + 3或1 + 1取决于if
var a = "1:2:3:4";
var b = "0:1:5:2";
Run Code Online (Sandbox Code Playgroud)
我想在最后:
var c = "1:3:8:6";
Run Code Online (Sandbox Code Playgroud)
意思是,数字按列相加.
我的解决方案是:
var i, k;
var a_arr = a.split(':');
var b_arr = b.split(':');
for (i=0;i<a_arr.length;i++){
and here again another loop over b_arr
}
Run Code Online (Sandbox Code Playgroud)
好的,我没有解决方案..最可爱的方法是什么?
我怎么知道
word = " a "
Run Code Online (Sandbox Code Playgroud)
它周围有一个空格(它在这里做,但是字是动态的)然后,如果它有,那么strip()它呢?