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
The proper way to display multiple windows in tkinter?
38,103,426
<p>I am currently working on a project using Python and tkinter.</p> <p>The problem is that I don't know what's the proper way to display multiple windows, or screens, I don't know how to call them. Let me explain better.</p> <p>When the application starts the login screen appears. After that, if I click register, I ...
-1
2016-06-29T15:04:17Z
38,103,551
<p>You can do that- just call <code>window.withdraw()</code> on the <code>Toplevel</code> you need to hide after creating a new <code>Toplevel</code>. Changing the widgets in the first is also an option- if you like, you could always try a <code>Notebook</code> widget and disable manual flipping or just put each "scree...
0
2016-06-29T15:09:31Z
[ "python", "user-interface", "tkinter" ]
Rescaling to (0,1) certain columns from Pandas Python dataframe
38,103,467
<p>I have the following type of dataframe: </p> <pre><code> Channel Region Fresh Milk Grocery Frozen Detergents_Paper Delicassen 0 2 3 12669 9656 7561 214 2674 1338 1 2 3 7057 9810 9568 1762 3293 1776 2 2 3 635...
2
2016-06-29T15:05:48Z
38,103,525
<p>For 1, you can select a list of columns like this:</p> <pre><code>df[['Milk','Frozen','Grocery']] </code></pre> <p>Therefore, to rescale only those three columns, use:</p> <pre><code>df[['Milk','Frozen','Grocery']] /= df[['Milk','Frozen','Grocery']].max() </code></pre> <p>This method already scales your column i...
3
2016-06-29T15:08:13Z
[ "python", "pandas", "dataframe", "scaling" ]
TypeError: unhashable type: 'list' by converting list to set
38,103,527
<p>I have a list of codes coming from a csv file:</p> <pre><code>file_path = 'c:\\temp\\list.csv' csvfile = open(file_path, 'rb') reader = csv.reader(csvfile, delimiter=';') rr = [] for sor in reader: if sor[1][0] == '1': rr.append(sor) print type(rr) &lt;type 'list'&gt; set (rr) Traceback (most recent c...
0
2016-06-29T15:08:14Z
38,103,571
<p>Every <code>sor</code> is a csv row - a list of row "cell" values, <code>rr</code> becomes a <em>list of lists</em>. Lists cannot be items of a set since <em>lists are <a href="http://stackoverflow.com/questions/14535730/what-do-you-mean-by-hashable-in-python">not hashable</a></em>. </p> <p><code>res1</code> on the...
3
2016-06-29T15:10:16Z
[ "python", "list", "python-2.7", "set" ]
unknown error in beautifulsoup web scrapping using python
38,103,620
<pre><code>&lt;div id="browse_in_widget"&gt; &lt;span id="browse_in_breadcrumb" style="width: 583px;"&gt; &lt;div class="seo_itemscope" itemtype="http://data-vocabulary.org/Breadcrumb" itemscope=""&gt; &lt;a itemprop="url" href="/search/"&gt; Arabian Area&lt;/a&gt; &lt;span class="seo_itemprop-title" itemprop="title"&g...
0
2016-06-29T15:12:23Z
38,103,670
<p>The first problem is that you are looking for <code>span</code> elements with <code>seo_itemscope</code> class which don't exist. Use <code>seo_itemprop-title</code> if you are looking for the titles:</p> <pre><code>Type = [item.get_text() for item in soup.find_all("span", {"class": "seo_itemprop-title"})] </code><...
1
2016-06-29T15:14:29Z
[ "python", "web-scraping", "beautifulsoup", "findall", "bs4" ]
How to add a custom column with csv.writer
38,103,658
<p>I have a python script that takes a huge file and copies out only the few columns that I want while also writing a new custom header in the new file.</p> <pre><code>import csv,time,string,os, requests og_file = "\\\\network\\x\\test.csv" today = time.strftime("%Y-%m-%d") #fields to keep from original file fields...
0
2016-06-29T15:14:04Z
38,103,783
<pre><code>fields = ["id"] + fields # so it'll write later with open(og_file) as infile, open("c:\\upload\\output_" + today + ".csv", "wb") as outfile: r = csv.DictReader(infile) w = csv.DictWriter(outfile, fields, extrasaction="ignore") wtr = csv.writer( outfile ) wtr.writerow(["id","upload_date...
1
2016-06-29T15:19:44Z
[ "python", "csv" ]
How to add a custom column with csv.writer
38,103,658
<p>I have a python script that takes a huge file and copies out only the few columns that I want while also writing a new custom header in the new file.</p> <pre><code>import csv,time,string,os, requests og_file = "\\\\network\\x\\test.csv" today = time.strftime("%Y-%m-%d") #fields to keep from original file fields...
0
2016-06-29T15:14:04Z
38,103,790
<p>You can use a <code>itertools.count</code> object for the <code>id</code> column:</p> <pre><code>from itertools import count with open(og_file) as infile, open("c:\\upload\\output_" + today + ".csv", "wb") as outfile: r = csv.DictReader(infile) w = csv.DictWriter(outfile, fields, extrasaction="ignore") ...
1
2016-06-29T15:20:04Z
[ "python", "csv" ]
Get system information(CPU speed-Total RAM-Graphic Card model etc.) under Windows
38,103,690
<p>I searched a lot but couldn't find anything useful. Is this possible to get system information like;</p> <pre><code>CPU: Intel Core i7-3770K CPU @3.5Ghz RAM: 8GB Graphic Card: NVIDIA GeForce GTX 680 </code></pre> <p>under Windows? How can I reach this output?</p> <p>Edit: <code>platform.processor()</code> is not ...
1
2016-06-29T15:15:24Z
38,105,273
<p>I've been wondering how to do this myself for a while now, so I dug around a bit and came up with this solution using <code>wmi</code> (which requires <code>pywin32</code>). <strong>Of course, it goes without saying, this only works on Windows machines (and the question has the <code>Windows</code> tag).</strong></p...
4
2016-06-29T16:26:40Z
[ "python", "windows", "python-3.4", "system-information" ]
Plotting parallel coordinates in pandas/python
38,103,738
<p>I am trying to use pandas in python to plot the following higher-dimensional data: <a href="http://i.stack.imgur.com/34nbR.jpg" rel="nofollow">http://i.stack.imgur.com/34nbR.jpg</a></p> <p>Here is my code:</p> <pre><code>import pandas from pandas.tools.plotting import parallel_coordinates data = pandas.read_csv('...
2
2016-06-29T15:17:46Z
38,104,166
<p>The second argument is supposed to be the column name that defines <code>class</code>. Think <code>['dog', 'dog', 'cat', 'bird', 'cat', 'dog']</code>.</p> <p>In the <a href="http://pandas.pydata.org/pandas-docs/stable/visualization.html#parallel-coordinates" rel="nofollow">example online</a> they use <code>'Name'<...
1
2016-06-29T15:35:49Z
[ "python", "csv", "pandas", "parallel-coordinates" ]
python - find unused IP / find a number not used in an range of nos?
38,103,896
<p>I have a list of IP addresses (or just numbers for what it matters)</p> <p>example list:</p> <pre><code>192.168.1.1 192.168.1.2 192.168.1.4 192.168.1.5 192.168.1.7 192.168.1.9 </code></pre> <p>what i would like is a function that will show me what IPs/numbers are free in a range.</p> <p>for example if my range w...
-1
2016-06-29T15:24:37Z
38,103,987
<p>So if I understand it you would want to return 192.168.1.3 in your example? If you know what your numbers are going to look like (like all of the form 192.168.1.x) you could probably just iterate up from 1 and check if your number is free. If it is then return it, otherwise increment and repeat.</p>
0
2016-06-29T15:28:26Z
[ "python" ]
python - find unused IP / find a number not used in an range of nos?
38,103,896
<p>I have a list of IP addresses (or just numbers for what it matters)</p> <p>example list:</p> <pre><code>192.168.1.1 192.168.1.2 192.168.1.4 192.168.1.5 192.168.1.7 192.168.1.9 </code></pre> <p>what i would like is a function that will show me what IPs/numbers are free in a range.</p> <p>for example if my range w...
-1
2016-06-29T15:24:37Z
38,103,996
<p>Youou could try something like </p> <pre><code>usable = [] for i in range(1,255): # or whichever are the available ports if i not in octect_list: usable.append(i) min(usable) # min value of the unused ports </code></pre>
1
2016-06-29T15:29:00Z
[ "python" ]
How can I send a command and have Errbot respond to me privately?
38,103,967
<p>I am attempting to use Errbot to create the following workflow:</p> <p>!calculate Errbot then responds to me privately with the answer for number1+number2. I'm not sure how to tell Errbot to respond in a private message, can anyone help assist?</p> <p>Thanks!</p>
1
2016-06-29T15:27:28Z
38,105,959
<p>The simplest way to do that is to use the config:</p> <pre><code>// in config.py [...] DIVERT_TO_PRIVATE = ['calculate',] [...] </code></pre>
0
2016-06-29T17:03:45Z
[ "python", "errbot" ]
Test type of value in list during list comprehension BEFORE iterating on value?
38,103,980
<p>I have a list that looks like this:</p> <pre><code>test = [[1,11],[2,22],3.0] </code></pre> <p>and I want to create a list of the first value in each pair from it like this:</p> <pre><code>[f for [f,l] in test] </code></pre> <p>so that I get this result:</p> <pre><code>[1,2] </code></pre> <p>but, as expected, ...
4
2016-06-29T15:28:09Z
38,104,064
<p>You can't do the unpacking quite so early in this case since you need the full item in order to check it's type.</p> <pre><code>&gt;&gt;&gt; test = [[1,11],[2,22],3.0] &gt;&gt;&gt; [item[0] for item in test if isinstance(item, list)] [1, 2] </code></pre> <p>The way that you were doing it (<code>for a, b in iterabl...
3
2016-06-29T15:32:07Z
[ "python", "list", "python-3.x", "list-comprehension" ]
Test type of value in list during list comprehension BEFORE iterating on value?
38,103,980
<p>I have a list that looks like this:</p> <pre><code>test = [[1,11],[2,22],3.0] </code></pre> <p>and I want to create a list of the first value in each pair from it like this:</p> <pre><code>[f for [f,l] in test] </code></pre> <p>so that I get this result:</p> <pre><code>[1,2] </code></pre> <p>but, as expected, ...
4
2016-06-29T15:28:09Z
38,104,066
<p>Your unpacking does not work because your list contains non matching types. You can simply filter on <code>hasattr</code> given that only your lists (in this case) will have the attribute <code>__len__</code> and index the first item of the list:</p> <pre><code>&gt;&gt;&gt; test = [[1,11],[2,22],3.0] &gt;&gt;&gt; ...
0
2016-06-29T15:32:11Z
[ "python", "list", "python-3.x", "list-comprehension" ]
Test type of value in list during list comprehension BEFORE iterating on value?
38,103,980
<p>I have a list that looks like this:</p> <pre><code>test = [[1,11],[2,22],3.0] </code></pre> <p>and I want to create a list of the first value in each pair from it like this:</p> <pre><code>[f for [f,l] in test] </code></pre> <p>so that I get this result:</p> <pre><code>[1,2] </code></pre> <p>but, as expected, ...
4
2016-06-29T15:28:09Z
38,104,122
<pre><code>test = [[1,11],[2,22],3.0] print([f for [f,l] in filter(lambda x: type(x) is list, test)]) </code></pre> <blockquote> <p>[1, 2]</p> </blockquote>
2
2016-06-29T15:33:57Z
[ "python", "list", "python-3.x", "list-comprehension" ]
Test type of value in list during list comprehension BEFORE iterating on value?
38,103,980
<p>I have a list that looks like this:</p> <pre><code>test = [[1,11],[2,22],3.0] </code></pre> <p>and I want to create a list of the first value in each pair from it like this:</p> <pre><code>[f for [f,l] in test] </code></pre> <p>so that I get this result:</p> <pre><code>[1,2] </code></pre> <p>but, as expected, ...
4
2016-06-29T15:28:09Z
38,104,914
<p>You can try a simple approach like this:</p> <pre><code>test = [[1,11],[2,22],3.0] test_copy = test[:] for num in test: if type(num) != list: test_copy.remove(num) else: print([num[0] for num in test_copy]) </code></pre> <p>Output:</p> <pre><code>[1, 2] </code></pre> <p>You can also replace the...
0
2016-06-29T16:08:11Z
[ "python", "list", "python-3.x", "list-comprehension" ]
Sympy solveset() returns ConditionSet() when it should be returning a numerical answer
38,104,025
<p>I am using sympy to solve the following rather complex equation:</p> <p><img src="http://latex.codecogs.com/gif.latex?%7B%28%7B%5Cfrac%20%7B1%7D%7B2%7D%7D%5C%2C%5Cmathrm%20%7Berf%7D%20%7B%5CBig%20%5B%7D%7B%5Cfrac%20%7B%5Clog%20%28Xmax%29%20-%28%5Clog%28mode%29&plus;s%5E%7B2%7D%29%20%7D%7B%7B%5Csqrt%20%7B2%7D%7D%5Cs...
1
2016-06-29T15:30:07Z
38,107,546
<p>I think <code>solveset</code> is trying to find a symbolic solution. If you only want a numerical solution, I think <code>findroot</code> is the function to use.</p>
1
2016-06-29T18:32:59Z
[ "python", "math", "sympy" ]
Python Dictionary with a list of values for each key
38,104,095
<p>I have two different text files: One with words and their frequencies that looks like:</p> <p><code>word1&lt;space&gt;frequency</code></p> <p>Second one is a file that has a word in the first place followed by its associated features. It looks like:</p> <p><code>word1&lt;tab&gt;feature1&lt;tab&gt;feature2...........
0
2016-06-29T15:33:13Z
38,104,241
<pre><code>mydict = dict() with open('sample_word_freq_sorted.txt', 'r') as f1: data = set([ line.split()[0] for line in f1]) with open('sample_features.txt', 'r') as f2: for line in f2: word = line.split(' ')[0].strip() if word in data: mydict[word] = mydict.get...
0
2016-06-29T15:39:10Z
[ "python", "python-2.7", "dictionary" ]
Python Dictionary with a list of values for each key
38,104,095
<p>I have two different text files: One with words and their frequencies that looks like:</p> <p><code>word1&lt;space&gt;frequency</code></p> <p>Second one is a file that has a word in the first place followed by its associated features. It looks like:</p> <p><code>word1&lt;tab&gt;feature1&lt;tab&gt;feature2...........
0
2016-06-29T15:33:13Z
38,104,293
<p>I think your most robust way would be to use Pandas and merge.</p> <pre><code>df1 = pd.read_csv('sample_word_freq_sorted.txt', delim_whitespace=True) df2 = pd.read_csv('sample_features.txt', delimeter='\t') df2 = df2.drop_duplicates() df = df1.merge(df2, how='left', on='word') </code></pre> <p>Obviously that need...
0
2016-06-29T15:41:18Z
[ "python", "python-2.7", "dictionary" ]
Python Dictionary with a list of values for each key
38,104,095
<p>I have two different text files: One with words and their frequencies that looks like:</p> <p><code>word1&lt;space&gt;frequency</code></p> <p>Second one is a file that has a word in the first place followed by its associated features. It looks like:</p> <p><code>word1&lt;tab&gt;feature1&lt;tab&gt;feature2...........
0
2016-06-29T15:33:13Z
38,104,357
<p>A file is an iterator meaning you can only iterate over it once:</p> <pre><code>&gt;&gt;&gt; x = (i for i in range(3)) #example iterator &gt;&gt;&gt; for line in x: print(line) 0 1 2 &gt;&gt;&gt; for line in x: #second time produces no results. print(line) &gt;&gt;&gt; </code></pre> <p>So the loop <code...
0
2016-06-29T15:43:46Z
[ "python", "python-2.7", "dictionary" ]
retrying.RetryError: RetryError[Attempts: 1289627, Value: None]
38,104,195
<p>I am trying to use <a href="https://pypi.python.org/pypi/retrying" rel="nofollow">retrying</a> module as below but running into retrying.RetryError: whenever the <code>stop_max_delay</code> is encountered,appreciate if anyone provide inputs on how to fix it?</p> <pre><code>import time from retrying import retry ...
0
2016-06-29T15:37:09Z
38,107,353
<p>You should do like below</p> <pre><code>from retrying import retry, RetryError try: might_return_none() except RetryError as e: print "RetryError" print "End : %s" % time.ctime() </code></pre>
1
2016-06-29T18:22:13Z
[ "python" ]
Order of filenames from os.listdir
38,104,264
<p>Assume that folder A contains the following files:</p> <pre><code>0.jpg 1.jpg 2.jpg . . . n.jpg . . . </code></pre> <p>Now, a python script looks into folder A and using </p> <pre><code>for path, dirs, files in os.walk(path_to_A): for filename in files: fullpath = os.path.join(path, filename) </code><...
0
2016-06-29T15:40:05Z
38,104,376
<p>No, the j-th position will (or at least CAN) vary. From <a href="https://docs.python.org/3/library/os.html#os.listdir" rel="nofollow">the docs</a> (emphasis mine)</p> <blockquote> <p><code>os.listdir(path='.')</code><br> Return a list containing the names of the entries in the directory given by path. <strong>T...
4
2016-06-29T15:44:28Z
[ "python" ]
Session.get not opening the right page?
38,104,318
<p>I'm trying to open a link in a python script. </p> <p><a href="http://rads.stackoverflow.com/amzn/click/15718891" rel="nofollow">https://www.amazon.com/Best-Sellers-Automotive-Transmission-Fluid-Additives/zgbs/automotive/15718891/ref=zg_bs_nav_auto_4_15718881#2</a> </p> <p>which when I copy into my browser shows t...
1
2016-06-29T15:42:10Z
38,108,409
<p>You need to pass certain <em>params</em> as the content is retrieved with an ajax request:</p> <pre><code>params = {"_encoding": "UTF8", "pg": "2", "ajax": "1"} url = "http://rads.stackoverflow.com/amzn/click/15718891" r = requests.get(url, params=params) print(r.text) </code></pre> <p>Once y...
0
2016-06-29T19:23:55Z
[ "python", "web-scraping", "python-requests" ]
Can I access a class variable using object of that class
38,104,319
<p>I have two very basic object oriented question</p> <p>1) Can we modify a class variable with member function?</p> <p>For example</p> <pre><code>class test: '''test class''' idd=0 def __init__(self,mark,subject): self.markk=mark self.subjectt=subject def display(self): p...
1
2016-06-29T15:42:12Z
38,104,367
<p>As long as it is a public variable you should be able to.</p>
0
2016-06-29T15:43:59Z
[ "python", "class", "oop", "object" ]
Can I access a class variable using object of that class
38,104,319
<p>I have two very basic object oriented question</p> <p>1) Can we modify a class variable with member function?</p> <p>For example</p> <pre><code>class test: '''test class''' idd=0 def __init__(self,mark,subject): self.markk=mark self.subjectt=subject def display(self): p...
1
2016-06-29T15:42:12Z
38,104,433
<p>I think that you're not understanding that python looks up values by looking at a "chain" of objects<sup>1</sup>. When you do <code>value = self.foo</code>, python will first look for <code>foo</code> on the instance. Then it will look on the class. Then it will look on the super-classes (in their "Method Resolut...
1
2016-06-29T15:47:08Z
[ "python", "class", "oop", "object" ]
IndexError: index out of bounds
38,104,340
<p>I am new to Python and appreciate any constructive feedback. My task is to solve a PDE using ODEINT where my spatial grid is defined as follows:</p> <pre><code>L = [8.0, 4.0, 8.0] # Lenght of spatial zones dN = 1.0e2 # Number of grid points N = [int(l*dN) for l in L] # Gives number of grid points over...
0
2016-06-29T15:43:12Z
38,104,766
<p>From a quick look, it seems the problem is the for loop, instead of using <code>for i in [N[0]]</code>, are you sure it's not <code>for i in range(N[0])</code>?</p> <p><code>for i in [N[0]]</code> is rather redundant because the list only contains one element, ie. <code>N[0]</code>, so the list of size <strong>800<...
0
2016-06-29T16:02:32Z
[ "python", "arrays", "syntax-error", "pde", "odeint" ]
IndexError: index out of bounds
38,104,340
<p>I am new to Python and appreciate any constructive feedback. My task is to solve a PDE using ODEINT where my spatial grid is defined as follows:</p> <pre><code>L = [8.0, 4.0, 8.0] # Lenght of spatial zones dN = 1.0e2 # Number of grid points N = [int(l*dN) for l in L] # Gives number of grid points over...
0
2016-06-29T15:43:12Z
38,105,127
<pre><code>L = [8.0, 4.0, 8.0] dN = 1.0e2 N = [int(l*dN) for l in L] # create array [800, 400, 800] dydt = np.zeros(shape=N) # create 3 dimensional matrix # 1d has size 800 (from 0 to 799 including) # 2d has size 400 (from 0 to 399 including) ...
0
2016-06-29T16:18:53Z
[ "python", "arrays", "syntax-error", "pde", "odeint" ]
Merging two Pandas dataframes on multiple differently-named columns
38,104,350
<p>I have two Pandas dataframes that I would like to join on two columns. The columns are named differently in each df. </p> <pre><code>In [11]: df1 Out[11]: ID_1 ID_2 Hour 132 235 1 133 236 2 134 237 3 In [12]: df2 Out[12]: ID Hour Price 132 1 17.2 133 2 14.6 134 3 21.3 </code></pre...
3
2016-06-29T15:43:37Z
38,104,451
<p>Try:</p> <pre><code>df1.merge(df2, left_on=['ID_1', 'Hour'], right_on=['ID', 'Hour']) ID_1 ID_2 Hour ID Price 0 132 235 1 132 17.2 1 133 236 2 133 14.6 2 134 237 3 134 21.3 </code></pre>
2
2016-06-29T15:47:48Z
[ "python", "pandas", "join", "dataframe", "merge" ]
Sqlalchemy: Find row in which record is located
38,104,369
<p>What should I add to my code so it prints in which row of the table is the username located <code>if exist == True :</code> ? It can also return the id of the record as it would show me its position in the table. I did not include the database code because I think that it is not necessary. Sorry for my bad explanati...
0
2016-06-29T15:44:15Z
38,105,282
<p>sqlalchemy supports <code>select</code> statement queries. So I would do something like:</p> <pre><code>def _get_users(attempt): stmt = sqlalchemy.select([users]).where(users.c.username == attempt) return [dict(r) for r in sqlalchemy.execute(stmt)] def _get_attempt(): username_attempt = raw_input('Ent...
1
2016-06-29T16:27:09Z
[ "python", "sqlite", "sqlalchemy" ]
Writing results into a .txt file
38,104,405
<p>I created a code to take two .txt files, compare them and export the results to another .txt file. Below is my code (sorry about the mess). </p> <p>Any ideas? Or am I just an imbecile? </p> <p>Using python 3.5.2:</p> <pre><code># Barcodes Search (V3actual) # Import the text files, putting them into arrays/lists ...
1
2016-06-29T15:45:50Z
38,104,758
<p>Try <code>BarcodesSearch29_06_16.write(str(in_barcodes_but_not_in_EAN_staging))</code>. Also, you'll want to close the file after you're done writing to it with <code>BarcodesSearch29_06_16.close()</code>.</p>
1
2016-06-29T16:02:01Z
[ "python", "arrays", "text-files", "with-statement", "file-writing" ]
Writing results into a .txt file
38,104,405
<p>I created a code to take two .txt files, compare them and export the results to another .txt file. Below is my code (sorry about the mess). </p> <p>Any ideas? Or am I just an imbecile? </p> <p>Using python 3.5.2:</p> <pre><code># Barcodes Search (V3actual) # Import the text files, putting them into arrays/lists ...
1
2016-06-29T15:45:50Z
38,104,947
<p>From the comments to your question, it sounds like your issue is that you want to save your list of strings as a file. <code>File.write</code> expects a single string as input, while <code>File.writelines</code> expects a list of strings, which is what your data appears to be.</p> <pre class="lang-py prettyprint-o...
2
2016-06-29T16:10:10Z
[ "python", "arrays", "text-files", "with-statement", "file-writing" ]
Splicing MultiIndex (.loc not working)
38,104,480
<p>I am having trouble with slicing a MultiIndex. I have tried several tecniques by now but escept for one I don't get them to work. My DataFrame is composed of several rows like this:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pr...
2
2016-06-29T15:49:25Z
38,104,574
<h3>Solution 1: <code>pd.IndexSlice</code></h3> <pre><code>df.loc[pd.IndexSlice[:, 'cre', :], :] Total DL DM Mouse Genotype Intensity 455 cre s 15.114886 13.626841 16.602930 w 41.419970 33.916706 ...
1
2016-06-29T15:53:51Z
[ "python", "pandas", "slice", "multi-index" ]
Formset: saving models won't work
38,104,516
<p>Been trying to make this work all day. I have a main model which is entry. An entry can include several shifts. This is part of an app to store working hours. Here's the view for creating an entry:</p> <pre><code>class EntryCreateView(FormView): template_name = 'entry/create.html' form_class = AddWorkDay...
0
2016-06-29T15:50:42Z
38,123,403
<p>Ok, with a fresh head I looked at my code, and then it occurred to me. I wanted to make sure that the entry and each shift are built correctly first, and then only save them if they don't violate any rules. So as you can see above: I'm saving both with commit=False. That means however that entry has not been assigne...
1
2016-06-30T12:40:32Z
[ "python", "django", "forms", "formsets" ]
Compare two lists - if item from one list is present in another do something
38,104,546
<p><strong>UPDATE</strong> I have two lists of countries: one from <a href="https://www.countries-ofthe-world.com/world-currencies.html" rel="nofollow">https://www.countries-ofthe-world.com/world-currencies.html</a> and the second one from <a href="http://www.nationsonline.org/oneworld/country_code_list.htm" rel="nofol...
0
2016-06-29T15:52:35Z
38,104,935
<p>As the commenters have suggested, using sets you can get the latter part of your question (ie the differences between the list) using this code:</p> <pre><code>list1 = ['Russia','Vanuatu','Venezuela','Viet Nam','Virgin Islands, 'US', 'Wallis and Futuna Islands','Western Sahara','Yemen','Zambia','Zimbabwe'] list2 =...
1
2016-06-29T16:09:23Z
[ "python", "regex", "for-loop" ]
Using numpy data types in argparse
38,104,558
<p>I am setting up a Argparse parser to read some user input through the shell. The input will be used to extract data from a pandas DataFrame containing strings and numbers. I want to automatically set the <code>type=</code> argument in Argparse<code>.add_argument()</code> to match the datatype of the respective colum...
3
2016-06-29T15:53:09Z
38,105,365
<p>Use</p> <pre><code>inputtype = np.dtype(inputdata[c]).type </code></pre> <p>or</p> <pre><code>inputtype = inputdata[c].dtype.type </code></pre> <p>The <code>.type</code> attribute is callable, and can be used to create new instances of that dtype.</p>
5
2016-06-29T16:32:17Z
[ "python", "numpy", "pandas", "user-input", "argparse" ]
can you compile/run masm in linux?
38,104,587
<p>Sounds like a stupid question, but I don't know how else to ask it: I am trying to make a python library that will test <a href="https://en.wikipedia.org/wiki/CPUID" rel="nofollow">CPUID</a> codes and return a result, that happens to work on both linux and windows. The only way I could figure to do CPUID efficiently...
0
2016-06-29T15:54:37Z
38,127,663
<p>Since I don't have the rep to write a comment, I'll have to make an answer. </p> <p>The reason you can't have "one (dynamic) library to rule them all" is because, Windows and Linux consider dynamic lib files (.dll's, .so's) to be executable formats. Windows dynamic libs have the PE header, which Linux cannot execut...
5
2016-06-30T15:34:54Z
[ "python", "assembly", "nasm", "masm" ]
Python shell does not print carriage returns
38,104,602
<p>I'm using IDLE (Python 2.7) on Debian Wheezy. I sourced questions <a href="http://stackoverflow.com/questions/5419389/how-to-overwrite-the-previous-print-to-stdout-in-python">here</a> and <a href="http://stackoverflow.com/questions/26575014/python-carriage-return-not-working">here</a>. I tried applying what they sai...
1
2016-06-29T15:55:25Z
38,104,964
<p>Terminals vary in their capabilites of handling such special characters. A similar question <a href="http://stackoverflow.com/a/19188881/2465194">was answered</a> by <a href="http://stackoverflow.com/users/344286/wayne-werner">Wayne Werner</a>, who said that IDLE just does not handle those special characters (i.e. p...
1
2016-06-29T16:11:04Z
[ "python", "console", "python-idle", "carriage-return" ]
python setup.py install, out of memory in virtualenv
38,104,637
<p>I am coding a Python package that includes some Cython code. I use virtualenv. It compiles fine when I write</p> <pre><code>$ source activate $ python setup.py build_ext --inplace </code></pre> <p>but then, when I try to install the package, it starts to consume memory until my computer hangs (or I kill the proces...
1
2016-06-29T15:57:02Z
38,105,382
<p>I have finally found the problem. The folder structure of the package is the following</p> <pre><code>ColoredHRG/setup.py ... ColoredHRG/ColoredHRG/ColoredHRG.pyx ColoredHRG/ColoredHRG/MC.pyx ... ColoredHRG/ColoredHRG/examples/examples.py ... </code></pre> <p>Aditionally, inside the folder <code>examples</code>, t...
1
2016-06-29T16:33:02Z
[ "python", "install", "cython", "distutils" ]
Django admin - Add a custom link that runs a a function in a pop up next to a particular field?
38,104,747
<p>Hopefully my screen shot will demonstrate what im trying to achieve. Basically i have a function which checks all the current "DMVPN DSL IPs" in the database and then returns the lowest free IP, this part is done. However i want to be able to run that function in a pop up next to that field in the admin page. so whe...
2
2016-06-29T16:01:23Z
38,659,402
<p>Yes it's possible and you have some way to achieve your goal:</p> <ul> <li>write a custom <a href="https://docs.djangoproject.com/en/dev/ref/forms/widgets/" rel="nofollow">widget</a>, then use it on your admin form. The widget will include all the logic and the graphics of your popup</li> <li>write inside the <code...
3
2016-07-29T12:52:35Z
[ "python", "django" ]
Django admin - Add a custom link that runs a a function in a pop up next to a particular field?
38,104,747
<p>Hopefully my screen shot will demonstrate what im trying to achieve. Basically i have a function which checks all the current "DMVPN DSL IPs" in the database and then returns the lowest free IP, this part is done. However i want to be able to run that function in a pop up next to that field in the admin page. so whe...
2
2016-06-29T16:01:23Z
38,776,826
<p>You can achieve it by writing javascript code in a file custom.js:</p> <pre><code>(function ($) { function findFreeIp() { $.ajax({ url: "/custom/findFreeIp", success: function(response) { $("input#id_field_name").val(response); } ...
0
2016-08-04T20:24:26Z
[ "python", "django" ]
Why are these two same functions creating two output process?
38,104,823
<p>I tried to check the validity of my functions and I noticed that two of my functions which have the same code are giving two different outputs. I need to change the if-conditional in one of them but I also need to make sure that both of them works properly. Can </p> <pre><code>data_out = open("mentees_all_attribute...
0
2016-06-29T16:04:47Z
38,105,068
<p>Your two functions seem to be the same (unless I overlooked something). The problem seems to be with the <code>reader</code>. A reader, like any file handle, is an <code>iterator</code>, and once you've iterated all the lines in the reader, it is exhausted. Thus, when you use <em>the same</em> <code>reader</code> <e...
1
2016-06-29T16:15:56Z
[ "python", "python-2.7" ]
Why are these two same functions creating two output process?
38,104,823
<p>I tried to check the validity of my functions and I noticed that two of my functions which have the same code are giving two different outputs. I need to change the if-conditional in one of them but I also need to make sure that both of them works properly. Can </p> <pre><code>data_out = open("mentees_all_attribute...
0
2016-06-29T16:04:47Z
38,105,089
<pre><code>data_out.seek(0) between the funcs </code></pre>
0
2016-06-29T16:17:06Z
[ "python", "python-2.7" ]
Pass variable to multicorn foreign data wrapper
38,104,860
<p>I am trying to pass my fdw an option who's value is a variable. My instinct is to do it like this, but it says that there is a syntax error at x abc. What do I need to do to get this to work?</p> <pre><code>DO $$ DECLARE abc varchar :='hi'; Begin drop server partner cascade; create server partner foreign da...
0
2016-06-29T16:05:58Z
38,105,571
<p>Tried getting something similar to work once and finally went with <a href="https://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN" rel="nofollow">executing</a> a <a href="https://www.postgresql.org/docs/current/static/functions-string.html#FUNCTIONS-STRING-FORMAT" re...
1
2016-06-29T16:43:58Z
[ "python", "postgresql", "python-2.7", "multicorn" ]
How to handle huge (~3 gb) xml, parse it into json in python. Using xml.etree to iterate over it but memory error
38,105,023
<p>I need to convert terminological resource IATE to json in a specific format for further processing. I am using xml.etree to iterate through the xml, conditionally check the tags and add relevant texts into a dictionary. I need a list of these dictionaries as an output. </p> <p>As the size of this final list of dict...
0
2016-06-29T16:13:41Z
38,124,044
<p>If anyone still struggling on this problem, I added <code>element.clear()</code> after every instance i capture the element. </p> <p>Although it is mentioned at many places but I am still to find some resource where it explains how xml.etree handle memory internally. Any leads will be appreciated. </p> <p>Thank y...
0
2016-06-30T13:06:00Z
[ "python", "json", "xml", "memory-management", "nlp" ]
Fast 2D Convolution in C
38,105,132
<p>I'm trying to implement a convolutional neural network in Python. Originally, I was using scipy.signal's convolve2d function to do the convolution, but it has a lot of overhead, and it would be faster to just implement my own algorithm in C and call it from python, since I know what my input looks like.</p> <p>I've...
5
2016-06-29T16:18:59Z
38,105,227
<p>If you're running on x86 only then consider using SSE or AVX SIMD optimisation. For <code>double</code> data the throughput improvement will be modest, but if you can switch to <code>float</code> then you may be able to get to around 4x improvement with SSE or 8x with AVX. There are a number of questions and answers...
2
2016-06-29T16:24:01Z
[ "python", "c", "algorithm", "performance", "optimization" ]
What's the order of __hash__ and __eq__ evaluation for a Python dict?
38,105,134
<p>I'm trying to understand what Python dictionaries must be doing internally to locate a key. It seems to me that <strong>hash</strong> would be evaluated first, and if there's a collision, Python would iterate through the keys till it finds one for which <strong>eq</strong> returns True. Which makes me wonder why the...
4
2016-06-29T16:19:04Z
38,105,240
<p>Anything you use as a dict key has to satisfy the invariant that <code>bool(x == x) is True</code>. (I would have just said <code>x == x</code>, but there are reasonable objects for which that isn't even a boolean.)</p> <p>The dict assumes that this will hold, so the routine it uses to check key equality actually c...
5
2016-06-29T16:24:51Z
[ "python", "dictionary", "hashable" ]
SyntaxError within nested if statement
38,105,187
<p>I have written the following:</p> <pre><code>if ((playerVX &gt; 0.0) and (playerVX &lt; maxSpeed)) or ((playerVX &lt; 0.0) and (playerVX &gt; -maxSpeed)): if not haveJumped and (leftDown or rightDown) playerVX = playerVX * 1.1 </code></pre> <p>However, I am getting a syntax error. Can someone please e...
-6
2016-06-29T16:21:32Z
38,105,251
<p>Looks like one extra parenthesis in the <code>(playerVX &gt; 0.0)</code> comparison.</p> <pre><code>if ((playerVX &gt; 0.0) and (playerVX &lt; maxSpeed)) or ((playerVX &lt; 0.0) and (playerVX &gt; -maxSpeed)): if not haveJumped and (leftDown or rightDown): playerVX = playerVX * 1.1 </code></pre>
1
2016-06-29T16:25:27Z
[ "python" ]
SyntaxError within nested if statement
38,105,187
<p>I have written the following:</p> <pre><code>if ((playerVX &gt; 0.0) and (playerVX &lt; maxSpeed)) or ((playerVX &lt; 0.0) and (playerVX &gt; -maxSpeed)): if not haveJumped and (leftDown or rightDown) playerVX = playerVX * 1.1 </code></pre> <p>However, I am getting a syntax error. Can someone please e...
-6
2016-06-29T16:21:32Z
38,555,882
<p>if (0.0 &lt; playerVX &lt; maxSpeed) or (-maxSpeed &lt; playerVX &lt; 0.0): if not haveJumped and (leftDown or rightDown): playerVX = playerVX * 1.1</p> <p>This did the trick for me.</p>
0
2016-07-24T19:24:38Z
[ "python" ]
Primer needed in python pathnames
38,105,213
<p>I am a very novice coder, and Python is my first (and, practically speaking, only) language. I am charged as part of a research job with manipulating a collection of data analysis scripts, first by getting them to run on my computer. I was able to do this, essentially by removing all lines of coding identifying path...
2
2016-06-29T16:23:33Z
38,105,751
<p>I agree with cdarke's comment that you are probably running into an issue with backslashes. Replacing the line with:</p> <p><code>sys.path.append(r'C:\Users\Ben\Documents\TRACMIP_Project\mymodules')</code></p> <p>will likely solve your problem. Details below.</p> <p>In general, Python treats paths as if they're r...
0
2016-06-29T16:52:40Z
[ "python", "csv", "path", "relative-path", "absolute-path" ]
Primer needed in python pathnames
38,105,213
<p>I am a very novice coder, and Python is my first (and, practically speaking, only) language. I am charged as part of a research job with manipulating a collection of data analysis scripts, first by getting them to run on my computer. I was able to do this, essentially by removing all lines of coding identifying path...
2
2016-06-29T16:23:33Z
38,105,784
<h2><a href="https://docs.python.org/3/library/sys.html#sys.path" rel="nofollow">sys.path</a></h2> <p>This is simple list of directories where python will look for modules and packages (<code>.py</code> and dirs with <code>__init__.py</code> file, look at <a href="https://docs.python.org/3/tutorial/modules.html" rel="...
1
2016-06-29T16:54:28Z
[ "python", "csv", "path", "relative-path", "absolute-path" ]
How to pass connection parameter "ApplicationIntent=ReadOnly" when using pymssql
38,105,350
<p>I only have readonly access to a SQL Server db. How do I pass connection parameter "ApplicationIntent=ReadOnly" when using pymssql to connect to the database? If pymssql doesn't support it, is there any other python library that I can use?</p>
0
2016-06-29T16:31:36Z
38,106,879
<p>Because pymssql is dependent on FreeTDS You really need to address the connection parameters to your MS-SQL server used by FreeTDS</p> <p>Because ApplicationIntent is listed in the freetds <a href="http://www.freetds.org/userguide/odbcconnattr.htm" rel="nofollow">user guide</a> as an option you should be able to u...
0
2016-06-29T17:55:39Z
[ "python", "sql-server", "pymssql" ]
How to pass connection parameter "ApplicationIntent=ReadOnly" when using pymssql
38,105,350
<p>I only have readonly access to a SQL Server db. How do I pass connection parameter "ApplicationIntent=ReadOnly" when using pymssql to connect to the database? If pymssql doesn't support it, is there any other python library that I can use?</p>
0
2016-06-29T16:31:36Z
38,510,752
<p>pyodbc has a readonly parameter. For example:</p> <pre><code>import pyodbc conn = pyodbc.connect(driver='{SQL Server}', host=Server, database=Database, trusted_connection='yes', user='', password='', readonly = True) </code></pre>
0
2016-07-21T17:31:29Z
[ "python", "sql-server", "pymssql" ]
Convert dta files in csv
38,105,378
<p>I want to convert several dta files into csv. So far my code is (to be honest I used an answer I found on stackoverflow...)</p> <pre><code>library(foreign) setwd("C:\Users\Victor\Folder") for (f in Sys.glob('*.dta')) write.csv(read.dta(f), file = gsub('dta$', 'csv', f)) </code></pre> <p>It works, but if m...
1
2016-06-29T16:32:51Z
38,105,836
<p>In R to do this you just set <code>recursive = T</code> in <code>list.files</code>. </p> <p>Actually, specifying recursion when dealing with directories is kind of general -- it works with command line operations in OS's including Linux and Windows with commands like <code>rm -rf</code> and applies to multiple func...
0
2016-06-29T16:57:32Z
[ "python", "csv" ]
Convert dta files in csv
38,105,378
<p>I want to convert several dta files into csv. So far my code is (to be honest I used an answer I found on stackoverflow...)</p> <pre><code>library(foreign) setwd("C:\Users\Victor\Folder") for (f in Sys.glob('*.dta')) write.csv(read.dta(f), file = gsub('dta$', 'csv', f)) </code></pre> <p>It works, but if m...
1
2016-06-29T16:32:51Z
38,113,416
<p>Consider using base R's <a href="http://www.inside-r.org/r-doc/base/list.files" rel="nofollow">list.files()</a> as the <em>recursive</em> argument specifies to search in subdirectories. You will also want <em>full.names</em> set to return absolute paths for file referencing.</p> <p>So, set your pattern to look for ...
0
2016-06-30T03:18:07Z
[ "python", "csv" ]
Solving a large number of small linear systems
38,105,390
<p>I need to solve a large number of 3x3 symmetric, postive-definite systems with Python. So far, I did</p> <pre><code>res = numpy.zeros(n) for k, obj in enumerate(data_array): # construct A, rhs, idx from obj res[idx] += numpy.linalg.solve(A, rhs) </code></pre> <p>This produces the correct result, however ...
1
2016-06-29T16:33:28Z
38,105,566
<p>In NumPy 1.8 and later, <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html" rel="nofollow"><code>numpy.linalg.solve</code> actually broadcasts</a>. For <code>numpy.linalg.solve(a, b)</code>, if <code>b.ndim == a.ndim - 1</code>, it will perform a broadcasted matrix-vector solve; oth...
4
2016-06-29T16:43:49Z
[ "python", "numpy", "scipy" ]
how to optimize script to have 1 second between spoken words using speech module
38,105,412
<p>the problem is that when i run my script it takes longer than the expected time 1 second before it says the next command. i think this has something to do with the speech command. what can i do to optimize this?</p> <p>edit: link to the sppech module <a href="https://pypi.python.org/pypi/speech/0.5.2" rel="nofollow...
-1
2016-06-29T16:34:26Z
38,105,451
<p>Refer the post here <a href="http://stackoverflow.com/questions/1133857/how-accurate-is-pythons-time-sleep">How accurate is python&#39;s time.sleep()?</a></p> <p>It says:</p> <blockquote> <p>"The accuracy of the time.sleep function depends on the accuracy of your underlying OS's sleep accuracy. For non-realtim...
0
2016-06-29T16:36:27Z
[ "python", "python-2.7", "sleep", "text-to-speech", "speech" ]
how to optimize script to have 1 second between spoken words using speech module
38,105,412
<p>the problem is that when i run my script it takes longer than the expected time 1 second before it says the next command. i think this has something to do with the speech command. what can i do to optimize this?</p> <p>edit: link to the sppech module <a href="https://pypi.python.org/pypi/speech/0.5.2" rel="nofollow...
-1
2016-06-29T16:34:26Z
38,108,139
<p>As you say in the comments, sleep(1) is fairly accurately 1s. </p> <p>What you want to do to make each part take 1s, is time the "say" call, and then wait the remaining time to fill out the second. Something like this:</p> <pre><code>start = time.time() speech.say("whatever") end = time.time() sleep(1 - (end - sta...
0
2016-06-29T19:06:19Z
[ "python", "python-2.7", "sleep", "text-to-speech", "speech" ]
WinRM - the specified credentials were rejected by the server
38,105,486
<p>I am unable to get WinRM session in a python script.</p> <h2>Environment</h2> <pre><code>ad-dns.test.com - Windows 2012 AD and DNS Server box88.test.com - CentOS 7.2 : Kerberos, Python (Not joined to domain) box62.test.com - Windows 2012 R2 Standard (Joined to domain) box63.test.com - Windows 10 (Jo...
1
2016-06-29T16:38:40Z
38,472,499
<p>Solved it finally, it was a permission issue and not invalid credentials as pointed out in logs. There are two solutions to this issue</p> <ol> <li>Add the domain user to the <code>Domain Admins</code> Group</li> <li>Execute <code>winrm configSDDL default</code> on the Windows server and check <code>Read</code> and...
1
2016-07-20T04:45:48Z
[ "python", "kerberos", "winrm" ]
Python: When should I ever use file.read() or file.readlines()?
38,105,507
<p>I noticed that if I iterate over a file that I opened, it is much faster to iterate over it without "read"-ing it. </p> <p>i.e. </p> <pre><code>l = open('file','r') for line in l: pass (or code) </code></pre> <p>is much faster than </p> <pre><code>l = open('file','r') for line in l.read() / l.readlines(): ...
5
2016-06-29T16:39:42Z
38,105,645
<p>Hope this helps!</p> <p><a href="https://docs.python.org/2/tutorial/inputoutput.html#methods-of-file-objects" rel="nofollow">https://docs.python.org/2/tutorial/inputoutput.html#methods-of-file-objects</a></p> <blockquote> <p>When size is omitted or negative, the entire contents of the file will be read and retur...
0
2016-06-29T16:47:14Z
[ "python", "io", "timeit" ]
Python: When should I ever use file.read() or file.readlines()?
38,105,507
<p>I noticed that if I iterate over a file that I opened, it is much faster to iterate over it without "read"-ing it. </p> <p>i.e. </p> <pre><code>l = open('file','r') for line in l: pass (or code) </code></pre> <p>is much faster than </p> <pre><code>l = open('file','r') for line in l.read() / l.readlines(): ...
5
2016-06-29T16:39:42Z
38,105,733
<p>The short answer to your question is that each of these three methods of reading bits of a file have different use cases. As noted above, f.read() reads the file as an individual string, and so allows relatively easy file-wide manipulations, such as a file-wide regex search or substitution.</p> <p>f.readline() rea...
4
2016-06-29T16:51:51Z
[ "python", "io", "timeit" ]
Manipulating Python: datetime.now() output to display incrementing time values per individual line
38,105,559
<p>Initially I was given an exercise in which I had to write the 'RandomFile.txt' as seven separate lines with each line listing the summation of integers given and the current time. After completing this task I was assigned to show an increment of one second per line (i.e first line = 5s, second line = 6s, third line ...
0
2016-06-29T16:43:27Z
38,106,082
<p>You need to increment your time by one minute in some way inside this branch: <code>if type(total) == int:</code>. Currently, what you do is just assign <code>total_time</code> the original value of <code>clock</code> (which corresponds to your start time) instead of keeping track of the changing time value in some ...
0
2016-06-29T17:10:00Z
[ "python", "python-2.7", "datetime", "output" ]
Matlab/Python Data Conversion
38,105,588
<p>I am looking for a way to extract my data from huge text file and insert into excel-like format, e.g.;</p> <pre><code>blablablablabla Loc1:38 Loc1:77 blablablablablabla Loc2:-335 . . . </code></pre> <p>I want those numbers and variables <code>Loc1</code>, <code>Loc2</code>, <code>38</code>, <code>335</code>, .....
0
2016-06-29T16:44:52Z
38,105,672
<p>not quite sure if this is what you want but you could use notepad search and replace funktion and just do find : </p> <p>replace with =</p>
0
2016-06-29T16:48:59Z
[ "python", "matlab" ]
Matlab/Python Data Conversion
38,105,588
<p>I am looking for a way to extract my data from huge text file and insert into excel-like format, e.g.;</p> <pre><code>blablablablabla Loc1:38 Loc1:77 blablablablablabla Loc2:-335 . . . </code></pre> <p>I want those numbers and variables <code>Loc1</code>, <code>Loc2</code>, <code>38</code>, <code>335</code>, .....
0
2016-06-29T16:44:52Z
38,105,694
<p>The fastest way is to not use python nor matlab. Use grep and awk</p> <pre><code>grep Loc1 filename | awk -F":" '{print $2}' &gt; Loc1.txt grep Loc2 filename | awk -F":" '{print $2}' &gt; Loc2.txt </code></pre> <p>and then simply read Loc1.txt and Loc2.txt into a table using your favorite tool (use matlab or pytho...
2
2016-06-29T16:49:52Z
[ "python", "matlab" ]
Odd results from MATLAB function called in python
38,105,605
<p>So I have a rather comlicated matlab function (it calls a simulation that in turn calls an external optimisation suite (cplex or gurobi)). And for certain settings and inputs the MATLAB function and the python function called from Matlab give the same result but for others they differ (correct answer is ~4500) pyth...
0
2016-06-29T16:45:23Z
38,106,001
<p>So turns out, that on occasion the code will run if some variables aren't specified as double, and in other cases it integer division or what not, results false results. I have no idea how this correlates to the input as it really shouldn't but I just went and specified all variables in the relevant section of code ...
0
2016-06-29T17:05:43Z
[ "python", "matlab", "python-2.7", "cplex" ]
Breaking Up A List Using Values As Breakpoints?
38,105,620
<p>I have a list that contains a few values, each followed by a number of Nones:</p> <pre><code>['Apple', None, None, None, None, None, None, 'Orange', None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 'Pear', None, None, None, None, None, None, None, 'Banana', None, None]...
1
2016-06-29T16:46:04Z
38,105,826
<p>You said you wanted to replace the None's with the latest non-None value. I'll skip the "how do I split" question, and answer the "replacing" question:</p> <pre><code>def fill_nones(seq): last = None for val in seq: if val is not None: last = val yield last </code></pre> <p>Now...
2
2016-06-29T16:56:59Z
[ "python", "list" ]
Breaking Up A List Using Values As Breakpoints?
38,105,620
<p>I have a list that contains a few values, each followed by a number of Nones:</p> <pre><code>['Apple', None, None, None, None, None, None, 'Orange', None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 'Pear', None, None, None, None, None, None, None, 'Banana', None, None]...
1
2016-06-29T16:46:04Z
38,105,838
<p>Try the following:</p> <pre><code>x = ['Apple', None, None, None, None, None, None, 'Orange', None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 'Pear', None, None, None, None, None, None, None, 'Banana', None, None] output = [] sub = [] for i in range(len(x)): cur =...
1
2016-06-29T16:57:37Z
[ "python", "list" ]
Breaking Up A List Using Values As Breakpoints?
38,105,620
<p>I have a list that contains a few values, each followed by a number of Nones:</p> <pre><code>['Apple', None, None, None, None, None, None, 'Orange', None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 'Pear', None, None, None, None, None, None, None, 'Banana', None, None]...
1
2016-06-29T16:46:04Z
38,105,844
<p>Might be a better way with list comprehensions but something like this will split the original list into a list of smaller lists as long as the first value isn't None.</p> <pre><code>def splitlist(listin): newlist = [] for val in listin: if val != None: newlist.append([val]) else...
2
2016-06-29T16:57:59Z
[ "python", "list" ]
Breaking Up A List Using Values As Breakpoints?
38,105,620
<p>I have a list that contains a few values, each followed by a number of Nones:</p> <pre><code>['Apple', None, None, None, None, None, None, 'Orange', None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 'Pear', None, None, None, None, None, None, None, 'Banana', None, None]...
1
2016-06-29T16:46:04Z
38,107,541
<p>I solve this problem using two new auxiliary lists.</p> <p>The code looks like this:</p> <pre><code>def fill_list(seq): list_aux_1 = list() list_out = list() for item in seq: if isinstance(item, str): list_out.append(list_aux_1) list_aux_1 = list() list_aux_1....
0
2016-06-29T18:32:37Z
[ "python", "list" ]
find the biggest string in each row in a Pandas DataFrame
38,105,743
<p>I am new to Pandas and I am trying to get the biggest string for every row in a DataFrame.</p> <pre><code>import pandas as pd import sqlite3 authors = pd.read_sql('select * from authors') authors['name'] ... 12 KRISHNAN RAJALAKSHMI 13 J O 14 TSIPE 15 ...
0
2016-06-29T16:52:18Z
38,105,961
<p>You are not replacing its values...</p> <p>Try this function:</p> <pre><code>def getName(df): df[0] = df[0].apply(lambda x: max(x.split(), key=len)) </code></pre> <p>And then you just have to call:</p> <pre><code>getName(authors) </code></pre> <p>Note that I reassign each value of <code>df[0]</code> in this...
1
2016-06-29T17:03:54Z
[ "python", "string", "pandas", "split", "max" ]
find the biggest string in each row in a Pandas DataFrame
38,105,743
<p>I am new to Pandas and I am trying to get the biggest string for every row in a DataFrame.</p> <pre><code>import pandas as pd import sqlite3 authors = pd.read_sql('select * from authors') authors['name'] ... 12 KRISHNAN RAJALAKSHMI 13 J O 14 TSIPE 15 ...
0
2016-06-29T16:52:18Z
38,106,176
<p>When you tell pandas to apply <code>max</code> to the split series, it doesn't know what it should be maximizing. You might instead try something like</p> <pre class="lang-py prettyprint-override"><code>authors['name'].apply(lambda x: max(x.split(), key=len)) </code></pre> <p>For each row, this will create an arr...
3
2016-06-29T17:15:02Z
[ "python", "string", "pandas", "split", "max" ]
How can I create a form instance outside of a view?
38,105,760
<p>I'm currently writing a Flask app. One of my views has very complex business logic so I moved that to a class declared outside the view. In the constructor of that class I create several instances of <code>flask_wtf.form.Form</code> objects.</p> <p>My problem is that at runtime I get the following error:</p> <pre>...
0
2016-06-29T16:53:01Z
38,105,911
<p>You can't. <code>flask_wtf.Form</code> requires the application context to set up CSRF.</p> <p>It doesn't really make sense to instantiate a form outside of where it will be used, because you need to instantiate it with the data that is submitted to do anything useful.</p> <p>Move creating the form instances to a...
2
2016-06-29T17:00:59Z
[ "python", "flask", "wtforms", "flask-wtforms" ]
Delete rows from pandas DataFrame with non-unique index
38,105,804
<p>I am looking for a way to delete rows in a pandas DataFrame when the index is <em>not</em> guaranteed to be unique. </p> <p>So, I want to drop items 0 and 4 from my DataFrame df. This would be the typical code you would use to do that:</p> <pre><code>df.drop([0, 4].index) </code></pre> <p>If each index is uniqu...
3
2016-06-29T16:55:44Z
38,106,499
<p>This is not very elegant too, but let me post it as an alternative:</p> <pre><code>df = df.reset_index().drop([0, 4]).set_index("site") </code></pre> <p>It temporarily changes the index to a regular index, drops the rows and sets the original index back. The idea is from <a href="http://stackoverflow.com/a/1198284...
3
2016-06-29T17:33:29Z
[ "python", "pandas", "dataframe" ]
Delete rows from pandas DataFrame with non-unique index
38,105,804
<p>I am looking for a way to delete rows in a pandas DataFrame when the index is <em>not</em> guaranteed to be unique. </p> <p>So, I want to drop items 0 and 4 from my DataFrame df. This would be the typical code you would use to do that:</p> <pre><code>df.drop([0, 4].index) </code></pre> <p>If each index is uniqu...
3
2016-06-29T16:55:44Z
38,111,213
<p>alternative solution (using numpy):</p> <pre><code>In [252]: mask = np.ones(len(df)).astype(bool) In [253]: mask[[0,4]] = False In [254]: mask Out[254]: array([False, True, True, True, False], dtype=bool) In [255]: df[mask] Out[255]: age mc03 0.348 mc03 0.348 mc03 0.420 </code></pre>
1
2016-06-29T22:42:20Z
[ "python", "pandas", "dataframe" ]
Clarification of What is Happening in Python For Loop
38,105,837
<p>I am working through the Coursera Python course and am a bit turned around with some shorthand. </p> <pre><code> x = 0 y = 1 for i in range(40): x, y = y, x + y print y </code></pre> <p>I understand it is adding X and Y and assigning the new value to Y but don't quite follow the x, y = y, x + y ...
1
2016-06-29T16:57:33Z
38,105,933
<pre><code>x, y = y, x + y </code></pre> <p>x is assigned the value of y<br> and y is assigned the value of x + y</p>
1
2016-06-29T17:02:02Z
[ "python", "for-loop" ]
Clarification of What is Happening in Python For Loop
38,105,837
<p>I am working through the Coursera Python course and am a bit turned around with some shorthand. </p> <pre><code> x = 0 y = 1 for i in range(40): x, y = y, x + y print y </code></pre> <p>I understand it is adding X and Y and assigning the new value to Y but don't quite follow the x, y = y, x + y ...
1
2016-06-29T16:57:33Z
38,105,964
<p>The <code>comma</code> indicates that the right hand side is a tuple containing <code>y</code> and <code>x+y</code>. The <code>comma</code> on the left indicates that the unpacking should be done.</p> <p>So <code>x</code> gets the value of <code>y</code> and <code>y</code> gets the value of <code>x+y</code></p> <p...
1
2016-06-29T17:04:09Z
[ "python", "for-loop" ]
Clarification of What is Happening in Python For Loop
38,105,837
<p>I am working through the Coursera Python course and am a bit turned around with some shorthand. </p> <pre><code> x = 0 y = 1 for i in range(40): x, y = y, x + y print y </code></pre> <p>I understand it is adding X and Y and assigning the new value to Y but don't quite follow the x, y = y, x + y ...
1
2016-06-29T16:57:33Z
38,105,977
<p>This assigns y to x and x+y to y, but notice that it does it at the "same time". If you tried something like</p> <pre><code>x = y y = x + y print y </code></pre> <p>you would get an entirely different result.</p>
0
2016-06-29T17:04:52Z
[ "python", "for-loop" ]
Clarification of What is Happening in Python For Loop
38,105,837
<p>I am working through the Coursera Python course and am a bit turned around with some shorthand. </p> <pre><code> x = 0 y = 1 for i in range(40): x, y = y, x + y print y </code></pre> <p>I understand it is adding X and Y and assigning the new value to Y but don't quite follow the x, y = y, x + y ...
1
2016-06-29T16:57:33Z
38,106,501
<p>This feature called <a href="https://docs.python.org/2/tutorial/datastructures.html#tuples-and-sequences" rel="nofollow"><code>sequence packing\unpacking</code></a>. It consist of two parts: packing expression of right side near <code>=</code> sign and then unpacking it into variables from the right.</p> <blockquot...
0
2016-06-29T17:33:35Z
[ "python", "for-loop" ]
Persist authenticated session between crawls for development in Scrapy
38,105,849
<p>I'm using a Scrapy spider that authenticates with a login form upon launching. It then scrapes with this authenticated session.</p> <p>During development I usually run the spider many times to test it out. Authenticating at the beginning of each run spams the login form of the website. The website will often force ...
0
2016-06-29T16:58:12Z
38,111,852
<p>Turns out that for an ad-hoc development solution, this is easier to do than I thought. Get the cookie string with <code>cookieString = request.headers['Cookie']</code>, save, then on subsequent outgoing requests load it up and do:</p> <pre><code>request.headers.appendlist('Cookie', cookieString) </code></pre>
0
2016-06-29T23:48:01Z
[ "python", "cookies", "scrapy" ]
How to multiply each row in pandas dataframe by a different value
38,105,864
<p>I am trying to multiply each row of a pandas dataframe by a different value and wondering what the best way to do this is.</p> <p>For example if I have the following dataframe:</p> <pre><code>import numpy as np import pandas as pd df = pd.DataFrame(np.random.randn(2, 3)) df 0 1 2 0 -1.283...
1
2016-06-29T16:58:56Z
38,106,048
<p>The method is <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.mul.html" rel="nofollow"><code>mul</code></a>:</p> <pre><code>df.mul([1, 100], axis=0) Out[17]: 0 1 2 0 -1.198766 -1.340028 1.990843 1 113.890468 -68.177755 -9.060228 </code></pre>
3
2016-06-29T17:08:09Z
[ "python", "pandas" ]
How is TA-Lib identifying Dojis
38,105,872
<p>I'm trying to fiddle with the TA-Lib functions, trying to understand how they identify patterns.</p> <p>The following code produces strange results </p> <pre><code>import talib import numpy sample_data = [ ['1/22/14', 10, 18, 5, 20], ['1/23/14', 12, 21, 7, 22], ['1/24/14', 14, 24, 9 , 24], ...
1
2016-06-29T16:59:15Z
38,127,531
<p>I've changed the underlying data for it to be even more obivous</p> <p><code>sample_data = [ ['1/22/14', 10, 22, 5, 20], ['1/23/14', 12, 23, 7, 22], ['1/24/14', 14, 24, 9 , 24], ['1/25/14', 16, 27, 11, 26], ['1/26/14', 18, 30, 13, 28], ['1/27/14', 20, 33, 15, 30], ['1/28/14', 22, 36, 17, 32], ['1/29/14', 24, 39, 19...
1
2016-06-30T15:29:33Z
[ "python", "ta-lib" ]
How is TA-Lib identifying Dojis
38,105,872
<p>I'm trying to fiddle with the TA-Lib functions, trying to understand how they identify patterns.</p> <p>The following code produces strange results </p> <pre><code>import talib import numpy sample_data = [ ['1/22/14', 10, 18, 5, 20], ['1/23/14', 12, 21, 7, 22], ['1/24/14', 14, 24, 9 , 24], ...
1
2016-06-29T16:59:15Z
38,960,904
<p>If you are running python and TA-Lib on Windows, this problem occurs because of issues with the installed TA-Lib binaries.</p> <p>I checked this on a Linux machine with Python 2.7 after building from source as per <a href="https://github.com/mrjbq7/ta-lib" rel="nofollow">https://github.com/mrjbq7/ta-lib</a>. The ou...
0
2016-08-15T18:35:36Z
[ "python", "ta-lib" ]
pandas groupby aggregation results from another dataframe
38,105,880
<p>I'm having trouble using <code>groupby</code> and <code>aggregation</code> when working w/ multiple dataframes. I'm trying to calculate <code>num_maint_over_$90</code> from two different dataframes.</p> <pre><code>cars_dict = {"ABC123": ["Ford", "Compact_Car"], "XYZ148": ["Chevy", "Truck"], "ASX133": ["Ford", "Truc...
1
2016-06-29T16:59:39Z
38,106,102
<pre><code>merged = pd.merge(maintenance_records, cars, how='left', left_on='License_Plate', right_index=True) merged.query('Cost &gt; 90')['Type'].value_counts() </code></pre>
0
2016-06-29T17:11:06Z
[ "python", "pandas", "dataframe" ]
pandas groupby aggregation results from another dataframe
38,105,880
<p>I'm having trouble using <code>groupby</code> and <code>aggregation</code> when working w/ multiple dataframes. I'm trying to calculate <code>num_maint_over_$90</code> from two different dataframes.</p> <pre><code>cars_dict = {"ABC123": ["Ford", "Compact_Car"], "XYZ148": ["Chevy", "Truck"], "ASX133": ["Ford", "Truc...
1
2016-06-29T16:59:39Z
38,106,353
<p>Here is the naive for-loop solution:</p> <pre><code>car_types = {} for index, row in cars.iterrows(): car_type = row["Type"] if car_type not in car_types: car_types[car_type] = 0 for index, row in maintenance_records.iterrows(): if row["Cost"] &gt; 90: car_license = row["License_Plat...
0
2016-06-29T17:24:53Z
[ "python", "pandas", "dataframe" ]
Recursively calling a method for about (2^60)+ times in python
38,105,905
<p>I am having a case where a method should be called recursively for about (2^60) or more number of times </p> <p>I made successfully up to 2^9 then is caused "maximum recursion depth exceeded in comparison" is there any way to do this </p> <p>I am trying to change it to a Iterative method </p> <p>I am using Pytho...
-1
2016-06-29T17:00:46Z
38,106,086
<p>You need to change your function to iterate instead of recurse.<br> Example:</p> <pre><code>def recursionSum(n): if n==0: return 0 return n + recursionSum(n-1) def iterativeSum(n): sum = 0 while(n&gt;0): sum += n n = n-1 # update parameter and loop again return sum </cod...
2
2016-06-29T17:10:11Z
[ "python" ]
Recursively calling a method for about (2^60)+ times in python
38,105,905
<p>I am having a case where a method should be called recursively for about (2^60) or more number of times </p> <p>I made successfully up to 2^9 then is caused "maximum recursion depth exceeded in comparison" is there any way to do this </p> <p>I am trying to change it to a Iterative method </p> <p>I am using Pytho...
-1
2016-06-29T17:00:46Z
38,106,188
<p><a href="https://docs.python.org/2/library/sys.html#sys.setrecursionlimit" rel="nofollow">Python Docs:</a></p> <blockquote> <pre><code>sys.setrecursionlimit(limit) </code></pre> <p>Set the maximum depth of the Python interpreter stack to limit. This limit prevents infinite recursion from causing an overflow of...
0
2016-06-29T17:15:39Z
[ "python" ]
Recursively calling a method for about (2^60)+ times in python
38,105,905
<p>I am having a case where a method should be called recursively for about (2^60) or more number of times </p> <p>I made successfully up to 2^9 then is caused "maximum recursion depth exceeded in comparison" is there any way to do this </p> <p>I am trying to change it to a Iterative method </p> <p>I am using Pytho...
-1
2016-06-29T17:00:46Z
38,106,197
<p>You can try the following:</p> <pre><code>import sys sys.setrecursionlimit(n) </code></pre> <p>where <code>n</code> is a large number. This is a limit set by the interpreter, another limit is set by the OS. Therefore for large <code>n</code> you will see a different error message. 2^60 recursion calls are definite...
0
2016-06-29T17:15:56Z
[ "python" ]
Recursively calling a method for about (2^60)+ times in python
38,105,905
<p>I am having a case where a method should be called recursively for about (2^60) or more number of times </p> <p>I made successfully up to 2^9 then is caused "maximum recursion depth exceeded in comparison" is there any way to do this </p> <p>I am trying to change it to a Iterative method </p> <p>I am using Pytho...
-1
2016-06-29T17:00:46Z
38,106,399
<p>As you said you looking at something involving Bellman Equations, I suggest that you look for implementations regarding that. </p> <p>A quick Google search found <a href="https://github.com/rncarpio/bellman/blob/master/bellman.py" rel="nofollow">this example on GitHub by rncarpio</a>.</p> <p>I haven't taken a in-d...
1
2016-06-29T17:28:11Z
[ "python" ]
concat turns values to nan data
38,105,917
<p>I have this code:</p> <pre><code>gg=df_met[['Less','Middle','Greater']].resample('h').mean() Filtered_mean=Filtered[['Conc']].resample('h').mean() result = pd.concat([Filtered_mean, gg], axis=1, join_axes=[df1.index]) Reduced_result=result.dropna(axis=0,how='any') </code></pre> <p>Where gg is a file:</p> <pre><c...
2
2016-06-29T17:01:11Z
38,106,278
<p>yes indeed. You should have consistent index types across the two dataframes.</p> <p>Use </p> <pre><code>filtered_mean.reset_index(inplace=True) filtered_mean['date']=pd.to_datetime(filtered_mean['date']) filtered_mean.set_index('date',inplace=True) </code></pre> <p>Now both <code>filtered_mean</code> and <code>g...
2
2016-06-29T17:20:50Z
[ "python", "pandas" ]
Dimension Mismatch in LSTM Keras
38,105,999
<p>I want to create a basic RNN that can add two bytes. Here are the input and outputs, which are expected of a simple addition</p> <pre><code>X = [[0, 0], [0, 1], [1, 1], [0, 1], [1, 0], [1, 0], [1, 1], [1, 0]] </code></pre> <p>That is, <code>X1 = 00101111</code> and <code>X2 = 01110010</code></p> <pre><code>Y = [1...
2
2016-06-29T17:05:41Z
38,108,796
<p>In Keras the Sequential models expect an input of shape <code>(batch_size, sequence_length, input_dimension)</code>. I suspect you need to change the two last dimensions of your input array. Remember, the batch dimension is not explicitly defined. </p>
2
2016-06-29T19:46:01Z
[ "python", "deep-learning", "keras", "lstm" ]
Dimension Mismatch in LSTM Keras
38,105,999
<p>I want to create a basic RNN that can add two bytes. Here are the input and outputs, which are expected of a simple addition</p> <pre><code>X = [[0, 0], [0, 1], [1, 1], [0, 1], [1, 0], [1, 0], [1, 1], [1, 0]] </code></pre> <p>That is, <code>X1 = 00101111</code> and <code>X2 = 01110010</code></p> <pre><code>Y = [1...
2
2016-06-29T17:05:41Z
38,119,629
<p>Change X to <code>[[[0, 0], [0, 1], [1, 1], [0, 1], [1, 0], [1, 0], [1, 1], [1, 0]]]</code> so that its shape is <code>(1, 8, 2)</code></p>
2
2016-06-30T09:52:35Z
[ "python", "deep-learning", "keras", "lstm" ]
Csv files and giving dictionary certain keys
38,106,158
<p>I have a Csv file with temperatures in Celsius. Like this:</p> <pre><code>17;15;13;13;12;13;14;15;15;16;17;18;19;21;23;25;25;23;22;22;21;19;18;18 </code></pre> <p>Each number is the temperature at X hour of the day, the csv is ordered.. Now I want to give each entry a key, like this:</p> <pre><code>{0: 17, 1: 15...
1
2016-06-29T17:14:09Z
38,106,247
<p>To use numeric keys like the example you gave, try this:</p> <pre><code>result = {} # a dictionary, not a list for idx, d in enumerate(reader): result[idx] = d </code></pre> <p>The <a href="https://docs.python.org/2/library/functions.html#enumerate" rel="nofollow"><code>enumerate</code></a> function will giv...
2
2016-06-29T17:18:57Z
[ "python", "python-2.7", "python-3.x", "csv" ]
Csv files and giving dictionary certain keys
38,106,158
<p>I have a Csv file with temperatures in Celsius. Like this:</p> <pre><code>17;15;13;13;12;13;14;15;15;16;17;18;19;21;23;25;25;23;22;22;21;19;18;18 </code></pre> <p>Each number is the temperature at X hour of the day, the csv is ordered.. Now I want to give each entry a key, like this:</p> <pre><code>{0: 17, 1: 15...
1
2016-06-29T17:14:09Z
38,106,276
<p>One possible way is to just zip them with a <code>range(24)</code> e.g.:</p> <pre><code>&gt;&gt;&gt; temps = "17;15;13;13;12;13;14;15;15;16;17;18;19;21;23;25;25;23;22;22;21;19;18;18".split(";") &gt;&gt;&gt; temps ['17', '15', '13', '13', '12', '13', '14', '15', '15', '16', '17', '18', '19', '21', '23', '25', '25', ...
0
2016-06-29T17:20:46Z
[ "python", "python-2.7", "python-3.x", "csv" ]
Scheme to avoid recomputation
38,106,203
<p><strong>Motivation:</strong></p> <p>For the sake of abstractness, I have a method treating a list of objects. Here I show a simplified version for illustration purpose (using Python2.7 here):</p> <pre><code>def foo(obj_lst, f): return list(map(f, obj_lst)) </code></pre> <p>However, for some cases, the input c...
1
2016-06-29T17:16:20Z
38,106,314
<p>You're describing <a href="https://en.wikipedia.org/wiki/Memoization" rel="nofollow">memoization</a>.</p> <p>This can be done by <a href="http://www.python-course.eu/python3_memoization.php" rel="nofollow">creating your own helper/decorator function</a> or using <a href="https://docs.python.org/3/library/functools....
3
2016-06-29T17:23:01Z
[ "python", "performance", "scala" ]
Scheme to avoid recomputation
38,106,203
<p><strong>Motivation:</strong></p> <p>For the sake of abstractness, I have a method treating a list of objects. Here I show a simplified version for illustration purpose (using Python2.7 here):</p> <pre><code>def foo(obj_lst, f): return list(map(f, obj_lst)) </code></pre> <p>However, for some cases, the input c...
1
2016-06-29T17:16:20Z
38,106,640
<p>Something like this perhaps?</p> <pre><code> import java.util.{Collections, WeakHashMap} case class Memoized[T,R](f: T =&gt; R) extends Function1[T,R] { val mem = Collections.synchronizedMap(new WeakHashMap[T,R]) def apply(t: T) = Option(mem.get(t)).getOrElse { val r = f(t) mem.put(t, r) ...
0
2016-06-29T17:41:28Z
[ "python", "performance", "scala" ]
Asyncio: Problems with very simple write-and-disconnect UDP client
38,106,209
<p>I wanted to try out the new <code>asyncio</code> module from Python 3.5.1. Here's my test code:</p> <pre><code>import asyncio class EchoClientProtocol: def __init__(self, message, loop): self.message = message self.loop = loop self.transport = None def connection_made(self, transpo...
0
2016-06-29T17:16:33Z
38,111,994
<p>The <code>DatagramTransport</code> (actually <code>_SelectorDatagramTransport</code>) schedules two actions on connection, the first one is <code>connection_made</code> from given protocol, the second is <code>_read_ready</code> (recvfrom) - in that order (<a href="https://github.com/python/asyncio/blob/master/async...
0
2016-06-30T00:06:07Z
[ "python", "python-3.x", "python-asyncio", "python-sockets" ]
Is issubclass broken for comparing with typing.Generic in Python 3.5?
38,106,227
<p>How do I find out if a given class is a subclass of any <code>typing.Generic</code>? Calling <code>issubclass</code> does not seem to work as I expected:</p> <pre class="lang-py prettyprint-override"><code>import typing T = typing.TypeVar('T') class A(typing.Generic[T]): pass class B: pass issubclass(A,...
3
2016-06-29T17:17:30Z
38,112,456
<p>This is expected behavior (as of right now, at least). You can't mix a type as specified in the context of type hinting with a class. You can consider a <code>type</code> as being a tag, an indication for a possible type checker. A class is a runtime object with which you interact. </p> <p>More information can be f...
2
2016-06-30T01:15:17Z
[ "python", "python-3.x", "type-hinting" ]
Is a flask config file persistent?
38,106,288
<p>If I create a variable in a Flask config file, will the actual config file be updated when I update the variable in the app?</p>
-1
2016-06-29T17:21:12Z
38,106,541
<p>No. The config file is read once, and never written to. If you change the file, or change the config, you will need to read or write those changes yourself.</p> <p>This is trivial to verify by making a change and viewing the file afterwards.</p> <p>Reading config from a file is just one way you can configure you...
1
2016-06-29T17:36:28Z
[ "python", "flask" ]
Python won't Receive UDP Packets(Non Broadcast)
38,106,302
<p>I'm Writing a script in python2.7 on a windows XP machine. The machine is connected to multiple networks using different network cards. I have already posted a question that relates to this issue but does not directly address it <a href="http://stackoverflow.com/questions/37976551/python-udp-sockets-with-multiple-in...
1
2016-06-29T17:22:10Z
38,543,146
<p>Turns out, the Packets that my "server" was sending where not IP kosher. so they where getting rejected at the network and transport layers. Solution was to not use python socket class, but instead communicate directly to OSI-L2 using <a href="https://www.winpcap.org/" rel="nofollow">winpcap</a> and ctypes</p>
0
2016-07-23T14:59:58Z
[ "python", "sockets", "networking", "udp" ]
rsyslog template "eating" the first part of a message
38,106,307
<p>I'm logging messages to syslog with Python's <code>SysLogHandler</code>. The problem is that <code>startswith</code> combined with a template seems to "eat" the beginning of the logged string.</p> <p>Rsyslogd is version 8.4.2, Python 2.7.9 (same behaviour on 2.7.11). It does not seem to happen on rsyslogd 7.x with ...
0
2016-06-29T17:22:33Z
38,146,621
<p>The solution appears to be:</p> <ol> <li>Use <code>$syslogtag startswith</code> instead of <code>$msg startswith</code></li> <li>In the python source, <strong><em>separate</em></strong> the <code>name</code> from the rest of the string with an empty space: <code>logging.Formatter('%(name)s: %(message)s', '%Y-%m-%d ...
0
2016-07-01T13:23:50Z
[ "python", "rsyslog" ]
Numpy flatten array of array from cv2
38,106,342
<p>Wait! Before you 'harrumph' and downvote, this seems like a repeat question but I've looked at the other questions and they don't really fit my use case.</p> <p>I was reading images one by one into a list with cv2, with the intention of running a classifier over them. eg:</p> <pre><code>lst = [] for picture in di...
0
2016-06-29T17:24:38Z
38,107,888
<p>Here's a suggestion. Only works if all images are indeed the same size after flattening.</p> <pre><code>lst = [] for picture in directory: img = cv2.imread(picture) img = img.flatten() # because classifiers require it to be flat if lst = []: lst = img else: lst = concatenate((lst, [i...
0
2016-06-29T18:52:15Z
[ "python", "numpy" ]
counting number of elements in a list
38,106,368
<p>I have a list</p> <pre><code>my_list = ['TTATGCTAAGTATC,TTATGCTAAGTATC,TTATGCTAAGTATC,TTATGCTAAGTATC,TTATGCTAAGTATC,TTATGCTAAGTATC,TTATGCTAAGTATC,TTATGCTAAGTATC', 'TTATGCTAAGTATC,TTATGCTAAGTATC,TTATGCTAAGTATC,TTATGCTAAGTATC,TTATGCTAAGTATC,TTATGCTAAGTATC,TTATGCTAAGTATC,TTATGCTAAGTATC', 'AGCTCCCCGTTTTC,AGCTCCCCGTTTTC...
0
2016-06-29T17:26:15Z
38,106,413
<p>Your iteration loop is mixing concepts. It should just be:</p> <pre><code>for i in my_list: Counter(i).most_common() </code></pre> <p>You don't need to do the indexing.</p> <p>This gives me:</p> <pre><code>[('T', 48), ('A', 32), ('C', 16), ('G', 16), (',', 7)] [('T', 48), ('A', 32), ('C', 16), ('G', 16), (',',...
3
2016-06-29T17:28:42Z
[ "python" ]