Sounds like you can split the string on a space and throw
away the right side:

s='\\serverName\C:\FolderName1\FolderName2\example.exe' -u ABC -g XYZ
p=s.split(" ", 1)[0]
print p

'\\serverName\C:\FolderName1\FolderName2\example.exe'

Larry Bates

Hitesh wrote:
> 
> 
> Hi,
> 
> Everything is working fine and dandy but I ran across another issue
> here.
> Some of the path comes with some extra chars padded at the end.
> i.e.
> 
> '\\serverName\C:\FolderName1\FolderName2\example.exe' -u ABC -g XYZ
> abcdef
> 
> Now those padded chars are not constant all the time. It can be
> anything.
> Only common denometer in each string that comes with those padded chars
> is that it is after .exe and then there is space and then 99% of the
> time it is -u and then there can be anything, I meant its dynemic after
> that.
> 
> so I am using string1.find(".exe") and could retrive the index but
> don't know how to get rid any garbase after index + 4
> 
> hj
> 
> 
> Dennis Lee Bieber wrote:
>> On 16 Aug 2006 09:00:57 -0700, "Hitesh" <[EMAIL PROTECTED]> declaimed
>> the following in comp.lang.python:
>>
>>> Thank you Fredrik. That works for a string.
>>> But I am getting list of tuples from DB.
>>>
>>> rows = [('\\serverName\C:\FolderName1\FolderName2\example.exe',),
>>> ('\\serverName\C:\FolderName1\FolderName2\example2.exe',),
>>> ('\\serverName\C:\FolderName1\FolderName2\example3.exe',),
>>> ('\\serverName\C:\FolderName1\FolderName2\example4.exe',)]
>>>
>>> I tried this:
>>> for i in rows:
>>>     row = str(i)
>>>     path = row.replace("C:" , "c$")
>>>     print path
>>>
>>> I am getting path something like
>>>
>>> ('\\serverName\c$:\FolderName1\FolderName2\example.exe',)
>>>
>>> How on the earth I can remove those paranthesis?
>>>
>>      By accessing the contents of the tuple, not the tuple itself
>>
>>>>> rows = [('\\serverName\C:\FolderName1\FolderName2\example.exe',),
>> ... ('\\serverName\C:\FolderName1\FolderName2\example2.exe',),
>> ... ('\\serverName\C:\FolderName1\FolderName2\example3.exe',),
>> ... ('\\serverName\C:\FolderName1\FolderName2\example4.exe',)]
>>>>> rows
>> [('\\serverName\\C:\\FolderName1\\FolderName2\\example.exe',),
>> ('\\serverName\\C:\\FolderName1\\FolderName2\\example2.exe',),
>> ('\\serverName\\C:\\FolderName1\\FolderName2\\example3.exe',),
>> ('\\serverName\\C:\\FolderName1\\FolderName2\\example4.exe',)]
>>>>> modRows = [itm[0].replace("C:", "C$") for itm in rows]
>>>>> modRows
>> ['\\serverName\\C$\\FolderName1\\FolderName2\\example.exe',
>> '\\serverName\\C$\\FolderName1\\FolderName2\\example2.exe',
>> '\\serverName\\C$\\FolderName1\\FolderName2\\example3.exe',
>> '\\serverName\\C$\\FolderName1\\FolderName2\\example4.exe']
>> --
>>      Wulfraed        Dennis Lee Bieber               KD6MOG
>>      [EMAIL PROTECTED]               [EMAIL PROTECTED]
>>              HTTP://wlfraed.home.netcom.com/
>>      (Bestiaria Support Staff:               [EMAIL PROTECTED])
>>              HTTP://www.bestiaria.com/
> 
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to