Import Function Error

A forum for general discussion of the Python programming language.

Import Function Error

Postby IYI_Osmancik » Fri May 17, 2013 4:49 pm

Hi all.I'm new at forum and im newbie python user. I use IDLE 2.7.4 in windows and i have an error.I hope you can help me.Thanks for your patience.
-I defined function whose name is "multiplication"
def multiplication(a,b):
print a*b
-And i save it
-Than i created new file and i wrote
from func import multiplication

-Than i saved it and when i try to run it gives me that error.

Traceback (most recent call last):
File "C:/Python27/test", line 1, in <module>
from func import carpma
ImportError: No module named func

-How can i solve this.And thank a lot for your help...
Posts: 2
Joined: Fri May 17, 2013 4:39 pm

Re: Import Function Error

Postby setrofim » Fri May 17, 2013 5:48 pm

Make sure that either the two files are in the same directory, or that is somewhere in your PYTHONPATH (basically, stick into C:\Python27\Lib\site-packages). Also, please use [code] tags when posting code.
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: Import Function Error

Postby IYI_Osmancik » Sat May 18, 2013 7:19 pm

Yeah they are at same directory (C:\Python27). And not working... :roll:
Posts: 2
Joined: Fri May 17, 2013 4:39 pm

Re: Import Function Error

Postby snippsat » Sat May 18, 2013 9:49 pm

Make sure that there is no name conflict,call it

Saved to python27 folder.
Code: Select all
def multiplication(a, b):
    return a * b

Code: Select all
>>> from my_func import multiplication
>>> multiplication(5, 10)
User avatar
Posts: 705
Joined: Thu Feb 21, 2013 12:04 am

Re: Import Function Error

Postby Yoriz » Sat May 18, 2013 10:52 pm

Looks like you are definatly importing a differant file as your error is in the line
Code: Select all
from func import carpma

but your code doesnt mention anything about defining carpma.
New Users, Read This
Join the #python-forum IRC channel on!
User avatar
Posts: 1459
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Return to General Discussions

Who is online

Users browsing this forum: No registered users and 2 guests