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 |
|---|---|---|---|---|---|---|---|---|---|
How to draw a heatmap in pandas with items that don't occur in both columns | 39,291,261 | <p>In <a href="http://stackoverflow.com/questions/39279858/how-to-draw-a-graphical-count-table-in-pandas">How to draw a graphical count table in pandas</a> I asked how to draw a heatmap from input data such as:</p>
<pre><code>customer1,customer2
a,b
a,c
a,c
b,a
b,c
b,c
c,c
a,a
b,c
b,c
</code></pre>
<p>The answer was<... | 0 | 2016-09-02T11:27:51Z | 39,291,743 | <p>Try this:</p>
<pre><code>In [129]: df
Out[129]:
customer1 customer2
0 a b
1 a c
2 a c
3 b b
4 b c
5 b c
6 c c
7 a b
8 b c
9 b c
In [130]: x = df.pivot_ta... | 1 | 2016-09-02T11:50:49Z | [
"python",
"pandas",
"seaborn"
] |
Is is possible to break in lambda when the expected result is found | 39,291,336 | <p>I am Python newbie, and just become very interested in Lambda expression. The problem I have is to find one and only one target element from a list of elements with lambda filter. In theory, when the target element is found there is no sense to continue anymore. </p>
<p>With <code>for loop</code> it is pretty simpl... | 4 | 2016-09-02T11:31:28Z | 39,291,614 | <p>From <a href="https://docs.python.org/3/library/functions.html#filter" rel="nofollow">https://docs.python.org/3/library/functions.html#filter</a></p>
<blockquote>
<p>Note that <code>filter(function, iterable)</code> is equivalent to the <strong>generator</strong>
expression <code>(item for item in iterable if f... | 1 | 2016-09-02T11:44:34Z | [
"python",
"loops",
"lambda"
] |
Is is possible to break in lambda when the expected result is found | 39,291,336 | <p>I am Python newbie, and just become very interested in Lambda expression. The problem I have is to find one and only one target element from a list of elements with lambda filter. In theory, when the target element is found there is no sense to continue anymore. </p>
<p>With <code>for loop</code> it is pretty simpl... | 4 | 2016-09-02T11:31:28Z | 39,292,696 | <p>with just lambdas is no possible, you need either use <a href="https://docs.python.org/3/library/functions.html#filter" rel="nofollow"><code>filter</code></a> (<a href="https://docs.python.org/2/library/itertools.html#itertools.ifilter" rel="nofollow"><code>itertools.ifilter</code></a> in python 2) or a conditional ... | 0 | 2016-09-02T12:40:45Z | [
"python",
"loops",
"lambda"
] |
Problems with Tkinter Canvas | 39,291,365 | <p>I'm doing some simple tasks to prepare myself for python on University I am going to attend but I ran into a problem.
When I ran my code for the first time, the tkinter window appeared and the image was drawn, but when I ran it for the second time, the tkinter window did not appear :(
This is the code: </p>
<pre>... | -1 | 2016-09-02T11:32:47Z | 39,300,500 | <p>I presume that the second 'first' should be 'second'. There are two other problems.</p>
<p>You did not say <em>how</em> you ran this either time. Exact details can be important.</p>
<p>You did not create and pass to Canvas an instance of tkinter.Tk. Instead, you relied on the default root mechanism. I consider... | 0 | 2016-09-02T20:47:52Z | [
"python",
"canvas",
"tkinter"
] |
Can I prevent a C++ dll from loading in Python Ctypes? | 39,291,466 | <p>I'd like to know if it's possible prevent or allow a dll to be loaded by python ctypes, based on whether a condition is true <strong>from within the dll.</strong></p>
<p><em>Some background:</em></p>
<p>My application uses various calculation algorithms, which I prototyped in Python, and then reimplemented in C++ ... | 0 | 2016-09-02T11:38:01Z | 39,291,567 | <p>Add <code>DllMain</code> function to your library.</p>
<blockquote>
<p>An optional entry point into a dynamic-link library (DLL). When the
system starts or terminates a process or thread, it calls the
entry-point function for each loaded DLL using the first thread of the
process. The system also calls the e... | 1 | 2016-09-02T11:42:37Z | [
"python",
"c++",
"c",
"dll",
"ctypes"
] |
How to one-hot-encode from a csv file input | 39,291,475 | <p>I have a csv file which I read in with</p>
<pre><code>import pandas
df = pd.read_csv("inputfile")
</code></pre>
<p>Some of the columns are numerical and some are strings. Let's call one of the numerical columns <code>'num'</code> and one of the string ones <code>'col'</code>. I would like do the following:</p>
<... | 2 | 2016-09-02T11:38:22Z | 39,308,115 | <p>Say you start with</p>
<pre><code>In [31]: df = pd.DataFrame({'col': ['foo', 'foo', 'bar', 'bar'], 'num': [1, 1, 3, 213]})
In [32]: df
Out[32]:
col num
0 foo 1
1 foo 1
2 bar 3
3 bar 213
</code></pre>
<p>First, let's take care of <code>col</code>:</p>
<p>If we define</p>
<pre><code>In [33]: d ... | 1 | 2016-09-03T14:39:34Z | [
"python",
"csv",
"pandas",
"scikit-learn"
] |
python shapely intersection function: clock-wise or counter-clock-wise | 39,291,481 | <p>I have used the Shapely polygon intersection function: </p>
<pre><code>object.intersection(other)
</code></pre>
<p>and get inconsistency in the direction and order of the vertices of the output polygon. </p>
<p>Is there a way to have a systematic set of outputs, or should I run through the output polygon and sort... | 0 | 2016-09-02T11:38:32Z | 39,291,987 | <p>You may get better answers on <a href="http://gis.stackexchange.com/">http://gis.stackexchange.com/</a> </p>
<p>Double check that you are using the right DE-9IM method. <a href="https://en.wikipedia.org/wiki/DE-9IM" rel="nofollow">DE-9IM Wikipedia</a> </p>
<p>If I understand you correctly with the systematic outpu... | 0 | 2016-09-02T12:03:20Z | [
"python",
"shapely"
] |
How to concatenate multiple column values into a single column in Panda dataframe | 39,291,499 | <p>This question is same to <a href="http://stackoverflow.com/questions/11858472/pandas-combine-string-and-int-columns">this posted</a> earlier. I want to concatenate three columns instead of concatenating two columns:</p>
<p>Here is the combining two columns:</p>
<pre><code>df = DataFrame({'foo':['a','b','c'], 'bar'... | 0 | 2016-09-02T11:39:33Z | 39,291,591 | <p>I think you are missing one <em>%s</em></p>
<pre><code>df['combined']=df.apply(lambda x:'%s_%s_%s' % (x['bar'],x['foo'],x['new']),axis=1)
</code></pre>
| 3 | 2016-09-02T11:43:28Z | [
"python",
"pandas",
"dataframe"
] |
How to concatenate multiple column values into a single column in Panda dataframe | 39,291,499 | <p>This question is same to <a href="http://stackoverflow.com/questions/11858472/pandas-combine-string-and-int-columns">this posted</a> earlier. I want to concatenate three columns instead of concatenating two columns:</p>
<p>Here is the combining two columns:</p>
<pre><code>df = DataFrame({'foo':['a','b','c'], 'bar'... | 0 | 2016-09-02T11:39:33Z | 39,291,596 | <p>you can simply do:</p>
<pre><code>In[17]:df['combined']=df['bar'].astype(str)+'_'+df['foo']+'_'+df['new']
In[17]:df
Out[18]:
bar foo new combined
0 1 a apple 1_a_apple
1 2 b banana 2_b_banana
2 3 c pear 3_c_pear
</code></pre>
| 3 | 2016-09-02T11:43:44Z | [
"python",
"pandas",
"dataframe"
] |
How to concatenate multiple column values into a single column in Panda dataframe | 39,291,499 | <p>This question is same to <a href="http://stackoverflow.com/questions/11858472/pandas-combine-string-and-int-columns">this posted</a> earlier. I want to concatenate three columns instead of concatenating two columns:</p>
<p>Here is the combining two columns:</p>
<pre><code>df = DataFrame({'foo':['a','b','c'], 'bar'... | 0 | 2016-09-02T11:39:33Z | 39,293,567 | <p>Just wanted to make a time comparison for both solutions (for 30K rows DF):</p>
<pre><code>In [1]: df = DataFrame({'foo':['a','b','c'], 'bar':[1, 2, 3], 'new':['apple', 'banana', 'pear']})
In [2]: big = pd.concat([df] * 10**4, ignore_index=True)
In [3]: big.shape
Out[3]: (30000, 3)
In [4]: %timeit big.apply(lamb... | 2 | 2016-09-02T13:24:17Z | [
"python",
"pandas",
"dataframe"
] |
Why "ImportError: No module named builtins" appears after importing hive from PyHive package? | 39,291,533 | <p>I have a simple question to ask. I have been trying to execute HIVE queries from Python using <a href="https://github.com/cloudera/impyla" rel="nofollow">impyla</a> package. But I stuck into <a href="http://stackoverflow.com/questions/35854145/impyla-hangs-when-connecting-to-hiveserver2">cursor problem</a>, already ... | 0 | 2016-09-02T11:41:00Z | 39,291,894 | <p>In python 3 the module <strong>builtin</strong> was renamed to builtins.</p>
<p>It is possible that you have installed a python 3 package and trying to run it with python 2</p>
| 0 | 2016-09-02T11:58:00Z | [
"python",
"hadoop",
"hive"
] |
How to sort a dictionary with multiple inputs | 39,291,613 | <p>I have a dictionary called language list with 2 items: suburb and language.
Each suburb may have more than 1 language.</p>
<p>This is what is in the dictionary "languagelist":
('Edgecumbe', 'Farsi, English'), ('Junction Triangle', 'English, Mandarin'), ('Guildwood', 'Mandarin, English'), ('Greenmeadows', 'English')... | -1 | 2016-09-02T11:44:32Z | 39,291,890 | <p>Say you start with</p>
<pre><code>languagelist = dict([('Edgecumbe', 'Farsi, English'), ('Junction Triangle', 'English, Mandarin'), ('Guildwood', 'Mandarin, English'), ('Greenmeadows', 'English')])
</code></pre>
<p>Then, for any <code>place</code>, the sorted languages spoken at that place is</p>
<pre><code>', '.... | 0 | 2016-09-02T11:57:57Z | [
"python",
"sorting",
"dictionary"
] |
How to replace the pattern w{3,3} with w{3} | 39,291,618 | <p>I meant any numbers in this regex expression.</p>
<pre><code>w{1,1} --> w{1}
w{2,2} --> w{2}
</code></pre>
<p>and so on.</p>
| 1 | 2016-09-02T11:44:46Z | 39,291,825 | <p>Find <code>w\{(\d*),\1\}</code> and replace it with <code>w{\1}</code>.</p>
<p>Here is a full example with python code:</p>
<pre><code>import re
re.sub(r'w\{\s*([0-9]+)\s*,\s*\1\s*\}', r'w{\1}', 'w{1,1}')
</code></pre>
<p>Explanation:</p>
<ul>
<li>we have to escape the curly braces: <code>\{</code> and <code>\}... | 1 | 2016-09-02T11:54:52Z | [
"python",
"regex",
"python-2.7",
"python-3.x"
] |
Python Azure-Storage 0.33.0 broken with Azure WebApp | 39,291,622 | <p>I have this really weird issue with Flask app crashing when importing azure.storage. So I have this code:</p>
<pre><code>from azure.storage.queue import QueueService
</code></pre>
<p>As soon as I deploy it to Azure, it fails. Any ideas ? I have put both Azure and Azure-Storage in requirements.txt.</p>
<p>What cou... | 1 | 2016-09-02T11:44:56Z | 39,341,273 | <p>Azure-storage 0.33.0 (latest as of now) has a dependency of cryptography package, which fails to install, take a look here:</p>
<p><a href="https://github.com/Azure/azure-storage-python/issues/219" rel="nofollow">https://github.com/Azure/azure-storage-python/issues/219</a></p>
<p>workaround: use earlier version, 0... | 1 | 2016-09-06T05:32:20Z | [
"python",
"azure",
"flask"
] |
send request body using a decorator in python | 39,291,895 | <p>I have a function in a django project something like this:</p>
<pre><code>class my_class():
def post(self, request, id, format=None):
logger.info(
''.join(
["id"+str(request.get('id')),
"name"+str(request.get('name')),
"grade"+str(re... | 1 | 2016-09-02T11:58:06Z | 39,292,102 | <p>I guess this should suffice, you might want to also read <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=240845" rel="nofollow">this</a>.</p>
<pre><code>class Logger(object):
def __init__(self, f):
self.f = f
def __call__(self, request, *args, **kwargs):
logger.info(request.GET)... | 0 | 2016-09-02T12:10:00Z | [
"python",
"django",
"request",
"decorator"
] |
send request body using a decorator in python | 39,291,895 | <p>I have a function in a django project something like this:</p>
<pre><code>class my_class():
def post(self, request, id, format=None):
logger.info(
''.join(
["id"+str(request.get('id')),
"name"+str(request.get('name')),
"grade"+str(re... | 1 | 2016-09-02T11:58:06Z | 39,292,122 | <pre><code>def logger(func):
def decorator(request, *args, **kwargs):
# log here
return func(request, *args, **kwargs)
return decorator
</code></pre>
| 1 | 2016-09-02T12:10:47Z | [
"python",
"django",
"request",
"decorator"
] |
TypeError: 'bytes' object is not callable | 39,292,002 | <h1>Edit:</h1>
<p>I made the very trivial mistake of having bound <code>bytes</code> to something else previous to executing the following code. This question is now entirely trivial and probably doesn't help anyone. Sorry.</p>
<h1>Original question:</h1>
<p>Code:</p>
<pre><code>import sys
print(sys.version)
b = by... | -3 | 2016-09-02T12:04:05Z | 39,292,022 | <p>You have assigned <em>a <code>bytes</code> value</em> to the name <code>bytes</code>:</p>
<pre><code>>>> bytes([10, 20, 30, 40])
b'\n\x14\x1e('
>>> bytes = bytes([10, 20, 30, 40])
>>> bytes([10, 20, 30, 40])
Traceback (most recent call last):
File "<stdin>", line 1, in <module&... | 2 | 2016-09-02T12:05:24Z | [
"python",
"byte"
] |
portalocker does not seem to lock | 39,292,051 | <p>I have a sort of checkpoint file which I wish to modify sometimes by various python programs. I load the file, try to lock it using portalocker, change it, than unlock and close it.</p>
<p>However, portalocker does not work in the simplest case.
I created a simple file:</p>
<pre><code>$echo "this is something here... | 2 | 2016-09-02T12:07:23Z | 39,338,942 | <p>The problem is that, by default, Linux uses advisory locks. <a href="https://stackoverflow.com/questions/12062466/mandatory-file-lock-on-linux">To enable mandatory locking (which you are referring to) the filesytem needs to be mounted with the <code>mand</code> option</a>. The advisory locking system actually has se... | 1 | 2016-09-06T00:02:30Z | [
"python",
"python-3.x",
"locking"
] |
How to make thicker stem lines in matplolib | 39,292,117 | <p>I want to make thicker stem lines in python when using <code>plt.stem</code>.</p>
<p>Here is my code</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
N = 20
n = np.arange(0, 2*N, 1)
x = np.exp(-n/N)*np.exp(1j * 2*np.pi/N*n)
plt.stem(n,x.real)
plt.show()
</code></pre>
<p>I changed <code>plt.... | 2 | 2016-09-02T12:10:34Z | 39,292,212 | <p>The documentation of <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.stem"><code>plt.stem</code></a> shows that the function returns all the line objects created by the plot. You can use that to manually make the lines thicker after plotting:</p>
<pre><code>import matplotlib.pyplot as plt
impor... | 6 | 2016-09-02T12:15:33Z | [
"python",
"stem"
] |
How to make thicker stem lines in matplolib | 39,292,117 | <p>I want to make thicker stem lines in python when using <code>plt.stem</code>.</p>
<p>Here is my code</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
N = 20
n = np.arange(0, 2*N, 1)
x = np.exp(-n/N)*np.exp(1j * 2*np.pi/N*n)
plt.stem(n,x.real)
plt.show()
</code></pre>
<p>I changed <code>plt.... | 2 | 2016-09-02T12:10:34Z | 39,292,292 | <p>This can also be modified using <code>plt.setp()</code> as is shown in the matplotlib documentation <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.stem" rel="nofollow">example</a>. The <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.setp" rel="nofollow"><code>plt.setp()</c... | 4 | 2016-09-02T12:19:51Z | [
"python",
"stem"
] |
Python: indexing letters of string in a list | 39,292,190 | <p>I would like to ask if there is a way how to get exact letters of some string stored in a list? I'm working with DNA strings, get them from FASTA file using BioPython SeqIO and store them as strings in a list. In next step I will convert it to numerical sequence (called genomic signals). But as novice in Python I do... | 0 | 2016-09-02T12:14:15Z | 39,292,439 | <p>I don't know how MATLAB does it. In Python you can access any position in a string without converting to a list:</p>
<pre><code>DNA = "ACGTACGTACGT"
print(DNA[2])
# outputs "G", the third base
</code></pre>
<p>If you want to store "strings in a list" you can do this:</p>
<pre><code>DNA_list = ["AAAAAA", "CCCCC", ... | 1 | 2016-09-02T12:27:46Z | [
"python",
"biopython"
] |
Python: indexing letters of string in a list | 39,292,190 | <p>I would like to ask if there is a way how to get exact letters of some string stored in a list? I'm working with DNA strings, get them from FASTA file using BioPython SeqIO and store them as strings in a list. In next step I will convert it to numerical sequence (called genomic signals). But as novice in Python I do... | 0 | 2016-09-02T12:14:15Z | 39,292,704 | <p>if you use the following you can convert any string to a list<code>
list(The string)</code></p>
| 0 | 2016-09-02T12:41:06Z | [
"python",
"biopython"
] |
Why crash when derive from QListWidgetItem AND QObject | 39,292,260 | <p>The following minimal example crashes in pyqt 5.7.1 on windows (copy-paste this in a .py file and run):</p>
<pre><code>from PyQt5.QtWidgets import QListWidgetItem, QListWidget, QApplication
from PyQt5.QtCore import QObject, pyqtSlot, pyqtSignal
class MyListItem(QListWidgetItem):
def __init__(self, obj):
... | 1 | 2016-09-02T12:18:12Z | 39,297,775 | <p>This has got nothing to do with <code>pyqtSlot</code>.</p>
<p>The actual problem is that you are trying to inherit from two Qt classes, and that is <a href="http://pyqt.sourceforge.net/Docs/PyQt5/gotchas.html#multiple-inheritance" rel="nofollow">not generally supported</a>. The only exceptions to this are Qt classe... | 1 | 2016-09-02T17:21:55Z | [
"python",
"multiple-inheritance",
"signals-slots",
"pyqt5"
] |
Pandas DataFrame with continuous index | 39,292,275 | <p>I have the following code:</p>
<pre><code>import pandas as pd
df = pd.DataFrame(
{'Index' : ['1', '2', '5','7', '8', '9', '10'],
'Vals' : [1, 2, 3, 4, np.nan, np.nan, 5]})
</code></pre>
<p>This gives me:</p>
<pre><code> Index Vals
0 1 1.0
1 2 2.0
2 5 3.0
3 7 4.0
4 8 NaN
5 ... | 3 | 2016-09-02T12:19:01Z | 39,292,535 | <p>So for your example it will look like:</p>
<pre><code>import pandas as pd
import numpy as np
df = pd.DataFrame(
{'Index' : ['1', '2', '5','7', '8', '9', '10'],
'Vals' : [1, 2, 3, 4, np.nan, np.nan, 5]})
df['Index'] = df['Index'].astype(int)
clean_data = pd.DataFrame({'Index' : range(1,11)})
result = clea... | 3 | 2016-09-02T12:31:56Z | [
"python",
"pandas",
"indexing"
] |
Pandas DataFrame with continuous index | 39,292,275 | <p>I have the following code:</p>
<pre><code>import pandas as pd
df = pd.DataFrame(
{'Index' : ['1', '2', '5','7', '8', '9', '10'],
'Vals' : [1, 2, 3, 4, np.nan, np.nan, 5]})
</code></pre>
<p>This gives me:</p>
<pre><code> Index Vals
0 1 1.0
1 2 2.0
2 5 3.0
3 7 4.0
4 8 NaN
5 ... | 3 | 2016-09-02T12:19:01Z | 39,293,045 | <p>You can put the <code>Index</code> column in the index (after casting as integer), select the rows <code>1</code> through <code>10</code> (which will create the appropriate <code>NaN</code>s) and reset the index.</p>
<pre><code>import numpy as np
import pandas as pd
df = pd.DataFrame(
{'Index' : ['1', '2', '5'... | 1 | 2016-09-02T12:58:38Z | [
"python",
"pandas",
"indexing"
] |
How to convert 1-channel numpy matrix to 4-channel monochromatic image | 39,292,401 | <p>I am working on a pyqt project with numpy and cv2. Basically, I want to use a binary numpy mask <code>(1024, 1024)</code> to create a 4 channel monochromatic image <code>(1024, 1024, 4)</code>, where all 1s from the mask are pink and all 0s are invisible. Then I convert the image and show it as overlay in my QScene ... | 2 | 2016-09-02T12:26:04Z | 39,292,493 | <p>Yes! Use <a href="http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html" rel="nofollow"><code>NumPy broadcasting</code></a> to clean it up and have a <code>one-liner</code>, like so -</p>
<pre><code>transposed = mask.T[...,None]*color
</code></pre>
<p><strong>Explanation:</strong></p>
<ol>
<li>Use <code>m... | 3 | 2016-09-02T12:30:30Z | [
"python",
"numpy",
"pyqt4"
] |
Slot on list widget item data object never called (in PyQt 5.7) | 39,292,449 | <p>In PyQt 5.5 the following code worked, but not so in PyQt 5.7 (the list shows 'example' rather than 'new example', and indeed debugging shows that the slot is never hit). Does anyone know what is wrong with it: </p>
<pre><code>from PyQt5.QtWidgets import QListWidgetItem, QListWidget, QApplication
from PyQt5.QtCore... | 1 | 2016-09-02T12:28:28Z | 39,298,185 | <p>There seems to be some kind of garbage-collection issue. Try this instead:</p>
<pre><code> hit_item = QListWidgetItem('example')
data = MyListItemData(hit_item, obj)
hit_item.setData(Qt.UserRole, data)
</code></pre>
| 1 | 2016-09-02T17:50:26Z | [
"python",
"signals-slots",
"pyqt5",
"qlistwidgetitem"
] |
does the zoom parameter value of the html file change when I zoom-in or zoom-out in the google map? | 39,292,506 | <p>I'm not sure whether my question is clear enough or not. This is my problem:</p>
<p>I am working with the gmplot module for python and I would like to make the grids of the scalable according to the value of the zoom of the google map. I read the html file but, as I know nothing about html, I don't know if the valu... | 0 | 2016-09-02T12:31:06Z | 39,292,848 | <p>Your best bet I think would be to use JavaScript to get the zoom value from the <a href="https://developers.google.com/maps/documentation/javascript/reference?csw=1" rel="nofollow"><code>google.maps.Map</code> object</a>.</p>
<p>You should already have such an object referenced somewhere in your code if you are see... | 1 | 2016-09-02T12:49:08Z | [
"python",
"html",
"google-maps",
"google-maps-api-3"
] |
Python BeautifulSoup replace img src | 39,292,881 | <p>I'm trying to parse HTML content from site, change a href and img src. A href changed successful, but img src don't.</p>
<p>It changed in variable but not in HTML (post_content):</p>
<pre><code><p><img alt="alt text" src="https://lifehacker.ru/wp-content/uploads/2016/08/15120903sa_d2__1471520915-630x523.j... | 1 | 2016-09-02T12:50:46Z | 39,292,990 | <p>Looks like you're never assigning <code>img_urls</code> back to <code>img['src']</code>. Try doing that at the end of the block.</p>
<pre><code>img_urls = img_urls.replace(img_urls, attachment_url)
img['src'] = img_urls
</code></pre>
<p>... But first, you need to change your <code>with</code> statement so it uses ... | 1 | 2016-09-02T12:55:29Z | [
"python",
"html",
"href",
"src"
] |
generating XML from config using python | 39,292,951 | <p>Please tell me how I can get out of *.conf [section name] and the value of the first parameter (after the name of the section) and on their basis to create a XML file using python? I have a very simple config file, but each section is more than one option. Thank you in advance.</p>
| -3 | 2016-09-02T12:53:42Z | 39,293,051 | <p>In the standard library you can find <a href="https://docs.python.org/3/library/configparser.html" rel="nofollow">configparser</a> which helps you read such files and <a href="https://docs.python.org/3/library/xml.etree.elementtree.html" rel="nofollow">xml.etree.ElementTree</a> which helps you bould valid XML files ... | 0 | 2016-09-02T12:58:47Z | [
"python",
"xml"
] |
generating XML from config using python | 39,292,951 | <p>Please tell me how I can get out of *.conf [section name] and the value of the first parameter (after the name of the section) and on their basis to create a XML file using python? I have a very simple config file, but each section is more than one option. Thank you in advance.</p>
| -3 | 2016-09-02T12:53:42Z | 39,320,869 | <pre><code>import xml.etree.cElementTree as ET # on Python 3.3+ use xml.etree.ElementTree instead
import configparser
config = configparser.ConfigParser()
config.read('sipusers.conf')
Main = ET.Element("Main")
ET.SubElement(Main, "TCMIPPhoneDirectory", clearlight="true")
ET.SubElement(Main, "Title").text = "Phone... | 0 | 2016-09-04T19:48:11Z | [
"python",
"xml"
] |
How to get pandas to throw exception (or otherwise note) if some fields are missing from csv? | 39,293,118 | <p>I am reading csv files with pandas in python. When a record in the file has less than the expected number of fields, then pandas just silently fills in the fields with NaN. Instead, I want an exception to be thrown.</p>
<p>For example, if I have a CSV file like this:</p>
<pre><code>A, B, C
1, 2, 3
4,,6
5
</code></... | 1 | 2016-09-02T13:02:05Z | 39,293,296 | <p>See <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow">documentation</a> </p>
<p>Set <code>error_bad_lines</code> to <code>False</code> :</p>
<pre><code>error_bad_lines : boolean, default True
Lines with too many fields (e.g. a csv line with too many commas) will by... | 0 | 2016-09-02T13:10:59Z | [
"python",
"csv",
"pandas"
] |
Can Python or SQLite search and replace output on the fly? | 39,293,119 | <p>Programs: SQLite database 3.14.1 & Python 2.7</p>
<p>I have a table called transactions. The field "name" has names in it. I can use Python to return the rows from selected fields to a text file based on criteria specified from tranType while adding some strings to it on the fly:</p>
<pre><code>e = open("ex... | 0 | 2016-09-02T13:02:12Z | 39,293,158 | <p>With the <a href="http://www.sqlite.org/lang_corefunc.html#replace" rel="nofollow">replace() function</a>, this can be done on the fly:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT replace(name, ' ', '+'), quantity, item, tDate FROM ...
</code></pre>
| 1 | 2016-09-02T13:04:06Z | [
"python",
"sqlite",
"loops",
"replace",
"string-concatenation"
] |
Python - Parsing Json format input | 39,293,190 | <p>I need to make a data parsing that come from another program in JSON format:</p>
<pre><code>import json
input = '''
Array
(
[error] => Array
(
)
[result] => Array
(
[0] => Person Object
(
[arr:Person:private] => Array
... | -1 | 2016-09-02T13:05:30Z | 39,293,382 | <p>your function is correct.</p>
<p>but the provided json string is wrong</p>
<p>in fact the input is a mixed array and class object</p>
<p>you can import json in python like this:</p>
<pre><code>import json
j = json.loads('{"one" : "1", "two" : "2", "three" : "3"}')
print j['two']
</code></pre>
| 1 | 2016-09-02T13:15:34Z | [
"python",
"json",
"parsing"
] |
Python Tkinter textbox inserting issue | 39,293,222 | <pre><code>from tkinter import *
import time
class MyClass(object):
def __init__(self):
root = Tk()
button = Button(root, text="Button", command=self.command).pack()
#scrollbar and textbox
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
self.tbox = ... | 1 | 2016-09-02T13:07:22Z | 39,299,436 | <p>time.sleep() is a blocking call. Use <a href="http://effbot.org/tkinterbook/widget.htm#Tkinter.Widget.after-method" rel="nofollow">after</a>.</p>
<pre><code>from tkinter import *
import time
class MyClass(object):
def __init__(self):
self.root = Tk()
button = Button(self.root, text="Button", c... | 1 | 2016-09-02T19:22:04Z | [
"python",
"tkinter",
"textbox",
"python-3.5"
] |
Python Tkinter textbox inserting issue | 39,293,222 | <pre><code>from tkinter import *
import time
class MyClass(object):
def __init__(self):
root = Tk()
button = Button(root, text="Button", command=self.command).pack()
#scrollbar and textbox
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
self.tbox = ... | 1 | 2016-09-02T13:07:22Z | 39,300,930 | <p>If you want to show texts one by one using <code>time.sleep()</code> you will need to use <code>Threading</code> module.</p>
<pre><code>from tkinter import *
import time
import threading
class Threader(threading.Thread):
def __init__(self, tbox, *args, **kwargs):
threading.Thread.__init__(self, *args... | 0 | 2016-09-02T21:27:35Z | [
"python",
"tkinter",
"textbox",
"python-3.5"
] |
How do I successfully include a definition in a if function | 39,293,257 | <p>How do I put a definition function into a <code>if</code> statement so when it's running the program will activate the definition by itself.</p>
<pre><code>person=int(input("select the number of any option which you would like to execute:"))
if (person)==(1):
print ("please write the value for each class ")
... | 0 | 2016-09-02T13:09:10Z | 39,293,395 | <p>You can't call <code>main()</code> at a point where <code>main()</code> hasn't been defined. Move your definition of <code>main()</code> to above the place where you try and call it.</p>
<pre><code>def main():
juvenile = input("number of juveniles:")
adult = input("number of adults:")
senile = input("nu... | 1 | 2016-09-02T13:15:58Z | [
"python"
] |
how to efficiently cythonize the "vectorize" function (numpy library) - python | 39,293,273 | <p>as the title suggets, I'd like to efficiently cythonize the <code>numpy.vectorize</code> function, which, to the core, is simplyfying this piece below (the complete function is way too long to post but the majority of the time is spent here):</p>
<pre><code> def func(*vargs):
for _n, _i in enumerate(inds... | 1 | 2016-09-02T13:09:56Z | 39,297,140 | <p>The function you show is just a bit of dancing to deal with <code>kwargs</code>. Note the comment at the head of that block in <code>vectorize.__call__</code>. With simpler arguments it just sets <code>func = self.pyfunc</code>.</p>
<p>The actual work is done in the last line:</p>
<pre><code>self._vectorize_call... | 2 | 2016-09-02T16:36:44Z | [
"python",
"numpy",
"vectorization",
"cython"
] |
How to join two pandas Series into a single one with interleaved values? | 39,293,328 | <p>I have two pandas.Series...</p>
<pre><code>import pandas as pd
import numpy as np
length = 5
s1 = pd.Series( [1]*length ) # [1, 1, 1, 1, 1]
s2 = pd.Series( [2]*length ) # [2, 2, 2, 2, 2]
</code></pre>
<p>...and I would like to have them joined together in a single Series with the interleaved values from the first... | 3 | 2016-09-02T13:12:54Z | 39,293,329 | <p>Here we are:</p>
<pre><code>s1.index = range(0,len(s1)*2,2)
s2.index = range(1,len(s2)*2,2)
interleaved = pd.concat([s1,s2]).sort_index()
idx values
0 1
1 2
2 1
3 2
4 1
5 2
6 1
7 2
8 1
9 2
</code></pre>
| 2 | 2016-09-02T13:12:54Z | [
"python",
"pandas",
"numpy"
] |
How to join two pandas Series into a single one with interleaved values? | 39,293,328 | <p>I have two pandas.Series...</p>
<pre><code>import pandas as pd
import numpy as np
length = 5
s1 = pd.Series( [1]*length ) # [1, 1, 1, 1, 1]
s2 = pd.Series( [2]*length ) # [2, 2, 2, 2, 2]
</code></pre>
<p>...and I would like to have them joined together in a single Series with the interleaved values from the first... | 3 | 2016-09-02T13:12:54Z | 39,293,424 | <p>Here's one using <code>NumPy stacking</code>, <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.vstack.html" rel="nofollow"><code>np.vstack</code></a> -</p>
<pre><code>pd.Series(np.vstack((s1,s2)).ravel('F'))
</code></pre>
| 3 | 2016-09-02T13:17:17Z | [
"python",
"pandas",
"numpy"
] |
How to join two pandas Series into a single one with interleaved values? | 39,293,328 | <p>I have two pandas.Series...</p>
<pre><code>import pandas as pd
import numpy as np
length = 5
s1 = pd.Series( [1]*length ) # [1, 1, 1, 1, 1]
s2 = pd.Series( [2]*length ) # [2, 2, 2, 2, 2]
</code></pre>
<p>...and I would like to have them joined together in a single Series with the interleaved values from the first... | 3 | 2016-09-02T13:12:54Z | 39,293,470 | <p>Using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.column_stack.html" rel="nofollow">np.column_stack</a>:</p>
<pre><code>In[27]:pd.Series(np.column_stack((s1,s2)).flatten())
Out[27]:
0 1
1 2
2 1
3 2
4 1
5 2
6 1
7 2
8 1
9 2
dtype: int64
</code></pre>
| 4 | 2016-09-02T13:19:26Z | [
"python",
"pandas",
"numpy"
] |
AttributeError: 'module' object has no attribute 'version' Canopy | 39,293,375 | <p>Hi I am going to preface this with I could just be really dumb so don't overlook that, but suddenly when opening canopy today I wasn't able to run one of my typical scripts with the error AttributeError: 'module' object has no attribute ' version' when trying to load pandas. From what I can gather it seems when bump... | 0 | 2016-09-02T13:15:17Z | 39,293,932 | <p>Just had the same problem after downgrading Pandas and upgrading again to fix another issue. This is just a hack, but you could try this:</p>
<p>Open <code>...pandas/compat/numpy_compat.py</code> and replace <code>np.version.short_version</code> with <code>np._np_version</code></p>
<p>Hope that helps!</p>
| 0 | 2016-09-02T13:44:23Z | [
"python",
"numpy",
"canopy"
] |
How to edit dict in views.py from django admin | 39,293,387 | <p>I'm working on a site to better learn the Django-framework. I've currently set up views and links to template files to display content on the main page. In my views.py file I've added a dictionary that is displays the dict value for each key in in the index.html page when it gets rendered:</p>
<p>views.py:</p>
<pr... | 0 | 2016-09-02T13:15:42Z | 39,294,020 | <p>You'll probably want to create a Model for Projects, so projects can be saved to a Database and easily displayed in the Admin. </p>
<p>Inside models.py include the following: </p>
<pre><code>class Project(models.Model):
message = models.CharField(max_length=20)
title = models.CharField(max_length=20)
t... | 1 | 2016-09-02T13:48:23Z | [
"python",
"django",
"django-admin"
] |
generate multiple 2 dimensional data from given 2 dimensional data | 39,293,490 | <p>I have CCD with 512 x512 data of single frame (reference ). I need to generate 100000, 512x512 frames provided sum of value of pixel in each frame should give actual value of the corresponding pixel in the reference frame. Could you please help in this. </p>
| 0 | 2016-09-02T13:20:34Z | 39,294,683 | <p>I suppose you want to generate <code>1000000</code> frames with <strong>random</strong> values? Here is one approach. For simplicity and memory reasons I will take only <code>3x3</code> data instead of <code>512x512</code> and generate only <code>10</code> frames instead of <code>100000</code>.</p>
<pre><code>#I wi... | 0 | 2016-09-02T14:20:58Z | [
"python"
] |
Finding largest distance (on number scale) between n pairs of numbers | 39,293,520 | <p>I am trying to write an algorithm that finds the largest distance between two numbers, given n pairs of numbers.</p>
<p>Here is what I have so far.</p>
<p>Wire ints is my example numbers, with first pair being <code>1,10</code> and second pair being <code>1,10</code> and third pair being <code>7,7</code>.</p>
<pr... | 1 | 2016-09-02T13:21:41Z | 39,293,708 | <p>As far as you can have only unique keys in dictionary, you should either use pair number as a key or use a list:</p>
<pre><code>wire_ints = [10, 1, 1, 10, 7, 7]
longest_dict = []
longest_so_far = 0
for i in range(len(wire_ints)//2):
j = i*2
a, b = wire_ints[j:j+2]
dist = abs(a - b)
pair = [dist, i + 1]
... | 2 | 2016-09-02T13:32:01Z | [
"python"
] |
Finding largest distance (on number scale) between n pairs of numbers | 39,293,520 | <p>I am trying to write an algorithm that finds the largest distance between two numbers, given n pairs of numbers.</p>
<p>Here is what I have so far.</p>
<p>Wire ints is my example numbers, with first pair being <code>1,10</code> and second pair being <code>1,10</code> and third pair being <code>7,7</code>.</p>
<pr... | 1 | 2016-09-02T13:21:41Z | 39,293,802 | <p>This takes your initial input and converts it to a list of tuples. Then it calculates the absolute difference between the tuple members and puts that into a new list. Then your final output is created as index_list.</p>
<pre><code>wire_ints = [10, 1, 1, 10, 7, 7]
new_list = [(x,y) for (x,y) in zip(wire_ints[::2], ... | 3 | 2016-09-02T13:36:32Z | [
"python"
] |
Finding largest distance (on number scale) between n pairs of numbers | 39,293,520 | <p>I am trying to write an algorithm that finds the largest distance between two numbers, given n pairs of numbers.</p>
<p>Here is what I have so far.</p>
<p>Wire ints is my example numbers, with first pair being <code>1,10</code> and second pair being <code>1,10</code> and third pair being <code>7,7</code>.</p>
<pr... | 1 | 2016-09-02T13:21:41Z | 39,294,108 | <p>What you are missing is not keeping distance indexes in a list. You can provide it by the code below:</p>
<pre><code>longest_cases = {}
wire_ints = [10, 1, 1, 10, 7, 7]
leftIndex = 0
rightIndex = 1
largest_length = 0
y = 1
while leftIndex < len(wire_ints):
cur_length = abs(wire_ints[leftIndex] - wire_ints... | 0 | 2016-09-02T13:52:24Z | [
"python"
] |
Django : Adding extra feature in the User model of auth App | 39,293,543 | <p>I want to add extra feature in the User model of auth app but I don't want to get my hand dirty with the django source code or I don't want to create a new User model which extends the User model of auth app. Is it possible? if yes then how ?</p>
<p>P.S I have seen django-eav but I want to permanently store the val... | 0 | 2016-09-02T13:22:52Z | 39,293,717 | <p>There are a few ways to do this, but I'd recommend subclassing Django's Abstract User model. For example:</p>
<pre><code>from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils.translation import ugettext_lazy as _
class KarmaUser(AbstractUser):
karma = models.Positi... | 0 | 2016-09-02T13:32:29Z | [
"python",
"django"
] |
How to Filter Out Today's Date in Pandas Dataframe | 39,293,580 | <p>I have the following data frame:</p>
<pre><code>Company Date Value
ABC 08/21/16 00:00:00 500
ABC 08/22/16 00:00:00 600
ABC 08/23/16 00:00:00 650
ABC 08/24/16 00:00:00 625
ABC 08/25/16 00:00:00 675
ABC 08/26/16 00:00:00 680
</code>... | 1 | 2016-09-02T13:25:01Z | 39,294,800 | <p>I think you want to filter the dates that appear earlier than your specified date, though the title seems misleading. You must convert the <code>Date</code> column which are of dtype <code>object</code> to <code>datetime64</code>.</p>
<pre><code>In [22]: df['Date'] = pd.to_datetime(df['Date'], format='%Y-%m-%d')
I... | 2 | 2016-09-02T14:27:17Z | [
"python",
"datetime",
"pandas"
] |
Linked-list Data Structure understanding | 39,293,890 | <p>I have a little difficulty in understanding one thing in the structure of the Linked-lists.
Basically nodes of a linked list are created using the following class, and the next reference is obtained by the method getNext():
I have omitted other methods as not relevant to my problem.</p>
<pre><code>class Node:
d... | 2 | 2016-09-02T13:41:58Z | 39,294,830 | <p><code>current</code> is basically an instance of <code>UnOrderedList</code> in which each element is <code>Node</code> object. Hence the methods that are applied on <code>Nodes</code> can be applied on each element of <code>current</code>. Nodes are added to <code>UnOrderedList</code> using the add method.</p>
<pre... | 1 | 2016-09-02T14:28:43Z | [
"python",
"class",
"data-structures",
"linked-list"
] |
Merge, sum and removing duplicates with pandas | 39,293,946 | <p>I have two different data frames with different sizes just like this:</p>
<pre><code>df_web = (['Event Category', 'ID', 'Total Events',
'Unique Events', 'Event Value', 'Avg. Value'])
df_app = (['Event Category', 'ID', 'Total Events',
'Unique Events', 'Event Value', 'Avg. Value']
</code></pre... | 0 | 2016-09-02T13:44:54Z | 39,295,541 | <p>Modified solution from your code using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow">pd.concat</a>:</p>
<pre><code>In [46]: df
Out[46]:
0 1 2
0 Video A 10
1 Video B 5
2 Video C 1
3 Video F 1
4 Video G 1
5 ... | 0 | 2016-09-02T15:04:26Z | [
"python",
"pandas"
] |
(Python) How do i search directories and find files that match regex? | 39,293,968 | <p>I recently started getting into Python and i am having a hard time searching through directories and matching files based on a regex that i have created. Basically i want it to scan through all the directories in another directory and find all the files that ends with .zip or .rar or .r01 and then run various comman... | -1 | 2016-09-02T13:46:16Z | 39,294,155 | <pre><code>import os
import re
rootdir = "/mnt/externa/Torrents/completed"
regex = re.compile('(.*zip$)|(.*rar$)|(.*r01$)')
for root, dirs, files in os.walk(rootdir):
for file in files:
if regex.match(file):
print(file)
</code></pre>
<p><strong>CODE BELLOW ANSWERS QUESTION IN FOLLOWING COMMENT</strong><... | 2 | 2016-09-02T13:55:10Z | [
"python",
"linux",
"directory"
] |
Shrink pandas Df by deleting rows through modulo | 39,294,132 | <p>I need to reduce (or select) for example multiple of 4 of the index.
i have a 2MS dataframe and i want to get less data for a future plot. so the idea is to work with 1/4 of the data. leaving only the rows with index 4 - 8 - 16 - 20 - 4*n (or maybe the same but with 5*n)
if someone has any idea i will be grateful.</... | 1 | 2016-09-02T13:53:39Z | 39,294,197 | <p>You can use the <code>iloc</code> function, which takes a row/column slice. </p>
<p>From the <a href="http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.DataFrame.iloc.html" rel="nofollow">docs</a></p>
<blockquote>
<p>Purely integer-location based indexing for selection by position.</p>
<p... | 1 | 2016-09-02T13:57:25Z | [
"python",
"pandas",
"dataframe"
] |
Why does my QStandardItemModel itemFromIndex method return None? (index invalid) | 39,294,136 | <p>I am trying to make a listview with checkboxes that checks the selected boxes when the <strong>enter/return key</strong> is pressed. I do this with an override of the eventfilter for my MainWindow (yes I ought to subclass it, but I couldn't get that working)</p>
<p>In the eventfilter i get a <strong>None</strong> v... | 0 | 2016-09-02T13:53:57Z | 39,326,817 | <p>As discussed in the comments:</p>
<p>The indices returned by <code>QItemSelectionModel.selectedIndexes()</code> come from the view and relate to the connection between the view and its immediate model. The identity of that model can be found by calling <code>QModelIndex.model()</code> and in this case it is not th... | 0 | 2016-09-05T08:45:15Z | [
"python",
"qt",
"pyqt",
"qlistview",
"qstandarditemmodel"
] |
Finding most frequent combinations of numbers | 39,294,224 | <p>I have a list of 1000s of 7-number sequences and I want to know which combination of numbers are most frequent, ranging from 2 to 7 numbers.</p>
<p>So, for instance, in this list:</p>
<pre><code>1, 2, 3, 4, 5, 6, 7
1, 2, 4, 5, 6, 8, 9
1, 2, 9, 10, 12, 15, 27
</code></pre>
<p><code>[1, 2]</code> would be the highe... | 0 | 2016-09-02T13:58:37Z | 39,294,789 | <p>You can use a data mining approach in order to achieve your goal: It is called frequent itemset mining.</p>
<p>Indeed, assuming that :</p>
<pre><code>1, 2, 3, 4, 5, 6, 7
1, 2, 4, 5, 6, 8, 9
1, 2, 9, 10, 12, 15, 27
</code></pre>
<p>is your transactions database, where a transaction is a row (for instance : 1, 2, 3... | 1 | 2016-09-02T14:26:57Z | [
"python",
"numpy"
] |
Naming rotating log files specific name in Python | 39,294,275 | <p>I want to name rotating log files as I want.</p>
<p>For example, if I use RotatingFileHandler, It separates log file when it reaches to specific file size naming <code>log file name + extension numbering</code>, like below.</p>
<pre><code>filename.log #first log file
filename.log.1 #rotating log file1
file... | 1 | 2016-09-02T14:00:49Z | 39,296,094 | <p>Check the following code and see if it helps. As far as I could understand from your question if your issue is in achieving the filename based on timestamp then this shall work for you.</p>
<pre><code>import datetime, time
# This return the epoch timestamp
epochTime = time.time()
# We generate the timestamp
# ... | 1 | 2016-09-02T15:36:00Z | [
"python",
"logging"
] |
Naming rotating log files specific name in Python | 39,294,275 | <p>I want to name rotating log files as I want.</p>
<p>For example, if I use RotatingFileHandler, It separates log file when it reaches to specific file size naming <code>log file name + extension numbering</code>, like below.</p>
<pre><code>filename.log #first log file
filename.log.1 #rotating log file1
file... | 1 | 2016-09-02T14:00:49Z | 39,351,132 | <p>I inherit and override <code>RotatingFileHandler</code> of python logging handler.</p>
<p>RotatingFileHandler has <code>self.baseFilename</code> value, the handler will use <code>self.baseFilename</code> to create logFile.(when it creates file first or when rollover happens)</p>
<p><code>self.shouldRollover()</cod... | 0 | 2016-09-06T14:09:56Z | [
"python",
"logging"
] |
Get timestamp in seconds from python's datetime | 39,294,293 | <p>How to get timestamp from the structure datetime? What is right alternative for non-existing <code>datetime.utcnow().timestamp()</code>?</p>
| 0 | 2016-09-02T14:01:46Z | 39,294,363 | <pre><code>import time,datetime
time.mktime(datetime.datetime.today().timetuple())
</code></pre>
| 1 | 2016-09-02T14:06:03Z | [
"python",
"timestamp"
] |
Get timestamp in seconds from python's datetime | 39,294,293 | <p>How to get timestamp from the structure datetime? What is right alternative for non-existing <code>datetime.utcnow().timestamp()</code>?</p>
| 0 | 2016-09-02T14:01:46Z | 39,294,913 | <p>If you don't have to get timestamp from structure datetime, you can decrease instruction like this</p>
<pre><code>import time
print time.time()
</code></pre>
| 0 | 2016-09-02T14:32:29Z | [
"python",
"timestamp"
] |
Get timestamp in seconds from python's datetime | 39,294,293 | <p>How to get timestamp from the structure datetime? What is right alternative for non-existing <code>datetime.utcnow().timestamp()</code>?</p>
| 0 | 2016-09-02T14:01:46Z | 39,296,248 | <p>There is another stupid trick - achieve <code>timedelta</code> </p>
<pre><code>(datetime.utcnow()-datetime(1970,1,1,0,0,0)).total_seconds()
</code></pre>
<p>found <a href="http://stackoverflow.com/a/7852969/3743145">here</a>. <strong>Better</strong></p>
<pre><code>(datetime.utcnow()-datetime.fromtimestamp(0)).tot... | 0 | 2016-09-02T15:43:40Z | [
"python",
"timestamp"
] |
Get timestamp in seconds from python's datetime | 39,294,293 | <p>How to get timestamp from the structure datetime? What is right alternative for non-existing <code>datetime.utcnow().timestamp()</code>?</p>
| 0 | 2016-09-02T14:01:46Z | 39,296,289 | <p>If I understand correctly what sort of output you are seeking:</p>
<pre><code>from datetime import datetime
timestamp = datetime.now().strftime("%H:%M:%S")
print(timestamp)
> 11:44:40
</code></pre>
<p>EDIT: Appears I misinterpreted your question? You are asking for the naive universal time, then galaxyan's ans... | 0 | 2016-09-02T15:45:38Z | [
"python",
"timestamp"
] |
Python code to run for next 100 days from today | 39,294,317 | <p>I want to run below line of code for 200 days from today.
Suppose today is 1st days so my code is- </p>
<pre><code>line = linecache.getline("lines1.txt",1)
print(line)
</code></pre>
<p>Suppose today is 2nd days so my code is-</p>
<pre><code>line = linecache.getline("lines1.txt",2)
print(line)
</code></pre>
<p>S... | -2 | 2016-09-02T14:03:06Z | 39,294,475 | <p>set a marker date then calculated difference between today dan marker date</p>
<pre><code>(datetime.datetime(2016,9,2) - datetime.datetime(2016,9,1) ).days
output:
1
</code></pre>
| 1 | 2016-09-02T14:11:31Z | [
"python",
"python-3.x",
"linecache"
] |
How to run a sql query inside a WLST script | 39,294,327 | <p>As it is possible to access a specific weblogic jdbc datasource in wlst, how can we run a sql query on this datasource ?</p>
<p>Here is how i retreive the specific datasource : </p>
<pre><code># Load the properties file with all necessary values
loadProperties('domain.properties')
# Go online
connect(adminusername... | 0 | 2016-09-02T14:03:42Z | 39,308,688 | <p>Try this WLST command</p>
<p>loadDB('12C', 'myDataSource', 'select name from emp')</p>
| -1 | 2016-09-03T15:47:41Z | [
"python",
"oracle",
"weblogic",
"wlst"
] |
How to specify argument types? | 39,294,350 | <p>I'm very much a Python newbie, but I've searched for a solution and I'm stumped. </p>
<p>I have defined a function which accepts several arguments:</p>
<pre><code>def func(arg1, arg2, arg3):
</code></pre>
<p>The first argument will be a string but the next two are always going to be integers. I need to construct ... | 0 | 2016-09-02T14:05:32Z | 39,294,414 | <p>try to round for whole formula </p>
<pre><code>for x in range(int(arg2/2))
</code></pre>
| 0 | 2016-09-02T14:08:32Z | [
"python",
"python-3.x",
"arguments",
"formats"
] |
How to specify argument types? | 39,294,350 | <p>I'm very much a Python newbie, but I've searched for a solution and I'm stumped. </p>
<p>I have defined a function which accepts several arguments:</p>
<pre><code>def func(arg1, arg2, arg3):
</code></pre>
<p>The first argument will be a string but the next two are always going to be integers. I need to construct ... | 0 | 2016-09-02T14:05:32Z | 39,294,415 | <p>In Python 3.x:</p>
<p>When you <code>arg2 / 2</code> you will get a float. If you want an int try <code>arg2 // 2</code></p>
<p>For example <code>2 / 2 = 1.0</code> but <code>2 // 2 = 1</code> </p>
<p>But you will lose accuracy doing this, but since you want an int I'm assuming you want to round up or down anyway... | 3 | 2016-09-02T14:08:32Z | [
"python",
"python-3.x",
"arguments",
"formats"
] |
SQLAlchemy GLOB | 39,294,367 | <p>I'm using SQLAlchemy over an SQLite backend and I want to perform the following sort of update: </p>
<pre><code>UPDATE Measurement SET MeasurementCampaign=? WHERE filename GLOB ?
</code></pre>
<p>But I can't find any equivalent GLOB functionality in the SQLAlchemy docs. I have quite a few wildcard expressions and ... | 0 | 2016-09-02T14:06:08Z | 39,315,682 | <p>It turns out you can use the <a href="http://docs.sqlalchemy.org/en/latest/orm/internals.html?highlight=in_#sqlalchemy.orm.interfaces.PropComparator.op" rel="nofollow" title="op">'op'</a> function for exactly this:</p>
<pre><code>session.query(Measurement).filter(Measurement.filename.op('GLOB')(wildcard)).update({.... | 0 | 2016-09-04T09:55:19Z | [
"python",
"sqlite",
"sqlalchemy"
] |
How can I find start and end occurrence of character in Python | 39,294,469 | <p>I have a dataframe <code>df</code> with the following ids (in <code>Col</code>).
The last occurrence of A/B/C represents the start, and the last occurrence of X is the end. I should ignore any other A,B,C between start and end (e.g. rows 8 and 9).</p>
<p>I have to find start and end records from this data and assi... | 4 | 2016-09-02T14:11:20Z | 39,350,539 | <p>To find your indices of A, B, and C you can do:</p>
<pre><code>df[(df.Col =='A')|(df.Col =='B')|(df.Col =='C')].index
</code></pre>
<p>Print your start counts:</p>
<pre><code>df1 = df[df['count'] != df['count'].shift(+1)]
print df1[df1['count'] != 0]['count']
</code></pre>
<p>Print your end counts:</p>
<pre><co... | 1 | 2016-09-06T13:42:15Z | [
"python",
"pandas",
"indexing",
"shift",
"find-occurrences"
] |
django-subdomains config localhost | 39,294,559 | <p>I'm having trouble getting mine configured correctly.</p>
<p>Have sites enabled and site domain for "SITE_ID = 1" (db object 1 domain) set too "mysite.app"</p>
<p>I have these subdomains setup</p>
<pre><code>ROOT_URLCONF = 'mysite.urls'
SUBDOMAIN_URLCONFS = {
None: 'frontend.urls', # no subdomain, e.g. ``exa... | 0 | 2016-09-02T14:15:32Z | 39,299,755 | <p>Try <a href="http://api.127.0.0.1.xip.io:8000/" rel="nofollow">http://api.127.0.0.1.xip.io:8000/</a> with your dev server running at 127.0.0.1:8000. Since 127.0.0.1 isn't really a domain but an IP, it can't have subdomains. And since your hosts file redirects to 127.0.0.1 not 127.0.0.1.xip.io or similar (you don't h... | 0 | 2016-09-02T19:48:24Z | [
"python",
"django"
] |
django-subdomains config localhost | 39,294,559 | <p>I'm having trouble getting mine configured correctly.</p>
<p>Have sites enabled and site domain for "SITE_ID = 1" (db object 1 domain) set too "mysite.app"</p>
<p>I have these subdomains setup</p>
<pre><code>ROOT_URLCONF = 'mysite.urls'
SUBDOMAIN_URLCONFS = {
None: 'frontend.urls', # no subdomain, e.g. ``exa... | 0 | 2016-09-02T14:15:32Z | 39,299,976 | <p>Simply had to restart the dev server. All was configured correctly. </p>
| 1 | 2016-09-02T20:05:07Z | [
"python",
"django"
] |
Check if values in list exceed threshold a certain amount of times and return index of first exceedance | 39,294,564 | <p>I am searching for a clean and pythonic way of checking if the contents of a list are greater than a given number (first threshold) for a certain number of times (second threshold). If both statements are true, I want to return the index of the first value which exceeds the given threshold.</p>
<p><strong>Example</... | 1 | 2016-09-02T14:15:44Z | 39,294,786 | <p>A naive and straightforward approach would be to iterate over the list counting the number of items greater than the first threshold and returning the index of the first match if the count exceeds the second threshold:</p>
<pre><code>def answer(l, thr1, thr2):
count = 0
first_index = None
for index, ite... | 0 | 2016-09-02T14:26:51Z | [
"python",
"list",
"iterator",
"threshold"
] |
Check if values in list exceed threshold a certain amount of times and return index of first exceedance | 39,294,564 | <p>I am searching for a clean and pythonic way of checking if the contents of a list are greater than a given number (first threshold) for a certain number of times (second threshold). If both statements are true, I want to return the index of the first value which exceeds the given threshold.</p>
<p><strong>Example</... | 1 | 2016-09-02T14:15:44Z | 39,294,790 | <p>I don't know if I'd call it clean or pythonic, but this should work</p>
<pre><code>def get_index(list1, thr1, thr2):
cnt = 0
first_element = 0
for i in list1:
if i > thr1:
cnt += 1
if first_element == 0:
first_element = i
if cnt > thr2:
... | 0 | 2016-09-02T14:27:00Z | [
"python",
"list",
"iterator",
"threshold"
] |
Check if values in list exceed threshold a certain amount of times and return index of first exceedance | 39,294,564 | <p>I am searching for a clean and pythonic way of checking if the contents of a list are greater than a given number (first threshold) for a certain number of times (second threshold). If both statements are true, I want to return the index of the first value which exceeds the given threshold.</p>
<p><strong>Example</... | 1 | 2016-09-02T14:15:44Z | 39,294,793 | <p>Try this:</p>
<pre><code>def check_list(testlist)
overages = [x for x in testlist if x > thr1]
if len(overages) >= thr2:
return testlist.index(overages[0])
# This return is not needed. Removing it will not change
# the outcome of the function.
return None
</code></pre>
<p>This use... | 1 | 2016-09-02T14:27:02Z | [
"python",
"list",
"iterator",
"threshold"
] |
Check if values in list exceed threshold a certain amount of times and return index of first exceedance | 39,294,564 | <p>I am searching for a clean and pythonic way of checking if the contents of a list are greater than a given number (first threshold) for a certain number of times (second threshold). If both statements are true, I want to return the index of the first value which exceeds the given threshold.</p>
<p><strong>Example</... | 1 | 2016-09-02T14:15:44Z | 39,294,795 | <pre><code>thr1 = 4
thr2 = 5
list1 = [1, 1, 1, 5, 1, 6, 7, 3, 6, 8]
list2 = [1, 1, 6, 1, 1, 1, 2, 1, 1, 1]
def func(lst)
res = [ i for i,j in enumerate(lst) if j > thr1]
return len(res)>=thr2 and res[0]
</code></pre>
<p>Output:</p>
<pre><code>func(list1)
3
func(list2)
false
</code></pre>
| 0 | 2016-09-02T14:27:05Z | [
"python",
"list",
"iterator",
"threshold"
] |
Check if values in list exceed threshold a certain amount of times and return index of first exceedance | 39,294,564 | <p>I am searching for a clean and pythonic way of checking if the contents of a list are greater than a given number (first threshold) for a certain number of times (second threshold). If both statements are true, I want to return the index of the first value which exceeds the given threshold.</p>
<p><strong>Example</... | 1 | 2016-09-02T14:15:44Z | 39,294,893 | <p>If you are looking for a one-liner (or almost)</p>
<pre><code>a = filter(lambda z: z is not None, map(lambda (i, elem) : i if elem>=thr1 else None, enumerate(list1)))
print a[0] if len(a) >= thr2 else false
</code></pre>
| 0 | 2016-09-02T14:31:32Z | [
"python",
"list",
"iterator",
"threshold"
] |
Check if values in list exceed threshold a certain amount of times and return index of first exceedance | 39,294,564 | <p>I am searching for a clean and pythonic way of checking if the contents of a list are greater than a given number (first threshold) for a certain number of times (second threshold). If both statements are true, I want to return the index of the first value which exceeds the given threshold.</p>
<p><strong>Example</... | 1 | 2016-09-02T14:15:44Z | 39,295,068 | <p>I don't know if it's considered pythonic to abuse the fact that booleans are ints but I like doing like this</p>
<pre><code>def check(l, thr1, thr2):
c = [n > thr1 for n in l]
if sum(c) >= thr2:
return c.index(1)
</code></pre>
| 3 | 2016-09-02T14:40:21Z | [
"python",
"list",
"iterator",
"threshold"
] |
Convert SQL result from self-join to square pandas dataframe | 39,294,602 | <p>Here's a tl;dr version of what I'm after; the details are below:
A SQL query gives me a table with fields [person 1 id], [person 2 id], and [number of times they were in a group together]. I want to convert to a pandas dataframe that's square -- one row per person and one column per person, with the value of each el... | 1 | 2016-09-02T14:17:17Z | 39,296,287 | <p>You could use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> after converting the required columns to type <code>str</code> and aggregate by joining them as well as taking their counts.</p>
<pre><code>df[['person_id', 'assignment... | 1 | 2016-09-02T15:45:23Z | [
"python",
"postgresql",
"pandas"
] |
Multiple dictionaries causing AttributeError? | 39,294,613 | <p>I have 1 variable that contains multiple dictionaries:</p>
<pre><code>a = {"foo": "foo"}, {"foo2": "foo2"}
</code></pre>
<p>But if I do:</p>
<pre><code>a.get("foo")
</code></pre>
<p>it returns as <code>AttributeError</code>:</p>
<pre class="lang-none prettyprint-override"><code>AttributeError: 'tuple' object ha... | 1 | 2016-09-02T14:18:01Z | 39,294,626 | <p>You're assigning to variable a tuple of two elements which are dicts. </p>
<p>This:</p>
<pre><code>a = {"foo": "foo"}, {"foo2": "foo2"}
</code></pre>
<p>is equivalent to:</p>
<pre><code>a = ({"foo": "foo"}, {"foo2": "foo2"})
</code></pre>
<p>so you cannot access to dictionary in this way you try. </p>
<pre><co... | 3 | 2016-09-02T14:18:38Z | [
"python",
"dictionary",
"tuples",
"attributeerror"
] |
Multiple dictionaries causing AttributeError? | 39,294,613 | <p>I have 1 variable that contains multiple dictionaries:</p>
<pre><code>a = {"foo": "foo"}, {"foo2": "foo2"}
</code></pre>
<p>But if I do:</p>
<pre><code>a.get("foo")
</code></pre>
<p>it returns as <code>AttributeError</code>:</p>
<pre class="lang-none prettyprint-override"><code>AttributeError: 'tuple' object ha... | 1 | 2016-09-02T14:18:01Z | 39,294,752 | <p>Multiple dictionaries does not exist in Python.
If you define <code>a</code> as:</p>
<pre><code>a = {"foo": "foo"}, {"foo2": "foo2"}
</code></pre>
<p><code>a</code> will be a <code>tuple</code>. So you have to call the element as follow:</p>
<pre><code>a[0].get("foo")
</code></pre>
<p>To use <code>a.get</code> m... | 2 | 2016-09-02T14:24:31Z | [
"python",
"dictionary",
"tuples",
"attributeerror"
] |
Custom date string to Python date object | 39,294,700 | <p>I am using Scrapy to parse data and getting date in <code>Jun 14, 2016
</code> format, I have tried to parse it with <code>datetime.strftime</code> but </p>
<p>what approach should I use to convert custom date strings and what to do in my case.</p>
<p><strong>UPDATE</strong></p>
<p>I want to parse UNIX timestamp ... | -1 | 2016-09-02T14:22:00Z | 39,295,034 | <p>Something like this should work:</p>
<pre><code>import time
import datetime
datestring = "September 2, 2016"
unixdatetime = int(time.mktime(datetime.datetime.strptime(datestring, "%B %d, %Y").timetuple()))
print(unixdatetime)
</code></pre>
<p>Returns: <code>1472792400</code></p>
| 0 | 2016-09-02T14:38:51Z | [
"python",
"date",
"converter",
"python-3.5"
] |
unite 2 strings from array Python | 39,294,723 | <p>I want to unite 2 strings from an array extracted from a text file:</p>
<pre><code>for n in arrayhere:
for i in arrayhere:
newvariable = n+i
</code></pre>
<p>I also tried <code>x.split()</code> in both for loops and <code>str(n+i)</code>.</p>
<p>When I print <code>newvariable</code> or write it on the... | 0 | 2016-09-02T14:23:01Z | 39,294,834 | <p>Add this line to your code prior to looping through the elements in your list (they're not called arrays in python, but i'll refer to the list as <code>arrayhere</code> just like you did so you can substitute the code easily):</p>
<pre><code>arrayhere = [x.strip('\n') for x in arrayhere]
</code></pre>
<p>This will... | 0 | 2016-09-02T14:28:56Z | [
"python",
"arrays",
"string",
"for-loop"
] |
Matplotlib: How to increase colormap/linewidth quality in streamplot? | 39,294,987 | <p>I have the following code to generate a streamplot based on an <code>interp1d</code>-Interpolation of discrete data:</p>
<pre><code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from scipy.interpolate import interp1d
# CSV Import
a1array=pd.read_csv('a1.c... | 8 | 2016-09-02T14:36:31Z | 39,352,147 | <p>I think your best bet is to use a colormap other than jet. Perhaps <code>cmap=plt.cmap.plasma</code>.</p>
<p><a href="http://i.stack.imgur.com/Vw0Gc.png" rel="nofollow"><img src="http://i.stack.imgur.com/Vw0Gc.png" alt="The same graph with the plasma colormap"></a></p>
<p>Wierd looking graphs obscure understanding... | 0 | 2016-09-06T14:58:21Z | [
"python",
"numpy",
"matplotlib"
] |
Matplotlib: How to increase colormap/linewidth quality in streamplot? | 39,294,987 | <p>I have the following code to generate a streamplot based on an <code>interp1d</code>-Interpolation of discrete data:</p>
<pre><code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from scipy.interpolate import interp1d
# CSV Import
a1array=pd.read_csv('a1.c... | 8 | 2016-09-02T14:36:31Z | 39,425,263 | <p>If you don't mind changing the <code>streamplot</code> code (<code>matplotlib/streamplot.py</code>), you could simply decrease the size of the integration steps. Inside <code>_integrate_rk12()</code> the maximum step size is defined as:</p>
<pre><code>maxds = min(1. / dmap.mask.nx, 1. / dmap.mask.ny, 0.1)
</code></... | 2 | 2016-09-10T10:46:01Z | [
"python",
"numpy",
"matplotlib"
] |
Matplotlib: How to increase colormap/linewidth quality in streamplot? | 39,294,987 | <p>I have the following code to generate a streamplot based on an <code>interp1d</code>-Interpolation of discrete data:</p>
<pre><code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from scipy.interpolate import interp1d
# CSV Import
a1array=pd.read_csv('a1.c... | 8 | 2016-09-02T14:36:31Z | 39,440,194 | <p>I had another look at this and it wasnt as painful as I thought it might be. </p>
<p>Add:</p>
<pre><code> subdiv = 15
points = np.arange(len(t[0]))
interp_points = np.linspace(0, len(t[0]), subdiv * len(t[0]))
tgx = np.interp(interp_points, points, tgx)
tgy = np.interp(interp_points, points, tgy... | 2 | 2016-09-11T20:10:57Z | [
"python",
"numpy",
"matplotlib"
] |
Matplotlib: How to increase colormap/linewidth quality in streamplot? | 39,294,987 | <p>I have the following code to generate a streamplot based on an <code>interp1d</code>-Interpolation of discrete data:</p>
<pre><code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from scipy.interpolate import interp1d
# CSV Import
a1array=pd.read_csv('a1.c... | 8 | 2016-09-02T14:36:31Z | 39,440,338 | <p>You could increase the <code>density</code> parameter to get more smooth color transitions,
but then use the <code>start_points</code> parameter to reduce your overall clutter.
The start_points parameter allows you to explicity choose the location and
number of trajectories to draw. It overrides the default, which ... | 1 | 2016-09-11T20:29:07Z | [
"python",
"numpy",
"matplotlib"
] |
Indentation Error for a loop | 39,295,051 | <p>I keep getting a IndentationError: expected an indented block. Why is this error occurring?</p>
<pre><code>import arcpy
from arcpy import env
env.workspace = r'D:\Programming\Lab1\lab1.gdb'
env.overwriteOutput = 1
env.qualifiedFieldNames = "UNQUALIFIED"
#list the feature classes
soils = arcpy.ListFeatureClasses()
... | -6 | 2016-09-02T14:39:14Z | 39,295,066 | <p>Python is expecting an indented block, which wasn't there:</p>
<pre><code>for soils in arcpy.ListFeatureClasses():
# here should be something
</code></pre>
<p>By providing some values we solve the problem, for example by putting <code>pass</code> value, which does nothing, but solves <code>IndentationError</co... | 4 | 2016-09-02T14:40:14Z | [
"python"
] |
Indentation Error for a loop | 39,295,051 | <p>I keep getting a IndentationError: expected an indented block. Why is this error occurring?</p>
<pre><code>import arcpy
from arcpy import env
env.workspace = r'D:\Programming\Lab1\lab1.gdb'
env.overwriteOutput = 1
env.qualifiedFieldNames = "UNQUALIFIED"
#list the feature classes
soils = arcpy.ListFeatureClasses()
... | -6 | 2016-09-02T14:39:14Z | 39,295,950 | <p>You are missing code inside your for loop.</p>
<p>Try:</p>
<pre><code>for soil in soils:
print(soil)
# or pass
</code></pre>
| 0 | 2016-09-02T15:27:15Z | [
"python"
] |
Find values in array and change them efficiently | 39,295,128 | <p>I am working with a large array with around 300 000 values. It has 100 000 rows and 3 columns. I am doing iterations with this array and if any value in the first column exceeds a limit of lets say 10, I want the number to be replaced. Is there any more efficient way than running something like this?:</p>
<pre><cod... | 2 | 2016-09-02T14:43:19Z | 39,295,320 | <p>If I understand you correctly you`re looking for something like that:</p>
<pre><code>>>> from numpy import array
>>> a = array([[1,2,3],[4,5,6],[7,8,9]])
>>> a
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
>>> a[a>5]=10 # <--- here the "magic" happens
>>... | 0 | 2016-09-02T14:52:29Z | [
"python",
"arrays"
] |
Find values in array and change them efficiently | 39,295,128 | <p>I am working with a large array with around 300 000 values. It has 100 000 rows and 3 columns. I am doing iterations with this array and if any value in the first column exceeds a limit of lets say 10, I want the number to be replaced. Is there any more efficient way than running something like this?:</p>
<pre><cod... | 2 | 2016-09-02T14:43:19Z | 39,295,334 | <p>Convert your array to a numpy array (<code>numpy.asarray</code>) then to replace the values you would use the following:</p>
<pre><code>import numpy as np
N = np.asarray(N)
N[N > 10] = 0
</code></pre>
<p><a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.asarray.html" rel="nofollow">nump... | 2 | 2016-09-02T14:52:56Z | [
"python",
"arrays"
] |
Find values in array and change them efficiently | 39,295,128 | <p>I am working with a large array with around 300 000 values. It has 100 000 rows and 3 columns. I am doing iterations with this array and if any value in the first column exceeds a limit of lets say 10, I want the number to be replaced. Is there any more efficient way than running something like this?:</p>
<pre><cod... | 2 | 2016-09-02T14:43:19Z | 39,295,368 | <p>I've assumed you may not want to use the same threshold/replacement value for each column. That being the case, you can pack the three items in a list of tuples and iterate through that.</p>
<pre><code>import numpy as np
arr = np.ndarray(your_array)
#Edited with your values, and a more than symbol
threshold = 10
c... | 1 | 2016-09-02T14:54:44Z | [
"python",
"arrays"
] |
Gradient clipping appears to choke on None | 39,295,136 | <p>I'm trying to add gradient clipping to my graph. I used the approach recommended here: <a href="http://stackoverflow.com/questions/36498127/how-to-effectively-apply-gradient-clipping-in-tensor-flow">How to effectively apply gradient clipping in tensor flow?</a></p>
<pre><code> optimizer = tf.train.GradientDescen... | 0 | 2016-09-02T14:44:00Z | 39,295,309 | <p>So, one option that seems to work is this:</p>
<pre><code> optimizer = tf.train.GradientDescentOptimizer(learning_rate)
if gradient_clipping:
gradients = optimizer.compute_gradients(loss)
def ClipIfNotNone(grad):
if grad is None:
return grad
return tf.... | 0 | 2016-09-02T14:51:22Z | [
"python",
"machine-learning",
"tensorflow"
] |
Can I use functions imported from .py files in Dask/Distributed? | 39,295,200 | <p>I have a question about serialization and imports. </p>
<ul>
<li>should functions have their own imports? <a href="https://docs.continuum.io/anaconda-scale/howto/spark-basic#modify-std-script" rel="nofollow">like I've seen done with PySpark</a></li>
<li>Is the following just plain wrong? Does <code>mod.py</code> ne... | 3 | 2016-09-02T14:46:49Z | 39,295,372 | <h3>Quick Answer</h3>
<p>Upload your mod.py file to all of your workers. You can do this using whatever mechanism you used to set up dask.distributed, or you can use the <a href="http://distributed.readthedocs.io/en/latest/api.html#distributed.executor.Executor.upload_file" rel="nofollow">upload_file</a> method</p>
... | 2 | 2016-09-02T14:54:49Z | [
"python",
"distributed-computing",
"dask"
] |
Using Flask web app as Windows application | 39,295,219 | <p>We have a web application developed using Flask that runs on a Windows server with clients that connect to it. We now have a use case where it is desired that the server and client be combined onto a laptop so that both server and client code run together and make it appear as a native Windows application.</p>
<p>... | 0 | 2016-09-02T14:47:54Z | 39,296,721 | <p>I do not currently have a Windows client here so I cannot exactly test what I am suggesting.</p>
<p>Using <strong>pywinauto</strong> you can check for a Window's name.</p>
<p>You could build a script that checks this in background and kills your Flask application when the requested browser window is not opened.</p... | 0 | 2016-09-02T16:09:50Z | [
"python",
"flask"
] |
Using Flask web app as Windows application | 39,295,219 | <p>We have a web application developed using Flask that runs on a Windows server with clients that connect to it. We now have a use case where it is desired that the server and client be combined onto a laptop so that both server and client code run together and make it appear as a native Windows application.</p>
<p>... | 0 | 2016-09-02T14:47:54Z | 39,351,372 | <p>After reading the docs more thoroughly and experimenting with the implementation, we found the following main code to satisfy the objective.</p>
<pre><code>from multiprocessing import Process, freeze_support
def run_browser():
import webbrowser
chrome = webbrowser.get(r'C:\\Program\ Files\ (x86)\\Google\\... | 0 | 2016-09-06T14:20:34Z | [
"python",
"flask"
] |
FIWARE Authentication in Python | 39,295,231 | <p>I am trying to authenticate user using FIWARE. It returns a 404 when I request the token, but I don't have problems to get access code request.
My code:</p>
<pre><code>class OAuth2(object):
def __init__(self):
self.client_id = "<client_id>"
self.client_secret = "<client_secret>"
... | 0 | 2016-09-02T14:48:20Z | 39,295,313 | <p>Try using POST method instead of GET</p>
| 0 | 2016-09-02T14:51:42Z | [
"python",
"authentication",
"fiware"
] |
FIWARE Authentication in Python | 39,295,231 | <p>I am trying to authenticate user using FIWARE. It returns a 404 when I request the token, but I don't have problems to get access code request.
My code:</p>
<pre><code>class OAuth2(object):
def __init__(self):
self.client_id = "<client_id>"
self.client_secret = "<client_secret>"
... | 0 | 2016-09-02T14:48:20Z | 39,328,038 | <p>Please, check that you are correctly sending the Authorization header</p>
| 0 | 2016-09-05T09:55:29Z | [
"python",
"authentication",
"fiware"
] |
Good way to input PASCAL-VOC 2012 training data and labels with tensorflow | 39,295,263 | <p>I want to do object detection of <a href="http://host.robots.ox.ac.uk/pascal/VOC/voc2012/index.html#introduction" rel="nofollow">PASCAL-VOC 2012 dataset</a> with tensorflow. </p>
<p>I want to input <strong>the whole image</strong> with <strong>object labels</strong> and the corresponding <strong>bounding boxes</str... | 0 | 2016-09-02T14:49:30Z | 39,312,792 | <p>It seems that TF have no support of xml files yet. </p>
<ol>
<li><p>You can try to make batches by yourself and feed them to TF placeholders.
<a href="https://www.tensorflow.org/versions/r0.10/how_tos/reading_data/index.html#feeding" rel="nofollow">https://www.tensorflow.org/versions/r0.10/how_tos/reading_data/ind... | 0 | 2016-09-04T01:34:40Z | [
"python",
"tensorflow",
"deep-learning"
] |
Why a filename is given closefd parameter of open() Function must be True in Python 3.5.2? | 39,295,337 | <p>In Python 3.5.2, when I give False value to closefd parameter of open() function with a filename, I get this error below:</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Cannot use closefd=False with file name
</code></pre>
<p>Results for me of my quest... | 0 | 2016-09-02T14:53:02Z | 39,295,513 | <p>In Python, <a href="https://docs.python.org/3/library/functions.html#open" rel="nofollow">open()</a> has two purposes:</p>
<ol>
<li>To open a given file from its name, or</li>
<li>To wrap a file descriptor representing an already open file.</li>
</ol>
<p>The second purpose is useful if you have a file descriptor a... | 1 | 2016-09-02T15:02:56Z | [
"python",
"python-3.x"
] |
QTextBrowser won't append link correctly if that link has equals sign inside it | 39,295,342 | <pre><code>class TextBrowser(QtGui.QTextBrowser):
def __init__(self, parent=None):
QtGui.QTextBrowser.__init__(self, parent)
self.setAcceptRichText(True)
self.setOpenExternalLinks(True)
self.insertHtml('<a href=' + 'https://www.google.com/#q=dfsdf'+'>' + 'gg' + '</a>')
... | 0 | 2016-09-02T14:53:11Z | 39,298,997 | <p>Always make sure html attributes are enclosed in double-quotes, otherwise special characters like <code>=</code> may be parsed wrongly. The html should look like this:</p>
<pre><code> <a href="https://www.google.com/#q=dfsdf">gg</a>
</code></pre>
| 2 | 2016-09-02T18:50:25Z | [
"python",
"python-2.7",
"qt",
"pyqt",
"qt4"
] |
How to see error for python application in gunicorn | 39,295,358 | <p>I have <a href="https://falcon.readthedocs.io/en/stable/index.html" rel="nofollow">falcon</a> application which is run with gunicorn. If there are errors in .py file it gives traceback, but in grunicorn it sends to console only:</p>
<pre><code>[2016-09-02 17:39:26 +0300] [6927] [INFO] Starting gunicorn 19.6.0
[2016... | 0 | 2016-09-02T14:53:52Z | 39,300,848 | <p>This is a problem with gunicorn log (not falcon). Sometimes it won't output the exception that generated the boot failure. So to debug my WSGI <code>app</code> what I usually do is to run the server with the test server provided by <code>wsgiref</code> as follows:</p>
<pre><code>from wsgiref import simple_server
i... | 0 | 2016-09-02T21:19:34Z | [
"python",
"error-handling",
"gunicorn",
"falconframework"
] |
How can I find out what Python distribution I am using from within Python? | 39,295,364 | <p>I'm using an application (QGIS) that can execute Python and can be extended with plugins written in Python. Depending on the platform, the installer of this application brings along its own Python distribution which it installs alongside the application to be used by the application. On other platforms, the installa... | 2 | 2016-09-02T14:54:15Z | 39,295,365 | <p>You can retrieve the path of the Python executable in use with <a href="https://docs.python.org/library/sys.html#sys.executable" rel="nofollow"><code>sys.executable</code></a>:</p>
<pre><code>import sys
print(sys.executable)
# e.g.
# /usr/bin/python2
# for the system Python 2 interpreter on Linux
</code></pre>... | 1 | 2016-09-02T14:54:15Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.