Posts

Showing posts with the label Python Program

Python vs RUBY vs PHP vs TCL vs PERL vs JAVA

Programming Languages Python versus other languages Java   vs. Python Python takes less time to develop although it is expected to run slower than Java programs Due to Python high-level data types and its dynamic typing programs are shorter than Java programs Perl vs. Python Although both these languages are considered similar in many ways,   Perl   supports common application-oriented task like report generating, file scanning, etc.while Python supports for common programming methodologies like data structure design and OOPs programming for programmers making language to readable code Tcl vs. Python Tcl is a standalone programming language it is considered weak on data structures It is slower in executing code compared to Python PHP Python has easy to read code while   PHP   has more syntax from C/C++ and Perl In Python, classes are used extensively in the standard library while PHP has SPL which is fully class based Python su...

Python XML Parser Tutorial: Create & Read XML with Examples

Image
Python enables you to parse and modify XML document. In order to parse XML document you need to have the entire XML document in memory. In this tutorial, we will see how we can use XML minidom class in Python to load and parse XML file.  In this tutorial, we will learn- How to Parse XML How to Create XML Node How to Parse XML We have created a sample XML file that we are going to parse. Step 1)  Inside file, we can see first name, last name, home and the area of expertise (SQL, Python, Testing and Business) Step 2 : Once we have parsed the document, we will print out the  "node name"  of the root of the document and the " firstchild tagname" . Tagname and nodename are the standard properties of the XML file. Import the xml.dom.minidom module and declare file that has to be parsed (myxml.xml) This file carries some basic information about employee like first name, last name, home, expertise, etc. We use the parse function on the XML minido...

Internet Access with Python Tutorial: Open, Parse & Read URL

Image
With Python you can also access and retrieve data from the internet like XML, HTML, JSON, etc. You can also use Python to work with this data directly. In this tutorial we are going to see how we can retrieve data from the web. For example, here we used a guru99 video URL, and we are going to access this video URL using Python as well as print HTML file of this URL.  In this tutorial we will learn How to connect to Internet data How to read HTML file for your URL in Python How to connect to Internet data Before we run the code to connect to Internet data, we need to import statement for URL library two module or "urllib2". It is a Python module that provides utilities for connecting to web addresses and retrieving data from them. Import urllib2 Define your main function Declare the variable webUrl Then call the urlopen function on the URL lib two library The URL we are opening is guru99 tutorial on youtube Next, we going to print the result code Resu...

Python OS Module, Shell Script Commands

Image
Sometimes you need to do more with files than just reading and writing data. You might need to find out the information about the file like whether it exists, what is the path of the file is, whether the path is a directory or a file, etc. So, to get all these information Python provides path related utilities.  In this tutorial we will learn Various OS operations in Python Python File System Shell Methods Various OS operations in Python Step 1 : You can identify the name of the O.S system by calling through Python code. In our case, it will print "nt" as we are using window O.S When you run the code you can observe that you are printing out the letters "nt" as such we are using Windows eight and the OS name as far as programmer are concerned it is denoted as nt. Now you might encounter different name based on what kind of computer you are using, if you are using  Linux  or Mac, it might print different name. Step 2 : In this step we can see, how...

Python FILE Tutorial: Create, Append, Read, Write

Image
In Python, there is no need for importing external library to read and write files. Python provides an inbuilt function for creating, writing and reading files. In this tutorial, we will learn How to create a Text File How to Append Data to a File How to Read a File How to create a Text File With Python you can create a .text files (guru99.txt) by using the code, we have demonstrated here how you can do this Step 1) f= open("guru99.txt","w+") We declared the variable f to open a file named textfile.txt. Open takes 2 arguments, the file that we want to open and a string that represents the kinds of permission or operation we want to do on the file Here we used "w" letter in our argument, which indicates write and the plus sign that means it will create a file if it does not exist in library The available option beside "w" are "r" for read and "a" for append and plus sign means if it is not there then cr...

Python CALENDAR Tutorial with Example

Image
Calendar module in Python has the calendar class that allows the calculations for various task based on date, month, and year. On top of it, the TextCalendar and HTMLCalendar class in Python allows you to edit the calendar and use as per your requirement. Let see what we can do with Python Calendar. Step1 : Code Line # 1: We begin with "import calendar" which will import all the classes of this module. Code Line # 3: c= calendar.TextCalendar(calendar.SUNDAY) tells the interpreter to create a text calendar. Start of the month will be Sunday. In Python, you can format the calendar as you can change the day of the month to begin with Code Line # 4: str= c.formatmonth(2015,1) We are creating calendar for the year 2015, Month 1 – January Code Line # 5: print str will print the output. Run the code. Let's quickly change the value from Sunday to Thursday and check the output Step 2 : You can also print out the Calendar in HTML format, this feature is helpful...