explore-python's People
explore-python's Issues
Update *everything*
How to do this
- Look at
content/basics-1.rst
and match its headings/general structure - Remove any mention of repl.it and replace with code playground (see #1)
print
is a function not a keyword:.. DON'T do this .. code-block:: python print "hi" .. Do this instead: .. code-block:: python print("hi")
type
returns a class, not a type object:.. DON'T do this .. code-block:: python >>> type(60) <type 'int'> .. Do this instead .. code-block:: python >>> type(60) <class 'int'>
- Always use explicit directives
.. DON'T do this Read the following code block:: >>> name = "Hackbright" .. Do this instead Read the following code block: .. code-block:: python >>> name = "Hackbright"
- Any question-answer nonsense should be converted to an
mcq
. Fallback to usingtogglereveal
to hide answers instead oftopic
:.. DON'T do this What part is the variable? .. topic:: ``hackbright`` :class: hover-reveal We can think of this like a nickname... .. Do this instead What part is the variable? .. togglereveal:: ``hackbright`` is the variable. We can think of this like a nickname...
- Use
#.
for numbered lists.. DON'T do this 1) Make a variable 2) Then do this .. Do this instead #. Make a variable #. Then do this
- Remove External Resources section
- Remove Final Assignment section
To do
- Explore Python (this is the title page)
- Welcome/introduction paragraph(s)
- Python Basics
- Intro
- Python Syntax
- Objects and Classes
- Functions
- Practice Section
- Debugging Section
- More Python Basics
- Booleans and Conditional Expressions
- Lists
- Logic and Control Flow
Brython throws JavaScript TypeError instead of regular TypeError
Summary
Most of the time, Brython throws regular lookin' errors but since it is a JavaScript implementation of Python, it occasionally throws bizarre looking errors.
The solution is so simple, it's beautiful. And, as a bonus, it makes a bunch of other issues that come with using Brython disappear (because the solution is to run Python, natively, in the browser!!)
Details
NameError
looks normal, which is why it took me a while to catch on that using Brython is probably a bad idea.
Later in contents/basics-1.rst
, we explain what might happen when you call a function with the wrong number of arguments. This should result in a TypeError
(and it does), but not like any TypeError
you've seen before...
Yuck! 🤮
Needless to say, this would look real confusing to beginners.
Solution
I can't believe I've never thought to do this before, but since the CPython (the default Python distribution) is implemented in C, it can be ported to Wasm. This should allow us to run Python "natively" in the browser, without having to use JavaScript as an intermediary.
Also since porting C to Wasm is A Thing™️, there's probably a tool that'll compile any C executable to Wasm (turns out it does exist — see emscripten).
Which means that porting CPython to Wasm wouldn't just be an easy task — it could be a super easy task so it's probably likely that someone will have done it already!
Mozilla's Pyodide to the rescue
I did manage to find https://github.com/dgym/cpython-emscripten, a dead Python build for emscripten. But the repo manager doesn't have any pre-built releases and I really didn't want to futz with makefiles in order to get the build to work on my machine. Plus, I wasn't even sure this would work out.
That's when I stumbled on this blog post on a Mozilla product called Pyodide. Pyodide is a data science notebook, which is very neat, but that's not all — it's a data science notebook that doesn't need a Python server because Mozilla ported Python to Wasm and it freakin' works.
Sidenote: it's a good thing I never went down the rabbit hole of trying to build https://github.com/dgym/cpython-emscripten myself because I didn't foresee that it wouldn't be 100% compatible with a browser environment out of the box. Mozilla did a lot of additional work to make Python in the browser possible and I highly recommend that you check out their blog post where they talk about how Pyodide works. Another sidenote — why haven't I ever heard of Pyodide before? Oh, right, because every time I see the word "data science" my eyes glaze over. They really should have lead with "Python in the browser".
Anyways, I've deployed a version of this project without Brython over at https://hackbrightacademy.github.io/test/contents/basics-1.html. I had to do a tiny bit of fiddling to get things working, but I'll document that over in a PR.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.