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
RTSP: cannot get session identifier
39,192,256
<p>I am trying to control an ip cam using a python script (I can see the stream with VLC or mplayer).</p> <p>After received OPTIONS and DESCRIBE informations, every SETUP I try give me an error:</p> <pre><code>SETUP rtsp://192.168.0.41:554/xxxxxx RTSP/1.0 CSeq: 3 Transport: RTP/AVP/UDP;unicast;client_port=3056-3057 ...
0
2016-08-28T14:22:03Z
39,230,867
<p>Finally I discovered the problem: missing <strong>\r\n</strong> in the last python code line!</p> <p>wrong:</p> <pre><code>Transport: RTP/AVP/UDP;unicast;client_port=52318-52319 </code></pre> <p>correct:</p> <pre><code>Transport: RTP/AVP/UDP;unicast;client_port=52318-52319\r\n </code></pre> <p>Now it works.</p>...
0
2016-08-30T14:55:59Z
[ "python", "streaming", "rtsp", "onvif" ]
Django Multi-site with shared database
39,192,404
<p>I am about to develop multiple sites for different real estate companies. All share the same html, sections, etc. The difference is in the content, specially the properties... But some of those properties can be shared among the rest of the companies.</p> <p>I am thinking in sharing the same database and differenti...
0
2016-08-28T14:38:37Z
39,196,364
<p>I have done that.<br> Was it a good idea? Yes, in my case it was. I had to reuse the same content and when we changed the content, it had to be changed on all pages. On a simple site, a triple deploy and changing the content in three different projects is kind of overkill. But whereas it works fine in a simple front...
0
2016-08-28T22:27:53Z
[ "python", "django" ]
Which is faster a dictionary retrieve or a list indexing?
39,192,442
<p>I'm trying to decide which data structure best fits my needs.</p> <p>Technical details apart, I may translate the needs of my program to use dictionaries or to use lists, and since performance will be an issue I was wondering what may be a faster solution. I ended up concluding that retrieving/indexing will be the ...
0
2016-08-28T14:44:45Z
39,192,475
<p>Well, retrieving from a dict has the same complexity as retrieving from a list:</p> <pre><code>_dict[1] _list[1] </code></pre> <p>but..., with dicts, u can use:</p> <pre><code>_dict.get(1, 'something else') </code></pre> <p>It just returns 'something else' if there is no key <code>1</code>. Using lists, you cann...
0
2016-08-28T14:48:13Z
[ "python", "list", "dictionary", "profiling" ]
Which is faster a dictionary retrieve or a list indexing?
39,192,442
<p>I'm trying to decide which data structure best fits my needs.</p> <p>Technical details apart, I may translate the needs of my program to use dictionaries or to use lists, and since performance will be an issue I was wondering what may be a faster solution. I ended up concluding that retrieving/indexing will be the ...
0
2016-08-28T14:44:45Z
39,192,562
<p><a href="https://wiki.python.org/moin/TimeComplexity" rel="nofollow">https://wiki.python.org/moin/TimeComplexity</a> provides all the info you're looking for</p>
0
2016-08-28T14:57:37Z
[ "python", "list", "dictionary", "profiling" ]
Which is faster a dictionary retrieve or a list indexing?
39,192,442
<p>I'm trying to decide which data structure best fits my needs.</p> <p>Technical details apart, I may translate the needs of my program to use dictionaries or to use lists, and since performance will be an issue I was wondering what may be a faster solution. I ended up concluding that retrieving/indexing will be the ...
0
2016-08-28T14:44:45Z
39,192,976
<p>If you don't need to search, use a list. It's faster, and uses less RAM than a dict. For small collections (&lt;100 items) the speed differences are minimal, but for large collections the dict will be around 20% slower. And it will certainly use more RAM.</p> <p>Here's some <code>timeit</code> code that compares th...
1
2016-08-28T15:42:50Z
[ "python", "list", "dictionary", "profiling" ]
I have a nested list, but i want to add a nested list inside the nested list
39,192,477
<p>I have a list like:</p> <pre><code>[[21, 32, 32], [23, 34, 32], [32, 34, 57]] </code></pre> <p>I would like to convert each number to its own list like</p> <pre><code>[[[21], [32], [32]], [[23], [34], [32]], [[32], [34], [57]]] </code></pre> <p>How would i do that?</p> <p>Thanks!</p>
2
2016-08-28T14:48:24Z
39,192,518
<p>Use a <em>list comprehension</em>:</p> <pre><code>&gt;&gt;&gt; lst = [[21, 32, 32], [23, 34, 32], [32, 34, 57]] &gt;&gt;&gt; new_lst = [[[i] for i in sub_lst] for sub_lst in lst] &gt;&gt;&gt; new_lst [[[21], [32], [32]], [[23], [34], [32]], [[32], [34], [57]]] </code></pre> <hr> <p>You can also use <code>numpy</c...
1
2016-08-28T14:52:43Z
[ "python", "python-3.x" ]
I have a nested list, but i want to add a nested list inside the nested list
39,192,477
<p>I have a list like:</p> <pre><code>[[21, 32, 32], [23, 34, 32], [32, 34, 57]] </code></pre> <p>I would like to convert each number to its own list like</p> <pre><code>[[[21], [32], [32]], [[23], [34], [32]], [[32], [34], [57]]] </code></pre> <p>How would i do that?</p> <p>Thanks!</p>
2
2016-08-28T14:48:24Z
39,192,545
<p>Here is a method using <code>numpy.reshape()</code>:</p> <pre><code>import numpy as np arr = np.array([[21, 32, 32], [23, 34, 32], [32, 34, 57]]) arr.reshape(3,3,1) # array([[[21], # [32], # [32]], # [[23], # [34], # [32]], # [[32], # [34], # [57]]]...
1
2016-08-28T14:55:39Z
[ "python", "python-3.x" ]
I have a nested list, but i want to add a nested list inside the nested list
39,192,477
<p>I have a list like:</p> <pre><code>[[21, 32, 32], [23, 34, 32], [32, 34, 57]] </code></pre> <p>I would like to convert each number to its own list like</p> <pre><code>[[[21], [32], [32]], [[23], [34], [32]], [[32], [34], [57]]] </code></pre> <p>How would i do that?</p> <p>Thanks!</p>
2
2016-08-28T14:48:24Z
39,195,015
<p>Method using list comprehension:</p> <pre><code>a = [[21, 32, 32], [23, 34, 32], [32, 34, 57]] print [[[element] for element in each] for each in a] </code></pre> <p>Output:</p> <pre><code>[[[21], [32], [32]], [[23], [34], [32]], [[32], [34], [57]]] </code></pre>
0
2016-08-28T19:30:43Z
[ "python", "python-3.x" ]
pytest-bdd reuse same method for different steps
39,192,481
<p>I want to use same method for @given, @when and @then of same step. e.g. </p> <pre><code>Scenario: Launch an application Given username and password entered And login button pressed Then the app launches Scenario: Launch application again Given user logged out And username an...
2
2016-08-28T14:48:40Z
39,582,866
<p>In pytest-BDD it does not currently support the ability to use two different step types/definitions on one function definition. How ever there are "work arounds"</p> <p><strong>Option 1: Turn off Gherkin strict mode</strong> </p> <pre><code>@pytest.fixture def pytestbdd_strict_gherkin(): return False </code></...
0
2016-09-19T22:10:04Z
[ "python", "bdd", "py.test" ]
pandas dataframe fillna() not working?
39,192,614
<p>I have a data set in which I am performing a principal components analysis (PCA). I get a <code>ValueError</code> message when I try to transform the data. Below is some of the code:</p> <pre><code>import pandas as pd import numpy as np import matplotlib as mpl from sklearn.preprocessing import StandardScaler from ...
0
2016-08-28T15:02:46Z
39,192,648
<p>You have to replace data by the returned object from <code>fillna</code></p> <p>Small reproducer:</p> <pre><code>import pandas as pd data = pd.DataFrame(data=[0,float('nan'),2,3]) print(data.isnull().values.any()) # prints True data = data.fillna(0) # replace NaN values with 0 print(data.i...
0
2016-08-28T15:07:00Z
[ "python", "pandas", "dataframe", "missing-data" ]
I want to print integer variables string separated by some string in Python3
39,192,628
<p>I am trying to print 3 integer variables separated by some string. But it is giving me an error </p> <blockquote> <p>TypeError: unsupported operand type(s) for +: 'int' and 'str'.</p> </blockquote> <p>My attempt: </p> <pre><code>def unpack_values(grades): first, *middle, last = grades avg = sum(middle...
-2
2016-08-28T15:04:13Z
39,192,658
<p>The error occurs when trying to calculate <code>sum(middle)</code>, because <code>middle</code> is a list of strings. You need to convert it to integers first.</p> <pre><code>In [1]: def unpack_values(grades): ...: first, *middle, last = [int(g) for g in grades] ...: avg = sum(middle) / len(middle) ...
5
2016-08-28T15:08:18Z
[ "python", "python-3.x" ]
Finding the minimum of a function on a closed interval with Python
39,192,643
<p>Updated: How do I find the minimum of a function on a closed interval [0,3.5] in Python? So far I found the max and min but am unsure how to filter out the minimum from here. </p> <pre><code>import sympy as sp x = sp.symbols('x') f = (x**3 / 3) - (2 * x**2) + (3 * x) + 1 fprime = f.diff(x) all_solutions = [(xx,...
1
2016-08-28T15:05:51Z
39,192,723
<p>Here's a possible solution using sympy:</p> <pre><code>import sympy as sp x = sp.Symbol('x', real=True) f = (x**3 / 3) - (2 * x**2) - 3 * x + 1 #f = 3 * x**4 - 4 * x**3 - 12 * x**2 + 3 fprime = f.diff(x) all_solutions = [(xx, f.subs(x, xx)) for xx in sp.solve(fprime, x)] interval = [0, 3.5] interval_solutions =...
1
2016-08-28T15:14:22Z
[ "python", "numpy", "sympy" ]
Finding the minimum of a function on a closed interval with Python
39,192,643
<p>Updated: How do I find the minimum of a function on a closed interval [0,3.5] in Python? So far I found the max and min but am unsure how to filter out the minimum from here. </p> <pre><code>import sympy as sp x = sp.symbols('x') f = (x**3 / 3) - (2 * x**2) + (3 * x) + 1 fprime = f.diff(x) all_solutions = [(xx,...
1
2016-08-28T15:05:51Z
39,193,838
<p><a href="http://i.stack.imgur.com/88Dzj.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/88Dzj.jpg" alt="Interactive Python session"></a></p> <p>The f.subs commands show two ways of displaying the value of the given function at x=3.5, the first as a rational approximation, the second as the exact fraction.</p...
0
2016-08-28T17:13:03Z
[ "python", "numpy", "sympy" ]
Finding the minimum of a function on a closed interval with Python
39,192,643
<p>Updated: How do I find the minimum of a function on a closed interval [0,3.5] in Python? So far I found the max and min but am unsure how to filter out the minimum from here. </p> <pre><code>import sympy as sp x = sp.symbols('x') f = (x**3 / 3) - (2 * x**2) + (3 * x) + 1 fprime = f.diff(x) all_solutions = [(xx,...
1
2016-08-28T15:05:51Z
39,235,550
<p>Perhaps something like this</p> <pre><code>from sympy import solveset, symbols, Interval, Min x = symbols('x') lower_bound = 0 upper_bound = 3.5 function = (x**3/3) - (2*x**2) - 3*x + 1 zeros = solveset(function, x, domain=Interval(lower_bound, upper_bound)) assert zeros.is_FiniteSet # If there are infinite solut...
1
2016-08-30T19:22:50Z
[ "python", "numpy", "sympy" ]
Feature extraction
39,192,660
<p>Suppose I have been given data sets with headers : id, query, product_title, product_description, brand, color, relevance.</p> <p>Only id and relevance is in numeric format while all others consists of words and numbers. Relevance is the relevancy or ranking of a product with respect to a given query. For eg - que...
-2
2016-08-28T15:08:26Z
39,197,840
<p>I think there is no book that will give the answers you need, as feature extraction is the phase that relates directly to the problem being solved and the existing data,the only tip you will find is to create features that describe the data you have. In the past i worked in a problem similar to yours and some featur...
1
2016-08-29T02:45:19Z
[ "python", "machine-learning" ]
Running shell script from python
39,192,749
<p>I have written a small python programme which writes a C-shell script, and then calls the script with subprocess. However, python fails to execute the script. I tested this in the terminal and discovered that the script will also not run from the terminal (i.e. not a python issue). Further testing revealed I could w...
0
2016-08-28T15:17:13Z
39,214,180
<p>In case this is useful I used <code>xxd</code> (as suggested in the comments above, <a href="http://linuxcommand.org/man_pages/xxd1.html" rel="nofollow">http://linuxcommand.org/man_pages/xxd1.html</a>) to convert both script files, one created in python and one written manually, to hex</p> <pre><code>xxd script.txt...
0
2016-08-29T19:56:58Z
[ "python", "shell", "unix", "vi", "csh" ]
Make Bleach to allow code tags
39,192,753
<p>I'm trying to use <a href="https://github.com/mozilla/bleach" rel="nofollow">bleach</a> to escape HTML tags. It works just fine, unless I'm trying to insert a code snipped as a content of a page. The snippet is inserted like this:</p> <pre><code>&lt;pre&gt; &lt;code&gt; Code sample &lt;/code&gt; &lt;/pre&gt; </cod...
2
2016-08-28T15:17:27Z
39,193,438
<p>You want to whitelist children tags of &lt; pre > and &lt; code >. From what I can infer from reading on the documentation, you have to define one by one the tags you want to whitelist or use a callable that every time a tag gets encountered the callable will be invoked.</p> <p>Check on the documentation the sectio...
0
2016-08-28T16:31:46Z
[ "python", "markdown", "bleach" ]
Create list from multiple lists
39,192,759
<p>I saved the results of a loop in a varibale. Now I have multiple (>500) separate lists. Which was okay for the beginning, but now I would like to work again with those lists. Do someone has an idea how I can create one list out of those multiple lists?</p> <p>The code I have so far:</p> <pre><code>for f in file: ...
0
2016-08-28T15:17:47Z
39,192,828
<p>You are creating <code>my_result</code> at every iteration, as you've put the initialization part inside the loop. Put it outside the loop, so that it become initialized only once.</p> <pre><code>my_results =[] for f in file: #do some stuff if score &gt;= 0: my_results.append(str(score)) print my_re...
1
2016-08-28T15:23:43Z
[ "python", "python-2.7" ]
Create list from multiple lists
39,192,759
<p>I saved the results of a loop in a varibale. Now I have multiple (>500) separate lists. Which was okay for the beginning, but now I would like to work again with those lists. Do someone has an idea how I can create one list out of those multiple lists?</p> <p>The code I have so far:</p> <pre><code>for f in file: ...
0
2016-08-28T15:17:47Z
39,192,830
<p>You are on the right track, but you seem confused about for loops. This should do what you want:</p> <pre><code>my_result = [] for f in file: #do some stuff here if score &gt;= 0: my_result.append(str(score)) print my_result </code></pre> <p>The problem with your current code is that you keep setti...
1
2016-08-28T15:23:54Z
[ "python", "python-2.7" ]
Create list from multiple lists
39,192,759
<p>I saved the results of a loop in a varibale. Now I have multiple (>500) separate lists. Which was okay for the beginning, but now I would like to work again with those lists. Do someone has an idea how I can create one list out of those multiple lists?</p> <p>The code I have so far:</p> <pre><code>for f in file: ...
0
2016-08-28T15:17:47Z
39,193,311
<p>You can use list comprehension, that would be fast, if you are not doing some stuff inside the for loop.</p> <pre><code>my_result = [str(score) for score in file if score &gt;= 0] </code></pre>
1
2016-08-28T16:18:10Z
[ "python", "python-2.7" ]
Python split a list into n groups in all possible combinations of group length and elements within group
39,192,777
<p>I want to split a list into n groups in all possible combinations (allowing for variable group length). </p> <p>Say, I have the following list:</p> <pre><code>lst=[1,2,3,4] </code></pre> <p>If I specify n=2, the list could be divided either into groups of 1 element-3 elements or 2 elements-2 elements. Within thos...
2
2016-08-28T15:19:35Z
39,193,050
<p>Try to use:</p> <pre><code>from itertool import combinations, permutations </code></pre>
0
2016-08-28T15:50:02Z
[ "python" ]
Python split a list into n groups in all possible combinations of group length and elements within group
39,192,777
<p>I want to split a list into n groups in all possible combinations (allowing for variable group length). </p> <p>Say, I have the following list:</p> <pre><code>lst=[1,2,3,4] </code></pre> <p>If I specify n=2, the list could be divided either into groups of 1 element-3 elements or 2 elements-2 elements. Within thos...
2
2016-08-28T15:19:35Z
39,197,711
<p>Following the helpful links from @friendly_dog, I'm attempting to answer my own question by tweaking the functions used in <a href="http://stackoverflow.com/questions/19368375/set-partitions-in-python/30134039#30134039">this</a> post. I have a rough solution that works, although I fear it is not particularly efficie...
0
2016-08-29T02:21:47Z
[ "python" ]
Python split a list into n groups in all possible combinations of group length and elements within group
39,192,777
<p>I want to split a list into n groups in all possible combinations (allowing for variable group length). </p> <p>Say, I have the following list:</p> <pre><code>lst=[1,2,3,4] </code></pre> <p>If I specify n=2, the list could be divided either into groups of 1 element-3 elements or 2 elements-2 elements. Within thos...
2
2016-08-28T15:19:35Z
39,199,937
<p>We can use the basic recursive algorithm from <a href="http://stackoverflow.com/a/30134039">this answer</a> and modify it to produce partitions of a particular length without having to generate and filter out unwanted partitions. </p> <pre><code>def sorted_k_partitions(seq, k): """Returns a list of all unique k...
2
2016-08-29T06:38:09Z
[ "python" ]
What does self[] mean in a method?
39,192,798
<p>When reading a python program, I once find a function uses <code>self</code> in the following way. </p> <pre><code>class Auto(object): _biases_str = "biases{0}" def _b(self, n, suffix=""): name_b_out = self._biases_str.format(i + 1) + "_out" return `self[self._biases_str.format(n) + suffix]` </code...
0
2016-08-28T15:20:45Z
39,192,852
<p>It doesn't mean anything other than what <code>variable[something]</code> would mean. In Python <code>variable[something]</code> in an expression will just call <code>variable.__getitem__(something)</code>, and <code>self</code> is the name conventionally used for the current object, or the receiver, in Python, so <...
5
2016-08-28T15:25:58Z
[ "python", "python-2.7", "python-3.x" ]
does python function work if multiple user call it at same instant
39,192,846
<p>I am using django framework. I have built one web application using python and django. I am not using any classes or oops concept in my application. I am just using python's function. for e.g. </p> <pre><code>def addnum(request): a=request.GET.get('a') b=request.GET.get('b') res=a+b return HttpResp...
1
2016-08-28T15:25:11Z
39,194,389
<p>It does not depend upon how you are writing your code it depends upon the server that how it handles multiple requests. I think that a free server on <a href="http://pythonanywhere.com" rel="nofollow">pythonanywhere</a> would be able to handle about 1K concurrent user requests. A server and user is connected using u...
0
2016-08-28T18:17:15Z
[ "javascript", "python", "django", "python-2.7", "django-views" ]
does python function work if multiple user call it at same instant
39,192,846
<p>I am using django framework. I have built one web application using python and django. I am not using any classes or oops concept in my application. I am just using python's function. for e.g. </p> <pre><code>def addnum(request): a=request.GET.get('a') b=request.GET.get('b') res=a+b return HttpResp...
1
2016-08-28T15:25:11Z
39,233,232
<p>When multiple users access it "at the same time", it's actually not at the same time. Let's say you are using uWSGI to serve your webapp, which means that your webapp has a bunch of workers that handle requests.</p> <p>Let's take the simplest case where you just have a single worker. In this case, everything is jus...
0
2016-08-30T17:02:23Z
[ "javascript", "python", "django", "python-2.7", "django-views" ]
Why is translated Sudoku solver slower than original?
39,192,878
<p>I transcribed my Java Sudoku solver into python. Everything works, however solving takes up to 2mins, while the identical puzzle takes only a few seconds in Java. Also the iterations needed amount to the exact same number. Am I missing something?</p> <pre><code>import numpy as np def solve_recursive(puzzle, pos): ...
-1
2016-08-28T15:29:37Z
39,195,131
<p>I modified your function to print the <code>pos</code> and to maintain a running count of the times it's been called. And I stop it early.</p> <p>Stopping at <code>pos==46</code> results in 1190 calls, with just a slight visible delay. But for 47 the count is 416621, with a minute or more run. </p> <p>Assuming ...
2
2016-08-28T19:44:35Z
[ "java", "python", "numpy", "sudoku" ]
Django Product Total
39,193,002
<p>I'm trying to learn in Django. I'm trying to prepare the inventory application. But I do not calculate the input and output products. </p> <p>I prepare models &amp; views.</p> <p><strong>Models:</strong></p> <pre><code>class Kategori(models.Model): adi = models.CharField(max_length=10, verbose_name="Kategori"...
0
2016-08-28T15:45:09Z
39,196,158
<p>If I understand your question correctly, you want to aggregate the values of <code>miktar</code> of both models and subtract them from each other. You can do it with Django built-in aggregation:</p> <pre><code>from django.db.models import Sum total = StokGiris.objects.all().aggregate(Sum('miktar')) - StokCikis.obj...
0
2016-08-28T21:56:01Z
[ "python", "django" ]
Python html div class
39,193,005
<p>I'm trying to write a simple program which saves the values of a table in a matrix (later I want to send the matrix to a database).</p> <p>Here is my code:</p> <pre><code>pfad = "https://business.facebook.com/ads/manager/account/ads/?act=516059741896803&amp;pid=p2&amp;report_spec=6056690557117&amp;business_id=4018...
-1
2016-08-28T15:45:27Z
39,194,180
<p>Try using <code>lxml</code> and xpath expressions to pull out the relevant information. Beautifulsoup is built on lxml, I believe. Assuming you loaded the document into a string called <code>html_string</code>.</p> <pre><code>from lxml import html h = html.fromstring(html_string) h.xpath('//div[@class="ellipsis_...
0
2016-08-28T17:51:32Z
[ "python", "html", "beautifulsoup" ]
Location of static files when creating a Django exe using pyinstaller
39,193,073
<p>I have a Django project with the following structure: root videos static templates</p> <p>and the STATIC_URL setting in settings.py is STATIC_URL = '/static/'</p> <p>I managed to use pyinstaller to create a windows executable from manage.py. I can start the Django server but I can't figure out where to p...
0
2016-08-28T15:53:09Z
39,193,157
<p>First make sure that <code>django.contrib.staticfiles</code> is included in your <code>INSTALLED_APPS</code> in <code>settings.py</code>. Then have to insert in your <code>settings.py</code> for example this one:</p> <pre><code>STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), ] </code></pre> <p>I hope de...
0
2016-08-28T16:01:42Z
[ "python", "django", "pyinstaller" ]
Moving python package without messing internal imports
39,193,092
<p>I wrote a python package that includes many modules. The modules import each other within the package. Now after it is complete I wish to move my package inside a different package as a subdirectory. But I can't do it because now all the imports get errors because they can't find the modules on their new path.</p> ...
1
2016-08-28T15:55:46Z
39,193,824
<p>I would use relative imports internally:</p> <pre><code>from .a import x </code></pre> <p>If your module is self-contained, you can relocate it without issues if it uses relative imports.</p>
1
2016-08-28T17:12:04Z
[ "python", "import", "packages" ]
pandas: dataframe from dict with comma separated values
39,193,110
<p>I'm trying to create a DataFrame from a nested dictionary, where the values are in comma separated strings.</p> <p>Each value is nested in a dict, such as:</p> <pre><code>dict = {"1":{ "event":"A, B, C"}, "2":{ "event":"D, B, A, C"}, "3":{ "event":"D, B, C"} ...
1
2016-08-28T15:56:58Z
39,193,319
<p>From what you have(modified the split a little to strip the extra spaces) <code>df1</code>, you can probably just <code>stack</code> the result and use <code>pd.crosstab()</code> on the index and value column:</p> <pre><code>df1 = df.loc['event'].str.split('\s*,\s*').apply(pd.Series) df2 = df1.stack().rename('val...
1
2016-08-28T16:19:05Z
[ "python", "pandas", "dataframe" ]
pandas: dataframe from dict with comma separated values
39,193,110
<p>I'm trying to create a DataFrame from a nested dictionary, where the values are in comma separated strings.</p> <p>Each value is nested in a dict, such as:</p> <pre><code>dict = {"1":{ "event":"A, B, C"}, "2":{ "event":"D, B, A, C"}, "3":{ "event":"D, B, C"} ...
1
2016-08-28T15:56:58Z
39,193,945
<p>You can use a couple of comprehensions to massage the nested dict into a better format for creation of a DataFrame that flags if an entry for the column exists or not:</p> <pre><code>the_dict = {"1":{ "event":"A, B, C"}, "2":{ "event":"D, B, A, C"}, "3":{ "even...
2
2016-08-28T17:26:22Z
[ "python", "pandas", "dataframe" ]
how to find match first word in string with regex in python
39,193,133
<p>I want to match the word <code>'St' or 'St.' or 'st' or 'st.'</code> BUT only in first word of a string. For example ' St. Mary Church Church St.' - should find ONLY first St. </p> <ul> <li>'st. Mary Church Church St.' - should find ONLY 'st.' </li> <li>'st Mary Church Church St.' - should find ONLY 'st'</li> </ul>...
0
2016-08-28T15:58:59Z
39,193,245
<p>You don't need to use a regex for this, just use the <code>split()</code> method on your string to split it by whitespace. This will return a list of every word in your string:</p> <pre><code>matches = ["St", "St.", "st", "st."] name = "St. Mary Church Church St." words = name.split() #split the string into words...
1
2016-08-28T16:11:05Z
[ "python", "regex" ]
how to find match first word in string with regex in python
39,193,133
<p>I want to match the word <code>'St' or 'St.' or 'st' or 'st.'</code> BUT only in first word of a string. For example ' St. Mary Church Church St.' - should find ONLY first St. </p> <ul> <li>'st. Mary Church Church St.' - should find ONLY 'st.' </li> <li>'st Mary Church Church St.' - should find ONLY 'st'</li> </ul>...
0
2016-08-28T15:58:59Z
39,193,251
<pre><code>import re string = "Some text" replace = {'St': 'Saint', 'St.': 'Saint', 'st': 'Saint', 'st.': 'Saint'} replace = dict((re.escape(k), v) for k, v in replace.iteritems()) pattern = re.compile("|".join(replace.keys())) for text in string.split(): text = pattern.sub(lambda m: replace[re.escape(m.group(0))...
-1
2016-08-28T16:11:27Z
[ "python", "regex" ]
how to find match first word in string with regex in python
39,193,133
<p>I want to match the word <code>'St' or 'St.' or 'st' or 'st.'</code> BUT only in first word of a string. For example ' St. Mary Church Church St.' - should find ONLY first St. </p> <ul> <li>'st. Mary Church Church St.' - should find ONLY 'st.' </li> <li>'st Mary Church Church St.' - should find ONLY 'st'</li> </ul>...
0
2016-08-28T15:58:59Z
39,193,348
<p>Regex <code>sub</code> allows you to define the number of occurence to replace in a string. </p> <p>i.e. : </p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; s = "St. Mary Church Church St." &gt;&gt;&gt; new_s = re.sub(r'^(St.|st.|St|st)\s', r'Saint ', s, 1) # the last argument defines the number of occurrences t...
1
2016-08-28T16:21:59Z
[ "python", "regex" ]
how to find match first word in string with regex in python
39,193,133
<p>I want to match the word <code>'St' or 'St.' or 'st' or 'st.'</code> BUT only in first word of a string. For example ' St. Mary Church Church St.' - should find ONLY first St. </p> <ul> <li>'st. Mary Church Church St.' - should find ONLY 'st.' </li> <li>'st Mary Church Church St.' - should find ONLY 'st'</li> </ul>...
0
2016-08-28T15:58:59Z
39,193,434
<p>Try using the regex <code>'^\S+'</code> to match the first non-space character in your string.</p> <pre><code>import re s = 'st Mary Church Church St.' m = re.match(r'^\S+', s) m.group() # 'st' s = 'st. Mary Church Church St.' m = re.match(r'^\S+', s) m.group() # 'st.' </code></pre>
-1
2016-08-28T16:31:26Z
[ "python", "regex" ]
Splitting strings in python using import re
39,193,180
<p>Why does this work:</p> <pre><code>string = 'N{P}[ST]{P}' &gt;&gt;&gt; import re &gt;&gt;&gt; re.split(r"[\[\]]", string) &gt;&gt;&gt; ['N{P}', 'ST', '{P}'] </code></pre> <p>But this don't?</p> <pre><code>&gt;&gt;&gt; re.split(r"{\{\}}", string) </code></pre>
0
2016-08-28T16:03:52Z
39,193,221
<p>You have to do this:</p> <pre><code>re.split(r"[{}]", string) </code></pre> <p><code>r"{\{\}}"</code> is a special re syntax to repeat groups (ex: <code>(ab){1,3}</code> matches <code>ab</code>, <code>abab</code> or <code>ababab</code>) but not the character range (note that you don't have to escape the curly brac...
1
2016-08-28T16:08:14Z
[ "python", "regex" ]
Splitting strings in python using import re
39,193,180
<p>Why does this work:</p> <pre><code>string = 'N{P}[ST]{P}' &gt;&gt;&gt; import re &gt;&gt;&gt; re.split(r"[\[\]]", string) &gt;&gt;&gt; ['N{P}', 'ST', '{P}'] </code></pre> <p>But this don't?</p> <pre><code>&gt;&gt;&gt; re.split(r"{\{\}}", string) </code></pre>
0
2016-08-28T16:03:52Z
39,193,257
<p><code>{</code> and <code>}</code> are meta-characters in regular expressions and should be escaped or put into a character class<br> <code>{\{\}}</code> - means just escaped curly braces within unescaped </p>
0
2016-08-28T16:12:02Z
[ "python", "regex" ]
scrapy LxmlLinkExtractor to crawl relative urls
39,193,198
<p>I want to crawl all the relative urls under tag in <a href="http://news.qq.com/" rel="nofollow">http://news.qq.com/</a></p> <p>the code of mine is that:</p> <pre><code>import scrapy from scrapy.selector import Selector from homework.items import HomeworkItem from scrapy.contrib.spiders import CrawlSpider, Rule f...
1
2016-08-28T16:05:35Z
39,193,247
<p>You're subclassing <code>Spider</code>, but since you have <code>start_urls</code>, I think you meant to use <code>CrawlSpider</code>. In this case, you need to revise your structure, since <code>parse</code> is actually used internally by <code>CrawlSpider</code> to find new links to crawl:</p> <pre><code>rules = ...
0
2016-08-28T16:11:10Z
[ "python", "scrapy", "web-crawler" ]
scrapy LxmlLinkExtractor to crawl relative urls
39,193,198
<p>I want to crawl all the relative urls under tag in <a href="http://news.qq.com/" rel="nofollow">http://news.qq.com/</a></p> <p>the code of mine is that:</p> <pre><code>import scrapy from scrapy.selector import Selector from homework.items import HomeworkItem from scrapy.contrib.spiders import CrawlSpider, Rule f...
1
2016-08-28T16:05:35Z
39,203,066
<p>First thing you are either using an outdate scrapy version or having bad imports since right now scrapy has only 1 type of link extractors - LinkExtractor (which is renamed LxmlExtractor)</p> <p>I've tested this and it works perfectly fine:</p> <pre><code>$ scrapy shell 'http://news.qq.com/' from scrapy.linkextrac...
0
2016-08-29T09:40:54Z
[ "python", "scrapy", "web-crawler" ]
Get first letter with maximum occurence of a string
39,193,241
<p>I would like to get the first letter with the maximum occurence of a string.</p> <p>For instance:</p> <pre><code> "google" -&gt; g "azerty" -&gt; a "bbbaaa" -&gt; b </code></pre> <p>I already have a working code, using <a href="https://docs.python.org/3/library/collections.html#collections.Counter">OrdererD...
6
2016-08-28T16:10:42Z
39,193,335
<p>The documentation for <code>collections.OrderedDict</code> actually has <a href="https://docs.python.org/3/library/collections.html#ordereddict-examples-and-recipes">a recipe for an <code>OrderedCounter</code></a>:</p> <pre><code>In [5]: from collections import Counter, OrderedDict In [6]: class OrderedCounter(Cou...
6
2016-08-28T16:20:46Z
[ "python", "string", "python-3.x", "dictionary" ]
Get first letter with maximum occurence of a string
39,193,241
<p>I would like to get the first letter with the maximum occurence of a string.</p> <p>For instance:</p> <pre><code> "google" -&gt; g "azerty" -&gt; a "bbbaaa" -&gt; b </code></pre> <p>I already have a working code, using <a href="https://docs.python.org/3/library/collections.html#collections.Counter">OrdererD...
6
2016-08-28T16:10:42Z
39,193,379
<p>Probably not very fast, but one-liner!</p> <pre><code>&gt;&gt;&gt; s = "aaabbbbc" &gt;&gt;&gt; sorted(s, key=lambda c: (-s.count(c), s.index(c)))[0] 'b' </code></pre> <p><strong>Edit</strong></p> <p>Even shorter, thanks to @Ohad Eytan's comment:</p> <pre><code>&gt;&gt;&gt; min(s, key=lambda c: (-s.count(c), s.in...
5
2016-08-28T16:25:35Z
[ "python", "string", "python-3.x", "dictionary" ]
Get first letter with maximum occurence of a string
39,193,241
<p>I would like to get the first letter with the maximum occurence of a string.</p> <p>For instance:</p> <pre><code> "google" -&gt; g "azerty" -&gt; a "bbbaaa" -&gt; b </code></pre> <p>I already have a working code, using <a href="https://docs.python.org/3/library/collections.html#collections.Counter">OrdererD...
6
2016-08-28T16:10:42Z
39,193,424
<p>You can use <code>Counter()</code> together with <code>next()</code> to find the first letter that meets the condition:</p> <pre><code>&gt;&gt;&gt; s = "google" &gt;&gt;&gt; c = Counter(s) &gt;&gt;&gt; next(x for x in s if c[x] == c.most_common(1)[0][1]) 'g' </code></pre>
2
2016-08-28T16:30:41Z
[ "python", "string", "python-3.x", "dictionary" ]
Get first letter with maximum occurence of a string
39,193,241
<p>I would like to get the first letter with the maximum occurence of a string.</p> <p>For instance:</p> <pre><code> "google" -&gt; g "azerty" -&gt; a "bbbaaa" -&gt; b </code></pre> <p>I already have a working code, using <a href="https://docs.python.org/3/library/collections.html#collections.Counter">OrdererD...
6
2016-08-28T16:10:42Z
39,193,439
<p>You can also fix the issue you describe at the end of your question about using Counter by having the resulting list sorted by various attributes: firstly count, secondly lexicographical order like this:</p> <pre><code>from collections import Counter sentence = "google" c = Counter(sentence) print(sorted(c.most_c...
1
2016-08-28T16:31:49Z
[ "python", "string", "python-3.x", "dictionary" ]
Get first letter with maximum occurence of a string
39,193,241
<p>I would like to get the first letter with the maximum occurence of a string.</p> <p>For instance:</p> <pre><code> "google" -&gt; g "azerty" -&gt; a "bbbaaa" -&gt; b </code></pre> <p>I already have a working code, using <a href="https://docs.python.org/3/library/collections.html#collections.Counter">OrdererD...
6
2016-08-28T16:10:42Z
39,193,896
<p>I am aware that you want a one-liner, but what if you had to repeat this task many times or handle really long sentences? I don't know the exact use case here but it could be worth your time considering the space and time complexity of the algorithm.</p> <p>In your solution, for example, you are iterating through t...
3
2016-08-28T17:19:59Z
[ "python", "string", "python-3.x", "dictionary" ]
Log in to ASP website using Python's Requests module
39,193,278
<p>Im trying to webscrap some information from my school page, but im having hard time to get past login. I know there are similar threeds, i have spend whole day reading, but cannot make it work. </p> <p>This is program im using (User name and password were changed):</p> <pre><code>import requests payload = {'ctl00...
0
2016-08-28T16:14:41Z
39,204,230
<p>First off, you are not using a <a href="http://docs.python-requests.org/en/master/user/advanced/#session-objects" rel="nofollow">Session</a> so even if your first post successfully logs you on the second knows nothing about it. Second, you are missing data that needs to be posted, <em>__VIEWSTATEGENERATOR</em> and ...
0
2016-08-29T10:39:21Z
[ "python", "asp.net", "login", "web-scraping", "python-requests" ]
How to get top of keys from dict by values?
39,193,279
<p>I have dictionary:</p> <pre><code>{ "key1" : 1, "key2" : 2, ...., "key100" : 100 } </code></pre> <p>I want to get list top5 keys by sort values from this dictionary:</p> <pre><code>[ "key100", "key99",.. "key95" ] </code></pre> <p>How to do it ?</p>
0
2016-08-28T16:14:41Z
39,193,322
<p>Just sort keys using lambda function to return value as key, reversed, and take the 5 first values:</p> <pre><code>d={ "key1" : 1, "key2" : 2, "key3" : 3, "key200" : 200 , "key100" : 100 , "key400" : 400} print(sorted(d.keys(),reverse=True,key=lambda x : d[x] )[:5]) </code></pre> <p>output:</p> <pre><code>['key...
4
2016-08-28T16:19:16Z
[ "python" ]
How to get top of keys from dict by values?
39,193,279
<p>I have dictionary:</p> <pre><code>{ "key1" : 1, "key2" : 2, ...., "key100" : 100 } </code></pre> <p>I want to get list top5 keys by sort values from this dictionary:</p> <pre><code>[ "key100", "key99",.. "key95" ] </code></pre> <p>How to do it ?</p>
0
2016-08-28T16:14:41Z
39,193,400
<pre><code>d = { "key1" : 1, "key2" : 2, ...., "key100" : 100 } a = sorted(d.values()) a.reverse() req_list = [] for i in a[:5]: req_list.append(d.keys()[d.values().index(i)]) print req_list </code></pre> <p>This would give you the list with greatest 5 values. Is this what you wanted?</p>
0
2016-08-28T16:27:47Z
[ "python" ]
How to get top of keys from dict by values?
39,193,279
<p>I have dictionary:</p> <pre><code>{ "key1" : 1, "key2" : 2, ...., "key100" : 100 } </code></pre> <p>I want to get list top5 keys by sort values from this dictionary:</p> <pre><code>[ "key100", "key99",.. "key95" ] </code></pre> <p>How to do it ?</p>
0
2016-08-28T16:14:41Z
39,193,657
<pre><code>Python 2.7.10 (default, Oct 23 2015, 19:19:21) &gt;&gt;&gt; d = {"key1": 1, "key2": 2, "key3": 3, "key98": 98 , "key99": 99 , "key100": 100} &gt;&gt;&gt; sorted(d, reverse=True, key=d.get)[:3] ['key100', 'key99', 'key98'] </code></pre>
0
2016-08-28T16:53:24Z
[ "python" ]
How To Open A Custom File Extension as .txt Using Python
39,193,307
<p>I'm making a code that will create a new form of file extension (in this case .aobj, which will be used to help me make games easier). I tried using the code below (this is using Python)</p> <pre><code>print "Starting..." info = [] part1 = open('temporary.aobj', 'r') part2 = part1.readlines() for line in part2: ...
0
2016-08-28T16:17:49Z
39,193,387
<p>You are printing info, which is an object somewhat similar to nested list. </p> <pre><code>a = [[1,2],[3,4]] print (a) </code></pre> <p>This prints<br> [[1, 2], [3, 4]]</p> <pre><code>for i in a: print(i) </code></pre> <p>This prints <br> [1, 2] [3, 4]</p> <pre><code>for i in a: for j in i: ...
0
2016-08-28T16:26:36Z
[ "python", "file" ]
How To Open A Custom File Extension as .txt Using Python
39,193,307
<p>I'm making a code that will create a new form of file extension (in this case .aobj, which will be used to help me make games easier). I tried using the code below (this is using Python)</p> <pre><code>print "Starting..." info = [] part1 = open('temporary.aobj', 'r') part2 = part1.readlines() for line in part2: ...
0
2016-08-28T16:17:49Z
39,194,417
<p>I was experimenting and found out that it would allow you to read the format properly as long as you wrote the info using python's write() function. As so:</p> <pre><code>file = open('temporary.aobj', 'r+') file.write('foo') info = file.readlines() lines = [] for line in info: lines.append(line) print lines </c...
0
2016-08-28T18:21:33Z
[ "python", "file" ]
How to extract content between a prefix and a suffix?
39,193,338
<p>I want to extract text from {inside} the curly brackets. The differences between those texts are the prefixes, such as <code>\section{</code> or <code>\subsection{</code> to categorize everything accordingly. And every end needs to be set by the next closed curly bracket <code>}</code>.</p> <pre><code>file = "This ...
0
2016-08-28T16:20:51Z
39,193,922
<p>I think you want to use the regular expression module. </p> <pre><code>import re s = "This is a string of an \section{example file} used for \subsection{Latex} documents." pattern = re.compile(r'\\(?:sub)?section\{(.*?)\}') re.findall(pattern, s) #output: ['example file', 'Latex'] </code></pre>
0
2016-08-28T17:23:46Z
[ "python", "latex" ]
How to extract content between a prefix and a suffix?
39,193,338
<p>I want to extract text from {inside} the curly brackets. The differences between those texts are the prefixes, such as <code>\section{</code> or <code>\subsection{</code> to categorize everything accordingly. And every end needs to be set by the next closed curly bracket <code>}</code>.</p> <pre><code>file = "This ...
0
2016-08-28T16:20:51Z
39,194,739
<p>If you just want the pairs <code>(section-level, title)</code> for all the file you can use a simple regex:</p> <pre><code>import re codewords = [ 'section', 'subsection', # add other here if you want to ] regex = re.compile(r'\\({})\{{([^}}]+)\}}'.format('|'.join(re.escape(word) for word in codewords...
0
2016-08-28T18:56:57Z
[ "python", "latex" ]
Assistance with Python regex
39,193,354
<p>I have the following strings.</p> <p>Example:</p> <ul> <li>12 CG GRB</li> <li>6GRC 11.2 MK</li> <li>2 GR 1.75LRG</li> </ul> <p>And I would like to break them to the following group</p> <ul> <li>[12,CG] [GRB]</li> <li>[6,GRC] [11.2,MK]</li> <li>[2,GR] [1.75,LRG]</li> </ul> <p>I'm using this regex - (\d+.?\d*).*?...
0
2016-08-28T16:22:31Z
39,193,452
<p>You may replace the <code>.*?</code> with a <code>\s*</code> to match zero or more whitespasces, and make the first capture group optional:</p> <pre><code>(\d*\.?\d+)?\s*([A-Z]+) ^^^^ </code></pre> <p>See the <a href="https://regex101.com/r/tK3tL1/1" rel="nofollow">regex demo</a>.</p> <p>Note I also mo...
0
2016-08-28T16:32:47Z
[ "python", "regex" ]
Assistance with Python regex
39,193,354
<p>I have the following strings.</p> <p>Example:</p> <ul> <li>12 CG GRB</li> <li>6GRC 11.2 MK</li> <li>2 GR 1.75LRG</li> </ul> <p>And I would like to break them to the following group</p> <ul> <li>[12,CG] [GRB]</li> <li>[6,GRC] [11.2,MK]</li> <li>[2,GR] [1.75,LRG]</li> </ul> <p>I'm using this regex - (\d+.?\d*).*?...
0
2016-08-28T16:22:31Z
39,208,915
<pre><code>s = "12 CG GRB\n6GRC 11.2 MK\n2 GR 1.75LRG" re.split(r"(?&lt;!\d)\s", s) </code></pre> <p>The output is:</p> <pre><code>['12 CG', 'GRB', '6GRC', '11.2 MK', '2 GR', '1.75LRG'] </code></pre>
0
2016-08-29T14:39:15Z
[ "python", "regex" ]
Py_InitModule copies the name but not the function pointer?
39,193,366
<p>When I register callbacks using <code>Py_InitModule</code>, and if I later change the function pointer in the structure to point to a new function, the new function is called. But if I change the name, the new name is not recognized.</p> <pre><code>#include &lt;Python.h&gt; PyObject* foo1(PyObject *self, PyObject ...
1
2016-08-28T16:23:44Z
39,193,891
<p>The inconsistency you see arises from the difference between a function's code, which is the property of the function itself, and the name by which it is invoked from a module, which is the property of the module (key in its dict). While a function's name is also stored in the function object, it is only used for <c...
2
2016-08-28T17:19:07Z
[ "python", "c++", "python-embedding" ]
Merge counter.items() dictionaries into one dictionary
39,193,519
<p>How do I get the output of this code into one dictionary with total number of key:value pairs?</p> <pre><code>import re from collections import Counter splitfirst = open('output.txt', 'r') input = splitfirst.read() output = re.split('\n', input) for line in output: counter = Counter(line) ab = counter.ite...
1
2016-08-28T16:40:18Z
39,193,551
<p>The <code>+</code> operator merges counters:</p> <pre><code>&gt;&gt;&gt; Counter('hello') + Counter('world') Counter({'l': 3, 'o': 2, 'e': 1, 'r': 1, 'h': 1, 'd': 1, 'w': 1}) </code></pre> <p>so you can use <code>sum</code> to combine a collection of them:</p> <pre><code>from collections import Counter with open...
1
2016-08-28T16:43:43Z
[ "python", "python-2.7", "dictionary", "merge", "counter" ]
Merge counter.items() dictionaries into one dictionary
39,193,519
<p>How do I get the output of this code into one dictionary with total number of key:value pairs?</p> <pre><code>import re from collections import Counter splitfirst = open('output.txt', 'r') input = splitfirst.read() output = re.split('\n', input) for line in output: counter = Counter(line) ab = counter.ite...
1
2016-08-28T16:40:18Z
39,193,680
<p>Here's a <a href="http://stackoverflow.com/help/mcve">mcve</a> of your problem:</p> <pre><code>import re from collections import Counter data = """this is the first line this is the second one this is the last one """ output = Counter() for line in re.split('\n', data): output += Counter(line) print output <...
0
2016-08-28T16:57:21Z
[ "python", "python-2.7", "dictionary", "merge", "counter" ]
How to create a dynamic SQL query
39,193,527
<p>I have a large sqlite table of 33k records (movies) . I want to give the user the ability to search in that table via filters . Each movie record has 10 fields : Actors, Directors, Runtime, Genre, Rating and few more . The only filters available for the user to use are people (Include Actors and Directors), Genre, R...
0
2016-08-28T16:40:55Z
39,193,642
<p>If you're given a list of filters, you can just apply <code>Query.filter_by()</code> or <code>Query.filter()</code> over and over:</p> <pre><code>filters = [ ('rating', 3), ('runtime', 90), ('genre', 'documentary') ] query = session.query(Movie) for column, value in filters: # Make sure `column` a...
2
2016-08-28T16:52:10Z
[ "python", "sql", "sqlalchemy", "flask-sqlalchemy" ]
Make image to use it like character in pygame
39,193,549
<p>I'm beginner with using pygame but i saw a website that provide a tutorial and he used character in the program </p> <p>here it is <a href="http://i.stack.imgur.com/lKN08.png" rel="nofollow"><img src="http://i.stack.imgur.com/lKN08.png" alt="enter image description here"></a> </p> <p>so my question is can i make a...
-7
2016-08-28T16:43:27Z
39,196,738
<p>Your question is vague: Do you want to MAKE a character or make an image BEHAVE like a character?</p> <p><strong>If you wanted to make a character</strong><br> If you wanted to make a character, I suggest going to <a href="http://pixelartor.com/" rel="nofollow">PixelArtor</a> and choosing the file size you want. I ...
0
2016-08-28T23:31:43Z
[ "python", "python-2.7", "pygame" ]
Object Persistence in SqlAlchemy - Adding Self to a database
39,193,592
<p>I have an object which I am trying to add persistence to using sqlalchemy to allow for a local lookup of the object if I've already created an instance of it before. Within the init statement for the object, I have the following code:</p> <pre><code>persistent = session.query(exists().where(myobject.myfield==self.m...
0
2016-08-28T16:47:55Z
39,194,703
<p>Take a look at signature of <a href="http://docs.sqlalchemy.org/en/latest/orm/session_api.html#sqlalchemy.orm.session.Session.add" rel="nofollow"><code>session.add</code></a> method:</p> <pre><code>add(instance, _warn=True) </code></pre> <p>As you can see, you need to pass instance of class that you want to store....
1
2016-08-28T18:52:40Z
[ "python", "sqlalchemy" ]
GAE Python: How to use NDB KeyProperty models for many-to-one relationship?
39,193,684
<p>There are posts on how to <a href="http://stackoverflow.com/questions/14192331/how-to-set-an-ndb-keyproperty">set</a>, <a href="http://stackoverflow.com/questions/19868410/how-do-i-use-ndb-keyproperty-properly-in-this-situation">get</a>, <a href="http://stackoverflow.com/questions/14072491/app-engine-structured-prop...
1
2016-08-28T16:57:31Z
39,210,503
<p>According to the documentation (<a href="https://cloud.google.com/appengine/docs/python/datastore/entities" rel="nofollow">https://cloud.google.com/appengine/docs/python/datastore/entities</a>), "The Datastore API does not distinguish between creating a new entity and updating an existing one". That is, the put() me...
1
2016-08-29T16:01:57Z
[ "python", "google-app-engine" ]
I can't able to install gunicorn whitenoise in heroku
39,193,716
<p>I'm trying to deploy my <code>python-django website on heroku</code> .I used the command </p> <pre><code>(firstproject) $ pip install dj-database-url gunicorn whitenoise </code></pre> <p>I got an error like this</p> <pre><code>Requirement already satisfied (use --upgrade to upgrade): dj-database-url in /home/apar...
0
2016-08-28T17:01:37Z
39,194,127
<p>The error message is saying that you typed <code>whitenose</code> rather than <code>whitenoise</code>.</p>
0
2016-08-28T17:45:35Z
[ "python", "django", "heroku" ]
Python create indented string from a list
39,193,735
<p>I have a list of table of contents that I'd like to create into an indented string</p> <pre><code>list = ['1. Section', '1.1 Subsection', '1.1.1 Subsubsection', '1.1.2 Subsubsection', '2. Section', '2.1 Subsection', '2.1.1 Subsubsection', '2.1.2 Subsubsection', '2.2 Subsection', '2.2.1 Subsubsection'] </code></pre>...
2
2016-08-28T17:03:17Z
39,193,785
<p>Reverse the order of <code>if re.match(...)</code> statements. All of your items pass the first test so the code never enters elif block.</p>
1
2016-08-28T17:08:52Z
[ "python" ]
Python create indented string from a list
39,193,735
<p>I have a list of table of contents that I'd like to create into an indented string</p> <pre><code>list = ['1. Section', '1.1 Subsection', '1.1.1 Subsubsection', '1.1.2 Subsubsection', '2. Section', '2.1 Subsection', '2.1.1 Subsubsection', '2.1.2 Subsubsection', '2.2 Subsection', '2.2.1 Subsubsection'] </code></pre>...
2
2016-08-28T17:03:17Z
39,193,798
<p>Try this:</p> <pre><code>toc = '' for tocitem in list: if re.match('(\d+)\.(\d+)\.', tocitem): toc += '\t\t' + tocitem + '\n' elif re.match('(\d+)\.(\d+)', tocitem): toc += '\t' + tocitem + '\n' else: toc +=tocitem + '\n' </code></pre>
1
2016-08-28T17:09:50Z
[ "python" ]
Python create indented string from a list
39,193,735
<p>I have a list of table of contents that I'd like to create into an indented string</p> <pre><code>list = ['1. Section', '1.1 Subsection', '1.1.1 Subsubsection', '1.1.2 Subsubsection', '2. Section', '2.1 Subsection', '2.1.1 Subsubsection', '2.1.2 Subsubsection', '2.2 Subsection', '2.2.1 Subsubsection'] </code></pre>...
2
2016-08-28T17:03:17Z
39,193,805
<p>First, I use <code>lst</code> instead of <code>list</code>, because <code>list</code> is a function...</p> <p>Next, for this to work you need to match first the longest<br> series of numbers, then work down to the shortest one.</p> <pre><code>toc = '' for tocitem in lst: if re.match('(\d+)\.(\d+)\.(\d+)', toc...
1
2016-08-28T17:10:13Z
[ "python" ]
Python create indented string from a list
39,193,735
<p>I have a list of table of contents that I'd like to create into an indented string</p> <pre><code>list = ['1. Section', '1.1 Subsection', '1.1.1 Subsubsection', '1.1.2 Subsubsection', '2. Section', '2.1 Subsection', '2.1.1 Subsubsection', '2.1.2 Subsubsection', '2.2 Subsection', '2.2.1 Subsubsection'] </code></pre>...
2
2016-08-28T17:03:17Z
39,193,871
<p>The first if-condition matches also the other cases. So you have to switch the order, or make a more general approach:</p> <pre><code>toc = '' for tocitem in list: number = tocitem.split()[0] toc += '\t' * number.strip('.').count('.') + tocitem + '\n' </code></pre>
1
2016-08-28T17:17:12Z
[ "python" ]
Python create indented string from a list
39,193,735
<p>I have a list of table of contents that I'd like to create into an indented string</p> <pre><code>list = ['1. Section', '1.1 Subsection', '1.1.1 Subsubsection', '1.1.2 Subsubsection', '2. Section', '2.1 Subsection', '2.1.1 Subsubsection', '2.1.2 Subsubsection', '2.2 Subsection', '2.2.1 Subsubsection'] </code></pre>...
2
2016-08-28T17:03:17Z
39,193,946
<p>Really interesting question! here's a possible solution which assumes your data isn't sorted.</p> <p><strong>python 2.x</strong>:</p> <pre><code>import re import random # Unordered data!!! lst = ['1. Section', '1.1 Subsection', '1.1.1 Subsubsection', '1.1.2 Subsubsection', '2. Section', '2.1 Subsection', '...
1
2016-08-28T17:26:23Z
[ "python" ]
Python create indented string from a list
39,193,735
<p>I have a list of table of contents that I'd like to create into an indented string</p> <pre><code>list = ['1. Section', '1.1 Subsection', '1.1.1 Subsubsection', '1.1.2 Subsubsection', '2. Section', '2.1 Subsection', '2.1.1 Subsubsection', '2.1.2 Subsubsection', '2.2 Subsection', '2.2.1 Subsubsection'] </code></pre>...
2
2016-08-28T17:03:17Z
39,194,002
<p>Given the sorted list with section titles:</p> <pre><code>li = ['1. Section', '1.1 Subsection', '1.1.1 Subsubsection', '1.1.2 Subsubsection', '2. Section', '2.1 Subsection', '2.1.1 Subsubsection', '2.1.2 Subsubsection', '2.2 Subsection', '2.2.1 Subsubsection'] </code></pre> <p>You can do:</p> <pre><code>print '\n...
1
2016-08-28T17:31:54Z
[ "python" ]
Derivative of summations
39,193,771
<p>I am using sympy from time to time, but am not very good at it. At the moment I am stuck with defining a list of indexed variables, i.e. n1 to nmax and performing a summation on it. Then I want to be able to take the derivative:</p> <p>So far I tried the following:</p> <pre><code>numSpecies = 10 n = IndexedBase('n...
8
2016-08-28T17:06:58Z
39,193,990
<p>I don't know why the <code>IndexedBase</code> approach does not work (I would be interested to know also). You can, however, do the following:</p> <pre><code>import sympy as sp numSpecies = 10 n = sp.symbols('n0:%d'%numSpecies) # note that n equals the tuple (n0, n1, ..., n9) ntot = sum(n) # sum elements ...
1
2016-08-28T17:30:46Z
[ "python", "sympy", "derivative" ]
Derivative of summations
39,193,771
<p>I am using sympy from time to time, but am not very good at it. At the moment I am stuck with defining a list of indexed variables, i.e. n1 to nmax and performing a summation on it. Then I want to be able to take the derivative:</p> <p>So far I tried the following:</p> <pre><code>numSpecies = 10 n = IndexedBase('n...
8
2016-08-28T17:06:58Z
39,194,000
<p>I'm not clear about what you want to do. However, perhaps this will help. Edited in response to two comments received.</p> <pre><code>from sympy import * nspecies = 10 [var('n%s'%_) for _ in range(nspecies)] expr = sympify('+'.join(['n%s'%_ for _ in range(nspecies)])) expr print ( diff(expr,n1) ) expr = sympify(...
1
2016-08-28T17:31:39Z
[ "python", "sympy", "derivative" ]
Derivative of summations
39,193,771
<p>I am using sympy from time to time, but am not very good at it. At the moment I am stuck with defining a list of indexed variables, i.e. n1 to nmax and performing a summation on it. Then I want to be able to take the derivative:</p> <p>So far I tried the following:</p> <pre><code>numSpecies = 10 n = IndexedBase('n...
8
2016-08-28T17:06:58Z
39,202,749
<p>With SymPy's development version, your example works.</p> <p>To install SymPy's development version, just pull it down with <code>git</code>:</p> <pre><code>git clone git://github.com/sympy/sympy.git cd sympy </code></pre> <p>Then run python from that path or set the <code>PYTHONPATH</code> to include that direct...
4
2016-08-29T09:26:25Z
[ "python", "sympy", "derivative" ]
Tkinter .icursor(*arg) strange behaviour
39,193,794
<p>I'd like to create an Entry with Tkinter where the user can type its telephone number and the text dynamically changes in order that once finished it becomes like <code>+34 1234567890</code>.</p> <p>In my code the function <code>.icursor(n)</code>, used to set the cursor position, at first does not work properly, b...
1
2016-08-28T17:09:35Z
39,194,825
<p>The problem is that you're setting the cursor, but then the underlying widget sets the cursor the way it normally does. Because you're inserting characters into the widget in the middle of Tkinter processing a key press and release, it gets confused. For example, on the very first keystroke it thinks the cursor shou...
2
2016-08-28T19:06:24Z
[ "python", "python-2.7", "function", "tkinter", "cursor" ]
python beautifoulsoup wrong parsing table
39,193,837
<p>I tried to parse the table and write its data to csv, but <strong>beautifoulsoup</strong> <strong>doesn't parse</strong> the table correctly. This is the page: <a href="http://projects.fivethirtyeight.com/2016-election-forecast/arizona/" rel="nofollow">http://projects.fivethirtyeight.com/2016-election-forecast/arizo...
0
2016-08-28T17:12:58Z
39,208,741
<p>As you can see into the comments, I solved it extracting the <strong>json object</strong> <code>race.stateData</code> from the <strong>script</strong> tag using a regular expression. Data will be finally parsed.</p>
0
2016-08-29T14:30:32Z
[ "python", "html", "csv", "parsing", "beautifulsoup" ]
How to print the most times a char occurs from a counter in python
39,193,849
<pre><code>Counter(str) print max(Counter(str)) </code></pre> <p>When this prints, it will print the letter in the string that occurs the most, I want to print how many times it occurs not what letter. How do I go about doing this?</p>
1
2016-08-28T17:14:20Z
39,193,867
<p>The <code>collections.Counter</code> object already provides a method for this - <a href="https://docs.python.org/2/library/collections.html#collections.Counter.most_common" rel="nofollow"><code>most_common</code></a>:</p> <blockquote> <p>Return a list of the <code>n</code> most common elements and their counts f...
3
2016-08-28T17:16:36Z
[ "python", "counter" ]
How to print the most times a char occurs from a counter in python
39,193,849
<pre><code>Counter(str) print max(Counter(str)) </code></pre> <p>When this prints, it will print the letter in the string that occurs the most, I want to print how many times it occurs not what letter. How do I go about doing this?</p>
1
2016-08-28T17:14:20Z
39,193,906
<p>A counter behaves like a dictionary, so this works:</p> <pre><code>max(Counter(s).values()) </code></pre> <p>Comment: Don't use <code>str</code> as your variable, because<br> <code>str</code> is a type in Python.</p>
0
2016-08-28T17:21:22Z
[ "python", "counter" ]
Is there any practical use for the datetime.timezone class in Python 3 standard library?
39,193,888
<p>The documentation for the datetime.timezone class only says:</p> <blockquote> <p>A class that implements the tzinfo abstract base class as a fixed offset from the UTC.</p> </blockquote> <p>And it accepts a timedelta as its argument.</p> <p>I never saw an example using it directly from other's code snippets, a...
0
2016-08-28T17:18:55Z
39,194,593
<p>From the <a href="https://docs.python.org/3/library/datetime.html#datetime.timezone" rel="nofollow">Python 3 documentation</a>:</p> <blockquote> <p>The datetime module supplies a simple concrete subclass of tzinfo, timezone, which can represent timezones with fixed offset from UTC such as UTC itself or North ...
0
2016-08-28T18:40:28Z
[ "python", "datetime", "timezone", "standard-library", "pytz" ]
python selenium how to get link from google
39,193,913
<p>How do I get a link from Google? I tried the following ways, but none of them worked:</p> <ol> <li><code>find_elements_by_xpath("//*[@class='r']/@href")</code></li> <li><code>driver.find_element_by_xpath("//a").get_attribute("href")</code></li> <li><code>driver.find_element_by_xpath("//a").get_attribute(("href")[2]...
0
2016-08-28T17:21:51Z
39,194,385
<p>You maye have multiple issues here: First and third options are a not a valid xpath. Second options may find more than one matches, so it will return the first that fits, which is not necessarily the one you want. So I suggest:</p> <ol> <li><p>Make <em>find</em> specific enough to locate a proper element. I'd sugge...
0
2016-08-28T18:16:54Z
[ "python", "selenium" ]
How to sum list of tuples?
39,193,920
<p>I have a list of tuples:</p> <pre><code>[ (a,1), (a,2), (b,1), (b,3) ] </code></pre> <p>I want to get the sum of both the <code>a</code> and <code>b</code> values. The results should be in this format:</p> <pre><code>[ { 'key' : a, 'value' : 3 }, {'key' : b, 'value' : 4 } ] </code></pre> <p>How can I do this?</p...
0
2016-08-28T17:23:28Z
39,193,993
<pre><code>from itertools import groupby [{'key': k, 'value': sum(v for _,v in g)} for k, g in groupby(sorted(lst), key = lambda x: x[0])] # [{'key': 'a', 'value': 3}, {'key': 'b', 'value': 4}] </code></pre>
1
2016-08-28T17:31:05Z
[ "python" ]
How to sum list of tuples?
39,193,920
<p>I have a list of tuples:</p> <pre><code>[ (a,1), (a,2), (b,1), (b,3) ] </code></pre> <p>I want to get the sum of both the <code>a</code> and <code>b</code> values. The results should be in this format:</p> <pre><code>[ { 'key' : a, 'value' : 3 }, {'key' : b, 'value' : 4 } ] </code></pre> <p>How can I do this?</p...
0
2016-08-28T17:23:28Z
39,194,004
<pre><code>from collections import defaultdict lst = [("a", 1), ("a", 2), ("b", 1), ("b", 3)] out = defaultdict(list) [out[v[0]].append(v[1]) for v in lst] out = [{"key": k, "value": sum(v)} for k, v in out.iteritems()] print out </code></pre>
1
2016-08-28T17:32:04Z
[ "python" ]
How to sum list of tuples?
39,193,920
<p>I have a list of tuples:</p> <pre><code>[ (a,1), (a,2), (b,1), (b,3) ] </code></pre> <p>I want to get the sum of both the <code>a</code> and <code>b</code> values. The results should be in this format:</p> <pre><code>[ { 'key' : a, 'value' : 3 }, {'key' : b, 'value' : 4 } ] </code></pre> <p>How can I do this?</p...
0
2016-08-28T17:23:28Z
39,194,026
<pre><code>from collections import Counter a = [('a', 1), ('a', 2), ('b', 1), ('b', 3)] c = Counter() for tup in a: c = c + Counter(dict([tup])) </code></pre>
0
2016-08-28T17:34:12Z
[ "python" ]
How to sum list of tuples?
39,193,920
<p>I have a list of tuples:</p> <pre><code>[ (a,1), (a,2), (b,1), (b,3) ] </code></pre> <p>I want to get the sum of both the <code>a</code> and <code>b</code> values. The results should be in this format:</p> <pre><code>[ { 'key' : a, 'value' : 3 }, {'key' : b, 'value' : 4 } ] </code></pre> <p>How can I do this?</p...
0
2016-08-28T17:23:28Z
39,194,134
<p>You can use <a href="https://docs.python.org/2/library/collections.html#collections.Counter" rel="nofollow"><code>collections.Counter</code></a> to create a <a href="https://en.wikipedia.org/wiki/Multiset" rel="nofollow"><em>multiset</em></a> from the initial list and then modify the result to match your case:</p> ...
0
2016-08-28T17:46:11Z
[ "python" ]
How to sum list of tuples?
39,193,920
<p>I have a list of tuples:</p> <pre><code>[ (a,1), (a,2), (b,1), (b,3) ] </code></pre> <p>I want to get the sum of both the <code>a</code> and <code>b</code> values. The results should be in this format:</p> <pre><code>[ { 'key' : a, 'value' : 3 }, {'key' : b, 'value' : 4 } ] </code></pre> <p>How can I do this?</p...
0
2016-08-28T17:23:28Z
39,194,470
<p>Very similar to answers given already. Little bit longer, but easier to read, IMHO.</p> <pre><code>from collections import defaultdict lst = [('a', 1), ('a', 2), ('b', 1), ('b', 3)] dd = defaultdict(int) for name, value in lst: dd[name] += value final = [{'key': k, 'value': v} for k, v in dd.items()] </code...
0
2016-08-28T18:26:22Z
[ "python" ]
Using %systemdrive% in python
39,193,953
<p>I would like to open and work with a file with Python however I would like to use Windows <code>%systemdrive%</code> when referring to a file instead of full path. This piece of code works:</p> <pre><code>if not os.path.isfile('C:\\Work\\test\sample.txt'): </code></pre> <p>This does not:</p> <pre><code>if not os...
0
2016-08-28T17:27:14Z
39,194,118
<p>You can use <a href="https://docs.python.org/3.6/library/os.html?highlight=environment#os.environ" rel="nofollow">os.environ</a></p> <pre><code>import os import os.path fn = r'{0}\Work\test\sample.txt'.format( os.environ['systemdrive'] ) if not os.path.isfile(fn): ... </code></pre>
1
2016-08-28T17:44:23Z
[ "python", "windows" ]
Using %systemdrive% in python
39,193,953
<p>I would like to open and work with a file with Python however I would like to use Windows <code>%systemdrive%</code> when referring to a file instead of full path. This piece of code works:</p> <pre><code>if not os.path.isfile('C:\\Work\\test\sample.txt'): </code></pre> <p>This does not:</p> <pre><code>if not os...
0
2016-08-28T17:27:14Z
39,194,352
<p>There is a dedicated function for solving this problem named <a href="https://docs.python.org/2/library/os.path.html#os.path.expandvars" rel="nofollow"><code>os.path.expandvars</code></a>.</p> <blockquote> <p>Return the argument with environment variables expanded. Substrings of the form <code>$name</code> or <...
2
2016-08-28T18:12:49Z
[ "python", "windows" ]
Encoding for OrientDB (can't send a literal string)
39,193,957
<p>I have the next problem. I need to create a vertex with a propertyA with a value 'المساء'. The problem is from python, python CAN'T send the string 'المساء' so...</p> <p>I know I need to do a encode, like the next:</p> <pre><code>&gt;&gt;&gt;a = 'المساء' &gt;&gt;&gt;b = a.encode('cp270') &gt;&gt;...
0
2016-08-28T17:27:29Z
39,202,338
<p>I have tried with this code with orientDb version 2.2.7</p> <pre><code>import pyorient db_name='MyDb' print("connection to the server...") client=pyorient.OrientDB("localhost",2424) client.set_session_token(True) session_id=client.connect("root","root") client.db_open( db_name, "admin", "admin" ) myFunction = ...
0
2016-08-29T09:05:33Z
[ "python", "character-encoding", "orientdb" ]
Encoding for OrientDB (can't send a literal string)
39,193,957
<p>I have the next problem. I need to create a vertex with a propertyA with a value 'المساء'. The problem is from python, python CAN'T send the string 'المساء' so...</p> <p>I know I need to do a encode, like the next:</p> <pre><code>&gt;&gt;&gt;a = 'المساء' &gt;&gt;&gt;b = a.encode('cp270') &gt;&gt;...
0
2016-08-28T17:27:29Z
39,245,226
<p>Using python I can do this:</p> <pre><code>&gt;&gt;&gt; a = 'غريبديالى#مخيسةالعز' &gt;&gt;&gt; type(a) &lt;type 'str'&gt; &gt;&gt;&gt; b = a.decode('utf8') &gt;&gt;&gt; b u'\u063a\u0631\u064a\u0628\u062f\u064a\u0627\u0644\u0649#\u0645\u062e\u064a\u0633\u0629\u0627\u0644\u0639\u0632' &gt;&gt;&gt; p...
0
2016-08-31T09:04:47Z
[ "python", "character-encoding", "orientdb" ]
I am trying to understand class and function and can't seem to figure out what is wrong with my code
39,194,006
<p>Calculating the area of a triangle</p> <pre><code>class area: def traingle(self,height,length): self.height=height self.length=length def calculate(self,maths): self.maths= (self.height)*(self.length)*(0.5) def answer(self): print 'Hello, the aswer is %i'%self.maths f...
1
2016-08-28T17:32:15Z
39,194,065
<p>What about this?</p> <pre><code>import math class Triangle: def __init__(self, height, length): self.height = height self.length = length def calculate(self): return (self.height) * (self.length) * (0.5) def answer(self): print 'Hello, the aswer is %.2f' % self.calcu...
2
2016-08-28T17:38:31Z
[ "python", "oop" ]
Javascript is not recognizing a Flask variable
39,194,047
<p>I'm passing a set of variables into a Flask template, and I would like to first manipulate them with Javascript. The problem is that when I use the <code>{{ var }}</code> syntax, Javascript isn't recognizing it. <a href="http://i.stack.imgur.com/fLkdB.png" rel="nofollow">The errors look like this.</a> The left brack...
-1
2016-08-28T17:37:17Z
39,194,123
<p>Jinja2 (flask's templating engine) is a preprocessor, meaning that its output is the real JS and it does not care about you're using it with HTML, JS or whatever, it only prints text.</p> <p>That error you're getting is your text editor trying to help you but it's not smart enough to realize you're writing Jinja2 i...
1
2016-08-28T17:44:51Z
[ "javascript", "python", "flask" ]
How to get the image src data through beautifulsoup?
39,194,152
<p>I want to get the image src data of all <code>coming soon</code> movies from this link:- <a href="http://www.fandango.com/moviescomingsoon?GenreFilter=Drama" rel="nofollow">Fandango.com</a> </p> <p>This is the code:-</p> <pre><code>def poster(genre): poster_link = [] request = requests.get(http://www.f...
0
2016-08-28T17:48:40Z
39,194,327
<p>Try this. It shortcuts the subsetting and grabs all of the images that have the proper class.</p> <pre><code>def poster(genre): poster_link = [] request = requests.get('http://www.fandango.com/moviescomingsoon?GenreFilter=%s' %genre) content = request.content soup = BeautifulSoup(content, "html.par...
0
2016-08-28T18:09:52Z
[ "python", "beautifulsoup" ]
How to get the image src data through beautifulsoup?
39,194,152
<p>I want to get the image src data of all <code>coming soon</code> movies from this link:- <a href="http://www.fandango.com/moviescomingsoon?GenreFilter=Drama" rel="nofollow">Fandango.com</a> </p> <p>This is the code:-</p> <pre><code>def poster(genre): poster_link = [] request = requests.get(http://www.f...
0
2016-08-28T17:48:40Z
39,194,658
<p>James's answer is great but I noticed it grabs more than the images for that particular section - it grabs the 'New + Coming Soon' section for the bottom of the page too, which seems to be outside the scope of the genre and appears on other pages. This code restricts the image grab to just the genre-specific coming ...
0
2016-08-28T18:46:53Z
[ "python", "beautifulsoup" ]
assertRaises not catching Exception, even when function is passed as callable
39,194,226
<p>When I run the below unit test, I get the following output.</p> <pre><code> ====================================================================== ERROR: test_find_playlist_file_invalid (__main__.TestSpotifyScraperAPI) ---------------------------------------------------------------------- Traceback (most recent ...
0
2016-08-28T17:57:05Z
39,194,320
<p>Exception comes from constructor. To assert for it in unittest you may use <code>assertRaises</code> as context manager, and move constructor to context manager body.</p> <pre><code>class TestSpotifyScraperAPI(unittest.TestCase): def test_find_playlist_file_invalid(self): with self.assertRaises(OSError...
2
2016-08-28T18:08:55Z
[ "python", "python-3.x" ]
Why can't I see the arguments to the print function imported from future?
39,194,325
<p>I noticed that I cannot use flush with the new python function after I import it using <code>from __future__ import print_function</code>. In my journey to discover why I discovered I can't even inspect what arguments/parameters it takes. Why is it?</p> <ol> <li>First I made sure that the inspect function worked.</...
1
2016-08-28T18:09:40Z
39,194,404
<p>Extracted from <a href="https://funcsigs.readthedocs.io/en/0.3/#signature" rel="nofollow">signature</a>:</p> <blockquote> <p>Note</p> <p>Some callables may not be introspectable in certain implementations of Python. For example, in CPython, built-in functions defined in C provide no metadata about their ...
2
2016-08-28T18:19:36Z
[ "python", "python-2.7", "python-3.x", "printing" ]
Why can't I see the arguments to the print function imported from future?
39,194,325
<p>I noticed that I cannot use flush with the new python function after I import it using <code>from __future__ import print_function</code>. In my journey to discover why I discovered I can't even inspect what arguments/parameters it takes. Why is it?</p> <ol> <li>First I made sure that the inspect function worked.</...
1
2016-08-28T18:09:40Z
39,194,678
<p>The <code>flush</code> keyword was added to print() in 3.3.</p> <p>C functions do not normally carry with them the information needed for introspection. That is simply a fact of how C is defined and compiled. As a substitute, signatures were added to their docstrings. IDLE calltips fall back to the docstring if ...
1
2016-08-28T18:48:29Z
[ "python", "python-2.7", "python-3.x", "printing" ]
Adapting Tensorflow CIFAR10 model for own data
39,194,335
<p>I am just starting with tensorflow and I thought a good first step would be to adapt CIFAR10 model for my own use. My database are not images but signals and a whole database has a shape of <code>[16400,3000,1,1]</code> (dimensionwise: number of all samples, height, width and number of channels added on purpose). I ...
0
2016-08-28T18:11:02Z
39,194,665
<p>For the relatively small data set you want to work with, you might consider just loading it into a big numpy array, then iterating over it in mini-batches, which you feed to the computation graph via <code>tf.placeholder</code>s and the <code>feed_dict</code> mechanism.</p> <p>The mini-batch iteration could look so...
0
2016-08-28T18:47:16Z
[ "python", "tensorflow", "conv-neural-network" ]
Invert values of colour in CSS
39,194,402
<p>I have a CSS file where there are colours defined for certain elements. I want to invert the colours of these elements using some Python script. The format of colours are</p> <ul> <li>#XXX; or #XXX followed by space</li> <li>#XXXXXX; or #XXXXXX followed by space</li> </ul> <p>I am able to grab the pattern using fo...
0
2016-08-28T18:19:12Z
39,194,636
<p>I have some pretty basic code that can invert hex.</p> <pre><code># function takes in a hex color and outputs it inverted def invert(color_to_convert): table = string.maketrans('0123456789abcdef', 'fedcba9876543210') return '#' + color_to_convert[1:].lower().translate(table).upper() </code></pre> <p>Becau...
1
2016-08-28T18:44:56Z
[ "python", "css" ]
Extracting string from an HTML table from a given tab using Python
39,194,407
<p>I need to extract a string value from the HTML table below. I want to loop through the table from a particular tab, and copy the results horizontally into the command line or some file.</p> <p>I am pasting only one row of information here. This table gets updated based on the changes happening on the Gerrits. The ...
0
2016-08-28T18:20:22Z
39,195,825
<p>What stops you from leveraging BeautifulSoup for this?</p> <p>Lets say you have already read the html (using sgmllib or any other library) into a string variable named html_contents. Since you are not mentioning which column you want to get data from, I am extracting the gerrit number column.</p> <p>You can simpl...
0
2016-08-28T21:11:55Z
[ "python", "html", "parsing", "html-table" ]
timeout decorator in python through __init__ params
39,194,479
<p>I want to have a timeout for a function (rest API call) in python &amp; for that I am following <a href="http://stackoverflow.com/a/2282656/5582349">this</a> SO answer. </p> <p>I already have one existing code structure where i want to have a timeout decorator. I am defining a timeout seconds in ".txt" file &amp...
2
2016-08-28T18:27:36Z
39,194,566
<p>At <code>A</code> the <code>self</code> is not defined because the decorator is outside the method, but self only exists inside the method:</p> <pre><code>@timeout(self.timeout) # &lt;== A def bar(self,arg1,arg2,arg3): pass </code></pre> <p>You can try to set the <code>barTimeout</code> attribute at <code>_...
0
2016-08-28T18:37:16Z
[ "python", "python-2.7", "function", "timeout", "settimeout" ]
Posting Content to Friendica using Python
39,194,527
<p>I'm working on a project that is written in Python and needs to post updates to a Friendica server and interact using various APIs available. However, I have had very limited API usage experience and so I'm unsure of how to code this functionality in Python. There is an example on the Friendica GitHub however the Py...
1
2016-08-28T18:33:17Z
39,194,915
<p>According to the <a href="https://bitbucket.org/tobiasd/python-friendica/src/b0b75ae80a6e747e8724b1ae36972ebfd939beb5/friendica.py?fileviewer=file-view-default" rel="nofollow">source link</a> you posted, friendica uses https by default. Your successful curl request is using http.<br> Try instantiating friendica it ...
0
2016-08-28T19:17:52Z
[ "python", "api" ]