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
Apply weight formula over rows of Dataframe Pandas
39,519,167
<p>I have a <code>df1</code> below. I make a copy of it to <code>df2</code> to conserve <code>df1</code>; then I use <code>df3</code> to compute over <code>df2</code>.</p> <pre><code>df2=df1.copy() </code></pre> <p>I want to calculate a weight such as <code>Weight(A) = Price(A) / Sum(row_Prices)</code> and return it ...
-2
2016-09-15T19:44:23Z
39,525,049
<p>As far as I know, there's no one-liner-quick-and-dirty way to achieve what you are trying to do. You need to calculate all your data and then merge it all into a <code>DataFrame</code> that uses a multi-level index:</p> <pre><code># Making weight/std DataFrames cols = list('ABCDE') weight = pd.DataFrame([df[col] / ...
1
2016-09-16T06:29:46Z
[ "python", "pandas", "dataframe", "apply" ]
Special characters/kanji problems using Python unicode
39,519,180
<p>I want to use videofileclip(), but a UnicodeDecodeError occurs. The videofiles include japanese kanji or special characters.</p> <p>My example code:</p> <pre><code>#-*- coding: utf-8 -*- import sys from moviepy.editor import VideoFileClip reload(sys) sys.setdefaultencoding('utf-8') a='H:\\kittens.mkv' clip1=...
1
2016-09-15T19:44:54Z
39,599,706
<p>Here's a workaround using the <a href="https://sourceforge.net/projects/pywin32" rel="nofollow">pywin32</a> extensions. Basically, you use the <a href="http://timgolden.me.uk/pywin32-docs/win32api__GetShortPathName_meth.html" rel="nofollow"><code>GetShortPathName</code></a> function to generate a legacy <a href="htt...
0
2016-09-20T16:50:45Z
[ "python", "unicode", "special-characters", "moviepy" ]
Data Conversion using pyodbc to query iSeries database - Conversion error
39,519,204
<p>I am trying to filter records based on a Zoned Decimal value that is returning as Decimal(160919, ). How can I use this to filter against a date (ie: 160919) Below is the code that I'm using to extract the order data:</p> <pre><code>#connect to APlus import pyodbc import time import cursor as cursor today = int(...
1
2016-09-15T19:46:41Z
39,521,359
<p>There ended up being a space at the end of the date in the record. I used Left(OHEXDT, 6) to compare and everything is working as expected. </p> <p>This actually only worked for an isolated occurrence, and then failed. </p> <p>I am now using substring to pull out the numbers in the format I need to compare them t...
0
2016-09-15T22:38:45Z
[ "python", "sql", "ibm-midrange", "pyodbc", "db2400" ]
Regex to remove bit signal noise spikes
39,519,207
<p>I am dealing with RF signals that sometimes have noise spikes.<br> The input is something like this:<br> <code>00000001111100011110001111100001110000001000001111000000111001111000 </code> </p> <p>Before parsing the data in the signal, I need to remove the spike bits, that are 0's and 1's sequence with a lenght low...
4
2016-09-15T19:46:55Z
39,519,271
<pre><code>import re THRESHOLD=3 def fixer(match): ones = match.group(0) if len(ones) &lt; THRESHOLD: return "0"*len(ones) return ones my_string = '00000001111100011110001111100001110000001000001111000000111001111000' print(re.sub("(1+)",fixer,my_string)) </code></pre> <p>if you want to also remove "spik...
6
2016-09-15T19:51:27Z
[ "python", "regex" ]
Regex to remove bit signal noise spikes
39,519,207
<p>I am dealing with RF signals that sometimes have noise spikes.<br> The input is something like this:<br> <code>00000001111100011110001111100001110000001000001111000000111001111000 </code> </p> <p>Before parsing the data in the signal, I need to remove the spike bits, that are 0's and 1's sequence with a lenght low...
4
2016-09-15T19:46:55Z
39,519,769
<p>Alternative approach without using <code>regex</code>, and by using <code>replace()</code> instead (in case someone might find it useful in future):</p> <pre><code>&gt;&gt;&gt; my_signal = '00000001111100011110001111100001110000001000001111000000111001111000' &gt;&gt;&gt; my_threshold = 3 &gt;&gt;&gt; for i in rang...
0
2016-09-15T20:25:48Z
[ "python", "regex" ]
Regex to remove bit signal noise spikes
39,519,207
<p>I am dealing with RF signals that sometimes have noise spikes.<br> The input is something like this:<br> <code>00000001111100011110001111100001110000001000001111000000111001111000 </code> </p> <p>Before parsing the data in the signal, I need to remove the spike bits, that are 0's and 1's sequence with a lenght low...
4
2016-09-15T19:46:55Z
39,520,001
<pre><code>def fix_noise(s, noise_thold=3): pattern=re.compile(r'(?P&lt;before&gt;1|0)(?P&lt;noise&gt;(?&lt;=0)1{1,%d}(?=0)|(?&lt;=1)0{1,%d}(?=1))' % (noise_thold-1, noise_thold-1)) result = s for noise_match in pattern.finditer(s): beginning = result[:noise_match.start()+1] end = result[noi...
0
2016-09-15T20:39:40Z
[ "python", "regex" ]
Regex to remove bit signal noise spikes
39,519,207
<p>I am dealing with RF signals that sometimes have noise spikes.<br> The input is something like this:<br> <code>00000001111100011110001111100001110000001000001111000000111001111000 </code> </p> <p>Before parsing the data in the signal, I need to remove the spike bits, that are 0's and 1's sequence with a lenght low...
4
2016-09-15T19:46:55Z
39,520,346
<p>To match both cases <code>[01]</code>in a single regex, it's simply this: </p> <p><code>(?&lt;=([01]))(?:(?!\1)[01]){1,2}(?=\1)</code> </p> <p>Expanded </p> <pre><code> (?&lt;= # Lookbehind for 0 or 1 ( [01] ) # (1), Capture behind 0 or 1 ) (?: # Match spike...
1
2016-09-15T21:04:05Z
[ "python", "regex" ]
how to get value from returned instance of deferred
39,519,240
<p>I use txmongo lib as the driver for mongoDB. In its limited docs, the find function in txmongo will return an instance of deferred, but how can I get the actual result (like {"IP":11.12.59.119})?? I tried yield, str() and repr() but does not work.</p> <pre><code>def checkResource(self, resource): """ use the me...
0
2016-09-15T19:49:13Z
39,520,688
<p>If you want to write asynchronous code in twisted looking more like synchronous, try using <code>defer.inlineCallbacks</code></p> <p>This is from the docs: <a href="http://twisted.readthedocs.io/en/twisted-16.2.0/core/howto/defer-intro.html#inline-callbacks-using-yield" rel="nofollow">http://twisted.readthedocs.io/...
1
2016-09-15T21:32:12Z
[ "python", "mongodb", "twisted" ]
passing items from list to an empty object in another list
39,519,289
<p>I want to pass items from lists to the empty object in store i.e. I want:</p> <pre><code>store = [ [['a', 'b'], ['c', 'd']], [] ] </code></pre> <p>I am getting an unintended result: </p> <pre><code>lists = [['a', 'b'], ['c', 'd']] store = [[], []] counter = 0 for l in lists: for s in store: s.appen...
-1
2016-09-15T19:52:03Z
39,519,348
<p>Store has two empty lists, and you're adding on to both of them. If you only want to add onto the first then</p> <pre><code>for l in lists: store[0].append(l) </code></pre>
0
2016-09-15T19:55:29Z
[ "python", "list", "nested-loops" ]
passing items from list to an empty object in another list
39,519,289
<p>I want to pass items from lists to the empty object in store i.e. I want:</p> <pre><code>store = [ [['a', 'b'], ['c', 'd']], [] ] </code></pre> <p>I am getting an unintended result: </p> <pre><code>lists = [['a', 'b'], ['c', 'd']] store = [[], []] counter = 0 for l in lists: for s in store: s.appen...
-1
2016-09-15T19:52:03Z
39,519,380
<p>The nested for loop is an overkill. You should instead <code>extend</code> the first sublist in <code>store</code> with <code>lists</code>:</p> <pre><code>lists = [['a', 'b'], ['c', 'd']] store = [[], []] store[0].extend(lists) # ^ indexing starts from 0 print(store) # [[['a', 'b'], ['c', 'd']], []] </code></p...
1
2016-09-15T19:57:32Z
[ "python", "list", "nested-loops" ]
passing items from list to an empty object in another list
39,519,289
<p>I want to pass items from lists to the empty object in store i.e. I want:</p> <pre><code>store = [ [['a', 'b'], ['c', 'd']], [] ] </code></pre> <p>I am getting an unintended result: </p> <pre><code>lists = [['a', 'b'], ['c', 'd']] store = [[], []] counter = 0 for l in lists: for s in store: s.appen...
-1
2016-09-15T19:52:03Z
39,519,427
<p>This is very simple man. The best way to do this would be to simply assign the lists to stores[0]. </p> <pre><code>stores[0]= lists </code></pre> <p>is all you need to do.</p>
0
2016-09-15T20:01:51Z
[ "python", "list", "nested-loops" ]
passing items from list to an empty object in another list
39,519,289
<p>I want to pass items from lists to the empty object in store i.e. I want:</p> <pre><code>store = [ [['a', 'b'], ['c', 'd']], [] ] </code></pre> <p>I am getting an unintended result: </p> <pre><code>lists = [['a', 'b'], ['c', 'd']] store = [[], []] counter = 0 for l in lists: for s in store: s.appen...
-1
2016-09-15T19:52:03Z
39,519,625
<p>How about simply doing this:</p> <pre><code>store = [lists, []] # value of 'store' = [[['a', 'b'], ['c', 'd']], []] </code></pre> <p>As I believe based on your question, that the desired O/P is:</p> <pre><code>store = [ [['a', 'b'], ['c', 'd']], [] ] </code></pre> <p>from the input list:</p> <pre><code>lists = ...
0
2016-09-15T20:15:22Z
[ "python", "list", "nested-loops" ]
passing items from list to an empty object in another list
39,519,289
<p>I want to pass items from lists to the empty object in store i.e. I want:</p> <pre><code>store = [ [['a', 'b'], ['c', 'd']], [] ] </code></pre> <p>I am getting an unintended result: </p> <pre><code>lists = [['a', 'b'], ['c', 'd']] store = [[], []] counter = 0 for l in lists: for s in store: s.appen...
-1
2016-09-15T19:52:03Z
39,519,688
<p>If </p> <pre><code>store = [ [['a', 'b'], ['c', 'd']], [] ] </code></pre> <p>is indeed what you want, then you've overshot the mark. The inner loop is unnecessary and will execute your code for <em>each</em> item in <code>store</code>. You have two empty lists in <code>store</code>, thus creating two populated lis...
1
2016-09-15T20:19:42Z
[ "python", "list", "nested-loops" ]
How do I improve my quick sort pivot selection in python?
39,519,343
<p>I was originally using only a single random pivot given by </p> <pre><code>pivots = random.randrange(l,r) </code></pre> <p>Here l and r will be integers that define my range</p> <p>I wanted to improve the run time by greatly increasing the likely hood that my pivot would be a good pivot by selecting the median of...
4
2016-09-15T19:54:59Z
39,519,585
<p>Though it can be outperformed by random choice on occasion, it's still worth looking into the <a href="https://en.wikipedia.org/wiki/Median_of_medians" rel="nofollow">median-of-medians</a> algorithm for pivot selection (and rank selection in general), which runs in O(n) time. It's not too far off of what you are cur...
1
2016-09-15T20:12:04Z
[ "python", "pivot", "quicksort" ]
How do I improve my quick sort pivot selection in python?
39,519,343
<p>I was originally using only a single random pivot given by </p> <pre><code>pivots = random.randrange(l,r) </code></pre> <p>Here l and r will be integers that define my range</p> <p>I wanted to improve the run time by greatly increasing the likely hood that my pivot would be a good pivot by selecting the median of...
4
2016-09-15T19:54:59Z
39,519,787
<p>You could choose the pivot in this way:</p> <pre><code>alen = len(array) pivots = [[array[0],0], [array[alen//2],alen//2], [array[alen-1],alen-1]]] pivots.sort(key=lambda tup: tup[0]) #it orders for the first element of the tupla pivot = pivots[1][1] </code></pre> <p>Example:</p> <p><a href="http://i.stack.imgur....
2
2016-09-15T20:26:33Z
[ "python", "pivot", "quicksort" ]
How to get the response of calling a redis command
39,519,369
<p>I'm using python 2.6.6 and I can't upgrade.</p> <p>I had it working fine with subprocess.check_output but I didn't realize we are using python 2.6.6 and I can't upgrade it on my end.</p> <p>I tried this:</p> <pre><code>command = "redis-cli hget some_key some_field" command_output = subprocess.Popen(command, stdou...
0
2016-09-15T19:56:28Z
39,519,415
<p>Yup, you should use lists to give your command line.</p> <pre><code>command = ["redis-cli", "hget", "some_key", "some_field"] command_output = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0] </code></pre> <p>Relevant from Moses Koledoye@</p> <blockquote> <p><code>command.split()</code> does t...
1
2016-09-15T20:00:33Z
[ "python" ]
Python Selenium: Firefox neverAsk.saveToDisk when downloading from Blob URL
39,519,518
<p>I wish to have Firefox using <code>selenium</code> for Python to download the <em>Master data (Download, XLSX)</em> Excel file from this <a href="http://www.xetra.com/xetra-en/instruments/etf-exchange-traded-funds/list-of-tradable-etfs" rel="nofollow">Frankfurt stock exchange webpage</a>.</p> <p>The problem: I can'...
1
2016-09-15T20:07:57Z
39,519,560
<p>The actual mime-type to be used in this case is:</p> <pre><code>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet </code></pre> <hr> <p>How do I know that? Here is what I've done:</p> <ul> <li>opened Firefox manually and navigated to the target site</li> <li>when downloading the file, checked the...
1
2016-09-15T20:10:47Z
[ "python", "selenium", "firefox", "blob" ]
Using variable as part of name of new file in python
39,519,599
<p>I'm fairly new to python and I'm having an issue with my python script (split_fasta.py). Here is an example of my issue:</p> <pre><code>list = ["1.fasta", "2.fasta", "3.fasta"] for file in list: contents = open(file, "r") for line in contents: if line[0] == "&gt;": new_file = open(file +...
0
2016-09-15T20:13:11Z
39,519,785
<p>You are giving the full path of the old file, plus a new name. So basically, if <code>file == /home/data/something.fasta</code>, the output file will be <code>file + "_chromosome.fasta"</code> which is <code>/home/data/something.fasta_chromosome.fasta</code></p> <p>If you use <code>os.path.basename</code> on <code...
2
2016-09-15T20:26:27Z
[ "python", "fasta" ]
Python compare md5 hash
39,519,734
<p>I'm using the following code I found on stackoverflow which suggested is an effective way to get the md5 hash of the contents of a text file and comparing with the generated md5 hash I got from <a href="http://www.miraclesalad.com/webtools/md5.php" rel="nofollow">http://www.miraclesalad.com/webtools/md5.php</a></p> ...
1
2016-09-15T20:23:22Z
39,519,897
<p>The issue could be with newlines. If your file ends in a newline <code>"test\n"</code>, the MD5 hash would be <code>d8e8fca2dc0f896fd7cb4cb0031ba249</code>.</p> <p>Line endings can also differ whether you are on a Windows or Unix system.</p>
2
2016-09-15T20:33:22Z
[ "python", "hash", "md5sum" ]
Python compare md5 hash
39,519,734
<p>I'm using the following code I found on stackoverflow which suggested is an effective way to get the md5 hash of the contents of a text file and comparing with the generated md5 hash I got from <a href="http://www.miraclesalad.com/webtools/md5.php" rel="nofollow">http://www.miraclesalad.com/webtools/md5.php</a></p> ...
1
2016-09-15T20:23:22Z
39,519,914
<p>With only the text of <code>test</code>, (no blank line after) in both the web generator and Python I get the MD5 hash of:</p> <pre><code>098f6bcd4621d373cade4e832627b4f6 </code></pre> <p>If I add a carriage return / new line (\n) afterwards I get:</p> <pre><code>d8e8fca2dc0f896fd7cb4cb0031ba249 # Using the web s...
2
2016-09-15T20:34:13Z
[ "python", "hash", "md5sum" ]
Python compare md5 hash
39,519,734
<p>I'm using the following code I found on stackoverflow which suggested is an effective way to get the md5 hash of the contents of a text file and comparing with the generated md5 hash I got from <a href="http://www.miraclesalad.com/webtools/md5.php" rel="nofollow">http://www.miraclesalad.com/webtools/md5.php</a></p> ...
1
2016-09-15T20:23:22Z
39,519,916
<p>Are you sure that your size param is large enough (I can't imagine it wouldn't be, but worth checking)? When I test your code above with a simple value and compare with a standard MD5 hash (using miraclesalad or whatever), I get back a correct response. Carriage returns or special characters could be of some concern...
1
2016-09-15T20:34:19Z
[ "python", "hash", "md5sum" ]
Python compare md5 hash
39,519,734
<p>I'm using the following code I found on stackoverflow which suggested is an effective way to get the md5 hash of the contents of a text file and comparing with the generated md5 hash I got from <a href="http://www.miraclesalad.com/webtools/md5.php" rel="nofollow">http://www.miraclesalad.com/webtools/md5.php</a></p> ...
1
2016-09-15T20:23:22Z
39,519,990
<p>On windows, I did the following to reproduce.</p> <pre><code>C:\Users\adsmith\tmp&gt;echo test&gt;test.txt </code></pre> <p>Then in Python:</p> <pre><code>&gt;&gt;&gt; import hashlib &gt;&gt;&gt; a = hashlib.md5() &gt;&gt;&gt; b = hashlib.md5() &gt;&gt;&gt; with open("test.txt", "rb") as fh: ... data = fh.rea...
1
2016-09-15T20:39:01Z
[ "python", "hash", "md5sum" ]
Django can't convert 'Recipe_instruction' object to str implicitly
39,519,796
<p>I am developing an application in django. Here is my models.py and views.py code:</p> <pre><code>#models.py class Recipe_instruction(models.Model): content = models.TextField(max_length=500) recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE) order = models.IntegerField(max_length=500) clas...
1
2016-09-15T20:27:26Z
39,520,226
<p>The problem isn't with the code here.. but whilst we're looking at it, try changing the entire code to</p> <pre><code>instructions = Recipe_instruction.objects.filter(recipe=recipe).values_list('content', flat=True) recipe_instructions_stri...
1
2016-09-15T20:56:32Z
[ "python", "django" ]
Making Combination from lists using itertools
39,519,871
<pre><code>import itertools a = [[2, 3], [3, 4]] b = [[5, 6], [7, 8], [9, 10]] c = [[11, 12], [13, 14]] d = [[15, 16], [17, 18]] e = [[12,16],[13,17],[14,18],[15,19]] q=[] q=list(itertools.combinations((a, b, b,c, c, d,e),7) print q </code></pre> <p>How would I go about using the combination function from itertools p...
2
2016-09-15T20:32:09Z
39,520,003
<p><strong>Updated given clarification of expected output</strong>:</p> <p><a href="https://docs.python.org/3/library/itertools.html#itertools.product" rel="nofollow">You want <code>itertools.product</code></a>:</p> <pre><code>itertools.product(a, b, b, c, c, c, c, d, e) </code></pre> <p>Which will pick one element ...
1
2016-09-15T20:39:50Z
[ "python", "list", "combinations", "itertools" ]
Making Combination from lists using itertools
39,519,871
<pre><code>import itertools a = [[2, 3], [3, 4]] b = [[5, 6], [7, 8], [9, 10]] c = [[11, 12], [13, 14]] d = [[15, 16], [17, 18]] e = [[12,16],[13,17],[14,18],[15,19]] q=[] q=list(itertools.combinations((a, b, b,c, c, d,e),7) print q </code></pre> <p>How would I go about using the combination function from itertools p...
2
2016-09-15T20:32:09Z
39,520,252
<p>It seems like you are looking for a combination of <a href="https://docs.python.org/3/library/itertools.html#itertools.combinations" rel="nofollow"><code>combinations</code></a> and <a href="https://docs.python.org/3/library/itertools.html#itertools.product" rel="nofollow"><code>product</code></a>: Use <code>combina...
2
2016-09-15T20:57:56Z
[ "python", "list", "combinations", "itertools" ]
Making Combination from lists using itertools
39,519,871
<pre><code>import itertools a = [[2, 3], [3, 4]] b = [[5, 6], [7, 8], [9, 10]] c = [[11, 12], [13, 14]] d = [[15, 16], [17, 18]] e = [[12,16],[13,17],[14,18],[15,19]] q=[] q=list(itertools.combinations((a, b, b,c, c, d,e),7) print q </code></pre> <p>How would I go about using the combination function from itertools p...
2
2016-09-15T20:32:09Z
39,520,465
<p>What your are trying to achieve is the <code>Cartesian product of input iterables</code> and not the combinations of the item present in the list. Hence you have to use <a href="https://docs.python.org/3/library/itertools.html#itertools.product" rel="nofollow"><code>itertools.product()</code></a> instead.</p> <p>In...
1
2016-09-15T21:13:39Z
[ "python", "list", "combinations", "itertools" ]
Update dictionary if in list
39,519,910
<p>I'm running through an excel file reading line by line to create dictionaries and append them to a list, so I have a list like:</p> <pre><code>myList = [] </code></pre> <p>and a dictionary in this format:</p> <pre><code>dictionary = {'name': 'John', 'code': 'code1', 'date': [123,456]} </code></pre> <p>so I do th...
0
2016-09-15T20:33:55Z
39,520,040
<p>I would modify <code>checkGuy</code> to something like:</p> <pre><code>def findGuy(dude_name): for d in myList: if d['name'] == dude_name: return d else: return None # or use pass </code></pre> <p>And then do:</p> <pre><code>def addGuy(row_info): guy = findGuy(row_info[1]) ...
2
2016-09-15T20:42:56Z
[ "python", "dictionary" ]
Update dictionary if in list
39,519,910
<p>I'm running through an excel file reading line by line to create dictionaries and append them to a list, so I have a list like:</p> <pre><code>myList = [] </code></pre> <p>and a dictionary in this format:</p> <pre><code>dictionary = {'name': 'John', 'code': 'code1', 'date': [123,456]} </code></pre> <p>so I do th...
0
2016-09-15T20:33:55Z
39,520,233
<p>This answer suggestion is pasted on the comments where it was suggested that if "name" is the only criteria to search on then it could be used as a key in a dictionary instead of using a list.</p> <pre><code>master = {"John" : {'code': 'code1', 'date': [123,456]}} def addGuy(row_info): key = row_info[1] co...
0
2016-09-15T20:56:53Z
[ "python", "dictionary" ]
Update dictionary if in list
39,519,910
<p>I'm running through an excel file reading line by line to create dictionaries and append them to a list, so I have a list like:</p> <pre><code>myList = [] </code></pre> <p>and a dictionary in this format:</p> <pre><code>dictionary = {'name': 'John', 'code': 'code1', 'date': [123,456]} </code></pre> <p>so I do th...
0
2016-09-15T20:33:55Z
39,520,309
<p>If you <em>dict.update</em> the existing data each time you see a repeated name, your code can be reduced to a dict of dicts right where you read the file. Calling update on existing dicts with the same keys is going to overwrite the values leaving you with the last occurrence so even if you had multiple "John" dict...
0
2016-09-15T21:01:41Z
[ "python", "dictionary" ]
PySpark reduceByKey with multiple values
39,519,922
<p>So while I have the identical title as this question: <a href="http://stackoverflow.com/questions/30831530/pyspark-reducebykey-on-multiple-values">PySpark reduceByKey on multiple values</a></p> <p>I cannot get the answer to work for what I want to do.</p> <pre><code>A = sc.parallelize([("a", (1,0)), ("b", (4,2)),(...
0
2016-09-15T20:34:27Z
39,520,267
<p>I found the problem. Some parenthesis:</p> <pre><code>A.reduceByKey(lambda x, y: (x[0]+y[0] ,x[1]+y[1])).collect() </code></pre>
0
2016-09-15T20:58:43Z
[ "python", "apache-spark", "pyspark" ]
How can I get my gradle test task to use python pip install for library that isn't on maven central?
39,519,939
<p>I am trying to set up a gradle task that will run Robot tests. Robot uses a python library to interact with Selenium in order to test a web page through a browser. But unfortunately it seems the only way to install the <a href="https://github.com/robotframework/Selenium2Library" rel="nofollow">https://github.com/rob...
2
2016-09-15T20:35:44Z
39,661,942
<p>I had to use a gradle Exec task to run a python script that then kicked off the robot tests. So it looked like this:</p> <p>build.gradle</p> <pre><code>task acceptanceTest(type: Exec) { workingDir 'src/testAcceptance' commandLine 'python', 'run.py' } </code></pre> <p>src/testAcceptance/run.py</p> <pre><c...
0
2016-09-23T13:24:40Z
[ "python", "selenium", "gradle", "robotframework", "selenium2library" ]
Print values from list based from separate text file
39,519,978
<p>How do I print a list of words from a separate text file? I want to print all the words unless the word has a length of 4 characters. </p> <p>words.txt file looks like this:</p> <p>abate chicanery disseminate gainsay latent aberrant coagulate dissolution garrulous laud</p> <p>It has 334 total words in...
-1
2016-09-15T20:38:18Z
39,521,850
<p>To read all words from a text file, and print each of them unless they have a length of 4:</p> <pre><code>with open("words.txt","r") as wordsFile: words = wordsFile.read() wordsList = words.split() print ("Selected words are:") for word in wordsList: if len(word) != 4: # ..unless it has a length of ...
1
2016-09-15T23:38:25Z
[ "python", "python-3.x" ]
Print values from list based from separate text file
39,519,978
<p>How do I print a list of words from a separate text file? I want to print all the words unless the word has a length of 4 characters. </p> <p>words.txt file looks like this:</p> <p>abate chicanery disseminate gainsay latent aberrant coagulate dissolution garrulous laud</p> <p>It has 334 total words in...
-1
2016-09-15T20:38:18Z
39,521,961
<p>Given that you only want the first 10 words. There isn't much point reading all 4 lines. You can safely read just the 1st and save yourself some time.</p> <pre><code>#from itertools import chain with open('words.txt') as f: # could raise `StopIteration` if file is empty words = next(f).strip().split() ...
1
2016-09-15T23:54:02Z
[ "python", "python-3.x" ]
Print values from list based from separate text file
39,519,978
<p>How do I print a list of words from a separate text file? I want to print all the words unless the word has a length of 4 characters. </p> <p>words.txt file looks like this:</p> <p>abate chicanery disseminate gainsay latent aberrant coagulate dissolution garrulous laud</p> <p>It has 334 total words in...
-1
2016-09-15T20:38:18Z
39,522,408
<p>While i'd use a for or a while loop, like Paul Rooney suggested, you can also adapt your code. When you create the list lengths[], you create a list with ALL the lengths of the words contained in wordList.</p> <p>You then cycle the first 10 lengths in lengths[] with the for loop; If you need to use this method, you...
1
2016-09-16T01:01:49Z
[ "python", "python-3.x" ]
Nested comprehensions in Elixir
39,520,002
<p>In Python, one can do this <code>[e2 for e1 in edits1(word) for e2 in edits1(e1)]</code>. What is the equivalent (and right) form of this construct in Elixir?</p> <p>What I tried, is:</p> <pre><code>def edits2(word) do (for e1 &lt;- edits1(word), do: edits1(e1)) |&gt; Enum.reduce(MapSet.new, fn(item, acc) -&gt...
1
2016-09-15T20:39:41Z
39,521,510
<p>Ok, so the anwser to my initial question is just what @Dogbert suggested: <code>for e1 &lt;- edits1(word), e2 &lt;- edits1(e1), into: MapSet.new, do: e2</code></p> <p>But the bottleneck wan't this particular line. See <a href="https://github.com/visar/spell_check/commit/857653593ca98310db028601e9cfc59dc1ac13a4?diff...
0
2016-09-15T22:53:34Z
[ "python", "elixir", "list-comprehension" ]
numpy - return index If value inside one of 3d array
39,520,060
<p>How to do this in Numpy : Thank you!</p> <p><strong>Input :</strong> </p> <pre><code>A = np.array([0, 1, 2, 3]) B = np.array([[3, 2, 0], [0, 2, 1], [2, 3, 1], [3, 0, 1]]) </code></pre> <hr> <p><strong>Output :</strong></p> <pre><code>result = [[0, 1, 3], [1, 2, 3], [0, 1, 2], [0, 2, 3]] </code></pre> <hr> ...
3
2016-09-15T20:44:14Z
39,520,541
<p><strong>Approach #1</strong></p> <p>Here's a NumPy vectorized approach using <a href="http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html" rel="nofollow"><code>broadcasting</code></a> -</p> <pre><code>R,C = np.where((A[:,None,None] == B).any(-1)) out = np.split(C,np.flatnonzero(R[1:]&gt;R[:-1])+1) </code...
3
2016-09-15T21:20:01Z
[ "python", "arrays", "numpy", "indexing", "collect" ]
numpy - return index If value inside one of 3d array
39,520,060
<p>How to do this in Numpy : Thank you!</p> <p><strong>Input :</strong> </p> <pre><code>A = np.array([0, 1, 2, 3]) B = np.array([[3, 2, 0], [0, 2, 1], [2, 3, 1], [3, 0, 1]]) </code></pre> <hr> <p><strong>Output :</strong></p> <pre><code>result = [[0, 1, 3], [1, 2, 3], [0, 1, 2], [0, 2, 3]] </code></pre> <hr> ...
3
2016-09-15T20:44:14Z
39,520,550
<p>An option with a combination of <code>numpy</code> and <code>list-comprehension</code>:</p> <pre><code>import numpy as np [np.where((B == x).sum(axis = 1))[0] for x in A] # [array([0, 1, 3]), array([1, 2, 3]), array([0, 1, 2]), array([0, 2, 3])] </code></pre>
0
2016-09-15T21:20:33Z
[ "python", "arrays", "numpy", "indexing", "collect" ]
Docker, pylibmc, memcached
39,520,061
<p>I've project that uses memcached. So when docker trying to "pip install pylibmc", library can't find libmemcached cause it's not installed yet. How can I organise my docker-compose.yml, or maybe I have to do something with dockerfile?</p> <p>Now my docker-compose.yml looks like (I've deleted memcached container lin...
0
2016-09-15T20:44:14Z
39,522,252
<p>You have two options. Installing it within your app container or install memcached as isolated container. </p> <p><strong>OPTION 1</strong></p> <p>You can add a command to install <code>libmemcached</code> on your app's <code>Dockerfile</code>. </p> <p>If you are using some kind of ubuntu based image or alpine</p...
0
2016-09-16T00:39:07Z
[ "python", "docker", "memcached", "docker-compose", "pylibmc" ]
Docker, pylibmc, memcached
39,520,061
<p>I've project that uses memcached. So when docker trying to "pip install pylibmc", library can't find libmemcached cause it's not installed yet. How can I organise my docker-compose.yml, or maybe I have to do something with dockerfile?</p> <p>Now my docker-compose.yml looks like (I've deleted memcached container lin...
0
2016-09-15T20:44:14Z
39,548,568
<p>The easiest way to solve this problem is to update the <code>Dockerfile</code> for the app and install the development dependencies required to build the python package. </p> <p>On ubuntu/debian that might be something like:</p> <pre><code>apt-get install libmemcached-dev gcc python-dev </code></pre> <p>A second ...
0
2016-09-17T15:31:24Z
[ "python", "docker", "memcached", "docker-compose", "pylibmc" ]
Creating summary rows in pivot tables
39,520,069
<p>I have dataframe: </p> <pre><code>df = pd.DataFrame({'State': {0: "AZ", 1: "AZ", 2:"AZ", 4: "AZ", 5: "AK", 6: "AK", 7 : "AK", 8: "AK"}, 'City': {0: "A", 1: "A", 2:"B", 4: "B", 5: "C", 6: "C", 7 : "D", 8: "D"}, 'Area': {0: "North", 1: "South", 2:"North", 4: "South", 5: "North", 6: "So...
1
2016-09-15T20:44:59Z
39,523,064
<p>Edit: missed the fact that you wanted the state margins in there as well. I'm leaving the original answer up just in case -- it might still be useful. Scroll down for some hacky pandas.</p> <hr> <p>Does this help?</p> <pre><code>In [1]: import pandas as pd In [2]: import numpy as np In [3]: df = pd.DataFrame({'...
1
2016-09-16T02:47:14Z
[ "python", "pandas" ]
Python Selenium: Firefox set_preference to overwrite files on download?
39,520,095
<p>I am using these Firefox preference setting for <code>selenium</code> in Python 2.7:</p> <pre><code>ff_profile = webdriver.FirefoxProfile(profile_dir) ff_profile.set_preference("browser.download.folderList", 2) ff_profile.set_preference("browser.download.manager.showWhenStarting", False) ff_profile.set_preference(...
1
2016-09-15T20:47:05Z
39,520,192
<p>This is something that is <em>out of the Selenium's scope</em> and is handled by the operating system.</p> <p>Judging by the context of this and your <a href="http://stackoverflow.com/q/39519518/771848">previous question</a>, you know (or can determine from the link text) the filename beforehand. If this is really ...
1
2016-09-15T20:54:25Z
[ "python", "selenium", "firefox" ]
Tkinter not displaying Unicode characters properly on Linux
39,520,096
<p>While on Windows tkinter seems to display the characters properly, the same does not happen with the same code on Linux.</p> <p>I've tried the method shown <a href="http://tkinter.unpythonic.net/wiki/UnicodeSupport]" rel="nofollow">here</a>, adding a <code>.encode("utf-8")</code> after the character, but that just ...
0
2016-09-15T20:47:06Z
39,520,160
<p>The font "arial" don't support unicode characters U+23EE and U+23ED on your Linux installation. Can you check that with a font manager?</p>
1
2016-09-15T20:51:31Z
[ "python", "python-3.x", "unicode", "tkinter" ]
Tkinter not displaying Unicode characters properly on Linux
39,520,096
<p>While on Windows tkinter seems to display the characters properly, the same does not happen with the same code on Linux.</p> <p>I've tried the method shown <a href="http://tkinter.unpythonic.net/wiki/UnicodeSupport]" rel="nofollow">here</a>, adding a <code>.encode("utf-8")</code> after the character, but that just ...
0
2016-09-15T20:47:06Z
39,530,226
<p>The Arial on your Linux Mint machine doesn't appear to support those characters.</p> <p>I would suggest adding the font from Windows on Linux.</p> <p>A simple guide can be found here: <a href="https://community.linuxmint.com/tutorial/view/29" rel="nofollow">https://community.linuxmint.com/tutorial/view/29</a></p> ...
1
2016-09-16T11:20:26Z
[ "python", "python-3.x", "unicode", "tkinter" ]
Tkinter not displaying Unicode characters properly on Linux
39,520,096
<p>While on Windows tkinter seems to display the characters properly, the same does not happen with the same code on Linux.</p> <p>I've tried the method shown <a href="http://tkinter.unpythonic.net/wiki/UnicodeSupport]" rel="nofollow">here</a>, adding a <code>.encode("utf-8")</code> after the character, but that just ...
0
2016-09-15T20:47:06Z
39,544,538
<p>All modern Linux GUI toolkits support font substitution since about 2003 (the toolkit will use other fonts to complete the selected one if it's missing glyphs), but tk is not a modern toolkit, it is windows-oriented and butt-ugly on Linux, and it largely missed this change, not sure how stuck in the past it currentl...
1
2016-09-17T08:15:35Z
[ "python", "python-3.x", "unicode", "tkinter" ]
Pandas pd.cut Field Where Other Field Equals Value
39,520,101
<p>I am trying to use pd.cut to create a new field. The creation/population of this new field is dependent on a value in another field, however. </p> <pre><code>hdl_bins = [0,40,59,300] hdl_labels = ['hdl_high risk','hdl_borderline','hdl_protective'] df['hdl'] = pd.cut(df['value'],bins=hdl_bins,labels=hdl_labels)...
0
2016-09-15T20:47:15Z
39,520,301
<p><strong>UPDATE:</strong></p> <p>Pay attention at the last row (<code>value == 'XXX'</code>): </p> <pre><code>In [55]: df Out[55]: id date name value 0 1 1/1/11 Weight 76.3 1 1 1/2/11 Height 152.7 2 1 1/3/11 Bo...
1
2016-09-15T21:00:48Z
[ "python", "pandas", "dataframe" ]
Get directory dynamically with python script
39,520,149
<p>I run my python script in the background from a terminal with:</p> <pre><code>python myscript.py &amp; </code></pre> <p>In the script I have a loop which gets the current directory with os.getcwd(). If I change my working directory in the terminal though, the script doesn't get the new directory because as far as ...
0
2016-09-15T20:50:49Z
39,520,287
<p><em>Disclaimer:</em> don't do this. </p> <pre><code>import os import subprocess from time import sleep ppid = os.getppid() print "parent process id: ", ppid subprocess.check_call(['pwdx', str(ppid)]) sleep(5) # do `cd other` in the parent process here subprocess.check_call(['pwdx', str(ppid)]) </code></pre>
1
2016-09-15T21:00:00Z
[ "python", "terminal", "directory" ]
Using SQLAlchemy, determine which list values are not in a DB column
39,520,159
<p>Using SQLAlchemy, given a list, I'd like to determine which values in the list are not present in a given column in an sqlite DB table. One way to do it is the following:</p> <pre><code>def get_user_ids_not_in_DB(self, user_ids): query__belongs = User_DB.user_id.in_(user_ids) select__user_ids_in_DB = self.S...
1
2016-09-15T20:51:24Z
39,520,248
<p>Select all users then outer join it to an Aliased the User_db object Then add a filter for non-Aliased user_id's that are null.</p> <pre><code> # an alias to a subquery on a table. All user ids in you list ualias = aliased(User_DB, User_DB.user_id.in_(user_ids)) results = self.SQL_Helper.db.query(User_D...
2
2016-09-15T20:57:39Z
[ "python", "python-2.7", "sqlalchemy" ]
Using SQLAlchemy, determine which list values are not in a DB column
39,520,159
<p>Using SQLAlchemy, given a list, I'd like to determine which values in the list are not present in a given column in an sqlite DB table. One way to do it is the following:</p> <pre><code>def get_user_ids_not_in_DB(self, user_ids): query__belongs = User_DB.user_id.in_(user_ids) select__user_ids_in_DB = self.S...
1
2016-09-15T20:51:24Z
39,520,393
<p>That's the most efficient I can think of (quite close to yours):</p> <pre><code>from future_builtins import zip, map from operator import itemgetter def get_user_ids_not_in_DB(self, user_ids): unique_ids = set(user_ids) query__belongs = User_DB.user_id.in_(unique_ids) select__user_ids_in_DB = self.SQL_...
1
2016-09-15T21:08:46Z
[ "python", "python-2.7", "sqlalchemy" ]
Add constraint to OpenMDAO at the driver/prob level
39,520,186
<p>Is it possible to add a constraint to an OpenMDAO problem? In the following example, I would like to constrain the objective function to lying below <code>-3.16</code>. I have imported the sellar problem from another file, <code>sellar_backend.py</code>. Is it possible for me to add this constraint without modifying...
0
2016-09-15T20:53:59Z
39,520,407
<p>You were close. The <code>add</code> method is on top.root, not top. You add components to Groups, in this case the root group of the problem.</p> <pre><code># This is my best attempt so far at adding a constraint at this level top.root.add('new_constraint', ExecComp('new_con = -3.16 - obj'), promotes=['*']) top.dr...
1
2016-09-15T21:09:31Z
[ "python", "optimization", "constraints", "openmdao" ]
How to subscribe to a list of multiple kafka wildcard patterns using kafka-python?
39,520,222
<p>I'm subscribing to Kafka using a pattern with a wildcard, as shown below. The wildcard represents a dynamic customer id.</p> <pre><code>consumer.subscribe(pattern='customer.*.validations') </code></pre> <p>This works well, because I can pluck the customer Id from the topic string. But now I need to expand on the f...
3
2016-09-15T20:56:21Z
39,574,630
<p>In the KafkaConsumer code, it supports list of topics, or a pattern,</p> <p><a href="https://github.com/dpkp/kafka-python/blob/68c8fa4ad01f8fef38708f257cb1c261cfac01ab/kafka/consumer/group.py#L717" rel="nofollow">https://github.com/dpkp/kafka-python/blob/68c8fa4ad01f8fef38708f257cb1c261cfac01ab/kafka/consumer/group...
4
2016-09-19T13:38:16Z
[ "python", "apache-kafka", "python-kafka" ]
Weird behaviour with threads and processes mixing
39,520,236
<p>I'm running the following python code:</p> <pre><code>import threading import multiprocessing def forever_print(): while True: print("") def main(): t = threading.Thread(target=forever_print) t.start() return if __name__=='__main__': p = multiprocessing.Process(target=main) p.sta...
2
2016-09-15T20:57:02Z
39,520,316
<p>You need to call <code>t.join()</code> in your <code>main</code> function.</p> <p>As your <code>main</code> function returns, the process gets terminated with both its threads.</p> <p><code>p.join()</code> blocks the main thread waiting for the spawned process to end. Your spawned process then, creates a thread bu...
2
2016-09-15T21:02:08Z
[ "python", "multithreading", "multiprocessing" ]
Weird behaviour with threads and processes mixing
39,520,236
<p>I'm running the following python code:</p> <pre><code>import threading import multiprocessing def forever_print(): while True: print("") def main(): t = threading.Thread(target=forever_print) t.start() return if __name__=='__main__': p = multiprocessing.Process(target=main) p.sta...
2
2016-09-15T20:57:02Z
39,520,414
<p>For now, threads created <em>by</em> <code>multiprocessing</code> worker processes act like daemon threads with respect to process termination: the worker process exits without waiting for the threads it created to terminate. This is due to worker processes using <code>os._exit()</code> to shut down, which skips m...
2
2016-09-15T21:09:45Z
[ "python", "multithreading", "multiprocessing" ]
Weird behaviour with threads and processes mixing
39,520,236
<p>I'm running the following python code:</p> <pre><code>import threading import multiprocessing def forever_print(): while True: print("") def main(): t = threading.Thread(target=forever_print) t.start() return if __name__=='__main__': p = multiprocessing.Process(target=main) p.sta...
2
2016-09-15T20:57:02Z
39,520,417
<p>The gotcha is that the <code>multiprocessing</code> machinery calls <a href="https://docs.python.org/2/library/os.html#os._exit" rel="nofollow"><code>os._exit()</code></a> after your target function exits, which violently kills the child process, even if it has background threads running.</p> <p>The code for <code>...
2
2016-09-15T21:10:06Z
[ "python", "multithreading", "multiprocessing" ]
Ignore preceding values for a given column when calculating rolling.mean using Pandas
39,520,283
<p>Here is a <em>very small</em> subset of time series data that I have:</p> <pre><code>Date Client Value 01-Sep-2016T ABC 160000 02-Sep-2016T ABC 150000 03-Sep-2016T ABC 190000 04-Sep-2016T ABC 200000 05-Sep-2016T ABC 14000...
1
2016-09-15T20:59:48Z
39,520,351
<p>I have a solution for you that doesn't directly answer the specific question you asked, but will probably solve the problem you actually have ;)</p> <p>To wit: The <code>groupby</code> feature of Pandas. </p> <p>Obviously your datadrame is <em>not</em> just a simple time series. It is instead a bunch of time serie...
1
2016-09-15T21:04:44Z
[ "python", "pandas", "moving-average" ]
Ignore preceding values for a given column when calculating rolling.mean using Pandas
39,520,283
<p>Here is a <em>very small</em> subset of time series data that I have:</p> <pre><code>Date Client Value 01-Sep-2016T ABC 160000 02-Sep-2016T ABC 150000 03-Sep-2016T ABC 190000 04-Sep-2016T ABC 200000 05-Sep-2016T ABC 14000...
1
2016-09-15T20:59:48Z
39,520,500
<p><strong>UPDATE:</strong></p> <pre><code>In [41]: df['new'] = (df.groupby('Client', as_index=False) ....: .rolling(3, min_periods=1, center=False) ....: .Value.mean() ....: .reset_index(drop=True)) In [42]: df Out[42]: Date Client Value ...
1
2016-09-15T21:16:28Z
[ "python", "pandas", "moving-average" ]
Filtering / smoothing a step function to retrieve biggest increments
39,520,349
<p>I have a pandas Series where the index are date time.</p> <p>I can plot my function with the <code>step()</code> function which plots each point of the Series relatively to the time (x is the time).</p> <p>I want a less precise approach of the evolution in time. So I need to reduce the number of steps, and ignore ...
1
2016-09-15T21:04:31Z
39,521,031
<p>One way is to create a mask from your original series where the absolute difference in value from the previous value in the series is compared against your sensitivity threshold. The mask is simply a boolean selection array (matrix) for filtering your original series.</p> <pre><code>#my_series is your Series thresh...
0
2016-09-15T22:05:38Z
[ "python", "pandas", "numpy" ]
Filtering / smoothing a step function to retrieve biggest increments
39,520,349
<p>I have a pandas Series where the index are date time.</p> <p>I can plot my function with the <code>step()</code> function which plots each point of the Series relatively to the time (x is the time).</p> <p>I want a less precise approach of the evolution in time. So I need to reduce the number of steps, and ignore ...
1
2016-09-15T21:04:31Z
39,521,035
<p>You could use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.resample.html" rel="nofollow">pandas resample function</a>. </p> <p>Import the data and set the columns to 'Date' and 'Values'. The rest parses the Date column as datetime. </p> <pre><code>import pandas as pd from datetim...
-1
2016-09-15T22:06:01Z
[ "python", "pandas", "numpy" ]
Filtering / smoothing a step function to retrieve biggest increments
39,520,349
<p>I have a pandas Series where the index are date time.</p> <p>I can plot my function with the <code>step()</code> function which plots each point of the Series relatively to the time (x is the time).</p> <p>I want a less precise approach of the evolution in time. So I need to reduce the number of steps, and ignore ...
1
2016-09-15T21:04:31Z
39,524,763
<p>so this is my idea:</p> <pre><code># Load the data a = load_table('&lt;your_data_file&gt;', delim_whitespace=True, names=['value'], index_col=0) # Create and additional column containing the difference #+between two consecutive values: a['diff'] = a.value.diff() # select only the value of the 'diff' column highe...
1
2016-09-16T06:09:37Z
[ "python", "pandas", "numpy" ]
Filtering a multiindex dataframe based on column values dropping all rows inside level
39,520,362
<p>I am trying to filter a DataFrame based on one or more values. Here is an example CSV:</p> <pre><code>AlignmentId,TranscriptId,classifier,value ENSMUST00000025010-1,ENSMUST00000025010,AlnCoverage,0.99612 ENSMUST00000025010-1,ENSMUST00000025010,AlnIdentity,0.93553 ENSMUST00000025010-1,ENSMUST00000025010,Badness,0.06...
2
2016-09-15T21:06:20Z
39,520,885
<p>try this:</p> <pre><code>In [169]: df = df.drop(df[(df.classifier=='AlnCoverage') &amp; (df.value &lt; 1)].index) In [170]: df Out[170]: classifier value AlignmentId TranscriptId ENSMUST00000025014-1 ENSMUST00000025014 AlnCoverage 1.00000 ...
2
2016-09-15T21:50:09Z
[ "python", "pandas", "dataframe", "multi-index" ]
Plotting dates and associated values from a dictionary with Matplotlib
39,520,366
<p>I have a dictionary containing instances of Python's <code>datetime.date</code> and associated numeric values (integers). Something like this but a lot larger of course:</p> <pre><code>{datetime.date(2016, 5, 31): 27, datetime.date(2016, 9, 1): 87} </code></pre> <p>I am trying to use Matplotlib in order to build a...
0
2016-09-15T21:06:31Z
39,520,576
<p>Using only <code>matplotlib</code>:</p> <pre><code>In [1]: import matplotlib.pyplot as plt In [2]: time_dict = {datetime.date(2016, 5, 31): 27, datetime.date(2016, 8, 1): 88, datetime.date(2016, 2, 5): 42, datetime.date(2016, 9, 1): 87} In [3]: x,y = zip(*sorted(time_dict.items())) In [4]: plt.plot(x,y) Out[4]:...
1
2016-09-15T21:22:29Z
[ "python", "datetime", "matplotlib" ]
Phone 'MA' is mising in the acoustic model; word 'masoud' - pocketsphinx
39,520,456
<p>my name is <code>masoud</code>. now I want to when I say <code>masoud</code>, my app print a console log. </p> <p>to do this I made a <code>mdic.txt</code> file and I put my name inside it :</p> <blockquote> <p>masoud MA S O D</p> </blockquote> <p>I changed <code>mdic.txt</code> to <code>mdic.dict</code> and pu...
0
2016-09-15T21:13:08Z
39,525,224
<p>The correct transcription for masoud is "M AH S UW D". </p> <p>There is no phone MA in acoustic model. The error says about that.</p>
1
2016-09-16T06:42:21Z
[ "android", "python", "pocketsphinx", "pocketsphinx-android" ]
How to measure the memory footprint of importing pandas?
39,520,532
<p>I am running Python on a low memory system.</p> <p>I want to know whether or not importing pandas will increase memory usage significantly.</p> <p>At present I just want to import pandas so that I can use the date_range function.</p>
0
2016-09-15T21:18:58Z
39,520,634
<p>You can try to use the <code>info()</code> method of <code>pd.DataFrame</code>, this will give you an idea of the memory usage.</p> <pre><code>In [56]: df = pd.DataFrame(data=np.random.rand(5,5), columns=list('ABCDE')) In [57]: df Out[57]: A B C D E 0 0.229201 0.145442 ...
2
2016-09-15T21:26:44Z
[ "python", "pandas" ]
How to measure the memory footprint of importing pandas?
39,520,532
<p>I am running Python on a low memory system.</p> <p>I want to know whether or not importing pandas will increase memory usage significantly.</p> <p>At present I just want to import pandas so that I can use the date_range function.</p>
0
2016-09-15T21:18:58Z
39,520,649
<p>You may also want to use a Memory Profiler to get an idea of how much memory is allocated to your Pandas objects. There are several Python Memory Profilers you can use (a simple Google search can give you an idea). PySizer is one that I used a while ago.</p>
3
2016-09-15T21:28:21Z
[ "python", "pandas" ]
Matplotlib colored sphere
39,520,555
<p>I have a data set which maps a tuple of phi and theta to a value which represents the strength of the signal. I want to plot these on a sphere. I simply followed a demo from matplotlib and adjusted the code to my use case. </p> <pre><code>from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm import mat...
0
2016-09-15T21:20:59Z
39,535,813
<p>If your question is: "How to get rid of this IndexError?", I modified your code and now it works. <code>plot_surface</code> takes X,Y,Z and facecolors as 2D arrays of corresponding <strong>values on a 2D grid</strong>. Facecolors in your case weren't and this was the source of your error. </p> <pre><code>from mpl_...
2
2016-09-16T16:04:14Z
[ "python", "matplotlib" ]
allPrimes printing out a empty tuple Python
39,520,586
<p>So I have this code and it is supposed to print out a tuple with all the prime numbers in it. But instead, it's just printing out a empty tuple... </p> <blockquote> <p>Can anyone tell me why? I also MUST USE A TUPLE.</p> </blockquote> <pre><code>def isPrime(number): for i in range(2,int(number**(0.5))+1): ...
0
2016-09-15T21:23:06Z
39,520,638
<p>It's because your isPrime function doesn't work.</p> <p><code>number % 1</code>, i.e. 'remainder when divided by 1', will always be zero for integers. </p>
1
2016-09-15T21:27:13Z
[ "python", "tuples", "primes" ]
allPrimes printing out a empty tuple Python
39,520,586
<p>So I have this code and it is supposed to print out a tuple with all the prime numbers in it. But instead, it's just printing out a empty tuple... </p> <blockquote> <p>Can anyone tell me why? I also MUST USE A TUPLE.</p> </blockquote> <pre><code>def isPrime(number): for i in range(2,int(number**(0.5))+1): ...
0
2016-09-15T21:23:06Z
39,520,681
<p>Your <code>isPrime()</code> function starts at 1. Every integer is evenly divisible by 1, so it always returns <code>False</code>. Start at 2 instead.</p> <pre><code>def isPrime(number): if number &lt; 2: return False for i in range(2, int(number ** (0.5)) + 1): if number % i == 0: ...
2
2016-09-15T21:32:09Z
[ "python", "tuples", "primes" ]
allPrimes printing out a empty tuple Python
39,520,586
<p>So I have this code and it is supposed to print out a tuple with all the prime numbers in it. But instead, it's just printing out a empty tuple... </p> <blockquote> <p>Can anyone tell me why? I also MUST USE A TUPLE.</p> </blockquote> <pre><code>def isPrime(number): for i in range(2,int(number**(0.5))+1): ...
0
2016-09-15T21:23:06Z
39,520,755
<p>There are a few issues in your code:</p> <p>1) In <code>isPrime</code> returns <code>True</code> on the wrong line</p> <p>2) You are printing <code>tup</code> outside the function scope</p> <p>3) You are not handling case of <code>1</code> (in <code>isPrime</code>)</p> <p>4) You are using <code>tuple</code> to s...
1
2016-09-15T21:38:17Z
[ "python", "tuples", "primes" ]
allPrimes printing out a empty tuple Python
39,520,586
<p>So I have this code and it is supposed to print out a tuple with all the prime numbers in it. But instead, it's just printing out a empty tuple... </p> <blockquote> <p>Can anyone tell me why? I also MUST USE A TUPLE.</p> </blockquote> <pre><code>def isPrime(number): for i in range(2,int(number**(0.5))+1): ...
0
2016-09-15T21:23:06Z
39,520,770
<p>Because in the first iteration if <code>number % i != 0:</code> the number is prime, you have to return <code>True</code> at the end of the iteration an break it if `number % i == 0: </p> <pre><code>def isPrime(number): res = True if number &lt; 2: res = False else: for i in range(2,int...
0
2016-09-15T21:39:23Z
[ "python", "tuples", "primes" ]
Determining where certain text comes from on website
39,520,633
<p>I'm trying to write a bash script that downloads the Photo of the Day from <a href="http://www.nationalgeographic.com/photography/photo-of-the-day/" rel="nofollow">National Geographic</a>, sets it as the desktop background, and puts the description of the picture found on the page in a text file on the desktop. (I'm...
2
2016-09-15T21:26:42Z
39,520,838
<p>Buried within the html for that National Geographic page is the following attribute:</p> <pre><code>data-platform-endpoint="http://www.nationalgeographic.com/photography/photo-of-the-day/_jcr_content/.gallery.2016-09.json" </code></pre> <p>The caption that you seek is in the JSON file that that URL points to. For ...
1
2016-09-15T21:46:48Z
[ "python", "html", "bash" ]
Reading XML on python 2.1
39,520,702
<p>So, i'm trying to process a XML file on python.</p> <p>I'm using minidom as I'm in python 2.1 and there's no change to updating to 3.6. Currently, I have this</p> <pre><code>import xml.dom.minidom as minidom import socket print 'Getting the xml file' # Get the xml contents file = open('&lt;filepath&gt;') #print fi...
0
2016-09-15T21:33:13Z
39,537,678
<p>So, I was able to get this working</p> <p>For starters, after trying to convince to either update or install a plugin, I was notified that all python scripts are ran on <code>jython</code>, which mean, I have several java libraries to my disposal (wish they could had told me this quite sooner)</p> <p>So, after som...
1
2016-09-16T18:08:56Z
[ "python", "xml", "python-2.1" ]
Using selenium on calendar date picker
39,520,708
<p>I am trying to pick a date (01/01/2011) from a calendar on this page. <a href="https://cotthosting.com/NYRocklandExternal/LandRecords/protected/SrchQuickName.aspx" rel="nofollow">https://cotthosting.com/NYRocklandExternal/LandRecords/protected/SrchQuickName.aspx</a></p> <p>The calendar is on the part of the form th...
1
2016-09-15T21:33:57Z
39,525,969
<p>I use Actions Class in Java . The Java code which ran successfully is as belows: </p> <pre><code>package stackoverflow; public class question1 { @Test public void a () throws InterruptedException{ System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\CP-SAT\\Chromedriver\\chromedriver.exe"); WebDr...
0
2016-09-16T07:26:58Z
[ "python", "selenium", "datepicker" ]
Using selenium on calendar date picker
39,520,708
<p>I am trying to pick a date (01/01/2011) from a calendar on this page. <a href="https://cotthosting.com/NYRocklandExternal/LandRecords/protected/SrchQuickName.aspx" rel="nofollow">https://cotthosting.com/NYRocklandExternal/LandRecords/protected/SrchQuickName.aspx</a></p> <p>The calendar is on the part of the form th...
1
2016-09-15T21:33:57Z
39,532,746
<p>To get this to work, add one extra step of clicking the element before sending the keys:</p> <pre><code>datefield = driver.find_element_by_id('ctl00_cphMain_SrchDates1_txtFiledFrom') datefield.click() datefield.send_keys("01012011") </code></pre> <h1>Update:</h1> <p>It looks like you might have to use <a href="ht...
0
2016-09-16T13:30:10Z
[ "python", "selenium", "datepicker" ]
How do I check if a function is being called by a method?
39,520,806
<p>How do I check if a function b() is being called by a method?</p> <pre><code>class hello(): delete(): b() </code></pre> <p>I want to use mock in a unit test.</p>
0
2016-09-15T21:42:20Z
39,521,115
<p>If you are just looking for a way to mock objects <a href="https://docs.python.org/3/library/unittest.mock.html" rel="nofollow">this</a> is probably the best way to do it.</p> <p>To answer the first part of your question, there is indeed a way to get information about the caller function. <a href="https://stackover...
0
2016-09-15T22:14:08Z
[ "python", "django", "python-2.7", "mocking" ]
How do I check if a function is being called by a method?
39,520,806
<p>How do I check if a function b() is being called by a method?</p> <pre><code>class hello(): delete(): b() </code></pre> <p>I want to use mock in a unit test.</p>
0
2016-09-15T21:42:20Z
39,524,728
<p>Assuming you have a test environment you can in fire up the python(or the Ipython) shell and use the debugger to call the function:</p> <p>if this is your function </p> <pre><code>def multiplier(a,b): print a*b </code></pre> <p>then you can do this in the shell and debug the code:</p> <pre><code>import ipdb ...
0
2016-09-16T06:06:23Z
[ "python", "django", "python-2.7", "mocking" ]
Flask WTF forms adding a glyphicon in a form field
39,520,899
<p>I have a Flask Wtf form as follows:</p> <pre><code>class URL_Status(Form): url = URLField("Enter URL", validators=[url(), DataRequired()], render_kw={"placeholder": "http://www.example.com"},) submit = SubmitField('Search', render_kw={"onclick": "loading()"}) </...
0
2016-09-15T21:51:21Z
39,521,319
<p>I haven't used wtforms in a while. I think you need a custom widget:</p> <pre><code>class CustomURLInput(URLInput): ... def __call__(self,....): ... </code></pre> <p>Take a look at this <a href="https://github.com/wtforms/wtforms/blob/9be964158fbcd1af52b345451bbd14751127dd37/wtforms/widgets/core.py...
1
2016-09-15T22:34:45Z
[ "python", "html", "twitter-bootstrap", "flask", "wtforms" ]
Flask WTF forms adding a glyphicon in a form field
39,520,899
<p>I have a Flask Wtf form as follows:</p> <pre><code>class URL_Status(Form): url = URLField("Enter URL", validators=[url(), DataRequired()], render_kw={"placeholder": "http://www.example.com"},) submit = SubmitField('Search', render_kw={"onclick": "loading()"}) </...
0
2016-09-15T21:51:21Z
39,558,171
<p>Here is a little trick to solve this problem.</p> <p>CSS:</p> <pre><code>.user { padding-left:30px; background-repeat: no-repeat; background-position-x: 4px; background-position-y: 4px; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAWCAYAAAArdgcFAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlY...
1
2016-09-18T13:31:24Z
[ "python", "html", "twitter-bootstrap", "flask", "wtforms" ]
"Cannot deserialize instance of string from START_ARRAY value" Salesforce API issue
39,520,902
<p>Trying to create a SF Contact with values from an .xlsx sheet.</p> <p>I can create a contact if I manually type in a fake email address, lastname and firstname but cannot reference it to a value I have defined from an xlsx sheet. the print commands are working fine and reading the appropriate data I want them to r...
0
2016-09-15T21:51:39Z
39,522,501
<p>The error message from the server says </p> <blockquote> <p>Cannot deserialize instance of string from START_ARRAY value [line:1, column:2]</p> </blockquote> <p>meaning that the server is expecting a field value to be a string, but the request has an array instead.</p> <p>Therefore guessing that sheet.col_val...
0
2016-09-16T01:16:36Z
[ "python", "excel", "python-2.7", "salesforce", "xlrd" ]
How to disable uploading a package to PyPi unless --public is passed to the upload command
39,520,987
<p>I'm developing packages and uploading development/testing/etc versions of my packages to a local devpi server. </p> <p>In order to prevent an accidental upload to PyPi, I'm adopted the common practice of:</p> <pre><code>setup(..., classifiers=[ "Programming Language :: Python", "Programming ...
1
2016-09-15T22:01:05Z
39,522,563
<p>Going backwards on your questions; while it's really broad, the topic is still constrained enough.</p> <p>I can tell you that the classifiers are not manipulated, but rather read from the and then written to <code>PKG-INFO</code> file by the <code>egg_info</code> command, which in turn looks for all <code>egg_info...
1
2016-09-16T01:25:54Z
[ "python", "setuptools", "pypi", "devpi" ]
Python SQLITE substituted query returns nothing from database
39,521,186
<p>I am trying to execute the following query:</p> <pre><code>sqlite&gt; select * from history where timeStamp &gt;= "2016-09-15 13:05:00" and timeStamp &lt; "2016-09-15 13:06:00"; timeStamp isOpen ------------------- ---------- 2016-09-15 13:05:04 0 2016-09-15 13:05:09 0 2016-09-15...
0
2016-09-15T22:21:30Z
39,523,175
<p>In your example SQL, you are using datetimes with the format</p> <pre><code>YYYY-MM-DD HH:MM:SS </code></pre> <p>In your Python example, however, you are using datetimes with the format</p> <pre><code>YYYY/MM/DD HH:MM:SS </code></pre> <p>SQLite isn't seeing this as a valid date format. Change your <code>/</code>...
1
2016-09-16T03:03:39Z
[ "python", "sqlite", "select", "flask", "sqlite3" ]
Importing C file with python bindings in python file
39,521,205
<p>There is a great program written in C, that also contains a conversion to python using python bindings. However I would like to extend the file with bindings to give it more functionality.</p> <p>When I try to change 'import bounded_file' to 'import my_bounded_file' in the python file the bindings are used in, I ge...
-1
2016-09-15T22:23:55Z
39,521,968
<p>The C file needs to be compiled to a shared library. Then, you import this library.</p>
0
2016-09-15T23:55:02Z
[ "python", "c", "import", "binding" ]
Python-Indexing- I do not understand how this bit of code is working
39,521,213
<p>What I do not understand is how indexing a string s = "azcbobobegghakl" would correctly give me the answer 'beggh' if I was looking for the longest substring in alphabetical order. How does this code tell the computer that 'beggh' is in alphabetical order? I thought indexing just gave each letter in the string a num...
0
2016-09-15T22:25:03Z
39,521,261
<p><code>&gt;=</code> compares two characters by their lexicographical order; the expression</p> <pre><code>if c &gt;= current[-1]: </code></pre> <p>tests if <code>c</code> (a single character), is the same or is 'greater' than <code>current[-1]</code> (another single character. Strings are ordered lexicographically ...
1
2016-09-15T22:29:11Z
[ "python", "python-3.x" ]
Python-Indexing- I do not understand how this bit of code is working
39,521,213
<p>What I do not understand is how indexing a string s = "azcbobobegghakl" would correctly give me the answer 'beggh' if I was looking for the longest substring in alphabetical order. How does this code tell the computer that 'beggh' is in alphabetical order? I thought indexing just gave each letter in the string a num...
0
2016-09-15T22:25:03Z
39,521,274
<p>The expression <code>c &gt;= current[-1]</code> lexicographically compares each character with its predecessor in the string. More simply:</p> <pre><code>&gt;&gt;&gt; 'a' &gt;= 'a' True &gt;&gt;&gt; 'b' &gt;= 'a' True &gt;&gt;&gt; 'b' &gt;= 'c' False &gt;&gt;&gt; 'z' &gt;= 'a' True </code></pre> <p>So all the code...
1
2016-09-15T22:30:41Z
[ "python", "python-3.x" ]
Python-Indexing- I do not understand how this bit of code is working
39,521,213
<p>What I do not understand is how indexing a string s = "azcbobobegghakl" would correctly give me the answer 'beggh' if I was looking for the longest substring in alphabetical order. How does this code tell the computer that 'beggh' is in alphabetical order? I thought indexing just gave each letter in the string a num...
0
2016-09-15T22:25:03Z
39,521,320
<pre><code>s = "azcbobobegghakl" # initialize vars to first letter in string longest = s[0] current = s[0] # start iterating through rest of string for c in s[1:]: # c is the letter of current iteration and current[-1] # is the last letter of the current string. Every character # has an ASCII value so t...
0
2016-09-15T22:34:53Z
[ "python", "python-3.x" ]
pyspark error: AttributeError: 'SparkSession' object has no attribute 'parallelize'
39,521,341
<p>I am using pyspark on Jupyter notebook. Here is how Spark setup:</p> <pre><code>import findspark findspark.init(spark_home='/home/edamame/spark/spark-2.0.0-bin-spark-2.0.0-bin-hadoop2.6-hive', python_path='python2.7') import pyspark from pyspark.sql import * sc = pyspark.sql.SparkSession.builder.maste...
1
2016-09-15T22:36:40Z
39,521,419
<p><code>SparkSession</code> is not a replacement for a <code>SparkContext</code> but an equivalent of the <code>SQLContext</code>. Just use it use the same way as you used to use <code>SQLContext</code>:</p> <pre><code>spark.createDataFrame(...) </code></pre> <p>and if you ever have to access <code>SparkContext</cod...
1
2016-09-15T22:44:27Z
[ "python", "hadoop", "pandas", "apache-spark", "pyspark" ]
Error installing python-docx
39,521,451
<p>Trying to install python-docx through pip for 'Learn to Automate the Boring Things with Python'. I am getting errors like <a href="http://imgur.com/a/el2oY" rel="nofollow">this</a>. </p> <p>I have Googled up some solutions to this issue, but they don't seem to work for me, or I am not deploying the solution correct...
1
2016-09-15T22:48:10Z
39,521,575
<p>This mean that C++ Common Tools are not installed.<br> To install them for Python2.7 go to <a href="https://www.microsoft.com/en-us/download/details.aspx?id=44266" rel="nofollow">Microsoft Visual C++ Compiler for Python 2.7</a><br> For python3 install <code>Visual Studio Community 2015</code> and execute the followi...
1
2016-09-15T23:01:54Z
[ "python", "python-2.7", "python-3.x", "pip" ]
Error installing python-docx
39,521,451
<p>Trying to install python-docx through pip for 'Learn to Automate the Boring Things with Python'. I am getting errors like <a href="http://imgur.com/a/el2oY" rel="nofollow">this</a>. </p> <p>I have Googled up some solutions to this issue, but they don't seem to work for me, or I am not deploying the solution correct...
1
2016-09-15T22:48:10Z
39,555,322
<p>so I found the answer to this issue.</p> <p>So I wasn't aware that to install the lxml file, you first need to change to the directory of that file, and type in the <strong>complete name</strong> of that file. Either that, or typing the path of the lxml file directly into the cmd prompt, like:</p> <pre><code>pip i...
0
2016-09-18T07:48:50Z
[ "python", "python-2.7", "python-3.x", "pip" ]
How can I average ACROSS groups in python-pandas?
39,521,461
<p>I have a dataset like this:</p> <pre><code>Participant Type Rating 1 A 6 1 A 5 1 B 4 1 B 3 2 A 9 2 A 8 2 B 7 2 B 6 </code></pre> <p>I want obtain this:</p> <...
0
2016-09-15T22:49:15Z
39,521,666
<p>First use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.DataFrameGroupBy.rank.html" rel="nofollow"><code>groupby.rank</code></a> to create a column that allows you to align the highest values, second highest values, etc. Then perform another <code>groupby</code> using the newly ...
6
2016-09-15T23:12:19Z
[ "python", "pandas" ]
Limit program to send only one email
39,521,551
<p>I have a program to control lots of the things about my hen house including opening and closing the door at set times. Occasionally something happens and the door doesn't open or close and I have now got it to send an email when this happens. The problem is it will send 6 or more emails and I have been trying to wor...
1
2016-09-15T22:58:23Z
39,521,779
<p>Assuming <code>sendemail()</code> is a function you defined, you could rewrite it to store the time it last sent an email, and if it hasn't been long enough, don't send it.</p> <p>The <code>now.minute == HOUR_ON.minute + 120</code> doesn't make sense to me—it looks like you're saying 2 hours, not 2 minutes, unles...
0
2016-09-15T23:28:16Z
[ "python", "raspberry-pi" ]
Limit program to send only one email
39,521,551
<p>I have a program to control lots of the things about my hen house including opening and closing the door at set times. Occasionally something happens and the door doesn't open or close and I have now got it to send an email when this happens. The problem is it will send 6 or more emails and I have been trying to wor...
1
2016-09-15T22:58:23Z
39,551,265
<p>This seems to do it. </p> <pre><code>def loop(): global emailsent1 global emailsent2 # retrieve current datetime now = datetime.time(datetime.datetime.now().hour, datetime.datetime.now().minute) # Open door on all days at the correct time if ((now.hour == HOUR_ON.hour) and (now.minute == HOUR_ON.minut...
0
2016-09-17T20:13:02Z
[ "python", "raspberry-pi" ]
Python - When trying to run the code nothing happens. I don't even get an error
39,521,608
<p>I am trying to create a small betting application with Python and when I try to run the program nothing happens what so ever. I am using IDLE. This is my code:</p> <pre><code>def bet(): #balance = 100 x = 0 with open("bal.txt", "r") as f: for l in f: bal = (sum([int(a) for a in l.spl...
0
2016-09-15T23:05:13Z
39,521,657
<p>The ONLY thing that code does is define a function named <code>bet</code>. You could type <code>bet()</code> in the IDLE shell to call it, or put <code>bet()</code> at the bottom of the file (not indented!) to call it automatically.</p>
2
2016-09-15T23:11:24Z
[ "python", "python-idle" ]
Python - When trying to run the code nothing happens. I don't even get an error
39,521,608
<p>I am trying to create a small betting application with Python and when I try to run the program nothing happens what so ever. I am using IDLE. This is my code:</p> <pre><code>def bet(): #balance = 100 x = 0 with open("bal.txt", "r") as f: for l in f: bal = (sum([int(a) for a in l.spl...
0
2016-09-15T23:05:13Z
39,521,663
<p>Check bal.txt can be open and that it has at least one line whose sum is > 0. The thing here is that one of your conditions is failing</p>
0
2016-09-15T23:12:07Z
[ "python", "python-idle" ]
Django: How to do reverse foreign key lookup of another class without an instance of this class?
39,521,610
<p>I have the following two Django Classes <code>MyClassA</code> and <code>MyClassB</code>.</p> <p><code>MyClassB</code> has a foreign key reference to an instance of <code>MyClassA</code>.</p> <pre><code>from django.db import models class MyClassA(models.Model): name = models.CharField(max_length=50, null=False...
2
2016-09-15T23:05:34Z
39,521,633
<p>Since it is a <code>staticmethod</code>, you don't need an instance. </p> <p>You can call <code>MyClassB.my_method_b()</code> directly.</p>
1
2016-09-15T23:08:11Z
[ "python", "django", "static-methods", "class-method", "instance-method" ]
Raise ClientException(required_message.format(attribute)) praw.exceptions.ClientException: Required configuration setting 'client_id' missing
39,521,621
<p>I am not sure how to make this work. I also can't find client_id in my app. I just see the app secret there:</p> <pre><code>&gt;&gt;&gt; import praw &gt;&gt;&gt; r = praw.Reddit(user_agent='custom data mining framework', ... site_name='lamiastella') Traceback (most recent call last): File "&lt;stdin&gt;", line 2,...
1
2016-09-15T23:07:18Z
39,522,434
<p>The error is caused from a missing <code>client_id</code> (which is your unique API key and secret for the Reddit API) in your <code>praw.ini</code> file or in your Python script.</p> <p>In your script you could have something like:</p> <pre><code>r.set_oauth_app_info(client_id='stJlUSUbPQe5lQ', ... ...
1
2016-09-16T01:05:41Z
[ "python", "reddit", "praw" ]
I'm struggling to write numbers (0-10) into a CSV file. How do I change into a list, convert to integers, and have the number on each line?
39,521,623
<h1>Writes numbers from 0 to 10 into a CSV file</h1> <p>import csv</p> <pre><code>fileW = open('numbers.csv', 'w') fileW.write('0,') fileW.write('\n1,') fileW.write('\n2,') fileW.write('\n3,') fileW.write('\n4,') fileW.write('\n5') fileW.write('\n6,') fileW.write('\n7,') fileW.write('\n8,') fileW.write('\n9,') fileW....
-2
2016-09-15T23:07:24Z
39,521,730
<p>let's use a for loop, shall we ?</p> <pre><code># generate the list with commas fileW = open('numbers.csv', 'w') for i in xrange(11): fileW.write('%s,\n'%i) fileW.close() # open the file and read line by line with open('numbers.csv','r') as fileR: for line in fileR: # remove the trailing comma,...
0
2016-09-15T23:21:40Z
[ "python" ]
I'm struggling to write numbers (0-10) into a CSV file. How do I change into a list, convert to integers, and have the number on each line?
39,521,623
<h1>Writes numbers from 0 to 10 into a CSV file</h1> <p>import csv</p> <pre><code>fileW = open('numbers.csv', 'w') fileW.write('0,') fileW.write('\n1,') fileW.write('\n2,') fileW.write('\n3,') fileW.write('\n4,') fileW.write('\n5') fileW.write('\n6,') fileW.write('\n7,') fileW.write('\n8,') fileW.write('\n9,') fileW....
-2
2016-09-15T23:07:24Z
39,521,740
<p>This is a pythonic way to save, obtain the numbers and create a list named int_list with all those integers:</p> <pre><code>with open('numbers.csv', 'w') as fileW: for i in range(11): fileW.write('%s\n'%i) int_list = [] with open('numbers.csv','r') as fileR: for line in fileR: line = line.r...
0
2016-09-15T23:23:11Z
[ "python" ]
I'm struggling to write numbers (0-10) into a CSV file. How do I change into a list, convert to integers, and have the number on each line?
39,521,623
<h1>Writes numbers from 0 to 10 into a CSV file</h1> <p>import csv</p> <pre><code>fileW = open('numbers.csv', 'w') fileW.write('0,') fileW.write('\n1,') fileW.write('\n2,') fileW.write('\n3,') fileW.write('\n4,') fileW.write('\n5') fileW.write('\n6,') fileW.write('\n7,') fileW.write('\n8,') fileW.write('\n9,') fileW....
-2
2016-09-15T23:07:24Z
39,521,772
<p>What you want is the Python "csv" module <a href="https://docs.python.org/2/library/csv.html" rel="nofollow">https://docs.python.org/2/library/csv.html</a>. This makes it extremely easy to read and write CSV format. For example,</p> <pre><code>import csv import sys writer = csv.writer(sys.stdout) writer.writero...
1
2016-09-15T23:26:41Z
[ "python" ]
Trimming string from oracle
39,521,643
<p>I'm attempting, poorly, to compare two lists of filenames and provide a list of the differences. I have read and attempted the numerous examples available. Before you close this as a Duplicate, or Already Answered, please read further.</p> <p>In python, I'm making a call via ftp to obtain a list of files. This re...
0
2016-09-15T23:09:17Z
39,521,685
<p>So first of all if you want to remove characters from both sides of a string you can use <code>lstrp</code> and <code>rstrip</code>.</p> <pre><code>&gt;&gt;&gt; "('filename')".lstrip("('") 'filename')' &gt;&gt;&gt; "('filename')".rstrip("')") "('filename" </code></pre> <p>But I suspect that the return data is actu...
0
2016-09-15T23:15:05Z
[ "python", "cx-oracle" ]
Python regex search or match not working
39,521,711
<p>I wrote this regex:</p> <pre><code> re.search(r'^SECTION.*?:', text, re.I | re.M) re.match(r'^SECTION.*?:', text, re.I | re.M) </code></pre> <p>to run on this string:</p> <pre><code>text = 'SECTION 5.01. Financial Statements and Other Information. The Parent\nwill furnish to the Administrative Agent:\n ...
1
2016-09-15T23:19:25Z
39,521,756
<p>The <code>.*</code> will match all the text and since your text doesn't ended with <code>:</code> it returns <code>None</code>. You can use a negated character class instead to get the expected result:</p> <pre><code>In [32]: m = re.search(r'^SECTION[^:]*?:', text, re.I | re.M) In [33]: m.group(0) Out[33]: 'SECTIO...
1
2016-09-15T23:25:28Z
[ "python", "regex" ]
how to get a result without brackets in a list?
39,521,715
<p>I have a function which merges two sorted lists (a, b) into one sorted (c). If given lists have different lengths I need to insert the rest of the longest into the list c. But the way I did it - it gives the result with brackets inside the list c (for instance if a = [1,3,5] and b = [2,4,6] then the function returns...
1
2016-09-15T23:19:39Z
39,521,875
<p>you would have to add each value individually like this:</p> <pre><code>if i &lt; len(a): for k in a[i:]: c.append(k) </code></pre>
1
2016-09-15T23:41:12Z
[ "python", "list" ]
how to get a result without brackets in a list?
39,521,715
<p>I have a function which merges two sorted lists (a, b) into one sorted (c). If given lists have different lengths I need to insert the rest of the longest into the list c. But the way I did it - it gives the result with brackets inside the list c (for instance if a = [1,3,5] and b = [2,4,6] then the function returns...
1
2016-09-15T23:19:39Z
39,522,262
<p>You should use <a href="https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types" rel="nofollow"><code>.extend()</code></a> in your last lines:</p> <pre><code>if i &lt; len(a): c.extend(a[i:]) if j &lt; len(b): c.extend(b[j:]) </code></pre> <p>because <code>a[i:]</code> and <code>b[j:]</code>...
1
2016-09-16T00:40:23Z
[ "python", "list" ]