Questions tagged «python-3.6»

2016年12月发布的Python编程语言版本。针对特定于Python 3.6的问题。尽可能使用更通用的[python]和[python-3.x]标签。

4
是否在Python 3.6+中订购了字典?
与以前的版本不同,字典在Python 3.6中排序(至少在CPython实现下)。这似乎是一个重大更改,但只是文档中的一小段。它被描述为CPython实现细节而不是语言功能,但这也意味着将来可能会成为标准。 在保留元素顺序的同时,新的字典实现如何比旧的实现更好? 以下是文档中的文字: dict()现在使用PyPy率先提出的“紧凑”表示形式。与Python 3.5相比,新dict()的内存使用量减少了20%至25%。PEP 468(在函数中保留** kwarg的顺序。)由此实现。此新实现的顺序保留方面被认为是实现细节,因此不应依赖(将来可能会更改,但是希望在更改语言规范之前,先在几个发行版中使用该新dict实现该语言,为所有当前和将来的Python实现强制要求保留顺序的语义;这还有助于保留与仍旧有效的随机迭代顺序的旧版本语言(例如Python 3.5)的向后兼容性。(由INADA Naoki在发行27350。最初由Raymond Hettinger提出的想法。) 2017年12月更新:Python 3.7 保证dict保留插入顺序

6
ModuleNotFoundError:__main__不是软件包是什么意思?
我正在尝试从控制台运行模块。我的目录结构是这样的: 我正在尝试使用以下命令p_03_using_bisection_search.py从problem_set_02目录中运行模块: $ python3 p_03_using_bisection_search.py 里面的代码p_03_using_bisection_search.py是: __author__ = 'm' from .p_02_paying_debt_off_in_a_year import compute_balance_after def compute_bounds(balance: float, annual_interest_rate: float) -> (float, float): # there is code here, but I have omitted it to save space pass def compute_lowest_payment(balance: float, annual_interest_rate: float) -> float: # there is code here, but I have …

6
如何将Python的.py转换为.exe?
我试图将一个相当简单的Python程序转换为可执行文件,但是找不到我想要的东西,所以我有几个问题(我正在运行Python 3.6): 到目前为止,我发现的方法如下 下载旧版本的Python并使用 pyinstaller/py2exe 在Python 3.6中设置一个虚拟环境,这将允许我执行1。 下载Python到C ++转换器并使用它。 这是我尝试过的/遇到的问题。 我在安装pyinstaller所需的下载之前安装了它(pypi-something),所以它无法正常工作。下载必备文件后,pyinstaller仍然无法识别它。 如果要在Python 2.7中设置virtualenv,我是否真的需要安装Python 2.7? 同样,我看到的唯一的python至C ++转换器只能在Python 3.5之前工作-尝试这样做是否需要下载并使用此版本?

16
为什么Python 3.6.1抛出AttributeError:模块'enum'没有属性'IntFlag'?
我刚刚为MacOS X安装了Python 3.6.1 当我尝试运行控制台(或使用Python3运行任何命令)时,抛出此错误: AttributeError: module 'enum' has no attribute 'IntFlag' $ /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 Failed to import the site module Traceback (most recent call last): File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module> main() File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 530, in main known_paths = addusersitepackages(known_paths) File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 282, in addusersitepackages user_site = getusersitepackages() File …


10
如何推迟/推迟对f弦的评估?
我正在使用模板字符串生成一些文件,为此我喜欢新的f字符串的简洁性,以减少类似以下内容的我以前的模板代码: template_a = "The current name is {name}" names = ["foo", "bar"] for name in names: print (template_a.format(**locals())) 现在,我可以直接替换变量: names = ["foo", "bar"] for name in names: print (f"The current name is {name}") 但是,有时在其他地方定义模板是有意义的-在代码中较高的位置,或者从文件或其他内容中导入模板。这意味着模板是带有格式标记的静态字符串。字符串上必须发生一些事情,以告诉解释器将字符串解释为新的f字符串,但是我不知道是否有这种事情。 有什么方法可以引入字符串并将其解释为f字符串,从而避免使用.format(**locals())调用? 理想情况下,我希望能够像这样进行编码...(magic_fstring_function我不理解的部分在哪里出现): template_a = f"The current name is {name}" # OR [Ideal2] template_a = magic_fstring_function(open('template.txt').read()) names …

4
如何在for循环中注释类型
我想在for-loop中注释变量的类型。我尝试了这个: for i: int in range(5): pass 但这显然没有用。 我期望在PyCharm 2016.3.2中能够自动完成工作。像这样的预注释: i: int for i in range(5): pass 没有帮助。 适用于PyCharm> = 2017.1的PS预注释作品

4
Python中的多行f字符串
我正在尝试为一个国内项目编写符合PEP-8的代码(我必须承认那是我在python世界中的第一步),而且我的f字符串长度超过80个字符 -self.text点附近的实线是80个字符。(对不起没有预览的可悲链接,但我必须有10个以上的代表才能发布它们) 我试图把它分成不同的线路在最Python的方式,但唯一的aswer,实际工作是我的棉短绒错误 工作代码: def __str__(self): return f'{self.date} - {self.time},\nTags:' + \ f' {self.tags},\nText: {self.text}' 输出: 2017-08-30 - 17:58:08.307055, Tags: test tag, Text: test text 短绒棉匠认为我不尊重PEP-8的E122,有没有办法使字符串正确并符合代码?

2
什么是Python 3.6中的变量注释?
Python 3.6即将发布。PEP 494-Python 3.6发布时间表提到了12月底,所以我仔细研究了Python 3.6的新增功能,看看他们提到了变量注释: PEP 484引入了功能参数的类型注释(也称为类型提示)的标准。该PEP向Python添加了语法,以注释变量的类型,包括类变量和实例变量: primes: List[int] = [] captain: str # Note: no initial value! class Starship: stats: Dict[str, int] = {} 就像函数注释一样,Python解释器不会在变量注释中附加任何特殊含义,而仅将它们存储在__annotations__类或模块的特殊属性中。与静态类型语言中的变量声明相反,注释语法的目的是提供一种通过抽象语法树和__annotations__属性为第三方工具和库指定结构化类型元数据的简便方法。 因此,根据我的阅读,它们是来自Python 3.5的类型提示的一部分,如Python 3.5中的类型提示中所述。 我遵循captain: str和class Starship示例,但不确定最后一个示例:如何primes: List[int] = []解释?它是否定义了一个只允许整数的空列表?

3
ModuleNotFoundError:没有名为“ distutils.core”的模块
我最近从升级Ubuntu 18.04到19.04拥有python 3.7。但是我使用从事许多项目Python 3.6。 现在,当我尝试在PyCharm中创建virtualenvwithPython 36时,它引发了: ModuleNotFoundError: No module named 'distutils.core' 我不知道该怎么办。 我尝试安装distutils: milano@milano-PC:~$ sudo apt-get install python3-distutils Reading package lists... Done Building dependency tree Reading state information... Done python3-distutils is already the newest version (3.7.3-1ubuntu1). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 但是正如您所看到的,我拥有最新版本。 你知道该怎么办吗?

3
在Mac上同时安装Python3.6和Python3.7
我正在尝试使用Python3.7在Mac上安装tensorflow。但是,我得到了错误: $ pip3 -v install tensorflow ... Skipping link https://files.pythonhosted.org/packages/56/7a/c6bca0fe52a94ca508731d8b139e7dbd5a36cddc64c19f422f97e5a853e8/tensorflow-1.10.0rc1-cp36-cp36m-win_amd64.whl#sha256=3ab24374888d6a13d55ce2e3cf4ba0c9cd6f824723313db5322512087525cb78 (from https://pypi.org/simple/tensorflow/); it is not compatible with this Python Could not find a version that satisfies the requirement tensorflow (from versions: ) Cleaning up... Removed build tracker '/private/var/folders/4n/9342s4wd3jv0qzwjz8rxrygr0000gp/T/pip-req-tracker-3p60r2lo' No matching distribution found for tensorflow 据我所知,这是因为tensorflow尚不支持Python3.7。作为一种解决方法,我想将Python3.6与3.7一起安装,然后将tensorflow安装到该版本。但是,我是Mac的新手,不确定在不混淆现有的Python版本的情况下执行此操作的正确方法。 我已经尝试过使用brew,但是Python3看起来像它一样具体。做我追求的正确方法是什么?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.