Found 34494 Articles for Programming

Support for line-oriented command interpreters in Python

Ankith Reddy
Updated on 26-Jun-2020 06:29:29

353 Views

The cmd module contains only one class called Cmd. This is used as base class for a user defined framework for line oriented command line interpreters.CmdAn object of this class or its subclass provides the line oriented interpreter framework. Important methods of this class inherited by the subclass are listed below.cmdloop()This method sends the object in a loop, accepts inputs and sends the same to appropriate command handler method in the class.As the loop starts an introductory message (give as parameter to cmdloop() method) will be displayed with a default (cmd) prompt which may be customized by prompt attribute.The interpreter ... Read More

Java Program to convert float to String

Samual Sam
Updated on 26-Jun-2020 06:30:12

211 Views

The valueOf() method is used in Java to convert float to string.Let’s say we have the following float value.float val = 10.18465F;Converting the above float value to string.String.valueOf(val);Example Live Demopublic class Demo {    public static void main(String[] args) {       float val = 98.18465F;       // converting float to String       String str = String.valueOf(val);       System.out.println("String: "+str);    } }OutputString: 98.18465

Python getpass Module

Arjun Thakur
Updated on 26-Jun-2020 06:31:13

1K+ Views

There are two functions defined in getpass module of Python’s standard library. They are useful whenever a terminal based application needs to be executed only after validating user credentials.getpass()This function prompts the user to enter a password. By default the keys entered by user in the terminal are not echoed. Also the default prompt that appears on terminal is ‘password’ which can be customized by providing a string as parameter.In following example, Python prompt is invoked from Command prompt terminal on Windows. The password entered is not echoed in the terminal.C:\python36>python Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 ... Read More

Keywords in Java

Samual Sam
Updated on 26-Jun-2020 07:04:17

661 Views

Keywords in Java are reserved words that represent predefined actions, internal processes etc. Because of this, keywords cannot be used as names of variables, functions, objects etc.The main difference between keywords and identifiers is that keywords are reserved words that represent predefined actions while identifiers are the names of variables, functions, objects etc.Some of the keywords in the Java are given as follows −abstractassertbooleanbreakbytecasecatchcharclassconstcontinuedefaultdodoubleelseenumextendsfinalfinallyfloatforgotoifimplementsimportinstanceofintinterfacelongnativenewpackageprivateprotectedpublicreturnshortstaticstrictfpsuperswitchsynchronizedthisthrowthrowstransienttryvoidvolatilewhileA program that demonstrates keywords is given as follows −Example Live Demopublic class Example { public static void main(String[] args) { int i = 5; char c = 'A'; System.out.println("i = " + i); System.out.println("c = " + ... Read More

Work with ZIP archives in Python (zipfile)

George John
Updated on 25-Jun-2020 14:25:59

796 Views

The ZIP is one of the most popular file formats used for archiving and compression. It has been in use since the days of MSDOS and PC and has been used by famous PKZIP application.The zipfile module in Python’s standard library provides classes that facilitate the tools for creating, extracting, reading and writing to ZIP archives.ZipFile()This function returns a ZipFile object from a file parameter which can be a string or file object as created by built-in open() function. The function needs a mode parameter whose default value is ‘r’ although it can take ‘w’ or ‘a’ value for opening ... Read More

High-level file operations in Python (shutil)

Chandu yadav
Updated on 25-Jun-2020 14:26:52

972 Views

A number of functions for hgh level operations on files and directories have been defined in shutil module of Python’s standard library.copy()This function copies a file to a specified file in same or other directory. First parameter to the function is a string representation of existing file. Second argument is either name of resultant file or directory. If it is a directory, the file is coped in it with same name. The metadata of original file is not maintained.>>> import shutil >>> shutil.copy("hello.py", "newdir/") 'newdir/hello.py'copy2()This function is similar to copy() function except for the fact that it retains metadata of ... Read More

Unix style pathname pattern expansion in Python (glob)

Arjun Thakur
Updated on 25-Jun-2020 14:28:31

416 Views

Many a times a program needs to iterate through a list of files in the file system, often with names matching a pattern. The glob module is useful in creating lit of files in specific directory, having a certain extension, or with a certain string as a part of file name.The pattern matching mechanism used by glob module functions follows UNIX path expansion rules. This module though doesn’t expand tilde (~) and shell variables.There are mainly three function in glob moduleglob()This function returns a list of files that match the given pattern in pathname parameter. The pathname can be absolute ... Read More

Read and write tar archive files using Python (tarfile)

George John
Updated on 26-Jun-2020 07:01:45

2K+ Views

The ‘tar’ utility was originally introduced for UNIX operating system. Its purpose is to collect multiple files in a single archive file often called tarball which makes it easy to distribute the files. Functions in tarfile module of Python’s standard library help in creating tar archives and extracting from the tarball as required. The archives can be constructed with gzip, bz2 and lzma compressions or without any compression at all.Main function defined in this module is main() using which writing to tar file or reading from it is accomplished.Open()This function returns a TarFile object corresponding to file name which is ... Read More

Deque in Java

Samual Sam
Updated on 26-Jun-2020 06:18:01

659 Views

The dequeue is a double ended queue and data elements can be added or removed from either end. The dequeue in Java is implemented using the java.util.Deque interface which is a subtype of the java.util.Queue interface.A program that demonstrates some of the methods of a dequeue is given as follows −Example Live Demoimport java.util.*; public class Example {    public static void main(String[] args) {       Deque d = new LinkedList();       d.add("5");       d.addFirst("1");       d.addLast("9");       d.push("7");       d.offer("8");       d.offerFirst("6");       d.offerLast("2"); ... Read More

Compression using the LZMA algorithm using Python (lzma)

Chandu yadav
Updated on 26-Jun-2020 06:16:10

3K+ Views

The Lempel–Ziv–Markov chain algorithm(LZMA) performs lossless data compression using a dictionary compression scheme featuring a higher compression ratio than other compression algorithms. Python’s lzma module consists of classes and convenience functions for compression and decompression of data with LZMA algorithm.Although the functionality in this module is similar to that of bz2 module, the LZMAFile class is not thread safe as compared to BZ2File class.Here again, open() function in lzma module is a very easiest way to open lzma-compressed file object.open()This function opens a LZMA-compressed file and returns a file object. The function requires two main parameters – file name and ... Read More

Advertisements