在许多SO问题和bash教程中,我看到我可以通过两种方式访问bash脚本中的命令行参数:
$ ~ >cat testargs.sh
#!/bin/bash
echo "you passed me" $*
echo "you passed me" $@
Run Code Online (Sandbox Code Playgroud)
结果如下:
$ ~> bash testargs.sh arg1 arg2
you passed me arg1 arg2
you passed me arg1 arg2
Run Code Online (Sandbox Code Playgroud)
$*和之间有什么区别$@?
应该何时使用前者,何时使用后者?
我有Bash的问题,我不知道为什么.
在shell下,我输入:
echo $$ ## print 2433
(echo $$) ## also print 2433
(./getpid) ## print 2602
Run Code Online (Sandbox Code Playgroud)
"getpid"是一个获取当前pid的C程序,如:
Run Code Online (Sandbox Code Playgroud)int main() { printf("%d", (int)getpid()); return 0; }
令我困惑的是:
你能帮助我吗?
在保存模型之前,我会重新调整图片大小.但是,如何检查是否添加了新图片或更新了描述,以便每次保存模型时都可以跳过重新缩放?
class Model(model.Model):
image=models.ImageField(upload_to='folder')
thumb=models.ImageField(upload_to='folder')
description=models.CharField()
def save(self, *args, **kwargs):
if self.image:
small=rescale_image(self.image,width=100,height=100)
self.image_small=SimpleUploadedFile(name,small_pic)
super(Model, self).save(*args, **kwargs)
Run Code Online (Sandbox Code Playgroud)
我想仅在新图像加载或图像更新时重新缩放,但在更新描述时不重新缩放.
我正在为下一个函数编写测试:
def foo():
print 'hello world!'
Run Code Online (Sandbox Code Playgroud)
所以,当我想测试这个函数时,代码将是这样的:
import sys
from foomodule import foo
def test_foo():
foo()
output = sys.stdout.getline().strip() # because stdout is an StringIO instance
assert output == 'hello world!'
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用-s参数运行nosetests,测试会崩溃.如何通过unittest或nose模块捕获输出?
本来我想问这个问题,但后来我发现之前已经想过......
谷歌搜索我发现这个扩展configparser的例子.以下适用于Python 3:
$ python3
Python 3.2.3rc2 (default, Mar 21 2012, 06:59:51)
[GCC 4.6.3] on linux2
>>> from configparser import SafeConfigParser
>>> class AmritaConfigParser(SafeConfigParser):
... def __init_(self):
... super().__init__()
...
>>> cfg = AmritaConfigParser()
Run Code Online (Sandbox Code Playgroud)
但不是Python 2:
>>> class AmritaConfigParser(SafeConfigParser):
... def __init__(self):
... super(SafeConfigParser).init()
...
>>> cfg = AmritaConfigParser()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __init__
TypeError: must be type, not classob
Run Code Online (Sandbox Code Playgroud)
然后我读了一下Python New Class和Old Class样式(例如 …
我有两个日期范围,其中每个范围由开始和结束日期(显然,datetime.date()实例)确定.这两个范围可以重叠或不重叠.我需要重叠的天数.当然,我可以预先填充两个集合,所有日期都在两个范围内,并且执行一个集合交集,但这可能是低效的...除了使用覆盖所有情况的长if-elif部分的另一个解决方案之外,还有更好的方法吗?
我刚刚从python.org安装了Python3,并且无法安装包pip.根据设计,网络上有一个中间人的数据包检测设备,通过使用自己的证书重新签名所有ssl连接来检查所有数据包(包括ssl).部分GPO将自定义根证书推送到Windows密钥库.
使用Java时,如果我需要访问任何外部https站点,我需要手动更新JVM中的cacerts以信任自签名CA证书.
我如何为python实现这一目标?现在,当我尝试安装软件包时pip,可以理解,我得到了很多[SSL: CERTIFICATE_VERIFY_FAILED]错误.
我意识到我可以使用--trusted-host参数忽略它们,但我不想为我正在尝试安装的每个包执行此操作.
有没有办法更新python使用的CA证书存储?
尽管安装了插件,我似乎无法使用Nose进行代码覆盖.
有想法该怎么解决这个吗?
12:15:25 ~/sandbox/ec$ nosetests --plugins
Plugin xunit
Plugin deprecated
Plugin skip
Plugin multiprocess
Plugin failuredetail
Plugin capture
Plugin logcapture
Plugin coverage
Plugin attributeselector
Plugin doctest
Plugin profile
Plugin id
Plugin allmodules
Plugin collect-only
Plugin isolation
Plugin pdb
12:15:34 ~/sandbox/ec$ nosetests -v --with-coverage
nose.plugins.cover: ERROR: Coverage not available: unable to import coverage module
tests.edgecast_client_tests.test_log ... ok
----------------------------------------------------------------------
Ran 1 test in 0.206s
OK
Run Code Online (Sandbox Code Playgroud) 我有这个模型
summary = models.TextField()
Run Code Online (Sandbox Code Playgroud)
但我想只有4行15列.
此外,如果我这样做,我需要再次安装数据库.
python ×6
bash ×2
django ×2
configparser ×1
coverage.py ×1
date ×1
date-range ×1
groovy ×1
inheritance ×1
java ×1
linux ×1
nose ×1
nosetests ×1
pid ×1
pip ×1
python-nose ×1
shell ×1
ssl ×1
unit-testing ×1
windows ×1