In Python 2.6, I need to create a string by concatenating INTRANET\
and a userid such as jDoe
to obtain a string INTRANET\jDoe
. This will string will be a part of a SQL query. I have tried this a number of ways but end up getting INTRANET\\jDoe
and hence my query does not return any results.
I want to do this:
a = 'INTRANET\\'
b = 'jDoe'
c = a+b ### want to get c as 'INTRANET\jDoe', not 'INTRANET\\jDoe'
Thanks
The problem seems a little different:
When I print c, I get 'INTRANET\jDoe'. But when I append c to a list (to be used in a sql query) as below:
list1 = []
list1.append(c)
print list1
>>>['INTRANET\\jDoe']
Why is this ?
The additional \
is there due to python escaping.
>>> print 'INTERNET\\jDoe'
INTERNET\jDoe
It doesn't affect the SQL you are using. You should look at another direction.
Try the following code,
s1 = "INTRANET"
s1 = s1 + "\\"
s1 = s1 + "jDoe"
print s1
This will give the correct output INTERNET\jDoe
If you simply try to view the content of the variable you will see an extra \, which is an escape sequence in python. In that case it will show,
'INTERNET\\jDoe'
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