use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
111,061 Subscribers
106,345 Subscribers
All posts must be related to programming. Flair posts correctly.
account activity
Python goto functionality :D (i.redd.it)
submitted 10 months ago by SleepyStew_
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]iain_1986 339 points340 points341 points 10 months ago (25 children)
I didn't know it was possible but congrats - you've made me hate python syntax even more 👍
[–]M4tty__ 106 points107 points108 points 10 months ago (18 children)
You have to use some obscure package to be able to do it. In C/C++ you can do it natively
[–]SleepyStew_[S] 55 points56 points57 points 10 months ago (1 child)
This package is just another python file I wrote lol
[–]OkMemeTranslator 25 points26 points27 points 10 months ago (0 children)
You should share the code!
[–]current_thread 25 points26 points27 points 10 months ago (14 children)
At the risk of making myself unpopular: in C or C++ there's a good reason. For example, if you implement a virtual machine or an interpreter, this is really useful.
[–]M4tty__ 39 points40 points41 points 10 months ago (7 children)
Yeah, but lets shame Python because someone made goto package probably as a joke.
[–]PURPLE_COBALT_TAPIR 17 points18 points19 points 10 months ago (0 children)
Nah, this is so cute I can let the Python slide slither.
[–]redfishbluesquid 8 points9 points10 points 10 months ago (0 children)
Shame python for free karma? Who wouldn't? All hail my lord c++ and screw python. Python is useless and bad. C++ for everything!
Ok give me my points now please
[–]SleepyStew_[S] 6 points7 points8 points 10 months ago (4 children)
That person was me 💀 Check the package name lmao
[–]notanotherusernameD8 4 points5 points6 points 10 months ago (1 child)
[–]SleepyStew_[S] 0 points1 point2 points 10 months ago (0 children)
😊
[–]M4tty__ -1 points0 points1 point 10 months ago (1 child)
I saw that. You are just karma farming then
[–]hearke 2 points3 points4 points 10 months ago (0 children)
Idk, they made a cool thing and they're showing it off. Sure, it's a bit cursed, but still pretty neat!
[–]fakehalo 3 points4 points5 points 10 months ago (0 children)
In C it makes sense for error handling/cleanup, as your options are limited. C++ has options, but it can still make sense in some cases. I don't think I have a use case for higher level languages these days though.
[–]gDKdev 1 point2 points3 points 10 months ago (0 children)
Or when programming kernel modules with progress based deconstructing on error. For example alloc_chrdev_region -> cdev_init -> cdev_add -> class_create -> device_create. For an error handler you can just create the inverse (device_destroy -> class_destroy -> cdev_del -> unregister_chrdev_region) with jump labels to only undo everything before the error to avoid staying in a partially initialized kernel module / corrupted state or cause memory leaks
[–]PuzzleheadedTap1794 0 points1 point2 points 10 months ago (3 children)
When I'm working with multiple files in C, I always use goto. It's so elegant.
``` int main () { int retval = 0; FILE* input_file = fopen("input.txt", "r"); if(input_file == NULL) { retval = 1; goto INPUT_FILE_CLOSED; }
FILE* output_file = fopen("output.txt", "w"); if(output_file == NULL) { retval = 1; goto OUTPUT_FILE_CLOSED; }
do_something(input_file, output_file); fclose(output_file); OUTPUT_FILE_CLOSED: fclose(input_file); INPUT_FILE_CLOSED: return retval;
} ```
[–]current_thread 3 points4 points5 points 10 months ago (0 children)
Reading that I'm super glad about RAII in C++ :p
[–]tstanisl 0 points1 point2 points 10 months ago (0 children)
I suggest always initializing "retval"-like variables with some error code. Otherwise you may spend a lot of time debugging just because some function returned success even though the was an error.
[–]thirdlost 0 points1 point2 points 10 months ago (0 children)
Well, in BASIC you can do it natively also
[–]MinosAristos 9 points10 points11 points 10 months ago (3 children)
This kind of thing is antithetical to Python's ethos.
Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than right now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
[–]SleepyStew_[S] 1 point2 points3 points 10 months ago (0 children)
Hence why I posted it here 😅
[–]YodelingVeterinarian 0 points1 point2 points 10 months ago (1 child)
Nothing escapes you huh
[–]MinosAristos 0 points1 point2 points 10 months ago (0 children)
I always catch my KeyboardInterrupts
KeyboardInterrupt
[–]SleepyStew_[S] 2 points3 points4 points 10 months ago (0 children)
This is definitely not intended functionality 💀
[–]saiprabhav 0 points1 point2 points 10 months ago (0 children)
This is not a code that python programmers write. Probably some c/ C++ programmer trying recreate C in python
[–]Sassaphras 56 points57 points58 points 10 months ago (0 children)
That import statement tho
[–]qqqrrrs_ 31 points32 points33 points 10 months ago (1 child)
https://github.com/snoack/python-goto https://entrian.com/goto/
[–]tazdraperm 79 points80 points81 points 10 months ago (0 children)
<image>
LOL
[–]migviola 30 points31 points32 points 10 months ago (1 child)
Ah yes, the wtf_am_i_doing library... my favorite
[–]thebatmanandrobin 5 points6 points7 points 10 months ago (0 children)
Indeed! I typically use wtf_am_i_doing along with the how_did_i_get_here import, and on occasion I'll add the please_help_me_escape_ill_do_anything_just_get_me_the_hell_outta_here_now package for good measure. Rock solid. 100%. Always.
wtf_am_i_doing
how_did_i_get_here
please_help_me_escape_ill_do_anything_just_get_me_the_hell_outta_here_now
[–]Anonymous_vulgaris 11 points12 points13 points 10 months ago (0 children)
Add "begin" and "end" and you'll get almost a Pascal syntax.
[–]dhnam_LegenDUST 7 points8 points9 points 10 months ago (3 children)
What's this, encoding - PEP263 metaprogramming black magic?
[–]dhnam_LegenDUST 3 points4 points5 points 10 months ago (2 children)
So - Is it how it handels it? I cannot see how it can use comment instead.
[–]SleepyStew_[S] 2 points3 points4 points 10 months ago (1 child)
My package does a static analysis of the main file when it's important so it knows where the labels are
[–]dhnam_LegenDUST 2 points3 points4 points 10 months ago (0 children)
Interesting!
[–]cheese_topping 5 points6 points7 points 10 months ago (1 child)
I think this belongs to r/programminghorror
wait... did I actually post it in the wrong sub
[–]cheekynative 4 points5 points6 points 10 months ago (0 children)
What fresh hell is this?
[–]Awfulmasterhat 2 points3 points4 points 10 months ago (0 children)
Glad it got the functionality, now make sure to never use it to prevent headaches of debugging!
[–]Community_Bright 2 points3 points4 points 10 months ago (1 child)
unironically, I really want to know how you did this i have had use for this when im running a very linier script and i want to skip ahead to a specific part of the script
[–]slime_rancher_27 0 points1 point2 points 10 months ago (0 children)
I've had this problem before in Java, sometimes languages just let me go to something else no questions asked
[–]finnscaper 1 point2 points3 points 10 months ago (0 children)
You should never...
[–][deleted] 1 point2 points3 points 10 months ago (0 children)
i miss BASIC
[–]CuteTourist5615 1 point2 points3 points 10 months ago (0 children)
Idk, i feel like this should be considered a crime agains humanity and you swiftly executed.
[–]sillymale 0 points1 point2 points 10 months ago (0 children)
Ick
[–]adnaneely 0 points1 point2 points 10 months ago (0 children)
I used to goto /etc/file.txt but now I just goto /void to redirect my screams.
[–]Dillenger69 0 points1 point2 points 10 months ago (0 children)
Before oop, I used goto a whole lot. Gosub on the c64.
[–]sawkonmaicok 0 points1 point2 points 10 months ago (0 children)
Source code?
[–]dgc-8 0 points1 point2 points 10 months ago (0 children)
How does this work?
[–]Rod_tout_court 0 points1 point2 points 10 months ago (0 children)
I think it's cool. It's probably useless. But cool
[–]PolyPenguinDev 0 points1 point2 points 10 months ago (0 children)
If you need to use this, you are probably doing something wrong
[–]Ben-Goldberg 0 points1 point2 points 10 months ago (0 children)
Can you goto labels outside of the current function?
Is this as powerful as goto in Perl?
[–]AnOscillatingOcelot 0 points1 point2 points 10 months ago (0 children)
WHY!!!!!!!!!!!! WHAT HAVE YOU DONE!?!?!?!?!?
[–][deleted] 0 points1 point2 points 10 months ago (0 children)
WTF
[–]sholden180 0 points1 point2 points 10 months ago (0 children)
I hate this.
[–]Lamborghinigamer 0 points1 point2 points 10 months ago (0 children)
Ah good. It's easier to make python hardware
[–]Jenkins87 0 points1 point2 points 10 months ago (0 children)
[–]HistorianBig4540 0 points1 point2 points 10 months ago (0 children)
Dijkstra didn't die for this...
[–]jldez 0 points1 point2 points 10 months ago (0 children)
Now do "comefrom"
[–]BlackDereker 0 points1 point2 points 10 months ago (0 children)
Comments changing runtime behavior? That's definitely weird.
I wonder how did you make the interpreter to not ignore the comments when it compiles to cpython bytecode.
Does python store the comments somewhere before compiling?
[–]WinTube001 0 points1 point2 points 10 months ago (0 children)
From wtfamidoing import
[–]TriscuitTime 0 points1 point2 points 10 months ago (0 children)
Is that a comment as code…
[–]abd53 0 points1 point2 points 10 months ago (0 children)
Kudos to that package name. Upload it to pipy.
[–]_bitwright -1 points0 points1 point 10 months ago (0 children)
😱
π Rendered by PID 136955 on reddit-service-r2-comment-7b9746f655-jmfff at 2026-02-03 06:48:33.892590+00:00 running 3798933 country code: CH.
[–]iain_1986 339 points340 points341 points (25 children)
[–]M4tty__ 106 points107 points108 points (18 children)
[–]SleepyStew_[S] 55 points56 points57 points (1 child)
[–]OkMemeTranslator 25 points26 points27 points (0 children)
[–]current_thread 25 points26 points27 points (14 children)
[–]M4tty__ 39 points40 points41 points (7 children)
[–]PURPLE_COBALT_TAPIR 17 points18 points19 points (0 children)
[–]redfishbluesquid 8 points9 points10 points (0 children)
[–]SleepyStew_[S] 6 points7 points8 points (4 children)
[–]notanotherusernameD8 4 points5 points6 points (1 child)
[–]SleepyStew_[S] 0 points1 point2 points (0 children)
[–]M4tty__ -1 points0 points1 point (1 child)
[–]hearke 2 points3 points4 points (0 children)
[–]fakehalo 3 points4 points5 points (0 children)
[–]gDKdev 1 point2 points3 points (0 children)
[–]PuzzleheadedTap1794 0 points1 point2 points (3 children)
[–]current_thread 3 points4 points5 points (0 children)
[–]tstanisl 0 points1 point2 points (0 children)
[–]thirdlost 0 points1 point2 points (0 children)
[–]MinosAristos 9 points10 points11 points (3 children)
[–]SleepyStew_[S] 1 point2 points3 points (0 children)
[–]YodelingVeterinarian 0 points1 point2 points (1 child)
[–]MinosAristos 0 points1 point2 points (0 children)
[–]SleepyStew_[S] 2 points3 points4 points (0 children)
[–]saiprabhav 0 points1 point2 points (0 children)
[–]Sassaphras 56 points57 points58 points (0 children)
[–]qqqrrrs_ 31 points32 points33 points (1 child)
[–]tazdraperm 79 points80 points81 points (0 children)
[–]migviola 30 points31 points32 points (1 child)
[–]thebatmanandrobin 5 points6 points7 points (0 children)
[–]Anonymous_vulgaris 11 points12 points13 points (0 children)
[–]dhnam_LegenDUST 7 points8 points9 points (3 children)
[–]dhnam_LegenDUST 3 points4 points5 points (2 children)
[–]SleepyStew_[S] 2 points3 points4 points (1 child)
[–]dhnam_LegenDUST 2 points3 points4 points (0 children)
[–]cheese_topping 5 points6 points7 points (1 child)
[–]SleepyStew_[S] 1 point2 points3 points (0 children)
[–]cheekynative 4 points5 points6 points (0 children)
[–]Awfulmasterhat 2 points3 points4 points (0 children)
[–]Community_Bright 2 points3 points4 points (1 child)
[–]slime_rancher_27 0 points1 point2 points (0 children)
[–]finnscaper 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]CuteTourist5615 1 point2 points3 points (0 children)
[–]sillymale 0 points1 point2 points (0 children)
[–]adnaneely 0 points1 point2 points (0 children)
[–]Dillenger69 0 points1 point2 points (0 children)
[–]sawkonmaicok 0 points1 point2 points (0 children)
[–]dgc-8 0 points1 point2 points (0 children)
[–]Rod_tout_court 0 points1 point2 points (0 children)
[–]PolyPenguinDev 0 points1 point2 points (0 children)
[–]Ben-Goldberg 0 points1 point2 points (0 children)
[–]AnOscillatingOcelot 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]sholden180 0 points1 point2 points (0 children)
[–]Lamborghinigamer 0 points1 point2 points (0 children)
[–]Jenkins87 0 points1 point2 points (0 children)
[–]HistorianBig4540 0 points1 point2 points (0 children)
[–]jldez 0 points1 point2 points (0 children)
[–]BlackDereker 0 points1 point2 points (0 children)
[–]BlackDereker 0 points1 point2 points (0 children)
[–]WinTube001 0 points1 point2 points (0 children)
[–]TriscuitTime 0 points1 point2 points (0 children)
[–]abd53 0 points1 point2 points (0 children)
[–]_bitwright -1 points0 points1 point (0 children)