- Sep 2024
-
en.wikipedia.org en.wikipedia.org
-
In comparison, Perl/Python/Javascript, which also have the latter property, have other false-like values (0 and empty string), which make || differ from a null-coalescing operator in many more cases (numbers and strings being two of the most frequently used data types). This is what led Perl/Python/Javascript to add a separate operator while Ruby hasn't.
-
- Jul 2024
-
pythononline.net pythononline.net
-
Say goodbye to the headaches of setting up Python locally. No more installations or configurations, you can execute Python code right in your web browser. Just input your code, hit RUN, and watch the magic happen! Compile, run, and share Python code online with our powerful integrated Python development environment (IDE). Want to show off your work? Use the SHARE option to make your code accessible to anyone, anywhere.
One of the best python compilers if you're a new dev and dont want to install Python locally.
Tags
Annotators
URL
-
- Apr 2024
-
lucasoshiro.github.io lucasoshiro.github.io
-
What are the tools that comes on your mind when someone say “debug”? Let me guess: a memory leak detector (e.g. Valgrind); a profiler (e.g. GNU gprof); a function that stops your program and gives you a REPL (e.g. Python’s breakpoint and Ruby’s byebug); something that we call a “debugger” (like GDB, or something similar embedded on the IDEs); or even our old friend, the print function. So, in this text I’ll try to convince you to add Git to your debug toolbelt.
6 differen debugging tools
-
- May 2023
-
stackoverflow.com stackoverflow.com
-
How can I add, subtract, and compare binary numbers in Python without converting to decimal?
I think the requirements of this were not spelled out well. After reading this over a couple of times, I think the problem should be…
"Add, subtract, and compare binary numbers in Python as strings, without converting them to decimal."
I'll take on that problem sometime when I get free time!
-
-
-
'handlers': { 'console': { 'level': 'INFO', 'class': 'logging.StreamHandler', 'stream': sys.stdout, 'formatter': 'verbose' }, },
It's as simple as adding "sys.stdout" to the "stream" attribute.
-
-
codeinthehole.com codeinthehole.com
-
16 August 2011
This is a pretty old article, from 2011. Note that it refers to Python 2.6 and 2.7. Today, Python is up to version 3.12.
-
- Mar 2023
-
mode80.github.io mode80.github.io
-
So why aren't more people using Nim? I don't know! It's the closest thing to a perfect language that I've used by far.
Nim sounds as the most ideal language when comparing to Python, Rust, Julia, C#, Swift, C
Tags
Annotators
URL
-
- Feb 2023
-
Local file Local file
-
What object-oriented means
What does the object-oriented means? Objects are models of somethings that can do certain things and have certain things done to them. Formally, an object is a collection of data and associated behaviors.
-
The difference between object-oriented design and object-orientedprogramming
What is the design and programming mean in OOP?
-
- Oct 2022
-
innerjoin.bit.io innerjoin.bit.io
-
SSL is disabled by default in jdbc, npgsql, node-postgres, and pgx.
Table with programming libraires and their default SSL mode:
-
- Aug 2022
-
blog.khinsen.net blog.khinsen.net
-
What is not OK is what I perceive as the dominant attitude today: sell SciPy as a great easy-to-use tool for all scientists, and then, when people get bitten by breaking changes, tell them that it’s their fault for not having a solid maintenance plan for their code.
-
- Jun 2022
-
www.pythoncentral.io www.pythoncentral.io
-
Definition of Tuple in Python.
-
- Apr 2022
-
pythonspeed.com pythonspeed.com
-
Then, if the string can be represented as ASCII, only one byte of memory is used per character. If the string uses more extended characters, it might end up using as many as 4 bytes per character. We can see how much memory an object needs using sys.getsizeof()
"a" takes less bytes than "❄", which takes less bytes than "💵"
-
-
ruudvanasseldonk.com ruudvanasseldonk.com
-
Using named arguments is nice for languages that support it, but this is not always a possibility. Even in Python, where time.sleep is defined with a single argument named secs, we can’t call sleep(secs=300) due to implementation reasons. In that case, we can give the value a name instead.Instead of this:time.sleep(300)Do this:sleep_seconds = 300 time.sleep(sleep_seconds)Now the code is unambiguous, and readable without having to consult the documentation.
Putting units in variable names
-
- Dec 2021
-
mnscu-my.sharepoint.com mnscu-my.sharepoint.com
- May 2021
-
stackabuse.com stackabuse.com
-
you want to pass a function as an argument to higher-order functions
Functional programming - passing functions as arguments, as opposed to data objects.
-
- Feb 2021
-
sobolevn.me sobolevn.me
-
You can use container values, that wraps actual success or error value into a thin wrapper with utility methods to work with this value. That’s exactly why we have created @dry-python/returns project. So you can make your functions return something meaningful, typed, and safe.
-
-
-
I'm not a fan of listing exceptions functions can throw, especially here in Python, where it's easier to ask forgiveness than permission.
-
- Dec 2020
-
stackoverflow.blog stackoverflow.blog
-
Turning my Jupyter-compatible Python code into Flask-compatible Python code took dozens of hours. I ran into small bugs and errors
That's how I always expected Python notebook development to be
-
- Oct 2020
-
arogozhnikov.github.io arogozhnikov.github.io
-
use code to parameterize calls:
You can write Python code to parametrize calls:
python -c " from mymodule import set_dragon_feeding_schedule, Creatures, Date set_dragon_feeding_schedule( feeding_times=['10:00', '14:00', '18:00'], dishes={Creatures.Tiger: 2, Creatures.Human: 1}, start_day=Date('1020-03-01'), ) "
instead of:
python -m mymodule \ set_dragon_feeding_schedule \ --feeding-times ['10:00','14:00','18:00'] # hopefully this way it gets recognized \ # how will you define parsing a dict with enum to integer mapping? --dishes=Creatures.Tiger:2 \ --dishes=Creatures.Human:1 \ --start-day=1020-03-21 # BTW bash allows no comments in multiline calls
-
That’s it. Types are parsed, checked and converted. Defaults and description are picked from function itself. Even provides bash completions you can install. You wrote no code for that!
Good example of writing CLI interfaces in Python with typer:
import typer from pathlib import Path app = typer.Typer() @app.command() def find_dragon(name: str, path: Path, min_age_years: int = 200): <implementation goes here> @app.command() def feed_dragon(dragon_name: str, n_humans: int = 3): <implementation goes here> if __name__ == "__main__": app()
later we can call it that way:
python example.py find_dragon 'Drake' --path /on/my/planet
-
- Jun 2020
-
martinheinz.dev martinheinz.dev
-
in Python - setting up basic logger is very simple
Apart from printing the result, it is better to debug with logging.
Sample logger:
import logging logging.basicConfig( filename='application.log', level=logging.WARNING, format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', datefmt='%H:%M:%S' ) logging.error("Some serious error occurred.") logging.warning('Function you are using is deprecated.')
the sample result:
[12:52:35] {<stdin>:1} ERROR - Some serious error occurred. [12:52:35] {<stdin>:1} WARNING - Function you are using is deprecated.
to find its location, type:
logging.getLoggerClass().root.handlers[0].baseFilename
Tags
Annotators
URL
-
- May 2020
-
muldoon.cloud muldoon.cloud
-
Programming languages These will probably expose my ignorance pretty nicely.
When to use different programming languages (advice from an Amazon employee):
- Java - enterprise applications
- C# - Microsoft's spin on Java (useful in the Microsoft's ecosystem)
- Ruby - when speed is more important then legibility or debugging
- Python - same as Ruby but also for ML/AI (don't forget to use type hinting to make life a little saner)
- Go/Rust - fresh web service where latency and performance were more important than community/library support
- Haskell/Erlang - for very elegant/mathematical functional approach without a lot of business logic
- Clojure - in situation when you love Lisp (?)
- Kotlin/Scala - languages compiling to JVM bytecode (preferable over Clojure). Kotlin works with Java and has great IntelliJ support
- C - classes of applications (operating systems, language design, low-level programming and hardware)
- C++ - robotics, video games and high frequency trading where the performance gains from no garbage collection make it preferable to Java
- PHP/Hack - testing server changes without rebuilding. PHP is banned at Amazon due to security reasons, but its successor, Hack, runs a lot of Facebook and Slack's backends
-
- Apr 2020
-
-
In Python, when trying to do a dubious operation, you get an error pretty soon. In JavaScript… an undefined can fly through a few layers of abstraction, causing an error in a seemingly unrelated piece of code.
Undefined nature of JavaScript can hide an error for a long time. For example,
function add(a,b) { return + (a + b) } add(2,2) add('2', 2)
will result in a number, but is it the same one?
-
-
realpython.com realpython.com
-
Sometimes, the best way to learn is to mimic others. Here are some great examples of projects that use documentation well:
Examples of projects that use documentation well
(chech the list below)
-
Class method docstrings should contain the following: A brief description of what the method is and what it’s used for Any arguments (both required and optional) that are passed including keyword arguments Label any arguments that are considered optional or have a default value Any side effects that occur when executing the method Any exceptions that are raised Any restrictions on when the method can be called
Class method should contain:
- brief description
- arguments
- label on default/optional arguments
- side effects description
- raised exceptions
- restrictions on when the method can be called
(check example below)
-
From examining the type hinting, you can immediately tell that the function expects the input name to be of a type str, or string. You can also tell that the expected output of the function will be of a type str, or string, as well.
Type hinting introduced in Python 3.5 extends 4 rules of Jeff Atwood and comments the code itself, such as this example:
def hello_name(name: str) -> str: return(f"Hello {name}")
- user knows that the code expects input of type
str
- the same about output
- user knows that the code expects input of type
-
Docstrings can be further broken up into three major categories: Class Docstrings: Class and class methods Package and Module Docstrings: Package, modules, and functions Script Docstrings: Script and functions
3 main categories of docstrings
-
Docstring conventions are described within PEP 257. Their purpose is to provide your users with a brief overview of the object.
Docstring conventions
-
All multi-lined docstrings have the following parts: A one-line summary line A blank line proceeding the summary Any further elaboration for the docstring Another blank line
Multi-line docstring example:
"""This is the summary line This is the further elaboration of the docstring. Within this section, you can elaborate further on details as appropriate for the situation. Notice that the summary and the elaboration is separated by a blank new line. # Notice the blank line above. Code should continue on this line.
-
say_hello.__doc__ = "A simple function that says hello... Richie style"
Example of using
__doc
:Code (version 1):
def say_hello(name): print(f"Hello {name}, is it me you're looking for?") say_hello.__doc__ = "A simple function that says hello... Richie style"
Code (alternative version):
def say_hello(name): """A simple function that says hello... Richie style""" print(f"Hello {name}, is it me you're looking for?")
Input:
>>> help(say_hello)
Returns:
Help on function say_hello in module __main__: say_hello(name) A simple function that says hello... Richie style
-
class constructor parameters should be documented within the __init__ class method docstring
init
-
Scripts are considered to be single file executables run from the console. Docstrings for scripts are placed at the top of the file and should be documented well enough for users to be able to have a sufficient understanding of how to use the script.
Docstrings in scripts
-
Documenting your code, especially large projects, can be daunting. Thankfully there are some tools out and references to get you started
You can always facilitate documentation with tools.
(check the table below)
-
Along with these tools, there are some additional tutorials, videos, and articles that can be useful when you are documenting your project
Recommended videos to start documenting
(check the list below)
-
If you use argparse, then you can omit parameter-specific documentation, assuming it’s correctly been documented within the help parameter of the argparser.parser.add_argument function. It is recommended to use the __doc__ for the description parameter within argparse.ArgumentParser’s constructor.
argparse
-
There are specific docstrings formats that can be used to help docstring parsers and users have a familiar and known format.
Different docstring formats:
- Google docstrings (not a formal specification)
- reStructured Text
- NumPy/SciPy docstrings
- Epytext
-
Daniele Procida gave a wonderful PyCon 2017 talk and subsequent blog post about documenting Python projects. He mentions that all projects should have the following four major sections to help you focus your work:
Public and Open Source Python projects should have the
docs
folder, and inside of it:- Tutorials
- How-To Guides
- References
- Explanations
(check the table below for a summary)
-
Since everything in Python is an object, you can examine the directory of the object using the dir() command
dir() function examines directory of Python objects. For example
dir(str)
.Inside
dir(str)
you can find interesting property__doc__
-
Documenting your Python code is all centered on docstrings. These are built-in strings that, when configured correctly, can help your users and yourself with your project’s documentation.
Docstrings - built-in strings that help with documentation
-
Along with docstrings, Python also has the built-in function help() that prints out the objects docstring to the console.
help() function.
After typing
help(str)
it will return all the info about str object -
The general layout of the project and its documentation should be as follows:
project_root/ │ ├── project/ # Project source code ├── docs/ ├── README ├── HOW_TO_CONTRIBUTE ├── CODE_OF_CONDUCT ├── examples.py
(private, shared or open sourced)
-
In all cases, the docstrings should use the triple-double quote (""") string format.
Think only about """ when using docstrings
-
-
-
Since we have much faster CPUs now, numerical calculations are done in Python which is much slower than Fortran. So numerical calculations basically take the same amount of time as they did 20 years ago.
Python vs Fortran ;)
-
-
towardsdatascience.com towardsdatascience.com
-
Python unit testing libraries, like unittest, can be used within a notebook, but standard CI/CD tooling has trouble dealing with notebooks for the same reasons that notebook diffs are hard to read.
unittest Python library doesn't work well in a notebook
-
- Oct 2018
-
www.paulgraham.com www.paulgraham.com
-
All you can do is send a message (AYCDISAM) = Actors model - there is no direct manipulation of objects, only communication with (or invocation of) them. The presence of fields in Java violates this.
from what I understand in Java... there are some variables on classes (class instances) that are only acessible through methods and for those the "only send message" paradigm holds but there are also fields which are like attributes in python which you can change directly
Tags
Annotators
URL
-
- Jul 2017
-
www.datacamp.com www.datacamp.com
-
Learn Data Science Online
Data analysis courses using R and Python
Tags
Annotators
URL
-
-
runestoneinteractive.org runestoneinteractive.org
-
Runestone Interactive
Interactive textbooks on programming
-
- Apr 2016
-
github.com github.com
-
Transcrypt, a Python to JavaScript transpiler.
Tags
Annotators
URL
-
- Jul 2015
-
www.venturesity.com www.venturesity.com
-
Up for a Challenge?
Do you have what it takes? Signup on www.venturesity.com and unlock opportunities.
-
- Nov 2014
-
learnxinyminutes.com learnxinyminutes.com
-
Python was created by Guido Van Rossum in the early 90s. It is now one of the most popular languages in existence. I fell in love with Python for its syntactic clarity. It’s basically executable pseudocode.
Helpful concise, Python syntax doc
-
-
www.pythonlearn.com www.pythonlearn.com
-
The goal of this site is to provide a set of materials in support of my Python for Informatics: Exploring Information book to allow you to learn Python on your own. This page serves as an outline of the materials to support the textbook.
http://www.pythonlearn.com/ | A great resource for starting programmers looking to build knowledge and gain skills. Open Source Course
-
- Feb 2014
-
pythonpracticeprojects.com pythonpracticeprojects.com
-
The hard part is teaching the consequences of each choice.
Once you get the syntax and basic language idioms out of the way this is the real problem that faces us no matter what language we pick.
-
- Oct 2013
-
www.pip-installer.org www.pip-installer.org
-
Three things are required to fully guarantee a repeatable installation using requirements files.
"Ensuring Repeatability"
-