title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
How to activate virtualenv in Cygwin | 39,202,912 | <p>complete beginner here. Trying to build a flask web app. Using Windows 8.</p>
<p>Having some problems activating my python virtualenv in Cygwin. I have been using git shell up till now with no problems.</p>
<p>I copied my folder ("app") into my cygwin home directory and it is set up like so:</p>
<pre><code>app - ... | 0 | 2016-08-29T09:33:43Z | 39,207,090 | <p>You should not move the virtualenv. The <code>activate</code> script inside the virtualenv uses absolute paths internally. If you move the directory, the paths will no longer work, and so <code>which python</code> finds the first valid binary on <code>PATH</code>, which is your global binary.</p>
<p>If you need to ... | 0 | 2016-08-29T13:06:03Z | [
"python",
"shell",
"cygwin",
"virtualenv"
] |
AssertionError: yield from wasn't used with future | 39,202,962 | <p>This code:</p>
<pre><code>import asyncio
async def wee():
address = 'localhost'
port = 5432
reader, writer = asyncio.open_connection(address, port)
message = '/t'
print('Send: %r' % message)
writer.write(message.encode())
async def main():
t2 = asyncio.ensure_future(wee())
await t2
... | 1 | 2016-08-29T09:35:31Z | 39,203,159 | <p>You need to change the <code>asyncio.open_connection(address, port)</code> line to <code>await asyncio.open_connection(address, port)</code>. Open connection returns a future/promise etc and you need to "await" that result in order to be able to access its contents.</p>
| 2 | 2016-08-29T09:45:45Z | [
"python",
"python-3.x",
"python-asyncio"
] |
how to match paper sheet by opencv | 39,203,011 | <p>I have some kinds of paper sheet and I am writing python script with opencv to recognize the same paper sheet to classify. I am stuck in how to find the same kind of paper sheet. For example, I attached two pic. Picture 1 is the template and picture 2 is some kind of paper I need to know if it is matching with the t... | 1 | 2016-08-29T09:37:56Z | 39,221,626 | <p>I'm not sure if such paper form is rich enough in visual information for this solution, but I think you should start with feature detection and homography calculation (opencv tutorial: <a href="http://docs.opencv.org/3.0-beta/doc/tutorials/features2d/feature_homography/feature_homography.html#feature-homography" rel... | 0 | 2016-08-30T07:44:11Z | [
"python",
"c++",
"algorithm",
"opencv",
"matching"
] |
how to match paper sheet by opencv | 39,203,011 | <p>I have some kinds of paper sheet and I am writing python script with opencv to recognize the same paper sheet to classify. I am stuck in how to find the same kind of paper sheet. For example, I attached two pic. Picture 1 is the template and picture 2 is some kind of paper I need to know if it is matching with the t... | 1 | 2016-08-29T09:37:56Z | 39,222,154 | <p>Check out the findContours and MatchShape function. Either way, you are much better off matching a specific visual ID within the form that is representative of the form. Like a really simple form of barcode.</p>
| 0 | 2016-08-30T08:13:10Z | [
"python",
"c++",
"algorithm",
"opencv",
"matching"
] |
Optional keys in string formats using '%' operator? | 39,203,016 | <p>Is is possible to have optional keys in <a href="https://docs.python.org/2/library/stdtypes.html#string-formatting-operations" rel="nofollow">string formats</a> using '%' operator?
Iâm using the <strong>logging</strong> API with Python 2.7, so I can't use <a href="https://www.python.org/dev/peps/pep-3101/" rel="n... | 0 | 2016-08-29T09:38:14Z | 39,207,618 | <p>A) The <code>defaultdict</code> approach works fine, but only if used directly.</p>
<pre><code>>>> import collections
>>> dd=collections.defaultdict(str)
>>> dd['k'] = 22
>>> '%(k)s %(nn)s' % dd
'22 '
</code></pre>
<hr>
<p>B) The <code>extra</code> argument to a log function is... | 1 | 2016-08-29T13:33:50Z | [
"python",
"python-2.7",
"string-formatting"
] |
Function keeps doing the same thing | 39,203,043 | <p>This program suppose to find 1000 prime numbers and pack them into a list</p>
<p>Here's the code:</p>
<pre><code>num = raw_input('enter a starting point')
primes = [2]
num = int(num)
def prime_count(num):
if num % 2 == 0: #supposed to check if the number is divided by 2 evenly
num = num +1 #if it is, ... | 0 | 2016-08-29T09:39:26Z | 39,203,135 | <p>You're never using the return value from prime_count. Try this:</p>
<pre><code>while len(primes) <= 999:
num = prime_count(num)
</code></pre>
<p>You've set your self up for confusion by using the name <code>num</code> as both a parameter (also a local variable) inside of <code>prime_count</code>, and also... | 0 | 2016-08-29T09:44:15Z | [
"python",
"function",
"loops"
] |
Python configparser get all from a section and write to new file | 39,203,224 | <p>how would one use python config parser to get every entry under a single section and write to a new file without actually specifying each entry</p>
<p>for example how would I go about getting everything under section "testing" and write to a new file without using config.get and listing every entry?</p>
<p>config ... | 1 | 2016-08-29T09:48:15Z | 39,204,762 | <p>"for x in testing" will just parse the keys of the dictionary 'testing' .</p>
<p>you need :
for x in testing.items():
print x[0] + '=' + x[1]</p>
| 0 | 2016-08-29T11:07:33Z | [
"python",
"parsing",
"config",
"python-config"
] |
Printing out all the possibilites of ambiguous Morse code | 39,203,263 | <p>I've been tasked with a problem for school and it's left me stumped. What I have to do is read in an ambiguous Morse Code string (i.e. without any spaces to state what is a letter and what is not) and print out what all the possible <em>valid</em> english translations for that Morse Code could be. I've seen an algor... | -1 | 2016-08-29T09:50:00Z | 39,208,045 | <p>To complete the program, you need to use a recursive algorithm as there are so many possible combinations of words.</p>
<p>I have changed your variable names so that they are easy to understand what data they hold.</p>
<p>The <code>decode</code> function is used as a recursive algorithm. The first line checks if t... | 1 | 2016-08-29T13:54:25Z | [
"python",
"morse-code"
] |
how to pass string containing newline to python in php | 39,203,274 | <p>I have the following line of code in php that I m using to execute the python screen. and it takes in text from a html textarea which will contain newline characters</p>
<pre><code>$string = $_POST['textarea']; // e.g. "String 1\n string 2\n"
$command = escapeshellcmd("python script.py -c \"$string\"");
</code></pr... | 0 | 2016-08-29T09:50:20Z | 39,217,994 | <p>I have managed to find a way to do this.</p>
<p>In the php file, replace all the newline with '\n' before calling escapeshellcmd</p>
<pre><code>$string = trim(preg_replace('/[\r\n]+/', '\n', $_POST['textarea']));
// For a string like:
// abcd
// defg
// will become
// abde\\ndefg
</code></pre>
<p>Since the newli... | 0 | 2016-08-30T02:42:45Z | [
"php",
"python"
] |
How to change the field value as Red color when end date is less than current date on field? | 39,203,384 | <p>I want to change the field value as red color when end date is less than current date on field ? I have field name followup_date, If Follow up Date has passed then it should be marked as Red on Grid. The method will create previous date is less than current date, but i have no idea how to write this method? How is ... | 0 | 2016-08-29T09:56:06Z | 39,213,314 | <p>If by grid you mean a One2many table. Here is an example that may help you.</p>
<pre><code><tree colors="red:followup_date < current_date">
<field name="followup_date"/>
</tree>
</code></pre>
| 1 | 2016-08-29T18:59:57Z | [
"python",
"methods",
"openerp",
"odoo-8"
] |
How to change the field value as Red color when end date is less than current date on field? | 39,203,384 | <p>I want to change the field value as red color when end date is less than current date on field ? I have field name followup_date, If Follow up Date has passed then it should be marked as Red on Grid. The method will create previous date is less than current date, but i have no idea how to write this method? How is ... | 0 | 2016-08-29T09:56:06Z | 39,215,310 | <p>I resolved my problem by this, its working for me now...</p>
<pre><code> <tree string="Claims" position="attributes">
<attribute name="colors">red:followup_date &lt; current_date;</attribute>
</tree>
<field name="stage_id" position="after">
... | 0 | 2016-08-29T21:12:58Z | [
"python",
"methods",
"openerp",
"odoo-8"
] |
Scikit Learn Categorical data with random forests | 39,203,422 | <p>I am trying to work with the titanic survival challenge in kaggle <a href="https://www.kaggle.com/c/titanic" rel="nofollow">https://www.kaggle.com/c/titanic</a>.</p>
<p>I am not experienced in R so i am using Python and Scikit Learn for the <strong>Random Forest Classifier</strong></p>
<p>I am seeing many people u... | 0 | 2016-08-29T09:57:44Z | 39,208,325 | <p>If you just map levels to numeric values, python will treat your values as numeric. That is, numerically <code>1<2</code> and so on even if your levels were initially unordered. Think about the "distance" problem. This distance between 1 and 2 is 1, between 1 and 3 is 2. But what were the original distances betwe... | 2 | 2016-08-29T14:08:02Z | [
"python",
"scikit-learn",
"random-forest"
] |
Convert a list of dictionaries into a set of dictionaries | 39,203,516 | <p>How can i make a set of dictionaries from one list of dictionaries?</p>
<p>Example:</p>
<pre><code>import copy
v1 = {'k01': 'v01', 'k02': {'k03': 'v03', 'k04': {'k05': 'v05'}}}
v2 = {'k11': 'v11', 'k12': {'k13': 'v13', 'k14': {'k15': 'v15'}}}
data = []
N = 5
for i in range(N):
data.append(copy.deepcopy(v1))
... | -1 | 2016-08-29T10:02:06Z | 39,203,628 | <p>Dictionaries are mutable and therefore not hashable in python.</p>
<p>You could either create a dict-subclass with a <code>__hash__</code> method. Make sure that the hash of a dictionary does not change while it is in the set (that probably means that you cannot allow modifying the members).
See <a href="http://cod... | 0 | 2016-08-29T10:07:13Z | [
"python",
"dictionary"
] |
Convert a list of dictionaries into a set of dictionaries | 39,203,516 | <p>How can i make a set of dictionaries from one list of dictionaries?</p>
<p>Example:</p>
<pre><code>import copy
v1 = {'k01': 'v01', 'k02': {'k03': 'v03', 'k04': {'k05': 'v05'}}}
v2 = {'k11': 'v11', 'k12': {'k13': 'v13', 'k14': {'k15': 'v15'}}}
data = []
N = 5
for i in range(N):
data.append(copy.deepcopy(v1))
... | -1 | 2016-08-29T10:02:06Z | 39,204,359 | <p>A cheap workaround would be to serialize your dicts, for example:</p>
<pre><code>import json
dset = set()
d1 = {'a':1, 'b':{'c':2}}
d2 = {'b':{'c':2}, 'a':1} # the same according to your definition
d3 = {'x': 42}
dset.add(json.dumps(d1, sort_keys=True))
dset.add(json.dumps(d2, sort_keys=True))
dset.add(json.dump... | 2 | 2016-08-29T10:46:35Z | [
"python",
"dictionary"
] |
Euclidean Distance Matrix Using Pandas | 39,203,662 | <p>I have a .csv file that contains city, latitude and longitude data in the below format:</p>
<pre><code>CITY|LATITUDE|LONGITUDE
A|40.745392|-73.978364
B|42.562786|-114.460503
C|37.227928|-77.401924
D|41.245708|-75.881241
E|41.308273|-72.927887
</code></pre>
<p>I need to create a distance matrix in the below format ... | 1 | 2016-08-29T10:08:57Z | 39,205,919 | <p>You can use <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.pdist.html#scipy.spatial.distance.pdist" rel="nofollow">pdist</a> and <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.squareform.html#scipy.spatial.distance.squareform" rel="nofollow">s... | 2 | 2016-08-29T12:04:48Z | [
"python",
"pandas",
"dataframe"
] |
Euclidean Distance Matrix Using Pandas | 39,203,662 | <p>I have a .csv file that contains city, latitude and longitude data in the below format:</p>
<pre><code>CITY|LATITUDE|LONGITUDE
A|40.745392|-73.978364
B|42.562786|-114.460503
C|37.227928|-77.401924
D|41.245708|-75.881241
E|41.308273|-72.927887
</code></pre>
<p>I need to create a distance matrix in the below format ... | 1 | 2016-08-29T10:08:57Z | 39,205,931 | <pre><code>for i in df["CITY"]:
for j in df["CITY"]:
row = df[df["CITY"] == j][["LATITUDE", "LONGITUDE"]]
latitude = row["LATITUDE"].tolist()[0]
longitude = row["LONGITUDE"].tolist()[0]
df.loc[df['CITY'] == i, j] = ((df["LATITUDE"] - latitude)**2 + (df["LONGITUDE"] - longitude)**2)**... | 0 | 2016-08-29T12:05:12Z | [
"python",
"pandas",
"dataframe"
] |
List of Structure subclass returns wrong values when casting to numpy array | 39,203,714 | <p>I've built a simple Structure subclass with two fields, holding a void pointer to an array, and the array length. However, when I try to create a list of these using input lists of the same length, the value of the returned void pointer is the same as the last array used to create the instance:</p>
<pre><code>from ... | 1 | 2016-08-29T10:11:19Z | 39,259,163 | <p>The problem is that the numpy array is immediately garbage-collected and the underlying memory freed, resulting in a dangling pointer.</p>
<p>The solution is to keep a reference to the underlying <code>buffer</code> object:</p>
<pre><code>def __init__(self, seq):
array = np.array(seq, dtype=np.float64)
sel... | 2 | 2016-08-31T21:18:49Z | [
"python",
"arrays",
"numpy",
"ctypes"
] |
'CsrfViewMiddleware' object is not iterable | 39,203,826 | <p>I am new to Django, and I just took over from another developer on this project. All I have done so far is clone the code from git and install the dependencies.</p>
<p>Immediately after setting up the project, and running <code>python manager.py runserver</code> and going to <code>localhost:8000/admin</code> I get ... | 0 | 2016-08-29T10:18:59Z | 39,204,804 | <p>Try removing <code>'django.middleware.csrf.CsrfViewMiddleware',</code> from <code>TEMPLATES</code>. Probably <code>'corsheaders.middleware.CorsMiddleware',</code> too</p>
| 3 | 2016-08-29T11:09:39Z | [
"python",
"django",
"django-templates",
"django-views",
"django-csrf"
] |
Why does '\b' look like invalid as the last character of sentence in Python? | 39,203,888 | <p>I feel puzzled about '\b'.
I know that '\b' means backspace, but in Python, if the last character of sentence it seems invalid.</p>
<p>Example:</p>
<pre><code>>>print 'abc\be'
>>abe
>>print 'abc\b'
>>abc
</code></pre>
<p>Why?</p>
<p>Andï¼another example on OSX/python2.7.10 <strong>IPytho... | 3 | 2016-08-29T10:22:26Z | 39,203,974 | <p>There's an implied newline after the <code>print</code> finishes, which causes a newline immediately after the <code>\b</code> is echoed. This causes the cursor to move to the next line, so there won't be anything overwriting the <code>c</code> from the previous line.</p>
<p>If you did something like:</p>
<pre><co... | 4 | 2016-08-29T10:26:43Z | [
"python",
"character"
] |
@login_required flask trouble. No user_loader has been installed for this LoginManager | 39,203,956 | <p>I have created separate Blueprints for separate modules of my project.
I am having trouble with @login_required decorator.
I read a very similar <a href="http://stackoverflow.com/questions/28575234/login-required-trouble-in-flask-app">question</a> but it couldn't help me.</p>
<p>The model.py file is as following:</... | -1 | 2016-08-29T10:25:12Z | 39,207,829 | <p>You have two different applications: the one in <code>__init__</code> and the one in your blueprint module. This is wrong. You're registering Flask-Login with the second application, but that application is never run (and shouldn't be).</p>
<p>Remove the following from your blueprint module.</p>
<pre><code>appli... | 0 | 2016-08-29T13:44:16Z | [
"python",
"flask",
"flask-login"
] |
Send XML to activeMQ using Django | 39,204,113 | <p>I am trying to send a XML file generated using 'ElementTree' to activeMQ server using python django 'requests' library .My views.py code is :</p>
<pre><code>from django.shortcuts import render
import requests
import xml.etree.cElementTree as ET
# Create your views here.
def index(request):
return render(reques... | 0 | 2016-08-29T10:33:58Z | 39,292,983 | <p>I suggest looking at using the available STOMP protocol instead of HTTP. You'll have more control over message payloads and message headers.</p>
<p>Python library: <a href="https://pypi.python.org/pypi/stomp.py" rel="nofollow">https://pypi.python.org/pypi/stomp.py</a>
ActiveMQ Support: <a href="http://activemq.apac... | 0 | 2016-09-02T12:55:13Z | [
"python",
"xml",
"django",
"jms",
"activemq"
] |
Python Mathematical signs in function parameter? | 39,204,420 | <p>I would like to know if there is a way to add math symbols into the function parameters. </p>
<pre><code>def math(x, y, symbol):
answer = x 'symbol' y
return answer
</code></pre>
<p>this is an small example what I mean. </p>
<p><strong>EDIT:
here is the whole problem</strong> </p>
<pre><code>def code... | -1 | 2016-08-29T10:49:10Z | 39,204,444 | <p>Use the corresponding functions, from <code>operator</code> module:</p>
<pre><code>from operator import add
def math(x, y, add):
answer = add(x, y)
return answer
</code></pre>
<p>The only way that you can pass a mathematics sign to a function is passing is in string mode, then you'd have two problems, ... | 1 | 2016-08-29T10:50:50Z | [
"python",
"function",
"math",
"symbols",
"sign"
] |
Python Mathematical signs in function parameter? | 39,204,420 | <p>I would like to know if there is a way to add math symbols into the function parameters. </p>
<pre><code>def math(x, y, symbol):
answer = x 'symbol' y
return answer
</code></pre>
<p>this is an small example what I mean. </p>
<p><strong>EDIT:
here is the whole problem</strong> </p>
<pre><code>def code... | -1 | 2016-08-29T10:49:10Z | 39,204,490 | <p>You can not pass operator to the function, but however you may pass operator's functions defined in <a href="https://docs.python.org/2/library/operator.html" rel="nofollow"><code>operator</code></a> library. Hence, your function will be like:</p>
<pre><code>>>> from operator import eq, add, sub
>>>... | 2 | 2016-08-29T10:53:29Z | [
"python",
"function",
"math",
"symbols",
"sign"
] |
Python Mathematical signs in function parameter? | 39,204,420 | <p>I would like to know if there is a way to add math symbols into the function parameters. </p>
<pre><code>def math(x, y, symbol):
answer = x 'symbol' y
return answer
</code></pre>
<p>this is an small example what I mean. </p>
<p><strong>EDIT:
here is the whole problem</strong> </p>
<pre><code>def code... | -1 | 2016-08-29T10:49:10Z | 39,204,582 | <p>You should first consider that you have to use <code>answer = x symbol y</code> and not the contrary.</p>
<p>Then concerning the use of symbols, you can send the function as a parameter.
For the basic operator you might use the <a href="https://docs.python.org/2/library/operator.html" rel="nofollow">operator</a> mo... | 0 | 2016-08-29T10:57:57Z | [
"python",
"function",
"math",
"symbols",
"sign"
] |
Python Mathematical signs in function parameter? | 39,204,420 | <p>I would like to know if there is a way to add math symbols into the function parameters. </p>
<pre><code>def math(x, y, symbol):
answer = x 'symbol' y
return answer
</code></pre>
<p>this is an small example what I mean. </p>
<p><strong>EDIT:
here is the whole problem</strong> </p>
<pre><code>def code... | -1 | 2016-08-29T10:49:10Z | 39,204,699 | <p>I am surprised noone mentioned <code>eval()</code>. Look at the example below:</p>
<pre><code>def function(operator1, operator2, symbol):
return eval(str(operator1) + symbol + str(operator2))
print(function(2, 3, '+')) # prints: 5
print(function(2, 3, '-')) # prints: -1
# Of course you can also "cha... | 0 | 2016-08-29T11:04:26Z | [
"python",
"function",
"math",
"symbols",
"sign"
] |
Make the rectangle keep moving towards the direction i give to him | 39,204,471 | <p>I'm making a snake game but I'm using rectangle not snake actually, I can't make the rectangle keep moving towards the direction i give to him it just move one when i press it ,So i want to make it keep moving how to do it .</p>
<p>that is the code :</p>
<pre><code>def keys ():
pressed = pygame.key.get_presse... | -1 | 2016-08-29T10:52:25Z | 39,208,880 | <p>If you want the rectangle to continue moving, even when no button is pressed, I would recommend a <code>speed</code> variable. Two, actually, you will need an <code>x_speed</code> and a <code>y_speed</code>.</p>
<pre><code>x_speed = y_speed = 0
x_location = y_location = 0
def keys():
global x_speed
global... | 0 | 2016-08-29T14:37:32Z | [
"python",
"python-2.7",
"pygame"
] |
String time complexity | 39,204,564 | <pre><code>public String joinWords(String[] words)
{
String sentence = "";
for (String w : words)
{
sentence = sentence + w;
}
return sentence;
}
</code></pre>
<blockquote>
<p>Assume that the strings are all the same length (call this x) and that there are n strings.
On each con... | 2 | 2016-08-29T10:56:45Z | 39,204,632 | <p>In the 1st iteration <code>sentence</code> has 0 characters and <code>w</code> has x characters, so you have to copy x characters.</p>
<p>In the 2nd iteration <code>sentence</code> has x characters and <code>w</code> has x characters, so you have to copy 2*x characters.</p>
<p>In the 3rd iteration <code>sentence</... | 6 | 2016-08-29T11:00:44Z | [
"java",
"c#",
"python",
"string",
"data-structures"
] |
String time complexity | 39,204,564 | <pre><code>public String joinWords(String[] words)
{
String sentence = "";
for (String w : words)
{
sentence = sentence + w;
}
return sentence;
}
</code></pre>
<blockquote>
<p>Assume that the strings are all the same length (call this x) and that there are n strings.
On each con... | 2 | 2016-08-29T10:56:45Z | 39,204,795 | <p><code>String</code> itself is immutable but reference is not.</p>
<p>Assume next example:</p>
<pre><code>String s = "1";
s = s + "2";
</code></pre>
<p><code>s</code> will contains value <code>"12"</code>, but string <code>"1"</code> will not changes.
We can check it in next example:</p>
<pre><code>String s = "1"... | 2 | 2016-08-29T11:09:24Z | [
"java",
"c#",
"python",
"string",
"data-structures"
] |
Deal with errors in parametrised sigmoid function in python | 39,204,595 | <p>I am trying to convert a set of numbers into sigmoids:</p>
<pre><code>actualarray = {
'open_cost_1':{
'cost_matrix': [
{'a': 24,'b': 56,'c': 78},
{'a': 3,'b': 98,'c':1711},
{'a': 121,'b': 12121,'c': 12989121},
]
},
'open_cost_2':{
'cost_matrix'... | 0 | 2016-08-29T10:58:37Z | 39,207,159 | <p>As the warning states, the exponential in your implementation of the sigmoid function is overflowing. When that happens, the function returns <code>nan</code>:</p>
<pre><code>In [3]: sigmoid(1000, 1, 1)
/Users/warren/miniconda3/bin/ipython:2: RuntimeWarning: overflow encountered in exp
if __name__ == '__main__':... | 1 | 2016-08-29T13:10:01Z | [
"python",
"numpy",
"logistic-regression",
"sigmoid"
] |
Combine dictionaries based on key value | 39,204,684 | <p>How do I combine the rows of dictionaries having same keys. For instance If I have </p>
<pre><code>my_dict_list = [{'prakash': ['confident']},
{'gagan': ['good', 'luck']},
{'jitu': ['gold']},
{'jitu': ['wins']},
{'atanu': ['good', 'glory']},
{'atanu': ['top', 'winner','good']}]
</code></pre>
<p>My objective i... | 0 | 2016-08-29T11:03:52Z | 39,205,039 | <p>You could loop over the dicts in your list and either insert or append the key-value pairs to a new dict:</p>
<pre><code>my_dict_list = [{'prakash': ['confident']},
{'gagan': ['good', 'luck']},
{'jitu': ['gold']},
{'jitu': ['wins']},
{'atanu': ['good',... | 2 | 2016-08-29T11:20:45Z | [
"python"
] |
Combine dictionaries based on key value | 39,204,684 | <p>How do I combine the rows of dictionaries having same keys. For instance If I have </p>
<pre><code>my_dict_list = [{'prakash': ['confident']},
{'gagan': ['good', 'luck']},
{'jitu': ['gold']},
{'jitu': ['wins']},
{'atanu': ['good', 'glory']},
{'atanu': ['top', 'winner','good']}]
</code></pre>
<p>My objective i... | 0 | 2016-08-29T11:03:52Z | 39,205,061 | <p>Here's a working example:</p>
<pre><code>from itertools import groupby
my_dict_list = [
{'prakash': ['confident']},
{'gagan': ['good', 'luck']},
{'jitu': ['gold']},
{'jitu': ['wins']},
{'atanu': ['good', 'glory']},
{'atanu': ['top', 'winner']}
]
my_new_dict_list = []
for k, g in groupby(my... | 1 | 2016-08-29T11:22:16Z | [
"python"
] |
Combine dictionaries based on key value | 39,204,684 | <p>How do I combine the rows of dictionaries having same keys. For instance If I have </p>
<pre><code>my_dict_list = [{'prakash': ['confident']},
{'gagan': ['good', 'luck']},
{'jitu': ['gold']},
{'jitu': ['wins']},
{'atanu': ['good', 'glory']},
{'atanu': ['top', 'winner','good']}]
</code></pre>
<p>My objective i... | 0 | 2016-08-29T11:03:52Z | 39,205,132 | <p>a minimalist approach using <code>defaultdict</code>:</p>
<pre><code>from collections import defaultdict
my_dict_list = [{'prakash': ['confident']},
{'gagan': ['good', 'luck']},
{'jitu': ['gold']},
{'jitu': ['wins']},
{'atanu': ['good', 'glory']},
{'atanu': ['top', 'winner','good']}]
merged_dict = defaultdic... | 0 | 2016-08-29T11:25:54Z | [
"python"
] |
Combine dictionaries based on key value | 39,204,684 | <p>How do I combine the rows of dictionaries having same keys. For instance If I have </p>
<pre><code>my_dict_list = [{'prakash': ['confident']},
{'gagan': ['good', 'luck']},
{'jitu': ['gold']},
{'jitu': ['wins']},
{'atanu': ['good', 'glory']},
{'atanu': ['top', 'winner','good']}]
</code></pre>
<p>My objective i... | 0 | 2016-08-29T11:03:52Z | 39,205,145 | <pre><code>my_dict_list = [{'prakash': ['confident']},
{'gagan': ['good', 'luck']},
{'jitu': ['gold']},
{'jitu': ['wins']},
{'atanu': ['good', 'glory']},
{'atanu': ['top', 'winner','good']}]
my_new_dict_list = []
tmp_dict = {}
order = []
for d in my_dict_list:
for k, v in d.iteritems():
if not k in order:... | 1 | 2016-08-29T11:26:22Z | [
"python"
] |
matplotlib - barchar with blurry effect | 39,204,875 | <p>I'm working with bar charts in matplotlib, and I'm focusing on colors. I have the following simple cose:</p>
<pre><code>import matplotlib.pyplot as plt
A = [5, 30, 45, 80]
X = range(4)
col = ['r','orange','y','g']
plt.bar(X, A, color = col)
plt.show()
</code></pre>
<p>What I would like to achieve is a blurry colo... | 0 | 2016-08-29T11:12:54Z | 39,207,346 | <p>You have a pretty good example from matplotlib documentation on this <a href="http://matplotlib.org/examples/pylab_examples/gradient_bar.html" rel="nofollow">link</a>. Adapting this to your example you would obtain something like this:</p>
<pre><code>import matplotlib.pyplot as plt
from matplotlib.pyplot import fig... | 1 | 2016-08-29T13:19:02Z | [
"python",
"matplotlib",
"colors",
"bar-chart"
] |
Get specific text from xml using python | 39,204,902 | <p>I have an XML string which looks like this:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:geonode="http://www.geonode.org/" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" targetNamespace="http://www.geonode.org/"&... | 0 | 2016-08-29T11:14:05Z | 39,205,465 | <p>The following is one of the ways to extract data from xml file using xml.etree library and python 2.7.
Replace the xml file name and the tag name in the corresponding places in the code.</p>
<pre><code>import xml.etree.ElementTree as XT
dataTree = XT.parse('your_xml_file_name.xml')
dataRoot = dataTree.getroot()
geo... | 0 | 2016-08-29T11:41:17Z | [
"python",
"xml"
] |
Python asyncio: stop the loop when one coroutine is done | 39,204,929 | <p>I'm quite new in this python asyncio topic. I have a simple question:
I have a task containing two coroutines to be run concurrently. First coroutine(my_coroutine) would just print something continuously until second_to_sleep is reached. The second coroutine(seq_coroutine) would call 4 other coroutines sequentially ... | 0 | 2016-08-29T11:15:29Z | 39,208,428 | <p>I just found a suitable solution for my problem.
I won't remove my post and I'll post my solution so that it may help others who face the same question.
I used <code>asyncio.wait(task, return_when=asyncio.FIRST_COMPLETED)</code> and it will return the result whenever the first task is finished.
This is the solution:... | 3 | 2016-08-29T14:13:57Z | [
"python",
"coroutine",
"python-asyncio"
] |
Python script execution time increases when executed multiple time parallely | 39,204,955 | <p>I have a python script whose execution time is 1.2 second while it is being executed standalone.</p>
<p>But when I execute it 5-6 time parallely ( Am using postman to ping the url multiple times) the execution time shoots up.</p>
<p>Adding the breakdown of the time taken.</p>
<pre><code>1 run -> ~1.2seconds
2 ... | 11 | 2016-08-29T11:17:07Z | 39,247,616 | <p>1) You really can't ensure the execution will take always the same time, but at least you can avoid performance degradation by using a "locking" strategy like the ones described in <a href="http://raspberrypi.stackexchange.com/a/22006">this answer</a>.</p>
<p>Basically you can test if the lockfile exists, and if so... | 2 | 2016-08-31T10:51:21Z | [
"python",
"time"
] |
Python script execution time increases when executed multiple time parallely | 39,204,955 | <p>I have a python script whose execution time is 1.2 second while it is being executed standalone.</p>
<p>But when I execute it 5-6 time parallely ( Am using postman to ping the url multiple times) the execution time shoots up.</p>
<p>Adding the breakdown of the time taken.</p>
<pre><code>1 run -> ~1.2seconds
2 ... | 11 | 2016-08-29T11:17:07Z | 39,337,216 | <p>The ec2 cloud does not guarantee 7.5gb of free memory on the server. This would mean that the VM performance is severely impacted like you are seeing where the server has less than 7.5gb of physical free ram. Try reducing the amount of memory the server thinks it has.</p>
<p>This form of parallel performance is v... | 0 | 2016-09-05T20:19:49Z | [
"python",
"time"
] |
Python script execution time increases when executed multiple time parallely | 39,204,955 | <p>I have a python script whose execution time is 1.2 second while it is being executed standalone.</p>
<p>But when I execute it 5-6 time parallely ( Am using postman to ping the url multiple times) the execution time shoots up.</p>
<p>Adding the breakdown of the time taken.</p>
<pre><code>1 run -> ~1.2seconds
2 ... | 11 | 2016-08-29T11:17:07Z | 39,356,242 | <p>It might be because of the way computers are run.</p>
<p>Each program gets a <strong>slice of time on a computer</strong> (quote <a href="http://rads.stackoverflow.com/amzn/click/146541956X" rel="nofollow"><strong><em>Help Your Kids With Computer Programming</em></strong></a>, say maybe <strong><em>1/1000</em> of a... | 0 | 2016-09-06T19:11:21Z | [
"python",
"time"
] |
Python script execution time increases when executed multiple time parallely | 39,204,955 | <p>I have a python script whose execution time is 1.2 second while it is being executed standalone.</p>
<p>But when I execute it 5-6 time parallely ( Am using postman to ping the url multiple times) the execution time shoots up.</p>
<p>Adding the breakdown of the time taken.</p>
<pre><code>1 run -> ~1.2seconds
2 ... | 11 | 2016-08-29T11:17:07Z | 39,357,591 | <h2>Here's what we have:</h2>
<ul>
<li><p>EC2 instance type is m3.large box which has only <strong>2</strong> vCPUs <a href="https://aws.amazon.com/ec2/instance-types/?nc1=h_ls" rel="nofollow">https://aws.amazon.com/ec2/instance-types/?nc1=h_ls</a></p></li>
<li><p>We need to run a CPU- and memory-hungry script which ... | 1 | 2016-09-06T20:48:06Z | [
"python",
"time"
] |
Python script execution time increases when executed multiple time parallely | 39,204,955 | <p>I have a python script whose execution time is 1.2 second while it is being executed standalone.</p>
<p>But when I execute it 5-6 time parallely ( Am using postman to ping the url multiple times) the execution time shoots up.</p>
<p>Adding the breakdown of the time taken.</p>
<pre><code>1 run -> ~1.2seconds
2 ... | 11 | 2016-08-29T11:17:07Z | 39,359,263 | <p>1)</p>
<h1>More servers equals more availability</h1>
<p>Hearsay tells me that one effective way to ensure consistent request times is to use multiple requests to a cluster. As I heard it the idea goes something like this. </p>
<h3>The chance of a slow request</h3>
<p><sub>(Disclaimer I'm not much of a mathemati... | 1 | 2016-09-06T23:37:08Z | [
"python",
"time"
] |
Python search for a start hex string, save the hex string after that to a new file | 39,204,960 | <p>PYTHON</p>
<p>I would like to open a text file, search for a HEX pattern that starts with 45 3F, grab the following hex 6 HEX values, for example 45 4F 5D and put all this in a new file. I also know that it always ends with 00 00.</p>
<p>So the file can look like: bla bla sdsfsdf 45 3F 08 DF 5D 00 00 dsafasdfsadf ... | 0 | 2016-08-29T11:17:16Z | 39,206,586 | <p>Here's a complete answer (Python 3):</p>
<pre><code>with open('file.txt') as reader:
my_data = reader.read()
matches = re.findall(r"45 3F ([0-9A-F]{2} [0-9A-F]{2} [0-9A-F]{2})", my_data)
data_to_write = " ".join(matches)
with open('out.txt', 'w') as writer:
writer.write(data_to_write)
</code></pre>
<p><co... | 0 | 2016-08-29T12:39:12Z | [
"python"
] |
Boolean displays True when using list but not text file | 39,204,995 | <p>I am having an issue with getting a ping_reply == 0 when opening a file. When I use a list for the ip_list variable, it has no issue returning 0 (Which 0 represents successful)</p>
<pre><code>import subprocess
ip_list = []
def ip_is_valid():
check = False
#Global exposes outside the local function
... | 0 | 2016-08-29T11:19:01Z | 39,205,662 | <p>Try to remove the spaces before and after the ip:</p>
<p><code>ip_file = raw_input("# Enter IP file name followed by extension: ").strip()</code></p>
| 0 | 2016-08-29T11:51:45Z | [
"python",
"networking"
] |
Boolean displays True when using list but not text file | 39,204,995 | <p>I am having an issue with getting a ping_reply == 0 when opening a file. When I use a list for the ip_list variable, it has no issue returning 0 (Which 0 represents successful)</p>
<pre><code>import subprocess
ip_list = []
def ip_is_valid():
check = False
#Global exposes outside the local function
... | 0 | 2016-08-29T11:19:01Z | 39,205,666 | <p>Ah yes, I almost forgot about that, Mark. Here is the fixed code:</p>
<pre><code>import subprocess
ip_list = []
def ip_is_valid():
check = False
#Global exposes outside the local function
global ip_list
while True:
#Prompting user for input
print "\n" + "# " * 20 + "\n"
ip_file = raw_i... | 0 | 2016-08-29T11:51:58Z | [
"python",
"networking"
] |
The program only works with one client id | 39,204,997 | <p>Here is a sample of the textfile I use:</p>
<pre><code>NaQua,High
ImKol,Moderate
YoTri,Moderate
RoDen,High
NaThe,Moderate
ReWes,Moderate
BrFre,High
KaDat,High
ViRil,High
TrGeo,High
</code></pre>
<p>For some reason, the program will only work with the last client id on the list. It prints the intensity level but th... | 0 | 2016-08-29T11:19:07Z | 39,205,503 | <p>Change to:</p>
<pre><code>elif 'Moderate' in clientintensity:
</code></pre>
<p>and: </p>
<pre><code>if 'High' in clientintensity:
</code></pre>
<p>as you are using list comprehension (a good tutorial on list comprehension in <em>Python</em> <a href="http://www.pythonforbeginners.com/basics/list-comprehensions-in... | 0 | 2016-08-29T11:43:18Z | [
"python"
] |
Loop character A/B alternately | 39,205,105 | <p>How can I print A/B character alternately in python loop?</p>
<p>What I expect in result:</p>
<pre><code>oneA
twoB
threeA
fourB
...
</code></pre>
| -1 | 2016-08-29T11:24:27Z | 39,205,171 | <p>You can use <a href="https://docs.python.org/3.4/library/itertools.html#itertools.cycle" rel="nofollow"><code>itertools.cycle</code></a> to repeat through a sequence. This is typically used with <a href="https://docs.python.org/3/library/functions.html#zip" rel="nofollow"><code>zip</code></a> to iterate through a lo... | 3 | 2016-08-29T11:27:22Z | [
"python",
"loops",
"for-loop"
] |
Loop character A/B alternately | 39,205,105 | <p>How can I print A/B character alternately in python loop?</p>
<p>What I expect in result:</p>
<pre><code>oneA
twoB
threeA
fourB
...
</code></pre>
| -1 | 2016-08-29T11:24:27Z | 39,205,204 | <p>You could also try using the modulus operator % on the index of an incremented for loop for the numbers to alternate the letters:</p>
<pre><code>list_num = ['one', 'two', 'three', 'four', 'five', 'six']
list_alpha = ['A', 'B']
list_combined = []
for i in range(0, len(list_num)):
list_combined.append(list_num[i]... | 1 | 2016-08-29T11:29:01Z | [
"python",
"loops",
"for-loop"
] |
Loop character A/B alternately | 39,205,105 | <p>How can I print A/B character alternately in python loop?</p>
<p>What I expect in result:</p>
<pre><code>oneA
twoB
threeA
fourB
...
</code></pre>
| -1 | 2016-08-29T11:24:27Z | 39,205,208 | <p>try this:</p>
<pre><code>l1 = ['A','B']
l2 = ['one','two','three','four']
for i,val in enumerate(l2):
print(val + l1[i%len(l1)])
</code></pre>
| 1 | 2016-08-29T11:29:15Z | [
"python",
"loops",
"for-loop"
] |
Loop character A/B alternately | 39,205,105 | <p>How can I print A/B character alternately in python loop?</p>
<p>What I expect in result:</p>
<pre><code>oneA
twoB
threeA
fourB
...
</code></pre>
| -1 | 2016-08-29T11:24:27Z | 39,205,373 | <p>Something like:</p>
<pre><code>alternate_words = ['A', 'B']
count = 0
while count < 5:
print count+1, alternate_words[count % len(alternate_words)]
count += 1
</code></pre>
<p>Output:</p>
<p>1 A</p>
<p>2 B</p>
<p>3 A</p>
<p>4 B</p>
<p>5 A</p>
| 0 | 2016-08-29T11:36:56Z | [
"python",
"loops",
"for-loop"
] |
Loop character A/B alternately | 39,205,105 | <p>How can I print A/B character alternately in python loop?</p>
<p>What I expect in result:</p>
<pre><code>oneA
twoB
threeA
fourB
...
</code></pre>
| -1 | 2016-08-29T11:24:27Z | 39,205,737 | <p>I think this will help -></p>
<pre><code>a1 = ['A','B']
a2 = ['one','two','three','four']
for i in range(len(a2)):
print a2[i]+a1[i%2]
</code></pre>
| 0 | 2016-08-29T11:55:21Z | [
"python",
"loops",
"for-loop"
] |
Loop character A/B alternately | 39,205,105 | <p>How can I print A/B character alternately in python loop?</p>
<p>What I expect in result:</p>
<pre><code>oneA
twoB
threeA
fourB
...
</code></pre>
| -1 | 2016-08-29T11:24:27Z | 39,219,879 | <p>At the suggestion of @Graipher instead of using combined <code>zip()</code> with <code>itertools.cycle()</code>, better and simpler solution will be use <code>itertools.product()</code> which is </p>
<blockquote>
<p>Cartesian product of input iterables.</p>
<p>Roughly equivalent to nested for-loops in a gene... | 0 | 2016-08-30T06:06:38Z | [
"python",
"loops",
"for-loop"
] |
How to initialize OpenGL with glXChooseFBConfig and ctypes module? | 39,205,116 | <p>I want to make some simple OpenGL animation on my tkinter window. I dont want to include any needless dependencies so I'm writing everything from scratch with ctypes. So far I have this:</p>
<pre><code>#!/usr/bin/env python3
import tkinter
import ctypes
from ctypes import cdll
GLX_PIXMAP_BIT = 0x00000002
GLX_WIND... | 0 | 2016-08-29T11:24:58Z | 39,206,504 | <p>After selecting a FBConfig you also have to select a window visual that matches that FBConfig to make sure that this FBConfig can in fact be used for the window you're trying to attach do. Also the Window must have set its visual/FBConfig to that format so that you can make current the OpenGL context on it.</p>
<p>... | 0 | 2016-08-29T12:35:33Z | [
"python",
"opengl",
"ctypes",
"glx"
] |
How to initialize OpenGL with glXChooseFBConfig and ctypes module? | 39,205,116 | <p>I want to make some simple OpenGL animation on my tkinter window. I dont want to include any needless dependencies so I'm writing everything from scratch with ctypes. So far I have this:</p>
<pre><code>#!/usr/bin/env python3
import tkinter
import ctypes
from ctypes import cdll
GLX_PIXMAP_BIT = 0x00000002
GLX_WIND... | 0 | 2016-08-29T11:24:58Z | 39,208,012 | <p>I don't have a linux distribution at hand right now to test it, but what about this <a href="http://stackoverflow.com/help/mcve">mcve</a>?</p>
<pre><code>from ctypes import c_char_p, c_void_p, cdll
from ctypes import c_bool, c_char_p, c_double, c_float, c_int, c_uint, c_ulong, c_void_p, POINTER
from tkinter import ... | 1 | 2016-08-29T13:52:38Z | [
"python",
"opengl",
"ctypes",
"glx"
] |
Why do processes take long time to join even when the map call to pool is completed? | 39,205,198 | <p>This is yet another question regarding <code>multiprocessing</code> module in <code>Python 3.</code>5. My problem is that I know all the forked processed have done their job (I can see their result in <code>Queue</code>), the AsyncResult.result() returns True which means that jobs are completed but when I proceed wi... | 1 | 2016-08-29T11:28:51Z | 39,206,081 | <p>The issue here is that you are using an extra <code>Queue</code> in your worker, other than the one fournished by <code>Pool</code>.
When the processes finish their work, they will all join the <code>FeederThread</code> used in the <code>multiprocessing.Queue</code> and these calls will hang (probably because all t... | 2 | 2016-08-29T12:13:55Z | [
"python",
"parallel-processing",
"multiprocessing",
"zombie-process"
] |
pandas fill N.A. for specific column | 39,205,200 | <p>I want to fill N.A. values in a specific column if a condition is met in another column to only replace this single class of N.A. values with an imputed / replacement value.</p>
<p>E.g. I want to perform: <code>if column1 = 'value1' AND column2 = N.A fillna_in_column2 with value 'replacementvalue'</code></p>
<p>H... | 1 | 2016-08-29T11:28:51Z | 39,205,258 | <p>You can try this:</p>
<pre><code>cond1 = df['column1'] == value1
cond2 = np.isnan(df['column2'])
df['column2'][cond1 & cond2] = replacement_value
</code></pre>
| 0 | 2016-08-29T11:32:04Z | [
"python",
"pandas",
"fill",
"na",
"imputation"
] |
pandas fill N.A. for specific column | 39,205,200 | <p>I want to fill N.A. values in a specific column if a condition is met in another column to only replace this single class of N.A. values with an imputed / replacement value.</p>
<p>E.g. I want to perform: <code>if column1 = 'value1' AND column2 = N.A fillna_in_column2 with value 'replacementvalue'</code></p>
<p>H... | 1 | 2016-08-29T11:28:51Z | 39,205,388 | <pre><code>df.loc[(df['col1']==val1) & (df['col2'].isnull()), 'col2'] = replacement_value
</code></pre>
| 2 | 2016-08-29T11:37:40Z | [
"python",
"pandas",
"fill",
"na",
"imputation"
] |
Dominant colors with Image package in python | 39,205,332 | <p>I have a transparent image and I am trying to extract major colors out of it using <code>Image</code> module's <code>getcolor()</code> method</p>
<pre><code>y = Image.open('img.png')
y.getcolors()
[Out]: [(21841, 0),
(13328, 1),
(8171, 2),
(2673, 3),
(1337, 4),
(1010, 5),
(892, 6),
(519, 7),
(379, 8),
(234,... | 0 | 2016-08-29T11:34:41Z | 39,207,838 | <p>I am not sure whether the following code snippet is what you are finding. Convert the <code>Image</code> object to RGBA object and use <code>getcolors()</code> as follows.</p>
<pre><code>from PIL import Image
im = Image.open('img.png')
rgba_im = im.convert('RGBA')
print ( rgba_im.getcolors() )
"""
<Output>
... | 0 | 2016-08-29T13:44:42Z | [
"python",
"image",
"pillow"
] |
How to use xpath in selenium python? | 39,205,371 | <p>I am new to Selenium Python. I am trying to run the following snippet. It works with find_element_by_name but not find_element_by_xpath.</p>
<p>Any idea what I am doing wrong?</p>
<p>Thanks </p>
<pre><code>from selenium import webdriver
# create a new Firefox session
driver = webdriver.Firefox()
driver.implicitly... | -1 | 2016-08-29T11:36:52Z | 39,205,414 | <p>Try this
search_field = driver.find_element_by_xpath("//input[@name='q']")</p>
| 1 | 2016-08-29T11:38:48Z | [
"python",
"selenium",
"xpath"
] |
sklearn.cluster.DBSCAN gives unexpected result | 39,205,392 | <p>I'm using DBSCAN method for clustering images, but it gives unexpected result. Let's assume I have 10 images. </p>
<p>Firstly, I read an images in a loop using <code>cv2.imread</code>.
Then I compute structural similarity index between each images. After that, I have a matrix like this:</p>
<pre><code>[
[ 1. ... | 0 | 2016-08-29T11:38:01Z | 39,208,214 | <p>The problem was that I've calculated distance matrix incorrectly - the entries on the main diagonal are all zero.</p>
| 0 | 2016-08-29T14:02:26Z | [
"python",
"scikit-learn",
"cluster-analysis",
"dbscan"
] |
sklearn.cluster.DBSCAN gives unexpected result | 39,205,392 | <p>I'm using DBSCAN method for clustering images, but it gives unexpected result. Let's assume I have 10 images. </p>
<p>Firstly, I read an images in a loop using <code>cv2.imread</code>.
Then I compute structural similarity index between each images. After that, I have a matrix like this:</p>
<pre><code>[
[ 1. ... | 0 | 2016-08-29T11:38:01Z | 39,209,669 | <p>DBSCAN usually assumes a <em>dissimilarity</em> (distance) not a similarity. It can be implemented with a similarity threshold, too (see Generalized DBSCAN)</p>
| 0 | 2016-08-29T15:16:01Z | [
"python",
"scikit-learn",
"cluster-analysis",
"dbscan"
] |
Python after running script for a long time memory allocation error | 39,205,528 | <p>I have this code which scrapes usernames:</p>
<pre><code>def fetch_and_parse_names(url):
html = requests.get(url).text
soup = BeautifulSoup(html, "lxml")
return (a.string for a in soup.findAll(href=USERNAME_PATTERN))
def get_names(urls):
# Create a concurrent executor
with concurrent.futures.Th... | 1 | 2016-08-29T11:44:35Z | 39,205,880 | <p>You can use <a href="https://docs.python.org/2/library/resource.html" rel="nofollow">Python Resource Library</a> to increase your process allocated memory as threads of a process use memory of their parent process they cannot allocate extra memory.</p>
| 1 | 2016-08-29T12:02:36Z | [
"python"
] |
Python after running script for a long time memory allocation error | 39,205,528 | <p>I have this code which scrapes usernames:</p>
<pre><code>def fetch_and_parse_names(url):
html = requests.get(url).text
soup = BeautifulSoup(html, "lxml")
return (a.string for a in soup.findAll(href=USERNAME_PATTERN))
def get_names(urls):
# Create a concurrent executor
with concurrent.futures.Th... | 1 | 2016-08-29T11:44:35Z | 39,206,034 | <p>The code you use keeps all the downloaded documents in memory for two reasons:</p>
<ul>
<li>you return <code>a.string</code>, which is not just a <code>str</code> but a <code>bs4.element.NavigableString</code> and as such keeps a reference to its parent and ultimately to the whole document tree.</li>
<li>you return... | 2 | 2016-08-29T12:11:17Z | [
"python"
] |
getElementById() takes exactly 1 argument (2 given) | 39,205,598 | <p>I want to do an automation of the Internet Explorer. Open the Internet Explorer, navigate to login.live.com and set a value into the email textbox.</p>
<p>Here's the simple script:</p>
<pre><code>import win32com.client
import time
IE = win32com.client.DispatchEx("InternetExplorer.Application")
IE.Visible = 1
IE.N... | 0 | 2016-08-29T11:48:36Z | 39,205,691 | <p>As <a href="http://stackoverflow.com/a/33024922/1752959">this</a> answer suggests you have to use</p>
<pre><code>DOC.Body.getElementById('i0116').value = 'test'
</code></pre>
| 0 | 2016-08-29T11:52:52Z | [
"python",
"win32com"
] |
getElementById() takes exactly 1 argument (2 given) | 39,205,598 | <p>I want to do an automation of the Internet Explorer. Open the Internet Explorer, navigate to login.live.com and set a value into the email textbox.</p>
<p>Here's the simple script:</p>
<pre><code>import win32com.client
import time
IE = win32com.client.DispatchEx("InternetExplorer.Application")
IE.Visible = 1
IE.N... | 0 | 2016-08-29T11:48:36Z | 39,223,681 | <p>Okay.. I wrote a workaround for this:</p>
<pre><code>DOC = IE.Document
inputs = DOC.documentElement.getElementsByTagName('input')
for field in inputs:
if field.id == 'i0116':
email = field
break
email.value = 'example@test.com'
</code></pre>
<p>For browser automation I recommend to use the <a ... | 0 | 2016-08-30T09:27:35Z | [
"python",
"win32com"
] |
Python configparser reading section and creating new config | 39,205,668 | <p>I'm currently reading a config file getting all values from a specific section and printing them however, instead of printing them I would like to create a new config file with just that section I am reading. </p>
<p>How would I go about this?</p>
<p>code</p>
<pre><code>configFilePath = 'C:\\testing.ini'
config =... | 0 | 2016-08-29T11:52:02Z | 39,206,866 | <p>I got it working with </p>
<pre><code>for x in configdata.items():
confignew.set(section,x[0],x[1])
confignew.write( EqualsSpaceRemover( cfgfile ) )
</code></pre>
<p>however, how would I edit my code so it can read text with characters like " ñ " and parse/write them without getting errors about decode pro... | 0 | 2016-08-29T12:54:40Z | [
"python",
"parsing",
"configparser",
"python-config"
] |
pyhs2 set queue in query | 39,205,710 | <p>I am using pyhs2 to query hive through python but I cannot set the queue inside the query.</p>
<p>I want to set the queue to adhoc</p>
<pre><code>cursor.execute("set mapred.job.queue.name=adhoc;")
cursor.execute("select * from test")
pyhs2.error.Pyhs2Exception: 'Error while processing statement: FAILED: Execution ... | 0 | 2016-08-29T11:53:56Z | 40,108,757 | <p>Apparently it is not possible to run multiple statements with <code>pyhs2</code> therefore you are unable to set the mapred queue name. Pyhs2 is no longer maintained and the readme advises to use <a href="https://github.com/dropbox/PyHive" rel="nofollow">PyHive</a> which supports these kind of operations.</p>
| 0 | 2016-10-18T12:49:17Z | [
"python",
"hive",
"queue"
] |
Error while executing with subprocess | 39,205,793 | <p>I'm trying to execute a shell command via Python code, but I'm not capable to understand why it is failing.</p>
<p>When printing the command and pasting it to the shell to try executing it directly works perfectly fine, that's the strange part.</p>
<p>From Python I'm getting the following:</p>
<pre><code>/bin/sh:... | 0 | 2016-08-29T11:58:23Z | 39,206,132 | <p>Your command contains a process substitution, but <code>Popen</code> runs its command using <code>/bin/sh</code>. When run as <code>/bin/sh</code>, though, <code>bash</code> does not allow process substitutions. You can explicitly request that the command be run with <code>bash</code> using the <code>executable</cod... | 0 | 2016-08-29T12:16:49Z | [
"python",
"bash",
"shell"
] |
How string formats '%' operator is implemented? | 39,205,815 | <p>How does string formats '%' operator is implemented in CPython 2.7?</p>
<p>Can't find any reference in the <a href="https://docs.python.org/2/index.html" rel="nofollow">Python documentation</a>.</p>
<p>Well, I fact I found the topic: <a href="https://docs.python.org/2/c-api/conversion.html" rel="nofollow">String c... | 0 | 2016-08-29T11:59:27Z | 39,206,131 | <p>The implementation is in the <a href="https://github.com/python/cpython/blob/2.7/Objects/stringobject.c#L4229" rel="nofollow"><code>PyString_Format</code></a> that is called by the <a href="https://github.com/python/cpython/blob/2.7/Objects/stringobject.c#L3743" rel="nofollow"><code>string_mod</code> function</a> in... | 2 | 2016-08-29T12:16:47Z | [
"python",
"python-2.7",
"string-formatting"
] |
Model create using dictionary in django | 39,205,874 | <p>In Django is it possible to create through dictionary similar as to filtering?</p>
<p>Here is my models.py:</p>
<pre><code>class Personnels(models.Model):
name = models.CharField(max_length=100)
</code></pre>
<p>Here is my views.py:</p>
<pre><code>from . models import *
def artists(request):
personnels ... | 0 | 2016-08-29T12:02:22Z | 39,206,056 | <p>Simply unwrap the dictionary within <code>create</code> function like:</p>
<pre><code>Personnels.objects.create(**data)
</code></pre>
| 1 | 2016-08-29T12:12:39Z | [
"python",
"django"
] |
Curl command from Python Subprocess to store output into variable | 39,205,906 | <p>I am using the below python code to read data from a url. The curl command from unix works. But when i try to store the returned json in a python variable, it is always blank.</p>
<p>Any pointers ? I do see the output on the Spyder Console, but never in the variable.</p>
<pre><code> p =sp.Popen(["curl","-i","-X... | 1 | 2016-08-29T12:04:14Z | 39,206,111 | <p>You can use the subprocess PIPE to capture the stdout and stderr, like so:</p>
<pre><code>>>> import subprocess
>>> p = subprocess.Popen(["curl", "https://google.co.uk"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> print p.stdout.read() # <-- you can assign a variable to the c... | 0 | 2016-08-29T12:15:55Z | [
"python",
"api",
"curl",
"pipe",
"subprocess"
] |
Curl command from Python Subprocess to store output into variable | 39,205,906 | <p>I am using the below python code to read data from a url. The curl command from unix works. But when i try to store the returned json in a python variable, it is always blank.</p>
<p>Any pointers ? I do see the output on the Spyder Console, but never in the variable.</p>
<pre><code> p =sp.Popen(["curl","-i","-X... | 1 | 2016-08-29T12:04:14Z | 39,206,255 | <p>My Bad :(</p>
<p>Actually, I am on a secure connection behind firewall.
Hence, i have to set the proxy before i make the call.</p>
<pre><code> os.environ['https_proxy']="https://iss-uk.corporate.pb.com:80"
p =sp.Popen(["curl","-i","-X", "POST" ,"-H", "Content-Type:application/json" ,"-H", "Authorization:Basic N... | 0 | 2016-08-29T12:22:20Z | [
"python",
"api",
"curl",
"pipe",
"subprocess"
] |
Google app engine HTTP error 500 | 39,205,979 | <p>I just installed Google app engine for Python 2.7 and I wrote some code for test. Just a simple HTML form. Here is the code:</p>
<pre><code>import webapp2
form = """
<form method="post">
What is your birthday?
<br>
<label> Month
<input type="text" name="month">
</... | 0 | 2016-08-29T12:07:51Z | 39,206,510 | <p>You have probably mixed up tabs and spaces. See this answer for more information and hints on how to fix it: <a href="http://stackoverflow.com/a/3920674/3771575">http://stackoverflow.com/a/3920674/3771575</a></p>
| 1 | 2016-08-29T12:35:43Z | [
"python",
"google-app-engine"
] |
How to refresh multiple printed lines inplace using Python? | 39,206,020 | <p>I would like to understand how to reprint multiple lines in Python 3.5.</p>
<p>This is an example of a script where I would like to refresh the printed statement in place.</p>
<pre><code>import random
import time
a = 0
while True:
statement = """
Line {}
Line {}
Line {}
Value = {}
""".form... | 4 | 2016-08-29T12:10:20Z | 39,206,615 | <p>If you want to clear the screen each time you call <code>print()</code>, so that it <em>appears</em> the print is overwritten each time, you can use <code>clear</code> in unix or <code>cls</code> in windows, for example:</p>
<pre><code>import subprocess
a = 0
while True:
print(a)
a += 1
subprocess.call(... | 1 | 2016-08-29T12:41:04Z | [
"python",
"python-3.x",
"printing",
"stdout"
] |
How to refresh multiple printed lines inplace using Python? | 39,206,020 | <p>I would like to understand how to reprint multiple lines in Python 3.5.</p>
<p>This is an example of a script where I would like to refresh the printed statement in place.</p>
<pre><code>import random
import time
a = 0
while True:
statement = """
Line {}
Line {}
Line {}
Value = {}
""".form... | 4 | 2016-08-29T12:10:20Z | 39,206,642 | <p>If I've understood correctly you're looking for this type of solution:</p>
<pre><code>import random
import time
import os
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')
a = 0
while True:
clear_screen()
statement = """
Line {}
Line {}
Line {}
Value = {}
""".f... | 2 | 2016-08-29T12:42:30Z | [
"python",
"python-3.x",
"printing",
"stdout"
] |
How to refresh multiple printed lines inplace using Python? | 39,206,020 | <p>I would like to understand how to reprint multiple lines in Python 3.5.</p>
<p>This is an example of a script where I would like to refresh the printed statement in place.</p>
<pre><code>import random
import time
a = 0
while True:
statement = """
Line {}
Line {}
Line {}
Value = {}
""".form... | 4 | 2016-08-29T12:10:20Z | 39,333,155 | <p>You could use <a href="https://docs.python.org/3/library/curses.html?highlight=ncurses" rel="nofollow">curses</a> for this.</p>
<pre><code>#!/usr/bin/python3
import curses
from time import sleep
from random import random
statement = """
Line {}
Line {}
Line {}
Value = {}"""
screen = curses.initscr()
n = 0
while... | 0 | 2016-09-05T14:52:40Z | [
"python",
"python-3.x",
"printing",
"stdout"
] |
Make a new column of the first n letters of a column, where n is the value in another column | 39,206,151 | <p>I have a dataframe with names and ages:</p>
<pre><code>name: age:
john 2
sean 3
jack 1
peter 4
</code></pre>
<p>Depending on their age <code>n</code> I want to print the first <code>n</code> letters of their name, so for instance <code>sean</code> becomes <code>sea</code> in a new column. </p>
<p>I ... | 1 | 2016-08-29T12:17:43Z | 39,206,283 | <p>Please try this:</p>
<pre><code>family['newcol'] = [family.ix[x]['name'][0:family.ix[x]['age']] for x in family.index]
</code></pre>
| 2 | 2016-08-29T12:24:21Z | [
"python",
"pandas"
] |
Why Do I have to worry about Thread Safety in CPython? | 39,206,242 | <p>From what I understand, the Global Interpreter Lock allows only a single thread to access the interpreter and execute bytecode. If that's the case, then at any given time, only a single thread will be using the interpreter and its memory. </p>
<p>With that I believe that it is fair to exclude the possibility of hav... | 2 | 2016-08-29T12:21:43Z | 39,206,297 | <p>Of course race conditions can still take place, because access to datastructures is <em>not atomic</em>.</p>
<p>Say you test for a key being present in a dictionary, then do something to add the key:</p>
<pre><code>if key not in dictionary:
# calculate new value
value = elaborate_calculation()
dictiona... | 6 | 2016-08-29T12:24:52Z | [
"python",
"multithreading",
"thread-safety",
"cpython",
"gil"
] |
Why Do I have to worry about Thread Safety in CPython? | 39,206,242 | <p>From what I understand, the Global Interpreter Lock allows only a single thread to access the interpreter and execute bytecode. If that's the case, then at any given time, only a single thread will be using the interpreter and its memory. </p>
<p>With that I believe that it is fair to exclude the possibility of hav... | 2 | 2016-08-29T12:21:43Z | 39,206,973 | <p>An important note: the multiprocessing module in Python is synchonous to some degree despite the GIL, in that access to the same variable can occur across different processes simultaneously. </p>
<p>This has a likelyhood of corrupting your data, or at least disrupting your control flow, which would be why thread sa... | 0 | 2016-08-29T12:59:59Z | [
"python",
"multithreading",
"thread-safety",
"cpython",
"gil"
] |
How to query a one to many/many to many relationship in Flask SQL Alchemy? | 39,206,298 | <p>These are two database models that are important in my problem. </p>
<p><b>I have established a one to many relationship (a Conversation can have multiple Messages) </b>
There is also a many to many relationship established between User and Conversation. </p>
<p><b>After obtaining two User objects, say <i>user1... | 0 | 2016-08-29T12:24:54Z | 39,207,144 | <p>This isn't a pure SQL query, but here's how I would accomplish what you're asking using Pandas.</p>
<pre><code>import pandas as pd
import sqlalchemy
import urllib
#setup vars and connection
server = 'myServer'
db = 'myDb'
user1 = 'someId1'
user2 = 'someId2'
#You'll have to maybe change this a little if you aren'... | -1 | 2016-08-29T13:09:07Z | [
"python",
"flask",
"sqlalchemy"
] |
How to query a one to many/many to many relationship in Flask SQL Alchemy? | 39,206,298 | <p>These are two database models that are important in my problem. </p>
<p><b>I have established a one to many relationship (a Conversation can have multiple Messages) </b>
There is also a many to many relationship established between User and Conversation. </p>
<p><b>After obtaining two User objects, say <i>user1... | 0 | 2016-08-29T12:24:54Z | 39,208,130 | <p>The best way I know to do this is to use SQLAlchemy's <a href="http://docs.sqlalchemy.org/en/latest/orm/internals.html#sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains" rel="nofollow">contains</a>. </p>
<pre><code>Conversation.query.filter(
Conversation.users.contains(user1),
Conversation.... | 1 | 2016-08-29T13:58:46Z | [
"python",
"flask",
"sqlalchemy"
] |
Can any immutable data type be used as a python dictionary key? | 39,206,342 | <p>So I've gone through a few books and sites. Most of the listed possible data types are immutable. I understand how mutable data types can cause problems.</p>
<p>Also tuples were mentioned as possible keys, but when you make the tuples elements lists it raises an error. So I thought that any key, as long as it's imm... | 0 | 2016-08-29T12:26:39Z | 39,206,441 | <p>Any object, as long as it is <a href="https://docs.python.org/2/glossary.html#term-hashable"><strong>hashable</strong></a>, can be used as a key:</p>
<blockquote>
<p>An object is hashable if it has a hash value which never changes during its lifetime (it needs a <code>__hash__()</code> method), and can be compare... | 7 | 2016-08-29T12:32:17Z | [
"python",
"python-2.7",
"dictionary"
] |
Python 3 throws UnicodeEncodeError with environment variable LANG=C | 39,206,705 | <p>I have the following Python script:</p>
<pre><code>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
print('âº')
</code></pre>
<p>When I run it on my Debian system, it produces the following output, as expected:</p>
<pre><code>$ ./test.py
âº
$
</code></pre>
<p>However, when I change locale to "C", by setting t... | 0 | 2016-08-29T12:45:49Z | 39,206,776 | <p>This is because Python 3 uses the locale settings to deduce the output character encoding; that is, Python will use the locale that would be displayed for <code>LC_CTYPE</code> when you execute the locale command:</p>
<pre><code>% locale
...
LC_CTYPE="en_US.UTF-8"
...
</code></pre>
<p>If you force <code>LC_CTYPE<... | 3 | 2016-08-29T12:49:40Z | [
"python",
"python-3.x",
"unicode",
"locale"
] |
How can I add two or more images using matplotlib? | 39,206,713 | <p>I read the images using imread and then I would like to compute the average image. How can I add(and divide) using matplotlib?</p>
<p>I'm searching for something like imadd in matlab.</p>
<p>Code:</p>
<pre><code>img1 = matplotlib.image.imread("path")
img2 = matplotlib.image.imread("path1")
img3 = matplotlib.image... | -1 | 2016-08-29T12:46:18Z | 39,207,034 | <p><code>matplotlib.image</code> is probably what you are looking for. You'll also need <code>numpy</code> if you want to manipulate the images otherwise, because they are basically just arrays in the size of the image (e.g. 1920 x 1080) with 3 or 4 dimensions (RGB or RGBA).</p>
<pre><code>import matplotlib.image as m... | 1 | 2016-08-29T13:03:03Z | [
"python",
"image",
"matplotlib"
] |
How can I add two or more images using matplotlib? | 39,206,713 | <p>I read the images using imread and then I would like to compute the average image. How can I add(and divide) using matplotlib?</p>
<p>I'm searching for something like imadd in matlab.</p>
<p>Code:</p>
<pre><code>img1 = matplotlib.image.imread("path")
img2 = matplotlib.image.imread("path1")
img3 = matplotlib.image... | -1 | 2016-08-29T12:46:18Z | 39,207,078 | <p>You can use the normal sum operations:</p>
<pre><code>img4 = img1 + img2 + img3
</code></pre>
<p>This, however, is not exactly the same as <a href="http://fr.mathworks.com/help/images/ref/imadd.html" rel="nofollow">imadd</a> from matlab. Matplotlib works with RGB values from 0 to 1. As so the sum in some pixels wi... | 1 | 2016-08-29T13:05:22Z | [
"python",
"image",
"matplotlib"
] |
Log disabling in python | 39,206,739 | <p>I am new to this logging module.</p>
<pre><code>logging.basicConfig(level=logging.DEBUG)
logging.disable = True
</code></pre>
<p>As per my understanding this should disable debug logs. But when it is executed it prints debug logs also.</p>
<p>I have only debug logs to print. I dont have critical or info logs. So... | 0 | 2016-08-29T12:47:50Z | 39,206,802 | <p>logging.disable is method, not a configurable attribute.</p>
<p>You can disable logging with :</p>
<p><a href="https://docs.python.org/2/library/logging.html#logging.disable" rel="nofollow">https://docs.python.org/2/library/logging.html#logging.disable</a></p>
<p>To disable all, call:</p>
<pre><code>logging.disa... | 2 | 2016-08-29T12:51:11Z | [
"python",
"python-2.7"
] |
Log disabling in python | 39,206,739 | <p>I am new to this logging module.</p>
<pre><code>logging.basicConfig(level=logging.DEBUG)
logging.disable = True
</code></pre>
<p>As per my understanding this should disable debug logs. But when it is executed it prints debug logs also.</p>
<p>I have only debug logs to print. I dont have critical or info logs. So... | 0 | 2016-08-29T12:47:50Z | 39,206,830 | <p>You can add change <code>level=logging.CRITICAL</code> and receive only critical logs</p>
| 0 | 2016-08-29T12:52:50Z | [
"python",
"python-2.7"
] |
Log disabling in python | 39,206,739 | <p>I am new to this logging module.</p>
<pre><code>logging.basicConfig(level=logging.DEBUG)
logging.disable = True
</code></pre>
<p>As per my understanding this should disable debug logs. But when it is executed it prints debug logs also.</p>
<p>I have only debug logs to print. I dont have critical or info logs. So... | 0 | 2016-08-29T12:47:50Z | 39,206,913 | <p>the <code>level</code> argument in <code>logging.basicConfig</code> you've set to <code>logging.DEBUG</code> is the lowest level of logging which will be displayed.
the order of logging levels is documented <a href="https://docs.python.org/2/library/logging.html#logging-levels" rel="nofollow">here</a>. </p>
<p>if y... | 0 | 2016-08-29T12:56:58Z | [
"python",
"python-2.7"
] |
Django Apache mod_wsgi permission errors | 39,206,968 | <p>Have setup Django in virtualenv but get 500 Internal Server Error. Development server worked fine.</p>
<h2>Environment:</h2>
<ul>
<li>Python 2.7.12</li>
<li>Apache 2.4.23</li>
<li>Django 1.10</li>
<li>Fedora 24</li>
</ul>
<h2>Server log:</h2>
<pre><code>[Mon Aug 29 12:27:49.364393 2016] [mime_magic:error] [pid 1... | 2 | 2016-08-29T12:59:53Z | 39,303,918 | <p>Moving the project outside the home directory to /var/www/django solved my question.</p>
| 1 | 2016-09-03T06:27:01Z | [
"python",
"django",
"apache",
"mod-wsgi"
] |
Numpy: Get rectangle area just the size of mask | 39,206,986 | <p><strong>I have an image and a mask. Both are numpy array.</strong> I get the mask through GraphSegmentation (cv2.ximgproc.segmentation), so the area isn't rectangle, but not divided. I'd like to get a rectangle just the size of masked area, but I don't know the efficient way.</p>
<blockquote>
<p>In other words, u... | 3 | 2016-08-29T13:00:27Z | 39,207,737 | <p>If you prefer pure Numpy, you can achieve this using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow"><code>np.where</code></a> and <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html#numpy.meshgrid" rel="nofollow"><code>np.meshgrid</code></a>... | 1 | 2016-08-29T13:39:15Z | [
"python",
"opencv",
"numpy"
] |
Python: null character breaking xml format | 39,207,067 | <p>I have some python code that processes input files and dumps certain fields from the input to XML files. This code broke when passing a null character from input -- throwing an invalid token error:</p>
<pre><code>def pretty_print_xml(elem):
rough_string = ET.tostring(elem, 'utf-8')
reparsed = minidom.pars... | 0 | 2016-08-29T13:04:40Z | 39,209,884 | <p>NUL literals are not allowed in XML. See <a href="https://www.w3.org/TR/xml11/#charsets" rel="nofollow">the XML standard, version 1.1</a>:</p>
<blockquote>
<h2>2.2 Characters</h2>
<p>[Definition: A parsed entity contains text, a sequence of <a href="https://www.w3.org/TR/xml11/#dt-character" rel="nofollow">c... | 1 | 2016-08-29T15:27:21Z | [
"python",
"xml"
] |
Python can't add canvas to ttk notebook page | 39,207,185 | <pre><code>from tkinter import *
from tkinter import ttk
class MainGame(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
global canvas
# ===Part A ===
self.parent.title('PythonPage')... | -1 | 2016-08-29T13:11:39Z | 39,208,143 | <p>If you want the canvas to be in the notebook, you must add it to one of the notebook pages. For example, if you want it in <code>self.page</code>, you would change this line:</p>
<pre><code>canvas = Canvas(self)
</code></pre>
<p>... to this:</p>
<pre><code>canvas = Canvas(self.page1)
</code></pre>
| 0 | 2016-08-29T13:59:27Z | [
"python",
"tkinter",
"polygon",
"ttk",
"tkinter-canvas"
] |
Scrapy error for multiple formrequest | 39,207,197 | <p>I am using scrapy to login into a website using FormRequest, but since the site is built in ASP.Net, for pagination, I have to use FormRequest too, the code is running alright but I don't know how to configure it for pagination since I am new to scrapy. When I use return in parse_item(), it works but I want to work ... | 0 | 2016-08-29T13:12:11Z | 39,211,217 | <p>You return a list when scrapy either expects <code>scrapy.Item</code> or <code>scrapy.Request</code>.</p>
<p>The culprit lines:</p>
<pre><code>request = [FormRequest.from_response(response, formdata = data, callback = self.parse_page2)]
return request
</code></pre>
<p>To fix this you should either not make reques... | 0 | 2016-08-29T16:46:56Z | [
"python",
"scrapy",
"web-crawler",
"python-requests"
] |
Get subject key identifier from certificate | 39,207,234 | <p>Is it possible to extract the <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2" rel="nofollow">subject key identificator</a> from an existing certificate with python? </p>
<p>I tried someting like:</p>
<pre><code>from OpenSSL.crypto import load_certificate, FILETYPE_PEM
cert_string='-----BEGIN CERTIFI... | 1 | 2016-08-29T13:13:54Z | 39,208,054 | <pre><code>subject=certificate.get_extension(0)
</code></pre>
<p>did the job. With </p>
<pre><code>certificate.get_extension_count()
</code></pre>
<p>you can check how much extensions the certificate has.</p>
| 1 | 2016-08-29T13:54:53Z | [
"python",
"cryptography",
"certificate",
"pyopenssl"
] |
Get subject key identifier from certificate | 39,207,234 | <p>Is it possible to extract the <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2" rel="nofollow">subject key identificator</a> from an existing certificate with python? </p>
<p>I tried someting like:</p>
<pre><code>from OpenSSL.crypto import load_certificate, FILETYPE_PEM
cert_string='-----BEGIN CERTIFI... | 1 | 2016-08-29T13:13:54Z | 39,210,777 | <p>The code that will extract subject key identifier:</p>
<pre><code>from cryptography import x509
from cryptography.hazmat.backends import default_backend
cert = x509.load_pem_x509_certificate(pem_data, default_backend())
ski = cert.extensions.get_extension_for_oid(x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER)
print... | 1 | 2016-08-29T16:18:49Z | [
"python",
"cryptography",
"certificate",
"pyopenssl"
] |
PIP how escape character # in password? | 39,207,316 | <p>want to continue question
<a href="http://stackoverflow.com/questions/19080352/how-to-get-pip-to-work-behind-a-proxy-server/39206294#39206294">How to get pip to work behind a proxy server</a></p>
<p>I have Windows Server and Python 3.5 (64).</p>
<p>In password my user include #.</p>
<p>I try to use some solve:</p... | 1 | 2016-08-29T13:17:19Z | 39,207,995 | <p><strong>Quick way out</strong>: Enter it in the encoded form i.e. <code># -> %23</code></p>
<p>OR </p>
<blockquote>
<p>A better way for pip to handle this might be to add a <code>--proxy-auth</code>
flag that takes : and does the encoding for the
user before adding it to the Proxy URL.</p>
</blockquote>
... | 0 | 2016-08-29T13:51:46Z | [
"python",
"python-3.x",
"pip",
"http-proxy"
] |
PIP how escape character # in password? | 39,207,316 | <p>want to continue question
<a href="http://stackoverflow.com/questions/19080352/how-to-get-pip-to-work-behind-a-proxy-server/39206294#39206294">How to get pip to work behind a proxy server</a></p>
<p>I have Windows Server and Python 3.5 (64).</p>
<p>In password my user include #.</p>
<p>I try to use some solve:</p... | 1 | 2016-08-29T13:17:19Z | 39,210,711 | <pre><code>else examples
</code></pre>
<pre>
$user = str_replace('@', '%40', $user);
$pass = str_replace('%', '%25', $pass); // don't down! (%)
$pass = str_replace('#', '%23', $pass);
$pass = str_replace('@', '%40', $pass);
$pass = str_replace(':', '%3a', $pass);
$pass = str_replace(';', '%3b'... | 0 | 2016-08-29T16:14:20Z | [
"python",
"python-3.x",
"pip",
"http-proxy"
] |
How do you convert a list of nested lists into a list of lists with unique data? | 39,207,333 | <p>After looping my brains out creating reference dictionaries and multi-nested lookup lists I've decided that there has to be an easier way to do this. I can't be the first person to do this type of conversion. I don't even know where to start looking in the docs for a solution.</p>
<p>I have a system that is outputt... | -4 | 2016-08-29T13:18:18Z | 39,207,434 | <p>You can use the <code>itertools.product</code>, which produces </p>
<blockquote>
<p>Cartesian product of input iterables.</p>
<p>Roughly equivalent to nested for-loops in a generator expression. For
example, product(A, B) returns the same as ((x,y) for x in A for y in
B).</p>
</blockquote>
<p>Use it on ... | 3 | 2016-08-29T13:23:51Z | [
"python",
"unique",
"nested-lists"
] |
how to remove the print lines in bash into a log file when start a flask app? | 39,207,436 | <p>I start a flask application in bash like</p>
<blockquote>
<p>python app.py &</p>
</blockquote>
<p>But there is a lot of output informations in the bash when the application running, just as </p>
<blockquote>
<p>Running on <a href="http://0.0.0.0:9999/" rel="nofollow">http://0.0.0.0:9999/</a> (Press CTRL+C... | -2 | 2016-08-29T13:23:59Z | 39,207,482 | <p>try this</p>
<blockquote>
<p>python app.py &>> log.txt</p>
</blockquote>
<p>using single '>' character will truncate the previous data in log file each time new output comes but '>>' will append output.</p>
<p>I hope it helps</p>
| 0 | 2016-08-29T13:26:41Z | [
"python",
"flask"
] |
how to remove the print lines in bash into a log file when start a flask app? | 39,207,436 | <p>I start a flask application in bash like</p>
<blockquote>
<p>python app.py &</p>
</blockquote>
<p>But there is a lot of output informations in the bash when the application running, just as </p>
<blockquote>
<p>Running on <a href="http://0.0.0.0:9999/" rel="nofollow">http://0.0.0.0:9999/</a> (Press CTRL+C... | -2 | 2016-08-29T13:23:59Z | 39,207,595 | <p>You can capture both standard output & error like this (and run in the background):</p>
<pre><code>(python app.py 2&>1 >logfile.txt &)
</code></pre>
<p>If you want to suppress output completely and drop the log:</p>
<pre><code>(python app.py 2&>1 >/dev/null &)
</code></pre>
<p>The... | 0 | 2016-08-29T13:33:00Z | [
"python",
"flask"
] |
Give multiple terminal commands in a single file and run all the commands at once? | 39,207,545 | <p>I'm a beginner into Raspberry pi and i have a basic doubt.</p>
<p>I'm basically trying to make my raspberry pi into a beacon and advertise data from it to a Android app. </p>
<p>I wonder if I can give multiple terminal commands in a single file and run all the commands simply by compiling and running the file?</p>... | 1 | 2016-08-29T13:30:17Z | 39,208,828 | <p>Say you have a file <code>example.txt</code> with your commands:</p>
<pre><code>sudo hcitool lescan
sudo hcitool hci0
sudo hcitool -i hci0 0x008
</code></pre>
<p>Then you can execute those commands by running <code>sh example.txt</code> or <code>bash example.txt</code>.
See <a href="http://stackoverflow.com/questi... | 1 | 2016-08-29T14:34:59Z | [
"python",
"linux",
"raspberry-pi",
"bluetooth-lowenergy",
"ibeacon"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.