1 answer

How to test python code containing blank lines in the interpreter

It seems the python interpreter decides "it is now time to execute your code" when it sees a newline. Is there any workaround to this? The scala equivalent is to run ":paste" on a code snippet. BTW ...

1 answers | 16 secs ago by javadba on Stack Overflow stackoverflow.com
1 answer

Getting TypeError: can only concatenate tuple (not “str”) to tuple. How to fix it?

I am writing the following two functions: def sent_transform(sent_string): stemmer = PorterStemmer() tokens = word_tokenize(sent_string) tokens = [stemmer.stem(token.lower()) for token in ...

1 answers | 32 secs ago by Martha Pears on Stack Overflow stackoverflow.com
2 answers

Find pair of index values that minimizes the Euclidian distance between two meshgrids and a column vector

I want to find the two find the pair of values and their index number in a meshgrid that a closets to another pair of values. Suppose I have two vectors a= np.array([0.01,0.5,0.9]) and b = ...

2 answers

How to force 2 Python subprocesses to run one after the other

I want to run 2 programs in Python one after the other. I use Popen but it appears they run in parallel. I have something like this: p1 = Popen(['./program1']) p2 = Popen(['./program2']) How can I ...

2 answers | 2 mins ago by cody on Stack Overflow stackoverflow.com
1 answer

Numpy: Fastest way of computing diagonal for each row of a 2d array

Given a 2d Numpy array, I would like to be able to compute the diagonal for each row in the fastest way possible, I'm right now using a list comprehension but I'm wondering if it can be vectorised ...

1 answers | 2 mins ago by Kel Solaar on Stack Overflow stackoverflow.com
2 answers

Send Cookie Using Python Requests

I am trying to scrape some data (reproduce a POST operation I did in a browser) by using Python Requests library. Expecting it will return the content I saw while using browser by copying the request ...

1 answer

write python package to run inside and outside django

I'm writing python helper package to run inside my django project, but I want to use it also inside other regular python code (e.g. outside of django). The issue is that I want to take the settings ...

1 answers | 4 mins ago by eran on Stack Overflow stackoverflow.com
0 answers

Replicating the escape key press in os.system() method [PYTHON]

I'm trying to create a simple script for executing some commands in the Mac Terminal. I was wondering how I could simulate the escape key press following another command. os.system("emacs") ...

7 answers

Equivalent C++ to Python generator pattern

I've got some example Python code that I need to mimic in C++. I do not require any specific solution (such as co-routine based yield solutions, although they would be acceptable answers as well), I ...

0 answers

write a program that reads a text file with two columns of numbers then calculates the total and average of each column?

I have to write a program that reads a text file with two columns of numbers then calculates the total and average of each column. I was able to separate the columns, but i keep getting a variety of ...

0 answers

Generate next moves of a game using python

I have a board 6x6 (an multidimensional array) and I want to generate the next moves for each piece, it's allowed to come back, go to vertical, horizontal and vertical positions, one square and if ...

2 answers

Run all my doctests for all python modules in a folder without seeing failures because of bad imports

I've started integrating doctests into my modules. (Hooray!) These tend to be files which started as scripts, and are now are a few functions with CLI apps in the __name__=='__main__', so I don't ...

2 answers | 5 mins ago by Thomas on Stack Overflow stackoverflow.com
2 answers

How to dump values from a Grib1/.grb file

I am wondering, is there a way to dump values from a grib1 file? My end goal is to find values for individual messages at latitude and longitude, or at least a grid point. I am using a linux system. ...

4 answers

Substitute multiple whitespace with single whitespace in Python

I have this string: mystring = 'Here is some text I wrote ' How can I substituate the double, triple (...) whitespaces to just one whitespace so that I get: mystring = 'Here is some ...

4 answers | 6 mins ago by creativz on Stack Overflow stackoverflow.com
0 answers

Django test view issue

i'm trying to test a view in my django project. I can't get the context from that view. i'm working in the shell. I type: >>> from django.test.client import Client >>> c = Client() ...

2 answers

Why is my object properly removed from a list when __eq__ isn't being called?

I have the following code, which is making me scratch my head - class Element: def __init__(self, name): self.name = name def __repr__(self): return self.name def eq(self, ...

1 answer

Flask + SQLAlchemy adjacency list backref error

I have the following model: class Category(db.Model): __tablename__ = 'categories' id = db.Column(db.Integer, primary_key=True) parent_id = db.Column(db.Integer, db.ForeignKey(id), ...

1 answer

Replace specific value within file

I'm trying to replace one value in a file with a values. Everything works fine but when I look at the file after its completed there no change at all. What can I use for this? Content of the file: ...

1 answers | 10 mins ago by Beertje Knuffel on Stack Overflow stackoverflow.com
1 answer

configure python in elastic Beanstalk

I'm trying since 4 hours to make a small python code working on elastic Beanstalk But Im getting each time some error such as "Application version failed to deploy." or "Your WSGIPath refers to a file ...

1 answer

Ming ODM MappedClass json conversion

How do I convert a MappedClass object to JSON? json.dumps({"data": mappedClassObject}, indent=True) Above code raises error that MappedClass object is not JSON serializable. Is there any utility ...

1 answers | 13 mins ago by Jack on Stack Overflow stackoverflow.com
3 answers

area of a triangle - python 27

The program is set to calculate the area of a triangle. Triangle sides (a,b,c) are an input. The code works fine only with certian numbers and not with others. E.g. when a,b and c are respectively: ...

3 answers | 13 mins ago by nutship on Stack Overflow stackoverflow.com
1 answer

End a program after meeting user entered sum in Python

total = 0 not_total = True sum_of_square = int(input("Enter desired sum: ")) while (not_total == True): for n in range (2): total = total + n**2 print("The sum of squares ...

1 answers | 15 mins ago by Roshaan S on Stack Overflow stackoverflow.com
1 answer

Change parent shell's environment from a subprocess

If I have a program written in a language other than bash (say python), how can I change environment variables or the current working directory inside it such that it reflects in the calling shell? I ...

1 answers | 16 mins ago by Vivek Ghaisas on Stack Overflow stackoverflow.com
2 answers

in Python remember last method called/get

I'm trying to do something like this: inst = AnyClass() remember_last_method(inst) inst.foo() inst.bar() print inst.last_method # print bar inst.foo print inst.last_method # print foo ...

2 answers | 17 mins ago by user744629 on Stack Overflow stackoverflow.com
0 answers

Using Scrapy, getting “Error: ImportError: No module named testspiders.spiders.followall”

I am trying to run Scrapy from a script, and have been following the tutorial here. I am running into an error message that states Error: ImportError: No module named testspiders.spiders.followall. I ...

1 answer

What is scipy's equivalent to matlab's `mle` function?

I'm trying to fit some data to a mixed model using an expectation maximization approach. In Matlab, the code is as follows % mixture model's PDF mixtureModel = ... @(x,pguess,kappa) pguess/180 + ...

0 answers

Relative Import Issue in Flask when Debug == True

I have a flask app that is running as a module. The structure looks like this app/ __init.py __main__.py app.py cli.py __main__.py looks like this: from . import cli cli.main() cli.py ...

3 answers

Effective 1-5 grams extraction with python

I have a huge files of 3,000,000 lines and each line have 20-40 words. I have to extract 1 to 5 ngrams from the corpus. My input files are tokenized plain text, e.g.: This is a foo bar sentence . ...

2 answers

How find values in an array that meet two conditions using Python

I have an array a=[1,2,3,4,5,6,7,8,9] and I want to find the indices of the element s that meet two conditions i.e. a>3 and a<8 ans=[3,4,5,6] a[ans]=[4,5,6,7] I can use ...

2 answers | 24 mins ago by David on Stack Overflow stackoverflow.com
4 answers

Minify HTML output from Flask application with Jinja2 templates

Is there a Flask or Jinja2 configuration flag / extension to automatically minify the HTML output after rendering the template?

15 30 50 per page
1 2 3