Python has a simple concatenation using the +
operator. But I am observing something unusual.
I tried :
final_path = '/home/user/' + path + '/output'
Where path
is a staring variable I want to concatenate.
print final_path
gives me:
/home/user/path
/output
Instead of /home/user/path/output
Why is going to the next line. Is the forward slash causing the issue. I tried using the escape character as well. but It does not work.
From the looks of your code, it may be the variable path
that is the problem. Check to see if path
has a new line at the end. Escape characters start with a backslash \
and not a forward slash /
.
As victor said, your path variable has '\n' added at the end implicitly, so you can do such a trick to overcome the problem:
final_path = '/home/user/' + path.strip('\n') + '/output'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With