Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 569027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:15:03+00:00 2026-05-13T13:15:03+00:00

As a hobby/learning project, I’m writing a parser generator in Python. One of my

  • 0

As a hobby/learning project, I’m writing a parser generator in Python. One of my code files is named “token.py” – which contains a couple of classes for turning plain strings into Token objects. I’ve just discovered that using the “help()” function from the console in Python raises an error for any module defined in a directory that contains a “token.py”.

Here’s a way to reproduce the error. Create a new directory with the following files:

/New Folder
  main.py
  token.py

Leave ‘token.py’ blank. In main.py, write a simple function – for example:

def test():
    pass

Then, in your Python console, import ‘main’ and call ‘help(main.test)’ – here’s what you’ll get:

C:\New Folder>python
Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import main
>>> help(main.test)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python31\lib\site.py", line 428, in __call__
    import pydoc
  File "C:\Python31\lib\pydoc.py", line 55, in <module>
    import sys, imp, os, re, inspect, builtins, pkgutil
  File "C:\Python31\lib\inspect.py", line 40, in <module>
    import tokenize
  File "C:\Python31\lib\tokenize.py", line 37, in <module>
    COMMENT = N_TOKENS
NameError: name 'N_TOKENS' is not defined
>>>

If you delete the ‘token.py’ file, help() will behave normally. Both Python 3.1 and Python 2.5 exhibit this behavior.

Is this a known issue? If not, how do I report it?

EDIT:

Several comments state that this behavior isn’t a bug. The module that defines “help” imports a module called “token” from Python’s standard library. However, Python looks in the application folder before it looks in its library to find modules. In the example above, “help” tries to use my “token.py” instead of Python’s, which causes the error.

Since Python is defined to exhibit this behavior, I suppose it isn’t a bug. But why do people think that this behavior is acceptable? It implies that adding new modules to Python’s library – even without changing existing modules – could break existing applications. It also implies that programmers are expected to have memorized the names of all modules in Python’s library – how is that any less ridiculous than expecting programmers to memorize every namespace in .NET or Java? Why don’t Python applications get their own namespaces? Why aren’t Python standard library modules in their own namespace?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:15:04+00:00Added an answer on May 13, 2026 at 1:15 pm

    The problem is that your local token.py is being imported by help() instead of Python’s actual token.py. This will occur for any number of .py files whose names collide with built-in modules. For example, try creating a pydoc.py file in the CWD and then try help() in Python. The help() function is just a built-in Python function, so it follows the same import path as any other Python code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 456k
  • Answers 456k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well, I found out how to do it, so if… May 15, 2026 at 10:27 pm
  • Editorial Team
    Editorial Team added an answer On the back end, you will definitely want to run… May 15, 2026 at 10:27 pm
  • Editorial Team
    Editorial Team added an answer Yup. If I'm not mistaken, it should do this automatically,… May 15, 2026 at 10:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.