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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:27:41+00:00 2026-06-15T08:27:41+00:00

This one might best be summarized as Python isn’t letting me do something stupid,

  • 0

This one might best be summarized as “Python isn’t letting me do something stupid,” but I digress — I have a bad habit of turning XML into strings so I can use regex to fetch something out of it, rather than actually being a good person and doing the Xpath thing.

I’m having an issue currently where I’m looping through a list of dicts (the dicts themselves being several levels deep, containing encoded XML). I’m trying to do re.findall(pattern, str(listitem)), which is giving me an “unhashable type: ‘DictionaryElement'” error. Any ideas?

edit: this is pubmed API stuff using biopython:

handle = Entrez.efetch(db="pubmed", id=pmids, retmode="xml")
records = Entrez.read(handle)
records = list(records)

meshterms = {}
for y in records:
    meshterms[y] = re.findall(r'(?<=DescriptorName\'\:\sStringElement\(\').+?(?=\')',str(y))

y would include something that looks like:

{u'MedlineCitation': DictElement({u'OtherID': [], u'OtherAbstract': [], u'CitationSubset': ['IM'], u'KeywordList': [], u'DateCreated': {u'Month': '11', u'Day':
'20', u'Year': '2012'}, u'SpaceFlightMission': [], u'GeneralNote': [], u'Article': DictElement({u'ArticleDate': [], u'Pagination': {u'MedlinePgn': '140-54'}, u'AuthorList': ListElement([DictElement({u'LastName': 'Goupil', u'Initials': 'L',
u'NameID': [], u'ForeName': 'Louise'}, attributes={u'ValidYN': u'Y'}), DictElement({u'LastName': 'Bekinschtein', u'Initials': 'T', u'NameID': [], u'ForeName': 'Tristan'}, attributes={u'ValidYN': u'Y'})], attributes={u'Type': u'authors', u'CompleteYN': u'Y'}), u'Language': ['eng'], u'PublicationTypeList': ['Journal Article'], u'Journal': {u'ISSN': StringElement('0003-9829', attributes={u'IssnType': u'Print'}), u'ISOAbbreviation': 'Arch Ital Biol', u'JournalIssue': DictElement({u'Volume': '150', u'Issue': '2-3', u'PubDate': {u'Month': 'Jun', u'Year': '2012'}}, attributes={u'CitedMedium': u'Print'}), u'Title': 'Archives italiennes de biologie'}, u'Affiliation': 'MRC Cognition and Brain Sciences Unit, 15 Chauces Road, CB2 7EF, Cambridge,UK Email: louisegoupil@hotmal.fr.', u'ArticleTitle': 'Cognitive processing during the transition to sleep.', u'ELocationID': [StringElement('10.4449/aib.v150i2.1247', attributes={u'ValidYN': u'Y', u'EIdType': u'doi'})], u'Abstract': {u'AbstractText': ['Several dramatic physiological and behaviourl changes occur during the transition from wakefulness to sleep. The process is regarded as a grey area of consciousness between attentive wakefulness and slow wave sleep. Although there is evidence of neurophysiological integration decay
as signalled by sleep EEG elements, changes in power spectra and coherence, thalamocortical connectivity in fMRI, and single neuron changes in firing patterns,
little is known about the cognitive and behavioural dynamics of these transitions. Hereby we revise the body and brain physiology, behaviour and phenomenology of these changes of consciousness and propose an experimental framework to integrate the two aspects of consciousness that interact in the transition, wakefulness and awareness.']}}, attributes={u'PubModel': u'Print'}), u'PMID': StringElement('23165874', attributes={u'Version': u'1'}), u'MedlineJournalInfo': {u'MedlineTA': 'Arch Ital Biol', u'Country': 'Italy', u'NlmUniqueID': '0372441', u'ISSNLinking': '0003-9829'}}, attributes={u'Owner': u'NLM', u'Status': u'In-Data-Review'}), u'PubmedData': {u'ArticleIdList': [StringElement('23165874', attributes={u'IdType': u'pubmed'})], u'PublicationStatus': 'ppublish', u'History': [DictElement({u'Month': '2', u'Day': '07', u'Year': '2012'}, attributes={u'PubStatus': u'accepted'}), DictElement({u'Minute': '0', u'Month': '11', u'Day': '21', u'Hour': '6', u'Year': '2012'}, attributes={u'PubStatus': u'entrez'}), DictElement({u'Minute': '0', u'Month': '11', u'Day': '21', u'Hour': '6', u'Year': '2012'}, attributes={u'PubStatus': u'pubmed'}), DictElement({u'Minute': '0', u'Month': '11', u'Day': '21', u'Hour': '6', u'Year': '2012'}, attributes={u'PubStatus': u'medline'})]}

where my regex is trying to pull the contents of StringElement below DescriptorName (incidentally, not present in the above record, but you get the idea.

Thanks!

  • 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-15T08:27:43+00:00Added an answer on June 15, 2026 at 8:27 am

    well, this got really odd, but I was able to do it as follows:

    scratch = open("mcs_scratch.txt","wb")
    scratch.write(str(y))
    scratch = open("mcs_scratch.txt","r")
    y = str(scratch.read())
    

    somehow I doubt this qualifies as good practice, but it works.

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

Sidebar

Related Questions

This might be a simple one, but since I don't have much knowledge about
This question might belong on one of the other trilogies, but it sorta seemed
This might be an easy one, but I'm not really experienced with sql. I
This might seem like a stupid question I admit. But I'm in a small
Im not sure if i have explaned this the best i can but, here
This one might be a little confusing. I'm using AMCharts with rails. Amcharts comes
I really nead to ask you this one, many of you might think it's
Please don't crucify me for this one. I decided it might be good to
This might be a really trivial one. Is File storage OS dependant ? Why
anyone shed any light as to why this might be happening for one user

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.