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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
How to restore a tensorflow model? | 38,428,294 | <p>I am trying to restore a model using a <code>.ckpt</code> file, which I got by running <code>word2vec_optimized.py</code> in <code>tensorflow/models/embedding</code>. I am not sure how to go about restoring the variables so that I can load the model and use it because all of the tf variables are encapsulated and ini... | 1 | 2016-07-18T03:46:29Z | 38,437,188 | <p>When you call the save function on your saver you pass it the tf.Session that you were using to train the model on. This contains a reference to the graph which contains all the variables. Don't confuse python variables with tensorflow variables. Even if you no longer have a variable in python which points to a te... | 1 | 2016-07-18T12:52:25Z | [
"python",
"tensorflow",
"word2vec"
] |
I need to know why this is the output for these python condition | 38,428,304 | <pre><code>numbers=[i**3 for i in range (10) if i**3%3==1]
print(numbers)
#gets 1,64,343
</code></pre>
<p>Why is <code>1, 64, 343</code> the answer?</p>
| 0 | 2016-07-18T03:47:32Z | 38,428,372 | <p>This is equivalent to the code:</p>
<pre><code>for i in range(10):
if (i*i*i) % 3 == 1:
numbers.append(i*i*i)
print (numbers)
</code></pre>
<p>You are checking if the remainder obtained when the cube of a number from 1 to 10 is divided by 3 is equal to 1. If it is, you are adding it to a list and prin... | 3 | 2016-07-18T03:56:50Z | [
"python",
"list",
"list-comprehension"
] |
I need to know why this is the output for these python condition | 38,428,304 | <pre><code>numbers=[i**3 for i in range (10) if i**3%3==1]
print(numbers)
#gets 1,64,343
</code></pre>
<p>Why is <code>1, 64, 343</code> the answer?</p>
| 0 | 2016-07-18T03:47:32Z | 38,428,751 | <p>first <code>i</code> is in <code>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]</code><br>
then if <code>(i*i*i) rem 3</code> is equal to <code>1</code><br>
it selects <code>(i*i*i)</code><br>
and for [1,4,7]: <code>(1*1*1)%3==1</code>, <code>(4*4*4)%3==1</code> and <code>(7*7*7)%3==1</code>:<br>
1*1*1=1 and 1/3=0 :remainder=1<br>... | 2 | 2016-07-18T04:49:31Z | [
"python",
"list",
"list-comprehension"
] |
I need to know why this is the output for these python condition | 38,428,304 | <pre><code>numbers=[i**3 for i in range (10) if i**3%3==1]
print(numbers)
#gets 1,64,343
</code></pre>
<p>Why is <code>1, 64, 343</code> the answer?</p>
| 0 | 2016-07-18T03:47:32Z | 38,428,773 | <ol>
<li>The meaning of <code>**</code>
ex: <code>2**3</code>= <code>2*2*2</code> <code>#this means 2 to the power 3 = 8</code></li>
<li>The meaning of <code>%</code>
ex: <code>5%2</code>= <code>1</code> <code>#the sign means module, that means the remaining value after divide 5 by 2, it is one.</code></li>
</ol>
... | 2 | 2016-07-18T04:51:31Z | [
"python",
"list",
"list-comprehension"
] |
Capture all output and error, warning of a command in windows by python | 38,428,331 | <p>In bash shell of Linux, I can read a command (from file), then execute the command and write all the output, error, and return code to a file. Can I do that by using python in windows.</p>
| 0 | 2016-07-18T03:51:30Z | 38,428,689 | <p>Of course you can. There are many ways to do this.</p>
<p>Assuming you had a text file named <code>commands</code> that contained a command on each line. You could do something like this:</p>
<ul>
<li>open the input file</li>
<li>read the next command name from the file</li>
<li>execute the command using <code>s... | 0 | 2016-07-18T04:40:47Z | [
"python",
"windows",
"shell"
] |
the login field is not visible after implementing it | 38,428,481 | <p>I am trying to implement the login field using django's authenticationForm.</p>
<p>the problem im having is that,because im trying to display two different forms inside one page (post_list) it seem to cause many errors.</p>
<p>one is for login field, and one is for the posting articles.</p>
<p>i also seem to have... | 0 | 2016-07-18T04:10:41Z | 38,428,690 | <p>When your page is initially displayed, <code>request.method</code> is <code>GET</code>. Therefore the post_list view is creating a <code>PostForm</code> instance and passing that into your template as the <code>form</code> element.</p>
<p><code>PostForm</code> does not have <code>username</code> or <code>password<... | 0 | 2016-07-18T04:41:34Z | [
"python",
"django"
] |
I keep getting the following error trying to parse json in python "string indices must be integers" | 38,428,523 | <p>When I use json.loads I get the following error</p>
<pre><code>string indices must be integers
</code></pre>
<p>I was doing some research and saw someone with what I thought was a similar situation. I changed this</p>
<pre><code>json.dumps(newstring_two)
</code></pre>
<p>to this</p>
<pre><code>json.loads(json.d... | 0 | 2016-07-18T04:17:01Z | 38,428,738 | <p>You should use a integer instead of 'file' statement at that line:</p>
<pre><code>finishe = parsed_json['file']
</code></pre>
<p>So, it can be so:</p>
<pre><code>finishe = parsed_json[0]
</code></pre>
<p>The 0 number at example can be 1,2,3,4 ..... You must find out which is the true number.</p>
| 0 | 2016-07-18T04:47:30Z | [
"python",
"json",
"parsing"
] |
I keep getting the following error trying to parse json in python "string indices must be integers" | 38,428,523 | <p>When I use json.loads I get the following error</p>
<pre><code>string indices must be integers
</code></pre>
<p>I was doing some research and saw someone with what I thought was a similar situation. I changed this</p>
<pre><code>json.dumps(newstring_two)
</code></pre>
<p>to this</p>
<pre><code>json.loads(json.d... | 0 | 2016-07-18T04:17:01Z | 38,429,565 | <p>'newstring_two' is string, so <code>parsed_json = json.dumps(newstring_two)</code> should be replaced <code>parsed_json = json.loads(newstring_two)</code>.
see <a href="https://docs.python.org/2/library/json.html" rel="nofollow">JSON encoder and decoder</a></p>
| 1 | 2016-07-18T06:05:19Z | [
"python",
"json",
"parsing"
] |
why my python scraping script is not working for different urls? | 38,428,537 | <p>i wrote a scraping script using python for 2 different urls</p>
<p><a href="http://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA" rel="nofollow">http://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA</a></p>
<p><a href="http:... | 0 | 2016-07-18T04:18:57Z | 38,429,251 | <p>You should see the content of <code>soup.prettify()</code> first. The website of <code>www.yellowpages.com.au</code> may be protected by firewall, which ensure real humans are accessing their information.<br/>
If the first step is okay, then you can fetch the content of website and debug the rest code. Maybe <code>f... | 0 | 2016-07-18T05:37:15Z | [
"python",
"beautifulsoup"
] |
Django 1.9 - IOError at /login/ | 38,428,560 | <p>Sorry if you tried helping me when I asked this earlier. Had to delete that post because I thought the question was poorly written.</p>
<p>So I have a login view that when I click submit throws the Error:</p>
<pre><code>Exception Type: IOError
Exception Value:
[Errno 22] Invalid argument: u"C:\\Users\\Me\\Des... | -1 | 2016-07-18T04:22:08Z | 38,430,110 | <p>The first argument of <a href="https://docs.djangoproject.com/en/1.9/topics/http/shortcuts/#render" rel="nofollow">render</a> must be <code>request object</code>, second template name, third context.</p>
<pre><code>return render(request, 'all_posts.html', {'user': request.user})
</code></pre>
| 2 | 2016-07-18T06:43:11Z | [
"python",
"django"
] |
Numpy Mask using np.count_nonzero() for individual rows | 38,428,585 | <p>Is there a way to create a numpy mask to individual rows in a numpy array without using a for loop?</p>
<p>Example: If row has more than zero nonzero values, apply a True mask</p>
<p>Given input: <code>array = [[0,0],[0,1],[0,2],[0,0]]</code></p>
<p>Expected output: <code>mask = [False,True,True,False]</code></p>... | 0 | 2016-07-18T04:25:43Z | 38,429,021 | <p>This could be made by numpy itself. But you have to think a little.</p>
<p>First you need to write out your condition and observe what will you get. For example:</p>
<pre><code>>>> print(array>0)
[[False False]
[False True]
[False True]
[False False]]
</code></pre>
<p>Then you should find a metho... | 2 | 2016-07-18T05:15:45Z | [
"python",
"numpy"
] |
python cython ImportError: DLL load failed: %1 is not a valid Win32 application | 38,428,589 | <p>This is what i have done, but i failed in <code>Step3</code>, I try my best and can't find how to solve it.</p>
<p>step1: install python-2.7.12.amd64 , Cython-0.24-cp27-cp27m-win_amd64 and vs2015.3.com_enu.(there are some problems,but be soveled.)</p>
<p>step2: do as:<a href="http://docs.cython.org/src/quickstart/... | 0 | 2016-07-18T04:26:17Z | 38,445,369 | <p>As @J.J.Hakala mentioned be sure to use the compiler he linked to or it won't work with your Python version. Also make sure you have all your includes listed in <code>setup.py</code>, i.e. </p>
<pre><code>from Cython.Distutils import build_ext
from setuptools import setup
from setuptools import Extension
module ... | 0 | 2016-07-18T20:21:21Z | [
"python",
"cython"
] |
Getting the absolute position of cursor in tkinter | 38,428,593 | <p>So I have a code from my supervisor that I am facing problems in understanding. I wish to draw a rectangle where my cursor is, using the <code>create_rectangle</code> method for which I give arguments/coordinates as:</p>
<p><code>rect = create_rectangle(x, y, x + 10, y + 10, fill = 'blue', width = 0)</code></p>
<p... | 1 | 2016-07-18T04:26:59Z | 38,429,800 | <p>You are asking about the difference between <strong>absolute SCREEN</strong> and <strong>relative</strong> mouse pointer's positions.</p>
<p>The notation:</p>
<pre><code>x = root.winfo_pointerx() - root.winfo_rootx()
y = root.winfo_pointery() - root.winfo_rooty()
</code></pre>
<p>reflects the mouse pointer's abso... | 3 | 2016-07-18T06:23:32Z | [
"python",
"canvas",
"tkinter",
"tkinter-canvas"
] |
Getting the absolute position of cursor in tkinter | 38,428,593 | <p>So I have a code from my supervisor that I am facing problems in understanding. I wish to draw a rectangle where my cursor is, using the <code>create_rectangle</code> method for which I give arguments/coordinates as:</p>
<p><code>rect = create_rectangle(x, y, x + 10, y + 10, fill = 'blue', width = 0)</code></p>
<p... | 1 | 2016-07-18T04:26:59Z | 38,447,028 | <p>Simple:<br></p>
<pre><code>from tkinter import *
root = Tk()
def f(event):
print(event.x, event.y)
root.bind("<Motion>", f)
</code></pre>
| 1 | 2016-07-18T22:39:23Z | [
"python",
"canvas",
"tkinter",
"tkinter-canvas"
] |
How to implement SVM for a Web Prediciton Program | 38,428,683 | <p>I am building a WPP using Modified Markov Model but i need to build an SVM with a classifier to train the data of the webpages.
Whats the easiest way to implement?</p>
| -2 | 2016-07-18T04:39:39Z | 38,428,999 | <p>You can use <a href="http://scikit-learn.org/stable/modules/svm.html" rel="nofollow">Scikit-learn</a></p>
<p>Example:</p>
<pre><code>from sklearn import svm
X = [[0, 0], [1, 1]]
y = [0, 1]
clf = svm.SVC
clf.fit(X, y)
</code></pre>
<p>And then for a prediction:</p>
<pre><code>clf.predict([[2., 2.]])
</code></pre>... | 0 | 2016-07-18T05:13:25Z | [
"python",
"c++",
"machine-learning"
] |
Install Tensorflow with Quantization Support | 38,428,718 | <p>This is a follow-up of another question by me : <a href="http://stackoverflow.com/q/38366876/1134940">Error with 8-bit Quantization in Tensorflow</a></p>
<p>Basically, I would like to install the Tensorflow with 8-bit quantization support. Currently, I installed Tensorflow 0.9 with pip installation method on CentOS... | 0 | 2016-07-18T04:45:17Z | 38,495,999 | <p>For time-being, I could figure out a method to do this. But still waiting for official method from any TensorFlow developers.</p>
<ol>
<li>First install the tensorflow ( I tried both source installation as well as PIP installation, both are fine)</li>
<li>Get the tensorflow source from the Github repo and go to the... | 1 | 2016-07-21T06:00:07Z | [
"python",
"tensorflow",
"quantization",
"tensorboard"
] |
Django failed to run test server: ImportError: No module named hitcount | 38,428,734 | <p>I'm new to Django and I've been working with it recently for a group project. I have it successfully installed and correctly configured - it worked fine when I tried to create my own test projects, yet when I started to run the test server on the project pulled from my teammate's repo it raised the following error:<... | 1 | 2016-07-18T04:46:55Z | 38,428,770 | <p>Try installing hitcount:</p>
<pre><code>pip install django-hitcount
</code></pre>
| 0 | 2016-07-18T04:51:14Z | [
"python",
"django"
] |
"ImportError: No module named selenium" | 38,428,735 | <pre><code>Installed selenium using pip : pip install selenium<br>
pip version : pip 8.1.2 from /usr/local/lib/python2.7/site-packages (python 2.7)<br>
python version : Python 2.7.5
</code></pre>
<p>Wasn't getting this error earlier. </p>
<pre><code>"ImportError: No module named selenium"
</code></pre>
... | -2 | 2016-07-18T04:46:57Z | 38,429,662 | <p>Please check if you have multiple python interpreters in your machine.</p>
<p>check what is your default interpreter by python in your terminal and press ENTER.</p>
<p>if it is same as the version mentioned y PIP while installing, you should not have any problems.</p>
<p>or else,</p>
<p>change your default inte... | 0 | 2016-07-18T06:12:53Z | [
"python",
"osx",
"selenium",
"selenium-webdriver",
"pip"
] |
The right way to implement Named group for choices in Django | 38,428,786 | <p>I'm a newbie and I'm wonder how to make choices into named group, in django documentation it says "You can also collect your available choices into named groups that can be used for organizational purposes". Based on documentation i try to make some model below</p>
<pre><code>python_2_unicode_compatible
class Music... | 1 | 2016-07-18T04:53:04Z | 38,443,366 | <p>In order to retrieve Human readable names you will need to use <code>Model.get_FOO_display()</code> method.</p>
<p>In your case, this should do the trick.</p>
<pre><code>#lets say song is a Music object
print song.get_Music_Media_display()
</code></pre>
<p>Here is more documentation for this method.
<a href="http... | 0 | 2016-07-18T18:11:27Z | [
"python",
"django"
] |
How to do 'lateral view explode()' in pandas | 38,428,796 | <p>I want to do this :</p>
<pre><code># input:
A B
0 [1, 2] 10
1 [5, 6] -20
# output:
A B
0 1 10
1 2 10
2 5 -20
3 6 -20
</code></pre>
<p>Every column A's value is a list</p>
<pre><code>df = pd.DataFrame({'A':[[1,2],[5,6]],'B':[10,-20]})
df = pd.DataFrame([[item]+list(df.loc[line,'B':]) for li... | 4 | 2016-07-18T04:53:54Z | 38,432,346 | <h3>Method 1 (OP)</h3>
<pre><code>pd.DataFrame([[item]+list(df.loc[line,'B':]) for line in df.index for item in df.loc[line,'A']],
columns=df.columns)
</code></pre>
<h3>Method 2 (pir)</h3>
<pre><code>df1 = df.A.apply(pd.Series).stack().rename('A')
df2 = df1.to_frame().reset_index(1, drop=True)
df2.join(... | 2 | 2016-07-18T08:51:23Z | [
"python",
"pandas"
] |
Where do I put C libraries required by Python packages? | 38,428,828 | <p>For example,On windows I have been trying to download Pillow for Python 2.7 using Pycharm's inbuilt pip like feature. Whenever I try to download Pillow it gives me error.</p>
<blockquote>
<p>ValueError: zlib is required unless explicitly disabled using
--disable-zlib</p>
</blockquote>
<p>I do not want to disab... | -1 | 2016-07-18T04:56:58Z | 38,429,094 | <p>For windows, it is easiest to download the installer package. It is available from the <a href="https://pypi.python.org/pypi/Pillow/2.7.0" rel="nofollow">pypi listing page</a>. Scroll down the list of files and you should see <code>Pillow-2.7.0.win32-py2.7.exe</code>; click on that and run the executable to install ... | 0 | 2016-07-18T05:22:53Z | [
"python",
"c",
"pillow"
] |
Python - Create dictionary of dictionaries from CSV | 38,428,878 | <p>I have a CSV with the first column having many duplicate values, and the second column being a predetermined code that maps to a value in the third column, such as this:</p>
<pre><code>1, a, 24
1, b, 13
1, c, 30
1, d, 0
2, a, 1
2, b, 12
2, c, 82
2, d, 81
3, a, 04
3, b, 23
3, c, 74
3, d, 50
</code></pre>
<p>I'm try... | 1 | 2016-07-18T05:00:45Z | 38,428,920 | <p>You don't need <code>dict2</code> and you are not setting it to be the value dict anyway. Try this modified version:</p>
<pre><code>with open(file, mode='rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
dict1 = {} # creates main dict
for row in reader: # iterates through the rows of the c... | 2 | 2016-07-18T05:04:49Z | [
"python",
"csv",
"dictionary",
"nested"
] |
Python - Create dictionary of dictionaries from CSV | 38,428,878 | <p>I have a CSV with the first column having many duplicate values, and the second column being a predetermined code that maps to a value in the third column, such as this:</p>
<pre><code>1, a, 24
1, b, 13
1, c, 30
1, d, 0
2, a, 1
2, b, 12
2, c, 82
2, d, 81
3, a, 04
3, b, 23
3, c, 74
3, d, 50
</code></pre>
<p>I'm try... | 1 | 2016-07-18T05:00:45Z | 38,428,954 | <p>Use <a href="https://docs.python.org/3/library/collections.html#collections.defaultdict" rel="nofollow">collections.defaultdict</a> for this.</p>
<pre><code>import collections
with open(file, mode='rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
dict1 = collections.defaultdict(dict)
for r... | 2 | 2016-07-18T05:08:22Z | [
"python",
"csv",
"dictionary",
"nested"
] |
Attribute in a Class immediately runs at the wrong time? | 38,429,100 | <p>I am fairly new to Python and I am learning how classes and methods interact by creating a text-based game. The code runs great, however, my question lies in the Name(object) class. Wherever I put it in the code, (in the beginning or in the middle as shown below) I will always be prompted with an input. I suspect i... | -1 | 2016-07-18T05:23:32Z | 38,429,210 | <p>define constructors for your Character class and subclasses that don't take a name as a paramter:
e.g.</p>
<p>class Warrior(Character):</p>
<pre><code>def __init__(self, weapon, spec_ability, health, armor):
super(Warrior, self).__init__(weapon, spec_ability, health)
self.armor = armor
</code></pre>
<p>an... | 1 | 2016-07-18T05:33:39Z | [
"python"
] |
Attribute in a Class immediately runs at the wrong time? | 38,429,100 | <p>I am fairly new to Python and I am learning how classes and methods interact by creating a text-based game. The code runs great, however, my question lies in the Name(object) class. Wherever I put it in the code, (in the beginning or in the middle as shown below) I will always be prompted with an input. I suspect i... | -1 | 2016-07-18T05:23:32Z | 38,429,310 | <p>When you run your program, the module-level code is executed. This includes your <code>Name</code> class.</p>
<pre><code>class Name(object):
name_new = raw_input("> ")
</code></pre>
<p>This creates the class <code>Name</code> and also <em>executes the code within the class</em>. Which is why you're prompted... | 2 | 2016-07-18T05:42:47Z | [
"python"
] |
How to overlay precipitation data on a shapefile using matplotlib and pygrib? | 38,429,211 | <p>I have read this question- <a href="http://stackoverflow.com/questions/20728529/how-to-overlay-a-shapefile-in-matplotlib">Overlay shape file on matplotlib</a> and I am not sure it applies to me but I have a shapefile of my country and I want to overlay the precipitation data from a GRIB file onto that shapefile. Thi... | 0 | 2016-07-18T05:33:42Z | 38,431,000 | <p>I'm not sure if I understand, because your code seems to basically work. I made a few changes:</p>
<ul>
<li><code>resolution</code> kwarg in <code>Basemap</code> can be set to <code>None</code> because you won't use the built-in coastlines</li>
<li><code>m.readshapefile</code> requires a <code>name</code> argument<... | 1 | 2016-07-18T07:35:06Z | [
"python",
"matplotlib",
"python-3.4",
"shapefile"
] |
Python/Flask : psutil date ranges | 38,429,271 | <p>I'm currently writing a web application using Flask in python that generates the linux/nix performances(CPU, Disk Usage, Memory Usage). I already implemented the python library psutil.</p>
<p>My question is how can I get the values of each util with date ranges. For example: Last 3 hours of CPU, Disk Usage, Memory ... | 0 | 2016-07-18T05:38:55Z | 38,521,678 | <p>For future need, I found a way to this. Using ElasticSearch and Psutil.</p>
<p>I indexed the psutil values to elasticsearch then used the date-range and date-histogram aggs.</p>
<p>Thanks!</p>
| 0 | 2016-07-22T08:28:17Z | [
"python",
"flask",
"psutil"
] |
Reading and comparing coordinates from Excel | 38,429,566 | <p>I was hoping to get some advice or help if possible. This is my first ever coding project so if my questions too vague or if anything else needs work on my end please let me know. </p>
<p>I have two different (x,y) coordinates stored in an excel sheet. First thing I need to do is write a code that can read these in... | 1 | 2016-07-18T06:05:22Z | 38,430,299 | <p>The easiest way for a starter would be to:</p>
<p>1.Calculate the difference in x and y for the whole table:</p>
<pre><code>table1['x_diff'] = table2['x'] - table1['x']
table1['y_diff'] = table2['y'] - table1['y']
</code></pre>
<p>2.Apply your function to the new columns:</p>
<pre><code>dist = table1.apply(lambd... | 3 | 2016-07-18T06:56:08Z | [
"python",
"excel",
"pandas",
"math",
"coordinates"
] |
How to return a matching item from a list in Python | 38,429,582 | <p>I want my function to return one of the short string in the list if it exists in another piece of long string. How would you do it?</p>
<p>This is what comes up in my mind at the moment, but is there a better way to implement the func in Python?</p>
<pre><code>>>> def func(shortStrList, longStr):
... ... | 2 | 2016-07-18T06:06:40Z | 38,429,643 | <p>You can use a generator expression with an if clause:</p>
<pre><code>def func(shortStrList, longStr):
return next(s for s in shortStrList if s in longStr)
</code></pre>
| 4 | 2016-07-18T06:11:25Z | [
"python"
] |
How to return a matching item from a list in Python | 38,429,582 | <p>I want my function to return one of the short string in the list if it exists in another piece of long string. How would you do it?</p>
<p>This is what comes up in my mind at the moment, but is there a better way to implement the func in Python?</p>
<pre><code>>>> def func(shortStrList, longStr):
... ... | 2 | 2016-07-18T06:06:40Z | 38,429,678 | <p>For the matter of taste, you can use <code>filter</code> instead of list comprehensions if you like.</p>
<pre><code>def func(shortStrList, longStr):
filter( lambda x: x in longStr, shortStrList)[0]
func( ['ABC', 'DEF', 'GHI', 'JDSLDF'], 'PQRABCD')
# ABC
</code></pre>
<p>Hope it helps :)</p>
| 0 | 2016-07-18T06:13:54Z | [
"python"
] |
How to return a matching item from a list in Python | 38,429,582 | <p>I want my function to return one of the short string in the list if it exists in another piece of long string. How would you do it?</p>
<p>This is what comes up in my mind at the moment, but is there a better way to implement the func in Python?</p>
<pre><code>>>> def func(shortStrList, longStr):
... ... | 2 | 2016-07-18T06:06:40Z | 38,430,000 | <p>To consolidate the answers/comments, and to do a quick test on the performance of different answers...</p>
<pre><code>>>> def timeTest(s, f):
... t1 = time.clock()
... for x in xrange(s):
... f(['ABC', 'DEF', 'GHI'], 'PQRABCD')
... f(['ABC', 'DEF', 'GHI'], 'PQRACDEF')
... f(... | 2 | 2016-07-18T06:36:06Z | [
"python"
] |
How to return a matching item from a list in Python | 38,429,582 | <p>I want my function to return one of the short string in the list if it exists in another piece of long string. How would you do it?</p>
<p>This is what comes up in my mind at the moment, but is there a better way to implement the func in Python?</p>
<pre><code>>>> def func(shortStrList, longStr):
... ... | 2 | 2016-07-18T06:06:40Z | 38,430,208 | <p>You can just keep it simple like this:</p>
<pre><code>def func(shortStrList, longStr):
try:
return [string for string in shortStrList if string in longStr][0]
except IndexError:
return("No matches found")
</code></pre>
<p>Output:</p>
<pre><code>>>> func(['ABC', 'DEF', 'GHI'], 'PQR... | 0 | 2016-07-18T06:50:36Z | [
"python"
] |
Docs unexpectedly being deleted from elasticsearch after scraping | 38,429,706 | <p>For my fantasy football team, I have been scraping data from www.footywire.com, which I am then trying to import into Kibana via elasticsearch. All of this is being written in Python 2.7 with BeautifulSoup.</p>
<p>So for each player, I am scraping info like the number of possessions that player had, the opposing te... | 0 | 2016-07-18T06:16:02Z | 38,447,906 | <p>As rightly pointed out by @rajat, elasticsearch needed unique ids for each doc that is sent to it. I had incorrectly set this up.</p>
| 0 | 2016-07-19T00:39:20Z | [
"python",
"elasticsearch"
] |
How to omitt newlines in Phython? | 38,429,810 | <p>I know..... one way to omitting new lines in Python with concatenation: </p>
<pre><code>a = 'strin'
b = 2
print str(b)+a
</code></pre>
<p>how many ways we can this be done?</p>
| -2 | 2016-07-18T06:24:06Z | 38,429,965 | <p>I believe, you are using Python2.x. You can try following:</p>
<ol>
<li><p>use a trailing comma.</p>
<pre><code> print a, # no new line will be printed
</code></pre></li>
<li><p>use print function from future</p>
<pre><code>from __future__ import print_function
print(a,end='') # no new line will be printed
</code... | 2 | 2016-07-18T06:33:40Z | [
"python"
] |
How to omitt newlines in Phython? | 38,429,810 | <p>I know..... one way to omitting new lines in Python with concatenation: </p>
<pre><code>a = 'strin'
b = 2
print str(b)+a
</code></pre>
<p>how many ways we can this be done?</p>
| -2 | 2016-07-18T06:24:06Z | 38,430,159 | <p>You can try this also,</p>
<p><code>print(repr(b), a) # ',' will avoid the newline</code></p>
| 1 | 2016-07-18T06:46:21Z | [
"python"
] |
How to omitt newlines in Phython? | 38,429,810 | <p>I know..... one way to omitting new lines in Python with concatenation: </p>
<pre><code>a = 'strin'
b = 2
print str(b)+a
</code></pre>
<p>how many ways we can this be done?</p>
| -2 | 2016-07-18T06:24:06Z | 38,448,545 | <p>Yes finally I found the answer.<br>
We can omit newlines in 3:</p>
<ol>
<li><p><strong>"+"</strong> (Concatenation)<br>
Ex:</p>
<pre><code>a = sachin
b = 'tendulkar'
a += b
print(a)
</code></pre></li>
<li><p>By using <strong>","</strong> (comma) see above answers </p></li>
<li><p>By using <strong>write() functi... | 0 | 2016-07-19T02:16:34Z | [
"python"
] |
Executing python script in node application | 38,429,824 | <p>I am very new to javascript / nodejs / web app development. I have a python script which would perform data crawling and storing the crawled data into the database when executed. The script would require users to input a date which would crawl data created on the particular date that is being submitted.</p>
<p>I ha... | -1 | 2016-07-18T06:24:50Z | 38,429,886 | <p><a href="https://github.com/extrabacon/python-shell" rel="nofollow">python-shell</a> sounds like exactly what you need. Here's one of their examples:</p>
<pre><code>var PythonShell = require('python-shell');
PythonShell.run('my_script.py', function (err) {
if (err) throw err;
console.log('finished');
});
</cod... | 1 | 2016-07-18T06:29:03Z | [
"javascript",
"python",
"html"
] |
Calculating the 2D mean of a 3D jagged NumPy Array | 38,429,927 | <p>I'm trying to calculate the Hurst Exponent of a time series in python, a value that determines some mean reversion characteristics of a time series for quantitative finance. I've taken a time series, of any length, and chosen to split it into chunks of data, a process that is a part of calculating the Hurst Exponent... | 2 | 2016-07-18T06:31:39Z | 38,430,543 | <p>To make a list of averages you can simply use <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk" rel="nofollow">list comprehension</a>:</p>
<pre><code> [mean(x[axis]) for axis in range(len(x))]
</code></pre>
<p>it goes over the axes and compute the mean of each part.</p>
| 0 | 2016-07-18T07:10:10Z | [
"python",
"multidimensional-array",
"mean",
"exponent",
"quantitative-finance"
] |
Calculating the 2D mean of a 3D jagged NumPy Array | 38,429,927 | <p>I'm trying to calculate the Hurst Exponent of a time series in python, a value that determines some mean reversion characteristics of a time series for quantitative finance. I've taken a time series, of any length, and chosen to split it into chunks of data, a process that is a part of calculating the Hurst Exponent... | 2 | 2016-07-18T06:31:39Z | 38,433,151 | <p>For anybody that stumbles across this, I've solved the problem and resolved to using a Pandas Dataframe instead...</p>
<pre><code>def hurst(y,n):
y = prices.as_matrix()
y = array_split(y,n)
y = pd.DataFrame.from_records(y).transpose()
y = y.dropna()
# Mean Centered Series
m = y.mean(axis='columns')
Y = y.sub(m,... | 0 | 2016-07-18T09:28:54Z | [
"python",
"multidimensional-array",
"mean",
"exponent",
"quantitative-finance"
] |
how to get xpath of all elements in xml file with default namespace using python? | 38,429,935 | <p>I wanted to get xpath of each element in xml file.</p>
<p><strong>xml file:</strong></p>
<pre><code><root
xmlns="http://www.w3.org/TR/html4/"
xmlns:h="http://www.w3schools.com/furniture">
<table>
<tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</tr>
</... | 2 | 2016-07-18T06:32:04Z | 38,430,272 | <p>You could use <code>getelementpath</code>, which always returns the elements in Clark notation, and replace the namespaces manually:</p>
<pre><code>x = """
<root
xmlns="http://www.w3.org/TR/html4/"
xmlns:h="http://www.w3schools.com/furniture">
<table>
<tr>
<h:td>Apples</h:td>... | 0 | 2016-07-18T06:54:38Z | [
"python",
"xml",
"xpath",
"xml-namespaces",
"elementtree"
] |
Failed to start segment instance database sdwXX when I init greenplum | 38,429,999 | <p>I encounter a problem when I init Greenplum,so I can't install Greenplum successfully.
I have installed Greenplum successfully in VMs which I used bridge modeï¼during initialization I also encounted a problem which said that it cant copy files between segments(such as sdw1 and sdw2),I find the solution setting the ... | 0 | 2016-07-18T06:35:59Z | 38,445,859 | <p>check that all your environment variables are setup correctly. The segments should have these</p>
<p>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LIBRARY_PATH=$LD_LIBRARY_PATH
~</p>
<p>Also, please check if you performed gpseginstall before gpinitsystem</p>
| 0 | 2016-07-18T20:56:40Z | [
"python",
"database",
"postgresql",
"greenplum"
] |
Python:OpenFile dialog did not appear because of cannot access the text variable | 38,430,257 | <p>I already created a button, an entry and a function for file dialog. After i press the 'browse' button the file dialog did not appear, so how can i make sure my <code>custName.set(filename)</code> can be use in my TracingMethod () function.</p>
<p>Steps for me to create a file dialog:</p>
<p>Step 1: import the fil... | 1 | 2016-07-18T06:53:37Z | 38,431,075 | <p>You have several mistakes here:</p>
<ul>
<li><code>custName</code> (and certainly <code>location_ent</code>) should be an attribute of the class</li>
<li><p>The <code>open</code> function must be a method of your <code>TracingInterface</code> class and the return string must be assigned to <code>self.custName</code... | 1 | 2016-07-18T07:39:34Z | [
"python",
"tkinter",
"openfiledialog"
] |
Python:OpenFile dialog did not appear because of cannot access the text variable | 38,430,257 | <p>I already created a button, an entry and a function for file dialog. After i press the 'browse' button the file dialog did not appear, so how can i make sure my <code>custName.set(filename)</code> can be use in my TracingMethod () function.</p>
<p>Steps for me to create a file dialog:</p>
<p>Step 1: import the fil... | 1 | 2016-07-18T06:53:37Z | 38,431,080 | <p><code>self.browseButton</code> widget does not appear because you set the <code>columnspan</code> option for <code>location_ent</code> to 1. You must modify it to 2 because you have <code>self. configUAButton</code> button there too.</p>
<p>This means you need to change:</p>
<pre><code>location_ent.grid(row =2, co... | 3 | 2016-07-18T07:39:51Z | [
"python",
"tkinter",
"openfiledialog"
] |
When should we use split() in Python? | 38,430,418 | <p>So I would like to remove the white space from my integer input and store them into a list.</p>
<pre><code>t = raw_input().split()
numbers = [int(x.strip()) for x in t]
numbers = sorted(numbers)
print numbers
</code></pre>
<p>However, the output's still the same when I don't use strip(). Can somebody please explai... | -7 | 2016-07-18T07:02:34Z | 38,430,761 | <p>I don't understand the confusion. The <code>split()</code> function return a list of all subparts of your string by removing all occurences of the given argument.</p>
<p>For example, if you have the following string : "Hello world!" and split this one by split("o") then your output will be : ["Hell", " w", "rld!"]<... | 1 | 2016-07-18T07:21:57Z | [
"python"
] |
When should we use split() in Python? | 38,430,418 | <p>So I would like to remove the white space from my integer input and store them into a list.</p>
<pre><code>t = raw_input().split()
numbers = [int(x.strip()) for x in t]
numbers = sorted(numbers)
print numbers
</code></pre>
<p>However, the output's still the same when I don't use strip(). Can somebody please explai... | -7 | 2016-07-18T07:02:34Z | 38,431,692 | <p><code>split(split_item)</code> returns a list with dividing the input by the split_item</p>
<p><code>strip(strip_item)</code> will remove the strip_item from leading and trailing end and will return the remaining item.</p>
<p>eg:</p>
<p><code>a = " how are you "</code></p>
<p><code>a.split()</code> will give <co... | 0 | 2016-07-18T08:14:39Z | [
"python"
] |
How can i solve this errors in python django? | 38,430,446 | <p>Hi im very novice at python django.</p>
<p>This is my django views.py codes</p>
<pre><code>def post_list(request):
request.session['lat'] = request.POST['user_lat']
request.session['lon'] = request.POST['user_lon']
userpoint = GEOSGeometry('POINT('lat' 'lon')', srid=4326)
list_total = list_1
i=1
while i:
list_... | 1 | 2016-07-18T07:04:09Z | 38,430,473 | <p>You've missed the closing backet at line:</p>
<pre><code>list_i = Post.objects.filter(point_distance__lte = userpoint, D(km=i)
</code></pre>
| 0 | 2016-07-18T07:05:50Z | [
"python",
"django"
] |
How can i solve this errors in python django? | 38,430,446 | <p>Hi im very novice at python django.</p>
<p>This is my django views.py codes</p>
<pre><code>def post_list(request):
request.session['lat'] = request.POST['user_lat']
request.session['lon'] = request.POST['user_lon']
userpoint = GEOSGeometry('POINT('lat' 'lon')', srid=4326)
list_total = list_1
i=1
while i:
list_... | 1 | 2016-07-18T07:04:09Z | 38,430,669 | <p>You can not instantiate a GEOSGeometry object with that mis-formed string. Use </p>
<p>userpoint = GEOSGeometry('POINT('+ latvariable + ' ' + lonvariable +')', srid=4326)</p>
| 1 | 2016-07-18T07:17:56Z | [
"python",
"django"
] |
Writing to xlsx creating duplicate lines in one cell | 38,430,472 | <p>I'm reading data from <code>in.txt</code> and writing specific lines from that to <code>Sample.xlsx</code>. I'm grepping data between lines containing <code>start</code> and <code>end</code> and I set <code>Flag</code> when I'm parsing this section of input data. When <code>Flag</code> is set, whenever I encounter <... | 3 | 2016-07-18T07:05:49Z | 38,434,722 | <p>It's possible and advisable to try and avoid using a counter in Python. The following code is more expressive and maintainable.</p>
<pre><code>from openpyxl import Workbook, load_workbook
fin = open('in.txt', 'r')
wb = Workbook()
ws = wb.active
ws.append([None, None, "NAME", "AGE"])
Flag = False
for line in fin.r... | 1 | 2016-07-18T10:45:15Z | [
"python",
"excel",
"python-2.7",
"openpyxl"
] |
How to import a Google doc to Python app as markdown? | 38,430,491 | <p>I'm writing a Python application that needs to fetch a Google document from Google Drive as markdown.</p>
<p>I'm looking for ideas for the design and existing open-source code.</p>
<p>As far as I know, Google doesn't provide export as markdown. I suppose this means I would have to figure out, which of the availabl... | 0 | 2016-07-18T07:06:52Z | 38,434,343 | <p>You might want to take a look at <a href="http://pandoc.org/" rel="nofollow" title="Pandoc">Pandoc</a> which supports conversions i.e. from docx to markdown. There are several Python wrappers for Pandoc, such as <a href="https://pypi.python.org/pypi/pypandoc/" rel="nofollow" title="pypandoc">pypandoc</a>.</p>
<p>Af... | 1 | 2016-07-18T10:25:26Z | [
"python",
"google-drive-sdk",
"markdown",
"google-docs"
] |
How to import a Google doc to Python app as markdown? | 38,430,491 | <p>I'm writing a Python application that needs to fetch a Google document from Google Drive as markdown.</p>
<p>I'm looking for ideas for the design and existing open-source code.</p>
<p>As far as I know, Google doesn't provide export as markdown. I suppose this means I would have to figure out, which of the availabl... | 0 | 2016-07-18T07:06:52Z | 38,454,081 | <p>Google Drive offers a "Zipped HTML" export option.</p>
<p><a href="http://i.stack.imgur.com/BosJ2.png" rel="nofollow"><img src="http://i.stack.imgur.com/BosJ2.png" alt="enter image description here"></a></p>
<p>Use the <a href="https://pypi.python.org/pypi/html2text" rel="nofollow">Python module <code>html2text</c... | 1 | 2016-07-19T09:08:07Z | [
"python",
"google-drive-sdk",
"markdown",
"google-docs"
] |
Python 3.5 - ctypes - create string buffer for Citect API | 38,430,520 | <p>I would like to access our Citect SCADA system from external script in Python. I found some example code here: <a href="https://github.com/mitchyg/Random/blob/master/pyctapi/src/pyctapi.py" rel="nofollow">https://github.com/mitchyg/Random/blob/master/pyctapi/src/pyctapi.py</a></p>
<p>When I run this fragment of cod... | 2 | 2016-07-18T07:08:34Z | 38,433,773 | <p>OK, first of all i mixed up arguments for ctCicode and ctTagRead so code should look like(without ",None" argument):</p>
<pre><code>def ct_tag_read(self, tag_name):
buffer = create_string_buffer('\000' * 32)
ok = windll.CtApi.ctTagRead(self.hCTAPI, tag_name, byref(buffer), sizeof(buffer))
if ok == False... | 0 | 2016-07-18T09:58:21Z | [
"python",
"api",
"ctypes",
"scada"
] |
py.test fixture how can I change fixture's scope | 38,430,607 | <p>I am running tests in two modes: with bare pytest and with pytest-xdist.
I have a heavy fixture that was defined with module scope. Inside this fixture, I have some optimization for the case when I am running tests with xdist:</p>
<pre><code>@pytest.fixture(scope="module")
def myfixture(request):
if running_wi... | 1 | 2016-07-18T07:13:17Z | 38,475,256 | <p>I gave a really good try to command line options, but it seems that fixture param <code>scope</code> only accepts string value, can't take callable function:
<a href="https://github.com/pytest-dev/pytest/issues/1682" rel="nofollow">https://github.com/pytest-dev/pytest/issues/1682</a></p>
<p>I guess just need to wai... | 0 | 2016-07-20T07:42:58Z | [
"python",
"py.test",
"xdist"
] |
list of functions with parameters | 38,430,628 | <p>I need to obtain a list of functions, where my function is defined as follows:</p>
<pre><code>import theano.tensor as tt
def tilted_loss(y,f,q):
e = (y-f)
return q*tt.sum(e)-tt.sum(e[e<0])
</code></pre>
<p>I attempted to do </p>
<pre><code>qs = np.arange(0.05,1,0.05)
q_loss_f = [tilted_loss(q=q) for q... | 2 | 2016-07-18T07:14:52Z | 38,430,663 | <p>You can use <a href="https://docs.python.org/2/library/functools.html#functools.partial" rel="nofollow"><code>functools.partial</code></a>:</p>
<pre><code>q_loss_f = [functools.partial(tilted_loss, q=q) for q in qs]
</code></pre>
| 3 | 2016-07-18T07:17:27Z | [
"python"
] |
list of functions with parameters | 38,430,628 | <p>I need to obtain a list of functions, where my function is defined as follows:</p>
<pre><code>import theano.tensor as tt
def tilted_loss(y,f,q):
e = (y-f)
return q*tt.sum(e)-tt.sum(e[e<0])
</code></pre>
<p>I attempted to do </p>
<pre><code>qs = np.arange(0.05,1,0.05)
q_loss_f = [tilted_loss(q=q) for q... | 2 | 2016-07-18T07:14:52Z | 38,433,449 | <p>There are 2 ways you can solve this problem. Both ways require you know the default values for y and f. </p>
<p>With the current function, there's simply no way for the Python interpreter to know the value of y and f when you call tilted_loss(q=0.05). y and f are simply undefined & unknown.</p>
<p><strong>Solu... | 1 | 2016-07-18T09:43:37Z | [
"python"
] |
Cryptic error in lxml when opening file | 38,430,637 | <p>My code is rather simple; </p>
<pre><code>f = open(r"C:\filepath\file.xml")
xml = f.read()
tree = etree.parse(xml)
</code></pre>
<p>When running this, I get the stack trace </p>
<pre><code>tree = etree.parse(xml)
File "src/lxml/lxml.etree.pyx", line 3427, in lxml.etree.parse (src\lxml\lxml.etree.c:79801)
File... | -1 | 2016-07-18T07:15:40Z | 38,430,915 | <p><code>parse()</code> accepts path to the XML file :</p>
<pre><code>tree = etree.parse(r"C:\filepath\file.xml")
</code></pre>
<p>Currently your code passes actual content of the XML to <code>parse()</code>, which will trigger such <code>IOError</code>. You can use <code>fromstring()</code> instead to create <code>E... | 1 | 2016-07-18T07:30:08Z | [
"python",
"python-2.7",
"debugging",
"error-handling",
"lxml"
] |
How to check if a unittest.mock.Mock has return_value set? | 38,430,661 | <p>I have a <a href="https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock" rel="nofollow"><code>unittest.mock.Mock</code></a> instance <code>m</code>. The only thing I know is that it mocks a class with a <code>foo()</code> method. I need to determine whether <code>m.foo.return_value</code> has been ... | 0 | 2016-07-18T07:17:19Z | 38,430,749 | <p>As long as you haven't actually accessed <code>mock.return_value</code> yet, you can test if a non-standard return value has been set with:</p>
<pre><code>m.foo._mock_return_value is unittest.mock.DEFAULT
</code></pre>
<p>The moment you use the <code>mock.return_value</code> property, if <code>mock._mock_return_va... | 1 | 2016-07-18T07:21:18Z | [
"python",
"mocking",
"python-unittest"
] |
Python Module Issue: TypeError: 'module' object is not callable | 38,430,733 | <p>I've been attempting to develop a text adventure type game in Python (and PyGame), and thus needed a module to repeatedly blit text to the screen. After searching through a few, I downloaded KTextSurfaceWriter and installed it. Then I tried to follow the demo in the text provided here (<a href="http://www.pygame.org... | 0 | 2016-07-18T07:20:49Z | 38,430,950 | <p>You are calling the <code>pygame.surface</code> module:</p>
<pre><code>surface = pygame.surface ( (400, 400), flags = SRCALPHA, depth = 32)
</code></pre>
<p>Either use <code>pygame.surface.Surface()</code> or use <code>pygame.Surface()</code> (note the capital <code>S</code>); these are both the same class but <co... | 2 | 2016-07-18T07:32:21Z | [
"python",
"python-2.7",
"module",
"pygame"
] |
Python Module Issue: TypeError: 'module' object is not callable | 38,430,733 | <p>I've been attempting to develop a text adventure type game in Python (and PyGame), and thus needed a module to repeatedly blit text to the screen. After searching through a few, I downloaded KTextSurfaceWriter and installed it. Then I tried to follow the demo in the text provided here (<a href="http://www.pygame.org... | 0 | 2016-07-18T07:20:49Z | 38,431,069 | <p>I have seen your code and soure code. </p>
<pre><code>surface = pygame.surface ( (400, 400), flags = SRCALPHA, depth = 32)
</code></pre>
<p>In your code, "surface" is lowercase, which is a python module, so python interpreter tells you the err msg.</p>
<pre><code>surface = pygame.Surface( (400,400), flags=SRCALPH... | 0 | 2016-07-18T07:39:04Z | [
"python",
"python-2.7",
"module",
"pygame"
] |
Define the marker and color setting by the dataset label | 38,430,844 | <p>I think my target was simple. But I haven't check out my hidden mistake somewhere. </p>
<p>I was learning PLA(Perceptron Linear Algorithm) and tried to achieve it in Python language. </p>
<p>The algorithm itself has been work out. Then, I want to plot the adjust process through the algorithm. </p>
<h3>The data... | 2 | 2016-07-18T07:26:38Z | 38,432,085 | <p>The problem is that your one line loops don't produce your required output. If you just run them to test their output then the result is color:<code>'b'</code> and marker:<code>'x'</code> which explains why your output is the way it is. </p>
<p>The solution below does not use one line loops but does produce the req... | 1 | 2016-07-18T08:36:24Z | [
"python",
"matplotlib"
] |
How to create an optimizer in Tensorflow | 38,431,054 | <p>I want to write a new optimization algorithm for my network on Tensorflow. I hope to implement the <a href="https://en.wikipedia.org/wiki/Levenberg%E2%80%93Marquardt_algorithm" rel="nofollow">Levenberg Marquardt optimization algorithm</a>, which now is excluded from TF API. I found poor documentation on how to write... | 3 | 2016-07-18T07:37:53Z | 38,446,694 | <p>The simplest example of an optimizer is probably the <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/training/gradient_descent.py" rel="nofollow">gradient descent optimizer</a>. It shows how one creates an instance of the basic <a href="https://github.com/tensorflow/tensorflow/blob/m... | 3 | 2016-07-18T22:03:36Z | [
"python",
"python-2.7",
"optimization",
"tensorflow",
"mathematical-optimization"
] |
Runtime error in build_pdf module of latex - python | 38,431,066 | <p>Below is my latex_template.py file</p>
<pre><code>min_latex = (r"\documentclass{article}"
r"\begin{document}"
r"Hello, world!"
r"\end{document}")
from latex import build_pdf
# this builds a pdf-file inside a temporary directory
pdf = build_pdf(min_latex)
# look at the first... | 1 | 2016-07-18T07:38:55Z | 38,431,421 | <p>It seems like your're missiing the latex binaries.</p>
<p>On linux machines it's calles <code>texlive</code> --> <a href="http://www.tug.org/texlive/" rel="nofollow">More infos</a></p>
<p>For example Ubuntu:</p>
<pre><code>sudo apt-get install texlive
</code></pre>
<p>For OSX you can install <a href="https://tug... | 1 | 2016-07-18T08:00:14Z | [
"python",
"python-2.7",
"latex"
] |
Runtime error in build_pdf module of latex - python | 38,431,066 | <p>Below is my latex_template.py file</p>
<pre><code>min_latex = (r"\documentclass{article}"
r"\begin{document}"
r"Hello, world!"
r"\end{document}")
from latex import build_pdf
# this builds a pdf-file inside a temporary directory
pdf = build_pdf(min_latex)
# look at the first... | 1 | 2016-07-18T07:38:55Z | 38,433,604 | <p>If your system is ubuntu or debian, the solution is below.</p>
<pre><code>sudo apt-get install latexmk
</code></pre>
<p>If your system is other linux distribution, you need to find solution to install "latexmk" by yourself.</p>
<p>You must haven't installed "latexmk" judged by "bool(which(self.latexmk))" in the f... | 0 | 2016-07-18T09:50:33Z | [
"python",
"python-2.7",
"latex"
] |
_tkinter.TclError: can't find package Tktable | 38,431,120 | <p>I wanted to run this program posted here <a href="http://tkinter.unpythonic.net/wiki/TkTableCalendar" rel="nofollow">http://tkinter.unpythonic.net/wiki/TkTableCalendar</a>, but to run this I need the <code>tktable</code> wrapper <a href="https://tkinter.unpythonic.net/wiki/TkTableWrapper" rel="nofollow">https://tkin... | 1 | 2016-07-18T07:42:17Z | 38,431,714 | <p>You should install tktable...
Go this link: <a href="https://pypi.python.org/pypi/tkintertable/1.1.2" rel="nofollow">https://pypi.python.org/pypi/tkintertable/1.1.2</a></p>
<p>Download it...
Extract file.
And open the folder which has been extracted.
Open command prompt in same folder and type this command:</p>
<b... | -1 | 2016-07-18T08:15:54Z | [
"python",
"tkinter",
"tktable"
] |
_tkinter.TclError: can't find package Tktable | 38,431,120 | <p>I wanted to run this program posted here <a href="http://tkinter.unpythonic.net/wiki/TkTableCalendar" rel="nofollow">http://tkinter.unpythonic.net/wiki/TkTableCalendar</a>, but to run this I need the <code>tktable</code> wrapper <a href="https://tkinter.unpythonic.net/wiki/TkTableWrapper" rel="nofollow">https://tkin... | 1 | 2016-07-18T07:42:17Z | 38,439,697 | <p>After searching for a long time I found this</p>
<blockquote>
<p><a href="http://blog.clintecker.com/post/148453368/tktable-for-tkinter-and-python" rel="nofollow">http://blog.clintecker.com/post/148453368/tktable-for-tkinter-and-python</a></p>
</blockquote>
<p>which solves my problem.</p>
<p>Now the <code>TkTab... | 0 | 2016-07-18T14:46:25Z | [
"python",
"tkinter",
"tktable"
] |
Call a custom function inside cx_Oracle | 38,431,403 | <p>I have a custom function in Oracle Locator and I will use this function inside cx_Oracle to transform my SDO_Geometry in GeoJSON!</p>
<pre><code>import cx_Oracle
import json
connection = cx_Oracle.Connection("TEST_3D/limo1013@10.40.33.160:1521/sdetest")
cursor = connection.cursor()
cursor.execute("""SELECT a.id A... | 0 | 2016-07-18T07:59:09Z | 38,460,018 | <p>This capability is available in the currently unreleased version of cx_Oracle. You can get the source from <a href="https://bitbucket.org/anthony_tuininga/cx_oracle" rel="nofollow">https://bitbucket.org/anthony_tuininga/cx_oracle</a>.</p>
| 0 | 2016-07-19T13:28:09Z | [
"python",
"json",
"cx-oracle"
] |
Python QT NextButton action as validation | 38,431,429 | <p>I want to perform some action when the next button is clicked before allowing the next page to be passed(for example run a function), when I tried doing it using connect I found that the actions of the next page are already performed(even though it is not shown, meaning some other thread is already running the next ... | 0 | 2016-07-18T08:00:33Z | 38,432,664 | <p>You can reimplement <code>QWizard::validateCurrentPage()</code>, returning <code>false</code> if the next page is not allowed.</p>
<p>See <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qwizard.html#validateCurrentPage" rel="nofollow">QWizard::validateCurrentPage</a></p>
| 1 | 2016-07-18T09:07:31Z | [
"python",
"multithreading",
"qt"
] |
BeautifulSoup returning [] when I run it | 38,431,446 | <p>I am using Beautiful soup with python to retrieve weather data from a website.</p>
<p>Here's how the website looks like:</p>
<pre class="lang-xml prettyprint-override"><code><channel>
<title>2 Hour Forecast</title>
<source>Meteorological Services Singapore</source>
<description>... | 1 | 2016-07-18T08:01:25Z | 38,431,810 | <p>The <a href="https://www.nea.gov.sg/api/" rel="nofollow">main API page on the Singapore NEA site</a> shows clearly that the response you get is an XML document:</p>
<blockquote>
<p>2-hour Nowcast<br>
<strong>Data Description</strong>: Weather forecast for next 2 hours<br>
<strong>Last API Update</strong>: 1-... | 2 | 2016-07-18T08:22:07Z | [
"python",
"xml",
"beautifulsoup"
] |
Django Rest Framework permission_class | 38,431,484 | <p>I am new to DRF, and I had came across the following problem when I trying to customize the <a href="http://www.django-rest-framework.org/api-guide/permissions/" rel="nofollow">Permission</a> in DRF.</p>
<p>Suppose I had the following code in my permissions.py file:</p>
<pre><code>class GetPermission(BasePermissio... | 0 | 2016-07-18T08:03:35Z | 38,432,242 | <p>You need to create subclasses of your permission for each attribute, and use <code>self.obj_attr</code> inside the <code>has_permission</code> method.</p>
<pre><code>class DefaultPermission(GetPermission):
obj_attr = 'POITS'
class AssignmentPermission(GetPermission):
obj_attr = 'ASSIGNMENT'
</code></pre>
| 0 | 2016-07-18T08:45:37Z | [
"python",
"django",
"rest",
"permissions",
"django-rest-framework"
] |
Improving python code- how to group list elements by their property values | 38,431,639 | <p>I have the following piece of code in Python, it is organizing(grouping) playing cards by their ranks. I did this in old-school way but I am sure there is a better way as Python is actually famous of that kind of thing.
How can I do the same in shorter and more elegant way?</p>
<p>Here is the method code:</p>
<pre... | 0 | 2016-07-18T08:12:03Z | 38,431,952 | <ul>
<li><a href="https://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP8</a>
<ul>
<li><code>gather_ranks</code> instead of <code>gatherRanks</code></li>
<li>Indent using 4 spaces instead of 8</li>
</ul></li>
<li>Use lists / dicts and for loops to make it more compact and thus more readable (and less prone to m... | 0 | 2016-07-18T08:29:39Z | [
"python"
] |
Improving python code- how to group list elements by their property values | 38,431,639 | <p>I have the following piece of code in Python, it is organizing(grouping) playing cards by their ranks. I did this in old-school way but I am sure there is a better way as Python is actually famous of that kind of thing.
How can I do the same in shorter and more elegant way?</p>
<p>Here is the method code:</p>
<pre... | 0 | 2016-07-18T08:12:03Z | 38,432,878 | <p>Real improvement is only possible here if you get rid of your <code>self.value1</code>, <code>self.value2</code>, etc. lists. Whenever you see yourself creating variables like that, you should be using a list instead.</p>
<p>The following code does what you want (I omitted the <code>self</code> because it's not rel... | 0 | 2016-07-18T09:16:47Z | [
"python"
] |
Improving python code- how to group list elements by their property values | 38,431,639 | <p>I have the following piece of code in Python, it is organizing(grouping) playing cards by their ranks. I did this in old-school way but I am sure there is a better way as Python is actually famous of that kind of thing.
How can I do the same in shorter and more elegant way?</p>
<p>Here is the method code:</p>
<pre... | 0 | 2016-07-18T08:12:03Z | 38,433,159 | <p>It looks like the number of ranks is pre-determined, judging from the use of variables self.value1 to self.value4.</p>
<p>If that is in fact the case, dictionary could come in handy.</p>
<pre><code>def gather_ranks(self, hand):
# initialize the dictionary with card ranks
# r1...r4 represents card ranks
... | 0 | 2016-07-18T09:29:02Z | [
"python"
] |
Improving python code- how to group list elements by their property values | 38,431,639 | <p>I have the following piece of code in Python, it is organizing(grouping) playing cards by their ranks. I did this in old-school way but I am sure there is a better way as Python is actually famous of that kind of thing.
How can I do the same in shorter and more elegant way?</p>
<p>Here is the method code:</p>
<pre... | 0 | 2016-07-18T08:12:03Z | 38,433,212 | <p>(Edited example)</p>
<p>I would use a <a href="https://docs.python.org/3/library/collections.html?highlight=defaultdict#collections.defaultdict" rel="nofollow">defaultdict</a>:</p>
<pre><code>from collections import defaultdict
from pprint import pprint
import itertools
import random
class Card(object):
def ... | 0 | 2016-07-18T09:32:04Z | [
"python"
] |
Running openmdao 1.7.0 GUI | 38,431,782 | <p>Is openmdao GUI available on 1.7.0 version? And if yes, how to run it? I have found, how to run the GUI on the 0.10.7 version, but it doesn't work on the 1.7. </p>
| 1 | 2016-07-18T08:20:09Z | 38,436,394 | <p>We no longer have a GUI, and certain changes that we made to improve performance and maintainability have made it unlikely that OpenMDAO is capable of being run interactively like it was before.</p>
<p>However, we have been working on some visualization tools. You should definitely check out the N2 viewer:</p>
<pr... | 3 | 2016-07-18T12:11:44Z | [
"python",
"python-3.x",
"openmdao"
] |
Running openmdao 1.7.0 GUI | 38,431,782 | <p>Is openmdao GUI available on 1.7.0 version? And if yes, how to run it? I have found, how to run the GUI on the 0.10.7 version, but it doesn't work on the 1.7. </p>
| 1 | 2016-07-18T08:20:09Z | 38,446,190 | <p>Worked for me after updating to 1.7.1 via pip on Fedora v20. The command with conventional naming is: </p>
<blockquote>
<blockquote>
<p>view_tree(top)</p>
</blockquote>
</blockquote>
| 0 | 2016-07-18T21:21:07Z | [
"python",
"python-3.x",
"openmdao"
] |
Large graph as input to find all paths | 38,431,849 | <p>I'm using the following python code in order to find all paths between each two nodes. It's not any problem for small graphs.</p>
<pre><code>def bfs(graph, start, end):
# maintain a queue of paths
queue = []
# push the first path into the queue
queue.append([start])
while queue:
# get th... | 1 | 2016-07-18T08:24:11Z | 38,435,818 | <p>Your answer is it may <strong>couldn't be done</strong>, <strong>except</strong> the case that your graph is a special graph, number of paths between two nodes in such graph may be enormous.consider following case:
For a complete graph of 200 vertices and 20K edges there is <strong>198!/2</strong> different paths be... | 0 | 2016-07-18T11:40:35Z | [
"python",
"graph",
"bigdata",
"shortest-path"
] |
Python: nested if statements in lambda | 38,431,958 | <p>How are you supposed to write nested if statements in lambda functions?</p>
<p>I'm trying to use a filter function using lambda:</p>
<pre><code>final_list = filter(lambda x: False if isinstance x(float) or isinstance(x, int) if x<5, another_list)
</code></pre>
<p>What I'm trying to do is:</p>
<ol>
<li>Check i... | 0 | 2016-07-18T08:30:01Z | 38,432,006 | <p>You can't use statements in a lambda, only expressions. In addition, your <code>isinstance()</code> calls are wrong too.</p>
<p>In this case, you only need a boolean expression anyway:</p>
<pre><code>final_list = filter(lambda x: not (isinstance(x, (int, float)) and x < 5), another_list)
</code></pre>
<p>This'... | 3 | 2016-07-18T08:32:02Z | [
"python"
] |
Python: nested if statements in lambda | 38,431,958 | <p>How are you supposed to write nested if statements in lambda functions?</p>
<p>I'm trying to use a filter function using lambda:</p>
<pre><code>final_list = filter(lambda x: False if isinstance x(float) or isinstance(x, int) if x<5, another_list)
</code></pre>
<p>What I'm trying to do is:</p>
<ol>
<li>Check i... | 0 | 2016-07-18T08:30:01Z | 38,432,124 | <p>Like Martijn said, in this specific example you could fit what you want into a lambda function. However, if in the future you want to make a filter with conditions that don't fit cleanly in a lambda function, you could make a separate function and pass it in to <code>filter</code> as an argument. Try something like ... | 0 | 2016-07-18T08:38:54Z | [
"python"
] |
Searching a TreeView | 38,432,030 | <p>I am working on a project and am using a treeview. I have done lots of searching and all ive found to my answer is to itterate through the whole treeview but not even how to do it, so my question is how do i search a treeview for an item that contains an input string. The idea will be to have an entry box and have u... | 0 | 2016-07-18T08:33:12Z | 38,501,981 | <p>This answer is an outline of the solution.</p>
<p>You may find the code I wrote for SCM Workbench useful for reference:</p>
<p><a href="https://github.com/barry-scott/scm-workbench/blob/master/Source/Scm/wb_scm_table_model.py" rel="nofollow">https://github.com/barry-scott/scm-workbench/blob/master/Source/Scm/wb_sc... | 0 | 2016-07-21T10:38:23Z | [
"python",
"treeview",
"pyqt5"
] |
Kivy importing Python variables into inline KV | 38,432,104 | <p>I've been banging my head off this particular wall for days now. None of the relevant articles here have worked, so I really need to know where I'm going wrong. The relevant sections of code are:</p>
<pre><code> def print_scb(myscb):
print(myscb)
scb_string = ''
scb_list = [ 'Combat' , 'C... | 1 | 2016-07-18T08:37:30Z | 38,433,675 | <p>As you mentioned in the comments.</p>
<blockquote>
<p>print_scb is not a global function. It is defined in the CharacterSheet(Screen): class.</p>
</blockquote>
<p>When you defined the function you forgor self.</p>
<p>So instead of <code>def print_scb(myscb):</code> it shall be <code>def print_scb(self, myscb):<... | 0 | 2016-07-18T09:53:45Z | [
"python",
"variables",
"kivy"
] |
Thread from another class in a Producer Consumer with Queue | 38,432,277 | <p>I would like to implement a for a Consumer Producer implementations. I haven't implemented the consumer yet because I have a problem with the Producer. The purpose is to download some files in the internet. The threads are started inside a method of a custom object. Threads are objects subclassing threading.Thread. ... | 1 | 2016-07-18T08:47:27Z | 38,433,048 | <p>Your threads never terminate, as they have a <code>run()</code> method with an infinite loop. In your <code>download()</code> method you <a href="https://docs.python.org/2/library/threading.html#threading.Thread.join" rel="nofollow"><code>join()</code></a> to those threads:</p>
<pre><code> for thread in self... | 1 | 2016-07-18T09:24:03Z | [
"python",
"multithreading",
"queue",
"producer-consumer"
] |
python subprocess pipe unbuffered behaviour | 38,432,336 | <p>I've the below piece of code to read data from a child process as its generated and write to a file. </p>
<pre>
from subprocess import Popen, PIPE
proc = Popen('..some_shell_command..', shell=True, stdout=PIPE)
fd = open("/tmp/procout", "wb")
while True:
data = proc.stdout.read(1024)
if len(data) == 0:
... | 0 | 2016-07-18T08:51:09Z | 38,433,285 | <p>Answering to your questions:</p>
<ul>
<li>No, it will not be stored in memory. The child process will stuck on <code>write</code> operation after exceeding <code>pipe-max-size</code> limit (cat /proc/sys/fs/pipe-max-size);</li>
<li>The child process will write about 1M before it will stuck, until the parent process... | 1 | 2016-07-18T09:35:05Z | [
"python",
"pipe",
"subprocess",
"buffer"
] |
Submit ChoiceField form Django | 38,432,468 | <p>I'm dealing with how make a custom form in Django and now I'm stuck on the submit step.</p>
<p>When I press submit, I'm getting an <code>__init__() got multiple values for keyword argument 'networkList'</code>.</p>
<p>My <code>forms.py</code> it's:</p>
<pre><code>class SimpleDeploy(forms.Form):
def __init__(s... | 0 | 2016-07-18T08:58:00Z | 38,432,587 | <p>You've defined your form init so that the first positional argument is <code>networkList</code>; so when you do <code>form = SimpleDeploy(request.POST, networkList=None...)</code>, both the positional arg and the keyword arg both go to the same name, which isn't allowed.</p>
<p>Don't change the signature at all; ge... | 1 | 2016-07-18T09:03:41Z | [
"python",
"django",
"forms",
"post",
"choicefield"
] |
Inconsistent labeling in sklearn LabelEncoder? | 38,432,632 | <p>I have applied a <code>LabelEncoder()</code> on a dataframe, which returns the following:</p>
<blockquote>
<p><a href="http://i.stack.imgur.com/yETjp.png" rel="nofollow"><img src="http://i.stack.imgur.com/yETjp.png" alt="enter image description here"></a></p>
</blockquote>
<p>The <code>order/new_cart</code>s hav... | 4 | 2016-07-18T09:05:44Z | 38,432,949 | <p>LabelEncoder works on one-dimensional arrays. If you apply it to multiple columns, it will be consistent within columns but not across columns.</p>
<p>As a workaround, you can convert the dataframe to a one dimensional array and call LabelEncoder on that array.</p>
<p>Assume this is the dataframe:</p>
<pre><code>... | 4 | 2016-07-18T09:19:45Z | [
"python",
"pandas",
"scikit-learn"
] |
Inconsistent labeling in sklearn LabelEncoder? | 38,432,632 | <p>I have applied a <code>LabelEncoder()</code> on a dataframe, which returns the following:</p>
<blockquote>
<p><a href="http://i.stack.imgur.com/yETjp.png" rel="nofollow"><img src="http://i.stack.imgur.com/yETjp.png" alt="enter image description here"></a></p>
</blockquote>
<p>The <code>order/new_cart</code>s hav... | 4 | 2016-07-18T09:05:44Z | 38,433,781 | <h3>Your <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html" rel="nofollow">LabelEncoder</a> object is being re-fit to each column of your DataFrame.</h3>
<p>Because of the way the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html"... | 2 | 2016-07-18T09:58:51Z | [
"python",
"pandas",
"scikit-learn"
] |
pattern between two strings in python | 38,432,655 | <p>I have a string in following format:</p>
<p>In-product feedback from Vince (aaa@bbb.com)...In-product feedback from Corey Zimmerman Anderson (ccc@ddd.com)...In-product feedback from Andrea Ibarra (eee@fff.com)</p>
<p>I need to extract the email ID from above string. The "In-product feedback from " will be static a... | -6 | 2016-07-18T09:07:15Z | 38,432,775 | <p>Use the following code:</p>
<pre><code>import re
r = re.findall(r"\(([^)]+)\)", s)
print(r)
</code></pre>
<p>where s in your strings.</p>
| 1 | 2016-07-18T09:12:29Z | [
"python",
"regex"
] |
pattern between two strings in python | 38,432,655 | <p>I have a string in following format:</p>
<p>In-product feedback from Vince (aaa@bbb.com)...In-product feedback from Corey Zimmerman Anderson (ccc@ddd.com)...In-product feedback from Andrea Ibarra (eee@fff.com)</p>
<p>I need to extract the email ID from above string. The "In-product feedback from " will be static a... | -6 | 2016-07-18T09:07:15Z | 38,432,839 | <p>Since the text you have is pretty much static and names will likely not contain <code>()</code> you can use a non regex approach:</p>
<pre><code>s = "In-product feedback from Vince (aaa@bbb.com)"
s_clean = s.rsplit('(')[1].strip(')')
print(s_clean)
# 'aaa@bbb.com'
</code></pre>
<p>Or use regex anyway:</p>
<pre><c... | 3 | 2016-07-18T09:15:05Z | [
"python",
"regex"
] |
pattern between two strings in python | 38,432,655 | <p>I have a string in following format:</p>
<p>In-product feedback from Vince (aaa@bbb.com)...In-product feedback from Corey Zimmerman Anderson (ccc@ddd.com)...In-product feedback from Andrea Ibarra (eee@fff.com)</p>
<p>I need to extract the email ID from above string. The "In-product feedback from " will be static a... | -6 | 2016-07-18T09:07:15Z | 38,432,909 | <p>Try this</p>
<pre><code>import re
str = 'In-product feedback from Vince (aaa@bbb.com)'
regex = '(In-product feedback from) ([a-zA-Z ]+) \(([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)\)'
phrase= re.match(regex, str)
print phrase.group(1) # In-product feedback from
print phrase.group(2) # Vince
print phrase.grou... | 0 | 2016-07-18T09:18:00Z | [
"python",
"regex"
] |
scrapy a weird bug code that can't call pipeline | 38,432,786 | <p>I write a small spider, when I run and it can't call pipeline.</p>
<p>After debug for a while, I find the bug code area.</p>
<p>The logic of the spider is that I crawl the first url to fetch cookie, then I crawl the second url to download the code picture with cookie, and I post some data I prepare to the third ur... | 0 | 2016-07-18T09:13:00Z | 38,459,442 | <p>The problem seems to be that the <code>parse</code> method only yields <code>scrapy.Request</code> objects, never <code>scrapy.Item</code> instances.</p>
<p>The <code>else:</code> branch calls the generator <code>parseData(body)</code> but doesn't use the data it can produce (namely <code>containItem</code> objects... | 0 | 2016-07-19T13:03:12Z | [
"python",
"scrapy",
"web-crawler"
] |
Dynamic XML template generation using get_template jinja2 | 38,432,809 | <p>I am new in Python as well as in XML, I am using the below python code and xml file to replace the value of variables in xml file and generate another output xml file with updated value in parameter <code>{{param}}</code>.</p>
<p><strong>netconf_payload.py</strong></p>
<pre><code>#!/usr/bin/env python
import os
fr... | -1 | 2016-07-18T09:13:46Z | 38,433,012 | <p>So <code>param</code> is a list which always has 3 values? I don't think you want to iterate over it in this case, I think instead you need to reference each item in the list explicitly to get the output you want. E.g.</p>
<pre><code><bridge>
<bridgeId>{{ param[0] }}</bridgeId>
<bridg... | 0 | 2016-07-18T09:22:18Z | [
"python",
"xml",
"jinja2"
] |
Dynamic XML template generation using get_template jinja2 | 38,432,809 | <p>I am new in Python as well as in XML, I am using the below python code and xml file to replace the value of variables in xml file and generate another output xml file with updated value in parameter <code>{{param}}</code>.</p>
<p><strong>netconf_payload.py</strong></p>
<pre><code>#!/usr/bin/env python
import os
fr... | -1 | 2016-07-18T09:13:46Z | 38,433,051 | <p>You are looping over <code>param</code>, which is a list of 3 elements:</p>
<pre><code>param = [3, 'ieee', 3]
</code></pre>
<p>For each of these values, you create <em>3 elements</em>:</p>
<pre class="lang-xml prettyprint-override"><code>{% for param in param -%}
<bridgeId>{{ param }}</bridgeId&g... | 0 | 2016-07-18T09:24:06Z | [
"python",
"xml",
"jinja2"
] |
Listing extractors from import.io | 38,432,877 | <p>I would like to know how to get the crawling data (list of URLs manually input through the GUI) from my import.io extractors.
The API documentation is very scarce and it does not specify if the GET requests I make actually start a crawler (and consume one of my crawler available runs) or just query the result of man... | 1 | 2016-07-18T09:16:46Z | 38,775,977 | <p>The legacy API will not work for any non-legacy connectors, so you will have to use the new Web Extractor API. Unfortunately, there is no documentation for this. </p>
<p>Luckily, with some snooping you can find the following call to list connectors connected to your apikey:</p>
<pre><code>https://store.import.io/s... | 1 | 2016-08-04T19:35:44Z | [
"python",
"web-crawler",
"import.io"
] |
mysql.connector.errors.interfaceerror 2003 | 38,432,882 | <p>My summer project is to put data into SQL for processing. Unfortunately I can not establish a connection to the SQL with mysql connector.</p>
<p>The python file I am testing with are two lines:
import mysql.connector</p>
<pre><code>db1 = mysql.connector.connect(host="localhost", database="thename", user="user",pas... | 0 | 2016-07-18T09:16:52Z | 38,440,072 | <p>Once again it has been proven that it is easy to get blinded when digging. I was trying to use mysql connector to connect to a ms sql. I have now switched to pypyodbc to handle the communication with the SQL.</p>
| 0 | 2016-07-18T15:03:22Z | [
"python",
"sql",
"localhost",
"connection-refused"
] |
Django pagination from doc not working | 38,432,955 | <p>I referred pagination code from official django documentation.I am not getting any error but all the objects are being displayed in the same page.I have ten objects in the view and I gave 5 objects(book image with details) to be displayed in each page but all 10 objects are being displayed in page 1 and 2.</p>
<p>v... | 0 | 2016-07-18T09:20:01Z | 38,433,117 | <p>You are sending <code>my_product_list</code> to the template, which is your entire queryset before pagination. Your context dictionary should instead look like:</p>
<pre><code>context = {
"form":form,
"products":queryset,
}
</code></pre>
<p>And then in the template, use <code>{% products.has_next %... | 1 | 2016-07-18T09:27:13Z | [
"python",
"django"
] |
Which exception to raise if arrived at an illegal location in code? | 38,433,028 | <p>My code needs to process either a file or a directory (either of them is accepted from the shell as arguments from <code>argparse</code>).</p>
<p>The relevant snippet is:</p>
<pre><code>if in_dir:
in_glob = os.path.join(in_dir, "*." + ext)
elif in_file:
in_glob = in_file
else:
# Should never arrive her... | 1 | 2016-07-18T09:23:06Z | 38,433,143 | <p>Many other languages have an <code>assert_not_reached</code> function for this purpose, but python does not. It's commonly subsituted with</p>
<pre><code>assert False, 'this should never be reached'
</code></pre>
<p>or something similar.</p>
| 2 | 2016-07-18T09:28:35Z | [
"python",
"exception",
"exception-handling"
] |
Which exception to raise if arrived at an illegal location in code? | 38,433,028 | <p>My code needs to process either a file or a directory (either of them is accepted from the shell as arguments from <code>argparse</code>).</p>
<p>The relevant snippet is:</p>
<pre><code>if in_dir:
in_glob = os.path.join(in_dir, "*." + ext)
elif in_file:
in_glob = in_file
else:
# Should never arrive her... | 1 | 2016-07-18T09:23:06Z | 38,433,429 | <p>I would recommend to use either <code>SystemError</code> or <code>EnvironmentError</code> but will be handy to use <code>IOError</code> or <code>LookupError</code> as well.</p>
| 0 | 2016-07-18T09:42:49Z | [
"python",
"exception",
"exception-handling"
] |
Wrapped error with setup_databases for pytest-django | 38,433,029 | <p>After I added a new class to my models, I am unable to run my tests in my server. The problem is the error message seems to be wrapped and doesn't provide further information about the error. As you can see, the table doesn't exist in the database, as expected, but why can't I retrieve more information why it fails ... | 0 | 2016-07-18T09:23:12Z | 38,437,941 | <p>Well, after hours I found out I was forgetting to commit my migrations to GitLab. <code>pytest-django</code> didn't know what to migrate, therefore the problem.</p>
| 0 | 2016-07-18T13:25:56Z | [
"python",
"django",
"py.test",
"pytest-django"
] |
Is regex in Python too slow? | 38,433,077 | <p>I have a set of sentences in a file ( say <code>500</code> ). I am trying to find whether a pair of words ( say <code>word1</code> and <code>word2</code> ) is present in any of the sentences. I have <code>58000</code> such pairs of words.</p>
<p>For example, let the set of sentences be:</p>
<p><code>I am a good b... | 0 | 2016-07-18T09:25:29Z | 38,435,677 | <p>You say you have 500 sentences and 58000 word pairs which means you intend to create 58000 different regular expressions to run against the sentences and most of the searches will match nothing.</p>
<p>A better approach by far would be to create a <code>dict</code> mapping each word that occurs in a word pair to a ... | 4 | 2016-07-18T11:33:27Z | [
"python",
"regex"
] |
Is regex in Python too slow? | 38,433,077 | <p>I have a set of sentences in a file ( say <code>500</code> ). I am trying to find whether a pair of words ( say <code>word1</code> and <code>word2</code> ) is present in any of the sentences. I have <code>58000</code> such pairs of words.</p>
<p>For example, let the set of sentences be:</p>
<p><code>I am a good b... | 0 | 2016-07-18T09:25:29Z | 38,435,802 | <p>You've got to keep in mind that the better way to do a thing is to use the <em>right</em> tool. Regex are good for (complex) pattern matching where you can't use method like <code>word1 in sentence</code> because you're looking for a pattern and not a finite string.</p>
<p>Some will says that <em>regex is faster</e... | 4 | 2016-07-18T11:39:52Z | [
"python",
"regex"
] |
python spider how to get the input radio's value | 38,433,344 | <p>the part of the html is:</p>
<pre class="lang-html prettyprint-override"><code><p class="more">
<span>S</span><br />
<input type="radio" name="rt0" value="0/0/S" onclick='showEI(this,"0", "0", "","S")'/>
ï¿¥1140<br />
<span class="seatNum">>9</span>... | 0 | 2016-07-18T09:38:33Z | 38,433,400 | <p>the part of html is:</p>
<pre><code><p class="more">
<span>S</span><br />
<input type="radio" name="rt0" value="0/0/S" onclick='showEI(this,"0", "0", "","S")'/>
ï¿¥1140<br />
<span class="seatNum">>9</span>
</p>
</code></pre>
| 0 | 2016-07-18T09:41:25Z | [
"jquery",
"python",
"input",
"radio",
"elementtree"
] |
python spider how to get the input radio's value | 38,433,344 | <p>the part of the html is:</p>
<pre class="lang-html prettyprint-override"><code><p class="more">
<span>S</span><br />
<input type="radio" name="rt0" value="0/0/S" onclick='showEI(this,"0", "0", "","S")'/>
ï¿¥1140<br />
<span class="seatNum">>9</span>... | 0 | 2016-07-18T09:38:33Z | 38,434,181 | <pre><code>html = """<p class="more">
<span>S</span><br />
<input type="radio" name="rt0" value="0/0/S" onclick='showEI(this,"0", "0", "","S")'/>
ï¿¥1140<br />
<span class="seatNum">>9</span>
</p>"""
import re
pattern = re.compile('<input type=... | 0 | 2016-07-18T10:17:48Z | [
"jquery",
"python",
"input",
"radio",
"elementtree"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.