- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Rajendra Dharmkar has Published 452 Articles
Rajendra Dharmkar
131 Views
The timetuple() method of datetime.date instances returns an object of type time.struct_time. The struct_time is a named tuple object (A named tuple object has attributes that can be accessed by an index or by name). exampleYou can print the complete time tuple by simply passing it to print.import datetime todaysDate = ... Read More
Rajendra Dharmkar
2K+ Views
The floating-point numbers in units of seconds for time interval are indicated by Tick in python. Particular instants in time are expressed in seconds since 12:00am, January 1, 1970(epoch). You can use the time module to use functions for working with times, and for converting between representations. For example, if ... Read More
Rajendra Dharmkar
2K+ Views
Character classA "character class", or a "character set", is a set of characters put in square brackets. The regex engine matches only one out of several characters in the character class or character set. We place the characters we want to match between square brackets. If you want to match ... Read More
Rajendra Dharmkar
1K+ Views
The following code shows how space is added before and after the pipe '|' character in given string. Exampleimport re regex = r'\b[|:]\b' s = "abracadabra abraca|dabara | abra cadabra abra ca dabra abra ca dabra abra" print(re.sub(regex, ' \g ', s))OutputThis gives the outputabracadabra abraca | dabara | abra cadabra ... Read More
Rajendra Dharmkar
10K+ Views
The re.groups() methodThis method returns a tuple containing all the subgroups of the match, from 1 up to however many groups are in the pattern. The default argument is used for groups that did not participate in the match; it defaults to None. In later versions (from 1.5.1 on), a ... Read More
Rajendra Dharmkar
1K+ Views
The simplest way to use SSH using python is to use paramiko. You can install it using −$ pip install paramikoTo use paramiko, ensure that you have correctly set up SSH keys(https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html) on the host machine and when running the python script, these keys are accessible. Once that is done ... Read More
Rajendra Dharmkar
282 Views
You can use the ftplib module in Python. It allows you to write programs that perform a variety of automated FTP jobs. You can easily connect to a FTP server to retrieve files and process them locally.exampleimport ftplib ftp = ftplib.FTP('ftp.yourserver.com', 'yourusername', 'your@email.address') print "File List: " files = ftp.dir() ... Read More
Rajendra Dharmkar
13K+ Views
The easiest way to copy files from one server to another over ssh is to use the scp command. For calling scp you'd need the subprocess module. exampleimport subprocess p = subprocess.Popen(["scp", "my_file.txt", "username@server:path"]) sts = os.waitpid(p.pid, 0)You need the waitpid call to wait for the copying to complete.Another solution is ... Read More
Rajendra Dharmkar
649 Views
To touch all the files recursively, you need to walk the directory tree using os.walk and add touch all the files in it using os.utime(path_to_file). exampleimport os # Recursively walk the tree for root, dirs, files in os.walk(path): for file in files: # Set utime ... Read More
Rajendra Dharmkar
815 Views
You can use the tempfile module to create a unique temporary directory in the most secure manner possible. There are no race conditions in the directory’s creation. The directory is readable, writable and searchable only by the creating user ID. Note that the user of mkdtemp() is responsible for deleting ... Read More