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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:36:24+00:00 2026-05-17T00:36:24+00:00

I have a trusted remote server that stores many custom Python modules. I can

  • 0

I have a trusted remote server that stores many custom Python modules. I can fetch them via HTTP (e.g. using urllib2.urlopen) as text/plain, but I cannot save the fetched module code to the local hard disk. How can I import the code as a fully operable Python module, including its global variables and imports?
I suppose I have to use some combination of exec and imp module’s functions, but I’ve been unable to make it work yet.

  • 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-17T00:36:25+00:00Added an answer on May 17, 2026 at 12:36 am

    It looks like this should do the trick: importing a dynamically generated module

    >>> import imp
    >>> foo = imp.new_module("foo")
    >>> foo_code = """
    ... class Foo:
    ...     pass
    ... """
    >>> exec foo_code in foo.__dict__
    >>> foo.Foo.__module__
    'foo'
    >>>
    

    Also, as suggested in the ActiveState article, you might want to add your new module to sys.modules:

    >>> import sys
    >>> sys.modules["foo"] = foo
    >>> from foo import Foo
    <class 'Foo' …>
    >>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assembly and want to restrict the assemblies and applications that can
I have an application that uses a database on SQL Server and I want
I have a java application that needs to connect to a server. Its rather
I have both VS2008 and VS2010 Setup projects that create .MSI files. On server
For example, I have a trusted client and a server. The client wants to
first I have checked that Server Authentication is already set to: SQL server and
I've created a Winform that connects to SQL Server Express x64 using Trusted Connection
I have a Silverlight app that needs low-level socket support. It's an Out-of-Browser Trusted
I have an application that needs to support a small set of trusted users
I have obtained a certificate by a trusted authority (have been given a .pfx

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.