对于以下(损坏)函数,我想True在创建或更新实体时返回,False否则.问题是我不知道是否get_or_insert()有现有实体或插入了实体.有没有一种简单的方法来确定这个?
class MyModel(ndb.Model):
def create_or_update(key, data):
"""Returns True if entity was created or updated, False otherwise."""
current = MyModel.get_or_insert(key, data=data)
if(current.data != data)
current.data = data
return True
return False
Run Code Online (Sandbox Code Playgroud) 我在Google appengine应用程序中有以下模型.
class TestModel(db.Model):
names = db.StringListProperty(required=False)
Run Code Online (Sandbox Code Playgroud)
所以,我想获取名称属性中没有空的条目.我试过这样的.
TestModel.all().filter('names !=', [])
Run Code Online (Sandbox Code Playgroud)
但它引发了异常:BadValueError:不支持对列表进行过滤
我该如何过滤它?或者我应该像往常一样逐一检查?
for entry in TestModel.all():
if len(entry.names) > 0:
result.append(entry)
Run Code Online (Sandbox Code Playgroud) 我有一个名为 testSwitch.ps1 的 powershell 脚本:
param(
[switch] $s
)
Return 's= ' + $s
Run Code Online (Sandbox Code Playgroud)
当我像这样直接在 PowerShell 中调用这个脚本时:
.\testSwitch.ps1 -s
Run Code Online (Sandbox Code Playgroud)
输出是
s= True
Run Code Online (Sandbox Code Playgroud)
当开关丢失时,它输出 False 。但是当我尝试使用此 C# 代码调用相同的脚本时:
Command command = new Command(@"testSwitch.ps1");
command.Parameters.Add(new CommandParameter("s"));
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
using (Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration))
{
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.Add(command);
IEnumerable<PSObject> psresults = new List<PSObject>();
psresults = pipeline.Invoke();
Console.WriteLine(psresults.ToArray()[0].ToString());
}
Run Code Online (Sandbox Code Playgroud)
输出是:
s= False
Run Code Online (Sandbox Code Playgroud)
与 PowerShell 命令行解释器不同,CommandParameter 似乎总是将开关参数解释为 false。令人沮丧的是,这会导致脚本看到[switch]参数的值为 false,而不会引发任何关于未指定值的异常。与[bool]参数相反,如果您没有在CommandParameter构造函数中提供值,它将引发异常。
假设我有一个包含文件的文件夹,其名称如下:
log_1.loglog_2.loglog_2.gz我想在log_2.gz上执行一些操作,比如说移动.
在Windows cmd.exe中,我习惯于执行以下步骤:
move(没有别的)log_2.gzdestination但是在bash shell中(在Mac OS X 10.8.3上的iTerm2中),我必须做这样的事情:
mv llog_去做一个恼人的哔哔声2log_2.去做一个恼人的哔哔声glog_2.gz,并且令人满意地保持沉默destination正如您所看到的,即使您知道目标文件名,bash也需要更多步骤,但想象一下您不确定文件名究竟是什么的场景(可能ls太长了).我经常发现自己在这种情况下经过一些tab+键入后被迫放弃命令,ls再次运行,复制文件名,甚至可以运行一个pwd与文件夹连接,然后从我离开的地方继续.这非常烦人.
我正在使用以下参数启动dev_appserver.py:
dev_appserver.py --require_indexes=yes --datastore_path=/Users/mattfaus/dev/webapp/datastore/current.sqlite --blobstore_path=/Users/mattfaus/dev/webapp/datastore/blobs/ --host=0.0.0.0 --port=8080 --skip_sdk_update_check=yes --enable_sendmail=yes /Users/mattfaus/dev/webapp
Run Code Online (Sandbox Code Playgroud)
并且在活动监视器中,我看到即使不为请求提供服务,它也一直在使用150%的CPU。我看到的最大症状是,Macbook Pro的电池寿命大大减少,CPU几乎过热。现在,我在不使用应用服务器时必须小心关闭它,以防止发生这些情况。
这大约在1个月前开始,可能是在我升级到1.8.1或1.8.2时发生的。有什么方法可以配置GAE停止使用太多CPU?
我正在使用GAE SDK 1.8.3,下面是我的硬件/软件概述。
硬件概述:
型号名称:MacBook Pro型号标识符:MacBookPro9,1处理器名称:Intel Core i7处理器速度:2.3 GHz处理器数量:1内核总数:4 L2高速缓存(每个内核):256 KB L3高速缓存:6 MB内存:16 GB突然运动传感器:状态:启用
系统软件概述:
系统版本:OS X 10.8.4(12E55)内核版本:Darwin 12.4.0启动卷:Macintosh HD启动模式:普通计算机名称:mattfaus用户名:Matt Faus(mattfaus)安全虚拟内存:启用
我创建了一个带有2个参数的方法.我注意到调用代码可以为两个参数传递相同的变量,但是这种方法要求这些参数是分开的.我想出了我认为最好的方法来验证这是真的,但我不确定它是否会100%有效.这是我提出的代码,嵌入了问题.
private static void callTwoOuts()
{
int same = 0;
twoOuts(out same, out same);
Console.WriteLine(same); // "2"
}
private static void twoOuts(out int one, out int two)
{
unsafe
{
// Is the following line guaranteed atomic so that it will always work?
// Or could the GC move 'same' to a different address between statements?
fixed (int* oneAddr = &one, twoAddr = &two)
{
if (oneAddr == twoAddr)
{
throw new ArgumentException("one and two must be seperate variables!");
} …Run Code Online (Sandbox Code Playgroud)