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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:09:17+00:00 2026-05-23T12:09:17+00:00

Question: is it possible to reverse engineer python objects into a string? Info: I’m

  • 0

Question: is it possible to reverse engineer python objects into a string?


Info: I’m working on a project right now that distributes my prof’s research across several dozen computers instead of just his. Being a good programmer I’m making it a generalized program that can be used for more than just his specific program. So the computers that will be running his code do not and will not have his .py files for them to import. The way I’ve gotten around this in the past is he just has to have everything in one file and pass the path to that file to my system which then imports that code as a from its state as a string (using the information gleaned from this question).

But that made me wonder. I can now import from a string and have the code execute fine and dandy. thats all well and good, but it made me think, is there a way for me to get around having to have him pass his code file to me? particularly I’m wondering something like this. say he has all of this in his file:

def hello():
    print "Hello world!"

upon importing this file “hello” would be added to the global namespace. but now I want to transfer it across the network. you can’t call pickle on “hello” and have it work, I’ve tried, pickle out right refuses.

on the other end I have the node computers using “exec code in newMod.dict” to get the code created. so if I could take “hello” and push it through some function that returns to me “def hello():\n print \”Hello world!\”” so that my exec method could then run. I would be golden. I could then make it so he could have more than just 1 file because I could just reverse engineer any non-standard imports he has.

I’m honestly expecting the answer to be no, but i figured it is worth a shot. Simply stated again, I want to take an module that has been imported and convert it into a string.

  • 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-23T12:09:18+00:00Added an answer on May 23, 2026 at 12:09 pm

    Although it’s not a good approach, you can pickle only the __code__ from the function…

    >>> def foo():
    ...     print "Hello"
    
    >>> import pickle
    >>> code = pickle.dumps(foo.__code__)
    >>> def bar():
    ...     pass
    
    >>> bar()
    >>> bar.__code__ = pickle.loads(code)
    >>> bar()
    Hello
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application shows a question and possible answers on that question. Now I want
Question: Is it possible to construct a web page that has a script to
Question So I've recently came up with some new possible projects that would have
Here is my question, Would it be possible, knowing that classic asp support server-side
In the context of this question link text is possible from a Controller that
Over in this question, Scott writes that it is possible to get the current
A very popular question is how to reverse a C-Style string. The C-Style string
Possible Duplicate: How to reverse a string in place in c using pointers? The
Right now my products model has a string column of category, with the form
It's quite possible a question like this has been asked before, but I can't

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.