| | |
combining strings with slash seperater
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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: 151
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.
Views: 2380 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Python
alarm aliased application beginner calculator casino character code command cursor cx-freeze definedlines development dictionary dynamic error event examples excel exe file filename float format ftp function google graphics gui homework ideas import input java launcher line linux list lists logging loop matching microphone mouse movingimageswithpygame newb number numbers obexftp output parsing path permissions phonebook port prime program programming projects py2exe pygame pygtk pyqt pysimplewizard python random recursion recursive refresh return reverse scrolledtext shebang simple skinning sprite ssh statistics string strings table terminal text thread threading time tkinter tlapse tricks tuple tutorial ubuntu unicode urllib urllib2 valueerror variable voip windows wxpython





