Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial is unclear on multiple imports of a module. #59780

Closed
roysmith mannequin opened this issue Aug 7, 2012 · 5 comments
Closed

Tutorial is unclear on multiple imports of a module. #59780

roysmith mannequin opened this issue Aug 7, 2012 · 5 comments
Labels
docs Documentation in the Doc dir easy type-feature A feature request or enhancement

Comments

@roysmith
Copy link
Mannequin

roysmith mannequin commented Aug 7, 2012

BPO 15575
Nosy @ezio-melotti, @bitdancer
Files
  • module_multi_exec_doc_27.patch: 2.7 patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2013-04-21.21:17:06.903>
    created_at = <Date 2012-08-07.18:11:02.084>
    labels = ['easy', 'type-feature', 'docs']
    title = 'Tutorial is unclear on multiple imports of a module.'
    updated_at = <Date 2013-04-21.21:17:06.902>
    user = 'https://bugs.python.org/roysmith'

    bugs.python.org fields:

    activity = <Date 2013-04-21.21:17:06.902>
    actor = 'r.david.murray'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2013-04-21.21:17:06.903>
    closer = 'r.david.murray'
    components = ['Documentation']
    creation = <Date 2012-08-07.18:11:02.084>
    creator = 'roysmith'
    dependencies = []
    files = ['29575']
    hgrepos = []
    issue_num = 15575
    keywords = ['patch', 'easy']
    message_count = 5.0
    messages = ['167628', '167629', '185256', '187524', '187525']
    nosy_count = 6.0
    nosy_names = ['roysmith', 'ezio.melotti', 'r.david.murray', 'docs@python', 'python-dev', 'jamesob']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue15575'
    versions = ['Python 2.7']

    @roysmith
    Copy link
    Mannequin Author

    roysmith mannequin commented Aug 7, 2012

    Opening this bug at Ben Finney's request. See https://groups.google.com/forum/?fromgroups#!topic/comp.lang.python/wmDUrpW2ZCU for the full thread discussing the problem. Here's a significant excerpt:

    -------------------------------------------------
    The tutorial is misleading on this. It it says plainly:

    A module can contain executable statements as well as function 
    definitions. […] They are executed only the *first* time the module 
    is imported somewhere. 
    
    <URL:http://docs.python.org/tutorial/modules.html> 
    

    but it doesn't make clear that a module can exist in the ‘sys.modules’
    list multiple times under different names.
    -------------------------------------------------

    Also note:

    --------------------------------------------------
    The footnote to that is wrong too:

    [1] In fact function definitions are also ‘statements’ that are ‘executed’; the execution of a module-level function enters the function name in the module’s global symbol table.

    I think what it's supposed to say is "... the execution of a module-level def statement ..."
    ---------------------------------------------------

    @roysmith roysmith mannequin assigned docspython Aug 7, 2012
    @roysmith roysmith mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Aug 7, 2012
    @bitdancer
    Copy link
    Member

    Well, I don't think a full discussion of the subtlety about a module appearing under multiple names belongs in the tutorial, but I think the sentence could be amended to say "Statements in a module are executed only the *first* time the module name is encountered in an import statement".

    The other is indeed a bug (IMO the sentence is missing the word 'definition', as in 'execution of a function definition').

    @jamesob
    Copy link
    Mannequin

    jamesob mannequin commented Mar 26, 2013

    Howdy; attached is a patch containing the doc changes. I figured that some elaboration was in addition to what r.david.murray recommended, so I've included a brief allusion to the problem of equivalent paths.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 21, 2013

    New changeset 9df9931fae96 by R David Murray in branch '3.3':
    bpo-15575: Clarify tutorial description of when modules are executed.
    http://hg.python.org/cpython/rev/9df9931fae96

    New changeset dac847938326 by R David Murray in branch 'default':
    bpo-15575: Clarify tutorial description of when modules are executed.
    http://hg.python.org/cpython/rev/dac847938326

    New changeset a1421d28393b by R David Murray in branch '2.7':
    bpo-15575: Clarify tutorial description of when modules are executed.
    http://hg.python.org/cpython/rev/a1421d28393b

    @bitdancer
    Copy link
    Member

    Thanks, James. I wound up going with a different wording for the "elaboration": since the concept of running a python file as a script is mentioned just a bit earlier, I added a parenthetical that the statements are also executed if the module is run as a script.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir easy type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants