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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:34:14+00:00 2026-05-14T20:34:14+00:00

zjm_code |—–a.py |—–a |—– __init__.py |—–b.py in a.py is : c=’ccc’ in b.py is

  • 0
zjm_code
    |-----a.py
    |-----a
          |----- __init__.py
    |-----b.py

in a.py is :

c='ccc'

in b.py is :

import a

print dir(a)

when i execute b.py ,it show (it import ‘a’ folder):

['__builtins__', '__doc__', '__file__', '__name__', '__path__']

and when i delete a folder, it show ,(it import a.py):

['__builtins__', '__doc__', '__file__', '__name__', 'c']

so my question is :

how to import a.py via not delete a folder

thanks

updated

i use imp.load_source, so in b.py is :

import imp,os
path = os.path.join(os.path.dirname(__file__), os.path.join('aaa.py'))
ok=imp.load_source('*',path)
print ok.c

it is ok now ,and print ‘ccc’

and

how to show ‘ccc’ via “print c” not via “print ok.c” ???

thanks

updated2

it is ok now :

imp.load_source('anyname',path)

from anyname import *
print c

it show ‘ccc’

updated3

it is also ok:

import imp,os
imp.load_source('anyname','aaa.py')
from anyname import *
print c
  • 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-14T20:34:15+00:00Added an answer on May 14, 2026 at 8:34 pm

    Use imp.load_module – there you can specify the file directory, overriding the behaviour of import.

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

Sidebar

Related Questions

import sys print sys.path ['D:\\zjm_code\\register2', 'C:\\WINDOWS\\system32\\python25.zip', 'D:\\Python25\\DLLs', 'D:\\Python25\\lib', 'D:\\Python25\\lib\\plat-win', 'D:\\Python25\\lib\\lib-tk', 'D:\\Python25', 'D:\\Python25\\lib\\site-packages'] and #from
import sys print sys.path sys.path+=['D:\\zjm_code'] print sys.path it can't be save,how does do it.
print : D:\zjm_code\register2>python D:\Python25\Lib\site-packages\django\bin\django-adm in.py makemessages -l cn Error: This script should be run
My code is: print os.urandom(64) which outputs: > D:\Python25\pythonw.exe D:\zjm_code\a.py \xd0\xc8=<\xdbD' \xdf\xf0\xb3>\xfc\xf2\x99\x93 =S\xb2\xcd'\xdbD\x8d\xd0\\xbc{&YkD[\xdd\x8b\xbd\x82\x9e\xad\xd5\x90\x90\xdcD9\xbf9.\xeb\x9b>\xef#n\x84 which
import MySQLdb and traceback: Traceback (most recent call last): File D:\zjm_code\sphinx_test\a.py, line 1, in
print u'\xe4\xf6\xfc'.encode('utf-8') print unicode(u'\xe4\xf6\xfc') traceback: 盲枚眉 Traceback (most recent call last): File D:\zjm_code\a.py, line
a='1234;5' print a.index('s') the error is : > D:\Python25\pythonw.exe D:\zjm_code\kml\a.py Traceback (most recent call
D:\zjm_code\basic_project>python manage.py syncdb Error: One or more models did not validate: topics.topic: Accessor for
This is my code: print '哈哈'.decode('gb2312').encode('utf-8') ...and it prints: SyntaxError: Non-ASCII character '\xe5' in

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.