好吧,我也是SO,OOP和python的新手,所以请温柔;)
我在其他地方寻找与此范围问题相关的线索和解释,但没有发现任何问题.如有任何帮助,我将不胜感激.
示例代码:
class Zeus(object):
def __init__(self):
self.name='zeus'
self.maze=Maze()
self.maze.get_zeus_name_1()
self.maze.get_zeus_name_2(self)
self.get_name_1()
self.get_name_2(self)
def get_name_1(self):
try:
print zeus.name
except:
print "impossible!?"
def get_name_2(self,scope):
print scope.name
class Maze(object):
def get_zeus_name_1(self):
try:
print zeus.name
except:
print "can't be done!?"
def get_zeus_name_2(self,scope):
print scope.name
zeus=Zeus()
print 'now external calls:'
zeus.maze.get_zeus_name_1()
zeus.maze.get_zeus_name_2(zeus)
zeus.get_name_1()
zeus.get_name_2(zeus)
Run Code Online (Sandbox Code Playgroud)
输出:
can't be done!?
zeus
impossible!?
zeus
now external calls:
zeus
zeus
zeus
zeus
Run Code Online (Sandbox Code Playgroud)
在实例化期间zeus,如果__init__方法创建另一个类的实例maze,则此新实例无法访问其创建者对象zeus(除非self传递给它).(另外,如果__init__方法在其自己的类中调用方法get_name_1,则该方法也无法访问其对象属性(除非self …
码:
class MyClass:
def __init__(self, aa ):
print('aa='+str(aa)+' of type '+str(type(aa)))
self.aa = aa,
print('self.aa='+str(self.aa)+' of type '+str(type(self.aa)))
DEBUG = MyClass(aa = 'DEBUG')
Run Code Online (Sandbox Code Playgroud)
输出:
aa=DEBUG of type <type 'str'>
self.aa=('DEBUG',) of type <type 'tuple'>
Run Code Online (Sandbox Code Playgroud)
为什么会self.aa成为元组而不是字符串?
我是第一次尝试使用暴发户.我有两个我想要开始的java程序.第一个是在jetty上运行的solr搜索服务器,第二个是应该在solr服务器启动后启动的自定义搜寻器.
我的爬虫初始化脚本如下所示:
description "crawler"
author ""
start on runlevel [2345]
stop on runlevel [!2345]
respawn
script
cd /home/crawler
java -Duser.timezone=Europe/Berlin -jar crawler.jar
end script
Run Code Online (Sandbox Code Playgroud)
现在为solr服务器我写了这个:
description "server"
start on starting crawler
stop on runlevel [!2345]
respawn
script
cd /home/server/version0.1/example
java -Duser.language=en -Dsolr.clustering.enabled=true -Duser.country=US -Dfile.encoding=UTF-8 -jar start.jar
end script
Run Code Online (Sandbox Code Playgroud)
两者都开始,所以它似乎工作,但我希望爬行器在稍微延迟2秒后启动,以给服务器时间启用一切.谁知道怎么做?您如何看待这两个新贵脚本是好还是我错过了什么?(我是一个初始菜鸟)
我正在考虑以下自定义视图控制器:
- (id)init
{
self = [super init];
if (self == nil) {
return self;
}
return [[UINavigationController alloc] initWithRootViewController:[self autorelease]];
}
Run Code Online (Sandbox Code Playgroud)
这个可以吗?
也许在init(PortletConfig)中通过PortletConfig
事情是使用
((PortletConfigImpl) portletConfig).getPortletId();
Run Code Online (Sandbox Code Playgroud)
是不允许的,因为在package.properties中添加portal-impl.jar会在尝试执行build ant target时抛出异常,说不再允许这样做
对于companyID,我直接不知道从哪里开始.我目前正在使用
long companyId = CompanyLocalServiceUtil.getCompanies().get(0).getCompanyId();
Run Code Online (Sandbox Code Playgroud)
但是一旦我有一家以上的公司,它就会失败
如果我能以某种方式得到Portlet对象,我认为这足以获得portletId和companyId
当我们必须在应用程序启动时设置一些数据时,在调用servlet init方法或实现servlet上下文监听器之间更好.
我知道这很容易,但我无法弄明白.我们想在一台机器上运行两个luigi实例,因此需要修改init.d脚本以将PID写入文件而不是仅触摸空文件.
echo -n $"Starting luigid scheduler as $LUIGID_USER: "
( ( /usr/bin/sudo -u $LUIGID_USER $LUIGID_BIN >>/var/log/luigid/server.log 2>&1 ) &)
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/luigid && echo_success || echo_failure
echo
return $RETVAL
Run Code Online (Sandbox Code Playgroud)
目前它只是触摸空的PID文件.我希望它将PID写入文件.同时停止我想通过存储在PID文件中的PID来杀死
echo -n $"Stopping luigid scheduler: "
killproc luigid
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/luigid && echo_success || echo_failure
echo
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?
谢谢
我读过这解释之间的差异的其他问题__init__和__new__,但我就是不明白,为什么在与Python 2了下面的代码:
init
Run Code Online (Sandbox Code Playgroud)
和Python3:
new
init
Run Code Online (Sandbox Code Playgroud)
示例代码:
class ExampleClass():
def __new__(cls):
print ("new")
return super().__new__(cls)
def __init__(self):
print ("init")
example = ExampleClass()
Run Code Online (Sandbox Code Playgroud) 我编写了自己的Button,Textfield,...类。在“自定义类”的情节提要中,将类设置为UIElement。这很好。
现在,我需要以编程方式添加的工具栏。当我在ViewController中添加工具栏时,一切都很好。但是我想像这样创建自己的工具栏类。
class MyOwnToolbar : UIToolbar {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
//never called
self.backgroundColor = UIColor.redColor()
self.tintColor = UIColor.greenColor()
self.barTintColor = UIColor.blueColor()
}
override init(frame: CGRect) {
//error: super.init isn'T called on all paths before returning from initiliazer
}
Run Code Online (Sandbox Code Playgroud)
在我的ViewController中,我尝试这样调用:
fromToolBar = MyOwnToolBar() //call nothing?
fromToolBar = MyOwnToolBar(frame: CGRectMake(0,0,0,0)) //doesn't work because init(frame: CGRECT) doesnt work
Run Code Online (Sandbox Code Playgroud)
我的ViewController中的旧代码有效:
self.untilToolBar = UIToolbar(frame: CGRectMake(0,0,0,0))
untilToolBar?.backgroundColor = redColor
untilToolBar?.tintColor = greenColor
untilToolBar?.barTintColor = blueColor
Run Code Online (Sandbox Code Playgroud)
因此,我可以使用有效的解决方案,但我想理解为什么我的代码无法正常工作。因此,也许有人有解决方案或良好的联系。