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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:18:12+00:00 2026-05-16T14:18:12+00:00

I have a such text to load: https://sites.google.com/site/iminside1/paste I’d prefer to create a python

  • 0

I have a such text to load: https://sites.google.com/site/iminside1/paste
I’d prefer to create a python dictionary from it, but any object is OK. I tried pickle, json and eval, but didn’t succeeded. Can you help me with this?
Thanks!
The results:

a = open("the_file", "r").read()

json.loads(a)
ValueError: Expecting property name: line 1 column 1 (char 1)

pickle.loads(a)
KeyError: '{'

eval(a)
File "<string>", line 19
from: {code: 'DME', airport: "Домодедово", city: 'Москва', country: 'Россия', terminal: ''},
    ^
SyntaxError: invalid syntax
  • 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-16T14:18:13+00:00Added an answer on May 16, 2026 at 2:18 pm

    Lifted almost straight from the pyparsing examples page:

    # read text from web page
    import urllib
    page = urllib.urlopen("https://sites.google.com/site/iminside1/paste")
    html = page.read()
    page.close()
    
    start = html.index("<pre>")+len("<pre>")+3 #skip over 3-byte header
    end = html.index("</pre>")
    text = html[start:end]
    print text
    
    # parse dict-like syntax    
    from pyparsing import (Suppress, Regex, quotedString, Word, alphas, 
    alphanums, oneOf, Forward, Optional, dictOf, delimitedList, Group, removeQuotes)
    
    LBRACK,RBRACK,LBRACE,RBRACE,COLON,COMMA = map(Suppress,"[]{}:,")
    integer = Regex(r"[+-]?\d+").setParseAction(lambda t:int(t[0]))
    real = Regex(r"[+-]?\d+\.\d*").setParseAction(lambda t:float(t[0]))
    string_ = Word(alphas,alphanums+"_") | quotedString.setParseAction(removeQuotes)
    bool_ = oneOf("true false").setParseAction(lambda t: t[0]=="true")
    item = Forward()
    
    key = string_
    dict_ = LBRACE - Optional(dictOf(key+COLON, item+Optional(COMMA))) + RBRACE
    list_ = LBRACK - Optional(delimitedList(item)) + RBRACK
    item << (real | integer | string_ | bool_ | Group(list_ | dict_ ))
    
    result = item.parseString(text,parseAll=True)[0]
    print result.data[0].dump()
    print result.data[0].segments[0].dump(indent="  ")
    print result.data[0].segments[0].flights[0].dump(indent="  -  ")
    print result.data[0].segments[0].flights[0].flightLegs[0].dump(indent="  -  -  ")
    for seg in result.data[6].segments:
        for flt in seg.flights:
            fltleg = flt.flightLegs[0]
            print "%(airline)s %(airlineCode)s %(flightNo)s" % fltleg,
            print "%s -> %s" % (fltleg["from"].code, fltleg["to"].code)
    

    Prints:

    [['index', 0], ['serviceClass', '??????'], ['prices', [3504, ...
    - eTicketing: true
    - index: 0
    - prices: [3504, 114.15000000000001, 89.769999999999996]
    - segments: [[['indexSegment', 0], ['stopsCount', 0], ['flights', ... 
    - serviceClass: ??????
      [['indexSegment', 0], ['stopsCount', 0], ['flights', [[['index', 0], ...
      - flights: [[['index', 0], ['time', 'PT2H45M'], ['minAvailSeats', 9], ...
      - indexSegment: 0
      - stopsCount: 0
      -  [['index', 0], ['time', 'PT2H45M'], ['minAvailSeats', 9], ['flight...
      -  - flightLegs: [[['flightNo', '309'], ['eTicketing', 'true'], ['air... 
      -  - index: 0
      -  - minAvailSeats: 9
      -  - stops: []
      -  - time: PT2H45M
      -  -  [['flightNo', '309'], ['eTicketing', 'true'], ['airplane', 'Boe... 
      -  -  - airline: ?????????
      -  -  - airlineCode: UN
      -  -  - airplane: Boeing 737-500
      -  -  - availSeats: 9
      -  -  - classCode: I
      -  -  - eTicketing: true
      -  -  - fareBasis: IPROW
      -  -  - flightClass: ECONOMY
      -  -  - flightNo: 309
      -  -  - from:   -  -  [['code', 'DME'], ['airport', '??????????'], ... 
      -  -    - airport: ??????????
      -  -    - city: ??????
      -  -    - code: DME
      -  -    - country: ??????
      -  -    - terminal: 
      -  -  - fromDate: 2010-10-15
      -  -  - fromTime: 10:40:00
      -  -  - time: 
      -  -  - to:   -  -  [['code', 'TXL'], ['airport', 'Berlin-Tegel'], ... 
      -  -    - airport: Berlin-Tegel
      -  -    - city: ??????
      -  -    - code: TXL
      -  -    - country: ????????
      -  -    - terminal: 
      -  -  - toDate: 2010-10-15
      -  -  - toTime: 11:25:00
    airBaltic BT 425 SVO -> RIX
    airBaltic BT 425 SVO -> RIX
    airBaltic BT 423 SVO -> RIX
    airBaltic BT 423 SVO -> RIX
    

    EDIT: fixed grouping and expanded output dump to show how to access individual key fields of results, either by index (within list) or as attribute (within dict).

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

Sidebar

Related Questions

I have designed a softkeypad and changing textbox text programmatically such as myKeypad.getControl.Text +=
I have a description text file with content constructed in such manner: Book title
i have such code (copy paste from wiki). Its multiplication of those big numbers
My iframe code is set up as such <iframe src= https://www.facebook.com/plugins/registration ?client_id= &redirect_uri= &fields=
I have ads served via adspeed.com I would like our rich text (testimonial) ads
I have a table such as: PK_ID LOCATION_ID LOCATION_TEXT 1 21 NULL 2 44
have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE
I have such XML structure which was returned by SharePoint web services. <rs:data ItemCount=4
i have such function to solve some logic riddle iloczyny is list with such
I have such a grid square disk. Every grid represents a pixel. My aim

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.