Introducing FriendUP v1.1 Open Source

The Friend Project is really starting to reach high velocity. After having expanded our development team, we have been able to overcome a lot of challenges in record speed. This has culminated in the…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Python packages that you may not have heard of

Now glom’s not just a data access package, but also a data formatting package. For example, given a dictionary of animals we might want to get a list of all the different colors that are in our data. So if we had this dictionary:

which prints

The end of this string is red.

Another useful feature that crayons provides is that of turning off the colors when you want to via calling crayons.disable().

and our normal, naive, test case might look like:

Notice that this is a bad test case because we forgot to check edge cases. Well, if we rewrite the test case using Hypothesis, we can find those edge cases. Here’s how we would write it:

In this test case, we are asking Hypothesis to generate us test cases where we are testing an integer up to 100 and checking that it is squared correctly. Upon running this, Hypothesis alerts us:

indicating that when x = -1 we fail our test. We can then fix our function and noticed all tests now pass:

Here we have a schema that represents some animal, similar to our glom example. Now we could try load some JSON into this:

However, Marshmallow realises that this data isn’t the correct format since it is missing the color field and therefore raises a ValidationError alerting us to this fact. Note that if we excluded the required=True argument from the color field this would not happen. If we fix the JSON, our call will return to us a native python dictionary ready to be used elsewhere:

and the result would be:

Add a comment

Related posts:

Importing Your CryptoTrader.Tax Report Into TurboTax Online With More than 250 trades

If you have more than 250 taxable events and still want to file with TurboTax Online, they suggest following the below steps. You will still need to keep your 8949 summary from CryptoTrader.Tax for…

AI to create user interfaces

AI should able to draw a user interface to present the information to the user and accept user’s input as click, touch, voice or gestures. Only a few fraction of people in the world are able to code…