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
list(set) for nested lists?
37,536,419
<p>I am currently working on a module that will compute the angle between a vector and the normal of a plane.</p> <p>Anyhow to satisfy the conditions of computing the normal to the plane, I need 3 points in R3.</p> <p>I have found a way to do this by converting the list elements to strings, however this complicates t...
0
2016-05-31T03:37:07Z
37,536,504
<p>In case that you want to get all the lists with three or more instances and preserve the ordering you can use <a href="https://docs.python.org/3.5/library/collections.html#collections.OrderedDict" rel="nofollow"><code>OrderedDict</code></a> where keys are tuples and values are counts:</p> <pre><code>from collection...
0
2016-05-31T03:47:32Z
[ "python", "math" ]
Assigning a named Colormap / palette across different seaborn or matplotlib plots
37,536,478
<p>I have the following dummy data.</p> <pre><code>import seaborn as sb import pandas as pd import matplotlib.pyplot as pet # Generate dummy data a = np.random.random(70) b = np.random.random(70) * 1.2 c = np.random.random(70) * 0.5 + 0.5 d = np.random.random(70) * 1.2 - 0.2 # Collate into a DataFrame df = pd.DataFr...
0
2016-05-31T03:44:01Z
37,536,893
<p>You can pass a dictionary:</p> <pre><code>pal = dict(Control="k", Group1="b", Group2="g", Group3="r") sns.swarmplot(..., palette=pal) </code></pre>
1
2016-05-31T04:34:12Z
[ "python", "matplotlib", "ipython", "seaborn" ]
Django Help: Resolving NOT NULL constraint failed error with CreateView
37,536,577
<p>I am new to stackoverflow, python and Django, have a question on the '(NOT NULL constraint failed: sixerrapp_gig.user_id)' error I am getting when i click submit on the form. </p> <p>Pretty sure it is because I have not assigned a user_id value from what I have found on StackOverflow thus far, but I am not sure how...
4
2016-05-31T03:56:26Z
37,536,665
<p>You need to handle that in <code>form_valid()</code> method of the view.</p> <pre><code>class CreateGig(CreateView): model = Gig fields = ['title','category','description','price','photo','status'] def form_valid(self, form): form.instance.user = self.request.user return super(Creat...
4
2016-05-31T04:08:33Z
[ "python", "django", "create-view" ]
python run ImportError:No module named
37,536,832
<p><a href="http://i.stack.imgur.com/GqWSt.png" rel="nofollow"><img src="http://i.stack.imgur.com/GqWSt.png" alt="This is my project structure"></a></p> <p>This is my project structure. I use virtualenv in my project but when I run it ,it has an ImportError.I use <strong>Mac</strong>. <a href="http://i.stack.imgur.com...
0
2016-05-31T04:27:30Z
37,537,067
<p>Your issue is that you are requesting <code>create_config</code>, which is located too far up in the directory structure. I also don't understand why you are requesting files that way, due to the fact that they are located in the directory that <code>handler.py</code> is in. I would just type.</p> <pre><code>import...
-1
2016-05-31T04:52:59Z
[ "python" ]
python run ImportError:No module named
37,536,832
<p><a href="http://i.stack.imgur.com/GqWSt.png" rel="nofollow"><img src="http://i.stack.imgur.com/GqWSt.png" alt="This is my project structure"></a></p> <p>This is my project structure. I use virtualenv in my project but when I run it ,it has an ImportError.I use <strong>Mac</strong>. <a href="http://i.stack.imgur.com...
0
2016-05-31T04:27:30Z
37,539,019
<p>PyCharm automatically adds project directories marked as containing sources to the <code>PYTHONPATH</code> environment variable, whihc is why it works from within pycharm. On the terminal use</p> <pre><code>PYTHONPATH=${PWD}/..:${PYTHONPATH} python handler.py </code></pre>
0
2016-05-31T07:06:17Z
[ "python" ]
python run ImportError:No module named
37,536,832
<p><a href="http://i.stack.imgur.com/GqWSt.png" rel="nofollow"><img src="http://i.stack.imgur.com/GqWSt.png" alt="This is my project structure"></a></p> <p>This is my project structure. I use virtualenv in my project but when I run it ,it has an ImportError.I use <strong>Mac</strong>. <a href="http://i.stack.imgur.com...
0
2016-05-31T04:27:30Z
37,539,309
<p>You can use explicit relative imports:</p> <pre><code>from .modules import db, json_parse, config_out </code></pre> <p>The proper way to do this is to turn your project into a proper Python package by adding a <code>setup.py</code> file and then installing it with <code>pip install -e .</code></p>
0
2016-05-31T07:22:03Z
[ "python" ]
python run ImportError:No module named
37,536,832
<p><a href="http://i.stack.imgur.com/GqWSt.png" rel="nofollow"><img src="http://i.stack.imgur.com/GqWSt.png" alt="This is my project structure"></a></p> <p>This is my project structure. I use virtualenv in my project but when I run it ,it has an ImportError.I use <strong>Mac</strong>. <a href="http://i.stack.imgur.com...
0
2016-05-31T04:27:30Z
37,542,639
<p>probably because PyCharm added your project folder to the <a href="http://stackoverflow.com/questions/17198319/how-to-configure-custom-pythonpath-with-vm-and-pycharm"><code>PythonPath</code></a>, so you can run you app inside PyCharm.</p> <p>However, when you try to run it from command line, python interpreter cann...
0
2016-05-31T10:03:24Z
[ "python" ]
Differences of where to put the variable: variable_name.upper( ) vs. len(variable_name)
37,536,842
<p>Why in the methods <code>len( )</code>, the placement of variables different from the others, for example the<code>upper( )</code></p> <pre><code># with len() len(variable_name) # with upper() variable_name.upper() </code></pre> <p>Things may be trivial , it makes me uncomfortable if do not know it ... thanks.</p...
0
2016-05-31T04:28:59Z
37,536,910
<p><code>variable_name.upper()</code> is calling a method of the <code>variable_name</code> class or an inherited class.</p> <p><code>len(variable_name)</code> is calling Python's built-in <code>len</code> function on a <code>variable_name</code> object for which the <code>len</code> function determines the length dep...
0
2016-05-31T04:36:06Z
[ "python", "string", "function", "methods", "formatting" ]
Why are the "normal" methods for generating random integers so slow?
37,536,868
<p>Not a maths major or a cs major, I just fool around with python (usually making scripts for simulations/theorycrafting on video games) and I discovered just how bad random.randint is performance wise. It's got me wondering why random.randint or random.randrange are used/made the way they are. I made a function that ...
4
2016-05-31T04:31:32Z
37,539,910
<p>This is probably rarely a problem but <code>randint(0,10**1000)</code> works while <code>fastrandint(0,10**1000)</code> crashes. The slower time is probably the price you need to pay to have a function that works for all possible cases...</p>
0
2016-05-31T07:51:30Z
[ "python", "performance", "random" ]
Why are the "normal" methods for generating random integers so slow?
37,536,868
<p>Not a maths major or a cs major, I just fool around with python (usually making scripts for simulations/theorycrafting on video games) and I discovered just how bad random.randint is performance wise. It's got me wondering why random.randint or random.randrange are used/made the way they are. I made a function that ...
4
2016-05-31T04:31:32Z
37,540,299
<p><code>random.randint()</code> and others are calling into <code>random.getrandbits()</code> which may be less efficient that direct calls to <code>random()</code>, but for good reason. </p> <p>It is actually more correct to use a <code>randint</code> that calls into <code>random.getrandbits()</code>, as it can be d...
2
2016-05-31T08:12:54Z
[ "python", "performance", "random" ]
Why are the "normal" methods for generating random integers so slow?
37,536,868
<p>Not a maths major or a cs major, I just fool around with python (usually making scripts for simulations/theorycrafting on video games) and I discovered just how bad random.randint is performance wise. It's got me wondering why random.randint or random.randrange are used/made the way they are. I made a function that ...
4
2016-05-31T04:31:32Z
37,540,577
<p><a href="https://hg.python.org/cpython/file/3.5/Lib/random.py#l214" rel="nofollow"><code>randint</code></a> calls <a href="https://hg.python.org/cpython/file/3.5/Lib/random.py#l170" rel="nofollow"><code>randrange</code></a> which does a bunch of range/type checks and conversions and then uses <a href="https://hg.pyt...
2
2016-05-31T08:27:25Z
[ "python", "performance", "random" ]
how to call columns/row in python
37,536,890
<p>I need to call/retrieve some specific columns in a row of a dataset using the number (not the names of the columns). what is the best way to do this? My code is:</p> <pre><code>with open('collected_quotes_total_chunk2.csv', 'rb') as quote_sample: quote_database = csv.DictReader(quote_sample) to_db =...
1
2016-05-31T04:33:56Z
37,536,948
<p>Use a <a href="https://docs.python.org/3/library/csv.html#csv.reader" rel="nofollow">reader</a>, instead of <a href="https://docs.python.org/3/library/csv.html#csv.DictReader" rel="nofollow">DictReader</a>, to read the row as an array.</p>
0
2016-05-31T04:41:10Z
[ "python" ]
Shuffle elements in a string and get all the possible arrangements
37,536,896
<p>This is what I want to do, when given a list, I want to shuffle the elements in the list and get all the possible combinations of elements in that list. E.g. given a list as shown below,</p> <pre><code> Ben went to the shop </code></pre> <p>so listing and printing all the possible combinations,</p> <pre><code>...
-1
2016-05-31T04:34:26Z
37,536,923
<pre><code>&gt;&gt;&gt; s="Ben went to the shop" &gt;&gt;&gt; L=s.split() &gt;&gt;&gt; import itertools &gt;&gt;&gt; print('\n'.join(' '.join(i) for i in list(itertools.permutations(L)))) Ben went to the shop Ben went to shop the Ben went the to shop Ben went the shop to Ben went shop to the Ben went shop the to Ben to...
0
2016-05-31T04:38:10Z
[ "python", "string", "random" ]
Shuffle elements in a string and get all the possible arrangements
37,536,896
<p>This is what I want to do, when given a list, I want to shuffle the elements in the list and get all the possible combinations of elements in that list. E.g. given a list as shown below,</p> <pre><code> Ben went to the shop </code></pre> <p>so listing and printing all the possible combinations,</p> <pre><code>...
-1
2016-05-31T04:34:26Z
37,536,946
<p>Let's say you have a string <code>text</code> with your string inside. To implement <code>itertools</code> into this, you just need to <code>.split()</code> it by whitespace, then <code>.join()</code> them back with whitespace.</p> <p>If you are having any trouble with <code>itertools</code> in the future, just rem...
0
2016-05-31T04:40:26Z
[ "python", "string", "random" ]
Shuffle elements in a string and get all the possible arrangements
37,536,896
<p>This is what I want to do, when given a list, I want to shuffle the elements in the list and get all the possible combinations of elements in that list. E.g. given a list as shown below,</p> <pre><code> Ben went to the shop </code></pre> <p>so listing and printing all the possible combinations,</p> <pre><code>...
-1
2016-05-31T04:34:26Z
37,537,002
<p>This ought to do it:</p> <pre><code>string = "Ben went to the shop".split() res = [] while len(res) &lt; factorial(len(string)): temp = create_random(string) if temp not in res: res.append(temp) print(res) </code></pre>
0
2016-05-31T04:45:54Z
[ "python", "string", "random" ]
Checking Pygame Version
37,536,936
<p>I'm very new to both Python and Pygame. I have <strong><em>Python 3.5.1 32-bits</em></strong> installed on Window and <strong><em>Pygame 1.9.2 Python 3.5</em></strong> installed as well. But in case if i forget, is there a way to check the pygame version I have installed from either command line or Python IDLE.</p> ...
0
2016-05-31T04:38:58Z
37,537,039
<p>Use this: <code>pip show &lt;pack_name&gt;</code></p> <p>Alternative:</p> <pre><code>pip freeze | grep &lt;pack_name&gt; </code></pre>
2
2016-05-31T04:48:36Z
[ "python", "python-3.x", "pygame" ]
How to read a csv file, individually for further processing
37,536,983
<p>I am trying to read a csv file line by line. But it's proving to be a bit more difficult then first anticipated.</p> <p><strong>The Code:</strong></p> <pre><code>#!/usr/bin/env python import glob import os file_dir=os.getcwd() files_2=glob.glob(file_dir) m_class="ABC" m_id="123" device=m_class+"-"+m_id with op...
1
2016-05-31T04:44:43Z
37,537,012
<p>Use the <a href="https://docs.python.org/3/library/csv.html" rel="nofollow">csv</a> module. Create a <a href="https://docs.python.org/3/library/csv.html#csv.reader" rel="nofollow">reader</a> to parse the file and a <a href="https://docs.python.org/3/library/csv.html#csv.writer" rel="nofollow">writer</a> to write the...
0
2016-05-31T04:46:44Z
[ "python", "csv" ]
How to read a csv file, individually for further processing
37,536,983
<p>I am trying to read a csv file line by line. But it's proving to be a bit more difficult then first anticipated.</p> <p><strong>The Code:</strong></p> <pre><code>#!/usr/bin/env python import glob import os file_dir=os.getcwd() files_2=glob.glob(file_dir) m_class="ABC" m_id="123" device=m_class+"-"+m_id with op...
1
2016-05-31T04:44:43Z
37,537,058
<p>The problem here is with this code:</p> <pre><code>counter=1 with open('output_temp.csv', 'r') as f: content = f.readlines() print "Line: " + str(counter) + " data: " + str(content) counter=counter+1 </code></pre> <p><code>content</code> here is a list with all the lines. Iterate through <code>content...
0
2016-05-31T04:51:18Z
[ "python", "csv" ]
How to read a csv file, individually for further processing
37,536,983
<p>I am trying to read a csv file line by line. But it's proving to be a bit more difficult then first anticipated.</p> <p><strong>The Code:</strong></p> <pre><code>#!/usr/bin/env python import glob import os file_dir=os.getcwd() files_2=glob.glob(file_dir) m_class="ABC" m_id="123" device=m_class+"-"+m_id with op...
1
2016-05-31T04:44:43Z
37,537,074
<p>Using the csv module in python you could do this easily. The example below prints the csv file line by line. </p> <pre><code>import csv import os os.chdir("/Users/xaviermerino/Desktop") with open('csvExample.csv') as csvFile: reader = csv.reader(csvFile) for row in reader: print row[0] </code></pr...
0
2016-05-31T04:53:18Z
[ "python", "csv" ]
Configure event profile in pyalgotrade to look back further than one bar ( eg bards[-2] )
37,536,998
<p>I'm trying to write various predicates on simple candle stick structures. For example one component of a '3 green candles in a row' predicate would require a look back of -4 <p>To start off simple I try an test it with a 'higher_highs' predicate. If the close of the previous candle is below the current candles clos...
0
2016-05-31T04:45:33Z
37,558,394
<p>The problem is that on the first call to eventOccurred bards only has one item, so trying to do bards[-2] will fail. Check the length of bards first.</p>
0
2016-06-01T02:18:30Z
[ "python", "trading", "algorithmic-trading", "pyalgotrade" ]
Django cycle into template ,ORM
37,537,079
<p>I have a django view and a make a render html to return a ORM query some as </p> <pre><code>products.objects.all() return render(request,'index.html',{"product":products}) </code></pre> <p>I can make a render correctly from html page using a for cycle , the query of products this return a code and product's quant...
0
2016-05-31T04:53:31Z
37,537,208
<p>You're attempting to treat Django's template language as if it's an <code>eval</code>, and your variable <code>{{product.quantity}}</code> will be replaced with an integer, resulting in your statement <code>for a in range(x)</code> being executed.</p> <p>That's incorrect.</p> <p>Django's template language is not P...
1
2016-05-31T05:05:10Z
[ "python", "django", "django-templates", "django-views", "django-orm" ]
Unittest - Test for dict equality
37,537,087
<p>I am trying to do a unit-test but don't quite get why these 2 dicts show up as not equal. I was wondering if someone could give me an explanation for this occurrence. My code is...</p> <pre><code>import unittest class TestEmailValidator(unittest.TestCase): def test(self): known_dict = { 'd...
2
2016-05-31T04:53:59Z
37,537,181
<p>You are misusing the assert. All the <code>assertXYZ</code> methods don't return a boolean value, they just raise an exception if the assertion fails. As these methods don't return anything, they implicitly return <code>None</code>. When evaluating <code>None</code> as a boolean it's treated as false, and hence your...
0
2016-05-31T05:02:48Z
[ "python", "python-2.7", "unit-testing", "dictionary" ]
Using Mypy local stubs
37,537,194
<p>I am trying the typing hint introduced by Python 3.5 and got a problem by using local stubs as the typing hint with mypy.</p> <p>The experiment I do is to creat kk.py containing </p> <pre><code>def type_check(a): pass </code></pre> <p>Also, I put kk.pyi containing </p> <pre><code>def type_check(a: int):... <...
1
2016-05-31T05:03:28Z
37,805,107
<p>I do not know why someone have voted down this question without answering it or commenting about why he/she disliked it, but here is the answer I figured out:</p> <p>The stub file of mypy only works when importing a module. Thus, if you have </p> <pre><code>def try_check(a): pass </code></pre> <p>in kk.py, an...
2
2016-06-14T07:04:48Z
[ "python", "mypy" ]
Accessing global cursor from within function
37,537,198
<p>This works okay (some code ommited for brevity):</p> <pre><code># main.py cursor = db.cursor() cursor.execute('foo') </code></pre> <p>As does this:</p> <pre><code># other.py def do_something(script, cursor): cursor.execute(script) # main.py from other import do_something cursor = db.cursor() do_something('foo'...
0
2016-05-31T05:04:05Z
37,538,144
<p>try this code</p> <pre><code># other.py def do_something(script): global cursor cursor.execute(script) # main.py from other import do_something import other other.cursor = db.cursor() do_something(script) </code></pre> <p>My English is not good, so you can read these answers</p> <ul> <li><strong><a href=...
0
2016-05-31T06:16:59Z
[ "python", "python-2.7", "mysql-python" ]
Why pygame screen won´t refresh until I move the window arround?
37,537,327
<p>I´m a newbie on pygame, and i have this code for trying to do kind of a startscreen for a football game, this start screen has a static background image that is"img_start_screen" and the logo of the game that I want it to have a little animation that stops when it reaches the certain point on the screen, that logo ...
1
2016-05-31T05:17:19Z
37,586,473
<p>As you know pygame.display.update is a function as seen if you print it:</p> <pre><code>&gt;&gt;&gt; print pygame.display.update &lt;built-in function update&gt; </code></pre> <p>so when you call pygame.display.update without parenthesis () you are merely stating a reference to a function. Whereas if you use paren...
0
2016-06-02T08:27:06Z
[ "python", "pygame" ]
Access Pandas Data Frame row with index value
37,537,343
<p>I have a very simple Pandas Data Frame with one index (of type <code>TimedeltaIndex</code>) and one column named <code>TotalVolume</code>.</p> <pre><code>&gt;&gt; print(df) TotalVolume ... 09:00:00 143846.153846 09:05:00 84353.846154 09:10:00 46946.153846 09:15:00 46765.384615 09:20:00 53076.923077...
1
2016-05-31T05:18:27Z
37,537,379
<p>For me works <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.loc.html" rel="nofollow"><code>loc</code></a>:</p> <pre><code>print (df) TotalVolume 09:00:00 143846.153846 09:05:00 84353.846154 09:10:00 46946.153846 09:15:00 46765.384615 09:20:00 53076.923077 09:25:...
1
2016-05-31T05:21:48Z
[ "python", "pandas", "indexing", "dataframe", "timedelta" ]
Passing On Values Between Functions
37,537,354
<p>Hi i'm working on a program where a user selects an image, then it gets turned into an ASCII version of the picture, which displays in both the console and then gets saved to a notepad .txt file. The code below currently does this but I think the way I am using my returns in the functions is messing up the code. Ins...
-2
2016-05-31T05:19:53Z
37,537,483
<p>Call the inputs function only once, and store that everywhere. This ensures that the user will be asked for input only once:</p> <pre><code>def inputs(): image = input('What image file?') return (image) def pictureConvert(): a = inputs() # codefollows </code></pre>
1
2016-05-31T05:31:31Z
[ "python" ]
openpyxl _external_links too slow
37,537,393
<p>I need to read a excel and get the external_books the excel used(for there is INDEX or VLOOKUP func used in the excel)</p> <p>I choose openpyxl,the openpyxl.WorkBook._external_links api can do it well,but the speed is too slow(my excel is 600KB),about 27s</p> <p>here is my code:</p> <pre><code>wb=openpy...
-1
2016-05-31T05:23:20Z
37,537,856
<p>Try "read_only=True" option it should reduce time.</p>
0
2016-05-31T05:59:02Z
[ "python", "excel", "xlrd", "openpyxl" ]
How do I transition a quotation from "Draft" to "Sent" after print?
37,537,450
<p>I have a custom report for Quotations and would like to, on print (generating PDF), transit the quotation from the "Draft" to "Sent" state. How can I achieve this?</p> <p>Report was written by predecessor in RML. I tried adding a write method to change the state but to no avail:</p> <pre><code>import time from ope...
0
2016-05-31T05:28:52Z
37,558,820
<p>Found a workaround by using additional buttons on the form page instead. Note 'sale.order.my_quotation' is the custom report that was previously created.</p> <ol> <li><p>my_sale.py</p> <p>from openerp.osv import osv, fields</p> <p>class my_sale_order(osv.osv):</p> <pre><code>_inherit = 'sale.order' def print_qu...
0
2016-06-01T03:17:37Z
[ "python", "report", "openerp", "odoo-8" ]
python - Change python to /usr/local/bin/python?
37,537,596
<p>I'm trying to install <code>opencv</code> using <code>python2.7</code>. </p> <p>When I use <code>brew install python</code>. I got</p> <blockquote> <p>Warning: python-2.7.11 already installed, it's just not linked</p> </blockquote> <p>And then I run <code>brew link python</code> and <code>brew install python</c...
0
2016-05-31T05:38:56Z
37,538,059
<p>Did you try closing your terminal session and then open a new one? <code>~/.bash_profile</code> is only picked up when bash is executed as a login shell, which is the default for Terminal.app when you open a new terminal window. Or you can do <code>source ~/.bash_profile</code> if you do not want to close the termin...
0
2016-05-31T06:11:24Z
[ "python", "osx", "python-2.7", "opencv" ]
How to map a function to every item in every sublist of a list
37,537,609
<p>Is there a way to do this without using a regular for loop to iterate through the main list? </p> <pre><code>&gt;&gt;&gt; map(lambda x: x*2, [[1,2,3],[4,5,6]]) [[1, 2, 3, 1, 2, 3], [4, 5, 6, 4, 5, 6]] # want [[2,4,6],[8,10,12]] </code></pre>
3
2016-05-31T05:39:53Z
37,537,652
<p>You have nested lists, and <code>x</code> represents just one of the lists. To process that, you need to actually map the multiplication function on to the individual elements of <code>x</code>, like this</p> <pre><code>&gt;&gt;&gt; map(lambda x: map(lambda y: y * 2, x), [[1, 2, 3], [4, 5, 6]]) [[2, 4, 6], [8, 10, ...
11
2016-05-31T05:43:51Z
[ "python", "list", "python-2.7" ]
How to map a function to every item in every sublist of a list
37,537,609
<p>Is there a way to do this without using a regular for loop to iterate through the main list? </p> <pre><code>&gt;&gt;&gt; map(lambda x: x*2, [[1,2,3],[4,5,6]]) [[1, 2, 3, 1, 2, 3], [4, 5, 6, 4, 5, 6]] # want [[2,4,6],[8,10,12]] </code></pre>
3
2016-05-31T05:39:53Z
37,539,482
<p>Alternative solution would be to go for numpy vectorized operations:</p> <pre><code>import numpy as np ll = [[1,2,3],[4,5,6]] (2*np.array(ll)).tolist() #Out[6]: [[2, 4, 6], [8, 10, 12]] </code></pre>
3
2016-05-31T07:30:28Z
[ "python", "list", "python-2.7" ]
How to map a function to every item in every sublist of a list
37,537,609
<p>Is there a way to do this without using a regular for loop to iterate through the main list? </p> <pre><code>&gt;&gt;&gt; map(lambda x: x*2, [[1,2,3],[4,5,6]]) [[1, 2, 3, 1, 2, 3], [4, 5, 6, 4, 5, 6]] # want [[2,4,6],[8,10,12]] </code></pre>
3
2016-05-31T05:39:53Z
37,652,749
<p>This is a bit overkill and not too practical for this particular example, but another stylistic option could be to use <a href="https://docs.python.org/2/library/functools.html#functools.partial" rel="nofollow"><code>functools.partial</code></a> to make it very clear what is happening and a combination of <code>map<...
0
2016-06-06T08:27:10Z
[ "python", "list", "python-2.7" ]
Convert BASH script to Python
37,537,637
<p>my script:</p> <pre><code>#!/bin/bash #!/usr/bin/java JAVA=/usr/bin/java INDEXER=/home/indexer.jar for count in {79..129} do DIR=/media/MyBook/TS6/Ok/TSAnimShort/BTM000$count/*.ps for filenam in $DIR; do $JAVA -jar $INDEXER $filenam true done done </code></pre> <hr> <p>convert linux script to python script </p...
-6
2016-05-31T05:42:47Z
37,538,297
<pre><code>#!/usr/bin/python #!/usr/bin/java import os import subprocess JAVA='/usr/bin/java' INDEXER='/home/indexer.jar' for i in range(79,130): DIR='/media/MyBook/TS6/Ok/TSAnimShort/BTM000'+str(count)+'/' for root, directories, files in os.walk(DIR): for f in files: if f.endswith('.ps'): ...
0
2016-05-31T06:26:05Z
[ "python", "linux" ]
How to fix LookupError?
37,537,643
<p>I want to get a symbol from Unicode database.</p> <p>After running this thing <em>(my terminal doesn't support Unicode characters, that's why I do it)</em>:</p> <pre><code>chcp 65001 </code></pre> <p>And this code:</p> <pre><code>print u"\N{GREEK CAPITAL LETTER DELTA}" </code></pre> <p>I get an error:</p> <pre...
-1
2016-05-31T05:43:01Z
37,537,994
<p>Use AutoRun Entry in the registry. Set AutoRun for the command chcp 65001.</p>
0
2016-05-31T06:07:26Z
[ "python", "python-2.7", "unicode", "error-handling" ]
Python: PyVisa with USB connection - > wait_for_srq() or wait_on_event?
37,537,927
<p>I'm trying to controlling to a USB instrument (Keithley 2450) using pyVisa but I get an error. I'm following the simple example on the <a href="http://pyvisa.readthedocs.io/en/master/example.html" rel="nofollow">pyVisa website</a></p> <p>I have a problem after I send a "service request"</p> <pre><code>keithley.wai...
1
2016-05-31T06:03:42Z
37,575,918
<p>I tried with my Pyvisa just now, it has the same problem as well. I'm currently using Pyvisa version <code>1.8</code>. </p> <p>I think it is due to that when you open the device, you used the <code>usb</code> interface<code>instead of the</code>gpib` interface. </p> <p>If you go to the source of <a href="http://py...
3
2016-06-01T18:10:31Z
[ "python", "usb", "visa" ]
Increment two variables in a loop with a relation between them
37,538,041
<p>I am trying to increment two different variables, in the same for loop or even in nested loops, these two variables are related, one should be less than the other by 10. </p> <p>Output should look something like this:</p> <p><strong>First Iteration:</strong></p> <blockquote> <p>Text1 &lt; First variable/number...
0
2016-05-31T06:10:38Z
37,538,239
<p>This appears to do what you want:</p> <pre><code>for i in xrange(200): print "Text%d" % (i) print "blah blah %d" % ((i//10) +1) </code></pre>
0
2016-05-31T06:22:14Z
[ "python", "loops" ]
giving more weight to a feature using sklearn svm
37,538,068
<p>I 'm using svm to predict the label from the title of a book. However I want to give more weight to some features pre defined. For example, if the title of the book contains words like <strong><em>fairy, Alice</em></strong> I want to label them as children's books. I'm using word n-gram svm. Please suggest how to ac...
1
2016-05-31T06:11:49Z
37,538,260
<p>You can create one more feature vector in your training data, if the name of the book contains your predefined words then make it one otherwise zero.</p>
0
2016-05-31T06:23:39Z
[ "python", "svm" ]
Pandas Inconsistent date-time format
37,538,080
<p>I started using pandas library about a fortnight back. Learning the new features. I would appreciate help on the following problem.</p> <p>I have a column with dates in mixed format. These are the 2 formats present</p> <ol> <li><code>mm/dd/yyyy</code></li> <li><code>dd/mm/yyyy</code></li> </ol> <p>An extract from...
2
2016-05-31T06:12:39Z
37,538,321
<p>The real problem is that there are ambiguous dates in your dataset (do you parse it as mm/dd/yyyy or dd/mm/yyyy if it could be either?? <em>(I've been here, and we decided just to pick what the majority seemed to be; essentially the dataset was compromised... and we had to treat it as such).</em></p> <hr> <p>If it...
1
2016-05-31T06:27:25Z
[ "python", "pandas", "string-to-datetime" ]
Pandas Inconsistent date-time format
37,538,080
<p>I started using pandas library about a fortnight back. Learning the new features. I would appreciate help on the following problem.</p> <p>I have a column with dates in mixed format. These are the 2 formats present</p> <ol> <li><code>mm/dd/yyyy</code></li> <li><code>dd/mm/yyyy</code></li> </ol> <p>An extract from...
2
2016-05-31T06:12:39Z
37,538,346
<p>I think it is impossible distinguish in some dates e.g. between <code>6/5/2016</code> and <code>5/6/2016</code> - you get ambiguous dates.</p> <p>But maybe is possible theoretically use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow"><code>to_datetime</code></a...
0
2016-05-31T06:29:03Z
[ "python", "pandas", "string-to-datetime" ]
How to sort out first row in a list
37,538,116
<p>I would like to sort out the first row of a given list. I've been already tried to use python "replace" to remove the second row. But the problem is that the replace function seems not work at all. Here is the regular expression I used: replace(r'^ //.*$','')</p> <p>Here is the list:</p> <pre><code>//SA/... //shor...
-2
2016-05-31T06:15:29Z
37,538,375
<pre><code>l = ["1 12","3 12","2 12"] # space separated n = [x.split()[0] for x in l] print sorted(n) </code></pre>
0
2016-05-31T06:31:20Z
[ "python", "replace" ]
Python function returns pair of values
37,538,194
<p>I have seen the following python code:</p> <pre><code>W_grads, _ = backward_gradient(X, S, grad_out, wRec) </code></pre> <p>And in the function backward_gradient, I have the following return statement:</p> <pre><code>return (wx_grad, wRec_grad), grad_over_time </code></pre> <p>What exactly does the underscore re...
0
2016-05-31T06:19:18Z
37,538,237
<p><code>_</code> is just a variable. <code>backward_gradient</code> will return a tuple like this <code>((x,y),z)</code>, so the value of <code>z</code> or <code>grad_over_time</code> will go into the <code>_</code>. </p> <p>Yes, you're storing <code>(wx_grad,wRec_grad)</code> in <code>W_grads</code>.</p>
1
2016-05-31T06:22:11Z
[ "python", "function" ]
Python function returns pair of values
37,538,194
<p>I have seen the following python code:</p> <pre><code>W_grads, _ = backward_gradient(X, S, grad_out, wRec) </code></pre> <p>And in the function backward_gradient, I have the following return statement:</p> <pre><code>return (wx_grad, wRec_grad), grad_over_time </code></pre> <p>What exactly does the underscore re...
0
2016-05-31T06:19:18Z
37,538,245
<p>That function returns two values:</p> <ol> <li>A tuple containing two values: <code>(wx_grad, wRec_grad)</code></li> <li>Then the single value <code>grad_over_time</code></li> </ol> <p>This code:</p> <pre><code>W_grads, _ = backward_gradient(X, S, grad_out, wRec) </code></pre> <p>Assigns the tuple to <code>W_gra...
2
2016-05-31T06:22:39Z
[ "python", "function" ]
Python function returns pair of values
37,538,194
<p>I have seen the following python code:</p> <pre><code>W_grads, _ = backward_gradient(X, S, grad_out, wRec) </code></pre> <p>And in the function backward_gradient, I have the following return statement:</p> <pre><code>return (wx_grad, wRec_grad), grad_over_time </code></pre> <p>What exactly does the underscore re...
0
2016-05-31T06:19:18Z
37,538,615
<p>visit <a href="http://www.bogotobogo.com/python/python_if__name__equals__main__.php" rel="nofollow">http://www.bogotobogo.com/python/python_if__name__equals__main__.php</a> this may helps you to understand _ and __ in python</p>
0
2016-05-31T06:44:40Z
[ "python", "function" ]
Matplotlib: set x y label in one line
37,538,236
<p>If I want to set the x, y label of axises, I have to do something like this:</p> <pre><code>import matplotlib.pyplot as plt plt.plot([1,2,3,4]) plt.ylabel('This is y label') plt.xlabel('This is x label') plt.show() </code></pre> <p>I need to set <code>xlabel</code>, <code>ylabel</code> seperately.</p> <p>I'm wond...
1
2016-05-31T06:22:02Z
37,538,499
<p>Maybe this can help you</p> <pre><code>import matplotlib.pyplot as plt def grap_label(g, lx='',ly=''): plt.xlabel(lx) plt.ylabel(ly) plt.show() grap_label(plt.plot([1,2,3,4]), 'This is x label','This is y label') </code></pre>
1
2016-05-31T06:39:10Z
[ "python", "matplotlib" ]
Matplotlib: set x y label in one line
37,538,236
<p>If I want to set the x, y label of axises, I have to do something like this:</p> <pre><code>import matplotlib.pyplot as plt plt.plot([1,2,3,4]) plt.ylabel('This is y label') plt.xlabel('This is x label') plt.show() </code></pre> <p>I need to set <code>xlabel</code>, <code>ylabel</code> seperately.</p> <p>I'm wond...
1
2016-05-31T06:22:02Z
37,539,355
<p>Once you start using the object oriented model of matplotlib more often, you'll be able to add all relevant parameters of an axes as keywords to the functions that make these axes.</p> <p>A simple example:</p> <pre><code>fig = plt.figure() ax = fig.add_subplot(111, xlabel="time", ylabel="money") </code></pre> <p>...
4
2016-05-31T07:24:19Z
[ "python", "matplotlib" ]
Sending arguments to a program that is already open in Python 3
37,538,325
<p>What I am trying to do is better explained here: <a href="http://stackoverflow.com/questions/37560427/sending-to-the-stdin-of-a-program-in-python3">Sending to the stdin of a program in python3</a></p> <p>I am trying to send arguments to a program while it is open e.g:</p> <p>rec.py</p> <pre><code>import sys impor...
-2
2016-05-31T06:27:40Z
37,539,289
<p>That's not the way interprocess-communication works. You are mixing command line arguments with the standard input pipe.</p> <p>This will work:</p> <h3>rec.py:</h3> <pre><code>import sys import time arguments = list(sys.argv) while True: print(arguments) arguments.append(next(sys.stdin)) </code></pre> <...
0
2016-05-31T07:20:38Z
[ "python", "python-3.x", "subprocess", "communication", "popen" ]
Sending arguments to a program that is already open in Python 3
37,538,325
<p>What I am trying to do is better explained here: <a href="http://stackoverflow.com/questions/37560427/sending-to-the-stdin-of-a-program-in-python3">Sending to the stdin of a program in python3</a></p> <p>I am trying to send arguments to a program while it is open e.g:</p> <p>rec.py</p> <pre><code>import sys impor...
-2
2016-05-31T06:27:40Z
37,543,668
<p>You can't change the command-line arguments after the program has started i.e., <code>sys.argv</code> can be changed only from the inside (normally) of the process itself.</p> <p><code>Popen.communicate(input=data)</code> can send <code>data</code> to the child process via its standard input (if you pass <code>std...
1
2016-05-31T10:52:04Z
[ "python", "python-3.x", "subprocess", "communication", "popen" ]
Getting non-ascii string from server, using urllib2
37,538,337
<p>I use urllib2 to get a string from a server. I expect the string should be like this: </p> <pre><code>Bouteflika veut croire qu'il est un dirigeant hors du commun aimé de son peuple. </code></pre> <p>However, when I print it, it likes this:</p> <pre><code>Bouteflika veut croire qu'il est un dirigeant hors du co...
0
2016-05-31T06:28:19Z
37,538,414
<p>It depends on how the server sends the response.</p> <p>If the response is JSON for example then it will have double quotes around it and escaped characters.</p> <p>To decode that you need</p> <pre><code> import json result = json.loads(response_text) </code></pre> <p>and the resulting will directly be an unico...
0
2016-05-31T06:33:37Z
[ "python", "string", "unicode", "ascii", "urllib2" ]
Using Python to manipulate csv files: vlookup from another csv, insert columns, delete rows, loop
37,538,355
<p>I have 100 csv files, each contains publication data of different institutions and I would like to perform the same manipulation on all of them:</p> <p>1.Get the Institution name from cell B1. This is always after 'at' or 'at the'. For example 'Publications at Tohoku University' 2.Vlookup the matching InstitutionCo...
-1
2016-05-31T06:29:39Z
37,539,359
<p>I could give you the code, but instead, I'll explain to you how you can write it yourself.</p> <ol> <li><p>Read the Codes file and store the institutions and codes in a dictionary. You can read more about reading csv files here: <a href="https://pymotw.com/2/csv/" rel="nofollow">https://pymotw.com/2/csv/</a> or her...
1
2016-05-31T07:24:22Z
[ "python", "csv", "pandas", "match" ]
Index Out of Range for Large List Unless Last Element is Deleted
37,538,545
<p>I am facing a problem where I have a fairly large nested list (56k nested lists) created from a csv file. Each nested list contains 4 strings. I am trying to find nested lists which contains a specific string at a particular location.</p> <p>I keep getting an IndexError although I noticed the error disappears if I ...
0
2016-05-31T06:41:14Z
37,539,125
<p>This error is probably thrown because the last element in your List has less than three entries.</p> <p>In that case <code>[x for x in main_list if 'Hallux' in x[2]]</code> will fail, since <code>x[2]</code> does not exist.</p> <p>You can try a workaround like this:</p> <pre><code>[x for x in main_list if 'Hallux...
0
2016-05-31T07:12:03Z
[ "python", "python-2.7" ]
Does QtUiTools.QUiLoader() require QFile as input for some reason?
37,538,612
<p>I have:</p> <pre><code>from PySide import QtGui, QtUiTools </code></pre> <hr> <p>What is the difference between:</p> <pre><code>ui_file = QtCore.QFile('my_ui.ui') ui_file.open(QtCore.QFile.ReadOnly) my_ui = QtUiTools.QUiLoader().load(ui_file) ui_file.close() </code></pre> <p>and:</p> <pre><code>self.ui = QtUiT...
1
2016-05-31T06:44:25Z
37,539,117
<p>Looking into the Documentation of <code>QUILoader::load</code>, it takes as the first argument a <strong><a href="http://doc.qt.io/qt-5/qiodevice.html" rel="nofollow">QIODevice</a></strong> which is basically an interface class that can handle any block of Data such as QFile, QBuffer. </p> <p>In the <a href="https...
2
2016-05-31T07:11:27Z
[ "python", "pyside" ]
Speed up multi-loop data computation in Pandas
37,538,631
<p>Here is my question. Take the dataframe below as an example: </p> <p><a href="http://i.stack.imgur.com/VDfQS.png" rel="nofollow"><img src="http://i.stack.imgur.com/VDfQS.png" alt="enter image description here"></a></p> <ul> <li>The dataframe <code>df</code> has 8 columns, each of them has finite values. </...
2
2016-05-31T06:45:32Z
37,538,748
<p>You can first <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.filter.html" rel="nofollow"><code>filter</code></a> <code>DataFrame</code> and then multiple by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.mul.html" rel="nofollow"><code>mul</code></a>:<...
2
2016-05-31T06:52:46Z
[ "python", "loops", "pandas", "dataframe" ]
Use one app for several uwsgi instances
37,538,633
<p>I have found a lot of examples explaining how we can use uwsgi and emperor mode to achieve multiple apps deployment. This means for me: several apps folder with one vassal (ini, socket, application.py) per app.</p> <p>I was not yet able to find examples of configurations where there were only one app folder with mu...
0
2016-05-31T06:45:33Z
37,579,167
<h3>"Is this a good practice or do you have similar setup ?"</h3> <p>I do have similar setup. I won't answer if it's good practice, because it's opinion based, but there are small differences between this and copying code base for every customer. Main difference is: if someone will break into one app and he will be ab...
1
2016-06-01T21:34:06Z
[ "python", "nginx", "uwsgi", "multi-tenant", "saas" ]
assignment operator in print statement
37,538,731
<p>I am trying to execute the below code , say "s.py".</p> <pre><code>#!/usr/bin/env python import sys args = sys.argv[1:] print args aa = "Hey there !!" def main(): for unused_i in range(len(args)): print aa, nexts = args[unused_i] if __name__ == "__main__": main() </code></pre> <p>Output d...
-6
2016-05-31T06:51:41Z
37,538,997
<p>Fixed it, but for future reference:</p> <p>Try to format your question correctly.</p> <p>Write which approaches you tried but failed</p> <p>Try to solve the problem on your own.</p> <p>Stack Overflow is NOT a beginners course in programming</p> <pre><code>import sys args = sys.argv[1:] #print args aa = "Hey th...
0
2016-05-31T07:05:27Z
[ "python" ]
Boto script for creating weighted record in route53 throws error
37,538,737
<p>I have written a script which creates a weighted record and associates with health check. But as i need to create two records with same name,the first one gets created and in the second one ot throws error:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;ErrorResponse xmlns="https://route53.amazonaws.com/doc/2013-04...
0
2016-05-31T06:51:59Z
37,557,886
<p>The set identifier has to be unique. Think of it like a friendly name for that IP address.</p>
1
2016-06-01T01:03:01Z
[ "python", "amazon-web-services", "boto", "amazon-route53" ]
Python chinese characters
37,538,925
<p>I have the following encoding in python 2.7:</p> <pre><code>["\xe5\x81\x9a\xe6\x88\x8f\xe4\xb9\x8b\xe8\xaf\xb4"] </code></pre> <p>I need to get the following (chinese characters) from that:</p> <pre><code>["做戏之说"] </code></pre> <p>Anyone knows how to decode the above to get that?</p>
-3
2016-05-31T07:01:49Z
37,539,028
<p>You need to decode your string:</p> <pre><code>&gt;&gt;&gt; l = ["\xe5\x81\x9a\xe6\x88\x8f\xe4\xb9\x8b\xe8\xaf\xb4"] &gt;&gt;&gt; a = [l[0].decode('utf8')] &gt;&gt;&gt; print a[0] 做戏之说 </code></pre> <p>If you want to show your Unicode inside the list you need to convert the standard representation of the l...
2
2016-05-31T07:06:54Z
[ "python", "encoding", "character-encoding" ]
HTML Form no longer calls Python through JavaScript
37,539,013
<p>I was displaying some data from a flask-app via an html table, including a dynamic form in this table:</p> <pre><code>&lt;Table id="Datenbank" width="800px" align="left" &gt; &lt;tr&gt; &lt;th&gt;ID&lt;/th&gt; &lt;th&gt;Wochentag&lt;/th&gt; &lt;th&gt;Startzeitpunkt&lt;/th&gt; ...
0
2016-05-31T07:06:05Z
37,594,748
<p>Thanks for the input, my code now looks like this:</p> <p>Flask-app:</p> <pre><code>@app.route('/_delete_data_via_table_v2') def delete_data_via_table_v2(): del_ID = request.args.get('a', 0, type=int) tmp_string = "DELETE FROM ledtext WHERE ID = "+ str(del_ID) g.db.execute(tmp_string) g.db.commit() flash ('Eintrag...
0
2016-06-02T14:29:30Z
[ "javascript", "jquery", "python", "html", "flask" ]
HTML Form no longer calls Python through JavaScript
37,539,013
<p>I was displaying some data from a flask-app via an html table, including a dynamic form in this table:</p> <pre><code>&lt;Table id="Datenbank" width="800px" align="left" &gt; &lt;tr&gt; &lt;th&gt;ID&lt;/th&gt; &lt;th&gt;Wochentag&lt;/th&gt; &lt;th&gt;Startzeitpunkt&lt;/th&gt; ...
0
2016-05-31T07:06:05Z
37,641,644
<p>I now solved it with adding "<em>location.reload(false)</em>". There may be a better solution.</p> <pre><code> $('#Datenbank tbody').on( 'click', 'button', function () { var data = table.row( $(this).parents('tr') ).data(); $.getJSON($SCRIPT_ROOT + '/_delete_data_via_table_v2', { ...
0
2016-06-05T12:01:44Z
[ "javascript", "jquery", "python", "html", "flask" ]
Display foreign key columns as link to detail object in Django admin
37,539,132
<p>As explained in <a href="http://stackoverflow.com/questions/28832897/link-in-django-admin-to-foreign-key-object">link-in-django-admin-to-foreign-key-object</a>, one can display a ForeignKey field as a link to the admin detail page.</p> <p>To summarize,</p> <pre><code>class Foo(Model): bar = models.ForeignKey(B...
0
2016-05-31T07:12:33Z
37,539,948
<p>A good start would be looking at the source of <a href="https://github.com/django/django/blob/master/django/contrib/admin/options.py#L97" rel="nofollow"><code>BaseModelAdmin</code></a> and <a href="https://github.com/django/django/blob/master/django/contrib/admin/options.py#L480" rel="nofollow"><code>ModelAdmin</cod...
0
2016-05-31T07:53:01Z
[ "python", "django", "django-admin" ]
For an array a and b in Python, what is the code a[b[0:2]] is actually trying to do?
37,539,146
<p>Could somebody please help on explaining the meaning of this error message?</p> <p>There is this part of lines of code that I am trying to understand. So I experimented myself with an easier example.</p> <p>I have </p> <pre><code>a = array([[0, 1], [2, 3], [4, 5]]) </code></pre> <p>and</p> <pr...
0
2016-05-31T07:13:13Z
37,539,257
<pre><code>&gt;&gt;&gt; a = np.array([[0, 1], [2,3],[4,5]]) &gt;&gt;&gt; a2 = np.array([[0, 1], [2,3],[4,5],[6,7]]) </code></pre> <p>Two arrays: </p> <p>a - with elements number 0 to 2</p> <p>a2 - with elements number 0 to 3</p> <pre><code>&gt;&gt;&gt; b[0:2] [1, 3] </code></pre> <p>b[0:2] - means two elements (...
3
2016-05-31T07:18:46Z
[ "python", "list", "python-3.x", "numpy", "slice" ]
gsutil - regex with alternative not working
37,539,462
<p>I am looking to synchronize content between Google bucket and my local directory. I want to ignore certain files while performing this operation.</p> <p>Like I want to ignore file which ends with country.csv and version.csv at the end.</p> <p>So I use following regex, which doesn't work</p> <pre><code> gsuti...
1
2016-05-31T07:29:49Z
37,542,065
<p>This ought to work:</p> <pre><code>gsutil -m rsync -x ".*country\.csv$^|.*version\.csv$" gs://[bucket_id] test/ </code></pre> <p>See eg <a href="http://stackoverflow.com/questions/1200235/how-to-pass-a-quoted-pipe-character-to-cmd-exe">How to pass a quoted pipe character to cmd.exe?</a></p>
2
2016-05-31T09:36:39Z
[ "python", "regex", "gsutil" ]
Observing tensorflow rnn model weights
37,539,561
<p>I am using tensorflow rnn translation model published here:<br> <a href="https://github.com/tensorflow/tensorflow/tree/master/tensorflow/models/rnn/translate" rel="nofollow">translation model</a> </p> <p>I want to make changes in part of this code according to my own ideas.<br> First thing I wanna do is to see the...
0
2016-05-31T07:33:40Z
37,555,078
<p>What you are looking for is probably <strong><a href="https://www.tensorflow.org/versions/r0.7/how_tos/summaries_and_tensorboard/index.html" rel="nofollow">TensorBoard</a></strong>, which gives you ability to visualize arbitrary values/statistics of your network.</p> <p><a href="http://i.stack.imgur.com/DWVqD.png" ...
1
2016-05-31T20:29:11Z
[ "python", "machine-learning", "tensorflow", "machine-translation" ]
Text File Art Manipulation Python
37,539,577
<p>i'm currently working on a project for taking .png/.gif images and turning them it into ASCII and saving it to a text file. The way I achieved this was by getting the Gray Scale average of each pixel then have 2 for loops going through the pictures height and width then appending all of it into a 2 dimensional List(...
0
2016-05-31T07:34:27Z
37,539,882
<p>In theory, it's quite simple to flip and rotate; read the <code>x, y</code> values of the image in different orders. I highly recommend combining transformations to create some sort of notation that contains the following information:</p> <pre><code>x/y first? first or last first for x? first or last for y? </code>...
1
2016-05-31T07:49:54Z
[ "python" ]
Search query doesn't return anything in elasticsearch
37,539,587
<p>I am working on elasticsearch. I created and indexed json file content in elasticsearch.Now am trying to search text using search query.When i try to execute the below query in elasticsearch, it doesn't return anything in the result. But values are in it. Because i checked using the curl command,it return result.</p...
0
2016-05-31T07:34:56Z
37,540,517
<p>The problem with your code is "port" as string</p> <pre><code>ES_HOST = {"host":"xxx.xx.xx.xx","port":"9200"} </code></pre> <p>It should be:</p> <pre><code>ES_HOST = {"host":"xxx.xx.xx.xx","port": 9200} </code></pre> <p>This is the needed python code (<strong>you need to replace host_ip with your host IP</strong...
1
2016-05-31T08:24:26Z
[ "python", "elasticsearch" ]
Error in converting TensorType(float32, matrix) to TensorType(int32, matrix)
37,539,598
<p>I have written a code for a Deep Learning Algorithm. However I am stuck just in the final stage of loading the data.</p> <pre><code>self.x = T.imatrix("x") self.y = T.ivector("y") </code></pre> <p>are defined as the variables which hold the data</p> <p>then I do</p> <pre><code>train_x, train_y, train_lengths = d...
0
2016-05-31T07:35:27Z
37,543,833
<p>I found the answer. It is actually the training_x bit which was giving the error not the training_y.</p>
0
2016-05-31T10:59:07Z
[ "python", "matrix", "theano" ]
I want to use simiki to create my own wiki,but some errors happened when i "simiki init "in the terminal
37,539,671
<p>➜ mywiki python Python 2.7.10 (default, Jul 14 2015, 19:46:27) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin Type "help", "copyright", "credits" or "license" for more information.</p> <blockquote> <blockquote> <blockquote> <p>exit() ➜ mywiki simiki new -t "Hello Simiki" -...
-3
2016-05-31T07:38:32Z
37,539,961
<p>see this post: You have a conflict between your jinja2 module and real one. It mistake grow from python2 import politics. But you can add to first line of your script from <strong>future</strong> import absolute_import</p> <p><a href="http://stackoverflow.com/a/31279085/3131945">http://stackoverflow.com/a/31279085/...
0
2016-05-31T07:53:36Z
[ "python" ]
How to parse and loads JSON in bash shell script?
37,539,854
<p>I am trying to loads and print JSON response in shell script.I dont have any idea how to achieve this.Please help me on this.</p> <p>Code:</p> <pre><code>#!/bin/sh malop_q=$(curl -X GET -k -H "SEC: xxxxxxxxxxxxxxxxxxxxxx" 'https://127.0.0.1/api/reference_data/sets/malopid?fields=data(value)') echo $malop_q </cod...
1
2016-05-31T07:48:50Z
37,540,243
<p>The following python code do the parsing, assuming that you save it as: my_json.py</p> <pre><code>import json,sys obj=json.load(sys.stdin) for i in range(len(obj['data'])): print obj['data'][i]['value'] </code></pre> <p>You can get the respond using:</p> <pre><code>malop_q=$(curl -X GET -k -H "SEC: xxxxxxxxx...
2
2016-05-31T08:09:21Z
[ "python", "json", "bash", "shell", "api" ]
How to parse and loads JSON in bash shell script?
37,539,854
<p>I am trying to loads and print JSON response in shell script.I dont have any idea how to achieve this.Please help me on this.</p> <p>Code:</p> <pre><code>#!/bin/sh malop_q=$(curl -X GET -k -H "SEC: xxxxxxxxxxxxxxxxxxxxxx" 'https://127.0.0.1/api/reference_data/sets/malopid?fields=data(value)') echo $malop_q </cod...
1
2016-05-31T07:48:50Z
37,540,257
<p>With Python :</p> <pre><code>import json with open('file.json') as json_file: datas = json.load(json_file) for d in datas["data"]: print(d["value"]) </code></pre>
1
2016-05-31T08:10:27Z
[ "python", "json", "bash", "shell", "api" ]
Pythonic way to access Flask request arguements
37,539,970
<p>In my Flask app I am setting a number of local variables that have come in via an API call, using the </p> <pre><code>from flask import request . . submission_id = request.args.get('submission_id') grader = request.args.get('grader') grading_factor = float(request.args.get('grading_factor')) answer_key = request.ar...
1
2016-05-31T07:54:02Z
37,540,366
<p>Firstly, I don't think there's anything wrong with the way you're doing it. But, there are a couple of different approaches you could take; the first being to the call to get the argument from <code>request</code>:</p> <pre><code>from flask import request # ... def getRequestArg(name, *args): return request.a...
1
2016-05-31T08:16:32Z
[ "python", "flask" ]
Pythonic way to access Flask request arguements
37,539,970
<p>In my Flask app I am setting a number of local variables that have come in via an API call, using the </p> <pre><code>from flask import request . . submission_id = request.args.get('submission_id') grader = request.args.get('grader') grading_factor = float(request.args.get('grading_factor')) answer_key = request.ar...
1
2016-05-31T07:54:02Z
37,541,868
<pre><code>from flask import Flask, request app = Flask(__name__) class DotDict(object): def __init__(self, inner): self._inner = inner def __getattr__(self, item): return self._inner.get(item) def get(self, item, default=None): return self._inner.get(item, default) class LazyAt...
2
2016-05-31T09:28:24Z
[ "python", "flask" ]
Pythonic way to access Flask request arguements
37,539,970
<p>In my Flask app I am setting a number of local variables that have come in via an API call, using the </p> <pre><code>from flask import request . . submission_id = request.args.get('submission_id') grader = request.args.get('grader') grading_factor = float(request.args.get('grading_factor')) answer_key = request.ar...
1
2016-05-31T07:54:02Z
37,542,404
<p>As I suggested in the comments, you could come up with a decorator that would map the request arguments to the corresponding function parameters, such as:</p> <pre><code>def map_args(func): @functools.wraps(func) def wrapper(**kwargs): all_args = dict(request.args, **kwargs) return func(**al...
2
2016-05-31T09:52:05Z
[ "python", "flask" ]
How to do a job every half an hour
37,539,991
<p>I want to do a job every half an hour. My application is based on Flask, and running on Windows. </p> <p>Now I create a task for the job, using Windows scheduler service.</p> <p>I want to know if there is another way I can do cyclic tasks using Flask’s built-in functions...</p> <p>Sorry for my poor English.</p>...
0
2016-05-31T07:55:12Z
37,546,645
<blockquote> <p>I want to know if there is another way I can do [periodic] tasks using Flask’s built-in functions.</p> </blockquote> <p>Being somewhat a minimalist microframework, I don't think Flask has or <em>ever will have</em> a <strong>built-in</strong> feature to schedule periodic tasks. </p> <p>The customa...
0
2016-05-31T13:07:38Z
[ "python", "flask", "scheduled-tasks" ]
How to do a job every half an hour
37,539,991
<p>I want to do a job every half an hour. My application is based on Flask, and running on Windows. </p> <p>Now I create a task for the job, using Windows scheduler service.</p> <p>I want to know if there is another way I can do cyclic tasks using Flask’s built-in functions...</p> <p>Sorry for my poor English.</p>...
0
2016-05-31T07:55:12Z
37,573,363
<p>I m not sure if this help, but I've been testing the schedule module and it's easy to use and it works well:</p> <pre><code>$pip install schedule </code></pre> <p>and this is a sample from the <a href="https://pypi.python.org/pypi/schedule" rel="nofollow">official documentation</a>:</p> <pre><code>import schedule...
0
2016-06-01T15:48:31Z
[ "python", "flask", "scheduled-tasks" ]
Python Regex Picking "not include" word
37,540,405
<p>I am trying to find words in the string that do not contain any "a" characters. I wrote the code below but it does not work. How can I say to regex "do not include"? Can't I use "^" sign as "not"?</p> <pre><code>import re string2 = "asfdba12312sssdr1 12şljş1 kf" t = re.findall(r'([^a]\w*) | \w*[^a] ', string2 ) p...
2
2016-05-31T08:18:35Z
37,540,503
<p>You need to use a regex with word boundaries with a <code>re.UNICODE</code> flag:</p> <pre><code>r = re.compile(ur'\b[^\Wa]+\b', re.UNICODE) </code></pre> <p>The <code>\W</code> and <code>\b</code> will become Unicode aware then.</p> <p>See the <a href="https://regex101.com/r/rT2sS4/1" rel="nofollow">regex demo</...
2
2016-05-31T08:23:43Z
[ "python", "regex", "search", "find", "match" ]
Python Regex Picking "not include" word
37,540,405
<p>I am trying to find words in the string that do not contain any "a" characters. I wrote the code below but it does not work. How can I say to regex "do not include"? Can't I use "^" sign as "not"?</p> <pre><code>import re string2 = "asfdba12312sssdr1 12şljş1 kf" t = re.findall(r'([^a]\w*) | \w*[^a] ', string2 ) p...
2
2016-05-31T08:18:35Z
37,540,528
<p><code>[^a]</code> is the single non-<code>a</code> character. <code>[^a]\w*</code> is a single non-<code>a</code> character followed by any number of word-characters. Note that a space is a non-<code>a</code> character, and word-characters can also include <code>a</code>...</p> <p>The easiest and the most intuitive...
1
2016-05-31T08:25:01Z
[ "python", "regex", "search", "find", "match" ]
How to return a list instead of string from a class by default?
37,540,458
<pre><code>class A: def __init__(self, message): self.message = message def __repr__(self): return self.message print A("Hello") </code></pre> <p>The above code prints prints "Hello", as a string is returned. But I want to return a list by default. Like if I write :</p> <pre><code>class A: ...
1
2016-05-31T08:21:16Z
37,540,507
<p><a href="https://docs.python.org/3/reference/datamodel.html#object.__str__" rel="nofollow"><code>__str__</code></a> and <a href="https://docs.python.org/3/reference/datamodel.html#object.__repr__" rel="nofollow"><code>__repr__</code></a> methods must return strings. You have to make a custom getter function.</p> <p...
3
2016-05-31T08:23:55Z
[ "python", "class" ]
How to return a list instead of string from a class by default?
37,540,458
<pre><code>class A: def __init__(self, message): self.message = message def __repr__(self): return self.message print A("Hello") </code></pre> <p>The above code prints prints "Hello", as a string is returned. But I want to return a list by default. Like if I write :</p> <pre><code>class A: ...
1
2016-05-31T08:21:16Z
37,540,518
<p>This is a bad idea. <code>__repr__</code> should always return a str because it gets used by lots of internals (like you see here in <code>print</code>). For info read on: <a href="https://docs.python.org/3/reference/datamodel.html#object.__repr__" rel="nofollow">https://docs.python.org/3/reference/datamodel.html#ob...
3
2016-05-31T08:24:27Z
[ "python", "class" ]
django - How to create an object to be used in many views (for a dynamic menu)
37,540,552
<p>I have a dynamic menu that i include in multiple templates. (sidebar.html)</p> <pre><code>&lt;div class="sidebar"&gt; &lt;h3&gt;Service Menu&lt;/h3&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="{% url 'service:showrooms' %}"&gt;Showroom&lt;/a&gt;&lt;/li&gt; {% for link in major_sites %} &lt;li&gt;&lt...
1
2016-05-31T08:26:02Z
37,540,878
<p>Create a file <code>context_processors.py</code> in your app's directory. In there, create a function like</p> <pre><code>def add_sidebar_stuff(request): model_urls = MajorSiteInfoData.objects.only('location') return { 'link_urls': model_urls, } </code></pre> <p>And load it in <code>settings....
2
2016-05-31T08:42:30Z
[ "python", "django" ]
django - How to create an object to be used in many views (for a dynamic menu)
37,540,552
<p>I have a dynamic menu that i include in multiple templates. (sidebar.html)</p> <pre><code>&lt;div class="sidebar"&gt; &lt;h3&gt;Service Menu&lt;/h3&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="{% url 'service:showrooms' %}"&gt;Showroom&lt;/a&gt;&lt;/li&gt; {% for link in major_sites %} &lt;li&gt;&lt...
1
2016-05-31T08:26:02Z
37,540,976
<p>In django, you could use the concept of a context processor. Just write a function, which will be called on every request. It must return a dictionary of context you want to add, which in your case will be something like:</p> <pre><code>def menu_context_processor(request): return { 'link': MajorSiteInfo...
0
2016-05-31T08:47:33Z
[ "python", "django" ]
The browser only shows the first application results with Flask
37,540,632
<p>When I run the code:</p> <pre><code>from flask import Flask app = Flask(__name__) @app.route('/') def index(): return "Hello, world!" if __name__ == '__main__': app.run(debug=True) </code></pre> <p>I get the string <strong>"Hello, world!"</strong> in the chrome browser, but when I change the code:</p> ...
-2
2016-05-31T08:30:12Z
37,540,690
<p>Maybe the page is cached by your browser? Use <code>Ctrl + F5</code> to force reload , or append <code>?foo=1</code> to the url to make your browser make a new request to your web app. </p>
1
2016-05-31T08:33:04Z
[ "python", "flask" ]
How to extract the line in the text file that contains matching phrases?
37,540,670
<p>I have a text corpus which contains many lines of sentences. I was hoping to extract the lines that contains the key words. </p> <p>I wrote a simple python script but I get no value at all. </p> <p>My python Script:</p> <pre><code> corpus = [] with open('CatList2.text') as f: for line in f: corpus.appen...
-1
2016-05-31T08:31:54Z
37,540,778
<p>The problem is that when you read the keywords from the file, you are also getting the newlines.</p> <p>You can use <code>rstrip</code> to remove it (see <a href="http://stackoverflow.com/questions/275018/how-can-i-remove-chomp-a-newline-in-python">this SO post</a>).</p> <p>Python interpreter:</p> <pre><code>&gt;...
0
2016-05-31T08:37:49Z
[ "python", "python-2.7" ]
using functools with IronPython
37,540,724
<p>I'm using the functools library with IronPython.</p> <p>It works fine on the development machine, but in production the library can't be imported. Exception is thrown:</p> <blockquote> <p>IronPython.Runtime.Exceptions.ImportException: No module named _functools</p> </blockquote> <p>IronPython is installed on ...
2
2016-05-31T08:35:02Z
37,541,483
<p>Normally <code>_functools</code> is the native component that <code>functools.py</code> wraps. Given that native modules are not supported in IronPython (as of now) the relevant functionality is implemented in <code>IronPython.Modules.dll</code> (as seen <a href="https://github.com/IronLanguages/main/blob/c5c192bc4c...
1
2016-05-31T09:11:54Z
[ "python", "ironpython" ]
Django datetime default value in migrations
37,540,744
<p>I've read some questions about this issue in so, also <a href="http://stackoverflow.com/q/2771676/5476782">this</a> question is <strong>not</strong> giving the correct answer for my case:</p> <p>I'm adding a created_time field in my already existing models, so no date in the mysql table belonging to the model.</p> ...
0
2016-05-31T08:35:56Z
37,541,094
<p><a href="https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.DateField.auto_now_add" rel="nofollow">auto_now_add</a> set the current datetime when the instance is created, which never happens during your migration so you are trying to leave <code>NULL</code> a non-nullable field.</p> <p>The so...
1
2016-05-31T08:53:12Z
[ "python", "mysql", "django", "django-migrations" ]
python in powershell vs python CLI
37,540,755
<p>I am new to python, and I would like to ask what is the difference if I run python on Windows power-shell compared to when I run it directly and lunch the app's command-line?</p> <p>Is there an impact if i use the latter method?</p>
1
2016-05-31T08:36:24Z
37,540,899
<p>Launching the "Python" application for the terminal interface seems to use the system's default command prompt, which, for Windows, is cmd.exe. If you run it this way, using <code>quit()</code> or <code>exit()</code> will exit the interpreter and then close the window entirely. If you start Python from an actual cmd...
1
2016-05-31T08:43:40Z
[ "python", "powershell" ]
Delete nan AND corresponding elements in two same-length array
37,540,782
<p>I have two lists of the same length that I can convert into array to play with the <a href="http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.pearsonr.html" rel="nofollow">numpy.stats.pearsonr</a> method. Now, some of the elements of these lists are <code>nan</code>, and can thus not be used for...
2
2016-05-31T08:38:07Z
37,541,262
<p>The accepted answer to proposed duplicate gets you half-way there. Since you're using Numpy already you should make these into numpy arrays. Then you should generate an indexing expression, and then use it to index these 2 arrays. Here indices will be a new array of <code>bool</code> of same shape where each element...
4
2016-05-31T09:01:38Z
[ "python", "arrays", "python-3.x", "numpy" ]
How to multiply to each value in each element in SArray in Python?
37,540,864
<p>I'm using Graphlab, but I guess this question can apply to pandas.</p> <pre><code>import graphlab sf = graphlab.SFrame({'id': [1, 2, 3], 'user_score': [{"a":4, "b":3}, {"a":5, "b":7}, {"a":2, "b":3}], 'weight': [4, 5, 2]}) </code></pre> <p>I want to create a new column where the value of each element in 'user_scor...
1
2016-05-31T08:41:45Z
37,541,379
<p>I'm using <code>pandas</code> dataframe, but it should also work in your case. </p> <pre><code>import pandas as pd df['new']=[dict((k,v*y) for k,v in x.items()) for x, y in zip(df['user_score'], df['weight'])] </code></pre> <p><strong>Input dataframe:</strong></p> <pre><code>df Out[34]: id user_score...
1
2016-05-31T09:07:05Z
[ "python", "pandas", "graphlab" ]
How to multiply to each value in each element in SArray in Python?
37,540,864
<p>I'm using Graphlab, but I guess this question can apply to pandas.</p> <pre><code>import graphlab sf = graphlab.SFrame({'id': [1, 2, 3], 'user_score': [{"a":4, "b":3}, {"a":5, "b":7}, {"a":2, "b":3}], 'weight': [4, 5, 2]}) </code></pre> <p>I want to create a new column where the value of each element in 'user_scor...
1
2016-05-31T08:41:45Z
37,541,417
<p>here is one of many possible solutions:</p> <pre><code>In [69]: df Out[69]: id user_score weight 0 1 {'b': 3, 'a': 4} 4 1 2 {'b': 7, 'a': 5} 5 2 3 {'b': 3, 'a': 2} 2 In [70]: df['user_score'] = df['user_score'].apply(lambda x: pd.Series(x)).mul(df.weight, axis=0).to_dict('reco...
0
2016-05-31T09:09:06Z
[ "python", "pandas", "graphlab" ]
How to multiply to each value in each element in SArray in Python?
37,540,864
<p>I'm using Graphlab, but I guess this question can apply to pandas.</p> <pre><code>import graphlab sf = graphlab.SFrame({'id': [1, 2, 3], 'user_score': [{"a":4, "b":3}, {"a":5, "b":7}, {"a":2, "b":3}], 'weight': [4, 5, 2]}) </code></pre> <p>I want to create a new column where the value of each element in 'user_scor...
1
2016-05-31T08:41:45Z
37,551,392
<p>This is subtle, but I think what you want is this:</p> <pre><code>sf.apply(lambda row: trans(row['user_score'], row['weight'])) </code></pre> <p>The apply function takes a function as its argument, and will pass each row as the parameter to that function. In your version, you are evaluating the trans function befo...
0
2016-05-31T16:47:03Z
[ "python", "pandas", "graphlab" ]
Python BeautifulSoup find all tags under a certain type of tag
37,540,974
<p>I have an XML file with nested tags as such:</p> <pre><code>&lt;tag1&gt; &lt;tag2&gt;text0&lt;/tag2&gt; text1 &lt;tag2&gt;text2&lt;/tag2&gt; &lt;/tag1&gt; &lt;tag2&gt;text3&lt;/tag2&gt; text4 &lt;tag1&gt; &lt;tag2&gt;text5&lt;/tag2&gt; &lt;/tag1&gt; </code></pre> <p>Where I want to get all the content of a...
0
2016-05-31T08:47:28Z
37,541,790
<p>You can use <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#css-selectors" rel="nofollow">CSS selector</a>, for example, to select <code>tag2</code> that is direct child of <code>tag1</code> :</p> <pre><code>tag2entries = soup.select('tag1 &gt; tag2') </code></pre> <p>or, to select <code>tag2</code...
2
2016-05-31T09:25:03Z
[ "python", "beautifulsoup" ]
Python BeautifulSoup find all tags under a certain type of tag
37,540,974
<p>I have an XML file with nested tags as such:</p> <pre><code>&lt;tag1&gt; &lt;tag2&gt;text0&lt;/tag2&gt; text1 &lt;tag2&gt;text2&lt;/tag2&gt; &lt;/tag1&gt; &lt;tag2&gt;text3&lt;/tag2&gt; text4 &lt;tag1&gt; &lt;tag2&gt;text5&lt;/tag2&gt; &lt;/tag1&gt; </code></pre> <p>Where I want to get all the content of a...
0
2016-05-31T08:47:28Z
37,541,954
<p>You could use a list comprehension:</p> <pre><code>entry_list = [entry.text for entry in soup.find_all('tag2') if entry.parent.name == 'tag1'] </code></pre> <p>which results in:</p> <pre><code>['text0', 'text2', 'text5'] </code></pre>
0
2016-05-31T09:32:10Z
[ "python", "beautifulsoup" ]
How to upload Child page to Confluence using REST Api/JSON object with python?
37,541,003
<p>I want to create a program that uploads the changes in our git repo periodically to confluence. So far i have these: - the program collects the changes from the git repository - formats it according to a pre-defined html template and saves it to a text file - later it is parsed with python into a JSON object</p> <p...
0
2016-05-31T08:48:45Z
37,669,242
<p>Confluences REST API Documentation is available <a href="https://docs.atlassian.com/confluence/REST/latest/#d3e1426" rel="nofollow">here</a>:</p> <p>as per the document you need to update, the following uri to perform your request will be necessary:</p> <pre><code>/rest/api/content/{contentId} </code></pre> <p>If...
0
2016-06-07T01:42:15Z
[ "python", "json", "git", "rest", "confluence" ]
Trying to find substrings in large string
37,541,052
<p>Given this string </p> <pre><code>dna3 = "CATGTAATAGATGAATGACTGATAGATATGCTTGTATGCTATGAAAATGTGAAATGACCC" </code></pre> <p>the following code should print the following 4 substrings.</p> <pre><code>ATGTAA ATGAATGACTGATAG ATGCTATGA ATGTGA </code></pre> <p>However, it is printing the following:</p> <pre><code>ATGTA...
0
2016-05-31T08:50:51Z
37,541,756
<p>changes:</p> <p>1) min should use "key=int" otherwise the sort will be done as string...</p> <pre><code>return min(stop1,stop2,stop3, key=int) </code></pre> <p>2) break was replaced with exit to avoid another loop with while</p>
0
2016-05-31T09:23:38Z
[ "python", "dna-sequence" ]
Trying to find substrings in large string
37,541,052
<p>Given this string </p> <pre><code>dna3 = "CATGTAATAGATGAATGACTGATAGATATGCTTGTATGCTATGAAAATGTGAAATGACCC" </code></pre> <p>the following code should print the following 4 substrings.</p> <pre><code>ATGTAA ATGAATGACTGATAG ATGCTATGA ATGTGA </code></pre> <p>However, it is printing the following:</p> <pre><code>ATGTA...
0
2016-05-31T08:50:51Z
37,541,806
<p>I think you could have explained it a bit better but to get what you want to get you cannot return the min like that or when you do you have to treat it otherwise. The long chains you are getting is because you are returning '60' which is the length of the whole sequence. I modified the code a bit and it does only p...
1
2016-05-31T09:25:51Z
[ "python", "dna-sequence" ]
Trying to find substrings in large string
37,541,052
<p>Given this string </p> <pre><code>dna3 = "CATGTAATAGATGAATGACTGATAGATATGCTTGTATGCTATGAAAATGTGAAATGACCC" </code></pre> <p>the following code should print the following 4 substrings.</p> <pre><code>ATGTAA ATGAATGACTGATAG ATGCTATGA ATGTGA </code></pre> <p>However, it is printing the following:</p> <pre><code>ATGTA...
0
2016-05-31T08:50:51Z
37,541,888
<p>We may need some additional informations regarding DNA structure. From what you described, it feels like the substrings <strong>can't overlap each other</strong>. In this case, you need to replace <code>start = loc + 3</code> by <code>start = stop + 3</code> (the characters seem to be <strong>grouped 3 by 3</strong>...
0
2016-05-31T09:29:22Z
[ "python", "dna-sequence" ]
Trying to find substrings in large string
37,541,052
<p>Given this string </p> <pre><code>dna3 = "CATGTAATAGATGAATGACTGATAGATATGCTTGTATGCTATGAAAATGTGAAATGACCC" </code></pre> <p>the following code should print the following 4 substrings.</p> <pre><code>ATGTAA ATGAATGACTGATAG ATGCTATGA ATGTGA </code></pre> <p>However, it is printing the following:</p> <pre><code>ATGTA...
0
2016-05-31T08:50:51Z
37,541,987
<p>change start = loc + 3 to start = loc +len(gene)+ 3</p> <pre><code>def findStopIndex(dna,index): stop1 = dna.find("tga",index) if(stop1 == -1 or (stop1-index) % 3 != 0): stop1 = len(dna) stop2 = dna.find("taa",index) if(stop2 == -1 or (stop2-index) % 3 != 0): stop2 = len(dna) ...
0
2016-05-31T09:33:10Z
[ "python", "dna-sequence" ]
Trying to find substrings in large string
37,541,052
<p>Given this string </p> <pre><code>dna3 = "CATGTAATAGATGAATGACTGATAGATATGCTTGTATGCTATGAAAATGTGAAATGACCC" </code></pre> <p>the following code should print the following 4 substrings.</p> <pre><code>ATGTAA ATGAATGACTGATAG ATGCTATGA ATGTGA </code></pre> <p>However, it is printing the following:</p> <pre><code>ATGTA...
0
2016-05-31T08:50:51Z
37,542,380
<p>I think, you don't want the results, that lead to printing the string till the end, so you have to rule these cases out. And better use a for-loop for all endings:</p> <pre><code>def findStopIndex(dna, index): stops = [] for tag in ["TGA", "TAA", "TAG"]: stop = dna.find(tag, index) if stop &...
0
2016-05-31T09:50:49Z
[ "python", "dna-sequence" ]
Why does default authentication backend of django calls set_password after raising UserModel.DoesNotExist exception?
37,541,065
<p>I am writing a custom auth backend for a custom user model inherited from AbstractUser in django. I have gone through default auth backend of django and saw that user object is fetched using username with <code>UserModel._default_manager.get_by_natural_key(username)</code> authenticate() is as below</p> <pre><code>...
2
2016-05-31T08:51:29Z
37,541,207
<p>You should read this:</p> <p><a href="https://code.djangoproject.com/ticket/20760" rel="nofollow">https://code.djangoproject.com/ticket/20760</a></p> <p>It is to make sure if user does not exit it return not too soon, so bot can know if user exist or not.</p>
2
2016-05-31T08:59:18Z
[ "python", "django", "authentication", "exception", "custom-authentication" ]
Why does default authentication backend of django calls set_password after raising UserModel.DoesNotExist exception?
37,541,065
<p>I am writing a custom auth backend for a custom user model inherited from AbstractUser in django. I have gone through default auth backend of django and saw that user object is fetched using username with <code>UserModel._default_manager.get_by_natural_key(username)</code> authenticate() is as below</p> <pre><code>...
2
2016-05-31T08:51:29Z
37,541,227
<p>The comment explains exactly why. If it immediately returned False, it would take much less time than for a user that did not exist. An attacker would then be able to tell the difference between an existing and a non-existing username.</p>
2
2016-05-31T09:00:10Z
[ "python", "django", "authentication", "exception", "custom-authentication" ]
Unable to pip install --upgrade simplejson under cygwin
37,541,077
<p>In Windows 10 and a 64bit Cygwin installed today with all python packages. I then installed pip using <code>python -m ensurepip</code>.</p> <p>After that the <code>pip install --upgrade simplejson</code> goes awry like this</p> <pre><code>$ pip install --upgrade simplejson Collecting simplejson Using cached simp...
1
2016-05-31T08:52:11Z
40,055,131
<p>I am assuming you are trying to install simplejson through the installer when you already installed it through pip. That can cause issues when done so.</p> <p>I'd recommend seeking help if you don't know how to remove both, the pip version as well as the Cygwin version, manually.</p> <p>OFF TOPIC: (I'm still wonde...
0
2016-10-15T05:01:14Z
[ "python", "cygwin", "pip", "simplejson" ]