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
Command failed: tar xzf android-sdk_r20-linux.tgz
38,562,910
<p>I was trying to build kivy app to android and got this error</p> <pre><code># Check configuration tokens # Ensure build layout # Check configuration tokens # Preparing build # Check requirements for android # Install platform # Apache ANT found at /home/ali/.buildozer/android/platform/apache-ant-1.9.4 # Android SDK...
6
2016-07-25T08:28:13Z
38,613,838
<p>I figured it out!</p> <p>the problem was some google services are not available where i live due to USA sanctions on my country (Sudan) and the returned response is html (not in gzip format).</p> <p>the solution is to use vpn.</p>
2
2016-07-27T13:05:40Z
[ "android", "python", "kivy", "buildozer" ]
How to get sum of numbers having exactly 2 one's in their binary representation in a range?
38,562,982
<p>I want to find out the sum of numbers in a range say N which has exactly 2 ones in its binary representation.I wrote the code as:</p> <pre><code>N = int(raw_input()) sum1 = 0 for i in range(1, N + 1): if bin(i)[2:].count('1') == 2: sum1 = sum1 + i </code></pre> <p>This code takes a lot of time. Is there...
0
2016-07-25T08:32:02Z
38,563,347
<p>Try this code:</p> <pre><code>def two_bit_numbers(N): bit0 = 0 bit1 = 1 while True: n = (1&lt;&lt;bit1) + (1&lt;&lt;bit0) if n &gt; N: break yield n bit0 += 1 if bit0 == bit1: bit1 += 1 bit0 = 0 N = 100 sum1 = 0 for i in two_b...
4
2016-07-25T08:52:09Z
[ "python", "python-2.7" ]
How to get sum of numbers having exactly 2 one's in their binary representation in a range?
38,562,982
<p>I want to find out the sum of numbers in a range say N which has exactly 2 ones in its binary representation.I wrote the code as:</p> <pre><code>N = int(raw_input()) sum1 = 0 for i in range(1, N + 1): if bin(i)[2:].count('1') == 2: sum1 = sum1 + i </code></pre> <p>This code takes a lot of time. Is there...
0
2016-07-25T08:32:02Z
38,564,208
<p>If we look at how to find number that have two '1' when written in binary, we get to two cases : </p> <ul> <li>We have an element > 1 with 1 '1' in binary representation and we add 1 to it</li> <li>We have an element that has two '1' in binary representation, and we multiply it by 2.</li> </ul> <p>So, to look for...
-1
2016-07-25T09:33:14Z
[ "python", "python-2.7" ]
pip permission issue on OS X
38,562,987
<p>I can't automatically update <strong>pip</strong> because it alway show error with permission:</p> <pre><code>OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py' </code></pre> <p>Command for update:</p> <blockquote> <p>sudo -H pip freeze --local | grep -v '^...
0
2016-07-25T08:32:23Z
38,563,095
<p>The <code>sudo</code> command doesn't apply to the whole pipe; it only applies to the first <code>pip freeze</code> command.</p> <p>You'll need to use <code>sudo</code> on the <code>xargs</code> command too:</p> <pre><code>sudo -H pip freeze --local | grep -v '^-e' | cut -d = -f 1 | xargs sudo -H pip install -U </...
1
2016-07-25T08:38:36Z
[ "python", "osx", "pip" ]
OpenCV-Python cv2.CV_CAP_PROP_POS_FRAMES error
38,563,079
<p>Currently, I am use opencv 3.1.0, and I encountered the following error when executing the following code:</p> <pre><code>post_frame = cap.get(cv2.CV_CAP_PROP_POS_FRAMES) </code></pre> <p>I got the following error Message:</p> <p>File "videoOperation.py", line 37, in pos_frame = cap.get(cv2.CV_CAP_PROP_POS_F...
0
2016-07-25T08:37:38Z
38,566,846
<p>You're looking for this:</p> <pre><code>post_frame = cap.get(cv2.CAP_PROP_POS_FRAMES) </code></pre>
0
2016-07-25T11:43:03Z
[ "python", "opencv", "image-processing", "constants", "video-capture" ]
OpenCV-Python cv2.CV_CAP_PROP_POS_FRAMES error
38,563,079
<p>Currently, I am use opencv 3.1.0, and I encountered the following error when executing the following code:</p> <pre><code>post_frame = cap.get(cv2.CV_CAP_PROP_POS_FRAMES) </code></pre> <p>I got the following error Message:</p> <p>File "videoOperation.py", line 37, in pos_frame = cap.get(cv2.CV_CAP_PROP_POS_F...
0
2016-07-25T08:37:38Z
38,568,807
<p>Try typing this instead of yours:</p> <pre><code>post_frame = cap.get(1) #CAP_PROP_POS_FRAMES = 1 </code></pre> <p>If you type <code>help('cv2')</code> in the Python shell you will find some modifications to the syntax.These are not all the <code>Data</code>. Just an illustration.</p> <pre><code>CAP_PROP_PAN = 33...
0
2016-07-25T13:15:05Z
[ "python", "opencv", "image-processing", "constants", "video-capture" ]
Error while updating column in mysql using python
38,563,131
<p>Basically what my code does is simply update the database I have created where all the column are of 'varchar' format. My code is able to create a new entry when the time frame is '10:00-10:15'. However, when it is unable to update it when the time frame becomes '10:15-10:30' or basically any other time frame. My co...
0
2016-07-25T08:40:39Z
38,563,161
<p>You should set your value as an iterable:</p> <pre><code>value = (3,) # ^ </code></pre> <p>What you have <code>(3)</code> is an integer with a grouping parenthesis. The parenthesis does not make the integer an iterable. But adding that comma makes it a singleton tuple which is what you want.</p>
0
2016-07-25T08:42:12Z
[ "python", "mysql" ]
Timing out a function in windows(python)
38,563,164
<p>I want to implement a function which should be able to timeout a function after particular time.</p> <p>In Linux, SIGALRM is there to use, but in windows i could not find any thing like that. </p> <p>Is there any way i can achieve this in windows? Can it be done without decorator??</p> <p>Please Note Am a newbie ...
0
2016-07-25T08:42:18Z
38,563,273
<p>Unfortunately this isn't something natively built into windows. What you can do is a workaround whereby you create your own thread handler. </p> <p><a href="http://stackoverflow.com/questions/8420422/python-windows-equivalent-of-sigalrm">Described in a previous question here</a></p>
0
2016-07-25T08:48:50Z
[ "python" ]
Inception v3 retraining error (flower example)
38,563,173
<p>I'm currently facing a weird bug with the flower retraining example (<a href="https://www.tensorflow.org/versions/r0.9/how_tos/image_retraining/index.html" rel="nofollow">https://www.tensorflow.org/versions/r0.9/how_tos/image_retraining/index.html</a>).</p> <p>Tensorflow Release 0.9 was installed from source and I ...
1
2016-07-25T08:43:11Z
38,652,873
<p>This is a bug in TensorFlow that I have also encountered (I'm using 2x GTX 1080 in Ubuntu 14.04) </p> <p>One option is to install Cuda 8.0. However, Cuda 8.0 isn't fully supported and you may encounter other issues.</p> <p>Another way to work around this if you are just experimenting is to build it and run it on...
0
2016-07-29T07:25:05Z
[ "python", "tensorflow" ]
Python's equivalent of Java's Set.add()?
38,563,245
<p>Java's <code>Set.add</code> function will return a boolean value, which is <code>true</code> if the set did not already contain the specified element.</p> <p>Python's <code>Set.add</code> does not have a return value.</p> <p>Seems like in Python if I want to do the same thing, I have to check if it is in the set f...
1
2016-07-25T08:47:22Z
38,563,291
<p>No, Python's set implementation has no such method; as you noted you'll have to test for presence separately:</p> <pre><code>if obj not in setobj: setobj.add(obj) </code></pre> <p>or, what I usually do:</p> <pre><code>if obj in setobj: return # or break out of a loop, etc. # handle the case where the se...
2
2016-07-25T08:49:34Z
[ "java", "python", "set" ]
Python's equivalent of Java's Set.add()?
38,563,245
<p>Java's <code>Set.add</code> function will return a boolean value, which is <code>true</code> if the set did not already contain the specified element.</p> <p>Python's <code>Set.add</code> does not have a return value.</p> <p>Seems like in Python if I want to do the same thing, I have to check if it is in the set f...
1
2016-07-25T08:47:22Z
38,563,374
<p>The union operator is much faster than add anyway.</p> <pre><code>&gt;&gt;&gt; set_a = set('pqrs') &gt;&gt;&gt; set_b = ['t', 'u', 'v'] &gt;&gt;&gt; set_a |= set(set_b) &gt;&gt;&gt; set_a set(['p','q','r','s','t','u','v']) </code></pre>
-1
2016-07-25T08:53:34Z
[ "java", "python", "set" ]
Python's equivalent of Java's Set.add()?
38,563,245
<p>Java's <code>Set.add</code> function will return a boolean value, which is <code>true</code> if the set did not already contain the specified element.</p> <p>Python's <code>Set.add</code> does not have a return value.</p> <p>Seems like in Python if I want to do the same thing, I have to check if it is in the set f...
1
2016-07-25T08:47:22Z
38,563,459
<p>maybe with ternary conditional operator : </p> <pre><code>the_set.add(what_ever) or True if what_ever not in the_set else False </code></pre> <p>This will return False if <code>what_ever</code> was in the set, True if it wasn't</p>
-1
2016-07-25T08:57:39Z
[ "java", "python", "set" ]
Python's equivalent of Java's Set.add()?
38,563,245
<p>Java's <code>Set.add</code> function will return a boolean value, which is <code>true</code> if the set did not already contain the specified element.</p> <p>Python's <code>Set.add</code> does not have a return value.</p> <p>Seems like in Python if I want to do the same thing, I have to check if it is in the set f...
1
2016-07-25T08:47:22Z
38,563,651
<p>If you want a one-liner, you could use <code>or</code> to add the element only if it is not present, and <code>not</code> to inverse the returned value and at the same time coerce to <code>bool</code>:</p> <pre><code>&gt;&gt;&gt; s = set() &gt;&gt;&gt; not(42 in s or s.add(42)) True &gt;&gt;&gt; not(42 in s or s.ad...
3
2016-07-25T09:06:16Z
[ "java", "python", "set" ]
Python list notation, Numpy array notation: predictions[predictions < 1e-10] = 1e-10
38,563,377
<p>I am trying to find out operation applied on list. I have list/array name predictions and and executing following set of instruction.</p> <pre><code>predictions[predictions &lt; 1e-10] = 1e-10 </code></pre> <p>This code snippet is from a Udacity Machine Learning assignment that uses Numpy. </p> <p>It was used in ...
5
2016-07-25T08:53:40Z
38,563,484
<p>All elements of the array, for which the condition (element &lt; 1e-10) is true, are set to 1e-10. Practically you are setting a minimum value.</p>
1
2016-07-25T08:58:39Z
[ "python", "python-3.x", "numpy" ]
Python list notation, Numpy array notation: predictions[predictions < 1e-10] = 1e-10
38,563,377
<p>I am trying to find out operation applied on list. I have list/array name predictions and and executing following set of instruction.</p> <pre><code>predictions[predictions &lt; 1e-10] = 1e-10 </code></pre> <p>This code snippet is from a Udacity Machine Learning assignment that uses Numpy. </p> <p>It was used in ...
5
2016-07-25T08:53:40Z
38,563,615
<p>As pointed out by @MosesKoledoye, <code>predictions</code> is most likely a <code>numpy</code> array. </p> <p>A boolean array would then be generated using <code>predictions &lt; 1e-10</code>. At all indices where the boolean array set by the condition is <code>True</code>, the value will be changed to <code>1e-10<...
4
2016-07-25T09:04:56Z
[ "python", "python-3.x", "numpy" ]
OpenCV + Python - NameError: name 'imSize' is not defined
38,563,440
<p>I am using <code>OpenCV</code> for image processing. In which, I am getting these errors please suggest what to do, below is my code:</p> <pre><code>import dicom import Image import ImageOps meta=dicom.read_file("E:\A_SHIVA\ANANADAN\IM_0.dcm") imHeight=meta.Rows imWidth=meta.Columns imSize=(imWidth,imHeight) TT=...
-1
2016-07-25T08:56:52Z
38,566,188
<p>The code is fine. It worked for me. The name error exception happened because it could not find imSize variable, which means it never got made. This can only happen when you haven't read the Dicom file properly, so try changing the path and printing the variable 'meta' to see if it has any value. After reading the f...
0
2016-07-25T11:10:15Z
[ "python", "opencv" ]
Default python unittests returns false positives
38,563,477
<p>I have a python 2.7 project in visual studio using the python tools plugin.</p> <p>I have created a basic test generated by the Visual studio template,</p> <pre><code>import unittest class Test_test1(unittest.TestCase): def test_A(self): self.fail("Not implemented") if __name__ == '__main__': uni...
0
2016-07-25T08:58:24Z
38,568,990
<p>I have solved this issue now, the only solution I could find was to uninstall then reinstall the python tools for visual studio.</p>
0
2016-07-25T13:24:21Z
[ "python", "visual-studio", "python-2.7", "python-unittest", "test-explorer" ]
SVN/ PySVN: Get path to last changed files
38,563,570
<p>TL;DR Having an url to a SVN repo, how can I substract all the paths to the files that have been changed since a given revision number?</p> <p>Long Story: I have a script that downloads some files from a SVN repo. It does so every 'n' hours. But if I only changed one file, I do not need to re-download everything ag...
0
2016-07-25T09:02:43Z
38,568,744
<p>The summary makes me think that your are trying to re-invent a bicycle. Just checkout and update a working copy instead of exporting the data. That's the task of working copy and the update command.</p> <p>BTW, I'd better use the <a href="http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/swig/pyt...
0
2016-07-25T13:12:29Z
[ "python", "svn", "pysvn" ]
SVN/ PySVN: Get path to last changed files
38,563,570
<p>TL;DR Having an url to a SVN repo, how can I substract all the paths to the files that have been changed since a given revision number?</p> <p>Long Story: I have a script that downloads some files from a SVN repo. It does so every 'n' hours. But if I only changed one file, I do not need to re-download everything ag...
0
2016-07-25T09:02:43Z
38,973,462
<p>use pysvn.Client().log() to find all the changes. For example:</p> <pre><code>all_logs = pysvn.Client().log( path, revision_start=pysvn.Revision( opt_revision_kind.head ), revision_end=pysvn.Revision( opt_revision_kind.number, last_revision ), discover_changed_paths=True ) </code></pre> <p>This will alway...
1
2016-08-16T11:14:51Z
[ "python", "svn", "pysvn" ]
How to link Spark output to Logstash input
38,563,851
<p>I have a Spark Streaming job outputting some logs which are currently stored in HDFS, and I want to process them with logstash. Unfortunately it seems that although there is a plugin to write in hdfs for logstash, it is imposible to actually <strong>read</strong> from hdfs with it.</p> <p>I have search a solution t...
0
2016-07-25T09:14:44Z
38,568,981
<p>This seems like a perfect job to use <a href="http://kafka.apache.org/" rel="nofollow">Kafka</a> for. In your Spark Streaming job, write to Kafka, then consume the record from Logstash. </p> <pre><code>stream.foreachRDD { rdd =&gt; rdd.foreachPartition { partition =&gt; val producer = createKafkaProducer() ...
0
2016-07-25T13:24:02Z
[ "python", "apache-spark", "hdfs", "logstash", "spark-streaming" ]
The value on plot is not updated
38,563,896
<p>The value on the plot will be not updated. In my own class, I have one integrated from our community friends.The Plot won't show generated values!How could I turn on autoscale ?Further, I would like that x-axis to be moved during the program execute. For example, it shows always a last 10 seconds.</p> <pre><code>im...
0
2016-07-25T09:16:49Z
38,564,264
<p>I was looking at the code, is the line "plt.subplots()" correct? and there is another thing, in th following line, you write: "self.lines, =" maybe the comma should be off,can you confirm it? Good luck!</p>
0
2016-07-25T09:36:05Z
[ "python", "class", "canvas", "plot", "tkinter" ]
Default behavior of maplotlib imshow()
38,563,948
<p>In matplotlib, when using <code>imshow()</code>, the default behavior is to display the image with bilinear interpolation. </p> <p>I know I can change this explicitly by calling <code>imshow(...,interpolation='none')</code>. But this is cumbersome for many calls to <code>imshow</code>. </p> <p>How do I change the ...
1
2016-07-25T09:20:02Z
38,564,020
<p>Found it! Apparently, there's a dictionary controlling many aspects of matplotlib, called <code>rcParams</code>. Straight from <a href="http://matplotlib.org/users/customizing.html#dynamic-rc-settings" rel="nofollow">the matplotlib docs</a>:</p> <pre><code>import matplotlib as mpl mpl.rcParams['lines.linewidth'] =...
1
2016-07-25T09:23:24Z
[ "python", "matplotlib", "imshow" ]
Is it possible to display hyperlinks in a Tkinter message widget?
38,563,981
<p>I am creating a news feed program that uses the Feedparser module to read the Yahoo! RSS API, write key data to a text file, and then display the data organised in a Tkinter GUI.</p> <p>I was enquiring if it is possible to have clickable hyperlinks in a text file/Tkinter message widget.</p> <p>My current thinking ...
0
2016-07-25T09:21:29Z
38,564,117
<p>Most uses of hyperlinks in a tkinter application i have seen involved using the webbrowser and attaching events to your tkinter object to trigger callbacks, but there may be simpler ways, but heres what i mean :</p> <pre><code>from tkinter import * import webbrowser def callback(event): webbrowser.open_new(r"h...
1
2016-07-25T09:28:31Z
[ "python", "hyperlink", "tkinter", "rss", "feedparser" ]
Is it possible to display hyperlinks in a Tkinter message widget?
38,563,981
<p>I am creating a news feed program that uses the Feedparser module to read the Yahoo! RSS API, write key data to a text file, and then display the data organised in a Tkinter GUI.</p> <p>I was enquiring if it is possible to have clickable hyperlinks in a text file/Tkinter message widget.</p> <p>My current thinking ...
0
2016-07-25T09:21:29Z
38,564,229
<p><a href="http://i.stack.imgur.com/gbF8d.png" rel="nofollow"><img src="http://i.stack.imgur.com/gbF8d.png" alt="The output"></a></p> <p>I think it is easy to create hyperlink in tkinter using following link and its easy for modifying as per your requirement </p> <p><a href="http://effbot.org/zone/tkinter-text-hyper...
0
2016-07-25T09:34:18Z
[ "python", "hyperlink", "tkinter", "rss", "feedparser" ]
Using Pandas to Manipulate Multiple Columns
38,563,999
<p>I have a 30+ million row data set that I need to apply a whole host of data transformation rules to. For this task, I am trying to explore Pandas as a possible solution because my current solution isn't very fast.</p> <p>Currently, I am performing a row by row manipulation of the data set, and then exporting it to...
1
2016-07-25T09:22:21Z
38,564,067
<p>You can use list comprehension with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>concat</code></a> if need apply some function working only with <code>Series</code>:</p> <pre><code>import pandas as pd data = pd.DataFrame({'A':[' ff ','2','3'], ...
2
2016-07-25T09:25:52Z
[ "python", "pandas" ]
python VTK context menu not at mouse position
38,564,063
<p>I am having problems with the context menu position in VTK with PyQt. The main GUI window has set the VTK widget as central widget:</p> <pre><code>from vtk_widget.vtk_widget import VTKWidget class DySMainWindow(QtGui.QMainWindow): def __init__(self): self.vtk_widget = VTKWidget(self) self.setC...
0
2016-07-25T09:25:48Z
38,586,895
<p>The contextmeny event method takes a point as an input. If we assume that your menu is called qMenuVTK and you have a parent window, the following should work:</p> <p>In your rightbuttonpressevent add the following:</p> <pre class="lang-py prettyprint-override"><code>self.parent.setContextMenuPolicy(QtCore.Qt.Cust...
1
2016-07-26T10:06:26Z
[ "python", "pyqt", "vtk", "qvtkwidget" ]
how to calculate short path geodesic distance of adjacency matrix csv [python]?
38,564,308
<p>i have an adjacency matrix of graph </p> <p><a href="http://i.stack.imgur.com/IBom1.png" rel="nofollow">graph</a></p> <blockquote> <p>n 1 2 3 4 5 6 7 8 9</p> <p>1 0 1 1 1 0 0 0 0 0</p> <p>2 1 0 1 0 0 0 0 0 0</p> <p>3 1 1 0 1 0 0 0 0 0</p> <p>4 ...
0
2016-07-25T09:38:33Z
38,823,024
<p><code>networkx</code> can calculate the whole matrix. One just need not to give source or destination to the <code>nx.shortest_path</code> function (see <a href="https://networkx.github.io/documentation/networkx-1.10/reference/generated/networkx.algorithms.shortest_paths.generic.shortest_path.html" rel="nofollow">ht...
0
2016-08-08T07:01:54Z
[ "python", "csv", "matrix", "shortest-path", "adjacency-matrix" ]
How to replace invalid unicode characters in a string in Python?
38,564,456
<p>As far as I know it is the concept of python to have only valid characters in a string, but in my case the OS will deliver strings with invalid encodings in path names I have to deal with. So I end up with strings that contain characters that are non-unicode.</p> <p>In order to correct these problems I need to disp...
0
2016-07-25T09:45:42Z
38,564,967
<p>Thanks to you for your comments. This way I was able to implement a better solution:</p> <pre><code> try: s2 = codecs.encode(s, "utf-8") return (True, s, None) except Exception as e: ret = codecs.decode(codecs.encode(s, "utf-8", "replace"), "utf-8") return (False, ret, e) </co...
0
2016-07-25T10:11:22Z
[ "python", "string", "unicode", "character-encoding" ]
How to replace invalid unicode characters in a string in Python?
38,564,456
<p>As far as I know it is the concept of python to have only valid characters in a string, but in my case the OS will deliver strings with invalid encodings in path names I have to deal with. So I end up with strings that contain characters that are non-unicode.</p> <p>In order to correct these problems I need to disp...
0
2016-07-25T09:45:42Z
38,564,992
<p>You have not given any example. Therefore I have considered one example to answer your question.</p> <p>x='This is a cat which looks good 😊' print x x.replace('😊','')</p> <p>output is: This is a cat which looks good 😊 'This is a cat which looks good '</p>
0
2016-07-25T10:12:04Z
[ "python", "string", "unicode", "character-encoding" ]
How to replace invalid unicode characters in a string in Python?
38,564,456
<p>As far as I know it is the concept of python to have only valid characters in a string, but in my case the OS will deliver strings with invalid encodings in path names I have to deal with. So I end up with strings that contain characters that are non-unicode.</p> <p>In order to correct these problems I need to disp...
0
2016-07-25T09:45:42Z
38,565,489
<p>If you have a <em>bytestring</em> (undecoded data), use the <code>'replace'</code> error handler. For example, if your data is (mostly) UTF-8 encoded, then you could use:</p> <pre><code>decoded_unicode = bytestring.decode('utf-8', 'replace') </code></pre> <p>and <a href="https://codepoints.net/U+FFFD" rel="nofollo...
0
2016-07-25T10:36:12Z
[ "python", "string", "unicode", "character-encoding" ]
Strange error in a PyCOMPSs application: Script without last "y" not found
38,564,536
<p>I am trying to run one of the example pyCOMPSs application with version 1.4 and I am getting the following error, which says that the python script without the final "y" can not be found. Do you have any idea what could be the error?</p> <pre><code>xxx:~/xxx_xx/python/increment&gt; runcompss --lang=python increment...
4
2016-07-25T09:49:41Z
38,564,625
<p>You have miss the ./ or the absolute pathe before the python script</p> <pre><code>runcompss --lang=python ./increment.py 3 1 2 3 </code></pre> <p>or </p> <pre><code>runcompss --lang=python /path/to/script/increment.py 3 1 2 3 </code></pre>
4
2016-07-25T09:54:09Z
[ "python", "distributed-computing", "hpc", "compss", "pycompss" ]
Run c++ class from python
38,564,620
<p>Is there a way to <strong>run a c++ class from python without using any external libraries</strong> like Boost.Python, SWING ect? I don't want to pass any arguments to this class or call a specific method and in my c++ class I have only a void main method, I just want to run the main and that is all.</p> <p>Or if t...
-4
2016-07-25T09:53:54Z
38,564,697
<blockquote> <p>is there a way to run a c++ class</p> </blockquote> <p>you don't run C++ classes. They are data types!</p> <blockquote> <p>Boost.Python, SWING</p> </blockquote> <p>It's called SWIG, not SWING :)</p> <p>You can add your own C wrapper code that initializes a PyObject. I'd recommend reading the CPy...
1
2016-07-25T09:57:31Z
[ "python", "c++" ]
Python Argparse usage instructions
38,564,644
<p>I'am trying to write a function which can parse 1 or 2 ip addresses &amp; a searchterm.</p> <pre><code>For example: ./system.py 172.16.19.152,172.16.19.153 model\ name Output: Search term: model name Server: 172.16.19.152 Results: Processor 0: model name : Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz Server: 172.16.19...
1
2016-07-25T09:55:03Z
38,565,171
<p>To resume, you can use argparse as below.</p> <pre><code>parser = argparse.ArgumentParser() parser.add_argument('--IP', nargs=2) parser.add_argument('--TERM', nargs=1) </code></pre>
0
2016-07-25T10:20:38Z
[ "python", "argparse" ]
Python Argparse usage instructions
38,564,644
<p>I'am trying to write a function which can parse 1 or 2 ip addresses &amp; a searchterm.</p> <pre><code>For example: ./system.py 172.16.19.152,172.16.19.153 model\ name Output: Search term: model name Server: 172.16.19.152 Results: Processor 0: model name : Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz Server: 172.16.19...
1
2016-07-25T09:55:03Z
38,565,185
<pre><code>import argparse parser = argparse.ArgumentParser() parser.add_argument('ips',metavar='IP',nargs='+') parser.add_argument('search_term',metavar='SEARCH\\ TERM',nargs=1) </code></pre> <p>The <code>metavar</code> keyword will be used in the usage text for your program. The double backslash is used for escapin...
2
2016-07-25T10:21:20Z
[ "python", "argparse" ]
wxPython layout using boxsizers
38,564,654
<p>I've recently started using wxPython to build a GUI and I'm trying to create the following layout:</p> <pre><code>Button1 Button2 Button3 ---------------------------------------- listbox | textctrl </code></pre> <p>The buttons should have a flexible width, expanding to fill the full width of the frame with a borde...
0
2016-07-25T09:55:27Z
38,585,615
<p>It is working for me, I'm on win64, python 32bit 2.7.3.3, wx '2.8.12.1 (msw-unicode)'. The full working test example is:</p> <pre><code>import wx class testframe(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'some title') mainPanel = wx.Panel(self, -1) parentBox = wx....
0
2016-07-26T09:08:49Z
[ "python", "python-2.7", "wxpython" ]
Selenium clicking on link before it's visible
38,564,702
<p>I'm running into a problem where Selenium is clicking on a link before it's being displayed on the screen.</p> <p>I've tried using both:</p> <pre><code>WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID,('menu-link-dashboard')))) </code></pre> <p>and</p> <pre><code>WebDriverWait(self.driver,...
0
2016-07-25T09:57:52Z
38,565,182
<p>I managed to solve it. The problem was caused because I was waiting for the link to be visible. I actually needed to wait for the home page to be visible (which only happened 2 seconds after the menu links were visible).</p> <p>I changed the Webdriverwait to be performed on an object on the home page instead.</p>
0
2016-07-25T10:21:14Z
[ "python", "selenium" ]
Selenium with Python - Switching to main content after popup overlay
38,564,738
<p>After handling a pop up overlay the rest of the code no longer works.</p> <pre><code>from selenium import webdriver browser = webdriver.Firefox() browser.get('https://www.vapordna.com/login.asp') #handling popup browser.find_element_by_css_selector("div.age-verify-button.age-modal__btn.btn.btn-primary").click() ...
0
2016-07-25T09:59:49Z
38,564,923
<p>After seeing your website I observe this is neither an frame nor a window, I just a form so there is <strong>no need</strong> to use here <code>browser.switchTo().defaultContent();</code> which actually using for switching from any frame to default, Actually when you are going to find this button on the opened popup...
0
2016-07-25T10:09:15Z
[ "python", "selenium", "selenium-webdriver" ]
Python 3.5 | Scraping data from website
38,564,754
<p>I want to scrape a specific part of the website <a href="https://www.kickstarter.com/discover/categories/technology?ref=discover_index" rel="nofollow">Kickstarter.com</a></p> <p>I need the strings of the Project-title. The website is structured and every project has this line.</p> <p><div class="snippet" data-lang...
4
2016-07-25T10:00:40Z
38,565,858
<p><code>find()</code>only returns one element. To get all, you must use <code>findAll</code></p> <p>Here's the code you need</p> <pre><code>project_elements = soup.findAll('h6', {'class': 'project-title'}) project_titles = [project.findChildren('a')[0].text for project in project_elements] print(project_titles) </co...
2
2016-07-25T10:54:28Z
[ "python", "python-3.x", "beautifulsoup", "python-3.5" ]
Python 3.5 | Scraping data from website
38,564,754
<p>I want to scrape a specific part of the website <a href="https://www.kickstarter.com/discover/categories/technology?ref=discover_index" rel="nofollow">Kickstarter.com</a></p> <p>I need the strings of the Project-title. The website is structured and every project has this line.</p> <p><div class="snippet" data-lang...
4
2016-07-25T10:00:40Z
38,565,982
<p>All the data you want is in the section with the css class <em>staff-picks</em>, just find the <em>h6's</em> with the <em>project-title</em> class and extract the text from the anchor tag inside:</p> <pre><code>soup = BeautifulSoup(thepage,"html.parser") print [a.text for a in soup.select("section.staff-picks h6....
0
2016-07-25T11:00:31Z
[ "python", "python-3.x", "beautifulsoup", "python-3.5" ]
Python 3.5 | Scraping data from website
38,564,754
<p>I want to scrape a specific part of the website <a href="https://www.kickstarter.com/discover/categories/technology?ref=discover_index" rel="nofollow">Kickstarter.com</a></p> <p>I need the strings of the Project-title. The website is structured and every project has this line.</p> <p><div class="snippet" data-lang...
4
2016-07-25T10:00:40Z
38,584,902
<p>With respect to the title of this post i would recommend you two different tutorial based on scraping particular data from a website . They do have a detailed explanation regarding how the task is achieved.</p> <p>Firstly i would recommend to checkout pyimagesearch <a href="http://www.pyimagesearch.com/2015/10/12/s...
1
2016-07-26T08:37:19Z
[ "python", "python-3.x", "beautifulsoup", "python-3.5" ]
Pandas: replace values in column
38,564,756
<p>I have df and I want to replace values there</p> <pre><code>df = pd.read_csv('visits_april.csv') df1 = pd.read_csv('participants.csv')` url, date aliexpress.com/payment/payment-result.htm... 2016-04-30 22:57:41 shoppingcart.aliexpress.com/order/confirm_orde... 2016-04-30 23:05:21 shoppingcart.aliexpress.c...
1
2016-07-25T10:00:53Z
38,565,006
<p>You can <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.extract.html" rel="nofollow"><code>extract</code></a> joined list with <code>|</code> (regex <code>or</code>) from column <code>visits</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.tolist...
2
2016-07-25T10:12:58Z
[ "python", "pandas", "replace", "dataframe" ]
django foreign key of foreign key but can't show in admin page
38,564,758
<p>I get a problem with the models.py and views.py. When user add a reply to comment, the "Dish_comment_reply_post" always show nothing, I need select by myself in admin page. Please give me a hand...</p> <p>models.py:</p> <pre><code>class Dish_comment(models.Model): Dish_comment_post=models.ForeignKey('dish.Dis...
0
2016-07-25T10:00:59Z
38,565,665
<p>change <code>Dish_comment_post=models.ForeignKey('dish.Dish_post', related_name='comments')</code> to <code>Dish_comment_post=models.ForeignKey('Dish_post', related_name='comments')</code> and <code>Dish_comment_reply_post=models.ForeignKey('dish.Dish_comment', related_name='replies', null=True)</code> to <code>D...
0
2016-07-25T10:44:52Z
[ "python", "django" ]
Synchronizing Django social auth with User registration
38,564,782
<p>I created a django project which has separate User registration form and uses <strong>python-social-auth</strong> for direct login. Whenever I try to login with social_auth which uses the email id which I already used for creating a account through registration form, a separate row has been inserted instead of usin...
1
2016-07-25T10:01:58Z
38,565,269
<p>I think adding <code>associate_user</code> to <code>SOCIAL_AUTH_PIPELINE</code> was designed to fix this:</p> <pre><code>SOCIAL_AUTH_PIPELINE = ( ... 'social.pipeline.social_auth.associate_by_email', 'social.pipeline.user.create_user', 'social.pipeline.social_auth.associate_user', # &lt;------ '...
0
2016-07-25T10:25:51Z
[ "python", "django", "user-accounts", "python-social-auth" ]
Synchronizing Django social auth with User registration
38,564,782
<p>I created a django project which has separate User registration form and uses <strong>python-social-auth</strong> for direct login. Whenever I try to login with social_auth which uses the email id which I already used for creating a account through registration form, a separate row has been inserted instead of usin...
1
2016-07-25T10:01:58Z
38,566,634
<p>When you are using social auth it has separate table 'social_auth_usersocialauth' it gets filled when you call the login for the first time, social auth work in such a way that if it doesn't have an entry in 'social_auth_usersocialauth' it creates a new entry in it and it assumes that you are login it for the first ...
0
2016-07-25T11:32:38Z
[ "python", "django", "user-accounts", "python-social-auth" ]
django.db.utils.OperationalError no matter what I try
38,564,851
<p>OK, I'm stumped. I think I've tried everything. </p> <p>I created a model in an app's <code>models.py</code> and also added some more fields to an existing model (all with default values). Then I ran <code>makemigrations</code>. The result:</p> <pre><code>$ python3 manage.py makemigrations Traceback (most rece...
0
2016-07-25T10:05:29Z
38,604,017
<p>I figured it out! Lesson learned: read the whole stacktrace, not just the last line. In this case, the offensive line was in my <code>views.py</code>: </p> <pre><code>File "/path/to/myproject/myapp/views.py", line 8, in &lt;module&gt; existing_model = MyExistingModel.objects.all()[0] </code></pre> <p>Like I sa...
0
2016-07-27T04:55:24Z
[ "python", "django", "python-3.x", "django-models", "mezzanine" ]
Python BeautifulSoup only select top tag
38,565,096
<p>I encounter a problem, it might be very easy, but I didn't saw it on document.</p> <p>Here is the target html structure, very simple.</p> <pre><code>&lt;h3&gt;Top &lt;em&gt;Mid&lt;/em&gt; &lt;span&gt;Down&lt;/span&gt; &lt;/h3&gt; </code></pre> <p>I want to get the "Top" text which was inside the <code>h...
1
2016-07-25T10:17:22Z
38,565,191
<p>Try something like this:</p> <pre><code>from bs4 import BeautifulSoup html ="&lt;h3&gt;Top &lt;em&gt;Mid &lt;/em&gt;&lt;span&gt;Down&lt;/span&gt;&lt;/h3&gt;" soup = BeautifulSoup(html) print soup.select("h3").findChildren()[0] </code></pre> <p>Though I am not entirely sure. Check this as well - <a href="http://sta...
0
2016-07-25T10:21:46Z
[ "python", "html", "beautifulsoup" ]
Python BeautifulSoup only select top tag
38,565,096
<p>I encounter a problem, it might be very easy, but I didn't saw it on document.</p> <p>Here is the target html structure, very simple.</p> <pre><code>&lt;h3&gt;Top &lt;em&gt;Mid&lt;/em&gt; &lt;span&gt;Down&lt;/span&gt; &lt;/h3&gt; </code></pre> <p>I want to get the "Top" text which was inside the <code>h...
1
2016-07-25T10:17:22Z
38,565,440
<p>its easy for you to search using a regex something like this </p> <pre><code> pageid=re.search('&lt;h3&gt;(.*?)&lt;/h3&gt;', curPage, re.DOTALL) </code></pre> <p>and get the each of the data inside the tag using <code>pageid.group(value)</code> method</p>
-1
2016-07-25T10:34:22Z
[ "python", "html", "beautifulsoup" ]
Python BeautifulSoup only select top tag
38,565,096
<p>I encounter a problem, it might be very easy, but I didn't saw it on document.</p> <p>Here is the target html structure, very simple.</p> <pre><code>&lt;h3&gt;Top &lt;em&gt;Mid&lt;/em&gt; &lt;span&gt;Down&lt;/span&gt; &lt;/h3&gt; </code></pre> <p>I want to get the "Top" text which was inside the <code>h...
1
2016-07-25T10:17:22Z
38,565,739
<p>You can use <em>find</em> setting <em>text=True</em> and <em>recursive=False</em>:</p> <pre><code>In [2]: from bs4 import BeautifulSoup ...: html ="&lt;h3&gt;Top &lt;em&gt;Mid &lt;/em&gt;&lt;span&gt;Down&lt;/span&gt;&lt;/h3&gt;" ...: soup = BeautifulSoup(html,"html.parser") ...: print(soup.find("h3").find(...
1
2016-07-25T10:48:45Z
[ "python", "html", "beautifulsoup" ]
How to name list of lists in Python?
38,565,104
<p>I have the following list of lists: </p> <pre><code>sims1 = [[(2, 0.90452874), (1, 0.83522302), (4, 0.77591574), (0, 0.72705799), (3, 0.52282226)], [(3, 0.79298556), (1, 0.78112978), (2, 0.76006395), (0, 0.58570701), (4, 0.40093967)], [(2, 0.9549554), (1, 0.71705657), (0, 0.58731651), (3, 0.43987...
0
2016-07-25T10:17:43Z
38,565,168
<p>Use <code>zip()</code> and <code>dict()</code>:</p> <pre><code>result = dict(zip(url, sims1)) </code></pre> <p>Make sure that the elements in <code>url</code> are strings like <code>'a'</code> rather than a variable name like <code>a</code>, or the definition of <code>url</code> will fail with a <code>NameError</c...
1
2016-07-25T10:20:27Z
[ "python", "arrays", "list" ]
How to name list of lists in Python?
38,565,104
<p>I have the following list of lists: </p> <pre><code>sims1 = [[(2, 0.90452874), (1, 0.83522302), (4, 0.77591574), (0, 0.72705799), (3, 0.52282226)], [(3, 0.79298556), (1, 0.78112978), (2, 0.76006395), (0, 0.58570701), (4, 0.40093967)], [(2, 0.9549554), (1, 0.71705657), (0, 0.58731651), (3, 0.43987...
0
2016-07-25T10:17:43Z
38,565,188
<p>You can use dictionary:</p> <pre><code>names = ['a', 'b', 'c', 'd', 'e'] named_sims1 = dict(zip(names, sims1)) print(named_sims1['a']) </code></pre> <p>If you want to access the variables as <code>a</code> instead of <code>x.a</code> or x['a'], you can use this:</p> <pre><code>exec(",".join(names) + ' = ' + str(s...
3
2016-07-25T10:21:27Z
[ "python", "arrays", "list" ]
Regex replacement for strip()
38,565,110
<p>Long time/first time.</p> <p>I am a pharmacist by trade by am going through the motions of teaching myself how to code in a variety of languages that are useful to me for things like task automation at work, but mainly Python 3.x. I am working through the automatetheboringstuff eBook and finding it great. </p> <p>...
1
2016-07-25T10:17:53Z
38,565,208
<p>You <code>(.+)</code> is greedy, (by default). Just change it to non greedy, by using <code>(.+?)</code><br> You can test python regex at <a href="https://regex101.com/#python" rel="nofollow">this site</a></p> <p>edit : As someone commented, <code>(.+?)</code> and <code>(.+)?</code> do not do the same thing : <code...
3
2016-07-25T10:22:35Z
[ "python", "regex", "python-3.x" ]
Regex replacement for strip()
38,565,110
<p>Long time/first time.</p> <p>I am a pharmacist by trade by am going through the motions of teaching myself how to code in a variety of languages that are useful to me for things like task automation at work, but mainly Python 3.x. I am working through the automatetheboringstuff eBook and finding it great. </p> <p>...
1
2016-07-25T10:17:53Z
38,565,745
<p>As I mentioned in my comment, you did not include special chars into the character class.</p> <p>Also, the <code>.*</code> without a <code>re.S</code> / <code>re.DOTALL</code> modifier does not match newlines. You may avoid using it with <code>^PATTERN|PATTERN$</code> or <code>\APATTERN|PATTERN\Z</code> (note that ...
1
2016-07-25T10:49:00Z
[ "python", "regex", "python-3.x" ]
Zoom action in android using appium-python-client
38,565,116
<p>Does anybody know how to zoom an element in android via appium python client?</p> <p>I am currently using</p> <p><code>self.driver.zoom(self.element, percent)</code> but this gives an error</p> <pre><code>self.driver.zoom(self.element, percent) File "/usr/local/lib/python2.7/site-packages/appium/webdriver/webdriv...
7
2016-07-25T10:18:20Z
38,614,216
<p>The MultiAction attempt looks good, but after testing a bit on my phone's native camera app, I was able to get a nice zoom gesture by adding 500ms wait() after the moveTo():</p> <pre><code># Zoom action1.long_press(x=xx, y=yy).move_to(x=0, y=50).wait(500).release() action2.long_press(x=xx, y=yy).move_to(x=0, y=-50)...
4
2016-07-27T13:21:37Z
[ "android", "python", "zoom", "appium", "python-appium" ]
Kivy Launcher orientation
38,565,231
<p>Just a quick question: Is it possible to enable both portrait and landscape mode in androind.txt for app run via Kivy Launcher?</p> <p>I've seen that for buldozer there are "portrait/landscape/all" parameters available but it doesn't seem to work for Kivy Launcher</p>
0
2016-07-25T10:24:04Z
38,669,257
<p>Afaik, <code>orientation=all</code> or similar thing in <code>android.txt</code> does for launcher nothing, because it maybe needs some initial orientation(?) in the beginning and rotating isn't implemented maybe?. I'd go for not implemented, because the launcher itself can rotate in all types of orientation.</p> <...
0
2016-07-30T00:35:15Z
[ "python", "kivy" ]
Python Read ethernet frames using socket on Windows?
38,565,335
<p>I'm trying to read Ethernet (IEEE 802.2 / 3) frames using primarily <code>socket</code>. The application shuld just sniff ethernet frames and depending on the content, act on it. However, there are almost no information on how to do this on Windows, the default (unix way) being <code>socket.socket(socket.AF_PACKET,...
0
2016-07-25T10:28:41Z
38,565,421
<p>Python's socket doesn't come with sniffing capabilites. Simple as that.</p> <p>The idea of having a network stack in your operating system is that programs "register" for specific types of packets to be delivered to them – typically, this is something like listening on a IP port, ie. one to two levels above raw e...
0
2016-07-25T10:33:34Z
[ "python", "windows", "sockets", "ethernet" ]
Can't install PyAL in Pycharm
38,565,378
<p>I wanted to use OpenAL in Python, therefore I tried to install <strong>PyAL</strong> through the Pycharm project settings. </p> <p>I got the error message: </p> <pre><code>No matching distribution found for PyAL s the requirement PyAL (from version: ) </code></pre> <p>Is this a known issue or am I doing something...
1
2016-07-25T10:31:13Z
38,565,404
<p>There is no source or binary distribution for <a href="https://pypi.python.org/pypi/PyAL" rel="nofollow">PyAL</a></p> <p>Maybe you should download it from <a href="https://bitbucket.org/marcusva/py-al/downloads" rel="nofollow">bitbucket</a></p> <p>The homepage sais:</p> <blockquote> <p>PyAL is easy to install a...
0
2016-07-25T10:32:38Z
[ "python", "pycharm", "python-3.5", "openal" ]
Tensorflow - transfer learning implementation (semantic segmentation)
38,565,497
<p>I'm working on implementing a CNN architecture (FCN-8s model, with pretrained VGG16 model) for semantic segmentation on my own data (2 classes, therefore, a binary per-pixel classification)</p> <p>How I intend to go about this is:</p> <ol> <li>Load the pre-trained model with weights</li> <li>Add/remove additional ...
0
2016-07-25T10:36:55Z
38,568,258
<p>You could just pass the output of the pretrained model into sess.run(pretrained_output, ...) and capture the output of the pretrained model. After you save the output you could then feed it into your model. In this case the optimizer would not be able to propagate the gradients to the pretrained model. </p> <p>Y...
1
2016-07-25T12:49:43Z
[ "python", "tensorflow", "image-segmentation", "pre-trained-model" ]
Pandas: European style date_range
38,565,592
<p>I am trying to generate <code>date_range</code> in European style <code>dd/mm/yyyy</code></p> <pre><code>import pandas as pd rng = pd.date_range(start = '1/09/2016', periods = 10, dayfirst = True) </code></pre> <p>The output is as follows:</p> <pre><code>DatetimeIndex(['2016-01-09', '2016-01-10', '2016-01-11', '...
1
2016-07-25T10:40:56Z
38,565,644
<p>You can use only <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DatetimeIndex.strftime.html" rel="nofollow"><code>DatetimeIndex.strftime</code></a>, but lost <code>DatetimeIndex</code> and get <code>list</code> of <code>strings</code>:</p> <pre><code>print (rng.strftime('%d/%m/%Y')) ['09/01/2...
0
2016-07-25T10:43:42Z
[ "python", "python-2.7", "pandas", "date-range" ]
Boolean expression is producing a "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"
38,565,606
<p>When running the following code, I get the Error message "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()" </p> <pre><code>import random import numpy as np nx, ny = (32, 32) xaxis = np.linspace(-310, 310, nx) yaxis = np.linspace(-310, 310, ny) xys = np.dsta...
0
2016-07-25T10:41:44Z
38,568,944
<p>I think your problem is that absX has a bunch of numbers and x_rand+width only is one. Your x_rand &lt;= absX returns an array. Apply np.all (or any) to that, and then the test against x_rand + width, e.g. <code>np.all(x_rand &lt;= absX) &lt; x_rand+width</code>.</p>
1
2016-07-25T13:22:07Z
[ "python", "numpy", "boolean-expression" ]
Python: pause function but not whole program
38,565,613
<p>I have two function, which generate random integer, and sleep for the given interval. However, I would like to sleep those two functions independently, while <code>time.sleep()</code> pauses the whole Python program. </p> <pre><code>def fun1(): interval1 = random.randint(2,800) time.sleep(interval1) # do other t...
1
2016-07-25T10:42:04Z
38,565,796
<p>Simply do like this:</p> <pre><code>from threading import Thread thread1 = Thread(target=fun1) thread2 = Thread(target=fun2) thread1.start() thread2.start() </code></pre> <p>This will start two threads which are independent of the main thread, calling <code>fun1</code> and <code>fun2</code> respectively.</p> <p>E...
1
2016-07-25T10:50:54Z
[ "python", "multithreading", "python-2.7", "sleep" ]
Python: pause function but not whole program
38,565,613
<p>I have two function, which generate random integer, and sleep for the given interval. However, I would like to sleep those two functions independently, while <code>time.sleep()</code> pauses the whole Python program. </p> <pre><code>def fun1(): interval1 = random.randint(2,800) time.sleep(interval1) # do other t...
1
2016-07-25T10:42:04Z
38,565,999
<p>Try this:</p> <pre><code>from multiprocessing import Process def fun1(): interval1 = random.randint(2,800) time.sleep(interval1) # do other things def fun2(): interval2 = random.randint(1, 999) time.sleep(interval2) # do other things proc1 = Process(target=fun1) proc2 = Process(target=fun...
1
2016-07-25T11:01:19Z
[ "python", "multithreading", "python-2.7", "sleep" ]
How to place ListBox object at text cursor position
38,565,617
<p>I have a code editor, that can autocomplete and give hints of code like the picture below</p> <p><a href="http://i.stack.imgur.com/2O9bI.png" rel="nofollow"><img src="http://i.stack.imgur.com/2O9bI.png" alt="Example picture"></a></p> <p>I was able to create a list of Autocompletion words and was able to filter dow...
0
2016-07-25T10:42:09Z
38,579,296
<p>The winconfig_event function in IDLE's AutoCompleteWindow / autocomplete_w (pre3.6 / current 3.6) module has this code.</p> <pre><code> text = self.widget text.see(self.startindex) x, y, cx, cy = text.bbox(self.startindex) acw = self.autocompletewindow acw_width, acw_height = acw.winfo_width(), a...
0
2016-07-26T00:21:33Z
[ "python", "text", "tkinter", "autocomplete", "listbox" ]
django api for create data in db
38,565,706
<p>every one, I am trying to wrote an django api to create data in db ,here is my </p> <h3>models.py</h3> <pre><code>class ProductsTbl(models.Model): model_number = models.CharField( max_length=255, blank=True, unique=True, error_messages={ 'unique': "這 model number ...
1
2016-07-25T10:47:03Z
38,602,209
<p>the <code>api_create</code> method seems to be totally redundant and can be deleted safely. Your urls.py should instead point to the <code>create_thing</code> method in views.py</p> <pre><code>urlpatterns = [ ..... url(r'^productsTbls/create_thing/$',views.create_thing,name='api_create_t'), ] </code></pre> ...
1
2016-07-27T01:14:03Z
[ "python", "django", "api" ]
Subset of dictionary keys
38,565,727
<p>I've got a python dictionary of the form <code>{'ip1:port1' : &lt;value&gt;, 'ip1:port2' : &lt;value&gt;, 'ip2:port1' : &lt;value&gt;, ...}</code>. Dictionary keys are strings, consisting of ip:port pairs. Values are not important for this task.</p> <p>I need a list of <code>ip:port</code> combinations with unique ...
4
2016-07-25T10:48:00Z
38,565,965
<p>You can use <a href="https://docs.python.org/3/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a> to group by same IP addresses:</p> <pre><code>data = {'ip1:port1' : "value1", 'ip1:port2' : "value2", 'ip2:port1' : "value3", 'ip2:port2': "value4"} by_ip = {k: list(g) for k, g...
7
2016-07-25T10:59:44Z
[ "python", "dictionary" ]
Subset of dictionary keys
38,565,727
<p>I've got a python dictionary of the form <code>{'ip1:port1' : &lt;value&gt;, 'ip1:port2' : &lt;value&gt;, 'ip2:port1' : &lt;value&gt;, ...}</code>. Dictionary keys are strings, consisting of ip:port pairs. Values are not important for this task.</p> <p>I need a list of <code>ip:port</code> combinations with unique ...
4
2016-07-25T10:48:00Z
38,566,384
<p>I've changed few characters in my solution and now am satisfied with it.</p> <pre><code>def get_uniq_worker_ips(workers): wip = set(w.split(':')[0] for w in workers.iterkeys()) return [next(worker for worker in workers.iterkeys() if worker.startswith(w)) for w in wip] </code></pre> <p>Thanks to @Ignacio Va...
0
2016-07-25T11:19:28Z
[ "python", "dictionary" ]
Subset of dictionary keys
38,565,727
<p>I've got a python dictionary of the form <code>{'ip1:port1' : &lt;value&gt;, 'ip1:port2' : &lt;value&gt;, 'ip2:port1' : &lt;value&gt;, ...}</code>. Dictionary keys are strings, consisting of ip:port pairs. Values are not important for this task.</p> <p>I need a list of <code>ip:port</code> combinations with unique ...
4
2016-07-25T10:48:00Z
38,566,415
<p>One way to do this is to transform your keys into a custom class that only looks at the IP part of the string when doing an equality test. It also needs to supply an appropriate <code>__hash__</code> method.</p> <p>The logic here is that the <code>set</code> constructor will "see" keys with the same IP as identical...
4
2016-07-25T11:21:03Z
[ "python", "dictionary" ]
Switch to vim like editor interactivelly to change a Python string
38,565,797
<p>I have the following source code:</p> <pre><code>import sys, os import curses import textwrap if __name__ == "__main__": curses.setupterm() sys.stdout.write(curses.tigetstr('civis')) os.system("clear") str = "abcdefghijklmnopqrstuvwxyz" * 10 # only example for line in textwrap.wrap(str, 60): os.syste...
0
2016-07-25T10:50:56Z
38,571,331
<p><strong>Idea:</strong></p> <p>Let us choose <code>\o</code> and <code>\w</code> for our purpose. Keep the cursor on "TO DO" or any other word you like and press <code>\o</code>. Then, it opens new tab. You can write anything in new buffer and then press <code>\w</code>. It will copy the whole thing and close the bu...
0
2016-07-25T15:06:48Z
[ "python", "vim", "curses" ]
Switch to vim like editor interactivelly to change a Python string
38,565,797
<p>I have the following source code:</p> <pre><code>import sys, os import curses import textwrap if __name__ == "__main__": curses.setupterm() sys.stdout.write(curses.tigetstr('civis')) os.system("clear") str = "abcdefghijklmnopqrstuvwxyz" * 10 # only example for line in textwrap.wrap(str, 60): os.syste...
0
2016-07-25T10:50:56Z
38,686,401
<p>Not exactly: you can't do it that way. Programs generally cannot read what you printed to the screen.</p> <p>You <em>could</em> make a program which displays text on the screen and (knowing what it wrote) pass that information to an editor. For instance, <code>lynx</code> (an application using curses) displays a ...
0
2016-07-31T17:02:15Z
[ "python", "vim", "curses" ]
Switch to vim like editor interactivelly to change a Python string
38,565,797
<p>I have the following source code:</p> <pre><code>import sys, os import curses import textwrap if __name__ == "__main__": curses.setupterm() sys.stdout.write(curses.tigetstr('civis')) os.system("clear") str = "abcdefghijklmnopqrstuvwxyz" * 10 # only example for line in textwrap.wrap(str, 60): os.syste...
0
2016-07-25T10:50:56Z
38,761,065
<pre><code>def runVim(ln): with tempfile.NamedTemporaryFile(suffix=".txt") as tmp: tmp.write(ln) tmp.flush() call(['vim', '+1', '-c set filetype=txt', tmp.name]) # for centering +1 can be changed with open(tmp.name, 'r') as f: lines = f.read() return lines ... x = getch() if x == "e": ...
1
2016-08-04T07:29:54Z
[ "python", "vim", "curses" ]
Pandas: replace substring in string
38,565,849
<p>I want to replace substring <code>icashier.alipay.com</code> in column in <code>df</code></p> <pre><code>url icashier.alipay.com/catalog/2758186/detail.aspx icashier.alipay.com/catalog/2758186/detail.aspx icashier.alipay.com/catalog/2758186/detail.aspx vk.com </code></pre> <p>to <code>aliexpress.com</code>.</p> <...
1
2016-07-25T10:54:02Z
38,565,881
<p>use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.replace.html" rel="nofollow"><code>str.replace</code></a> to replace a substring, <code>replace</code> looks for exact matches unless you pass a regex pattern and param <code>regex=True</code>:</p> <pre><code>In [25]: df['url'] = d...
1
2016-07-25T10:55:15Z
[ "python", "pandas", "replace", "dataframe", "substring" ]
Pandas: replace substring in string
38,565,849
<p>I want to replace substring <code>icashier.alipay.com</code> in column in <code>df</code></p> <pre><code>url icashier.alipay.com/catalog/2758186/detail.aspx icashier.alipay.com/catalog/2758186/detail.aspx icashier.alipay.com/catalog/2758186/detail.aspx vk.com </code></pre> <p>to <code>aliexpress.com</code>.</p> <...
1
2016-07-25T10:54:02Z
38,565,899
<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.replace.html" rel="nofollow"><code>replace</code></a> with <code>dict</code> for replacing and parameters <code>inplace=True</code> and <code>regex=True</code>:</p> <pre><code>df['url'].replace({'icashier.alipay.com': 'aliexpress.com'}...
3
2016-07-25T10:56:04Z
[ "python", "pandas", "replace", "dataframe", "substring" ]
flask query print all record table
38,565,927
<p>When i use this script in flask i'll print on the screen one record stored on my database only for 3 data :</p> <pre><code>app = Flask(__name__) @app.route("/") def index(): cur = mysql.connection.cursor() cur.execute('SELECT temperatura,umidita, orario FROM soggiorno ORDER BY id DESC LIMIT 1;...
0
2016-07-25T10:57:54Z
38,566,553
<p>In your sql remove <code>LIMIT 1</code> like so:</p> <p><code> cur.execute('SELECT temperatura,umidita, orario FROM soggiorno ORDER BY id DESC;') </code></p>
0
2016-07-25T11:28:16Z
[ "python", "html", "mysql", "flask" ]
.value_counts() giving truncated results
38,565,985
<p>I have an excel file with a single column of multiple words. I am trying to count the frequency of occurrence of each word. So If I have a list</p> <pre><code>Labels a a b b c c c </code></pre> <p>The output should be </p> <pre><code>c : 3 b : 2 a : 2 </code></pre> <p>I am using the following the code snippet...
1
2016-07-25T11:00:37Z
38,566,070
<p>You're passing <code>str(A)</code></p> <p>just call <code>to_csv</code> on <code>A</code>:</p> <pre><code>A = train['Labels'].value_counts() A.to_csv("ani3.csv",mode='a') </code></pre> <p>When you did <code>str(A)</code> you're converting the output, which will be affected by the pandas display options, to a stri...
4
2016-07-25T11:04:36Z
[ "python", "pandas" ]
Pyramid get current user/user id without access to request
38,566,092
<p>Is there any way to access current user object or at least id without access to request? Let's say in model?</p> <p>I use pyramid and SQLAlchemy.</p> <p>First I thought about Singleton, but I think this may return wrong object when there is more users.</p> <pre><code>class UserSingleton(object): user = None ...
3
2016-07-25T11:05:44Z
38,569,125
<p>Ok, found a solution by doing:</p> <pre><code>from pyramid.threadlocal import get_current_request request = get_current_request() </code></pre>
3
2016-07-25T13:30:15Z
[ "python", "sqlalchemy", "pyramid" ]
Timezone not working properly in Django
38,566,228
<p>I want to change timezone in Django, so I read documentation how to do it nad here's what I've got:</p> <pre><code>#settings.py TIME_ZONE = 'Europe/Ljubljana' #models.py #date_time gets filled with "auto_now=True") date_time = models.DateTimeField(auto_now=True) </code></pre> <p>UTC DST offset for given locatio...
2
2016-07-25T11:12:21Z
38,566,337
<p>From the <a href="https://docs.djangoproject.com/en/1.9/topics/i18n/timezones/" rel="nofollow">documentation</a></p> <blockquote> <p>When support for time zones is enabled, Django stores datetime information in UTC in the database, uses time-zone-aware datetime objects internally, and translates them to the end u...
2
2016-07-25T11:17:10Z
[ "python", "django", "timezone" ]
Python3 , OOP : Multiple classes inheritance into single class
38,566,396
<p>I am Inheriting from multiple parent classes into a single class. What I am trying to do is make a situation of object data conflict. </p> <p>I mean if two classes hold a variable with same name and different data, which data will be loaded by Python if that variable comes to picture?</p> <p>what I did </p> <pre>...
0
2016-07-25T11:20:06Z
38,566,686
<p>Without changing the order of inheritance, your subclass will always get an attribute it can find in the first class, from the first class. If you want to find out what the corresponding value is in the second class, you're going to have to explicitly ask for the second class's value.</p> <p>In your case, something...
1
2016-07-25T11:35:25Z
[ "python", "oop" ]
Python3 , OOP : Multiple classes inheritance into single class
38,566,396
<p>I am Inheriting from multiple parent classes into a single class. What I am trying to do is make a situation of object data conflict. </p> <p>I mean if two classes hold a variable with same name and different data, which data will be loaded by Python if that variable comes to picture?</p> <p>what I did </p> <pre>...
0
2016-07-25T11:20:06Z
38,566,943
<p>You could also return a list/tuple of the possible values by using the following code:</p> <pre><code>@property def var2(self): key='var2' return [getattr(c,key) for c in self.__class__.mro()[1:-1] if hasattr(c,key)] </code></pre> <p>The <code>mro</code> method returns a list of classes, the fi...
0
2016-07-25T11:47:29Z
[ "python", "oop" ]
Python3 , OOP : Multiple classes inheritance into single class
38,566,396
<p>I am Inheriting from multiple parent classes into a single class. What I am trying to do is make a situation of object data conflict. </p> <p>I mean if two classes hold a variable with same name and different data, which data will be loaded by Python if that variable comes to picture?</p> <p>what I did </p> <pre>...
0
2016-07-25T11:20:06Z
38,567,236
<p>You can set self.var2=cac.var2 in the newclass's <strong>init</strong> method:</p> <pre><code>class newclass(pac, cac): def __init__(self): self.var2 = cac.var2 </code></pre>
1
2016-07-25T12:01:52Z
[ "python", "oop" ]
Python/Pandas if statement and index
38,566,406
<p>I'm sure there is a simple solution to this problem but I cannot seem to find it. </p> <p>I am trying to check if an age from a list is in the age column of my dataframe. However, it is only comparing to the index and not the column. </p> <p>Here is a simplified piece of code from my program:</p> <pre><code>def f...
1
2016-07-25T11:20:38Z
38,566,437
<p>Use <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.where.html" rel="nofollow"><code>numpy.where</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isin.html" rel="nofollow"><code>isin</code></a>:</p> <pre><code>np.where(data['age'].isin(ages),'yes...
0
2016-07-25T11:22:39Z
[ "python", "function", "pandas", "if-statement", "dataframe" ]
Python/Pandas if statement and index
38,566,406
<p>I'm sure there is a simple solution to this problem but I cannot seem to find it. </p> <p>I am trying to check if an age from a list is in the age column of my dataframe. However, it is only comparing to the index and not the column. </p> <p>Here is a simplified piece of code from my program:</p> <pre><code>def f...
1
2016-07-25T11:20:38Z
38,566,551
<h1>DataFrame column access return a Series</h1> <p>In your code, <code>data['age']</code> is returning a series of columns <code>age</code>. In this case the <code>in</code> operator will compare against the index. To compare against the values in the series use the <code>.values</code> attribute to get an array of ...
1
2016-07-25T11:28:12Z
[ "python", "function", "pandas", "if-statement", "dataframe" ]
AttributeError: module 'pandas' has no attribute 'to_csv'
38,566,430
<p>I took some rows from csv file like this </p> <pre><code>pd.DataFrame(CV_data.take(5), columns=CV_data.columns) </code></pre> <p>and performed some functions on it. now i want to save it in csv again but it is giving error <code>module 'pandas' has no attribute 'to_csv'</code> I am trying to save it like this </p...
-2
2016-07-25T11:22:05Z
38,566,460
<p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html" rel="nofollow"><code>to_csv</code></a> is a method of a <code>DataFrame</code> object, not of the <code>pandas</code> module. </p> <pre><code>df = pd.DataFrame(CV_data.take(5), columns=CV_data.columns) # whatever manipulat...
2
2016-07-25T11:23:43Z
[ "python", "csv", "pandas", "export-to-csv", "spark-dataframe" ]
How to use Airbnb Caravel Time Filter
38,566,435
<p>Recently, I use Caravel to do Log Analytics Dashboard, and I think Caravel Time filter is not good to use, for example:</p> <ul> <li>I can't display all data without Time filter</li> <li>Time filter is too rough, so I can't get data within two datetime</li> </ul> <p>Is any way can resolve these problem? Thank you...
0
2016-07-25T11:22:29Z
38,626,662
<p>I found the answer: </p> <p>In Time Filter, you can just type 1 day, 2 day or a date string in Since and Until field</p>
0
2016-07-28T03:35:37Z
[ "python", "airbnb" ]
NameError: name 'View' is not defined in views.py
38,566,446
<p>I am trying to define a class in views.py which is inheriting generic view. The code is as follows. On running server I get the error that class UserFormView(View): NameError: name 'View' is not defined </p> <p>although I have imported generic. Please let me know the reason.</p> <pre><code>from django.views impo...
0
2016-07-25T11:23:09Z
38,566,482
<p>The <code>View</code> name needs to be <em>imported</em>. Add the following import statement:</p> <pre><code>from django.views.generic import View </code></pre> <p>Or use the already imported <code>generic</code> module in </p> <pre><code>class UserFormView(generic.View) # ^ </code></pre>
2
2016-07-25T11:24:58Z
[ "python", "django" ]
NameError: name 'View' is not defined in views.py
38,566,446
<p>I am trying to define a class in views.py which is inheriting generic view. The code is as follows. On running server I get the error that class UserFormView(View): NameError: name 'View' is not defined </p> <p>although I have imported generic. Please let me know the reason.</p> <pre><code>from django.views impo...
0
2016-07-25T11:23:09Z
38,566,573
<p>You need to either import <code>View</code> explicitly:</p> <pre><code>from django.views.generic import View </code></pre> <p>or refer to it as <code>generic.View</code>:</p> <pre><code>class UserFormView(generic.View): # ... </code></pre>
1
2016-07-25T11:29:29Z
[ "python", "django" ]
Flask Blueprint url_for BuildError when using add_url_rule
38,566,481
<p>I am stuck in blueprint when I am trying to use flask blueprint in the way of <code>add_url_rule</code></p> <p>Here's my flask project structure:</p> <pre><code>myapp ... __init__.py ... app.py ... model ... static ... views ...... main.py ... templates ...... base.html ...... results.html </code></pre> <p>In mai...
0
2016-07-25T11:24:51Z
38,567,627
<p>Ok, so the first problem I see that is even though you're trying to use blueprint you're not actually doing anything with it. </p> <p>Yeah, in the line <code>main_bp = Blueprint('main', __name__)</code> you create it, but after that you don't actually register any url endpoints for it and instead try to do it via i...
1
2016-07-25T12:20:56Z
[ "python", "flask", "blueprint", "url-for" ]
flask template setting id for divs in a for loop
38,566,525
<p>In the html file:</p> <pre><code>{% for elems in result2 %} &lt;div style="border:1px solid green;"&gt; {% for elem in elems %} {{ elem }} {%endfor%} &lt;/div&gt;&lt;br&gt; {%endfor%} </code></pre> <p>I want to give <code>id</code> to <code>&lt;div&gt;</code> and t...
-1
2016-07-25T11:26:54Z
38,567,213
<p>I think you could just use <code>id="{{ elems[0][1] }}"</code></p>
1
2016-07-25T12:00:59Z
[ "python", "templates", "for-loop", "flask" ]
flask template setting id for divs in a for loop
38,566,525
<p>In the html file:</p> <pre><code>{% for elems in result2 %} &lt;div style="border:1px solid green;"&gt; {% for elem in elems %} {{ elem }} {%endfor%} &lt;/div&gt;&lt;br&gt; {%endfor%} </code></pre> <p>I want to give <code>id</code> to <code>&lt;div&gt;</code> and t...
-1
2016-07-25T11:26:54Z
38,567,227
<p>The data structure being used for <code>result2</code> is unclear, but assuming that it is a list of lists of tuples you should be able to reach the second element of the first tuple of each list with <code>elems.0.1</code>. In the template:</p> <pre><code>{% for elems in result2 %} &lt;div id="{{ elems.0.1...
1
2016-07-25T12:01:37Z
[ "python", "templates", "for-loop", "flask" ]
Django testing: AssertionError: The form 'form' was not used to render the response
38,566,704
<p>So I'm writing a test to check for the occurrence of Validation Errors in my Form.</p> <p>In doing so I'm getting the following error:</p> <pre><code>====================================================================== FAIL: test_start_date_before_end_date_errors (reports.tests.ScheduleValidation) --------------...
0
2016-07-25T11:36:07Z
38,567,262
<p>When you use <code>client.post()</code>, you should use the actual URL, not the name of the url.</p> <p>You could either hardcode it, for example:</p> <pre><code>response = self.client.post('/reports/schedules/create/, self.data, follow=True) </code></pre> <p>Or you could reverse the url:</p> <pre><code>from dja...
1
2016-07-25T12:02:46Z
[ "python", "django", "forms", "testing" ]
Python - import error when trying to activate a virtual environment, or lauch Spyder
38,566,705
<p>I get an ImportError whenever I try to activate a virtual environment, or when I try to launch Spyder.</p> <p>When trying to activate a virtual environment:</p> <pre><code>Traceback (most recent call last): File "/home/pauline/anaconda3/bin/conda", line 3, in &lt;module&gt; from conda.cli import main ImportError: ...
0
2016-07-25T11:36:08Z
38,566,782
<p>If you are using a different python version, whatever packages that you had with anaconda or that you may have installed with <code>conda install</code> will not be there on the new version. You need to install them with <code>pip</code> or <code>conda</code> again.</p>
1
2016-07-25T11:40:15Z
[ "python", "virtualenv", "anaconda", "spyder", "pythonpath" ]
number of files; date creation and file size
38,566,804
<p>desperately need your help - i have a folder which consists of many files created different days and has different quantity and different size. For a file size measure i use : </p> <pre><code>find . -name "*20160725*" -print -exec du -ks {} \; | cut -f1 | awk '{total=total+$1}END{print total/1024}' </code></pre> ...
0
2016-07-25T11:41:13Z
38,569,822
<p>Try this :</p> <pre><code>find . -name '*' -printf '%Td-%Tb %s\n' | awk 'NR==1 {print "DATE\tQUANTITY\tSIZE"}{a[$1]+=$2;b[$1]+=1;}END{for(i in a)print i"\t"b[i]"\t"a[i]/1024}' </code></pre> <p>The <code>printf</code> option of the <code>find</code> command outputs date and size for each file. </p> <p>The ouput ...
0
2016-07-25T14:01:13Z
[ "python", "bash", "shell" ]
Pandas: concatenate some df
38,566,920
<p>I have two df</p> <pre><code>ID url visits 123 vk.com 14 789 twitter.com 7 </code></pre> <p>And </p> <pre><code>ID url buys 123 vk.com 3 456 facebook.com 1 </code></pre> <p>Desire output</p> <pre><code>ID url visits buys 123 vk.com 14 3 456 facebook.com NaN 1 789 twitter.com ...
1
2016-07-25T11:46:26Z
38,566,959
<p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a> on columns <code>ID</code> and <code>url</code> with outer join by parameter <code>how='outer'</code>:</p> <pre><code>result = pd.merge(short, short1, on=['ID','url'], how='outer'...
2
2016-07-25T11:48:49Z
[ "python", "pandas" ]
Populating python matrix
38,566,995
<p>I'm doing the splitting of the words from the text file in python. I've receive the number of row (c) and a dictionary (word_positions) with index. Then I create a zero matrix (c, index). Here is the code:</p> <pre><code>from collections import defaultdict import re import numpy as np c=0 f = open('/Users/Half_Pi...
1
2016-07-25T11:50:43Z
38,568,742
<p>It looks like you are trying to create something similar to an <a href="https://pythonprogramming.net/python-3-multi-dimensional-list/" rel="nofollow">n-dimensional list</a>. these are achieved by nesting lists inside themselves as such:</p> <pre><code>two_d_list = [[0, 1], [1, 2], [example, blah, blah blah]] wor...
0
2016-07-25T13:12:20Z
[ "python", "arrays", "numpy", "matrix" ]
Populating python matrix
38,566,995
<p>I'm doing the splitting of the words from the text file in python. I've receive the number of row (c) and a dictionary (word_positions) with index. Then I create a zero matrix (c, index). Here is the code:</p> <pre><code>from collections import defaultdict import re import numpy as np c=0 f = open('/Users/Half_Pi...
1
2016-07-25T11:50:43Z
38,573,259
<p>Try next:</p> <pre><code>import re import numpy as np from itertools import chain text = open('/Users/Half_Pint_Boy/Desktop/sentenses.txt') text_list = text.readlines() c=0 for i in range(len(text_list)): c=c+1 text_niz = [] for i in range(len(text_list)): text_niz.append(text_list[i].lower()) # пеÑ...
1
2016-07-25T16:41:04Z
[ "python", "arrays", "numpy", "matrix" ]
In sympy, how functional expression can be translated into operator overloaded expression?
38,567,219
<p>Recently I am working with boolean network and I am using sympy to manipulate boolean functions. I think this can be very basic question but I could not find any clue.</p> <p>Following line works well. </p> <pre><code>&gt;&gt;&gt;from sympy import * &gt;&gt;&gt;x,y = symbols("x y") &gt;&gt;&gt;(x | y) &amp; x And(...
0
2016-07-25T12:01:12Z
38,567,388
<p>Sympy makes extensive use of Python operator overloading capabilities. In Python each class can define as any mathematical operator will take effect, by defining methods with special names - these methods allways are prefixed and postfixed with <code>__</code>, and are described in the <a href="https://docs.python....
0
2016-07-25T12:09:11Z
[ "python", "expression", "sympy", "prefix", "infix-notation" ]
In sympy, how functional expression can be translated into operator overloaded expression?
38,567,219
<p>Recently I am working with boolean network and I am using sympy to manipulate boolean functions. I think this can be very basic question but I could not find any clue.</p> <p>Following line works well. </p> <pre><code>&gt;&gt;&gt;from sympy import * &gt;&gt;&gt;x,y = symbols("x y") &gt;&gt;&gt;(x | y) &amp; x And(...
0
2016-07-25T12:01:12Z
38,598,499
<p>If you just want nicer printing, you can run </p> <pre><code>init_printing() </code></pre> <p>and it will print it using Unicode characters, or even LaTeX if it's available (like in the Jupyter notebook)</p> <pre><code>In [1]: (x | y) &amp; x Out[1]: x ∧ (x ∨ y) </code></pre> <p>You can also use the <code>pp...
0
2016-07-26T19:36:52Z
[ "python", "expression", "sympy", "prefix", "infix-notation" ]
Function not returning values after being called for a second time
38,567,257
<p>I'm trying to complete a python Hangman miniproject to help me learn to code.</p> <p>I've created a function that will hopefully ask the player for a letter, check the letter is only 1 letter and make sure it is not a number. </p> <p>Here is the code I have so far:</p> <pre><code>def getLetter(): letter = raw...
0
2016-07-25T12:02:42Z
38,567,297
<p>You are not returning the result of your recursive calls; everywhere you call <code>getLetter()</code> you <em>drop</em> the return value.</p> <p>Add <code>return</code> before those calls to pass on the result up the call chain:</p> <pre><code>return getLetter() </code></pre> <p>However, you should not be using ...
4
2016-07-25T12:04:06Z
[ "python", "function" ]
Function not returning values after being called for a second time
38,567,257
<p>I'm trying to complete a python Hangman miniproject to help me learn to code.</p> <p>I've created a function that will hopefully ask the player for a letter, check the letter is only 1 letter and make sure it is not a number. </p> <p>Here is the code I have so far:</p> <pre><code>def getLetter(): letter = raw...
0
2016-07-25T12:02:42Z
38,567,656
<pre><code>def get_valid_letter(): while True: letter = raw_input('Please enter a letter...') if letter.isdigit() == True: print('That is a number!') elif len(str(letter)) &gt;1: print("Sorry, you have to enter exactly ONE letter") else: ret...
0
2016-07-25T12:22:11Z
[ "python", "function" ]
Debugging a Python Prime Number Program
38,567,337
<p>I wrote the code for a Python prime number generator, to generate the first 100 primes. But, somehow, I get non-primes like 22, 25, etc. in my output. I've rechecked it over and over again for hours now and still can't figure out where I went wrong... Please help!</p> <p>Here's my code:</p> <pre><code>from math im...
2
2016-07-25T12:06:17Z
38,567,464
<p>the content of your else should be outside the for loop. Here you are appending x to your array as soon as it failed to be divided by "at least one of the i" instead of "failing to be divided by each of the i"</p> <p>Also this algorithms is very inefficient. For a fast one try: <a href="https://en.wikipedia.org/wik...
2
2016-07-25T12:13:07Z
[ "python", "debugging" ]
Debugging a Python Prime Number Program
38,567,337
<p>I wrote the code for a Python prime number generator, to generate the first 100 primes. But, somehow, I get non-primes like 22, 25, etc. in my output. I've rechecked it over and over again for hours now and still can't figure out where I went wrong... Please help!</p> <p>Here's my code:</p> <pre><code>from math im...
2
2016-07-25T12:06:17Z
38,567,581
<p>Your test for a number being prime is wrong. You check whether a number is divisible by <code>i</code> going from 2 to <code>sqrt(x)</code> which is correct, but as soon as you hit a number which isn't a factor you assume that the number is prime, which is not correct. You have to check all numbers and if none is fa...
0
2016-07-25T12:18:52Z
[ "python", "debugging" ]
Debugging a Python Prime Number Program
38,567,337
<p>I wrote the code for a Python prime number generator, to generate the first 100 primes. But, somehow, I get non-primes like 22, 25, etc. in my output. I've rechecked it over and over again for hours now and still can't figure out where I went wrong... Please help!</p> <p>Here's my code:</p> <pre><code>from math im...
2
2016-07-25T12:06:17Z
38,567,648
<p>As user2346536 said, your else should not be inside the loop. You will only ever look at the element for <code>i = 2</code></p> <p>How to do it :</p> <pre><code>from math import sqrt, ceil prime_list = [2] x = 2 while prime_list != 100: x += 1 is_prime = True for element in range(2,int(ceil(sqrt(x)))):...
0
2016-07-25T12:21:57Z
[ "python", "debugging" ]