Hex to integer when reading MIDI file

This might be a simple question. I'm reading a binary MIDI file using Python 3 and I'm having problems understanding how to turn the hex value \x00\x00\x00\x06 into an integer, as I don't know what to do with the slash \. To get this value I'm using ...
more »

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

Select 'some' random points from numpy array

I have two related numpy arrays, X and y. I need to select n random rows from X and store this in an array, the corresponding y value and the appends to it the index of the points randomly selected. I have another array index which stores a list of...
more »

2017-04-20 01:04 (2) Answers

XML to CSV using Python

I have XML file which I want to convert to CSV using Python. I need contents from the Testitemname tag as CSV headers and contents in the Testvalue tag as values in CSV. Can some one help me with this? Sample XML file (input) <sample:batch xmln...
more »

2017-04-19 23:04 (1) Answers

Concating pandas dataframe

I have following dataframe: df1 = pd.DataFrame.from_dict({'A':[3,5,1,7], 'DateTime' : pd.date_range("11:00", "14:00", freq="60min")}).set_index('DateTime') df2 = pd.DataFrame.from_dict({'B':[13,15,1,17], 'DateTime' : pd.date_range("12:00", "15:00"...
more »

2017-04-19 21:04 (1) Answers

Can a function know how it has been called?

Is there a way to know within a function if the function has been called by itself or assigned to a variable with = ? I would like to do something like this: def func(): if 'assigned with equal': return 5 else: print 'not as...
more »

2017-04-19 16:04 (2) Answers

How to access pk in views (Django)

I'm writing a small chat programm in Django but have problems getting any further. Here's the code: models.py from django.db import models from datetime import datetime from django.utils import timezone class Chat(models.Model): chatname = mo...
more »

2017-04-19 16:04 (2) Answers

What is python .. ("dot dot") notation syntax?

I recently came across a syntax I never seen before when I learned python nor in most tutorials, the .. notation, it looks something like this: f = 1..__truediv__ # or 1..__div__ for python 2 print(f(8)) # prints 0.125 I figured it was exactly t...
more »

2017-04-19 08:04 (4) Answers

Python variable in string error

I'm putting a variable in a print statement, and I get this error message: Traceback (most recent call last): File "C:\Users\Samuel\workspace\First Python Project\com\fireboxtraining\Person.py", line 13, in <module> print("Dude, %s is n...
more »

2017-04-19 04:04 (1) Answers

python class default parameter

I was wondering if someone could explain why these two examples ultimately yield the same result: class Myclass(): def __init__ (self, parameter=None) if parameter is None: self.parameter = 1.0 else: self.parameter = pa...
more »

2017-04-19 01:04 (2) Answers

How to modify full text of some columns in pandas

I got a fairly big dataframe from a csv in pandas. The problem is that on some columns I get strings of text which I would like to isolate the last character to turn it into integers. I found a solution, but I am fairly sure it's not the most effic...
more »

2017-04-18 23:04 (2) Answers

Array slicing with booleans as indices

Can someone explain this syntax to me? I've searched through docs/blogs but can't find any mention of using booleans as indices for array slicing. I found this syntax in this script convert_base.py: is_negative = num_as_string[0] == '-' num_as_str...
more »

2017-04-18 23:04 (2) Answers

Opening files by using a list?

EDIT: The way I wrote the question did not seam to get the answer I was looking for. Here is a shorter version of the question I think is more clear. I want to take the following code and condense it int a single for loop. with open("vzt_notes", "r...
more »

2017-04-18 20:04 (3) Answers

linux - watch not showing colors through ssh

I have a simple python script that prints text with color, using colorama package. test.py #!/usr/bin/env python from colorama import Fore text = "Test" print(Fore.RED + text) Problem is - when I try to put it into watch command when connected...
more »

2017-04-18 17:04 (1) Answers