如果我有一个字符串(0x61
0x62
0xD
),repr
该字符串的函数将返回'ab\r'
.
有没有办法进行反向操作:如果我有字符串'ab\r'
(带字符0x61
0x62
0x5C
0x72
),我需要获取字符串0x61
0x62
0xD
.
我想创建一些Django ORM过滤器查询的一部分,现在我可以这样做:
if some:
Obj.filter(
some_f1=some_v1,
f1=v1,
f2=v2,
f3=v3,
f4=v4,
...
)
else:
Obj.filter(
f1=v1,
f2=v2,
f3=v3,
f4=v4,
...
)
Run Code Online (Sandbox Code Playgroud)
我希望没有代码重复的东西像这样:
Obj.filter(
Q(some_f1=some_v1) if some else True, # what to use instead of True?
f1=v1,
f2=v2,
f3=v3,
f4=v4,
...
)
Run Code Online (Sandbox Code Playgroud) 我有2个输入,当用户按Enter键时,希望切换焦点从第一个到第二个.我尝试将jQuery与Vue混合因为我找不到任何功能可以专注于Vue文档中的某些内容:
<input v-on:keyup.enter="$(':focus').next('input').focus()"
...>
<input ...>
Run Code Online (Sandbox Code Playgroud)
但在输入时我看到控制台中的错误:
build.js:11079 [Vue warn]: Property or method "$" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. (found in anonymous component - use the "name" option for better debugging messages.)warn @ build.js:11079has @ build.js:9011keyup @ build.js:15333(anonymous function) @ build.js:10111
build.js:15333 Uncaught TypeError: $ is not a function
Run Code Online (Sandbox Code Playgroud) 我有:
class MyUser(Model):
today_ref_viewed_ips = ManyToManyField(
UniqAddress,
related_name='today_viewed_users',
verbose_name="Adresses visited referal link today")
...
Run Code Online (Sandbox Code Playgroud)
在一些老生常谈的日常要求中,我这样做:
for u in MyUser.objects.all():
u.today_ref_viewed_ips.clear()
Run Code Online (Sandbox Code Playgroud)
可以通过更新在数据库服务器上完成吗?
MyUser.objects.all().update(...)
Run Code Online (Sandbox Code Playgroud)
好的,我无法更新,谢谢。但我唯一需要的是 TRUNCATE m2m 内部表,是否可以从 django 执行?如何在没有 mysql 控制台“SHOW TABLES”的情况下知道它的名称?
如果我的文本日志文件的大小超过最大值,我想清理它的一些容量:
FileInfo f = new FileInfo(filename);
if (f.Length > 30*1024*1024)
{
var lines = File.ReadLines(filename).Skip(10000);
File.WriteAllLines(filename, lines);
}
Run Code Online (Sandbox Code Playgroud)
但我有例外
System.IO.IOException: The process cannot access the file '<path>' because it is being used by another process.
Run Code Online (Sandbox Code Playgroud)
问题:
我想将默认值从 django 1.8 传递到 DurationField。根据文档,它应该是 datetime.timedelta
from datetime import timedelta
pause = DurationField(default=timedelta(minutes=20))
Run Code Online (Sandbox Code Playgroud)
但是在 makemigrations 上它说:
ValueError: Cannot serialize: datetime.timedelta(0, 1200)
There are some values Django cannot serialize into migration files.
Run Code Online (Sandbox Code Playgroud)
好的。也许我们应该传递整数?
pause = DurationField(default=int(timedelta(minutes=20).total_seconds()))
Run Code Online (Sandbox Code Playgroud)
或者:
pause = DurationField(default=20*60)
Run Code Online (Sandbox Code Playgroud)
makemigrations 运行正常,但在创建对象时我看到:
for obj in self.query.objs
File "/home/web/django_env/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 920, in <listcomp>
for obj in self.query.objs
File "/home/web/django_env/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 918, in <listcomp>
) for f in fields
File "/home/web/django_env/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 710, in get_db_prep_save
prepared=False)
File "/home/web/django_env/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 1683, in get_db_prep_value
return …
Run Code Online (Sandbox Code Playgroud) 我有一些bytearray
长度2*n
:
a1 a2 b1 b2 c1 c2
Run Code Online (Sandbox Code Playgroud)
我需要在每个2字节字中切换字节字节序,并使:
a2 a1 b2 b1 c2 c1
Run Code Online (Sandbox Code Playgroud)
现在我使用下一个方法但是我的任务非常慢:
converted = bytearray([])
for i in range(int(len(chunk)/2)):
converted += bytearray([ chunk[i*2+1], chunk[i*2] ])
Run Code Online (Sandbox Code Playgroud)
是否可以bytearray
通过调用某些system/libc函数来切换endian ?
好的,多亏了所有,我提出了一些建议:
import timeit
test = [
"""
converted = bytearray([])
for i in range(int(len(chunk)/2)):
converted += bytearray([ chunk[i*2+1], chunk[i*2] ])
""",
"""
for i in range(0, len(chunk), 2):
chunk[i], chunk[i+1] = chunk[i+1], chunk[i]
""",
"""
byteswapped = bytearray([0]) * len(chunk)
byteswapped[0::2] = chunk[1::2]
byteswapped[1::2] …
Run Code Online (Sandbox Code Playgroud) 执行:
#define HIGH32(V64) ((uint32_t)((V64 >> 32)&0xffFFffFF))
#define LOW32(V64) ((uint32_t)(V64&0xffFFffFF))
uint32_t a = 0xffFFffFF;
uint32_t b = 0xffFFffFF;
uint64_t res = a * b;
printf("res = %08X %08X\n", HIGH32(res), LOW32(res));
Run Code Online (Sandbox Code Playgroud)
得到:
"res = 00000000 00000001"
Run Code Online (Sandbox Code Playgroud)
但我期待:fffffffe00000001.我做错了什么?单一作业:
res = 0x0123456789ABCDEF;
printf("res = %08X %08X\n", HIGH32(res), LOW32(res));
Run Code Online (Sandbox Code Playgroud)
给
res = 01234567 89ABCDEF
Run Code Online (Sandbox Code Playgroud)
环境:
$gcc --version
gcc (GCC) 4.8.3
Copyright (C) 2013 Free Software Foundation, Inc.
$ gcc -v
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-cygwin/4.8.3/lto-wrapper.exe
dest arch: i686-pc-cygwin
$ file a.exe
a.exe: PE32 executable (console) Intel 80386, for …
Run Code Online (Sandbox Code Playgroud) 我使用Qt QWebView组件,它使用flash播放器进行视频播放.如何在我的QWebView内部执行的flashplayer上禁用声音?
我考虑的一种方法是执行一些javascript代码来禁用播放器上的声音,但何时执行它?例如,如果在调用"load"后1秒运行它,则下一个代码禁用声音:
page.mainFrame().evaluateJavaScript("""
var mute_all_tags=function(tag){
var elems = document.getElementsByTagName(tag);
for(var i = 0; i < elems.length; i++){
elems[i].muted=true;
//alert(elems[i]);
}
}
mute_all_tags("video");
mute_all_tags("audio");
""")
Run Code Online (Sandbox Code Playgroud)
早先的电话不会停止声音.调用QWebView.loadFinished会停止声音但是那时已经发出了一些声音,我该如何立即停止声音?
我想验证智能卡上的PIN1并读取重试计数器.根据ISO 7816-4第54页(1),在验证命令后,重试计数器存储在SW2的2 LSB(SW1应为63)中,但如果密码正确,则我有SW1 SW2 = 90 00:
>> Reset
<< 3b 19 94 80 67 94 08 01 03 02 01 03
>> ff 00 ff
<< ff 00 ff
>> a0 a4 00 00 02
<< a4
>> 3f 00
<< 9f 16
>> a0 f2 00 00 16
<< f2 00 00 63 f4 3f 00 01 00 00 00 00 00 09 33 03 0a 08 00 83 8a 83 8a 90 00
0: pin enabled...
>> …
Run Code Online (Sandbox Code Playgroud) 例如,如果我将 QStatusBar 添加到我的窗口,我会看到太宽的角落:
self.stat = QtGui.QStatusBar()
widLayout = QtGui.QVBoxLayout()
widLayout.addWidget(some_pannel)
widLayout.addWidget(self.stat)
self.setLayout(widLayout)
Run Code Online (Sandbox Code Playgroud)
我有select
和button
:
<select id="s">
<option id="o1">O1</option>
<option id="o2">O2</option>
</select>
<button id="a">O1 -> O11</button>
Run Code Online (Sandbox Code Playgroud)
我想O11
在按下按钮后看到选择:
$('#s').click(function(){
$('#o1').text('O11');
})
Run Code Online (Sandbox Code Playgroud)
但只有在单击选择后才选择刷新.
如果我将通过UDP VPN使用它,应用程序中的TCP是否可靠?例如,我有一个应用程序的VPN服务器在10.8.0.1:8080上侦听TCP,我将从主机10.8.0.2到10.8.0.1:8080从TCP连接.它会可靠吗?
|----------| udp tunnel |----------|
| Server |----------------------| Client |
| 10.8.0.1==========tcp=============10.8.0.2 |
| |----------------------| |
|----------| |----------|
Run Code Online (Sandbox Code Playgroud) python ×4
django ×3
javascript ×2
apdu ×1
bytearray ×1
c ×1
c# ×1
cygwin ×1
django-1.8 ×1
django-orm ×1
django-q ×1
endianness ×1
fileinfo ×1
flash ×1
focus ×1
gcc ×1
io ×1
jquery ×1
logging ×1
many-to-many ×1
openvpn ×1
option ×1
pin-code ×1
pyqt ×1
pyside ×1
qt ×1
qwebview ×1
refresh ×1
repr ×1
select ×1
sim-card ×1
smartcard ×1
sql ×1
swap ×1
tcp ×1
timedelta ×1
udp ×1
vpn ×1
vue.js ×1
windows ×1