skip to navigation
skip to content

Planet Python

Last update: July 20, 2019 09:47 PM UTC

July 20, 2019


Weekly Python StackOverflow Report

(clxxxvii) stackoverflow python report

These are the ten most rated questions at Stack Overflow last week.
Between brackets: [question score / answers count]
Build date: 2019-07-20 20:30:24 GMT


  1. Concatenation using the + and += operators in Python - [37/1]
  2. Issues implementing the "Wave Collapse Function" algorithm in Python 2.7 - [26/1]
  3. Finding all combinations based on multiple conditions for a large list - [10/1]
  4. Custom Neural Network Implementation on MNIST using Tensorflow 2.0? - [9/2]
  5. Fast combination of non-unique rows in numpy array, mapped to columns (i.e. fast pivot table problem, without Pandas) - [8/4]
  6. Why does python allow list[a:b] but not list[a] if a and b are out of index range? - [7/4]
  7. What is wrong with the comparison a,b == 1,2? - [7/2]
  8. dictionary keys to replace strings in pandas dataframe column with dictionary values and perform evaluate - [6/5]
  9. Fastest way to search a list of named tuples? - [6/5]
  10. Filling cell based on existing cells - [6/3]

July 20, 2019 08:30 PM UTC


PSF GSoC students blogs

GSoC week #7

Hey everyone,

This is week 7th of Google Summer of Code 2019. So far, I have made the backend of my project and only some things need to be done (regarding deployment and hosting) and it will be working fine. This week I am preparing to start with the left over front end part. So I started with desigining prototype on Adobe XD. Since my project is 70% backend and the front end part is almost similar to the Cheatsheet part which other GSoC student is already working on, so I have to take his prototype and code and just implement my Icons Picker features in it. 

Here is the link to the prototype: https://xd.adobe.com/view/6ed4e66f-e6f5-486e-4e74-340d073d1771-18e5/

PS: Link might not work later because adobe only allows one active link :P

Thanks for reading

Cheers!

July 20, 2019 05:41 PM UTC


Django Weblog

The first PyCon Africa

In just a few weeks, from the 6th to 10th of August, the first ever pan-African PyCon will take place in Accra, Ghana.

PyCon Africa 2019 is an amazing step for the rapidly growing Python community in Africa.

Django at PyCon Africa

Django will be well represented with a Django Girls workshop, several talks, and many members of the Django Software Foundation in attendance.

Numerous DSF members have attended Python events in Africa in the past, and we're excited to see the conference come to fruition. May it be the first of many!

The DSF is one of PyCon Africa's sponsors, passing on some of the donations it has received to help with its goals of supporting community development across the world.

Sponsorship

It's thanks to its sponsors that the event can go ahead. All the basic costs of the event are now covered and attendees from many African countries will be represented. However, the organisers are looking for further sponsorship for the financial assistance programme.

Travel, even within Africa and to a well-connected city like Accra, is expensive and difficult for many Africans. Entry visas to Ghana can cost $100-200 per person, which when combined with other expenses puts the event out of the range of a lot of potential attendees.

There's an opportunity here.

Sponsoring PyCon Africa means more people from across Africa will be able to attend, strengthening the network of the African Python community and building its expertise. We’ve already seen the results of this engagement within Python, as African Pythonistas have advanced in their careers and contributed back to the software and the community (just for example, Anna Makarudze from Zimbabwe serves on the Django Software Foundation board, as Vice President of the DSF itself).

Companies interested in sponsorship should get in touch with the organising team via the website. Individuals can also contribute to the financial assistance fund via the GoFundMe page.

You can read more about the conference on the official website. Also Noah Alorwu and Abigail Mesrenyame Dogbe, two of the organizers, gave a great talk at DjangoCon Europe this year about developing their community - including an announcement for the first DjangoCon Africa next year!

July 20, 2019 03:20 PM UTC


ListenData

Python : Complete Guide to Date and Time Functions

In this tutorial, we will cover python datetime module and how it is used to handle date, time and datetime formatted columns (variables). It includes various practical examples which would help you to gain confidence in dealing dates and times with python functions. In general, Date types columns are not easy to manipulate as it comes with a lot of challenges like dealing with leap years, different number of days in a month, different date and time formats or if date values are stored in string (character) format etc.
Table of Contents

Introduction : datetime module

It is a python module which provides several functions for dealing with dates and time. It has four classes as follows which are explained in the latter part of this article how these classes work.
  1. datetime
  2. date
  3. time
  4. timedelta
datetime python with examples

People who have no experience of working with real-world datasets might have not encountered date columns. They might be under impression that working with dates is rarely used and not so important. To enlighten them, I have listed down real-world examples wherein using datetime module can be beneficial.

  1. Selecting all the saving account holders who were active on 30th June, 2018 and checking their status whether they are still active
  2. Identifying insureds who filed more than 20 claims in the last 3 months
  3. Identifying customers who made multiple transactions in the last 6 months
  4. Extracting dates from timestamp values
Import datetime module
You can import or load datetime module by using the command below -
import datetime
You don't need to install this module as it comes bundled with the installation of python software.

Dates

Here we are using datetime.date class which is used to represent calendar date values. today() method is used to fetch current date.
datetime.date.today()

Output
datetime.date(2019, 7, 19)
In order to display it like a proper calendar date, we can wrap it within print( ) command.

print(datetime.date.today())

Output
2019-07-19
READ MORE »

July 20, 2019 09:38 AM UTC

July 19, 2019


NumFOCUS

Meet our 2019 Google Summer of Code Students (Part 1)

The post Meet our 2019 Google Summer of Code Students (Part 1) appeared first on NumFOCUS.

July 19, 2019 10:13 PM UTC


PSF GSoC students blogs

Weekly check in [week 7 - 08/07 - 14/07]

1. What did you do this week?

  • This week I did principally three things: I studied the REST API, I created a random issue generator and started creating a command-line interface. I studied a bit more the REST API, specifically I studied the implementation that is used in Roundup, since I will have to work with it later. I also created a new section in the website where a developer can generate any number of random new issues, this will be very useful to help with testing later (and probably will be useful to other developers in the future). Last I started creating a command-line interface to access the tracker; I'm still in the early stages of development, and I'm still planning exactly how to implement this feature, and I also need to take in consideration that some sort of command-line access is already present in Roundup.

2. What is coming up next?

  • In the next week I will finish the command-line interface, and I will start work on two new features for the site: a statistic page (the exact details that will be shown in this page still need to be defined) and a new ways of ordering the issues in the main page, as the current implementation is a bit lacking. Eventually a customizable dashboard will be added, but this idea needs to be discussed a bit more.

3. Did you get stuck anywhere?

  • I didn't necessarily got stuck, but I had some difficulties understanding the way Roundup works on a code level, with the added difficulty understanding the changes made in the bpo instance. I had to this as the work now on is not concentrated anymore only on the front-end but also on the back-end.

July 19, 2019 09:41 PM UTC

Week 7: Waypoints and their Interaction

What did I do this week?

I restored most of previous functionality I stripped off for simpler progress. Further major time was spent on getting the working of waypoints correct. After changing most of plotting routines into cartopy, the waypoints were working with all their functions but thy lost functionality and couldn't adapt to change in projection. So I also worked on solving that and did solved it at the end.

What is up next?

Currenty, testing for bugs and making sure the correct functionality of all the option controls like:

    1. WMS
    2. KML
    3. Satellite

Apart from that options to manually enable/disable the features and changing the color is also to be done.

Did you get stuck anywhere?

Yes, I think solving the waypoints issue maybe took a bit more time than needed but I think it was necessary for a confidence boost to me about my abilities to debug and trace the most delicate issues and solve them on my own. 

July 19, 2019 07:58 PM UTC

Blog post: Week 8

This week I focused in two things:

Also in the process I learned a couple of things:

I will continue working at these two items the next week.

 

The second part of GSoC is almost ending and we already have some good results, but lot of work is ahead!

July 19, 2019 07:11 PM UTC


Roberto Alsina

Old Guy @ The Terminal Ep 2: Python Sucks!

Episodio 2! Oh yeah!

Esta es una charla relámpago que dí en la PyCon Argentina de 2018, es cortita y sencilla, ojalá les guste!

July 19, 2019 06:52 PM UTC


Stack Abuse

Python List Sorting with sorted() and sort()

In this article, we'll examine multiple ways to sort lists in Python.

Python ships with two built-in methods for sorting lists and other iterable objects. The method chosen for a particular use-case often depends on whether we want to sort a list in-place or return a new version of the sorted list.

Assuming we want to sort a list in place, we can use the list.sort() method as follows:

>>> pets = ['Turtle', 'Cat', 'Fish', 'Dingo']
>>> pets.sort()
>>> pets
['Cat', 'Dingo', 'Fish', 'Turtle']

By default, the list is sorted in ascending order. Notice how the original pets list is changed after the sort method is called on it. If we don't want this to happen, we can use the built-in sorted() function to return a new sorted list while leaving the original list unchanged:

>>> pets = ['Turtle', 'Cat', 'Fish', 'Dingo']
>>> new_pets = sorted(pets)
>>> new_pets
['Cat', 'Dingo', 'Fish', 'Turtle']
>>> pets
['Turtle', 'Cat', 'Fish', 'Dingo']

The reverse argument can be used to sort lists in descending order:

>>> pets = ['Turtle', 'Cat', 'Fish', 'Dingo']
>>> new_pets = sorted(pets, reverse=True)
>>> new_pets
['Turtle', 'Fish', 'Dingo', 'Cat']
>>> pets.sort(reverse=True)
>>> pets
['Turtle', 'Fish', 'Dingo', 'Cat']

However, there are scenarios where we might want to sort a list based on custom criteria that we define. For example, we may want to sort our pets list by the length of each entry. In that case Python offers the key argument, which accepts a user-defined function to specify the sorting criteria:

>>> pets = ['Turtle', 'Cat', 'Fish', 'Dingo']
>>> get_len(x):
...    return len(x)
...
>>> new_pets = sorted(pets, key=get_len)
>>> new_pets
['Cat', 'Fish', 'Dingo', 'Turtle']
>>> pets.sort(key=get_len)
>>> pets
['Cat', 'Fish', 'Dingo', 'Turtle']

Now let's consider a slightly more complex example. Here we have a list of dictionaries that contain data about a group of people, and we want to sort the list based the peoples' ages, in descending order. To do this we will use both the key and reverse keyword arguments, as well as a Python lambda function. That way we can create the sorting function on the fly, instead of defining it beforehand:

>>> data = [ { 'name': 'Billy', 'age': 26, 'country': 'USA' }, { 'name': 'Timmy', 'age': 5, 'country': 'Australia' }, { 'name': 'Sally', 'age': 19, 'country': 'Costa Rica' }, { 'name': 'Tommy', 'age': 67, 'country': 'Serbia' } ]
>>> new_data = sorted(data, key=lambda x: x['age'], reverse=True)
>>> new_data
[{'country': 'Serbia', 'age': 67, 'name': 'Tommy'}, {'country': 'USA', 'age': 26, 'name': 'Billy'}, {'country': 'Costa Rica', 'age': 19, 'name': 'Sally'}, {'country': 'Australia', 'age': 5, 'name': 'Timmy'}]
>>> data.sort(key=lambda x: x['age'], reverse=True)
>>> data
[{'country': 'Serbia', 'age': 67, 'name': 'Tommy'}, {'country': 'USA', 'age': 26, 'name': 'Billy'}, {'country': 'Costa Rica', 'age': 19, 'name': 'Sally'}, {'country': 'Australia', 'age': 5, 'name': 'Timmy'}]

Notice how the dictionaries startd in a seamingly random order and then ended up with the oldest people first and youngest people last in the list.

Using the sorting functions and lambdas in this way allows us to easily sort complex data structures, all in one line of code. And the order of the sort can be set to descending order by setting reverse=True.

About the Author

This article was written by Jacob Stopak, a software consultant and developer with a passion for helping others improve their lives through code. Jacob is the creator of Code Card - a convenient tool for developers to look up, copy, and paste common code snippets.

July 19, 2019 12:35 PM UTC


Made With Mu

Mu at EuroPython

Mu made a number of appearances at last week’s wonderful EuroPython 2019 conference in Basel, Switzerland. This is a report of what happened…

EuroPython is a famously friendly event, and well known for welcoming folks who are new to the Python community. One of the most effective ways of achieving this is the beginners’ day, run during the tutorial sessions that preceed the main conference. Many folks who have contributed to Mu volunteered their time to organise the beginners’ day and support those taking their first steps into programming. The latest version of Mu was used as the development platform for each of the activities that took place, and it was a huge relief to avoid spending the first hour helping folks download, install, configure and setup Python and a code editor. Mu’s bundled approach saved a huge amount of time!

The following photographs, taken by the talented Gaetano Scognamiglio, give a flavour of the day.

Many thanks especially to Kassia, Dan and Tiago for leading, presenting and planning several of the Mu based activities with which the beginners engaged. By the end of the day they had created computer art with Python’s turtle module, made a simple website with Flask, used MicroPython to program some BBC micro:bits (kindly donated by the micro:bit foundation) and made a cat game with PyGameZero. The afternoon was particularly good fun since the participants were encouraged to let their creative juices flow and come up with simple coding projects of their own.

These two videos capture the sorts of things folks got up to. First up is a hilarious splat-a-cat game.


I particularly like how this participant made a mashup of micro:bit and PyGameZero.


Members of the Mu community were also speaking at EuroPython.

Long time contributor, Tiago, gave a barn storming performance of live coding in front of an appreciative audience, where he created a simple arcade game using just Python’s turtle module and a few lines of code. What I particularly enjoyed about Tiago’s talk was the way he was able to tell the story of how the code is built up in simple steps to create a rather compelling and entertaining game.


I (Nicholas) also gave a talk about how we go about developing Mu. This was a story of the sorts of things we focus on, the technical choices that result and the motivation that keeps us working on Mu.


Finally, at the end of the conference were “code sprints”, where developers got together to code with each on various different projects. During this time Tiago was able to make quite a large number of issues, pull requests and other contributions via Mu’s GitHub repository. Hopefully these will make their way into the upcoming alpha 3 release of Mu.

All that remains is for me to thank the organisers of EuroPython for putting on such a well organised, relaxed, welcoming and community focused conference.

I’m already looking forward to next year’s edition.

July 19, 2019 08:45 AM UTC


PyCharm

PyCharm 2019.2 Release Candidate

PyCharm 2019.2 is almost ready to be released, and we’re happy to announce that a release candidate is available for download now.

New in PyCharm

Enable of actions during indexing

Further improvements

Read the release notes to learn more.

Interested?

Download the RC from our website. Alternatively, you can use the JetBrains Toolbox App to stay up to date.

If you’re on Ubuntu 16.04 or later, you can use snap to get PyCharm RC versions, and stay up to date. You can find the installation instructions on our website.

The release candidate (RC) is not an early access program (EAP) build, and does not bundle an EAP license. If you get PyCharm Professional Edition RC, you will either need a currently active PyCharm subscription, or you will receive a 30-day free trial.

July 19, 2019 06:52 AM UTC


Kushal Das

Setting up WKD

We fetch any GPG public key from the keyservers using the GPG fingerprint (or parts of it). This step is still a problematic one for most of us. As the servers may not be responding, or the key is missing (not pushed) to the server. Also, if we only have the email address, there is no easy way to download the corresponding GPG key.

Web Key Directory to rescue

The Web Key Directory comes to the picture. We use WKD to enable others to get our GPG keys for email addresses very easily. In simple terms:

The Web Key Directory is the HTTPS directory from which keys can be fetched.

Let us first see this in action:

gpg --auto-key-locate clear,wkd --locate-key mail@kushaldas.in

The above will fetch you the key for the email address, and you can also assume the person who owns the key also has access to the https://kushaldas.in server.

There are many available email clients, which will do this for you. For example Thunderbird/Enigmail 2.0 or Kmail version 5.6 onwards.

Setting up WKD for your domain

I was going through the steps mentioned in the GNUPG wiki, while weasel pointed to me to a Makefile to keep things even more straightforward.

all: update install

update:
        rm -rfv openpgpkey
        mkdir -v openpgpkey
        echo 'A85FF376759C994A8A1168D8D8219C8C43F6C5E1 mail@kushaldas.in' | /usr/lib/gnupg/gpg-wks-client -v --install-key
        chmod -v 0711 openpgpkey/kushaldas.in
        chmod -v 0711 openpgpkey/kushaldas.in/hu
        chmod -v 0644 openpgpkey/kushaldas.in/hu/*
        touch openpgpkey/kushaldas.in/policy

        ln -s kushaldas.in/hu openpgpkey/
        ln -s kushaldas.in/policy openpgpkey/

install: update
        rsync -Pravz --delete ./openpgpkey root@kushaldas.in:/usr/local/www/kushaldas.in/.well-known/

.PHONY: all update install

The above Makefile is using gpg-wks-client executable and also pushing the changes to the right directory on the server.

Email providers like protonmail already allow users to publish similar information. I hope this small Makefile will help you to set up your domain.

July 19, 2019 05:35 AM UTC


PSF GSoC students blogs

Week 7 P2

After doing some traceback of the program, I found that when running multithread scanning, each thread instantiates a nvd object NVDSQLite, while in nvd.get_cvelist_if_stale() the object tries to call init_database() regardless of the database situation, and in line 131 of NVDAutoUpdate.py, it will execute the CREATE TABLE IF NOT EXISTS. Since this is not thread-safe, the database might be locked.

Therefore, there might be a logical incorrection in previous code, which is posted in issue #177. I think in getting cves we don't need to check database status since we have already checked it before, if not we could manually checked the status first and then try to get cve, therefore, we only need to make a cursor and connect to the database. So I will fix that first and then test mutithread mode.

Actually I don't think sqlite3 is a good fit with multithread since in python's official document it says "Older SQLite versions had issues with sharing connections between threads. That’s why the Python module disallows sharing connections and cursors between threads. If you still try to do so, you will get an exception at runtime."

July 19, 2019 02:16 AM UTC

Week 7

This week I'm working on implementing mutithread extracting and scaning. So far the extracting works. From this week I acquired how does multithread pool work in Python. The pool has a method called `map`, which is basically same as `map` in Python: taking a function and an iterable as input, apply the function to the iterable in a multithread way. For extracting, this is easy to implement because we don't need to worry about thread-safe issue. However, for scanning, this could be a problem. We know that multiprocessing in operating system is really hard because we need to keep all processes/threads synchronized by using locks/mutex/semaphore. At first I thought this is okay because in scanning function we are supposed to just run mutiple queries at the same time, so we don't need lock.

But acutally this becomes a problem. I will explain later.

Another problem is the difference of pool.map() between python2 and python3. In python3, pool is supported as a context manager, thus we could use something like "*pool.map()", while this is invalid in python2. So we had to go back to use try/finally or the pool will not terminate correctly.

July 19, 2019 02:08 AM UTC


ListenData

Drop one or more columns in Pandas Dataframe

In this tutorial, we will cover how to drop or remove one or multiple columns from pandas dataframe.
What is pandas in Python?
pandas is a python package for data manipulation. It has several functions for the following data tasks:
  1. Drop or Keep rows and columns
  2. Aggregate data by one or more columns
  3. Sort or reorder data
  4. Merge or append multiple dataframes
  5. String Functions to handle text data
  6. DateTime Functions to handle date or time format columns
drop columns python
Import or Load Pandas library
To make use of any python library, we first need to load them up by using import command.
import pandas as pd
import numpy as np
Let's create a fake dataframe for illustration
The code below creates 4 columns named A through D.
df = pd.DataFrame(np.random.randn(6, 4), columns=list('ABCD'))
          A         B         C         D
0 -1.236438 -1.656038 1.655995 -1.413243
1 0.507747 0.710933 -1.335381 0.832619
2 0.280036 -0.411327 0.098119 0.768447
3 0.858730 -0.093217 1.077528 0.196891
4 -0.905991 0.302687 0.125881 -0.665159
5 -2.012745 -0.692847 -1.463154 -0.707779

Drop a column in python

In pandas, drop( ) function is used to remove column(s).axis=1 tells Python that you want to apply function on columns instead of rows.
df.drop(['A'], axis=1)
Column A has been removed. See the output shown below.
          B         C         D
0 -1.656038 1.655995 -1.413243
1 0.710933 -1.335381 0.832619
2 -0.411327 0.098119 0.768447
3 -0.093217 1.077528 0.196891
4 0.302687 0.125881 -0.665159
5 -0.692847 -1.463154 -0.707779
In order to create a new dataframe newdf storing remaining columns, you can use the command below.
newdf = df.drop(['A'], axis=1)
To delete the column permanently from original dataframe df, you can use the option inplace=True
df.drop(['A'], axis=1, inplace=True)
#Check columns in df after dropping column A
df.columns

Output
Index(['B', 'C', 'D'], dtype='object')
The parameter inplace= can be deprecated (removed) in future which means you might not see it working in the upcoming release of pandas package. You should avoid using this parameter if you are not already habitual of using it. Instead you can store your data after removing columns in a new dataframe (as explained in the above section).

If you want to change the existing dataframe, try this df = df.drop(['A'], axis=1)

Remove Multiple Columns in Python

You can specify all the columns you want to remove in a list and pass it in drop( ) function.
Method I
df2 = df.drop(['B','C'], axis=1)
Method II
cols = ['B','C']
df2 = df.drop(cols, axis=1)
Select or Keep Columns
If you wish to select a column (instead of drop), you can use the command
df['A']
To select multiple columns, you can submit the following code.
df[['A','B']]

How to drop column by position number from pandas Dataframe?

You can find out name of first column by using this command df.columns[0]. Indexing in python starts from 0.
df.drop(df.columns[0], axis =1)
To drop multiple columns by position (first and third columns), you can specify the position in list [0,2].
cols = [0,2]
df.drop(df.columns[cols], axis =1)

Drop columns by name pattern

df = pd.DataFrame({"X1":range(1,6),"X_2":range(2,7),"YX":range(3,8),"Y_1":range(2,7),"Z":range(5,10)})
   X1  X_2  YX  Y_1  Z
0 1 2 3 2 5
1 2 3 4 3 6
2 3 4 5 4 7
3 4 5 6 5 8
4 5 6 7 6 9

Drop column whose name starts with letter 'X'

df.loc[:,~df.columns.str.contains('^X')]
How it works?
  1. ^X is a expression of regex language which refers to beginning of letter 'X'
  2. df.columns.str.contains('^X') returns array [True, True, False, False, False].
    True where condition meets. Otherwise False
  3. Sign ~ refers to negate the condition.
  4. df.loc[ ] is used to select columns
It can also be written like :
df.drop(df.columns[df.columns.str.contains('^X')], axis=1)
Other Examples
#Removing columns whose name contains string 'X'
df.loc[:,~df.columns.str.contains('X')]

#Removing columns whose name contains string either 'X' or 'Y'
df.loc[:,~df.columns.str.contains('X|Y')]

#Removing columns whose name ends with string 'X'
df.loc[:,~df.columns.str.contains('X$')]

Drop columns where percentage of missing values is greater than 50%

df = pd.DataFrame({'A':[1,3,np.nan,5,np.nan],
'B':[4,np.nan,np.nan,5,np.nan]
})
% of missing values can be calculated by mean of NAs in each column.
cols = df.columns[df.isnull().mean()>0.5]
df.drop(cols, axis=1)

July 19, 2019 01:08 AM UTC

July 18, 2019


Mike Driscoll

New Malicious Python Libraries Found Targeting Linux

ZDNet published an article recently about a newly discovered set of malware-related Python packages on the Python Package Index (PyPI). These packages contained a backdoor that would only activate when installed on Linux.

These packages were named:

  • libpeshnx
  • libpesh
  • libar

They were written by a user named ruri12. These packages were removed by the PyPI team on July 9, 2019. However they were available since November 2017 and had been downloaded fairly regularly.

See the original article for more details.

As always, when using a package that you aren’t familiar with, be sure to do your own thorough vetting to be sure you are not installing malware accidentally.

Related Reading

The post New Malicious Python Libraries Found Targeting Linux appeared first on The Mouse Vs. The Python.

July 18, 2019 09:00 PM UTC


PSF GSoC students blogs

Weekly Check-in #8 : (12 July - 18 July)

What did you do this week?

What is coming up next?

Did you get stuck anywhere?

Nothing major.

July 18, 2019 05:09 PM UTC


Talk Python to Me

#221 Empowering developers by embedding Python

How do we get kids excited about programming? Make programming tangible with embedded devices. Did you know that after kids learned to code with the BBC micro:bit, 90% of kids "thought coding was for everyone" and 86% said it made CS topics more interesting?

July 18, 2019 08:00 AM UTC


Python Bytes

#139 f"Yes!" for the f-strings

July 18, 2019 08:00 AM UTC


IslandT

Start a new Cryptocurrency project with Python

  1. Start a new python cryptocurrency project in PyCharm.
  2. Install related module needs for this new project.
  3. Write a simple program to find out whether the new module is working or not.

Hello and welcome to another episode of the “Python Programming Journey” article series. Starting from today I have restructured the Python category of this website into these few sections.

  1. Project: Create around 3 projects within this year. I have already started the web analytic project a few days ago and today I have included this new cryptocurrency project. I will restart one of the previous projects which are now on Github anytime soon. All these projects will be uploaded to Github once they have shown some progress and I welcome those of you who know python to contribute to these open projects on Github as well.
  2. Example: We will continue to solve some simple problems with Python once a while on this website.
  3. Tool: Python developer needs a tool, thus once in a while, I will introduce to you all some new tools or IDE used to write the python program.

With that said I am now ready and have a ton of python related materials to write about throughout this year.

As I have mentioned before at the beginning of this article we will start a new Cryptocurrency project with Python, so let get started!

Start a new python cryptocurrency project in PyCharm :

Start the PyCharm IDE, if you do not have one then you can download it for free on its website. After you have opened up PyCharm IDE, Goto File->New Projects. Fill in the necessary details to create this new cryptocurrency project.

Install the cryptocurrency module needs in this project then write a simple python program to see the outcome :

Right-click on the project folder, then select New->Directory, give the new directory a name then click on the ‘OK’ button to create the new project directory where we will keep all the python files in it. Right-click on the newly created directory and select Mark Directory as -> Source Root. Next, we will need to install three python packages (Pandas for extracting data, Requests which is required by the Cryptocompy package and Cryptocompy for retrieving the related cryptocurrency market data) before writing that simple python program. Goto File->Settings to open up the Settings panel, then on the left side of the Settings panel select Project Interpreter. On the right side of the Settings’ panel, click on the plus sign to open up the installation panel, then type in the name of those packages to search for them and then install them to your project. You might need to close the installation panel and click on the plus sign again to start the installation panel again to install another package after you have installed one of the packages.

Finally, right-click on the new directory you have created just now and then select New->Python File, give the new python file a name and then click on the ‘OK’ button to create that new python file. Next, enter these lines of code into that new python file you have just created.

import pandas as pd
from cryptocompy import price

coin_data = price.get_current_price("BTC", ["EUR", "USD"])
print(pd.DataFrame.from_records(coin_data)) # read the returned dictionary object with Pandas then print those data
The average price of BTC vs EUR and BTC vs USD

I just take a look at Google search for these two prices and find out there is a little bit different as compared to those from the REST call, therefore I think those prices might be the average price either from Google or from the CryptoCompare data. Cryptocompy is actually using the CryptoCompare API call to gather those data. If we use the cryptocompy package to make the API call then we do not need to sign up for a free API key from CryptoCompare to make a call to get the required data, therefore I think maybe the data is a little bit outdated which means perhaps the author of this package has downloaded the weekly data and stored on his or her online storage site and thus that API call is actually calling the author website instead of direct call to the CryptoCompare data storage site. If we make a direct call to the CryptoCompare site then there will be a 100,000 calls per month limit under the free API plan package. Anyhow, I will use this python package for a while just for this project.

Hey people, this article takes me a lot of time to create, if you like this article then don’t forget to share it with your friends. Don’t forget to subscribe to the Python-related rss feed through this link with your favorite rss reader to get notified and read the latest article related to Python programming!

July 18, 2019 06:45 AM UTC


PSF GSoC students blogs

4th weekly check-in

Hello everyone!

This weekly check-in is related to the scheduled for July 15.

1. What did you do this week?

Reviewed the code for the `spidermon setup` command so far. Merged setup with enable command and wrote tests for the new modules I wrote.

2. What is coming up next?

Finishing tests and documentation.

3. Did you get stuck anywhere?

Besides my final exams, I really stuck on writing tests. I had no idea how to use pytest fixtures and how they would help my testing. Now I'm getting used to the library and its features and I'm writing relevant tests for my new utils modules.

 

Leonardo Rodrigues.

July 18, 2019 12:16 AM UTC

My path this far - 3rd blog post

Hello guys!

 

This seems to be the post that goes by my 3rd blog post (July 8). I genuinely misunderstood the blog post assignment and I'm sorry I'm late with them.

I had motivation issues the last 2 weeks due to the fact I was really focused with the semester ending in my university. Not only I had exams every week, I had to finish some studies I had late the past weeks, and that contributed negatively to my focus to the project.

Even though I had a good start, I delayed a lot my unit tests and feedback reviewing, which delayed all my cronogram and showed me I was really optimistic with my timings.

My schedule was really good, and I had my feature implemented by the end of the 3rd week; but feature per feature isn't enough, and I was reminded I am contributing to a open source project after all. It's not only about the thing being done, but done right, with tests, clear and maintainable. More than once I was reminded of PEP20, and my efforts were more towards making my code usable by the project than anything else.

For the future, I'll need more steps planned so I can make good schedules of my tasks. It's not only about the code, but the community. It's not only about the features, but all the processes involved in making the feature something good for the project.

I'm really grateful I can experience this and be in contact with so much talented people.

 

Leonardo Rodrigues.

July 18, 2019 12:12 AM UTC


Catalin George Festila

Python 3.7.3 : The pandas python module.

Since I started learning python programming language I have not found a more complex and complete module for viewing complex data. The official documentation of this python module tells us: pandas is a Python package providing fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive. It aims to be the fundamental

July 18, 2019 12:11 AM UTC

July 17, 2019


Roberto Alsina

Old Guy @ The Terminal: Episodio 1!

Este es el primer (y por ahora único, obviamente) episodio de un nuevo canal de video llamado "Old Guy @ The Terminal" en el que muestro algunas cositas de Linux, programación, como se relacionan cosas actuales con cosas viejas y veremos qué más a medida que se me ocurran temas.

Nunca había hecho algo parecido, así que no sean muy duros conmigo ;-)

En este episodio vemos qué es una terminal, como se hace un programa para terminal y una terminal para el programa, porque por qué no.

En algún momento va a haber una versión en inglés (tal vez).

El código: en GitHub

July 17, 2019 08:33 PM UTC