| | |
combining strings with slash seperater
![]() |
Python Syntax (Toggle Plain Text)
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
•
•
Join Date: Sep 2005
Posts: 133
Reputation:
Solved Threads: 58
Hi!
or
If you want to make this os-independent, have a look at the os module (os.path.join might be your friend
)
Regards, mawe
Python Syntax (Toggle Plain Text)
print "\\".join((str1, str2))
Python Syntax (Toggle Plain Text)
print "%s\\%s" % (str1, str2)
)Regards, mawe
Python Syntax (Toggle Plain Text)
>>> str3 = str1 + '\\' + str2 >>> print str3 c:\documents and settings\user\desktop\starcraft.exe >>>
•
•
Join Date: Apr 2006
Posts: 148
Reputation:
Solved Threads: 40
•
•
•
•
Python Syntax (Toggle Plain Text)
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
Python Syntax (Toggle Plain Text)
dir = os.path.join("C:\\","documents and settings","user","desktop") starcraftpath = os.path.join(dir,"starcraft.exe")
![]() |
Similar Threads
- Please help me compare strings (Java)
- C++ handling of strings in a boolean expression (C++)
- Compare strings... (C++)
- comparing two strings with linear search.. (Java)
- JSP and Oracle (JSP)
Other Threads in the Python Forum
- Previous Thread: can't figure out loop
- Next Thread: Too many questions.
| Thread Tools | Search this Thread |
alarm app beginner cipher cmd coordinates cx-freeze data decimals development dictionary directory dynamic error examples feet file float format function generator getvalue gui halp homework http images import input ip itunes java keycontrol leftmouse line linux list lists loop maintain maze millimeter module mouse mysqldb number numbers output parsing path port prime programming projects push py2exe pygame pyglet pymailer pyqt python queue random recursion schedule screensaverloopinactive script scrolledtext slicenotation split sqlite ssh string strings sudokusolver table terminal text thread threading time tlapse tuple tutorial ubuntu unicode url urllib urllib2 variable variables ventrilo verify vigenere web webservice wikipedia wx.wizard wxpython xlwt





