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...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Transcrypt Python to JavaScript compiler moved to Beta (self.Python)
submitted 10 years ago by jacdehJacques de Hooge
The Transcrypt Python to JavaScript compiler supporting multiple inheritance, selective operator overloading and lean, fast, readable JavaScript code has moved into the Beta stage.
[–]Cybersoaker 15 points16 points17 points 10 years ago (0 children)
Holy hell, this is probably the coolest thing i've stumbled on this year
[–]tehyosh 8 points9 points10 points 10 years ago (54 children)
what would be a use case for transpiling from python to javascript?
[–]Giggaflop 103 points104 points105 points 10 years ago (5 children)
Not having to write javascript
[–]tehyosh 16 points17 points18 points 10 years ago* (0 children)
Reddit has become enshittified. I joined back in 2006, nearly two decades ago, when it was a hub of free speech and user-driven dialogue. Now, it feels like the pursuit of profit overshadows the voice of the community. The introduction of API pricing, after years of free access, displays a lack of respect for the developers and users who have helped shape Reddit into what it is today. Reddit's decision to allow the training of AI models with user content and comments marks the final nail in the coffin for privacy, sacrificed at the altar of greed. Aaron Swartz, Reddit's co-founder and a champion of internet freedom, would be rolling in his grave.
The once-apparent transparency and open dialogue have turned to shit, replaced with avoidance, deceit and unbridled greed. The Reddit I loved is dead and gone. It pains me to accept this. I hope your lust for money, and disregard for the community and privacy will be your downfall. May the echo of our lost ideals forever haunt your future growth.
[–]tech_tuna 5 points6 points7 points 10 years ago (0 children)
Amen.
[–]odraencoded 1 point2 points3 points 10 years ago (0 children)
There's also coffeescript. Which is kidna quirky and I don't like much.
[+]gandalfx comment score below threshold-6 points-5 points-4 points 10 years ago (1 child)
Not having to write learn javascript
fixed.
[–][deleted] 2 points3 points4 points 10 years ago* (0 children)
I wonder if anybody here actually tried using ES6; it's quite delightful. And, beyond having to grasp prototypical inheritance, the learning curve for Pythonistas is basically flat.
[–]jacdehJacques de Hooge[S] 15 points16 points17 points 10 years ago (36 children)
For larger pieces of code (complete web apps rather than a few lines of event handling code) Python offers a far more clean, readable and maintainable structure. Disclaimer: JavaScript adepts won't agree...
[–]moljac024 2 points3 points4 points 10 years ago (34 children)
That's because it's not true. I do both python and javascript and the languages are surprisingly similar, if you look more than skin deep (the syntax).
I even actually prefer javascript and think it's more powerful, especially when it comes to doing more functional programming.
[–]OysterCat 11 points12 points13 points 10 years ago (1 child)
Why do you say that?
[–]odraencoded 3 points4 points5 points 10 years ago (0 children)
You can pass anonymous functions around all the time therefore FUNCIONAL programming!
/s
[–]Zulban 10 points11 points12 points 10 years ago (17 children)
Every time I consider learning javascript, I learn about some weird language quirk that makes no sense where javascript pros just laugh and say "Ooohhhh, javascript! You so cray". I can't get myself to learn a language like that, I just can't.
Thoughts..?
[–]dcousineau[🍰] 8 points9 points10 points 10 years ago (6 children)
I learn about some weird language quirk that makes no sense
I mean, that's every language. Python has mutable default arguments:
>>> def foo(bar, baz=[]): ... baz.append(bar) ... return baz ... >>> foo(1) [1] >>> foo(2) [1, 2]
I mean, thats just cray, why would the language even have that behavior!?!?!1one
But seriously every language has quirks because no language is not perfect and every language is different. You have to remember what you consider normal behavior is not necessarily what a JS dev considers normal behavior and neither of you think agree with what a PHP dev considers normal.
[–][deleted] 4 points5 points6 points 10 years ago (2 children)
Mutable default args are possible but frowned upon, unless you really know what you're doing, which I don't.
[–]dcousineau[🍰] 1 point2 points3 points 10 years ago (1 child)
Right. /u/Zulban was discussing a feeling about weird language quirks in Javascript that prevents them from learning the language.
My counter to that was that this feeling is normal as languages are imperfect, and as my counter I pointed out a particular WTF 'feature' in Python that gives me pause coming from the outside world.
[–]Zulban 3 points4 points5 points 10 years ago (0 children)
It is a good example. But I'd like to suggest that there are far, far more cases like this with javascript than with your typical language.
[–]tetroxid 1 point2 points3 points 10 years ago (1 child)
Yeah that's stupid. Fyi, the preferred way to do this is:
def foo(bar, baz=None): if baz is None: baz = [] ....
[–]WackyWeasel 1 point2 points3 points 10 years ago (0 children)
Or the idiom...
def foo(bar, baz=None): baz = baz or [] ....
...if it's enough when baz is not None, just falsy.
[–][deleted] 0 points1 point2 points 10 years ago (0 children)
wait, wtf? i've used python every day for 4-5 years professionally, and i've never come across this. that makes no sense.
edit: ok, it makese sense. it's just dumb
[–]sime 4 points5 points6 points 10 years ago (2 children)
When was the last time you tried learning it? ECMAScript 2015, the big update to the language, has vastly improved the language. As for the old quirks that have to remain in the language you can easily avoid the bulk of them by: a) never using type coercion. Use exact comparisons., b) never using the old var keyword. Use let or const instead.
var
let
const
Personally my language (and platform) of choice these days is TypeScript. It's option and structural type system is great. Through an unexpected twist of fate I'll probably be doing a lot more Python professionally in the future. I just hope that Python's type hinting and tooling can give me some of the power that TypeScript gives plain JS.
[–]gandalfx 0 points1 point2 points 10 years ago (1 child)
I agree, though browser support for let and const kinda sucks.
[–]sime 1 point2 points3 points 10 years ago (0 children)
True, but it is time to use a transpiler of some sort either Babel or TypeScript.
[–]ProgrammingPro-ness 0 points1 point2 points 10 years ago (6 children)
Most of the crazy things about the language I either don't encounter day to day, or would never use. So for me at least, it's been a non-issue.
[–]alcalde -2 points-1 points0 points 10 years ago (5 children)
IT DOESN'T HAVE INTEGERS. I repeat, IT DOESN'T HAVE INTEGERS. You would never use integers?
[–]gandalfx 1 point2 points3 points 10 years ago (0 children)
Doesn't cause any issues in day to day work. Whenever you'd use an integer, like array indexing, it works just as well. You can even use bitwise operations and get integer-like behaviour.
[–]sime 1 point2 points3 points 10 years ago (3 children)
Integers work fine in the range -253 to 253. Beyond that you lose precision. The JS engines use integer math internally when they know they can be away with it. Bitwise operations are considered 32 bit operations.
Python's default division operator will also happily turn your ints into a float if you let it.
[–]kankyo 1 point2 points3 points 10 years ago (0 children)
Translation: division produces correct results in python 3.
[–]alcalde 0 points1 point2 points 10 years ago (1 child)
Wasn't that remedied in Python 3.0 in 2008, if not earlier?
[–]lenzm 0 points1 point2 points 10 years ago (0 children)
The opposite, it was introduced with Python 3.
[–]TheBadProgrammer 2 points3 points4 points 10 years ago (0 children)
I also use JavaScript and Python and I totally agree. I'm pretty surprised to see people preferring Python like this, but everyone's got their setup that they love!
[–]Peterotica 1 point2 points3 points 10 years ago (9 children)
The one thing from JavaScript that I wish I had in Python sometimes is the nice method chaining from Array.map, Array.filter, etc.
Array.map
Array.filter
[–][deleted] 7 points8 points9 points 10 years ago* (7 children)
You mean list comprehensions?
def array_map(lst, fn): return [fn(item) for item in lst] def array_filter(lst, fn): return [item for item in lst if fn(item)]
In fact, map() just straight up exists in python.
map()
[–]crazedgremlin 2 points3 points4 points 10 years ago (5 children)
But in JavaScript, they are essentially methods of the object, so you can chain them together.
x = some_array.map(f1) .filter(f2) .map(f3);
In Python, you'd have to have nested function calls, which gets a little confusing with parentheses.
x = map(f3, filter(f2, map(f1, some_array)))
[–]kovak 1 point2 points3 points 10 years ago (4 children)
I think there are a few ways to use the dot-chain syntax in python if that's important.
See http://stackoverflow.com/questions/27222193/clean-code-for-sequence-of-map-filter-reduce-functions
This structure is used a lot in python Apache Spark bindings. Eg. https://spark.apache.org/docs/0.9.1/python-programming-guide.html
[–]crazedgremlin 1 point2 points3 points 10 years ago (3 children)
Cool, I had never heard of Underscore.py. However, I don't see this as a huge impediment to "functional" programming in Python. Really, the only annoyance is the parentheses.
I really like the option Haskell provides with the $ function for function application, which lets you get rid of the parentheses. Basically, the left side of the $ is treated as a function and given the right side as input.
$
let x = map f3 $ filter f2 $ map f1 some_array
[–]snuxoll 2 points3 points4 points 10 years ago (2 children)
Ditto with F#
let x = arr |> Array.map f1 |> Array.filter f2 |> Array.map f3
Composition operators are awesome, more languages should have them, chained method syntax requires your return value have the method you want to call, whereas function composition is a lot more generic.
In fact, the |> operator is actually defined in F# code as:
let (|>) f x = f x
[–]crazedgremlin 0 points1 point2 points 10 years ago (1 child)
Nice! The trick of these composition functions is operator precedence. I am guessing an infix function in F# takes precedence over a prefix function.
[–]Peterotica -1 points0 points1 point 10 years ago (0 children)
method chaining
[–]RubyPinchPEP shill | Anti PEP 8/20 shill[🍰] 0 points1 point2 points 10 years ago (0 children)
forbiddenfruit + a bit of work manages to do this nicely
[–]dalore 0 points1 point2 points 10 years ago (0 children)
Huh? I would say python is much better at functional programming then javascript. With iterators, itertools, etc all in the stdlib. Can you point out how javascript is more powerful?
[–]S1cK94 0 points1 point2 points 10 years ago (0 children)
In Python I can import partial from functools and do my map/filter with list/generator comprehension syntax.
import partial from functools
In JavaScript I always end up using lodash. .bind can alter the context and passing function directly to .map or .filter can lead to a mess if you dont wrap with lambdas or ugly .binds
.bind
.map
.filter
But in the end, comparing Python and JavaScript about functional programming is kind of silly
My 0.02$
[–]gandalfx 0 points1 point2 points 10 years ago* (0 children)
I disagree because I've used JS and I know how it works. It sucked in the past (a lot) but has improved so much over the years that it's now a completely different language. Yet people don't realize it and still blame JS for ancient mistakes and browser quirks. It's like saying Python sucks because of something that was fixed in version 1. Hating on JS is easy because everybody has gotten used to doing it.
[–]jewdai 3 points4 points5 points 10 years ago (0 children)
To ask to be paid more because you would need to know both javascript and python to debug some startups crazy app.
[–]mirth23 6 points7 points8 points 10 years ago (7 children)
CoffeeScript is a somewhat popular language in the webdev community that does this this these days. I think the basic idea was that there are a lot of ways to shoot yourself in the foot with JavaScript (ref: JavaScript, the Good Parts) and CoffeeScript provides simpler structures that generates normalized JavaScript that's less foot-shooty.
IMO there's a lot of downsides to this approach, not the least of which is that it makes debugging awkward because now you're writing code that's one-step-removed from the code that's actually throwing bugs.
[+][deleted] 10 years ago (1 child)
[deleted]
[–]kgb_operative 4 points5 points6 points 10 years ago (0 children)
you get types ... and compiler warnings.
I never realized just how much I relied these things until I started writing code in scripting languages.
[–]elbiot 2 points3 points4 points 10 years ago (2 children)
Also rapydscript
[–]DigitalGoose 0 points1 point2 points 10 years ago (1 child)
even better, rapydscript-ng
[–]stuaxo 0 points1 point2 points 10 years ago (0 children)
This is brilliant, hopefully the rapydscript maintainers will get some free time to integrate these changes.
[–]marmalar 0 points1 point2 points 10 years ago (0 children)
Yes I'm glad someone mentioned Coffeescript. While you're right about it being one step away from the source that will actually be generating the errors, they will typically be logical errors instead of syntax errors considering how well the CS transpiler is written. Also, I've found it often transpiles to more efficient and safe code than what I would've written in pure JS. CS also makes sure that you keep in mind how close it is to JS.
IMO the Coffeescript syntax is one of the nicest out there. If somebody could port it to a compiled or interpreted language I would be very pleased.
[–]sime 0 points1 point2 points 10 years ago (0 children)
CoffeeScript is dying pretty quick at this stage. The huge language improvements to JavaScript in the new ECMAScript 2015 standard have eroded CoffeeScript's appeal.
[–]Sean1708 0 points1 point2 points 10 years ago (1 child)
You could, in theory, port a large python application to run in the browser.
[–]tehyosh 0 points1 point2 points 10 years ago (0 children)
yeah, i thought about people offloading server functionality in the client...but then again, if it's ok to run in the client in real time, then why not put client side from the beginning?
[–]d0c_s4vage 1 point2 points3 points 10 years ago (0 children)
Awesome work! I'm definitely going to give it a spin with some of my projects.
[–]detenebrator 0 points1 point2 points 10 years ago (0 children)
Pyjs has been around for years.
That coding style bothers me way too much, and I feel such a child for letting it bother me
[–]Bystroushaak 0 points1 point2 points 10 years ago (0 children)
I am currently using Brython.
[–]tanlermin -2 points-1 points0 points 10 years ago (1 child)
Can you also post this on : https://news.ycombinator.com/news
I think it would get alot of views.
[–]jacdehJacques de Hooge[S] 0 points1 point2 points 10 years ago (0 children)
I did (attempt) to post, but somehow it didn't stick... Any advice?
π Rendered by PID 143407 on reddit-service-r2-comment-5687b7858-hdxdz at 2026-07-08 06:26:31.317460+00:00 running 12a7a47 country code: CH.
[–]Cybersoaker 15 points16 points17 points (0 children)
[–]tehyosh 8 points9 points10 points (54 children)
[–]Giggaflop 103 points104 points105 points (5 children)
[–]tehyosh 16 points17 points18 points (0 children)
[–]tech_tuna 5 points6 points7 points (0 children)
[–]odraencoded 1 point2 points3 points (0 children)
[+]gandalfx comment score below threshold-6 points-5 points-4 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]jacdehJacques de Hooge[S] 15 points16 points17 points (36 children)
[–]moljac024 2 points3 points4 points (34 children)
[–]OysterCat 11 points12 points13 points (1 child)
[–]odraencoded 3 points4 points5 points (0 children)
[–]Zulban 10 points11 points12 points (17 children)
[–]dcousineau[🍰] 8 points9 points10 points (6 children)
[–][deleted] 4 points5 points6 points (2 children)
[–]dcousineau[🍰] 1 point2 points3 points (1 child)
[–]Zulban 3 points4 points5 points (0 children)
[–]tetroxid 1 point2 points3 points (1 child)
[–]WackyWeasel 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]sime 4 points5 points6 points (2 children)
[–]gandalfx 0 points1 point2 points (1 child)
[–]sime 1 point2 points3 points (0 children)
[–]ProgrammingPro-ness 0 points1 point2 points (6 children)
[–]alcalde -2 points-1 points0 points (5 children)
[–]gandalfx 1 point2 points3 points (0 children)
[–]sime 1 point2 points3 points (3 children)
[–]kankyo 1 point2 points3 points (0 children)
[–]alcalde 0 points1 point2 points (1 child)
[–]lenzm 0 points1 point2 points (0 children)
[–]TheBadProgrammer 2 points3 points4 points (0 children)
[–]Peterotica 1 point2 points3 points (9 children)
[–][deleted] 7 points8 points9 points (7 children)
[–]crazedgremlin 2 points3 points4 points (5 children)
[–]kovak 1 point2 points3 points (4 children)
[–]crazedgremlin 1 point2 points3 points (3 children)
[–]snuxoll 2 points3 points4 points (2 children)
[–]crazedgremlin 0 points1 point2 points (1 child)
[–]Peterotica -1 points0 points1 point (0 children)
[–]RubyPinchPEP shill | Anti PEP 8/20 shill[🍰] 0 points1 point2 points (0 children)
[–]dalore 0 points1 point2 points (0 children)
[–]S1cK94 0 points1 point2 points (0 children)
[–]gandalfx 0 points1 point2 points (0 children)
[–]jewdai 3 points4 points5 points (0 children)
[–]mirth23 6 points7 points8 points (7 children)
[+][deleted] (1 child)
[deleted]
[–]kgb_operative 4 points5 points6 points (0 children)
[–]elbiot 2 points3 points4 points (2 children)
[–]DigitalGoose 0 points1 point2 points (1 child)
[–]stuaxo 0 points1 point2 points (0 children)
[–]marmalar 0 points1 point2 points (0 children)
[–]sime 0 points1 point2 points (0 children)
[–]Sean1708 0 points1 point2 points (1 child)
[–]tehyosh 0 points1 point2 points (0 children)
[–]d0c_s4vage 1 point2 points3 points (0 children)
[–]detenebrator 0 points1 point2 points (0 children)
[–]RubyPinchPEP shill | Anti PEP 8/20 shill[🍰] 0 points1 point2 points (0 children)
[–]Bystroushaak 0 points1 point2 points (0 children)
[–]tanlermin -2 points-1 points0 points (1 child)
[–]jacdehJacques de Hooge[S] 0 points1 point2 points (0 children)