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
Why I can't instantiate a instance in the same module?
38,989,481
<p>Suppose my module is <code>myclass.py</code>, and here is the code:</p> <pre><code>#!/usr/bin/env python # coding=utf-8 class A(object): b = B() def __init__(self): pass class B(object): pass </code></pre> <p>and import it</p> <pre><code>In [1]: import myclass -------------------------------...
2
2016-08-17T06:27:00Z
38,993,358
<p>Is there any good reason to do what you are doing? In general this is quite dangerous pattern in Python.</p> <p>In your case</p> <pre><code>class A(object): b = B() def __init__(self): pass </code></pre> <p>You are binding an instance of B to the class A, which means that every instance of class A...
0
2016-08-17T09:54:43Z
[ "python" ]
celery launches more processes than configured
38,989,533
<p>I'm running a celery machine, using redis as the broker with the following configuration:</p> <pre><code>celery -A project.tasks:app worker -l info --concurrency=8 </code></pre> <p>When checking the number of celery running processes, I see more than 8.</p> <p>Is there something that I am missing? Is there a limi...
0
2016-08-17T06:30:29Z
38,989,780
<p>For the concurrency problem, I have no suggestion.</p> <p>For the memory problem, you can look at redis configuration in <code>~/.redis/redis.conf</code>. You have a <code>maxmemory</code> attribute which fix a limit upon tasks…</p> <p>See the <a href="http://redis.io/topics/config" rel="nofollow">Redis configur...
0
2016-08-17T06:43:38Z
[ "python", "celery" ]
celery launches more processes than configured
38,989,533
<p>I'm running a celery machine, using redis as the broker with the following configuration:</p> <pre><code>celery -A project.tasks:app worker -l info --concurrency=8 </code></pre> <p>When checking the number of celery running processes, I see more than 8.</p> <p>Is there something that I am missing? Is there a limi...
0
2016-08-17T06:30:29Z
38,994,438
<p>With the default settings Celery will always start one more process than the number you ask. This additional process is a kind of bookkeeping process that is used to coordinate the other processes that are part of the worker. It communicates with the rest of Celery, and dispatches the tasks to the processes that act...
0
2016-08-17T10:44:19Z
[ "python", "celery" ]
Python2 and Python3 both in windows 10
38,989,589
<p>I used Anaconda for python.</p> <p>python2 is installed in <code>D:\Python\Anaconda2</code></p> <p>python3 is installed in <code>D:\Python\Anaconda3</code></p> <p>python3 is the default.</p> <p>created two environmental variables with name: <code>python2</code> and <code>python2</code> and selected respect...
0
2016-08-17T06:33:57Z
38,989,865
<p>I'm not sure whether this directly answers your question,but anaconda manages environments for you. <a href="http://conda.pydata.org/docs/using/envs.html" rel="nofollow">Reference</a></p> <p>You should be able to type into your Anaconda prompt to create your environment:</p> <pre><code>conda create --name pyenv py...
1
2016-08-17T06:48:02Z
[ "python", "windows", "anaconda" ]
Quick Sort in python with last element as pivot
38,989,629
<p>I have successfully tested my code.It works with last element as pivot. However, when i try to count the total no. of comparisons made, it shows incorrect count. I am counting through the global variable <strong>tot_comparisons</strong>.</p> <p>Suggestions,where am i going wrong ? Is there some silly error that i a...
0
2016-08-17T06:35:54Z
38,990,584
<p>I checked that your quicksort works, though it's slightly different from the algorithm given in popular algorithmic texts, in which the last element is switched to the first and then the partitioning ensues. This may change the ordering of the sort which has an effect on the number of comparisons.</p> <p>For exampl...
1
2016-08-17T07:29:15Z
[ "python", "recursion", "quicksort" ]
Quick Sort in python with last element as pivot
38,989,629
<p>I have successfully tested my code.It works with last element as pivot. However, when i try to count the total no. of comparisons made, it shows incorrect count. I am counting through the global variable <strong>tot_comparisons</strong>.</p> <p>Suggestions,where am i going wrong ? Is there some silly error that i a...
0
2016-08-17T06:35:54Z
38,991,390
<p>I would suggest you to declare global variable at the top of your script, check this working basic example:</p> <pre><code>inside = 0 def qsort(l): global inside inside += 1 if len(l) &lt;= 1: return l pivot = l[-1] return qsort(filter(lambda x: x &lt; pivot, l[:-1])) + [pivot] + qsort(f...
0
2016-08-17T08:13:50Z
[ "python", "recursion", "quicksort" ]
Why can a lambda for collections.defaultdict have no arguments?
38,989,635
<p>In python I have the following line of code:</p> <pre><code>my_var = collections.defaultdict(lambda: collections.defaultdict(collections.defaultdict(float))) </code></pre> <p>I don't understand what it is doing. One of the things I don't understand is how we have not specified any variables for the lambda function...
-2
2016-08-17T06:36:05Z
39,000,442
<p>The <em><code>default_factory</code></em> argument to <code>defaultdict</code> should be a function that doesn't accept any arguments which creates and returns an object which will become the value of any non-existent entries that get referenced.</p> <p>One way to provide such a function is to create an anonymous o...
3
2016-08-17T15:14:18Z
[ "python", "lambda" ]
Overriding __iadd__ in python for fractions
38,989,665
<p>I am trying to override the <code>__iadd__</code> method in python with fractions, now this is what I did. Please could some one check to see if I did it right. I have <a href="https://stackoverflow.com/questions/1047021/overriding-in-python-iadd-method">this</a> and <a href="https://stackoverflow.com/questions/3551...
0
2016-08-17T06:37:53Z
38,990,010
<ul> <li>Use <code>__iadd__</code> to increment in-place.</li> <li>Use <code>__add__</code> to increment and create a new instance.</li> </ul> <p>So, you can change your code as follow.</p> <pre><code>def __iadd__(self, other): self.num = self.num * other.den + self.den * other.num self.den = self.den * other...
2
2016-08-17T06:57:02Z
[ "python", "magic-methods" ]
How to create non linear axis in plot
38,989,667
<p>I'm using matplotlib to plot a series of datas and get a result as below</p> <p><a href="http://i.stack.imgur.com/TmB2a.png" rel="nofollow"><img src="http://i.stack.imgur.com/TmB2a.png" alt="enter image description here"></a></p> <p>But I'm expecting to have a non linear axis as below.</p> <p><a href="http://i.st...
0
2016-08-17T06:38:07Z
38,989,812
<p>You can set the y-axis to logaritmic by writing <code>plt.yscale('log')</code></p> <p>full example:</p> <pre><code>import matplotlib.pyplot as plt example = [pow(2,i) for i in range(10)] plt.plot(example) plt.yscale('log') plt.show() </code></pre>
3
2016-08-17T06:45:11Z
[ "python", "matplotlib" ]
How to create non linear axis in plot
38,989,667
<p>I'm using matplotlib to plot a series of datas and get a result as below</p> <p><a href="http://i.stack.imgur.com/TmB2a.png" rel="nofollow"><img src="http://i.stack.imgur.com/TmB2a.png" alt="enter image description here"></a></p> <p>But I'm expecting to have a non linear axis as below.</p> <p><a href="http://i.st...
0
2016-08-17T06:38:07Z
38,989,923
<p>You can use <code>plt.semilogy</code>:</p> <pre><code>import matplotlib.pyplot as plt plt.semilogy([i**2 for i in range(100)]) plt.show() </code></pre> <p>Result:</p> <p><a href="http://i.stack.imgur.com/5Sv0b.png" rel="nofollow"><img src="http://i.stack.imgur.com/5Sv0b.png" alt="enter image description here"></...
2
2016-08-17T06:50:57Z
[ "python", "matplotlib" ]
How to install scikit -learn
38,989,896
<p>I do no how to install external modules So far i came to know that we can use pip command to install But for scikit -learn we need to install numpy and matplotlib </p> <p>I need some body to help on this how to install these modules using pip command</p>
0
2016-08-17T06:49:29Z
38,990,089
<p>Using Python 3.4, I run the following from the command line:</p> <p>c:\python34\python.exe -m pip install package_name</p> <p>So you would substitute "numpy" and "matplotlib" for 'package_name'</p>
0
2016-08-17T07:01:53Z
[ "python", "windows", "scikit-learn" ]
Execute python script from C
38,989,905
<p>As part of my C code I run python script,(one of the .dll files runs the script)</p> <pre><code>getcwd(directory); ret_value = ShellExecute(NULL,NULL,"myScript.py",NULL,directory,0); </code></pre> <p>This is the folder of the program after build.</p> <p>If I run the .exe from the folder every thing works.</p> <p...
0
2016-08-17T06:50:01Z
39,041,564
<p>GetModuleFileNameW() function retrieves the fully qualified path for the file that contains the specified module. This way you can find absolute path of the .dll and use _chdir and change the current working directory to that path.</p>
1
2016-08-19T14:28:51Z
[ "python", "c" ]
Iteration input and update on dictionary python
38,989,964
<p>Keys of dictionay <strong><em>y</em></strong></p> <p>I have dictionary <strong>x</strong></p> <pre><code>x = {1 :'a', 2 :'b', 3 :'c', 4 :'d', 5 :'e'} </code></pre> <p>The program displays these as choices. Next, the user selects one to update, and then enters a value. The program is supposed to add this value t...
-1
2016-08-17T06:53:39Z
39,047,696
<p>This program does have its problems. First of all, a dictionary is overkill for your menu of choices. Since you never change it, you can simply hard-code the choices and print the list each time.</p> <p>Your <strong>y</strong> dictionary is a collection of running sums -- accumulations -- for the five items. You...
0
2016-08-19T21:08:14Z
[ "python", "dictionary", "while-loop" ]
python bracket notation for dict to setitem method
38,990,054
<p>I know that for a <strong>dict</strong> D in python,</p> <pre><code>D = {0:1, 1: {2:3} } D[0] = 1 </code></pre> <p>is equivalent to </p> <pre><code>D.__setitem__(0,1) </code></pre> <p>what about below</p> <pre><code>D[1][3] = 4 </code></pre> <p>although it's equivalent to</p> <pre><code>D[1].__setitem__(3,4) ...
0
2016-08-17T06:59:26Z
38,990,098
<p>It'll be like this: <code> D.__getitem__(1).__setitem__(3,4) </code></p> <p>Note that <code>__setitem__</code> called not for <code>D</code> variable, but for valirable retured by <code>__getitem__</code></p>
1
2016-08-17T07:02:21Z
[ "python", "dictionary" ]
python bracket notation for dict to setitem method
38,990,054
<p>I know that for a <strong>dict</strong> D in python,</p> <pre><code>D = {0:1, 1: {2:3} } D[0] = 1 </code></pre> <p>is equivalent to </p> <pre><code>D.__setitem__(0,1) </code></pre> <p>what about below</p> <pre><code>D[1][3] = 4 </code></pre> <p>although it's equivalent to</p> <pre><code>D[1].__setitem__(3,4) ...
0
2016-08-17T06:59:26Z
38,990,167
<p>Another way, if you absolutely must avoid bracket notation for some reason:</p> <pre><code>&gt;&gt;&gt; D.get(1).update([(3,4)]) &gt;&gt;&gt; D {0: 1, 1: {2: 3, 3: 4}} </code></pre>
1
2016-08-17T07:06:20Z
[ "python", "dictionary" ]
How to deal with data with pandas without influencing nan?
38,990,192
<p>I have a string series with some nan, and I want to replace some characters and then turn it into int(float is ok) but nan still remain nan. Like </p> <pre><code>In[1]:df = pd.DataFrame(["type 12", None, "type13"], columns=['A']) Out[1]: A 0 12 1 NaN 2 13 </code></pre> <p>Is there any good way to do it?</p>
-3
2016-08-17T07:08:01Z
38,990,508
<p>No, unfortunately. You will have to settle for <code>floats</code>. </p> <pre><code>&gt;&gt;&gt; s = pd.Series(['1', '2', '3', '4', '5'], index=list('abcde')) &gt;&gt;&gt; s a 1 b 2 c 3 d 4 e 5 dtype: object &gt;&gt;&gt; s = s.reindex(['a','b','c','f','u']) &gt;&gt;&gt; s a 1 b 2 c 3 f...
1
2016-08-17T07:25:12Z
[ "python", "pandas" ]
Writing string to file from loop if does not already exist
38,990,204
<p>This has been asked and answered, and I've read lots of those posts... but for some reason my code isn't working. Hopefully someone can help.</p> <p>The code matches strings within a variable and then attempts to write those strings to a file if they don't already exist within that file. </p> <p>Code doesn't wor...
0
2016-08-17T07:08:48Z
38,990,592
<p>Problem is you are iterating through the file once, and file is not rewound afterwards. File is only scanned once.</p> <p>You have to read the data into a <code>set</code> first, then you can loop over the strings (and <code>set</code> is very performant because uses dichotomic search in O(log(N)))</p> <p>Problem:...
2
2016-08-17T07:29:52Z
[ "python" ]
Writing string to file from loop if does not already exist
38,990,204
<p>This has been asked and answered, and I've read lots of those posts... but for some reason my code isn't working. Hopefully someone can help.</p> <p>The code matches strings within a variable and then attempts to write those strings to a file if they don't already exist within that file. </p> <p>Code doesn't wor...
0
2016-08-17T07:08:48Z
38,990,622
<p>The problem here is that files don't (really) support membership tests with the <code>in</code> operator.</p> <p>The reason why no error is thrown is because files are iterable and thus <code>x in file</code> evaluates to <code>any(x is e or x == e for e in file)</code> (<a href="https://docs.python.org/3/reference...
3
2016-08-17T07:31:40Z
[ "python" ]
Python: issue while trying to print a string
38,990,457
<pre><code>import os from os import path import datetime from datetime import date, time, timedelta import time def main(): # Print the name of the OS print(os.name) # Check for item existence and type print("Item exists: " + (str(path.exists("textfile.txt")))) #print("Item is a file: " + str(pat...
0
2016-08-17T07:22:42Z
38,990,544
<p>According to the error you got, somewhere in your code (which doesn't appear in your post) you assigned to <code>str</code>...</p> <p><strong>ADDED</strong> after reading comments:</p> <p>This code runs fine. Maybe you run it from an IDE like spyder, where it remembers vars you assigned earlier in the shell or in ...
5
2016-08-17T07:27:26Z
[ "python", "printing" ]
Django send mail and sms after 6 hours of user sign up
38,990,472
<p>I am using django 1.9. I am working on requirement where we need to send users reminder to activate their account by email after x hours h/she has signed on our platform.</p> <p>I have send_mail task and I have configured <a href="https://github.com/ui/django-rq" rel="nofollow">Django RQ</a> to send mails. </p> <p...
0
2016-08-17T07:23:21Z
38,992,398
<p>Looking at the django-rq documentation, if you have both <code>django-rq</code> and <code>rq-scheduler</code> installed, it seems you don't need to create a periodic job. Just schedule your job during sign on. </p> <pre><code># From django-rq docs import django_rq # Select the queue you want to use, here it uses ...
1
2016-08-17T09:08:36Z
[ "python", "django", "email" ]
How to combine two columns to make a third column taking property from group by method?
38,990,565
<p>I don't know if I can ask this question clearly, but here I try! </p> <p>I have a classification problem in which I have to predict a person's credit score based on his income group. I have used this code:</p> <pre><code>dta.groupby(['income_bracket'])['credit_score'].get_values() </code></pre> <p>Now I have a d...
1
2016-08-17T07:28:12Z
38,990,735
<p>You need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.DataFrameGroupBy.idxmax.html" rel="nofollow"><code>idxmax</code></a> for get <code>index</code> values per group which max value in <code>val</code> and then select these rows by <a href="http://pandas.pydata.org/pandas-docs/...
1
2016-08-17T07:38:33Z
[ "python", "pandas", "indexing", "group-by", "max" ]
What is the best way to evaluate whether a string is a stringified dictionary or not
38,990,616
<p>I could use a regex, but am wondering if there is a better way.</p> <p>For example, a value might be returned either as:</p> <p>1.) <code>'{"username": "joe.soap", "password": "pass@word123"}'</code></p> <p>or</p> <p>2.) <code>'https://www.url-example.com'</code></p> <p>In the case of 1.) I want to convert the ...
3
2016-08-17T07:31:23Z
38,990,684
<p>Don't bother with a complex regex, simply try to convert the string to a dictionary.</p> <p>I'm assuming you are using <code>json.loads</code> to do it. If the string doesn't represent a dictionary <code>json.loads</code> will raise an exception.</p> <p>Note that if you do use <code>json.loads</code> the conversio...
8
2016-08-17T07:35:50Z
[ "python", "dictionary" ]
History on spyder kills the kernel
38,990,620
<p>My spyder has worked for month but it has suddenly stopped working. Here is the internal log.</p> <pre><code>/Users/Name_User/anaconda/lib/python2.7/site-packages/nbformat/current.py:19: UserWarning: nbformat.current is deprecated. - use nbformat for read/write/validate public API - use nbformat.vX directly to com...
0
2016-08-17T07:31:37Z
39,011,842
<p>The cause of this is that the history file somehow got truncated or otherwise corrupted. The history file is called <code>history.py</code> and it is in the spyder configuration directory, which is <code>/Users/Name_User/.spyder2</code> or similar. To solve that problem one needs to remove that file. </p>
0
2016-08-18T07:03:05Z
[ "python", "kernel", "anaconda", "spyder" ]
Using p5's functions without the setup/draw format
38,990,679
<p>I'm relatively new to Javascript, and i was tinkering around with the <a href="https://p5js.org/" rel="nofollow">p5</a> library. In Python i can import a single function from a library using the <code>from x import y statement</code>:</p> <pre><code>from subprocess import check_output </code></pre> <p>My question ...
1
2016-08-17T07:35:22Z
38,997,669
<p>With questions like this, it's best to just put together a super simple test to try things out:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;title&gt;Noise Test&lt;/title&gt; &lt;script src="p5.js" type="text/javascript"&gt;&lt;/script&gt; &lt;scr...
2
2016-08-17T13:12:36Z
[ "javascript", "python", "import", "p5.js" ]
openCV 3.1.0 Cannot load .dat
38,990,723
<p>I moved from python 2.7 to python 3.5</p> <p>So, I had to use openCV 3.x.x.</p> <p>The problem is that I cannot load SVM data.</p> <p>For openCV 2.x.x, I could use</p> <pre><code>svm.load('filename') </code></pre> <p>However, for openCV 3.x.x, there is no load method.</p> <p>I read <a href="http://stackoverflo...
0
2016-08-17T07:37:46Z
38,991,733
<p>Ok.. Additional infos to my <a href="http://stackoverflow.com/a/38956656/3524844">answer</a>:</p> <p>Use the opencv master branch (currently 3.1.0-dev) of opencv </p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; import cv2 &gt;&gt;&gt; cv2.__version__ '3.1.0-dev' </code></pre> <p>there is the <a h...
0
2016-08-17T08:32:29Z
[ "python", "opencv" ]
How to resolve attribute error in python
38,991,025
<p>on the begin I'll say that I was looking for the answer but can't find it and sorry for so basic question.I created program with TTS. I created global variable called "list_merge", but most of you said that global variables are BAD. So I decided to put this list in init. PS. ignore whitespaces, they exist only becau...
0
2016-08-17T07:54:39Z
38,991,145
<p>You have to set if first before you use it:</p> <pre><code>class Ver2ProjectWithTTS(object): def __init__(self): # first set it self.list_merge = [] self.read_json_file() self.read_xml_file() self.say_something() </code></pre> <p>Anyway don't do any advanced logic in co...
3
2016-08-17T08:01:25Z
[ "python", "python-2.7", "object", "text-to-speech" ]
Pytest assert of returned value from method
38,991,156
<p>This is works as expected:</p> <pre><code>def my_method(): return True; def test_method(): assert my_method() </code></pre> <p>But this not:</p> <pre><code>assert filecmp.cmp(path1, path2) </code></pre> <p>Instead I get:</p> <pre><code>AssertionError: assert &lt;function cmp at 0x1042db840&gt;((((('/Us...
1
2016-08-17T08:01:54Z
38,991,224
<p>Everything seems right. This looks like the regular py.test output if an <code>assert</code> was not fulfilled.</p> <p>Are <code>path1</code> and <code>path2</code> really equal? Try</p> <pre><code>assert filecmp.cmp(path1, path1) </code></pre> <p>to see if the <code>assert</code> statement itself works.</p>
1
2016-08-17T08:05:52Z
[ "python", "python-3.x", "py.test" ]
django:OperationalError at /admin/login/ unable to open database file
38,991,164
<p>I deploy my django project in iis6.When i login in the admin-page using the superuser name and password,it produce mistakes as follows:</p> <pre><code>enter code here Environment: Request Method: POST Request URL: http://localhost/admin/login/?next=/admin/ Django Version: 1.9.6 Python Version: 2.7.11 Installed A...
-1
2016-08-17T08:02:17Z
38,991,299
<p>Use slashes instead of backslashes in the db file path <a href="https://docs.djangoproject.com/en/1.10/ref/settings/#name" rel="nofollow">as is stated here</a>.</p>
2
2016-08-17T08:09:25Z
[ "python", "django", "windows", "iis-6" ]
Use a for loop/ accumulator pattern
38,991,168
<p>How to write a function emphasize() that takes as an input a string s and print it with spaces inserted between adjacent letters. This is what I tried</p> <pre><code>def emphasize (s): for aWord in s: print(s.replace [1:-1]) </code></pre>
0
2016-08-17T08:02:38Z
38,991,463
<p>You can use <a href="https://docs.python.org/3/library/stdtypes.html#str.join" rel="nofollow">.join</a> to </p> <pre><code>def emphasize(s): print(" ".join(s)) </code></pre>
1
2016-08-17T08:17:53Z
[ "python", "string" ]
Numpy Softmax - The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
38,991,216
<p>I am using a softmax function in getting an output from a neural network and getting the minimum value as the output in calculating the error.</p> <p>However if the output is all the same assuming [0,0,0] the output of the softmax function is [0.33,0.33,0.33]</p> <p>So when selecting the minimum from this like, </...
0
2016-08-17T08:05:27Z
39,022,221
<p>The answer's buried in the comments above: your error is likely the result of passing a multi-dimensional ndarray to the standard python min(), which doesn't understand them.</p> <p>Way #1: call np.min instead of min</p> <p>Way #2 (not recommended): flatten your array, min(tarminout.ravel())</p> <p>Way #1 is pref...
0
2016-08-18T15:33:40Z
[ "python", "arrays", "numpy" ]
How to query XML node using ElementTree in python
38,991,456
<p>I have the following example XML tree:</p> <pre><code>&lt;main&gt; &lt;section&gt; &lt;list key="capital" value="sydney"&gt; &lt;items&gt; &lt;item id="abc-123"&gt;&lt;/item&gt; &lt;item id="abc-345"&gt;&lt;/item&gt; &lt;/items&gt; &lt;/list&gt; &lt;list key="c...
0
2016-08-17T08:17:34Z
38,991,582
<p>You can use XPath expression that <code>xml.etree</code> supports (see <a href="https://docs.python.org/2/library/xml.etree.elementtree.html#supported-xpath-syntax" rel="nofollow">the documentation</a>) via <code>find()</code> or <code>findall()</code> method :</p> <pre><code>from xml.etree import ElementTree as ET...
0
2016-08-17T08:24:30Z
[ "python", "xml", "extract", "elementtree" ]
python - upload image into directory, save it and rename it
38,991,461
<p>I want to upload an image "camera.jpg" and save it to "static/photo/" directory and then rename the "camera.jpg" file to "niloofar.jpg" file.</p> <p>How can I do that?</p> <p><strong>app.py:</strong></p> <pre><code>from flask import Flask, request, url_for, render_template, make_response, redirect from flask_sqla...
0
2016-08-17T08:17:43Z
38,991,671
<p>Try giving the complete target path in <code>os.rename</code>. </p> <p><code>os.rename(UPLOAD_FOLDER + filename, UPLOAD_FOLDER+'niloofar.jpg')</code></p>
1
2016-08-17T08:29:18Z
[ "python", "file", "upload", "save", "rename" ]
Handling Bounce in Sendgrid smtp API in Python
38,991,472
<p>I am sending marketing emails through sendgrid smtp api via python EmailMultiAlternatives. I want to know how can I handle bounces directly from there to mark particular emails as undeliverable.</p> <p>The code snippet is:</p> <pre><code>def send1(): text_content = 'Hi this is the text version' connection ...
0
2016-08-17T08:18:30Z
39,147,370
<p>The best way to respond to events like blocks and bounces is to implement the <a href="https://sendgrid.com/docs/API_Reference/Webhooks/event.html" rel="nofollow">event webhook</a>.</p> <p>You can also poll for the data via the <a href="https://sendgrid.com/docs/API_Reference/Web_API_v3/bounces.html" rel="nofollow"...
0
2016-08-25T13:59:10Z
[ "python", "email", "smtp", "sendgrid" ]
Remove first encountered elements from a list
38,991,478
<p>I have two Python lists with the same number of elements. The elements of the first list are unique, the ones in the second list - not necessarily so. For instance</p> <pre><code>list1 = ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7'] list2 = ['h1', 'h2', 'h1', 'h3', 'h1', 'h2', 'h4'] </code></pre> <p>I want to remove ...
12
2016-08-17T08:18:46Z
38,991,619
<p>Here: </p> <pre><code>list1 = ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7'] list2 = ['h1', 'h2', 'h1', 'h3', 'h1', 'h2', 'h4'] seen = [] output = [] for index in range(len(list1)): if list2[index] not in seen: seen.append(list2[index]) else: output.append(list1[index]) print output </code></p...
2
2016-08-17T08:26:18Z
[ "python", "list" ]
Remove first encountered elements from a list
38,991,478
<p>I have two Python lists with the same number of elements. The elements of the first list are unique, the ones in the second list - not necessarily so. For instance</p> <pre><code>list1 = ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7'] list2 = ['h1', 'h2', 'h1', 'h3', 'h1', 'h2', 'h4'] </code></pre> <p>I want to remove ...
12
2016-08-17T08:18:46Z
38,991,663
<p>An efficient way would be to use a <code>set</code>, which contains all already seen keys. A <code>set</code> will guarantee you an average lookup of <code>O(1)</code>. </p> <p>So something like this should work:</p> <pre><code>s = set() result1 = [] result2 = [] for x, y in zip(list1, list2): if y in s: ...
7
2016-08-17T08:28:53Z
[ "python", "list" ]
Remove first encountered elements from a list
38,991,478
<p>I have two Python lists with the same number of elements. The elements of the first list are unique, the ones in the second list - not necessarily so. For instance</p> <pre><code>list1 = ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7'] list2 = ['h1', 'h2', 'h1', 'h3', 'h1', 'h2', 'h4'] </code></pre> <p>I want to remove ...
12
2016-08-17T08:18:46Z
38,991,667
<p>Just use a <code>set</code> object to lookup if the current value is already seen, like this</p> <pre><code>&gt;&gt;&gt; list1 = ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7'] &gt;&gt;&gt; list2 = ['h1', 'h2', 'h1', 'h3', 'h1', 'h2', 'h4'] &gt;&gt;&gt; &gt;&gt;&gt; def filterer(l1, l2): ... r1 = [] ... r2 = [] ...
10
2016-08-17T08:29:09Z
[ "python", "list" ]
Remove first encountered elements from a list
38,991,478
<p>I have two Python lists with the same number of elements. The elements of the first list are unique, the ones in the second list - not necessarily so. For instance</p> <pre><code>list1 = ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7'] list2 = ['h1', 'h2', 'h1', 'h3', 'h1', 'h2', 'h4'] </code></pre> <p>I want to remove ...
12
2016-08-17T08:18:46Z
38,991,697
<p>Use a set to keep track of values you've already encountered:</p> <pre><code>seen= set() index= 0 while index &lt; len(list1): i1, i2= list1[index], list2[index] if i2 in seen: index+= 1 else: seen.add(i2) del list1[index] del list2[index] </code></pre>
4
2016-08-17T08:30:39Z
[ "python", "list" ]
Remove first encountered elements from a list
38,991,478
<p>I have two Python lists with the same number of elements. The elements of the first list are unique, the ones in the second list - not necessarily so. For instance</p> <pre><code>list1 = ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7'] list2 = ['h1', 'h2', 'h1', 'h3', 'h1', 'h2', 'h4'] </code></pre> <p>I want to remove ...
12
2016-08-17T08:18:46Z
38,991,706
<p>I might be code golfing here but i find this interesting:</p> <pre><code>list1_new = [x for i, x in enumerate(list1) if list2[i] in list2[:i]] print(list1_new) # prints ['e3', 'e5', 'e6'] </code></pre> <p>What happens here in case you are not familiar with list comprehensions is the following (reading it from the ...
7
2016-08-17T08:31:03Z
[ "python", "list" ]
Remove first encountered elements from a list
38,991,478
<p>I have two Python lists with the same number of elements. The elements of the first list are unique, the ones in the second list - not necessarily so. For instance</p> <pre><code>list1 = ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7'] list2 = ['h1', 'h2', 'h1', 'h3', 'h1', 'h2', 'h4'] </code></pre> <p>I want to remove ...
12
2016-08-17T08:18:46Z
38,991,920
<p>You an try :</p> <pre><code>&gt;&gt;&gt; list1 = ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7'] &gt;&gt;&gt; list2 = ['h1', 'h2', 'h1', 'h3', 'h1', 'h2', 'h4'] &gt;&gt;&gt; repeat = list(set([x for x in list2 if list2.count(x) &gt; 1])) &gt;&gt;&gt; print repeat ['h2', 'h1'] &gt;&gt;&gt; l1=[] &gt;&gt;&gt; l2=[] &gt;&...
3
2016-08-17T08:43:52Z
[ "python", "list" ]
Remove first encountered elements from a list
38,991,478
<p>I have two Python lists with the same number of elements. The elements of the first list are unique, the ones in the second list - not necessarily so. For instance</p> <pre><code>list1 = ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7'] list2 = ['h1', 'h2', 'h1', 'h3', 'h1', 'h2', 'h4'] </code></pre> <p>I want to remove ...
12
2016-08-17T08:18:46Z
38,996,607
<p>From a comment:</p> <blockquote> <p>I was hoping to avoid that and edit the lists in place</p> </blockquote> <p>I don't really advise doing this unless your code actually is running out of memory (or you reasonably expect that it will), but it's certainly possible:</p> <pre><code>seen = set() toidx = 0 for firs...
4
2016-08-17T12:24:54Z
[ "python", "list" ]
Checking if a string is a prefix of a possible regex match
38,991,497
<p>I want to traverse a tree structure, but only those parts that match a wildcard expression, a la python glob, where double asterisk means 'any number of subdirs'.</p> <p>For example, say my wildcard expression is /*/foo/**/bar/. This would match /a/foo/bar/, /b/foo/note/bar/, but not /a/bar/foo/bar/. You get the id...
0
2016-08-17T08:19:59Z
38,991,987
<p>Consider the following code for starters. I assume you have each "directory" in the path and pattern as elements in a pair of lists:</p> <pre><code>def traverse(pattern_list, path_list): if pattern_list[0] == '**': traverse_children(pattern_list, path_list[1:]) if current_matches(pattern_list[0], pa...
0
2016-08-17T08:47:52Z
[ "python", "regex", "tree", "wildcard", "directory-structure" ]
Python get query from MySQL, remove the string format
38,991,558
<p>I'm currently using an example to select a variable from MySQL via Python. For this I'm using the MySQLdb import.</p> <p>It all works great, I'm able to get the value from MySQL but when I print the result, it returns as:</p> <pre><code>('text',) </code></pre> <p>Is there a way to get this to just show up as </p>...
0
2016-08-17T08:23:26Z
38,991,617
<p>Python 3 :</p> <pre><code>print(results[0]) </code></pre> <p>Python 2 :</p> <pre><code>print results[0] </code></pre> <p>This will take the first and only element of the tuple, which is <code>'text'</code>, and printing a string will just write <code>text</code> without quotes in the console.</p>
2
2016-08-17T08:26:11Z
[ "python", "mysql" ]
How to read data from a HTML table and create a csv in python
38,991,625
<p>I want to read the data from a url which gives an HTML table as output. After reading the data I need the data in the csv format, just like the page itself.</p> <p>Below mentioned is the HTML output.</p> <p><a href="http://i.stack.imgur.com/6Ky2m.jpg" rel="nofollow">enter image description here</a></p> <p>HTML So...
-3
2016-08-17T08:26:38Z
38,991,721
<p>I think you can combine these two StackOverflow answers to get what you need:</p> <p><a href="http://stackoverflow.com/questions/6325216/parse-html-table-to-python-list">html table -> python list</a></p> <p><a href="http://stackoverflow.com/questions/2084069/create-a-csv-file-with-values-from-a-python-list">python...
0
2016-08-17T08:31:39Z
[ "python", "html" ]
ImportError: name 'Restaurant' is not defined
38,991,637
<p>App that i am developing is about online food order. A restaurant owner lists his/her restaurant with menus available in that restaurant. I have designed the models for such scenario. But I am facing problem in my review models where i get an error of NameError: name 'Restaurant' is not defined while importing for R...
0
2016-08-17T08:27:18Z
38,991,927
<p>You probably have a circular import error; the models files are attempting to import each other, and Python can't resolve it.</p> <p>Note that there is no need to import the actual model if all you want to do is define a relationship; you can use a string value instead. Remove the import from review.models and do t...
0
2016-08-17T08:44:25Z
[ "python", "django", "python-3.x", "django-models" ]
ImportError: name 'Restaurant' is not defined
38,991,637
<p>App that i am developing is about online food order. A restaurant owner lists his/her restaurant with menus available in that restaurant. I have designed the models for such scenario. But I am facing problem in my review models where i get an error of NameError: name 'Restaurant' is not defined while importing for R...
0
2016-08-17T08:27:18Z
38,993,459
<p>You need to add full path to restaurants into system path</p> <p>Add following code in review/models.py</p> <pre><code>import sys sys.path.append('&lt;full path to parent dir of restaurants&gt;') from restaurants.models import Restaurant </code></pre>
0
2016-08-17T09:59:07Z
[ "python", "django", "python-3.x", "django-models" ]
Making submodules visible to each other inside the same Python module
38,991,687
<p>Say I have a folder <code>Awesome_stuff/my_module</code> that contains the following files: <code>my_algorithm.py</code>, <code>my_settings.py</code>, <code>my_utils.py</code>. The main file <code>my_algorithm.py</code> contains the following lines:</p> <pre><code># my_algorithm.py import my_utils as mu from my_set...
2
2016-08-17T08:30:21Z
38,991,901
<p>Since you've added an <code>__init__.py</code> file, you've made a package. So now, you have to use that package name when importing from the package:</p> <pre><code># my_algorithm.py import my_module.my_utils as mu from my_module.my_settings import My_settings def alg(): # do something if __name__ == "__main...
3
2016-08-17T08:42:21Z
[ "python", "import", "module" ]
Python - How to check print outputs of multiple py files?
38,991,734
<p>I have a number of test cases in separate .py files that I want to test on a module I've created. All of these files use a py module that I've created and all these py files will print a pre-determined output (some in thousands of lines).</p> <p>Is there a way to run a .py script that runs these other test .py scri...
0
2016-08-17T08:32:34Z
38,991,930
<p>try this</p> <pre><code>import glob lst = glob.glob("/home/test/*.py") for each_file in lst: variables= {} #what ever variables to need run execfile(each_file, variables ) </code></pre>
1
2016-08-17T08:44:30Z
[ "python" ]
Python - How to check print outputs of multiple py files?
38,991,734
<p>I have a number of test cases in separate .py files that I want to test on a module I've created. All of these files use a py module that I've created and all these py files will print a pre-determined output (some in thousands of lines).</p> <p>Is there a way to run a .py script that runs these other test .py scri...
0
2016-08-17T08:32:34Z
38,992,068
<p>What you need to do is, you will invoke these scripts by </p> <p><code>subprocess.Popen(['python',file_name],universal_newlines=True,stdout=stdout, stderr=stderr)</code></p> <p>These <code>stdout</code>,<code>stderr</code> are all file objects, they will write the result into these files. Then you can use <code>sl...
1
2016-08-17T08:51:54Z
[ "python" ]
Using Google App Engine SDK for Python with Python 3
38,991,770
<p>I have both Python 3.5.2 and Python 2.7.12 Installed (On Windows). But when I try to deploy from Using Google App Engine SDK for Python, I receive this error message:</p> <pre><code>in &lt;module&gt; run_file(__file__, globals()) File "C:\Program Files (x86)\Google\google_appengine\appcfg.py", line 129, in ru...
1
2016-08-17T08:34:41Z
38,992,057
<p>You need to select the correct Python path, when you have multiple copies of Python the wrong path might be selected as the default. <br> Usually it's <code>C:\Python27\pythonw.exe</code> however it may be something else if you changed that during installation. <br> Go to the Google App Engine Launcher and change th...
1
2016-08-17T08:51:17Z
[ "python", "windows", "python-2.7", "python-3.x", "google-app-engine" ]
Scikit-learn and pyspark integration
38,991,799
<p>I have trained a logistic regression model in sklearn and saved the model to .pkl files. Is there a method of using this pkl file from within spark?</p>
0
2016-08-17T08:36:11Z
38,994,681
<p>The fact that you are using spark shouldn't hold you from using external python libraries.</p> <p>You can import sklearn library in your spark-python code, and use sklearn logistic regression model with the saved pkl file.</p>
0
2016-08-17T10:55:39Z
[ "python", "apache-spark", "scikit-learn", "pyspark" ]
Use existing open tab and url in Selenium py
38,991,897
<p>Hi I'm trying to use Selenium python to use a url that is already open on Internet Explorer. I had a look around and not sure if this is possible. </p> <p>The reason why I wouldn't like to open new brower or tab is because the page changes to different text.</p> <p>So far my text only opens a new browser <strong>C...
0
2016-08-17T08:42:01Z
38,999,589
<p><a href="http://stackoverflow.com/a/37274741/6335604">This answer</a> helped me with same problem.</p> <p>By now you can not access previously opened tabs with selenium. But you can try to recreate your session, passing what is needed using requests library, for example.</p>
0
2016-08-17T14:34:33Z
[ "python", "python-2.7", "python-3.x", "selenium", "selenium-webdriver" ]
Is there a way to add a parameter that supress the need of other parameters using argparse on Python?
38,991,939
<p>I am using Argparse on python to do a script on command line. I have this for my script:</p> <pre><code>parser = argparse.ArgumentParser(prog = 'manageAdam') parser.add_argument("-s", action='store_true', default=False, help='Shows configuration file') parser.add_argument("d", type=str, help="device") parser.add_a...
0
2016-08-17T08:44:56Z
38,992,060
<p>No, there are no such way.</p> <p>You can make all arguments optional and set default value to <code>None</code> then perform check that all of them aren't <code>None</code> otherwise raise <code>argparse.ArgumentError</code>, if <code>manageAdam</code> provided skip check for other arguments.</p>
0
2016-08-17T08:51:26Z
[ "python", "argparse" ]
Is there a way to add a parameter that supress the need of other parameters using argparse on Python?
38,991,939
<p>I am using Argparse on python to do a script on command line. I have this for my script:</p> <pre><code>parser = argparse.ArgumentParser(prog = 'manageAdam') parser.add_argument("-s", action='store_true', default=False, help='Shows configuration file') parser.add_argument("d", type=str, help="device") parser.add_a...
0
2016-08-17T08:44:56Z
38,992,632
<p>There is no built-in way to do this. You <em>might</em> be able to achieve something by writing some custom <a href="https://docs.python.org/3/library/argparse.html#argparse.Action" rel="nofollow"><code>Action</code></a> classes that keep track on the parser about their state, but I believe it will become quite mess...
1
2016-08-17T09:20:26Z
[ "python", "argparse" ]
Web Push notification Payload data is getting null
38,992,034
<p>Hi I'm trying to implement web push notification for web i followed the following <a href="https://serviceworke.rs/push-payload_index_doc.html" rel="nofollow">example</a>,except the server part for which i'm using python script to connect to gcm/fcm and generating payload .i'm getting the push event but the event.da...
0
2016-08-17T08:50:10Z
39,045,532
<p>Both, Google Chrome and Mozilla Firefox currently support payload for push messages, see <a href="https://developer.mozilla.org/ru/docs/Web/API/PushMessageData#Browser_compatibility" rel="nofollow">PushMessageData</a> on MDN. But according to the Push API specification, any payload MUST be encrypted, otherwise a bro...
0
2016-08-19T18:23:24Z
[ "python", "push-notification", "service-worker", "payload", "web-push" ]
How to convert blob to integer in python?
38,992,157
<p>I have some file with little-endian encoding bytes in it, I want to take <code>N</code> bytes, specify endianess and convert them into a decimal number using python (any version). How to do it correctly?</p>
0
2016-08-17T08:56:04Z
38,992,417
<p>In Python 3 you can use something like this:</p> <pre><code>int.from_bytes(byte_string, byteorder='little') </code></pre>
4
2016-08-17T09:09:30Z
[ "python", "endianness" ]
How to convert blob to integer in python?
38,992,157
<p>I have some file with little-endian encoding bytes in it, I want to take <code>N</code> bytes, specify endianess and convert them into a decimal number using python (any version). How to do it correctly?</p>
0
2016-08-17T08:56:04Z
38,992,523
<p>Using Python 3 (or 2), you can achieve this with the <a href="https://docs.python.org/3/library/struct.html" rel="nofollow">struct</a> library.</p> <pre><code>with open('blob.dat', 'rb') as f: data = f.read(n) </code></pre> <p>Now, you unpack using the appropriate <a href="https://docs.python.org/3/library/str...
0
2016-08-17T09:15:26Z
[ "python", "endianness" ]
How to convert blob to integer in python?
38,992,157
<p>I have some file with little-endian encoding bytes in it, I want to take <code>N</code> bytes, specify endianess and convert them into a decimal number using python (any version). How to do it correctly?</p>
0
2016-08-17T08:56:04Z
38,995,819
<p>As Harshad Mulmuley' answer shows, this is easy in Python 3, using the <code>int.from_bytes</code> method. In Python 2, it's a little trickier.</p> <p>The <code>struct</code> module is designed to handle standard C data types. It won't handle arbitrary length integers (Python 2 <code>long</code> integers), as these...
1
2016-08-17T11:49:26Z
[ "python", "endianness" ]
Azure SDK Python: tag a particular resource
38,992,201
<p>I want to create tag on each resource in Azure using python.</p> <p>I see this module in the docs: <a href="http://azure-sdk-for-python.readthedocs.io/en/latest/ref/azure.mgmt.resource.resources.operations.html#azure.mgmt.resource.resources.operations.TagsOperations" rel="nofollow">http://azure-sdk-for-python.readt...
0
2016-08-17T08:58:39Z
39,000,653
<p>If you are using the Python SDK, you can generally add tags to a resource using that resource's <code>create_or_update</code> method. These methods take an object called <code>parameters</code> which is generally the object type of the resource you are interested in. This is where you will find tags.</p> <p>For exa...
2
2016-08-17T15:24:39Z
[ "python", "azure", "azure-sdk-python" ]
Python Web Crawling on JQuery/ Json outputs
38,992,234
<p>I am wondering how can we crawl J Query / JSON outputs using Beautiful Soup or Selenium. Please have a look at <a href="https://www.udemy.com/courses/design/web-design/all-courses/" rel="nofollow">https://www.udemy.com/courses/design/web-design/all-courses/</a>.</p> <p>The left column gives number of Free and Paid ...
0
2016-08-17T09:00:36Z
38,992,343
<p>There is an easy way to do these, press F12 and you will see developer tab in chrome, in there you can see network tab from where you can track all the API calls made, I found <code>https://www.udemy.com/api-2.0/channels/1654/courses?is_angular_app=true&amp;lang=en</code> as the API you're looking for maybe.</p> <p...
-1
2016-08-17T09:05:49Z
[ "jquery", "python", "json", "beautifulsoup" ]
Tensorflow: Py_func returns unknown shape
38,992,445
<p>I have a simple question re the <code>tf.py_func</code> function.</p> <p>I have an image tensor <code>my_img</code> of shape <code>(1,224,224,3)</code>. To test <code>py_func</code>, I feed the tensor to a python function <code>return_tf</code> that should give back the same tensor (after being converted to a numpy...
1
2016-08-17T09:11:13Z
38,993,931
<p>Just found a work-around.. since py_func returns a tensorflow list, I can do the ff:</p> <pre><code>test = tf.reshape(tf.concat(1, test), [ &lt;&lt;a shape&gt;&gt; ]) </code></pre> <p>to get a tensor with a desired shape</p>
1
2016-08-17T10:21:20Z
[ "python", "numpy", "tensorflow" ]
how to remove first x characters from a string in a list
38,992,480
<p>So I have a list and a couple of string in it. I just want to remove the first 7 characters from each of the strings. How do I do that?</p> <p>I've tried:</p> <pre><code>lst = ["1234567something", "1234567smthelse"] for i in lst: i [7:] print lst </code></pre> <p>But I get the same list from the beginning....
-2
2016-08-17T09:12:55Z
38,992,528
<p>Try this:</p> <pre><code>for i in range(0, len(lst)): lst[i] = lst[i][7:] </code></pre>
1
2016-08-17T09:15:37Z
[ "python", "string", "list" ]
how to remove first x characters from a string in a list
38,992,480
<p>So I have a list and a couple of string in it. I just want to remove the first 7 characters from each of the strings. How do I do that?</p> <p>I've tried:</p> <pre><code>lst = ["1234567something", "1234567smthelse"] for i in lst: i [7:] print lst </code></pre> <p>But I get the same list from the beginning....
-2
2016-08-17T09:12:55Z
38,992,555
<p>You can do the following:</p> <pre><code>lst = ["1234567something", "1234567smthelse"] newlst=[] for i in lst: newlst.append(i[7:]) print newlst </code></pre> <p>I hope that helps.</p>
1
2016-08-17T09:16:43Z
[ "python", "string", "list" ]
how to remove first x characters from a string in a list
38,992,480
<p>So I have a list and a couple of string in it. I just want to remove the first 7 characters from each of the strings. How do I do that?</p> <p>I've tried:</p> <pre><code>lst = ["1234567something", "1234567smthelse"] for i in lst: i [7:] print lst </code></pre> <p>But I get the same list from the beginning....
-2
2016-08-17T09:12:55Z
38,992,562
<p><code>i[7:]</code> is not inplace, it returns a new string which you are doing nothing with.</p> <p>You can create a new list with the required string:</p> <pre><code>lst = [string[7:] for string in lst] </code></pre> <p>Or you can modify the same list:</p> <pre><code>for idx, string in enumerate(ls): ls[idx...
1
2016-08-17T09:17:12Z
[ "python", "string", "list" ]
how to remove first x characters from a string in a list
38,992,480
<p>So I have a list and a couple of string in it. I just want to remove the first 7 characters from each of the strings. How do I do that?</p> <p>I've tried:</p> <pre><code>lst = ["1234567something", "1234567smthelse"] for i in lst: i [7:] print lst </code></pre> <p>But I get the same list from the beginning....
-2
2016-08-17T09:12:55Z
38,992,564
<p>You're not saving the value of <code>i[7:]</code> anywhere… Just create a new list with the trimmed values:</p> <pre><code>lst = [i[7:] for i in lst] </code></pre>
1
2016-08-17T09:17:17Z
[ "python", "string", "list" ]
how to remove first x characters from a string in a list
38,992,480
<p>So I have a list and a couple of string in it. I just want to remove the first 7 characters from each of the strings. How do I do that?</p> <p>I've tried:</p> <pre><code>lst = ["1234567something", "1234567smthelse"] for i in lst: i [7:] print lst </code></pre> <p>But I get the same list from the beginning....
-2
2016-08-17T09:12:55Z
38,992,576
<p>try this:</p> <pre><code>lst = [s[7:] for s in lst] </code></pre>
1
2016-08-17T09:17:54Z
[ "python", "string", "list" ]
how to remove first x characters from a string in a list
38,992,480
<p>So I have a list and a couple of string in it. I just want to remove the first 7 characters from each of the strings. How do I do that?</p> <p>I've tried:</p> <pre><code>lst = ["1234567something", "1234567smthelse"] for i in lst: i [7:] print lst </code></pre> <p>But I get the same list from the beginning....
-2
2016-08-17T09:12:55Z
38,992,593
<p>You never reassigned the lst in your question, which is why the output of lst in print(lst) does not change. Try reassigning like this:</p> <pre><code>lst = ["1234567something", "1234567smthelse"] lst = [i[7:] for i in lst] print(lst) </code></pre> <p>returns</p> <blockquote> <p>['something', 'smthelse']</p> </...
1
2016-08-17T09:18:32Z
[ "python", "string", "list" ]
how to remove first x characters from a string in a list
38,992,480
<p>So I have a list and a couple of string in it. I just want to remove the first 7 characters from each of the strings. How do I do that?</p> <p>I've tried:</p> <pre><code>lst = ["1234567something", "1234567smthelse"] for i in lst: i [7:] print lst </code></pre> <p>But I get the same list from the beginning....
-2
2016-08-17T09:12:55Z
38,992,598
<p>When doing <code>i [7:]</code> you are <strong>not actually editing</strong> the element of the list, you are just computing a new string, without the first 7 characters, and not doing anything with it.</p> <p>You can do this instead :</p> <pre><code>&gt;&gt;&gt; lst = [e[7:] for e in lst] &gt;&gt;&gt; lst ['somet...
3
2016-08-17T09:18:48Z
[ "python", "string", "list" ]
python/pandas - counting unique values in a single DataFrame column and displaying counts as new columns
38,992,512
<p>I am starting with data of city transits with an additional column containing the mode of transportation</p> <pre><code>Orig Dest Type NY SF Train NY SF Plane NO NY Plane SE NO Plane SE NO Train </code></pre> <p>I want to aggregate it such that each unique value in...
2
2016-08-17T09:14:46Z
38,992,606
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.SeriesGroupBy.nunique.html" rel="nofollow"><code>nunique</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.unstack.html" rel="nofollow"><code>unstack</code></a>. Last <a href="http...
2
2016-08-17T09:19:22Z
[ "python", "pandas", "group-by" ]
Arrow with color gradient in matplotlib
38,992,615
<p>Is it possible to make arrows in matplotlib where the color of the arrow is changing gradually from one color to another?</p>
0
2016-08-17T09:19:41Z
38,994,432
<p>I don't think it's possible out of the box, but it's probably hackable.</p> <ul> <li>For a start, have a look at <a href="http://matplotlib.org/examples/pylab_examples/multicolored_line.html" rel="nofollow">This example that shows how to do a gradient line</a></li> <li>or <a href="http://matplotlib.org/examples/pyl...
1
2016-08-17T10:44:05Z
[ "python", "matplotlib" ]
I need a python regex to tokenize the sentences upon finding a "\\n"
38,992,647
<p>I used a document converter to get the text from pdf. The text appears in the form: </p> <blockquote> <p>"Hello Programmers\\nToday we will learn how to create a program in python\\nThefirst task is very easy and the level will exponentially increase\\nso please bare in mind that this course is not for the ...
1
2016-08-17T09:21:03Z
38,992,880
<p>Hey you need to use <code>gaps</code></p> <pre><code>&gt;&gt;&gt; tokenizer = RegexpTokenizer(r'\\n', gaps=True) &gt;&gt;&gt; tokenizer.tokenize(s) ['Hello Programmers', 'Today we will learn how to create a program in python', 'Thefirst task is very easy and the level will exponentially increase', 'so please bare i...
1
2016-08-17T09:32:51Z
[ "python", "regex" ]
I need a python regex to tokenize the sentences upon finding a "\\n"
38,992,647
<p>I used a document converter to get the text from pdf. The text appears in the form: </p> <blockquote> <p>"Hello Programmers\\nToday we will learn how to create a program in python\\nThefirst task is very easy and the level will exponentially increase\\nso please bare in mind that this course is not for the ...
1
2016-08-17T09:21:03Z
38,993,009
<p>The most basic solution which may be useful is:</p> <pre><code>text = "Hello Programmers\\nToday we will learn how to create a program in python\\nThefirst task is very easy and the level will exponentially increase\\nso please bare in mind that this course is not for the weak hearted\\n" each_line = text.split('\...
1
2016-08-17T09:38:31Z
[ "python", "regex" ]
matlabish "strncmp" in python
38,992,764
<p>I need to find indices of all occurrences of a particular pattern in a string (or numerical vector). For example, given the boolean list (DataFrame):</p> <pre><code>z = 15 False 16 False 17 False 18 False 19 False 20 False 21 False 22 False 23 False 24 True 25 True 26 True 27...
1
2016-08-17T09:27:28Z
38,993,552
<p>I'm assuming here that your inputs are lists:</p> <pre><code>inds = [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49] bools = [False,False,False,False,False,False,False,False,False, True, True, True,False,False,False,...
1
2016-08-17T10:03:33Z
[ "python", "dataframe", "strcmp" ]
matlabish "strncmp" in python
38,992,764
<p>I need to find indices of all occurrences of a particular pattern in a string (or numerical vector). For example, given the boolean list (DataFrame):</p> <pre><code>z = 15 False 16 False 17 False 18 False 19 False 20 False 21 False 22 False 23 False 24 True 25 True 26 True 27...
1
2016-08-17T09:27:28Z
39,005,217
<p>Although this can be done using list comprehensions, you lost a lot of the advantage of using numpy arrays or pandas dataframes, specifically that you can vectorize operations. The better approach would be to use <code>numpy.correlate</code>, which allows you to compare two arrays to see how well they match up. Yo...
1
2016-08-17T19:56:09Z
[ "python", "dataframe", "strcmp" ]
Trying to run Cloudera Image in Docker
38,992,850
<p>I am trying to run cloudera/clusterdock in a docker image for a university project. This is my first time using docker and so far I have been using the instructions on the cloudera website which are a little sparse.</p> <p>I successfully downloaded docker and the cloudera image and when I run the <code>docker-image...
0
2016-08-17T09:31:44Z
38,993,584
<p>If you look at <a href="https://github.com/cloudera/clusterdock/blob/master/Dockerfile#L54" rel="nofollow">Dockerfile</a> for <code>cloudera/clusterdock:latest</code>, you can see:</p> <pre><code>ENTRYPOINT ["python"] </code></pre> <p>So, when you do <code>docker run cloudera/clusterdock:latest /bin/bash</code>, y...
1
2016-08-17T10:04:59Z
[ "python", "bash", "command-line", "docker" ]
Trying to run Cloudera Image in Docker
38,992,850
<p>I am trying to run cloudera/clusterdock in a docker image for a university project. This is my first time using docker and so far I have been using the instructions on the cloudera website which are a little sparse.</p> <p>I successfully downloaded docker and the cloudera image and when I run the <code>docker-image...
0
2016-08-17T09:31:44Z
39,042,298
<p>The associated docs (e.g. the description on the image's Docker Hub page or our blog post) describe that clusterdock is intended to be run by sourcing clusterdock.sh. This is required because the framework controls Docker on the host machine.</p>
0
2016-08-19T15:05:05Z
[ "python", "bash", "command-line", "docker" ]
How tdo you run an elif function in a graph?
38,992,866
<p>I have a dataset which has corresponding temperature values, with a column called CO2-rh:</p> <pre><code>import pandas as pd df=pd.read_csv('F:/data32.csv',parse_dates=['Date']) print (df) Temperature unit unit.1 CO2 flux.1 %Root Resp CO2-Rh 4.5 umol/m2/s mg/cm^2/h 0.001210 ...
1
2016-08-17T09:32:27Z
38,993,004
<p>It looks like need <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html" rel="nofollow"><code>DataFrame.plot</code></a>:</p> <pre><code>impo...
1
2016-08-17T09:38:23Z
[ "python", "pandas", "if-statement", "matplotlib", "statistics" ]
Scrapy crawled 0 pages with 200 response status
38,992,887
<p>I am testing with Scrapy to crawl web pages. I cannot crawl the pages I want and I cannot find the reason why. Can anyone solve my problem?</p> <p>p.s. Thx for someone's reminder, the previous web page shows an error. I have changed the path.</p> <p>total_corner_spider.py</p> <pre><code>name = "totalcorner" allow...
0
2016-08-17T09:33:18Z
38,993,387
<p>I found the reason, a silly mistake. The file name for the spider should be totalcorner_spider.py. My bad. Thanks for your effort.</p>
0
2016-08-17T09:55:42Z
[ "python", "scrapy", "web-crawler" ]
celery workers not releasing memory after tasks are finished
38,992,930
<p>I am running celery with redis as the broker, on centos 6.5 machine, with the following configuration:</p> <pre><code>app.conf.update( CELERY_ENABLE_UTC=True, CELERY_SEND_TASK_SENT_EVENT=True, CELERY_ACCEPT_CONTENT=['msgpack', 'json', 'application/x-python-serialize'], CELERY_TASK_SERIALIZER='msgpac...
0
2016-08-17T09:35:15Z
38,994,639
<p>Usually, Unix processes do not systematically return to the OS the memory they acquire from it when they no longer need it. So over time the memory usage of a process will increase. </p> <p>If you are satisfied there's no actual coding or configuration problem affecting your workers, you could restart them periodic...
0
2016-08-17T10:53:56Z
[ "python", "linux", "celery" ]
insert element with element tree to existing xml
38,992,981
<p>I'm trying to find the simplest way to add an element to these item entries using element tree.</p> <p>I have the below XML output stored in (xmldata). I don't want to write this to a file yet, I just need to add the id so I an further use the data by relating it to a corresponding id in other data.</p> <p>Where y...
1
2016-08-17T09:37:36Z
38,993,280
<p>Something like this should give you the idea</p> <pre><code>root = ET.fromstring(xmldata) for item in root.iterfind('tasks/item'): idtag = ET.Element('id') idtag.text = '555666' item.insert(0, idtag) xmldata = ET.tostring(root, encoding="unicode") </code></pre>
1
2016-08-17T09:51:07Z
[ "python", "xml", "string", "elementtree" ]
how to match two columns using one of the column as reference?
38,993,072
<p>I have done some analysis and have found a particular pattern , and now I am trying to do some predictions. I have a data set that predicts the ratings for students with a given number of accidents in their childhood. My prediction matrix is looks some thing like this:</p> <pre><code> A injuries ratings...
1
2016-08-17T09:40:58Z
38,993,174
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow"><code>map</code></a> if all values for mapping are in DataFrame <code>A</code>:</p> <pre><code>B['predictions'] = B['injuries'].map(A.set_index('injuries')['ratings']) print (B) siblings income inj...
1
2016-08-17T09:45:42Z
[ "python", "pandas", "dataframe", "multiple-columns", "maping" ]
Running unix checksum command in Python
38,993,138
<p>Is there anyway we can run below unix command in Python.</p> <pre><code>csum -h SHA1 &lt;filename&gt; </code></pre> <p>The checksum produced in python would be stored and supposed to match with the checksum produced by unix command in destination server.<br> I know we can produce checksum through python itself.<br...
-1
2016-08-17T09:43:54Z
38,993,279
<p>You can use </p> <pre><code>import commands print commands.getstatusoutput('csum -h SHA1 foobar') (0, 'YOURCHECKSUM') </code></pre> <p>be aware that <code>commands</code> is deprecated in python 3 </p>
0
2016-08-17T09:51:04Z
[ "python", "unix", "checksum" ]
Running unix checksum command in Python
38,993,138
<p>Is there anyway we can run below unix command in Python.</p> <pre><code>csum -h SHA1 &lt;filename&gt; </code></pre> <p>The checksum produced in python would be stored and supposed to match with the checksum produced by unix command in destination server.<br> I know we can produce checksum through python itself.<br...
-1
2016-08-17T09:43:54Z
38,993,285
<p>You can just call unix from python using <code>subprocess.call</code></p> <pre><code>import subprocess subprocess.call("csum -h SHA1 {}".format(filename)) </code></pre>
1
2016-08-17T09:51:17Z
[ "python", "unix", "checksum" ]
flask: `@after_this_request` not working
38,993,146
<p>I want to delete a file after the user downloaded a file which was created by the flask app.</p> <p>For doing so I found this <a href="http://stackoverflow.com/a/24613980/3991125">answer on SO</a> which did not work as expected and raised an error telling that <code>after_this_request</code> is not defined.</p> <p...
0
2016-08-17T09:44:26Z
38,993,208
<p>There is no specific <em>after this request</em> functionality in Flask. There is only a <em>after <strong>every</strong> request</em> hook, which is what the snippet coopts to handle per-request call-backs.</p> <p>You did not implement the hook:</p> <pre><code>@app.after_request def per_request_callbacks(response...
0
2016-08-17T09:47:25Z
[ "python", "python-3.x", "flask", "request", "delete-file" ]
PyOpenSSL get server certificate from SNI host with unknown hostnames
38,993,256
<p>My code sample:</p> <pre><code> import OpenSSL import socket ctx = OpenSSL.SSL.Context(OpenSSL.SSL.SSLv23_METHOD) s = socket.socket(AF_INET, SOCK_STREAM) connection = OpenSSL.SSL.Connection(ctx, s) connection.connect((str(ip), port)) connection.setblocking(1) connection.do_handshake(...
0
2016-08-17T09:50:08Z
39,005,454
<blockquote> <p>Is there a way to connect to host by ip and retrieve all available hostnames that provide certificates? Or is there a way to just retrieve all certificates from a SNI host?</p> </blockquote> <p>None of this is possible using HTTPS. If you are lucky you can gather information about the possible hostna...
0
2016-08-17T20:12:01Z
[ "python", "sockets", "openssl", "pyopenssl" ]
Trigger python file under django project from a HTML button
38,993,259
<p>My python script file in under django project but in some other folder(say, otherPythons). I want to trigger this python file on click of a HTML button using javascript.</p> <p>Please no PHP</p> <p>Thanks in advance</p>
-2
2016-08-17T09:50:19Z
38,993,300
<p>Django doesn't care which folder your view code is in. Just define a URL that points to it.</p>
0
2016-08-17T09:51:59Z
[ "javascript", "jquery", "python", "ajax", "django" ]
Text based data format which supports multiline strings
38,993,265
<p>I search a text based data format which supports multiline strings.</p> <p>JSON does not allow multiline strings:</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; json.dumps(dict(text='first line\nsecond line')) '{"text": "first line\\nsecond line"}' </code></pre> <p>My desired output:</p> <pre><code>{"text"...
15
2016-08-17T09:50:34Z
39,037,722
<p>I think you should consider <a href="http://yaml.org/"><code>YAML</code></a> format. It supports block notation which is <a href="http://www.yaml.org/spec/1.2/spec.html#id2760844">able to preserve newlines</a> like this</p> <pre><code>data: | There once was a short man from Ealing Who got on a bus to Darjeeli...
21
2016-08-19T11:17:49Z
[ "python", "json", "format" ]
Text based data format which supports multiline strings
38,993,265
<p>I search a text based data format which supports multiline strings.</p> <p>JSON does not allow multiline strings:</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; json.dumps(dict(text='first line\nsecond line')) '{"text": "first line\\nsecond line"}' </code></pre> <p>My desired output:</p> <pre><code>{"text"...
15
2016-08-17T09:50:34Z
39,039,087
<p><code>ini</code> format also supports multiline strings; configparser from Python stdlib can handle it. See <a href="https://docs.python.org/3/library/configparser.html#supported-ini-file-structure" rel="nofollow">https://docs.python.org/3/library/configparser.html#supported-ini-file-structure</a>.</p>
2
2016-08-19T12:29:08Z
[ "python", "json", "format" ]
Text based data format which supports multiline strings
38,993,265
<p>I search a text based data format which supports multiline strings.</p> <p>JSON does not allow multiline strings:</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; json.dumps(dict(text='first line\nsecond line')) '{"text": "first line\\nsecond line"}' </code></pre> <p>My desired output:</p> <pre><code>{"text"...
15
2016-08-17T09:50:34Z
39,040,301
<p>If the files are only used by Python (overlooking the <em>interchange</em>), you could simply put your data in a python script file and import this as a module:</p> <p>Data</p> <pre><code>datum_1 = """ lorem ipsum dolor """ datum_list = [1, """two liner"""] datum_dict = {"key": None, "another": [None, 42.13]} datu...
2
2016-08-19T13:27:18Z
[ "python", "json", "format" ]
Text based data format which supports multiline strings
38,993,265
<p>I search a text based data format which supports multiline strings.</p> <p>JSON does not allow multiline strings:</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; json.dumps(dict(text='first line\nsecond line')) '{"text": "first line\\nsecond line"}' </code></pre> <p>My desired output:</p> <pre><code>{"text"...
15
2016-08-17T09:50:34Z
39,040,460
<p>XML with <a href="https://docs.python.org/3/library/xml.etree.elementtree.html" rel="nofollow">ElementTree</a> (standard library) or <a href="http://lxml.de/" rel="nofollow">lxml</a> if you are OK with the markup overhead:</p> <p>Data</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;data&gt; &lt;string&gt;Lorem Ip...
2
2016-08-19T13:36:15Z
[ "python", "json", "format" ]
Text based data format which supports multiline strings
38,993,265
<p>I search a text based data format which supports multiline strings.</p> <p>JSON does not allow multiline strings:</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; json.dumps(dict(text='first line\nsecond line')) '{"text": "first line\\nsecond line"}' </code></pre> <p>My desired output:</p> <pre><code>{"text"...
15
2016-08-17T09:50:34Z
39,077,281
<p>Apropos of your comment:</p> <blockquote> <p>I want to use it for configuration. A lot of applications invent their own configuration language. I want to avoid this. But json and ConfigParser don't satisfy me. Json does not allow strings with newlines (only \n) and ConfigParser does not allow nested data ...
4
2016-08-22T10:33:56Z
[ "python", "json", "format" ]
Text based data format which supports multiline strings
38,993,265
<p>I search a text based data format which supports multiline strings.</p> <p>JSON does not allow multiline strings:</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; json.dumps(dict(text='first line\nsecond line')) '{"text": "first line\\nsecond line"}' </code></pre> <p>My desired output:</p> <pre><code>{"text"...
15
2016-08-17T09:50:34Z
39,136,805
<p>Not sure whether I've understood your question correctly, but are you not asking for something like this?</p> <pre><code>my_config = { "text": """first line second line""" } print my_config </code></pre>
0
2016-08-25T04:40:56Z
[ "python", "json", "format" ]
Text based data format which supports multiline strings
38,993,265
<p>I search a text based data format which supports multiline strings.</p> <p>JSON does not allow multiline strings:</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; json.dumps(dict(text='first line\nsecond line')) '{"text": "first line\\nsecond line"}' </code></pre> <p>My desired output:</p> <pre><code>{"text"...
15
2016-08-17T09:50:34Z
39,156,392
<p>If you're using Python 2, I actually think json can do what you need. You can dump and load json while decoding and encoding it with <code>string-escape</code>:</p> <pre><code>import json config_dict = { 'text': 'first line\nsecond line', } config_str = json.dumps(config_dict).decode('string-escape') print co...
1
2016-08-25T23:48:54Z
[ "python", "json", "format" ]
Keep initialize value of a dict if no key is present
38,993,266
<p>I am trying to parse a pdf metadata like:</p> <pre><code> fields = ["Author", "Year", "Journal", "Title", "Publisher", "Page", "Address", "Annote", "Booktitle", "Chapter", "Crossred", "Edition", "Editor", "HowPublished", "Institution", "Month", "Note", "N...
0
2016-08-17T09:50:35Z
38,993,377
<p>There are a bunch of ways of going this, but the simplest is to drop the initial version of the dict and instead check afterwards if Author is present:</p> <pre><code>new_op = { field: str(value) for field in fields for key, value in op[0].items() if field.lower() in key.lower() } if 'Author' not in new_op:...
1
2016-08-17T09:55:16Z
[ "python", "python-3.x" ]
Keep initialize value of a dict if no key is present
38,993,266
<p>I am trying to parse a pdf metadata like:</p> <pre><code> fields = ["Author", "Year", "Journal", "Title", "Publisher", "Page", "Address", "Annote", "Booktitle", "Chapter", "Crossred", "Edition", "Editor", "HowPublished", "Institution", "Month", "Note", "N...
0
2016-08-17T09:50:35Z
38,993,393
<p>You are reassigning the <code>new_op</code> dictionary. Instead, after the following assignment</p> <pre><code>new_op = { field: str(value) for field in fields for key, value in op[0].items() if field.lower() in key.lower() } </code></pre> <p>Do this:</p> <pre><code>if not new_op.has_key('Author'): ne...
0
2016-08-17T09:56:12Z
[ "python", "python-3.x" ]
Keep initialize value of a dict if no key is present
38,993,266
<p>I am trying to parse a pdf metadata like:</p> <pre><code> fields = ["Author", "Year", "Journal", "Title", "Publisher", "Page", "Address", "Annote", "Booktitle", "Chapter", "Crossred", "Edition", "Editor", "HowPublished", "Institution", "Month", "Note", "N...
0
2016-08-17T09:50:35Z
38,993,394
<pre><code>try: id_auth=new_op["Author"].split()[-1] except KeyError: id_auth="Unknown" </code></pre>
0
2016-08-17T09:56:17Z
[ "python", "python-3.x" ]
Encrypted data in REST Services Response
38,993,326
<p>I use Django and Django-rest-framework about REST services from Back-end and Mobile Client Apps.</p> <p>I would to have some responses with encrypted data. I have to return to my client some sensible and private data and I would to apply an additional security layer (in fact I already use SSL, but I would to disarm...
0
2016-08-17T09:53:37Z
39,090,347
<p>A good encryption libary with various implementations is <a href="https://github.com/google/keyczar" rel="nofollow">Keyczar</a>.</p> <p>What you would need to do is write a global interceptor on all incoming request to your backend application, and when responses are sent back they are encrypted using the Keyczar l...
-1
2016-08-22T23:49:29Z
[ "python", "django", "encryption", "django-rest-framework", "restful-architecture" ]
zero index for all rows in python dataframe
38,993,372
<p>I have problem with indexing python <code>dataframe</code>. I have dataframe which I fill it with loop. I simplified it like this :</p> <pre><code>d = pd.DataFrame(columns=['img', 'time', 'key']) for i in range(5): image = i timepoint = i+1 key = i+2 temp = pd.DataFrame({'img':[image], 'timepoint':[...
1
2016-08-17T09:55:10Z
38,993,497
<pre><code>d = d.reset_index(drop=True) </code></pre> <p>PS: It's better practice to make a list of rows and then turn it into a DataFrame, much less computationally expensive and it will make a good index instantly.</p> <p>This list could be a list of lists combined with the columns in your DataFrame init or a list ...
0
2016-08-17T10:00:24Z
[ "python", "python-3.x", "pandas", "indexing", "dataframe" ]
zero index for all rows in python dataframe
38,993,372
<p>I have problem with indexing python <code>dataframe</code>. I have dataframe which I fill it with loop. I simplified it like this :</p> <pre><code>d = pd.DataFrame(columns=['img', 'time', 'key']) for i in range(5): image = i timepoint = i+1 key = i+2 temp = pd.DataFrame({'img':[image], 'timepoint':[...
1
2016-08-17T09:55:10Z
38,993,587
<p>You may want to use the <code>ignore_index</code> parameter in your concatenation :</p> <pre><code>d = pd.concat([d, temp], ignore_index=True) </code></pre> <p>This gives me the following result :</p> <pre><code> img key time timepoint 0 0.0 2.0 NaN 1.0 1 1.0 3.0 NaN 2.0 2 2.0 4.0 NaN ...
2
2016-08-17T10:05:05Z
[ "python", "python-3.x", "pandas", "indexing", "dataframe" ]
zero index for all rows in python dataframe
38,993,372
<p>I have problem with indexing python <code>dataframe</code>. I have dataframe which I fill it with loop. I simplified it like this :</p> <pre><code>d = pd.DataFrame(columns=['img', 'time', 'key']) for i in range(5): image = i timepoint = i+1 key = i+2 temp = pd.DataFrame({'img':[image], 'timepoint':[...
1
2016-08-17T09:55:10Z
38,993,861
<p>I think better is first fill <code>lists</code> by values and then once use <code>DataFrame</code> constructor:</p> <pre><code>image, timepoint, key = [],[],[] for i in range(5): image.append(i) timepoint.append(i+1) key.append(i+2) d = pd.DataFrame({'img':image, 'time':timepoint, 'key': key}) print (d...
0
2016-08-17T10:18:01Z
[ "python", "python-3.x", "pandas", "indexing", "dataframe" ]
Run Python function with input arguments form command line
38,993,606
<p>New to Python, used to use MATLAB.</p> <p>My function convert.py is:</p> <pre><code>def convert(a,b) factor = 2194.2 return (a-b)*factor </code></pre> <p>How do I run it from the command line with input arguments 'a' and 'b' ? I tried:</p> <pre><code>python convert.py 32 46 </code></pre> <p>But got an error...
-2
2016-08-17T10:05:56Z
38,993,785
<p>There exists a Python module for this sort of thing called <a href="https://docs.python.org/3/library/argparse.html" rel="nofollow">argparse</a>, which allows you to do really fancy things around command line flags. You don't really need that - you've just got two numbers on the command line. This can be handled rea...
-1
2016-08-17T10:14:16Z
[ "python", "function", "input", "command-line", "arguments" ]