result = sm.OLS(gold_lookback, silver_lookback ).fit()
Run Code Online (Sandbox Code Playgroud)
得到结果后,我怎样才能得到系数和常数?
换句话说,如果
y = ax + c
如何获得价值a和c?
我有一个自定义用户模型。我已经创建了一个用于用户注册的 api。以下是我的序列化程序。
class UserSerializer(serializers.ModelSerializer):
email = serializers.EmailField(
required=True,
validators=[
UniqueValidator(queryset=get_user_model().objects.all())
]
)
password = serializers.CharField(min_length=8)
class Meta:
model = get_user_model()
fields = ('email', 'password')
extra_kwargs = {'password': {'write_only': True}, }
def create(self, validated_data):
email = validated_data.pop('email')
password = validated_data.pop('password')
user = get_user_model().objects.create_user(email, password, **validated_data)
return user
Run Code Online (Sandbox Code Playgroud)
这是我的观点:
class Registration(generics.CreateAPIView):
serializer_class = UserSerializer
queryset = get_user_model().objects.all()
Run Code Online (Sandbox Code Playgroud)
有两个输入email和password。password字段作为 write_only 字段给出。但是在创建用户后,api 返回散列的密码。如何防止密码被退回?
我在virtualenv中使用了刮板外壳。IPython安装在virtualenv内部。当我开始使用scrapy shell时
scrapy shell 'https://example.com'
Run Code Online (Sandbox Code Playgroud)
并按Tab键获取自动完成建议,它会显示很多调试信息。如何禁用此功能?
In [1]: from scra2018-03-23 10:05:45 [parso.python.diff] DEBUG: diff parser start
2018-03-23 10:05:45 [parso.python.diff] DEBUG: diff parser calculated
2018-03-23 10:05:45 [parso.python.diff] DEBUG: diff: line_lengths old: 1, new: 1
2018-03-23 10:05:45 [parso.python.diff] DEBUG: diff replace old[1:1] new[1:1]
2018-03-23 10:05:45 [parso.python.diff] DEBUG: parse_part from 1 to 1 (to 0 in part parser)
2018-03-23 10:05:45 [parso.python.diff] DEBUG: diff parser end
Run Code Online (Sandbox Code Playgroud)
我正在尝试设置函数超时,但是没有成功。
我从https://docs.python.org/3/library/signal.html?highlight=signal%20sigalrm#example运行示例代码
但是,我得到了 AttributeError。
我在 Windows10 上使用 python 3.6.3
这是我的代码。
\>>> import signal
\>>> signal.SIGALRM
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'signal' has no attribute 'SIGALRM'
Run Code Online (Sandbox Code Playgroud) 我已经使用channels.invite方法将用户添加到松弛通道。添加用户后,我使用了channels.kick方法将用户从频道中删除。但松弛会返回一个错误:
stricted_action:团队首选项阻止经过身份验证的用户踢球。
我无法从频道中删除用户的原因可能是什么?
我正在编写一个脚本来读取一个 csv 文件。csv 文件和脚本位于同一目录中。但是当我尝试打开文件时,它给了我FileNotFoundError: [Errno 2] No such file or directory: 'zipcodes.csv'. 我用来读取文件的代码是
with open('zipcodes.csv', 'r') as zipcode_file:
reader = csv.DictReader(zipcode_file)
Run Code Online (Sandbox Code Playgroud)
如果我提供文件的完整路径,它将起作用。为什么open()需要文件的完整路径?
我有一个基于通用类的视图:
class ProjectDetails(mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
generics.GenericAPIView):
queryset = Project.objects.all()
# Rest of definition
Run Code Online (Sandbox Code Playgroud)
在我urls.py,我有:
urlpatterns = [
url(r'^(?P<pk>[0-9]+)/$', views.ProjectDetails.as_view())
]
Run Code Online (Sandbox Code Playgroud)
当使用不存在的id调用API时,它将返回HTTP 404包含内容的响应:
{
"detail": "Not found."
}
Run Code Online (Sandbox Code Playgroud)
是否可以修改此响应?
我只需要为此视图自定义错误消息.
我有一个 Slack 应用程序,我已经使用这个应用程序进行了身份验证。当我列出所有频道时,没有列出一些私人频道。我们是否需要工作区管理员的访问令牌来列出所有私人和公共频道?
我正在使用 Ubuntu 14.04。我创建了一个虚拟环境并使用
pip install orange3
Run Code Online (Sandbox Code Playgroud)
我还使用安装了 PyQt4
sudo apt-get install python3-pyqt4
Run Code Online (Sandbox Code Playgroud)
但是当我从终端启动 orange3 时,出现以下错误。
Traceback (most recent call last):
File "/home/arun/.virtualenvs/orange3env/bin/orange-canvas", line 11, in <module>
load_entry_point('Orange3', 'gui_scripts', 'orange-canvas')()
File "/home/arun/.virtualenvs/orange3env/lib/python3.4/site-packages/pkg_resources/__init__.py", line 561, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/home/arun/.virtualenvs/orange3env/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2649, in load_entry_point
return ep.load()
File "/home/arun/.virtualenvs/orange3env/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2303, in load
return self.resolve()
File "/home/arun/.virtualenvs/orange3env/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2309, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/home/arun/lab/orange3/Orange/canvas/__main__.py", line 21, in <module>
from AnyQt.QtGui import QFont, QColor, QDesktopServices
File "/home/arun/.virtualenvs/orange3env/lib/python3.4/site-packages/AnyQt/QtGui.py", line …Run Code Online (Sandbox Code Playgroud) 正如此答案中所讨论的,我编写了用于检查唯一键违规的代码:
if err, ok := err.(*pq.Error); ok {
if err.Code.Name() == "unique_violation" {
fail(w, http.StatusBadRequest, 0, "Item already exists")
return
}
}
Run Code Online (Sandbox Code Playgroud)
为了编写单元测试用例,我需要模拟这个错误。我已经为错误编写了模拟,如下所示:
return pq.Error{Code: "unique_violation"}
Run Code Online (Sandbox Code Playgroud)
但这与代码不匹配。我如何嘲笑pq.Error?
python ×7
django ×2
slack ×2
slack-api ×2
file ×1
go ×1
ipython ×1
orange ×1
pandas ×1
postgresql ×1
pq ×1
pyqt4 ×1
python-3.4 ×1
python-3.x ×1
rest ×1
scrapy ×1
signals ×1
statsmodels ×1
unit-testing ×1