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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:27:28+00:00 2026-05-27T17:27:28+00:00

I have a simple function I want to call in two separate program executions.

  • 0

I have a simple function I want to call in two separate program executions. The first time I run the program it saves the function pointer into a file:

import cPickle

def test():
    pass

def main():
    a = test
    pFile = open('test.txt', 'wb')
    cPickle.dump(a, pFile)
    pFile.close()

The second time I want to load the file and execute the function saved in the object:

import cPickle

def test():
    pass

def main():
    pFile = open('test.txt', 'rb')
    a = cPickle.load(pFile)
    pFile.close()
    a() 

Note that with cPickle, this works, which is a bit odd, since I figured this is basically a pointer to the function and that this would change at runtime? When I print ‘a’, it gives me something like :function test at 0x0351C170:.

So I guess my first question is, why does this work, even though the reference address should change at runtime?

And my second question would be, if it does not change/or it’s irrelevant somehow, how can I execute the function just from having the string: :function test at 0x0351C170:. e.g. something like:

def test():
    print 'test'

a = test
a()          #outputs: 'test'

b = str(a)   #<function test at 0x03509170>
eval(b)()    #error
  • 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-27T17:27:29+00:00Added an answer on May 27, 2026 at 5:27 pm

    See the pickle documentation:

    The following types can be pickled:

    • None, True, and False
    • integers, long integers, floating point numbers, complex numbers
    • normal and Unicode strings
    • tuples, lists, sets, and dictionaries containing only picklable objects
    • functions defined at the top level of a module
    • built-in functions defined at the top level of a module
    • classes that are defined at the top level of a module
    • instances of such classes whose __dict__ or __setstate__() is picklable (see section The pickle protocol for details)

    So the pickle module actually writes out the Python bytecode in the pickle file. When the pickle file is reloaded, the function is recreated from the code object.

    To answer the second part of your question, no, it is not possible to directly call Python code just by knowing the internal address value.

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

Sidebar

Related Questions

I have a simple function that I want to call in the code behind
I have a Windows Form and a class with two simple methods that run
I have JavaScript function call to changeMapLocation function where in it I want to
I have a simple function in which an array is declared with size depending
I have a simple function written in Oracle 9i (version 9.2.0.4.0) to simulate an
I have a simple function to open an editor: open_an_editor() { nano $1 }
I have a simple function that returns an NSString after decoding it. I use
I have this simple function: <script type=text/javascript> //<![CDATA[ jQuery(function($){ function here(b){alert(b);} ; here(6); });
I have a simple function which takes an array of characters as an argument,
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>

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.