Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. How i can check if char is '\'?
Forum Updated to NodeBB v4.3 + New Features

How i can check if char is '\'?

Scheduled Pinned Locked Moved Unsolved Language Bindings
5 Posts 4 Posters 1.5k Views 2 Watching
  • 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.
  • D Offline
    D Offline
    Dl10
    wrote on 1 Jan 2018, 09:56 last edited by A Former User 1 Jan 2018, 13:28
    #1

    Hi,
    How I can check if char is '' in python?
    I add a pitcher.
    Help, tnx!

    0_1514800865169_qqqqqqqqqqq.jpg

    J 1 Reply Last reply 2 Jan 2018, 09:40
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 1 Jan 2018, 10:27 last edited by
      #2

      Hi

      \
      

      Must be escaped as

      \\
      

      https://docs.python.org/2.0/ref/strings.html

      1 Reply Last reply
      3
      • D Dl10
        1 Jan 2018, 09:56

        Hi,
        How I can check if char is '' in python?
        I add a pitcher.
        Help, tnx!

        0_1514800865169_qqqqqqqqqqq.jpg

        J Offline
        J Offline
        JonB
        wrote on 2 Jan 2018, 09:40 last edited by
        #3

        @Dl10 said in How i can check if char is '\'?:

        Hi,
        How I can check if char is '' in python?
        I add a pitcher.
        Help, tnx!

        0_1514800865169_qqqqqqqqqqq.jpg

        1. As @mrjj said, just as you have correctly doubled the \ to \\ in your second line, you must double it to \\ in the first line. This is true whether you include it inside 's or "s.

        2. Although your use of is here does work, personally I would not use it in this context and would always use == instead. See, say, https://stackoverflow.com/a/22885981/489865, which you should read & understand for how is actually works.

        3. Purely as a matter of taste, the += operator is defined for strings and does an append. I find that clearer/less error-prone than repeating the variable name on the right-hand side of the assignment.

        So personally I would write your code as:

        if char == '\\':
            file_ += '\\'
        
        1 Reply Last reply
        3
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 2 Jan 2018, 09:47 last edited by
          #4

          Hi,

          To add to @JonB: file_ += char would be even cleaner.

          Out of curiosity, why do you need to check for a backslash ? Are you manipulating file paths ?

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

          J 1 Reply Last reply 2 Jan 2018, 09:49
          0
          • S SGaist
            2 Jan 2018, 09:47

            Hi,

            To add to @JonB: file_ += char would be even cleaner.

            Out of curiosity, why do you need to check for a backslash ? Are you manipulating file paths ?

            J Offline
            J Offline
            JonB
            wrote on 2 Jan 2018, 09:49 last edited by JonB 1 Feb 2018, 09:49
            #5

            @SGaist said in How i can check if char is '\'?:

            To add to @JonB: file_ += char would be even cleaner.

            I left it using the literal rather than the "variable", as it's not obvious from the context whether OP really wants the same char he's testing for appended or always a \, if you see what I mean!

            1 Reply Last reply
            0

            1/5

            1 Jan 2018, 09:56

            • Login

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