Caching attributes in superclass

I have a class which caches some values to avoid computing them many times, for instance class A(object): def __init__(self, a, b): self.a = a self.b = b self._value = None @property def value(self): if ...
more »

2017-03-20 22:03 (1) Answers

How to re-order and rename pandas pivot?

I am trying to re-order the columns exported to my excel. It is currently ordered alphabetically. I want Sales Order Net Value, Billed Net Value and then Open Amount? Is there a way to rename the columns just for the excel? How can I rename All to ...
more »

2017-03-20 21:03 (1) Answers

Two implementations of Numpy fromfile?

I am trying to update some legacy code that uses np.fromfile in a method. When I try searching the numpy source for this method I only find np.core.records.fromfile, but when you search the docs you can find np.fromfile. Taking a look at these two me...
more »

2017-03-20 19:03 (1) Answers

Sort a list with longest items first

I am using a lambda to modify the behaviour of sort. sorted(list, key=lambda item:(item.lower(),len(item))) Sorting a list containing the elements A1,A2,A3,A,B1,B2,B3,B, the result is A,A1,A2,A3,B,B1,B2,B3. My expected sorted list would be A1,A2,...
more »

2017-03-20 10:03 (4) Answers

Have I been hardware hacked/backdoored?

I'm on Linux Mint, never connected to the internet for weeks, and still not connected, doing some python programming (Python 3.6). I happened to look at the firewall program in it 'report' section and see this (please not that the firewall was actua...
more »

2017-03-20 10:03 (1) Answers

Python in place object update in a for loop

In Python >= 3.5: x = np.zeros((2,3)) for x_e in x: x_e += 123 This operation returns a 2x3 matrix of all 123's. Whereas the following returns all zeros: x = np.zeros((2,3)) for x_e in x: x_e = 123 This is a little off putting to me sin...
more »

2017-03-19 19:03 (2) Answers

About Inheritance and super()

Given the code: class Character(): def __init__(self, name): self.name = name self.health = 50 self.damage = 10 class Warrior(Character): def __init__(self, name, weapon, armor): super(Character).__init__() ...
more »

2017-03-19 12:03 (1) Answers

error and output issues for python matrix?

I am building a function that takes a list made up of lists (ex: [['a'],['b'],['c']]) and outputs it as a table. I cannot use pretty table because I need a specific output (ex | a | b | ) with the lines and the spaces exactly alike. Here is my func...
more »

2017-03-18 21:03 (2) Answers

How to use an SMTP Server with Python 3.6

I have made an SMTP server but I have no idea how to use it. The python docs for smtplib is where I started but I can't do the localhost thing. What email address am I supposed to use? I have sent emails using the gmail port (587) but I want to learn...
more »

2017-03-18 18:03 (0) Answers

Calling a function within the said function

How can i call a def from the same def? I mean, i want to do that: def cal(cal): stat = stat_dict() profile = profile_dict() skill = skill_dict() ... Abreviation.... elif cal == 'Phy': return round(stat['Str']*4 + stat['Con']/3 +...
more »

2017-03-18 16:03 (1) Answers

Selection with pandas multiIndexed dataframe

I have a multiIndexed dataframe that looks like this: df.head(): How can I select all of the rows where the first index == "particular school name" and all of second indices, where the Month column == "Jan"? I haven't worked with multiIndexed d...
more »

2017-03-18 15:03 (1) Answers

19.1.14 email: Examples - Issues with 5th example

I am trying to extract attachments from .msg files. The solutions on github are too detailed for me to understand properly, and the answers here are not as complete as I'd like. This example was pointed out in another question similar to mine, but ...
more »

2017-03-17 23:03 (1) Answers

Numpy normalize multi dim (>=3) array

I have a 5 dim array (comes from binning operations) and would like to have it normed (sum == 1 for the last dimension). I thought I found the answer here but it says: ValueError: Found array with dim 5. the normalize function expected <= 2. I a...
more »

2017-03-17 11:03 (1) Answers

np.percentile not equal to quartiles

I'm trying to calculate the quartiles for an array of values in python using numpy. X = [1, 1, 1, 3, 4, 5, 5, 7, 8, 9, 10, 1000] I would do the following: quartiles = np.percentile(X, range(0, 100, 25)) quartiles # array([1. , 2.5 , 5. , 8.2...
more »

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

Class that should not be instantiated

I want to create a class hierarchy in which I have a class Block which can be instantiated by itself. Then I have a class List which inherits from Block and contains methods common to all lists, and finally I have classes OrderedList, LableledList et...
more »

2017-03-16 15:03 (4) Answers

Output Error for Matrix in Python?

I am trying to create a function that outputs a matrix that contains each item in a list on a separate line with lines in between. The only output I'm getting is quotations (''). I do not understand why. I think I set it all up correctly to output wh...
more »

2017-03-16 01:03 (1) Answers