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
python write cell to matrix in wrong way
39,009,805
<p>I have a simple code for testing, my code supposed to only write matrix at (1,1) and (2,2), these two cells.</p> <pre><code>grid = [ [1,1,1,2,], [1,9,1,2,], [1,8,9,2,], [1,2,3,4,] ] n = 4 duplicate = [[0]*n]*n for i in range(1,n-1): for j in range(1,n-1): cur = grid[i][j] if (cur &gt; grid[...
0
2016-08-18T04:03:18Z
39,009,850
<p>Usual mistake: <code>[[0]*n]*n</code> creates a list of <code>n</code> references to the same list <code>[0]*n</code>. You need do this to create <code>n</code> different lists: <code>[[0]*n for _ in range(n)]</code> so you can update each one of them independently.</p>
1
2016-08-18T04:09:39Z
[ "python" ]
python write cell to matrix in wrong way
39,009,805
<p>I have a simple code for testing, my code supposed to only write matrix at (1,1) and (2,2), these two cells.</p> <pre><code>grid = [ [1,1,1,2,], [1,9,1,2,], [1,8,9,2,], [1,2,3,4,] ] n = 4 duplicate = [[0]*n]*n for i in range(1,n-1): for j in range(1,n-1): cur = grid[i][j] if (cur &gt; grid[...
0
2016-08-18T04:03:18Z
39,009,947
<p>The list your create use [[0]*n]*n is the same, You can prove by</p> <pre><code>duplicate = [[0]*4]*4 duplicate[1][1] = 1 </code></pre> <p>You may understand more by look at this problem</p> <pre><code>def extendList(val, list=[]): list.append(val) return list list1 = extendList(10) list2 = extendList(12...
0
2016-08-18T04:20:15Z
[ "python" ]
Python - How to display a single data point on a scatter plot?
39,009,872
<p>I'm trying to display a 3D scatter plots. The code below works but it displays the current and old data points. I would like to display only one at a time. I've tried different options but I can't get it to work properly. Any suggestions?</p> <p>Thanks!</p> <pre><code>import matplotlib.pyplot as plt import matplot...
0
2016-08-18T04:11:58Z
39,017,438
<p>You can clear the axes in each iteration in the <code>for</code> loop. Note that you need to take care of the axes limits as well.</p> <pre><code>import matplotlib.pyplot as plt import matplotlib.animation as animation from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.add_subplot(111, projection=...
0
2016-08-18T11:48:12Z
[ "python", "animation", "matplotlib" ]
How to do a math equation using y = x^2 with range to print multiple outputs
39,009,897
<p>Hi this is my first question. I want this program to output y = x^2 y = 1-1000 and x = 1-1000 and it runs through each. This is what happens. Below source. </p> <pre><code>y = range(0,1000) x = range(0,1000) stuff = x ** 2 / y print stuff </code></pre> <blockquote> <pre><code>Traceback (most recent call last): ...
0
2016-08-18T04:14:46Z
39,009,985
<p><code>range(0,1000)</code> runs from 0 to 999. You want to use <code>range(1,1001)</code>.</p> <p>Try this:</p> <pre><code>for x in range(1, 1001): # from 1 to 1000 for y in range(1, 1001): stuff = (x ** 2)/y print stuff </code></pre>
0
2016-08-18T04:24:09Z
[ "python", "python-2.7" ]
How to do a math equation using y = x^2 with range to print multiple outputs
39,009,897
<p>Hi this is my first question. I want this program to output y = x^2 y = 1-1000 and x = 1-1000 and it runs through each. This is what happens. Below source. </p> <pre><code>y = range(0,1000) x = range(0,1000) stuff = x ** 2 / y print stuff </code></pre> <blockquote> <pre><code>Traceback (most recent call last): ...
0
2016-08-18T04:14:46Z
39,010,744
<p>As a list comprehension:</p> <pre><code>print [(x ** 2)/y for x in xrange(1, 1001) for y in xrange(1, 1001)] </code></pre>
1
2016-08-18T05:48:49Z
[ "python", "python-2.7" ]
How to do a math equation using y = x^2 with range to print multiple outputs
39,009,897
<p>Hi this is my first question. I want this program to output y = x^2 y = 1-1000 and x = 1-1000 and it runs through each. This is what happens. Below source. </p> <pre><code>y = range(0,1000) x = range(0,1000) stuff = x ** 2 / y print stuff </code></pre> <blockquote> <pre><code>Traceback (most recent call last): ...
0
2016-08-18T04:14:46Z
39,012,047
<p>Using <code>map</code>:</p> <pre><code>&gt;&gt;&gt; map(lambda x, y: (x ** 2)/y, xrange(1, 1001), xrange(1, 1001)) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 5...
0
2016-08-18T07:15:33Z
[ "python", "python-2.7" ]
How to replace an re match with a transformation of that match?
39,009,967
<p>For example, I have a string:</p> <pre class="lang-none prettyprint-override"><code>The struct-of-application and struct-of-world </code></pre> <p>With <code>re.sub</code>, it will replace the matched with a predefined string. How can I replace the match with a transformation of the matched content? To get, for ...
1
2016-08-18T04:22:28Z
39,010,075
<p>Try this:</p> <pre><code>&gt;&gt;&gt; p = re.compile(r"((\w+-)+\w+)") &gt;&gt;&gt; p.sub('[\\1](http://\\1)','The struct-of-application and struct-of-world') 'The [struct-of-application](http://struct-of-application) and [struct-of-world](http://struct-of-world)' </code></pre>
1
2016-08-18T04:34:43Z
[ "python", "regex" ]
How to replace an re match with a transformation of that match?
39,009,967
<p>For example, I have a string:</p> <pre class="lang-none prettyprint-override"><code>The struct-of-application and struct-of-world </code></pre> <p>With <code>re.sub</code>, it will replace the matched with a predefined string. How can I replace the match with a transformation of the matched content? To get, for ...
1
2016-08-18T04:22:28Z
39,010,137
<p>Use a <a href="https://docs.python.org/3/library/re.html#re.sub" rel="nofollow">function for the replacement</a></p> <pre><code>s = 'The struct-of-application and struct-of-world' p = re.compile('((\w+-)+\w+)') def replace(match): return 'http://{}'.format(match.group()) &gt;&gt;&gt; p.sub(replace, s) 'The h...
2
2016-08-18T04:41:50Z
[ "python", "regex" ]
How to speed up math operations in Python?
39,009,986
<p>I am writing a code in Python in which I am doing a lot of matrix multiplications on huge matrices. For the performance as well as the speed I am using numpy.einsum. Anyways, that einum is optimized very well, my code works very slowly. This is a reason that I'm looking for a solution to speed it up. I thought that ...
-3
2016-08-18T04:24:19Z
39,011,812
<p><code>einsum</code> constructs an iterator (<code>ndinter</code>) that loops (in C) over the problem space. With the dimensions and indexes in your expression that space is <code>1000**5</code> (5 variables, each of size 1000). That's <code>10**15</code> operations.</p> <p>If the problem involved multiplying 3 or...
0
2016-08-18T07:01:29Z
[ "python", "performance", "numpy" ]
How to speed up math operations in Python?
39,009,986
<p>I am writing a code in Python in which I am doing a lot of matrix multiplications on huge matrices. For the performance as well as the speed I am using numpy.einsum. Anyways, that einum is optimized very well, my code works very slowly. This is a reason that I'm looking for a solution to speed it up. I thought that ...
-3
2016-08-18T04:24:19Z
39,013,856
<blockquote> <p>'Matrx_krls is 1000 by 1000 by 1000 by 1000'</p> </blockquote> <p>So thats a 4-terabyte array, assuming 4-byte floats... I think you are better off investing time in Hadoop than in GPGPU. Even if you stream that data to a GPU, you will see little benefit because of limited PCIE bandwidth.</p> <p>Tha...
0
2016-08-18T08:54:24Z
[ "python", "performance", "numpy" ]
finding maximum value form csv column
39,010,023
<pre><code>dataset=[] f= open('auto-mpg-data.csv') csv_f=csv.reader(f) for row in csv_f: dataset.append(row) #reading column mpg=[] for row in dataset: mpg.append(row[0]) print(mpg) print(max(mpg)) </code></pre> <p>this is the <a href="http://i.stack.imgur.com/RcGgV.png" rel="nofollow">data</a>. When I try t...
0
2016-08-18T04:28:26Z
39,010,408
<p>The problem is that the items of the list <code>mpg</code> are strings, so the result is true as '9' is greater than '46.6' when comparing strings. You should convert the items in the list <code>mpg</code> to float numbers first:</p> <pre><code>mpg = [float(row[0]) for row in dataset] </code></pre>
0
2016-08-18T05:12:52Z
[ "python", "csv" ]
ValueError: invalid literal for int() with base 10: 'False'
39,010,059
<p>Any idea how to fix this issue?</p> <pre><code>Traceback (most recent call last): File "manage.py", line 1, in &lt;module&gt; from punchstarter import manager File "/app/punchstarter/__init__.py", line 29, in &lt;module&gt; mail = Mail(app) File "/app/.heroku/python/lib/python2.7/site-packages/flask_m...
-1
2016-08-18T04:33:11Z
39,492,066
<p>Set</p> <pre><code>app.debug = 0 </code></pre> <p>This worked for me</p> <pre><code>mail = Mail() app.debug = 0 mail.init_app(app) </code></pre>
0
2016-09-14T13:42:32Z
[ "python", "flask-mail" ]
pandas calculate the strangeness of the topic
39,010,111
<p>Here is a very short description of my task. I have a dataframe that looks like this: <code>df = pd.DataFrame([[2, 0], [2, 1], [1, 0], [1, 0], [1, 1], [3, 0]], columns=['topic', 'strange'])</code></p> <p>For every topic, I need to caclulate the percentage of rows that are 'strange'. So the result will be like this...
1
2016-08-18T04:38:18Z
39,010,250
<p>If <code>strange</code> is guaranteed to be 0 or 1 only, you can just take the mean:</p> <pre><code>In [7]: df.groupby("topic").mean() Out[7]: strange topic 1 0.333333 2 0.500000 3 0.000000 </code></pre>
2
2016-08-18T04:54:42Z
[ "python", "pandas" ]
How to compare multiple files in python and show all the name variations associated with SSN's
39,010,226
<p>Filter/sort files to list all names variations associated with each SSN.</p> <pre><code>Input File1: SSN, First Name, Last Name 333-22-9898, Tom, Tillman 556-11-7484, Mak, Burhan 333-22-9898, Tom, B Tillman Input File2: SSN, First Name, Last Name 857-87-9899, Si, H Input File 3.... Output File: 333-22-9898...
-1
2016-08-18T04:51:24Z
39,050,550
<p>Solution:</p> <pre><code>f = open('out.txt', 'w') # sample data in f1.txt (111-23-9999) filenames = ["f1.txt", "f2.txt", "f3.txt", "f4.txt"] files = [open(name) for name in filenames] sets = [set(line.strip() for line in file) for file in files] common = set.union(*sets) my_list = list(common) my_lis...
0
2016-08-20T04:42:18Z
[ "python", "python-3.x" ]
How to remove the brackets from the list in python
39,010,420
<p>I have a list:</p> <pre><code>list1 = ['field1','field2','field3'] </code></pre> <p>i have used different methods but i is of no help.</p> <pre><code>list1= ( " ".join( repr(e) for e in list1) ) </code></pre> <p>but it is printing each character in the string as seperate word like </p> <pre><code>"f","i","e","l...
-3
2016-08-18T05:14:06Z
39,010,545
<p>I <em>imagine</em> (the question isn't very clear as noted in the comments) you are looking for:</p> <pre><code>print ",".join(list1) </code></pre> <p>Produces:</p> <pre><code>field1,field2,field3 </code></pre> <blockquote> <p>So how can i remove only the brackets from the list without modifying the strings....
0
2016-08-18T05:28:03Z
[ "python" ]
How to remove the brackets from the list in python
39,010,420
<p>I have a list:</p> <pre><code>list1 = ['field1','field2','field3'] </code></pre> <p>i have used different methods but i is of no help.</p> <pre><code>list1= ( " ".join( repr(e) for e in list1) ) </code></pre> <p>but it is printing each character in the string as seperate word like </p> <pre><code>"f","i","e","l...
-3
2016-08-18T05:14:06Z
39,010,626
<p>Tada! <code>str(list1).strip('[').strip(']')</code></p> <p>Not sure if it is possible to get python to output:</p> <blockquote> <p>list1='field1','field2','field3'</p> </blockquote> <p>That is not valid python syntax... (unless defining a tuple):</p> <pre><code>&gt;&gt;&gt;list1='field1','field2','field3' ('fi...
0
2016-08-18T05:36:07Z
[ "python" ]
How to remove the brackets from the list in python
39,010,420
<p>I have a list:</p> <pre><code>list1 = ['field1','field2','field3'] </code></pre> <p>i have used different methods but i is of no help.</p> <pre><code>list1= ( " ".join( repr(e) for e in list1) ) </code></pre> <p>but it is printing each character in the string as seperate word like </p> <pre><code>"f","i","e","l...
-3
2016-08-18T05:14:06Z
39,010,699
<p>It sounds like you want to print your list in a specific format. You can do this using the <code>print()</code> function in python3 or the <code>print</code> statement in python2.</p> <p>First, make a string which represents how you want to output your list:</p> <pre><code>output = ",".join("'" + item + "'" for it...
0
2016-08-18T05:43:56Z
[ "python" ]
How to remove the brackets from the list in python
39,010,420
<p>I have a list:</p> <pre><code>list1 = ['field1','field2','field3'] </code></pre> <p>i have used different methods but i is of no help.</p> <pre><code>list1= ( " ".join( repr(e) for e in list1) ) </code></pre> <p>but it is printing each character in the string as seperate word like </p> <pre><code>"f","i","e","l...
-3
2016-08-18T05:14:06Z
39,010,919
<p>most of the previous answers would work, but perhaps the most simplest one is using a for loop:</p> <pre><code>mylist = ['1','2','3','4'] print('list=',end='') for myvar in mylist: print(myvar,end='') print('') </code></pre> <p>output:</p> <pre><code>list=1234 </code></pre> <p>however, this will only work ...
0
2016-08-18T06:02:32Z
[ "python" ]
How to remove the brackets from the list in python
39,010,420
<p>I have a list:</p> <pre><code>list1 = ['field1','field2','field3'] </code></pre> <p>i have used different methods but i is of no help.</p> <pre><code>list1= ( " ".join( repr(e) for e in list1) ) </code></pre> <p>but it is printing each character in the string as seperate word like </p> <pre><code>"f","i","e","l...
-3
2016-08-18T05:14:06Z
39,014,945
<p>Try this : <code>list1 = "'" + "','".join(list1) + "'"</code></p>
0
2016-08-18T09:44:53Z
[ "python" ]
Counting the number of times button is clicked during my program
39,010,447
<p>I am doing a program on a class list counter. I have one program, in frame 5 underneath "Population Count" and where it says 0, it is meant to increase by one for every time the button "Add to classlist" is clicked every time. I tried many different methods but all of those I tried never seem to work. It would be ap...
1
2016-08-18T05:17:26Z
39,010,520
<p>Rather than using a <strong>global</strong> <code>population</code> you need to declare <code>self.population = 0</code> in your <code>__init__</code> method and to increment <code>self.population</code> in your button click handler. It is normally also considered good practice to have a class method to get the valu...
3
2016-08-18T05:24:28Z
[ "python", "python-3.x", "tkinter" ]
Counting the number of times button is clicked during my program
39,010,447
<p>I am doing a program on a class list counter. I have one program, in frame 5 underneath "Population Count" and where it says 0, it is meant to increase by one for every time the button "Add to classlist" is clicked every time. I tried many different methods but all of those I tried never seem to work. It would be ap...
1
2016-08-18T05:17:26Z
39,016,244
<p><strong>Possible solution</strong>: if all you want to do is, have the population count, and increment it on each button click:</p> <pre><code>import pickle import os.path from tkinter import * import tkinter.messagebox import tkinter as tk class Class: def __init__(self, firstname, lastname): self.fir...
1
2016-08-18T10:47:58Z
[ "python", "python-3.x", "tkinter" ]
How to share raw input given in one file with another file in python
39,010,472
<p>I want raw input given in one file to be used in another file. For this I defined all variables in a <code>global_dec.py</code> file . Then modified the value of these variables in <code>main_file.py</code> and when I got printed these variables in another file <code>partfile.py</code> then variables having integer ...
0
2016-08-18T05:19:27Z
39,010,701
<p>If I am interpreting your question right you want to be able to do the following...</p> <pre><code>$ python main_file.py enter input for the global class: something main $ python partfile.py enter input for the global class: something else x: x inside global class y: something else a: 0 </code></pre> <p>If that ...
0
2016-08-18T05:44:02Z
[ "python" ]
Confidence in OpenCV FaceRecognizer predict method output
39,010,477
<p>I am using OpenCV for face recognition and have a newbie question. Here is a portion of my code:</p> <pre><code>recognizer = cv2.createLBPHFaceRecognizer() ... nbr_predicted, confidence = recognizer.predict(predict_image) ... </code></pre> <p>My question is the higher the <strong>confidence</strong> is means faces...
0
2016-08-18T05:20:11Z
39,046,368
<p>There is an implementation about face recognition wich you can read <a href="https://github.com/ragulin/face-recognition-server" rel="nofollow">here</a>. They use OpenCV with face module.</p> <p>In their read me there is an explanation about project and they say that confidence was more similiar when the number is ...
1
2016-08-19T19:24:01Z
[ "python", "opencv", "face-recognition" ]
Get file details in python
39,010,497
<p>I'm trying to extract the details of a file using Python. Specifically, when I right click a photo and select properties, under the Details tab of the menu that pops up, there's a whole bunch of details about the file. What I really need is the contents of the "People" detail.</p> <p>This is the menu in question:</...
2
2016-08-18T05:22:28Z
39,061,309
<p>This is not EXIF data but rather data that Windows populates for different types of objects in the Windows Property System.</p> <p>The one you are concerned with is called <a href="https://msdn.microsoft.com/en-us/library/dd391582(v=vs.85).aspx" rel="nofollow"><code>System.Photo.PeopleNames</code></a>:</p> <pre><c...
0
2016-08-21T06:04:09Z
[ "python", "file", "photo", "details" ]
Jupyter Notebook - Matplotlib keep running
39,010,594
<p>I just started to use <code>Jupiter Notebook</code> to learn <code>Python</code>. while I am trying out <code>matplotlib</code> with this basic code:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt plt.plot([1,2,3,4]) plt.ylabel('some numbers') plt.show() </code></pre> <p>The kernel just keep ru...
0
2016-08-18T05:33:54Z
39,010,693
<p>It likely showed you a Matplotlib popup, with the IP(y) logo. To show it inline you have to use some IPython magic. Run this in a cell somewhere:</p> <pre><code>%matplotlib inline </code></pre> <p>After you close the popup it will finish the statement in your kernel</p>
0
2016-08-18T05:43:33Z
[ "python", "numpy", "matplotlib", "ipython", "jupyter-notebook" ]
Jupyter Notebook - Matplotlib keep running
39,010,594
<p>I just started to use <code>Jupiter Notebook</code> to learn <code>Python</code>. while I am trying out <code>matplotlib</code> with this basic code:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt plt.plot([1,2,3,4]) plt.ylabel('some numbers') plt.show() </code></pre> <p>The kernel just keep ru...
0
2016-08-18T05:33:54Z
39,010,728
<p>To Visualize the plots created by the matplotlib in <strong>Jupiter Notebook or ipython notebook</strong> you have add one extra line at the beginning.</p> <pre><code>import numpy as np import matplotlib.pyplot as plt %matplotlib inline </code></pre> <p>If your matplotlib <strong>version is above 1.4, and you...
2
2016-08-18T05:46:27Z
[ "python", "numpy", "matplotlib", "ipython", "jupyter-notebook" ]
Jupyter Notebook - Matplotlib keep running
39,010,594
<p>I just started to use <code>Jupiter Notebook</code> to learn <code>Python</code>. while I am trying out <code>matplotlib</code> with this basic code:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt plt.plot([1,2,3,4]) plt.ylabel('some numbers') plt.show() </code></pre> <p>The kernel just keep ru...
0
2016-08-18T05:33:54Z
39,010,809
<p>It sometimes takes time until the kernel starts.</p> <p>Check that the code is color-highlighted. If it is, it means that the kernel is running. Evaluate the cell again. You will notice a <code>*</code> beside that cell, meaning it's running. </p> <p>And one more thing: Sometimes the plot is displayed but its wind...
0
2016-08-18T05:54:19Z
[ "python", "numpy", "matplotlib", "ipython", "jupyter-notebook" ]
Django 1.8 No module named front
39,010,599
<p>Here is my project folder structure.</p> <pre><code>&lt;pre&gt; front ├── __init__.py ├── __init__.pyc ├── manage.py ├── middleware.py ├── settings.py ├── news │   ├── __init__.py │   ├── __init__.pyc │   ├── admin.py │   ├── admin_views.py...
0
2016-08-18T05:34:22Z
39,011,378
<p>Either way this is wrong, whenever you're importing your own settings you should be importing from <code>django.conf</code></p> <pre><code>from django.conf import settings </code></pre> <p>This isn't a module, its an object that does magic to import any settings you have set in your <code>DJANGO_SETTINGS_MODULE</c...
4
2016-08-18T06:34:07Z
[ "python", "django" ]
Pandas: Adding two dataframes on the common columns
39,010,614
<p>I have 2 tables which have the same columns and I want to add the numbers where the key matches, and if it doesn't then just add it as is in the output df.. I tried combine first, merge, concat and join.. They all create 2 seperate columnd for t1 and t2, but its the same key, so should just be together I know this w...
2
2016-08-18T05:35:29Z
39,010,650
<p>First <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a> in both <code>DataFrames</code> by first columns and then use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.add.html" rel="nofollow"><code>...
3
2016-08-18T05:38:55Z
[ "python", "pandas", "dataframe", "add", "multiple-columns" ]
How to implement single logger in python for two scripts one defining the workflow and one containing all functions?
39,010,659
<p>I have two python scripts one as workflow.py and other is task.py. The workflow.py defines the workflow of the task.py and thus it has only main inside it in which it instantiate the constructor of task.py. The structure of worflow.py is as follows:</p> <pre><code>workflow.py from optparse import OptionParser from ...
1
2016-08-18T05:40:08Z
39,010,861
<p>I think I would define logger inside <code>workflow.py</code> and pass it as a parameter into the constructor of <code>task_C</code>. That would seem to be the easiest solution.</p>
0
2016-08-18T05:57:37Z
[ "python", "python-2.7", "logging" ]
How to implement single logger in python for two scripts one defining the workflow and one containing all functions?
39,010,659
<p>I have two python scripts one as workflow.py and other is task.py. The workflow.py defines the workflow of the task.py and thus it has only main inside it in which it instantiate the constructor of task.py. The structure of worflow.py is as follows:</p> <pre><code>workflow.py from optparse import OptionParser from ...
1
2016-08-18T05:40:08Z
39,015,779
<blockquote> <p>actually that can be done but the point is in that case log location has to be defined in workflow.py and i don't want to define location there as it is already defined in task.py. In workflow i don't want to define the same location for logger which is already set in task.py</p> </blockquote> ...
1
2016-08-18T10:25:30Z
[ "python", "python-2.7", "logging" ]
Can't figure out errors during c++ python binding using Boost
39,010,721
<p>I am creating a Qt based app that requires python code to be run from it. For this, I am using Boost.Python. The error I have is: </p> <pre><code>CMakeFiles/App.dir/main.cpp.o: In function `_GLOBAL__sub_I_main.cpp': main.cpp:(.text.startup+0x3): undefined reference to `_Py_NoneStruct' collect2: error: ld returned 1...
0
2016-08-18T05:46:09Z
39,011,538
<p>It seems that you are not linking with the required Python libraries. Try adding <code>${PYTHON_LIBRARIES$} to</code>target_link_libraries`:</p> <pre><code>target_link_libraries(${CMAKE_PROJECT_NAME} ${PYTHON_LIBRARIES} ) </code></pre>
-1
2016-08-18T06:44:41Z
[ "python", "c++", "qt", "boost" ]
python, how to handle event between multiple windows?
39,010,886
<p>I'm using the following sample code to generate two windows:</p> <pre><code>import Tkinter as tk class Demo1: def __init__(self, master): self.master = master self.frame = tk.Frame(self.master) self.button1 = tk.Button(self.frame, text = 'New Window', width = 25, command = self.new_wind...
-1
2016-08-18T06:00:19Z
39,012,049
<p>You may use <code>wait_window</code> method to wait for the second window to be destroyed before proceeding to the next statement in the first window.</p> <p>I have modified your code to make it work. Hope it helps -</p> <pre><code>import Tkinter as tk class Demo1(tk.Frame): def __init__(self, master): ...
2
2016-08-18T07:15:37Z
[ "python", "user-interface", "tkinter" ]
pip cant install radiopy
39,010,960
<p>I've tried <code>pip install radiopy</code></p> <p><em>Traceback:</em></p> <pre><code>C:\Users\олег\Downloads&gt;pip install radiopy Collecting radiopy Using cached radio py-0.6.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "&lt;string&gt;", line 1, in &...
0
2016-08-18T06:05:32Z
39,011,153
<p>The module seems to support Python 2 only. The <code>setup.py</code> contains a very dubious hack to evaluate the <code>__version__</code> variable:</p> <pre><code>def get_version(filename): """Extract __version__ from file by parsing it.""" with open(filename) as fp: for line in fp: if ...
0
2016-08-18T06:19:44Z
[ "python", "install", "pip" ]
Django avatar class not work
39,011,004
<p>In django-avatar I want to add a custom CSS class using the template tag, but it's not working.</p> <p>My template:</p> <pre><code>{% load avatar_tags %} &lt;li&gt; &lt;span class="userhome"&gt; {% avatar user 50 class="mmb-img" id="user_avatar" %} Welcome : {{ user.username }} &lt;/span&gt; ...
0
2016-08-18T06:09:17Z
39,011,315
<p>This is probably because the app <a href="http://django-avatar.readthedocs.io/en/latest/#global-settings" rel="nofollow">caches the output of those template tags</a>:</p> <blockquote> <p><code>AVATAR_CACHE_ENABLED</code></p> <p>Set to <code>False</code> if you completely disable avatar caching. Defaults to <...
2
2016-08-18T06:29:55Z
[ "python", "css", "django", "avatar" ]
Django avatar class not work
39,011,004
<p>In django-avatar I want to add a custom CSS class using the template tag, but it's not working.</p> <p>My template:</p> <pre><code>{% load avatar_tags %} &lt;li&gt; &lt;span class="userhome"&gt; {% avatar user 50 class="mmb-img" id="user_avatar" %} Welcome : {{ user.username }} &lt;/span&gt; ...
0
2016-08-18T06:09:17Z
39,117,006
<p>Same issue here, unable to set neither class="" nor id="".</p> <p>No idea what's going on, so temporarily I can only set it via JavaScript/JQuery.</p> <p>JQuery:</p> <pre><code>$(function() {$("span.userhome img").addClass("img-responsive")}); </code></pre>
0
2016-08-24T07:30:09Z
[ "python", "css", "django", "avatar" ]
How to change dictionary that one key has multiple values to dataframe?
39,011,022
<p>I have a dictionary <code>self._alpha_series</code>.</p> <p>I use <code>pd.DataFrame.from_dict(self._alpha_series.items())</code>,</p> <p>It will become below:</p> <p><a href="http://i.stack.imgur.com/StlhT.png" rel="nofollow"><img src="http://i.stack.imgur.com/StlhT.png" alt="enter image description here"></a></...
0
2016-08-18T06:10:59Z
39,011,207
<p>IIUC you can use:</p> <pre><code>print (df) 0 1 0 1101.TW (nan, nan) 1 2227.TW (nan, 100.5) 2 2887.TW (nan, 24.7) df[[1,2]] = pd.DataFrame.from_records(df.ix[:,1].values.tolist()) print (df) 0 1 2 0 1101.TW NaN NaN 1 2227.TW NaN 100.5 2 2887.TW NaN 24.7 </code...
1
2016-08-18T06:23:37Z
[ "python", "pandas", "dictionary" ]
Why does the local_binary_pattern function in scikit-image provide same value for different patterns
39,011,167
<p>I am using the <code>local_binary_pattern</code> function in the scikit-image package. I would like to compute the rotation invariant uniform LBP of 8 neighbors within radius 1. Here is my Python code:</p> <pre class="lang-python prettyprint-override"><code>import numpy as np from skimage.feature import local_binar...
2
2016-08-18T06:20:23Z
39,017,137
<p>The rotation-invariant LBP does not use the pixel values of neighbors directly, but rather values interpolated on a circle (for the rotation invariance). See <a href="https://github.com/scikit-image/scikit-image/blob/master/skimage/feature/_texture.pyx#L156" rel="nofollow">https://github.com/scikit-image/scikit-imag...
1
2016-08-18T11:32:51Z
[ "python", "feature-extraction", "scikit-image" ]
How do I 'squash' the values in a DataFrame that I know only has one item per row into a Series?
39,011,192
<p>I have a DataFrame which I have confirmed has no more than one value in each row (the rest are np.nan). How can I turn this into a one-dimensional array or Series?</p> <p>Say this is my starting array:</p> <pre><code>In [7]: import pandas as pd In [8]: data = [ [np.nan, 9.0, np.nan], [np.nan, np.nan, 3.0...
1
2016-08-18T06:22:19Z
39,011,358
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.first_valid_index.html" rel="nofollow"><code>first_valid_index</code></a>, but need condition if all values are <code>NaN</code>:</p> <pre><code>def f(x): if x.first_valid_index() is None: return None else: ...
2
2016-08-18T06:32:46Z
[ "python", "pandas", "dataframe", null, "series" ]
How do I 'squash' the values in a DataFrame that I know only has one item per row into a Series?
39,011,192
<p>I have a DataFrame which I have confirmed has no more than one value in each row (the rest are np.nan). How can I turn this into a one-dimensional array or Series?</p> <p>Say this is my starting array:</p> <pre><code>In [7]: import pandas as pd In [8]: data = [ [np.nan, 9.0, np.nan], [np.nan, np.nan, 3.0...
1
2016-08-18T06:22:19Z
39,011,722
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.max.html" rel="nofollow"><code>pd.DataFrame.max</code></a> or <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sum.html" rel="nofollow"><code>pd.DataFrame.sum</code></a> with the <code>skipna</c...
2
2016-08-18T06:56:10Z
[ "python", "pandas", "dataframe", null, "series" ]
How do I 'squash' the values in a DataFrame that I know only has one item per row into a Series?
39,011,192
<p>I have a DataFrame which I have confirmed has no more than one value in each row (the rest are np.nan). How can I turn this into a one-dimensional array or Series?</p> <p>Say this is my starting array:</p> <pre><code>In [7]: import pandas as pd In [8]: data = [ [np.nan, 9.0, np.nan], [np.nan, np.nan, 3.0...
1
2016-08-18T06:22:19Z
39,014,167
<p>I would make use of the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.update.html" rel="nofollow">update()</a> function. For a variable number of columns:</p> <pre><code>dataDF = pd.DataFrame(data) squash = pd.Series(index=dataDF.index) for col in dataDF.columns.values: squash.up...
1
2016-08-18T09:09:54Z
[ "python", "pandas", "dataframe", null, "series" ]
python getpass module is not taking German characters as input
39,011,208
<p>I am trying to enter password having German characters using python <strong>getpass</strong> module on Windows 7. Python version is 2.7.8</p> <ul> <li>First I set the system locale as German(Germany) and reboot.</li> <li>The command prompt codepage is now set to cp850 which supports German characters.</li> <li><p>T...
1
2016-08-18T06:23:40Z
39,037,079
<p>I was entering the German character (ö) by typing following : alt + 0246. But typing the same character directly from the German keyboard (semi-colon ';' on American keyboard) is working fine.</p> <p>However, still I am confused as to what is the difference between above two. Maybe alt code characters are in a dif...
0
2016-08-19T10:45:15Z
[ "python", "getpasswd" ]
Python randomly stops writing to csv, but for loop is still running
39,011,235
<p>I am trying to fetch data from Last.fm, and write these data to a CSV file. I have a.csv, and based on each line of this a.csv, I fetch additional data from Last.fm, then save them to b.csv. So as a result, a.csv and b.csv are of the same size.</p> <p>a.csv is a large text file with about 8 million data lines, so I...
0
2016-08-18T06:25:11Z
39,011,981
<p>Try adding a <code>f.flush()</code> call somewhere, for instance, in your 1000 lines checkpoint. Maybe the files are just being buffered, and not getting written to disk. For example, see <a href="http://stackoverflow.com/questions/3167494/how-often-does-python-flush-to-a-file">How often does python flush to a file?...
0
2016-08-18T07:11:51Z
[ "python", "file", "csv", "multiprocessing", "python-multiprocessing" ]
python function error : Type Error
39,011,363
<p>hi im fairly new to python and cant spot my error in this program, my error looks like this</p> <blockquote> <p>TypeError: hitormiss() missing 1 required positional argument: 'totalaim'</p> </blockquote> <pre><code>#!usr/bin/python3 import random def takeshot(prompt='do you want to take shot?\n'): answer = in...
-1
2016-08-18T06:32:49Z
39,011,405
<p>You should remove the <code>cal()</code> and <code>hitormiss()</code> function call and replace it with:</p> <pre><code>hitormiss(cal()) </code></pre> <p>This is because a parameter has to be passed to <code>hitormiss()</code> and <code>cal()</code> returns the <code>totalaim</code> value.</p>
0
2016-08-18T06:36:05Z
[ "python", "python-3.x" ]
python function error : Type Error
39,011,363
<p>hi im fairly new to python and cant spot my error in this program, my error looks like this</p> <blockquote> <p>TypeError: hitormiss() missing 1 required positional argument: 'totalaim'</p> </blockquote> <pre><code>#!usr/bin/python3 import random def takeshot(prompt='do you want to take shot?\n'): answer = in...
-1
2016-08-18T06:32:49Z
39,011,472
<p>Also, <code>cal.totalaim</code> won't resolve in the way you're planning</p> <pre><code>def hitormiss(totalaim, hit=50): if totalaim &gt;= hit: print("You have hit your target!") elif totalaim &lt; hit: print("You have missed your target!") else: print("Revise Code.") </code></pr...
0
2016-08-18T06:40:49Z
[ "python", "python-3.x" ]
How to use some field instead of primary keys in Django 1.6 model fixtures?
39,011,469
<p>I need to dump and load fixtures of model objects without usage of primary keys. The model is flat. I know about natural keys in Django, spent a lot of time reading the documentation, but all documentation has solutions only for usage natural keys instead of relations (fk / m2m). This is totally not what I need.</p>...
1
2016-08-18T06:40:42Z
39,012,174
<p>Django 1.6 does not provide a way to dump data with natural primary keys, but Django 1.7 does. </p> <ul> <li>Django 1.6 docs: <a href="https://docs.djangoproject.com/en/1.7/ref/django-admin/#dumpdata-app-label-app-label-app-label-model" rel="nofollow">https://docs.djangoproject.com/en/1.7/ref/django-admin/#dumpdata...
3
2016-08-18T07:22:39Z
[ "python", "django", "django-fixtures" ]
How to use some field instead of primary keys in Django 1.6 model fixtures?
39,011,469
<p>I need to dump and load fixtures of model objects without usage of primary keys. The model is flat. I know about natural keys in Django, spent a lot of time reading the documentation, but all documentation has solutions only for usage natural keys instead of relations (fk / m2m). This is totally not what I need.</p>...
1
2016-08-18T06:40:42Z
39,020,378
<p>Based on the <a href="/a/39012174/1911913">answer of régis-b</a> I wrote some code that allows use natural keys in Django 1.6 "loaddata" management command <strong>without upgrade to 1.7</strong>. I chose this way because a full upgrading of my project may be painful. This solution can be considered as a temporary....
0
2016-08-18T14:07:52Z
[ "python", "django", "django-fixtures" ]
Pandas expand rows from list data available in column
39,011,511
<p>I have a data frame like this in pandas:</p> <pre><code> column1 column2 [a,b,c] 1 [d,e,f] 2 [g,h,i] 3 </code></pre> <h1><strong>Expected output:</strong></h1> <pre><code>column1 column2 a 1 b 1 c 1 d 2 e ...
1
2016-08-18T06:42:41Z
39,011,596
<p>You can create <code>DataFrame</code> by its constructor and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.stack.html" rel="nofollow"><code>stack</code></a>:</p> <pre><code> df2 = pd.DataFrame(df.column1.tolist(), index=df.column2) .stack() .reset_index(level=1, dro...
1
2016-08-18T06:48:34Z
[ "python", "list", "pandas", "dataframe", "expand" ]
Hide button if access rights in Accounting and Finance = Invoicing & Payments
39,011,714
<p>I am trying to hide the button 'Refund Invoice' found in Accounting->Customer Invoices &amp; Customer Refunds</p> <p><a href="http://i.stack.imgur.com/gEgym.png" rel="nofollow"><img src="http://i.stack.imgur.com/gEgym.png" alt="enter image description here"></a></p> <p>If the user's access rights in Accounting and...
0
2016-08-18T06:55:43Z
39,012,267
<p>You have to extend/override the invoice formular view. You can set groups directly on fields or buttons, which will show these things only to member of these groups. You will find an example <a href="https://github.com/OCA/account-invoicing/blob/9.0/stock_picking_invoicing/stock_view.xml" rel="nofollow">here</a> whe...
1
2016-08-18T07:28:14Z
[ "python", "openerp", "openerp-7" ]
Softlayer - Running Jumpgate
39,011,757
<p>Fist question, somebody knows if the Jumpgate project still active? I see that the last activity was in 2014.</p> <p>Second, I tried to install Jumpgate using the steps in this article [<a href="http://bodenr.blogspot.jp/2014/03/managing-openstack-softlayer-resources.html]" rel="nofollow">http://bodenr.blogspot.jp/...
0
2016-08-18T06:59:11Z
39,019,622
<p>I've never installed jumpgate before, but I was able to install it.</p> <p>At firts I got a similar error like you got, but I fix it installing all the needed pakages using pip.</p> <pre><code>sudo pip install falcon sudo pip install requests sudo pip install six sudo pip install oslo.config sudo pip install softl...
0
2016-08-18T13:33:27Z
[ "python", "openstack", "softlayer" ]
Softlayer - Running Jumpgate
39,011,757
<p>Fist question, somebody knows if the Jumpgate project still active? I see that the last activity was in 2014.</p> <p>Second, I tried to install Jumpgate using the steps in this article [<a href="http://bodenr.blogspot.jp/2014/03/managing-openstack-softlayer-resources.html]" rel="nofollow">http://bodenr.blogspot.jp/...
0
2016-08-18T06:59:11Z
39,111,420
<p>Run all in a virtualenv and save yourself some headaches.</p>
0
2016-08-23T22:06:44Z
[ "python", "openstack", "softlayer" ]
pytest dependent parameters in parametrize
39,011,777
<p>I would like one parametrize to depend on an earlier one:</p> <pre><code>@pytest.mark.parametrize("locale_name", LOCALES) @pytest.mark.parametrize("money_string", ["500{currency}", "500 {currency}"]) @pytest.mark.parametrize("currency", LOCALES['locale_name']['currencies']) def test_do_stuff(locale_name, money_stri...
0
2016-08-18T06:59:56Z
39,061,694
<p>I dont think py.test supports tests with in tests, If I understand correctly based on your example code, all you want is to test the currencies, Assuming <code>LOCALES</code> is a nested dict , I would do something of this sort to address the test</p> <pre><code>import pytest LOCALES = {"US": {"currencies": "dolla...
0
2016-08-21T07:06:30Z
[ "python", "dependencies", "py.test" ]
I cannot use Quanterion values that i use with PyOpenGL.glRotatef in Unity
39,011,834
<p>i have values Quaternion(x,y,z,w)=(p0,p1,p2,p3) in pyOpenGl</p> <pre><code> norm=math.sqrt(program_dict['q0']*program_dict['q0'] + program_dict['q1']*program_dict['q1'] + program_dict['q2']*program_dict['q2'] + program_dict['q3']*program_dict['q3']) glPushMatrix() if (norm == 0): pass else: ...
1
2016-08-18T07:02:37Z
39,128,105
<p>The confusion here is between an axis-angle representation and a quaternion. The glRotatef you are using uses the former, while the <code>rotation</code> and <code>localRotation</code> of Unity's <code>Transform</code> are the latter. </p> <p>You can however convert between the two. <a href="https://docs.unity3d.co...
0
2016-08-24T16:03:34Z
[ "c#", "python", "unity3d", "unity5", "pyopengl" ]
display content of graphs in matplotlib inmmediately
39,011,935
<p>I'm using Canopy in a Win7 machine, with <code>%pylab</code> enabled and interactive(Qt4) as backend. IMHO, I'm getting what I consider a weird behavior of <code>matplotlib</code>.</p> <p>If the code is executed line by line, the frames for the graphs appear as I expect, but not the content of the graphs themselves...
1
2016-08-18T07:08:56Z
39,013,502
<p>If I understand, the problem is that <code>plt.show</code> will block and the second figure will not be plotted until the first is closed. With different backends the behaviour may be different but you shouldn't call show more than once (see <a href="http://stackoverflow.com/questions/5524858/matplotlib-show-doesnt-...
1
2016-08-18T08:37:03Z
[ "python", "matplotlib", "enthought" ]
display content of graphs in matplotlib inmmediately
39,011,935
<p>I'm using Canopy in a Win7 machine, with <code>%pylab</code> enabled and interactive(Qt4) as backend. IMHO, I'm getting what I consider a weird behavior of <code>matplotlib</code>.</p> <p>If the code is executed line by line, the frames for the graphs appear as I expect, but not the content of the graphs themselves...
1
2016-08-18T07:08:56Z
39,024,992
<p>As Ed Smith said, only the first call to <code>plt.show()</code> works. If you want to force a redraw of the figure, you can use <code>figure.canvas.draw()</code></p> <pre><code>import matplotlib.pyplot as plt fig = plt.figure() plt.plot([0, 1], [2, 3]) plt.show() #do more stuff, get user input plt.plot([5,6], [...
1
2016-08-18T18:19:36Z
[ "python", "matplotlib", "enthought" ]
reportlab, find position/coordinates for last paragraph in page
39,011,936
<p>I need to insert some text after last paragraph on last page, am not sure if it is possible to find coordinates for last paragraph.</p> <p>As I know reportlab is most robust library for dealing with pdf, however if that is possible via another library will be fine.</p> <p>Also to ask is it possible to replicate (f...
0
2016-08-18T07:08:57Z
39,067,810
<p>Solution is in Great pdfminer python library from Yusuke Shinyama. 5 stars for his project.</p> <p>pdfminer is at present available only for python2.7</p> <p>Is installing from source after unpacking archive with</p> <pre><code>sudo python setup.py install </code></pre> <p>After instalation commandline tool pdf2...
0
2016-08-21T18:58:39Z
[ "python", "reportlab", "pdfrw" ]
Pulling Income Statement Data using Python
39,011,939
<p>I am trying to pull data from Yahoo Finance using the below code but it is throwing me error. </p> <p>I tried to debug from my end and it looks the title is coming as blank when using the find command</p> <p>title = soup.find("strong", text=pattern) #returning blank</p> <p>Code:</p> <pre><code># -*- coding: utf-...
0
2016-08-18T07:09:15Z
39,070,877
<p>As far as I found out (I'm just staring, complete noob), Yahoo finance uses Java Script. And as such, Beautiful Soup will not work. At least this is what I was told. Selenium should be correct tool for sites like this. </p> <p>Here bellow is the link, where I asked similar question and in that link is code that wor...
0
2016-08-22T03:10:10Z
[ "python", "yahoo-finance" ]
Why can't I assign array to pandas DataFrame column?
39,011,954
<p>I am using <code>KNeighborsClassifier</code> to classify some values like this:</p> <pre><code>arr = classifier_3NN.predict(testData_df) len(arr) 10960 </code></pre> <p>I want to assign this array to a column in a DataFrame, I have checked &amp; it is the same size:</p> <pre><code>len(df[df['events']=='NaN']['eve...
1
2016-08-18T07:09:58Z
39,011,994
<p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isnull.html" rel="nofollow"><code>isnull</code></a> for checking <code>NaN</code> values with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.ix.html" rel="nofollow"><code>ix</code></a>:</p> ...
1
2016-08-18T07:12:36Z
[ "python", "arrays", "pandas", "numpy" ]
Issue regarding the installation of android backend server
39,012,030
<p>I have an issue regarding the android backend storage. Can anyone help in initial steps from determining which server to buy, how to use it and which integrated development environment (ide) should be used for python?? Any leads will be helpful. Thanks </p>
0
2016-08-18T07:14:27Z
39,012,131
<p>check out once about Firebase link: <a href="https://firebase.google.com/docs/" rel="nofollow">https://firebase.google.com/docs/</a> it may useful to you.it offers storage and realtime database and more.</p>
0
2016-08-18T07:19:45Z
[ "android", "python", "sql-server", "backend" ]
Spark ML Pipeline Causes java.lang.Exception: failed to compile ... Code ... grows beyond 64 KB
39,012,073
<p>Using Spark 2.0, I am trying to run a simple VectorAssembler in a pyspark ML pipeline, like so: </p> <pre><code>feature_assembler = VectorAssembler(inputCols=['category_count', 'name_count'], \ outputCol="features") pipeline = Pipeline(stages=[feature_assembler]) model = pipeli...
2
2016-08-18T07:16:54Z
39,976,133
<p>It seems like there may be a limit, namely 64KB, to Spark's lazy evaluation. In other words, it's being a little to lazy in this case which is causing it to hit that limit.</p> <p>I was able to work around this same exception, which I was triggering via a <code>join</code> rather than with a VectorAssembler, by ca...
0
2016-10-11T11:22:19Z
[ "python", "apache-spark", "pyspark", "apache-spark-sql", "pyspark-sql" ]
UnicodeEncodeError in Python CSV manipulation script
39,012,122
<p>I have a script that was working earlier but now stops due to UnicodeEncodeError.</p> <p>I am using Python 3.4.3.</p> <p>The full error message is the following:</p> <pre><code>Traceback (most recent call last): File "R:/A/APIDevelopment/ScivalPubsExternal/Combine/ScivalPubsExt.py", line 58, in &lt;module&gt; ...
0
2016-08-18T07:19:14Z
39,014,157
<p>The error is caused by an attempt to write a string containing a U+008A character using the default cp1252 encoding of your system. It is trivial to fix, just declare a latin1 encoding (or iso-8859-1) for your output file (because it just outputs the original byte without conversion):</p> <pre><code>with open(joine...
0
2016-08-18T09:09:20Z
[ "python", "csv", "unicode", "encode" ]
UnicodeEncodeError in Python CSV manipulation script
39,012,122
<p>I have a script that was working earlier but now stops due to UnicodeEncodeError.</p> <p>I am using Python 3.4.3.</p> <p>The full error message is the following:</p> <pre><code>Traceback (most recent call last): File "R:/A/APIDevelopment/ScivalPubsExternal/Combine/ScivalPubsExt.py", line 58, in &lt;module&gt; ...
0
2016-08-18T07:19:14Z
39,057,325
<p>Make sure to use the <strong>correct</strong> encoding of your source and destination files. You open files in three locations:</p> <pre><code>codes = csv.reader(open('Codes.csv')) : : : with open(joinedFileOut,'wt') as csvWriteFD: outputFD=csv.writer(csvWriteFD,delimiter=',') : : : with open(s...
0
2016-08-20T18:15:24Z
[ "python", "csv", "unicode", "encode" ]
How to redirect the output to file and print required words line by line in python
39,012,177
<p>Am beginner in python I have just extracted permissions from an file using python through this code</p> <pre><code>def remove_prefix(text, prefix): if text.startswith(prefix): return text[len(prefix):] return text file = open('op3.txt', 'w') from xml.dom.minidom import parseString data = '' with o...
-1
2016-08-18T07:22:50Z
39,012,384
<p>add a new line character when writing the strings</p> <p><code>file.write(perm1 + '\n')</code></p>
0
2016-08-18T07:35:02Z
[ "android", "python" ]
How do I combine nodes with the same node type from different matched patterns into a single column or collection?
39,012,181
<p>I'm creating a social network for learning Neo4J. We have users and their followers, posts. We want merge two statements.</p> <p><strong>Goal: list of posts including yours and those you follow in chronological order.</strong></p> <ol> <li>My posts</li> <li>My following users posts</li> </ol> <p>We tried <strong>...
-1
2016-08-18T07:23:03Z
39,012,344
<p>You can merge your two statements using <code>WITH</code>:</p> <pre><code>Match (cur_user: User {username: 'ahmetsa'})-[:FOLLOW]-&gt;(others: User)&lt;- [:POSTED_BY]-(p: Post) With cur_user, p Match ( l: Post) - [:POSTED_BY]-&gt;(cur_user) Return collect(p) + collect(l) as posts </code></pre> <p><code>WITH</code> ...
1
2016-08-18T07:32:13Z
[ "python", "neo4j" ]
change bin size of histogram data
39,012,192
<p>I have data from an SQL statement like</p> <pre><code>'select action_count, count(*) "num_users" from customers group by action_count;' </code></pre> <p>and load this into a pandas data frame. I can run a simple plot command on the data, or <em>barplot</em> it to make it look like a histogram. But how can I easily...
1
2016-08-18T07:23:36Z
39,013,133
<p>You can specify the location of the edges of bins using a list in <code>pandas</code> <code>hist</code>. For example, using a custom sequence with bin from <code>-2.0</code> to <code>-0.5</code> and then <code>-0.5</code> to <code>0.0</code> followed by a few increments of <code>0.1</code>,</p> <pre><code>import nu...
0
2016-08-18T08:17:38Z
[ "python", "pandas", "numpy", "matplotlib", "seaborn" ]
How to Access Many to many field in class based views in Django?
39,012,367
<p>I have two models, Author &amp; Book in models.py</p> <pre><code>class Author(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=40) email = models.EmailField() age = models.IntegerField() def __str__(self): return '%s %s' %(self.first_name, self...
3
2016-08-18T07:33:50Z
39,012,587
<p>You have defined a many-to-many relationship between <code>Book</code> and <code>Author</code> which means that a book can have any number of authors. In order to display them you need to loop through the set of authors:</p> <pre><code>Authors: &lt;ul&gt; {% for author in book_detail.author.all %} &lt;li&gt;{{ ...
6
2016-08-18T07:47:35Z
[ "python", "django", "many-to-many", "django-class-based-views" ]
Pandas groupby plot gives first plot twice
39,012,371
<p>I have a dataframe with several categories and I want to use <code>groupby</code> to plot each category individually. However, the first category (or the first plot) is always plotted twice.</p> <p>For example:</p> <pre><code> import pandas as pd import numpy as np import matplotlib.pyplot as plt ...
2
2016-08-18T07:33:58Z
39,012,557
<p>This is expected behaviour, see the warning in the <a href="http://pandas.pydata.org/pandas-docs/stable/groupby.html#flexible-apply" rel="nofollow">docs</a>:</p> <blockquote> <p><strong>Warning:</strong> In the current implementation apply calls func twice on the first group to decide whether it can take a fast o...
1
2016-08-18T07:45:33Z
[ "python", "pandas", "plot" ]
How to measure power consumption of my application on Android
39,012,385
<p>I have developed an android application and I would like to know the power consumption of my app on an android device. I came across various threads on SO but none of them helped me.</p> <p>Is there any application in android which measures the power consumption of my app or any other viable method?</p> <p>Let me ...
0
2016-08-18T07:35:04Z
39,494,352
<p>I don't know what you mean by can't read estimated value in the setting.</p> <p>Look at my answer in <a href="http://stackoverflow.com/questions/12581333/android-app-power-consumption">Android App power consumption</a> </p> <p>" First, the powertutor from Google Play is out of date. I've checked the source code of...
0
2016-09-14T15:30:04Z
[ "android", "python", "python-2.7", "battery", "measurement" ]
passing many arguments to one placeholder of django cursor (placeholer in IN)
39,012,390
<p>I mean something like this:</p> <pre><code>from django.db import connection cursor=connection.cursor() cursor.execute('SELECT * FROM mytable where id IN (%s)', [params]) </code></pre> <p>Parameters can not be just iterable - it doesn't work. Cannot be also in CSV format due escaping value by db handler.</p> <p>Ho...
0
2016-08-18T07:35:14Z
39,012,670
<p><strong>Updated Answer</strong> Sorry about the older answer. This should work as you want, but might not be the best solution. I tried it with both, params as a list of strings and a list of integers.</p> <pre><code>from django.db import connection params = [1, 2, 3, '4', '5'] placeholders = ('%s,'*len(params)).r...
1
2016-08-18T07:53:05Z
[ "python", "sql", "django", "placeholder" ]
passing many arguments to one placeholder of django cursor (placeholer in IN)
39,012,390
<p>I mean something like this:</p> <pre><code>from django.db import connection cursor=connection.cursor() cursor.execute('SELECT * FROM mytable where id IN (%s)', [params]) </code></pre> <p>Parameters can not be just iterable - it doesn't work. Cannot be also in CSV format due escaping value by db handler.</p> <p>Ho...
0
2016-08-18T07:35:14Z
39,013,919
<p>Solution is rather simple:</p> <p><code>c.execute('select * from mytable where id in (%s)' % (','.join(params),))</code></p> <p>See similar topic: <a href="http://stackoverflow.com/questions/589284/imploding-a-list-for-use-in-a-python-mysqldb-in-clause">imploding a list for use in a python MySQLDB IN clause</a></p...
0
2016-08-18T08:57:41Z
[ "python", "sql", "django", "placeholder" ]
passing many arguments to one placeholder of django cursor (placeholer in IN)
39,012,390
<p>I mean something like this:</p> <pre><code>from django.db import connection cursor=connection.cursor() cursor.execute('SELECT * FROM mytable where id IN (%s)', [params]) </code></pre> <p>Parameters can not be just iterable - it doesn't work. Cannot be also in CSV format due escaping value by db handler.</p> <p>Ho...
0
2016-08-18T07:35:14Z
39,035,248
<p>You cannot use <code>IN</code> for this since indeed, in expects a sequence of ints, but the ORM translates a list to an <code>ARRAY</code>, and if you use <code>join</code> you'll end up with a string.</p> <p>The solution is to use the equivalent <code>ANY</code>. The formatting is slightly different, but this sho...
0
2016-08-19T09:11:31Z
[ "python", "sql", "django", "placeholder" ]
How get equation after fitting in scikit-learn?
39,012,611
<p>I want to use <a href="http://scikit-learn.org/stable/" rel="nofollow">scikit-learn</a> for calculating the equation of some data. I used this code to fit a curve to my data:</p> <pre><code>svr_lin = SVR(kernel='linear', C=1e3) y_lin = svr_lin.fit(X, y).predict(Xp) </code></pre> <p>But I don't know what I should ...
1
2016-08-18T07:49:14Z
39,022,912
<p>Here is an example:</p> <pre><code>from sklearn.datasets import load_boston from sklearn.svm import SVR boston = load_boston() X = boston.data y = boston.target svr = SVR(kernel='linear') svr.fit(X,y); print('weights: ') print(svr.coef_) print('Intercept: ') print(svr.intercept_) </code></pre> <p>the output is:</...
2
2016-08-18T16:08:02Z
[ "python", "scikit-learn" ]
Python: List with [< >, <>...]
39,012,656
<p>I'm using PySVN to get diff between 2 links, and the function I'm using returns a list with '&lt;>':</p> <pre><code>[&lt;PysvnDiffSummary u'sdk_include/EthernetScannerSDK.h'&gt;, &lt;PysvnDiffSummary u'sdk_include/EthernetScannerSDKDefine.h'&gt;, &lt;PysvnDiffSummary u'sdk_include/CMakeLists.txt'&gt;] </code></pre>...
1
2016-08-18T07:52:26Z
39,012,795
<p>It's a representation of PySvnDiffSummary object. Try using dir(Object) to get it's attributes and from there. It's probably going to be something like object.url</p> <p>so when you find out what the attribute is (from comments elsewhere, it's <code>__name</code>), you'll want something like:</p> <pre><code>urls =...
1
2016-08-18T08:00:25Z
[ "python", "pysvn" ]
Regular expression matching lines that are not commented out
39,012,690
<p>Given the following code</p> <pre><code>print("aaa") #print("bbb") # print("ccc") def doSomething(): print("doSomething") </code></pre> <p>How can I use regular expression in Atom text editor to find all the <code>print</code> functions that are not commented out? I mean I only want to match the <code>print</...
3
2016-08-18T07:54:16Z
39,012,940
<p>I you want to match only the print (and not all arguments), you can use : </p> <pre><code>^\s*(print) </code></pre> <p>See this live sample : <a href="http://refiddle.com/refiddles/57b56c8075622d22e8080000" rel="nofollow">http://refiddle.com/refiddles/57b56c8075622d22e8080000</a></p>
0
2016-08-18T08:07:06Z
[ "python", "regex", "atom" ]
Regular expression matching lines that are not commented out
39,012,690
<p>Given the following code</p> <pre><code>print("aaa") #print("bbb") # print("ccc") def doSomething(): print("doSomething") </code></pre> <p>How can I use regular expression in Atom text editor to find all the <code>print</code> functions that are not commented out? I mean I only want to match the <code>print</...
3
2016-08-18T07:54:16Z
39,013,954
<p>Since you confirm my first suggestion (<code>^(?![ \t]*#)[ \t]*print</code>) worked for you (I deleted that first comment), I believe you just want to find the <code>print</code> on single lines. </p> <p>The <code>\s</code> matches any whitespace, incl. newline symbols. If you need to just match tabs or spaces, use...
3
2016-08-18T08:59:44Z
[ "python", "regex", "atom" ]
Changing words in a string using dictionary. python
39,012,700
<p>I have the following message:</p> <pre><code>msg = "Cowlishaw Street &amp;amp; Athllon Drive, Greenway now free of obstruction." </code></pre> <p>I want to change things such as "Drive" to "Dr" or "Street" to "St"</p> <pre><code>expected_msg = "Cowlishaw St and Athllon Dr Greenway now free of obstruction" </code>...
0
2016-08-18T07:54:40Z
39,013,014
<p>Isn't it simply:</p> <pre><code>translations = {'Drive': 'Dr'} for index, token in enumerate(tokens): if token in conversion: tokens[index] = conversion[token] return ' '.join(tokens) </code></pre> <p>However, this wouldn't work on sentences like <code>"Obstruction on Cowlishaw Street."</code> since ...
0
2016-08-18T08:10:58Z
[ "python", "string", "dictionary" ]
Need to extract all the font sizes and the text using beautifulsoup
39,012,739
<p>I have the following html file stored on my local system:</p> <pre><code>&lt;span style="position:absolute; border: gray 1px solid; left:0px; top:50px; width:612px; height:792px;"&gt;&lt;/span&gt; &lt;div style="position:absolute; top:50px;"&gt;&lt;a name="1"&gt;Page 1&lt;/a&gt;&lt;/div&gt; &lt;div style="position:...
0
2016-08-18T07:57:18Z
39,013,822
<p>You have to make some research for your self, the <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow">beautiful soup documentation</a> and the <a href="https://docs.python.org/2/library/re.html" rel="nofollow">regex doc</a> are something that you should read and understand how the things ...
0
2016-08-18T08:53:03Z
[ "python", "html", "fonts", "beautifulsoup" ]
Need to extract all the font sizes and the text using beautifulsoup
39,012,739
<p>I have the following html file stored on my local system:</p> <pre><code>&lt;span style="position:absolute; border: gray 1px solid; left:0px; top:50px; width:612px; height:792px;"&gt;&lt;/span&gt; &lt;div style="position:absolute; top:50px;"&gt;&lt;a name="1"&gt;Page 1&lt;/a&gt;&lt;/div&gt; &lt;div style="position:...
0
2016-08-18T07:57:18Z
39,015,419
<p>Hope this helps : I suggest you to read more documents on <code>BeautifulSoup</code></p> <pre><code>from bs4 import BeautifulSoup htmlData = open('/home/usr/Downloads/files/output.html', 'r') soup = BeautifulSoup(htmlData) font_spans = [ data for data in soup.select('span') if 'font-size' in str(data) ] output = [...
1
2016-08-18T10:07:20Z
[ "python", "html", "fonts", "beautifulsoup" ]
Need to extract all the font sizes and the text using beautifulsoup
39,012,739
<p>I have the following html file stored on my local system:</p> <pre><code>&lt;span style="position:absolute; border: gray 1px solid; left:0px; top:50px; width:612px; height:792px;"&gt;&lt;/span&gt; &lt;div style="position:absolute; top:50px;"&gt;&lt;a name="1"&gt;Page 1&lt;/a&gt;&lt;/div&gt; &lt;div style="position:...
0
2016-08-18T07:57:18Z
39,016,902
<p>You can use a <em>css select</em> <code>select("[style*=font-size]")</code> to fing tags with a style attribute that contains <em>font-size</em> and use a regex to extract the value:</p> <pre><code>In [12]: from bs4 import BeautifulSoup In [13]: import re In [14]: soup = BeautifulSoup(html, "html.parser") In [15...
1
2016-08-18T11:20:55Z
[ "python", "html", "fonts", "beautifulsoup" ]
Alternative to numpy.random.poisson() for drawin a SINGLE poisson distributed random number
39,012,787
<p>I noticed that drawing <strong>single</strong> random numbers using <code>numpy.random</code> is generally way slower than using <code>random</code>, obviously because <code>numpy.random</code> is optimized for drawing a bunch of random numbers in one shot. E.g., timings for sampling a random integer from a list are...
0
2016-08-18T07:59:54Z
39,014,499
<p>You can create all values at once by passing in an iterable of lambdas:</p> <pre><code>numpy.random.poisson(lam=numpy.arange(200), size=(100, 200)) </code></pre> <p>this will return 100 values for each of the 200 different lambda (100 * 200 values in total) values in one execution.</p>
0
2016-08-18T09:24:23Z
[ "python" ]
Python - Remove 'style'-attribute from HTML
39,012,857
<p>I have a String in Python, which has some HTML in it. Basically it looks like this.</p> <pre><code>&gt;&gt;&gt; print someString # I get someString from the backend "&lt;img style='height:50px;' src='somepath'/&gt;" </code></pre> <p>I try to display this HTML in a PDF. Because my PDF generator can't handle the...
-1
2016-08-18T08:03:08Z
39,013,125
<p>I wouldn't use RegEx with this because </p> <ol> <li>Regex is not really suited for HTML parsing and even though this is a simple one there could be many variations and edge cases you need to consider and the resulting regex could turn out to be a nightmare</li> <li>Regex sucks. It can be really useful but honestly...
0
2016-08-18T08:17:23Z
[ "python", "html" ]
Python - Remove 'style'-attribute from HTML
39,012,857
<p>I have a String in Python, which has some HTML in it. Basically it looks like this.</p> <pre><code>&gt;&gt;&gt; print someString # I get someString from the backend "&lt;img style='height:50px;' src='somepath'/&gt;" </code></pre> <p>I try to display this HTML in a PDF. Because my PDF generator can't handle the...
-1
2016-08-18T08:03:08Z
39,013,319
<p>Using RegEx to work with HTML is a very bad idea but if you really want to use it, try this:</p> <pre><code>/style=["']?((?:.(?!["']?\s+(?:\S+)=|[&gt;"']))+.)["']?/ig </code></pre>
0
2016-08-18T08:27:23Z
[ "python", "html" ]
Python3 and elementium
39,012,863
<p>I'm trying to refactor my tests from Python 2.7 to Python 3.5. On this moment I've got problem with elementium lib. What is wrong with this lib?</p> <pre><code>return SeElements( self.browser, context=self, fn=lambda context: [context.items[i]], config=self.config) </code></pre> <p>Error:</p> <pre><code>File ...
0
2016-08-18T08:03:21Z
39,018,391
<p>At the moment you are passing a value <code>i</code> to the <code>items</code> list. The error is pretty descriptive, it is complaining that the value of i is a string, not an integer. To access a list element by its index you must provide integer. </p> <p>Can you share a bit of the code where you define <code>i</c...
0
2016-08-18T12:34:28Z
[ "python", "python-2.7", "python-3.x", "pycharm" ]
Scrapy making Request with POST method
39,012,902
<p>I'm trying to scrape a list of product from "<a href="http://eastasiaeg.com/en/laptop-in-egypt" rel="nofollow">http://eastasiaeg.com/en/laptop-in-egypt</a>" using Scrapy. </p> <p>Part of products loads dynamically, and a tried to build Scrapy request. But something is wrong with it. Pls help.</p> <pre><code># -*- ...
0
2016-08-18T08:05:21Z
39,013,935
<p>You should use <code>scrapy.FormRequest</code> when you want to do POST requests with form data in them. </p> <pre><code>def start_requests(self): form_data = {} # your formdata yield scrapy.FormRequest(url, formdata=form_data) </code></pre> <p>Your approach could work as well, but your for loop doesn't m...
0
2016-08-18T08:58:37Z
[ "python", "request", "scrapy" ]
How do I check if there is a string item in a list of mixed types, in python
39,012,938
<p>Say I have a <code>list l1 = ['s',1,2] and l2 = [1,2,3]</code>. Obviously <code>l1</code> has an item of string type and <code>l2</code> doesn't.</p> <p>But when a list gets super large and I do not know the items in a list, how do I know if this list contains an item of string type.</p>
-1
2016-08-18T08:07:00Z
39,013,037
<pre><code>if any(isinstance(x, str) for x in your_list): print("the list contains a string") </code></pre>
5
2016-08-18T08:12:17Z
[ "python", "string", "list" ]
How do I check if there is a string item in a list of mixed types, in python
39,012,938
<p>Say I have a <code>list l1 = ['s',1,2] and l2 = [1,2,3]</code>. Obviously <code>l1</code> has an item of string type and <code>l2</code> doesn't.</p> <p>But when a list gets super large and I do not know the items in a list, how do I know if this list contains an item of string type.</p>
-1
2016-08-18T08:07:00Z
39,013,048
<p>You can use a loop and check if, at each index of your array, the value is corresponding to a number. Use ascii code ( code 48 to 57 for 0 to 9) If the ascii code of your value is between 48 and 57, you know it's a number. If not, you know it's not a number.</p> <p>Hope this helps</p>
1
2016-08-18T08:13:18Z
[ "python", "string", "list" ]
How do I check if there is a string item in a list of mixed types, in python
39,012,938
<p>Say I have a <code>list l1 = ['s',1,2] and l2 = [1,2,3]</code>. Obviously <code>l1</code> has an item of string type and <code>l2</code> doesn't.</p> <p>But when a list gets super large and I do not know the items in a list, how do I know if this list contains an item of string type.</p>
-1
2016-08-18T08:07:00Z
39,013,069
<p>You can try this:</p> <p><code>if any(type(each_item) is str for each_item in l1): # Do something</code></p>
0
2016-08-18T08:14:21Z
[ "python", "string", "list" ]
How do I check if there is a string item in a list of mixed types, in python
39,012,938
<p>Say I have a <code>list l1 = ['s',1,2] and l2 = [1,2,3]</code>. Obviously <code>l1</code> has an item of string type and <code>l2</code> doesn't.</p> <p>But when a list gets super large and I do not know the items in a list, how do I know if this list contains an item of string type.</p>
-1
2016-08-18T08:07:00Z
39,013,084
<p>The solution using <code>isinstance</code> function:</p> <pre><code>def hasString(l): for item in l: if isinstance(item, str): return True return False l1 = [1, 2, 3] l2 = ['s', 2, 3] print(hasString(l1)) # False print(hasString(l2)) # True </code></pre>
0
2016-08-18T08:15:43Z
[ "python", "string", "list" ]
How do I check if there is a string item in a list of mixed types, in python
39,012,938
<p>Say I have a <code>list l1 = ['s',1,2] and l2 = [1,2,3]</code>. Obviously <code>l1</code> has an item of string type and <code>l2</code> doesn't.</p> <p>But when a list gets super large and I do not know the items in a list, how do I know if this list contains an item of string type.</p>
-1
2016-08-18T08:07:00Z
39,013,275
<p>I just saw this post : <a href="http://stackoverflow.com/questions/152580/whats-the-canonical-way-to-check-for-type-in-python">What&#39;s the canonical way to check for type in python?</a></p> <p><strong>quote</strong> : <em>"Since Python encourages Duck Typing, you should just try to use the object's methods the w...
1
2016-08-18T08:25:05Z
[ "python", "string", "list" ]
SciPy's interp1d endpoints
39,013,058
<p>In SciPy's interpolation module there is a function called <strong>interp1d</strong>. The documentation says that it is a spline interpolation: <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html" rel="nofollow">http://docs.scipy.org/doc/scipy/reference/generated/scipy.interp...
1
2016-08-18T08:13:46Z
39,036,665
<p><code>CubicSpline</code>, which is new in scipy 0.18, allows a user control over the boundary conditions. Neither FITPACK nor interp1d do.</p>
1
2016-08-19T10:25:08Z
[ "python", "scipy", "interpolation", "cubic-spline" ]
Skip directories in a search in Python
39,013,059
<p>Im running the following code, and i want to skip 3 folders with respective names: folder1, folder2, .repository.</p> <p>However if some of the folders is not present i get the error:</p> <p>indentationerror: unindent does not match any outer indentation level</p> <p>How can I search skipping that folders, and ev...
-1
2016-08-18T08:13:52Z
39,013,259
<p>Your indentation of the if doesn't match the current indentation</p> <pre><code>import re import os from os.path import join comment=re.compile(r"&lt;!--\s+\| Start of user code \(user defined modules\)\s+\|--&gt;\s+&lt;!--\s+\| End of user code\s+\|--&gt;", re.MULTILINE) tag="&lt;module&gt;" for root, dirs, files...
0
2016-08-18T08:24:11Z
[ "python" ]
Trouble with Python3 imports
39,013,061
<p>This question was asked a lots of times but none of the solutions seem to help in my case.</p> <p>I have a directory structure like this</p> <pre><code>my_project/ main.py bootstrap/ __init__.py boot.py consumer/ __init__.py main.py </code></pre> <p>Being at the topleve...
0
2016-08-18T08:13:55Z
39,013,627
<p>You are getting this error because module search path only includes the current directory, and not its parents; and since your other module is not in the <code>PYTHONPATH</code> it isn't available to import.</p> <p>You can find this out yourself by printing <code>sys.path</code> in your script.</p> <p>I created a ...
4
2016-08-18T08:43:51Z
[ "python", "python-3.x", "import" ]
How to savefig as show in matplotlib.pyplot?
39,013,094
<p>I'm using <code>matplotlib.pyplot</code> to draw a bar chart with a legend, the figure saved by <code>plt.savefig()</code> is incomplete compared to <code>plt.show()</code>. To be more precise, the legend is out of the plot, the jpg file only have the leftside half of the legend.</p> <p>My codes:</p> <pre><code>fr...
0
2016-08-18T08:16:17Z
39,013,772
<p>Hope this will solve the problem.Add <code>bbox_inches='tight'</code> in the params which helps removing white spaces</p> <pre><code> fig.savefig('a.jpeg', bbox_inches='tight', pad_inches=0) </code></pre>
1
2016-08-18T08:51:03Z
[ "python", "matplotlib", "plot", "legend" ]
How to display two images on the same Tkinter Toplevel () window
39,013,108
<p>So I'm building an app which has the option to compare two photos. I put a listbox on the left side of the screen, and a place for the two photos on the right side of the screen. There are three buttons under the listbox which are used to place pictures under a certain title (Pic 1 or Pic 2). It works, but I can onl...
0
2016-08-18T08:16:41Z
39,042,026
<p>I'm using python 3.4 so i'm not 100% sure this will work for you (for me Tkinter is tkinter)</p> <p>When I want to use multiple images I add them all to a list, you don't need to do anything with the list after that</p> <p>This has always worked for me and I have the same problem you described without a list</p> ...
0
2016-08-19T14:51:46Z
[ "python", "image", "tkinter", "listbox", "global-variables" ]
zipfile in Python produces not quite normal ZIP files
39,013,110
<p>In my project set of files are created and packed to ZIP archive to be used at Android mobile phone. Android application is opening such ZIP files for reading initial data and then store results of its work to the same ZIPs. I have no access to source code of mentioned Android App and old script that generated zip f...
2
2016-08-18T08:16:46Z
39,031,727
<p>Based on the differences listed in UPDATE 2 of Question and examples from <a href="http://stackoverflow.com/questions/434641/how-do-i-set-permissions-attributes-on-a-file-in-a-zip-file-using-pythons-zip">other question about zipfile</a>, I have tried the following code to add directories to ZIP file and check the re...
1
2016-08-19T05:32:23Z
[ "python", "python-3.x", "zipfile" ]
odoo 9 get field value in current record
39,013,168
<p>I want to add up a number and field value in current record, this is my code:</p> <pre><code>def _add(self, cr, uid, ids, context=None): state_id = self.pool.get('ga.cashadvance').browse(self, cr, uid, ids, self.state) res = chr(int(state_id) + 1) return res class cashadvance(osv.osv): _name = 'ga....
1
2016-08-18T08:19:53Z
39,013,814
<p>Just write the state on every button click without so much code:</p> <pre class="lang-py prettyprint-override"><code>class cashadvance(orm.Model): _name = 'ga.cashadvance' _columns = { 'id_user': fields.many2one( 'res.users', string='User', required=True, readonly=True), 'descrip...
1
2016-08-18T08:52:33Z
[ "python", "python-2.7", "openerp" ]
Is there an official way to create discrete-valued range widget in GTK?
39,013,193
<p>From what I can see, the behavior any <code>Range</code>-based widget is defined by an <code>Adjustements</code> one.</p> <p>Since there seems to be no official way to restrict the range to a few discrete values, I have tried a lots of ways to actually reset the values.</p> <p>What works, <strong>but is not opti...
3
2016-08-18T08:21:32Z
39,036,673
<p>It seems you can just override the <code>change-value</code> signal:</p> <pre><code>class DiscreteScale(Gtk.Scale): def __init__(self, values, *args, **kwargs): super().__init__(*args, **kwargs) values.sort() self.values= values adjustment= self.get_adjustment() adjustm...
4
2016-08-19T10:25:50Z
[ "python", "python-3.x", "gtk", "gtk3", "gobject" ]
__metaclass__ in Python3.5
39,013,249
<p>In Python2.7 this code can work very well, <code>__getattr__</code> in <code>MetaTable</code> will run. But in Python 3.5 it doesn't work.</p> <pre><code>class MetaTable(type): def __getattr__(cls, key): temp = key.split("__") name = temp[0] alias = None if len(temp) &gt; 1: ...
0
2016-08-18T08:23:44Z
39,013,295
<p>Python 3 <a href="https://www.python.org/dev/peps/pep-3115/" rel="nofollow">changed how you specify a metaclass</a>, <code>__metaclass__</code> is no longer checked.</p> <p>Use <code>metaclass=...</code> in the class <em>signature</em>:</p> <pre><code>class Table(object, metaclass=MetaTable): </code></pre> <p>Dem...
1
2016-08-18T08:26:04Z
[ "python", "python-3.5", "metaclass" ]
why is only one thread gets executed and other is not
39,013,256
<pre><code>import threading,time def auto2(): while 1: print ("hello master") time.sleep(2) def auto1(): while 1: print "hello" time.sleep(3) x=threading.Thread(target=auto1(),args=()) y=threading.Thread(target=auto2(),args=()) x.start() y.start() </code></pre>
0
2016-08-18T08:24:05Z
39,013,306
<pre><code>import threading, time def auto2(): while 1: print("hello master") time.sleep(2) def auto1(): while 1: print ("hello") time.sleep(3) x = threading.Thread(target=auto1) y = threading.Thread(target=auto2) x.start() y.start() </code></pre> <p>target=auto1() - > target=au...
0
2016-08-18T08:26:36Z
[ "python", "python-multithreading" ]
Approximating a simple sin() function with lasagne
39,013,366
<p>I'm trying lasagne and the nolearn NeuralNet function to approximate a simple <code>sin</code> function. After all, neural nets are proven to be universal approximators, so I wanted to try lasagne on a simple non-linear function to show that fact experimentally. This is the code:</p> <pre><code>import lasagne impor...
1
2016-08-18T08:30:21Z
39,033,953
<p>I finally know what was happening. I post my guess in case anyone comes by the same problem.</p> <p>As it is known, NeuralNet from nolearn environment uses batch training. I don't exactly know how it chooses the batches, but it seems to me that it chooses them sequentially. Then, if the data is not randomized, a ba...
2
2016-08-19T08:00:06Z
[ "python", "lasagne", "nolearn", "function-approximation" ]