我想用空格填写一个字符串.我知道以下适用于零:
>>> print "'%06d'"%4
'000004'
Run Code Online (Sandbox Code Playgroud)
但是当我想要这个时我该怎么办?
'hi '
Run Code Online (Sandbox Code Playgroud)
当然我可以测量弦长并做str+" "*leftover,但我想要最短路.
当需要有关类型的信息时,您可以使用:
my_list = []
dir(my_list)
Run Code Online (Sandbox Code Playgroud)
得到:
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
Run Code Online (Sandbox Code Playgroud)
要么:
dir(my_list)[36:]
Run Code Online (Sandbox Code Playgroud)
得到:
['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
Run Code Online (Sandbox Code Playgroud)
现在,在Python的文档中可以找到有关这些函数的信息,但我想在终端/命令行中获取有关这些函数的信息.该怎么做?
什么是更好的做法?
self.call(1, True, "hi")
Run Code Online (Sandbox Code Playgroud)
要么
self.call(1, True, "hi",)
Run Code Online (Sandbox Code Playgroud)
以下情况如下:
self.call(
1,
True,
"hi"
)
Run Code Online (Sandbox Code Playgroud)
要么
self.call(
1,
True,
"hi",
)
Run Code Online (Sandbox Code Playgroud)
?
在数据结构中添加尾随逗号的原因对我来说很熟悉,但是函数调用呢?
当一个异常在一个线程内引发但没有在其他任何地方捕获它时,它会杀死整个应用程序/解释器/进程吗?或者它只会杀死线程?
当 XML 必须根据http://www.w3.org/TR/xml-exc-c14n/进行规范化时,以下 XML 片段是否应该变得相等?(注意,该.字符代表空格' ')
<a>
.<b>
..<c>data</c>
.</b>
</a>
Run Code Online (Sandbox Code Playgroud)
和
<a>
...<b>
......<c>data</c>
...</b>
</a>
Run Code Online (Sandbox Code Playgroud)
换句话说:独占规范化是否会忽略空格?(或忽略缩进大小)
或者,缩进应该保持不变吗?第一个怎么样?<b>(从秒的例子)的规范化版本会变成
...<b>
......<c>data</c>
...</b>
Run Code Online (Sandbox Code Playgroud)
或者
<b>
......<c>data</c>
...</b>
Run Code Online (Sandbox Code Playgroud)
或者
<b>
...<c>data</c>
</b>
Run Code Online (Sandbox Code Playgroud) 有没有办法做这样的事情?
if ['hel','ell','orl'] in 'hello world' :
Run Code Online (Sandbox Code Playgroud)
我想看看是否所有这些字符串都出现在单词中.如果可能的话,可以比完全写入多线foor环更短的方式.
在Python中,我需要规范化(c14n)XML字符串。
我可以使用哪个模块/软件包?我该怎么做呢?
(我更喜欢使用默认的python 2.7模块,而无需额外的安装或补丁。)
有关参考,请参见:http : //www.w3.org/TR/xml-exc-c14n/
是否有GUI工具可以显示有关WSDL文件和XSD文件的详细信息?
也许WSDL编辑器也是一种选择.我的需求主要是检查我必须调用服务的结构和选项.最好是比仅仅读取XML文件本身更具图形性.
我尝试过Eclipse WSDL编辑器,它非常有用,但是我遇到了麻烦.那么,是否有类似的替代方案?(否则我需要修复Eclipse工具......)
Python文件
# -*- coding: UTF-8 -*-
a = 'Köppler'
print a
print a.__class__.__name__
mydict = {}
mydict['name'] = a
print mydict
print mydict['name']
Run Code Online (Sandbox Code Playgroud)
输出:
Köppler
str
{'name': 'K\xc3\xb6ppler'}
Köppler
Run Code Online (Sandbox Code Playgroud)
似乎名称保持不变,但只有在打印字典时才能获得这个奇怪的转义字符串.那我在看什么?这是UTF-8表示吗?
如何在 PostgreSQL 中模拟 XOR 函数?或者,至少,我认为这是一种 XOR 类型的情况。
假设数据如下:
id | col1 | col2 | col3
---+------+------+------
1 | 1 | | 4
2 | | 5 | 4
3 | | 8 |
4 | 12 | 5 | 4
5 | | | 4
6 | 1 | |
7 | | 12 |
Run Code Online (Sandbox Code Playgroud)
我想为那些只填充一列的行返回 1 列。(暂时忽略col3..
让我们从这个 2 列的例子开始:
SELECT
id, COALESCE(col1, col2) AS col
FROM
my_table
WHERE
COALESCE(col1, col2) IS NOT NULL -- at least …Run Code Online (Sandbox Code Playgroud) python ×7
function ×2
string ×2
xml ×2
coding-style ×1
encoding ×1
exception ×1
linux ×1
methods ×1
pad ×1
postgresql ×1
web-services ×1
wsdl ×1
xsd ×1