I would do like this,

1.
import os.path
testPath = '/here/is/my/path/here/is/my/path/here/is/my/path'
path = os.path.split(testPath)[0]

2.
from xml.dom import minidom
doc = minidom.parse('/users/makoto/documents/test.xml' )
value = doc.getElementsByTagName('xmlTest')[0].getAttribute('myVersion')


On 2010/03/05, at 9:53, efecto wrote:

> i got it thank you all for help.
> a bit dirty though.
> 
> value = re.split(' ', xml[xml.index(tag)+len(tag):len(xml)])
> value = value[0].replace('="','').replace('"','')
> print value
> 
> On Mar 5, 9:38 pm, Adam Mechtley <[email protected]> wrote:
>> Yeah for that you need a different pattern, since the pipe character is not
>> counted as part of a word (only alphanumeric and underscore)
>> 
>> 
>> 
>> On Fri, Mar 5, 2010 at 2:00 AM, Daisuke Maki <[email protected]> wrote:
>>> oops.
>> 
>>> What about this one?
>> 
>>> import re
>>> xml = '<xmlTest yo345="wdwdd" test0="12345" test1="m|yP|ic" test2="1234"
>>> myVersion="6">'
>>> tag = 'test1' #to get myPic
>>> value = re.split('\W+', xml[xml.index(tag)+len(tag):len(xml)])[1]
>>> print value
>>> # m
>> 
>>> On Fri, Mar 5, 2010 at 7:37 PM, Adam Mechtley 
>>> <[email protected]>wrote:
>> 
>>>> No idea; works for me if I paste in what you just typed here
>> 
>>>> On Fri, Mar 5, 2010 at 12:32 AM, efecto <[email protected]> wrote:
>> 
>>>>> Thanks Adam. That worked a treat! I gotta rememebr that.
>> 
>>>>> Another question.
>>>>> When i tried the following
>> 
>>>>> import re
>>>>> xml = '<xmlTest test1="myPic" test2="1234" myVersion="6">'
>>>>> tag = 'test1' #to get myPic
>>>>> value = re.split('\W+', xml[xml.index(tag)+len(tag):len(xml)])[1]
>> 
>>>>> I wanted to get the value 'myPic' but it didnt seem to work. I guess
>>>>> splitting with '\W+' wasn't for this.
>> 
>>>>> Cheers,
>>>>> D
>> 
>>>>> On Mar 5, 5:55 pm, Adam Mechtley <[email protected]> wrote:
>>>>>> I'm sure there are plenty of other ways, but I would do:
>> 
>>>>>> 1.
>>>>>> testPath[0:testPath.rindex('/')] or testPath[0:testPath.rindex('/')+1]
>>>>> if
>>>>>> you really want that trailing slash for some reason
>> 
>>>>>> 2.
>>>>>> import re
>>>>>> xml = '<xmlTest test1="myPic" test2="1234" myVersion="6">'
>>>>>> tag = 'myVersion'
>>>>>> value = re.split('\W+', xml[xml.index(tag)+len(tag):len(xml)])[1]
>> 
>>>>>> On Thu, Mar 4, 2010 at 10:27 PM, efecto <[email protected]> wrote:
>>>>>>> 1.
>>>>>>> testPath = '/here/is/my/path/here/is/my/path/here/is/my/path'
>>>>>>> I want to get this path from the variable above.
>>>>>>> /here/is/my/path/here/is/my/path/here/is/my/
>>>>>>> I could use testPath.split('/') then manually create the path but i
>>>>>>> think they may be an easier way to generate the string.
>> 
>>>>>>> 2.
>>>>>>> I'm reading in an xml file and would like to get the version '6' from
>>>>>>> the string below.
>>>>>>> How would you do that efficiently? Again I may use split function but
>>>>>>> i'm sure there are more convenient ways
>>>>>>> <xmlTest test1="myPic" test2="1234" myVersion="6">
>> 
>>>>>>> Thanks for reading.
>> 
>>>>>>> --
>>>>>>> http://groups.google.com/group/python_inside_maya
>> 
>>>>> --
>>>>> http://groups.google.com/group/python_inside_maya
>> 
>>>>  --
>>>> http://groups.google.com/group/python_inside_maya
>> 
>>> --
>>> ~ Smile today ~
>> 
>>> --
>>> http://groups.google.com/group/python_inside_maya
> 
> -- 
> http://groups.google.com/group/python_inside_maya
> 

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to