如果我有一个文件指针,是否可以获取文件名?
fp = open("C:\hello.txt")
Run Code Online (Sandbox Code Playgroud)
可以"hello.txt"使用fp吗?
我正在编写一个简单的C++程序来演示锁的使用.我正在使用codeblocks和gnu gcc编译器.
#include <iostream>
#include <thread>
#include <mutex>
using namespace std;
int x = 0; // shared variable
void synchronized_procedure()
{
static std::mutex m;
m.lock();
x = x + 1;
if (x < 5)
{
cout<<"hello";
}
m.unlock();
}
int main()
{
synchronized_procedure();
x=x+2;
cout<<"x is"<<x;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:mutex in namespace std does not name a type.
为什么我收到此错误?编译器是否支持使用锁?
我有admin.py如下:
class profilesAdmin(admin.ModelAdmin):
list_display = ["type","username","domain_name"]
Run Code Online (Sandbox Code Playgroud)
现在我想在删除对象之前执行一些操作:
class profilesAdmin(admin.ModelAdmin):
list_display = ["type","username","domain_name"]
@receiver(pre_delete, sender=profile)
def _profile_delete(sender, instance, **kwargs):
filename=object.profile_name+".xml"
os.remove(os.path.join(object.type,filename))
Run Code Online (Sandbox Code Playgroud)
如果我使用像这样的删除信号方法我得到一个错误说self应该是第一个参数.
如何修改上述功能?
我想检索被删除对象的profile_name.如何才能做到这一点?
我也尝试重写delete_model方法:
def delete_model(self, request, object):
filename=object.profile_name+".xml"
os.remove(os.path.join(object.type,filename))
object.delete()
Run Code Online (Sandbox Code Playgroud)
但如果必须一次删除多个对象,这不起作用.
如何从数据库中删除特定数量的条目?我做了这样的事
EntriesToDelete=Statusmessages.objects.filter(time__lt=date)[:30000]
EntriesToDelete.delete()
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误,上面写着:
AssertionError. Cannot use 'limit' or 'offset' with delete.
如何指定要删除的条目数.
我有一个媒体类,如下
class helloAdmin(admin.ModelAdmin):
class Media:
js = ['choice.js']
admin.site.register(hello,helloAdmin)
Run Code Online (Sandbox Code Playgroud)
staticfiles应用程序STATIC_URL位于媒体路径之前。但我想MEDIA_URL,以预先考虑,而不是STATIC_URL和STATIC_URL不为空。如何才能做到这一点?
我在django admin中有一个模型如下
ChoiceA= (
("on-false","on-false"),
("on-true","on-true"),
)
ChoiceB = (
("always","always"),
("never","never"),
)
id = models.CharField(verbose_name="Field",max_length=32)
type = models.CharField(verbose_name="Expression",max_length=32)
action = models.CharField(max_length=32, choices=x)
Run Code Online (Sandbox Code Playgroud)
现在根据用户输入的类型,即如果用户输入type ="a",则应将操作选项设置为ChoiceA,如果用户输入type ="b",则应将操作选项设置为ChoiceB.如何在Django Admin中实现这一目标?
编辑:
action_change.js
jQuery(document).ready(function(){
$("#id_type").change( function(event) {
$.ajax({
"type" : "POST",
"url" : "/action_choices/",
"dataType" : "json",
"cache" : false,
"error" : alert("hello"),
"success" : function(json) {
$('#id_action >option').remove();
for(var j = 0; j < json.length; j++){
$('#id_action').append($('<option></option>').val(json[j][0]).html(json[j][1]));
}
}
});
});
});
Run Code Online (Sandbox Code Playgroud) 我想匹配以下网址
url(r'^home/Physician|Vendor/$, 'ViewerLog', name="monitor_viewerLog"),
Run Code Online (Sandbox Code Playgroud)
我如何匹配医生或供应商?这是正确的方法吗?
可能重复:
如何在C++循环中生成不同的随机数?
这是我的代码:
for(i=0;i<10;i++)
{
srand ( time(NULL) );
cout<<time(NULL);
max=100,min=0;
for(j=0;j<3;j++)
{
cout<<(( (rand() % (max - min + 1)) + min)%5);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我得到输出:
1357207288 0 1 4
1357207289 0 1 4
1357207290 0 1 4
等等.我想每次都得到不同的随机数.我怎样才能做到这一点.
我有
k= (('answer ', ' Answer the call for a channel(answer )'), ('att_xfer ', ' Attended Transfer(att_xfer )'), ('bind_digit_action ', ' Bind a key sequence or regex to an action.(bind_digit_action )'))
Run Code Online (Sandbox Code Playgroud)
我想去掉所有多余的空格。我怎样才能做到这一点
django ×5
python ×4
django-admin ×3
c++ ×2
django-urls ×1
locking ×1
mingw ×1
random ×1
regex ×1