Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. 'str' object has no attribute 'chop'
QtWS25 Last Chance

'str' object has no attribute 'chop'

Scheduled Pinned Locked Moved Solved Mobile and Embedded
pyqt4python2
3 Posts 2 Posters 684 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • cerrC Offline
    cerrC Offline
    cerr
    wrote on last edited by cerr
    #1

    Hi,
    I'm working on a pin tab which has a key to undo the last entered digit, my on click function looks something like:

    def on_click(self,val):
            if val == DEL:
                pin = self.pinlab.text()
                self.pinlab.setText(pin.chop(1))
            else:
                self.pinlab.setText(self.pinlab.text() + str (val))
    

    but it somehow doesn't like the usage of chop(1), I keep getting:

    AttributeError: 'str' object has no attribute 'chop'
    

    What am I doing wrong, could anyone here point out my mistake?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You write your code as if you where using QString objects. With either PySide2 or PyQt5 you'll have Python str objects. You need to translate these bits.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      cerrC 1 Reply Last reply
      4
      • SGaistS SGaist

        Hi,

        You write your code as if you where using QString objects. With either PySide2 or PyQt5 you'll have Python str objects. You need to translate these bits.

        cerrC Offline
        cerrC Offline
        cerr
        wrote on last edited by
        #3

        @SGaist said in 'str' object has no attribute 'chop':

        Hi,

        You write your code as if you where using QString objects. With either PySide2 or PyQt5 you'll have Python str objects. You need to translate these bits.

        rrrrrrright, Duh!
        I'm still kind of new to writing Qt in Python...
        changing my code to using pin[:-1] works as expected! Thanks!

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved