Tuesday, February 26, 2013

Data Attributes


While data attributes defined both ways may have unique values for any particular instance, those that exist in the class definition can be accessed without an instance of the class, as the following hypothetical example:
import sys;
class NewClass():
    data_attribute1 = 1;
    def __init__(self):
        self.data_attribute2 = 2;
print(NewClass.data_attribute1);
try:
    print(NewClass.data_attribute2);
except AttributeError:
    print(sys.exc_info()[0]);
instance = NewClass();
print(instance.data_attribute1);
print(instance.data_attribute2);
1
<type 'exceptions.AttributeError'>
1
2

Sunday, February 24, 2013

Basics of class implementation in Python

By reading ten pages of Chapter five today, I learnt instantiation and attributes. Here is what I programmed during reading the book:


class NewClass:
    pass;
dir(NewClass);
# Result: ['__doc__', '__module__'] #
class NewClass(object):
    pass;
     
dir(NewClass);
# Result: ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] #
instance1 = NewClass();
instance2 = NewClass();
instance3 = NewClass();
class NewClass():
    data_attribute = None;
    def function_attribute(*args):pass;
print(dir(NewClass));
['__doc__', '__module__', 'data_attribute', 'function_attribute']

Friday, February 22, 2013

Object-oriented programming

So today, I plan to start learning chapter 5. But before that, I need to review what is object-oriented programming, and some basic concepts.

1) Object-oriented programming (OOP) is a programming paradigm that represents concepts as "objects" that have data fields (attributes that describe the object) and associated procedures known asmethods. Objects, which are usually instances of classes, are used to interact with one another to design applications and computer programs.

2) Class is a construct that is used to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable its instances to have state and behavior.

3) Object is a location in memory having a value and referenced by an identifier. An object can be a variable, function, or data structure. With the later introduction of object-oriented programming the same word, "object," refers to a particular instance of a class.

4)Method is a subroutine (or procedure) associated with a class. Methods define the behavior to be exhibited by instances of the associated class at program run time. Methods have the special property that at run-time  they have access to data stored in an instance of the class (or class instance or class object or object) they are associated with and are thereby able to control the state of the instance.

5)Instance is an occurrence or a copy of an object, whether currently executing or not. Instances of a class share the same set of attributes, yet will typically differ in what those attributes contain.

I also learnt the three main differences between object-oriented and process-oriented. They are Inheritance, Encapsulation,Polymorphism. Since they are so complicated, it is better not describe them in detail here.

Wednesday, February 20, 2013

Using Eclipse as a Maya IDE

I used two hours to setup Eclipse as a Maya IDE. But until now, it doesn't work.
Here is the link I tried:
http://www.creativecrash.com/tutorials/using-eclipse-as-a-maya-ide#tabs
http://nealbuerger.com/2012/07/eclipse-python-editor-maya-2013/
http://autodesk.com/us/maya/2011help/PyMel/eclipse.html

I'm too tired now, but I will finish this tomorrow. Hope I could make it work tomorrow!!!

Tuesday, February 19, 2013

My first Module: spike

My first module is pretty simple, just create a soccer ball and then extrude it twice as the picture shows below. But I did learn lots of new maya commands and understand Module deeper. Here is the script:

"""This script prints some information and creates a spike ball."""
import maya.cmds
def addSpikes(obj):
    """This function adds spikes to a polygon object."""
    try: polycount = maya.cmds.polyEvaluate(obj, face=True)
    except: raise
    for i in range(0, polycount):
        face = '%s.f[%s]'%(obj, i)//遍历obj的所有face
        maya.cmds.polyExtrudeFacet(face, ltz=1, ch=0)//第一次extrude
        maya.cmds.polyExtrudeFacet(face, ltz=1, ch=0, ls=[.1,.1,.1])//第二次extrude 缩小为上一次的0.1倍
    maya.cmds.polySoftEdge(obj, a=180, ch=0)
    maya.cmds.select(obj)

print('module name: %s'%__name__)
print('globals:')
for k in globals().keys(): print('\t%s'%k)
addSpikes(maya.cmds.polyPrimitive(ch=0)[0])//创建一个soccer ball
Result:

Monday, February 18, 2013

Commands Python Help


1) Useful to check out the flags of each maya command
import maya.cmds;
print(maya.cmds.help('maya command'));

2) Good website to check out detail information about each maya command

http://download.autodesk.com/us/maya/2011help/CommandsPython/

Sunday, February 17, 2013

50 Important Modules in Python

This week I learnt a lot about Module in Python even I do not post my study notes on this blog anymore.Module, in my understanding, is a standalone Python file containing a sequence of definitions and executable statements and Python itself ships with a large library of default modules.

Here, I summarized 50 really useful Modules including Databases, GUIs, Images, Sound, OS interaction, Web, etc.

Graphical interface wxPython          http://wxpython.org     
Graphical interface pyGtk        http://www.pygtk.org    
Graphical interface pyQT         http://www.riverbankcomputing.co.uk/pyqt/        
Graphical interface Pmw         http://pmw.sourceforge.net/
Graphical interface Tkinter 3000    http://effbot.org/zone/wck.htm    
Graphical interface Tix    http://tix.sourceforge.net      
                         
Database          MySQLdb http://sourceforge.net/projects/mysql-python/    
Database          PyGreSQL          http://www.pygresql.org/      
Database          Gadfly       http://gadfly.sourceforge.net/     
Database          SQLAlchemy     http://www.sqlalchemy.org/ 
Database          psycopg   http://www.initd.org/pub/software/psycopg/       
Database          kinterbasdb      http://kinterbasdb.sourceforge.net/     
Database          cx_Oracle         http://www.cxtools.net/default.aspx?nav=downloads
Database          pySQLite  http://initd.org/tracker/pysqlite    
                         
MSN Messenger      msnlib      http://auriga.wearlab.de/~alb/msnlib/ 
MSN Messenger      pymsn      http://telepathy.freedesktop.org/wiki/Pymsn       
MSN Messenger      msnp        http://msnp.sourceforge.net/        
Network  Twisted    http://twistedmatrix.com/     
Images     PIL    http://www.pythonware.com/products/pil/ 
Images     gdmodule         http://newcenturycomputers.net/projects/gdmodule.html 
Images     VideoCapture  http://videocapture.sourceforge.net/   
                         
Sciences and Maths         scipy         http://www.scipy.org/    
Sciences and Maths         NumPy     http://numpy.scipy.org/           
Sciences and Maths         numarray          http://www.stsci.edu/resources/software_hardware/numarray
Sciences and Maths         matplotlib         http://matplotlib.sourceforge.net/        
                         
Games     Pygame    http://www.pygame.org/news.html      
Games     Pyglet       http://www.pyglet.org/ 
Games     PySoy        http://www.pysoy.org/  
Games     pyOpenGL         http://pyopengl.sourceforge.net/ 
                         
Jabber      jabberpy  http://jabberpy.sourceforge.net/  
                         
Web scrape      http://zesty.ca/python/scrape.html       
Web pythonweb       http://www.pythonweb.org/ 
Web mechanize        http://wwwsearch.sourceforge.net/mechanize/  
                         
Localisation      geoname.py     http://www.zindep.com/blog-zindep/Geoname-python/      
                         
Serial port         pySerial    http://pyserial.sourceforge.net/    
Serial port         USPP         http://ibarona.googlepages.com/uspp 
                         
Parallel Port     pyParallel          http://pyserial.sourceforge.net/pyparallel.html   
                         
USB Port  pyUSB       http://bleyer.org/pyusb/
                         
Windows pywin32   http://sourceforge.net/projects/pywin32/    
Windows pywinauto        http://www.openqa.org/pywinauto/     
Windows pyrtf          http://pyrtf.sourceforge.net/
                         
PDA/GSM/Mobiles  pymo        http://www.awaretek.com/pymo.html 
PDA/GSM/Mobiles  pyS60        http://sourceforge.net/projects/pys60 
                         
Sound       pySoundic         http://pysonic.sourceforge.net/    
Sound       pyMedia  http://pymedia.org/        
Sound       FMOD       http://www.fmod.org/   
Sound       pyMIDI     http://www.cs.unc.edu/Research/assist/developer.shtml   
                         
GMail       libgmail    http://libgmail.sourceforge.net/    
Google     pyGoogle http://pygoogle.sourceforge.net/ 
Expect      pyExpect  http://pexpect.sourceforge.net/   
WordNet  pyWordNet       http://osteele.com/projects/pywordnet/      
Command line cmd http://blog.doughellmann.com/2008/05/pymotw-cmd.html         
Compiler backend    llvm-py     http://mdevan.nfshost.com/llvm-py/     
3D    VPython   http://vpython.org
pyDes   DES lock/unlock  http://twhiteman.netfirms.com/des.html
pyparsing    similar to lex/yacc but easier   pyparsing.wikispaces.com