我正在尝试使用rb-appscript自动将文件添加到我的Xcode项目中.我对Ruby或Applescript没有多少经验,但是有两个人似乎已经为他们做了这个工作:
https://github.com/gonzoua/xcs/blob/master/xcs.thor
不幸的是,这些都不适合我.我可以让他们将文件添加到组中,但是将文件添加到目标中断.这是最简单的代码,对我不起作用:
require 'rubygems'
require 'appscript'
project_path = 'Users:me:Projects:xcode:project:src:AppScaffold.xcodeproj'
project_name = 'AppScaffold'
group_name = 'Classes'
file_name = 'ApplicationDelegate.m'
target_name = 'AppScaffold'
def lookup(sequence, name)
sequence.get.each { |item|
if item.name.get == name
return item
end
}
raise Exception.new("Couldn't find name '" + name + "' in sequence " + sequence.inspect)
end
app = Appscript.app('Xcode')
app.open(project_path)
project = lookup(app.projects, project_name)
target = lookup(project.targets, target_name)
group = lookup(project.root_group.item_references, group_name)
file = lookup(group.item_references, file_name)
file.add({:to => target})
# I also tried this: …Run Code Online (Sandbox Code Playgroud) 我在使用 pandas DataFrame 的 apply() 方法时遇到问题。我的问题是 apply() 可以返回 Series 或 DataFrame,具体取决于输入函数的返回类型;但是,当框架为空时,apply()(几乎)总是返回一个 DataFrame。所以我无法编写需要系列的代码。下面是一个例子:
import pandas as pd
def area_from_row(row):
return row['width'] * row['height']
def add_area_column(frame):
# I know I can multiply the columns directly, but my actual function is
# more complicated.
frame['area'] = frame.apply(area_from_row, axis=1)
# This works as expected.
non_empty_frame = pd.DataFrame(data=[[2, 3]], columns=['width', 'height'])
add_area_column(non_empty_frame)
# This fails!
empty_frame = pd.DataFrame(data=None, columns=['width', 'height'])
add_area_column(empty_frame)
Run Code Online (Sandbox Code Playgroud)
有没有标准的方法来处理这个问题?我可以执行以下操作,但这很愚蠢:
def area_from_row(row):
# The way we respond to an empty row tells pandas …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Scala 2.8中定义自定义集合接口.我想要求子类是Traversable,还有其他一些行为.我也想像map()这样的方法返回相应的类型,如下所示:
trait CustomCollection[+A] extends Traversable[A] {
def customOperation(i:Int):Int // for example
}
def incrementAll(c:CustomCollection[Int]):CustomCollection[Int] = c.map { _ + 1 }
Run Code Online (Sandbox Code Playgroud)
这不会编译,因为CustomCollection.map()返回Traversable.我想我需要定义一个CanBuildFrom,但是我需要定义一个从头构建实例的apply()方法.我不想指定一种方法来构建它; 这应该取决于实施者.这可能吗?
我试图让Xcode使用Applescript构建和运行我的项目.这与如何使用Applescript构建和运行Xcode的问题相同?,但我认为答案可能已经过时,因为它在我的机器上不起作用.我明白了:
execution error: Xcode got an error: The specified object is a property, not an element. (-10008)
Run Code Online (Sandbox Code Playgroud)
我也尝试过以下方法:
tell application "Xcode"
build project "MyProject"
end tell
Run Code Online (Sandbox Code Playgroud)
但它没有建立,只是返回"缺失值".
(使用Xcode 4.0.1,OS X 10.6.8)
尝试在Xcode中使用Applescript时遇到了很多麻烦; 我找不到任何实际的文档(除了Xcode字典,这是非常简洁的),只是似乎没有用的示例.任何帮助,将不胜感激.