小编Alg*_*bra的帖子

在 Typora 中增加编辑器宽度或可视区域

在 Typora 中书写时,可视宽度(编辑器宽度)是有限的。

在此处输入图片说明

我怎么能从A放大到B?

markdown editor

8
推荐指数
2
解决办法
2560
查看次数

值错误:命名空间 Gtk 不可用

按照说明操作时2. 入门 — Python GTK+ 3 Tutorial 3.4 文档

尝试

In [6]: import gi
   ...: gi.require_version('Gtk', '3.0')
   ...: from gi.repository import Gtk
Run Code Online (Sandbox Code Playgroud)

它报告错误:

~/anaconda3/lib/python3.7/site-packages/gi/__init__.py in require_version(namespace, version)
    128     available_versions = repository.enumerate_versions(namespace)
    129     if not available_versions:
--> 130         raise ValueError('Namespace %s not available' % namespace)
    131
    132     if version not in available_versions:

ValueError: Namespace Gtk not available
Run Code Online (Sandbox Code Playgroud)

按照如何安装 GTK+ 3.0?- 询问 Ubuntu并将 Gtk 安装到 ubuntu

sudo apt-get install libgtk-3-dev
Run Code Online (Sandbox Code Playgroud)

但是,它仍然报告相同的错误。

怎么能解决我的问题?

笔记:

尝试了解决方案

me@host:~:
$ sudo apt install …
Run Code Online (Sandbox Code Playgroud)

linux ubuntu pygobject python-3.x gtk3

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

ord()函数的名称代表什么?

官方Python文档解释道 ord(c)

ord(c):
给定一个表示一个Unicode字符的字符串,返回一个表示该字符的Unicode代码点的整数.例如,ord('a')返回整数97,ord('€')(欧元符号)返回8364.这是chr()的反函数.

它没有指明含义ord,谷歌搜索没有帮助.

它的起源是什么?

python unicode built-in ordinal ord

7
推荐指数
2
解决办法
1632
查看次数

TypeError:_transform()接受2个位置参数,但给出了3个

我了解了CaesarCipher:

In [90]: !cat caesar_cipher.py                                                                                                                        
class CaesarCipher:
    """Construct Caesar cipher using given integer shift for rotation."""
    def __init__(self, shift):
        encoder = [None] * 26
        decoder = [None] * 26
        for k in range(26):
            encoder[k] = chr((k + shift)%26 + ord('A'))
            decoder[k] = chr((k - shift)%26 + ord('A'))  #find the number of Letters
        self.encoder = "".join(encoder)
        self.decoder = "".join(decoder)

    def encrypt(self, message):
        print(self.encoder)
        return self._transform(message, self.encoder)

    def decrypt(self, message):
        return self._transform(message, self.decoder)

    def _transform(original, code):
        msg = list(original)
        for k in …
Run Code Online (Sandbox Code Playgroud)

python

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

wsl2 无法更改文件权限

我正在win10的wsl2上工作:

\n
PS C:\\Users\\Gaowei> wsl -l -v\n  NAME            STATE           VERSION\n* Ubuntu-20.04    Running         2\n
Run Code Online (Sandbox Code Playgroud)\n

进入wsl后,我制作了一个test.md的文件:

\n
\xe2\x9e\x9c  ~ ls -l test.md\n-rwxrwxrwx 1 gaowei gaowei 0 Aug 25 17:17 test.md\n
Run Code Online (Sandbox Code Playgroud)\n

然后尝试更改其权限:

\n
\xe2\x9e\x9c  ~ chmod 755 test.md\n\xe2\x9e\x9c  ~ ls -l test.md\n-rwxrwxrwx 1 gaowei gaowei 0 Aug 25 17:17 test.md\n\xe2\x9e\x9c  ~ sudo chmod 755 test.md\n\xe2\x9e\x9c  ~ ls -l test.md\n-rwxrwxrwx 1 gaowei gaowei 0 Aug 25 17:17 test.md\n
Run Code Online (Sandbox Code Playgroud)\n

不幸的是,事实证明它保持不变。

\n

我的机器信息:

\n
gaowei@Spiritme\n---------------\nOS: Ubuntu 20.04.1 LTS on Windows 10 x86_64\nKernel: 4.19.104-microsoft-standard\nUptime: …
Run Code Online (Sandbox Code Playgroud)

file-permissions chmod windows-subsystem-for-linux

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

直接在python中检索68个内置函数?

命令dir(__builtins__)只是列出所有 151 个内置库。

len(dir(__builtins__)) # output 151
Run Code Online (Sandbox Code Playgroud)

但是,它在2. Built-in Functions 中列出了 68 个内置函数 — Python 3.6.2 文档

我尝试dir(__builtins__)按照以下步骤获取功能:

#I hardtyped the functions as comparition.
officical_builtin_functions = ['abs','all',....]
y = official_builtin_functions
len(y) #output:68
# get official builtin functions from python_builtin_library
dir(__builtins__).index('abs') #output:79
qualified_functions = python_builtin_library[79:]
qualified_functions.pop('exit')
qualified_functions.pop('credits')
qualified_functions.pop('copyright')
qualified_functions.pop('quit')
qualified_functions.pop('license')
quilified_functions.append('__import__')
# then get the 68 qualified_functions from dir(__builtins__)
Run Code Online (Sandbox Code Playgroud)

如何直接列出68个内置函数?

python python-3.x

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

是否可以使用一行命令将[int,bool,float]转换为['int','bool','float']?

我使用多行命令将[int,bool,float]转换为['int','bool','float'].

Numbers = [int, bool, float]
>>> [ i for i in Numbers]
[<class 'int'>, <class 'bool'>, <class 'float'>]
>>>foo = [ str(i) for i in Numbers]
>>>foo
["<class 'int'>", "<class 'bool'>", "<class 'float'>"]
>>> bar = [ i.replace('<class ','') for i in foo]
>>> bar
["'int'>", "'bool'>", "'float'>"]
>>> baz = [i.replace('>','') for i in bar]
>>> baz
["'int'", "'bool'", "'float'"]
>>> [ eval(i) for i in baz]
['int', 'bool', 'float']
Run Code Online (Sandbox Code Playgroud)

如何以优雅的方式完成这项任务?

python

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

点在`django-admin.py startproject myproject .`中

在阅读Django源代码几周后,我记住了这个问题.

启动项目Django,

django-admin.py startproject myproject . # a tailed dot in the end
Run Code Online (Sandbox Code Playgroud)

manage.py 将在项目文件夹外创建.

如果没有'.',

manage.py 将包含在项目文件夹中.

怎么样'.' 工作?

django

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

`SyntaxError: no binding for nonlocal 'topics_with_log_tag' found` 虽然它是有界的

我想获取带有指定“日志”标签的主题:

在嵌套函数中get_topics_with_log_tag,我设置了变量topics_with_log_tagnonlocal:

def log(request):
    """Show all topics and entries with  log tags"""

    topics = Topic.objects.all()
    #select entries with log tag
    def get_topics_with_log_tag(topics):
        nonlocal topics_with_log_tag
        topics_with_log_tag = []
        for topic in topics:
            for entry in topic.entry_set.all():
                if "#log" in entry.tags:
                    topics_with_log_tag.append(topic)

    get_topics_with_log_tag(topics)
Run Code Online (Sandbox Code Playgroud)

它抛出语法错误:

SyntaxError: no binding for nonlocal 'topics_with_log_tag' found
Run Code Online (Sandbox Code Playgroud)

实际上,我确实绑定了它 topics_with_log_tag = []

上面的代码可以用冗余的方式重写为

topics = Topic.objects.all()
#select entries with log tag
def get_topics_with_log_tag(topics):
    # nonlocal topics_with_log_tag
    topics_with_log_tag = []
    for topic in topics:
        for entry …
Run Code Online (Sandbox Code Playgroud)

django

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

从Django模型创建数据库视图

我学会了将sql“视图”作为虚拟表来促进SQL操作,就像

MySQL [distributor]> CREATE VIEW CustomerEMailList AS
    -> SELECT cust_id, cust_name, cust_email
    -> FROM Customers
    -> WHERE cust_email IS NOT NULL;
Query OK, 0 rows affected (0.026 sec)

MySQL [distributor]> select * from customeremaillist;
+------------+---------------+-----------------------+
| cust_id    | cust_name     | cust_email            |
+------------+---------------+-----------------------+
| 1000000001 | Village Toys  | sales@villagetoys.com |
| 1000000003 | Fun4All       | jjones@fun4all.com    |
| 1000000004 | Fun4All       | dstephens@fun4all.com |
| 1000000005 | The Toy Store | kim@thetoystore.com   |
| 1000000006 | toy land      | …
Run Code Online (Sandbox Code Playgroud)

django

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