0% found this document useful (0 votes)
3 views

Python Microproject 1

Uploaded by

anonymous45
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python Microproject 1

Uploaded by

anonymous45
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

R C Technical Institute Ahmedabad

Python Programming
Sub-code : 4311601
Micro project
Name of student : Patel Meet J.
Branch : IT
Division : 11
Temp-Id : IT-22-019
Enrollment Number : 226400316131

Topic : List out new features of python 3.9 version and compare with older two
different versions.

When Python 2.7 was still supported, a lot of functionality in Python 3 was kept for backward
compatibility with Python 2.7. With the end of Python 2 support, these backward compatibility
layers have been removed, or will be removed soon. Most of them emitted a deprecation
writing warning for several years. For example, using collections mapping instead of
collection.abc.mapping emits a deprecation writing since Python 3.3, released in 2012.

Test your application with the -w default command-line option to see deprecation writing and
pending deprecation Waring or even with -w error to treat them as errors. Warnings Filter can
be used to ignore warnings from third-party code.

Python 3.9 is the last version providing those Python 2 backward compatibility layers, to give
more time to Python projects maintainers to organize the removal of the Python 2 support and
add support for Python 3.9.

Aliases to Abstract Base Classes in the collection module, like collections mapping alias to
collections, are kept for one last release for backward compatibility. They will be removed
from Python 3.10.

More generally, try to run your tests in the Python Development Mode which helps to prepare
your code to make it compatible with the next Python version.

Note: a number of pre-existing deprecations were removed in this version of Python as well.
Consult the Removed section.

Dictionary Merge & Update Operators


Merge (|) and update (|=) operators have been added to the built-in dict class. Those complement the
existing dict.update and {**d1, **d2} methods of merging dictionaries.
New String Methods to Remove Prefixes and Suffixes
str.removeprefix(prefix) and str.removesuffix(suffix) have been added to easily remove an unneeded
prefix or a suffix from a string. Corresponding bytes, bytearray, and collections.UserString methods
have also been added, PEP 616 for a full description. (Contributed by Dennis Sweeney in bpo-39939)

New Parser
Python 3.9 uses a new parser, based on PEG instead of LL(1). The new parser’s performance
is roughly comparable to that of the old parser, but the PEG formalism is more flexible than
LL(1) when it comes to designing new language features. We’ll start using this flexibility in
Python 3.10 and later.

The ast module uses the new parser and produces the same AST as the old parser.

In Python 3.10, the old parser will be deleted and so will all functionality that depends on it
(primarily the parser module, which has long been deprecated). In Python 3.9 only, you can
switch back to the LL(1) parser using a command line switch (-x old parser) or an
environment variable (PYTHONOLDPARSER=1).

See PEP 617 for more details. (Contributed by Guido van Rossum, Pablo Galindo and
Lysandros Nikolaou in bpo-40334.)

New Modules
zoneinfo
The zininfo module brings support for the IANA time zone database to the standard library. It
adds zoneinfo.zoneinfo, a concrete datetime.tzinfo implementation backed by the system’s
time zone data.

Example:

>>> from zoneinfo import ZoneInfo


>>> from datetime import datetime, timedelta

>>> # Daylight saving time


>>> dt = datetime(2020, 10, 31, 12, tzinfo=ZoneInfo("America/Los_Angeles"))
>>> print(dt)
2020-10-31 12:00:00-07:00
>>> dt.tzname()
'PDT'

>>> # Standard time


>>> dt += timedelta(days=7)
>>> print(dt)
2020-11-07 12:00:00-08:00
>>> print(dt.tzname())
PST
As a fall-back source of data for platforms that don’t ship the IANA database,
the tzdata module was released as a first-party package – distributed via PyPI and maintained
by the CPython core team.

See also
PEP 615-Support for the IANA Time Zone Database in the Standard Library
PEP written and implemented by Paul Ganssle

Improved modules
• pathlib
Added pathlib.Path.readlink() which acts similarly to os.readlink(). (Contributed by Girts Folkmanis
in bpo-30618)
• pdb
On Windows now Pdb supports ~/.pdbrc. (Contributed by Tim Hopper and Dan Lidral-Porter in bpo-
20523.)
• poplib
POP3 and POP3_SSL now raise a ValueError if the given timeout for their constructor is zero to
prevent the creation of a non-blocking socket. (Contributed by Dong-hee Na in bpo-39259.)
• print
pprint can now pretty-print types.SimpleNamespace. (Contributed by Carl Bordum Hansen in bpo-
37376.)
• pydoc
The documentation string is now shown not only for class, function, method etc, but for any object that
has its own __doc__ attribute. (Contributed by Serhiy Storchaka in bpo-40257.)
• random
Added a new random.Random.randbytes method: generate random bytes. (Contributed by Victor
Stinner in bpo-40286.)
• signal
Exposed the Linux-specific signal.pidfd_send_signal() for sending to signals to a process using a file
descriptor instead of a pid. (bpo-38712)
• smtplib
SMTP and SMTP_SSL now raise a ValueError if the given timeout for their constructor is zero to
prevent the creation of a non-blocking socket. (Contributed by Dong-hee Na in bpo-39259.)
LMTP constructor now has an optional timeout parameter. (Contributed by Dong-hee Na in bpo-39329.
Python 3.9
Support for the IANA Time Zone Database
Python 3.9 supports and has added a module named zoneinfo that lets you access and use the entire
Internet Assigned Numbers Authority (IANA) time zone database. By default, zoneinfo will use the
system’s time zone data if available.
Sample Code :
>>> print(datetime(2021, 7, 2, 12, 0).astimezone())
2020-07-2 12:00:00-05:00
>>> print(datetime(2021, 7, 2, 12, 0).astimezone()
... .strftime("%Y-%m-%d %H:%M:%S %Z"))
2020-07-2 12:00:00 EST
>>> print(datetime(2021, 7, 2, 12, 0).astimezone(timezone.utc))
2020-07-2 17:00:00+00:00

Merging and Updating Dictionaries


One of the coolest features that Python 3.9 possesses is merging or updating dictionaries using
operators. Two new operators, ( | ) for merge and ( |= ) to update, have been added to the built-in dict
class and hence provide ease of writing code, making it simpler and easier to understand.
Sample Code for Merge :
>>> a = {‘victor’: 1, 'article’: 2, 'python’: 3}
>>> b = {’victor’: 'dey’, 'topic’: 'python3.9’}
>>> a | b
{’article’: 2, 'python’: 3, ’victor’:’dey’, 'topic’: 'python3.9’}
>>> b | a
{’victor’: 1,’article’: 2, 'python’: 3, 'topic’:’python3.9’ }
Sample Code for Update :
>>> a |= b
>>> a
{’article’: 2, 'python’: 3,’victor’:’dey’}
New String Methods to remove Prefix and Suffixes
Python 3.9 has introduced new methods updated from the previous version to strip off prefixes and
suffixes from strings. The two new introduced methods are removeprefix() and removesuffix(). These
methods replace the previously used strip method as they showed many errors in code as per reviews.
Sample code to remove prefix :
>>> "Victor is playing outside”. Remove prefix("Victor ")‘is playing outside’
Deprecated
The disputes dictums command is now deprecated, use bdist_wheel (wheel packages) instead.
(Contributed by Hugo van Kemenade in bpo- 39586)
Currently math.factorial() accepts float instances with non-negative integer values (like 5.0). It raises
a valueerror for non-integral and negative floats. It is now deprecated. In future Python versions it will
raise a Type Error for all floats. (Contributed by Serhiy Storchaka in bpo-37315.)
The parser and symbol modules are deprecated and will be removed in future versions of Python. For
the majority of use cases, users can leverage the Abstract Syntax Tree (AST) generation and compilation
stage, using the as module.

Removed
The erroneous version at unittest.mock.__version__ has been removed.
nntplib.NNTP: xpath() and xgtitle() methods have been removed. These methods are deprecated since
Python 3.3. Generally, these extensions are not supported or not enabled by NNTP server
administrators. For xgtitle(), please
use nntplib.NNTP.descriptions() or nntplib.NNTP.description() instead. (Contributed by Dong-hee Na
in bpo-39366.)
array.array: tostring() and fromstring() methods have been removed. They were aliases
to tobytes() and frombytes(), deprecated since Python 3.2. (Contributed by Victor Stinner in bpo-
38916.)

Changes in the Python API


__import__() and importlib.util.resolve_name() now raise ImportError where it previously
raised ValueError. Callers catching the specific exception type and supporting both Python 3.9 and
earlier versions will need to catch both using except (ImportError, ValueError):.
The venv activation scripts no longer special-case when __VENV_PROMPT__ is set to "".
The select.epoll.unregister() method no longer ignores the EBADF error. (Contributed by Victor
Stinner in bpo-39239.)
The compresslevel parameter of bz2.BZ2File became keyword-only, since the buffering parameter has
been removed. (Contributed by Victor Stinner in bpo-39357.)
Simplified AST for subscription. Simple indices will be represented by their value, extended slices will
be represented as tuples. Index(value) will return a value itself, ExtSlice(slices) will
return Tuple(slices, Load()). (Contributed by Serhiy Storchaka in bpo-34822.)

New Features
PEP 573: Added PyType_FromModuleAndSpec() to associate a module with a
class; PyType_GetModule() and PyType_GetModuleState() to retrieve the module and its state;
and PyCMethod and METH_METHOD to allow a method to access the class it was defined in.
(Contributed by Marcel Plch and Petr Viktorin in bpo-38787.)
Added PyFrame_GetCode() function: get a frame code. Added PyFrame_GetBack() function: get the
frame next outer frame. (Contributed by Victor Stinner in bpo-40421.)
Added PyFrame_GetLineNumber() to the limited C API. (Contributed by Victor Stinner in bpo-
40421.)

THANK YOU -Meet Patel

You might also like