0

Four team tournament bracket

How can I produce a tournament bracket image, like the above, using Python? This sort of image reminds me of a dendrogram (I'm not sure if it's literally a dendrogram or not), and I know Python can produce very sophisticated dendrograms, so I feel like my simple and regular structure should be possible. My priority is for the solution to be as straightforward as possible. I don't need a highly customizable or beautiful result.

Code which produces the exact image above would be great, but also code that produces something similar would be very helpful and I can adapt it myself. Or a suggested method, with no code, would also be helpful.

I have tried using BracketMaker, which is the first hit which shows up when I try google searching this question. In a Jupyter notebook, running Python 3.7.10, I have tried the following:

!pip install BracketMaker
from bracket import bracket # from the BracketMaker documentation

and I get the error message:

SyntaxError: Missing parentheses in call to 'print'. Did you mean print("")? (bracket.py, line 50)

As far as I can tell, this is an error from using Python 2 code? I would like code that works in Python 3.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
CJD
  • 159
  • 1
  • 7
  • I posted a longer version of this question a few hours ago and it was closed for being "unfocused". Here is a similar question that was asked with regards to HTML rather than Python: https://stackoverflow.com/questions/18565727/tournament-brackets-using-only-html-tables-and-css/18565797 I am grateful to any suggestions for how to improve my question. I have tried to focus it by removing the list of things I already tried and by including a specific image. – CJD Jun 19 '21 at 12:17
  • Have you tried a [google search](https://www.google.com/search?q=python+print+tournament+bracket&rlz=1C1GCEU_enCA820CA822&biw=1920&bih=937&ei=Lt7GYJuNJMK0tQav6arYDA&oq=python+print+tournament+bracket&gs_lcp=Cgdnd3Mtd2l6EAMyCAghEBYQHRAeMggIIRAWEB0QHjIICCEQFhAdEB4yCAghEBYQHRAeMggIIRAWEB0QHjoHCAAQsQMQQzoCCAA6BQgAELEDOgsILhCxAxDHARCjAjoFCC4QsQM6DgguELEDEIMBEMcBEKMCOg4ILhDHARCvARCRAhCTAjoHCC4QsQMQQzoECC4QQzoECAAQQzoCCC46BAgAEAo6BQghEKABOgQIIRAVOgcIIRAKEKABUPwpWLhmYIt9aABwAngBgAG7A4gBqCySAQowLjI1LjQuMi4xmAEAoAEBqgEHZ3dzLXdpesABAQ&sclient=gws-wiz&ved=0ahUKEwib3Ondp5bxAhVCWs0KHa-0CssQ4dUDCA8&uact=5)? – tinstaafl Jun 19 '21 at 12:25
  • @tinstaafl Yes, I have installed BracketMaker but could not get it to work, and I have installed ete3 and had some success but it seemed overly sophisticated for my task. If there is a particular hit from the google search that you think is promising, I would be grateful if you told me which one. – CJD Jun 19 '21 at 12:30
  • If you tried something, show what exactly, preferably, with a [mcve], and how it didn't work. As it is now, the question is still not focused. – bereal Jun 19 '21 at 12:33
  • 1
    Does this answer your question? [How to use Python 2 packages in Python 3 project?](https://stackoverflow.com/questions/33885975/how-to-use-python-2-packages-in-python-3-project) – mkrieger1 Jun 19 '21 at 12:47

1 Answers1

2

You could look into diagrams. Its Custom class seems like it would help.

EDIT: I've updated the project to support Python3. You can clone it here. All you have to do is navigate to the directory and run $ python3 bracket/bracket.py.

I tried updating the PyPI project definition, but I can't without the author's permission.

  • 1
    Perfect, thank you, I had not heard of this before, this is exactly the sort of suggestion I was looking for. – CJD Jun 19 '21 at 12:54
  • 2
    You're welcome. I see you're new to Stack Overflow. I'm new to SO as well and It took me two years to even be allowed to comment. In fact this is my first comment ever on SO. I know the community might be a bit harsh sometimes. It's for the best of everyone. However, sometimes questions are unanswered simply because we're such beginners that we don't even know how to ask questions. I would recommend you [this essay on how to ask smart questions](http://catb.org/~esr/faqs/smart-questions.html) – Alexandru Cristiean Jun 19 '21 at 12:58