473,412 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

locate the errors in defining class

Expand|Select|Wrap|Line Numbers
  1. class Dialog:
  2.  
  3.     def Dialog(self):
  4.         self._dial = 'exit'
  5.  
  6.     def change(self)
  7.         index = self.index('x')
  8.         self._dial[index]='e'
  9.  
  10.     def __str__(self):
  11.         print 'this is ' +self._dial
  12.  
  13.  
There were several errors but I could not fix, please help me.

I just began learning defining a class and really being trouble in understanding.
Oct 4 '07 #1
2 1030
I figured out how to do fix the errors.
Oct 4 '07 #2
bartonc
6,596 Expert 4TB
I figured out how to do fix the errors.
You are well on your way to learning! Here are some comments and a working class:
Expand|Select|Wrap|Line Numbers
  1. class Dialog:
  2.     # the contructor is called automatically and is named __init__
  3. ##    def Dialog(self):
  4.     def __init__(self):
  5.         self._dial = 'exit'
  6.  
  7.     # I like all of the __builtin__ methods togeter
  8.     def __str__(self):
  9. ##        print 'this is ' + self._dial
  10.         # str is called by the print statement
  11.         return 'this is ' + self._dial
  12.  
  13. ##    def change(self)
  14. ##    Missing :
  15.     def change(self):
  16. ##        index = self.index('x')
  17.         # don't use reserved words as variable names
  18.         # remember to put the variable in
  19.         idx = self._dial.index('x')
  20.         # use spaces consistantly for readability
  21. ##        self._dial[idx] = 'e'
  22.         # strings are not mutable!
  23.         # slice up to idx, add 'e', slice one past idx and add that
  24.         self._dial = self._dial[:idx] + 'e' + self._dial[idx + 1:]
  25.  
  26.  
  27. d = Dialog()  # bad name for a class because it's used in other packages
  28. print d
  29. d.change()
  30. print d
Oct 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Alexander Kienzle | last post by:
I'm new to Java programming. I'm developing a Servlet for tomcat which needs an external configuration file. With external I mean a file (in XML format) which is customizable and not contained in...
0
by: Jonathan Brandmeyer | last post by:
I am attempting to create a class that inherits from a PyGTK class and a Boost.Python-based class. When the interpreter executes code like: class Myclass( gtk.some_class, my_boost_python_class):...
1
by: Conrad Chan | last post by:
I am trying to build some utilities for our internal development. Is there any way I can programmetically find out the original source file for a given class? Say I am inspecting a CLR type in...
7
by: Saulius | last post by:
template<template<typename T> class StoragePolicy> class construction_info { // Empty by default, specialize for other types. }; template<template<typename> class StoragePolicy, typename...
3
by: John Black | last post by:
Hi, In debugging a core dump, I run purify against my code, it says several "Free Memory Read" errors. All the errors are on one delete statement. Usually this means some pointer is deleted by...
78
by: Robert Baer | last post by:
The homepage i have had up and seemingly working is: http://oil4lessllc.com/ However, the validator has so many complaints, and being so incompetent, i have no clue as to how to fix it all. Would...
2
by: hyling.s1 | last post by:
Hi I'm getting "unresolved external symbol" linker errors from VC++ 2003 when I use a static instance of a class for example class myClass { protected: static class2 mInstance; /* fails with...
1
by: Pucca | last post by:
I'm getting the follow error message randomly and then my application crashes. How can I locate the bug code and how can I fix this? Managed Debugging Assistant 'DisconnectedContext' has...
3
by: Baheri | last post by:
Can some some guide me to a good link on how to throw errors in a webservice? Also if there is a standard way of defining different degress of erros while exposing your webservice to thrid parties?...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.