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 6641471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:48:54+00:00 2026-05-25T23:48:54+00:00

I’m fairly new to Python and don’t fully understand all items and I’ve been

  • 0

I’m fairly new to Python and don’t fully understand all items and I’ve been given a base for a programme and I need to alter bits, here’s what I have so far:

    import sys, os

    filename   = 'C:\main\in.txt'
    resultFile = 'C:\main\out.txt'

    try:
       file = open( filename, "w" )
    except Exception, e:
        logger.critical( "Failed to create file \"%s\" : %s" % ( filename, e )

    for name, value in brg.iteritems():
        if -1 == string.find( name, "CTRL" ) and name not in [ "name", "type" ]:
            file.write( "%s = %s\n" % ( name, value ) )
            file.close()

   # run the Fortran programme

    resultCode = os.system( '%sC:\main\Debug\main.exe -i %s -o %s.result' % ( options[ OPTION_script_path ], filename, filename ) ) 

    # Read the results

    try:
        file = open( resultFile, "r" ) 
    except Exception, e:
        logger.critical( "Failed to create file \"%s\" : %s" % ( resultFile, e ) 

        regexp = re.compile( "^(?P<name>.*)\\s*=\\s*(?P<value>.*)$" )
        for row in file.xreadlines():
        row = row.strip( "\\r\\n \\t" )
        m = regexp.match( row )
        if m:
                name = m.group( "name" )
                value = m.group( "value" )
                brg[ name ] = value

I am completely lost as to why it doesn’t currently work as it’s finding a Syntax error with: for name, value in bearing.iteritems():

I’m not sure whether some mistakes are due to indentation..

I also don’t quite understand the last part. I have an output text file and this is what the final part is reading. I have however don’t understand (in particular) this line:

regexp = re.compile( "^(?P<name>.*)\\s*=\\s*(?P<value>.*)$" )

With the RE’s, I don’t understand exactly what it means by ‘matching’ what is the ^, $ and ?P matching to what? Also what does ‘regexp’ represent?

Thank you for your time =)

  • 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-05-25T23:48:55+00:00Added an answer on May 25, 2026 at 11:48 pm
            logger.critical( "Failed to create file \"%s\" : %s" % ( filename, e )
    

    Has 2 left ( and only 1 right ). This appears to be a syntax error.

    Since the statement isn’t complete, Python continues parsing. The error message shows up on the following line.


    Read this: http://docs.python.org/library/re.html#regular-expression-syntax. Then update your question with more specific aspects of the regular expression which confuse you. Regular expressions are a (potentially) deep topic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to

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.