Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36657
| X-Received | by 10.224.178.204 with SMTP id bn12mr15854216qab.1.1357946597791; Fri, 11 Jan 2013 15:23:17 -0800 (PST) |
|---|---|
| Received | by 10.49.58.140 with SMTP id r12mr14447421qeq.35.1357946597745; Fri, 11 Jan 2013 15:23:17 -0800 (PST) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!p13no1098969qai.0!news-out.google.com!k2ni225qap.0!nntp.google.com!p13no1098968qai.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Fri, 11 Jan 2013 15:23:17 -0800 (PST) |
| In-Reply-To | <mailman.419.1357944212.2939.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=98.217.186.206; posting-account=w-5w_goAAADUIOLQGYHG22ns_QlDow8P |
| NNTP-Posting-Host | 98.217.186.206 |
| References | <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> <mailman.419.1357944212.2939.python-list@python.org> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <c9bdfe7f-e95d-400a-8e72-068cfad10aad@googlegroups.com> (permalink) |
| Subject | Re: Problem with importing in Python |
| From | su29090 <129km09@gmail.com> |
| Cc | python-list@python.org, d@davea.name |
| Injection-Date | Fri, 11 Jan 2013 23:23:17 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:36657 |
Show key headers only | View raw
On Friday, January 11, 2013 5:43:10 PM UTC-5, Dave Angel wrote:
> 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
Thanks for explanation which was very clear!
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Problem with importing in Python su29090 <129km09@gmail.com> - 2013-01-11 14:17 -0800
Re: Problem with importing in Python Adnan Sadzak <sadzak@gmail.com> - 2013-01-11 23:25 +0100
Re: Problem with importing in Python su29090 <129km09@gmail.com> - 2013-01-11 14:29 -0800
Re: Problem with importing in Python su29090 <129km09@gmail.com> - 2013-01-11 14:29 -0800
Re: Problem with importing in Python Chris Angelico <rosuav@gmail.com> - 2013-01-12 09:27 +1100
Re: Problem with importing in Python su29090 <129km09@gmail.com> - 2013-01-11 14:38 -0800
Re: Problem with importing in Python su29090 <129km09@gmail.com> - 2013-01-11 14:38 -0800
Re: Problem with importing in Python Dave Angel <d@davea.name> - 2013-01-11 17:43 -0500
Re: Problem with importing in Python su29090 <129km09@gmail.com> - 2013-01-11 15:23 -0800
Re: Problem with importing in Python su29090 <129km09@gmail.com> - 2013-01-11 15:23 -0800
Re: Problem with importing in Python Tim Roberts <timr@probo.com> - 2013-01-11 20:37 -0800
Re: Problem with importing in Python Chris Angelico <rosuav@gmail.com> - 2013-01-12 15:54 +1100
Re: Problem with importing in Python Dave Angel <d@davea.name> - 2013-01-12 00:14 -0500
Re: Problem with importing in Python Terry Reedy <tjreedy@udel.edu> - 2013-01-11 22:53 -0500
csiph-web