Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 16th, 2008, 05:17 AM
GryPhUs GryPhUs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 1 GryPhUs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 12 sec
Reputation Power: 0
Need urgent help please...

I need help with this code. It's code to insert and erase nodes in a list, and I think it's not correct:
•__slots__ = [‘__data’, ‘__next’, ‘__prev’]
def__init__(self, initdata):
self.__data = initdata
self.__next= None
self.__prev= None
defgetData(self):
returnself.__data
defgetNext(self)
returnself.__next
defgetPrev(self)
returnself.__prev
defsetData(self, newdata):
self.__data = newdata
defsetNext(self, newnext)
self.__next= newnext
defsetPrev(self, newprev)
self.__prev= newprev

This is the code to erase the nodes:
P.__prev.__next=P.__next
P.__next.__prev=P.__prev

and this is the code to insert nodes:
nuevo= CDnode(d)
nuevo.setNext(P.getNext())
nuevo.setPrev(P)
P.getNext().setPrev(nuevo)
P.setNext(nuevo)

What part of the code to insert or erase do you think it's not OK?
Thanks!!

Reply With Quote
  #2  
Old April 16th, 2008, 08:46 PM
c-2501 c-2501 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: Scotland
Posts: 28 c-2501 User rank is Corporal (100 - 500 Reputation Level)c-2501 User rank is Corporal (100 - 500 Reputation Level)c-2501 User rank is Corporal (100 - 500 Reputation Level)c-2501 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 10 h 22 m 21 sec
Reputation Power: 0
Question

Ok I'm going to try and help you here, but you don't make it easy.

First, when you paste code please maintain the proper indentation, make sure the code is exactly as it appears in your module(you have several missing colons) and use either the CODE or highlight="Python" tags.

I'm assuming for the first section what you want is a class like this:

Python Code:
Original - Python Code
  1. class CDnode:
  2.         __slots__ = ['__data', '__next', '__prev']
  3.        
  4.         def __init__(self, initdata):
  5.                 self.__data = initdata
  6.                 self.__next= None
  7.                 self.__prev= None
  8.                
  9.         def getData(self):
  10.                 return self.__data
  11.        
  12.         def getNext(self):
  13.                 return self.__next
  14.        
  15.         def getPrev(self):
  16.                 return self.__prev
  17.        
  18.         def setData(self, newdata):
  19.                 self.__data = newdata
  20.                
  21.         def setNext(self, newnext):
  22.                 self.__next = newnext
  23.                
  24.         def setPrev(self, newprev):
  25.                 self.__prev = newprev


The first thing I would say is that simple getters and setters like this aren't generally a good idea in python, its much simpler to reference the attributes directly. For example:

instead of your getData method you would use something like:
Python Code:
Original - Python Code
  1. node = CDnode(d)
  2. gotData = node.__data


This however brings me onto the next problem, because you have implemented the attributes with the double-underscore (__) style name, they are awarded a level of privacy by python. So rather than being available as above, the actual code would need to be:

Python Code:
Original - Python Code
  1. gotData = node._CDnode__data


Other than these points I'm really not sure what you are trying to achieve here, have a look at what I've posted and try asking again when you have a better idea of what you want to ask.

EDIT: I see what you are trying to achieve with the __slots__ attribute, forgot what that did for a second there You should probably have a look at the property builtin function too. Looking again at your code I think thats what you were trying to do in the first place, both my previous points still stand though, in this instance there is no need for anything as complex as a getter/setter pair or even use of the property builtin and the __ variable names will still (afaik) prevent you from using these variables as properties.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Need urgent help please...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway