小编fre*_*rik的帖子

根据文件类型在vscode中设置垂直标尺?

我希望仅在查看*.py文件时设置以下标尺.那可能吗?

{
    "editor.rulers": [72, 79]
}
Run Code Online (Sandbox Code Playgroud)

visual-studio-code

6
推荐指数
1
解决办法
1099
查看次数

如何在 QListWidgetItem 和 QCombobox 项目中设置样式(富文本)?(PyQt/PySide)

我发现有人提出了类似的问题,但没有答案或答案是替代解决方案。

我需要在 QComboBoxes 和 QListWidgets(在 PySide 中)中创建一个面包屑路径,并且我正在考虑将这些项目的文本设为粗体。但是,我很难找到有关如何实现这一目标的信息。

这就是我所拥有的:

# QComboBox
for server in servers:
    if optionValue == 'top secret':
        optionValue = server
    else:
        optionValue = '<b>' + server + '</b>'
    self.comboBox_servers.addItem( optionValue, 'data to store for this QCombobox item' )


# QListWidgetItem
for folder in folders:
    item = QtGui.QListWidgetItem()
    if folder == 'top secret':
        item.setText( '<b>' + folder + '</b>' )
    else:
        item.setText( folder )
    iconSequenceFilepath = os.path.join( os.path.dirname(__file__), 'folder.png' )
    item.setIcon( QtGui.QIcon(r'' + iconSequenceFilepath + ''))
    item.setData( QtCore.Qt.UserRole, 'data …
Run Code Online (Sandbox Code Playgroud)

python pyqt pyside

5
推荐指数
1
解决办法
7680
查看次数

如何在提示输入用户名和密码的情况下“ git push”到私有存储库?

我已经将我的私有 Github存储库克隆到了CentOS 6计算机(git版本1.7.1)上。我可以以某种方式设置本地git存储库,以便在键入时始终提示输入用户名和密码git push吗?

并非总是使用相同的用户名。

私人仓库

$ cat .git/config 

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://github.com/USER/PRIVATE-REPO.git
[branch "master"]
    remote = origin
    merge = refs/heads/master
Run Code Online (Sandbox Code Playgroud)

当我git push现在表演时,我得到以下信息:

error: The requested URL returned error: 403 Forbidden while accessing https://github.com/Industriromantik/render-linux.git/info/refs
fatal: HTTP request failed
Run Code Online (Sandbox Code Playgroud)

如果执行以下命令,则推送成功:

git push https://MY-GITHUB-USERNAME@github.com/USER/PRIVATE-REPO
Run Code Online (Sandbox Code Playgroud)

......不过,我要求只执行git push并得到提示两者的用户名和密码,如果在所有可能的。

git github

5
推荐指数
1
解决办法
1325
查看次数

如何将特定IP分配给容器并使其可以在VM主机外部访问?

我希望我的两个容器可以在VM主机之外的单独的特定IP地址(192.168.0.222,192.168.0.227)上使用,而不需要端口映射.这意味着我希望通过使用其IP来直接访问容器上的任何端口.我已经在VM主机外部的网络中运行的机器在192.168.0.1-192.168.0.221范围内.

现在可以使用Docker 1.10.0,如果是这样,怎么样?

我使用的是OS X 10.11 docker version 1.10.0, build 590d5108docker-machine version 0.6.0, build e27fb87使用boot2docker/VirtualBox驱动程序.


我一直试图弄清楚这一点,没有运气,我已经阅读了以下问题和答案:

docker boot2docker docker-machine

5
推荐指数
1
解决办法
2707
查看次数

在sys.modules中动态创建模块会导致sys变为None

我正在创建一个名为QtGithub link)的模块,在其中我为另一个模块命名(例如PyQt4),以便在导入Qt时实际上是在导入PyQt4

from Qt import QtWidgets  # this really imports PyQt4.QtGui
Run Code Online (Sandbox Code Playgroud)

示例Qt模块:

# Qt.py
import sys
import PyQt4.Qt

sys.modules["Qt"] = PyQt4
PyQt4.QtWidgets = PyQt4.QtGui
Run Code Online (Sandbox Code Playgroud)

但是,如果我print sys在Qt.py的末尾添加,sys等于None

print sys
>>> None
Run Code Online (Sandbox Code Playgroud)

为什么会sys“中断”,我是否可以避免中断?

这是在OS X上的Python 2.7.11中。


@ Lol4t0 –这是一个我仅使用标准模块的示例:

# Xyz.py

import os
import sys

sys.modules['Xyz'] = os
print sys  # this will print "None"
Run Code Online (Sandbox Code Playgroud)

因此,导入此文件将导致“未打印任何内容:

$ python
Python 2.7.11 (default, Jan …
Run Code Online (Sandbox Code Playgroud)

python

5
推荐指数
1
解决办法
732
查看次数

考虑到PEP-8处理长琴弦的最佳方法是什么?

结果字符串有一个换行符(我相信这个语法会破坏我的IDE中的函数折叠):

>>> def linebreak():
>>>     return """Hello this is a really long string which eventually
>>> needs to be breaked due to line length"""
>>> print(linebreak())
Hello this is a really long string which eventually
needs to be breaked
Run Code Online (Sandbox Code Playgroud)

这样更好,但这不仅包括换行符,还包括结果字符串中的多个空格:

>>> def whitespace():
>>>     some_string = """Hello this is a really long string which eventually
>>>                      needs to be breaked due to line length"""
>>> print(whitespace())
Hello this is a really long string which eventually
                     needs to be breaked
Run Code Online (Sandbox Code Playgroud)

正如 …

python

5
推荐指数
0
解决办法
493
查看次数

为什么我在Windows上使用async和await获取NotImplementedError?

我有这个代码:

import os
import time
import asyncio


async def run_command(*args):
    """
    Example from:
        http://asyncio.readthedocs.io/en/latest/subprocess.html
    """
    # Create subprocess
    process = await asyncio.create_subprocess_exec(
        *args,
        # stdout must a pipe to be accessible as process.stdout
        stdout=asyncio.subprocess.PIPE)

    # Wait for the subprocess to finish
    stdout, stderr = await process.communicate()

    # Result
    result = stdout.decode().strip()

    # Return stdout
    return result


def run_asyncio_commands(tasks):
    """Run tasks using asyncio and return results"""
    loop = asyncio.get_event_loop()
    commands = asyncio.gather(*tasks)  # Unpack list using *
    results = loop.run_until_complete(commands)
    loop.close() …
Run Code Online (Sandbox Code Playgroud)

python python-asyncio

5
推荐指数
2
解决办法
2067
查看次数

如何git checkout commit并使子模块更新到该commit?

我正在克隆一个带有子模块的项目,并恢复到大约一年前的提交:

$ git clone --recursive --branch 5.6 https://codereview.qt-project.org/pyside/pyside-setup
$ cd pyside-setup
$ git checkout 8913156381b7dc51f903b9e459c143fb25097cab

M   sources/pyside2-examples
M   sources/pyside2-tools
Note: checking out '8913156381b7dc51f903b9e459c143fb25097cab'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using …
Run Code Online (Sandbox Code Playgroud)

git

5
推荐指数
1
解决办法
283
查看次数

如何在PyQt/PySide中将数据设置为QComboBox?

以下是使用setData将数据添加到QListWidgetItem的方法.如何以类似的方式添加数据(隐藏它),但是添加到QComboBox项目 - 如何在QComboBoxItems中检索此数据?

item = QtGui.QListWidgetItem()
item.setText( myText )
item.setData( QtCore.Qt.UserRole, myData)

self.myListWidget.addItem( item )                       
Run Code Online (Sandbox Code Playgroud)

python pyqt pyside

4
推荐指数
1
解决办法
5049
查看次数

如何以用户身份使用 Slack API 上传文件?

现在,通过上传文件时使用的令牌files.upload与我的 Slack 用户帐户相关联。因此,使用此令牌执行的任何上传似乎都是由我完成的。

但是,我想指定类似的内容as_user(在使用时可用chat.PostMessage),这将使上传看起来好像是由指定的 Slack 用户上传的。这可能吗?

我有这个:

 upload_file(filepath='/path/to/file.jpg',
             channels='#uploads',
             title='my image',
             initial_comment='pls give me some feedback!')
Run Code Online (Sandbox Code Playgroud)

这是被调用的函数:

import os
import requests

TOKEN = your_token_here

def upload_file(
        filepath,
        channels,
        filename=None,
        content=None,
        title=None,
        initial_comment=None):
    """Upload file to channel

    Note:
        URLs can be constructed from:
        https://api.slack.com/methods/files.upload/test
    """

    if filename is None:
        filename = os.path.basename(filepath)

    data = {}
    data['token'] = TOKEN
    data['file'] = filepath
    data['filename'] = filename
    data['channels'] = channels

    if content is not None:
        data['content'] = content …
Run Code Online (Sandbox Code Playgroud)

python slack-api

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