我在这里的官方cpython代码链接上的说明如下.我做了一个
hg update 3.5
Run Code Online (Sandbox Code Playgroud)
然后做了以下.
sudo apt-get build-dep python3.5
Run Code Online (Sandbox Code Playgroud)
但它引发了一个错误,说明下面列出的语句:
Reading package lists... Done
Picking 'python3-defaults' as source package instead of 'python3'
E: Unable to find a source package for python3
Run Code Online (Sandbox Code Playgroud)
我确实读到了关于减少版本和尝试上面的代码集的问题,这也是因为以下原因引起的.
$ hg update 2.7
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ sudo apt-get build-dep python2.7
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may …Run Code Online (Sandbox Code Playgroud) 我是 Python 新手,正在编写一个读取目录(仅包含文件)中所有文件的脚本。我知道我可以使用如下循环获取文件:
for file in os.listdir("my directory"):
Run Code Online (Sandbox Code Playgroud)
或者使用以下语法的文件列表:
files = [f for f in os.listdir("my directory ")]
Run Code Online (Sandbox Code Playgroud)
问题是我以完全随机的顺序获取文件。我使用sort命令对列表进行排序解决了我的问题,但是,我仍然想知道:
Python 如何对方法返回的文件进行排序listdir?
这可能是最简单的问题.但我尝试以下列方式打印元组的各个值.
mytuple=('new','lets python','python 2.7')
>>> print "%{0} experience, %{1} with %{2} " %mytuple
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
print "%{0} experience, %{1} with %{2} " %mytuple
ValueError: unsupported format character '{' (0x7b) at index 1
Run Code Online (Sandbox Code Playgroud)
我想打印输出如下所示.
"new experience, lets python with python 2.7"
Run Code Online (Sandbox Code Playgroud)
我不记得它在哪里完成.它被称为解包元组值,打印格式化元组.
这是我在教学生时发现的Python怪异.
如果负索引应该正常,那么对于字符串m ='string',我执行了以下步骤.
>>> m='string'
>>> m[:-1]
'strin'
>>> m[:0]
''
>>> m[-1]
'g'
>>> m[0:]
'string'
>>> m[:-1]
'strin'
>>> m[:0]
''
>>>
Run Code Online (Sandbox Code Playgroud)
我想知道如何使用负索引访问整个字符串?
python ×4
python-2.7 ×2
android ×1
cpython ×1
directory ×1
list ×1
python-3.x ×1
string ×1
tuples ×1
ubuntu-16.04 ×1