LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-18-2011, 02:12 PM   #1
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Rep: Reputation: 16
Python Import Question


I'm after importing by reference, is there any way to do it?

Say, something like this?
Code:
items=['one','two','three']
for e in items:
	import e

Cheers!
 
Old 04-18-2011, 03:12 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Try
Code:
items = ['one','two','three']
for e in items:
    exec "import "+e
 
1 members found this post helpful.
Old 04-19-2011, 06:39 AM   #3
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Original Poster
Rep: Reputation: 16
Cheers Snark, it works, but not in my instance... It turns out it's been restricted...
 
Old 04-19-2011, 07:24 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Can you use importlib.import_module?
 
Old 04-19-2011, 07:27 AM   #5
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Original Poster
Rep: Reputation: 16
Just on my way back...

This works!

Code:
b= __import__("blob.blobby")
b.blobby.test()
 
Old 04-19-2011, 08:20 AM   #6
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Original Poster
Rep: Reputation: 16
This thread may also be of help...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python error , import numpy ufmale Programming 2 08-25-2008 11:59 PM
How do I import Tkinter into Python mugglemage Linux - Software 5 07-02-2008 08:47 AM
Python: how to import a python file that doesn't end in .py? BrianK Programming 5 04-15-2008 12:35 PM
python, import and execfile() cs-cam Programming 1 10-18-2005 08:47 PM
Python - can I import my own stuff? miknight Programming 1 06-10-2003 07:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration