我正在开始使用Python编程.我正在阅读一本基础教程,但这一点对我来说并不是很清楚.我很感激你能给我的任何帮助.
让我说我有两个可互换的代码片段,我想弄清楚哪一个需要较少的处理器时间来执行.我该怎么做?
为了得到非常粗略的估计,我可以将NSLog()调用放在我想要分析的代码的任何一侧,但看起来处理器非常繁忙可能会使结果产生偏差.
NSArray的-description方法将嵌套递归调用,如下所示:
2009-05-15 14:28:09.998 TestGUIProject[29695:813] (
a, // Array1 item 1
( // Array2, a second array, nicely indented another 4 spaces
a // Item in Array2
) // End of Array2
) // End of Array1
Run Code Online (Sandbox Code Playgroud)
我想为我自己的自定义类做一些类似的事情(使用我正在编写的脚本).
我不知道的是,当递归调用的对象添加自己的新行时,如何添加额外的缩进级别.
我所拥有的是以下内容:
- (NSString *)description {
return [NSString stringWithFormat:@"{{{\n"
@" prop1: %@\n"
@" prop2: %@\n"
@" prop3: %@\n"
@" prop4: %@\n"
@"}}}",
self.prop1,
self.prop2,
self.prop3,
self.prop4];
}
Run Code Online (Sandbox Code Playgroud)
但是,只要其中一个属性是NSArray或使用相同描述格式的另一个对象,它就会崩溃,因为它不能很好地嵌套.
相反,你得到:
2009-05-15 14:25:50.899 TestApp[29636:813] {{{
prop1: SomeValue1
prop2: ( // Prop 2 is an Array …
Run Code Online (Sandbox Code Playgroud) 我已经使用NSImageCell,一些NSTextFieldCells和一个NSPopUpButtonCell创建了NSCell的自定义子类.
我正在使用以下命令初始化弹出单元格:
myPopUpCell = [[NSPopUpButtonCell alloc] init];
[myPopUpCell setBordered:NO];
[myPopUpCell setAutoenablesItems:NO];
[myPopUpCell addItemsWithTitles:[NSArray arrayWithObjects:@"Item1", @"Item2", @"Item3"]];
Run Code Online (Sandbox Code Playgroud)
并将其吸引进去 drawInteriorWithFrame:inView:
一切似乎都很好,除了在运行我的应用程序时单击弹出单元格时,单元格不会弹出.关于可能出错的任何建议?
$a = array('matches' =>
array(
'5' => array('weight' => 6),
'15' => array('weight' => 6),
)
);
$b = array('matches' =>
array(
'25' => array('weight' => 6),
'35' => array('weight' => 6),
)
);
$merge = array_merge($a, $b);
print_r($merge);
Run Code Online (Sandbox Code Playgroud)
这个脚本的结果是
Array
(
[matches] => Array
(
[25] => Array
(
[weight] => 6
)
[35] => Array
(
[weight] => 6
)
)
)
Run Code Online (Sandbox Code Playgroud)
但为什么?
我想结果是这样的:
Array
(
[matches] => Array
(
[5] => Array
(
[weight] => 6
) …
Run Code Online (Sandbox Code Playgroud) 我有三个参数构造函数的恕我直言非常奇怪的问题,当我尝试运行程序时,visual studio只显示一个错误:"'Sort.HeapSort'不包含一个带有3个参数的构造函数112 35".
namespace Sort
{
class HeapSort
{
private int[] A;
private int heapSize;
private int min;
private int max;
Random myRandom = new Random();
HeapSort(int size, int min1, int max1) //this is the three argument constructor.
{
heapSize = size - 1;
min = min1;
max = max1;
A = new int[size];
}
}
class Program
{
static void Main(string[] args)
{
int size = 30;
int min = 0;
int max = 100;
HeapSort myHeapSort = new …
Run Code Online (Sandbox Code Playgroud) 我有一个以root身份运行的应用程序(一个守护进程/ Library/StartupItems),它偶尔会启动另一个进程system("open /Applications/MyAppName.app")
.这工作正常,但在某些计算机上,MyAppName以root身份启动,而不是在当前用户下运行.
我试图弄清楚为什么会这样,以及如何让应用程序始终作为当前用户启动.
问题似乎发生在运行某些Open/Active目录组合的企业站点上.我对这些机器的访问有限,所以在我请求更多时间之前,我试图至少形成一些假设.
另外一条线索是,如果你打开活动监视器并检查"Finder"进程,至少有一台计算机,"用户:"部分显示用户名但没有用户ID("(UID)"部分完全缺失了).
此外,父流程显示为" launchd (1)
"而不是launchd (95)
像大多数标准应用程序那样" ".我认为这个launchd实例是在计算机启动并以root身份运行的第一件事,与其他以登录用户身份运行的launchd实例相比.
除了显而易见的安全问题之外,我还要求应用程序不以root身份运行,以便它可以支持两个同时登录的用户打开/可见的内容.
有没有人对可能导致这种情况的原因有什么看法,或者我怎么解决它?
cocoa ×4
objective-c ×2
array-merge ×1
c# ×1
constructor ×1
custom-cell ×1
launchd ×1
logging ×1
optimization ×1
php ×1
pretty-print ×1