Feed on

to write a python dict to a text file:

f = open(‘text.file’,'w’)


to read a python dict from a text file:

f = open(‘text.file’,'r’)

my_dict = eval(f.read())

Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

35 Responses to “read or write a python dict to/from a text file.”

  1. on 01 Oct 2007 at 2:00 pm Eric Brunson

    Trusted input is a huge factor in using eval(). I’d suggest using the shelve module for persisting data like that, it’s more robust and not subject to code injection attacks for what you’ve done, but is actually more fully featured.

    Details can be found here: http://docs.python.org/lib/node329.html

  2. on 21 Jun 2010 at 2:13 am Jonathan

    I had to change your code to the following to get it to work:

    f = open(’text.file’,’w’)

    The close function isn’t necessary, but it is good if you are not exiting immediately.

    Thanks for the post.

  3. on 29 Mar 2012 at 11:45 am Mathieu

    def eval1(x):
    try: return eval(x)
    except: return x
    A = { eval1(y[0]) : eval1(y[1]) for y in [x.split() for x in open(filename).readlines()] }

  4. on 30 Aug 2012 at 12:39 pm Graham Jeffries

    a two line solution:

    with open(‘text.file’,'w’) as f:

  5. on 10 Nov 2012 at 5:19 am Sanjeev Kumar

    proper way of doing

    except Exception as er:
    print er

  6. ポールスミス ネクタイ 人気

    read or write a python dict to/from a text file. » from the desk of stinkpot

  7. on 18 May 2018 at 5:08 pm best place to buy yeezy boost

    I was very happy to find this website. I wanted to thank you for your
    time due to this fantastic read!! I definitely enjoyed every part of it and
    i also have you saved as a favorite to look at new stuff in your web site.

  8. on 27 Jun 2018 at 2:17 am PlumbersUsa

    Hello very nice website! Thank you for this specific info! keep it up.

  9. on 20 Jul 2018 at 2:09 am Erika

    Great web site you have here.. It’s difficult to find quality writing like yours these days.
    I seriously appreciate indivviduals like you!
    Take care!!

  10. on 28 Jul 2018 at 12:54 pm cheap yeezys

    You really make it appear really easy along with your presentation but I find
    this matter to be really one thing that I think I
    might never understand. It kind of feels too complicated and
    extremely wide for me. I’m looking forward to your subsequent put up,
    I will attempt to get the grasp of it!

  11. on 09 Sep 2018 at 12:34 pm gdzie kupic tanie follow na instagramie

    Thanks a lot for sharing this with all people you actually recognise what you’re speaking about!
    Bookmarked. Kindly additionally consult with my website =).
    We could have a hyperlink trade arrangement among us

  12. on 28 Nov 2018 at 8:03 am Bandar Domino

    This is absolutgely the easiest method to train yourself
    if you need to be a serious player. She is playing the piano by age four and used that skill
    like a teenager to try out through New York’s open mic
    nights at age 14. Whenn you are seeking the righ poker felt
    top, there are numerous opotions available, so take a momennt to ensure that you
    have the right choices open to you.

  13. on 22 Jun 2019 at 12:51 pm hayvansikicileri

    hayvan sikici

  14. on 22 Jun 2019 at 2:30 pm death of porn

    death of porn

  15. on 24 Jun 2019 at 5:28 am Sunny Stricklind

    Good comment.

  16. on 29 Jun 2019 at 11:03 pm Curtis Mcdearmon

    I wish to show some appreciation to the writer for bailing me out of such a circumstance. Just after browsing throughout the world-wide-web and meeting opinions which are not productive, I assumed my life was well over. Being alive minus the approaches to the difficulties you have solved all through the post is a serious case, and the ones that might have in a wrong way damaged my entire career if I had not encountered your website. The ability and kindness in touching all areas was priceless. I don’t know what I would have done if I had not come upon such a point like this. It’s possible to at this time relish my future. Thanks for your time very much for the skilled and results-oriented guide. I will not hesitate to endorse your web blog to anybody who would need guidance on this topic.

  17. on 19 Jul 2019 at 4:28 am ensest sikici

    ensest sikici

  18. on 24 Jul 2019 at 1:11 am Dagny Roam

    Ada beberapa hal yang mesti kalian pertimbangkan ketika akan memilih sebuah web judi bandarq seperti mencari web recommended yang banyak dianjurkan oleh sahabat ataupun para pemain judi lama. Ini nantinya amat berkhasiat bagi kamu agar tidak tertipu dengan website abal-abal. Bahkan apabila kalian memilih situs hal yang demikian secara sembarangan, kita akan menerima kerugian yang tidak sedikit.

  19. on 30 Jul 2019 at 6:16 am Maryln Bulwinkle

    i would be busy again doing some home decors this coming christmas, i’d be buying some new decors for the season’

  20. on 27 Aug 2019 at 6:44 am wynajem samochodow automat gdansk

    Wypożyczalnia samochodów w Gdańsku oferuje tani wynajem aut osobowych i dostawczych na terenie Trójmiasta i okolic. budynekfirmy zlokalizowana jest tuż przy dworcu kolejowym, będącym kapitalnym węzłem komunikacyjnym z Gdynią i Sopotem. Niewielka odległość dzieląca tanią wypożyczalnię samochodów od lotniska im. Lecha Wałęsy upoważnia na tranzyt w czasie krótszym niż 30 minut.

  21. on 29 Aug 2019 at 7:05 pm ankara cocuk

    ankara sikis

  22. on 09 Nov 2019 at 4:00 am Kumpulan Bandarqq

    Kumpulan Bandarqq

    read or write a python dict to/from a text file. » from the desk of stinkpot

  23. on 15 Nov 2019 at 6:24 am porn fast fuck

    dope bts funny moments

    funny dope smoking pictures

  24. on 01 Feb 2020 at 5:59 pm Teknik Taruhan Bola

    Hi there to every body, it’s my first visit of this web site; this website carries amazing and actually excellent data designed for visitors.

  25. on 03 Feb 2020 at 11:02 pm judi Togel Online

    A fascinating discussion is definitely worth comment.

    I think that you ought to write more about this subject matter, it might not be a taboo subject but generally people do
    not talk about these subjects. To the next! Cheers!!

  26. on 06 Feb 2020 at 6:45 am Situs Taruhan Togel

    It’s great that you are getting ideas from this article as well as from our
    argument made at this time.

  27. on 07 Feb 2020 at 1:28 pm Pahami website Bandar Togel

    Magnificent web site. A lot of helpful info here.

    I am sending it to several pals ans additionally
    sharing in delicious. And of course, thanks on your sweat!

  28. on 09 Feb 2020 at 3:21 pm LiveDraw Togel

    I was wondering if you ever considered changing the layout of
    your website? Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so people could connect with it better.
    Youve got an awful lot of text for only having 1 or 2 images.
    Maybe you could space it out better?

  29. on 11 Feb 2020 at 8:34 am Situs Judi Bola Profesional

    Hi there, every time i used to check blog posts here in the early hours
    in the daylight, for the reason that i love to gain knowledge of more and more.

  30. on 12 Feb 2020 at 4:49 am Taruhan Judi Bola

    I got this web site from my friend who told me concerning this site and now this time I am browsing this
    web page and reading very informative content at this time.

  31. Zuppa di pesce dieta dukano fare diete povere di carboidrati
    bruciano più grassi

  32. on 26 Mar 2020 at 9:30 pm togel hongkong

    Have you ever considered creating an e-book or guest authoring on other sites?
    I have a blog centered on the same ideas you
    discuss and would love to have you share some stories/information. I know my subscribers
    would appreciate your work. If you’re even remotely interested, feel free to shoot me an e mail.

  33. on 07 Apr 2020 at 7:09 am Wilbert Friedberg

    Situs berita bola yang paling oke dan terpercaya hanya di situs https://infobola138.com

  34. on 04 Jun 2020 at 1:04 am agen judi slot

    Thanks for a marvelous posting! I certainly enjoyed reading it, you are a
    great author.I will remember to bookmark your blog and will eventually come back from
    now on. I want to encourage you to continue your great posts, have a nice holiday weekend!

  35. on 24 Jun 2020 at 5:48 am data togel

    That is a really good tip particularly to those
    new to the blogosphere. Simple but very accurate information… Thanks
    for sharing this one. A must read post!

Did I get this wrong? Let me know!

Trackback URI | Comments RSS

More blogs about http://desk.stinkpot.org:8080/tricks.