小编gue*_*tli的帖子

生成SQL以更新主键

我想更改主键和引用此值的所有表行.

# table master
master_id|name
===============
foo|bar

# table detail
detail_id|master_id|name
========================
1234|foo|blu
Run Code Online (Sandbox Code Playgroud)

如果我给出一个脚本或功能

 table=master, value-old=foo, value-new=abc
Run Code Online (Sandbox Code Playgroud)

我想创建一个SQL片段,在所有引用表"master"的表上执行更新:

update detail set master_id=value-new where master_id=value-new;
.....
Run Code Online (Sandbox Code Playgroud)

在内省的帮助下,这应该是可能的.

我用postgres.

更新

问题是,有许多表具有表"master"的外键.我想要一种方法来自动更新所有具有外键到主表的表.

sql postgresql introspection

15
推荐指数
2
解决办法
1万
查看次数

通过`setup.py develop`安装失败 - pip工作

我的python包footools需要html5lib install_requires来自setup.py.

setup.py开发失败

安装setup.py develop失败:

cd src/footools/
python setup.py develop

Processing dependencies for footools==2016.205
Searching for html5lib==0.9999999
Reading https://source.example.com/pypi/simple/html5lib/
Download error on https://source.example.com/pypi/simple/html5lib/: 
   [Errno 185090050] _ssl.c:354: error:0B084002:x509 
   certificate routines:X509_load_cert_crl_file:system lib -- 
   Some packages may not be found!
Couldn't find index page for 'html5lib' (maybe misspelled?)
Run Code Online (Sandbox Code Playgroud)

pip工作

但是直接下载有效:

bar@workdevel123:~/src/footools> pip install html5lib==0.9999999
/home/bar/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: 
InsecurePlatformWarning: A true SSLContext object is not available. 
This prevents urllib3 from configuring SSL appropriately
and may cause certain SSL connections …
Run Code Online (Sandbox Code Playgroud)

python pip setup.py

15
推荐指数
2
解决办法
1791
查看次数

基于文本的数据格式,支持多行字符串

我搜索支持多行字符串的基于文本的数据格式.

JSON不允许多行字符串:

>>> import json
>>> json.dumps(dict(text='first line\nsecond line'))
'{"text": "first line\\nsecond line"}'
Run Code Online (Sandbox Code Playgroud)

我想要的输出:

{"text": "first line
second line"}
Run Code Online (Sandbox Code Playgroud)

这个问题是关于输入和输出的.数据格式应该可以使用vi,emacs或notepad等编辑器进行编辑.

我不在乎是否使用了简单的引号"或tripple引号(如在Python中)""".

是否有一个易于人类可读的文本数据交换格式支持这个?

用例

我想用多行字符串编辑数据vi.如果数据是json格式,这不好玩.

python format json

15
推荐指数
1
解决办法
535
查看次数

不是在Django中嵌套@atomic()的版本?

来自原子()文档

原子块可以嵌套

这听起来像一个很棒的功能,但在我的用例中我想要相反:我希望只要装饰的块@atomic()成功保留,事务就会持久.

有没有办法确保django的交易处理的持久性?

背景

交易是ACID."D"代表耐久性.这就是为什么我认为交易不能在不丢失特征"D"的情况下嵌套.

示例:如果内部事务成功,但外部事务不成功,则外部事务和内部事务将回滚.结果:内部事务不耐用.

我使用PostgreSQL,但AFAIK这应该不重要.

python django postgresql transactions acid

15
推荐指数
4
解决办法
499
查看次数

如何修复`错误:无效命令'bdist_wheel'`?

我尝试在 Ubuntu 20.04.01 上安装 watchman:

guettli@yoga15:~/tmp$ python3 -m venv pywatchman-test
guettli@yoga15:~/tmp$ cd pywatchman-test
guettli@yoga15:~/tmp/pywatchman-test$ . bin/activate

(pywatchman-test) guettli@yoga15:~/tmp/pywatchman-test$ pip install pywatchman
Run Code Online (Sandbox Code Playgroud)

失败:

Collecting pywatchman
  Using cached pywatchman-1.4.1.tar.gz (29 kB)
Building wheels for collected packages: pywatchman
  Building wheel for pywatchman (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/guettli/tmp/pywatchman-test/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-on_zbadt/pywatchman/setup.py'"'"'; __file__='"'"'/tmp/pip-install-on_zbadt/pywatchman/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-9np2rv_b
       cwd: /tmp/pip-install-on_zbadt/pywatchman/
  Complete output (6 lines):
  usage: setup.py [global_opts] cmd1 …
Run Code Online (Sandbox Code Playgroud)

python python-wheel watchman

15
推荐指数
1
解决办法
6137
查看次数

需要改变virtualenv的哪些部分才能重新定位?

所以,我有一个Python程序,有一些荒谬的插件/包.我希望能够在其virtualenv中分发程序,以便捆绑包.但是,该程序适用于Windows,并且在Windows上不支持virtualenvs的"可重定位"功能(以及仍在进行实验).

所以,我正在寻找编写脚本,或者只是编写指令来手动更改绝对路径名以重新定位virtualenv.

我的问题是,如果有人知道我必须在virtualenv中寻找绝对路径名称.我是Python包装的新手.activate.bat脚本包含绝对路径名,但是单个包是否将绝对路径名硬编码到其安装中?

Make Environments Relocatable一节描述了为什么不能简单地移动virtualenv,而是列出包含绝对路径名的地方.

python windows oop distutils virtualenv

14
推荐指数
2
解决办法
7538
查看次数

Django:多次到多次的IntegrityError add()

我们在django中遇到了一个已知问题:

多次到多次添加()中的IntegrityError

如果多个进程/请求尝试将同一行添加到ManyToManyRelation,则存在竞争条件.

如何解决这个问题?

Envionment:

  • Django 1.9
  • Linux服务器
  • Postgres 9.3(如有必要,可以进行更新)

细节

如何重现它:

my_user.groups.add(foo_group)
Run Code Online (Sandbox Code Playgroud)

如果两个请求尝试一次执行此代码,则上述操作失败.这是数据库表和失败的约束:

myapp_egs_d=> \d auth_user_groups
  id       | integer | not null default ...
  user_id  | integer | not null
  group_id | integer | not null
Indexes:
           "auth_user_groups_pkey" PRIMARY KEY, btree (id)
fails ==>  "auth_user_groups_user_id_group_id_key" UNIQUE CONSTRAINT,
                                            btree (user_id, group_id)
Run Code Online (Sandbox Code Playgroud)

环境

由于这只发生在生产机器上,并且我的上下文中的所有生产机器都运行postgres,因此仅使用postgres解决方案.

python django postgresql race-condition

14
推荐指数
1
解决办法
1606
查看次数

在Python中调试:显示最后N个执行行

我很想看到在发生此异常之前由python解释器执行的最后10行:

test_has_perm_in_foobar.py F
Traceback (most recent call last):
  File "/.../test_has_perm_in_foobar.py", line 50, in test_has_perm
    self.assertFalse(check_perm(request, some_object))
  File "/usr/lib/python2.7/unittest/case.py", line 416, in assertFalse
    raise self.failureException(msg)
AssertionError: True is not false
Run Code Online (Sandbox Code Playgroud)

我想看看哪里check_perm()回来了True.

我知道我可以使用交互式调试来查找匹配的行,但我很懒,想要找到check_perm()返回返回值的行的更简单方法.

我使用pyCharm,但基于文本的工具,也将解决我的需求.

顺便说一下:请不要告诉我如何使用调试器进行步进和步入.我知道这个.

这是一些代码来说明它.

def check_perm(request, some_object):
    if condition_1:
        return True
    if condition_2:
        return sub_check(some_object)
    if condition_3:
        return sub_check2(some_object)
    ...
Run Code Online (Sandbox Code Playgroud)

有几种方法check_perm()可以返回True.如果True因为condition_1而返回,那么我想看到这样的东西

+         if condition_1:
+            return True
Run Code Online (Sandbox Code Playgroud)

我想到的输出就像set -x在shell上一样.

更新

cgitb,pytest和其他工具可以显示断言失败的行之前的行.但是,它们只显示当前python文件的行.这个问题是关于在断言发生之前执行的行,但覆盖了所有文件.在我的情况下,我想知道check_perm()创建返回值的位置.工具pytest,cgitb,...没有显示这个.

我在搜索的内容就像set -x …

python debugging pycharm

14
推荐指数
1
解决办法
512
查看次数

DjangoCMS:通过http禁用登录,强制https

我们的DjangoCMS站点可通过http和https访问.

通过http匿名使用是可以的.但我想通过http禁用登录.

有没有办法在用户想要登录时强制使用https?

甚至登录页面(带有用户名和密码字段)也不应该通过http提供.

背景:我不希望密码通过未加密的电线.

更新:该站点托管在Apache Web服务器上.

django https django-cms

14
推荐指数
1
解决办法
785
查看次数

列出Python wheel文件的依赖关系

我有Python轮文件: psutil-5.4.5-cp26-none-linux_x86_64.whl

如何列出此轮具有的依赖关系?

python python-wheel

14
推荐指数
3
解决办法
5554
查看次数