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

  • Home
  • SEARCH
  • 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 4328468
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:41:16+00:00 2026-05-21T09:41:16+00:00

//Last modified: Sat, Apr 16, 2011 09:55:04 AM //Codeset: ISO-8859-1 fileInfo version 20×64; createNode

  • 0
//Last modified: Sat, Apr 16, 2011 09:55:04 AM
//Codeset: ISO-8859-1
fileInfo "version" "20x64";
createNode newnode -n "a_SET";
    addAttr -ci true -k true -sn "connections" -ln "connections" -dt "string";
    setAttr -l on -k off ".tx";
    setAttr -l on -k off ".ty";
    setAttr -l on -k off ".sz";
    setAttr -l on -k on ".test1" -type "string" "blabla";
    setAttr -l on -k on ".test2" -type "string" "blablabla";
createNode newnode -n "b_SET";
    addAttr -ci true -k true -sn "connections" -ln "connections" -dt "string";
    setAttr -l on -k off ".tx";
    setAttr -l on -k off ".ty";
    setAttr -l on -k off ".sz";
    setAttr -l on -k on ".test1" -type "string" "hmm";
    setAttr -l on -k on ".test2" -type "string" "ehmehm";

in Python:

I need to read the newnode names for instance “a_SET” and “b_SET” and their corresponding attribute values so {“a_SET”: {“test1″:”blabla”, “test2″:”blablabla”} and the same for the b_SET – there could be unknown amount of sets – like c_SET d_SET etc.

I’ve tried looping through lines and matching it there:

for line in fileopened:
    setmatch = re.match( r'^(createNode set -n ")(.*)(_SET)(.*)' , line)
     if setmatch:
            sets.append(setmatch.group(2))

and as soon as I find a match here I would loop through next lines to get the attributes (test1, test2) for that set until I find a new set – for instance c_SET or an EOF.

What would be the best way to grab all that info in one go with the re.MULTILINE?

  • 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-21T09:41:17+00:00Added an answer on May 21, 2026 at 9:41 am

    I got this:

    import re
    
    filename = 'tr.txt'
    
    with open(filename,'r') as f:
        ch = f.read()
    
    pat = re.compile('createNode newnode -n ("\w+?_SET");(.*?)(?=createNode|\Z)',re.DOTALL)
    pit = re.compile('^ *setAttr.+?("[^"\n]+").+("[^"\n]+");(?:\n|\Z)',re.MULTILINE)
    
    dic = dict( (mat.group(1),dict(pit.findall(mat.group(2)))) for mat in pat.finditer(ch)) 
    print dic
    

    result

    {'"b_SET"': {'".test2"': '"ehmehm"', '".test1"': '"hmm"'}, '"a_SET"': {'".test2"': '"blablabla"', '".test1"': '"blabla"'}}
    

    .

    Question:

    what if there must be character '"' in the strings ? How is it represented ?

    .

    EDIT

    I had some difficulty to find the solution because I didn’t choose the facility.

    Here’s a new pattern that catches the FIRST string "..." and the LAST string "..." present after a string " setAttr" and before the next " setAttr". So several "..." can be present , not only 3. You didn’t asked this condition, but I thought it may happen to be needed.

    I also managed to make possible the presence of newlines in the strings to catch "....\n......" , not only around them. For that , I was obliged to invent something new for me: (?:\n(?! *setAttr)|[^"\n]) that means : all characters, except '"' and common newlines \n , are accepted and also only the newlines that are not followed by a line beginning with ' *setAttr'

    For (?:\n(?! *setAttr)|.) it means : newlines not followed by a line beginning with ' *setAttr' and all the other non-newline characters.

    Hence, any other special sequence as tab or whatever else are automatically accpted in the matchings.

    ch = '''//Last modified: Sat, Apr 16, 2011 09:55:04 AM
    //Codeset: ISO-8859-1
    fileInfo "version" "20x64";
    createNode newnode -n "a_SET";
        addAttr -ci true -k true -sn "connections" -ln "connections" -dt "string";
        setAttr -l on -k off ".tx";
        setAttr -l on -k off ".ty";
        setAttr -l on -k off ".sz";
        setAttr -l on -k on ".test1" -type "string" "blabla";
        setAttr -l on -k on ".test2" -type "string" "blablabla";
    createNode newnode -n "b_SET";
        addAttr -ci true -k true -sn "connections" -ln "connections" -dt "string";
        setAttr -l on -k off ".tx";
        setAttr -l on -k off ".ty";
        setAttr -l on -k off ".sz";
        setAttr -l on -k on ".test1" -type "string" (
          "hmm bl
          abla\tbla" );
        setAttr -l on -k on ".tes\nt\t2" -type "string" "ehm\tehm";
        setAttr -l on -k on ".test3" -type "string" "too
        much" "pff" """ "feretini" "gol\nolo";
        '''
    
    import re
    
    pat = re.compile('createNode newnode -n ("\w+?_SET");(.*?)(?=createNode|\Z)',re.DOTALL)
    pot = re.compile('^ *setAttr.+?'
                     '"((?:\n(?! *setAttr)|[^"\n])+)"'
                     '(?:\n(?! *setAttr)|.)+'
                     '"((?:\n(?! *setAttr)|[^"\n])+)"'
                     '.*;(?:\n|\Z)',re.MULTILINE)
    
    dic = dict( (mat.group(1),dict(pot.findall(mat.group(2)))) for mat in pat.finditer(ch)) 
    for x in dic:
        print x,'\n',dic[x],'\n'
    

    result

    "b_SET" 
    {'.test3': 'gol\nolo', '.test1': 'hmm bl\n      abla\tbla', '.tes\nt\t2': 'ehm\tehm'} 
    
    "a_SET" 
    {'.test1': 'blabla', '.test2': 'blablabla'}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have this last_modified = xhr.getResponseHeader('Last-Modified'); /* Last-Modified: Wed, 06 Apr 2011 20:47:09
HTTP Last-Modified header contains date in following format (example): Wed, 09 Apr 2008 23:55:38
I want to get the last modified time of any part of a view
How do you get any file's last modified date using VB6?
I know how to get the user that last modified a file, but does
Is there an ISAPI filter that can automatically add the Last-Modified header in IIS?
is there any way of quick jump to the last modified line? eclipse has
How to list files in a directory in last modified date order? (PHP5 on
how get the date and time of the last modified particular TYPE file in
I'm trying to get some information about Azure blob (last modified UTC date time).

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.