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
Django, tutorial - error: No module named urls
39,640,718
<p>Hi I am following the tutorial to make first web app by Django(<a href="https://docs.djangoproject.com/en/1.10/intro/tutorial01/#write-your-first-view" rel="nofollow">link</a>) But I was given this error:</p> <pre><code> File "c:\Python27\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper fn(*a...
1
2016-09-22T13:39:58Z
39,716,488
<p>OMG I am doomed. The problem was with the file " urls.py". Notice the preceding space character. Thank you everyone for your help and please forgive me for this dumb mistake:)</p>
0
2016-09-27T05:17:33Z
[ "python", "django" ]
python built-in integer object
39,640,732
<p>I read an article that python retains some number objects for better performance. For example:</p> <pre><code>x = 3 y = 3 print(id(x)) print(id(y)) </code></pre> <p>gives out same values, which means that x and y are referencing to exactly same object. The article suggested that the retained number objects are app...
1
2016-09-22T13:40:26Z
39,640,855
<p>256 is a power of two and small enough that people would be using numbers to that range. </p> <p>-5 I am less sure about, perhaps as special values?</p> <p>Related: <a href="http://stackoverflow.com/questions/15171695/weird-integer-cache-inside-python">Weird Integer Cache inside Python</a></p> <p>Also a word of w...
1
2016-09-22T13:46:30Z
[ "python" ]
parsing a dictionary in a pandas dataframe cell into new row cells (new columns)
39,640,936
<p>I have a Pandas Dataframe that contains one column containing cells containing a dictionary of key:value pairs, like this:</p> <pre><code>{"name":"Test Thorton","company":"Test Group","address":"10850 Test #325\r\n","city":"Test City","state_province":"CA","postal_code":"95670","country":"USA","email_address":"test...
2
2016-09-22T13:49:55Z
39,641,107
<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>concat</code></a>:</p> <pre><code>df = pd.DataFrame({1:['a','h'],2:['b','h'], 5:[{6:'y', 7:'v'},{6:'u', 7:'t'}] }) print (df) 1 2 5 0 a b {6: 'y', 7: 'v'} 1 h h {6: ...
2
2016-09-22T13:56:24Z
[ "python", "pandas", "dictionary", "append", "multiple-columns" ]
parsing a dictionary in a pandas dataframe cell into new row cells (new columns)
39,640,936
<p>I have a Pandas Dataframe that contains one column containing cells containing a dictionary of key:value pairs, like this:</p> <pre><code>{"name":"Test Thorton","company":"Test Group","address":"10850 Test #325\r\n","city":"Test City","state_province":"CA","postal_code":"95670","country":"USA","email_address":"test...
2
2016-09-22T13:49:55Z
39,641,221
<p>consider <code>df</code></p> <pre><code>df = pd.DataFrame([ ['a', 'b', 'c', 'd', dict(F='y', G='v')], ['a', 'b', 'c', 'd', dict(F='y', G='v')], ], columns=list('ABCDE')) df </code></pre> <p><a href="http://i.stack.imgur.com/Zd89H.png" rel="nofollow"><img src="http://i.stack.imgur.com/Zd89H.png...
1
2016-09-22T14:01:04Z
[ "python", "pandas", "dictionary", "append", "multiple-columns" ]
Do I need different MIB with those OID?
39,640,966
<p>I got this legacy <code>powershell</code> script that retrieve information via SNMP, I'm trying to port it in Python using <code>snimpy</code>.</p> <pre><code>$PrintersIP = '10.100.7.47', '10.100.7.48' Function Get-SNMPInfo ([String[]]$Printers) { Begin { $SNMP = New-Object -ComObject olePrn.OleSNMP ...
2
2016-09-22T13:51:14Z
39,644,523
<p>If you use the load() method then scalars and row names from it will be made available as an instance attributes hence you're able to query for 'sysContact' etc, but as the 'sysDescr' and 'sysName' are not part of the IF-MIB you will not be able to get it.</p> <p>You will need to load in the relevant MIB such as SN...
1
2016-09-22T16:40:11Z
[ "python", "powershell", "snmp", "mib", "snimpy" ]
How to pass list of function and all its arguments to be executed in another function in python?
39,641,171
<p>I have a list of functions and its arguments like this:</p> <pre><code>(func1, *arg1), (func2, *arg2),... </code></pre> <p>I want to pass them into another function to execute them like this:</p> <pre><code>for func, arg* in (list of funcs, args): func(arg*) </code></pre> <p>How to do it in python? I have tri...
3
2016-09-22T13:59:02Z
39,641,355
<p>You can do like this, just use list of tuple where first is the function name, and rest are arguments. </p> <pre><code>def a(*args,**kwargs): print 1 list_f = [(a,1,2,3)] for f in list_f: f[0](f[1:]) </code></pre>
0
2016-09-22T14:07:01Z
[ "python" ]
How to pass list of function and all its arguments to be executed in another function in python?
39,641,171
<p>I have a list of functions and its arguments like this:</p> <pre><code>(func1, *arg1), (func2, *arg2),... </code></pre> <p>I want to pass them into another function to execute them like this:</p> <pre><code>for func, arg* in (list of funcs, args): func(arg*) </code></pre> <p>How to do it in python? I have tri...
3
2016-09-22T13:59:02Z
39,641,425
<p>You can use the <a href="https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists" rel="nofollow">*-operator to unpack the arguments out of the tuple</a>.</p> <p>For example, suppose the format of items in your invocation list is <code>(function,arg1,arg2,...)</code>. In other words, <code>item[...
3
2016-09-22T14:10:44Z
[ "python" ]
How to pass list of function and all its arguments to be executed in another function in python?
39,641,171
<p>I have a list of functions and its arguments like this:</p> <pre><code>(func1, *arg1), (func2, *arg2),... </code></pre> <p>I want to pass them into another function to execute them like this:</p> <pre><code>for func, arg* in (list of funcs, args): func(arg*) </code></pre> <p>How to do it in python? I have tri...
3
2016-09-22T13:59:02Z
39,641,684
<p>Assuming your function and arguments are separate in the tuple, </p> <pre><code>def squarer(*args): return map(lambda x: x*2, args) def subtracter(*args): return map(lambda x: x-1, args) funcAndArgs = [(squarer, [1,2,3,4]), (subtracter, [1,2,3,4])] for func, args in funcAndArgs: print func(*args) </c...
0
2016-09-22T14:21:58Z
[ "python" ]
How to find a given element in nested lists?
39,641,229
<p>This is my iterative solution:</p> <pre><code>def exists(key, arg): if not arg: return False else: for element in arg: if isinstance(element,list): for i in element: if i==key: return True elif element==key:...
2
2016-09-22T14:01:29Z
39,641,400
<p>The logic is to iterate each element in your list and check: </p> <ul> <li><em>if list:</em> call the function again with the sub-list.</li> <li><em>if equals the key:</em> return True</li> <li><em>else:</em> return False </li> </ul> <p>Below is sample code to find whether <code>key</code> exists or not in nested...
2
2016-09-22T14:09:29Z
[ "python", "recursion", "functional-programming" ]
How to find a given element in nested lists?
39,641,229
<p>This is my iterative solution:</p> <pre><code>def exists(key, arg): if not arg: return False else: for element in arg: if isinstance(element,list): for i in element: if i==key: return True elif element==key:...
2
2016-09-22T14:01:29Z
39,641,852
<p>You are close. You only have to check if arg[0] is a sublist and if make a new call. Next you are missing a loop to run through all items of the list. This should work.</p> <pre><code>def exists(key, arg): for item in arg: if isinstance(item, list): # Recursive call with sublist ...
2
2016-09-22T14:28:05Z
[ "python", "recursion", "functional-programming" ]
How to find a given element in nested lists?
39,641,229
<p>This is my iterative solution:</p> <pre><code>def exists(key, arg): if not arg: return False else: for element in arg: if isinstance(element,list): for i in element: if i==key: return True elif element==key:...
2
2016-09-22T14:01:29Z
39,641,904
<pre><code>def exists(k, l): if not isinstance(l, list): return False if k in l: return True return any(map(lambda sublist: exists(k, sublist), l)) </code></pre>
3
2016-09-22T14:30:17Z
[ "python", "recursion", "functional-programming" ]
How to find a given element in nested lists?
39,641,229
<p>This is my iterative solution:</p> <pre><code>def exists(key, arg): if not arg: return False else: for element in arg: if isinstance(element,list): for i in element: if i==key: return True elif element==key:...
2
2016-09-22T14:01:29Z
39,641,950
<p>If we consider these cases:</p> <ul> <li><code>my_list</code> is empty: the key isn't found</li> <li><code>my_list</code> is not a list: the key isn't found</li> <li><code>my_list</code> is a non-empty list (two cases): <ul> <li><code>my_list[0]</code> is the key: it was found</li> <li>otherwise, look for the key ...
2
2016-09-22T14:32:37Z
[ "python", "recursion", "functional-programming" ]
How to find a given element in nested lists?
39,641,229
<p>This is my iterative solution:</p> <pre><code>def exists(key, arg): if not arg: return False else: for element in arg: if isinstance(element,list): for i in element: if i==key: return True elif element==key:...
2
2016-09-22T14:01:29Z
39,648,238
<p>Thanks everyone for your help, here is the answer that I have figured out. While it does not look as elegant as most of the answers that were already provided, this answer is the only answer that my lab instructor will accept as it is a pure functional programming method meaning no side effects or for loops:</p> <p...
1
2016-09-22T20:23:09Z
[ "python", "recursion", "functional-programming" ]
Make an image contour black and white using open CV and Python
39,641,373
<p>I'm trying to paint part of an image as black and white using OpenCV2 and Python3. This is the code I'm trying:</p> <pre><code>(x, y, w, h) = cv2.boundingRect(c) cv2.rectangle(frame, (x,y), (x+w,y+h),0,0) sub_face = frame[y:y+h, x:x+w] # apply a gaussian blur on this new recangle image # sub_face = cv2.GaussianBlur...
1
2016-09-22T14:07:50Z
39,641,629
<p>You converted sub_face to a single channel image, but result_frame is a 3 channel image.</p> <p>In the last line you are trying to assign a single channel array to a 3 channel slice.</p> <p>You could do this:</p> <pre><code>result_frame[y:y+sub_face.shape[0], x:x+sub_face.shape[1], 0] = sub_face result_frame[y:y+...
0
2016-09-22T14:19:51Z
[ "python", "opencv", "image-processing" ]
Make an image contour black and white using open CV and Python
39,641,373
<p>I'm trying to paint part of an image as black and white using OpenCV2 and Python3. This is the code I'm trying:</p> <pre><code>(x, y, w, h) = cv2.boundingRect(c) cv2.rectangle(frame, (x,y), (x+w,y+h),0,0) sub_face = frame[y:y+h, x:x+w] # apply a gaussian blur on this new recangle image # sub_face = cv2.GaussianBlur...
1
2016-09-22T14:07:50Z
39,641,705
<p>You are trying to assign a single channel that results from your <code>cv2.cvtColor</code> call to three channels at once as <code>result_frame</code> is a RGB / three channel image. You are probably wanting to assign the single channel to all three channels. One way to do this cleanly is to exploit <a href="http:...
1
2016-09-22T14:22:40Z
[ "python", "opencv", "image-processing" ]
Is it faster to add a key to a dictionary or append a value to a list in Python?
39,641,413
<p>I have an application where I need to build a list or a dictionary and speed is important. Normally I would just declare a list of zeros of the appropriate length and assign values one at a time but I need to be able to check the length and have it still be meaningful.</p> <p>Would it be faster to add a key value p...
0
2016-09-22T14:10:13Z
39,641,691
<p>Best way is to use <code>time()</code> to check your execution time.</p> <p>In following example dict is slightly faster.</p> <pre><code>from time import time st_time = time() b = dict() for i in range(1, 10000000): b[i] = i print (time() - st_time) st_time = time() a = [] for i in range(1, 10000000): a...
0
2016-09-22T14:22:06Z
[ "python", "performance", "cpu-speed" ]
Py2app - Add "from x import y" to setup.py
39,641,419
<p>I am using py2app to create a standalone APP from a python script however I have run into a problem which I am hoping you could help with.</p> <p>The script relies heavily on tkinter, primarily the tkinter messagebox module, which is not imported with tkinter but rather has to be imported separately using:</p> <pr...
0
2016-09-22T14:10:22Z
39,658,000
<p>Found an answer after about a day of searching, basically the problem isn't with the tkinter messagebox module. The problem was with the requests module that was used to contact the API which then returned information to be displayed in the messagebox. That is why the messagebox wasnt showing, because no request to ...
0
2016-09-23T10:02:18Z
[ "python", "tkinter", "py2app" ]
open conditional python files but read data from one
39,641,430
<p>I want to open and read a file depending on a condition, read only if condition met true. I wrote the following scriptlet: </p> <pre><code>def bb(fname, species): if species in ('yeast', 'sc'): pm = open('file.txt', 'rU') for line in pm: line = line.split() with ope...
1
2016-09-22T14:10:57Z
39,641,541
<p>You can put the filename value in a variable</p> <pre><code>def bb(fname, species): if species in ('yeast', 'sc'): fname2 = 'file.txt' elif species in ('human', 'hs'): fname2 = 'file2.txt' else: raise ValueError("species received illegal value") with open(fname2, 'rU') as p...
1
2016-09-22T14:15:59Z
[ "python", "file", "if-statement" ]
open conditional python files but read data from one
39,641,430
<p>I want to open and read a file depending on a condition, read only if condition met true. I wrote the following scriptlet: </p> <pre><code>def bb(fname, species): if species in ('yeast', 'sc'): pm = open('file.txt', 'rU') for line in pm: line = line.split() with ope...
1
2016-09-22T14:10:57Z
39,641,561
<p>Since you seem to be doing the exact same thing regardless of the condition, you could just collapse everything? </p> <pre><code>def bb(fname, species): if species in ['yeast', 'sc', 'human', 'hs']: pm = open('file.txt', 'rU') for line in pm: line = line.split() wit...
0
2016-09-22T14:16:49Z
[ "python", "file", "if-statement" ]
open conditional python files but read data from one
39,641,430
<p>I want to open and read a file depending on a condition, read only if condition met true. I wrote the following scriptlet: </p> <pre><code>def bb(fname, species): if species in ('yeast', 'sc'): pm = open('file.txt', 'rU') for line in pm: line = line.split() with ope...
1
2016-09-22T14:10:57Z
39,641,740
<p>Just put opening of file in <code>if else</code> case rest will be done in a similar manner and same code block as well.</p> <pre><code>def bb(fname, species): if species in ('yeast', 'sc'): pm = open('file.txt', 'rU') elif species in ('human', 'hs'): pm = open('file2.txt', 'rU')...
0
2016-09-22T14:24:00Z
[ "python", "file", "if-statement" ]
How do I run two processes in Procfile?
39,641,568
<p>I have a Flask app where I have embedded a Bokeh server graph and I am not being able to have them both working on Heroku. I am trying to deploy on Heorku and I can either start the Bokeh app or the Flask app from the Procfile, but not both at the same time. Consequently, either the content served with Flask will sh...
3
2016-09-22T14:17:00Z
39,689,556
<p>Each Heroku dyno gets allocated a single public network port, which you can get from the <code>$PORT</code> variable, pre-assigned by Heroku before launching your app. The unfortunate side effect of this is that you can have only one public web server running in a dyno.</p> <p>I think the first thing that you need ...
4
2016-09-25T17:08:03Z
[ "python", "heroku", "flask", "bokeh", "procfile" ]
saving a numpy array as a io.BytesIO with jpg format
39,641,596
<h3>I am using xlsxwriter to insert image into excel in python code.</h3> <p>Now, I had image data(numpy array) after opencv process. I would like insert this image data to excel. But xlswriter only support io.BytesIO stream.</p> <p>question: I don't know how to convert numpy array to <a href="https://docs.python.org...
1
2016-09-22T14:18:07Z
39,674,461
<p>finally , I find out a solution. we can use <code>cv2.imencode</code> function to convert numpy array to a jpg format.</p> <p>let's close this question. </p>
1
2016-09-24T08:54:24Z
[ "python", "excel", "opencv", "numpy" ]
pexpect: How to interact() over file object using newer version of pexpect library
39,641,627
<p><code>pexpect</code> has gone through big changes since the version provided by Ubuntu 15.04 (3.2). When installing newest version of <code>pexpect</code> using <code>pip3</code>, this minimal program that previously successfully gave terminal emulation over serial console does not work any more:</p> <pre><code>#!...
0
2016-09-22T14:19:49Z
39,651,840
<p>Browsing the <a href="https://github.com/pexpect/pexpect" rel="nofollow">pexpect</a> <a href="https://github.com/pexpect/pexpect/issues" rel="nofollow">issues</a>, found <a href="https://github.com/pexpect/pexpect/issues/351" rel="nofollow">#351</a>, <a href="https://github.com/pexpect/pexpect/issues/356" rel="nofol...
0
2016-09-23T02:53:33Z
[ "python", "serial-port", "pexpect" ]
How do I extract attributes from xml tags using Beautiful Soup?
39,641,630
<p>I am trying to use Beautiful Soup in Django to extract xml tags. This is a sample of the tags that I'm using:</p> <pre><code>&lt;item&gt; &lt;title&gt; Title goes here &lt;/title&gt; &lt;link&gt; Link1 goes here &lt;/link&gt; &lt;description&gt; Description goes here &lt;/description&gt; &lt;media:thumbnail url="Im...
1
2016-09-22T14:19:54Z
39,642,459
<p>The issue is because not every item has a <em>media:thumbnail</em> so you need to check first:</p> <pre><code>In [60]: import requests In [61]: from bs4 import BeautifulSoup In [62]: soup = BeautifulSoup(requests.get("https://rss.sciencedaily.com/computers_math/computer_programming.xml").content, "xml") In [63...
1
2016-09-22T14:57:12Z
[ "python", "xml", "attributes", "beautifulsoup" ]
Parallelism inside of a function?
39,641,708
<p>I have a function that counts how often a list of items appears in <code>rows</code> below:</p> <pre><code>def count(pair_list): return float(sum([1 for row in rows if all(item in row.split() for item in pair_list)])) if __name__ == "__main__": pairs = [['apple', 'banana'], ['cookie', 'popsicle'], ['candy'...
2
2016-09-22T14:22:46Z
39,645,308
<p>1) The overall complexity of calculations is enormous, and it comes from different sources:</p> <p>a) You split row on low level of calculation, so python has to create new row split for every iteration. To avoid this, you can pre-calculate rows. Something like this will do the job (with minor changes in "count" fu...
1
2016-09-22T17:27:34Z
[ "python", "multithreading", "list", "parallel-processing" ]
Upload CSV file in django admin list view, replacing add object button
39,641,756
<p>I want to replace the add object button in the listview of an admin page. The underlying idea is that an administrator can download data on all models in the db, use a tool to edit the data, and then reupload as a CSV file. </p> <p>In the list view I am struggling to override the form, as setting </p> <pre><code>c...
0
2016-09-22T14:24:39Z
39,641,821
<p>to your class SomeModelForm add something like this:</p> <pre><code>class Meta: model = YourModel fields = '__all__' </code></pre> <p>and change from forms.Form to forms.ModelForm</p>
0
2016-09-22T14:27:01Z
[ "python", "django", "file-upload", "admin" ]
Upload CSV file in django admin list view, replacing add object button
39,641,756
<p>I want to replace the add object button in the listview of an admin page. The underlying idea is that an administrator can download data on all models in the db, use a tool to edit the data, and then reupload as a CSV file. </p> <p>In the list view I am struggling to override the form, as setting </p> <pre><code>c...
0
2016-09-22T14:24:39Z
39,676,926
<p>OP here, solution is as follows:</p> <pre><code>class SomeModelForm(forms.Form): csv_file = forms.FileField(required=False, label="please select a file") class SomeModel(admin.ModelAdmin): change_list_template = 'admin/my_app/somemodel/change_list.html def get_urls(self): urls = super().get_urls(...
0
2016-09-24T13:35:17Z
[ "python", "django", "file-upload", "admin" ]
can't define a udf inside pyspark project
39,641,770
<p>I have a python project that uses pyspark and i am trying to define a udf function inside the spark project (not in my python project) specifically in spark\python\pyspark\ml\tuning.py but i get pickling problems. it can't load the udf. The code:</p> <pre><code>from pyspark.sql.functions import udf, log test_udf =...
-1
2016-09-22T14:25:10Z
39,646,290
<p>add the following to your code. It isn't recognizing the datatype.</p> <pre><code>from pyspark.sql.types import * </code></pre> <p>Let me know if this helps. Thanks.</p>
0
2016-09-22T18:23:38Z
[ "python", "pyspark", "udf", "apache-spark-ml" ]
can't define a udf inside pyspark project
39,641,770
<p>I have a python project that uses pyspark and i am trying to define a udf function inside the spark project (not in my python project) specifically in spark\python\pyspark\ml\tuning.py but i get pickling problems. it can't load the udf. The code:</p> <pre><code>from pyspark.sql.functions import udf, log test_udf =...
-1
2016-09-22T14:25:10Z
39,646,961
<p>Found it there was 2 problems</p> <p>1) for some reason it didn't like the returnType=FloatType() i needed to convert it to just FloatType() though this was the signature</p> <p>2) The data in column x was a vector and for some reason i had to cast it to float</p> <p>The working code:</p> <pre><code>from pyspark...
0
2016-09-22T19:01:19Z
[ "python", "pyspark", "udf", "apache-spark-ml" ]
Python REGEX ignore case at the beginning of the sentence and take the rest
39,641,833
<p>I have this kind of results:</p> <pre><code>ª!è[008:58:049]HTTP_CLI:0 - Line written in... </code></pre> <p>And I want to ignore all the beginning characters like <code>ª!è</code> and get only: <code>HTTP_CLI:0 - Line written in...</code> but in a simple regex line. </p> <p>I tried this: <code>^[\W0-9]*</code...
0
2016-09-22T14:27:24Z
39,642,129
<p>If you want to get everything after the closing square bracket, no matter what, and skip everything before that you can go with a <code>match</code> like this:</p> <pre><code>s = "ª!è[008:58:049]HTTP_CLI:0 - Line written in..." m = re.match(r'^.*?]([\S\s]*)', s) print(m.group(1)) </code></pre> <p>Print's <code>'...
2
2016-09-22T14:40:46Z
[ "python", "regex", "ignore-case" ]
VS2015 linker error with python extension
39,641,868
<p>I'm trying to build my own python (3.5.2) c extension that depends on zlib. With gcc on linux it works perfectly but I can't seem to make it work on windows 64-bit.</p> <p>I installed zlib dll according to the instructions:</p> <pre><code>Installing ZLIB1.DLL ==================== Copy ZLIB1.DLL to the SYSTEM or ...
0
2016-09-22T14:28:48Z
39,644,837
<p>I downloaded the static zlib lib from <a href="http://www.winimage.com/zLibDll/index.html" rel="nofollow">this website</a> and it works. It's for an older version so I'd still appreciate if I could get a more current version but for now it's enough.</p>
0
2016-09-22T16:58:06Z
[ "python", "c", "zlib" ]
Python development on private network--no pip
39,641,963
<p>The company I work for has taken measures to make our IT assets more secure. As such, I use a computer on a private network which has <strong><em>no</em></strong> access to the Internet. Developing Python software in this environment is very difficult at times. I cannot pip install anything. Downloading, copying...
0
2016-09-22T14:33:09Z
39,642,047
<p>You can install <a href="http://doc.devpi.net/latest/" rel="nofollow">devpi</a> in a server, there you can host some pypi packages or upload your own.</p> <p>It's compatible with pip, so it won't break your workflow, you just need to point your pip.conf to use your local devpi</p>
0
2016-09-22T14:36:42Z
[ "python", "pip" ]
Python CSV Error
39,641,984
<p>Hello all I keep getting this error while making a small program to sort large CSV files out, below is my code and error, what am I doing wrong?</p> <pre><code>if selection: for stuff in stuffs: try: textFile = open("output.txt",'w') mycsv = csv.reader(open(stuff...
0
2016-09-22T14:33:50Z
39,642,312
<p>instead of </p> <pre><code>mycsv = csv.reader(open(stuff)) d_reader = csv.DictReader(mycsv) </code></pre> <p>you want </p> <pre><code>d_reader = csv.DictReader(open(stuff)) </code></pre> <p>the first line is the problem.</p>
0
2016-09-22T14:49:40Z
[ "python", "python-2.7", "csv" ]
Django 1.9 URLField removing the necessary http:// prefix
39,642,003
<p>I've seen a bunch of questions about this, but havent found an answer yet. </p> <p>This is my models:</p> <pre><code>class UserProfile(models.Model): user = models.OneToOneField(User) . . . website = models.URLField(max_length=100, blank=True, null=True) </code></pre> <p>and my forms.py:</p> ...
1
2016-09-22T14:34:44Z
39,642,072
<p>This validation isn't being done by Django, but by your browser itself. You can disable that by putting <code>novalidate</code> in the surrounding <code>&lt;form&gt;</code> element.</p>
2
2016-09-22T14:37:57Z
[ "python", "django", "django-models", "django-forms", "django-urls" ]
How do I group all my functions in Python into one function?
39,642,008
<p>I am using the Turtles Module where I am creating a U.S. Flag. The user decides the size of the flag and with that size I will be using it to create the width and length. </p> <p>I am trying to group/compress all of my subfunctions into one huge function so the user can simply type <code>Draw_USAFlag(t, w) ## T = t...
2
2016-09-22T14:34:54Z
39,642,569
<p>Quite simply, make a function that calls the others:</p> <pre><code>def draw_rectangle(t, w): # however you do this ... def draw_rectangle(t, w): # however you do this ... def Draw_USAFlag(t, w): draw_rectangle(t, w) draw_stripes(t, w) </code></pre> <p>This assumes they don't return anyth...
0
2016-09-22T15:01:55Z
[ "python" ]
Robotframework: Clicking web-elemnt in loop often fails to find an element
39,642,064
<p>I have created a keyword for RF and Selenium2Library. It is supposed to wait for some element by clicking periodically on some other element which will renew the area where the element is supposed to appear. I use it for example for waiting for mails in postbox.</p> <p>The problem is that pretty often the "renew el...
1
2016-09-22T14:37:27Z
39,651,575
<p>Shouldn't be using the keywords <code>Wait Until Page Contains Element</code> or <code>Wait Until Element Is Visible</code> of the <a href="http://robotframework.org/Selenium2Library/Selenium2Library.html" rel="nofollow">Selenium2Library</a> for this purpose:</p> <pre><code>*** Test cases *** Your Test Case Prere...
0
2016-09-23T02:19:36Z
[ "python", "selenium", "robotframework" ]
keep filename while uploading an url with python response library
39,642,077
<p>I am using python to upload a file to an api with</p> <pre><code>url = 'http://domain.tld/api/upload' files = {'file': open('image.jpg', 'rb')} r = requests.post(url, files=files) </code></pre> <p>this works well and my file is uploaded to the server as <code>image.jpg</code>. Now I don't have a local files but a...
1
2016-09-22T14:38:12Z
39,645,135
<p>You can pass the name:</p> <pre><code> files = {'name': ('image.jpg', urlopen('http://domain.tld/path/to/image.jpg'))} </code></pre> <p>If you look at the post body you will see for your variation:</p> <pre><code>Content-Disposition: form-data; name="file"; filename="file" </code></pre> <p>And using the code abo...
0
2016-09-22T17:16:58Z
[ "python", "python-requests" ]
Convert txt to csv python script
39,642,082
<p>I have a .txt file with this inside - 2.9,Gardena CA</p> <p>What I'm trying to do is convert that text into a .csv (table) using a python script: </p> <pre><code>import csv import itertools with open('log.txt', 'r') as in_file: stripped = (line.strip() for line in in_file) lines = (line for line in stripp...
0
2016-09-22T14:38:29Z
39,642,543
<p>You need to split the line first.</p> <pre><code>import csv with open('log.txt', 'r') as in_file: stripped = (line.strip() for line in in_file) lines = (line.split(",") for line in stripped if line) with open('log.csv', 'w') as out_file: writer = csv.writer(out_file) writer.writerow(('t...
0
2016-09-22T15:00:51Z
[ "python", "csv", "text" ]
Convert txt to csv python script
39,642,082
<p>I have a .txt file with this inside - 2.9,Gardena CA</p> <p>What I'm trying to do is convert that text into a .csv (table) using a python script: </p> <pre><code>import csv import itertools with open('log.txt', 'r') as in_file: stripped = (line.strip() for line in in_file) lines = (line for line in stripp...
0
2016-09-22T14:38:29Z
39,642,701
<p>I suposse this is the output you need:</p> <blockquote> <p>title,intro,tagline</p> <p>2.9,Gardena,CA</p> </blockquote> <p>It can be done with this changes to your code:</p> <pre><code>import csv import itertools with open('log.txt', 'r') as in_file: lines = in_file.read().splitlines() stripped = [...
0
2016-09-22T15:08:27Z
[ "python", "csv", "text" ]
How to Clear the window in tkinter (Python)?
39,642,102
<p>I want to hide/remove all the buttons from my window (temporarily) with the "hide_widgets" function so I can put them back after but its just not working for me, I have tried using <code>grid_hide()</code> and <code>destroy()</code> and anything I have tried so for from searching stackoverflow as not worked either.<...
1
2016-09-22T14:39:22Z
39,642,289
<p>You can hide the <code>Button</code>s by calling each one's <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/grid-methods.html" rel="nofollow"><code>grid_forget()</code></a> method.</p> <p>To make that easier you might want to create a <code>self.buttons</code> list or dictionary that contains them all.</...
1
2016-09-22T14:48:34Z
[ "python", "python-3.x", "user-interface", "tkinter", "clear" ]
How to Clear the window in tkinter (Python)?
39,642,102
<p>I want to hide/remove all the buttons from my window (temporarily) with the "hide_widgets" function so I can put them back after but its just not working for me, I have tried using <code>grid_hide()</code> and <code>destroy()</code> and anything I have tried so for from searching stackoverflow as not worked either.<...
1
2016-09-22T14:39:22Z
39,643,235
<p>Have you tried replacing <code>new_game.grid_forget()</code> with <code>self.new_game.grid_forget()</code>?</p> <p>Check <a href="http://stackoverflow.com/a/68324/6836841">this</a> answer out for an explanation as to why <code>self</code> needs to be referenced explicitly. I ran a very simple script to test this b...
0
2016-09-22T15:33:32Z
[ "python", "python-3.x", "user-interface", "tkinter", "clear" ]
How to Clear the window in tkinter (Python)?
39,642,102
<p>I want to hide/remove all the buttons from my window (temporarily) with the "hide_widgets" function so I can put them back after but its just not working for me, I have tried using <code>grid_hide()</code> and <code>destroy()</code> and anything I have tried so for from searching stackoverflow as not worked either.<...
1
2016-09-22T14:39:22Z
39,643,376
<p>Ok I got it working now, silly me forgot "()" in <code>self.hide_widgets()</code>, i just never thought about it because there was no error as it was creating a variable instead.</p>
0
2016-09-22T15:40:37Z
[ "python", "python-3.x", "user-interface", "tkinter", "clear" ]
Selecting all records id's from Odoo Contacts listview
39,642,143
<p>I have written some python code in my .py file to display an wizard</p> <pre><code>class DisplayWindow(models.Model): _inherit = 'res.partner' wizard_id = fields.Many2one('sale.example_wizard') def result_to_search(self, cr, uid, active_ids): wizard = self.pool['sale.example_wizard'].create(cr, uid, vals={ ...
0
2016-09-22T14:41:12Z
39,645,438
<p>You can get selected record by using following code.</p> <pre><code>wizard = self.pool['sale.example_wizard'].create(cr, uid, vals={ 'partner_ids': [(6, 0, self._context.get('active_ids',[]))] }) </code></pre> <p>Thanks</p>
0
2016-09-22T17:35:05Z
[ "python", "xml", "listview", "odoo-9" ]
Bind a button already on_press
39,642,263
<p>I want to change the function which is launched when my button is pressed.</p> <p>Python file:</p> <pre><code>class UpdateScreen(Screen): swimbot = {} def swimbot_connected(self): wallouh = list(AdbCommands.Devices()) if not wallouh: self.ids['text_label'].text = 'Plug your Swimbot and try again' ...
0
2016-09-22T14:47:21Z
39,649,044
<p>When you put <code>()</code> after a function in python you execute that function. So when you type</p> <pre><code>self.ids['action_button'].bind(on_press = self.check_need_update()) </code></pre> <p>You will actually pass the result of self.check_needed_update to <code>on_press</code>. So you need:</p> <pre><cod...
0
2016-09-22T21:19:26Z
[ "python", "button", "kivy", "bind" ]
How to remove everything (except certain characters) after the last number in a string
39,642,368
<p>This is a follow-up of <a href="http://stackoverflow.com/questions/39637955/how-to-remove-everything-after-the-last-number-in-a-string">this question.</a></p> <p>There I learned how to remove all characters after the last number in a string; so I can turn</p> <pre><code>w = 'w123 o456 t789-- --' </code></pre> <p>...
0
2016-09-22T14:52:26Z
39,642,446
<p>To keep certain characters <code>(</code> and <code>)</code> use:</p> <pre><code>re.sub('[^0-9()]+$', '', w) </code></pre> <p>to remove only certain characters from the end of the line:</p> <pre><code>re.sub('[- ]+$', '', w) </code></pre> <p>In square brackets, you can list the characters you want to match. If ...
4
2016-09-22T14:56:26Z
[ "python", "regex" ]
How to remove everything (except certain characters) after the last number in a string
39,642,368
<p>This is a follow-up of <a href="http://stackoverflow.com/questions/39637955/how-to-remove-everything-after-the-last-number-in-a-string">this question.</a></p> <p>There I learned how to remove all characters after the last number in a string; so I can turn</p> <pre><code>w = 'w123 o456 t789-- --' </code></pre> <p>...
0
2016-09-22T14:52:26Z
39,643,015
<p>You may use another re.sub in the callback as the replacement pattern.</p> <pre><code>re.sub(r'\D+$', lambda m: re.sub(r'[^()]+','',m.group(0)), s) </code></pre> <p>Here, you match all symbols other than digits at the end of the string, pass that value to the callback, and all symbols other than <code>(</code> an...
1
2016-09-22T15:23:30Z
[ "python", "regex" ]
How to remove everything (except certain characters) after the last number in a string
39,642,368
<p>This is a follow-up of <a href="http://stackoverflow.com/questions/39637955/how-to-remove-everything-after-the-last-number-in-a-string">this question.</a></p> <p>There I learned how to remove all characters after the last number in a string; so I can turn</p> <pre><code>w = 'w123 o456 t789-- --' </code></pre> <p>...
0
2016-09-22T14:52:26Z
39,643,040
<p>If there is always 3 groups of characters and each group start's with a single letter and has 3 digits after that, and only the last group might have brackets, this expression might be just what you need:</p> <pre><code>w = 'w123 o456 (t789)' clean = re.sub(r'^.*(\w\d{3})[ -]+(\w\d{3})[ -]+(\(?\w\d{3}\)?).*$', r'\1...
1
2016-09-22T15:25:00Z
[ "python", "regex" ]
How to remove everything (except certain characters) after the last number in a string
39,642,368
<p>This is a follow-up of <a href="http://stackoverflow.com/questions/39637955/how-to-remove-everything-after-the-last-number-in-a-string">this question.</a></p> <p>There I learned how to remove all characters after the last number in a string; so I can turn</p> <pre><code>w = 'w123 o456 t789-- --' </code></pre> <p>...
0
2016-09-22T14:52:26Z
39,643,512
<p>Instead of Regex, why not use list comprehension (this auto keeps letters and digits if you don't want certain letters or digits we can change it too):</p> <pre><code>w = 'w123 o456 t789-- --' list_to_keep =[' '] print(''.join([x for x in w if x.isalnum() or x in list_to_keep])) &gt;&gt; w123 o456 t789 w = 'w123 ...
1
2016-09-22T15:47:55Z
[ "python", "regex" ]
How to make equal space between words - python
39,642,374
<p>(SORRY FOR BAD ENGLISH) Im working at cmd. I want to do that thing:</p> <pre><code>file_name DIR file_name_3 DIR file_name_545 DIR file_name_LlK DIR </code></pre> <p>Instead of doing that thing:</p> <pre><code>file_name DIR file_name_3 DIR file_name_545 ...
0
2016-09-22T14:52:38Z
39,642,568
<p>Use format strings.</p> <pre><code>"{:20}{}".format(data,"DIR") </code></pre> <p>The same with <code>ljkust()</code></p> <pre><code>data.ljust(20) + "DIR" </code></pre> <p>See <code>help(str.ljust)</code> to understand <code>ljust</code></p>
0
2016-09-22T15:01:52Z
[ "python" ]
How to make equal space between words - python
39,642,374
<p>(SORRY FOR BAD ENGLISH) Im working at cmd. I want to do that thing:</p> <pre><code>file_name DIR file_name_3 DIR file_name_545 DIR file_name_LlK DIR </code></pre> <p>Instead of doing that thing:</p> <pre><code>file_name DIR file_name_3 DIR file_name_545 ...
0
2016-09-22T14:52:38Z
39,642,598
<p>First, find the widest point in your data. I assume you have a list of tuples.</p> <pre><code>col_width = max(tup[0] for tup in list_of_tuples) for tup in list_of_tuples: print(tup[0].ljust(col_width), tup[1].ljust(colwidth)) </code></pre> <p><code>ljust</code> is the function you want, but I think you are se...
0
2016-09-22T15:03:17Z
[ "python" ]
Python: Deadlock of a single lock in multiprocessing
39,642,399
<p>I'm using pyserial to acquire data with multiprocessing. The way I share data is very simple. So:</p> <p>I have member objects in my class:</p> <pre><code>self.mpManager = mp.Manager() self.shared_return_list = self.mpManager.list() self.shared_result_lock = mp.Lock() </code></pre> <p>I call my multiprocessing pr...
0
2016-09-22T14:54:13Z
39,644,957
<p>Without having a <a href="http://sscce.org/" rel="nofollow">SSCCE</a>, it's difficult to know if there's something else going on in your code or not.</p> <p>One possibility is that there is an exception thrown after a lock is acquired. Try wrapping each of your locked sections in a try/finally clause. Eg.</p> <p...
1
2016-09-22T17:05:40Z
[ "python", "thread-safety", "multiprocessing", "mutex", "python-3.4" ]
Python: Deadlock of a single lock in multiprocessing
39,642,399
<p>I'm using pyserial to acquire data with multiprocessing. The way I share data is very simple. So:</p> <p>I have member objects in my class:</p> <pre><code>self.mpManager = mp.Manager() self.shared_return_list = self.mpManager.list() self.shared_result_lock = mp.Lock() </code></pre> <p>I call my multiprocessing pr...
0
2016-09-22T14:54:13Z
40,110,367
<p>It turned out it's not a deadlock. My fault! The problem was that the data acquired from the device is sometimes so huge that copying the data through</p> <pre><code>shared_return_list.extend(acqBuffer) del acqBuffer[:] </code></pre> <p>Takes a very long time that the program freezes. I solved this issue by moving...
0
2016-10-18T14:02:21Z
[ "python", "thread-safety", "multiprocessing", "mutex", "python-3.4" ]
How to use pyparsing LineStart?
39,642,432
<p>I'm trying to use pyparsing to parse key:value pairs from the comments in a document. A key starts at the beginning of a line, and a value follows. Values may be continued on multiple lines that begin with whitespace.</p> <pre><code>import pyparsing as pp instring = """ -- This is (a) #%^&amp; comment /* name1:...
1
2016-09-22T14:55:56Z
39,653,686
<p>I think the confusion I have with <code>LineStart</code> is that, for <code>LineEnd</code>, I can look for a <code>'\n'</code> character, but there is no separate character for <code>LineStart</code>. So in <code>LineStart</code> I look to see if the current parser location is positioned just after a <code>'\n'</cod...
1
2016-09-23T06:08:10Z
[ "python", "python-3.x", "pyparsing" ]
Riak MapReduce in single node using javascript and python
39,642,462
<p>I want to perform MapReduce job on data in Riak DB using javascript. But stuck in very begining, i couldnot understand how it is returning value.</p> <pre><code>client = riak.RiakClient() query = client.add('user') query.map(""" function(v){ var i=0; i++; retur...
0
2016-09-22T14:57:17Z
39,694,795
<p>When you run a MapReduce job, the map phase code is sent out to the vnodes where the data is stored and executed for each value in the data. The resulting arrays are collected and passed to a single reduce phase, which also returns an array. If there are sufficiently many results, the reduce phase may be run multi...
1
2016-09-26T04:34:06Z
[ "javascript", "python", "dictionary", "riak" ]
Sort a list where there are strings, floats and integers
39,642,490
<p>I need some help because I wanted to know if there is a way in Python to sort a list where there are strings, floats and integers in it.</p> <p>I tried to use list.sort() method but of course it did not work.</p> <p>Here is an example of a list I would like to sort :</p> <pre><code> l = [1, 2.0, "titi", True, ...
-5
2016-09-22T14:58:25Z
39,642,636
<p>Python's comparison operators wisely refuse to work for variables of incompatible types. Decide on the criterion for sorting your list, encapsulate it in a function and pass it as the <code>key</code> option to <code>sort()</code>. For example, to sort by the <code>repr</code> of each element (a string):</p> <pre><...
0
2016-09-22T15:05:09Z
[ "python", "sorting", "python-3.3" ]
python u'\u00b0' returns u'\xb0'. Why?
39,642,521
<p>I use python 2.7.10.</p> <p>On dealing with character encoding, and after reading a lot of stack-overflow etc. etc. on the subject, I encountered this behaviour which looks strange to me. Python interpreter input</p> <pre><code>&gt;&gt;&gt;u'\u00b0' </code></pre> <p>results in the following output:</p> <pre><cod...
0
2016-09-22T15:00:00Z
39,642,638
<p>Python uses some rules for determining what to output from <code>repr</code> for each character. The rule for Unicode character codepoints in the 0x0080 to 0x00ff range is to use the sequence <code>\xdd</code> where <code>dd</code> is the hex code, at least in Python 2. There's no way to change it. In Python 3, all ...
0
2016-09-22T15:05:13Z
[ "python", "unicode", "character-encoding", "python-2.x", "string-literals" ]
Setting a local bool to control flow
39,642,592
<p>I have an issue in Python where I want to do a while loop and ask the player to input number of dice and the number of sides to do random dice rolls. On the second loop and any additional loops I want to ask if they would like to continue. If they input 'n' or 'no' then the program exits.</p> <p>I was able to get t...
0
2016-09-22T15:03:08Z
39,642,675
<p>You're pretty close.</p> <pre><code># move this outside the loop first_loop = True while True: if not first_loop: get_user_input() first_loop = False </code></pre> <p>And no need to use <code>first_loop</code> in the <code>get_user_input</code> function itself:</p> <pre><code>def get_user_input()...
2
2016-09-22T15:07:08Z
[ "python", "python-3.x" ]
Setting a local bool to control flow
39,642,592
<p>I have an issue in Python where I want to do a while loop and ask the player to input number of dice and the number of sides to do random dice rolls. On the second loop and any additional loops I want to ask if they would like to continue. If they input 'n' or 'no' then the program exits.</p> <p>I was able to get t...
0
2016-09-22T15:03:08Z
39,642,770
<p>You can put the variable in a <code>list</code>. This will allow you to change its value in the <code>get_user_input()</code> function and avoid making it a global variable.</p> <pre><code>import sys import random def get_user_input(first_loop): if not first_loop[0]: # access value in the list another...
1
2016-09-22T15:11:21Z
[ "python", "python-3.x" ]
Creating combinations from a tuple
39,642,629
<p>I take the data from the database. From the database they come in the form of a tuple:</p> <pre><code>[('test1', 'test12', 'test13', 'test14'), ('test21', 'test22', 'test23', 'test24'), ('test31', 'test32', 'test33', 'test34'), ('test41', 'test42', 'test43', 'test44'), ('test51', 'test52', 'test53', 'test54'), ...
-1
2016-09-22T15:04:56Z
39,643,675
<p>You need to use <a href="https://docs.python.org/3/library/itertools.html#itertools.product" rel="nofollow"><code>product</code></a> method from builtin package <a href="https://docs.python.org/3/library/itertools.html#itertools" rel="nofollow"><code>itertools</code></a> which gives cartesian product of input iterab...
0
2016-09-22T15:56:07Z
[ "python", "python-3.x", "combinations" ]
time.strftime() not updaing
39,642,663
<p>I am trying to get the time when a button is pushed, but I am going to have a few pushes without starting and calling the time module. In Ipython, I tested out some code, and the time is not updating</p> <pre><code>import time t = time.strftime("%b-%d-%y at %I:%m%p") print(t) #do something else for a little t = tim...
2
2016-09-22T15:06:39Z
39,642,802
<p>You are using <code>%m</code> at <code>%I:%m%p</code> to format your "minutes", which actually means a <strong>month</strong> in decimals. Try capital <code>%M</code>instead to get the minutes.</p> <p>So,</p> <pre><code>time.strftime("%b-%d-%y at %I:%M%p") </code></pre> <p>See <a href="https://docs.python.org/2/l...
3
2016-09-22T15:12:56Z
[ "python", "time", "module" ]
Create mask from skimage contour
39,642,680
<p>I have an image that I found contours on with <code>skimage.measure.find_contours()</code> but now I want to create a mask for the pixels fully outside the largest closed contour. Any idea how to do this? </p> <p>Modifying the example in the documentation: </p> <pre><code>import numpy as np import matplotlib.pyplo...
0
2016-09-22T15:07:25Z
39,857,243
<p>Ok, I was able to make this work by converting the contour to a path and then selecting the pixels inside:</p> <pre><code># Convert the contour into a closed path from matplotlib import path closed_path = path.Path(contour.T) # Get the points that lie within the closed path idx = np.array([[(i,j) for i in range(r....
0
2016-10-04T16:17:45Z
[ "python", "contour", "skimage", "masked-array" ]
Adding alpha channel to RGB array using numpy
39,642,721
<p>I have an image array in RGB space and want to add the alpha channel to be all zeros. Specifically, I have a <code>numpy</code> array with shape (205, 54, 3) and I want to change the shape to (205, 54, 4) with the additional spot in the third dimension being all 0.0's. Which numpy operation would achieve this?</p>
3
2016-09-22T15:09:08Z
39,643,014
<p>You could use one of the stack functions (<a href="http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.stack.html" rel="nofollow">stack</a>/<a href="http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.hstack.html" rel="nofollow">hstack</a>/<a href="http://docs.scipy.org/doc/numpy-dev/reference/ge...
2
2016-09-22T15:23:28Z
[ "python", "numpy" ]
Adding alpha channel to RGB array using numpy
39,642,721
<p>I have an image array in RGB space and want to add the alpha channel to be all zeros. Specifically, I have a <code>numpy</code> array with shape (205, 54, 3) and I want to change the shape to (205, 54, 4) with the additional spot in the third dimension being all 0.0's. Which numpy operation would achieve this?</p>
3
2016-09-22T15:09:08Z
39,643,047
<p>If you have your current image as rgb variable then just use:</p> <pre><code>rgba = numpy.concatenate((rgb, numpy.zeros((205, 54, 1))), axis=2) </code></pre> <p>Concatenate function merge rgb and zeros array together. Zeros function creates array of zeros. We set axis to 2 what means we merge in the thirde dimensi...
0
2016-09-22T15:25:12Z
[ "python", "numpy" ]
Python, list of strings, rows into columns
39,642,852
<p>So, my problem is, i want to transpose my list rows into columns for example: </p> <p>["AAA", "BBB", "CCC"] => ["ABC", "ABC", "ABC"]</p> <p>can't find an efficient way to do it.</p>
-2
2016-09-22T15:15:33Z
39,642,891
<p>You can do a simple use of <code>zip</code> and unpacking:</p> <pre><code>strs = ["AAA", "BBB", "CCC"] print zip(*strs) </code></pre> <p>Output will be tuples, though:</p> <blockquote> <p>[('A', 'B', 'C'), ('A', 'B', 'C'), ('A', 'B', 'C')]</p> </blockquote> <hr> <p>For strings you can use:</p> <pre><code>str...
3
2016-09-22T15:17:36Z
[ "python" ]
Python, list of strings, rows into columns
39,642,852
<p>So, my problem is, i want to transpose my list rows into columns for example: </p> <p>["AAA", "BBB", "CCC"] => ["ABC", "ABC", "ABC"]</p> <p>can't find an efficient way to do it.</p>
-2
2016-09-22T15:15:33Z
39,642,907
<pre><code>a = ["AAA", "BBB", "CCC"] print ([''.join(i) for i in zip(*a)]) </code></pre>
2
2016-09-22T15:18:30Z
[ "python" ]
Python, list of strings, rows into columns
39,642,852
<p>So, my problem is, i want to transpose my list rows into columns for example: </p> <p>["AAA", "BBB", "CCC"] => ["ABC", "ABC", "ABC"]</p> <p>can't find an efficient way to do it.</p>
-2
2016-09-22T15:15:33Z
39,643,188
<p>So this assumes that you are dealing with strings in your example, but you could expand the algorithm for dealing with whatever data type you come across, the logic will remain the same.</p> <pre><code>listRows = ["AAA", "BBB", "CCC"] transList = [] tempString = '' for s in range(0,len(listRows)): for i in rang...
0
2016-09-22T15:31:16Z
[ "python" ]
create df column name by adding global variable name and a string in Python
39,642,875
<p>I have a global variable <code> split_ask_min = 'Minimum_Spend' </code></p> <p>I would like to create a new variable in my df and name it 'Minimum_Spend_Sum' and make it the sum of Minimum_Spend. </p> <p><code> var_programs['split_ask_min+ _Sum'] = var_programs[split_ask_min].groupby(X['NAME']).transform('sum') <...
1
2016-09-22T15:16:53Z
39,642,987
<p>Unless you really need to create a variable, use a dictionary to store the value.</p> <pre><code>df = {} split_ask_min = 'Minimum_Spend' df[split_ask_min + '_Sum'] = ... print(df) </code></pre> <p>Otherwise you can use <code>globals()</code></p> <pre><code>globals[split_ask_min + '_Sum'] = ... # Minimum_Spend_Su...
0
2016-09-22T15:21:57Z
[ "python", "python-3.x", "pandas" ]
create df column name by adding global variable name and a string in Python
39,642,875
<p>I have a global variable <code> split_ask_min = 'Minimum_Spend' </code></p> <p>I would like to create a new variable in my df and name it 'Minimum_Spend_Sum' and make it the sum of Minimum_Spend. </p> <p><code> var_programs['split_ask_min+ _Sum'] = var_programs[split_ask_min].groupby(X['NAME']).transform('sum') <...
1
2016-09-22T15:16:53Z
39,643,222
<p>To create a new column in your df you can pass a constructed string to add a new column to your df:</p> <pre><code>In [239]: split_ask_min = 'Minimum_Spend' df = pd.DataFrame(np.random.randn(5,3), columns=list('abc')) df[split_ask_min + '_Sum'] = 0 df Out[239]: a b c Minimum_Spend_Sum 0 ...
1
2016-09-22T15:32:52Z
[ "python", "python-3.x", "pandas" ]
How to install psycopg2 for django on mac
39,642,961
<p>I have postgresql installed (with postgresql app). When I try "pip install psycopg2", i get "unable to execute gcc-4.2: No such file or directory. How to fix?</p>
0
2016-09-22T15:21:03Z
39,643,053
<p>You will need XCode to compile with gcc on macOS. Install it with this command in the terminal:</p> <pre><code>xcode-select --install </code></pre> <p>Or you cold install it from the app store.</p>
0
2016-09-22T15:25:41Z
[ "python", "django", "postgresql", "psycopg2" ]
pip installl tsne doesn't work
39,643,043
<p>I couldn't install tsne package on my Windows machine. I followed the instruction <a href="https://github.com/danielfrg/tsne/blob/master/README.md" rel="nofollow">here</a> to install tsne packages for Python. But either <code>pip install tsne</code> or <code>pip install git+https://github.com/danielfrg/tsne.git</cod...
0
2016-09-22T15:25:07Z
39,643,483
<p>I am sorry if you've already tried this, but i couldn't see what you typed into the command prompt to get that error.</p> <p>If you dont have your path variable set to pip, then type this in (just alter the path if python is in a different directory) and remember its case sensitive!</p> <pre><code>C:\Python34\Scri...
0
2016-09-22T15:46:25Z
[ "python", "pip" ]
pip installl tsne doesn't work
39,643,043
<p>I couldn't install tsne package on my Windows machine. I followed the instruction <a href="https://github.com/danielfrg/tsne/blob/master/README.md" rel="nofollow">here</a> to install tsne packages for Python. But either <code>pip install tsne</code> or <code>pip install git+https://github.com/danielfrg/tsne.git</cod...
0
2016-09-22T15:25:07Z
39,643,572
<p>The problem looks familiar. If you haven't done so already, the most immediate thing to do is to try:</p> <pre><code>easy_install tsne </code></pre> <p>or </p> <pre><code>npm install git+https://github.com/danielfrg/tsne.git </code></pre> <p>Also try the following, but you may need homebrew or have permission de...
0
2016-09-22T15:50:44Z
[ "python", "pip" ]
Random Odd Numbers
39,643,063
<p>My professor gave us our first assignment (Cs315), which involves dealing with some huge (odd) integers and determining if they are prime. I started to do this in c++ until I realized that even long long ints could not hold the numbers needed, so I was left with the choices of making a class of vectors in c++, or le...
0
2016-09-22T15:26:00Z
39,643,121
<p>You need to assign <code>x + 1</code> back to <code>x</code>. You can either do this like this: <code>x = x+1</code> or like this: <code>x += 1</code></p>
1
2016-09-22T15:28:40Z
[ "python", "python-3.x" ]
SQLObject install without internet
39,643,082
<p>Trying to setup a python flask server in a controlled environment, no access to internet</p> <pre><code># python setup.py install Traceback (most recent call last): File "setup.py", line 9, in &lt;module&gt; use_setuptools() File "/tmp/app_dependencies/SQLObject-3.1.0/ez_setup.py", line 150, in use_setuptoo...
0
2016-09-22T15:27:19Z
39,662,030
<p>Was able to install from a wheel file</p> <pre><code>pip install SQLObject-version.whl </code></pre>
0
2016-09-23T13:28:47Z
[ "python", "linux", "python-2.6", "sqlobject" ]
How to add navigation bar to PyDev?
39,643,128
<p>I am trying to add navigation bar to PyDev, something like <a href="http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-java-editor-breadcrumb.htm" rel="nofollow">this</a>.</p> <p>Is this navigation bar Breadcrumb for Java only?</p>
0
2016-09-22T15:29:08Z
39,644,740
<p>Unfortunately, this is java only (there's nothing really on the platform to implement it, all the code is inside JDT, the java plugin).</p>
0
2016-09-22T16:52:39Z
[ "python", "pydev", "navigationbar" ]
Why get a new logger object in each new module?
39,643,146
<p>The python logging module has a common pattern (<a href="http://stackoverflow.com/a/15735146/52074">ex1</a>, <a href="https://docs.python.org/2/howto/logging.html#advanced-logging-tutorial" rel="nofollow">ex2</a>) where in each module you get a new logger object for each python module.</p> <p>I'm not a fan of blind...
0
2016-09-22T15:29:49Z
39,643,474
<p>Each logger can be configured separately. Generally, a module logger is not configured <em>at all</em> in the module itself. You create a distinct logger and use it to log messages of varying levels of detail. Whoever <em>uses</em> the logger decides what level of messages to see, where to send those messages, and e...
1
2016-09-22T15:46:02Z
[ "python", "multithreading", "performance", "logging", "instrumentation" ]
Why get a new logger object in each new module?
39,643,146
<p>The python logging module has a common pattern (<a href="http://stackoverflow.com/a/15735146/52074">ex1</a>, <a href="https://docs.python.org/2/howto/logging.html#advanced-logging-tutorial" rel="nofollow">ex2</a>) where in each module you get a new logger object for each python module.</p> <p>I'm not a fan of blind...
0
2016-09-22T15:29:49Z
39,643,502
<p>The logger name defines <em>where</em> (logically) in your application events occur. Hence, the recommended pattern</p> <pre><code>logger = logging.getLogger(__name__) </code></pre> <p>uses logger names which track the Python package hierarchy. This in turn allows whoever is configuring logging to turn verbosity u...
1
2016-09-22T15:47:19Z
[ "python", "multithreading", "performance", "logging", "instrumentation" ]
Interactive matplotlib widget not updating with scipy ode solver
39,643,192
<p>I have been using the interactive matplotlib widgets to visualise the solution of differential equations. I have got it working with the odeint function in scipy, however have not managed to get it to update with the ode class. I would rather use the latter as it has greater control over which solver is used.</p> <...
0
2016-09-22T15:31:23Z
39,649,575
<p><em>For next time, please post the complete code with all imports etc. such that people can actually reproduce your problem.</em></p> <p>Comming to the question: I guess it's always wise to seperate calculations from plotting. Therefore first try to solve the ODE with some given initial conditions. Once that works,...
0
2016-09-22T22:04:03Z
[ "python", "matplotlib", "scipy" ]
Python Dictionary Comment Out a Line not Working
39,643,199
<p>I have a python dictionary that I import from another script. For example here is the dictionary that is in another script and loaded in:</p> <pre><code>def Log(): LogD = { 'Key': [0, 1, 2], 'Key2': [0, 1, 2], 'Key3': [0, 1, 2], # and so on for about 100 records } ...
-2
2016-09-22T15:31:48Z
39,859,194
<p>So since no one answered this I have figured it out. Props goes to someone who commented about PYC not indexing correctly. So I added a </p> <pre><code>os.remove(whatever.pyc) </code></pre> <p>after I edit my dictionary and everything works great.</p>
0
2016-10-04T18:19:39Z
[ "python", "dictionary", "comments" ]
Is it possible to group tensorflow FLAGS by type and generate a string from them?
39,643,256
<p>Is it possible to group tensorflow FLAGS by type? E.g. Some flags are system related (e.g. # of threads) while others are model hyperparams.</p> <p>Then, is it possible to use the model hyperparams FLAGS, in order to generate a string? (the string will be used to identify the model filename)</p> <p>Thanks</p>
0
2016-09-22T15:34:35Z
39,664,586
<p>I'm guessing that you're wanting to automatically store the hyper-parameters as part of the file name in order to organize your experiments better? Unfortunately there isn't a good way to do this with TensorFlow, but you can look at some of the high-level frameworks built on top of it to see if they offer something ...
0
2016-09-23T15:33:46Z
[ "python", "machine-learning", "computer-vision", "tensorflow" ]
Python Scraping - Unable to get required data from Flipkart
39,643,390
<p>I was trying to scrape the customer reviews from Flipkart website. The following is the <a href="https://www.flipkart.com/samsung-galaxy-j5-6-new-2016-edition-white-16-gb/product-reviews/itmegmrnzqjcpfg9?pid=MOBEG4XWJG7F9A6Z" rel="nofollow">link</a>. The following was my code to scrape, but it is always returning an...
1
2016-09-22T15:41:21Z
39,643,968
<p>This seemed to work for me</p> <pre><code>from selenium import webdriver from bs4 import BeautifulSoup driver = webdriver.Firefox() driver.get('https://www.flipkart.com/samsung-galaxy-j5-6-new-2016-edition-white-16-gb/product-reviews/itmegmrnzqjcpfg9?pid=MOBEG4XWJG7F9A6Z') html = driver.page_source soup = Beautiful...
0
2016-09-22T16:10:11Z
[ "python", "selenium", "beautifulsoup" ]
Python Scraping - Unable to get required data from Flipkart
39,643,390
<p>I was trying to scrape the customer reviews from Flipkart website. The following is the <a href="https://www.flipkart.com/samsung-galaxy-j5-6-new-2016-edition-white-16-gb/product-reviews/itmegmrnzqjcpfg9?pid=MOBEG4XWJG7F9A6Z" rel="nofollow">link</a>. The following was my code to scrape, but it is always returning an...
1
2016-09-22T15:41:21Z
39,644,642
<p>The reviews etc.. are populated using <em>reactjs</em>, the data is retrieved using an ajax request which you can mimic with requests:</p> <pre><code>import requests data = {"productId": "MOBEG4XWJG7F9A6Z", # end of url pid=MOBEG4XWJG7F9A6Z "count": "15", "ratings": "ALL", "reviewerType:ALL...
4
2016-09-22T16:46:45Z
[ "python", "selenium", "beautifulsoup" ]
How can I make a python script change itself?
39,643,428
<p>How can I make a python script change itself?</p> <p>To boil it down, I would like to have a python script (<code>run.py</code>)like this</p> <pre><code>a = 0 b = 1 print a + b # do something here such that the first line of this script reads a = 1 </code></pre> <p>Such that the next time the script is run it wou...
0
2016-09-22T15:43:33Z
39,643,816
<p>For an example (changing the value of <code>a</code> each time its run):</p> <pre><code>a = 0 b = 1 print a + b with open(__file__, 'r') as f: lines = f.read().split('\n') val = int(lines[0].split(' = ')[-1]) new_line = 'a = {}'.format(val+1) new_file = '\n'.join([new_line] + lines[1:]) with open(...
2
2016-09-22T16:02:37Z
[ "python", "runtime", "interpreter" ]
How can I make a python script change itself?
39,643,428
<p>How can I make a python script change itself?</p> <p>To boil it down, I would like to have a python script (<code>run.py</code>)like this</p> <pre><code>a = 0 b = 1 print a + b # do something here such that the first line of this script reads a = 1 </code></pre> <p>Such that the next time the script is run it wou...
0
2016-09-22T15:43:33Z
39,643,819
<p>Make a file <code>a.txt</code> that contains one character on one line:</p> <pre><code>0 </code></pre> <p>Then in your script, open that file and retrieve the value, then immediately change it:</p> <pre><code>with open('a.txt') as f: a = int(f.read()) with open('a.txt', 'w') as output: output.write(str(a+...
0
2016-09-22T16:02:44Z
[ "python", "runtime", "interpreter" ]
How can I make a python script change itself?
39,643,428
<p>How can I make a python script change itself?</p> <p>To boil it down, I would like to have a python script (<code>run.py</code>)like this</p> <pre><code>a = 0 b = 1 print a + b # do something here such that the first line of this script reads a = 1 </code></pre> <p>Such that the next time the script is run it wou...
0
2016-09-22T15:43:33Z
39,646,415
<p>What you're asking for would require you to manipulate files at the {sys} level; basically, you'd read the current file in, modify it, over-write it, and reload the current module. I played with this briefly because I was curious, but I ran into file locking and file permission issues. Those are <em>probably</em> ...
0
2016-09-22T18:30:37Z
[ "python", "runtime", "interpreter" ]
How do i set django setting to a file which is outside the django tree?
39,643,436
<p>I have this python file tasks.py</p> <pre><code>import os os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'DjangoWebProject.settings') from django.contrib.auth.models import User from logreg.models import ActivationCode import datetime def remove_users(): print 'hello worldddddddddddddd...
0
2016-09-22T15:44:02Z
39,646,435
<p>Note that you're trying to add a settings module inside a script that already requires it. </p> <p>Wouldn't it be easier if you add a specific django command? Thanks to it you'd be able to start your task with <code>python manage.py --settings=&lt;path_to_your_settings&gt;</code>.</p> <p>Another tip:</p> <p>Move ...
2
2016-09-22T18:31:56Z
[ "python", "django" ]
How do i set django setting to a file which is outside the django tree?
39,643,436
<p>I have this python file tasks.py</p> <pre><code>import os os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'DjangoWebProject.settings') from django.contrib.auth.models import User from logreg.models import ActivationCode import datetime def remove_users(): print 'hello worldddddddddddddd...
0
2016-09-22T15:44:02Z
39,647,673
<p>If you're creating any script that is using your django project, it is absolutely necessary to set path to settings of your project <strong>before</strong> any import from django or your project. And you're importing user model from django in 1st line and model from your project in second.</p> <p>Also, you will nee...
2
2016-09-22T19:45:59Z
[ "python", "django" ]
How to create related field in odoo?
39,643,493
<p>I am trying to create related field for displaying customer's balance in sale orders. I think i am creating wrong related field. Can anybody help me how to create related field in odoo? </p> <p><strong>here this is related field i am creating</strong></p> <p><code>customer_balance = fields.Related('partner_id.cred...
1
2016-09-22T15:47:04Z
39,643,997
<p>Try below code. It will work for you.</p> <pre><code>customer_balance = fields.Float(related="partner_id.credit",string="Balance") </code></pre> <p>Thanks..</p>
3
2016-09-22T16:11:22Z
[ "python", "openerp", "field", "odoo-8" ]
Django AdminEmailHandler hangs when DB is not accesible
39,643,527
<p>I noticed that when my database goes down, the queries to my Django app gives timeout instead of returning 500 to the client instantaneously. </p> <p>Tracing the problem I set database connect_timeout in config to 5s (<a href="http://stackoverflow.com/questions/1084488/how-to-set-timeout-for-database-connection-in-...
0
2016-09-22T15:48:30Z
39,646,550
<p>While no better alternative is given, this is the solution I have implemented.</p> <p>I have setup a custom AdminEmailHandler that inspect's the exception and in case of database OperationalError skips the exception and sends and error instead.</p> <pre><code>import logging from django.utils.log import AdminEmail...
0
2016-09-22T18:38:36Z
[ "python", "mysql", "django" ]
Identifying overlapping rows in multiple dataframes
39,643,601
<p>I have two dataframes like </p> <p>df1</p> <pre><code>Time accler 19.13.33 24 19.13.34 24 19.13.35 25 19.13.36 27 19.13.37 25 19.13.38 27 19.13.39 25 19.13.40 24 </code></pre> <p>df2</p> <pre><code> Time accler 19.13.29 24 19.13.30 24 19.13.31 25 19.13.32 27 19.13.33 25 19.13.34 27 19.13....
1
2016-09-22T15:52:10Z
39,643,687
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a>, default parameter <code>how='inner'</code> can be omited:</p> <pre><code>df = pd.merge(df1, df2, on='Time') print (df) Time accler_x accler_y 0 19.13.33 24 25 ...
3
2016-09-22T15:56:38Z
[ "python", "pandas", "merge", "inner-join", "concat" ]
How can programs make Lua(or python) interpreter execute statements provided by the program?
39,643,609
<p>I am using Cent OS 7.</p> <p>I want to write a program(written in Java or other languages) that can interact with Lua interpreter. I hope that my program can feed statements to Lua interpreter, and get executed real-time, while previous variables are still available.</p> <p>For example, my program feeds <code>a = ...
-1
2016-09-22T15:52:30Z
39,643,937
<p>As your question is very broad (interpret Lua or Python, in any language), I can only give you some hints. </p> <p>If you write in C or C++, you can use the Lua library directly. It probably allows you to execute Lua statements, make values in C visible to the Lua code, make C function available to the Lua code, an...
0
2016-09-22T16:08:22Z
[ "java", "python", "linux", "lua" ]
How to solve an issue in a simple TR Tkinter program
39,643,748
<p>Major programming noob here, and my very first question in stackoverflow. I'm trying to make a time reaction tester, with a simplistic Tkinter GUI.</p> <p>Here's the code</p> <pre><code>#!/usr/bin/env python import tkinter as tk import time import random class TRTest(tk.Frame): def __init__(self, master = N...
0
2016-09-22T15:58:23Z
39,644,059
<p>I think you are trying to run the method <code>Test</code> with</p> <pre><code>self.Test </code></pre> <p>Try instead </p> <pre><code>self.Test() </code></pre>
0
2016-09-22T16:14:49Z
[ "python", "python-3.x", "tkinter" ]
How to solve an issue in a simple TR Tkinter program
39,643,748
<p>Major programming noob here, and my very first question in stackoverflow. I'm trying to make a time reaction tester, with a simplistic Tkinter GUI.</p> <p>Here's the code</p> <pre><code>#!/usr/bin/env python import tkinter as tk import time import random class TRTest(tk.Frame): def __init__(self, master = N...
0
2016-09-22T15:58:23Z
39,644,608
<p>In addition to the answer from Patrick Haugh, you aren't using the .after method correctly.</p> <p>Change this line of code</p> <pre><code>self.after(random.randint(1000, 5000)) </code></pre> <p>to</p> <pre><code>self.after(random.randint(1000, 5000),self.Test) </code></pre> <p>and move it to after</p> <pre...
0
2016-09-22T16:44:09Z
[ "python", "python-3.x", "tkinter" ]
Python appending from previous for loop iteration
39,643,780
<p>I have a very simple but annoying problem. I am reading in a list of files one by one whose names are stored in an ascii file ("file_input.txt") and performing calculations on them. My issue is that when I print out the result of the calculation ("print peak_wv, peak_flux" in the script below) it appends the previou...
0
2016-09-22T16:00:33Z
39,644,803
<p>Based on your comment I believe the issue is that you are appending the data with each new file. You probably want to clear wv and flux for each new file. For example:</p> <pre><code>for j in range(len(fits)): wv = [] flux = [] f = open("%s"%(fits[j]),"r") </code></pre> <hr> <p>Edit: I should also p...
0
2016-09-22T16:56:24Z
[ "python" ]
Python function calling
39,643,806
<p>I've only started learning Python. If I wrote:</p> <pre><code>def questions(): sentence= input(" please enter a sentence").split() </code></pre> <p>How would I end the function If the user didn't input anything and just hit enter </p>
0
2016-09-22T16:02:16Z
39,643,936
<pre><code>def questions(): sentence= input(" please enter a sentence").split() if sentence == []: #This is what happens when nothing was entered else: #This happens when something was entered </code></pre>
1
2016-09-22T16:08:19Z
[ "python" ]
Python function calling
39,643,806
<p>I've only started learning Python. If I wrote:</p> <pre><code>def questions(): sentence= input(" please enter a sentence").split() </code></pre> <p>How would I end the function If the user didn't input anything and just hit enter </p>
0
2016-09-22T16:02:16Z
39,643,940
<p>You can add exception in your code. If you want to raise an exception only on the empty string, you'll need to do that manually:</p> <p>Example</p> <pre><code> try: input = raw_input('input: ') if int(input): ...... except ValueError: if not input: raise ValueError('empty string') e...
0
2016-09-22T16:08:33Z
[ "python" ]
Python function calling
39,643,806
<p>I've only started learning Python. If I wrote:</p> <pre><code>def questions(): sentence= input(" please enter a sentence").split() </code></pre> <p>How would I end the function If the user didn't input anything and just hit enter </p>
0
2016-09-22T16:02:16Z
39,643,955
<p>Did you test this? The function will work properly if the user simply hits <kbd>Enter</kbd>. The <code>sentence</code> variable would be an empty list. If there was nothing else in the function, it would return <code>None</code>, the default return value. If you wanted to do further processing that requires an actua...
1
2016-09-22T16:09:32Z
[ "python" ]
gRPC client side load balancing
39,643,841
<p>I'm using gRPC with Python as client/server inside kubernetes pods... I would like to be able to launch multiple pods of the same type (gRPC servers) and let the client connect to them (randomly).</p> <p>I dispatched 10 pods of the server and setup a 'service' to target them. Then, in the client, I connected to the...
1
2016-09-22T16:03:39Z
39,644,962
<p>If you've created a vanilla Kubernetes service, the service should have its own load-balanced virtual IP (check if <code>kubectl get svc your-service</code> shows a <code>CLUSTER-IP</code> for your service). If this is the case, DNS caching should not be an issue, because that single virtual IP should be splitting t...
0
2016-09-22T17:06:00Z
[ "python", "http", "dns", "kubernetes", "grpc" ]
gRPC client side load balancing
39,643,841
<p>I'm using gRPC with Python as client/server inside kubernetes pods... I would like to be able to launch multiple pods of the same type (gRPC servers) and let the client connect to them (randomly).</p> <p>I dispatched 10 pods of the server and setup a 'service' to target them. Then, in the client, I connected to the...
1
2016-09-22T16:03:39Z
39,756,233
<p>Let me take the opportunity to answer by describing how things are supposed to work.</p> <p>The way client-side LB works in the gRPC C core (the foundation for all but the Java and Go flavors or gRPC) is as follows (the authoritative doc can be found <a href="https://github.com/grpc/grpc/blob/master/doc/load-balanc...
3
2016-09-28T19:37:06Z
[ "python", "http", "dns", "kubernetes", "grpc" ]
Automatic installation of dependencies when publishing Python 3 project on pypi
39,643,861
<p>I want to publish a project using pypi. Ideally I would like the installation to be: </p> <pre><code>sudo pip3 install ProjectName </code></pre> <p>The problem is, I get:</p> <blockquote> <p>Could not find any downloads that satisfy the requirement itsdangerous (from ProjectName) Some insecure and unveri...
0
2016-09-22T16:04:30Z
39,652,320
<h2>To install</h2> <p>Update your <code>~/.config/pip/pip.conf</code> and/or <code>/etc/pip.conf</code>. </p> <p>Append the test repository to the <code>--find-links</code> option:</p> <pre><code>[install] find-links = https://pypi.python.org/pypi https://testpypi.python.org/pypi </code></pre> <p>The order...
1
2016-09-23T03:54:39Z
[ "python", "pip", "pypi" ]
Python can open file, PL/Python can't
39,643,998
<p>Connected to mydb in PostgreSQL:</p> <pre><code>mydb=# CREATE FUNCTION file_test () RETURNS text AS $$ if open('mydir/myfile.xsl'): return 'success' $$ LANGUAGE plpythonu; CREATE FUNCTION mydb=# SELECT file_test(); ERROR: IOError: [Errno 2] No such file or directory: 'mydir/myfile.xsl' CONTEXT: Traceback (most r...
0
2016-09-22T16:11:23Z
39,645,021
<p>At @hruske's suggestion I used <code>plpy.notice(os.path.abspath('mydir/myfile.xsl'))</code> to see how PL/Python was trying to resolve the path. It was <code>/var/lib/postgresql/9.5/main/mydir/myfile.xsl</code>, which was obviously not what I had in mind.</p> <p>The absolute path worked after all. Copying the file...
0
2016-09-22T17:08:58Z
[ "python", "postgresql", "xslt", "plpython" ]