Dario  Schaden

Dario Schaden

1654838940

Paginate: Python Pagination Module

What is pagination?

This module helps dividing large lists of items into pages. The user is shown one page at a time and can navigate to other pages. Imagine you are offering a company phonebook and let the user search the entries. If the search result contains 23 entries but you may want to display no more than 10 entries at once. The first page contains entries 1-10, the second 11-20 and the third 21-23. See the documentation of the "Page" class for more information.

How do I use this module?

The paginate module contains extensive in-line documentation with examples.

Concerning WebHelpers

This is a standalone module. Former versions were included in the WebHelpers Python module as webhelpers.paginate and were tightly coupled with the WebHelpers and the Pylons web framework. This version aims to be useful independent of any web framework.

Subclassing Page()

This module supports pagination through list-like objects. To paginate though other types of objects you can subclass the paginate.Page() class and provide a wrapper class that defines how to access elements of that special collection.

You can find examples in other paginate_* modules like paginate_sqlalchemy. Basically you would have to provide a class that implements the init, getitem and len methods.

It is trivial to make pagination for other datastores like Elasticsearch/Solr extending the base class.

Example::

class SqlalchemyOrmWrapper(object):
    """Wrapper class to access elements of a collection."""
    def __init__(self, obj):
        self.obj = obj

    def __getitem__(self, range):
        # Return a range of objects of an sqlalchemy.orm.query.Query object
        return self.obj[range]

    def __len__(self):
        # Count the number of objects in an sqlalchemy.orm.query.Query object
        return self.obj.count()

Then you can create your own Page class that uses the above wrapper class::

class SqlalchemyOrmPage(paginate.Page):
    """A pagination page that deals with SQLAlchemy ORM objects."""
    def __init__(self, *args, **kwargs):
        super(SqlalchemyOrmPage, self).__init__(*args, wrapper_class=SqlalchemyOrmWrapper, **kwargs)

As you can see it does not do much. It basically calls paginate.Page.init and adds wrapper_class=SqlalchemyOrmWrapper as an argument. The paginate.Page instance will use that wrapper class to access the elements.

Generating HTML code for current page

Example::

p = paginate.Page([], page=15, items_per_page=15, item_count=1010)
# item_count is optional, but we pass a dummy empty resultset for this example
pattern = '$link_first $link_previous ~4~ $link_next $link_last (Page $page our of $page_count - total $item_count)'
p.pager(pattern, url='http://foo.com?x=$page', dotdot_attr={'x':5}, link_attr={'y':6}, curpage_attr={'z':77})
# *_attr arguments are optional and can be used to attach additional classes/attrs to tags

Results in::

'<a class="L" href="URL?x=1">&lt;&lt;</a> <a class="L" href="URL?x=14">&lt;</a> <a class="L" href="URL?x=1">1</a> <span class="D">..</span> <a class="L" href="URL?x=11">11</a> <a class="L" href="URL?x=12">12</a> <a class="L" href="URL?x=13">13</a> <a class="L" href="URL?x=14">14</a> <span class="C">15</span> <a class="L" href="URL?x=16">16</a> <a class="L" href="URL?x=17">17</a> <a class="L" href="URL?x=18">18</a> <a class="L" href="URL?x=19">19</a> <span class="D">..</span> <a class="L" href="URL?x=68">68</a> <a class="L" href="URL?x=16">&gt;</a> <a class="L" href="URL?x=68">&gt;&gt;</a> (Page 15 our of 68 - total items 1010)'

Using url maker to generate links to specific result ranges

You can pass url_maker Callback to generate the URL of other pages, given its numbers. Must accept one int parameter and return a URI string.

Example::

def url_maker(page_number):
    return str('foo/%s' % page_number)
page = paginate.Page(range(100), page=1, url_maker=url_maker)
eq_(page.pager(), '1 <a href="foo/2">2</a> <a href="foo/3">3</a> .. <a href="foo/5">5</a>')

Alternatively if you will not pass the link builder function, the pager() method can also accept url argument that contains URL that page links will point to. Make sure it contains the string $page which will be replaced by the actual page number. Must be given unless a url_maker is specified to init, in which case this parameter is ignored.

Using link information for custom paginator templates

If you do not like the default HTML format produced by paginator you can use link_map() function to generate a dictionary of links you can use in your own template.

Example::

p.link_map('$link_first $link_previous ~4~ $link_next $link_last (Page $page our of $page_count - total items $item_count)',url='URL?x=$page',dotdot_attr={'class':'D'}, link_attr={'class':"L"}, curpage_attr={'class':"C"})

Returns something like::

{'current_page': {'attrs': {'class': 'C'}, 'href': 'URL?x=15', 'value': 15},
 'first_page': {'attrs': {'class': 'L'}, 'href': 'URL?x=1', 'type': 'first_page', 'value': 1},
 'last_page': {'attrs': {'class': 'L'}, 'href': 'URL?x=68', 'type': 'last_page', 'value': 68},
 'next_page': {'attrs': {'class': 'L'}, 'href': 'URL?x=16', 'type': 'next_page', 'value': 16},
 'previous_page': {'attrs': {'class': 'L'}, 'href': 'URL?x=14', 'type': 'previous_page', 'value': 14},
 'range_pages': [{'attrs': {'class': 'D'}, 'href': '', 'type': 'span', 'value': '..'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=11', 'type': 'page', 'value': '11'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=12', 'type': 'page', 'value': '12'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=13', 'type': 'page', 'value': '13'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=14', 'type': 'page', 'value': '14'},
  {'attrs': {'class': 'C'}, 'href': 'URL?x=15', 'type': 'current_page', 'value': 15},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=16', 'type': 'page', 'value': '16'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=17', 'type': 'page', 'value': '17'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=18', 'type': 'page', 'value': '18'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=19', 'type': 'page', 'value': '19'},
  {'attrs': {'class': 'D'}, 'href': '', 'type': 'span', 'value': '..'}],
  'radius': 4}

Using link_tag callable to generate custom link markup

In case you want to generate custom link markup for your project - for example for use with bootstrap, pager() accepts link_tag argument that expects a callable that can be used to easly override the way links are generated.

Example::

from paginate import Page, make_html_tag

def paginate_link_tag(item):
    """
    Create an A-HREF tag that points to another page usable in paginate.
    """
    a_tag = Page.default_link_tag(item)
    if item['type'] == 'current_page':
        return make_html_tag('li', a_tag, **{'class':'active'})
    return make_html_tag('li', a_tag)

paginator.pager(
curpage_attr={'class':'current_page'},
dotdot_attr={'class':'spacer'},
symbol_first='<i class="fa fa-chevron-circle-left"></i>',
symbol_last='<i class="fa fa-chevron-circle-right"></i>',
symbol_previous='<i class="fa fa-chevron-left"></i>',
symbol_next='<i class="fa fa-chevron-right"></i>',
link_tag=paginate_link_tag)

Author: Pylons
Source Code: https://github.com/Pylons/paginate
License: MIT license

#python #pyramid 

What is GEEK

Buddha Community

Paginate: Python Pagination Module
Ray  Patel

Ray Patel

1619571780

Top 20 Most Useful Python Modules or Packages

 March 25, 2021  Deepak@321  0 Comments

Welcome to my blog, In this article, we will learn the top 20 most useful python modules or packages and these modules every Python developer should know.

Hello everybody and welcome back so in this article I’m going to be sharing with you 20 Python modules you need to know. Now I’ve split these python modules into four different categories to make little bit easier for us and the categories are:

  1. Web Development
  2. Data Science
  3. Machine Learning
  4. AI and graphical user interfaces.

Near the end of the article, I also share my personal favorite Python module so make sure you stay tuned to see what that is also make sure to share with me in the comments down below your favorite Python module.

#python #packages or libraries #python 20 modules #python 20 most usefull modules #python intersting modules #top 20 python libraries #top 20 python modules #top 20 python packages

Ray  Patel

Ray Patel

1619510796

Lambda, Map, Filter functions in python

Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.

Lambda function in python: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is

Syntax: x = lambda arguments : expression

Now i will show you some python lambda function examples:

#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map

Shardul Bhatt

Shardul Bhatt

1626775355

Why use Python for Software Development

No programming language is pretty much as diverse as Python. It enables building cutting edge applications effortlessly. Developers are as yet investigating the full capability of end-to-end Python development services in various areas. 

By areas, we mean FinTech, HealthTech, InsureTech, Cybersecurity, and that's just the beginning. These are New Economy areas, and Python has the ability to serve every one of them. The vast majority of them require massive computational abilities. Python's code is dynamic and powerful - equipped for taking care of the heavy traffic and substantial algorithmic capacities. 

Programming advancement is multidimensional today. Endeavor programming requires an intelligent application with AI and ML capacities. Shopper based applications require information examination to convey a superior client experience. Netflix, Trello, and Amazon are genuine instances of such applications. Python assists with building them effortlessly. 

5 Reasons to Utilize Python for Programming Web Apps 

Python can do such numerous things that developers can't discover enough reasons to admire it. Python application development isn't restricted to web and enterprise applications. It is exceptionally adaptable and superb for a wide range of uses.

Robust frameworks 

Python is known for its tools and frameworks. There's a structure for everything. Django is helpful for building web applications, venture applications, logical applications, and mathematical processing. Flask is another web improvement framework with no conditions. 

Web2Py, CherryPy, and Falcon offer incredible capabilities to customize Python development services. A large portion of them are open-source frameworks that allow quick turn of events. 

Simple to read and compose 

Python has an improved sentence structure - one that is like the English language. New engineers for Python can undoubtedly understand where they stand in the development process. The simplicity of composing allows quick application building. 

The motivation behind building Python, as said by its maker Guido Van Rossum, was to empower even beginner engineers to comprehend the programming language. The simple coding likewise permits developers to roll out speedy improvements without getting confused by pointless subtleties. 

Utilized by the best 

Alright - Python isn't simply one more programming language. It should have something, which is the reason the business giants use it. Furthermore, that too for different purposes. Developers at Google use Python to assemble framework organization systems, parallel information pusher, code audit, testing and QA, and substantially more. Netflix utilizes Python web development services for its recommendation algorithm and media player. 

Massive community support 

Python has a steadily developing community that offers enormous help. From amateurs to specialists, there's everybody. There are a lot of instructional exercises, documentation, and guides accessible for Python web development solutions. 

Today, numerous universities start with Python, adding to the quantity of individuals in the community. Frequently, Python designers team up on various tasks and help each other with algorithmic, utilitarian, and application critical thinking. 

Progressive applications 

Python is the greatest supporter of data science, Machine Learning, and Artificial Intelligence at any enterprise software development company. Its utilization cases in cutting edge applications are the most compelling motivation for its prosperity. Python is the second most well known tool after R for data analytics.

The simplicity of getting sorted out, overseeing, and visualizing information through unique libraries makes it ideal for data based applications. TensorFlow for neural networks and OpenCV for computer vision are two of Python's most well known use cases for Machine learning applications.

Summary

Thinking about the advances in programming and innovation, Python is a YES for an assorted scope of utilizations. Game development, web application development services, GUI advancement, ML and AI improvement, Enterprise and customer applications - every one of them uses Python to its full potential. 

The disadvantages of Python web improvement arrangements are regularly disregarded by developers and organizations because of the advantages it gives. They focus on quality over speed and performance over blunders. That is the reason it's a good idea to utilize Python for building the applications of the future.

#python development services #python development company #python app development #python development #python in web development #python software development

Ray  Patel

Ray Patel

1625859240

Difference Between Python Module and Python Package?

Difference between python module and python package?

What’s the difference between a Python module and a Python package?

Module:  It is a simple Python file that contains collections of functions and global variables and has a “.py”  extension file. It’s an executable file and we have something called a “Package” in Python to organize all these modules.

Package:  It is a simple directory which has collections of modules, i.e., a package is a directory of Python modules containing an additional init.py  file. It is the init.py  which maintains the distinction between a package and a directory that contains a bunch of Python scripts. A Package simply is a namespace. A package can also contain sub-packages.

When we import a module or a package, Python creates a corresponding object which is always of type module . This means that the dissimilarity is just at the file system level between module and package.

#technology #python #what's the difference between a python module and a python package? #python package #python module

Art  Lind

Art Lind

1602968400

Python Tricks Every Developer Should Know

Python is awesome, it’s one of the easiest languages with simple and intuitive syntax but wait, have you ever thought that there might ways to write your python code simpler?

In this tutorial, you’re going to learn a variety of Python tricks that you can use to write your Python code in a more readable and efficient way like a pro.

Let’s get started

Swapping value in Python

Instead of creating a temporary variable to hold the value of the one while swapping, you can do this instead

>>> FirstName = "kalebu"
>>> LastName = "Jordan"
>>> FirstName, LastName = LastName, FirstName 
>>> print(FirstName, LastName)
('Jordan', 'kalebu')

#python #python-programming #python3 #python-tutorials #learn-python #python-tips #python-skills #python-development