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
Zero fill data frame forward fill
37,810,688
<p>I am trying to fill a dataframe with zeros, however <strong>I do not want to touch leading NaNs</strong>:</p> <pre><code>rng = pd.date_range('2016-06-01', periods=9, freq='D') df = pd.DataFrame({'data': pd.Series([np.nan]*3 + [20, 30, 40] + [np.nan]*3, rng)}) 2016-06-01 NaN 2016-06-02 NaN 2016-06-03 Na...
4
2016-06-14T11:26:44Z
37,810,958
<p>you can do it using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.last_valid_index.html" rel="nofollow">last_valid_index()</a> function:</p> <pre><code>In [80]: df Out[80]: data data1 data2 2016-06-01 NaN NaN NaN 2016-06-02 NaN NaN 10.0 2016-06-03 NaN...
4
2016-06-14T11:39:34Z
[ "python", "pandas", "dataframe" ]
Zero fill data frame forward fill
37,810,688
<p>I am trying to fill a dataframe with zeros, however <strong>I do not want to touch leading NaNs</strong>:</p> <pre><code>rng = pd.date_range('2016-06-01', periods=9, freq='D') df = pd.DataFrame({'data': pd.Series([np.nan]*3 + [20, 30, 40] + [np.nan]*3, rng)}) 2016-06-01 NaN 2016-06-02 NaN 2016-06-03 Na...
4
2016-06-14T11:26:44Z
37,811,092
<p>I think you can find first <code>group</code> of <code>NaN</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isnull.html" rel="nofollow"><code>isnull</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.cumsum.html" rel="nofollow"><code>cum...
3
2016-06-14T11:44:50Z
[ "python", "pandas", "dataframe" ]
How to send data to view without using html forms?
37,810,780
<p>I have some data(checkbox and input field) in template file which I want to send to views.Due to page refresh upon submit checkbox field is unchecked.So how to send data to django view without using html form.Is it possible using jquery/ajax?</p> <pre><code>&lt;form id="myform"&gt; {% csrf_token %} &lt;p id...
-1
2016-06-14T11:31:24Z
37,811,349
<p>It is possible indeed.</p> <p>Using javascript, catch the form submit event.</p> <p>In the function, serialize the form (exemple using jquery : <a href="https://api.jquery.com/serialize/" rel="nofollow">https://api.jquery.com/serialize/</a>), or get the field values using selectors.</p> <p>Craft your ajax request...
0
2016-06-14T11:57:40Z
[ "python", "django", "django-templates" ]
Fuzzer for Python dictionaries
37,810,910
<p>I am currently looking for a fuzzer for Python dictionaries. I am already aware of some fuzzing tools such as:</p> <ul> <li><a href="https://portswigger.net/burp/" rel="nofollow">Burp</a></li> <li><a href="http://www.peachfuzzer.com/" rel="nofollow">Peach</a></li> </ul> <p>However, they seem a bit broader of what ...
-1
2016-06-14T11:37:27Z
37,811,842
<p>Based on the comments to the question, why not simply writing a fixed length template based fuzzer like this:</p> <pre><code>#! /usr/bin/env python """Minimal template based dict string value fuzzer.""" from __future__ import print_function import random import string def random_string(rng, length, chars=string....
0
2016-06-14T12:19:26Z
[ "python", "dictionary", "fuzzer" ]
copy past objet in python opencv2
37,810,920
<p>i have this image <a href="http://i.stack.imgur.com/JCMKE.png" rel="nofollow"><img src="http://i.stack.imgur.com/JCMKE.png" alt="enter image description here"></a></p> <p>i already have the contour of the bullet shape using </p> <pre><code>contours, hierarchy = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_...
0
2016-06-14T11:37:54Z
37,811,099
<p>Use Grabcut algorithm to extract the forground image, here is some code that u will also like </p> <pre><code>img = cv2.imread('IMAGE.jpg') mask = np.zeros(img.shape[:2],np.uint8) bgdModel = np.zeros((1,65),np.float64) fgdModel = np.zeros((1,65),np.float64) rect = (50,50,450,290) cv2.grabCut(img,mask,rect,bgdMode...
0
2016-06-14T11:45:18Z
[ "python", "opencv", "paste", "cut" ]
Python, why does mmap.move() fill up the memory?
37,811,109
<p>edit: Using Win10 and python 3.5</p> <p>I have a function that uses mmap to remove bytes from a file at a certain offset:</p> <pre><code>def delete_bytes(fobj, offset, size): fobj.seek(0, 2) filesize = fobj.tell() move_size = filesize - offset - size fobj.flush() file_map = mmap.mmap(fobj.file...
5
2016-06-14T11:45:59Z
37,812,629
<p>This seems like it <em>should</em> work. I did find one suspicious bit in the mmapmodule.c source code, <code>#ifdef MS_WINDOWS</code>. Specifically, after all the setup to parse arguments, the code then does this:</p> <pre class="lang-c prettyprint-override"><code>if (fileno != -1 &amp;&amp; fileno != 0) { /...
1
2016-06-14T12:53:40Z
[ "python", "performance", "memory", "mmap" ]
Global variable in python function doesn't work for my code
37,811,168
<p>This works. </p> <pre><code>a = [2,5,3,7,9,12] def mean_list(x): b = 0 for i in x: b=b+i c = b/len(x) return c print(mean_list(a)) </code></pre> <p>but this doesn't work, even though I have declared my list as global. Why?</p> <pre><code>def mean_list(x): global a ...
-3
2016-06-14T11:49:00Z
37,811,260
<p>Your list (<code>a</code>) is only created when you call the function. So it is not created unless you call the function once, try calling the function with another variable and then <code>a</code></p>
1
2016-06-14T11:53:13Z
[ "python", "variables", "global" ]
Get appname from user-agent
37,811,207
<p>I have strings like</p> <pre><code>VK/28 CFNetwork/711.4.6 Darwin/14.0.0 Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13C75 Safari/601.1 Instagram 8.2.0 (iPhone4,1; iPhone OS 8_4; ru_RU; ru; scale=2.00; 640x960) AppleWebKit/420+ Mozilla/5.0 (iP...
-2
2016-06-14T11:50:38Z
37,811,380
<p>You can get like this:</p> <pre><code>&gt;&gt;&gt; log = '''VK/28 CFNetwork/711.4.6 Darwin/14.0.0 ... Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13C75 Safari/601.1 ... Instagram 8.2.0 (iPhone4,1; iPhone OS 8_4; ru_RU; ru; scale=2.00; 640x960) ...
1
2016-06-14T11:59:22Z
[ "python", "user-agent" ]
Get appname from user-agent
37,811,207
<p>I have strings like</p> <pre><code>VK/28 CFNetwork/711.4.6 Darwin/14.0.0 Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13C75 Safari/601.1 Instagram 8.2.0 (iPhone4,1; iPhone OS 8_4; ru_RU; ru; scale=2.00; 640x960) AppleWebKit/420+ Mozilla/5.0 (iP...
-2
2016-06-14T11:50:38Z
37,811,766
<p>It's not quite clear if you are just trying to parse headers, or trying to match User-agent string against known apps/services that access you server. Since the former question is answered by Adem, here is explanation for the latter.</p> <p>There's no way to find out the exact name of the app accessing your server ...
1
2016-06-14T12:15:59Z
[ "python", "user-agent" ]
Python 2.6 : piping bash commands containing python variables(inside python script)
37,811,350
<p>I want to run the below bash command from my python script:</p> <pre><code>stat --printf='%U%G%a' /tmp/file1.csv &amp;&amp;md5sum /tmp/file1.csv |awk '{print $1}' </code></pre> <p>I have done it using <code>subprocess.Popen</code> as below:</p> <pre><code>Command=subprocess.Popen(["stat --printf='%U%G%a' file1.cs...
0
2016-06-14T11:57:46Z
37,811,582
<p>When you call <code>Popen</code> you simply pass a string to the function. So you could use string formatting to put the correct variable in there: </p> <pre><code>filevar="/tmp/file.csv" Command=subprocess.Popen(["stat --printf='%U%G%a' %(filevar) &amp;&amp;md5sum filevar|awk '{print $1}'" % {"filevar": filevar}],...
0
2016-06-14T12:07:49Z
[ "python", "linux", "bash", "subprocess", "python-2.6" ]
Python 2.6 : piping bash commands containing python variables(inside python script)
37,811,350
<p>I want to run the below bash command from my python script:</p> <pre><code>stat --printf='%U%G%a' /tmp/file1.csv &amp;&amp;md5sum /tmp/file1.csv |awk '{print $1}' </code></pre> <p>I have done it using <code>subprocess.Popen</code> as below:</p> <pre><code>Command=subprocess.Popen(["stat --printf='%U%G%a' file1.cs...
0
2016-06-14T11:57:46Z
37,847,839
<p>To support spaces and other shell meta-characters, use <a href="https://docs.python.org/2/library/pipes.html#pipes.quote" rel="nofollow"><code>pipes.quote()</code></a>:</p> <pre><code>#!/usr/bin/env python import pipes from subprocess import check_output path = "/path/to/file.csv" output = check_output("stat --pri...
1
2016-06-16T00:14:22Z
[ "python", "linux", "bash", "subprocess", "python-2.6" ]
Change values in pandas Series between dates
37,811,420
<p>I have a pandas Series() which has daily entries all set to False:</p> <pre><code>d = pd.Series(False, pd.bdate_range("20100101", periods=100, freq="D")) </code></pre> <p>I now want to set the values between the 15th and 20th of each month to True. I generate a Series with indices being the start/end dates and val...
1
2016-06-14T12:00:56Z
37,811,572
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.between.html" rel="nofollow"><code>between</code></a>, but first you need create <code>Serie</code> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DatetimeIndex.day.html" rel="nofollow"><code>Datetime...
2
2016-06-14T12:07:14Z
[ "python", "numpy", "pandas", "scipy" ]
Change values in pandas Series between dates
37,811,420
<p>I have a pandas Series() which has daily entries all set to False:</p> <pre><code>d = pd.Series(False, pd.bdate_range("20100101", periods=100, freq="D")) </code></pre> <p>I now want to set the values between the 15th and 20th of each month to True. I generate a Series with indices being the start/end dates and val...
1
2016-06-14T12:00:56Z
37,811,638
<p>Using your existing <code>pd.Series</code>, you can use <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a> via the <code>.day</code> attribute of the <code>DateTimeIndex</code>, or use <code>np.in1d</code> to the same effect:</p> <pr...
2
2016-06-14T12:10:09Z
[ "python", "numpy", "pandas", "scipy" ]
How to export a Python program from PyCharm
37,811,518
<p>I have a Python project created in PyCharm. Now that it's finished I want to make it available without PyCharm (making it an executable is not relevant). It consists of different packages and quite a few files inside each package. How can I export the project so I can run it from one file that will call the rest?</p...
0
2016-06-14T12:05:09Z
37,812,234
<p>If you do not want to publish the project and just use it for yourself:</p> <ol> <li><p>Create a new <code>__main__.py</code> in your project root directory and start your program from there (by importing the old <code>main.py</code> etc.)</p></li> <li><p>Make sure the program runs as expected: Run <code>python __m...
1
2016-06-14T12:37:05Z
[ "python", "python-2.7", "pycharm", "project" ]
How to type # in python's command line?
37,811,524
<p>I am a student who is new to python and need to finish a python program for assignment. The goal of the program is to find some target strings in a list of news titles. </p> <p>For example, there is a file written with a list of news title. When I type this in command line:</p> <p>"python hw3.py Obama#Trump,Japan#...
-2
2016-06-14T12:05:31Z
37,812,805
<p>If you'd like to execute a file in the python shell with parameters: you can simply use: subprocess.call(['./abc.py', arg1, arg2]) for reference: <a href="http://stackoverflow.com/questions/5788891/execfile-with-argument-in-python-shell">execfile with argument in python shell</a></p>
0
2016-06-14T13:00:24Z
[ "python" ]
Integrating PayUmoney with django project
37,811,657
<p>I am new to django, i am trying to integrate payumoney with my django project. but i am unable to integrate please anyone can give me the steps of payumoney integration.</p>
0
2016-06-14T12:10:44Z
37,813,444
<p>Please refer <a href="https://www.payumoney.com/pdf/API-Docs.pdf" rel="nofollow">API documentation</a> ,<a href="https://www.payumoney.com/pdf/PayUMoney-Technical-Integration-Document.pdf" rel="nofollow">Integration doc</a>,and <a href="https://www.payumoney.com/websiteintegration.html" rel="nofollow">website integ...
0
2016-06-14T13:26:10Z
[ "python", "django", "payumoney" ]
how to get the datetimes before and after some specific dates in Pandas?
37,811,668
<p>I have a Pandas DataFrame that looks like</p> <pre><code>col1 2015-02-02 2015-04-05 2016-07-02 </code></pre> <p>I would like to add, for each date in col 1, the <code>x</code> days before and <code>x</code> days after that date. </p> <p>That means that the resulting DataFrame will contain more rows (specifically,...
3
2016-06-14T12:11:09Z
37,811,757
<p>Something like this takes a dataframe with a <code>datetime.date</code> column and then stacks another <code>Series</code> underneath with <code>timedelta</code> shifts to the original data.</p> <pre><code>import datetime import pandas as pd df = pd.DataFrame([{'date': datetime.date(2016, 1, 2)}, {'date': datetime....
1
2016-06-14T12:15:39Z
[ "python", "pandas" ]
how to get the datetimes before and after some specific dates in Pandas?
37,811,668
<p>I have a Pandas DataFrame that looks like</p> <pre><code>col1 2015-02-02 2015-04-05 2016-07-02 </code></pre> <p>I would like to add, for each date in col 1, the <code>x</code> days before and <code>x</code> days after that date. </p> <p>That means that the resulting DataFrame will contain more rows (specifically,...
3
2016-06-14T12:11:09Z
37,811,904
<p>you can do it this way, but I'm not sure that it's the best / fastest way to do it:</p> <pre><code>In [143]: df Out[143]: col1 0 2015-02-02 1 2015-04-05 2 2016-07-02 In [144]: %paste N = 2 (df.col1.apply(lambda x: pd.Series(pd.date_range(x - pd.Timedelta(days=N), ...
1
2016-06-14T12:22:37Z
[ "python", "pandas" ]
Lambda expression with list operations
37,811,713
<p>Shouldn't the below lambda expression return a list? Currently, it isn't.</p> <pre><code> &gt;&gt;&gt; f=lambda l ,x:l.append(x) &gt;&gt;&gt; print f([1],3) None </code></pre>
-5
2016-06-14T12:13:16Z
37,811,785
<p><a href="https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types" rel="nofollow"><code>append</code></a> is a side-effecting function; it appends a value to an existing list without returning a value (or None, depending on how you want to think of it).</p> <p>Perhaps you want:</p> <pre><code>lambda ...
1
2016-06-14T12:17:06Z
[ "python" ]
Lambda expression with list operations
37,811,713
<p>Shouldn't the below lambda expression return a list? Currently, it isn't.</p> <pre><code> &gt;&gt;&gt; f=lambda l ,x:l.append(x) &gt;&gt;&gt; print f([1],3) None </code></pre>
-5
2016-06-14T12:13:16Z
37,811,866
<p>the function <code>append</code> returns <code>None</code> so your lambda returns <code>None</code>, too. Also the <code>append</code> changes the local variable <code>l</code> only </p>
0
2016-06-14T12:20:46Z
[ "python" ]
Lambda expression with list operations
37,811,713
<p>Shouldn't the below lambda expression return a list? Currently, it isn't.</p> <pre><code> &gt;&gt;&gt; f=lambda l ,x:l.append(x) &gt;&gt;&gt; print f([1],3) None </code></pre>
-5
2016-06-14T12:13:16Z
37,811,950
<p><a href="https://docs.python.org/3/tutorial/datastructures.html" rel="nofollow"><code>list.append()</code></a> does not return a value but because the python list is a <a href="https://codehabitude.com/2013/12/24/python-objects-mutable-vs-immutable/" rel="nofollow">mutable object</a>, <code>3</code> will indeed be a...
0
2016-06-14T12:24:22Z
[ "python" ]
add code at class or function in python interperter
37,811,767
<p>I like to use python interpreter, as it shows the result instantly. But I sometimes make mistakes. Like misspelling or typing 'enter' twice during writing class or function. It's really annoying work to rewrite the code.</p> <p>Is it possible to add some code to a predefined class or function in the interpreter?</...
1
2016-06-14T12:16:04Z
37,811,868
<p>I don't know of a good way to achieve what you describe by just using the command line. But you can create a <code>script.py</code> file in the current directory and just <code>import script</code>. From there on out you are able to access all the defined functions and classes in the <code>script.py</code> file. </...
1
2016-06-14T12:20:52Z
[ "python" ]
add code at class or function in python interperter
37,811,767
<p>I like to use python interpreter, as it shows the result instantly. But I sometimes make mistakes. Like misspelling or typing 'enter' twice during writing class or function. It's really annoying work to rewrite the code.</p> <p>Is it possible to add some code to a predefined class or function in the interpreter?</...
1
2016-06-14T12:16:04Z
37,811,883
<p>You can use inheritance. Derived a new class (B) from your previous predefined class A. That way you can add method to it temporary during your development. </p> <pre><code>''' file a.py ''' class A: # predefined. pass </code></pre> <p>in the interpreter: </p> <pre><code>$ python -i a.py &gt;&gt;&gt; cla...
-2
2016-06-14T12:21:37Z
[ "python" ]
add code at class or function in python interperter
37,811,767
<p>I like to use python interpreter, as it shows the result instantly. But I sometimes make mistakes. Like misspelling or typing 'enter' twice during writing class or function. It's really annoying work to rewrite the code.</p> <p>Is it possible to add some code to a predefined class or function in the interpreter?</...
1
2016-06-14T12:16:04Z
37,812,075
<p>You can install ipython, it has the history function on steroids it does exactly what you ask, without adding code anywhere. If you make a typo or type enter twice, just use the "up arrow" and you get back all the class or function.</p>
1
2016-06-14T12:29:52Z
[ "python" ]
Cascading string interpolation in python
37,811,864
<p>Given a dictionary of format strings, I want to do cascading/recursive string interpolation.</p> <pre><code>FOLDERS = dict(home="/home/user", workspace="{home}/workspace", app_project="{workspace}/{app_name}", app_name="my_app") </code></pre> <p>I started with this impl...
-1
2016-06-14T12:20:41Z
37,812,197
<p>You can check for such reference cycles in the for loop easily. Just check if the key is referenced in the matching value within the for loop:</p> <pre><code>def interpolate(attrs): remain = [k for k, v in attrs.items() if "{" in v] while remain: for k in remain: attrs[k] = attrs[k].form...
1
2016-06-14T12:35:39Z
[ "python", "string-interpolation", "string-substitution" ]
Cascading string interpolation in python
37,811,864
<p>Given a dictionary of format strings, I want to do cascading/recursive string interpolation.</p> <pre><code>FOLDERS = dict(home="/home/user", workspace="{home}/workspace", app_project="{workspace}/{app_name}", app_name="my_app") </code></pre> <p>I started with this impl...
-1
2016-06-14T12:20:41Z
37,812,274
<p>If your only problem is to detect cyclic references in order to avoid infinite loops, you can stop as soon as one interpolation returns its input:</p> <pre><code>def interpolate(attrs): remain = [k for k, v in attrs.items() if "{" in v] while remain: for k in remain: attrs[k] = attrs[k]....
0
2016-06-14T12:38:33Z
[ "python", "string-interpolation", "string-substitution" ]
Import azure.servicebus error in Python
37,812,232
<p>I'm using the module azure.servicebus.</p> <pre><code>from azure.servicebus import ServiceBusService , Message , Queue </code></pre> <p>When I use it in an external made script and run it, it works and gives no errors.</p> <p>When I import the module in my <strong>init</strong>.py file and run the flask server. I...
0
2016-06-14T12:37:04Z
37,850,905
<p>There is a similar SO thread answered by me, which I think you can refer to, and try to solve the issue, please see <a href="http://stackoverflow.com/questions/34213764/unable-to-use-azure-sdk-in-python">Unable to use azure SDK in Python</a>.</p> <p>Meanwhile, per my experience, I suggest that you need to check whe...
0
2016-06-16T05:53:15Z
[ "python", "azure", "import", "python-import", "azureservicebus" ]
pandas - scatter plot with different color legend for each point
37,812,325
<p>Starting from the following example:</p> <pre><code>fig, ax = plt.subplots() df = pd.DataFrame({'n1':[1,2,1,3], 'n2':[1,3,2,1], 'l':['a','b','c','d']}) for label in df['l']: df.plot('n1','n2', kind='scatter', ax=ax, s=50, linewidth=0.1, label=label) </code></pre> <p>what I obtained is the following scatterp...
4
2016-06-14T12:40:25Z
37,812,952
<p>How about this,</p> <p><a href="http://i.stack.imgur.com/7uaka.png" rel="nofollow"><img src="http://i.stack.imgur.com/7uaka.png" alt="enter image description here"></a></p> <hr> <p>Here is the source code,</p> <pre><code>import matplotlib.pyplot as plt import pandas as pd import numpy as np from matplotlib impor...
2
2016-06-14T13:06:29Z
[ "python", "pandas", "matplotlib" ]
pandas - scatter plot with different color legend for each point
37,812,325
<p>Starting from the following example:</p> <pre><code>fig, ax = plt.subplots() df = pd.DataFrame({'n1':[1,2,1,3], 'n2':[1,3,2,1], 'l':['a','b','c','d']}) for label in df['l']: df.plot('n1','n2', kind='scatter', ax=ax, s=50, linewidth=0.1, label=label) </code></pre> <p>what I obtained is the following scatterp...
4
2016-06-14T12:40:25Z
37,813,290
<p>The following method will create a list of colors as long as your dataframe, and then plot a point with a label with each color:</p> <pre><code>import matplotlib.pyplot as plt import matplotlib.cm as cm import matplotlib.colors as colors import numpy as np import pandas as pd fig, ax = plt.subplots() df = pd.Data...
2
2016-06-14T13:20:15Z
[ "python", "pandas", "matplotlib" ]
pandas - scatter plot with different color legend for each point
37,812,325
<p>Starting from the following example:</p> <pre><code>fig, ax = plt.subplots() df = pd.DataFrame({'n1':[1,2,1,3], 'n2':[1,3,2,1], 'l':['a','b','c','d']}) for label in df['l']: df.plot('n1','n2', kind='scatter', ax=ax, s=50, linewidth=0.1, label=label) </code></pre> <p>what I obtained is the following scatterp...
4
2016-06-14T12:40:25Z
37,813,305
<p>IIUC you can do it this way:</p> <pre><code>import matplotlib.pyplot as plt from matplotlib import colors import pandas as pd colorlist = list(colors.ColorConverter.colors.keys()) fig, ax = plt.subplots() [df.ix[[i]].plot.scatter('n1', 'n2', ax=ax, s=50, label=l, color=colorlist[i % len(co...
2
2016-06-14T13:20:52Z
[ "python", "pandas", "matplotlib" ]
Django Rest Framework nested serializer
37,812,348
<p>I have models like -</p> <pre><code>class Sectors(models.Model): sector_mc = models.TextField() class Insector(models.Model): foundation = models.ForeignKey(Sectors) name = models.TextField() value = models.FloatField(default=0) </code></pre> <p>I want my data to be in a format like-</p> <pre><code> ...
1
2016-06-14T12:41:05Z
37,815,717
<p>You can <strong>create a <code>SectorSerializer</code></strong> which will contain a nested serializer <code>InsectorSerializer</code>. </p> <p>Since you are using different keys for output we can use <code>source</code> to get the corresponding values from the field names. </p> <p><code>name</code> key in the out...
1
2016-06-14T15:04:21Z
[ "python", "django", "d3.js", "django-rest-framework" ]
Django Rest Framework nested serializer
37,812,348
<p>I have models like -</p> <pre><code>class Sectors(models.Model): sector_mc = models.TextField() class Insector(models.Model): foundation = models.ForeignKey(Sectors) name = models.TextField() value = models.FloatField(default=0) </code></pre> <p>I want my data to be in a format like-</p> <pre><code> ...
1
2016-06-14T12:41:05Z
37,833,798
<p>There was a problem in my views file while saving data to models. DRF worked fine when views problem solved.</p>
0
2016-06-15T11:12:40Z
[ "python", "django", "d3.js", "django-rest-framework" ]
Pandas Dataframe exists outside of method. Why
37,812,416
<p>Lets presume a I have a simple dataframe <code>df</code> And a simple method that does something to the <code>dataframe</code></p> <pre><code>def alterDF(df): df1['new column'] = df['some column'] + x return df1 </code></pre> <p>In the above method I modify an entire <code>column</code> with x and save it...
1
2016-06-14T12:43:40Z
37,812,457
<p>Probably because you have a line like this</p> <pre><code>df1 = df # by doing this you copy the reference also </code></pre> <p>if you want to copy a dataframe use</p> <pre><code>df1 = df.copy() </code></pre> <p>instead</p>
2
2016-06-14T12:45:37Z
[ "python", "pandas", "dataframe" ]
Can't install Pillow in Fedora23
37,812,419
<pre><code> (.newenv)[max@cyber life_besto]$ sudo pip install git+https://github.com/python-pillow/Pillow.git Collecting git+https://github.com/python-pillow/Pillow.git Cloning https://github.com/python-pillow/Pillow.git to /tmp/pip-zSgmXr-build Installing collected packages: Pillow Found existing installation: ...
1
2016-06-14T12:43:44Z
37,812,712
<p>Try installing <code>python-devel</code> as well as <code>redhat-rpm-config</code> packages first (see how to do it <a href="https://stackoverflow.com/questions/6230444/how-to-install-python-developer-package">here</a>), then <code>pip install Pillow</code>.</p> <p>More info on manual installation (as opposed to in...
1
2016-06-14T12:56:41Z
[ "python", "django", "pip", "pillow" ]
How to render template inside of template with angular and django
37,812,424
<p>Question I want to be able to add a multiple Dimensions(Dimension Class) to my Sheet Class. What I would like to do is pass it into angular then back to Django if possible I just need help/guidance on how to do this I have looked a countless blogs and still can't come up with correct way of doing so any help would b...
0
2016-06-14T12:44:06Z
37,943,853
<p>I figured it out.</p> <h1>Here is my angular code</h1> <p>dim_app = angular.module('dim_form', []) </p> <pre><code> .controller('dim_ctrl', ['$scope', '$compile', function ($scope, $compile) { $scope.show_dim = function () { var comp = $compile("&lt;div &lt;/div&gt;")($scope); $("#i...
0
2016-06-21T12:00:04Z
[ "python", "angularjs", "django" ]
Downloading a file with a wildcard from Sharepoint URL with Python
37,812,426
<p>I'm not sure if this can be done or not but I thought I'd ask!</p> <p>I'm running a windows 10 PC using Python 2.7. I'm wanting to download a file form sharepoint to a folder on my C: drive.</p> <pre><code>OpenPath = "https://office.test.com/sites/Rollers/New improved files/" OpenFile = "ABC UK.xlsb" </code></pre>...
1
2016-06-14T12:44:09Z
37,813,298
<p>to find the file in your dir:</p> <pre><code>import os, requests, fnmatch #loop over dir for filename in os.listdir(OpenPath): #find the file if fnmatch.fnmatch(filename, 'ABC_UK*'): #download the file # open file handler with open('C:\dwnlfile.xls', 'wb') as fh: #try to ...
0
2016-06-14T13:20:37Z
[ "python", "python-2.7", "excel-vba", "sharepoint" ]
Parsing xml with same tags and different attributes
37,812,489
<p>I have a network file created from osm using Netconvert. The root element is edge with different attributes. For example, in the first part of the file, the edges are organized as follows.</p> <pre><code>&lt;edge id=":367367171_1" function="internal"&gt; &lt;lane id=":367367171_1_0" index="0" disallow="tram rai...
0
2016-06-14T12:47:11Z
37,812,639
<p>Python's <a href="https://docs.python.org/3/library/stdtypes.html#dict.get" rel="nofollow">get()</a> method for dictionaries is very helpful in these situations because it returns <code>None</code> when a key isn't found in a <code>dict</code>.</p> <pre><code>for elem in netFile.iter(tag='edge'): if elem.attrib...
2
2016-06-14T12:53:57Z
[ "python", "lxml" ]
Parsing xml with same tags and different attributes
37,812,489
<p>I have a network file created from osm using Netconvert. The root element is edge with different attributes. For example, in the first part of the file, the edges are organized as follows.</p> <pre><code>&lt;edge id=":367367171_1" function="internal"&gt; &lt;lane id=":367367171_1_0" index="0" disallow="tram rai...
0
2016-06-14T12:47:11Z
37,812,834
<p>You could detect wich part of the file you are proccessing by the presence of the attributes e.g.:</p> <pre><code># The !required! attributes for each part part1_attributes = ["id", "function"] part2_attributes = ["id", "from", "to", "priority", "type"] for elem in netFile.iter(tag='edge'): if all([attr in ele...
0
2016-06-14T13:01:26Z
[ "python", "lxml" ]
Parsing xml with same tags and different attributes
37,812,489
<p>I have a network file created from osm using Netconvert. The root element is edge with different attributes. For example, in the first part of the file, the edges are organized as follows.</p> <pre><code>&lt;edge id=":367367171_1" function="internal"&gt; &lt;lane id=":367367171_1_0" index="0" disallow="tram rai...
0
2016-06-14T12:47:11Z
37,821,878
<p>You have tagged this lxml so there are much simpler ways to <em>to selectively iterate through the edges in which the attribute 'from' is present</em> , you can use the following xpath to find all the edges that have the <em>from</em> attribute:</p> <pre><code>for e in root.xpath("//edge[@from]") </code></pre> <p>...
1
2016-06-14T20:53:00Z
[ "python", "lxml" ]
Django - forms vs model form, editing a model.textField, and getting the pk of an object?
37,812,517
<h1>models.py</h1> <pre><code>from django.db import models from django import forms class History(models.Model): commentTypes = ( ('1', 'issues'), ('2', 'risks'), ('3', 'dependencies'), ('4', 'accomplishments'), ('6', 'UGM') ) historyID = models.IntegerField() ...
1
2016-06-14T12:48:36Z
37,812,763
<p>Your question touches on a lot of different things, but I'll try to answer them.</p> <p>See the docs on <a href="https://docs.djangoproject.com/en/1.9/topics/forms/#rendering-fields-manually" rel="nofollow">rendering form fields manually</a>. If you don't want the label to be displayed, then leave it out.</p> <p>I...
1
2016-06-14T12:58:55Z
[ "python", "mysql", "django", "forms", "models" ]
Python String Checksum Calculator
37,812,524
<p>I managed to come up with a code to calculate the file checksum. Below is the code:</p> <pre><code>from Crypto.Hash import * def get_file_checksum(filename): h = SHA384.new() chunk_size = 8192 with open(filename, 'rb') as f: while True: chunk = f.read(chunk_size) if len(...
0
2016-06-14T12:48:55Z
37,812,711
<p>Strip out the white space in your file reading function like:</p> <pre><code>def get_file_checksum(filename): h = SHA384.new() chunk_size = 8192 with open(filename, 'rb') as f: while True: chunk = f.read(chunk_size).strip() if not chunk: break ...
0
2016-06-14T12:56:41Z
[ "python", "encryption", "hash" ]
Plotting an ellipsoid
37,812,525
<p>I have three numbers representing lengths. Each number is the length of an object on the x, y, and z axes. The object I want to represent is (probably) a deformed sphere.</p> <p>How can I 3D plot this object by specifying these 3 lengths ?</p> <p>I would like to go from this:</p> <p><a href="http://i.stack.imgur....
1
2016-06-14T12:48:57Z
37,812,662
<ol> <li>You should use different radii for the <code>x</code>, <code>y</code> and <code>z</code> coordinates</li> <li>to actually see the effect, use <code>ax.set_aspect(1.0)</code> otherwise the plot view will be scaled back, to a sphere</li> <li>(to have the ellipsoid not axis aligned/zero centered: use a rotation a...
3
2016-06-14T12:54:57Z
[ "python", "matplotlib" ]
Python outputting MySQL data returned from method
37,812,614
<p>This is a first of a kind problem for me, and really not sure how to troubleshoot it.</p> <p>I have a simple Python/MySQL project I'm working on for fun. I have a separate class, with it's own methods, to handle querying the database (using MySQLdb). </p> <p>The method which seems to be the culprit (<strong>Blog...
1
2016-06-14T12:53:02Z
37,813,381
<p>Try using pdb, the built-in python debugger. This will allow you to single-step through your program and figure out exactly where the output is occurring and why. Or if you prefer, there are other debuggers, such as pudb, that are visual or have other features. I think pdb should work fine for you though.</p> <p...
0
2016-06-14T13:24:01Z
[ "python", "mysql", "mysql-python" ]
Python outputting MySQL data returned from method
37,812,614
<p>This is a first of a kind problem for me, and really not sure how to troubleshoot it.</p> <p>I have a simple Python/MySQL project I'm working on for fun. I have a separate class, with it's own methods, to handle querying the database (using MySQLdb). </p> <p>The method which seems to be the culprit (<strong>Blog...
1
2016-06-14T12:53:02Z
37,823,990
<p>I think it's outputting the query results because you're using the <code>fetchall</code> call. This will make the query actually execute and return the results. I'd remove the <code>fetchall</code> and just return the cursor (e.g. return self.cursor). Then when you want to output the data, use the <code>fetchall</co...
0
2016-06-14T23:52:37Z
[ "python", "mysql", "mysql-python" ]
Django query between startdate and duration
37,812,765
<p>Im working on a Django project and I have to make a query that returns all my record that are active at the moment. The query must be between(startdate, startdate + duration)</p> <p>I got this query so far, but I don't know how to query startdate + duration &lt; datetime.now()</p> <p>View:</p> <pre><code>def hom...
0
2016-06-14T12:58:58Z
37,813,142
<p>Your code has several defects. First, it's not clear for us what unit does <code>duration</code> have, days, months, years, minutes? </p> <p>I assume you were using days, but you couldn't query that because you need to convert <code>start_time + duration</code> to datetime and treat it as end time for each record, ...
1
2016-06-14T13:14:55Z
[ "python", "django", "sqlite3" ]
Encode error scraping
37,812,900
<p>Scraping site with chineese simbols . How do i scrap chineese simbolse ??</p> <pre><code>from urllib.request import urlopen from urllib.parse import urljoin from lxml.html import fromstring URL = 'http://list.suning.com/0-258003-0.html' ITEM_PATH = '.clearfix .product .border-out .border-in .wrap .res-info .sell-...
1
2016-06-14T13:04:15Z
37,815,022
<p>From the <code>print</code> syntax and the imports, I assume that you use a Python3 version, since it can matter for unicode.</p> <p>So, we can expect that <code>href</code>, <code>title</code> and <code>title2</code> are all unicode strings (or Python 3 strings). But the print function will try to convert the stri...
0
2016-06-14T14:34:15Z
[ "python", "utf-8" ]
Python Basic Math Algorithm Function
37,813,019
<p>I am attempting to understand exactly how this function works, I have been playing around with it but I am unsure.</p> <ul> <li><p>What I know: anything with a remainder of 1 (odd number) will return 0</p></li> <li><p>What I am confused about: When I calculate it I got <code>2</code> which would result in but isn't...
1
2016-06-14T13:09:14Z
37,813,066
<p>nope that's not true since <code>anon(36/2)</code> will itself call <code>anon</code> <a href="https://en.wikipedia.org/wiki/Recursion#In_computer_science" rel="nofollow">recursively</a> and NOT just return <code>19</code></p>
2
2016-06-14T13:11:42Z
[ "python", "math" ]
Python Basic Math Algorithm Function
37,813,019
<p>I am attempting to understand exactly how this function works, I have been playing around with it but I am unsure.</p> <ul> <li><p>What I know: anything with a remainder of 1 (odd number) will return 0</p></li> <li><p>What I am confused about: When I calculate it I got <code>2</code> which would result in but isn't...
1
2016-06-14T13:09:14Z
37,813,098
<p>The function tells you, how often you can divide a number by two, as it calls itself recursively with the half of the original in input (if the input is even). It effectively counts who often it calls itself until returning <code>0</code>, by adding <code>1</code> to its return value with each recursive call.</p>
1
2016-06-14T13:12:59Z
[ "python", "math" ]
Python Basic Math Algorithm Function
37,813,019
<p>I am attempting to understand exactly how this function works, I have been playing around with it but I am unsure.</p> <ul> <li><p>What I know: anything with a remainder of 1 (odd number) will return 0</p></li> <li><p>What I am confused about: When I calculate it I got <code>2</code> which would result in but isn't...
1
2016-06-14T13:09:14Z
37,813,114
<p>Let's see what happens with anon(36):</p> <p>36 % 2 is not == to 1, so it returns 1 + anon(18).</p> <p>18 % 2 is not == to 1, so it returns 1 + anon(9).</p> <p>9 % 2 is == 1, so it returns 0.</p> <p>Add up all the returns to get: 1 + 1 + 0 = 2. I suggest looking into how recursion works with stack diagrams! Not...
3
2016-06-14T13:13:38Z
[ "python", "math" ]
Python Basic Math Algorithm Function
37,813,019
<p>I am attempting to understand exactly how this function works, I have been playing around with it but I am unsure.</p> <ul> <li><p>What I know: anything with a remainder of 1 (odd number) will return 0</p></li> <li><p>What I am confused about: When I calculate it I got <code>2</code> which would result in but isn't...
1
2016-06-14T13:09:14Z
37,813,171
<p>If you trace the function calls, this is what you are getting:</p> <pre><code>anon(36) # First call, even number = 1 1 + anon(36//2 = 18) # Even number = 1 1 + 1 + anon(18//2 = 9) # Odd number = 0 1 + 1 + 0 = 2 # Returned value </code></pre> <p>Hence, the return value is 2.</p>
1
2016-06-14T13:15:47Z
[ "python", "math" ]
I am getting peak frequency from wav file. But for recorded 2 channels wav it is not working
37,813,059
<p>I am getting the peak frequency from wav files</p> <p>My code for getting the peak frequency from a wav file is:</p> <pre><code>import wave import struct import numpy as np import wave import contextlib if __name__ == '__main__': fname = "test.wav" frate = 0 data_size = 0 with contextlib.closing(w...
3
2016-06-14T13:11:12Z
37,817,536
<p>Why so complicated? Consider the following</p> <pre><code>#!/usr/bin/env python3 import numpy as np from numpy import fft import scipy.io.wavfile as wf import matplotlib.pyplot as plt sr = 44100 # sample rate len_sig = 2 # length of resulting signal in seconds f = 1000 # frequency in Hz # set you time ...
1
2016-06-14T16:31:05Z
[ "python", "numpy", "audio", "fft" ]
I am getting peak frequency from wav file. But for recorded 2 channels wav it is not working
37,813,059
<p>I am getting the peak frequency from wav files</p> <p>My code for getting the peak frequency from a wav file is:</p> <pre><code>import wave import struct import numpy as np import wave import contextlib if __name__ == '__main__': fname = "test.wav" frate = 0 data_size = 0 with contextlib.closing(w...
3
2016-06-14T13:11:12Z
37,855,872
<p>I think this will help you on the way. Just added few more stuff to work with the way you looking. Used MaxPowers logic. You need to convert the 24 bit data to 32 bit and then this will work for 24 bit too.</p> <pre><code>import sys import wave import struct import numpy as np import wave import argparse def parse...
0
2016-06-16T09:57:52Z
[ "python", "numpy", "audio", "fft" ]
Replace words starting with a backslash in Python
37,813,152
<p>I need to remove words starting with a backslash from a string. I have tried the following (and slight variations) but the words are not removed.</p> <pre><code>test = "(students \u2019 education, 1, 3) || (DCUCampaign 8, 2, 2) || (Projects Stories, 1, 2) || (DCU, 14, 1) || (\u201c DCU graduate \u201d, 1, 4)" </cod...
1
2016-06-14T13:15:14Z
37,813,405
<p>You should use:</p> <pre><code>re.sub(r"\\\w+", "", str(test)) </code></pre> <p>You don't need word boundary <code>\b</code>, just a backslash and word characters. A word boundary <code>\b</code> is a virtual character between non-word characters and a word characters, because example of non-word characters: space...
0
2016-06-14T13:24:38Z
[ "python", "regex", "backslash" ]
Replace words starting with a backslash in Python
37,813,152
<p>I need to remove words starting with a backslash from a string. I have tried the following (and slight variations) but the words are not removed.</p> <pre><code>test = "(students \u2019 education, 1, 3) || (DCUCampaign 8, 2, 2) || (Projects Stories, 1, 2) || (DCU, 14, 1) || (\u201c DCU graduate \u201d, 1, 4)" </cod...
1
2016-06-14T13:15:14Z
37,813,627
<p>As more people have pointed out in the comments is that <code>\u2019</code> is actually an unicode escape sequence, which will be expanded to <code>’</code>. This feature is only in Python 3+, You can replace that with: <code>r'\u2019'</code>. Or in Python 2 with <code>u'\u2019'</code>.</p> <p>But you will soon n...
0
2016-06-14T13:33:59Z
[ "python", "regex", "backslash" ]
Replace words starting with a backslash in Python
37,813,152
<p>I need to remove words starting with a backslash from a string. I have tried the following (and slight variations) but the words are not removed.</p> <pre><code>test = "(students \u2019 education, 1, 3) || (DCUCampaign 8, 2, 2) || (Projects Stories, 1, 2) || (DCU, 14, 1) || (\u201c DCU graduate \u201d, 1, 4)" </cod...
1
2016-06-14T13:15:14Z
37,813,637
<p>The <code>\u2019</code> is actually not <code>\u2019</code> but rather the <a href="http://unicode-table.com/en/2019/" rel="nofollow"><code>Right Single Quotation Mark</code></a>: &#8217;</p> <p>It is encoded in <a href="https://en.wikipedia.org/wiki/Unicode" rel="nofollow"><code>unicode</code></a> and is just one ...
0
2016-06-14T13:34:41Z
[ "python", "regex", "backslash" ]
Replace words starting with a backslash in Python
37,813,152
<p>I need to remove words starting with a backslash from a string. I have tried the following (and slight variations) but the words are not removed.</p> <pre><code>test = "(students \u2019 education, 1, 3) || (DCUCampaign 8, 2, 2) || (Projects Stories, 1, 2) || (DCU, 14, 1) || (\u201c DCU graduate \u201d, 1, 4)" </cod...
1
2016-06-14T13:15:14Z
37,813,975
<p>Since the <code>\</code> is a non-word character, to prevent matching <code>\word</code> in <code>text\word</code>, you need to use a <code>\B</code> - <em>a non-word boundary</em> that matches at the places where <code>\b</code> does not match.</p> <p>In short: <code>\B</code> matches at the start of the string be...
1
2016-06-14T13:49:34Z
[ "python", "regex", "backslash" ]
Problems with tkinter textbox output into a .txt file
37,813,169
<p>I'm trying to create a program that opens a tkinter window with 4 entries. When I press a button, it's supposed to write everything from the entries into a .txt file from top to bottom. I've managed to make it work like I wanted to, but my only problem is that it only writes the last line into the created .txt file ...
0
2016-06-14T13:15:44Z
37,813,659
<p>The issue you have is that you are opening the file at each iteration of the loop and the info is being overwritten.</p> <p>You have two options:</p> <ul> <li><p>Use <code>with</code> to open the file in <code>fetch</code> which closes the file on exit of block:</p> <pre><code>def fetch(entries): with open("t...
1
2016-06-14T13:35:51Z
[ "python", "tkinter", "python-3.5" ]
APLpy/matplotlib: Coordinate grid alpha levels for EPS quality figure
37,813,267
<p>In the normal matplotlib axes class, it is possible to set gridlines to have a certain transparency (alpha level). I'm attempting to utilise this with the APLpy package using the following:</p> <pre><code>fig = pyplot.figure(figsize=(18,8)) gridspec_layout = gridspec.GridSpec(1,2) gridspec_layout1 = gridspec.Grid...
0
2016-06-14T13:19:11Z
37,813,689
<p>In the save function, there is an optional argument, transparent. transparent is set to False by default. If you set it to True, the transparency should be preserved when you save.</p> <p>So it should be something like:</p> <pre><code>M33.save(filename, transparent=True, ..) </code></pre> <p>ETA: In the comment...
1
2016-06-14T13:36:56Z
[ "python", "matplotlib", "astropy", "aplpy" ]
Create multiple plugin in a single placeholder in django cms when using default plugins
37,813,324
<p>How can I create multiple plugin in a single placeholder in django cms if I am using default plugins which django cms provide?</p>
-1
2016-06-14T13:21:25Z
37,832,435
<p>As you may have seen from the <a href="http://docs.django-cms.org/en/release-3.3.x/reference/configuration.html#cms-placeholder-conf" rel="nofollow">docs</a>, you can configure the plugins for a placeholder, but if you don't, then you can add any plugin you want without restriction.</p> <p>So for example, you could...
0
2016-06-15T10:12:13Z
[ "python", "django-cms" ]
Replace if the first two letters are repeating in python
37,813,374
<p>How to replace if the first two letters in a word repeats with the same letter?</p> <p>For instance,</p> <pre><code> string = 'hhappy' </code></pre> <p>And I want to get</p> <pre><code>happy </code></pre> <p>I tried with </p> <pre><code>re.sub(r'(.)\1+', r'\1', string) </code></pre> <p>But, this gives</p> <p...
1
2016-06-14T13:23:46Z
37,813,448
<p>You need to add a <a href="https://docs.python.org/2/library/re.html#regular-expression-syntax" rel="nofollow">caret (<code>^</code>)</a> to match only the start of the line. </p> <pre><code>re.sub(r'^(.)\1+', r'\1', string) </code></pre> <p>Example:</p> <pre><code>import re string = 'hhappy' print re.sub(r'^(.)\...
5
2016-06-14T13:26:19Z
[ "python", "regex" ]
Replace if the first two letters are repeating in python
37,813,374
<p>How to replace if the first two letters in a word repeats with the same letter?</p> <p>For instance,</p> <pre><code> string = 'hhappy' </code></pre> <p>And I want to get</p> <pre><code>happy </code></pre> <p>I tried with </p> <pre><code>re.sub(r'(.)\1+', r'\1', string) </code></pre> <p>But, this gives</p> <p...
1
2016-06-14T13:23:46Z
37,813,453
<p>The regex would be</p> <pre><code>\b(\w)\1+ </code></pre> <p><code>\b</code> checks for a word boundary.</p> <p><a href="https://regex101.com/r/bX3xR8/1" rel="nofollow">Check it out here at regex101</a>.</p>
1
2016-06-14T13:26:29Z
[ "python", "regex" ]
Replace if the first two letters are repeating in python
37,813,374
<p>How to replace if the first two letters in a word repeats with the same letter?</p> <p>For instance,</p> <pre><code> string = 'hhappy' </code></pre> <p>And I want to get</p> <pre><code>happy </code></pre> <p>I tried with </p> <pre><code>re.sub(r'(.)\1+', r'\1', string) </code></pre> <p>But, this gives</p> <p...
1
2016-06-14T13:23:46Z
37,813,559
<p>Or you could simply slice:</p> <pre><code>string = 'hhappy' func = lambda s: s[1:] if s[0] == s[1] else s new_string = func(string) # happy </code></pre>
1
2016-06-14T13:31:09Z
[ "python", "regex" ]
txt insert to sql server using python
37,813,407
<p>I have a txt file. Each line has 4 numbers separated with a space. (line example, <code>1243814474 832 23.5380533333333 37.88067</code>). I want to insert every number of every line in a 4-column table in sql server respectively (1243814474 in column 1, 832 in column 2 etc.). The code I give to you inserts only the ...
2
2016-06-14T13:24:42Z
37,813,886
<p>When you write : </p> <pre><code>for line in infile: </code></pre> <p><code>line</code> is a string, not a list. <code>line[0]</code> will return the first character of that string</p> <p>you can use the <code>split(" ")</code> function to turn a string in a list of strings by splitting it on spaces</p> <p>Also,...
2
2016-06-14T13:45:48Z
[ "python", "sql-server", "python-2.7", "text" ]
txt insert to sql server using python
37,813,407
<p>I have a txt file. Each line has 4 numbers separated with a space. (line example, <code>1243814474 832 23.5380533333333 37.88067</code>). I want to insert every number of every line in a 4-column table in sql server respectively (1243814474 in column 1, 832 in column 2 etc.). The code I give to you inserts only the ...
2
2016-06-14T13:24:42Z
37,895,955
<p>thank you! i removed the <code>" "</code> from <code>line.plit(" ")</code> and it worked properly!</p>
0
2016-06-18T10:29:27Z
[ "python", "sql-server", "python-2.7", "text" ]
How can I add group by with ascending and decs values in odoo?
37,813,449
<p>I have two fields one is date and one more is function field with integer values so I wanted to add group by function field in ascending or descending order?</p> <pre><code>&lt;search string="Feedback"&gt; &lt;group expand="0" string="Group By"&gt; &lt;filter string="Task Name" icon="terp-personal" do...
0
2016-06-14T13:26:19Z
37,835,894
<pre><code> &lt;field name="context"&gt;{'order':'date_of asc'}&lt;/field&gt; </code></pre> <p>Solved my problem </p>
0
2016-06-15T12:45:51Z
[ "python", "xml", "openerp" ]
Interprocess communcation between docker and host system
37,813,451
<p>I have a python program that does some machine learning. This is supposed to be accessible over network using HTTP. Since I want Apache to act as a server,I use a python script to send the data which is received to my program using python <code>multiprocessing.connection</code>.</p> <p>For eg script to send will b...
0
2016-06-14T13:26:25Z
37,813,917
<p>As part of the Processing library you will find the process Queue. This structure exists to allow messages to be passed between processes. If you are working on Linux it is a matter of setting up a global variable and pushing messages. The pattern is usually: any process can post, and a single process reads. With tw...
0
2016-06-14T13:46:45Z
[ "python", "apache", "multiprocessing" ]
Django Rest Framework - how to pass kwargs to model.save()?
37,813,554
<p>I have overridden the .save() method of one of my models to use an extra argument. My question is: how I can pass this argument through the serializer.save(). My code below:</p> <pre><code>class DeliveryCreate(generics.CreateAPIView): queryset = Delivery.objects.none() serializer_class = DeliverySerializer ...
0
2016-06-14T13:30:56Z
37,823,755
<p>According to the <a href="http://www.django-rest-framework.org/api-guide/serializers/#passing-additional-attributes-to-save" rel="nofollow">docs</a> <code>serializer.save(owner=self.request.user)</code> should be enough. The keyword arguments will be included in the validated_data argument when <code>.create()</code...
0
2016-06-14T23:26:29Z
[ "python", "django", "django-rest-framework" ]
How do I use AJAX to communicate with and run code on a server?
37,813,602
<p>I've been learning to use AJAX with the GET request that allows me to access a PHP script with an array of data on a server. I want to be able to send a request that tells the server to run code that will open an application and manipulate some info on this application.</p> <p>Here is the code I use to firstly comm...
0
2016-06-14T13:32:53Z
37,814,517
<p>As soon as you call the PHP file, this begins running code on the server. If you want to run an external application from PHP, take a look at the exec() function:</p> <p><a href="http://php.net/manual/en/function.exec.php" rel="nofollow">http://php.net/manual/en/function.exec.php</a></p>
1
2016-06-14T14:12:39Z
[ "javascript", "php", "jquery", "python", "ajax" ]
How do I use AJAX to communicate with and run code on a server?
37,813,602
<p>I've been learning to use AJAX with the GET request that allows me to access a PHP script with an array of data on a server. I want to be able to send a request that tells the server to run code that will open an application and manipulate some info on this application.</p> <p>Here is the code I use to firstly comm...
0
2016-06-14T13:32:53Z
37,846,846
<p>You have jQuery listed in your question tags. Have you compared the javascript and jQuery code?</p> <p>The advantages of using jQuery are:</p> <blockquote> <ul> <li>less typing,</li> <li>simpler structure</li> <li>automatically cross-browser</li> <li>easily use Promises interface</li> </ul> </blockquot...
0
2016-06-15T22:27:01Z
[ "javascript", "php", "jquery", "python", "ajax" ]
python new line (byte to string)
37,813,652
<p>Code:</p> <pre><code>word="hello\nhai" fout=open("sample.txt","w"); fout.write(word); </code></pre> <p>Output:</p> <pre><code>hello hai </code></pre> <p>But this:</p> <pre><code>word=b"hello\nhai" str_word=str(word) # stripping ' '(quotes) from byte str_word=str_word[2:len(str_word)-1] # a...
-4
2016-06-14T13:35:25Z
37,813,802
<p>Write the bytes in binary mode:</p> <pre><code>word=b"hello\nhai" with open("sample.txt","wb") as fout: fout.write(word); </code></pre> <p>You can also encode the original string to bytes:</p> <pre><code>word="hello\nhai".encode() </code></pre>
1
2016-06-14T13:41:53Z
[ "python" ]
NoReverseMatch while regex tester passes
37,813,795
<p>I'm trying to visit the following url in a browser: <code>http://localhost:8000/hourregistration/reminder/2016WK24/</code></p> <p>and I'm pulling my hair out trying to understand why it's failing with:</p> <pre><code>NoReverseMatch at /hourregistration/reminder/2016WK24/ Reverse for 'mailreminder' with arguments ...
2
2016-06-14T13:41:36Z
37,922,408
<p>Found the issue. I was passing <code>wknr</code> in my Context (in the view) instead of 'yearwknr'</p> <pre><code> context = {'slackers':slackers, 'yearwknr': wknr} </code></pre> <p>now</p> <pre><code> context = {'slackers':slackers, 'yearwknr': yearwknr} </code></pre> <p>No...
0
2016-06-20T12:17:22Z
[ "python", "django", "python-3.x" ]
Python: Set the maximum of a function and loop around to find the maximum of the next value in an array
37,813,813
<p>I am trying to find the maximum of function when I give it a range of values and then put that same value into an array for later use. In this case I have 2 parameters, one being the x and the other the theta. My issue is that it isn't looping around to the next x value in the list. Is there a way to make it loop ar...
1
2016-06-14T13:42:18Z
37,814,012
<p>The structure of your code is not correct, that is why you don't get any result. First, you define functions within for loops. This does not yield an error, but what you actually want to do is define the function earlier and then call it in the for loop, as such:</p> <pre><code>def myfunction(x): return x+ 3 for...
1
2016-06-14T13:51:36Z
[ "python", "arrays", "function", "loops" ]
Python: Set the maximum of a function and loop around to find the maximum of the next value in an array
37,813,813
<p>I am trying to find the maximum of function when I give it a range of values and then put that same value into an array for later use. In this case I have 2 parameters, one being the x and the other the theta. My issue is that it isn't looping around to the next x value in the list. Is there a way to make it loop ar...
1
2016-06-14T13:42:18Z
37,814,132
<p>This is the elaboration you asked for above:</p> <p>Your code:</p> <pre><code>def E(x): i = [] #creates an empty list for z in x: def kl(x): return (2*np.pi/lmda)*x*lmda/2 def U(theta): u = (np.cos(kl(z)*np.cos(theta))-np.cos(kl(z)))/np.sin(theta) return u theta = np.linspa...
0
2016-06-14T13:57:11Z
[ "python", "arrays", "function", "loops" ]
Cross-platform MIDI player for Python
37,813,857
<p>Is there any MIDI library for Python that works cross-platform, at least in Windows and the latest Mac OS? I've been using PyGame, but it doesn't work with the latest Mac OS anymore.</p> <p>Any help would be appreciated, thanks a lot!</p>
0
2016-06-14T13:44:23Z
37,814,354
<p>I think <a href="https://pypi.python.org/pypi/python-rtmidi" rel="nofollow"><code>rtmidi</code></a> may serve your purpose, they are Python bindings to the C++ RtMidi, which is a cross-platform API for realtime MIDI in/out.</p>
0
2016-06-14T14:06:46Z
[ "python", "midi" ]
Future-proof Python GUI + file drag-and-drop + executable
37,813,869
<p>I have a Python 2.7/Tkinter program that uses <em>TkinterDnD2</em> and <em>TkDnD</em> (not part of the standard Python distribution) to provide file drag-and-drop in a Win7/Win10 environment. I have been using <em>PyInstaller</em> to create a single-file executable for ease of distribution within our organization. ...
1
2016-06-14T13:44:54Z
38,275,815
<p>I have successfully migrated my application to <strong>Python 3.4/PySide 1.2.4/Qt 4.8.7</strong> running in Windows 10, and I can successfully package it into a single-file .exe with <strong>PyInstaller 3.2</strong>.</p> <p>The packaging is much more straightforward than it was with Python 2.7 and Tkinter/TkinterDn...
0
2016-07-08T21:45:03Z
[ "python", "user-interface", "drag-and-drop", "pyinstaller" ]
How do iterate through tuple functions following a certain condition
37,813,888
<p>I would like to iterate through a tuple following certain conditions such as follows. I have defined a variable L = []. I have several functions imported into a tuple and I would like, that if this condition is met, while iterating through the tuple, the function that meets this condition will print out an answer. I...
-1
2016-06-14T13:45:50Z
37,814,556
<p>Ok, </p> <pre><code>def one(): L = 1*2 print '1 yea!' return L def two(): L = 1+2 print '2 yea!' return L def three(): L = 1/2 print ' 3 yea!' return L def four (): L = 1-2 print '4 yea!' return L refined = (one, two, three, four) def these(re...
0
2016-06-14T14:14:17Z
[ "python" ]
General Script to Concatenate Series of DataFrames
37,813,907
<p>I have a dictionary of over 1000 dataframes (df_dict) where some elements may be series:</p> <pre><code>Schedule_RCL_03312007 Schedule_RCL_03312008 Schedule_RCL_03312009 Schedule_RCL_03312010(1_of_2) Schedule_RCL_03312010(2_of_2) Schedule_RCL_03312011(1_of_2) Schedule_RCL_03312011(2_of_2) Schedule_RCL_063020...
0
2016-06-14T13:46:32Z
37,814,491
<p>You could use <code>itertools.groupby</code>:</p> <pre><code>from itertools import groupby from operator import itemgetter df_names = ['Schedule_RCL_03312007', 'Schedule_RCL_03312008', 'Schedule_RCL_03312009', 'Schedule_RCL_03312010(1_of_2)', 'Schedule_RCL_03312010(2_of_2)', 'Schedule_RCL_03312011(1_of_2)', 'Schedu...
2
2016-06-14T14:11:31Z
[ "python", "dictionary", "pandas", "dataframe", "concatenation" ]
Trying to sort three list of data so the sort order of each list is the same
37,813,987
<p>I have a program that has three list off data called proffit, macdHi and macdLow. The macdHi and macdLo are the parmeters put into a function to create the price vales so</p> <pre><code>price[x]=f(macdHi]x],macdLow[x]) </code></pre> <p>This list is very large and I would like to sort the lists so after I sort pri...
0
2016-06-14T13:50:23Z
37,814,214
<p>You might find <a href="http://pandas.pydata.org/" rel="nofollow">Pandas</a> offers a much easier/faster/cleaner solution to this. It has built in methods for sorting data based on various criteria and is optimized for large data sets.</p> <p>A good tutorial on this is available here: <a href="http://chrisalbon.com...
0
2016-06-14T14:00:39Z
[ "python" ]
Trying to sort three list of data so the sort order of each list is the same
37,813,987
<p>I have a program that has three list off data called proffit, macdHi and macdLow. The macdHi and macdLo are the parmeters put into a function to create the price vales so</p> <pre><code>price[x]=f(macdHi]x],macdLow[x]) </code></pre> <p>This list is very large and I would like to sort the lists so after I sort pri...
0
2016-06-14T13:50:23Z
37,814,606
<p>You can try this</p> <pre><code>AllLists = [macdHi,macdLow] #sort by MacdHi SortedByMacdHi = sorted(AllLists, key=lambda row: row[0]) for i in range(len(SortedByMacdHi)): price[i]=f(AllLists[0][i],AllLists[1][i]) #sort by MacdLow SortedByMacdLow = sorted(AllLists, key=lambda row: row[1]) for i in range(len(So...
0
2016-06-14T14:16:16Z
[ "python" ]
Numpy cannot store matrix larger than 1GB in memory
37,814,004
<p>I need to store large matrix of order <code>20000x20000</code>. When I try to initialize a matrix of that order Python raises memory error.</p> <pre><code>Traceback (most recent call last): File "C:\Users\harwee\Desktop\Bubble\test_folder\test.py", line 3, in &lt;module&gt; a = numpy.ones((x,x),dtype=int) ...
1
2016-06-14T13:51:14Z
37,814,116
<p>If you're using 32-bit Python you won't be able to allocate more than ~2GB, if you're doing other things in your code you may be exceeding that limit. Also, I think numpy requires memory allocation to be contiguous, which can be kind of hard for larger blocks.</p>
2
2016-06-14T13:56:25Z
[ "python", "numpy", "matrix" ]
Numpy cannot store matrix larger than 1GB in memory
37,814,004
<p>I need to store large matrix of order <code>20000x20000</code>. When I try to initialize a matrix of that order Python raises memory error.</p> <pre><code>Traceback (most recent call last): File "C:\Users\harwee\Desktop\Bubble\test_folder\test.py", line 3, in &lt;module&gt; a = numpy.ones((x,x),dtype=int) ...
1
2016-06-14T13:51:14Z
37,814,128
<p>This isn't really a limit enforced by Python but rather one of 32 bit processing. There is only so much space in a 32 bit address system. You can remove this restriction by moving to a 64 bit Python installation.</p>
1
2016-06-14T13:56:58Z
[ "python", "numpy", "matrix" ]
GSVD for python Generalized Singular Value Decomposition
37,814,024
<p>MATLAB has a gsvd function to perform the generalised SVD. Since 2013 I think there has been a lot of discussion on the <a href="https://github.com/numpy/numpy/issues/3475" rel="nofollow">github pages</a> regarding putting it in scipy and some pages have code that I can use such as <a href="https://github.com/aancha...
2
2016-06-14T13:52:01Z
37,879,536
<p>If you want to work from the LJWillams implementation on github, there are a couple of bugs. However, to understand the technique fully, I'd probably recommend having a go at implementing it yourself. I looked up what Octave (MATLAB free software equivalent) do and their <a href="http://octave.sourceforge.net/line...
4
2016-06-17T10:41:28Z
[ "python", "python-3.x", "numpy", "scipy" ]
Why does this Python class have different addresses?
37,814,111
<p>I made a simple class:</p> <pre><code>class Foo: pass </code></pre> <p>then I checked its address with <code>id</code>:</p> <pre><code>&gt;&gt;&gt; id(Foo) 4299236488 </code></pre> <p>As I was curious, I checked another way:</p> <pre><code>&gt;&gt;&gt; id(Foo()) 4332721208 </code></pre> <p>Why do they have...
0
2016-06-14T13:56:03Z
37,814,246
<p>You did not check it in another way.</p> <p>When you call <code>foo</code> you just ask where your class is located.</p> <p>When you called <code>foo()</code> you created an instance of you class. And then ask where your instance of your class is located. </p>
0
2016-06-14T14:02:09Z
[ "python", "python-3.x", "pointers" ]
Why does this Python class have different addresses?
37,814,111
<p>I made a simple class:</p> <pre><code>class Foo: pass </code></pre> <p>then I checked its address with <code>id</code>:</p> <pre><code>&gt;&gt;&gt; id(Foo) 4299236488 </code></pre> <p>As I was curious, I checked another way:</p> <pre><code>&gt;&gt;&gt; id(Foo()) 4332721208 </code></pre> <p>Why do they have...
0
2016-06-14T13:56:03Z
37,814,266
<p><code>Foo</code> is an object and <code>Foo()</code> is an instance of the object <code>Foo</code>.</p> <pre><code>&gt;&gt;&gt; type(Foo) &lt;type 'classobj'&gt; &gt;&gt;&gt; id(Foo) 140710195094936 &gt;&gt;&gt; type(Foo()) &lt;type 'instance'&gt; &gt;&gt;&gt; id(Foo()) 140710195200224 </code></pre>
1
2016-06-14T14:03:14Z
[ "python", "python-3.x", "pointers" ]
python __lt__ __gt__ custom (overloaded) operators
37,814,154
<p>Having experimented with Python, I've come to the code:</p> <pre><code>class Chainable(object): value = [] def __init__(self,*args): self.value = [] for a in args: if isinstance(a,list): self.value += a elif isinstance(a,tuple): self.va...
0
2016-06-14T13:58:21Z
37,816,103
<p>The resulting solution (thanks to <a href="http://stackoverflow.com/users/3001761/jonrsharpe">jonrsharpe</a>):</p> <pre><code>class Chainable(object): value = [] def __init__(self,*args): self.value = [] for a in args: if isinstance(a,list): self.value += a ...
0
2016-06-14T15:21:19Z
[ "python", "overloading", "operator-keyword" ]
Error when trying to build schema with Haystack and Solr
37,814,171
<p>I have been following a tutorial from 'Django by example' that introduces Solr and Haystack and run into a problem. I have made the necessary changes to INSTALLED_APPS in settings.py and also added the following:</p> <pre><code>HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.solr_back...
0
2016-06-14T13:58:59Z
37,814,453
<p>This problem usually occurs when first adding Haystack to your project.</p> <p>1.Are you using the haystack directory within your django-haystack checkout/install?</p> <p>2.Is the haystack directory on your PYTHONPATH? Alternatively, is haystack symlinked into your project?</p> <p>3.Start a Django shell (./manage...
1
2016-06-14T14:10:05Z
[ "python", "django", "solr" ]
Error when trying to build schema with Haystack and Solr
37,814,171
<p>I have been following a tutorial from 'Django by example' that introduces Solr and Haystack and run into a problem. I have made the necessary changes to INSTALLED_APPS in settings.py and also added the following:</p> <pre><code>HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.solr_back...
0
2016-06-14T13:58:59Z
38,156,188
<p>so I eventually found that it was just a typo error here</p> <p>'ENGINE': 'haystack.backends.solr_backends.SolrEngine',</p> <p>this should be 'solr_backend' not plural :|</p>
0
2016-07-02T03:24:20Z
[ "python", "django", "solr" ]
Python or batch file to open multiple vbs files (vbs files open a program+file)
37,814,362
<p>I have multiple VBS files (each opening a different file, same program) and I wanted to open them all without having to click on all of them. I can get them to open without an issue if I use the python script I created and execute with NPPExec from Notepad++. The way I want the files to open (using method previously...
0
2016-06-14T14:06:57Z
37,816,452
<p>From a DOS BATCH perspective, this should help you:</p> <pre><code>FOR %%G IN (file1.txt file2.txt file3.txt) DO start notepad.exe %%G </code></pre> <p>You can make the necessary modifications to handle VBS files.</p>
0
2016-06-14T15:37:23Z
[ "python", "batch-file", "vbscript", "multiple-instances", "nppexec" ]
Python or batch file to open multiple vbs files (vbs files open a program+file)
37,814,362
<p>I have multiple VBS files (each opening a different file, same program) and I wanted to open them all without having to click on all of them. I can get them to open without an issue if I use the python script I created and execute with NPPExec from Notepad++. The way I want the files to open (using method previously...
0
2016-06-14T14:06:57Z
37,817,647
<p><a href="https://msdn.microsoft.com/en-us/library/wzcddbek(v=vs.84).aspx" rel="nofollow">AppActivate Method</a> reference:</p> <blockquote> <p>Activates an application window.</p> <ul> <li>Syntax: <code>object.AppActivate title</code> </li> <li>Arguments: <ul> <li><em>object</em>: <code>WshShell</...
1
2016-06-14T16:36:49Z
[ "python", "batch-file", "vbscript", "multiple-instances", "nppexec" ]
convert Php to Python, base64 encoded
37,814,372
<p>i am a Python beginner and would convert a php script to python. It connects my LG SmartTV to my Raspi, but theres a problem with the connect function</p> <p>Original php code</p> <pre><code> function connect() { $ws_handshake_cmd = "GET " . $this-&gt;path . " HTTP/1.1\r\n"; $ws_handshake...
-2
2016-06-14T14:07:16Z
37,842,976
<p>to specify the problem , i think its just the line with the $expectedResonse = base64_encode(pack('H*', sha1($this->ws_key . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'))); i dont know this in python ... </p>
0
2016-06-15T18:20:36Z
[ "php", "python", "sockets", "base64", "smart-tv" ]
Creating a Dictionary to Write to a file
37,814,465
<p>I am trying to change the format in which a file is written. The file is written in a generic file format. I am putting headers into the file and writing it so that it can be read by another program in the future by simply using a pandas dictionary or an xarray datarray. In order to do this, I am trying to make colu...
0
2016-06-14T14:10:33Z
37,814,946
<pre><code>import json # Create some random data structure animals = zip(['dogs', 'cats', 'mice'], [124156, 858532, 812885]) data = {k:{v: {k: [v, v, v, k, v, {k: [k, k, k, k]}]}} for k, v in animals} # Create a new file, dump the data to it with open('filename.ext', 'w+') as file: json.dump(data, file, indent=4,...
1
2016-06-14T14:31:02Z
[ "python", "file", "dictionary" ]
AttributeError: 'bool' object has no attribute 'count'
37,814,550
<p>I am new to Python and I am writing this code below. </p> <pre><code>fileName = input("Enter the file name: ") InputFile = open(fileName, 'r') text=InputFile.readable() sentences = text.count('.') + text.count('?') + \ text.count(':') + text.count(';') + \ text.count('!') </code></pre> <p>...
0
2016-06-14T14:14:00Z
37,814,641
<p>There is a buggy line in your code:</p> <pre><code>text = InputFile.readable() </code></pre> <p>Which returns a <code>boolean</code> that has no attribute <code>count</code></p> <p>Should have been:</p> <pre><code>text = InputFile.read() </code></pre>
5
2016-06-14T14:17:32Z
[ "python" ]
Python setuptools: Bad Marshal data
37,814,654
<p>I am getting this bad marshal data error when I try to run setup.py install, on python2</p> <pre><code>running install running bdist_egg running egg_info writing requirements to epigrass.egg-info/requires.txt writing epigrass.egg-info/PKG-INFO writing top-level names to epigrass.egg-info/top_level.txt writing depen...
0
2016-06-14T14:18:19Z
37,818,040
<p>All it needed was a <code>zip_safe=False</code> argument added to the setup call.</p> <p>It now builds normally.</p>
1
2016-06-14T16:58:04Z
[ "python", "python-2.7", "setuptools" ]
Selenium tests fail for all URLs with seemingly random errors
37,814,657
<p>I'm using Ubuntu 16.04. I've set up Django 1.9.7 and selenium 2.53.5 in a virtual environment.</p> <p>I'm following Harry J.W. Percival's book "Test Driven Development with Python", and i'm currently on the first tutorial ("Using Selenium to Test User Interactions") for functional tests in chapter 4. The code goes ...
2
2016-06-14T14:18:26Z
37,816,310
<p>The simple answer is you'll either have to downgrade Firefox to 46 or install the Marionette Web Driver. I've had similar problems. </p> <p>Please see the top rated answer on the question below.</p> <p><a href="http://stackoverflow.com/questions/37761668/cant-open-browser-with-selenium-after-firefox-update">Can&#3...
3
2016-06-14T15:30:36Z
[ "python", "django", "selenium", "virtualenv", "virtualenvwrapper" ]
shlex: Escaping quotes in Python 3
37,814,808
<p>I want to split the ascii text</p> <pre><code>1 'K\^o, Suk\'e' </code></pre> <p>which is printed as the Python string</p> <pre><code>line = "1 'K\\^o, Suk\\'e'\n" </code></pre> <p>into </p> <pre><code>['1', 'K\\^o, Suk\\'e'] </code></pre> <p><code>shlex.split(line)</code> doesn't work, giving a <code>ValueErro...
2
2016-06-14T14:24:52Z
37,815,057
<p>It might be simpler to use a regex for the split. This one will split into the first token before any whitespace, followed by the rest of the string.</p> <pre><code>re.match('(\S+)\s+(.*)', line).groups() </code></pre>
0
2016-06-14T14:36:02Z
[ "python", "python-3.x", "shlex" ]
shlex: Escaping quotes in Python 3
37,814,808
<p>I want to split the ascii text</p> <pre><code>1 'K\^o, Suk\'e' </code></pre> <p>which is printed as the Python string</p> <pre><code>line = "1 'K\\^o, Suk\\'e'\n" </code></pre> <p>into </p> <pre><code>['1', 'K\\^o, Suk\\'e'] </code></pre> <p><code>shlex.split(line)</code> doesn't work, giving a <code>ValueErro...
2
2016-06-14T14:24:52Z
37,816,630
<p>You can use posix mode and <code>escapedquotes</code> to <code>'"</code> instead of just <code>"</code></p> <pre><code>&gt;&gt;&gt; line = "1 'K\\^o, Suk\\'e'\n" &gt;&gt;&gt; lexer = shlex.shlex(line, posix=True) &gt;&gt;&gt; lexer.escapedquotes = "'\"" &gt;&gt;&gt; list(lexer) ['1', "K\\^o, Suk'e"] </code></pre>
1
2016-06-14T15:46:30Z
[ "python", "python-3.x", "shlex" ]
Sqlalchemy: OperationalError with pycharm but not at command line
37,814,925
<p><a href="http://i.stack.imgur.com/UmZmh.png" rel="nofollow"><img src="http://i.stack.imgur.com/UmZmh.png" alt="enter image description here"></a>I'm working with scrapy and have had a functioning pipeline which uses sql-alchemy to insert records into a sqllite db. This was working but then I added 2 new fields: name...
0
2016-06-14T14:30:15Z
37,819,319
<p>I suspect you're running with two different working directories. Try configuring PyCharm with the working directory you're using on the command line. Alternatively, specify an absolute path for the SQLAlchemy URL.</p>
1
2016-06-14T18:14:20Z
[ "python", "sqlite", "sqlalchemy", "pycharm" ]
Django Postgresql Configuration ERROR : ImproperlyConfigured: settings.DATABASES
37,814,926
<p>A newbie to Django!!</p> <p>In the process of switching from sqlite3 to postgresql, I tried to follow the steps in the link.</p> <blockquote> <p><a href="http://www.marinamele.com/taskbuster-django-tutorial/install-and-configure-posgresql-for-django" rel="nofollow">http://www.marinamele.com/taskbuster-django-tut...
0
2016-06-14T14:30:17Z
37,819,037
<p>Answering instead of commenting due to rep.</p> <p>Your settings.py shows this: 'ENGINE': 'django.db.backends.postgresql_psycopg2' But your shell output shows: 'ENGINE': 'django.db.backends.dummy'</p> <p>Are you sure you have everything configured correctly?</p>
0
2016-06-14T17:58:46Z
[ "python", "django", "postgresql", "sqlite3" ]
Django Postgresql Configuration ERROR : ImproperlyConfigured: settings.DATABASES
37,814,926
<p>A newbie to Django!!</p> <p>In the process of switching from sqlite3 to postgresql, I tried to follow the steps in the link.</p> <blockquote> <p><a href="http://www.marinamele.com/taskbuster-django-tutorial/install-and-configure-posgresql-for-django" rel="nofollow">http://www.marinamele.com/taskbuster-django-tut...
0
2016-06-14T14:30:17Z
37,820,299
<p>There was a mistake in settings.DATABASES configurations</p> <p>settings.py (The database settings now)</p> <pre><code>DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'myproject', 'USER': 'myprojectuser', 'PASSWORD': 'password', ...
0
2016-06-14T19:11:38Z
[ "python", "django", "postgresql", "sqlite3" ]
Python automatically converting data types
37,814,937
<p>I have implemented a class <code>BasicForm</code>, containing also a method <code>__str__</code> to be able to print stuff. I also have a function <code>stringToBasicForm(string)</code> converting certain types of strings to BasicForm objects.</p> <p>Later in my program, I have an array <code>array</code> of allowe...
0
2016-06-14T14:30:42Z
37,815,635
<p>Regarding your stringToBasicForm function the return value must be None or a BasicForm instance ...</p> <p>Can you just check with type() ?</p> <pre><code>class BasicForm: def __init__(self, s): pass def __str__(self): return "PLOP" array = ['toto', 'tata', 'tutu'] print([type(elem) for elem in array]) ...
0
2016-06-14T15:00:30Z
[ "python", "python-2.7", "data-type-conversion" ]