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 func.py
-Than i created new file and i wrote
from func import multiplication
multiplication(10,12)

-Than i saved it test.py and when i try to run test.py 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...
IYI_Osmancik
 
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 func.py is somewhere in your PYTHONPATH (basically, stick into C:\Python27\Lib\site-packages). Also, please use [code] tags when posting code.
setrofim
 
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:
IYI_Osmancik
 
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 my_func.py.

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

Test:
Code: Select all
>>> from my_func import multiplication
>>> multiplication(5, 10)
50
User avatar
snippsat
 
Posts: 124
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 irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 721
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