Python: Typehints for argparse.Namespace objects

Is there a way to have Python static analyzers (e.g. in PyCharm, other IDEs) pick up on Typehints on argparse.Namespace objects? Example: parser = argparse.ArgumentParser() parser.add_argument('--somearg') parsed = parser.parse_args(['--somearg','s...
more »

2017-02-16 17:02 (2) Answers

Capturing all output from subprocess in python3

I want to capture all output into variables that subprocess prints out. Here is my code: #!/usr/bin/env python3 import subprocess # Subprocess management import sys # System-specific parameters and functions try: args = ["svn", "info", "/direc...
more »

2017-02-16 16:02 (1) Answers

Matplotlib 2 inconsistent font

I updated Anaconda Python to the latest version (4.3), where they upgraded Matplotlib to version 2. The upgrade has made some major changes to the default style (see here). And, while I really like some of those changes, I am not in agreement with a...
more »

2017-02-15 13:02 (3) Answers

Order of operations in a dictionary comprehension

I came across the following interesting construct: assuming you have a list of lists as follows: my_list = [['captain1', 'foo1', 'bar1', 'foobar1'], ['captain2', 'foo2', 'bar2', 'foobar2'], ...] and you want to create a dict out of them with the ...
more »

2017-02-13 11:02 (4) Answers

django jeft join query

I have following models: class TestCaseStatus(models.Model): name = models.CharField(default='n/a', max_length=50) def __str__(self): return self.name class TestCase(models.Model): id = models.CharField(unique=True, max_length=...
more »

2017-02-12 04:02 (1) Answers

Advanced input in python

I want to receive some information from a user in a next way: My score is of 10 - is already printed Between 'is' and 'of' there is an empty place for user's input so he doesn't enter his information at the end( if using simple input() ) but in ...
more »

2017-02-11 14:02 (2) Answers

Functions and random integers

I want to first say this is my homework, so I do not want it done for me I just need some guidance as my teacher is not providing it for me nor can I find my answer online. Here is my problem Write a program that displays a table of distance equiva...
more »

2017-02-09 03:02 (0) Answers

File encoding the same code Windows, Linux

Can someone tell me why the same code works fine on Linux but it is not on Windows? The following code was executed on each os: print("Output :" + open("data.txt", "r").read()) On Windows error was raised: UnicodeDecodeError: 'charmap' codec can...
more »

2017-02-08 21:02 (1) Answers

How to split up a string using 2 split parameters?

Example: r="\\%4l\\%(wit.*wit\\)\\|\\%8l\\%(rood.*rood\\)\\|\\%12l\\%(blauw.*blauw\\)\\|\\%13l\\%(wit.*wit\\)\\|\\%14l\\%(blauw.*blauw\\)\\|\\%15l\\%(wit.*wit\\)\\|\\%16l\\%(wit.*wit\\)\\|\\%17l\\%(rood.*rood\\)\\|\\%19l\\%(wit.*wit\\)\\|\\%21l\\%(...
more »

2017-02-05 16:02 (2) Answers

Starting svn diff using Meld from a python3 script

I'm trying to run svn diff using Meld from a python3 script. So far I been using a separate shell script to achieve this. I'm sure there must be another way to do this without using a shell script. #!/usr/bin/env python3 #-*- coding: utf-8 -*- impo...
more »

2017-02-05 12:02 (0) Answers

Puput (Wagtail based blog) - Where are the files?

I've added a puput blog to an existing Django project. I followed all the steps for setting up a standalone blog app (https://puput.readthedocs.io/en/latest/setup.html). It works fine in that I now have working blog at http://127.0.0.1:8000/blog/ an...
more »

2017-02-05 08:02 (1) Answers

Mandelbrot set displays incorrectly

This is my attempt to program the Mandelbrot set in Python 3.5 using the Pygame module. import math, pygame pygame.init() def mapMandelbrot(c,r,dim,xRange,yRange): x = (dim-c)/dim y = (dim-r)/dim #print([x,y]) x = x*(xRange[1]-xRang...
more »

2017-02-05 03:02 (2) Answers

Django 1.10 patterns rewrite

The Wagtail docs contain the following example for setting up urls.py: if settings.DEBUG: from django.contrib.staticfiles.urls import staticfiles_urlpatterns urlpatterns += staticfiles_urlpatterns() # tell gunicorn where static files are in...
more »

2017-02-04 19:02 (3) Answers

How to replace df.ix with df.loc or df.iloc?

Given the coming deprecation of df.ix[...] How can i replace .ix in this piece of code? df_1 = df.ix[:, :datetime.time(16, 50)] df_2 = df.ix[:, datetime.time(17, 0) : ] df_3 = df2.shift(periods = 1) df_4 = pd.concat([df3, df1], axis =...
more »

2017-02-03 13:02 (1) Answers

Mapping a string into a list of pairs

I have a for loop that iterates through a string and returns pairs of each character and the next following one: >>> word = 'abcdef' >>> for i in range(len(word)-1): ... print word[i:i+2] ... ab bc cd de ef Is it possible to ...
more »

2017-01-29 18:01 (3) Answers

python3 scrape youtube save on an array

I am runnig the following easy script to scrape youtube and it works fine. How can I store the output as array instead of printing it out? My aim is to save the results of the search storing the keyword searched, the links to the video and a string w...
more »

2017-01-25 20:01 (0) Answers