Found 10805 Articles for Python

What is the process of compilation and linking in python?

AmitDiwan
Updated on 12-Aug-2022 12:51:26

5K+ Views

Compilation − The source code in python is saved as a .py file which is then compiled into a format known as byte code, byte code is then converted to machine code. After the compilation, the code is stored in .pyc files and is regenerated when the source is updated. This process is known as compilation. Linking − Linking is the final phase where all the functions are linked with their definitions as the linker knows where all these functions are implemented. This process is known as linking. image compilation.jpg----- Note − Python programs are both compiled as well as ... Read More

What is calendar module in python?

AmitDiwan
Updated on 11-Aug-2022 11:35:39

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

Interpreter base classes in Python

Rishi Raj
Updated on 30-Jul-2019 22:30:26

330 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

Package extension utility in Python

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

489 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

POP3 protocol client in Python

Rishi Raj
Updated on 30-Jul-2019 22:30:26

460 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

FTP protocol client in Python

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

801 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

zipapp - Manage executable Python zip archives

Arushi
Updated on 30-Jul-2019 22:30:26

441 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

Access to the underlying platform’s identifying data in Python

Arushi
Updated on 30-Jul-2019 22:30:26

141 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

C-style parser for command line options in Python

Rishi Raj
Updated on 30-Jul-2019 22:30:26

234 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

Working with Images in Python?

George John
Updated on 30-Jul-2019 22:30:26

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

Advertisements