Calculating a sequence of numbers using the while loop in Python

Python
I'm trying to return a sequence of numbers using the while loop, starting with the input value num and ending with 1. For example: >>> tray(...
3 years ago

=+ Python operator is syntactically correct

Python
I accidentally wrote: total_acc =+ accuracy instead, of course, of: total_acc += accuracy I searched the net and could not find anything. So wha...
3 years ago

Python - Find second smallest number

Python
I found this code on this site to find the second largest number: def second_largest(numbers): m1, m2 = None, None for x in numbers: ...
3 years ago

Remove newline from file in python

Python
I'm trying to remove all new line characters from a string. I've read up on how to do it, but it seems that I for some reason am unable to do so. Here...
3 years ago

Theano installation in Windows 32bit

Python
I am trying to install Theano library on a windows 32-bit machine. I've already installed python 2.7, numpy, scipy, mingw. The next dependency is bla...
3 years ago

how to declare variable type, C style in python

Python
i'm a programming student and my teacher is starting with C to teach us the programming paradigms, he said it's ok if i deliver my homework in python(...
3 years ago

how to assign variable value in python in terminal commands?

Python
My code: import os from xml.dom import minidom doc = minidom.parse("jobs.xml") job = doc.getElementsByTagName("job")[0] id = job.getElementsByTagNa...
3 years ago

Using metaclasses to "inherit" patched classes

Python
I have a base class extending unittest.TestCase, and I want to patch that base class, such that classes extending this base class will have the patche...
3 years ago

Pandas groupby - apply different functions to half the records in each group

Python
I have something like the following dataframe, where I have non-unique combinations of street address ranges and street names. import pandas as pd df...
3 years ago

Is it true that I can't use curly braces in Python?

Python
I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like ...
3 years ago

Python cannot import (cython) shared library

Python
the last few days, I managed to compile rnnlib as shared library. It is a c++ library. I want to call it from python. My choice fell to cython. so I c...
3 years ago

Getting value of specific key in a dictionary

Python
I have a dictionary like so: li = {'a': 'apple', 'b': 'benana', 'c': 'cherry'} So I have: >>> for key, value in li.items(): ... print...
3 years ago

Django csrf_token in ModelAdmin

Python
I want to add a form to the list display of my ModelAdmin, but can't get the csrf_token to render properly. I'm using django 1.6. My code looks like t...
3 years ago

What is the standard Python docstring format?

Python
I have seen a few different styles of writing docstrings in Python, is there an official or "agreed-upon" style?
3 years ago

Python: How to remove all empty fields in a nested dict

Python
If I have a dict, which field's values may also be a dict or an array. How can I remove all empty fields in it? "Empty field" means a field's value i...
3 years ago

Extract text of element line by line

Python
I am using BeautifulSoup to extract various elements from a website. I have run across a situation for which I am unable to determine an answer. I w...
3 years ago

Getting Substring in Python

Python
I have a string fullstr = "my|name|is|will" , and i would like to extract the substring "name". I used string.find to find the first position of '|' l...
3 years ago

Indexable weak ordered set in Python

Python
I was wondering if there is an easy way to build an indexable weak ordered set in Python. I tried to build one myself. Here's what I came up with: ...
3 years ago

When scattering Flask Models, RuntimeError: 'application not registered on db' was raised

Python
I am re-factoring my Flask application by scattering the models, blueprints but I am having a runtime error. def create_app(): app = flask.Flask...
3 years ago

Easy way to store multiple data in Python 3

Python
I am pretty new to Python, and so far I haven't stumbled upon any problems, until now. I need a data structure that allows me to store multi dimension...
3 years ago