[Tutor] Next steps...

2014-07-07 Thread Ni Hung
ok, I am now able to write scripts in python. I can read/modify scripts
written by others (true to some level).  I understand the basics of
libraries (how are they different from modules or are the same thing with
two names?)  like urllib2, json, sys, os etc. and have used them in some
scripts.

What should I do next to advance my knowledge of python? Should I study/use
libraries/modules?  Which ones?  Any other suggestions?

Thanks and Regards
Nii
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When to use classes

2014-04-10 Thread Ni hung
Thank you Alan, Dave and Cameron (and folks managing this email group)!
 Your replies were very helpful.

Regards
ni



On Wed, Apr 9, 2014 at 4:25 AM, Cameron Simpson  wrote:

> On 08Apr2014 22:58, Ni hung  wrote:
> > I am learning programming using python. I think of solving a problem
> using
> > functions and for this reason all/most of my code consists of functions
> and
> > no classes.  I have some understanding of classes/Object Oriented
> > Programming. I can write simple classes but I do not understand when to
> use
> > classes.
>
> Loosely speaking, you can usefully make a class when there is a
> particular type of object on which you are make an assortedment of
> operations.
>
> For example, if you have several functions looking like this:
>
>   def modify_thing1(obj1, ...):
>
>   def add_something(obj1, ...):
>
> and so on, where obj1 is always the same kind of thing, representing
> some well define idea you have when writing the code.
>
> In that circumstance you might make a class looking like this:
>
>   class ObjName(object):
>
> def __init__(self):
>   # "self" here is an "obj1" as used above
>   # set whatever attributes an "obj1" should have to start with
>   # you can pass in some of those values as parameters to the __init__
> function
>
> def modify(self, ...):
>   # this is the same as "modify_thing1(obj1, ...)" earlier
>   # using "self" as "obj1"
>
> def add(self, ...):
>   # this is the same as "add_something(obj1, ...)" earlier
>
> Then your code looks like:
>
>   obj1 = ObjName()
>   ...
>   obj1.modify(5)
>   obj1.add(6)
>
> or what have you.
>
> This has several advantages:
>
>   - all the code that affects this kind of object is in one place
>
>   - you can remove all the specifics of how things are done from the main
> code and keep them inside the class methods.
> This makes the main code more readable (if you pick good method names)
> and shorter (also more readable, usually).
>
>   - later, if need be, you can change the inner workings of how
> ObjNames work without changing the main code, or at least not
> much - sometimes not at all
>
> Anyway, that's an ok rule of thumb for when to make a class: when
> you have a bunch of operations to do to one type of thing.
>
> Cheers,
> --
> Cameron Simpson 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] When to use classes

2014-04-09 Thread Ni hung
Hi

I am learning programming using python. I think of solving a problem using
functions and for this reason all/most of my code consists of functions and
no classes.  I have some understanding of classes/Object Oriented
Programming. I can write simple classes but I do not understand when to use
classes.

Any suggestions, pointers to documents/blogs/books are welcome!

Many Thanks
Ni
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor