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 |
|---|---|---|---|---|---|---|---|---|---|
Removing "\n"s when printing sentences from text file in python? | 39,339,621 | <p>I am trying to print a list of sentences from a text file (one of the Project Gutenberg eBooks). When I print the file as a single string string it looks fine:</p>
<pre><code>file = open('11.txt','r+')
alice = file.read()
print(alice[:500])
</code></pre>
<p>Output is:</p>
<pre><code>ALICE'S ADVENTURES IN WONDERLA... | -1 | 2016-09-06T02:01:53Z | 39,339,757 | <p>If you want to replace all the newlines with one space, do this:</p>
<pre><code>import re
new_sentences = [re.sub(r'\n+', ' ', s) for s in sentences]
</code></pre>
| 3 | 2016-09-06T02:26:17Z | [
"python",
"split",
"format",
"sentence"
] |
Removing "\n"s when printing sentences from text file in python? | 39,339,621 | <p>I am trying to print a list of sentences from a text file (one of the Project Gutenberg eBooks). When I print the file as a single string string it looks fine:</p>
<pre><code>file = open('11.txt','r+')
alice = file.read()
print(alice[:500])
</code></pre>
<p>Output is:</p>
<pre><code>ALICE'S ADVENTURES IN WONDERLA... | -1 | 2016-09-06T02:01:53Z | 39,339,761 | <p>The text uses newlines to delimit sentences as well as fullstops. You have an issue where just replacing the new line characters with an empty string will result in having words without spaces between them. Before you split <code>alice</code> by <code>'.'</code>, I would use something along the lines of @elethan's s... | 0 | 2016-09-06T02:27:00Z | [
"python",
"split",
"format",
"sentence"
] |
Removing "\n"s when printing sentences from text file in python? | 39,339,621 | <p>I am trying to print a list of sentences from a text file (one of the Project Gutenberg eBooks). When I print the file as a single string string it looks fine:</p>
<pre><code>file = open('11.txt','r+')
alice = file.read()
print(alice[:500])
</code></pre>
<p>Output is:</p>
<pre><code>ALICE'S ADVENTURES IN WONDERLA... | -1 | 2016-09-06T02:01:53Z | 39,340,553 | <pre><code>file = open('11.txt','r+')
file.read().split('\n')
</code></pre>
| 0 | 2016-09-06T04:14:22Z | [
"python",
"split",
"format",
"sentence"
] |
creating numpy array with first and last elements different and all other elements the same | 39,339,646 | <p>I want to create the following type of array</p>
<pre><code>N = 5 # size of the array
eta = 2
a00 = 1 # first element of array
a0N = 3 # last element of array
# all entries should be 'eta' except the first and the last one
diag = [a00, eta, eta, eta, a0N]
</code></pre>
<p>I know how to create array that has eta a... | 1 | 2016-09-06T02:07:26Z | 39,339,760 | <p>I'm not aware of a built in method for this kind of array. This is a pretty standard way of doing it.</p>
<pre><code>N = 5 # size of the array
eta = 2
a00 = 1 # first element of array
a0N = 3 # last element of array
# make a vector of 'etas', then change the first and last element
diag = np.ones(N,)*eta
diag[0] = ... | 3 | 2016-09-06T02:26:33Z | [
"python",
"numpy",
"scipy"
] |
Why doesn't the bear(boolean) remain in its position? | 39,339,647 | <p>I wanted to add more functionality to exercise 35 of Zed Shaw's LPTHW. The script runs without crashing and allows the player to revisit previous rooms, as I desired. However, in the bear_room the only way the player can get through is to scream at the bear, switching the bear_moved boolean to True.</p>
<p>If the p... | 0 | 2016-09-06T02:07:39Z | 39,353,929 | <p>Here's the top of your <strong>bear_room</strong> function, with the global functionality fixed. You still have to appropriately alter the calls to the routine.</p>
<p>You are still learning about Boolean values; note the changes I made in your tests. You don't have to test <strong>bear_moved == True</strong>; th... | 2 | 2016-09-06T16:38:02Z | [
"python",
"recursion",
"boolean",
"global",
"functionality"
] |
Why doesn't the bear(boolean) remain in its position? | 39,339,647 | <p>I wanted to add more functionality to exercise 35 of Zed Shaw's LPTHW. The script runs without crashing and allows the player to revisit previous rooms, as I desired. However, in the bear_room the only way the player can get through is to scream at the bear, switching the bear_moved boolean to True.</p>
<p>If the p... | 0 | 2016-09-06T02:07:39Z | 39,355,176 | <p>I researched even more about Python's global and local variables. I now realize that I was changing a local variable within the function, not the global bear_moved. Which is exactly why the bear had plopped its fat self back in front of the door upon re-entry.</p>
<p>After stripping the parameter from the bear_room... | 0 | 2016-09-06T18:01:07Z | [
"python",
"recursion",
"boolean",
"global",
"functionality"
] |
Display Python 2D list without commas, brackets, etc | 39,339,703 | <p>I want to display a 2D list without brackets, commas, or any stuffs. I printed the content of the list using the following code: </p>
<pre><code>print(ncA_string[a][0],ncA_string[a][1],ncA_string[a][2],ncA_string[a][3])
</code></pre>
<p>Unfortunately, however, it is showing the commas, and brackets.
<a href="htt... | -4 | 2016-09-06T02:17:19Z | 39,340,011 | <p>You need to flatten <code>ncA_string[a]</code> first. Try to use <code>flatten</code> function from this answer <a href="http://stackoverflow.com/a/12472461/1112457">http://stackoverflow.com/a/12472461/1112457</a> . Then you can unpack the flattened list as arguments to the <code>print</code> function:</p>
<pre><co... | 0 | 2016-09-06T03:02:15Z | [
"python",
"list"
] |
How do I run Pygame on Pycharm | 39,339,709 | <p>I am trying to run pygame on the PyCharm IDE, I have installed the latest version of pygame for python 3.5 and have added it to the project interpreter. I installed pygame from <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame" rel="nofollow">http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame</a> and copied ... | 0 | 2016-09-06T02:18:27Z | 39,339,783 | <p>Follow the instructions provided here. I think its related to the problem you are having on pygame and PyCharm on windows.
<a href="http://stackoverflow.com/questions/35609592/how-do-i-download-pygame-for-python-3-5-1">How do I download Pygame for Python 3.5.1?</a></p>
| 0 | 2016-09-06T02:29:36Z | [
"python",
"python-3.x",
"pygame",
"pycharm",
"failed-installation"
] |
How does this for, in generator work in Python 2.7.x | 39,339,711 | <p>I'm aware of the <code>for x in list</code> loop in Python, but I stumbled on a type of generator whose documentation I couldn't find. I found out that the example below only works if the lists inside the list <code>a</code> are of length 2, or it gives an unpacking error, so I suspect some kind of 2-tuple or dict-r... | 1 | 2016-09-06T02:18:30Z | 39,339,744 | <p>Don't be fooled by the comma in <code>c, b</code>. In Python, commas -- not parentheses -- are what defines a tuple. Your code is equivalent to <code>[x for x in (b for (c, b) in a)]</code>, which iterates through the elements of <code>a</code>, assigning <code>c</code> to the first element of each two-element list ... | 4 | 2016-09-06T02:23:44Z | [
"python",
"python-2.7"
] |
How does this for, in generator work in Python 2.7.x | 39,339,711 | <p>I'm aware of the <code>for x in list</code> loop in Python, but I stumbled on a type of generator whose documentation I couldn't find. I found out that the example below only works if the lists inside the list <code>a</code> are of length 2, or it gives an unpacking error, so I suspect some kind of 2-tuple or dict-r... | 1 | 2016-09-06T02:18:30Z | 39,339,770 | <p>Starting from the inside, we are creating a generator expression from list a:</p>
<pre><code>a = [[1,2],[3,4],[5,6]]
</code></pre>
<p>So, Let us look at that one alone:</p>
<pre><code>(b for c, b in a)
</code></pre>
<p>So, if you look back at list <code>a</code>, we have a list of lists, where each sub-list is j... | 1 | 2016-09-06T02:28:12Z | [
"python",
"python-2.7"
] |
Backslash escaping is not working in Python | 39,339,743 | <p>I want Python interpreter to show me <code>\'</code> as a calculated value. I tried typing <code>"\\'"</code> and it returned me the same thing. If I try <code>"\'"</code> then the backslash is not shown anymore after I hit return. How do I get it to show the backslash like this after I hit return- <code>\'</code> ?... | 1 | 2016-09-06T02:23:33Z | 39,339,769 | <p><code>print("\'")</code></p>
<p>repr of a string will never put out a single backslash. repr smartly picks quotes to avoid backslashes. You can get a \' to come out if you do something like '\'"'</p>
| 0 | 2016-09-06T02:28:07Z | [
"python"
] |
Backslash escaping is not working in Python | 39,339,743 | <p>I want Python interpreter to show me <code>\'</code> as a calculated value. I tried typing <code>"\\'"</code> and it returned me the same thing. If I try <code>"\'"</code> then the backslash is not shown anymore after I hit return. How do I get it to show the backslash like this after I hit return- <code>\'</code> ?... | 1 | 2016-09-06T02:23:33Z | 39,339,772 | <p>Here are two ways to get <code>\'</code>:</p>
<pre><code>>>> print("\\'")
\'
>>> print(r"\'")
\'
</code></pre>
<h3>Discussion</h3>
<pre><code>>>> print("\'")
'
</code></pre>
<p>The above prints out a single <code>'</code> because an escaped <code>'</code> is just a <code>'</code>.</p>
... | 7 | 2016-09-06T02:28:26Z | [
"python"
] |
Celery Worker - Consume from Queue matching a regex | 39,339,804 | <p><strong>Background</strong></p>
<p>Celery worker can be started against a set of queues using -Q flag. E.g. </p>
<blockquote>
<p>-Q dev.Q1,dev.Q2,dev.Q3</p>
</blockquote>
<p>So far I have seen examples where all the queue names are explicitly listed as comma separated values. It is troublesome if I have a very ... | 0 | 2016-09-06T02:32:35Z | 39,340,088 | <p>Something along these lines would work: (\b(dev.)(\w+)).
Then refer to the second group for the stuff after "dev.".</p>
<p>You'll need to set it up to capturing repeated instances if you want to get multiple.</p>
| 0 | 2016-09-06T03:11:30Z | [
"python",
"celery",
"django-celery"
] |
How to get rows with the max value by using Python? | 39,339,907 | <p>I have R code to use data table to merger the rows with same FirstName and LastName but selecting the max value for specified columns(e.g. Score1, Score2, Score3). The input/output is as follows:</p>
<p><Strong>Input:</Strong></p>
<pre>
FirstName LastName Score1 Score2 Score3
fn1 ln1 41 88 50
f... | 3 | 2016-09-06T02:47:04Z | 39,340,129 | <p>Here is the way to do it with in-built packages of python:</p>
<pre><code>import csv
from collections import OrderedDict
newdata = OrderedDict()
with open('test.csv', 'rb') as testr:
testreader = csv.reader(testr)
for row in testreader:
name = row[0]+ '-' + row[1]
if name in newdata:
... | 1 | 2016-09-06T03:16:22Z | [
"python",
"apache-spark"
] |
How to get rows with the max value by using Python? | 39,339,907 | <p>I have R code to use data table to merger the rows with same FirstName and LastName but selecting the max value for specified columns(e.g. Score1, Score2, Score3). The input/output is as follows:</p>
<p><Strong>Input:</Strong></p>
<pre>
FirstName LastName Score1 Score2 Score3
fn1 ln1 41 88 50
f... | 3 | 2016-09-06T02:47:04Z | 39,340,143 | <p>As suggested by durbachit, you'll want to use pandas.</p>
<pre><code>import pandas as pd
df = pd.read_csv(**your file here**)
max_df = df.groupby(by=['FirstName','LastName']).max()
</code></pre>
<p>And max_df will be your desired output. <a href="http://pandas.pydata.org/pandas-docs/version/0.18.0/generated/pandas... | 2 | 2016-09-06T03:17:48Z | [
"python",
"apache-spark"
] |
How to get rows with the max value by using Python? | 39,339,907 | <p>I have R code to use data table to merger the rows with same FirstName and LastName but selecting the max value for specified columns(e.g. Score1, Score2, Score3). The input/output is as follows:</p>
<p><Strong>Input:</Strong></p>
<pre>
FirstName LastName Score1 Score2 Score3
fn1 ln1 41 88 50
f... | 3 | 2016-09-06T02:47:04Z | 39,340,205 | <pre><code>import pandas
rows = pandas.read_csv('rows.csv', delim_whitespace=True)
rows.groupby(['FirstName', 'LastName']).max()
</code></pre>
| 0 | 2016-09-06T03:27:26Z | [
"python",
"apache-spark"
] |
Pandas - dropping rows with missing data not working using .isnull(), notnull(), dropna() | 39,339,935 | <p>This is really weird. I have tried several ways of dropping rows with missing data from a pandas dataframe, but none of them seem to work.
This is the code (I just uncomment one of the methods used - but these are the three that I used in different modifications - this is the latest):</p>
<pre><code>import pandas a... | 2 | 2016-09-06T02:50:00Z | 39,340,010 | <p>Your example DF has <code>NaN</code> and <code>NaT</code> as strings which <code>.dropna</code>, <code>.notnull</code> and co. won't consider falsey, so given your example you can use...</p>
<pre><code>df[~df.isin(['NaN', 'NaT']).any(axis=1)]
</code></pre>
<p>Which gives you:</p>
<pre><code> A B C
0 1 1 1
... | 2 | 2016-09-06T03:02:02Z | [
"python",
"pandas"
] |
Pandas - dropping rows with missing data not working using .isnull(), notnull(), dropna() | 39,339,935 | <p>This is really weird. I have tried several ways of dropping rows with missing data from a pandas dataframe, but none of them seem to work.
This is the code (I just uncomment one of the methods used - but these are the three that I used in different modifications - this is the latest):</p>
<pre><code>import pandas a... | 2 | 2016-09-06T02:50:00Z | 39,340,141 | <p>Try this on orig data: </p>
<pre><code>Test.replace(["NaN", 'NaT'], np.nan, inplace = True)
Test = Test.dropna()
Test
</code></pre>
<p>Or Modify data and do this </p>
<pre><code>import pandas as pd
Test = pd.DataFrame({'A':[1,2,3,4,5],'B':[1,2,np.nan,4,5],'C':[1,2,3,pd.NaT,5]})
print(Test)
Test = Test.dropna()
pr... | 1 | 2016-09-06T03:17:34Z | [
"python",
"pandas"
] |
Regex - Match string with or without suffix, but without including it in match group | 39,339,957 | <p>I'm currently trying to make a text message command server (basically, I send a text to google voice, that gets forwarded to my email, I use a python IMAP library to access the message, and I parse it), and I have an interesting problem. Sometimes, when a text comes through, the string </p>
<pre><code>--
Sent using... | 0 | 2016-09-06T02:53:51Z | 39,340,116 | <p>If I understand your problem correctly, you are filtering out the optional signature of the message. In python you should be able to set the single line regex flag (i.e. <code>re.S</code>), and use the following regex to capture the desired content.</p>
<pre><code>regex = re.compile(r'(.+)(?=--)|(.+)', r.S)
</code>... | 0 | 2016-09-06T03:14:52Z | [
"python",
"regex"
] |
Regex - Match string with or without suffix, but without including it in match group | 39,339,957 | <p>I'm currently trying to make a text message command server (basically, I send a text to google voice, that gets forwarded to my email, I use a python IMAP library to access the message, and I parse it), and I have an interesting problem. Sometimes, when a text comes through, the string </p>
<pre><code>--
Sent using... | 0 | 2016-09-06T02:53:51Z | 39,340,314 | <pre><code>def remove_footer(incoming_str):
footer = '''
--
Sent using SMS-to-email. Reply to this email to text the sender back and save on SMS fees.
https://www.google.com/voice/'''
if incoming_str[-len(footer):] == footer:
return incoming_str[:-len(footer)]
else:
return incoming_str
</cod... | 0 | 2016-09-06T03:43:21Z | [
"python",
"regex"
] |
Django customize model fields to show on template | 39,339,962 | <p>I'm in a weird situation. I have following model. On a template i render only name and author. The thing is there is <strong>edit display</strong> button, when click on edit display. It should show all the fields name to choose. When i choose fields and save table's element should be updated as chosen fields.</p>
<... | 0 | 2016-09-06T02:54:20Z | 39,343,786 | <p>You can create a checkedbox form and handle the values in the view to return appropriate html content, for example (form):</p>
<pre><code>class CheckBox(forms.Form):
name = forms.BooleanField(required=False)
</code></pre>
<p>View:</p>
<pre><code>def your_view(request):
form = MyForm(request.POST or None)
... | 0 | 2016-09-06T08:09:20Z | [
"python",
"django"
] |
Screenshot from a user's mouse input with python | 39,340,002 | <p>So i want to implement a global and partial screenshot tool (like snipping tool in Windows) with python. I want user to input the area that he wants to screenshot with mouse. I can use pyscreenshot module but how can i manipulate the input on :</p>
<pre><code>im=ImageGrab.grab(bbox=(10,10,510,510)) # X1,Y1,X2,Y2
</... | 0 | 2016-09-06T03:00:07Z | 39,340,066 | <p>You could do something like</p>
<pre><code>cursor = X.NONE
self.window.grab_pointer(1,X.PointerMotionMask|X.ButtonReleaseMask|X.ButtonPressMask,X.GrabModeAsync, X.GrabModeAsync, X.NONE, cursor, X.CurrentTime)
</code></pre>
<p>See a complete example <a href="https://gist.github.com/initbrain/6628609" rel="nofollow"... | 0 | 2016-09-06T03:08:48Z | [
"python",
"screenshot"
] |
How to match a sentence exactly, rather than substring match | 39,340,046 | <p>So I created a simple reddit bot using PRAW:</p>
<pre><code>import praw
import time
from praw.helpers import comment_stream
r = praw.Reddit("han_solo_response")
r.login()
target_text = "I love you"
response_text = "I know"
processed = []
while True:
for c in comment_stream(r, 'all'):
if target_text i... | 0 | 2016-09-06T03:06:05Z | 39,340,078 | <p>This line:</p>
<p><code>if target_text in c.body and c.id not in processed:</code></p>
<p>should be:</p>
<p><code>if target_text == c.body and c.id not in processed:</code></p>
<p>If you want to make it case-insensitive:</p>
<p><code>target_text = "i love you"</code></p>
<p>and</p>
<p><code>if target_text == ... | 0 | 2016-09-06T03:10:21Z | [
"python",
"bots",
"reddit"
] |
UnicodeDecodeError while dumping dictionary to file using json dump | 39,340,074 | <p>I have a dictionary, created from reading the windows registry where keys of dictionary are registry keys and corresponding values are the values of the same key in dictionary.
Now, I am trying to dump to a file using <code>json.dump()</code>. But, this gives me two different errors on two different systems. I am ... | -2 | 2016-09-06T03:10:04Z | 39,340,725 | <p>I suppose that encoding of data read from the registry not changed. So it is UTF-16. Specifically, UTF-16LE on one system and UTF-16BE on another. This explains the different errors. If my assumption is correct, this may help you:</p>
<pre><code>import collections
import io
import json
def decode_dict(data):
i... | 1 | 2016-09-06T04:35:25Z | [
"python",
"json",
"python-2.7",
"dictionary"
] |
Plotting (and saving) specific cells from multiple dataframe in Pandas | 39,340,103 | <p>For example, if I have 3 dataframes like this:</p>
<pre><code>In [1]: df1 = pd.DataFrame({'A': ['32', '36', '40', '33'],
...: 'B': ['32', '34', '39', '35'],
...: 'C': ['34', '32', '35', '36'],
...: 'D': ['35', '39', '42', '40']},
...: ... | 2 | 2016-09-06T03:13:30Z | 39,340,421 | <p>You can do this either by doing a little bit of scripting or by making one big dataframe combining all the smaller dataframes</p>
<p>Scripting:</p>
<ol>
<li>Put all your df in a list <code>df_list = [df1, df2, df3]</code></li>
<li><p>Parse through the list, collect all the values in a list and then plot it. </p>
... | 0 | 2016-09-06T03:57:21Z | [
"python",
"pandas",
"dataframe"
] |
Plotting (and saving) specific cells from multiple dataframe in Pandas | 39,340,103 | <p>For example, if I have 3 dataframes like this:</p>
<pre><code>In [1]: df1 = pd.DataFrame({'A': ['32', '36', '40', '33'],
...: 'B': ['32', '34', '39', '35'],
...: 'C': ['34', '32', '35', '36'],
...: 'D': ['35', '39', '42', '40']},
...: ... | 2 | 2016-09-06T03:13:30Z | 39,340,653 | <p><strong><em>Option 1</em></strong></p>
<p>The most general solution to your question would be to wrap your dataframes into a <code>pandas.Panel</code></p>
<pre><code>pnl = pd.Panel({'df1': df1, 'df2': df2, 'df3': df3})[['df1', 'df2', 'df3']]
</code></pre>
<p>Then you could access the desired series</p>
<pre><cod... | 2 | 2016-09-06T04:26:21Z | [
"python",
"pandas",
"dataframe"
] |
How to set the python searching directory of data file in another sub-folder in pycharm? | 39,340,127 | <p>Here my project has folder alignment as follows:</p>
<pre><code> myProject:
---------
main.py
-------------
folder1:
test.py
--------------
folder2:
lib.py
__init__.py
---------------
folder_for_data:
data_file1
data_file2
<... | 0 | 2016-09-06T03:15:56Z | 39,347,898 | <p>For the most part, this question is independent of PyCharm. It's mostly about how to import modules and load data files in Python using relative paths.</p>
<p>Importing modules is different than opening data files, for quite a number of reasons. It is affected by: the working directory that you run Python from, the... | 0 | 2016-09-06T11:24:11Z | [
"python",
"pycharm"
] |
How to access the key values in python dictionary with variables? | 39,340,225 | <p>I have a dict whose keys are numbers. It looks like this:</p>
<pre><code>{'1': 3, '2': 7, '3', 14}
</code></pre>
<p>I need to access the value of each key with a variable, but get stuck because of the quotation marks of keys. How can I do that?</p>
| 0 | 2016-09-06T03:29:33Z | 39,340,264 | <p>You can cast your number to a string,</p>
<pre><code>my_dict = {'1': 3, '2': 7, '3': 14}
number = 2
print(my_dict[str(number)])
</code></pre>
| 1 | 2016-09-06T03:36:11Z | [
"python",
"dictionary"
] |
How to access the key values in python dictionary with variables? | 39,340,225 | <p>I have a dict whose keys are numbers. It looks like this:</p>
<pre><code>{'1': 3, '2': 7, '3', 14}
</code></pre>
<p>I need to access the value of each key with a variable, but get stuck because of the quotation marks of keys. How can I do that?</p>
| 0 | 2016-09-06T03:29:33Z | 39,340,514 | <p>If values is all what you want to access and the sequence doesn't matter then you can simply loop through the dict to access the values.</p>
<pre><code>my_dict = {'1': 3, '2': 7, '3': 14}
for k in my_dict:
print my_dict[k]
</code></pre>
| 0 | 2016-09-06T04:09:52Z | [
"python",
"dictionary"
] |
Don't understand why ValueError: No JSON object could be decoded occurs | 39,340,295 | <p>I'm getting this following error</p>
<pre class="lang-none prettyprint-override"><code>ValueError: No JSON object could be decoded
</code></pre>
<p>My json data is valid, i changing the JSON file encoding to utf-8, but still didn't work, this is my code :</p>
<pre><code>f = open(os.path.dirname(os.path.abspath(__... | 0 | 2016-09-06T03:40:11Z | 39,345,699 | <p>First of all, let's confirm your json data is valid emulating the content of your file like this:</p>
<pre><code>import json
from StringIO import StringIO
f = StringIO("""
{"X":19235, "Y":19220, "Z":22685}
""")
try:
data = f.read()
json.loads(data)
except:
print("BREAKPOINT")
print("DONE")
</code><... | 1 | 2016-09-06T09:40:35Z | [
"python",
"json",
"object"
] |
Scrapy Json Rule SgmlLink Extractor | 39,340,339 | <p>I just want to know on how can I make rule when the website sends me a json response instead of html? On the start url first response, it gives me an html response, but when I navigated through pages, it gives me json response. Here my rule:</p>
<pre><code> Rule(SgmlLinkExtractor(restrict_xpaths=('//div[@class="Gri... | 0 | 2016-09-06T03:46:22Z | 39,342,048 | <p>You can't parse json with xpath or css selectors. You can however turn the json to python dictionary:</p>
<pre><code>import json
def parse(self, response):
data = json.loads(response.body)
# then just parse it, e.g.
item = dict()
item['name'] = data['name']
# ...
</code></pre>
<p>Or you can con... | 0 | 2016-09-06T06:34:25Z | [
"python",
"json",
"scrapy",
"web-crawler",
"sgml"
] |
anti crawler - Python | 39,340,360 | <p>I know to write Python crawler with beautiful soup module. Now I want to detect if someone crawls my website. How to do that. Can someone point me to pesudo code or sourcecode. Basically I am looking to write anti-crawler in python. </p>
| -3 | 2016-09-06T03:48:58Z | 39,341,503 | <p>It's hard, but can do things to filter crawlers.</p>
<p><strong>Auth</strong></p>
<p>Show pages only to authorized users. </p>
<p><strong>Strong Captcha</strong></p>
<p>If your captcha system strong enough, can anti a part of crawlers.</p>
<p><strong>User Agent</strong></p>
<p>Requests from crawler may not set... | 0 | 2016-09-06T05:53:13Z | [
"python",
"python-2.7",
"python-3.x",
"web-crawler",
"google-crawlers"
] |
anti crawler - Python | 39,340,360 | <p>I know to write Python crawler with beautiful soup module. Now I want to detect if someone crawls my website. How to do that. Can someone point me to pesudo code or sourcecode. Basically I am looking to write anti-crawler in python. </p>
| -3 | 2016-09-06T03:48:58Z | 39,343,850 | <p>What about assuming that not all crawlers are nasty? Most do respect the <a href="http://www.robotstxt.org/" rel="nofollow">robots directives</a>. Of course you can implement all sorts of heuristics to block robots but the first thing you do would be to have </p>
<pre><code>User-agent: *
Disallow: /
</code></pre>
... | 0 | 2016-09-06T08:12:08Z | [
"python",
"python-2.7",
"python-3.x",
"web-crawler",
"google-crawlers"
] |
Django - Built project broken | 39,340,444 | <p>So basically, I have a DJANGO project that can be executed and work well. And I don't know why (maybe I upgrade my django or sth) that this is no longer working.</p>
<p>First I try "python3 manage.py runserver" I get this from console:</p>
<p><a href="http://i.stack.imgur.com/oLfwV.jpg" rel="nofollow"><img src="ht... | -2 | 2016-09-06T04:00:15Z | 39,340,846 | <p>It seems to me that you've got a python dependency problem. You've probably added django ckeditor in your INSTALLED_APPS settings, but it's not installed in your (virtual) env.</p>
<p>So have you installed django ckeditor using pip ? It's not related to the static folders or anything, they're not compile time error... | 0 | 2016-09-06T04:49:12Z | [
"python",
"django"
] |
Why can't PyBrain Learn Binary | 39,340,464 | <p>I am attempting to get a network (PyBrain) to learn binary. This my code and it keeps return values around 8, but it should be return 9 when I activate with this target.</p>
<pre><code>from pybrain.tools.shortcuts import buildNetwork
from pybrain.structure import *
from pybrain.datasets import *
from pybrain.superv... | 2 | 2016-09-06T04:02:51Z | 39,340,882 | <p>I would suggest you make the target something in the middle instead of on the fringe.</p>
<p>I tried expanding the training data upwards with 10 and 11, then it produced better results on predicting 9, even with 9 left out of the training data. Also you get a pretty good result if you try to predict 4, even if you ... | 1 | 2016-09-06T04:53:28Z | [
"python",
"neural-network",
"artificial-intelligence",
"pybrain"
] |
Why can't PyBrain Learn Binary | 39,340,464 | <p>I am attempting to get a network (PyBrain) to learn binary. This my code and it keeps return values around 8, but it should be return 9 when I activate with this target.</p>
<pre><code>from pybrain.tools.shortcuts import buildNetwork
from pybrain.structure import *
from pybrain.datasets import *
from pybrain.superv... | 2 | 2016-09-06T04:02:51Z | 39,341,487 | <p>You've built a network with 4 input nodes, 4 hidden nodes, and 1 output node, and 2 biases.</p>
<p><a href="http://i.stack.imgur.com/CsqV5.png" rel="nofollow"><img src="http://i.stack.imgur.com/CsqV5.png" alt="enter image description here"></a></p>
<p>Considering each letter as the activation for that node, we can... | 2 | 2016-09-06T05:51:20Z | [
"python",
"neural-network",
"artificial-intelligence",
"pybrain"
] |
Filling HTML password field using Python (Requests) | 39,340,490 | <p>I have been trying to login to a website (<a href="https://osu.ppy.sh/" rel="nofollow">https://osu.ppy.sh/</a>) using the Requests library in Python (<a href="http://docs.python-requests.org/" rel="nofollow">http://docs.python-requests.org/</a>). The following code seems to fill in the "username" field but not the "... | 0 | 2016-09-06T04:06:27Z | 39,341,170 | <p>First, it's not because the type of password, the most likely point is that your payload is not completed.</p>
<p>I checked the form data to login <a href="https://osu.ppy.sh" rel="nofollow">https://osu.ppy.sh</a>, it likes this:</p>
<p><a href="http://i.stack.imgur.com/bkzlF.png" rel="nofollow"><img src="http://i... | -2 | 2016-09-06T05:23:19Z | [
"python",
"python-3.x",
"python-requests"
] |
Shut down Flask SocketIO Server | 39,340,650 | <p>For circumstances outside of my control, I need to use the Flask server to serve basic html files, the Flask SocketIO wrapper to provide a web socket interface between any clients and the server. The <code>async_mode</code> has to be <code>threading</code> instead of <code>gevent</code> or <code>eventlet</code>, I u... | 0 | 2016-09-06T04:26:03Z | 39,342,270 | <p>I have good news for you, the testing environment does not use a real server, in that context the client and the server run inside the same process, so the communication between them does not go through the network as it does when you run things for real. Really in this situation there is no server, so there's nothi... | 1 | 2016-09-06T06:48:37Z | [
"python",
"python-2.7",
"flask",
"werkzeug",
"flask-socketio"
] |
Error while concatenating lists in python | 39,340,749 | <p>I am working on an assignment for one of my classes at school where I need to concatenate two lists together. I am using the code:</p>
<pre><code>flowers = ["rose", "bougainvillea", "yukka", "marigold", "daylily", "lily of the valley"]
thorny = flowers[0:3]
poisonous = flowers[-1]
dangerous = flowers[0:3] + flowe... | 0 | 2016-09-06T04:38:45Z | 39,340,759 | <p><code>flowers[0:3]</code> returns a list while <code>flowers[-1]</code> returns a string, so you are adding a string to a list. You can use <code>flowers[-1:]</code> to return a list instead.</p>
| 6 | 2016-09-06T04:40:28Z | [
"python"
] |
Error while concatenating lists in python | 39,340,749 | <p>I am working on an assignment for one of my classes at school where I need to concatenate two lists together. I am using the code:</p>
<pre><code>flowers = ["rose", "bougainvillea", "yukka", "marigold", "daylily", "lily of the valley"]
thorny = flowers[0:3]
poisonous = flowers[-1]
dangerous = flowers[0:3] + flowe... | 0 | 2016-09-06T04:38:45Z | 39,340,881 | <p>Put square brackets around <em>flowers[-1]</em> to return the item as a list. E.g. </p>
<pre><code>flowers = ["rose", "bougainvillea", "yukka", "marigold", "daylily", "lily of the valley"]
thorny = flowers[0:3]
poisonous = [(flowers[-1])]
dangerous = thorny + poisonous
</code></pre>
| -1 | 2016-09-06T04:53:26Z | [
"python"
] |
xbee.remote_at not working | 39,340,773 | <p>I am using python-xbee to work with XBee modules (Python 2.7). I have an XBee (coordinator) directly connected to my laptop through a serial port and another separate one (endpoint). I can easily communicate with them both using the <code>at</code> command, but I can't communicate with them using <code>remote_at</co... | 0 | 2016-09-06T04:41:43Z | 39,354,245 | <ol>
<li><code>escaped=True</code> is only if you have <code>ATAP</code> set to 2 (escaped API mode) instead of 1 (API mode).</li>
<li>Are you sure your modules are joined to each other, and you're not seeing an <code>ATND</code> response from your local device? Make sure you're using the address of the remote module.... | 0 | 2016-09-06T16:58:53Z | [
"python",
"serial-port",
"xbee",
"zigbee"
] |
xbee.remote_at not working | 39,340,773 | <p>I am using python-xbee to work with XBee modules (Python 2.7). I have an XBee (coordinator) directly connected to my laptop through a serial port and another separate one (endpoint). I can easily communicate with them both using the <code>at</code> command, but I can't communicate with them using <code>remote_at</co... | 0 | 2016-09-06T04:41:43Z | 39,380,421 | <p>remote_at requires a non-zero frame_id to return a response. Run:</p>
<pre><code>xbee.remote_at(dest_addr='\x61\xd4', command='MY', frame_id='A')
</code></pre>
<p>and the output is:</p>
<pre><code>{'status': '\x00', 'source_addr': '\x00\x00', 'source_addr_long': '\x00\x13\xa2\x00@\n\x05\xab', 'frame_id': 'A', 'co... | 0 | 2016-09-07T23:26:23Z | [
"python",
"serial-port",
"xbee",
"zigbee"
] |
More pythonic way to nest functions | 39,340,832 | <p>Here is the code that I have:</p>
<pre><code>def reallyquit():
from easygui import boolbox
if __debug__: print ("realy quit?")
answer = boolbox("Are you sure you want to Quit?")
if answer == 1:
sys.exit()
return
columns = ['adr1','adr2','spam','spam', 'spam']
St... | 2 | 2016-09-06T04:47:51Z | 39,340,889 | <pre class="lang-py prettyprint-override"><code>import sys
from easygui import boolbox, choicebox
def reallyquit():
"Ask if the user wants to quit. If so, exit."
if __debug__:
print("really quit?")
answer = boolbox("Are you sure you want to Quit?")
if answer == 1:
sys.exit()
columns =... | 2 | 2016-09-06T04:54:21Z | [
"python",
"python-2.7",
"easygui"
] |
More pythonic way to nest functions | 39,340,832 | <p>Here is the code that I have:</p>
<pre><code>def reallyquit():
from easygui import boolbox
if __debug__: print ("realy quit?")
answer = boolbox("Are you sure you want to Quit?")
if answer == 1:
sys.exit()
return
columns = ['adr1','adr2','spam','spam', 'spam']
St... | 2 | 2016-09-06T04:47:51Z | 39,341,149 | <p>I think this is more idiomatic than using a sentinel variable:</p>
<pre><code>while True:
street = choicebox("Street Address?", title, columns)
if street is None:
reallyquit()
else:
break
</code></pre>
<p>Also, consider using the <a href="https://docs.python.org/3/library/logging.html" ... | 0 | 2016-09-06T05:19:43Z | [
"python",
"python-2.7",
"easygui"
] |
Converting output of dependency parsing to tree | 39,340,907 | <p>I am using <code>Stanford dependency parser</code> and the I get the following output of the sentence</p>
<blockquote>
<p>I shot an elephant in my sleep</p>
</blockquote>
<pre><code>python dep_parsing.py
[((u'shot', u'VBD'), u'nsubj', (u'I', u'PRP')), ((u'shot', u'VBD'), u'dobj', (u'elephant', u'NN')), ((u'elep... | 0 | 2016-09-06T04:56:09Z | 39,342,032 | <p>You can traverse over <code>dep.triples()</code> and get your desired output.</p>
<p><strong>Code:</strong></p>
<pre><code>for triple in dep.triples():
print triple[1],"(",triple[0][0],", ",triple[2][0],")"
</code></pre>
<p><strong>Output:</strong></p>
<pre><code>nsubj ( shot , I )
dobj ( shot , elephant )... | 2 | 2016-09-06T06:33:38Z | [
"python",
"data-structures",
"nlp",
"dependency-parsing"
] |
Connection Refused on Concurrent connection to openerp with xmlrpc (via python) | 39,340,950 | <p>I've tried to build a stress test sistem which provide multiple concurent user login. The scheme is 1 thread for 1 user login. But i cant login with multiple user at the same time (concurent).</p>
<p>At the other side, i've tried to login with multiple user in sequential scheme (with thread.lock and thread.release ... | 1 | 2016-09-06T05:00:03Z | 39,344,711 | <p>You forgot <code>xml_port</code> when you create <code>theUser</code>, it should be: </p>
<pre><code>thread_ = theUser(idx, row, dbhost, xml_port, dbuser, dbpassword, dbname)
</code></pre>
<p>And <code>self.sock_common</code> won't be set if an exception is raised.You can move it to <code>run()</code> function.</... | 1 | 2016-09-06T08:54:44Z | [
"python",
"multithreading",
"openerp",
"python-multithreading",
"stress-testing"
] |
Converting stanford dependencies in numbered format | 39,340,965 | <p>I am using <code>Stanford dependency parser</code> and the I get the following output of the sentence</p>
<blockquote>
<p>I shot an elephant in my sleep</p>
</blockquote>
<pre><code>>>>python dep_parsing.py
[((u'shot', u'VBD'), u'nsubj', (u'I', u'PRP')), ((u'shot', u'VBD'), u'dobj', (u'elephant', u'NN'... | 0 | 2016-09-06T05:01:40Z | 39,417,631 | <p>Write a recursive function that traverses your tree. As a first pass, just try assigning the numbers to the words.</p>
| 0 | 2016-09-09T18:23:52Z | [
"python",
"nlp",
"nltk",
"stanford-nlp",
"dependency-parsing"
] |
assert vs == for testing code in Python? | 39,341,060 | <p>What is the need for importing unittest and running assertTrue (for example) while testing a python function instead of writing a usual python function with == True check for testing? What is the new thing about unittesting, as even the test cases have to be written by user, which can be checked by == instead of ass... | 1 | 2016-09-06T05:10:33Z | 39,341,480 | <p>I would say that the most interesting thing is the "easy-to-test" that the unittest package (as well as others, for example pytest) provides. When using unittest you can just run a command and check if your refactoring or your last feature broke something on the rest of the program. I would read something about <a h... | 1 | 2016-09-06T05:50:55Z | [
"python",
"python-2.7",
"unit-testing",
"testing",
"tdd"
] |
How to get the specific number of lines in a file using python programming? | 39,341,092 | <p>This is my code for getting 20 lines every time but f1.tell() gives last position of the file. So i cannot get 20 lines for the next time.
Can anyone help me to do this? please</p>
<pre><code>f1=open("sample.txt","r")
last_pos=0
while true:
f1.seek(last_pos)
for line,i in enumerate(f1.readlines()):
... | 0 | 2016-09-06T05:13:30Z | 39,341,185 | <p>Using <code>readlines</code> reads all the file: you reach the end, hence what you are experiencing.</p>
<p>Using a loop with <code>readline</code> works, though, and gives you the position of the end of the 20th line (well, rather the start of the 21st)</p>
<p>Code (I removed the infinite loop BTW):</p>
<pre><co... | 1 | 2016-09-06T05:25:16Z | [
"python",
"file"
] |
How to get the specific number of lines in a file using python programming? | 39,341,092 | <p>This is my code for getting 20 lines every time but f1.tell() gives last position of the file. So i cannot get 20 lines for the next time.
Can anyone help me to do this? please</p>
<pre><code>f1=open("sample.txt","r")
last_pos=0
while true:
f1.seek(last_pos)
for line,i in enumerate(f1.readlines()):
... | 0 | 2016-09-06T05:13:30Z | 39,341,497 | <p>Jean-François Fabre already explained that <code>readline</code> could read the whole file.</p>
<p>But anyway you should never mix line level input (<code>readline</code>) and byte level input (<code>tell</code>, <code>seek</code> or <code>read</code>). As the low level OS system calls can only read a byte count, ... | 0 | 2016-09-06T05:52:49Z | [
"python",
"file"
] |
Getting TypeError when I am trying to run server using Django? | 39,341,093 | <p>I found questions which were close to the question asked by me, but the solutions I found there were not useful to me. Using django version 1.10.1</p>
<p>Output to </p>
<blockquote>
<p>python manage.py runserver</p>
</blockquote>
<pre><code>Performing system checks...
Unhandled exception in thread started by &... | 0 | 2016-09-06T05:13:38Z | 39,341,186 | <p>In 1.10, you can no longer pass import paths to url(), you need to pass the actual view function:</p>
<pre><code>from django.conf.urls import url
from django.contrib import admin
from hacko import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.home, name='home'),
url(r'^index/$... | 0 | 2016-09-06T05:25:17Z | [
"python",
"django"
] |
Getting TypeError when I am trying to run server using Django? | 39,341,093 | <p>I found questions which were close to the question asked by me, but the solutions I found there were not useful to me. Using django version 1.10.1</p>
<p>Output to </p>
<blockquote>
<p>python manage.py runserver</p>
</blockquote>
<pre><code>Performing system checks...
Unhandled exception in thread started by &... | 0 | 2016-09-06T05:13:38Z | 39,341,189 | <p>Update your <strong>urls.py file</strong> like below</p>
<pre><code>from django.conf.urls import url
from django.contrib import admin
from hacko import views #importing views from app
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.home, name='home'),
url(r'^index/$', views.index, na... | 3 | 2016-09-06T05:25:36Z | [
"python",
"django"
] |
Numpy reshape issues | 39,341,156 | <pre><code>import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
from sklearn.linear_model import LinearRegression
from sklearn import preprocessing, cross_validation, svm
df = pd.read_csv('table.csv')
print (df.head())
df = df[['Price', 'Asset']]
x = np.array(df.Price)
y = np.array(df.Ass... | 1 | 2016-09-06T05:21:46Z | 39,345,490 | <p>If you only want to reshape an array from size <code>(x, 1)</code> to <code>(1, x)</code> you can use the <code>np.transpose</code> or <code>numpy.ndarray.T</code> function:</p>
<pre><code>x_train = x_train.T
y_train = np.transpose(y_train)
</code></pre>
<p>Both achieve the same result. </p>
<p>Edit: <em>This onl... | 0 | 2016-09-06T09:31:10Z | [
"python",
"numpy"
] |
Running 2 Gunicorn Apps and Nginx with Supervisord | 39,341,226 | <p>This problem has admittedly stumped me for months. I've just procrastinated fixing other bugs and putting this aside until now where it HAS to be fixed --</p>
<p>I am trying to run 2 separate gunicorn apps and start nginx within the same supervisord.conf file. When I start supervisor, I am able to successfully run ... | 1 | 2016-09-06T05:28:46Z | 39,341,380 | <p>This has nothing to do with supervisord. Supervisord is just a way for you to start/stop/restart your server. This has more to do with your server's configuration.</p>
<p>The basic: To serve two gunicorn apps with nginx, you have to run them on two different ports, then config nginx to proxy_pass the request to the... | 2 | 2016-09-06T05:41:54Z | [
"python",
"nginx",
"gunicorn",
"supervisord",
"supervisor"
] |
How to use sqlalchemy core for pagination in Flask? | 39,341,583 | <p>I am using flask framework with <strong>SQLAlchemy core</strong> only. My result set returned from the 'select' statement contains few thousands of records. I would like to use pagination to avoid memory error. How can I get a JSON output using cursor for api GET method, for any page dynamically? I have tried the ac... | 0 | 2016-09-06T05:59:38Z | 39,362,995 | <p>Currently, I have made changes to the above code to work this way:</p>
<pre><code>@app.route('/test/api/v1.0/docs_page2', methods=['POST'])
def search_docs_page2():
if 'id' in session:
docs = []
no_of_pgs = 0
header_dict = dict(request.headers)
for k in header_dict:
p... | 0 | 2016-09-07T06:50:04Z | [
"python",
"pagination",
"sqlalchemy"
] |
Numpy memmap better IO and memory usage | 39,341,636 | <p>Currently I am working with a NumPy memmap array with 2,000,000 * 33 * 33 *4 (N * W * H * C) data. My program reads <strong><em>random (N) indices</em></strong> from this array.</p>
<p>I have 8GB of RAM, 2TB HDD. The HDD read IO is only around 20M/s, RAM usage stays at 2.5GB. It seems that there is a HDD bottleneck... | 0 | 2016-09-06T06:04:08Z | 39,344,643 | <p>(Checking my python 2.7 source)
As far as I can tell NumPy memmap uses mmap.
mmap does define:</p>
<pre><code># Variables with simple values
...
ALLOCATIONGRANULARITY = 65536
PAGESIZE = 4096
</code></pre>
<p>However i am not sure it would be wise (or even possible) to change those.
Furthermore, this may not solve ... | 1 | 2016-09-06T08:51:20Z | [
"python",
"numpy",
"mmap",
"memory-mapped-files"
] |
Centering line scatterplot in plotly | 39,341,673 | <p>I am creating a line scatter plot using plotly python API. There are old and new data plotted in y-axis with the date in the x-axis.I would like to center the graph such that one part of the graph is old data and another half of the graph is new data. How can this be done in plotly?In the attached image, the blue on... | -1 | 2016-09-06T06:07:35Z | 39,341,950 | <p>Building on the manual axes example from the <a href="https://plot.ly/python/axes/" rel="nofollow">Plotly documentation</a>:</p>
<pre><code>import plotly.plotly as py
import plotly.graph_objs as go
xold=[5, 6, 7, 8]
yold=[3, 2, 1, 0]
xnew=[10, 11, 12, 13, 14, 15, 16, 17, 18]
ynew=[0, 1, 2, 3, 4, 5, 6, 7, 8]
oldDa... | 0 | 2016-09-06T06:28:05Z | [
"python",
"graph",
"center",
"scatter-plot",
"plotly"
] |
account.invoice add custom computed & filtered field | 39,341,727 | <p>I'm sorry for my English</p>
<p>I am writing a custom Odoo module and my goal is add a custom computed field in account.invoice with the sum of every tax value stored in tax_line_ids amount field (excluding negative withholdings); this is my code:</p>
<pre><code># -*- coding: utf-8 -*-
from openerp import models, ... | 1 | 2016-09-06T06:11:12Z | 39,344,119 | <pre class="lang-py prettyprint-override"><code>record.x_sum_stored_taxes_exclude_withholding =\
sum(line.amount for line in record.x_sum_stored_taxes_exclude_withholding)
</code></pre>
<p>You should use `tax_line_ids ?</p>
<pre class="lang-py prettyprint-override"><code>record.x_sum_stored_taxes_exclude_withhol... | 0 | 2016-09-06T08:27:08Z | [
"python",
"openerp",
"odoo-8",
"odoo-9"
] |
two charset in one website,how to parse | 39,341,801 | <p>i was study python scraping knowledge recently,and i want to scrap a website</p>
<p><a href="http://news.sina.com.cn/" rel="nofollow">a website with two charset,utf-8 and gb2312</a></p>
<p>i get the warning from beautifulsoup: </p>
<blockquote>
<p>Some characters could not be decoded, and were replaced with REP... | 0 | 2016-09-06T06:16:30Z | 39,341,858 | <p>Detect the page coding before parsing it.</p>
<p>Reference to chardet repo
<a href="https://github.com/chardet/chardet" rel="nofollow">https://github.com/chardet/chardet</a>.</p>
<p>You should't set the code_type as utf-8 for all pages, detect the right encoding of page and modify it to the right one.</p>
<p>Enco... | 0 | 2016-09-06T06:20:58Z | [
"python",
"web-scraping",
"beautifulsoup"
] |
Python to detect latex mathematics using regular expressions or other methods | 39,341,886 | <p>I want to detect if a long text string (input from "somewhere") contains mathematical expressions <a href="https://en.wikibooks.org/wiki/LaTeX/Mathematics" rel="nofollow">encoded in LaTeX</a>. This means searching for substrings (denoted <code>...</code> in what follows) enclosed inside either of:</p>
<ol>
<li><cod... | 0 | 2016-09-06T06:23:04Z | 39,342,081 | <p>You need to escape <code>\</code>,<code>[</code>,<code>]</code>,<code>{</code>,<code>}</code>,<code>(</code>,<code>)</code> as they have special meaning in regular expression. </p>
<p>So, you need to add an extra <code>\</code> before them, when you want to match them literally. </p>
<p>For your second pattern, u... | 0 | 2016-09-06T06:37:07Z | [
"python",
"string-matching"
] |
Django Rest Framework: Filter/Validate Related Fields | 39,341,994 | <p>I have two models: Foo which carries an owner field and Bar which has a relation to Foo:</p>
<pre><code>class Foo(models.Model):
owner = models.ForeignKey('auth.User')
name = models.CharField(max_length=20, null=True)
class Bar(models.Model):
foo = models.OneToOneField(Foo, related_name='bar')
[.... | 2 | 2016-09-06T06:31:04Z | 39,343,567 | <p>You can access the request inside a Serializer if you <a href="http://www.django-rest-framework.org/api-guide/serializers/#including-extra-context" rel="nofollow">include it in its context</a>.
Then you can do <a href="http://www.django-rest-framework.org/api-guide/serializers/#field-level-validation" rel="nofollow"... | 0 | 2016-09-06T07:57:42Z | [
"python",
"django",
"django-rest-framework"
] |
Dynamically created tasks/dags are not working in apache airflow | 39,342,255 | <p>I'm created a DAG with scheduling @daily interval and separate task id for every workflow. But Its is not running as excepted. Is it possible to do like this? Is there any other ways to create dynamic tasks for a particular dag? And to pause a particular task instance using command line?</p>
<pre><code>from __futur... | 0 | 2016-09-06T06:47:34Z | 39,400,952 | <p>The first problem I see is that you're using a dynamic <code>start_date</code>. I've seen some weird behavior when doing that, and I think it's based on the way that airflow maintains its list of past dagruns. Try to specify a fixed <code>start_date</code> and see if that resolves anything.</p>
<p>In either case,... | 0 | 2016-09-08T22:12:23Z | [
"python",
"airflow"
] |
Python while loop does not work properly | 39,342,318 | <p>I am using a <code>while</code> loop inside a <code>if</code> / <code>else</code> condition. For some reason under one condition the while loop does not work. The condition is shown in my code below. Under these conditions I would assume that the <code>else</code> condition should be utilized and the <code>weight</c... | 0 | 2016-09-06T06:50:53Z | 39,342,484 | <p>I think you are confused between <code>or</code> and <code>and</code>.</p>
<p><code>and</code> means that the expression will be <code>True</code> if both condition satisfies. Where <code>or</code> means any condition satisfies.</p>
<p>Now based on your code:</p>
<pre><code>weight = 0
max_speed = 15
if weight ==... | 1 | 2016-09-06T06:58:11Z | [
"python",
"if-statement",
"while-loop"
] |
Python while loop does not work properly | 39,342,318 | <p>I am using a <code>while</code> loop inside a <code>if</code> / <code>else</code> condition. For some reason under one condition the while loop does not work. The condition is shown in my code below. Under these conditions I would assume that the <code>else</code> condition should be utilized and the <code>weight</c... | 0 | 2016-09-06T06:50:53Z | 39,342,546 | <p>Assuming that you need your <code>weight=0</code> and <code>max_speed=10</code>; You can do this -> </p>
<pre><code>weight = 0
max_speed = 15
while weight !=0 or max_speed > 10:
if weight>0:
weight = weight-1
else:
weight = weight+1
if max_speed>10:
max_speed=max_... | 2 | 2016-09-06T07:01:34Z | [
"python",
"if-statement",
"while-loop"
] |
My python threads seem to freeze raspberry pi | 39,342,335 | <p>I wrote this python code to run continuously on my raspberry pi with Raspian by:
' nohup python code.py & '</p>
<p>It works like intended for a while (anything from 5 mins to 60), then seems to freeze my pi (I have not connected a monitor yet, but it kills the remote connection and the green on-LED stops),
The... | 0 | 2016-09-06T06:51:37Z | 39,354,528 | <p>Stupid me! I was using a <strong>powersupply</strong> with a current output at 0.45mA. I changed to 1A and no problems since!</p>
| 1 | 2016-09-06T17:17:27Z | [
"python",
"multithreading",
"raspberry-pi",
"nohup",
"youtube-dl"
] |
Simple 'chat' UDP client and server using Python, can't use `str` as `send()` payload | 39,342,336 | <p>Iam trying to do a simple 'chat' using UDP in python. I have done both client and server code that is, </p>
<h1>client</h1>
<pre><code>import socket
fd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM )
udp_ip = '127.0.0.1'
udp_port = 8014
while(True):
message = input("Client :")
fd.sendto(message, (udp_... | 1 | 2016-09-06T06:51:41Z | 39,342,485 | <blockquote>
<p>How to solve this problem? Is anything wrong there?</p>
</blockquote>
<p>well:</p>
<blockquote>
<pre><code>fd.sendto(reply, client_address)
Type Error: a bytes-like object is required, not 'str'
</code></pre>
</blockquote>
<p>As the error says, you can't directly send a string (Python3 strings are ... | 1 | 2016-09-06T06:58:14Z | [
"python",
"udp"
] |
Pandas select columns using slicing and integer index | 39,342,351 | <p>I am trying to select columns 2 and 4: (column 4 till the end):</p>
<pre><code>df3.iloc[:, [2, 4:]]
</code></pre>
<blockquote>
<p>File "", line 1<br>
df3.iloc[:, [2, 4:]]<br>
___________^<br>
SyntaxError: invalid syntax </p>
</blockquote>
<p>I get an error message obviously. There are many columns after ... | 1 | 2016-09-06T06:52:14Z | 39,342,508 | <p>You can use <code>range</code> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.shape.html" rel="nofollow"><code>shape</code></a>:</p>
<pre><code>df3 = pd.DataFrame({'A':[1,2,3],
'B':[4,5,6],
'C':[7,8,9],
'D':[1,3,5],
... | 2 | 2016-09-06T06:59:23Z | [
"python",
"pandas",
"indexing",
"dataframe",
"slice"
] |
Python: Which will take less memory and execution is fast? | 39,342,382 | <p>I have a ResponseMessageService() class, Which have several methods.
I need only one method.</p>
<p>Then Which is better?</p>
<p>call that method directly? by</p>
<pre><code> ResponseMessageService().WrongRegMsg(data="Your Reg ID is wrong!")
</code></pre>
<p>or take a object </p>
<pre><code> response_mess... | 1 | 2016-09-06T06:53:31Z | 39,342,715 | <p>Regarding your question, </p>
<pre><code>ResponseMessageService().WrongRegMsg(data="Your Reg ID is wrong!")
</code></pre>
<p>would likely to take less memory.</p>
<p>Assigning the instance to a variable makes it retained in the memory, at least until the variable's name is unbound, for example, by using <code>del... | 1 | 2016-09-06T07:13:07Z | [
"python"
] |
How to integrate odoo with elastix | 39,342,483 | <p>I am trying to integrate <strong>Odoo</strong> with <strong>Elastix</strong> . so i downloads all the module from <a href="https://github.com/OCA/connector-telephonyt" rel="nofollow">https://github.com/OCA/connector-telephony</a> . and install asterisk_click2dial, base_phone, crm_phone module , but i don't understan... | 0 | 2016-09-06T06:58:05Z | 39,368,540 | <p>AMI Manager login/password for elastix can be added in /etc/asterisk/manager_custom.conf</p>
<p>Most likly you should read more about AMI interface.</p>
<p>You question is too broad. First of all can recommend read entry-level book for asterisk (for example Asterisk The Future of Telephony), after that study doc f... | 0 | 2016-09-07T11:21:54Z | [
"python",
"openerp",
"asterisk",
"elastix"
] |
Why am I getting the error: OperationalError at /table/ no such table: table_book | 39,342,532 | <p>Whenever I run the program, I get the following error:</p>
<pre><code>OperationalError at /table/
no such table: table_book
</code></pre>
<p>It says that there's an error on line 7 in my template file.</p>
<p>Here is my template.html:</p>
<pre><code><table>
<tr>
<th>author</th>
<t... | -1 | 2016-09-06T07:00:22Z | 39,342,594 | <p>The database table table_book is missing. Did you run makemigrations and migrate ?</p>
| 0 | 2016-09-06T07:04:37Z | [
"python",
"django"
] |
(Python) Issue with linux command unrar, cannot for the life of me figure out why | 39,342,552 | <p>So recently i made a thread here about needing help with a script that should automatically extract <code>.rar</code> files and <code>.zip</code> files for me, without user interaction. With the various help of people i have made this:</p>
<pre><code>import os
import re
from subprocess import check_call
from os.pat... | 0 | 2016-09-06T07:01:58Z | 40,065,661 | <p>The <code>check_call</code> raises the <code>CalledProcessError</code> exception when unrar returns an error code different from zero.</p>
<p>Your error message show this:</p>
<blockquote>
<p>returned non-zero exit status 10</p>
</blockquote>
<p><code>Rar.txt</code> contains the following list of error codes: (... | 0 | 2016-10-16T00:37:09Z | [
"python",
"linux",
"unrar"
] |
Know if child class has implemented a parent method | 39,342,657 | <p>I have a base class class X, and a child class Y which could reimplement or not a method from the base class X.</p>
<p>I pass the name of the child class as a variable to functions. </p>
<p>Inside those functions I need to test if that class passed has implemented or not some methods from it's base class.</p>
<p>... | 0 | 2016-09-06T07:09:23Z | 39,342,800 | <p>use to compare:</p>
<pre><code> getattr(className, 'methodName') is getattr(className, 'method')
</code></pre>
<p>if <code>false</code>, the method was overridden</p>
| 1 | 2016-09-06T07:16:55Z | [
"python",
"python-2.7",
"python-2.x"
] |
Access properties defined with in parentheses | 39,342,740 | <p>I'm using antlr4 with python2 target,</p>
<pre><code>additive_expression returns [value] @init{$value = 0;}
: multiplicative_expression ((PLUS_OPERATOR | MINUS_OPERATOR) multiplicative_expression)*
</code></pre>
<p>Since the <code>((PLUS_OPERATOR | MINUS_OPERATOR) multiplicative_expression)</code> expression app... | 1 | 2016-09-06T07:14:18Z | 39,346,883 | <p>Try something like this:</p>
<pre><code>additive_expression returns [value]
@init{$value = 0;}
: e1=multiplicative_expression {$value = $e1.value;}
( PLUS_OPERATOR e2=multiplicative_expression {$value += $e2.value;}
| MINUS_OPERATOR e2=multiplicative_expression {$value -= $e2.value;}
)*... | 1 | 2016-09-06T10:34:17Z | [
"python",
"antlr",
"antlr4"
] |
How to format the slider value to datetime pattern in the matplotlib figure? | 39,342,833 | <p><a href="http://i.stack.imgur.com/TJgcf.png" rel="nofollow">The figure picture!</a>
Just like the picture, how can i format the number to datetime pattern. For example format 1472860800.0 to 2016-09-03.It can't use the datetime module to format directly. The key point is that it should be formatted in the matplotlib... | 0 | 2016-09-06T07:18:32Z | 39,342,916 | <p>Use <a href="https://docs.python.org/2/library/datetime.html#module-datetime" rel="nofollow">datetime</a> module</p>
<pre><code>>>> from datetime import datetime
>>> datetime.fromtimestamp(1472860800).strftime("%Y-%m-%d")
'2016-09-03'
</code></pre>
| 0 | 2016-09-06T07:23:02Z | [
"python",
"matplotlib"
] |
Running Jupyter kernel and notebook server on different machines | 39,342,838 | <p>I'm trying to run an iPython/ Jupyter kernel and the notebook server on two different Windows machines on a LAN.</p>
<p>From most of the links that I found on the internet, they offer advice on how we can access a remote kernel + server setup from a web browser, but no information on how to separate the kernel and ... | 0 | 2016-09-06T07:18:38Z | 39,394,467 | <p>This can be done, though it is a bit fiddly, and I do not believe that anyone has done it before on Windows. Jupyter applications use a class called a <a href="http://jupyter-client.readthedocs.io/en/latest/api/manager.html#jupyter_client.KernelManager" rel="nofollow">KernelManager</a> to start/stop kernels. Kernel... | 0 | 2016-09-08T15:08:01Z | [
"python",
"ipython",
"jupyter",
"jupyter-notebook"
] |
Running Jupyter kernel and notebook server on different machines | 39,342,838 | <p>I'm trying to run an iPython/ Jupyter kernel and the notebook server on two different Windows machines on a LAN.</p>
<p>From most of the links that I found on the internet, they offer advice on how we can access a remote kernel + server setup from a web browser, but no information on how to separate the kernel and ... | 0 | 2016-09-06T07:18:38Z | 39,739,526 | <p>I ended up using this <a href="https://github.com/jupyter/kernel_gateway_demos/tree/master/nb2kg" rel="nofollow">demo</a> which pretty much did this job for me. </p>
| 0 | 2016-09-28T06:26:50Z | [
"python",
"ipython",
"jupyter",
"jupyter-notebook"
] |
Python Battleship Game, Recursive Malfunction | 39,342,852 | <p>apologies in advance for the data dump. I'm recreating the Battleship game with Python. I'm having trouble with the <code>def battleship</code> function where the computer and user try to guess each other's coordinates. The computer has a <code>e/x</code>probability of guessing the user's coordinates correctly, wher... | 1 | 2016-09-06T07:19:29Z | 39,343,920 | <p>Your <code>if</code> statement means that <code>x</code> isn't calculated on a miss. You will have to add some more logic inside the else statement to work out what <code>x</code> should be. A starting point would be to duplicate the block of code that draws a graph but just keep the lines that modify the value of <... | 1 | 2016-09-06T08:15:33Z | [
"python",
"recursion"
] |
wxpython and multiple plt plots in multiple panels | 39,342,869 | <p>I built a wxpython gui and am trying to plot two different pie charts in two different panels. However it seems that i can only do one at a time (the other one crashes). Hoping someone might know how to handle this. I also want to do the same with bar charts. My code:</p>
<pre><code>self.V_Panel_Pie1 = FigurePa... | 0 | 2016-09-06T07:20:26Z | 39,343,436 | <p>Look at this <a href="http://stackoverflow.com/questions/10737459/embedding-a-matplotlib-figure-inside-a-wxpython-panel">minimal wxPython/matplotlib example</a>. The Key to success is to take fully use of the matplotlib-objectoriented interface instead of the pyplot interface. Avoid all call invoking pyplot.</p>
<p... | 1 | 2016-09-06T07:51:05Z | [
"python",
"matplotlib",
"wxpython",
"pie-chart"
] |
Using property in canvas results in TypeError: unsupported operand type(s) for *: 'int' and 'NoneType' | 39,342,884 | <p>I am trying to implement my own ProgressBar* widget.</p>
<pre><code>from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
kv = """
<MyProgressBar@Widget>:
max: 1
value: 0
limited_value: min(self.value, self.max)
# Filled ratio should never be 0 or 1
... | 1 | 2016-09-06T07:21:28Z | 39,344,107 | <p>Simply defining the properties in python before using them in kv-language fixes the issue: </p>
<pre><code>class MyProgressBar(Widget):
filled_ratio = NumericProperty(0)
empty_ratio = NumericProperty(0)
</code></pre>
<p><sub>(Note: I don't consider this a complete answer since it doesn't explain <em>why</e... | 0 | 2016-09-06T08:26:38Z | [
"python",
"kivy",
"kivy-language"
] |
My numpy is latest but tensroflow says it's old one | 39,342,920 | <pre><code>$pip list
numpy(1.11.1)
</code></pre>
<p>My numpy is latest and I am sure it could be used in python environment.</p>
<pre><code>>>> import numpy
>>> print numpy.__version__
1.11.1
</code></pre>
<p>however I use tensorflow </p>
<pre><code>$ tensorboard --logdir=/tmp/basic_rnn/logdir
</... | 0 | 2016-09-06T07:23:07Z | 39,343,558 | <p>I suspect that the <code>tensorboard</code> command is linked against the wrong Python environment. Make sure that <code>tensorflow</code> uses the same Python interpreter/virtual environment as you checked your numpy installation with. Also check your <code>PATH</code> and <code>PYTHONPATH</code> and take a look at... | 1 | 2016-09-06T07:57:22Z | [
"python",
"tensorflow"
] |
python import * or a list from other level | 39,342,990 | <p>I'm trying to import a few classes from a module in another level. I can type all the classes, but I' trying to do it dynamically</p>
<p>if I do:</p>
<pre><code>from ..previous_level.module import *
raise: SyntaxError: import * only allowed at module level
</code></pre>
<p>the same from myapp folder:</p>
<pr... | 1 | 2016-09-06T07:26:41Z | 39,343,518 | <p>The error <code>SyntaxError: import * only allowed at module level</code> happens if you try to import <code>*</code> from within a function. This is not visible from the question, but it seems that the original code was simething like:</p>
<pre><code>def func():
from ..previous_level.module import * # SyntaxE... | 0 | 2016-09-06T07:55:42Z | [
"python",
"python-3.x"
] |
Python Append String inside list just as an element without double quotes | 39,343,312 | <p>Editing my question so it is little clear:</p>
<p>Problem here is I want to put content of list1 inside List2. I was doing it wrong way as suggested in comments.</p>
<p>I get a list1
value4 = [{'PARAMS': ['ProcessingDate=2016-08-29', 'ReRun=Y']}]</p>
<p>The elements of the PARAMS should be suffixed with '-param'... | -1 | 2016-09-06T07:44:15Z | 39,343,466 | <p>I believe you are confusing putting a <strong>list inside a list</strong> and <strong>concatenating two lists</strong>:</p>
<pre><code>[1, 2, paramlist, 5] # [1, 2, [3, 4], 5]
</code></pre>
<p>is not the same as</p>
<pre><code>[1, 2] + paramlist + [5] # [1, 2, 3, 4, 5]
</code></pre>
<p>Instead of usi... | 5 | 2016-09-06T07:52:54Z | [
"python",
"string",
"list",
"python-3.x"
] |
Python module not importing | 39,343,337 | <p>I am attempting to install a <code>c++ / python</code> based library that offers musical onset detection. Typically, I run <code>sudo pip install foo</code> and <code>cmd+tab</code> over to PyCharm and type <code>import ...</code> and I get auto-completion as I noticed the package resides in <code>Library/Python/2.... | 0 | 2016-09-06T07:45:43Z | 39,343,494 | <p>EDIT: Don't have the rep to comment, yet - therefore I had to write an answer.</p>
<p>Just a wild guess, but do you use a virtual environment? If so, did you <code>pip install</code> the package globally or into your virtualenv? You might also check if pycharm is using the exact version of python where your package... | 0 | 2016-09-06T07:54:16Z | [
"python",
"module",
"cmake",
"packages"
] |
Python Selenium: Unable to click button | 39,343,408 | <p>I'm new to python and want to write a web scraper which involves mouse clicking an "OK" button on a pop-up window. </p>
<p>Everything else went well but I'm not able to click the final button which leads to the data downloading. </p>
<p>The javascript is as follows:</p>
<p><a href="http://i.stack.imgur.com/SYSWp.... | 0 | 2016-09-06T07:49:48Z | 39,343,468 | <p>try this:</p>
<pre><code>browser.find_element_by_id('ctl00_ContentContainer1_ctl00_ButtonsContent_ExportOptionsBottomButtons_OkLabel').click()
</code></pre>
<p>Changed this:</p>
<pre><code>find_elements_by_id
</code></pre>
<p>to this:</p>
<pre><code>find_element_by_id
</code></pre>
| 1 | 2016-09-06T07:53:06Z | [
"javascript",
"python",
"selenium"
] |
Python Selenium: Unable to click button | 39,343,408 | <p>I'm new to python and want to write a web scraper which involves mouse clicking an "OK" button on a pop-up window. </p>
<p>Everything else went well but I'm not able to click the final button which leads to the data downloading. </p>
<p>The javascript is as follows:</p>
<p><a href="http://i.stack.imgur.com/SYSWp.... | 0 | 2016-09-06T07:49:48Z | 39,343,491 | <p><code>find_elements_by_id</code> returns a list of elements. Either iterate over the list that <code>find_elements_by_id</code> returns or use <code>find_element_by_id</code> (notice the missing 's') which will return only a single element (if any).</p>
| 1 | 2016-09-06T07:53:57Z | [
"javascript",
"python",
"selenium"
] |
How to create documentdb account using python in azure? | 39,343,755 | <p>Is any one know how to create document db account programatically for azure? I am aware about creating a database into present document db account.</p>
| 1 | 2016-09-06T08:07:31Z | 39,355,242 | <p>You can create DocumentDB accounts programmatically using Azure Resource Manager templates or the Azure Command-Line Interface (CLI). See <a href="https://azure.microsoft.com/en-us/documentation/articles/documentdb-automation-resource-manager-cli/" rel="nofollow" title="DocumentDB Automation">DocumentDB Automation</... | 0 | 2016-09-06T18:05:49Z | [
"python",
"azure"
] |
How to create documentdb account using python in azure? | 39,343,755 | <p>Is any one know how to create document db account programatically for azure? I am aware about creating a database into present document db account.</p>
| 1 | 2016-09-06T08:07:31Z | 39,468,460 | <p>@Amol Shinde, Trying to use Azure SDK for Python to create documentdb account.</p>
<p>As reference, here is my sample code.</p>
<pre><code>from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
subscription_id = 'xxxx-xxxx-xxx-xxx-xxx'
client_id =... | 0 | 2016-09-13T11:04:12Z | [
"python",
"azure"
] |
Python multi-threading performance issue related to start() | 39,343,894 | <p>I had some performance issues with a multi-threading code to parallelize multiple telnet probes.</p>
<h2>Slow</h2>
<p>My first implementation was is really slow, same a if the tasks were run sequencially:</p>
<pre><code>for printer in printers:
â¦
thread = threading.Thread(target=collect, args=(task, pri... | 2 | 2016-09-06T08:14:27Z | 39,344,036 | <p>In your first implementation you are actually running the code sequentially because by <strong>calling <a href="https://docs.python.org/3/library/threading.html#threading.Thread.join" rel="nofollow"><code>join()</code></a> immediately after <a href="https://docs.python.org/3/library/threading.html#threading.Thread.s... | 4 | 2016-09-06T08:21:49Z | [
"python",
"performance",
"python-3.x",
"telnet",
"python-multithreading"
] |
Python multi-threading performance issue related to start() | 39,343,894 | <p>I had some performance issues with a multi-threading code to parallelize multiple telnet probes.</p>
<h2>Slow</h2>
<p>My first implementation was is really slow, same a if the tasks were run sequencially:</p>
<pre><code>for printer in printers:
â¦
thread = threading.Thread(target=collect, args=(task, pri... | 2 | 2016-09-06T08:14:27Z | 39,344,049 | <p>In your slow solution you are basically not using multithreading at all. Id's running a thread, waiting to finish it and then running another - there is no difference in running everything in one thread and this solution - you are running them in series.</p>
<p>The second one on the other hand starts all threads an... | 0 | 2016-09-06T08:22:31Z | [
"python",
"performance",
"python-3.x",
"telnet",
"python-multithreading"
] |
Python multi-threading performance issue related to start() | 39,343,894 | <p>I had some performance issues with a multi-threading code to parallelize multiple telnet probes.</p>
<h2>Slow</h2>
<p>My first implementation was is really slow, same a if the tasks were run sequencially:</p>
<pre><code>for printer in printers:
â¦
thread = threading.Thread(target=collect, args=(task, pri... | 2 | 2016-09-06T08:14:27Z | 39,344,065 | <p>thread.join() is blocking every thread as soon as they are created in your first implementation.</p>
| 0 | 2016-09-06T08:23:20Z | [
"python",
"performance",
"python-3.x",
"telnet",
"python-multithreading"
] |
Python multi-threading performance issue related to start() | 39,343,894 | <p>I had some performance issues with a multi-threading code to parallelize multiple telnet probes.</p>
<h2>Slow</h2>
<p>My first implementation was is really slow, same a if the tasks were run sequencially:</p>
<pre><code>for printer in printers:
â¦
thread = threading.Thread(target=collect, args=(task, pri... | 2 | 2016-09-06T08:14:27Z | 39,344,160 | <p>According to <a href="https://docs.python.org/3/library/threading.html#threading.Thread.join" rel="nofollow">threading.Thread.join()</a> documentation:</p>
<blockquote>
<p>Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is called terminates -- either normall... | 1 | 2016-09-06T08:28:57Z | [
"python",
"performance",
"python-3.x",
"telnet",
"python-multithreading"
] |
How to simulate the process of login using scrapy, when the information might be tranferred by ajax? | 39,343,916 | <p>I'm doing some crawling jobs on <a href="http://www.asianmetal.cn/" rel="nofollow">http://www.asianmetal.cn/</a>.
But I fail to login using a simple FormRequest like this:</p>
<pre><code>def start_requests(self):
url = 'http://www.asianmetal.cn/login/ajaxLogin.am'
fake_header = httputils.random_headers()
... | 0 | 2016-09-06T08:15:31Z | 39,347,246 | <p>You are probably missing some headers. I've tried gibberish log in and these are the headers that were sent:</p>
<p><a href="http://i.stack.imgur.com/tdrkB.png" rel="nofollow"><img src="http://i.stack.imgur.com/tdrkB.png" alt="enter image description here"></a></p>
<p>The only important here is probably <code>X-Re... | 0 | 2016-09-06T10:52:33Z | [
"python",
"ajax",
"scrapy"
] |
Modify a python code to solve a sequence of linear programs where a lower bound of a variable is being incremented by 1 | 39,343,950 | <p>Using Gurobi and Python I could optimally solve a linear problem for a given situation. However, when I am given a range in which a lower bound for one of the variable can increase in an increment of 1, I could not figure how to write the right syntax (for loop, while, or other), I think I am missing alot so to spea... | -1 | 2016-09-06T08:17:22Z | 39,714,245 | <p>First, define a class that acts as a wrapper for a Gurobi model. It should take a lower bound as an argument which you'll use when defining your variable.</p>
<pre><code>class GurobiModel:
def __init__(self, lowerBound):
# create an empty Gurobi model object
self.model = Model()
# add... | 0 | 2016-09-27T00:18:23Z | [
"python",
"gurobi"
] |
Python: Cast SwigPythonObject to Python Object | 39,344,039 | <p>I'm using some closed Python module: I can call methods via API, but I cannot access the implementation. I know this module is basically wraps some C++ code. </p>
<p>So one of the methods return value type is a <code>SwigPythonObject</code>. How can I work with this object later, suppose I don't have any other aids... | 0 | 2016-09-06T08:22:12Z | 39,357,579 | <p>It's a little unclear the semantics of what you're asking, but basically it seems as though you've got a pointer to an <code>unsigned char</code> from SWIG that you'd like to work with. Guessing slightly there are probably 3 cases you're likely to encounter this in:</p>
<ol>
<li>The pointer really is a pointer to a... | 1 | 2016-09-06T20:47:08Z | [
"python",
"swig"
] |
Date range issue in pandas python | 39,344,040 | <p>I tried this: </p>
<pre><code>pd.date_range(2000, periods = 365, freq = 'D',format = '%d-%m-%Y')
</code></pre>
<p>why I am getting this result:</p>
<pre><code>DatetimeIndex(['1970-01-01 00:00:00.000002', '1970-01-02 00:00:00.000002',
'1970-01-03 00:00:00.000002', '1970-01-04 00:00:00.000002',
... | 2 | 2016-09-06T08:22:17Z | 39,344,087 | <p>Try this</p>
<pre><code>pd.date_range('1/1/2000', periods = 365, freq = 'D',format = '%d-%m-%Y')
</code></pre>
| 1 | 2016-09-06T08:25:05Z | [
"python",
"date",
"pandas",
"date-range",
"datetimeindex"
] |
Date range issue in pandas python | 39,344,040 | <p>I tried this: </p>
<pre><code>pd.date_range(2000, periods = 365, freq = 'D',format = '%d-%m-%Y')
</code></pre>
<p>why I am getting this result:</p>
<pre><code>DatetimeIndex(['1970-01-01 00:00:00.000002', '1970-01-02 00:00:00.000002',
'1970-01-03 00:00:00.000002', '1970-01-04 00:00:00.000002',
... | 2 | 2016-09-06T08:22:17Z | 39,344,091 | <p>You need add <code>''</code> to <code>2000</code> only:</p>
<pre><code>print (pd.date_range('2000', periods = 365, freq = 'D'))
DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-03', '2000-01-04',
'2000-01-05', '2000-01-06', '2000-01-07', '2000-01-08',
'2000-01-09', '2000-01-10',
... | 2 | 2016-09-06T08:25:37Z | [
"python",
"date",
"pandas",
"date-range",
"datetimeindex"
] |
How to change variable value in other module? | 39,344,105 | <p>I have the following modules:</p>
<p><strong>test.py</strong></p>
<pre><code>import test1
var1 = 'Test1'
var2 = 'Test2'
print var1
print var2
test1.modify_vars(var1, var2)
print var1
print var2
</code></pre>
<p>and the module </p>
<p><strong>test1.py</strong></p>
<pre><code>def modify_vars(var1, var2):
... | 0 | 2016-09-06T08:26:35Z | 39,344,141 | <p>Strings are immutable. You cannot do what you want. Using <code>+=</code> with a string will always return a new string, which will have nothing to do with whatever <code>var1</code> and <code>var2</code> are assigned to.</p>
<p>The only way to achieve something close to what you want (and, to be honest, you should... | 3 | 2016-09-06T08:27:58Z | [
"python"
] |
How to change variable value in other module? | 39,344,105 | <p>I have the following modules:</p>
<p><strong>test.py</strong></p>
<pre><code>import test1
var1 = 'Test1'
var2 = 'Test2'
print var1
print var2
test1.modify_vars(var1, var2)
print var1
print var2
</code></pre>
<p>and the module </p>
<p><strong>test1.py</strong></p>
<pre><code>def modify_vars(var1, var2):
... | 0 | 2016-09-06T08:26:35Z | 39,344,727 | <p>Your function misses a return value</p>
<pre><code>var1 = 'Test1'
var2 = 'Test2'
def modify_var(var1, var2):
var1 += '_changed'
var2 += '_changed'
return (var1,var2)
(var1,var2) = modify_var(var1,var2)
print var1,var2
</code></pre>
<p>Does work. </p>
<p>I believe this requires minimal change to you... | -1 | 2016-09-06T08:55:27Z | [
"python"
] |
Grouped boxplot with seaborn | 39,344,167 | <p>I have following data in python panda DataFrame. I would like to have grouped box plot similar to one in <a href="https://stanford.edu/~mwaskom/software/seaborn/examples/grouped_boxplot.html" rel="nofollow">https://stanford.edu/~mwaskom/software/seaborn/examples/grouped_boxplot.html</a></p>
<p>For each id, I would ... | 1 | 2016-09-06T08:29:10Z | 39,344,866 | <p>Notice the table structure in the example you are looking at</p>
<pre><code>import seaborn as sns
tips = sns.load_dataset("tips")
sns.boxplot(x="day", y="total_bill", hue="sex", data=tips, palette="PRGn")
sns.despine(offset=10, trim=True)
</code></pre>
<p><a href="http://i.stack.imgur.com/Y1DJO.png" rel="nofollow... | 2 | 2016-09-06T09:02:23Z | [
"python",
"pandas",
"seaborn"
] |
Is raising exceptions safe within 'before' callback of a transitions.Machine model? | 39,344,177 | <p>I am using the <a href="https://github.com/tyarkoni/transitions" rel="nofollow">transitions</a> FSM library. Imagine having an application FSM using the following code:</p>
<pre><code>from transitions import Machine
import os
class Application(object):
states = ["idle", "data_loaded"]
def __init__(self):
... | 0 | 2016-09-06T08:29:37Z | 39,369,707 | <blockquote>
<p>However, I wonder whether the internal state of the machine instance might get corrupted.</p>
</blockquote>
<p>It is fine to work with raising Exceptions in callback functions unless you plan to use the <code>queued</code> feature of transitions.</p>
<p>Transitions are executed in the following orde... | 1 | 2016-09-07T12:15:02Z | [
"python",
"transitions",
"fsm"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.