这是我的Preferences.sublime-settings档案:
{
"bold_folder_labels": true,
"highlight_line": true,
"ignored_packages":
[
"Vintage"
],
"remember_open_files": true,
"folders":
[
{
"file_exclude_patterns": ["*.sublime-workspace"]
}
]
}
Run Code Online (Sandbox Code Playgroud)
当我在侧边栏中搜索所有打开的文件和文件夹(cmd-shift-f)时,我仍然会收到包含工作区文件的搜索结果,这些文件位于我打开的其中一个目录中.例如,如果我~/foo打开并且有一个文件~/foo/bar/hello.sublime-workspace,它将包含在搜索结果中.
如何让Sublime 永远不会.sublime-workspace在我的搜索中包含文件?
Cassandra中的这种行为似乎违反直觉,我想知道为什么会发生这种情况,并可能解决这个问题.
想象一下,我有一个包含三列的表:pk主键,text类型foo,a bigint,和bar另一个text.
insert into keyspace.table (pk, foo, bar) values ('first', 1, 'test') using ttl 60;
Run Code Online (Sandbox Code Playgroud)
这会在我的表中创建一行,其生存时间为60秒.看着它,它看起来像这样:
pk | foo | bar
------------------
first | 1 | test
Run Code Online (Sandbox Code Playgroud)
现在我做:
update keyspace.table using ttl 10 set bar='change' where pk='first';
Run Code Online (Sandbox Code Playgroud)
然后,看着这行,我看到它经历了以下变化:
pk | foo | bar
--------------------
first | 1 | change
first | 1 | <<null>> // after 10 seconds
<< deleted >> // after the initial 60 seconds
Run Code Online (Sandbox Code Playgroud)
一切都很好.我想要的是 …
在Java中,throws如果原始抽象方法不能(overridden method does not throw Exception.),则无法指定重写的抽象方法是否有异常.但是在Scala中,您可以执行此操作,因为它没有检查异常.很好,但如果您使用的@throws注释应该将Java编译器发送给正在发生的事情,对吧?
鉴于此Scala代码:
package myscala
abstract class SFoo {
def bar(): Unit
}
class SFoobar extends SFoo {
@throws[Exception]
override def bar(): Unit = {
throw new Exception("hi there")
}
}
Run Code Online (Sandbox Code Playgroud)
我有两个不同的Java程序,其中一个将Exception在运行时编译并运行,另一个将无法编译.
编译:
import myscala.SFoo;
import myscala.SFoobar;
public class Foobar {
public static void main(String[] args) {
SFoo mySFoo = new SFoobar();
mySFoo.bar();
}
}
Run Code Online (Sandbox Code Playgroud)
不编译(unreported exception Exception; must be caught or declared to be …
我正在尝试写一个代表银行帐户的记录:
-record(account, { name :: atom(),
type :: atom(),
balance = 0 :: integer() }).
Run Code Online (Sandbox Code Playgroud)
我也想限制平衡>= 0.我该怎么做呢?
说,我们需要一个程序来的字符串列表和分裂他们,并追加的前两个单词,在一个元组,到列表,并返回该列表; 换句话说,一个程序,它给你每个字符串的前两个单词.
input: ["hello world how are you", "foo bar baz"]
output: [("hello", "world"), ("foo", "bar")]
Run Code Online (Sandbox Code Playgroud)
它可以这样写(我们假设有效输入):
def firstTwoWords(strings):
result = []
for s in strings:
splt = s.split()
result.append((splt[0], splt[1]))
return result
Run Code Online (Sandbox Code Playgroud)
但列表理解会更好.
def firstTwoWords(strings):
return [(s.split()[0], s.split()[1]) for s in strings]
Run Code Online (Sandbox Code Playgroud)
但这涉及到两个电话split().有没有办法在理解中只执行一次拆分?我尝试了自然而然的,它是无效的语法:
>>> [(splt[0],splt[1]) for s in strings with s.split() as splt]
File "<stdin>", line 1
[(splt[0],splt[1]) for s in strings with s.split() as splt]
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud) 如果迭代完成但没有被中断,则/ 子句中的else块被执行,所以我读了.forelsebreak
是否有一种语言结构可以让我写一些只有在for循环没有开始迭代时执行的东西?如果我正在使用tuple或list,我会做这样的事情:
if seq:
for x in seq:
# something
else:
# something else
Run Code Online (Sandbox Code Playgroud)
但是当我使用生成器时,我没有得到我想要的行为:
>>> g = (x for x in range(2))
>>> for x in g:
... print x
... else:
... print "done"
...
0
1
done # I don't want "done" here
>>> g = (x for x in range(2) if x > 1)
>>> if g:
... for x in g: …Run Code Online (Sandbox Code Playgroud) 我有这样一个元素:
<a id="my%20id" href="#">hello</a>
Run Code Online (Sandbox Code Playgroud)
我一直在拼命地用jQuery选择它,但不能.我试过了:
$('a#my id') // obviously won't work
$('a#my\ id') // no such luck
$('a#my%20id') // unrecognized expression
$('a#my\%20id') // still unrecognized
$('a#' + encodeURIComponent('my id')) // same thing as 'a#my%20id'
Run Code Online (Sandbox Code Playgroud)
是否可以使用jQuery选择它?
类构造函数应该返回一个子类吗?
这主要是关于OOP风格和python风格的问题.我有问题需要实现一般案例解决方案,出于性能原因,我需要为特定输入类型实现优化解决方案.输入类型取决于用户.目前,我已经通过对一般案例解决方案进行子类化来实现这一目标,以制定优化的解决方案.我想出了以下示例来帮助描述我的意思.
from collections import Counter
class MyCounter(object):
"""General Case Counter"""
def __init__(self, seq):
self.seq = seq
def count(self, key):
return sum(key == item for item in self.seq)
class OptimizedCounter(MyCounter):
"""Counter optimized for hashable types"""
def __init__(self, seq):
self.counter = Counter(seq)
def count(self, key):
return self.counter.get(key, 0)
counter = MyCounter(['a', 'a', 'b', [], [0, 1]])
counter.count([0, 1])
# 1
counter = OptimizedCounter(['a', 'a', 'b'])
counter.count('a')
# 2
Run Code Online (Sandbox Code Playgroud)
我的问题是如何设计一个流畅的界面,以便用户获得一个合适的实例,而不必担心它是如何实现的.我考虑过做类似下面的事情,但这对我来说很难看.是否有更规范或OOP的方式来做这样的事情?
class MyCounter(object):
"""General Case Counter"""
def __new__(cls, seq):
if hasOnlyHashables(seq):
return object.__new__(OptimizedCounter) …Run Code Online (Sandbox Code Playgroud) 我想要一个具有以下属性的字典结构:
所以,如果我像这样添加项目:
# d = something dict-ish
d['a']['b']['c'] = 'd'
d['a'][1][2] = 3
d['f']['g']['e'] = 'g'
d['f'][5][6] = 7
d['a']['foo']['bar'] = 'hello world'
Run Code Online (Sandbox Code Playgroud)
以下理解的结果:
[(i, j, k, d[i][j][k]) for i in d for j in d[i] for k in d[i][j]]
Run Code Online (Sandbox Code Playgroud)
将会:
[('a', 'b', 'c', 'd'), ('a', 1, 2, 3), ('a', 'foo', 'bar', 'hello world'), ('f', 'g', 'e', 'g'), ('f', 5, 6, 7)]
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用a defaultdict为新键强制执行此结构,因此我不必长途键入它,如下所示:
# long way
d = OrderedDict()
d['a'] = OrderedDict([('b', OrderedDict([('c', 'd')]))])
d['a'][1] = …Run Code Online (Sandbox Code Playgroud) 在Cassandra中,我习惯USING TTL了upserts 的子句,它设置了一些秒,之后将删除upserted数据.
Oracle有这样的功能吗?我一直无法找到任何相关信息.
python ×4
python-2.7 ×2
annotations ×1
cassandra ×1
coding-style ×1
cql ×1
cql3 ×1
defaultdict ×1
erlang ×1
exception ×1
generator ×1
html ×1
java ×1
javascript ×1
jquery ×1
oop ×1
oracle ×1
records ×1
restrictions ×1
scala ×1
sql ×1
sublimetext ×1
sublimetext2 ×1
throws ×1
ttl ×1
types ×1