2011-11-24

second steps programming in python

The key to the success is the idea. And the key to the knowledge is to practice.
Firstly, I started with objects in PHP, then tried to do some work in VB2010 (i hope soon, till the end of the year there will be the result - groundwater and runoff modelling software METQ-UL aka MetCool) and today I tried to refresh my Py-mories... All day long tried to transfer VB code into the Python, but it seems that I`ve some small problems somewhere.
Another thing about Python - I didn`t find a way how to change values inside in method... as example if I have a method in class which does something, like

def f(self,a,b)
     a=a**2
     b=b**b
     return a

and in the same time i need to return value b, I have to make a list or dictionary, like
def f(self,a,b)
     a=a**2
     b=b**b
     D=dict(a=a,b=b)
     return D


In such case it is much more unhandy as it was in VB or Fortran, like

Sub f(ByRef dim a as integer, ByRef dim b as integer)
   ..
End sub

The difference is when such sub (function/subroutine) has to be called, the syntax is simple in the VB/Fortran

a=2
b=3
call f(a,b)
print.debug a,b
//returns 4 and 27

without neccesity to "extract" the modified value from function
unlike the other languages, where it has to be some object or variable which will have the modified values..
in the case of python -

//example when function are inside and are called from the class
a=2
b=3
dictionary = self.f(a,b)
print a,b //return 2,3
a=dictionary['a']
b=dictionary['b']
print a,b //return 4, 27

Nav komentāru:

Komentāra publicēšana