我正在尝试检索python 3.4的机械化模块.任何人都可以指导我朝着正确的方向前进,也许还会引导我完成我需要采取的步骤才能正确安装?我目前正在使用Windows 10.
我试图让argparse忽略这样一个事实,即当-l
指定了一个可选的参数()时,不应该评估两个通常需要的位置参数.
基本上我试图复制--help的行为:当你指定-h时,忽略所有缺少的必需参数.
示例代码:
parser = argparse.ArgumentParser(description="Foo bar baz")
parser.add_argument('arg1', help='arg1 is a positional argument that does this')
parser.add_argument('arg2', help='arg2 is a positional argument that does this')
parser.add_argument('-l', '--list', dest='list', help='this is an optional argument that prints stuff')
options, args = parser.parse_args()
if options.list:
print "I list stuff"
Run Code Online (Sandbox Code Playgroud)
当然,如果我现在运行它,我得到:
error: too few arguments
Run Code Online (Sandbox Code Playgroud)
我尝试了不同的东西nargs='?'
,但是无法正常工作.
这个问题非常相似,但没有得到回答.
我正在关注这个文档http://ivaynberg.github.io/select2/来创建选择框placeholder
.我的问题是placeholder
不起作用.你能帮忙解决这个问题吗?
代码:也在http://jsfiddle.net/VwGGU/3/
HTML:
<select style="width:300px" id="source">
<optgroup label="Alaskan/Hawaiian Time Zone">
<option value="AK">Alaska</option>
<option value="HI">Hawaii</option>
</optgroup>
<optgroup label="Pacific Time Zone">
<option value="CA">California</option>
<option value="NV">Nevada</option>
<option value="OR">Oregon</option>
<option value="WA">Washington</option>
</optgroup>
</select>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
$("#e2").select2({
placeholder: "Select a State",
allowClear: true
});
Run Code Online (Sandbox Code Playgroud)
上面的示例显示"Alaska"而不是"Select a State"作为占位符.
更新1:
select2.js
现在添加并清空option
.它仍然没有显示placeholder
HTML
<select style="width:300px" id="source" placeholder="testt test">
<option></option>
<optgroup label="Alaskan/Hawaiian Time Zone">
<option value="AK">Alaska</option>
<option value="HI">Hawaii</option>
</optgroup>
<optgroup label="Pacific Time Zone">
<option …
Run Code Online (Sandbox Code Playgroud) 我在Python 2.6和3.2中遇到了令我惊讶的行为:
>>> xs = dict.fromkeys(range(2), [])
>>> xs
{0: [], 1: []}
>>> xs[0].append(1)
>>> xs
{0: [1], 1: [1]}
Run Code Online (Sandbox Code Playgroud)
然而,dict
3.2中的理解表现出更礼貌的举止:
>>> xs = {i:[] for i in range(2)}
>>> xs
{0: [], 1: []}
>>> xs[0].append(1)
>>> xs
{0: [1], 1: []}
>>>
Run Code Online (Sandbox Code Playgroud)
为什么fromkeys
这样做?
import *
在Python中使用函数(大概来自importlib
)的等价物是什么?
我知道您可以导入一个模块mod = __import__(...)
,该模块将委托给当前配置的实现.你也可以这样做
mod_spec = importlib.utl.spec_from_file_location(...)
mod = importlib.util.module_from_spec(mod_spec)
mod_spec.loader.exec_module(mod)
Run Code Online (Sandbox Code Playgroud)
这允许你做一些疯狂的事情,比如通过在调用之前插入东西将东西注入模块exec_module
.(由/sf/answers/4738471/和/sf/answers/2705561491/提供)
但是,我的问题仍然存在.import *
功能形式如何工作?什么函数根据存在/内容确定从模块加载哪些名称__all__
?
我有一个自定义类,
class A:
def __init__(self, a, b):
self.a = a
self.b = b
Run Code Online (Sandbox Code Playgroud)
该类不可迭代或可索引或类似的东西.如果可能的话,我想保持这种方式.有可能像以下工作一样吗?
>>> x = A(1, 2)
>>> min(x)
1
>>> max(x)
2
Run Code Online (Sandbox Code Playgroud)
让我想到这一点的是,min
并max
在文档中列为"通用序列操作" .由于range
被同一个文档认为是序列类型,我认为必须有某种可能的优化range
,也许我可以利用它.
也许有一种我不知道的神奇方法可以实现这一点吗?
如果类型正确,提供输入数组作为numpy中的ufunc的可选输出参数通常是安全的吗?例如,我已经验证以下工作:
>>> import numpy as np
>>> arr = np.array([1.2, 3.4, 4.5])
>>> np.floor(arr, arr)
array([ 1., 3., 4.])
Run Code Online (Sandbox Code Playgroud)
数组类型必须与输出兼容或与输出相同(它是一个浮点数numpy.floor()
),否则会发生这种情况:
>>> arr2 = np.array([1, 3, 4], dtype = np.uint8)
>>> np.floor(arr2, arr2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ufunc 'floor' output (typecode 'e') could not be coerced to provided output parameter (typecode 'B') according to the casting rule ''same_kind''
Run Code Online (Sandbox Code Playgroud)
因此,给定一个正确类型的数组,通常可以安全地应用ufuncs吗?或者是floor()
一个例外情况?文档没有说清楚,以下两个线程也没有与问题相关:
编辑:
作为第一顺序猜测,我认为它基于http://docs.scipy.org/doc/numpy/user/c-info.ufunc-tutorial.html上的教程,经常但并不总是安全的.在计算过程中使用输出数组作为中间结果的临时持有者似乎没有任何限制.虽然类似于floor()
也ciel() …
a1=[1,2,3,4,5,6]
b1=[[1,2,3], [4,5,6]]
Run Code Online (Sandbox Code Playgroud)
如果使用np.shape
lista1
将返回(6,)
并且b1
将返回(2, 3)
.
如果禁止使用 Numpy,我如何获得 list 的形状a1
?
我主要对如何让python程序知道a1
只有一维感到困惑。有什么好的方法吗?
是否可以更改Rstudio中的背景颜色?我知道可以改变编辑器的主题,这是一个非常好的功能,我已经使用,但是可以改变其他窗口的背景颜色(环境,历史,文件等... )除了白色以外的东西和文字更暗的东西?太轻的背景让我头疼.
如果我运行以下代码
data = [[1,2],[3,4],[5,6]]
for x in data:
print(x[0])
for x[0] in data:
print(x)
Run Code Online (Sandbox Code Playgroud)
我得到以下输出
1
3
5
[[1, 2], 6]
[[3, 4], 6]
[[...], 6]
Run Code Online (Sandbox Code Playgroud)
我最终得到一个列表[[...], 6]
,但是这个[...]
列表是什么?
它不正常的行为,因为调用y = [[...], 6]
然后将下面的语句显示[...]
为0
>>> print(y)
[[Ellipsis], 6]
>>> print(y[0])
[0]
Run Code Online (Sandbox Code Playgroud)
但是,当我在顶部运行代码并键入以下语句时,结果没有意义:
>>> print(x)
[[...], 6]
>>> print(x[0])
[[...], 6]
>>> print(x[0][0])
[[...], 6]
>>> print(x[0][0][0])
[[...], 6]
Run Code Online (Sandbox Code Playgroud)
然而不知何故,这两个结果都是6
>>> print(x[1])
6
>>> print(x[0][1])
6
Run Code Online (Sandbox Code Playgroud)
回顾一下这个问题:这怎么可能,[...]
代表什么,以及顶部的for循环如何创建这样的列表?
python ×8
python-3.x ×4
argparse ×1
html ×1
in-place ×1
javascript ×1
jquery ×1
mechanize ×1
numpy ×1
numpy-ufunc ×1
rstudio ×1