Adding a char inside path string

Hitesh hitesh287 at gmail.com
Wed Aug 16 15:45:48 EDT 2006




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" <hitesh287 at gmail.com> 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
> 	wlfraed at ix.netcom.com		wulfraed at bestiaria.com
> 		HTTP://wlfraed.home.netcom.com/
> 	(Bestiaria Support Staff:		web-asst at bestiaria.com)
> 		HTTP://www.bestiaria.com/




More information about the Python-list mailing list