Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8084685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:52:14+00:00 2026-06-05T17:52:14+00:00

I’ve written an XML parser in Python and have just added functionality to read

  • 0

I’ve written an XML parser in Python and have just added functionality to read a further script from a different directory.

I’ve got two args, first is the path where I’m parsing XML. Second is a string in another XML file which I want to match with the first path;

arg1 = \work\parser\main\tools\app\shared\xml\calculators\2012\example\calculator
path = calculators/2012/example/calculator

How can I compare the two strings to match identify that they’re both referencing the same thing and also, how can I strip calculator from either string so I can store that & use it?

edit

Just had a thought. I have used a Regex to get the year out of the path already with year = re.findall(r"\.(\d{4})\.", path) following a problem Python has with numbers when converting the path to an import statement.

I could obviously split the strings and use a regex to match the path as a pattern in arg1 but this seems a long way round. Surely there’s a better method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:52:15+00:00Added an answer on June 5, 2026 at 5:52 pm

    Here I am assuming you are actually talking about strings, and not file paths – for which @mgilson’s suggestion is better

    How can I compare the two strings to match identify that they’re both
    referencing the same thing

    Well first you need to identify what you mean by “the same thing”

    At first glance it seems that if the the second string ends with the first string with the reversed slash, you have a match.

    arg1 = r'\work\parser\main\tools\app\shared\xml\calculators\2012\example\calculator'
    arg2 = r'calculators/2012/example/calculator'
    
    >>> arg1.endswith(arg2.replace('/','\\'))
    True
    

    and also, how can I strip calculator from
    either string so I can store that & use it?

    You also need to decide if you want to strip the first calculator, the last calculator or any occurance of calculator in the string.

    If you just want to remove the last string after the separator, then its simply:

    >>> arg2.split('/')[-1]
    'calculator'
    

    Now to get the orignal string back, without the last bit:

    >>> '/'.join(arg2.split('/')[:-1])
    'calculators/2012/example'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.