LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 05-14-2014, 02:45 AM   #1
fantasy1215
Member
 
Registered: Oct 2011
Posts: 75

Rep: Reputation: Disabled
Pure python code how do I dynamic load a method from different modules(files)?


Hope I can express it clearly with my English, I have a pure python multithreaded socket server code, and each thread dealing with a connection.
The socket server code receive a string as filename,
Question: the filename received vary and we assume the file do exist, these files all have the same entrance magic_main method, the server code need to load the magic_main from filenameA or filenameB according the received filename, How can I achive this?
Thanks in advance!
 
Old 05-14-2014, 09:18 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,219

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
If you're using Python 2.7 or later:

https://docs.python.org/2/library/im....import_module

If not:

https://docs.python.org/2/library/fu...tml#__import__
 
  


Reply



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
TSM-backup files with management class with the serialization dynamic/shared dynamic Rohit_4739 Linux - Software 1 01-18-2013 01:43 PM
[SOLVED] Python OOP - Class and code in seperate files, not working madsovenielsen Programming 1 08-25-2010 11:56 AM
python forcing zip import of dynamic modules Karimo Programming 1 04-18-2009 10:21 PM
python update - Unable to load GTK2 Python bindings: No module named gtk itpedersen Linux - Software 2 10-03-2008 03:44 AM
FATAL: Could not load /lib/modules/2.6.14-default/modules.dep no such file exist dr_zayus69 Linux - Software 3 12-26-2005 06:44 PM

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

All times are GMT -5. The time now is 04:22 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