Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36658
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <129km09@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| 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; 'explanation': 0.09; 'friday,': 0.09; 'imported': 0.09; 'instantiated': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; '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; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; '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; '11,': 0.33; 'conventions': 0.33; 'stands': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'clear': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'next': 0.35; 'but': 0.36; 'cc:no real name:2**1': 0.36; 'modules': 0.36; 'subject:with': 0.36; 'should': 0.36; 'keeps': 0.37; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'received:209.85.214': 0.39; 'called': 0.39; 'where': 0.40; 'your': 0.60; 'matter': 0.61; 'identify': 0.61; 'solve': 0.62; 'here': 0.65; 'circle': 0.65; '100': 0.78; '2013': 0.84; 'circle,': 0.84; 'saying:': 0.84; 'mistakenly': 0.91; 'angel': 0.93; 'have.': 0.95 |
| 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 |
| References | <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> <mailman.419.1357944212.2939.python-list@python.org> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-IP | 98.217.186.206 |
| MIME-Version | 1.0 |
| Subject | Re: Problem with importing in Python |
| From | su29090 <129km09@gmail.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Cc | python-list@python.org, d@davea.name |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.422.1357946607.2939.python-list@python.org> (permalink) |
| Lines | 174 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1357946607 news.xs4all.nl 6842 [2001:888:2000:d::a6]:34429 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:36658 |
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