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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:04:37+00:00 2026-05-28T20:04:37+00:00

Something weird… I was working on importing files from different folders.. and was working

  • 0

Something weird…
I was working on importing files from different folders..
and was working on python ide..

so my ide code:

>>> import os
>>> os.chdir("..")
>>> os.chdir("lib")
>>> os.chdir("native")
>>> os.getcwd()
'/.../.../Programming/lib/native'
>>> from category import *

works great..
but exactly same on my python file:

import os
import sys
#get current working directory
cur_dir = os.getcwd()
#move up one level
os.chdir("..")
new_cur_dir = os.getcwd()
print new_cur_dir
#move down to native
try:
 os.chdir("lib")
 print os.getcwd()
except IOError as e:
    sys.exit("Exitting: 'lib' folder missing!!")

try:
os.chdir("native")
print os.getcwd()
from category import *
from pilottest import *
from datainstance import *
from similar import *
from collections import defaultdict
from item import *
from pilottest import *
from infernumber import *

except IOError as e:
          sys.exit("Exitting: 'native' folder missing!!")

Error:

/../../Programming
/../../Programming/lib
/../../Programminglib/native
Traceback (most recent call last):
 File "foo.py", line 25, in <module>
  from category import *
ImportError: No module named category
  • 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-28T20:04:38+00:00Added an answer on May 28, 2026 at 8:04 pm

    When running code in the interpreter, the first entry of sys.path is an empty string, which indicates the current directory. However, when you run code from a file the first entry of sys.path is a fully qualified path of the directory that you ran the script from.

    This means that when you change directories in the interpreter you can always do imports from your current directory, but the same is not true for running from files.

    If you want to always be able to import from the current directory in your scripts add the following lines to the top of your files:

    import sys
    sys.path.insert(0, '')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Something really weird is going on with Xcode and an iPhone project I'm working
I just found something weird in the Python interpreter. Let me show you: $
I saw something weird, from the point that was not what I was expecting.
I just ran into something weird. I have two JSON arrays which holds different
I am working on a WCF SOAP service, and I noticed something weird. I
I'm working with parsing custom attributes, and I've come across something weird. Let's say
I've been working on my richtextbox but I ran into something weird... I want
I'm currently working with a library and noticed something weird when using functions I
There is something weird going on in my code so i have to ask.
When installing django-piston from the bitbucket repo with pip, I noticed something weird (first

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.