0
str1 = 'c:\documents and settings\user\desktop'
str2 = 'starcraft.exe'
print str1

I would like to know how it would be possible to add str2 to the end of str1 with a "\" inbetween the two strings. so that I end up with "c:\documents and settings\user\desktop\starcraft.exe".

Thanks

4
Contributors
3
Replies
5
Views
10 Years
Discussion Span
Last Post by ghostdog74
0

Hi!

print "\\".join((str1, str2))

or

print "%s\\%s" % (str1, str2)

If you want to make this os-independent, have a look at the os module (os.path.join might be your friend :))

Regards, mawe

1
str1 = 'c:\documents and settings\user\desktop'
str2 = 'starcraft.exe'
print str1

I would like to know how it would be possible to add str2 to the end of str1 with a "\" inbetween the two strings. so that I end up with "c:\documents and settings\user\desktop\starcraft.exe".

Thanks

one method i always use is the os.path.join() method.

dir = os.path.join("C:\\","documents and settings","user","desktop")
starcraftpath = os.path.join(dir,"starcraft.exe")

takes care of the slashes for you.

Votes + Comments
very insightful
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.