我正在尝试在一个使用null的函数上运行doctest.但是doctest似乎并不喜欢nulls ......
def do_something_with_hex(c):
"""
>>> do_something_with_hex('\x00')
'\x00'
"""
return repr(c)
import doctest
doctest.testmod()
Run Code Online (Sandbox Code Playgroud)
我看到了这些错误
Failed example:
do_something_with_hex(' ')
Exception raised:
Traceback (most recent call last):
File "C:\Python27\lib\doctest.py", line 1254, in __run
compileflags, 1) in test.globs
TypeError: compile() expected string without null bytes
**********************************************************************
Run Code Online (Sandbox Code Playgroud)
在这样的测试用例中,我该怎么做才能允许空值?
我在Windows XP上运行django 1.3,python 2.7
我正在尝试在我的django应用程序的静态文件夹中设置一个CSS.
模板看起来像:
<html>
<head>
<title>css demo</title>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/my.css" />
</head>
<body>
Run Code Online (Sandbox Code Playgroud)
生成的HTML如下所示:
<html>
<head>
<title>css demo</title>
<link rel="stylesheet" type="text/css" href="http://localhost/static/css/my.css" />
</head>
...
Run Code Online (Sandbox Code Playgroud)
因此,似乎我已经设置了所有内容,以便指定静态文件在模板中的位置,然后在生成的html中.
但是在' http://localhost/static/css/my.css '中注意到了.我怎么去那里?
我像这样跑了collectstatic:
C:\root\workspace\mywebapp\src\mywebapp>c:\Python27\python.exe manage.py collectstatic
You have requested to collect static files at the destination location as specified in your settings file.
This will overwrite existing files.
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Copying 'c:\root\workspace\mywebapp\src\mywebapp\css_demo\static\css\my.css' …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用如下的属性设置器.我在这里关注这个例子: @property装饰器是如何工作的?
class Contact:
def __init__(self):
self._funds = 0.00
@property
def funds(self):
return self._funds
@funds.setter
def funds(self, value):
self._funds = value
Run Code Online (Sandbox Code Playgroud)
吸气剂工作正常
>>> contact = Contact()
>>> contact.funds
0.0
Run Code Online (Sandbox Code Playgroud)
但是我错过了关于二传手的事情:
>>> contact.funds(1000.21)
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/doctest.py", line 1315, in __run
compileflags, 1) in test.globs
File "<doctest __main__.Contact[2]>", line 1, in <module>
contact.funds(1000.21)
TypeError: 'str' object is not callable
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?