Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'importerror:': 0.05; 'class,': 0.07; 'main()': 0.07; 'problem?': 0.07; 'python': 0.09; 'assumed': 0.09; 'called.': 0.09; 'imported': 0.09; 'instantiated': 0.09; 'def': 0.10; 'itself.': 0.11; 'advance.': 0.15; '"is"': 0.16; '#create': 0.16; '1):': 0.16; 'accidental': 0.16; 'called,': 0.16; 'ends,': 0.16; 'main().': 0.16; 'main():': 0.16; 'presume': 0.16; 'subject:Problem': 0.16; 'wrote:': 0.17; 'pointed': 0.17; 'specify': 0.17; 'version.': 0.17; 'module': 0.19; 'math': 0.20; 'trying': 0.21; 'import': 0.21; 'questions:': 0.22; 'defined': 0.22; 'second': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; '(see': 0.27; "doesn't": 0.28; 'indentation': 0.29; 'starts': 0.29; 'skip:_ 10': 0.29; 'source': 0.29; 'probably': 0.29; 'class': 0.29; "i'm": 0.29; 'classes': 0.30; 'function': 0.30; 'error': 0.30; 'asking': 0.32; 'file': 0.32; 'comments': 0.33; 'conventions': 0.33; 'stands': 0.33; 'to:addr :python-list': 0.33; 'thanks': 0.34; 'clear': 0.35; 'pm,': 0.35; 'there': 0.35; 'next': 0.35; 'but': 0.36; 'modules': 0.36; 'subject:with': 0.36; 'should': 0.36; 'keeps': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'called': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'your': 0.60; 'matter': 0.61; 'identify': 0.61; 'solve': 0.62; 'here': 0.65; 'circle': 0.65; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply- to:no real name:2**0': 0.72; '100': 0.78; 'circle,': 0.84; 'received:74.208.4.194': 0.84; 'saying:': 0.84; 'mistakenly': 0.91; 'have.': 0.95 Date: Fri, 11 Jan 2013 17:43:10 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Problem with importing in Python References: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> In-Reply-To: <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:sMfhYPXfyfHjM2DHWIN+n/7d8/oq0iI1dowAUnRBEvF ts666n9X/3GZ392gZruwUlPDf/XVkxUWbmoMCz874ihsYPyztX W4lz8aK3UM9fgfGQVUG3hf/8JTdJkkR1Oye0HL5i2y9OdmbsV4 L0wnYTtqkzXVVDodZsqx3AIUC7JBCRjcEjCE+Y5yQEGxNC9Ubr 3FuvmrFv3uyrQa8ZSqql4Z9JIxJi9gedfDxYI69bmRaFeQsgd3 F9TfFUOX+sBIAkVl0NpGoFb1e9c7uQVPiP6wW79FFiPbYMtyl/ NCH/XlzPGda9RNeQJcAvOTVgBklhCC+IibvhB3SbYFY19fXkw= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: d@davea.name List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 87 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357944212 news.xs4all.nl 6864 [2001:888:2000:d::a6]:39698 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36654 On 01/11/2013 05:17 PM, su29090 wrote: > I'm trying to import a python file it keeps saying: > > ImportError: cannot import name Circle > > Here is the file I'm trying to import: > > Circle.py > > import math > > class circle: > #Construct a circle object > def __init__(self, radius = 1): > self.radius = radius > > def getPerimeter(self): > return 2 * self.radius * math.pi > > def getArea(self): > return self.radius * self.radius * math.pi > > def setRadius(self, radius): > self.radius = radius > > from Circle import Circle > > def main(): > #Create a circle with a radius 1 > circle1 = Circle() > print("The area of the circle of radius", > circle1.radius, "is" , circle1.getArea()) > > #Create a circle with a radius 25 > circle2 = Circle(25) > print("The area of the circle of radius", > circle2.radius, "is" , circle2.getArea()) > > #Create a circle with a radius 125 > circle3 = Circle(125) > print("The area of the circle of radius", > circle3.radius, "is" , circle3.getArea()) > > #Modify circle radius > circle2.radius = 100 # or Circle2.setRadius(100) > print("The area of the circle of radius", > circle2.radius, "is" , circle2.getArea()) > > main() # Call the main function > > How can I solve this problem? > > Thanks in advance. > As Adnan has pointed out, Python is case insensitive. You're apparently trying to refer to the class Circle by the name circle, or the other way around. Some comments on asking clear questions: 1) Specify the Python version. I presume 3.3 It probably doesn't matter here, but it might have. 2) When showing two source files, identify where each starts and ends, and what the second one is called. 3) When showing an error, include the entire traceback, not just the last line. Now, there are conventions to follow as well (see Pep8). One is that modules should use all lowercase, and classes should begin with a capital. So the source file of your module should be named circle.py and the class Circle. When you imported and instantiated the class, you assumed it was called Circle, but when you defined it, you mistakenly called it circle. The next error is the accidental indentation of the call to main(). As it stands now, it's a recursive call to itself. And main() will never be called, because there's no call at top-level. -- DaveA