question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cycler object has no attribute 'next' in Python 3.4.3

See original GitHub issue

Python 3.4.3, Pyramid 1.5.7, Jinja 2.8 (2.7.3 produce the same error)

I got a weird exception

jinja2.exceptions.UndefinedError: 'jinja2.utils.Cycler object' has no attribute 'next'

in string

<li class='struct-item{{ row.next() }}' data-id="{{ category._id }}" 
data-owner="{{ category.owner }}">

template:

<ul>
{% set row = cycler('', ' back') %}
{% for category in categories[0] recursive %}
    <li class='struct-item{{ row.next() }}' data-id="{{ category._id }}" 
    data-owner="{{ category.owner }}">
        <div class="title">{{ category.caption }}</div>
        <div class="action">
            {% if not loop.depth0 %}
            <a href='#' class="category-add">
                <img src='/static/admin/img/action-add.png'>
             </a>
             {% endif %}
            <a href='#' class="category-edit">
                <img src='/static/admin/img/action-edit.png'>
            </a>
            <a href='#' class="category-delete">
                <img src='/static/admin/img/action-delete.png'>
            </a>
        </div>
    </li>
    {% if category._id in categories %}
        <ul class="children">{{ loop(categories[category._id]) }}</ul>
    {% endif %}
{% endfor %}
</ul>

When I make a call print(dir(self)) in a constructor Cycler, echo was

['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', 
 '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', 
 '__module__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', 
 '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 
 'current', 'items', 'pos', 'reset']

that means Cycler object really has no next method. Temporary fix is jinja2.utils.Cycler.next = jinja2.utils.Cycler.__next__ in a Pyramidmain method, but…

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tark-hiddencommented, Sep 18, 2015

Hey guys. This issue has been opened more than month ago.

This can be fixed by adding almost the same function implements_iterator in code block if not PY2 in _compat.py.

    def implements_iterator(cls):
        cls.next = cls.__next__
        return cls
0reactions
tark-hiddencommented, Sep 18, 2015

And I’m very sorry, I was wrong. In Python 2.7.3 current release works fine, as expected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'Cycler' object has no attribute 'change_key'
Just checked the version of cycler and it was outdated. Just update cycler with. sudo pip3 install --upgrade cycler.
Read more >
3. Data model — Python 3.11.1 documentation
Objects, values and types: Objects are Python's abstraction for data. All data in a Python program is represented by objects or by relations...
Read more >
ℎ - Nick Coghlan's Python Notes
the next major version of Red Hat Enterprise Linux (previously this had been ... AttributeError: 'bytes' object has no attribute 'encode'.
Read more >
Customizing Matplotlib with style sheets and rcParams
Runtime rc settings#. You can dynamically change the default rc (runtime configuration) settings in a python script or interactively from the python shell....
Read more >
Matplotlib pane throwing AttributeError when interactive=True
I have a panel app utilizing Matplotlib panes. ... flush_figures) AttributeError: 'NoneType' object has no attribute 'events'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found