按照说明操作时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) 官方Python文档解释道 ord(c)
ord(c):
给定一个表示一个Unicode字符的字符串,返回一个表示该字符的Unicode代码点的整数.例如,ord('a')返回整数97,ord('€')(欧元符号)返回8364.这是chr()的反函数.
它没有指明含义ord,谷歌搜索没有帮助.
它的起源是什么?
我了解了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) 我正在win10的wsl2上工作:
\nPS C:\\Users\\Gaowei> wsl -l -v\n NAME STATE VERSION\n* Ubuntu-20.04 Running 2\nRun 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\nRun 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\nRun Code Online (Sandbox Code Playgroud)\n不幸的是,事实证明它保持不变。
\n我的机器信息:
\ngaowei@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) 命令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个内置函数?
我使用多行命令将[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)
如何以优雅的方式完成这项任务?
在阅读Django源代码几周后,我记住了这个问题.
启动项目Django,
django-admin.py startproject myproject . # a tailed dot in the end
Run Code Online (Sandbox Code Playgroud)
manage.py 将在项目文件夹外创建.
如果没有'.',
manage.py 将包含在项目文件夹中.
怎么样'.' 工作?
我想获取带有指定“日志”标签的主题:
在嵌套函数中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) 我学会了将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)