Unexpected results with try, with open

This question already has an answer here: Recursive function returning none in Python [duplicate] 2 answers python recursion return None type 2 answers Return in Recursive Function 3 answers Python recursion and return statements 2 answers Can't figu

This python loop needs a solution

So, I have this code: path_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7

I'm trying to use classes with a dictionary with python

class student(object): def __init__(self, name, age, year): self.name, self.age, self.year = name, age, year self.grades=[] self.grade={} print(name,'-------->','Age:',age,'','Year:',year) def set_grades(self,score): self.grades.append(score) def get

reportlab PDF image: & ldquo; call tobytes () & rdquo;

I'm trying to generate PDF's with Images. im = ImageReader('00001.png') c = canvas.Canvas('networkanalyze.pdf', pagesize=A4) c.drawImage(im, 10, 10, mask='auto') c.showPage() c.save() Traceback: Traceback (most recent call last): File "pdf.py",

Effective way to create dummy variables in python

I want to create a vector of dummy variables(can take only O or 1). I am doing the following: data = ['one','two','three','four','six'] variables = ['two','five','ten'] I got the following two ways: dummy=[] for variable in variables: if variable in

Python CSV delete empty lines

This question already has an answer here: CSV file written with Python has blank lines between each row 5 answers Im having a hard time trying to delete empty(blank) rows from a csv file using python 3.4.3. Each time I run my script the output remain

How to delete documents from Elasticsearch

I can't find any example of deleting documents from Elasticsearch in Python. What I've seen by now - is definition of delete and delete_by_query functions. But for some reason documentation does not provide even a microscopic example of using these f

Popen.communicate () launches UnicodeDecodeError

I have this code: def __executeCommand(self, command: str, input: str = None) -> str: p = sub.Popen(command, stdout=sub.PIPE, stderr=sub.PIPE, stdin=sub.PIPE, universal_newlines=True) p.stdin.write(input) output, error = p.communicate() if (len(error

Why statsmodels GLM does not have R ^ 2 in the results?

I did a simple experiment of a GLM in statsmodels, and was perplexed to find why GLM Results did not contain any R^2 attributes? I feel like there is something very simple here about why GLM does not have an R^2 calculation, and ways that I can calcu

calculate annual and monthly interest

interest = int(float(raw_input("Interest Rate: "))) monintrate = int(float(( interest / 100.0 ) / 12)) annintrate = int(float(interest / 12)) print "Interest: ",interest print "Mon Int Rate: ",monintrate print "Ann Int R

How to work only on ints in Python?

I have problem with my code. The task was to search for 3 integers that solves this equation 6*a+9*b+20*c = x, where x is an input. The problem is that my code only works for floats, and I unable to force it to give me an anwser only while a,b,c are

How to use a previously generated tuple to generate a new tuple

I was wondering if someone could help me figure out how to generate a new tuple with a previously generated tuple. What I have so far is just generating an empty tuple import math as m grav = 9.807 #[m/s**2] gravity http://physics.nist.gov/cgi-bin/cu

bottle-sqlalchemy or sqlalchemy

I am new in both flask and sqlalchemy, I just start working on a flask app, and I am using sqlalchemy for now. I was wondering if there is any significant benefit I can get from using flask-sqlalchemy vs sqlalchemy. I could not find enough motivation

Virtualenv shell errors

I've just installed virtualenv (with Python 2.7.2) on my Mac, and I followed the guide here: http://virtualenvwrapper.readthedocs.org/en/latest/install.html But I now get the following errors when I start up my shell every time: stevedore.extension C

QtSql vs MySQLdb vs SQLAlchemy

I'm developing a PyQt program that will soon switch from an xml type backend to one hosted on a local MySQL server. I've been trying to read around about each of the three options, but thought it might be best to ask ye SO gods. My current experience

Sample google app engine task queue

HI all, I a newbie in google app engine, i'm using python. Currently, i try to working with task queue. But i dont see any complete sample on this metter. So please give me some sample of task queue in google app engine, written in python. ThanksPyth

Understand the behavior of the Python set

The documentation for the built-in type set says: class set([iterable]) Return a new set or frozenset object whose elements are taken from iterable. The elements of a set must be hashable. That is all right but why does this work: >>> l = range(1

Sampling keys due to their values

I have a dictionary in python with key->value as str->int. If I have to chose a key based on it's own value, then as the value gets larger the key has a lower possibility of being chosen. For example, if key1=2 and key2->1, then the attitude of k

assign points to bins

What is a good way to bin numerical values into a certain range? For example, suppose I have a list of values and I want to bin them into N bins by their range. Right now, I do something like this: from scipy import * num_bins = 3 # number of bins to

Django and Sqlite competition problem

I've done a bit of reading related to the concurrency issues with sqlite, but I don't see how they'd apply to Django since it's inherently single threaded. I'm not using any multiprocess modules either. I have absolutely no experience with concurrent