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.
  • C Offline
    C Offline
    cerr
    wrote on 17 May 2020, 02:18 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 May 2020, 05:43 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

      C 1 Reply Last reply 17 May 2020, 13:40
      4
      • S SGaist
        17 May 2020, 05:43

        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.

        C Offline
        C Offline
        cerr
        wrote on 17 May 2020, 13:40 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

        3/3

        17 May 2020, 13:40

        • Login

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