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.6k 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 last edited by A Former User
    #1

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

    0_1514800865169_qqqqqqqqqqq.jpg

    JonBJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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

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

        0_1514800865169_qqqqqqqqqqq.jpg

        JonBJ Online
        JonBJ Online
        JonB
        wrote on 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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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

          JonBJ 1 Reply Last reply
          0
          • SGaistS SGaist

            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 ?

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #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

            • Login

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