Skip to main content

First program in Python!!!

Here you go!!..

Learning new programming languages is quite equal to learning new regional language. I have head started with python programming language which is one of the oldest programming languages . It is has OOPS concept so that if we are familiar with OOPS concept then this programming language should be quite easy for us to learn. Only syntax varies.

To start with i have tried to write a smallest program in python language.The problem statement is very simple

Write a program to find 2 consecutive vowels in a string  .Consider those two consecutive vowels as one character and return the number of characters in that string.

I have used an online editor http://www.tutorialspoint.com/execute_python_online.php to learn coding practically.Now let me show you step by step to execute this small program

  1. When you open the  Online EDITOR linkby default you can see root folder and under that root folder there is file named main.py 











2.Now right click on Root folder and select Create new file. This is new class file in which we are going to write functionality. Infact you can write functionality withn the main.py file also. PY is the extension of python class file.















3.Rename newly created file with appropriate file name.

4.Inside the new class file write the functionality














In the above mentioned code


  • removeVowels is the class name .If there is a statement of line which is based on one of teh condition or which belongs to some code block then the parent statement should be end COLON(:). Since all of the functionality will be inside the class name , so we add colon at the end of the class.Here class is a keyword to represent its immediate next word is class name
                             class removeVowels:
  • getLength is the method name. You can see that at the end of the method there is a COLON. it means inside the method some lines of code are there which are strictly inside that method code block. the keyword def represents the word which is present immediately next to the def is METHOD/function.
                           def getLength(randomVariable,word):

     NOTE: in python INDENTATION plays biggest role. Huh!!!.. indentation means TAB. If a second line of the code is depending on the first line then after writing first line of the code and adding COLON at the end of that line you need to press ENTER key. Now you need to press TAB key. in the above two statements under bullets point THE CLASS AND METHOD are inter linked. Hence after writing a line of words for class and adding colon at the end, now press enter key and press TAB key. Write statement for METHOD getLength. You can clearly spot this in the 4th image 

  •  Now you can see another two lines of statement in which there is no colon and no TAB (indentation)














        vowel='aioue'
        for i in range(len(word)-1):
 for loop is not having a tab after the statement vowel='aioue'. Because these two lines of the code are independent .Now whatever we are going to write inside for loop should be indented.Means TAB


  • For loop ends with colon .If condition is inside the for loop and again if condition has some statement. So ideally if condition should have colon at the end and its statement should have one tab space after the if condition
5.Now double click on main.py file so that it gets opened . From this file we need to create instance of that class in the newly created class file.














In the above statements

  • So the functionality is in some other class and some other file.Not in main.py . So logically we need to import that class and its class file to our main.py from which we call the functionality inside that class.Inorder to do so, we need import the class and class file to calling class(main.py). The syntax is 
         from RemoveVowel import removeVowels

        In the above line of code from is a keyword . RemoveVowel word which is present immediately after this from keyword is CLASSFILE name without .py extension. in our case the new file name in which our class and method are present is RemoveVowel.py . So use only the file name here. Now import is also key which and the word which is present immediately after the import keyword is the class name. In our case the class name is removeVowels. You can see the code

  • Create object of the class as per below. In order to access any method,properties,variables inside any CLASS from another class , we need to create the object of that class. The statement is as mentioned below. 
         cls is object of the class removeVowels.open and closed brackets represents you care invoking constructors of the class. This is how we invoke class in any object oriented programming languages 
         cls=removeVowels();

  • Now you have got object of the class. By using the object of the class you class the method as follow
       cls.getLength("wuut")


6. Now execute the code by clicking on execute button in the editor













you can see the output in the output window which is present at the bottom of the editor. You can use the code here CODE


Happy coding!!!.. I will share some more tips and tricks from other programming languages such as server side, client side and database

Comments

Popular posts from this blog

The Fastest way to Export Schema of Sharepoint List

Many of my SharePoint Developer friends are struggling to get the Schema.xml file of a newly created list. The schema.xml file has the list's metadata information, by using the schema.xml, we can create the lis definition and paste this contents of Schema.xml to the Schema.xml file of the newly created List definition, so that you can deploy the list definition on another site. In order to do this, you guys might be following the procedure bu saving the site template and get the site definition solution. After this, you will open visual studio and import this solution and wait for few minutes. THIS IS A CRAPPY PROCEDURE..Why do you invest your time to get a schema of one or few list  by taking entire site definition?..If that site has lots of lists, then it will take lots of time. In my Research, i have found a the BEST  and quicker way to get schema.xml file of a particular list which you need Schema.xml. Follow the following procedure : Go to your site  click on the lis

How to avoid refreshing of page on clicking on BUTTON in jQuery?

Suppose you might have created a button on page.When you click on that button without page refresh some other custom things have to happen. But instead of that, on clicking on the button the page is getting refreshed. How to avoid this?.. Simple, The button click event has default event as refreshing the page. The solution is to "prevent the default event". $("#ButtonID").Click(function(e) {   e.preventDefault(); //Write your custom code here } ); Hope this may help Cheers Pradeepa Achar

This solution contains invalid markup or elements that cannot be deployed as part of a sandboxed solution. Solution manifest for solution 'cc218449-78b3-4430-b401-4884977560e2' failed validation, file manifest.xml, line 11, character 4: The element 'Solution' in namespace 'http://schemas.microsoft.com/sharepoint/' has invalid child element 'TemplateFiles' in namespace 'http://schemas.microsoft.com/sharepoint/'. List of possible elements expected: 'FeatureManifests, ActivationDependencies' in namespace 'http://schemas.microsoft.com/sharepoint/'. Troubleshoot issues with Microsoft SharePoint Foundation. Correlation ID: oplh6595a-a6hg-416f-a85f-a173bp03dda6 Date and Time: 30/10/2013 13:33:18

By looking at this bug you may get shocked and may not understand why this is happening. I can say, you have developed a wsp of farm solution, not the sandboxed solution  using visual studio and added some OOTB webparts such as visual webparts and trying to deploy the solution via solution gallery directly on to the sharepoint site. It is so simple.Understand that, when you create a .wsp file using visual studio, you deploy as farm solution. But when you try to deploy the same solution from site settings-> solution gallery, you deploy it as sand boxed solution. In this situation ,the "TemplateFiles" elements refers to the items that will be copied into the web servers. This is allowed only in farm solutions , not in sandboxed solutions. I suggest you guys to deploy the solution either using stsadm command or powershell command, so that it will work fine.If anyone wants to know about how to deploy using powershell command you can refer the   techNet  document for