- 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
Found 10784 Articles for Python
3K+ Views
The Calendar module in Python is used to display calendars and provides useful Built-in functions for displaying week, week day, month, month of the year, and other operations. By default, these calendars have Monday as the first day of the week, and Sunday as the last. Display the Calendar of an Year To display the calendar of an year, use the calendar() method and set year as the parameter − Example import calendar # Set the year year = 2022 # Display the calendar print(calendar.calendar(year)) Output ... Read More
346 Views
Python's interactive mode works on the principle of REPL (Read - Evaluate - Print - Loop). The code module in Python's standard library provides classes nd convenience functions to set up REPL environment from within Python script.Following two classes are defined in code module:InteractiveInterpreter: This class deals with parsing and interpreter state (the user’s namespace)InteractiveConsole: Closely emulate the behavior of the interactive Python interpreter.Two convenience functions in the module are:interact(): Convenience function to run a read-eval-print loop.compile_command(): This function is useful for programs that want to emulate Python’s interpreter main loop (the REPL).Interactive Interpreter methodsrunsource(): Compile and run some source ... Read More
528 Views
When you want to add to the module search path for a specific package and work with resources included in a package, you need to use pkgutil module from Python library. It includes functions for changing the import rules for Python packages. It is also possible to load non-code resources from files distributed within a package.extend_path(path, name)Extend the search path for the modules which comprise a package. Intended use is to place the following code in a package’s __init__.pyimport pkgutil __path__ = pkgutil.extend_path(__path__, __name__)extend_path() scans sys.path for directories that include a subdirectory named for the package given as the second ... Read More
501 Views
The poolib module from Python's standard library defines POP3 and POP3_SSL classes. POP3 class encapsulates a connection to a POP3 server and implements the protocol as defined in RFC 1939. POP3_SSL classsupports POP3 servers that use SSL as an underlying protocol layer.POP3 protocolis obsolescent as its implementation quality of POP3 servers is quite poor. If your mailserver supports IMAP, it is recommended to use the imaplib.IMAP4 class.Both classes have following methods defined −getwelcome()Returns the greeting string sent by the POP3 server.user(username)Send user command, response should indicate that a password is required.pass_(password)Send password.Stat()Get mailbox status. The result contains 2 integers: (message ... Read More
832 Views
The all important The FTP class in ftplib module implements the client side of the FTP protocol.To establish connection with a FTP server, obtain FTP object.con=FTP(hostname)The FTP class supports following methods −connect()Connect to the given host and port. The default port number is 21, as specified by the FTP protocol specification.Getwelcome()Return the welcome message sent by the server in reply to the initial connection.login(user='anonymous', passwd='', acct='')Log in as the given user. The passwd and acct parameters are optional and default to the empty string. If no user is specified, it defaults to 'anonymous'. If user is 'anonymous', the default passwd ... Read More
477 Views
The zipapp module has been introduced in Python's standard library since ver 3.5. This module is used to manage the creation of zip files containing Python code, which can be executed directly by the Python interpreter. The module provides both a Command-Line Interface and a programming interface.To use zipapp module programmatically, we should have a module in which main function is present. The executable archive is built by following command −python -m zipapp myapp -m "example:main"Here, the current path should have a folder called myapp. In this folder, there should be example.py which must have main() function.Create myapp folder and ... Read More
154 Views
Functions in the platform module help us probe the underlying platform’s hardware, operating system, and interpreter version information.architecture()This function queries the given executable (defaults to the Python interpreter executable) for various architecture information.>>> import platform >>> platform.architecture() ('64bit', '')machine()This function returns the machine type, e.g. 'i386'. An empty string is returned if the value cannot be determined.>>> platform.machine() 'x86_64'node()This function returns the computer’s network name.>>> platform.node() 'malhar-ubuntu'platform(aliased=0, terse=0)This function returns a single string identifying the underlying platform.>>> platform.platform() 'Linux-4.13.0-46-generic-x86_64-with-debian-stretch-sid'processor()This function returns the (real) processor name.>>> platform.processor() 'x86_64'python_build()This function returns a tuple (buildno, builddate)>>> platform.python_build() ('default', 'Oct 13 2017 12:02:49')python_compiler()This function ... Read More
248 Views
Python’s sys module provides access to any command-line arguments via the sys.argv. sys.argv is the list of command-line arguments and sys.argv[0] is the program ie. the script name.Save following code as args.pyimport sys print ('argument list', sys.argv)Execute above script from command line as follows:C:\python37>python args.py 11 22 argument list ['args.py', '11', '22']The getopt module has funcions toparse the command line arguments in sys.argv. It supports the same conventions as the Unix getopt() function (including the special meanings of arguments of the form ‘-‘ and ‘--‘).API is designed to be familiar to users of the C getopt() function.getopt(args, shortopts, longopts=[])Parses command ... Read More
3K+ Views
One of the most popular and considered as default library of python for image processing is Pillow. Pillow is an updated version of the Python Image Library or PIL and supports a range of simple and advanced image manipulation functionality. It is also the basis for simple image support in other Python libraries such as sciPy and Matplotlib.Installing PillowBefore we start, we need python and pillow. Incase of Linux, pillow will probably be there already, since major flavour of linux including Fedora, Debian/Ubuntu and ArchLinux includes Pillow in packages that previously contained PIL.The easiest way to install it is to ... Read More
1K+ Views
A common mistake for people new to programming is a misunderstanding of the way that boolean operators works, which stems from the way the python interpreter reads these expressions. For example, after initially learning about "and " and "or" statements, one might assume that the expression X = (‘x’ or ‘y’) would check to see if the variable X was equivalent to one of the strings ‘a’ or ‘b’. This is not so. To understand, what i’m trying to say, start an interactive session with the interpreter and enter the following expressions:>>> 'x' == ('x' or 'y') True >>> 'y' ... Read More