[Tutor] string fomatting
Kent Johnson
kent37 at tds.net
Sun Feb 1 13:35:20 CET 2009
On Sat, Jan 31, 2009 at 1:44 PM, Jay Jesus Amorin <jay.amorin at gmail.com> wrote:
> Thanks bob.
>
> I want to search any characters in test after https://www.localhost.org/ and
> the search will end after it finds another /
>
> and when i print it will display testmodule.
If *all* you want is the first element of the path, you can get that
simply by splitting the string on / and retrieving the correct piece:
In [28]: test
Out[28]: 'https://www.localhost.org/testmodule/dev/trunk/admin/sql/mytest.sql'
In [29]: test.split('/')
Out[29]:
['https:',
'',
'www.localhost.org',
'testmodule',
'dev',
'trunk',
'admin',
'sql',
'mytest.sql']
In [30]: test.split('/')[3]
Out[30]: 'testmodule'
Kent
More information about the Tutor
mailing list