问题列表 - 第48369页

使用tryCatch和source

假设我有两个R文件:correct.Rbroken.R.tryCatch用于检查错误的最佳方法是什么?

目前,我有

> x = tryCatch(source("broken.R"), error=function(e) e)
> x
 <simpleError in source("broken.R"): test.R:2:0: unexpected end of input
  1: x = {
     ^>
> y = tryCatch(source("correct.R"), error=function(e) e)
> y
 $value
 [1] 5

 $visible
 [1] FALSE
Run Code Online (Sandbox Code Playgroud)

但是,我构建的tryCatch方式意味着我必须询问xy对象以确定是否存在错误.

有没有更好的方法呢?


问题来自教学.100名学生上传他们的R脚本,我运行脚本.为了好,我打算创建一个简单的函数来确定它们的函数是否正确来源.它只需要返回TRUE或FALSE.

error-handling r try-catch

7
推荐指数
2
解决办法
3776
查看次数

如何自动滚动gtk.scrolledwindow?

我在a里面有一个treeview-widget ScrolledWindow,它在运行时填充.我希望ScrolledWindow自动滚动到列表的末尾.我"解决"问题,通过调整vadjustmentScrolledWindow,每次一个行插入到树视图.例如:

if new_line_in_row:
   adj = self.scrolled_window.get_vadjustment()
   adj.set_value( adj.upper - adj.page_size )
Run Code Online (Sandbox Code Playgroud)

如果我在交互式ipython会话中运行代码并自己设置值,一切都按预期工作.

如果我使用默认的python解释器运行代码,则自动滚动不会一直有效.我调试了代码,问题似乎是,调整值有某种"滞后",只在一段时间后才会改变.

我的问题是:如何可靠地滚动到最大位置ScrolledWindow?是一个特殊的信号生成,我可以使用?还是有更好的方法来设置adjustment-value

python gtk pygtk scrolledwindow gtktreeview

18
推荐指数
3
解决办法
8571
查看次数

为什么Thread.stop()如此危险

为什么Thread.stop()这么危险?

为什么建议使用Thread.interrupted()

我知道stop已被弃用.还有什么东西让它不安全?

有什么地方可以使用stop方法吗?如果是这样给我一个例子.

java multithreading

6
推荐指数
1
解决办法
2608
查看次数

学习python艰苦的方式锻炼18帮助

我理解除第一个以外的所有功能.什么(*args)是什么意思?

谢谢

def print_twice(*args):
    arg1, arg2 = args
    print 'arg1: %r arg2: %r' % (arg1, arg2)

def print_twice_again(arg1, arg2):
    print 'arg1: %r arg2: %r' % (arg1, arg2)

def print_once(arg1):
    print 'arg1: %r' % arg1

def print_none():
    print 'i got nothin...'

print_twice("neil", "harper")
print_twice_again("neil", "harper")
print_once("first!")
print_none()
Run Code Online (Sandbox Code Playgroud)

python

4
推荐指数
1
解决办法
771
查看次数

如何在Rails中同时保存多个has_many_through对象?

我有两个相关的模型如下。

USERS
has_many :celebrations
has_many :boards, :through => :celebrations

BOARDS
has_many :celebrations
has_many :users, :through => :celebrations


CELEBRATIONS
:belongs_to :user
:belongs_to :board
Run Code Online (Sandbox Code Playgroud)

在我的控制器中,我想从表单数据创建对象。我这样做如下:

  @user = User.new(params[:user])
  @board = Board.new(params[:board])
if @user.save & @board.save    
   @user.celebrations.create(:board_id => @board,:role => "MANAGER")
   redirect_to :action => some_action
end
Run Code Online (Sandbox Code Playgroud)

由于模型是由多个模型连接起来的,有没有一种方法可以一次性保存它们,然后一次生成错误消息,以便它们同时显示在表单上?

ruby-on-rails save has-many-through

4
推荐指数
1
解决办法
7339
查看次数

如何在不停止PHP脚本的其余部分的情况下停止foreach循环?

有一个foreach循环,如果某个条件变得有效,是否可以停止它?

例:

<?php
foreach ($foo as $bar) {

  if (2+2 === 4) {
    // Do something and stop the cycle
  }

}
?>
Run Code Online (Sandbox Code Playgroud)

我试图使用returnexit,但它没有按预期工作,因为我想继续执行剩余的PHP脚本.

php foreach loops

12
推荐指数
2
解决办法
3万
查看次数

SETENV:错误:$($)中的修饰符

我在Linux中使用tcsh终端.在我通常使用的另一个终端中,我将路径设置为某个许可证文件,如下所示:

  export PATH="$PATH:$MODEL_TECH"
Run Code Online (Sandbox Code Playgroud)

Tcsh shell无法识别此命令,因此我尝试了以下操作:

  setenv PATH "$PATH:$MODEL_TECH"
  set PATH "$PATH:$MODEL_TECH"
  setenv PATH=("$PATH:$MODEL_TECH")
Run Code Online (Sandbox Code Playgroud)

但后来我总是得到以下错误:

坏:$($)中的修饰符.

如果有人能够快速帮助我,尝试了很多组合但没有任何作用,这也很棒.

linux tcsh setenv

6
推荐指数
2
解决办法
2万
查看次数

释放CGContextDrawPDFPage使用的内存

当我用Instruments分析我的应用程序时,我发现CGContextDrawPDFPage分配的数据不会立即释放.由于我的程序收到很多"内存警告",我想释放尽可能多的内存,但我不知道如何释放这个内存.

正如您在http://twitpic.com/473e89/full上看到的,它似乎与此代码有关

-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx{
    NSAutoreleasePool * tiledViewPool = [[NSAutoreleasePool alloc] init];
    CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
    CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx));
    CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform([self.superview.superview getPage],kCGPDFMediaBox,tiledLayer.bounds, 0, true);
    CGContextSaveGState (ctx);
    CGContextTranslateCTM(ctx, 0.0, tiledLayer.bounds.size.height);
    CGContextScaleCTM(ctx, 1.0, -1.0);
    CGContextConcatCTM (ctx, pdfTransform);
    CGContextClipToRect (ctx, CGPDFPageGetBoxRect([self.superview.superview getPage],kCGPDFMediaBox));
    CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
    CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
    CGContextDrawPDFPage(ctx,[self.superview.superview getPage]);
    CGContextRestoreGState (ctx);
    UIGraphicsEndPDFContext();
    [tiledViewPool drain];
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试在它周围包装一个AutoReleasePool,但这似乎没有任何影响.屏幕截图是在TiledView(方法所属的视图)被释放后拍摄的.

我希望有人可以帮我减少内存使用量.

iphone cocoa-touch catiledlayer ios

6
推荐指数
1
解决办法
2607
查看次数

当宽度设置为100%时,div的内容比div本身更长?

我有div固定宽度只包含input文本框width,input并设置为100%.我希望它能填补div但反而稍微长一些.

演示代码:

HTML:

<div class="container">
    <input class="content" id="Text1" type="text" />
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.container
{
    width: 300px;
    height: 30px;
    border: thin solid red;
}
.content
{
    width: 100%;
}
Run Code Online (Sandbox Code Playgroud)

结果(Firefox):

在此输入图像描述

这也发生在IE 8,Chrome,Safari ......溢出宽度似乎在不同的浏览器中有所不同.如何使内容准确填充div

html css firefox

25
推荐指数
1
解决办法
3万
查看次数

Eclipse错误:没有可用的源""

在Mac OS X Leopard中使用Eclipse Helios并调试调用fsf gdb 7.1的C++代码,调试在main的第一行停止.然后在第一步之后我得到了

No source available for ""
View disassembly
Run Code Online (Sandbox Code Playgroud)

为什么这个错误?我应该提供额外的编译选项吗?Eclipse自动生成Makefile

eclipse debugging assembly

6
推荐指数
1
解决办法
4万
查看次数