How to call a function defined in another py file

Jeremy Gransden jeremy at gransdenonline.com
Mon Feb 19 15:43:19 EST 2007


On Feb 19, 2007, at 3:27 PM, silverburgh.meryl at gmail.com wrote:

> On Feb 19, 2:22 pm, "Martin Blume" <mbl... at socha.net> wrote:
>> <silverburgh.me... at gmail.com> schrieb
>>
>>> I have a function called 'test' defined in A.py.
>>> How can I call that function test in my another file B.py?
>>
>> In B.py:
>>
>> import A
>>
>> A.test()
>>
>> HTH
>> Martin
>
> But Do I need to put A.py and B.py in the same directory?
> if not, where does python look for A.py ?
No, they do not have to be in the same directory. A.py needs to be in  
your path.

> And do I need to compile A.py before I can import it to B.py?

No




jeremy





More information about the Python-list mailing list