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 |
|---|---|---|---|---|---|---|---|---|---|
Trying to update position of lines in Tkinter based off of text file | 40,034,044 | <p>I am creating a Tkinter program that creates a canvas that shows a vehicles position according to an angle that is saved to a text file. The problem that I have is that the program only reads the text file when it starts and doesn't continue checking. I know that it should be fairly simple but I have looked at many ... | 0 | 2016-10-14T02:36:27Z | 40,037,206 | <p>Use <code>root.after(miliseconds, function_name)</code> to run periodically function which will read file again and move line on canvas. </p>
<p>In code I create line only once (before vehicle) and later I change only line position.</p>
<pre><code>from Tkinter import *
import math
import time
w = 800
h = 480
# -... | 0 | 2016-10-14T07:19:13Z | [
"python",
"tkinter",
"tkinter-canvas"
] |
How do I resolve issues when everything in my mac messed up? | 40,034,048 | <p>my command line tools is set up by homebrew + pip. However, I installed macport trying to get some software but then turns out everything is messed up even after I removed macport... How could I re-set up my Mac for scientific computations including all the necessary command line tools (like vi, bash, they all have ... | 1 | 2016-10-14T02:37:01Z | 40,034,231 | <p>This isn't a python question...</p>
<p>For future reference, just use the anaconda distribution of python. Don't bother with homebrew or macports. You'll never have to mess with this</p>
| 0 | 2016-10-14T03:00:13Z | [
"python",
"bash",
"osx"
] |
How do I resolve issues when everything in my mac messed up? | 40,034,048 | <p>my command line tools is set up by homebrew + pip. However, I installed macport trying to get some software but then turns out everything is messed up even after I removed macport... How could I re-set up my Mac for scientific computations including all the necessary command line tools (like vi, bash, they all have ... | 1 | 2016-10-14T02:37:01Z | 40,034,697 | <p>Try this.</p>
<pre><code>brew update
brew upgrade
brew cleanup
brew unlinkapps
brew linkapps
</code></pre>
<p>Also there is</p>
<pre><code>brew doctor
</code></pre>
<p>Which shows if there are some problems/confilicts</p>
| 2 | 2016-10-14T03:56:31Z | [
"python",
"bash",
"osx"
] |
Python setattr() not assigning value to class member | 40,034,054 | <p>I'm trying to set up a simple test example of <code>setattr()</code> in Python, but it fails to assign a new value to the member. </p>
<pre><code>class Foo(object):
__bar = 0
def modify_bar(self):
print(self.__bar)
setattr(self, "__bar", 1)
print(self.__bar)
</code></pre>
<p>Here I ... | 0 | 2016-10-14T02:37:24Z | 40,034,125 | <p>A leading double underscore invokes python <a href="https://docs.python.org/2/tutorial/classes.html#private-variables-and-class-local-references" rel="nofollow">name-mangling</a>.</p>
<p>So:</p>
<pre><code>class Foo(object):
__bar = 0 # actually `_Foo__bar`
def modify_bar(self):
print(self.__bar) ... | 0 | 2016-10-14T02:46:09Z | [
"python",
"reflection",
"setattr"
] |
New Coder simple time clock | 40,034,159 | <p>I need help trying to solve this problem in python</p>
<p>You must write a program asking for the current time <code>(hours only)</code> and an amount of hours in the future. Use the modulo <code>%</code> operator to tell the time traveler the future hour to which they will be traveling.</p>
<p>the tricky part for... | -2 | 2016-10-14T02:52:13Z | 40,036,042 | <p>It seems like you're making your code more complicated than necessary:</p>
<pre><code># TODO 1: Ask for user input
hour = int(input("What time is it? "))
time_traveled = int(input("How many hours would you like to travel? "))
#TODO 2: Calculate the future hour
future_hour = (hour + time_traveled) % 24
print("You ... | 0 | 2016-10-14T06:07:52Z | [
"python"
] |
AWS SDK for Python - Boto - KeyPair Creation Confusion | 40,034,228 | <p>I am trying to create a EC2 key-pair using the create_key_pair() method, something like:</p>
<pre><code>key_name = 'BlockChainEC2InstanceKeyPair-1'
def create_new_key_pair(key_name):
newKey = objEC2.create_key_pair(key_name)
newKey.save(dir_to_save_new_key)
</code></pre>
<p>The keys are created as I ca... | 0 | 2016-10-14T02:59:50Z | 40,035,301 | <p>The <code>keypairs</code> are for each region. I suspect you are creating the keypair in one region using boto and you are checking for the keypair in a different region in your AWS console.</p>
<p>Make sure you default region in boto ( .aws/config ) and check your AWS dashboard is in the same region. If not change... | 1 | 2016-10-14T05:07:36Z | [
"python",
"amazon-web-services",
"amazon-ec2",
"boto"
] |
How to replace a dot with a string in a python list | 40,034,246 | <pre><code>my_list = ['b','.','.']
expected_list = ['b','.','w']
</code></pre>
<p>May be simple, moving into python recently so any suggestions would be fine</p>
| -1 | 2016-10-14T03:01:40Z | 40,034,640 | <p>If you are replacing every occurrence of '.' with 'w' then I would just suggest:</p>
<pre><code>for n, i in enumerate(my_list):
if i == '.':
my_list[n] = 'w'
</code></pre>
<p>Here is the documentation for how to use the enumerate() function: <a href="https://docs.python.org/2/library/functions.html#enu... | 0 | 2016-10-14T03:49:49Z | [
"python",
"python-2.7"
] |
How to replace a dot with a string in a python list | 40,034,246 | <pre><code>my_list = ['b','.','.']
expected_list = ['b','.','w']
</code></pre>
<p>May be simple, moving into python recently so any suggestions would be fine</p>
| -1 | 2016-10-14T03:01:40Z | 40,034,794 | <blockquote>
<p>You can do this by using list comprehension also</p>
</blockquote>
<pre><code>l = ['w' if i == '.' else i for i in my_list]
</code></pre>
| 1 | 2016-10-14T04:10:54Z | [
"python",
"python-2.7"
] |
Using data from one file to create two appended lists to a new file | 40,034,275 | <p>I am trying to take data from one file and create two lists which are both written to a new file. One of the lists contains names 6 characters or less and the second list contains a list with names that do not contain "a" or "e." I have the code done that will form both lists, I have tried them both separately and t... | 0 | 2016-10-14T03:05:22Z | 40,034,529 | <p>If I understand your qn correctly</p>
<pre><code>import re
l1 = []
l2 = []
lists = open('test.txt','w')
with open('words.txt') as f:
for line in f.read().split('\n'):
if len(line) <= 6:
l1.append(line)
if not re.search(r'a|e', line):
l2.append(line)
lists.write('\n'.... | 0 | 2016-10-14T03:36:12Z | [
"python",
"list",
"file",
"boolean",
"append"
] |
Django Allauth and urls | 40,034,300 | <p>I have a dev environment for a test of Django. I am running Python 3.5.2 out of a "local" <code>pyenv</code> install. I have Django 1.10.2. I discovered the <code>allauth</code> registration plugin yesterday and have been playing with it but have hit a snag.</p>
<p>My site is "dev.my.domain.com". The intent is ... | 1 | 2016-10-14T03:08:04Z | 40,036,524 | <p>In your <em>view.py</em> file, you just need to do a little "filter" before giving away the page to see if the user is authenticated.</p>
<p>An example for this will be:</p>
<pre><code>def myview(request):
if request.user.is_authenticated():
# do something if the user is authenticated, like showing a ... | 0 | 2016-10-14T06:40:08Z | [
"python",
"django",
"django-allauth"
] |
Using compression library to estimate information complexity of an english sentence? | 40,034,334 | <p>I'm trying to write an algorithm that can work out the 'unexpectedness' or 'information complexity' of a sentence. More specifically I'm trying to sort a set of sentences so the least complex come first. </p>
<p>My thought was that I could use a compression library, like zlib?, 'pre train' it on a large corpus of t... | 0 | 2016-10-14T03:12:02Z | 40,046,686 | <p>All this is going to do is tell you whether the words in the sentence, and maybe phrases in the sentence, are in the dictionary you supplied. I don't see how that's complexity. More like grade level. And there are better tools for that. Anyway, I'll answer your question.</p>
<p>Yes, you can preset the zlib compress... | 1 | 2016-10-14T15:20:27Z | [
"python",
"scala",
"compression",
"information-theory"
] |
Logarithm of a pandas series/dataframe | 40,034,378 | <p>In short: How can I get a logarithm of a column of a pandas dataframe?
I thought <code>numpy.log()</code> should work on it, but it isn't. I suspect it's because I have some <code>NaN</code>s in the dataframe?</p>
<p>My whole code is below. It may seem a bit chaotic, basically my ultimate goal (a little exaggerated... | 0 | 2016-10-14T03:16:32Z | 40,034,471 | <p>The problem isn't that you have <code>NaN</code> values, it's that you <em>don't</em> have <code>NaN</code> values, you have <strong>strings</strong> <code>"NaN"</code> which the <code>ufunc</code> np.log doesn't know how to deal with. Replace the beginning of your code with:</p>
<pre><code>hf = pd.DataFrame({'Z':n... | 4 | 2016-10-14T03:28:42Z | [
"python",
"pandas",
"numpy",
"matplotlib"
] |
Requiring tensorflow with Python 2.7.11 occurs ImportError | 40,034,570 | <p>I tried <code>pip install tensorflow</code> on OS X El Capitan and it succeeded.
However, if I tried to import tensorflow, ImportError occured.
Please tell me when you know.</p>
<pre><code>>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lo... | 4 | 2016-10-14T03:40:57Z | 40,039,137 | <p>I got the same question.
Try to follow the [official instruction] to install tensorflow: <a href="https://www.tensorflow.org/versions/r0.11/get_started/os_setup.html#pip-installation" rel="nofollow">https://www.tensorflow.org/versions/r0.11/get_started/os_setup.html#pip-installation</a></p>
<pre><code># Mac OS X
$ ... | 3 | 2016-10-14T09:02:27Z | [
"python",
"python-2.7",
"tensorflow"
] |
fast interpolation of a (50000,3000) numpy array along axis=-1 | 40,034,623 | <p>I have a 2D array of seismic data of shape (50000, 3000)</p>
<p>I need to 1d interpolate everything in axis=-1</p>
<p>If z=values, t0=value times, tx= new times, I'm currently doing </p>
<pre><code>for i in range(dataset.size):
result[i,:] = np.interp(tx[i,:], t0[i,:], z[i,:])
</code></pre>
<p>not surprisin... | 0 | 2016-10-14T03:47:50Z | 40,034,879 | <p>Depends on what you're trying to achieve. You can use array slicing to interpolate just a small subset of your data, if you know where the interesting region is. Or you may want to see the big picture by using statistical metrics.</p>
<p>I don't think there is a way to significantly speed up the <code>np.interp()</... | 0 | 2016-10-14T04:22:01Z | [
"python",
"numpy",
"scipy"
] |
Error trying to add +1 to value returned from list | 40,034,655 | <p>I have a list of lists I am trying to use as a matrix. In the last line of code when I add '+ 1' to the first argument in the min() function I get an error 'TypeError: can only concatenate list (not "int") to list'. Can someone help me with the correct way to add one to the value I am calling from the list to comp... | -1 | 2016-10-14T03:51:20Z | 40,034,775 | <p>Probably, you should replace:</p>
<pre><code>matrix[j].append([i])
</code></pre>
<p>with</p>
<pre><code>matrix[j].append(i)
</code></pre>
<p>You want to append integers to list, one matrix row to be:</p>
<pre><code>[0, 1, 2, 3, ...]
</code></pre>
<p>While you append lists to the list, which creates a row in th... | 0 | 2016-10-14T04:06:46Z | [
"python",
"list",
"python-3.x"
] |
Using urllib2 to download text to be used to evaluate a variable | 40,034,696 | <p>Am downloading a text page, c.txt, from a webserver. c.txt only contains the letter 'c' . Able to download file fine and print its contents, the character 'c'. Cannot, however, use its contents in the code below:</p>
<pre><code>import urllib2
req = urllib2.Request('http://localhost/c.txt')
response = urllib2.ur... | 0 | 2016-10-14T03:56:30Z | 40,034,971 | <p>There is most likely an extra white space character in the <code>result</code>. You can check for it by printing characters on either side.</p>
<pre><code>print '>%s<' % result
</code></pre>
<p>If the result looks like <code>>c <</code> you've got a trailing white space (including newline characters).<... | 1 | 2016-10-14T04:32:54Z | [
"python",
"urllib2"
] |
Can't load Boost.Python module - undefined symbols | 40,034,745 | <p>I have a library that I wrote in C and need to access from Python, so I wrapped it using Boost.Python. I can compile my library into a Boost .so file with no problems, but when I try to load it into Python (with <code>import tropmodboost</code>), I get the following error:</p>
<pre><code>ImportError: ./tropmodboost... | 0 | 2016-10-14T04:03:36Z | 40,048,144 | <p>After running <code>nm</code> on a few of my object files, I found that in the undefined symbol <code>_Z12simplex_freeP7simplex</code> was defined in simplex.o as just <code>simplex_free</code>, presumably because it was compiled from simplex.c using gcc. In other words, I think gcc and g++ were naming things differ... | 0 | 2016-10-14T16:42:49Z | [
"python",
"c++",
"python-2.7",
"linker",
"boost-python"
] |
Converting to a for loop | 40,034,749 | <p>I'm curious as to how this can be rewritten as a for loop? </p>
<pre><code>def decode (lst):
i=0
result=[]
while i<len(lst):
result+=([lst[i]]*lst[i+1])
i+=2
return(result)
print(decode([4,6,2,1,9,5,5,2,4,2]))
</code></pre>
| -2 | 2016-10-14T04:04:05Z | 40,034,856 | <p>Loop would look like:</p>
<pre><code>for x in range(0, len(lst), 2):
result+=(lst[i]*lst[i+1])
</code></pre>
<p>You may also use <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk" rel="nofollow">list comprehension</a> and simplify this.</p>
<p>Refer: <a href="https://wiki.python.org/moin/Fo... | 0 | 2016-10-14T04:18:50Z | [
"python",
"loops",
"for-loop",
"while-loop"
] |
Converting to a for loop | 40,034,749 | <p>I'm curious as to how this can be rewritten as a for loop? </p>
<pre><code>def decode (lst):
i=0
result=[]
while i<len(lst):
result+=([lst[i]]*lst[i+1])
i+=2
return(result)
print(decode([4,6,2,1,9,5,5,2,4,2]))
</code></pre>
| -2 | 2016-10-14T04:04:05Z | 40,034,861 | <p>Assuming that this is Python code (as it looks like) you can just specify the step in the range function.</p>
<pre><code>def decode (lst):
result = []
#More common syntax if not using python for(i = 0; i < len(lst); i += 2):
for i in range(0, len(lst), 2):
result += ([lst[i]] * lst[i+1])
... | 0 | 2016-10-14T04:19:42Z | [
"python",
"loops",
"for-loop",
"while-loop"
] |
django - How to customise Model save method when a specified field is changed | 40,034,780 | <p>I have a model, let's save A, the definition is as below:</p>
<pre><code>class A(models.Model):
name = models.CharField('name', max_length=10)
enabled = models.BooleanField('enabled', default=False)
field1 = models.CharField('field1', max_length=10)
field2 = models.CharField('field2', max_length=10)
... | 0 | 2016-10-14T04:08:10Z | 40,034,868 | <p>In short â no. But you can do it manually overloading the save method.</p>
<pre><code>class B(models.Model):
...
def save(self, *args, **kwargs):
if self.pk is not None:
original = B.objects.get(pk=self.pk)
if original.enabled != self.enabled:
C.enabled = ... | 1 | 2016-10-14T04:20:38Z | [
"python",
"django",
"save"
] |
django - How to customise Model save method when a specified field is changed | 40,034,780 | <p>I have a model, let's save A, the definition is as below:</p>
<pre><code>class A(models.Model):
name = models.CharField('name', max_length=10)
enabled = models.BooleanField('enabled', default=False)
field1 = models.CharField('field1', max_length=10)
field2 = models.CharField('field2', max_length=10)
... | 0 | 2016-10-14T04:08:10Z | 40,035,144 | <p>The best way to do this is using django signals <a href="https://docs.djangoproject.com/es/1.10/ref/signals/" rel="nofollow">https://docs.djangoproject.com/es/1.10/ref/signals/</a></p>
<p>You will call the method change_status when your model call the method <code>save()</code></p>
<pre><code>from django.db.models... | 1 | 2016-10-14T04:52:14Z | [
"python",
"django",
"save"
] |
Convert strings of assignments to dicts in Python | 40,034,846 | <p>I have the following strings - they are assignment commands:</p>
<pre><code>lnodenum = 134241
d1 = 0.200000
jobname = 'hcalfzp'
</code></pre>
<p>Is there a way to convert this string, containing variables and values, to keys and values of a dictionary? It'd be equivalent to executing the below command:</p>
<pre><... | 0 | 2016-10-14T04:17:41Z | 40,034,883 | <p>There's no need for <code>exec</code>. Just use a regular assignment with the <code>dict</code> function.</p>
<pre><code>my_str = """lnodenum = 134241
d1 = 0.200000
jobname = 'hcalfzp' """
my_dict = dict(pair for pair in (line.strip().split(' = ') for line in my_str.splitlines()))
</code></p... | 2 | 2016-10-14T04:22:37Z | [
"python",
"dictionary"
] |
Heroku Django Migrate Not Working | 40,034,892 | <p>I am in my way learning python with django, and when I tried to sync with Heroku, there's an error showing I haven't migrated them yet. I am pretty sure have done it, but the console still saying so.</p>
<p>Iam sure I left an obvious part. But still can't find which one.</p>
<p><a href="https://i.stack.imgur.com/Q... | 0 | 2016-10-14T04:24:02Z | 40,037,028 | <p>You cannot use sqlite on Heroku. You must use the postgres add-on.</p>
<p>Sqlite stores its db on the filesystem, but on Heroku the filesystem is ephemeral and not shared between dynos. Running a command spins up a whole new dyno, with its own database file which is migrated, but then thrown away. The next command... | 0 | 2016-10-14T07:08:50Z | [
"python",
"django",
"heroku"
] |
How to make replacement in python's dict? | 40,034,950 | <p>The goal I want to achieve is to exchange all items whose form is <code>#item_name#</code> to the from <code>(item_value)</code> in the dict. I use two <code>dict</code> named <code>test1</code> and <code>test2</code> to test my function. Here is the code:</p>
<pre><code>test1={'integer_set': '{#integer_list#?}', '... | 3 | 2016-10-14T04:30:43Z | 40,035,729 | <p>Your problem is caused by the fact that python dictionaries are unordered. Try using a <a href="https://docs.python.org/2/library/collections.html#collections.OrderedDict" rel="nofollow">OrderedDict</a> instead of <code>dict</code> and you should be fine. The OrderedDict works just like a normal <code>dict</code> bu... | 0 | 2016-10-14T05:44:19Z | [
"python",
"dictionary"
] |
How to make replacement in python's dict? | 40,034,950 | <p>The goal I want to achieve is to exchange all items whose form is <code>#item_name#</code> to the from <code>(item_value)</code> in the dict. I use two <code>dict</code> named <code>test1</code> and <code>test2</code> to test my function. Here is the code:</p>
<pre><code>test1={'integer_set': '{#integer_list#?}', '... | 3 | 2016-10-14T04:30:43Z | 40,035,870 | <p>Try this one. Your problem is due to mutating starting dict. You need to change its copy.</p>
<pre><code>test1={'integer_set': '{#integer_list#?}', 'integer_list': '#integer_range#(?,#integer_range#)*', 'integer_range': '#integer#(..#integer#)?', 'integer': '[+-]?\\d+'}
test2={'b': '#a#', 'f': '#e#', 'c': '#b#', 'e... | 0 | 2016-10-14T05:55:36Z | [
"python",
"dictionary"
] |
Python: How to fix an [errno 2] when trying to open a text file? | 40,034,968 | <p>I'm trying to learn Python in my free time, and my textbook is not covering anything about my error, so I must've messed up badly somewhere. When I try to open and read a text file through notepad (on Windows) with my code, it produces the error. My code is:</p>
<pre><code>def getText():
infile = open("C:/Users... | 0 | 2016-10-14T04:32:28Z | 40,035,260 | <p>To open a unicode file, you can do the following</p>
<pre><code>import codecs
def getText():
with codecs.open("C:/Users/****/AppData/Local/Programs/Python/Python35-32/lib/book.txt" , "r", encoding='utf8') as infile:
allText = infile.read()
return allText
</code></pre>
<p>See also: <a href="http:/... | 1 | 2016-10-14T05:03:02Z | [
"python",
"error-handling"
] |
Python: How to fix an [errno 2] when trying to open a text file? | 40,034,968 | <p>I'm trying to learn Python in my free time, and my textbook is not covering anything about my error, so I must've messed up badly somewhere. When I try to open and read a text file through notepad (on Windows) with my code, it produces the error. My code is:</p>
<pre><code>def getText():
infile = open("C:/Users... | 0 | 2016-10-14T04:32:28Z | 40,035,396 | <p>First of all, I recommend you to use relative path, not absolute path. It is simpler and will make your life easier especially now that you just started to learn Python. If you know how to deal with commandline, run a new commandline and move to the directory where your source code is located. Make a new text file t... | 0 | 2016-10-14T05:16:20Z | [
"python",
"error-handling"
] |
How to get element-wise matrix multiplication (Hadamard product) in numpy? | 40,034,993 | <p>I have two matrices </p>
<pre><code>a = [[1,2][3,4]]
b = [[5,6][7,8]]
</code></pre>
<p>I want to get the element-wise prodcut which will be <code>[[1*5,2*6][3*7,4*8]]</code> equals to </p>
<p><code>[[5,12][21,32]]</code></p>
<p>I tried with numpy </p>
<pre><code>print(np.dot(x,y))
</code></pre>
<p>and</p>
<p... | 0 | 2016-10-14T04:35:47Z | 40,035,077 | <p>just do this:</p>
<pre><code>import numpy as np
a = np.array([[1,2],[3,4]])
b = np.array([[5,6],[7,8]])
a * b
</code></pre>
| 3 | 2016-10-14T04:44:22Z | [
"python",
"numpy",
"matrix",
"matrix-multiplication",
"elementwise-operations"
] |
How to get element-wise matrix multiplication (Hadamard product) in numpy? | 40,034,993 | <p>I have two matrices </p>
<pre><code>a = [[1,2][3,4]]
b = [[5,6][7,8]]
</code></pre>
<p>I want to get the element-wise prodcut which will be <code>[[1*5,2*6][3*7,4*8]]</code> equals to </p>
<p><code>[[5,12][21,32]]</code></p>
<p>I tried with numpy </p>
<pre><code>print(np.dot(x,y))
</code></pre>
<p>and</p>
<p... | 0 | 2016-10-14T04:35:47Z | 40,035,266 | <p>Try this,</p>
<pre><code>import numpy as np
a = np.array([[1,2],[3,4]])
b = np.array([[5,6],[7,8]])
np.multiply(a,b)
</code></pre>
<p><strong>Result</strong> </p>
<pre><code>array([[ 5, 12],
[21, 32]])
</code></pre>
| 3 | 2016-10-14T05:04:28Z | [
"python",
"numpy",
"matrix",
"matrix-multiplication",
"elementwise-operations"
] |
Finding string in the format of TEXT-###, e.g SFS-444 inside of another string | 40,035,002 | <p>Pretty much as the statement states, I'm trying to figure out how to find text that follows this format TEXT-### inside of another string. However, there may be a lot of words or multiple numbers, such as,</p>
<pre><code>FRS-44215
SLMP-44
AG-1
</code></pre>
<p>So for example I have this text.</p>
<pre><code>"Lore... | 0 | 2016-10-14T04:37:04Z | 40,035,060 | <p>Use a regular expression to define the pattern that you are looking for, and then search the string for it.</p>
<pre><code>>>> s = '''"Lorem ipsum dolor sit amet, adversarium suscipiantur
... has ea, duo at alia assum, eu ius hinc
... aliquip percipitur SGF-7852 Nec ne
... nisl duis volutpat"'''
>>... | 1 | 2016-10-14T04:43:06Z | [
"python",
"string",
"subset"
] |
Unintended Notched Boxplot from Matplotlib, Error from Seaborn | 40,035,048 | <p>Using sklearn, and tried to do a boxplot using matplotlib. </p>
<pre><code>nps = np.array(all_s)
npd = [dd for dd in all_d]
plt.boxplot(nps.T, npd)
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/X6RoK.png" rel="nofollow"><img src="https://i.stack.imgur.com/X6RoK.png" alt="enter image description he... | 0 | 2016-10-14T04:41:22Z | 40,035,132 | <p>The second argument to <code>boxplot</code> is <code>notch</code>. By passing a nonempty list, you're passing a true value, so notches are shown. I'm not sure what your intent is with passing <code>npd</code> there.</p>
| 2 | 2016-10-14T04:50:25Z | [
"python",
"matplotlib",
"machine-learning",
"scikit-learn",
"seaborn"
] |
Unintended Notched Boxplot from Matplotlib, Error from Seaborn | 40,035,048 | <p>Using sklearn, and tried to do a boxplot using matplotlib. </p>
<pre><code>nps = np.array(all_s)
npd = [dd for dd in all_d]
plt.boxplot(nps.T, npd)
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/X6RoK.png" rel="nofollow"><img src="https://i.stack.imgur.com/X6RoK.png" alt="enter image description he... | 0 | 2016-10-14T04:41:22Z | 40,035,348 | <p>I ended up figuring it out! Thanks to BrenBarn for pointing out that the second argument of <code>.boxplot</code> is <code>notch</code>. I did the following: </p>
<pre><code>nps = np.array(all_s)
npd = [dd for dd in all_d]
box=sns.boxplot(data=nps.T)
box.set_xticklabels(npd)
plt.show()
</code></pre>
<p><a href="h... | 0 | 2016-10-14T05:11:55Z | [
"python",
"matplotlib",
"machine-learning",
"scikit-learn",
"seaborn"
] |
Django django.test django.db.models.fields.related_descriptors.ManyRelatedManager | 40,035,240 | <p>Please assert type: 'django.db.models.fields.related_descriptors.ManyRelatedManager'. </p>
<p>In other words, how to import the module in order to assert that the field 'user.groups' is of type 'django.db.models.fields.related_descriptors.ManyRelatedManager'?</p>
<pre><code>from django.db.models.fields import rela... | 0 | 2016-10-14T05:01:52Z | 40,036,963 | <p>You cannot make such an assertion on <code>user.groups</code> and <code>related_descriptors.ManyRelatedManager</code>. </p>
<p>The <code>ManyRelatedManager</code> class is not accessible using import like <code>from django.db.models.fields import related_descriptors</code> because if you look at the source code of ... | 1 | 2016-10-14T07:04:59Z | [
"python",
"django"
] |
Adding arrays to dataframe column | 40,035,276 | <p>Let's assume I have this dataframe <code>df</code>:</p>
<pre><code> 'Location' 'Rec ID' 'Duration'
0 Houston 126 17
1 Chicago 338 19.3
</code></pre>
<p>I would like to add a column with arrays corresponding to my recordings like:</p>
<pre><code> 'Location' 'Rec ID' 'Dur... | 3 | 2016-10-14T05:05:40Z | 40,035,425 | <p>I think the easiest is to assign <code>list</code> of <code>lists</code>, only you need same length of <code>lists</code> as <code>length</code> of <code>DataFrame</code>:</p>
<pre><code>arr = [[0.2, 0.34, 0.45, 0.28], [0.12, 0.3, 0.41, 0.39]]
print (arr)
[[0.2, 0.34, 0.45, 0.28], [0.12, 0.3, 0.41, 0.39]]
print (l... | 1 | 2016-10-14T05:19:33Z | [
"python",
"arrays",
"pandas",
"dataframe"
] |
Is it possible to retrieve a Javascript file from a server? | 40,035,331 | <p>In Python, I can retrieve Javascript from an HTML document using the following code.</p>
<pre><code>import urllib2, jsbeautifier
from bs4 import BeautifulSoup
f = urllib2.urlopen("http://www.google.com.ph/")
soup = BeautifulSoup(f, "lxml")
script_raw = str(soup.script)
script_pretty = jsbeautifier.beautify(scrip... | 1 | 2016-10-14T05:10:13Z | 40,035,480 | <pre><code><script src="some/directory/example.js" type="text/javascript">
</code></pre>
<p>the code above will get <code>some/directory/example.js</code> from server
you just make folders and file structure follow the pattern above</p>
| 1 | 2016-10-14T05:23:47Z | [
"javascript",
"python"
] |
Is it possible to retrieve a Javascript file from a server? | 40,035,331 | <p>In Python, I can retrieve Javascript from an HTML document using the following code.</p>
<pre><code>import urllib2, jsbeautifier
from bs4 import BeautifulSoup
f = urllib2.urlopen("http://www.google.com.ph/")
soup = BeautifulSoup(f, "lxml")
script_raw = str(soup.script)
script_pretty = jsbeautifier.beautify(scrip... | 1 | 2016-10-14T05:10:13Z | 40,035,526 | <p>If you want to load at run time, like some part of your javascript is dependent on other javascript, then for loading javascript at run time, you can use require.js .</p>
| 0 | 2016-10-14T05:27:10Z | [
"javascript",
"python"
] |
Is it possible to retrieve a Javascript file from a server? | 40,035,331 | <p>In Python, I can retrieve Javascript from an HTML document using the following code.</p>
<pre><code>import urllib2, jsbeautifier
from bs4 import BeautifulSoup
f = urllib2.urlopen("http://www.google.com.ph/")
soup = BeautifulSoup(f, "lxml")
script_raw = str(soup.script)
script_pretty = jsbeautifier.beautify(scrip... | 1 | 2016-10-14T05:10:13Z | 40,035,535 | <p>The easiest way is to right click on that page in your browser, choose <code>page script</code>, click on that <code>.js</code> link, and it will be there.</p>
| 1 | 2016-10-14T05:27:36Z | [
"javascript",
"python"
] |
How do I convert float decimal to float octal/binary? | 40,035,361 | <p>I have been searched everywhere to find a way to convert float to octal or binary. I know about the <code>float.hex</code> and <code>float.fromhex</code>. Is theres a modules which can do the same work for octal/binary values?</p>
<p>For example: I have a float <code>12.325</code> and I should get float octal <code... | 2 | 2016-10-14T05:12:46Z | 40,050,134 | <p>You could write your own, if you only care about three decimal places then set n to 3:</p>
<pre><code>def frac_to_oct(f, n=4):
# store the number before the decimal point
whole = int(f)
rem = (f - whole) * 8
int_ = int(rem)
rem = (rem - int_) * 8
octals = [str(int_)]
count = 1
# loo... | 1 | 2016-10-14T18:48:36Z | [
"python",
"binary",
"floating-point",
"octal"
] |
How do I convert float decimal to float octal/binary? | 40,035,361 | <p>I have been searched everywhere to find a way to convert float to octal or binary. I know about the <code>float.hex</code> and <code>float.fromhex</code>. Is theres a modules which can do the same work for octal/binary values?</p>
<p>For example: I have a float <code>12.325</code> and I should get float octal <code... | 2 | 2016-10-14T05:12:46Z | 40,050,158 | <p>Here's the solution, explanation below:</p>
<pre><code>def ToLessThanOne(num): # Change "num" into a decimal <1
while num > 1:
num /= 10
return num
def FloatToOctal(flo, places=8): # Flo is float, places is octal places
main, dec = str(flo).split(".") # Split into Main (integer component)... | 0 | 2016-10-14T18:49:51Z | [
"python",
"binary",
"floating-point",
"octal"
] |
convert a list to dict with key equal to every unique item and value equal to the indices of the item in the list | 40,035,429 | <p>For example, I have a list of <code>a = ['a', 'b', 'a']</code>, what is the best code to convert it to <code>b = {'a': [0, 2], 'b': [1]}</code>?</p>
| 0 | 2016-10-14T05:19:45Z | 40,035,465 | <p>You can use <a href="https://docs.python.org/3/library/collections.html#collections.defaultdict" rel="nofollow"><code>defaultdict</code></a> with <code>list</code> default factory:</p>
<pre><code>>>> from collections import defaultdict
>>> a = ['a', 'b', 'a']
>>> res = defaultdict(list)
&... | 3 | 2016-10-14T05:22:38Z | [
"python"
] |
convert a list to dict with key equal to every unique item and value equal to the indices of the item in the list | 40,035,429 | <p>For example, I have a list of <code>a = ['a', 'b', 'a']</code>, what is the best code to convert it to <code>b = {'a': [0, 2], 'b': [1]}</code>?</p>
| 0 | 2016-10-14T05:19:45Z | 40,035,525 | <pre><code>a = ['a', 'b', 'a']
b = dict.fromkeys(set(a), []) # {'a': [], 'b': []}
for i, val in enumerate(a):
b[val] = b.get(val)+[i]
print (b)
</code></pre>
<p>gives:</p>
<pre><code>{'a': [0, 2], 'b': [1]}
</code></pre>
| 2 | 2016-10-14T05:27:06Z | [
"python"
] |
Delete the row as soon as a column reaches a specific value | 40,035,446 | <p>If this be my model:</p>
<pre><code>class Entity(Base):
id = Column(Integer, primary_key=True)
count = Column(Integer, default=0)
</code></pre>
<p>I want to delete any rows that reach <code>count</code> value of 3 (or any number).
How can I do that?
should I implement such deletion in the Controller of my ... | 1 | 2016-10-14T05:21:28Z | 40,035,682 | <blockquote>
<p>Should I implement the deletion in the controller of my web application?</p>
</blockquote>
<p>Yes. You should implement it in your controller. Just make sure you have a view that will be able to access your <code>delete</code> function in the controller.</p>
<blockquote>
<p>Who [how] can I do that... | -2 | 2016-10-14T05:40:02Z | [
"python",
"postgresql",
"concurrency",
"sqlalchemy",
"locking"
] |
Delete the row as soon as a column reaches a specific value | 40,035,446 | <p>If this be my model:</p>
<pre><code>class Entity(Base):
id = Column(Integer, primary_key=True)
count = Column(Integer, default=0)
</code></pre>
<p>I want to delete any rows that reach <code>count</code> value of 3 (or any number).
How can I do that?
should I implement such deletion in the Controller of my ... | 1 | 2016-10-14T05:21:28Z | 40,053,192 | <p>After sometime pondering and consulting with experts I figured out that solution to this matter is either implementing a lock in database or using redis. Since locking may cause performance problems in multitude requests, It's better to store the value of <code>count</code> in a redis database and try updating the <... | 1 | 2016-10-14T23:04:07Z | [
"python",
"postgresql",
"concurrency",
"sqlalchemy",
"locking"
] |
Python connecting to an HTTP server | 40,035,567 | <p>In my program, I am trying to access <code>https://api.dropbox.com/1/oauth2/token</code>. In order to do that, I was trying to use <code>http.client.HTTPSConnection()</code>. However, I am receiving a 400 statement from the server, even though when I send the same request through my browser, I get an actual response... | 0 | 2016-10-14T05:30:33Z | 40,064,234 | <p>TL;DR: Change the lowercase 'get' to uppercase 'GET' should resolve the problem.</p>
<p>The reason: according to section 5.1.1, <a href="https://www.w3.org/Protocols/rfc2616/rfc2616.txt" rel="nofollow">RFC2616</a>:</p>
<blockquote>
<p>The Method token indicates the method to be performed on the
resource identi... | 2 | 2016-10-15T21:08:41Z | [
"python",
"http",
"dropbox"
] |
Python 3 Index Error | 40,035,724 | <p>Consider the following code:</p>
<pre><code>def anadist(string1, string2):
string1_list = []
string2_list = []
for i in range(len(string1)):
string1_list.append(string1[i])
for i in range(len(string2)):
string2_list.append(string2[i])
# Test returns for checking
# return (s... | 0 | 2016-10-14T05:43:37Z | 40,035,798 | <p>In some cases, you are shortening <code>string_list1</code> while you're iterating over it:</p>
<pre><code>if (string1_list[i]) in string2_list:
com = string1_list.pop(i) # string1_list gets shorter here
</code></pre>
<p>However, your <code>range</code> doesn't change. It's still going to go from <code>0</co... | 3 | 2016-10-14T05:50:07Z | [
"python",
"list",
"python-3.5",
"anagram"
] |
Python 3 Index Error | 40,035,724 | <p>Consider the following code:</p>
<pre><code>def anadist(string1, string2):
string1_list = []
string2_list = []
for i in range(len(string1)):
string1_list.append(string1[i])
for i in range(len(string2)):
string2_list.append(string2[i])
# Test returns for checking
# return (s... | 0 | 2016-10-14T05:43:37Z | 40,035,803 | <p>Your issue is that you are mutating the <code>string1_list</code> within the <code>for</code> loop by performing <code>string1_list.pop(i)</code>. The length of the list is being reduced within the <code>for</code> loop by doing <code>string1_list.pop(i)</code>, but you are still iterating over the length of the ori... | 1 | 2016-10-14T05:50:25Z | [
"python",
"list",
"python-3.5",
"anagram"
] |
Python 3 Index Error | 40,035,724 | <p>Consider the following code:</p>
<pre><code>def anadist(string1, string2):
string1_list = []
string2_list = []
for i in range(len(string1)):
string1_list.append(string1[i])
for i in range(len(string2)):
string2_list.append(string2[i])
# Test returns for checking
# return (s... | 0 | 2016-10-14T05:43:37Z | 40,035,808 | <p>Your second attempt works simply because a "match" is found only in the last element <code>5</code> and as such when you mutate your list <code>lst</code> it is during the <em>last iteration</em> and has no effect.</p>
<p>The problem with your first attempt is that you might remove from the beginning of the list. T... | 1 | 2016-10-14T05:50:55Z | [
"python",
"list",
"python-3.5",
"anagram"
] |
How to create AMI at runtime using AWS Lambda? | 40,035,818 | <p>Scenario -
Running AWS EC2 with AutoScaling to host web servers. Code is hosted on BitBucket.</p>
<p>Requirements - </p>
<ol>
<li>Integrate BitBucket with CodeDeploy for automated deployments.</li>
<li>After every successful deployment, create AMI of the running healthy instance.</li>
<li>Create a new Launch Conf... | 0 | 2016-10-14T05:51:47Z | 40,035,902 | <p>I went through above scenario and the challenging part was that Web Servers were running using IIS since it was a .NET app, which means I had to automated configuration part of .NET as well.</p>
<p>If you are also into similar situation, then I have written a post of that. Just click on the link below. It works for... | 0 | 2016-10-14T05:57:42Z | [
"python",
"amazon-web-services",
"bitbucket",
"aws-lambda"
] |
Python and Pip not in sync | 40,035,830 | <p>I am working on a remote linux server with python 2.7.6 pre-installed. I want to <strong>upgrade to python 2.7.12</strong> (because I am not able to install some libraries on the 2.7.6 due to some <strong>ssl error</strong> shown below).</p>
<p>I downloaded and compiled from source and installed 2.7.12 and <code>py... | 1 | 2016-10-14T05:52:54Z | 40,036,183 | <p>Upgrade (and automatically reinstall) pip this way: </p>
<pre><code>/path/to/python2.7.12 -m pip install pip --upgrade
</code></pre>
<p>The <code>-m</code> flag loads the corresponding module, and in the case of pip will execute <code>pip</code> (thanks to <a href="https://docs.python.org/3/library/__main__.html" ... | 1 | 2016-10-14T06:15:33Z | [
"python",
"linux",
"python-2.7",
"pip"
] |
Python and Pip not in sync | 40,035,830 | <p>I am working on a remote linux server with python 2.7.6 pre-installed. I want to <strong>upgrade to python 2.7.12</strong> (because I am not able to install some libraries on the 2.7.6 due to some <strong>ssl error</strong> shown below).</p>
<p>I downloaded and compiled from source and installed 2.7.12 and <code>py... | 1 | 2016-10-14T05:52:54Z | 40,036,342 | <p>Thanks @Evert , just before looking into your solution I tried,</p>
<pre><code>curl -O https://bootstrap.pypa.io/get-pip.py
python27 get-pip.py
</code></pre>
<p>This fixed my issue and I was able to install libraries to <code>2.7.12</code> using <code>pip/pip2.7</code></p>
<p>I was earlier trying <code>python2.7 ... | 0 | 2016-10-14T06:26:49Z | [
"python",
"linux",
"python-2.7",
"pip"
] |
python-RequestParser is not returning error when different datatype is sent in request | 40,035,872 | <p>I have created Flask application in that i am using RequestParser to check datatype of input fields like below</p>
<pre><code>parser = reqparse.RequestParser()
parser.add_argument('article_id',type=str,required=True, help='SUP-REQ-ARTICLEID')
parser.add_argument('description',type=str,required=True, help='SUP-REQ-D... | 1 | 2016-10-14T05:55:52Z | 40,036,127 | <p>At first, Postman creates a regular HTTP post from your data. And HTTP posts looks like this:</p>
<pre class="lang-none prettyprint-override"><code>article_id=2&description=some%20description&userid=1
</code></pre>
<p>There is no type information, that's plain old URL encoding. <em>Everything</em> is a str... | 3 | 2016-10-14T06:12:17Z | [
"python",
"json",
"parsing",
"flask-restful"
] |
Python Script to SSH | 40,036,052 | <p>I am a beginner trying to do SSH writing a basic code, I have tried everything not able to debug this , My code is as follows :</p>
<pre><code>import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print ("1")
ssh.connect('196.5.5.6', username='abc', password='abc')
pri... | 1 | 2016-10-14T06:08:16Z | 40,036,398 | <p>You don't need to do <code>readlines(</code>) on <code>stdin</code>. You can print it directly. <code>readlines()</code> expect a file to be opened and read from the file. Whereas <code>stdin</code>, <code>stdout</code>, <code>stderr</code> are not files, rather a block of strings ( or string buffer used in paramiko... | 0 | 2016-10-14T06:31:14Z | [
"python",
"shell",
"ssh"
] |
Python Script to SSH | 40,036,052 | <p>I am a beginner trying to do SSH writing a basic code, I have tried everything not able to debug this , My code is as follows :</p>
<pre><code>import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print ("1")
ssh.connect('196.5.5.6', username='abc', password='abc')
pri... | 1 | 2016-10-14T06:08:16Z | 40,036,448 | <p>You should enter commands try this </p>
<pre><code>import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print ("1")
ssh.connect('ip', username='user', password='pass')
print ("2")
stdin, stdout, stderr = ssh.exec_command('show version')
print ("3")
stdin,stdout,stder... | 0 | 2016-10-14T06:34:13Z | [
"python",
"shell",
"ssh"
] |
Spark - PySpark sql error | 40,036,060 | <p>I have a simple pyspark code but i can't run it. I try to run it on Ubuntu system and I use PyCharm IDE. I would like to connect to Oracle XE Database and I want to print my test table. </p>
<p>Here comes my spark python code: </p>
<pre><code>from pyspark import SparkContext
from pyspark.sql import SQLContext
sc ... | 0 | 2016-10-14T06:08:36Z | 40,036,227 | <p>Change to <code>dbtable</code> from <code>table</code> like this,</p>
<pre><code>demoDf = sqlContext.read.format("jdbc").options(
url="jdbc:oracle:thin:@10.10.10.10:1521:XE",
driver="oracle.jdbc.driver.OracleDriver",
dbtable="tst_table",
user="xxx",
password="xxx").load()
</code></pre>
| 2 | 2016-10-14T06:18:43Z | [
"python",
"apache-spark",
"pyspark"
] |
python script encountering error when reading from database and data is empty | 40,036,163 | <p>I am reading data from data table in database. The method is throwing an exception when there is no data in table in database. </p>
<pre><code>def readData(table):
"""Read the database table, parse it according to the field map, and return list of parsed lines"""
cmd = GETTABLE + ' ' + table
records = []
try:
r... | 0 | 2016-10-14T06:14:40Z | 40,036,730 | <p>First I would edit the code in a way that indentation is preserved and show the error message. As in the comment by smarx given you just need to check if you have something in lines left to pop. But the next lines are also error prone and should handle problems. Eg. if a line is there, but it is not a legal header, ... | 0 | 2016-10-14T06:52:09Z | [
"python"
] |
Calling defintions from inside a class | 40,036,261 | <p>I am currently having an issue with calling on definitions from inside a class, how do I fix the issue of <code>slideShow()</code> in line 32 not opening the slideshow sequence?</p>
<pre><code>import tkinter as tk
from itertools import cycle
root = ""
#create a splash screen, 80% of display screen size, centered,
... | -1 | 2016-10-14T06:20:41Z | 40,036,386 | <p>You have to use <code>self.</code> inside class. </p>
<pre><code>def slideShow(self):
</code></pre>
<p>and </p>
<pre><code>root.after(1, self.slideShow)
</code></pre>
<p>But probably you have problem with second <code>after</code> too. You have to create instance of class <code>splashscreen</code></p>
<pre><cod... | 0 | 2016-10-14T06:30:23Z | [
"python",
"tkinter"
] |
Multi Indexing and masks with logic pandas | 40,036,532 | <p>I have 4 indexes. Mun, loc, geo and block. And I need to create masks to operate with them so I can create masks and perform operations that will look like this:</p>
<pre><code> data1 data2
mun loc geo block
0 0 0 0 12 12
1 0 0 0 20 20
1 1 0 0... | 1 | 2016-10-14T06:40:47Z | 40,041,683 | <p>It was not easy. But mainly use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.get_level_values.html" rel="nofollow"><code>get_level_values</code></a> for select values for condition:</p>
<p>Level <strong><code>block</code></strong>:</p>
<pre><code>print (df)
data1 ... | 2 | 2016-10-14T11:08:35Z | [
"python",
"pandas",
"indexing",
"division",
"multi-index"
] |
Is it Pythonic to passed in arguments in a function that will be used by a function inside it? | 40,036,600 | <p>Is there a better way to do this? Like I'm passing in arguments to <code>func</code> that will be used in <code>inside_func</code> function? </p>
<pre><code>def inside_func(arg1,arg2):
print arg1, arg2
return
def func(arg1, arg2):
inside_func(arg1,arg2)
return
</code></pre>
| 0 | 2016-10-14T06:45:01Z | 40,036,650 | <p>Of course it is.</p>
<p>Your outer function provides a service, and to do its job it may need inputs to work with. <em>How it uses those inputs</em> is up to the function. If it needs another function to do their job and they pass in the arguments verbatim, is an implementation detail.</p>
<p>You are doing nothing... | 6 | 2016-10-14T06:47:28Z | [
"python",
"function"
] |
How can I decrease the number on a button? | 40,036,654 | <p>I'm trying to create a GUI that has only one button. Each time the button is pressed the number on the button should decrease. So I wrote this:</p>
<pre><code>import Tkinter
def countdown(x):
x -= 1
top = Tkinter.Tk()
def helloCallBack():
countdown(x)
B = Tkinter.Button(top, text=x, comma... | 0 | 2016-10-14T06:47:42Z | 40,037,108 | <p>As described in the "Button" section of <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/control-variables.html" rel="nofollow">http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/control-variables.html</a>, you need to create a special <code>StringVar</code> to make the button dynamically update. You can pa... | 0 | 2016-10-14T07:13:13Z | [
"python",
"python-2.7",
"tkinter"
] |
How can I decrease the number on a button? | 40,036,654 | <p>I'm trying to create a GUI that has only one button. Each time the button is pressed the number on the button should decrease. So I wrote this:</p>
<pre><code>import Tkinter
def countdown(x):
x -= 1
top = Tkinter.Tk()
def helloCallBack():
countdown(x)
B = Tkinter.Button(top, text=x, comma... | 0 | 2016-10-14T06:47:42Z | 40,037,813 | <p>You can create global variable and use it in function <code>countdown</code> (but you have to use <code>global</code>) and then you can use <code>config(text=...)</code> to change text on button.</p>
<pre><code>import Tkinter as tk
# --- functions ---
def countdown():
global x # use global variable
x -= ... | 2 | 2016-10-14T07:51:52Z | [
"python",
"python-2.7",
"tkinter"
] |
Django - What is the best way to have multi level status before login | 40,036,710 | <p>I have one scenario, there is a user registration and it should have multiple status(may be is_active - but this is boolean by default)</p>
<ol>
<li>List item Code - 0 -> Pending for Email Confirmation</li>
<li>List item Code - 1 -> Account Activated/Active(Only after email confirmed admin will approve it)</li>
<li... | 0 | 2016-10-14T06:50:50Z | 40,037,520 | <p>You should create custom <code>User</code> or custom <code>Profile</code>(i believe that it's better with custom <code>Profile</code>, to avoid messing with django <code>User</code>):</p>
<pre><code>from itertools import compress
class CustomProfile(Profile):
is_confirmed = models.BooleanField(default=False)
... | 1 | 2016-10-14T07:35:37Z | [
"python",
"django"
] |
Django - What is the best way to have multi level status before login | 40,036,710 | <p>I have one scenario, there is a user registration and it should have multiple status(may be is_active - but this is boolean by default)</p>
<ol>
<li>List item Code - 0 -> Pending for Email Confirmation</li>
<li>List item Code - 1 -> Account Activated/Active(Only after email confirmed admin will approve it)</li>
<li... | 0 | 2016-10-14T06:50:50Z | 40,038,644 | <p>You can use <code>decorators</code> for these kinds of scenarios. Decorators are just methods that accepts another method as argument. What you have to do is to <code>pass the get/post or any other methods together with its arguments to decorator</code> then check for email confirmation/account active. </p>
<pre><c... | 0 | 2016-10-14T08:36:01Z | [
"python",
"django"
] |
Django - Errors not showing on page, connection timeout error thrown after a while | 40,036,717 | <p>I'm having this issue that suddenly appeared with no obvious reasons. Initially, the errors and exceptions were being displayed both on the page and the console. However, whenever I get or reproduce any kind of error and refresh the page to see the results, the page loads for too long and nothing appear in the pytho... | 0 | 2016-10-14T06:51:20Z | 40,123,801 | <p>I discovered the source of the issue, which turned out to be from settings.py file. This piece of code was causing the breakage. Once removed, I was able to view the errors:</p>
<pre><code>LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'form... | 0 | 2016-10-19T06:30:03Z | [
"python",
"django"
] |
httplib post call error | 40,036,814 | <p>I am trying to automate few http requests where, I have following POST call data which i captured from the web : </p>
<p>Method: POST
Request Header : </p>
<p>POST /cgi-bin/auto_dispatch.cgi HTTP/1.1
Host: 10.226.45.6
Connection: keep-alive
Content-Length: 244
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1... | 0 | 2016-10-14T06:56:10Z | 40,121,820 | <p>I Tried with the curl commands which worked for me : </p>
<p>curl --request POST '<a href="http://10.226.45.6/cgi-bin/auto_dispatch.cgi" rel="nofollow">http://10.226.45.6/cgi-bin/auto_dispatch.cgi</a> HTTP/1.1' --data 'taskid=111&submit=submit'</p>
<p>curl --request POST '<a href="http://10.226.45.6/cgi-bin/au... | 0 | 2016-10-19T03:54:22Z | [
"python",
"apache",
"httplib"
] |
Running a Python program with arguments from within the Visual Studio Code | 40,036,942 | <p>I am running a Python program that takes some command line arguments. How can I provide these arguments when I am building a program within the Visual Studio Code?</p>
| 0 | 2016-10-14T07:03:44Z | 40,041,828 | <p>You can pass in the arguments into the program by defining the arguments in the <code>args</code> setting of launch.json as defined below:</p>
<p><code>json
{
"name": "Python",
"type": "python",
"pythonPath":"${config.python.pythonPath}",
"request": "launch",
"stopOnEntry": true,
"console":... | 1 | 2016-10-14T11:15:39Z | [
"python",
"build",
"vscode"
] |
Python How to Change Value in Loop | 40,036,957 | <p>There's a code I'm attempting to reverse-engineer for an assignment. The program asks you to enter an integer and it'll loop the words "Line (loop it's on) Hello World" as many times as the number you entered. On the first loop, it said 'Line 1', on the second, it said 'Line 2' and on the third, it said 'Line 3' etc... | -2 | 2016-10-14T07:04:20Z | 40,036,991 | <p>Something like this?</p>
<pre><code>for n in range(int(input())):
print("Line", n+1, "Hello World")
</code></pre>
<p>The <code>range</code> function gives you an iterator with a value <code>0</code>, <code>1</code>, <code>2</code>, ..., <code>n-1</code>. </p>
| 0 | 2016-10-14T07:06:48Z | [
"python",
"loops"
] |
Python How to Change Value in Loop | 40,036,957 | <p>There's a code I'm attempting to reverse-engineer for an assignment. The program asks you to enter an integer and it'll loop the words "Line (loop it's on) Hello World" as many times as the number you entered. On the first loop, it said 'Line 1', on the second, it said 'Line 2' and on the third, it said 'Line 3' etc... | -2 | 2016-10-14T07:04:20Z | 40,037,106 | <p>If this is what you want?</p>
<pre><code>>>> while 1:
... for n in range(int(input())):
... print("Hello World")
...
</code></pre>
<p>The output like this:</p>
<pre><code>1
Hello World
2
Hello World
Hello World
4
Hello World
Hello World
Hello World
Hello World
</code></pre>
| -1 | 2016-10-14T07:13:09Z | [
"python",
"loops"
] |
Cannot load customized op shared lib in tensorflow | 40,037,053 | <p>I tried to add a customized op to tensorflow, but I cannot load it from python. The question is similar to the closed <a href="https://github.com/tensorflow/tensorflow/issues/2455" rel="nofollow">issue</a> in github, but the solution there did not solve my problem.</p>
<p>Operating System: macOS 10.12</p>
<p>Insta... | 0 | 2016-10-14T07:10:05Z | 40,062,428 | <p>Well, I found a solution. Instead of building user op by bazel, use g++.</p>
<pre><code>g++ -v -std=c++11 -shared zero_out.cc -o zero_out.so -fPIC -I $TF_INC -O2 -undefined dynamic_lookup -D_GLIBCXX_USE_CXX11_ABI=0
</code></pre>
<p>It will work. The reason seems like that my gcc version is too high (v6.2.0).</p>
... | 0 | 2016-10-15T18:00:55Z | [
"python",
"tensorflow"
] |
Different marker colors for start and end points in pyplot | 40,037,070 | <p>I am trying to plot lines on a plot between two point tuples. I have following arrays:</p>
<pre><code>start_points = [(54.6, 35.2), (55.5, 32.7), (66.5, 23.7), (75.5, 47.8), (89.3, 19.7)]
end_points = [(38.9, 44.3), (46.7, 52.2), (72.0, 1.4), (62.3, 18.9), (80.8, 26.2)]
</code></pre>
<p>So what I am trying to do i... | -1 | 2016-10-14T07:10:48Z | 40,037,422 | <p>The trick is to first plot the line (<code>plt.plot</code>) and then plot the markers using a scatter plot (<code>plt.scatter</code>).</p>
<pre><code>import numpy as np
from matplotlib import pyplot as plt
start_points = [(54.6, 35.2), (55.5, 32.7), (66.5, 23.7), (75.5, 47.8), (89.3, 19.7)]
end_points = [(38.9, 44... | 1 | 2016-10-14T07:29:52Z | [
"python",
"matplotlib"
] |
Not able to install package because pip is not installed | 40,037,107 | <p>I am running Ubuntu and have both python 2.7 and python 3.5 on my system</p>
<p>I have tweaked the settings so that when I do</p>
<pre><code>python test.py
</code></pre>
<p>python3 runs</p>
<p>I wanted to install the module pyperclip in python3..</p>
<pre><code>pip install pyperclip
</code></pre>
<p>installed ... | 0 | 2016-10-14T07:13:10Z | 40,037,852 | <p>It seems like it could be an error in your path. If you installed Python 3.5 it should come with pip, so try doing <code>python -m pip</code> and this should run Python 3.5's pip. To install something, simply use the normal pip commands as you have, for example <code>python -m pip install pyperclip</code>.</p>
| 1 | 2016-10-14T07:54:03Z | [
"python",
"python-3.x",
"pip"
] |
Python. Find all possible combinations of numbers with set length | 40,037,118 | <p>I have a list of numbers: [0, 0, 1, 1, 2, 2]</p>
<p>I want to have all combinations of 2 numbers, I tried to do it with itertools:</p>
<pre><code>import itertools
a = [0, 0, 1, 1, 2, 2]
combinations = set(itertools.permutations(a, 2))
print(combinations)
# {(0, 1), (1, 2), (0, 0), (2, 1), (2, 0), (1, 1), (2, 2), (... | 1 | 2016-10-14T07:13:28Z | 40,037,165 | <p>A set is a data structure without duplicates. Use a list:</p>
<pre><code>import itertools
a = [0, 0, 1, 1, 2, 2]
combinations = list(itertools.permutations(a, 2))
print(combinations)
</code></pre>
| 3 | 2016-10-14T07:16:33Z | [
"python",
"algorithm",
"combinations"
] |
Python. Find all possible combinations of numbers with set length | 40,037,118 | <p>I have a list of numbers: [0, 0, 1, 1, 2, 2]</p>
<p>I want to have all combinations of 2 numbers, I tried to do it with itertools:</p>
<pre><code>import itertools
a = [0, 0, 1, 1, 2, 2]
combinations = set(itertools.permutations(a, 2))
print(combinations)
# {(0, 1), (1, 2), (0, 0), (2, 1), (2, 0), (1, 1), (2, 2), (... | 1 | 2016-10-14T07:13:28Z | 40,037,169 | <p>Just use <code>itertools.product</code>, it gives all possible combinations:</p>
<pre><code>from itertools import product
a = [0, 0, 1, 1, 2, 2]
print (list(product(a, repeat=2)))
</code></pre>
<p>gives:</p>
<pre><code>[(0, 0), (0, 0), (0, 1), (0, 1),
(0, 2), (0, 2), (0, 0), (0, 0),
(0, 1), (0, 1), (0, 2), (0,... | 5 | 2016-10-14T07:16:41Z | [
"python",
"algorithm",
"combinations"
] |
Retrieving log message within curly braces using Regex with Python | 40,037,174 | <p>I am trying to parse some logs which return some responses in a key-pair format. I only want they value contained by the last key-pair (Rs: {".."}). The information I want are enclosed inside the curly braces.</p>
<p>What I have done is to use regex to match anything inside the curly braces like this:</p>
<pre><co... | 1 | 2016-10-14T07:17:10Z | 40,037,337 | <p>It seems that you need two things: re-adjust the first capturing group boundaries to include curly braces, and use a lazy version of <code>.*</code> (in case there are multiple values in the string). I also recommend checking if there is a match first if you are using <code>re.search</code>, or just use <code>re.fi... | 0 | 2016-10-14T07:25:44Z | [
"python",
"regex"
] |
Retrieving log message within curly braces using Regex with Python | 40,037,174 | <p>I am trying to parse some logs which return some responses in a key-pair format. I only want they value contained by the last key-pair (Rs: {".."}). The information I want are enclosed inside the curly braces.</p>
<p>What I have done is to use regex to match anything inside the curly braces like this:</p>
<pre><co... | 1 | 2016-10-14T07:17:10Z | 40,037,372 | <p>The first part is easy: just move the capturing parens out a little bit use this as your regex:</p>
<pre><code>"Rs:(\{.*\})"
</code></pre>
<p>The other problem is more complicated - if you want the rest of the line (starting at <code>{</code>), then </p>
<pre><code>r'Rs:(\{.*)\Z'
</code></pre>
<p>would get you w... | 1 | 2016-10-14T07:27:18Z | [
"python",
"regex"
] |
UnicodeDecodeError when ssh from OS X | 40,037,191 | <p>My Django app loads some files on startup (or when I execute management command). When I ssh from one of my Arch or Ubuntu machines all works fine, I am able to successfully run any commands and migrations.</p>
<p>But when I ssh from OS X (I have El Capital) and try to do same things I get this error: </p>
<pre><c... | 0 | 2016-10-14T07:18:16Z | 40,037,801 | <p>Your terminal at your local machine uses a character encoding. The encoding it uses appears to be UTF-8. When you log on to your server (BTW, what OS does it run?) the programs that run there need to know what encoding your terminal supports so that they display stuff as needed. They get this information from <code>... | 0 | 2016-10-14T07:51:00Z | [
"python",
"django",
"osx",
"ssh",
"locale"
] |
Calling dir function on a module | 40,037,253 | <p>When I did a dir to find the list of methods in boltons I got the below output</p>
<pre><code>>>> import boltons
>>> dir(boltons)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
</code></pre>
<p>When I explicitly did </p>
<pre><code>>>> from boltons.strut... | 1 | 2016-10-14T07:21:45Z | 40,039,019 | <p>From the <a href="https://docs.python.org/3/library/functions.html#dir" rel="nofollow">docs</a> on what dir does:</p>
<blockquote>
<p>With an argument, attempt to return a list of valid attributes for
that object.</p>
</blockquote>
<p>When we import the boltons package we can see that strutils is not an attrib... | 2 | 2016-10-14T08:56:02Z | [
"python",
"python-2.7"
] |
Python: Dynamically importing a script in another folder from a string | 40,037,569 | <p>I need to import and run a script from a string (path) which is located in another folder. The input needs to be completely dynamic. The code below works when the file is in the same folder but I can't seem to get it working when the file is located elsewhere.</p>
<p>main.py</p>
<pre><code>path = 'bin\TestScript'
... | -1 | 2016-10-14T07:37:59Z | 40,038,075 | <p>You need to separate the directory from the module name and add that to the module search path. For example:</p>
<pre><code>import os.path
import sys
path = 'bin\\TestScript'
mdir = os.path.dirname(path)
modname = os.path.basename(path)
sys.path.append(mdir)
module = __import__(modname)
my_class = getattr(modul... | 1 | 2016-10-14T08:06:19Z | [
"python"
] |
Sequence Recognition using fsm in python | 40,037,580 | <p>What is the best way to detect a sequence of characters in python?</p>
<p>I'm trying to use transitions package by Tal yarkoni for creating fsm's based on input sequences. Then i want to use the created fsms for new sequence recognition.
I'm storing the created fsm in a dict with sequence number as key. </p>
<p>A... | 0 | 2016-10-14T07:38:33Z | 40,037,938 | <p>There is no concept of end state, but you can define a state 'end' on each fsm and check for it (see 'checking state' in the git readme), or you could add a 'on enter' reference on the 'end' state and that function will be called when the 'end' state is entered.</p>
<p>Haven't seen transitions before, looks very ni... | 0 | 2016-10-14T07:58:30Z | [
"python",
"transitions"
] |
Read cvs file to Dictionary python | 40,037,615 | <p>Please, I need to read CSV file and convert the result to a dictionary.</p>
<p>File input:</p>
<p><a href="https://i.stack.imgur.com/4h26Q.png" rel="nofollow"><img src="https://i.stack.imgur.com/4h26Q.png" alt="enter image description here"></a></p>
<p>The required object after reading like below:</p>
<pre><code... | 0 | 2016-10-14T07:40:57Z | 40,038,356 | <p>I always use <code>csv.DictReader</code> and then build the dictionary in the format you want like so:</p>
<p><a href="https://i.stack.imgur.com/weNmx.png" rel="nofollow"><img src="https://i.stack.imgur.com/weNmx.png" alt="enter image description here"></a></p>
<pre><code>import csv
import os
cwd = os.getcwd()
d... | 0 | 2016-10-14T08:20:29Z | [
"python",
"csv",
"dictionary"
] |
Adding reference to .net assembly which has dots in name and namespace | 40,037,684 | <p>I am trying to refer to assembly which has dots in the namespace.</p>
<pre class="lang-python prettyprint-override"><code>sys.path.append(assemblyPath)
clr.FindAssembly(r"isc.Eng.Hov")
clr.AddReference(r"isc.Eng.Hov")
print 'isc.Eng.Hov' in clr.ListAssemblies(False)
from isc.Eng.Hov import *
</code></pre>
<p>In... | 1 | 2016-10-14T07:44:43Z | 40,099,662 | <p>the solution was to use <a href="http://ilspy.net/" rel="nofollow">ILSPY</a> to investigate the DLL and find dependencies (right click recursively for each DLL and click on add dependencies). Then I copied all the dependencies to the same folder where the main DLL was. After that, I ran:</p>
<pre class="lang-python... | 1 | 2016-10-18T04:43:10Z | [
"python",
".net",
".net-assembly",
"python.net"
] |
Can't make python files executable in os x | 40,037,785 | <p>I want to put the path to the python file first in the file to run it without having to type python before it. Here is the output of the terminal that comfiuses me</p>
<pre><code>[Wolfie@Wolfies-MacBook-Pro] [08:54:28] [/Applications/MAMP/cgi-bin]
$python test.py
blaaaaa
[Wolfie@Wolfies-MacBook-Pro] [08:54:32] [/A... | 0 | 2016-10-14T07:50:21Z | 40,037,907 | <p>With any programming language, I'll use <code>#!/usr/bin/env [language]</code> and in this case replace <code>[language]</code> with <code>python</code>.</p>
| 1 | 2016-10-14T07:56:44Z | [
"python",
"osx"
] |
python scrapy shell exception: address "'http:" not found: [Errno 11001] getaddrinfo failed | 40,037,897 | <p>Actually it's a sample of scrapy tutorial in <strong>Extracting data</strong> of <a href="https://doc.scrapy.org/en/latest/intro/tutorial.html" rel="nofollow">scrapy</a>. Everything goes well until the sample of scrapy shell, when I type the command in Windows cmd:</p>
<pre><code>scrapy shell 'http://quotes.toscrap... | 0 | 2016-10-14T07:56:12Z | 40,038,161 | <p>Well,it may be related to the quotation, I tried to use <code>"</code> to enclose the urls and it works, I do not know if this command differs in different OS since the original tutorial commmand code use the <code>'</code> to enclose the urls.</p>
<hr>
<p>I also post this issue on the scrapy and as @kmike said, i... | 1 | 2016-10-14T08:11:35Z | [
"python",
"shell",
"scrapy"
] |
How should I read/write a data structure containing large arrays? | 40,037,998 | <p>I fetch a big array of data from a server. I store it in a combination of a dictionary and multi-dimensional array, and it will be used for a simple plot. It looks like:</p>
<pre><code>>> print(data)
{'intensity_b2': [array([ 1.46562588e+09, 1.46562588e+09, 1.46562588e+09, ...,
1.46566369e+09, 1.4... | 0 | 2016-10-14T08:01:52Z | 40,038,099 | <p>Your problem is that <code>str</code> is not a suitable way to serialise data. Typically, objects will have a string representation that would let a human understand what they are. For primitive objects, it would be a format that you could even <code>eval</code> to get back an equivalent object, but this isn't true ... | 1 | 2016-10-14T08:07:56Z | [
"python",
"arrays",
"dictionary",
"file-io"
] |
How should I read/write a data structure containing large arrays? | 40,037,998 | <p>I fetch a big array of data from a server. I store it in a combination of a dictionary and multi-dimensional array, and it will be used for a simple plot. It looks like:</p>
<pre><code>>> print(data)
{'intensity_b2': [array([ 1.46562588e+09, 1.46562588e+09, 1.46562588e+09, ...,
1.46566369e+09, 1.4... | 0 | 2016-10-14T08:01:52Z | 40,038,251 | <p>You can use <code>pickle</code> to handle serialization properly:</p>
<pre><code>In [23]: a
Out[23]:
{'intensity_b2': [array('f', [1465625856.0, 1465625856.0, 1465625856.0]),
array('f', [1465663744.0, 1465663744.0, 1465663744.0])]}
In [24]: pickle.dump(a, open('foo.p', 'wb'))
In [25]: aa = pickle.load(open('fo... | 1 | 2016-10-14T08:15:04Z | [
"python",
"arrays",
"dictionary",
"file-io"
] |
Python import modules in same directory for Flask | 40,038,042 | <p>I am trying to create a Flask application. I would like to include a separate module in my application to separate logic into distinct units. The separate module is called 'validator' and my current directory structure looks like this:</p>
<pre><code>src/
validation-api/
__init__.py
api.py
v... | 0 | 2016-10-14T08:03:58Z | 40,038,307 | <p>Thanks to @Daniel-Roseman, I've figured out what's going on. I changed the <code>FLASK_APP</code> environment variable to <code>validation-api.api</code>, and ran the <code>python -m flask run</code> command from <code>src</code>. All imports are working now!</p>
| 1 | 2016-10-14T08:17:19Z | [
"python",
"flask"
] |
fatal error:pyconfig.h:No such file or directory when pip install cryptography | 40,038,134 | <p>I wanna set up scrapy cluster follow this link <a href="http://scrapy-cluster.readthedocs.io/en/latest/topics/introduction/quickstart.html#cluster-quickstart" rel="nofollow">scrapy-cluster</a>,Everything is ok before I run this command:</p>
<pre><code>pip install -r requirements.txt
</code></pre>
<p>The requiremen... | -1 | 2016-10-14T08:09:51Z | 40,040,895 | <p>I have solved it by myself. for the default python of centos, there is only a file named pyconfg-64.h in usr/include/python2.7/,So run the command</p>
<pre><code>yum install python-devel
</code></pre>
<p>Then it works.</p>
| 1 | 2016-10-14T10:25:55Z | [
"python",
"cryptography",
"centos",
"scrapy",
"pip"
] |
Pandas: timestamp to datetime | 40,038,169 | <p>I have dataframe and column with dates looks like</p>
<pre><code> date
1476329529
1476329530
1476329803
1476329805
1476329805
1476329805
</code></pre>
<p>I use <code>df['date'] = pd.to_datetime(df.date, format='%Y-%m-%d %H:%M:%S')</code>
to convert that, but I'm get strange result</p>
<pre><cod... | 1 | 2016-10-14T08:12:02Z | 40,038,277 | <p>Something like this maybe:</p>
<pre><code>import datetime
date = datetime.datetime.fromtimestamp(1476329529)
date
# gives
# datetime.datetime(2016, 10, 13, 5, 32, 9)
str(date) # '2016-10-13 05:32:09'
</code></pre>
| 1 | 2016-10-14T08:16:07Z | [
"python",
"datetime",
"pandas"
] |
Pandas: timestamp to datetime | 40,038,169 | <p>I have dataframe and column with dates looks like</p>
<pre><code> date
1476329529
1476329530
1476329803
1476329805
1476329805
1476329805
</code></pre>
<p>I use <code>df['date'] = pd.to_datetime(df.date, format='%Y-%m-%d %H:%M:%S')</code>
to convert that, but I'm get strange result</p>
<pre><cod... | 1 | 2016-10-14T08:12:02Z | 40,038,308 | <p>This looks look epoch timestamps which is number of seconds since 1st January 1970 :</p>
<pre><code>In [71]:
pd.to_datetime(df['date'], unit='s')
â
Out[71]:
0 2016-10-13 03:32:09
1 2016-10-13 03:32:10
2 2016-10-13 03:36:43
3 2016-10-13 03:36:45
4 2016-10-13 03:36:45
5 2016-10-13 03:36:45
Name: date, d... | 2 | 2016-10-14T08:17:25Z | [
"python",
"datetime",
"pandas"
] |
How do I write web-scraped text into csv using python? | 40,038,175 | <p>I've been working on a practice web-scraper that gets written reviews and writes them to a csv file, with each review given its own row. I've been having trouble with it as:</p>
<ol>
<li>I can't seem to <strong>strip out the html</strong> and get only the text (i.e. the written review and nothing else)</li>
<li>The... | 0 | 2016-10-14T08:12:20Z | 40,109,064 | <p>You can use <code>row.get_text(strip=True)</code> to get the text from your selected <code>p.partial_entry</code>. Try the following:</p>
<pre><code>import bs4, os, requests, csv
# Get URL of the page
URL = ('https://www.tripadvisor.com/Attraction_Review-g294265-d2149128-Reviews-Gardens_by_the_Bay-Singapore.html')... | 0 | 2016-10-18T13:02:57Z | [
"python",
"csv",
"web-scraping",
"beautifulsoup"
] |
Invalid datetime format in python-mysql query | 40,038,181 | <p>I wanted to fetch a record from database which is having the <code>datetime</code> field a part of primary key. I am querying from <code>python</code> using <code>mysqldb package</code> which is resulting in error </p>
<blockquote>
<p>Invalid datetime format</p>
</blockquote>
<p>wherein the same query is working... | 0 | 2016-10-14T08:12:35Z | 40,038,274 | <p>Date format should be</p>
<pre><code>'2016-09-08 00:00:00'
</code></pre>
<p>if you need to set time zone, you need a separate SQL query</p>
<pre><code>set time_zone='+00:00';
</code></pre>
<p>See also: <a href="http://stackoverflow.com/questions/930900/how-to-set-time-zone-of-mysql">How to set time zone of mysq... | 0 | 2016-10-14T08:16:02Z | [
"python",
"mysql",
"python-2.7",
"datetime"
] |
Python - Guess Who game - Im not getting my expected output | 40,038,231 | <p>This is a small portion of my guess who game im developing that assigns the AI Opponents randomly chosen character with its linked features, and assigns those features to the feature variables. When the user asks the question the if statements will respond with a yes or no based on whether it has the features asked ... | 0 | 2016-10-14T08:14:21Z | 40,038,413 | <p>You're not <em>assigning</em> inside the conditional name check bit:</p>
<pre><code>AIChoiceFeatureHairLength == "Short"
</code></pre>
<p>should be:</p>
<pre><code>AIChoiceFeatureHairLength = "Short"
</code></pre>
<p>Also - I would seriously think about reading up a bit on Object-Oriented Programming. If you mak... | 1 | 2016-10-14T08:23:51Z | [
"python",
"output"
] |
Python - Guess Who game - Im not getting my expected output | 40,038,231 | <p>This is a small portion of my guess who game im developing that assigns the AI Opponents randomly chosen character with its linked features, and assigns those features to the feature variables. When the user asks the question the if statements will respond with a yes or no based on whether it has the features asked ... | 0 | 2016-10-14T08:14:21Z | 40,039,408 | <p><code>AIChoiceFeatureHairLength == "Short"</code> is a conditional statement, it will evaluate to either <code>True</code>or <code>False</code>. </p>
<p>What you want to do is a assignement like this: <code>AIChoiceFeatureHairLength = "Short"</code></p>
<p>I would also recomment using dictionaries like:</p>
<pre>... | 0 | 2016-10-14T09:16:14Z | [
"python",
"output"
] |
select identical entries in two pandas dataframe | 40,038,255 | <p>I have two dataframes. (a,b,c,d ) and (i,j,k) are the name columns dataframes</p>
<pre><code>df1 =
a b c d
0 1 2 3
0 1 2 3
0 1 2 3
df2 =
i j k
0 1 2
0 1 2
0 1 2
</code></pre>
<p>I want to select the entries that df1 is df2
I want to obtain</p>
<pre><code> df1=
... | 0 | 2016-10-14T08:15:22Z | 40,038,717 | <p>Doing a column-wise comparison would give the desired result:</p>
<pre><code>df1 = df1[(df1.a == df2.i) & (df1.b == df2.j) & (df1.c == df2.k)][['a','b','c']]
</code></pre>
<p>You get only those rows from <code>df1</code> where the values of the first three columns are identical to those of <code>df2</code>... | 0 | 2016-10-14T08:38:50Z | [
"python",
"pandas",
"dataframe"
] |
select identical entries in two pandas dataframe | 40,038,255 | <p>I have two dataframes. (a,b,c,d ) and (i,j,k) are the name columns dataframes</p>
<pre><code>df1 =
a b c d
0 1 2 3
0 1 2 3
0 1 2 3
df2 =
i j k
0 1 2
0 1 2
0 1 2
</code></pre>
<p>I want to select the entries that df1 is df2
I want to obtain</p>
<pre><code> df1=
... | 0 | 2016-10-14T08:15:22Z | 40,038,777 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.isin.html" rel="nofollow"><code>isin</code></a> for compare <code>df1</code> with each column of <code>df2</code>:</p>
<pre><code>dfs = []
for i in range(len(df2.columns)):
df = df1.isin(df2.iloc[:,i])
dfs.append(df)... | 1 | 2016-10-14T08:42:31Z | [
"python",
"pandas",
"dataframe"
] |
Create output in Array list | 40,038,257 | <p>An example of my input is:</p>
<pre><code>3->0 0->1 1->2 2->3
</code></pre>
<p>I need to produce output in an array list </p>
<pre><code>{3,0,1,2}
</code></pre>
<p>How can I achieve this?</p>
| -2 | 2016-10-14T08:15:25Z | 40,038,735 | <p>If you want the numbers located before the "arrows" (<code>-></code>), here is a solution using <a href="https://docs.python.org/3/library/re.html" rel="nofollow"><code>re</code></a> :</p>
<pre><code>>>> list(map(int, re.findall('[0-9](?=->)', '3->0 0->1 1->2 2->3')))
[3, 0, 1, 2]
</code>... | 0 | 2016-10-14T08:40:24Z | [
"python"
] |
Data buffering/storage - Python | 40,038,258 | <p>I am writing an embedded application that reads data from a set of sensors and uploads to a central server. This application is written in Python and runs on a Rasberry Pi unit. </p>
<p>The data needs to be collected every 1 minute, however, the Internet connection is unstable and I need to buffer the data to a non... | 0 | 2016-10-14T08:15:28Z | 40,038,345 | <p>This is only database work. You can create a master and slave databases in different locations and if one is not on the network, will run with the last synched info.</p>
<p>And when the connection came back hr merge all the data.</p>
<p>Take a look in this <a href="http://stackoverflow.com/questions/2366018/how-to... | -1 | 2016-10-14T08:19:58Z | [
"python",
"offline",
"buffering"
] |
Data buffering/storage - Python | 40,038,258 | <p>I am writing an embedded application that reads data from a set of sensors and uploads to a central server. This application is written in Python and runs on a Rasberry Pi unit. </p>
<p>The data needs to be collected every 1 minute, however, the Internet connection is unstable and I need to buffer the data to a non... | 0 | 2016-10-14T08:15:28Z | 40,038,445 | <p>If you mean a module to work with SQLite database, check out <a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a>.</p>
<p>If you mean a module which can do what cron does, check out <a href="https://docs.python.org/3/library/sched.html" rel="nofollow">sched</a>, a python event scheduler.</p>
<p>Howev... | 0 | 2016-10-14T08:25:45Z | [
"python",
"offline",
"buffering"
] |
Data buffering/storage - Python | 40,038,258 | <p>I am writing an embedded application that reads data from a set of sensors and uploads to a central server. This application is written in Python and runs on a Rasberry Pi unit. </p>
<p>The data needs to be collected every 1 minute, however, the Internet connection is unstable and I need to buffer the data to a non... | 0 | 2016-10-14T08:15:28Z | 40,038,789 | <blockquote>
<p>Is there a python module that can be used for such feature? </p>
</blockquote>
<p>I'm not aware of any readily available module, however it should be quite straight forward to build one. Given your requirement:</p>
<blockquote>
<p>the Internet connection is unstable and I need to buffer the data t... | 0 | 2016-10-14T08:43:10Z | [
"python",
"offline",
"buffering"
] |
Matplotlib : single line chart with different markers | 40,038,470 | <p>I have a list for markers on my time series depicting a trade. First index in each each list of the bigger list is the index where i want my marker on the line chart. Now I want a different marker for buy and sell</p>
<pre><code>[[109, 'sell'],
[122, 'buy'],
[122, 'sell'],
[127, 'buy'],
[131, 'sell'],
[142, 'b... | 0 | 2016-10-14T08:26:54Z | 40,038,728 | <p>Create two new arrays, one buy-array and one sell-array and plot them individually, with different markers. To create the two arrays you can use list-comprehension</p>
<pre><code>buy = [x[0] for x in your_array if x[1]=='buy']
sell = [x[0] for x in your_array if x[1]=='sell']
</code></pre>
| 0 | 2016-10-14T08:39:48Z | [
"python",
"matplotlib",
"time-series"
] |
I have a numpy array, and an array of indexs, how can I access to these positions at the same time | 40,038,557 | <p>for example, I have the numpy arrays like this</p>
<pre><code>a =
array([[1, 2, 3],
[4, 3, 2]])
</code></pre>
<p>and index like this to select the max values</p>
<pre><code>max_idx =
array([[0, 2],
[1, 0]])
</code></pre>
<p>how can I access there positions at the same time, to modify them.
like "a... | 1 | 2016-10-14T08:31:36Z | 40,038,640 | <p>Simply use <code>subscripted-indexing</code> -</p>
<pre><code>a[max_idx[:,0],max_idx[:,1]] = 0
</code></pre>
<p>If you are working with higher dimensional arrays and don't want to type out slices of <code>max_idx</code> for each axis, you can use <code>linear-indexing</code> to assign <code>zeros</code>, like so -... | 1 | 2016-10-14T08:35:57Z | [
"python",
"arrays",
"numpy"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.