0

I am using Python 2.7 from the Anaconda distro. I am trying to organize a complex data integration process into different classes and functions so I can better manage it.

As a simplified example, I have some part of my process in a file called function_test.py

import pandas as pd
import numpy as np

class Perform:
    def work(self):
        test_df = pd.DataFrame(np.random.randn(10,4), columns=['a','b','c','d'])
        print "really?"
        print test_df

I want to call and execute the above logic from function_call.py which is in the same directory:

import function_test

perform = function_test.Perform
perform.work

However, when I execute function_call.py I get the following message and nothing is printed.

UMD has deleted: function_test

How do I set this example up so function_test is imported and executed so test_df is available from within function_call.py?

Any advice is appreciated.

2 Answers 2

1

First of, don't use old-style classes like so:

class Perform:
    pass

Use new-style classes:

class Perform(object):
    pass

Next, you should remember - work is a method of the class Perform. So you should instantiate it first:

perform = function_test.Perform()
perform.work()

Does it work now?

Sign up to request clarification or add additional context in comments.

2 Comments

It does execute and prints from inside function_test.py. How do I make the test_df available in function_call.py? I added print test_df.dtypes and I get a 'test_df' is not defined error.
You can return it from function: return test_df and use: test_df = perform.work()
1

add brackets.

perform = function_test.Perform()
perform.work()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.