假设我有一个基类A1和派生类B1和B2。例如(人为):
class A1
{
public:
int foo(int input);
};
class B1: public A1
{
public:
int bar(int input) { return foo(input); }
};
class B2: public A1
{
public:
int bar(int input) { return foo(foo(input)); }
};
Run Code Online (Sandbox Code Playgroud)
是否可以创建与B1和B2相同但从A2而不是A1派生的类C1和C2,而不必重新定义“ B”?即我只想将“ foo”换成C1和C2中的另一个函数,而无需如下重新定义:
class A2
{
public:
int newFoo(int input);
};
class C1: public A2
{
public:
int bar(int input) { return newFoo(input); }
};
class C2: public A2
{
public:
int bar(int input) { return newFoo(newFoo(input)); }
};
Run Code Online (Sandbox Code Playgroud) 我已经安装了Android Studio和Cordova.我创建了一个名为myapp的新Cordova项目.我通过工具 - > Android - > AVD Manager设置了模拟器,选择:
4.65" 720p (Galaxy Nexus)
Run Code Online (Sandbox Code Playgroud)
设备显示:
$ cordova run --list
Available android devices:
Available android virtual devices:
4.65_720p_(Galaxy_Nexus)_API_23
Run Code Online (Sandbox Code Playgroud)
当我尝试在此模拟器上构建和运行项目时,我收到以下错误消息:
$ cordova emulate android
...
BUILD SUCCESSFUL
Total time: 1.284 secs
Built the following apk(s):
/home/daniel/cordova/myapp/platforms/android/build/outputs/apk/android-debug.apk
ANDROID_HOME=/home/daniel/Android/Sdk
JAVA_HOME=/usr/lib/jvm/jre1.8.0_101
No emulator specified, defaulting to 4.65_720p_(Galaxy_Nexus)_API_23
Waiting for emulator to start...
emulator: ERROR: virtual device name contains invalid characters
emulator: could not find virtual device named '4.65_720p_(Galaxy_Nexus)_API_23'
Run Code Online (Sandbox Code Playgroud) 我已经使用 Code::Blocks 编译了一个程序。我已经在“调试”目标下打开了“生成调试符号”,并且还关闭了“剥离所有符号...”但是当我使用 Valgrind 运行程序时,我在输出中出现问号:
$ valgrind --leak-check=yes --track-origins=yes --log-file=valgrind_output.txt
~/bin/myprg
==3766== Memcheck, a memory error detector
==3766== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==3766== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==3766== Command: /home/xxxxxx/bin/myprg
==3766== Parent PID: 3209
==3766==
==3766== Warning: client switching stacks? SP change: 0xffefff978 --> 0xffed13da0
==3766== to suppress, use: --max-stackframe=3062744 or greater
==3766== Invalid write of size 4
==3766== at 0x40892B: ??? (in /home/xxxxxx/bin/myprg)
==3766== by 0x40275C: …Run Code Online (Sandbox Code Playgroud) 如何更改 Qt Creator / Designer 右上角小部件的顺序,其中显示“对象类”?我试图通过单击“对象”下的名称以及单击“类”下的文本来向上拖动我的小部件,但两种方法都不起作用。我不想更改小部件的选项卡顺序,只想更改设计器中的顺序。
我在“models.py”中有一个日期时间:
class Foo(models.Model):
modified = models.DateTimeField()
Run Code Online (Sandbox Code Playgroud)
当我在模板中显示它时,它会根据我的区域设置(我处于英国夏令时间)正确显示:
{{ foo.modified }}
Run Code Online (Sandbox Code Playgroud)
设置:
LANGUAGE_CODE = 'en-gb'
TIME_ZONE = 'Europe/London'
USE_I18N = True
USE_L10N = True
USE_TZ = True
Run Code Online (Sandbox Code Playgroud)
正确输出我所期望的“2020 年 9 月 7 日下午 2:43”(在视图中打印“已修改”给出“2020-09-07 13:43:40.988953+00:00”)。
但是,当我尝试将此格式复制到视图中的字符串时,我得到了错误的日期/时间(它没有调整一小时):
from django.utils.formats import localize
from app.models import Foo
foo = get_object_or_404(Foo, pk=1)
modified = localize(foo.modified, use_l10n=True)
print(modified)
Run Code Online (Sandbox Code Playgroud)
输出“7 Sep 2020, 1:43 pm”,这是错误的。
我尝试了该线程上的其他答案,但没有输出调整后的日期时间: Stack Overflow thread
class Foo(models.Model):
class Bar(models.TextChoices):
CODE_A = 'A', "special code A"
CODE_B = 'B', "not so special code B"
bar = models.CharField(max_length=1, choices=Bar.choices)
Run Code Online (Sandbox Code Playgroud)
文本选择看起来像元组,但事实并非如此:
print(Foo.Bar.CODE_A[1])
Run Code Online (Sandbox Code Playgroud)
给出“IndexError:字符串索引超出范围”。我本来期待得到“特殊代码A”。如何以编程方式从视图访问代码字符串,而不是从模板内访问,而不仅仅是代码常量?
我尝试使用 get_urls 成员函数将非基于模型的 URL 添加到管理页面:
from django.contrib.admin.sites import AdminSite
from django.conf.urls import url
from myapp.models import Bar
class StaffAdmin(AdminSite):
site_header = 'My App'
site_title = site_header
def get_urls(self):
urls = super(StaffAdmin, self).get_urls()
my_urls = [
url(r'^foo/$', self.foo_view, name='foo'),
]
return my_urls + urls
def foo_view(self, request):
context = dict(
self.admin_site.each_context(request),
key=value,
)
return TemplateResponse(request, 'foo_view.html', context)
staff_admin_site = StaffAdmin()
staff_admin_site.register(Bar)
Run Code Online (Sandbox Code Playgroud)
Bar 在员工管理页面上显示正常,但缺少 foo。
参考: https: //docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_urls
我正在尝试从Python调用带有数组参数的C函数的测试项目:
test.cpp:
void testFn(int arr[]);
void testFn(int arr[])
{
arr[0] = 1;
arr[1] = 2;
}
Run Code Online (Sandbox Code Playgroud)
caller.pyx:
import ctypes
cdef extern from "test.cpp":
void testFn(int arr[])
def myTest():
a = [0, 0]
arr = a.ctypes.data_as(ctypes.POINTER(ctypes.c_integer))
testFn(arr)
print(arr)
Run Code Online (Sandbox Code Playgroud)
setup.caller.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
sourcefiles = ['caller.pyx']
ext_modules = [Extension("caller", sourcefiles)]
setup(
name = 'test app',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试构建项目时,出现错误:
$ python setup.caller.py build_ext --inplace
running …Run Code Online (Sandbox Code Playgroud) 说我有两个班:
class Foo
{
public:
int x;
};
class Bar
{
public:
Foo *foo;
};
Run Code Online (Sandbox Code Playgroud)
一个实例如下:
Bar *bar;
bar = new Bar();
Run Code Online (Sandbox Code Playgroud)
以及通过引用获取Foo对象的函数:
void func(Foo &foo);
Run Code Online (Sandbox Code Playgroud)
使用bar中的foo调用此函数的正确方法是什么,如bar-> foo?
假设我有如下视图:
class FooView(ListAPIView):
serializer_class = FooSerializer
pagination_class = FooPagination
Run Code Online (Sandbox Code Playgroud)
它返回一个典型的分页响应,例如:
{
"count":2,
"next":null,
"previous":null,
"results":[
{
"id":1,"name":"Josh"
},
{
"id":2,"name":"Vicky"
}]
}
Run Code Online (Sandbox Code Playgroud)
如何(如果可能)将自定义字段添加到此响应中以使结果如下?
{
"count":2,
"next":null,
"previous":null,
"custom":"some value",
"results":[
{
"id":1,"name":"Josh"
},
{
"id":2,"name":"Vicky"
}]
}
Run Code Online (Sandbox Code Playgroud)
假设“某个值”以适当的方法计算并存储,例如:
def get_queryset(self):
self.custom = get_custom_value(self)
# etc...
Run Code Online (Sandbox Code Playgroud) django ×4
c++ ×3
python ×3
android ×1
codeblocks ×1
cordova ×1
cython ×1
linux ×1
pagination ×1
python-3.x ×1
qt ×1
qt-creator ×1
qt-designer ×1
valgrind ×1