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 1078327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:42:25+00:00 2026-05-16T21:42:25+00:00

I have been trying to learn Python for a while now. By chance, I

  • 0

I have been trying to learn Python for a while now. By chance, I happened across chapter 6 of the official tutorial through a Google search link pointing
here.
When I learned, from that page, that functions were the heart of modules, and that modules could be called from the command line, I was all ears. Here’s my first attempt at doing both, openbook.py

import nltk, re, pprint
from __future__ import division

def openbook(book):
    file = open(book)
    raw = file.read()
    tokens = nltk.wordpunct_tokenize(raw)
    text = nltk.Text(tokens)
    words = [w.lower() for w in text]
    vocab = sorted(set(words))
    return vocab
if __name__ == "__main__":
    import sys
    openbook(file(sys.argv[1]))

What I want is for this function to be importable as the module openbook, as well as for openbook.py to take a file from the command line and do all of those things to it.

When I run openbook.py from the command line, this happens:

gemeni@a:~/Projects-FinnegansWake$ python openbook.py vicocyclometer
Traceback (most recent call last):
  File "openbook.py", line 23, in <module>
    openbook(file(sys.argv[1]))
  File "openbook.py", line 5, in openbook
    file = open(book)

When I try using it as a module, this happens:

>>> import openbook
>>> openbook('vicocyclometer')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable

So, what can I do to fix this, and hopefully continue down the long winding path to enlightenment?

  • 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-16T21:42:26+00:00Added an answer on May 16, 2026 at 9:42 pm

    Error executing openbook.py

    For the first error, you are opening the file twice:

    openbook(file(sys.argv[1]))
    ph0 = open(book)
    

    Calling both file() and open() is redundant. They both do the same thing. Pick one or the other: preferably open().

    open(…)

    open(name[, mode[, buffering]]) → file object

    Open a file using the file() type, returns a file object. This is the
    preferred way to open a file.

    Error importing openbook module

    For the second error, you need to add the module name:

    >>> import openbook
    >>> openbook.openbook('vicocyclometer')
    

    Or import the openbook() function into the global namespace:

    >>> from openbook import openbook
    >>> openbook('vicocyclometer')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to learn python over the last couple of months and
I have been trying to learn assembly for a few years now. I get
I have been using PHP for a while, but now I am trying to
I've been trying to learn python recently, and ran across something that I'm having
I have been trying to learn Prolog and came across this syntax on some
I have a question. I have been really trying to learn Python. For a
I have been trying to learn a bit more about delegates and lambdas while
i have been trying to learn PHP Repeat Region... i have searched google but
I have been trying to learn how to use sys.argv properly, while calling an
I have been trying to learn how to build jQuery plugins, so I'm still

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.