这只是为了学术兴趣.我经历了很多以下情况.
either_true = False
if x:
...do something1
either_true = True
elif y:
...do something2
either_true = True
if either_true:
..do something3
Run Code Online (Sandbox Code Playgroud)
是否有任何pythonic方式,或通常更好的编程方式.基本上只有当或者elif为真时才执行something3.
我是django和web开发的新手.在创建超级用户时从"Django的权威指南"中学习我得到以下错误(OS mac10.8.2&django1.4.3)
Would you like to create one now? (yes/no): yes
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py", line 110, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/Library/Python/2.7/site-packages/django/core/management/sql.py", line 189, in emit_post_sync_signal
interactive=interactive, …Run Code Online (Sandbox Code Playgroud) 我有两张桌子
table 1
col1 date
1 13/4/2014
2 15/4/2014
3 17/4/2014
5 19/4/2014
table 2
col1 date
1 13/4/2014
3 16/4/2014
6 18/4/2014
joining the two tables i should get
col1 date col2 date
1 13/4/2014 1 13/4/2014
2 15/4/2014
3 17/4/2014 3 16/4/2014
6 18/4/2014
5 19/4/2014
Run Code Online (Sandbox Code Playgroud)
重要的是date列应该排序,可以看到col数据6和5.这可能吗?
编辑:最后的表需要被命令col1.date并col2.date使得提前无论是在col1或col2将在连接表进行排序18/4/2014会之前,19/4/2014即使他们是在不同的列.我希望我明白我的观点.谢谢编辑:
table 1
1, "2014-04-03"
2, "2014-04-04"
3, "2014-04-11"
4, "2014-04-16" …Run Code Online (Sandbox Code Playgroud) 假设我们有两套:
t = {('b', 3), ('a', 2)}
r = {('b', 4), ('c', 6)}
Run Code Online (Sandbox Code Playgroud)
我希望第一个元素上的联合导致
u = {('b', 3), ('a', 2), ('c', 6)}
Run Code Online (Sandbox Code Playgroud)
如果两个地方都存在重复的符号(例如上面的例子'b'),那么应该保留第一个列表的元素.谢谢.