Home > Back-end >  Unwanted backslash added to string when join a list of strings
Unwanted backslash added to string when join a list of strings

Time:07-11

I have the following string:

/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections '-std=c  0x' -MD -MF bazel-out/k8-opt/bin/tensorflow/core/kernels/_objs/sparse_to_dense_op/sparse_to_dense_op.pic.d '-frandom-seed=bazel-out/k8-opt/bin/tensorflow/core/kernels/_objs/sparse_to_dense_op/sparse_to_dense_op.pic.o' -fPIC -DEIGEN_MPL2_ONLY '-DEIGEN_MAX_ALIGN_BYTES=64' -iquote . -iquote bazel-out/k8-opt/bin -iquote external/com_google_absl -iquote bazel-out/k8-opt/bin/external/com_google_absl -iquote external/nsync -iquote bazel-out/k8-opt/bin/external/nsync -iquote external/eigen_archive -iquote bazel-out/k8-opt/bin/external/eigen_archive -iquote external/gif -iquote bazel-out/k8-opt/bin/external/gif -iquote external/libjpeg_turbo -iquote bazel-out/k8-opt/bin/external/libjpeg_turbo -iquote external/com_google_protobuf -iquote bazel-out/k8-opt/bin/external/com_google_protobuf -iquote external/com_googlesource_code_re2 -iquote bazel-out/k8-opt/bin/external/com_googlesource_code_re2 -iquote external/farmhash_archive -iquote bazel-out/k8-opt/bin/external/farmhash_archive -iquote external/fft2d -iquote bazel-out/k8-opt/bin/external/fft2d -iquote external/highwayhash -iquote bazel-out/k8-opt/bin/external/highwayhash -iquote external/zlib -iquote bazel-out/k8-opt/bin/external/zlib -isystem external/nsync/public -isystem bazel-out/k8-opt/bin/external/nsync/public -isystem third_party/eigen3/mkl_include -isystem bazel-out/k8-opt/bin/third_party/eigen3/mkl_include -isystem external/eigen_archive -isystem bazel-out/k8-opt/bin/external/eigen_archive -isystem external/gif -isystem bazel-out/k8-opt/bin/external/gif -isystem external/com_google_protobuf/src -isystem bazel-out/k8-opt/bin/external/com_google_protobuf/src -isystem external/farmhash_archive/src -isystem bazel-out/k8-opt/bin/external/farmhash_archive/src -isystem external/zlib -isystem bazel-out/k8-opt/bin/external/zlib -w -DAUTOLOAD_DYNAMIC_KERNELS '-std=c  17' -DEIGEN_AVOID_STL_ARRAY -Iexternal/gemmlowp -Wno-sign-compare '-ftemplate-depth=900' -fno-exceptions '-DTENSORFLOW_USE_XLA=1' -DINTEL_MKL -msse3 -pthread '-DTENSORFLOW_USE_XLA=1' '-DINTEL_MKL=1' -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__=\"redacted\"' '-D__TIMESTAMP__=\"redacted\"' '-D__TIME__=\"redacted\"' -c tensorflow/core/kernels/sparse_to_dense_op.cc -o bazel-out/k8-opt/bin/tensorflow/core/kernels/_objs/sparse_to_dense_op/sparse_to_dense_op.pic.o)"

When I split this string based on white space and then join them using the following code:

string_new = ' '.join(string_old)

The string converts as:

-U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 \'-D_FORTIFY_SOURCE=1\' -DNDEBUG -ffunction-sections -fdata-sections \'-std=c  0x\' -MD -MF bazel-out/k8-opt/bin/tensorflow/core/kernels/_objs/sparse_to_dense_op/sparse_to_dense_op.pic.d \'-frandom-seed=bazel-out/k8-opt/bin/tensorflow/core/kernels/_objs/sparse_to_dense_op/sparse_to_dense_op.pic.o\' -fPIC -DEIGEN_MPL2_ONLY \'-DEIGEN_MAX_ALIGN_BYTES=64\' -iquote . -iquote bazel-out/k8-opt/bin -iquote external/com_google_absl -iquote bazel-out/k8-opt/bin/external/com_google_absl -iquote external/nsync -iquote bazel-out/k8-opt/bin/external/nsync -iquote external/eigen_archive -iquote bazel-out/k8-opt/bin/external/eigen_archive -iquote external/gif -iquote bazel-out/k8-opt/bin/external/gif -iquote external/libjpeg_turbo -iquote bazel-out/k8-opt/bin/external/libjpeg_turbo -iquote external/com_google_protobuf -iquote bazel-out/k8-opt/bin/external/com_google_protobuf -iquote external/com_googlesource_code_re2 -iquote bazel-out/k8-opt/bin/external/com_googlesource_code_re2 -iquote external/farmhash_archive -iquote bazel-out/k8-opt/bin/external/farmhash_archive -iquote external/fft2d -iquote bazel-out/k8-opt/bin/external/fft2d -iquote external/highwayhash -iquote bazel-out/k8-opt/bin/external/highwayhash -iquote external/zlib -iquote bazel-out/k8-opt/bin/external/zlib -isystem external/nsync/public -isystem bazel-out/k8-opt/bin/external/nsync/public -isystem third_party/eigen3/mkl_include -isystem bazel-out/k8-opt/bin/third_party/eigen3/mkl_include -isystem external/eigen_archive -isystem bazel-out/k8-opt/bin/external/eigen_archive -isystem external/gif -isystem bazel-out/k8-opt/bin/external/gif -isystem external/com_google_protobuf/src -isystem bazel-out/k8-opt/bin/external/com_google_protobuf/src -isystem external/farmhash_archive/src -isystem bazel-out/k8-opt/bin/external/farmhash_archive/src -isystem external/zlib -isystem bazel-out/k8-opt/bin/external/zlib -w -DAUTOLOAD_DYNAMIC_KERNELS \'-std=c  17\' -DEIGEN_AVOID_STL_ARRAY -Iexternal/gemmlowp -Wno-sign-compare \'-ftemplate-depth=900\' -fno-exceptions \'-DTENSORFLOW_USE_XLA=1\' -DINTEL_MKL -msse3 -pthread \'-DTENSORFLOW_USE_XLA=1\' \'-DINTEL_MKL=1\' -fno-canonical-system-headers -Wno-builtin-macro-redefined \'-D__DATE__="redacted"\' \'-D__TIMESTAMP__="redacted"\' \'-D__TIME__="redacted"\' -c tensorflow/core/kernels/sparse_to_dense_op.cc

As you can see, there are multiple backslashes added to the string. Any idea why this happens?

CodePudding user response:

I just figured out why I have unwanted backslashes. The reason is that in my list of strings, there are some string items that are in double quotation, when I join those items using white space, and in the joined string, I have backslashes in place of double quotation.

  • Related