Tuesday, September 28, 2021

Low-code contributions through GitHub

Low-code contributions through GitHub

Healthy, inclusive communities are critical to impactful open source projects. A challenge for established projects is that the history and implicit technical debt increase the barrier to contribute to significant portions of code base. The literacy of large code bases happens over time through incremental contributions, and we'll discuss a format that can help people begin this journey.

At Quansight Labs, we are motivated to provide opportunities for new contributors to experience open source community work regardless of their software literacy. Community workshops are a common format for onboarding, but sometimes the outcome can be less than satisfactory for participants and organizers. In these workshops, there are implicit challenges that need to be overcome to contribute to projects' revision history like Git or setting up development environments.

Our goal with the following low-code workshop is to offer a way for folks to join a project's contributors list without the technical overhead. To achieve this we'll discuss a format that relies solely on the GitHub web interface.

Read more… (5

(continued...)

from Planet SciPy
read more

Amjith Ramanujam: Examples are Awesome

There are two things I look for whenever I check out an Opensource project or library that I want to use.

1. Screenshots (A picture is worth a thousand words).

2. Examples (Don't tell me what to do, show me how to do it).

Having a fully working example (or many examples) helps me shape my thought process.

Here are a few projects that are excellent examples of this.

1. https://github.com/prompt-toolkit/python-prompt-toolkit

A CLI framework for building rich command line interfaces. The project comes with a collection of small self-sufficient examples that showcase every feature available in the framework and a nice little tutorial.

2. https://github.com/coleifer/peewee

A small ORM for Python that ships with multiple web projects to showcase how to use the ORM effectively. I'm always overwhelmed by SqlAlchemy's documentation site. PeeWee is a breath of fresh air with a clear purpose and succinct documentation.

3. https://github.com/coleifer/huey

An asynchronous task queue for Python that is simpler than Celery and more featureful than RQ. This project also ships with an awesome set of examples that show how to integrate the task queue with Django, Flask or standalone use case.

The beauty of these examples is that they're self-documenting and show us how the different pieces in the library work with each other as well as external code outside of their library such as Flask, Django, Asyncio etc.

Examples save the users hours of sifting through documentation to piece together how to use a library.

Please include examples in your project.



from Planet Python
via read more

PyCoder’s Weekly: Issue #492 (Sept. 28, 2021)

#492 – SEPTEMBER 28, 2021
View in Browser »

The PyCoder’s Weekly Logo


Python Behind the Scenes: The GIL and Its Effects on Python Multithreading

GIL stands for the Global Interpreter Lock, and its job is to make the CPython interpreter thread-safe. This post tells you more about non-obvious effects of the GIL. Along the way, you’ll see what the GIL really is, why it exists, how it works, and how it’s going to affect Python concurrency in the future.
VICTOR SKVORTSOV

The Django Template Language: Tags and Filters

Django templates use their own mini-language that’s inspired by Python. This tutorial covers Django template tags and filters, explaining how to compile and use templates. It covers conditional blocks, looping, and inheritance in tags as well as filters for strings and filters for lists.
REAL PYTHON

Receive a $5 Donation to the OSS of Your Choice When You Start Your Free Scout APM Trial Today

alt

Scout is an APM designed to provide the data insights necessary for any developer to become a performance pro. Find and fix observability issues before the customer ever sees them by connecting your error reporting and APM data on one platform, with Scout’s new error monitoring feature add-on →
SCOUT APM sponsor

New Testing Features in Django 4.0

Django 4.0 had its first alpha release last week and the final release should be out in December. It contains an abundance of new features, which you can check out in the release notes. This post looks at the changes to testing in a bit more depth.
ADAM JOHNSON

4 Things Tutorials Don’t Tell You About PyPI

“Although it’s well known PyPI is unforgiving for good reasons, the package publishing process is not as straightforward as the tutorials make it seem. I run into a few unexpected minor bumps none of the guides mention.”
PAOLOA AMOROSO

Discussions

Python Jobs

Senior Python Engineer @ Moody's AI & ML Center of Excellence (New York, NY, USA)

Moody's

Senior Software Engineer (Washington D.C., USA)

Quorum

Senior Backend Software Engineer (Anywhere)

Clay

More Python Jobs >>>

Articles & Tutorials

Python as a Build Tool

“Normally, when starting a Java project (or any other programming project, really), you don’t want to reinvent the wheel. You go with the de-facto build system, folder structure, environment, etc. The ones that the rest of the world is using. Yet, both Skija and JWM are built using Python scripts instead of more traditional Ant/Maven/Gradle/SBT. Why? Let’s find out!”
NIKITA TONSKY

Measuring Your Python Learning Progress

Where are you along the path of learning Python? Do you feel like you’re making progress? What are ways you can put the learning path into a more precise focus? This week on the show, a discussion with Martin Breuss about his recent article “How Long Does It Take to Learn Python?”
REAL PYTHON podcast

What Is Pathlib?

alt

The pathlib module was introduced in Python 3.4 and makes working with filesystem paths easier by implementing a Pythonic, OS-agnostic way to manipulate and interact with paths. In this quick video, Nafiul, developer advocate for PyCharm, shows how to use the library and some of its popular APIs.
JETBRAINS sponsor video

Rock, Paper, Scissors With Python: A Command Line Game

In this course, you’ll learn to program rock paper scissors in Python from scratch. You’ll learn how to take in user input, make the computer choose a random action, determine a winner, and split your code into functions.
REAL PYTHON course

Reverse Strings in Python: reversed(), Slicing, and More

In this step-by-step tutorial, you’ll learn how to reverse strings in Python by using available tools such as reversed() and slicing operations. You’ll also learn about a few useful ways to build reversed strings by hand.
REAL PYTHON

Understand Django: User File Use

Maybe your Django app needs to handle files from users like profile pictures. Accepting files from others is tricky to do safely. In this article, you’ll see the tools that the framework provides to manage files safely.
MATT LAYMAN • Shared by Matt Layman

Django REST Framework Views - APIViews

Django REST Framework (DRF) has its own flavor of views that inherit from Django’s View class. This article explores the most basic of the views: APIView. APIView is the base for every other DRF view.
ŠPELA GIACOMELLI • Shared by Špela Giacomelli

Why Does Black Insist on Reformatting My Entire Project?

Why Black recommends adopting it by reformatting your entire codebase in one go and refuses to do “region reformatting.” Thoughts from the creator for the popular Python auto-formatter.
ŁUKASZ LANGA

DataStax Astra DB – Built on Apache Cassandra. Get 80 Gigabytes of Storage Free Every Month

Need global scale on a startup budget? DataStax Astra DB is a multi-cloud DBaaS built on Apache Cassandra. Painless APIs, always free for developers, and no credit card required.
DATASTAX sponsor

Split, Merge and Rotate PDF Documents Using borb

Split, merge and rotate PDF documents using borb, the open-source pure Python PDF library.
JORIS SCHELLEKENS • Shared by Joris Schellekens

Type Check Your Django App

How to add gradual typing to your Django app, focusing on Django views and Django models.
KRACEKUMAR RAMARAJU • Shared by Kracekumar Ramaraju

Projects & Code

Events

PyConTW 2021

October 2 to October 4, 2021
PYCON.ORG

PyCon ZA 2021

October 7 to October 9, 2021
PYCON.ORG


Happy Pythoning!
This was PyCoder’s Weekly Issue #492.
View in Browser »

alt

[ Subscribe to 🐍 PyCoder’s Weekly 💌 – Get the best Python news, articles, and tutorials delivered to your inbox once a week >> Click here to learn more ]



from Planet Python
via read more

What Is ModelOps and How Is It Different From MLOps?

In the past few years, we’ve seen an increase in Artificial Intelligence and Machine Learning solutions in real-life situations. In big companies, these solutions have to be implemented in hundreds of use cases and it’s difficult to do this manually.  At the enterprise level, the deployment of AI solutions and machine learning models needs to […]

The post What Is ModelOps and How Is It Different From MLOps? appeared first on neptune.ai.



from Planet SciPy
read more

Python for Beginners: Python Scope

While programming in python, we have to deal with various constructs like variables, functions, modules, libraries, etc.  In several instances, it is possible that a variable name used at a place may also be used at a different place without having any relation to the previous definition. In this article on python scope, we will try to understand how the definition of the variables is handled by the python interpreter.

What is a scope in Python?

When we define a variable, a function or a class name in a program, It is accessible in only a certain region of the program. This certain region in which a name, once defined, can be used to identify an object, a variable or a function is called scope.  The scope may extend from a single block of code like a function to the entire runtime environment depending on the definition of variable or function names.  

The concept of scope is closely related to namespaces and scopes are implemented as namespaces. We can consider a namespace as a python dictionary that maps object names to objects. The keys of the dictionary correspond to the names and the values correspond to the objects in python.

In python, there are four types of scope definitions, namely in-built scope, global scope,local scope and enclosing scope. We will study about all of these in the following sections.

What is the in-built scope in Python?

The built-in scope in python contains built-in object and function definitions. It is implemented using the builtins module in recent versions of python. 

Whenever we start the python interpreter, the builtins module is automatically loaded into our runtime environment. As a result, we can access all the functions and objects defined in the module in our program without any need to import them.

The functions like print(),abs(),input(),int(), float(), string(),sum(),max(),sorted() and other similar functions which are not needed to be imported before being used are defined in the built-in scope. We can have a look at the functions and object definitions which are available in the built-in scope as follows.

builtin_names = dir(__builtins__)
for name in builtin_names:
    print(name)

Output:

ArithmeticError
AssertionError
AttributeError
BaseException
BlockingIOError
BrokenPipeError
BufferError
BytesWarning
ChildProcessError
ConnectionAbortedError
ConnectionError
ConnectionRefusedError
ConnectionResetError
DeprecationWarning
EOFError
Ellipsis
EnvironmentError
Exception
False
FileExistsError
FileNotFoundError
FloatingPointError
FutureWarning
GeneratorExit
IOError
ImportError
ImportWarning
IndentationError
IndexError
InterruptedError
IsADirectoryError
KeyError
KeyboardInterrupt
LookupError
MemoryError
ModuleNotFoundError
NameError
None
NotADirectoryError
NotImplemented
NotImplementedError
OSError
OverflowError
PendingDeprecationWarning
PermissionError
ProcessLookupError
RecursionError
ReferenceError
ResourceWarning
RuntimeError
RuntimeWarning
StopAsyncIteration
StopIteration
SyntaxError
SyntaxWarning
SystemError
SystemExit
TabError
TimeoutError
True
TypeError
UnboundLocalError
UnicodeDecodeError
UnicodeEncodeError
UnicodeError
UnicodeTranslateError
UnicodeWarning
UserWarning
ValueError
Warning
ZeroDivisionError
__build_class__
__debug__
__doc__
__import__
__loader__
__name__
__package__
__spec__
abs
all
any
ascii
bin
bool
breakpoint
bytearray
bytes
callable
chr
classmethod
compile
complex
copyright
credits
delattr
dict
dir
divmod
enumerate
eval
exec
exit
filter
float
format
frozenset
getattr
globals
hasattr
hash
help
hex
id
input
int
isinstance
issubclass
iter
len
license
list
locals
map
max
memoryview
min
next
object
oct
open
ord
pow
print
property
quit
range
repr
reversed
round
set
setattr
slice
sorted
staticmethod
str
sum
super
tuple
type
vars
zip

The built-in scope is created once the interpreter is loaded and is destroyed with the closing of the python interpreter. All the names defined in the builtins module are in the built-in scope of the program.

What is a global scope?

The python script in which we write our code is termed as __main__ module by the python interpreter. The scope associated with the __main__ module is termed as a global scope. 

For any python program, there can be only one global scope. The global scope is created once the program starts and gets destroyed with the termination of the python program.

We can understand the notion of global scope from the following program.

myNum1 = 10
myNum2 = 10


def add(num1, num2):
    temp = num1 + num2

    def print_sum():
        print(temp)

    return temp

In the above program, myNum1 and myNum2 are in the global scope of the program. Objects which are present in global scope are defined outside of any code block.

What is a local scope?

The local scope in a python program is defined for a block of code such as function. Each function in a python program has its own local scope in which all its variables  and object names are defined. 

The local scope of a function is loaded when the function is called by any other function. Once the function terminates, the local scope associated with it is also terminated.

To understand the concept of local scope, look at the following example.

myNum1 = 10
myNum2 = 10


def add(num1, num2):
    temp = num1 + num2

    def print_sum():
        print(temp)

    return temp

In the above program, variables num1, num2 and temp exist in the local scope of add() function. These names exists only till the function add() is being executed.

What is an enclosing scope in Python?

Whenever a function is defined inside any other function, the scope of the inner function is defined inside the scope of the outer function. Due to this, The scope of the outer function is termed as the enclosing scope of the inner function. 

We can access all the variable names in a function that has been defined in its enclosing scope. However, we cannot access the variable names inside the outer function which are defined in the inner function. This can be more clear from the following example.

myNum1 = 10
myNum2 = 10


def add(num1, num2):
    temp = num1 + num2

    def print_sum():
        print(temp)

    return temp

Here, the print_sum() function exists in the local scope of add() function. Due to this, the variable names num1, num2 and temp which are defined in add() function are accessible in the scope of print_sum() function.

Conclusion

In this article, we have studied the concept of scope in python. We have also studied different scope types and their examples. To read other python concepts such as list comprehension, stay tuned.

The post Python Scope appeared first on PythonForBeginners.com.



from Planet Python
via read more

Brett Cannon: Unravelling data structure displays

The title of this next post in my series on Python&aposs syntactic sugar may seem odd: what&aposs a "display" when it comes to data structures? It turns out that&aposs the technical term for what most folks would consider the literal form of lists, sets, and dictionaries. Comprehensions are part of a data structure&aposs display, but that was covered in a previous post. For this post I will be covering what you put between the square brackets and curly braces to make lists, sets, and dictionaries directly.

List displays

The language reference for list displays says what you think: stuff between [ and ], separated by commas, becomes a list. But how can we construct a list without using any syntax when each member of that list has been written out? Tuple and list() to the rescue!

The docs on list state that it can take an iterable and return a new list populated with the items from the list, otherwise it returns an empty list. That would suggest that we can translate [1, 2, 3] to list((1, 2, 3)) and [] to list().

We can re-implement list.__init__() to see what this looks like as Python code:

class list(builtins.list):

    """An implementation of list()."""

    def __init__(self, iterable=_NOTHING, /) -> None:
        if iterable is not _NOTHING:
            for item in iterable:
                self.append(item)
An implementation of list__init__()

Leaning on tuples as a way to write out the literal and then translating the tuple to the appropriate type via it&aposs constructor is a trick we are going to use throughout this post.

Set displays

The language reference entry on set displays is very similar to the one for lists. That also means that the translation is simple: {1, 2, 3} becomes set((1, 2, 3)) (set() is already the way to make an empty set so that&aposs taken care of for us).

Implementing set.__init__() for set is also very similar to list.__init__():

class set(builtins.set):

    """An implementation of set()."""

    def __init__(self, iterable=_NOTHING, /) -> None:
        if iterable is not _NOTHING:
            for item in iterable:
                self.add(item)
Implementation of set.__init__()

Dict displays

Dict displays from the language reference don&apost hold any surprises. Everything is evaluated left-to-right which is important as insertion order of dictionaries is preserved since Python 3.7.

The next question is what does dict do in dict.__init__()? There are three ways to populate a dictionary via dict.__init__(), two of which are exclusive. If a positional argument is provided it is checked to see if it has a keys() method. If it does, then the object is considered a map. The iterable from keys() is used to get the values from the map and add them to the dictionary. Without a keys() method the positional argument is considered an iterable of key/value pairs. Regardless of the positional argument, any keyword arguments are used to update the dictionary.

def __init__(self, iterable_or_mapping=_NOTHING, /, **kwargs) -> None:
        if iterable_or_mapping is not _NOTHING:
            if hasattr(iterable_or_mapping, "keys"):
                mapping = iterable_or_mapping
                for key in mapping.keys():
                    self[key] = mapping[key]
            else:
                iterable = iterable_or_mapping
                for key, val in iterable:
                    self[key] = val

        self.update(kwargs)
Implementation of dict.__init__()

With that, we can translate dictionaries into key/value tuples: {&aposa&apos: 1, &aposb&apos: 2} becomes dict(((&aposa&apos, 1), (&aposb&apos, 2))). We can&apost use the keyword arguments since there&aposs no guarantee the keys to the dictionary will be strings.

Tuple displays

One thing that is common about all of the unravellings I did above is they rely on tuples as the bottom data structure that everything devolves into before getting passed into the requisite type. But is there a way to unravel even tuples?

Tuples are written using parentheses and at least one comma (and since the parentheses are used for more than one thing I suspect that&aposs why the language reference doesn&apost have a concept of "tuple displays"). We just gave up using the syntax for other data structures, so we can&apost fall back on lists to unravel tuples (e.g. (1, 2, 3) can&apost be written as tuple([1, 2, 3]) since that list becomes a tuple itself using the technique above). But what if we used a different bit of Python to get ourselves a tuple?

Lambdas to the rescue! Did you know that *args is defined by the language reference for functions to be a tuple? Thanks to that and lambdas being an expression, we can exploit that to get us a tuple without using parentheses to explicitly denote a tuple! So (1, 2, 3) becomes (lambda *args: args)(1, 2, 3)!

This then plays into our other data structures covered in this post as well:

  • [1, 2, 3] becomes list((lambda *args: args)(1, 2, 3))
  • {1, 2, 3} becomes set((lambda *args: args)(1, 2, 3))
  • {&aposa&apos: 1, &aposb&apos: 2} becomes dict((lambda *pairs: pairs)((lambda *first_pair: first_pair)(&aposa&apos, 1), (lambda *second_pair: second_pair)(&aposb&apos, 2)))

Iterable and dictionary unpacking

One last detail when it comes to displays is iterable and dict unpacking. This is when you unpack something in-place as part of a display:

  • [1, 2, *[3, 4]]
  • {1, 2, *{3, 4}}
  • (1, 2, *(3, 4))
  • {&aposa&apos: 1, &aposb&apos: 2, **{&aposc&apos: 3, &aposd&apos: 4}}

Luckily all 4 possibilities lead to a new instance of the appropriate data structure, so there&aposs no in-place updating that needs to be supported. That would have made things tricky as the intermediate data structure would needed to have been stored somehow. The one issue we do have is what is being unpacked can be an aribtrary expression, so you can&apost simply make a longer display, e.g. making [1, 2, *[3, 4]] into list((1, 2, 3, 4)) isn&apost always possible.

But two details do make handling unpacking feasible. One is that every constructor takes an iterable as we have shown. And two, all of the data structures have some operator support for combining two instances together (as of Python 3.9 in the case of dictionaries). That turns out to be enough to unravel unpacking!

  • [1, 2, *[3, 4]] becomes list((1, 2)) + list((3, 4))
  • {1, 2, *{3, 4}} becomes set((1, 2)) | set((3, 4))
  • (1, 2, *(3, 4)) becomes (lambda *args: args)(1, 2) + (lambda *args: args)(3, 4)
  • {&aposa&apos: 1, &aposb&apos: 2, **{&aposc&apos: 3, &aposd&apos: 4}} becomes dict(((&aposa&apos, 1), (&aposb&apos, 2))) | dict(((&aposc&apos, 3), (&aposd&apos, 4)))


from Planet Python
via read more

Real Python: Rock, Paper, Scissors With Python: A Command Line Game

Game programming is a great way to learn how to program. You use many tools that you’ll see in the real world, plus you get to play a game to test your results! An ideal game to start your Python game programming journey is rock paper scissors.

In this course, you’ll learn how to:

  • Code your own rock paper scissors game
  • Take in user input with input()
  • Play several games in a row using a while loop
  • Clean up your code with Enum objects and functions
  • Define more complex rules with a dictionary

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]



from Planet Python
via read more

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...