Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-29-2004, 06:17 AM   #1 (permalink)
MealMan401
Registered User
 
MealMan401's Avatar
 
Join Date: Apr 2004
Posts: 10
MealMan401 is on a distinguished road
Python class definitions

Hi,

Just started playing around in Python. Copied out a example off of Sourceforge and it didn't work (after writing my own class and that didn't work either ). Neither did any other examples, so maybe i am missing something that is a assumed in the examples

THis is what i wrote in the interpreter (WIndows version of the IDLE Python 2.3)
Code:
first try:


>>> class SimpleClass:
	def _init_(self):
		self.data = 3
	def get(self):
		print self.data

	
>>> m = SimpleClass()
>>> m.get()

Traceback (most recent call last):
  File "<pyshell#12>", line 1, in -toplevel-
    m.get()
  File "<pyshell#10>", line 5, in get
    print self.data
AttributeError: SimpleClass instance has no attribute 'data'



and second try:


>>> class SimpleClass:
	def _init_(self, init_val):
		self.data = init_val
	def get(self):
		print self.data

>>> m = SimpleClass(1)

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in -toplevel-
    m = SimpleClass(1)
TypeError: this constructor takes no arguments






anyone know why its not working???

Thanks
MealMan401 is offline   Reply With Quote
Old 04-29-2004, 06:18 AM   #2 (permalink)
MealMan401
Registered User
 
MealMan401's Avatar
 
Join Date: Apr 2004
Posts: 10
MealMan401 is on a distinguished road
The indentation was correct on the real example that i typed into the interpreter, but was lost when i posted here.
MealMan401 is offline   Reply With Quote
Old 04-29-2004, 06:28 AM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
you can use the [code ] code goes here [/code ] tags without the spaces to show your indentations.

hmm ... inkedemn is really into python, but i haven't seen him around lately.
__________________
Mike
sde is offline   Reply With Quote
Old 05-21-2004, 06:00 PM   #4 (permalink)
toe_cutter
Code Monkey
 
Join Date: Aug 2002
Location: Boston, MA
Posts: 79
toe_cutter is on a distinguished road
Send a message via ICQ to toe_cutter Send a message via AIM to toe_cutter Send a message via Yahoo to toe_cutter
for you're constructor. I believe the init should have 2 _ so it looks like this

def __init__(self):

I could just be blowing smoke, but it looks like you're has only 1 on each side.

Toe
__________________
toe_cutter is offline   Reply With Quote
Old 05-22-2004, 01:17 PM   #5 (permalink)
MealMan401
Registered User
 
MealMan401's Avatar
 
Join Date: Apr 2004
Posts: 10
MealMan401 is on a distinguished road
Thanks, that was it!
MealMan401 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
to put data methods inside class or not? sde Java 2 05-25-2004 04:09 PM
New Tutorial: Python Lists Overview sde Code Newbie News 3 03-24-2004 09:54 AM


All times are GMT -8. The time now is 08:42 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting