Monday, June 3, 2019

They say a python tuple can't contain itself...

... but here at PDW we abhor that kind of defeatism!

>>> import ctypes
>>> tup = (None,)
>>> ctypes.pythonapi.PyTuple_SetItem.argtypes = ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p
>>> ctypes.pythonapi.PyTuple_SetItem(id(tup), 0, id(tup))
0


Showing the tuple itself is a little problematic
>>> tup
# ... hundreds of lines of parens ...
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
((Segmentation fault

29 comments:

  1. This is not surprising, since C-API is actually used. Without it, making a tuple instance with a part of itself will not possible.

    ReplyDelete
    Replies
    1. yup! only the C-API makes it possible

      it is kind of interesting though that tuple doesn't have any recursion handling in its repr()

      >>> a = []
      >>> a.append((a,))
      >>> a
      [([...],)]
      >>> a[0]
      ([([...],)],)

      rather than tuple(list(tuple)) showing ([(...,)]) it relies on the list repr() to detect the cycle and handle it one layer deeper

      contract with dict(list(dict)) in which the dict repr() detects the cycle

      >>> b = {}
      >>> b[0] = [b]
      >>> b
      {0: [{...}]}

      Delete
  2. Odd; not getting this error under ipython, though I do get it with plain python. Both should(?) be running the same python executable; at any rate both report running 2.7.15 (can't even try this in python3 it seems). But under ipython I just get ((...),) as one might expect.

    ReplyDelete
  3. I have bookmarked your blog, the articles are way better than other similar blogs.. thanks for a great blog! 统计代写

    ReplyDelete
  4. It was worthy experience to get some answers concerning hazardous complement. Valuable for everyone looking with respect to the issue.

    data scientist course in delhi

    ReplyDelete
  5. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    business analytics course

    ReplyDelete
  6. Hi there mates, how is all, and what you would like to say concerning this
    article, in my view its truly awesome in favor of me.

    Look at my web-site; 부산달리기

    ReplyDelete
  7. I like reading the aforementioned essay because it clearly explains everything and is both entertaining and effective. Thank you for your time and consideration, and best of luck with your future articles.Medical Essay Writing Service

    ReplyDelete
  8. Your post is helping me a lot. Its really nice and epic. Thanks a lot for the useful info on this topic. You did it so much well. I love to see more about GBWhatsApp. Keep sharing and updating. Also share more posts with us. Thank you.

    ReplyDelete
  9. Hello There. I found your blog using msn. This is a really well
    written article. I’ll make sure to bookmark it and come back to read more of your
    useful info. Thanks for the post. I’ll definitely return.



    카지노사이트
    바카라사이트
    카지노사이트추천

    ReplyDelete
  10. Great post. I was checking constantly this blog and I’m impressed! Extremely useful info specially the last part �� I care for such info a lot. I was seeking this certain information for a long time. 스포츠토토
    Thank you and best of luck.

    ReplyDelete
  11. Hello there! Quick question that’s totally off topic. Do you know how to make your site mobile friendly? My website looks weird when viewing from my iphone4. I’m trying to find a template or plugin that might be able to resolve this issue. If you have any recommendations, please share. Thanks! 토토사이트

    ReplyDelete
  12. Keep up the superb work, I read few blog posts on this website
    and I conceive that your site is really interesting and contains lots
    of wonderful info. 바카라사이트

    ReplyDelete
  13. 토토사이트 This is indeed an interesting read. I love sharing the content I receive here, so much good information.

    ReplyDelete
  14. 스포츠토토 I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit.

    ReplyDelete
  15. 바카라사이트 Admiring the time and effort you put into your blog and detailed information you offer!..

    ReplyDelete
  16. 카지노사이트 Wonderful and useful submit. I found this much helpful


    ReplyDelete
  17. Nice post love it check my site for fast Satta King
    we provide superfast and all time result SattaKing

    ReplyDelete
  18. Hi there! Nice post! Please tell us when I will see a follow up! 온라인경마

    ReplyDelete
  19. This is a great post and enjoy the look of your blog very much. Thanks for sharing. 파친코사이트

    ReplyDelete
  20. Hi there, its pleasant post about media print, we all understand media is a wonderful source of facts. 스포츠토토


    ReplyDelete
  21. According to Cheap Dissertation Writing Services experts, real-life begins with education. It is during schooling that children's mental abilities are assessed. And at the same time, students find out what they can do best for themselves.

    ReplyDelete
  22. “It’s awesome designed for me to have a web page, which is valuable for my experience.
    메이저사이트
    경마

    ReplyDelete
  23. I have read your excellent post. This is a great job. I have enjoyed reading your post first time. I want to say thanks for this post. Thank you... data science course in Vadodara

    ReplyDelete
  24. It's very interesting. And it's fun. This is a timeless article. I also write articles related to , and I run a community related to 온라인카지노 . For more information, please feel free to visit !!

    ReplyDelete