好奇心的问题...
假设我有以下文件... ~/.emacs、~/.emacs.d/init.el和~/.emacs.el.
现在,假设其中每个都包含单独的代码段,例如:
~/.emacs
(global-set-key (kbd "<f8>") 'execute-extended-command)
~/.emacs.d/init.el
(global-set-key (kbd "<apps>") 'execute-extended-command)
~/.emacs.el
(global-set-key (kbd "<menu>") 'execute-extended-command)
Run Code Online (Sandbox Code Playgroud)
请注意,所有文件都会对execute-extended-command. 当emacs打开时,这些文件中哪个会被执行?全部,其中之一,还是没有?是否有特殊的顺序先执行?另外,拥有多个初始化文件是不是一个坏主意?
任何涉及这些主题的答案以及任何附加信息都足够了,我只是想知道在这种情况下会发生什么。
所以我试图在 SwiftUI 的详细信息视图中隐藏导航栏。我在技术上通过在不同的视图中使用 init() 使其工作,但问题是它使整个应用程序的导航栏透明,我只希望它在一个视图中。我没有在 DetailsView 中使用 init() 的原因是因为我有一个需要输入的变量,所以我不知道该怎么做!这是初始化程序的代码:
init() {
let navBarAppearance = UINavigationBar.appearance()
navBarAppearance.backgroundColor = .clear
navBarAppearance.barTintColor = .clear
navBarAppearance.tintColor = .black
navBarAppearance.setBackgroundImage(UIImage(), for: .default)
navBarAppearance.shadowImage = UIImage()
}
Run Code Online (Sandbox Code Playgroud)
下面是在 detailsView 中使用 init() 的 Content View 和 Details View 代码的样子:
// 内容视图 //
struct ContentView: View {
var body: some View {
NavigationView {
List {
ForEach(0..<5) { i in
NavigationLink(destination: DetailsView(test: 1)) {
Text("DetailsView \(i)")
}
}
}
.listStyle(InsetGroupedListStyle())
.navigationBarTitle("Test App")
}
}
}
Run Code Online (Sandbox Code Playgroud)
// 详情查看 // …
在本地计算机中成功安装 google cloud SDK 后,我遇到了命令行问题:“gcloud init”。错误出现如下:
云初始化
欢迎!此命令将引导您完成 gcloud 的配置。
您当前的配置已设置为:[默认]
您可以使用以下标志下次跳过诊断:gcloud init --skip-diagnostics
网络诊断检测并修复本地网络连接问题。检查网络连接...完成。
可达性检查已通过。
网络诊断已通过(1/1 检查已通过)。
您需要登录才能继续操作。您想登录(是/否)吗?是
错误:gcloud 崩溃(NotADirectoryError):[Errno 20] 不是目录:“xdg-settings”
如果您想报告此问题,请运行以下命令:
云反馈
要检查 gcloud 是否存在常见问题,请运行以下命令:
gcloud 信息 --run-diagnostics "
我尝试使用此链接进行修复,但它在我的环境中不起作用。如果您有任何想法并希望我提供任何内容,请告诉我,请随时询问我。
最好的问候,PNV
我可能缺乏非常基本的Python基础。我正在处理别人制作的脚本。
我有一个脚本,比方说My_Class,其中的代码是:
import thing1
import thing_2
...etc
class My_Class:
def __init__(self, arg1, arg2 ...etc):
self.argument_1 = arg1
self.argument_2 = arg2
...etc
Run Code Online (Sandbox Code Playgroud)
__init__my_class 的参数未作为参数传递给 my_class是否正确?(my_class 根本没有参数)
如果类没有参数,如何arg1, arg2 ...etc传递参数?my_class
难道不应该吗
import thing1
import thing_2
...etc
class My_Class(arg1, arg2 ...etc):
def __init__(self, arg1, arg2 ...etc):
self.argument_1 = arg1
self.argument_2 = arg2
...etc
Run Code Online (Sandbox Code Playgroud)
反而?
笔记:
该类不会被实例化,仅直接在该类上调用其方法,即:
My_Class(arg1, arg2 ...etc).method_1()
Run Code Online (Sandbox Code Playgroud) 我不明白这些是用什么的,尤其是self论证?有些人可以向我解释这个问题吗?为什么你要传递这个呢?
此外,我一直认为__init__是'初始化',但我没有想过我以前从来没有在这里放任何东西.有人能给我一个简单的例子吗?
编辑:我每次看到self被传递到函数或其他类似的东西时都会感到困惑.
class Teller(object):
def __init__(self):
self.occupied = False
self.timeLeft = 0
self.totTime
def occupy(self, timeOcc):
self.occupied = True
self.timeLeft = timeOcc
def nextMin(self):
self.timeLeft -= 1
self.totTime += 1
if self.timeLeft == 0:
self.occupied = False
class Bank(object):
def __init__(numTellers, hoursOpen):
self.tellers = []
self.timeWaited = 0
self.clientsWaiting = []
for x in xrange(numTellers):
tempTeller = Teller.__init__()
self.tellers.append(tempTeller)
self.minutesOpen = hoursOpen * 60
def tellerOpen(self):
for x in xrange(len(self.tellers)):
if not self.tellers[x].occupied:
return x+1
return 0
def runSim(self, queueInput): #queueInput is …Run Code Online (Sandbox Code Playgroud) 我正在编写一个框架,我有一个自定义init方法的对象:
@implementation OSDatabase
@synthesize database;
// MEM
- (void)dealloc {
sqlite3_close(database);
[super dealloc];
}
// INIT
- (id)initWithDatabasePath:(NSString *)path error:(NSError **)error {
if (self = [super init]) {
if (!sqlite3_open_v2([path UTF8String], &database, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)) {
error = [NSError errorWithDomain:@"OSDatabaseErrorDomain" code:1 userInfo:nil];
[self dealloc];
return nil;
}
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
如果出现错误dealloc,在init方法内部调用是否安全?我不确定这一点,记忆管理是我生命中最重要的事情之一.
谢谢.
没有python对象,它看起来很好:
def obj(x={123:'a',456:'b'}):
return x
fb = obj()
print fb
Run Code Online (Sandbox Code Playgroud)
使用python对象,我收到以下错误:
def foobar():
def __init__(self,x={123:'a',456:'b'}):
self.x = x
def getStuff(self,field):
return x[field]
fb = foobar()
print fb.x
Traceback (most recent call last):
File "testclass.py", line 9, in <module>
print fb.x
AttributeError: 'NoneType' object has no attribute 'x'
Run Code Online (Sandbox Code Playgroud)
使用python对象,我收到一个错误:
def foobar():
def __init__(self,x={123:'a',456:'b'}):
self.x = x
def getStuff(self,field):
return x[field]
fb2 = foobar({678:'c'})
print fb2.getStuff(678)
Traceback (most recent call last):
File "testclass.py", line 8, in <module>
fb2 = foobar({678:'c'}) …Run Code Online (Sandbox Code Playgroud) 我有一个自定义的非ARC初始化,我想知道[super init]在释放自我之前是否应该打电话.
解决方案A,[super init]之前没有调用[self release]:
- (instancetype)initWithInteger:(NSInteger)anInteger
{
if (anInteger == 0)
{
[self release];
return nil;
}
self = [super init];
if (!self)
return nil;
// Initialization code
self.i = anInteger;
return self;
}
Run Code Online (Sandbox Code Playgroud)
解决方案B,[super init]之前调用[self release]:
- (instancetype)initWithInteger:(NSInteger)anInteger
{
self = [super init];
if (!self)
return nil;
if (anInteger == 0)
{
[self release];
return nil;
}
// Initialization code
self.i = anInteger;
return self;
}
Run Code Online (Sandbox Code Playgroud) 我有一个Django ModelForm,可以在form __init__()方法中设置某些表单属性。
class MyForm(forms.ModelForm):
class Meta:
model = MyModel
exclude = ['datecreated', 'datemodified']
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields['field1'].widget.attrs['class'] = 'class1'
self.fields['field2'].widget.attrs['class'] = 'class1'
self.fields['field3'].widget.attrs['class'] = 'class1'
# override Google Chrome field error issues making form unfocusable
self.fields['field1'].required = False
self.fields['field2'].required = False
self.fields['field3'].required = False
Run Code Online (Sandbox Code Playgroud)
是否可以设置表格中包含的所有字段的属性,而无需为每个字段分别编写self.fields?