Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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:
  #1  
Old January 7th, 2013, 06:23 AM
yiphome yiphome is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 yiphome User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 18 sec
Reputation Power: 0
Question about _this()

In the following code ( A molecule includes several atoms.):

for j in range(mol.getNbAtoms()):
mol.atoms[ j ]._this()
mol = mol._this()

my question is: what is the meaning of the Line 2. If _this() returns an atom, where will this atom be return?
These codes are from a program written by other people, So I don't understand it quite well.
Thanks for answers!

Reply With Quote
  #2  
Old January 7th, 2013, 09:49 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,357 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 10 m 28 sec
Reputation Power: 383
Guessing, you've shown hardly any code.

mol is an object representing some molecule. Let's call it carbon dioxide.


mol.getNbAtoms()

getNbAtoms is a method of the Molecule class. It returns the number of atoms in the molecule. 3 for CO_2.

mol.atoms is a an object with a __getitem__ method. In other words, it supports the [] indexing notation.

mol.atoms[ 0] would return an Atom object, say, for oxygen.

mol.atoms[1] likewise is an Atom object, say, carbon.

mol.atoms[2] would represent another oxygen. Could be the same object as mol.atoms[0], or a different one if the simulation accounts for the state of each atom.

_this is a method. A function that need not takes any parameters.

Molecule._this might be different from Atom._this .


Programming experiment. Before running the program again insert statements like

print('mol._this')
print(help(mol._this))
print(''atom 0 ._this')
print(help(mol.atoms[0]._this))
for j in range(mol.getNbAtoms()):
...



Summary: I think your interpretation of the program is incorrect. mol.atoms[j] represents the atom. Furthermore, without more code I'm clueless, this entire explanation may be an exercise in bogosity.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old January 7th, 2013, 11:01 AM
yiphome yiphome is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 yiphome User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
Guessing, you've shown hardly any code.

mol is an object representing some molecule. Let's call it carbon dioxide.


mol.getNbAtoms()

getNbAtoms is a method of the Molecule class. It returns the number of atoms in the molecule. 3 for CO_2.

mol.atoms is a an object with a __getitem__ method. In other words, it supports the [] indexing notation.

mol.atoms[ 0] would return an Atom object, say, for oxygen.

mol.atoms[1] likewise is an Atom object, say, carbon.

mol.atoms[2] would represent another oxygen. Could be the same object as mol.atoms[0], or a different one if the simulation accounts for the state of each atom.

_this is a method. A function that need not takes any parameters.

Molecule._this might be different from Atom._this .


Programming experiment. Before running the program again insert statements like

print('mol._this')
print(help(mol._this))
print(''atom 0 ._this')
print(help(mol.atoms[0]._this))
for j in range(mol.getNbAtoms()):
...



Summary: I think your interpretation of the program is incorrect. mol.atoms[j] represents the atom. Furthermore, without more code I'm clueless, this entire explanation may be an exercise in bogosity.


Thanks for your patiently reply!

Because it takes several pages to post the codes, I choose not to do that. Your guess actually makes sense.
The Line 3 is quite clear for me. For Line 2, I expect a line like this:
mol.atoms.append(NewAtom)
There is no implementation of _this() in Atom class, which makes me dizzy.
Your advice is quite useful, I will try and see what is inside _this().
Thanks!

Reply With Quote
  #4  
Old January 7th, 2013, 11:46 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,357 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 10 m 28 sec
Reputation Power: 383
_this might be defined in a parent class which you could find via source that looks like

class SubClass(ParentClass):


Likely that mols.atoms is a list.

print(type(mols.atoms)) # indicator

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Question about _this()

Developer Shed Advertisers and Affiliates



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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap