$ hg update [-r REV]
Run Code Online (Sandbox Code Playgroud)
这会将工作目录切换到指定的版本.但是,如果我的工作目录已修改更改,则会将更改合并回来REV.我意识到我可以使用该-C标志来丢弃我的更改,但我试图update在不同的场景中关注命令的行为.
$ hg update <bname>
Run Code Online (Sandbox Code Playgroud)
这会将我的工作目录切换为<bname>分支.但是,在我明确使用该命令之前,我的未提交的更改不会合并merge.
$ hg pull
$ hg update
Run Code Online (Sandbox Code Playgroud)
这会在最近一次之后再次将我的工作目录与远程存储库中的更改集合并pull.
/home/bar/foo/test.py:
Run Code Online (Sandbox Code Playgroud)
我试图test.py打印,/home/bar/foo无论我从哪里运行脚本:
import os
def foo():
print os.getcwd()
Run Code Online (Sandbox Code Playgroud)
测试运行:
[/home/bar $] python /home/bar/foo/test.py # echoes /home/bar
[/tmp $] python /home/bar/foo/test.py # echoes /tmp
Run Code Online (Sandbox Code Playgroud)
os.getcwd()不是任务的功能.我怎么能这样做呢?
这里我指的是一部分kgp.py节目 -
def getDefaultSource(self):
xrefs = {}
for xref in self.grammar.getElementsByTagName("xref"):
xrefs[xref.attributes["id"].value] = 1
xrefs = xrefs.keys()
standaloneXrefs = [e for e in self.refs.keys() if e not in xrefs]
if not standaloneXrefs:
raise NoSourceError, "can't guess source, and no source specified"
return '<xref id="%s"/>' % random.choice(standaloneXrefs)
Run Code Online (Sandbox Code Playgroud)
self.grammar:解析XML表示(using xml.dom.minidom) -
<?xml version="1.0" ?>
<grammar>
<ref id="bit">
<p>0</p>
<p>1</p>
</ref>
<ref id="byte">
<p><xref id="bit"/><xref id="bit"/><xref id="bit"/><xref id="bit"/>\
<xref id="bit"/><xref id="bit"/><xref id="bit"/><xref id="bit"/></p>
</ref> …Run Code Online (Sandbox Code Playgroud) 在工作中我使用svn7人共享的存储库.
为了避免因提交而破坏我的错误并打破每个人的构建并避免分支svn,我在目前正在处理hg的svn目录的一部分中创建了一个存储库.
我在工作时对hg执行本地提交,因为我在虚拟机上进行了所有设置,我甚至将我的hg存储库推送到私有的集中位置.
最近我迁移到Mac OS X lion我的虚拟机,所以我不得不重新设置它.所以我从我检查了项目svn trunk,现在想要在我正在处理的目录中找回hg更改集.
我有两个选择:
$ hg clone <remote repo>$ hg init && hg pull <remote repo>这相当吗?
class A{
A(int x){}
}
class B extends A{
B(int x){}
public static void main(String args[]){
B b = new B(10);
}
}
Run Code Online (Sandbox Code Playgroud)
我理解这会抛出一个错误(B的一个arg构造函数,隐式调用super(),因此A)不存在default-arg构造函数.我很好奇为什么B的一个arg构造函数,不使用super(x)来调用类A的一个arg构造函数.相反,让我陷入为A明确写一个无参数构造函数的麻烦,当我不需要一个!
我在我的python脚本中读取一个日志文件,并且我有一个startTimes和endTimes- 的元组列表
('[19:49:40:680]', '[19:49:49:128]')
('[11:29:10:837]', '[11:29:15:698]')
('[11:30:18:291]', '[11:30:21:025]')
('[11:37:44:293]', '[11:38:02:008]')
('[11:39:14:897]', '[11:39:21:572]')
('[11:42:19:968]', '[11:42:22:036]')
('[11:43:18:887]', '[11:43:19:633]')
('[11:44:26:533]', '[11:49:29:274]')
('[11:55:03:974]', '[11:55:06:372]')
('[11:56:14:096]', '[11:56:14:493]')
('[11:57:08:372]', '[11:57:08:767]')
('[11:59:26:201]', '[11:59:27:438]')
Run Code Online (Sandbox Code Playgroud)
如何以毫秒为单位来区分时间?
向前推进:
try:
f = open('foo', 'r')
except IOError as e:
error_log.write('Unable to open foo : %s\n' % e)
else:
data = f.read()
f.close()
Run Code Online (Sandbox Code Playgroud)
在我看来,else clause通过nested try...except避免需要可以避免仍然解决的角落案例else?:
try:
f = open('foo', 'r')
try:
data = f.read()
f.close()
except:
pass
except IOError as e:
error_log.write('Unable to open foo : %s\n' % e)
Run Code Online (Sandbox Code Playgroud) 我编写了一个在OS X上编写的traceroute程序.我试图将它移植到GNU/Linux.
[@osx]
>> sudo bin/traceroute www.google.com
Warning: www.google.com has multiple addresses; using 173.194.69.99
...
Run Code Online (Sandbox Code Playgroud)
为了使它在GNU/Linux上编译,我添加了_GNU_SOURCE功能测试宏.
[@ubuntu]
>> sudo bin/traceroute www.google.com
error setting socket options: Invalid argument
Run Code Online (Sandbox Code Playgroud)
问题出在:
85 send_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
86 if(send_socket == -1){
87 fprintf(stderr, "\ncannot create send socket");
88 freeaddrinfo(dest_addrinfo_collection);
89 return EXIT_FAILURE;
90 }
91 error = setsockopt(send_socket, IPPROTO_IP, IP_TTL, &ttl, sizeof(int));
92 if(error != 0){
93 perror("\nerror setting socket options");
94 freeaddrinfo(dest_addrinfo_collection);
95 return EXIT_FAILURE;
96 }
Run Code Online (Sandbox Code Playgroud)
看起来setsockopt(...)无法识别 …
我正在看UserDict班级来源,我有点不安地看到:
class UserDict:
def __init__(self, dict=None, **kwargs):
self.data = {}
if dict is not None:
self.update(dict)
...
Run Code Online (Sandbox Code Playgroud)
然后方法如:
def keys(self): return self.data.keys()
def items(self): return self.data.items()
def iteritems(self): return self.data.iteritems()
def iterkeys(self): return self.data.iterkeys()
def itervalues(self): return self.data.itervalues()
def values(self): return self.data.values()
Run Code Online (Sandbox Code Playgroud)
这样做会不会更好:
class UserDict(dict):
def __init__(self, dict=None, **kwargs):
#self.data = {} # now self itself is {}
if dict is not None:
self.update(dict)
...
Run Code Online (Sandbox Code Playgroud)
然后对上述方法的需求就会消失.
此外,它还有助于程序员在一开始就学习UserDict通过查看类定义本身来扩展dict的功能.