Skip to main content

PYTHON

26/10/15:
---------

* CLASSES AND METHODS:
----------------------

* Possible conventions include capitalizing method names, prefixing data attribute names with a small unique string (perhaps just an underscore), or using verbs for methods and nouns for data attributes.

*  It is not necessary that the function definition is textually enclosed in the class definition: assigning a function object to a local variable in the class is also ok
# Function defined outside the class
def f1(self, x, y):
    return min(x, x+y)
class C:
    f = f1
    def g(self):
        return 'hello world'
    h = g

* Methods may call other methods by using method attributes of the self argument:
class Bag:
    def __init__(self):
        self.data = []
    def add(self, x):
        self.data.append(x)
    def addtwice(self, x):
        self.add(x)
        self.add(x)

* The syntax for a derived class definition looks like this:
class DerivedClassName(BaseClassName):
    <statement-1>
    .
    .
    .
    <statement-N>

* when the base class is defined in another module:
class DerivedClassName(modname.BaseClassName):

* A method of a base class that calls another method defined in the same base class may end up calling a method of a derived class that overrides it

* There is a simple way to call the base class method directly: just call BaseClassName.methodname(self, arguments).

* There is a convention that is followed by most Python code: a name prefixed with an underscore (e.g. _spam) should be treated as a non-public part of the API (whether it is a function, a method or a data member).

* Any identifier of the form __spam (at least two leading underscores, at most one trailing underscore) is textually replaced with _classname__spam, where classname is the current class name with leading underscore(s) stripped.

* Useful for Verilog parsing:
A piece of Python code that expects a particular abstract data type can often be passed a class that emulates the methods of that data type instead. For instance, if you have a function that formats some data from a file object, you can define a class with methods read() and readline() that get the data from a string buffer instead, and pass it as an argument.

* PYTHON STYLE GUIDE:
---------------------
* https://www.python.org/dev/peps/pep-0008/

Comments

Popular posts from this blog

Install Modelsim in Ubuntu

Updates (23/09/14): The steps given below are for 32-bit version of Ubuntu. To install Modelsim on 64 bit Ubuntu, please refer to this link.  What is Modelsim? Modelsim is a hardware simulation and debug environment primarily targeted at smaller ASIC and FPGA design ( Ref ) How do I install it? Download Modelsim Linux edition from here   For more information visit me   Go to the download location of the .run file and type chmod +x ModelSimSetup-13.1.0.162.run Visit me for more details Use the command ./ ModelSimSetup-13.1.0.162.run install Modelsim  How do I start Modelsim?   Change your directory to 'Location_where_you_installed_Modelsim '/altera/13.1/modelsim_ase/linuxaloem   Type ./vsim   Verified on: Ubuntu 12.04 LTS

VIS & VL2MV

18/01/2016: -----------     Installing VIS model checker     ----------------------------         Download from: http://vlsi.colorado.edu/~vis/vis_files_2.4.html         Note: First do the installation of glu and then install vis or vl2mv (order doesn't matter)         Installation: Follow the steps in the VIS README file in http://vlsi.colorado.edu/~vis/vis_files_2.4.html         Pitfalls: Dont extract the vis and glu .tar.gz files using gui. Instead use the commands given below             % gzip -dc /tmp/glu-2.4.tar.gz | tar xf -             % gzip -dc /tmp/vis-2.4.tar.gz | tar xf -         Setting environment for VIS          ...

Installing Latex (Miktex+Winedt platform) in windows 7

courtesy: Jinu jayachandran (IIT Bombay) Note: To use latex in windows, you can use the softwares Mikitex and Winedt 1.install the mikitex 2.9 2.Install Winedit 7 3. Start->mikitex 2.9->maintenance->settings->general->change the preference for ‘install missing packages on-the-fly’ to ‘yes’ 4. Start->mikitex 2.9->maintenance(admin)->package manager->repository->change package repository->click ‘packages shall be installed from internet’-> give proxy settings and tick ‘authentication required’-> next->give ldap username and password 5. select any repository 6. Start->mikitex 2.9->maintenance(admin)->package manager->repository->synchronise 7.Start->mikitex 2.9->maintenance(admin)->update(admin) and update by selecting ‘use nearest package repository’ and give proxy settings Now you can start using mikitex using winedit interface. download MikiTex 2.9 download Winedt 7 userguide Note:The ldap i...