小编ska*_*gor的帖子

如何在Python中导入变量包,就像在PHP中使用变量变量($$)一样?

我想导入一些包,具体取决于用户选择的值.

默认为file1.py:

from files import file1
Run Code Online (Sandbox Code Playgroud)

如果用户选择file2,它应该是:

from files import file2
Run Code Online (Sandbox Code Playgroud)

在PHP中,我可以使用变量变量:

$file_name = 'file1';
include($$file_name);
Run Code Online (Sandbox Code Playgroud)
$file_name = 'file2';
include($$file_name);
Run Code Online (Sandbox Code Playgroud)

我怎么能用Python做到这一点?

python variables variable-variables

39
推荐指数
5
解决办法
3万
查看次数

使用mysql group by返回0

像这样的数据库表

============================
= suburb_id   |   value
= 1           |    2
= 1           |    3
= 2           |    4
= 3           |    5
Run Code Online (Sandbox Code Playgroud)

查询是

SELECT COUNT(suburb_id) AS total, suburb_id 
  FROM suburbs 
 where suburb_id IN (1,2,3,4) 
GROUP BY suburb_id
Run Code Online (Sandbox Code Playgroud)

但是,当我运行此查询时,当suburb_id = 0时它不会给COUNT(suburb_id)= 0因为在郊区表中没有suburb_id 4,我希望这个查询为suburb_id = 4返回0,就像

============================
= total       |   suburb_id
= 2           |    1
= 1           |    2
= 1           |    3
= 0           |    4
Run Code Online (Sandbox Code Playgroud)

mysql sql group-by count

9
推荐指数
1
解决办法
1万
查看次数

git忽略目录,除了指定

我想忽略整个public_html /目录,除了里面的一个文件

我给.gitignore如下:

public_html/*
!public_html/config/config.php
Run Code Online (Sandbox Code Playgroud)

但是,当我运行git status时,我找不到config.php已包含在内.

git gitignore

9
推荐指数
2
解决办法
3514
查看次数

如何使用jQuery获取attr?

<div class="item">
  <p><img src="images/photos_sample1.jpg" 
          border="0" rel="images/google_map.jpg"></p>
  <p>Dining Area</p>
</div>
<div class="item">
  <p><img src="images/photos_sample2.jpg" 
          border="0" rel="images/sample_photo.jpg"></p>
  <p>Pool Area</p>
</div>
Run Code Online (Sandbox Code Playgroud)

我有上面的HTML代码,我想rel在单击图像时获取属性的值.我写了这个jQuery脚本,但它似乎不起作用:

$('div.item').click(function() {
  var getvalue = $('this > p > img').attr('rel');
  alert(getvalue);
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery attributes

7
推荐指数
1
解决办法
5万
查看次数

如何在rails中更新twitter

def post_to_twitter
message = from some where
url = URI.parse('http://twitter.com/statuses/update.xml')
req = Net::HTTP::Post.new(url.path)
req.basic_auth 'account', 'password'
req.set_form_data({'status' => message})
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
  # ok
else
  # false
end

end
Run Code Online (Sandbox Code Playgroud)

这是twitter更新的代码,当我通过此操作向twitter发布一些更新时,它总是错误的.

我能知道哪里出错吗?

twitter ruby-on-rails

3
推荐指数
1
解决办法
1097
查看次数

rails中的模型更新方法

例如,我有一个表'post'和列'views'.当人们每次查看帖子时,会添加"视图"1.现在我的步骤是

@post = Post.find_by_id(params[:id])
@post.views += 1
@post.save
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来添加"观点"?

database model ruby-on-rails

2
推荐指数
1
解决办法
2685
查看次数

jquery-如何检测子ID?

<div id="first">
    <div id="here">...</div>
</div>
<div id="second">
    <div id="here">...</div>
</div>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$("#second #here").click(function(){});
Run Code Online (Sandbox Code Playgroud)

当我点击第二个时,如何编写jquery来检测?

javascript jquery

1
推荐指数
1
解决办法
7583
查看次数