qyuhen / book

学习笔记
12.52k stars 3.42k forks source link

Python 笔记 import * 在 Python 3 中没有废除 #36

Open twz915 opened 9 years ago

twz915 commented 9 years ago

from . import * 在 Python3中还是可以使用的,符合语法规则,我测试的 Python 3.5

PDF 87 页

myd7349 commented 8 years ago

@twz915 My test:

Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> def foo():
    from sys import *

SyntaxError: import * only allowed at module level
>>> 
shellexy commented 8 years ago

这个在 python2.7 里边也是这样啊

On Tue, Feb 2, 2016 at 8:40 AM, myd7349 notifications@github.com wrote:

@twz915 https://github.com/twz915 My test:

def foo(): from sys import SyntaxError: import \ only allowed at module level>>>

— Reply to this email directly or view it on GitHub https://github.com/qyuhen/book/issues/36#issuecomment-178274501.

twz915 commented 8 years ago

@shellexy 对的,这不是Python 2.7 和 Python 3.x 的不同,它们是一样的。还有为什么要在函数中引入,这是不推荐的

dinever commented 8 years ago

@myd7349 你这个是语法错误啊