我想导入一些包,具体取决于用户选择的值.
默认为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做到这一点?
像这样的数据库表
============================
= 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) 我想忽略整个public_html /目录,除了里面的一个文件
我给.gitignore如下:
public_html/*
!public_html/config/config.php
Run Code Online (Sandbox Code Playgroud)
但是,当我运行git status时,我找不到config.php已包含在内.
<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) 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发布一些更新时,它总是错误的.
我能知道哪里出错吗?
例如,我有一个表'post'和列'views'.当人们每次查看帖子时,会添加"视图"1.现在我的步骤是
@post = Post.find_by_id(params[:id])
@post.views += 1
@post.save
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来添加"观点"?
<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来检测?