Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36646 > unrolled thread
| Started by | su29090 <129km09@gmail.com> |
|---|---|
| First post | 2013-01-11 14:17 -0800 |
| Last post | 2013-01-11 22:53 -0500 |
| Articles | 14 — 6 participants |
Back to article view | Back to comp.lang.python
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
| From | su29090 <129km09@gmail.com> |
|---|---|
| Date | 2013-01-11 14:17 -0800 |
| Subject | Problem with importing in Python |
| Message-ID | <1eb7cd76-ade3-4c34-8816-6eaa7201262e@googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | Adnan Sadzak <sadzak@gmail.com> |
|---|---|
| Date | 2013-01-11 23:25 +0100 |
| Message-ID | <mailman.415.1357943131.2939.python-list@python.org> |
| In reply to | #36646 |
[Multipart message — attachments visible in raw view] — view raw
Python is case sensitive.
Circle and circle is not same.
/* sent from android */
On Jan 11, 2013 11:22 PM, "su29090" <129km09@gmail.com> 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.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
[toc] | [prev] | [next] | [standalone]
| From | su29090 <129km09@gmail.com> |
|---|---|
| Date | 2013-01-11 14:29 -0800 |
| Message-ID | <955b94c4-4916-4fb6-9917-5652ff88f6d4@googlegroups.com> |
| In reply to | #36648 |
On Friday, January 11, 2013 5:25:24 PM UTC-5, Adnan Sadzak wrote:
> Python is case sensitive.
>
> Circle and circle is not same.
>
>
>
>
>
>
> /* sent from android */
>
> On Jan 11, 2013 11:22 PM, "su29090" <129...@gmail.com> 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.
>
>
>
> --
>
> http://mail.python.org/mailman/listinfo/python-list
It still keeps showing the same message.
[toc] | [prev] | [next] | [standalone]
| From | su29090 <129km09@gmail.com> |
|---|---|
| Date | 2013-01-11 14:29 -0800 |
| Message-ID | <mailman.421.1357946170.2939.python-list@python.org> |
| In reply to | #36648 |
On Friday, January 11, 2013 5:25:24 PM UTC-5, Adnan Sadzak wrote:
> Python is case sensitive.
>
> Circle and circle is not same.
>
>
>
>
>
>
> /* sent from android */
>
> On Jan 11, 2013 11:22 PM, "su29090" <129...@gmail.com> 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.
>
>
>
> --
>
> http://mail.python.org/mailman/listinfo/python-list
It still keeps showing the same message.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-01-12 09:27 +1100 |
| Message-ID | <mailman.416.1357943251.2939.python-list@python.org> |
| In reply to | #36646 |
On Sat, Jan 12, 2013 at 9:17 AM, su29090 <129km09@gmail.com> wrote: > Circle.py > > class circle: > > from Circle import Circle Inside the Circle module is a class named circle. You can't import Circle from that. But Python isn't Java. You don't have to put each class into its own file. Just put class circle (or class Circle to follow Python naming convention) into the other file, whose name you haven't given. If they're already in the same file, then just drop the import. Easy! By the way: > main() # Call the main function You'll need to put that flush left. At the moment, that call is part of the definition of main(). Hope that helps! ChrisA
[toc] | [prev] | [next] | [standalone]
| From | su29090 <129km09@gmail.com> |
|---|---|
| Date | 2013-01-11 14:38 -0800 |
| Message-ID | <dc0fe049-c8a3-4ccb-a501-9fadd38b255c@googlegroups.com> |
| In reply to | #36649 |
On Friday, January 11, 2013 5:27:21 PM UTC-5, Chris Angelico wrote: > On Sat, Jan 12, 2013 at 9:17 AM, su29090 wrote: > > > Circle.py > > > > > > class circle: > > > > > > from Circle import Circle > > > > Inside the Circle module is a class named circle. You can't import > > Circle from that. > > > > But Python isn't Java. You don't have to put each class into its own > > file. Just put class circle (or class Circle to follow Python naming > > convention) into the other file, whose name you haven't given. > > > > If they're already in the same file, then just drop the import. Easy! > > > > By the way: > > > main() # Call the main function > > You'll need to put that flush left. At the moment, that call is part > > of the definition of main(). > > > > Hope that helps! > > > > ChrisA It worked! Thanks so much! :)
[toc] | [prev] | [next] | [standalone]
| From | su29090 <129km09@gmail.com> |
|---|---|
| Date | 2013-01-11 14:38 -0800 |
| Message-ID | <mailman.418.1357943914.2939.python-list@python.org> |
| In reply to | #36649 |
On Friday, January 11, 2013 5:27:21 PM UTC-5, Chris Angelico wrote: > On Sat, Jan 12, 2013 at 9:17 AM, su29090 wrote: > > > Circle.py > > > > > > class circle: > > > > > > from Circle import Circle > > > > Inside the Circle module is a class named circle. You can't import > > Circle from that. > > > > But Python isn't Java. You don't have to put each class into its own > > file. Just put class circle (or class Circle to follow Python naming > > convention) into the other file, whose name you haven't given. > > > > If they're already in the same file, then just drop the import. Easy! > > > > By the way: > > > main() # Call the main function > > You'll need to put that flush left. At the moment, that call is part > > of the definition of main(). > > > > Hope that helps! > > > > ChrisA It worked! Thanks so much! :)
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2013-01-11 17:43 -0500 |
| Message-ID | <mailman.419.1357944212.2939.python-list@python.org> |
| In reply to | #36646 |
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
[toc] | [prev] | [next] | [standalone]
| From | su29090 <129km09@gmail.com> |
|---|---|
| Date | 2013-01-11 15:23 -0800 |
| Message-ID | <c9bdfe7f-e95d-400a-8e72-068cfad10aad@googlegroups.com> |
| In reply to | #36654 |
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!
[toc] | [prev] | [next] | [standalone]
| From | su29090 <129km09@gmail.com> |
|---|---|
| Date | 2013-01-11 15:23 -0800 |
| Message-ID | <mailman.422.1357946607.2939.python-list@python.org> |
| In reply to | #36654 |
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!
[toc] | [prev] | [next] | [standalone]
| From | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2013-01-11 20:37 -0800 |
| Message-ID | <o3q1f8tkkm8un21i6fgmiagst1hl7pq4ih@4ax.com> |
| In reply to | #36654 |
Dave Angel <d@davea.name> wrote: > >As Adnan has pointed out, Python is case insensitive. That's not really what you meant to say... -- Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-01-12 15:54 +1100 |
| Message-ID | <mailman.427.1357966480.2939.python-list@python.org> |
| In reply to | #36666 |
On Sat, Jan 12, 2013 at 3:37 PM, Tim Roberts <timr@probo.com> wrote: > Dave Angel <d@davea.name> wrote: >> >>As Adnan has pointed out, Python is case insensitive. > > That's not really what you meant to say... UNinsensitive, your Majesty means, of course. UNinsensitive, of course, I meant. *watches the jurors write it down, some each way* ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2013-01-12 00:14 -0500 |
| Message-ID | <mailman.428.1357967707.2939.python-list@python.org> |
| In reply to | #36666 |
On 01/11/2013 11:37 PM, Tim Roberts wrote: > Dave Angel <d@davea.name> wrote: >> As Adnan has pointed out, Python is case insensitive. > That's not really what you meant to say... Nope. I meant Python is case sensitive. Thanks for the catch. I think the rest of my discourse made it clear that case matters. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2013-01-11 22:53 -0500 |
| Message-ID | <mailman.424.1357962885.2939.python-list@python.org> |
| In reply to | #36646 |
On 1/11/2013 5:17 PM, su29090 wrote: > Circle.py > > import math > > class circle: By current convention, you should call the file 'circle.py' and the class 'Circle'. Using all lower case for module filenames is the sanest thing to do in a world where different filesystems do different things with casing. -- Terry Jan Reedy
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web