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

  • SEARCH
  • Home
  • 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 7411929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:27:45+00:00 2026-05-29T06:27:45+00:00

Basically there is a file called 8puzzle.py and I want to import the file

  • 0

Basically there is a file called 8puzzle.py and I want to import the file into another file (in the same folder and I cannot change the file name as the file is provided). Is there anyway to do this in Python? I tried usual way from 8puzzle import *, it gives me an error.

Error is:

>>> import 8puzzle
  File "<input>", line 1
    import 8puzzle
           ^
SyntaxError: invalid syntax
>>> 
  • 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-29T06:27:46+00:00Added an answer on May 29, 2026 at 6:27 am

    You could do

    puzzle = __import__('8puzzle')
    

    Very interesting problem. I’ll remember not to name anything with a number.

    If you’d like to import * — you should check out this question and answer.

    12 years later…

    See answer below (use importlib.import_module from Python 3.1) for interoperability and understandability.

    https://docs.python.org/3/library/importlib.html#importlib.import_module

    This provides an implementation of import which is portable to any
    Python interpreter. This also provides an implementation which is
    easier to comprehend than one implemented in a programming language
    other than Python.

    ….

    The import_module() function acts as a simplifying wrapper around
    importlib.__import__(). This means all semantics of the function are
    derived from importlib.__import__(). The most important difference
    between these two functions is that import_module() returns the
    specified package or module (e.g. pkg.mod), while __import__() returns
    the top-level package or module (e.g. pkg).

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

Sidebar

Related Questions

I just want to design this very simple website. Basically there are multiple pages
Is there any name for the following DB table design: Basically we have generic
Basically there are two Kinect devices. One for the Xbox and one for the
here is the code: http://jsfiddle.net/duNHJ/2/ Basically there is an animations every div so when
I have some localization problems in my webpage. There are basically two problems (that
Basically I have two 2D points and there is a line between them. A
I basically need to check if there is an easier way to do this
so basically like the title says is there a way to use NSSortDescriptor to
Is there an equivalent of __DATE__ and __TIME__ in C#? Basically what I'm trying
Is there any jquery plugin for implementing iGoogle style dashboard? So basically drag n

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.