Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

added 8 characters in body
Source Link
TigerhawkT3
  • 49.4k
  • 6
  • 66
  • 101

If the given code precisely matches what you have, it's no wonder it's having problems. You're enclosing it with double quotes, but the string contains double quotes. Left as is, the string will end when the interpreter sees the next double quote, then there will be a bunch of terms it doesn't recognize (like DIAMETER and POWDER), then eventually another string will begin, and so on.

You need to either escape the string's double quotes with a backslash, or enclose the string with three quotes on each side.

ExampleText = "MINIMUM TRACK FASTENING SHALL BE 0.145\" DIAMETER POWDER ACTUATED FASTENERS (P.A.F.S) SPACED ON 8\" CENTERS FOR BEARING WALLS, AND AT 12\" O.C. FOR NON-LOAD BEARING WALLS (U.N.O.), WITH 1 1/2\" MINIMUM PENETRATION INTO CONCRETE. AT X-BRACED SHEAR WALLS, TRACK SHALL BE ATTACHED PER DETAILS. At Infinity Shear Panels (ISP’S) attach to slab w/ 0.145\" x 1 1/2\" powder actuated fasteners spaced on 4\" centers (HILTI DS 37 P10 or equal) -OR- (6) 3/8\" DIA. 2205 expansion anchors w/ 2 1/2\" min. embedment - OR-Simpson \"Titen\" screws @ 6\" o.c."

or

ExampleText = """MINIMUM TRACK FASTENING SHALL BE 0.145" DIAMETER POWDER ACTUATED FASTENERS (P.A.F.S) SPACED ON 8" CENTERS FOR BEARING WALLS, AND AT 12" O.C. FOR NON-LOAD BEARING WALLS (U.N.O.), WITH 1 1/2" MINIMUM PENETRATION INTO CONCRETE. AT X-BRACED SHEAR WALLS, TRACK SHALL BE ATTACHED PER DETAILS. At Infinity Shear Panels (ISP’S) attach to slab w/ 0.145" x 1 1/2" powder actuated fasteners spaced on 4" centers (HILTI DS 37 P10 or equal) -OR- (6) 3/8" DIA. 2205 expansion anchors w/ 2 1/2" min. embedment - OR-Simpson "Titen" screws @ 6" o.c."""

SO's built-in syntax highlighting indicates that your sample consists of several strings, while mine is one continuous string.

Also, the string contains only forward slashes, no backslashes, so there's no problem there. If there were backslashes and you wanted to resolve that, you would precede the string with an r to denote a raw string: r'hello\nworld prints as hello\nworld. The only thing raw strings can't handle is when the last character in the string is a backslash. Solve that by adding that afterward: r'C:\Users\jsmith' + '\\' or r'C:\Users\jsmith' '\\' (the + isn't strictly necessary when concatenating literal strings).

This is only necessary if you're writing the string into your source code. Strings from external sources like input() or files are processed automatically.

If the given code precisely matches what you have, it's no wonder it's having problems. You're enclosing it with double quotes, but the string contains double quotes. Left as is, the string will end when the interpreter sees the next double quote, then there will be a bunch of terms it doesn't recognize (like DIAMETER and POWDER), then eventually another string will begin, and so on.

You need to either escape the string's double quotes with a backslash, or enclose the string with three quotes on each side.

ExampleText = "MINIMUM TRACK FASTENING SHALL BE 0.145\" DIAMETER POWDER ACTUATED FASTENERS (P.A.F.S) SPACED ON 8\" CENTERS FOR BEARING WALLS, AND AT 12\" O.C. FOR NON-LOAD BEARING WALLS (U.N.O.), WITH 1 1/2\" MINIMUM PENETRATION INTO CONCRETE. AT X-BRACED SHEAR WALLS, TRACK SHALL BE ATTACHED PER DETAILS. At Infinity Shear Panels (ISP’S) attach to slab w/ 0.145\" x 1 1/2\" powder actuated fasteners spaced on 4\" centers (HILTI DS 37 P10 or equal) -OR- (6) 3/8\" DIA. 2205 expansion anchors w/ 2 1/2\" min. embedment - OR-Simpson \"Titen\" screws @ 6\" o.c."

or

ExampleText = """MINIMUM TRACK FASTENING SHALL BE 0.145" DIAMETER POWDER ACTUATED FASTENERS (P.A.F.S) SPACED ON 8" CENTERS FOR BEARING WALLS, AND AT 12" O.C. FOR NON-LOAD BEARING WALLS (U.N.O.), WITH 1 1/2" MINIMUM PENETRATION INTO CONCRETE. AT X-BRACED SHEAR WALLS, TRACK SHALL BE ATTACHED PER DETAILS. At Infinity Shear Panels (ISP’S) attach to slab w/ 0.145" x 1 1/2" powder actuated fasteners spaced on 4" centers (HILTI DS 37 P10 or equal) -OR- (6) 3/8" DIA. 2205 expansion anchors w/ 2 1/2" min. embedment - OR-Simpson "Titen" screws @ 6" o.c."""

SO's built-in syntax highlighting indicates that your sample consists of several strings, while mine is one continuous string.

Also, the string contains only forward slashes, no backslashes, so there's no problem there. If there were backslashes and you wanted to resolve that, you would precede the string with an r to denote a raw string: r'hello\nworld prints as hello\nworld. The only thing raw strings can't handle is when the last character in the string is a backslash. Solve that by adding that afterward: r'C:\Users\jsmith' + '\\' or r'C:\Users\jsmith' '\\' (the + isn't strictly necessary when concatenating strings).

This is only necessary if you're writing the string into your source code. Strings from external sources like input() or files are processed automatically.

If the given code precisely matches what you have, it's no wonder it's having problems. You're enclosing it with double quotes, but the string contains double quotes. Left as is, the string will end when the interpreter sees the next double quote, then there will be a bunch of terms it doesn't recognize (like DIAMETER and POWDER), then eventually another string will begin, and so on.

You need to either escape the string's double quotes with a backslash, or enclose the string with three quotes on each side.

ExampleText = "MINIMUM TRACK FASTENING SHALL BE 0.145\" DIAMETER POWDER ACTUATED FASTENERS (P.A.F.S) SPACED ON 8\" CENTERS FOR BEARING WALLS, AND AT 12\" O.C. FOR NON-LOAD BEARING WALLS (U.N.O.), WITH 1 1/2\" MINIMUM PENETRATION INTO CONCRETE. AT X-BRACED SHEAR WALLS, TRACK SHALL BE ATTACHED PER DETAILS. At Infinity Shear Panels (ISP’S) attach to slab w/ 0.145\" x 1 1/2\" powder actuated fasteners spaced on 4\" centers (HILTI DS 37 P10 or equal) -OR- (6) 3/8\" DIA. 2205 expansion anchors w/ 2 1/2\" min. embedment - OR-Simpson \"Titen\" screws @ 6\" o.c."

or

ExampleText = """MINIMUM TRACK FASTENING SHALL BE 0.145" DIAMETER POWDER ACTUATED FASTENERS (P.A.F.S) SPACED ON 8" CENTERS FOR BEARING WALLS, AND AT 12" O.C. FOR NON-LOAD BEARING WALLS (U.N.O.), WITH 1 1/2" MINIMUM PENETRATION INTO CONCRETE. AT X-BRACED SHEAR WALLS, TRACK SHALL BE ATTACHED PER DETAILS. At Infinity Shear Panels (ISP’S) attach to slab w/ 0.145" x 1 1/2" powder actuated fasteners spaced on 4" centers (HILTI DS 37 P10 or equal) -OR- (6) 3/8" DIA. 2205 expansion anchors w/ 2 1/2" min. embedment - OR-Simpson "Titen" screws @ 6" o.c."""

SO's built-in syntax highlighting indicates that your sample consists of several strings, while mine is one continuous string.

Also, the string contains only forward slashes, no backslashes, so there's no problem there. If there were backslashes and you wanted to resolve that, you would precede the string with an r to denote a raw string: r'hello\nworld prints as hello\nworld. The only thing raw strings can't handle is when the last character in the string is a backslash. Solve that by adding that afterward: r'C:\Users\jsmith' + '\\' or r'C:\Users\jsmith' '\\' (the + isn't strictly necessary when concatenating literal strings).

This is only necessary if you're writing the string into your source code. Strings from external sources like input() or files are processed automatically.

Source Link
TigerhawkT3
  • 49.4k
  • 6
  • 66
  • 101

If the given code precisely matches what you have, it's no wonder it's having problems. You're enclosing it with double quotes, but the string contains double quotes. Left as is, the string will end when the interpreter sees the next double quote, then there will be a bunch of terms it doesn't recognize (like DIAMETER and POWDER), then eventually another string will begin, and so on.

You need to either escape the string's double quotes with a backslash, or enclose the string with three quotes on each side.

ExampleText = "MINIMUM TRACK FASTENING SHALL BE 0.145\" DIAMETER POWDER ACTUATED FASTENERS (P.A.F.S) SPACED ON 8\" CENTERS FOR BEARING WALLS, AND AT 12\" O.C. FOR NON-LOAD BEARING WALLS (U.N.O.), WITH 1 1/2\" MINIMUM PENETRATION INTO CONCRETE. AT X-BRACED SHEAR WALLS, TRACK SHALL BE ATTACHED PER DETAILS. At Infinity Shear Panels (ISP’S) attach to slab w/ 0.145\" x 1 1/2\" powder actuated fasteners spaced on 4\" centers (HILTI DS 37 P10 or equal) -OR- (6) 3/8\" DIA. 2205 expansion anchors w/ 2 1/2\" min. embedment - OR-Simpson \"Titen\" screws @ 6\" o.c."

or

ExampleText = """MINIMUM TRACK FASTENING SHALL BE 0.145" DIAMETER POWDER ACTUATED FASTENERS (P.A.F.S) SPACED ON 8" CENTERS FOR BEARING WALLS, AND AT 12" O.C. FOR NON-LOAD BEARING WALLS (U.N.O.), WITH 1 1/2" MINIMUM PENETRATION INTO CONCRETE. AT X-BRACED SHEAR WALLS, TRACK SHALL BE ATTACHED PER DETAILS. At Infinity Shear Panels (ISP’S) attach to slab w/ 0.145" x 1 1/2" powder actuated fasteners spaced on 4" centers (HILTI DS 37 P10 or equal) -OR- (6) 3/8" DIA. 2205 expansion anchors w/ 2 1/2" min. embedment - OR-Simpson "Titen" screws @ 6" o.c."""

SO's built-in syntax highlighting indicates that your sample consists of several strings, while mine is one continuous string.

Also, the string contains only forward slashes, no backslashes, so there's no problem there. If there were backslashes and you wanted to resolve that, you would precede the string with an r to denote a raw string: r'hello\nworld prints as hello\nworld. The only thing raw strings can't handle is when the last character in the string is a backslash. Solve that by adding that afterward: r'C:\Users\jsmith' + '\\' or r'C:\Users\jsmith' '\\' (the + isn't strictly necessary when concatenating strings).

This is only necessary if you're writing the string into your source code. Strings from external sources like input() or files are processed automatically.

lang-py

AltStyle によって変換されたページ (->オリジナル) /