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
TypeError when running Pythonshell on my Mac
39,248,573
<p>I run a python script in node.js using python shell.<br> On my Windows system everything runs fine.<br> But running the same thing on my Macbook get's me this error:</p> <pre><code>Error: TypeError: can't multiply sequence by non-int of type 'float' at PythonShell.parseError (/Users/johannes/Dropbox/Javascript ...
0
2016-08-31T11:36:29Z
39,316,147
<p>Solved by changing a float value to int.</p> <p>(though it would be interesting to know, why this only occurred on Mac.)</p>
0
2016-09-04T10:53:59Z
[ "javascript", "python", "node.js", "osx", "typeerror" ]
Kivy Python "Invalid Indentation (too many levels)?
39,248,740
<p>When i take the label "id:meaning" out of the code it runs fine. I cant see where the indentation is incorrect. Can anyone help, please?</p> <p><a href="http://i.stack.imgur.com/tjTDQ.png" rel="nofollow"><img src="http://i.stack.imgur.com/tjTDQ.png" alt="ERROR MESSAGE"></a></p> <p><a href="http://i.stack.imgur.com...
0
2016-08-31T11:43:55Z
39,248,866
<p>Delete all the spaces and line feeds before and after lines 44, 45 and 46 and be sure to insert the right indentation characters</p> <p>Sometimes this errors are not enough clear. It happends that there is a problem in the line before or after the one indicated</p>
1
2016-08-31T11:49:37Z
[ "python", "kivy", "kivy-language" ]
Kivy Python "Invalid Indentation (too many levels)?
39,248,740
<p>When i take the label "id:meaning" out of the code it runs fine. I cant see where the indentation is incorrect. Can anyone help, please?</p> <p><a href="http://i.stack.imgur.com/tjTDQ.png" rel="nofollow"><img src="http://i.stack.imgur.com/tjTDQ.png" alt="ERROR MESSAGE"></a></p> <p><a href="http://i.stack.imgur.com...
0
2016-08-31T11:43:55Z
39,248,875
<p>Python needs a 4-space indent.</p> <p>Try to trim excess spaces and tabs from ends of lines, and remove empty lines at the end of files. Also ensure the last line ends with a newline.</p>
1
2016-08-31T11:49:58Z
[ "python", "kivy", "kivy-language" ]
Django REST custom authentication
39,248,825
<p>Here's my issue guys. I have a store user that can log to his site and view all kinds of data related to his store. In his store he has, let's say 10 android billing devices that send bills to him. Now I need to create a custom authentication in Django REST framework that will authenticate android devices with their...
2
2016-08-31T11:48:08Z
39,254,144
<p>yes... it is possible</p> <p><strong>Note:</strong> use a <a href="http://www.django-rest-framework.org/api-guide/authentication/#custom-authentication" rel="nofollow">custom authentication</a> and create your own Token Model that is related to you AndroidDevice model instead of the User Model or whatever you need ...
0
2016-08-31T15:57:57Z
[ "python", "django", "authentication", "django-rest-framework", "custom-authentication" ]
Correct format for IMAP append command in Python? (Yahoo mail)
39,248,898
<p>The following Python function works for outlook, gmail and my shared hosting exim server but when sending mail through yahoo.com it returns this error:</p> <pre><code>APPEND command error: BAD ['[CLIENTBUG] Additional arguments found after last expected argument']. Data: FHDJ4 APPEND inbox.sent "31-Aug-2016 12:30:4...
0
2016-08-31T11:51:09Z
39,252,246
<p>I've resolved this. I noticed the message text did not end with CRLF. Other mail servers were appending this serverside to accept the command, Yahoo does not. The below now works.</p> <p>I've amended the message payload line to: msg.set_payload("%s \r\n" % msgtext) # Yahoo is strict with CRLF at end of IMAP com...
0
2016-08-31T14:23:04Z
[ "python", "python-3.x", "yahoo-mail" ]
importing simpy in python - unnamed module error
39,248,925
<p>I am trying to import <code>simpy</code> package in python, however I get the unnamed module error. I am on a Mac OSX and have <code>anaconda</code> installed. I installed it using <code>pip install simpy</code> command. These outputs could also be helpful:</p> <pre><code>$ which python //anaconda/bin/python $ pip...
0
2016-08-31T11:52:19Z
39,249,070
<p>The error could be caused by your project configuration in pycharm pointing to another python interpreter, maybe python3 or a virtualenv? </p> <p>Check it by going through your project settings.</p> <p>Make sure you are using the same interpreter in PyCharm as the one where you installed your module. </p>
3
2016-08-31T11:59:31Z
[ "python", "python-3.x", "anaconda", "python-import", "simpy" ]
Writing variable sized arrays to Pandas cells
39,249,030
<p>I have a large data set and I want to do a convolution calculation using multiple rows that match a criteria. I need to calculate a vector for each row first, and I thought it would be more efficient to store my vector in a dataframe column so I could try and avoid a for loop when I do the convolution. Trouble is, t...
2
2016-08-31T11:57:15Z
39,251,861
<p>Try:</p> <pre><code>def get_vec(x): return [x.P] + np.zeros(x['Alloc']).tolist() + [1 - x.P] df.apply(get_vec, axis=1) 0 [0.5, 0.0, 0.0, 0.0, 0.5] 1 [0.3, 0.0, 0.0, 0.0, 0.0, 0.7] dtype: object </code></pre> <hr> <pre><code>df['Test'] = df.apply(get_vec, axis=1) df </code></pre> <p><a href="http...
2
2016-08-31T14:05:31Z
[ "python", "pandas" ]
Writing variable sized arrays to Pandas cells
39,249,030
<p>I have a large data set and I want to do a convolution calculation using multiple rows that match a criteria. I need to calculate a vector for each row first, and I thought it would be more efficient to store my vector in a dataframe column so I could try and avoid a for loop when I do the convolution. Trouble is, t...
2
2016-08-31T11:57:15Z
39,391,032
<p>So here's the answer. <a href="http://stackoverflow.com/users/2336654/pirsquared">piRSquared</a> was almost right, but not quite. There are several parts here.</p> <p>The apply method partially works. It passes a row to the function and you can do a calculation as shown above. The problem is, you get a "ValueError:...
0
2016-09-08T12:32:32Z
[ "python", "pandas" ]
Exit a multiprocessing script
39,249,050
<p>I am trying to exit a multiprocessing script when an error is thrown by the target function, but instead of quitting, the parent process just hangs.</p> <p>This is the test script I use to replicate the problem:</p> <pre><code>#!/usr/bin/python3.5 import time, multiprocessing as mp def myWait(wait, resultQueue):...
5
2016-08-31T11:58:37Z
39,253,759
<p>Firstly, your code has a major issue: you're trying to join the processes before flushing the content of the queues, if any, which can result in a deadlock. See the section titled 'Joining processes that use queues' here: <a href="https://docs.python.org/3/library/multiprocessing.html#multiprocessing-programming" re...
2
2016-08-31T15:37:48Z
[ "python", "multiprocessing", "python-3.5" ]
Exit a multiprocessing script
39,249,050
<p>I am trying to exit a multiprocessing script when an error is thrown by the target function, but instead of quitting, the parent process just hangs.</p> <p>This is the test script I use to replicate the problem:</p> <pre><code>#!/usr/bin/python3.5 import time, multiprocessing as mp def myWait(wait, resultQueue):...
5
2016-08-31T11:58:37Z
39,266,552
<p>You should use <code>multiprocessing.Pool</code> to manage your processes for you. And then use <code>Pool.imap_unordered</code> to iterate over the results in the order they are completed. As soon as you get the first exception, you can stop the pool and its child processes (this is automatically done when you exit...
1
2016-09-01T08:34:33Z
[ "python", "multiprocessing", "python-3.5" ]
Extract a part of fasta sequence based on bp coordinates
39,249,121
<p>I have a huge fasta file, but I need to extract only a part of it, If I know the start and end base pair coordinate of my sequence. Also, it should be in fasta format with the length of 60 bp per line.This is my try, please let me know if looks OK and any suggestions to improve it are welcome.</p> <pre><code>from B...
0
2016-08-31T12:02:26Z
39,249,843
<p>It's as easy as:</p> <pre><code>from Bio import SeqIO record = SeqIO.read("Chromosome.fas", "fasta") with open("output.fas", "w") as out: SeqIO.write(record[100:500], out, "fasta") </code></pre> <p>The <code>SeqIO.write</code> already uses a 60 character length wrapping. If you want to manipulate the line w...
1
2016-08-31T12:35:47Z
[ "python", "bioinformatics", "biopython", "fasta" ]
command to generate html report using nosetests over jenkins
39,249,155
<p>nosetests --processes=2 --process-timeout=1800 -v --nocapture -a=attr --attr=api src/tests/externalapi/test_accounts_api.py --with-html</p> <p>doesn't work</p> <p>console says: nosetests: error: no such option: --with-html Build step 'Execute shell' marked build as failure</p>
-1
2016-08-31T12:03:43Z
39,249,682
<p>You can publish test results by adding post build action named “Publish JUnit test result report” in configure section. You will need to generate <code>*.xml</code> file with Nose, tell Jenkins what is the name of that file and Jenkins will be able to interpret it and display it in nice looking form.</p> <p>Op...
0
2016-08-31T12:28:31Z
[ "python", "jenkins", "nose" ]
When use pip to install flask-bcrypt, one error is :UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 49: ordinal not in range(128)
39,249,166
<p>Today, when I install flask-bcrypt used:</p> <pre><code>pip install flask-bcrypt </code></pre> <p>This error happend:</p> <pre><code>Command /home/sf/python/venv/bin/python2 -c "import setuptools, tokenize;__file__='/tmp/pip-build-duYRO6/bcrypt/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).rea...
0
2016-08-31T12:04:10Z
39,249,585
<p>When you type under command to python shell, </p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; sys.getdefaultencoding() </code></pre> <p>it will output this:</p> <pre><code>'ascii' </code></pre> <p>So, I modify </p> <pre><code>/etc/python2.7/sitecustomize.py </code></pre> <p>added:</p> <pre><code>import ...
-1
2016-08-31T12:24:14Z
[ "python", "python-2.7", "pip" ]
ImportError: No module named impyla
39,249,170
<p>I have installed impyla and it's dependencies following <a href="https://github.com/cloudera/impyla" rel="nofollow">this</a> guide. The installation seems to be successful as now I can see the folder <strong>"impyla-0.13.8-py2.7.egg"</strong> in the Anaconda folder (64-bit Anaconda 4.1.1 version).</p> <p>But when I...
0
2016-08-31T12:04:20Z
39,250,176
<p>Usage is a little bit different then you mentioned (from <a href="https://github.com/cloudera/impyla" rel="nofollow">https://github.com/cloudera/impyla</a>)</p> <p>Impyla implements the Python DB API v2.0 (PEP 249) database interface (refer to it for API details):</p> <pre><code>from impala.dbapi import connect co...
2
2016-08-31T12:51:11Z
[ "python", "hadoop", "thrift", "impala" ]
Detect if Django function is running in a celery worker
39,249,172
<p>I have a post_save hook that triggers a task to run in celery. The task also updates the model, which causes the post_save hook to run. The catch is I do not want to <code>.delay()</code> the call in this instance, I just want to run it synchronously because it's already being run in a worker.</p> <p>Is there an en...
1
2016-08-31T12:04:26Z
39,259,111
<p>Usually you'd have <code>common.py, production.py, test.py and local.py/dev.py</code>. You could just add a <code>celery_settings.py</code> with the following content:</p> <pre><code>from production import * IS_CELERY = True </code></pre> <p>Then in your <code>celery.py</code> (I'm assuming you have one) you'll do...
2
2016-08-31T21:14:28Z
[ "python", "django", "celery" ]
Stack Bar Grapth with plot / pandas
39,249,233
<p>I am not being able to generate a stacked graph with the error below:</p> <pre><code>TypeError: There is no Line2D property "stacked" </code></pre> <p>My csv has the format:</p> <pre><code>feb-17,1,2,3 apr-17,2,4,3 may-18,3,5,3 oct-20,4,1,1 dec-21,5,1,1 </code></pre> <p>I would expect to see something like:</p> ...
0
2016-08-31T12:07:41Z
39,249,308
<p>Yes, change the type - </p> <pre class="lang-py prettyprint-override"><code>df.plot.bar(stacked=True, marker='.',markersize=8, title ="My graph", fontsize = 10, color=['b','g','c'], figsize=(15, 15)) </code></pre> <p>By default it tries to plot a 2D line and this indeed does not have a stacked option.</p> <p>See ...
0
2016-08-31T12:11:39Z
[ "python", "plot" ]
Stack Bar Grapth with plot / pandas
39,249,233
<p>I am not being able to generate a stacked graph with the error below:</p> <pre><code>TypeError: There is no Line2D property "stacked" </code></pre> <p>My csv has the format:</p> <pre><code>feb-17,1,2,3 apr-17,2,4,3 may-18,3,5,3 oct-20,4,1,1 dec-21,5,1,1 </code></pre> <p>I would expect to see something like:</p> ...
0
2016-08-31T12:07:41Z
39,250,056
<p>try the following code </p> <pre><code>df.plot(stacked=True,kind ='bar',title ="My graph",fontsize =10,color=['b','g','c'], figsize=(15, 15)) </code></pre> <p>you need to point out the bar kind and delete the marker/markersize</p>
1
2016-08-31T12:45:20Z
[ "python", "plot" ]
Using django ORM in my celery app giving error
39,249,312
<p>I am developing a celery standalone application which uses Django ORM to access my database and perform operations in my data. I followed the answer to this question: <a href="http://stackoverflow.com/questions/937742/use-django-orm-as-standalone">Use Django ORM as standalone</a></p> <p>But when I run my celery wor...
3
2016-08-31T12:11:53Z
39,249,431
<p>You need to configure your settings before you call <code>django.setup()</code>. Simply switching the statements should fix the issue:</p> <pre><code># tasks.py import django from celery import Celery from django.conf import settings settings.configure( DATABASE_ENGINE = "django.db.backends.mysql", DAT...
3
2016-08-31T12:17:39Z
[ "python", "django", "django-models", "orm" ]
Python print pdf file with win32print
39,249,360
<p>I'm trying to print a pdf file from python with module win32print but the only way i can print success is a text.</p> <pre><code>hPrinter = win32print.OpenPrinter("\\\\Server\Printer") filename = "test.pdf" try: hJob = win32print.StartDocPrinter(hPrinter, 1, ('PrintJobName',None,'RAW')) try:...
0
2016-08-31T12:13:39Z
39,249,850
<p>You can try</p> <pre><code>win32print.SetDefaultPrinter("\\\\Server\Printer") </code></pre> <p>This method accepts a String, not the printer object you tried to pass it.</p>
0
2016-08-31T12:35:56Z
[ "python", "pdf", "printing" ]
Numerical computation of the Spherical harmonics expansion
39,249,594
<p>I'm trying to understand the Spherical harmonics expansion in order to solve a more complex problem but the result I'm expecting from a very simple calculation is not correct. I have no clue why this is happening.</p> <hr> <p><strong>A bit of theory:</strong> It is well known that a function on the surface of a sp...
1
2016-08-31T12:24:37Z
39,250,424
<p>The spherical harmonics are orthonormal with the inner product</p> <pre><code>&lt;f|g&gt; = Integral( f(theta,phi)*g(theta,phi)*sin(theta)*dphi*dtheta) </code></pre> <p>So you should calulate the coefficients by</p> <pre><code> clm = Integral( Ylm( theta, phi) * sin(theta)*dphi*dtheta) </code></pre>
1
2016-08-31T13:02:04Z
[ "python", "math" ]
python 3D numpy array time index
39,249,639
<p>Is there a way to index a 3 dimensional array using some form of time index (datetime etc.) on the 3rd dimension?</p> <p>My problem is that I am doing time series analysis on several thousand radar images and I need to get, for example, monthly averages. However if i simply average over every 31 arrays in the 3rd d...
0
2016-08-31T12:26:43Z
39,250,087
<p>you can use pandas module. it supports indexing by date/datetime range. it also support multiindexing, which allows you to work with multidimensional data in 2D manner. </p> <pre><code>&gt;&gt;&gt; rng = pd.date_range('1/1/2016', periods=100, freq='D') &gt;&gt;&gt; rng[:5] DatetimeIndex(['2016-01-01', '2016-01-02'...
1
2016-08-31T12:46:46Z
[ "python", "arrays", "datetime", "numpy", "multidimensional-array" ]
Why is remote_addr missing from the Flask documentation?
39,249,655
<p><a href="http://stackoverflow.com/a/3760309">This question</a> answers how to find the IP of your visitors in Flask. The code works. However, <code>request.remote_addr</code> seems to be absent from the <a href="http://flask.pocoo.org/docs/0.11/api/#incoming-request-data" rel="nofollow">Flask documentation</a>. Why ...
0
2016-08-31T12:27:21Z
39,250,636
<p>Because the <a href="http://werkzeug.pocoo.org/docs/0.11/wrappers/#werkzeug.wrappers.BaseRequest" rel="nofollow"><code>Request</code></a> object comes from Werkzeug, where it <em>is</em> <a href="http://werkzeug.pocoo.org/docs/0.11/wrappers/#werkzeug.wrappers.BaseRequest.remote_addr" rel="nofollow">documented</a>. ...
4
2016-08-31T13:13:13Z
[ "python", "flask", "documentation" ]
Python/Tkinter - Using multiple classes, causes infinite loop when inheriting
39,249,702
<p>I am doing a bigger tkinter application and because the size of the application is quite big I have tried to divide the application to different classes and methods for making it clearer.</p> <p>The problem is that because the subclasses I have made are inheriting from the main class their initiation function cause...
2
2016-08-31T12:29:30Z
39,250,239
<p>Your <code>method</code> class shouldn't inherit from the <code>main_window</code> class. Just create an instance of <code>main_window</code> and pass it into the <code>__init__</code> of <code>method</code>.</p> <p>BTW, <code>method</code> is a confusing name for a class. Also, class names in Python are convention...
2
2016-08-31T12:54:19Z
[ "python", "inheritance", "tkinter", "infinite-loop", "subclassing" ]
Tensorflow : ValueError Duplicate feature column key found for column
39,249,704
<p>I was trying to get my hands dirty with Tensorflow and following <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/learn/wide_n_deep_tutorial.py" rel="nofollow">Wide and Deep Learning</a> example code. I modified certain imports for it to work with python 3.4 on centos 7. </p> <p>Hi...
3
2016-08-31T12:29:33Z
39,268,045
<p><strong>Final update</strong> I had this problem with the recommended 0.10rc0 branch, but after reinstalling using the master (no branch on git clone) this problem went away. I checked the source code and they fixed it. Python 3 now gets the same results as Python 2 for wide_n_deep mode, after fixing the urllib.re...
1
2016-09-01T09:42:06Z
[ "python", "machine-learning", "tensorflow", "python-3.4", "deep-learning" ]
Tensorflow : ValueError Duplicate feature column key found for column
39,249,704
<p>I was trying to get my hands dirty with Tensorflow and following <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/learn/wide_n_deep_tutorial.py" rel="nofollow">Wide and Deep Learning</a> example code. I modified certain imports for it to work with python 3.4 on centos 7. </p> <p>Hi...
3
2016-08-31T12:29:33Z
39,359,007
<p>First of all, as Jesse suggested use the master (no branch on git clone) when you are downloading the tutorial source code from tensorflow website. Second, you only need to pass the first two parameters to the class. You will get some warnings on the way; just ignore them and wait for the program to finish. So use t...
0
2016-09-06T23:03:06Z
[ "python", "machine-learning", "tensorflow", "python-3.4", "deep-learning" ]
Regex for a calculator input
39,249,894
<p>I'm trying to create a regular expression to decide if an input is a valid input for my very basic calculator.</p> <p>Basically </p> <ul> <li>nest parentheses is not allowed (meaning '(1+(2+3)) ' will get rejected</li> <li>after a bracket must come a number (or the expressions ends)</li> </ul> <p>Few examples for...
-1
2016-08-31T12:38:01Z
39,250,208
<p>With <code>re.match</code>. The pattern structure is simple: <code>operand (?: operator operand )*$</code> where <code>operand</code> can be a number or an expression between brackets. <em>(Note that with <code>re.match</code> you don't need to anchor the pattern at the start of the string)</em>.Result:</p> <pre><c...
1
2016-08-31T12:52:45Z
[ "python", "regex", "expression", "calculator" ]
Turtle freehand drawing
39,249,934
<p>I'm working on a simple drawing program that combines Tkinter and Turtle modules. </p> <p>I would like to add an option that the user can draw anything by just using mouse similar to pen widget on Paint. I tried many things, I could not figure out how l can do it.How can l make the turtle draw anything (like pen wi...
1
2016-08-31T12:39:27Z
39,278,539
<p>The following code will let you freehand draw with the turtle. You'll need to integrate with the rest of your code:</p> <pre><code>import tkinter import turtle sc = tkinter.Tk() sc.geometry("1000x1000+100+100") fr4 = tkinter.Frame(sc, height=500, width=600, bd=4, bg="light green", takefocus="", relief=tkinter.SU...
1
2016-09-01T18:27:12Z
[ "python", "turtle-graphics", "tkinter-canvas" ]
Scrapy: Looping through search results only returns first item
39,249,954
<p>I'm scraping a site by going through the search page, then looping through all results within. However it only seems to be returning the first result for each page. I also don't think it's hitting the start page's results either.</p> <p>Secondly, the price is returning as some sort of Unicode (£ symbol) - how can ...
1
2016-08-31T12:40:25Z
39,250,038
<p>To remove the £, just replace it with an empty string like this:</p> <pre><code>pricewithpound = u'\xa38.59' price = pricewithpound.replace(u'\xa3', '') </code></pre> <p>To investigate the scrapy issue, can you please provide the HTML source ?</p>
1
2016-08-31T12:44:40Z
[ "python", "scrapy" ]
Scrapy: Looping through search results only returns first item
39,249,954
<p>I'm scraping a site by going through the search page, then looping through all results within. However it only seems to be returning the first result for each page. I also don't think it's hitting the start page's results either.</p> <p>Secondly, the price is returning as some sort of Unicode (£ symbol) - how can ...
1
2016-08-31T12:40:25Z
39,254,815
<p>Yes it's returning only the first result because of your <code>parse_listing</code> method (you're returning the first url and you should be yielding it). I would do something like:</p> <pre><code>def parse_listings(self, response): for url in response.css('a.product_img::attr(href)').extract(): yield R...
2
2016-08-31T16:36:55Z
[ "python", "scrapy" ]
python time lags holidays
39,250,003
<p>In pandas, I have two data frames. One containing the Holidays of a particular country from <a href="http://www.timeanddate.com/holidays/austria" rel="nofollow">http://www.timeanddate.com/holidays/austria</a> and another one containing a date column. I want to calculate the <code>#days</code> after a holiday.</p> <...
0
2016-08-31T12:42:44Z
39,250,999
<p>To do this, join both data frames using a common column and then try this code</p> <pre><code>import pandas import numpy as np df = pandas.DataFrame(columns=['to','fr','ans']) df.to = [pandas.Timestamp('2014-01-24'), pandas.Timestamp('2014-01-27'), pandas.Timestamp('2014-01-23')] df.fr = [pandas.Timestamp('2014-01-...
0
2016-08-31T13:28:52Z
[ "python", "date", "pandas", "difference" ]
python time lags holidays
39,250,003
<p>In pandas, I have two data frames. One containing the Holidays of a particular country from <a href="http://www.timeanddate.com/holidays/austria" rel="nofollow">http://www.timeanddate.com/holidays/austria</a> and another one containing a date column. I want to calculate the <code>#days</code> after a holiday.</p> <...
0
2016-08-31T12:42:44Z
39,263,368
<p>I settled for something entirely different: Now, only the number of days since before the most current holiday will be calculated.</p> <p>my function:</p> <pre><code>def get_nearest_holiday(holidays, pivot): return min(holidays, key=lanbda x: abs(x- pivot) # this needs to be converted to an int, but at least...
0
2016-09-01T05:32:10Z
[ "python", "date", "pandas", "difference" ]
Format date string in a file using Python
39,250,152
<p>I get csv files from my client which contains variable number of columns. Out of these columns there can be some columns containing date string but the order is not defined, for example :</p> <pre><code>column1str|column2dt|column3str|column4int|column5int|column6dt ab c1|10/20/2010|1234|10.02|530.55|30-01-2011 ab ...
2
2016-08-31T12:49:57Z
39,250,454
<p>try this:</p> <pre><code>import pandas as pd data=pd.read_csv('so.txt',delimiter='|',parse_dates=['column2dt','column6dt']) </code></pre>
2
2016-08-31T13:03:27Z
[ "python", "datetime" ]
Format date string in a file using Python
39,250,152
<p>I get csv files from my client which contains variable number of columns. Out of these columns there can be some columns containing date string but the order is not defined, for example :</p> <pre><code>column1str|column2dt|column3str|column4int|column5int|column6dt ab c1|10/20/2010|1234|10.02|530.55|30-01-2011 ab ...
2
2016-08-31T12:49:57Z
39,250,948
<p>First, read that for reference for Python datetime.strptime() format strings: <a href="https://docs.python.org/3.5/library/datetime.html#strftime-strptime-behavior" rel="nofollow">https://docs.python.org/3.5/library/datetime.html#strftime-strptime-behavior</a></p> <p>And that for CSV parsing: <a href="https://docs....
1
2016-08-31T13:26:35Z
[ "python", "datetime" ]
Overlay two images without losing the intensity of the color using OpenCV and Python
39,250,226
<p>How can i overlay two images without losing the intensity of the colors of the two images.</p> <p>I have Image1 and Image2:</p> <ol> <li><a href="http://i.stack.imgur.com/kidOJ.png" rel="nofollow"><img src="http://i.stack.imgur.com/kidOJ.png" alt="enter image description here"></a> 2. <a href="http://i.stack.imgur...
1
2016-08-31T12:53:47Z
39,251,633
<p>Actually the <code>dst</code> is created according the following formula:</p> <pre><code>dst = src1*alpha + src2*beta + gamma </code></pre> <p>When you multiply your image which is an 3D array with alpha you are multiplying all the items for example for a blue pixle you have <code>[255, 0, 0]</code> and the white ...
1
2016-08-31T13:55:12Z
[ "python", "image", "opencv" ]
python matrix creation without using numpy or anything and max sum of rows and columns
39,250,315
<p>Want to create a matrix like below in python</p> <pre><code>[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] </code></pre> <p>but not sure how to do, i tried list comprehension like below</p> <pre><code>[[y+x for y in range(4)] for x in range(4)] </code></pre> <p>which gives output like below</p> ...
2
2016-08-31T12:57:28Z
39,250,378
<p>The range function accepts 3 arguments <code>start</code>, <code>end</code> and <code>step</code>. You can use one range with step 4 and another one for creating the nested lists using the outer range.</p> <pre><code>&gt;&gt;&gt; [[i for i in range(i, i+4)] for i in range(1, 17, 4)] [[1, 2, 3, 4], [5, 6, 7, 8], [9,...
3
2016-08-31T13:00:07Z
[ "python", "matrix" ]
python matrix creation without using numpy or anything and max sum of rows and columns
39,250,315
<p>Want to create a matrix like below in python</p> <pre><code>[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] </code></pre> <p>but not sure how to do, i tried list comprehension like below</p> <pre><code>[[y+x for y in range(4)] for x in range(4)] </code></pre> <p>which gives output like below</p> ...
2
2016-08-31T12:57:28Z
39,250,395
<pre><code>[[x * 4 + y + 1 for y in range(4)] for x in range(4)] </code></pre> <p>which is equivalent to:</p> <pre><code>[[(x &lt;&lt; 2) + y for y in range(1, 5)] for x in range(4)] </code></pre> <p>Here's a little benchmark:</p> <pre><code>import timeit def f1(): return [[x * 4 + y + 1 for y in range(4)] fo...
4
2016-08-31T13:00:56Z
[ "python", "matrix" ]
python matrix creation without using numpy or anything and max sum of rows and columns
39,250,315
<p>Want to create a matrix like below in python</p> <pre><code>[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] </code></pre> <p>but not sure how to do, i tried list comprehension like below</p> <pre><code>[[y+x for y in range(4)] for x in range(4)] </code></pre> <p>which gives output like below</p> ...
2
2016-08-31T12:57:28Z
39,250,552
<p>try this,</p> <pre><code>In [1]: [range(1,17)[n:n+4] for n in range(0, len(range(1,17)), 4)] Out[1]: [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] </code></pre>
1
2016-08-31T13:08:34Z
[ "python", "matrix" ]
python matrix creation without using numpy or anything and max sum of rows and columns
39,250,315
<p>Want to create a matrix like below in python</p> <pre><code>[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] </code></pre> <p>but not sure how to do, i tried list comprehension like below</p> <pre><code>[[y+x for y in range(4)] for x in range(4)] </code></pre> <p>which gives output like below</p> ...
2
2016-08-31T12:57:28Z
39,251,076
<p>This might be a quick fix</p> <pre><code>[([x-3,x-2,x-1,x]) for x in range(1,17) if x%4 ==0] </code></pre> <p>But what do you mean by maximum sum of column and row</p>
0
2016-08-31T13:31:52Z
[ "python", "matrix" ]
C-numpy: Setting the data type for fixed-width strings?
39,250,355
<p>I'm working with some data that is represented in C as strings. I'd like to return a numpy array based on this data. However, I'd like the array to have dtype='SX' where X is a number determined at runtime.</p> <p>So far I am copying the data in C like so:</p> <pre><code> buffer_len_alt = (MAX_WIDTH)*(MAX_NUMBE...
0
2016-08-31T12:59:07Z
39,254,725
<p>I'm not familiar with the <code>C</code> part of your code, but it appears that you are confusing the representation of byte strings and unicode strings. The <code>b'200'</code> display indicates that you are working in Py3, where unicode the default string type.</p> <p>In a Py3 session:</p> <p>The raw bytes:</p>...
1
2016-08-31T16:30:48Z
[ "python", "numpy", "python-c-api" ]
Count occurences in DataFrame
39,250,504
<p>I've a Dataframe in this format:</p> <pre><code>| Department | Person | Power | ... | |------------|--------|--------|-----| | ABC | 1234 | 75 | ... | | ABC | 1235 | 25 | ... | | DEF | 1236 | 50 | ... | | DEF | 1237 | 100 | ... | | DEF | 1238 | 25 | ....
2
2016-08-31T13:05:44Z
39,250,558
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.value_counts.html" rel="nofollow"><code>value_counts</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.sort_index.html" rel="nofollow"><code>sort_index</code></a>, then generate <code>D...
3
2016-08-31T13:08:46Z
[ "python", "pandas", "pivot-table", "reshape", "crosstab" ]
Count occurences in DataFrame
39,250,504
<p>I've a Dataframe in this format:</p> <pre><code>| Department | Person | Power | ... | |------------|--------|--------|-----| | ABC | 1234 | 75 | ... | | ABC | 1235 | 25 | ... | | DEF | 1236 | 50 | ... | | DEF | 1237 | 100 | ... | | DEF | 1238 | 25 | ....
2
2016-08-31T13:05:44Z
39,251,156
<p>or it can be done this way:</p> <pre><code>&gt;&gt;&gt; df.groupby(['Department','Power']).count().unstack().fillna(0) Person Power 25 50 75 100 Department ABC 1.0 0.0 1.0 0.0 DEF 1.0 2.0 0.0 1.0 </code></pre>
1
2016-08-31T13:35:02Z
[ "python", "pandas", "pivot-table", "reshape", "crosstab" ]
Python: find smallest missing positive integer in ordered list
39,250,520
<p>I need to find the first missing number in a list. If there is no number missing, the next number should be the last +1.</p> <p>It should first check to see if the first number is > 1, and if so then the new number should be 1.</p> <p>Here is what I tried. The problem is here: <code>if next_value - items &gt; 1:</...
0
2016-08-31T13:07:00Z
39,251,396
<p>First avoid using reserved word <code>list</code> for variable. Second use try:except to quickly and neatly avoid this kind of issues.</p> <pre><code>def free(l): if l == []: return 0 if l[0] &gt; 1: return 1 if l[-1] - l[0] + 1 == len(l): return l[-1] + 1 for i in range(len(l)): try: ...
0
2016-08-31T13:44:41Z
[ "python", "python-3.x" ]
Python: find smallest missing positive integer in ordered list
39,250,520
<p>I need to find the first missing number in a list. If there is no number missing, the next number should be the last +1.</p> <p>It should first check to see if the first number is > 1, and if so then the new number should be 1.</p> <p>Here is what I tried. The problem is here: <code>if next_value - items &gt; 1:</...
0
2016-08-31T13:07:00Z
39,251,409
<p>To get the smallest integer that is not a member of <code>vlans3</code>:</p> <pre><code>ints_list = range(min(vlans3), max(vlans3) + 1) missing_list = [x for x in ints_list if x not in vlans3] first_missing = min(missing_list) </code></pre> <p>However you want to return 1 if the smallest value in your list is grea...
1
2016-08-31T13:45:01Z
[ "python", "python-3.x" ]
Multi-Label Classifier in Tensorflow
39,250,828
<p>I want to develop a multi-label classifier with TensorFlow, i try to mean there exists multiple label which contains multiple classes. To illustrate you can image the situation like: </p> <ul> <li>label-1 classes: lighting raining, raining, partial raining, no raining </li> <li>label-2 classes: sunny, partly cloudy...
1
2016-08-31T13:21:33Z
39,254,757
<p>Why not just have your network produce two different outputs?</p> <p>network -> prediction1 and prediction2</p> <p>where prediction1 and prediction2 are both [#,#,#,#] but what I describe below works even if they're different sizes.</p> <p>Then just run </p> <pre><code>loss1 = tf.reduce_mean(tf.nn.softmax_cross_...
2
2016-08-31T16:32:52Z
[ "python", "machine-learning", "tensorflow", "classification", "multilabel-classification" ]
Python change xml attribute
39,250,857
<p>Python 2 Is it posible to change xml file using python when</p> <pre><code>&lt;Label name="qotl_type_label" position="910,980" font="headline_light" /&gt; </code></pre> <p>Search by name attribute and then change position?</p>
0
2016-08-31T13:22:46Z
39,250,940
<p>You can use the built-in <a href="https://docs.python.org/2/library/xml.etree.elementtree.html" rel="nofollow"><code>xml.etree.ElementTree</code></a> module to parse the XML, locate the <code>Label</code> element and change the <code>position</code> attribute via <a href="https://docs.python.org/2/library/xml.etree....
1
2016-08-31T13:26:17Z
[ "python", "python-2.7" ]
Think Python 4.1: Why does printing bob give me an object rather than an instance?
39,250,869
<p>All other answers on stackoverflow about instances vs. objects refer to classes, which the book hasn't covered yet. This is the code:</p> <pre><code>world= TurtleWorld() bob= Turtle() print bob wait_for_user() </code></pre> <p>and this is the result:</p> <p>It shows the turtle in a box, and prints</p> <pre><code...
0
2016-08-31T13:23:31Z
39,251,082
<p>You have an instance; an instance is a <em>kind</em> of Python object. If you didn't have an instance, you'd see something different:</p> <pre><code>&lt;class 'swampy.TurtleWorld.Turtle'&gt; </code></pre> <p>Now, in Python 2 using old-style classes, it would indeed have said <code>instance</code>; I can create suc...
1
2016-08-31T13:32:06Z
[ "python", "python-2.7", "oop" ]
maya component id data
39,250,993
<p>Does anyone know how to obtain the data in maya called the component ID of the vertices.</p> <p>I know how to get the vert number but the component ID on the vert is something that changes as the model has been changed. </p> <p>It seems that there is data in the vertex but just can't find any command to extract it...
0
2016-08-31T13:28:43Z
39,253,808
<p>try that, </p> <pre><code>import maya.OpenMaya as om sel = om.MSelectionList() om.MGlobal.getActiveSelectionList(sel) dag = om.MDagPath() comp = om.MObject() sel.getDagPath(0, dag, comp) itr = om.MItMeshFaceVertex(dag, comp) print '| %-15s| %-15s| %-15s' % ('Face ID', 'Object VertID', 'Face-relative VertId') while ...
0
2016-08-31T15:40:27Z
[ "python", "maya" ]
maya component id data
39,250,993
<p>Does anyone know how to obtain the data in maya called the component ID of the vertices.</p> <p>I know how to get the vert number but the component ID on the vert is something that changes as the model has been changed. </p> <p>It seems that there is data in the vertex but just can't find any command to extract it...
0
2016-08-31T13:28:43Z
39,379,215
<p>Maya components do not have persistent identities; the 'vertex id' is just the index of one entry in the vertex table (or the tables for faces, normals, etc). That's why its so easy to mess up a model with construction history if you go 'upstream' and change things that affect the model's component count or topolog...
0
2016-09-07T21:23:19Z
[ "python", "maya" ]
How can I copy a DOM Element form a existing Tree to a new Tree with minidom?
39,251,026
<p>I have to proceed a large XML file. I need a copy of the file, which contains specific Elements of the original file. I tried to generate the new DOM-document like this</p> <pre><code>import xml.dom.minidom as dom xml = dom.parse("somefile.xml") tree = dom.Document() copy = dom.Element("xmlcopy") tree.appendChild(c...
0
2016-08-31T13:30:11Z
39,251,435
<p>Use <code>importNode</code>: <code>tree.appendChild(tree.ownerDocument.importNode(header, TRUE))</code>.</p>
0
2016-08-31T13:46:12Z
[ "python", "xml", "dom" ]
How to read the status of the Power-LED on Raspberry Pi 3 with Python
39,251,079
<p>How to read the status of the Power-LED (or the rainbow square - if you like that better) on Raspberry Pi 3 to detect an low-voltage-condition in a python script? Since the wiring of the Power-LED has changed since Raspberry Pi 2, it seems that GPIO 35 cannot longer be used for that purpose.</p> <hr> <p><strong>Up...
1
2016-08-31T13:31:56Z
39,251,247
<p>Because of Pi3's BT/wifi support Power LED is controlled directly from the GPU through a GPIO expander. </p> <p>I believe that there's no way to do what you want</p>
2
2016-08-31T13:38:59Z
[ "python", "raspberry-pi3" ]
How to read the status of the Power-LED on Raspberry Pi 3 with Python
39,251,079
<p>How to read the status of the Power-LED (or the rainbow square - if you like that better) on Raspberry Pi 3 to detect an low-voltage-condition in a python script? Since the wiring of the Power-LED has changed since Raspberry Pi 2, it seems that GPIO 35 cannot longer be used for that purpose.</p> <hr> <p><strong>Up...
1
2016-08-31T13:31:56Z
39,251,786
<p>I have dig into the topic. Found a very good <a href="https://github.com/raspberrypi/linux/issues/1332" rel="nofollow">discussion</a>. In RPi 3 control of power LED from GPIO has been removed as OP mentioned.</p> <p>The probable reason:</p> <blockquote> <p>The power LED is different on Pi3. It is controlled from...
0
2016-08-31T14:01:56Z
[ "python", "raspberry-pi3" ]
Pyqt Terminal hangs after excuting close window command
39,251,122
<p>I have read lots of threads online, but still I could not find the solution. My question should be very simple: how to close a Pyqt window WITHOUT clicking a button or using a timer. The code I tried is pasted below</p> <pre><code>from PyQt4 import QtGui, QtCore import numpy as np import progressMeter_simple import...
0
2016-08-31T13:33:35Z
39,255,543
<p>It's not working because you're calling GUI methods on the dialog (<code>close()</code>) outside of the event loop. The event loop doesn't start until you call <code>app.exec_()</code>.</p> <p>If you really want to close the dialog <em>immediately</em> after it opens without using a <code>QTimer</code>, you can ov...
0
2016-08-31T17:23:13Z
[ "python", "pyqt", "pyqt4" ]
mpi4py: Spawn processes as Python threads for easier debugging
39,251,169
<p>To use mpi4py, the standard approach is to use <code>mpiexec</code> to start a program using multiple MPI processes. For example <code>mpiexec -n 4 python3.5 myprog.py</code>.</p> <p>Now, that makes debugging difficult, because one can not straight-forwardly use the Python interpreter plus maybe an IDE debugger usi...
0
2016-08-31T13:35:43Z
39,260,892
<p>You do not need to implement any hardcore idea. <code>mpiexec</code> is already spawning process for you. Assuming your using the pudb Python debugger you could do the following:</p> <p><code>mpiexec -np 4 xterm -e python2.7 -m pudb.run helloword.py</code></p> <p>The <code>-e</code> option of <code>xterm</code> is...
0
2016-09-01T00:14:58Z
[ "python", "multithreading", "mpi", "mpi4py" ]
Nested lists to nested dicts
39,251,223
<p>I've a list with master keys and a list of list of lists, where the first value of each enclosed list (like <code>'key_01'</code>) shall be a sub key for the corresponding values (like <code>'val_01', 'val_02'</code>). The data is shown here:</p> <pre><code>master_keys = ["Master_01", "Master_02", "Master_03"] data...
4
2016-08-31T13:37:51Z
39,251,450
<pre><code>master_keys = ["Master_01", "Master_02", "Master_03"] data_long = [[['key_01','val_01','val_02'],['key_02','val_03','val_04'], ['key_03','val_05','val_06']], [['key_04','val_07','val_08'], ['key_05','val_09','val_10'], ['key_06','val_11','val_12']], [['key_07','val_13','val_14'], ['key_...
6
2016-08-31T13:46:54Z
[ "python", "list", "dictionary", "enumerate" ]
Nested lists to nested dicts
39,251,223
<p>I've a list with master keys and a list of list of lists, where the first value of each enclosed list (like <code>'key_01'</code>) shall be a sub key for the corresponding values (like <code>'val_01', 'val_02'</code>). The data is shown here:</p> <pre><code>master_keys = ["Master_01", "Master_02", "Master_03"] data...
4
2016-08-31T13:37:51Z
39,251,502
<p>You can also use <code>pop</code> and a dict comprehension:</p> <pre><code>for key, elements in zip(master_keys, data_long): print {key: {el.pop(0): el for el in elements}} ...: {'Master_01': {'key_02': ['val_03', 'val_04'], 'key_03': ['val_05', 'val_06']}} {'Master_02': {'key_06': ['val_11', 'val_12'], 'key...
1
2016-08-31T13:48:47Z
[ "python", "list", "dictionary", "enumerate" ]
Nested lists to nested dicts
39,251,223
<p>I've a list with master keys and a list of list of lists, where the first value of each enclosed list (like <code>'key_01'</code>) shall be a sub key for the corresponding values (like <code>'val_01', 'val_02'</code>). The data is shown here:</p> <pre><code>master_keys = ["Master_01", "Master_02", "Master_03"] data...
4
2016-08-31T13:37:51Z
39,251,554
<p>Hope this will help:</p> <pre><code>{master_key: {i[0]: i[1:] for i in subkeys} for master_key, subkeys in zip(master_keys, data_long)} </code></pre>
2
2016-08-31T13:51:22Z
[ "python", "list", "dictionary", "enumerate" ]
Nested lists to nested dicts
39,251,223
<p>I've a list with master keys and a list of list of lists, where the first value of each enclosed list (like <code>'key_01'</code>) shall be a sub key for the corresponding values (like <code>'val_01', 'val_02'</code>). The data is shown here:</p> <pre><code>master_keys = ["Master_01", "Master_02", "Master_03"] data...
4
2016-08-31T13:37:51Z
39,251,576
<p>My functional approach:</p> <pre><code>master_dic = dict(zip(master_keys, [{k[0]: k[1::] for k in emb_list} for emb_list in data_long])) print(master_dic) </code></pre>
1
2016-08-31T13:52:29Z
[ "python", "list", "dictionary", "enumerate" ]
Get path of the current repo in PyGit2 from anywhere within the repo
39,251,365
<p>I'm using Pygit2 to run certain operations within the repo I'm working on.</p> <p>If my code file is not at the root of the repo, how can I get the path of the repo from anywhere within the repo?</p> <p>I can do the below in case the function is called from root, but how to do it if I run it from anywhere within t...
0
2016-08-31T13:43:23Z
39,252,289
<p>One option is simply to traverse parent directories until you find a <code>.git</code> directory:</p> <pre><code>import os import pathlib import pygit2 def find_toplevel(path, last=None): path = pathlib.Path(path).absolute() if path == last: return None if (path / '.git').is_dir(): ret...
1
2016-08-31T14:24:46Z
[ "python", "git", "python-3.x", "pygit2" ]
Using list comprehension to keep items not in second list
39,251,386
<p>I am trying to use list comprehension to remove a number of items from a list by just keeping those not specified.</p> <p>For example if I have 2 lists <code>a = [1,3,5,7,10]</code> and <code>b = [2,4]</code> I want to keep all items from <code>a</code> that are not at an index corresponding to a number in <code>b<...
0
2016-08-31T13:44:12Z
39,251,445
<p>You can use <a href="https://docs.python.org/2/library/functions.html#enumerate"><code>enumerate()</code></a> and look up indexes in <code>b</code>:</p> <pre><code>&gt;&gt;&gt; a = [1, 3, 5, 7, 10] &gt;&gt;&gt; b = [2, 4] &gt;&gt;&gt; [item for index, item in enumerate(a) if index not in b] [1, 3, 7] </code></pre> ...
6
2016-08-31T13:46:41Z
[ "python", "list", "list-comprehension", "not-operator" ]
Using list comprehension to keep items not in second list
39,251,386
<p>I am trying to use list comprehension to remove a number of items from a list by just keeping those not specified.</p> <p>For example if I have 2 lists <code>a = [1,3,5,7,10]</code> and <code>b = [2,4]</code> I want to keep all items from <code>a</code> that are not at an index corresponding to a number in <code>b<...
0
2016-08-31T13:44:12Z
39,251,534
<p>after this:</p> <pre><code>y = [a[x] for x in b] </code></pre> <p>just add:</p> <pre><code>for x in y: a.remove(x) </code></pre> <p>then you end up with a stripped down list in a</p>
-1
2016-08-31T13:50:08Z
[ "python", "list", "list-comprehension", "not-operator" ]
Using list comprehension to keep items not in second list
39,251,386
<p>I am trying to use list comprehension to remove a number of items from a list by just keeping those not specified.</p> <p>For example if I have 2 lists <code>a = [1,3,5,7,10]</code> and <code>b = [2,4]</code> I want to keep all items from <code>a</code> that are not at an index corresponding to a number in <code>b<...
0
2016-08-31T13:44:12Z
39,251,903
<p>Guess you're looking for somthing like : </p> <pre><code>[ x for x in a if a.index(x) not in b ] </code></pre> <p>Or, using filter:</p> <pre><code>filter(lambda x : a.index(x) not in b , a) </code></pre>
1
2016-08-31T14:07:45Z
[ "python", "list", "list-comprehension", "not-operator" ]
Using list comprehension to keep items not in second list
39,251,386
<p>I am trying to use list comprehension to remove a number of items from a list by just keeping those not specified.</p> <p>For example if I have 2 lists <code>a = [1,3,5,7,10]</code> and <code>b = [2,4]</code> I want to keep all items from <code>a</code> that are not at an index corresponding to a number in <code>b<...
0
2016-08-31T13:44:12Z
39,251,982
<p>Try this it will work </p> <pre><code> [j for i,j in enumerate(a) if i not in b ] </code></pre>
0
2016-08-31T14:10:30Z
[ "python", "list", "list-comprehension", "not-operator" ]
python invoking PV-Wave
39,251,432
<p>'/usr/local/bin/wave' only accepts a filename as input, so I need to invoke the process, then "send in" the commands, and wait for the output file to be written. Then my process can proceed to read the output file. Here is my code that does not write to the output file:</p> <pre><code>hdfFile = "/archive/HDF/160233...
0
2016-08-31T13:46:01Z
39,257,681
<p>I found what I was missing. The change is to the last 2 lines. They are:</p> <pre><code>wfile = subprocess.Popen ('/usr/local/bin/wave', stdin=subprocess.PIPE, stdout=subprocess.PIPE) wfile.communicate("\@hdf_startup\n\@hdf_common\n" + waveCmd + "\nquit\n") </code></pre> <p>I needed to set "stdout" to avoid extra ...
0
2016-08-31T19:36:22Z
[ "python", "linux" ]
Opening a SSL socket using a pem certificate
39,251,535
<p>I'm trying to connect to a ssl server using Java. I've already managed to do that in Python, however I've got a <code>PEM</code> file which isn't supported by Java. Converting it to <code>PKCS12</code> didn't work </p> <p>Error when trying to connect was:</p> <pre><code>sun.security.provider.certpath.SunCertPathBu...
0
2016-08-31T13:50:12Z
39,251,705
<p>don't you need to load the Key into the Java Keystore?</p> <p>that is a seperate program.</p> <p><a href="http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/keytool.html" rel="nofollow">http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/keytool.html</a></p> <p>-importcert {-alias alias} {-file...
1
2016-08-31T13:58:48Z
[ "java", "python", "sockets", "ssl", "ssl-certificate" ]
Two different ajax urls return the same data
39,251,588
<p>I am using jQuery ajax calls on my django site to populate the options in a select box which gets presented in a modal window that pops up (bootstrap) to the user. Specifically, it provides a list of available schemas in a particular database. The ajax url is dynamic which means it includes a db_host and a db_name...
1
2016-08-31T13:52:56Z
39,251,796
<p>Likely the problem in the way of setting <code>temporary_name</code> variable. It's not dynamic like it suppose to be ( I guess ), that's same database as first one are being used for all proceeding ajax calls, to fix it you have to replace line:</p> <pre><code>temporary_name = str(uuid.uuid4) </code></pre> <p>to...
0
2016-08-31T14:02:11Z
[ "javascript", "jquery", "python", "ajax", "django" ]
Formatting HTML style in PyCharm
39,251,661
<p>How to automatically generate tabs to get a proper tree view on a generated HTML file?</p> <p>For example, I've got a code like this:</p> <pre><code> def creating_html(self): something ='''&lt;table style="width:100%"&gt; &lt;tr&gt; &lt;th&gt;Firstname&lt;/th&gt; &lt;th&gt;Lastname&lt;/t...
0
2016-08-31T13:56:37Z
39,251,797
<pre><code>from lxml import etree, html html_string =''' &lt;table style="width:100%"&gt; &lt;tr&gt; &lt;th&gt;Firstname&lt;/th&gt; &lt;th&gt;Lastname&lt;/th&gt; &lt;th&gt;Age&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Jill...
1
2016-08-31T14:02:17Z
[ "python", "html", "python-2.7", "pycharm" ]
Formatting HTML style in PyCharm
39,251,661
<p>How to automatically generate tabs to get a proper tree view on a generated HTML file?</p> <p>For example, I've got a code like this:</p> <pre><code> def creating_html(self): something ='''&lt;table style="width:100%"&gt; &lt;tr&gt; &lt;th&gt;Firstname&lt;/th&gt; &lt;th&gt;Lastname&lt;/t...
0
2016-08-31T13:56:37Z
39,252,093
<p>You may use Beautiful Soup 4 installing it with pip and use it like follows:</p> <pre><code>from bs4 import BeautifulSoup something =''' &lt;table style="width:100%"&gt; &lt;tr&gt; &lt;th&gt;Firstname&lt;/th&gt; &lt;th&gt;Lastname&lt;/th&gt; &lt;th&gt;Age&lt;/th&gt; &...
2
2016-08-31T14:16:18Z
[ "python", "html", "python-2.7", "pycharm" ]
Tornado with_timeout correct usage
39,251,682
<p>I've got a web-server that runs some shell command. The command usually takes a couple of seconds, but in some occasions it takes more and in that case the client (it is not a web-browser or curl) disconnects. I have no possibility to fix the client, so I thought about fixing the server. It is based on tornado frame...
1
2016-08-31T13:57:26Z
39,252,642
<p>Although <code>run_slow_command</code> is decorated with <code>coroutine</code> it's still blocking, so Tornado is blocked and cannot run any code, including a timer, until the <code>os.system</code> call completes. You should defer the call to a thread:</p> <pre><code>from concurrent.futures import ThreadPoolExecu...
1
2016-08-31T14:41:21Z
[ "python", "tornado" ]
Multiple Dynamic OptionMenu using DataFrame in Python Tkinter GUI-PY_VAR21 Error
39,251,721
<p>I have been working on filtering the DataFrame rows so that I could arrive at a Single row with respect to different options chosen in OptionMenus in sequence. I did try to store the selected variable from OptionMenu and when I printed it, I get </p> <p>'PY_VAR21' </p> <p>as output. </p> <p>Can you kindly clarify...
0
2016-08-31T13:59:24Z
39,253,153
<p>When you see the <code>PY_VAR21</code> that is the instance of the variable. However if you say:</p> <pre><code>print self.variable0.get() </code></pre> <p>you should see the actual value of the variable.</p>
1
2016-08-31T15:05:55Z
[ "python", "python-2.7", "tkinter" ]
Multiple Dynamic OptionMenu using DataFrame in Python Tkinter GUI-PY_VAR21 Error
39,251,721
<p>I have been working on filtering the DataFrame rows so that I could arrive at a Single row with respect to different options chosen in OptionMenus in sequence. I did try to store the selected variable from OptionMenu and when I printed it, I get </p> <p>'PY_VAR21' </p> <p>as output. </p> <p>Can you kindly clarify...
0
2016-08-31T13:59:24Z
39,268,883
<p>see below for printing the variable outside the class after the loop has finished. </p> <pre><code>from Tkinter import * class GUI(): def __init__(self, master): self.variable0 = StringVar() self.variable0.set('Option1') self.option = OptionMenu(master, self.variable0, 'Option1', 'Opt...
0
2016-09-01T10:18:18Z
[ "python", "python-2.7", "tkinter" ]
Command error makemigrations in a Python/Django project
39,251,806
<p>Python: <code>2.7</code></p> <p>Django: <code>1.6</code></p> <p>I'm using <code>virtualenv</code> to manage my projects.</p> <p>I have my app added to INSTALLED_APPS.</p> <p>Tried to run the following command:</p> <pre><code>(pythonenv-1.6)xxxxx@xxxx.com python manage.py makemigrations Unknown command: 'makemig...
0
2016-08-31T14:02:42Z
39,251,930
<p>The message says that command is unknown. It was surely added in a later django version. If you don't like south you can drop table and run syncdb or manually change the SQL with ALTER command.</p>
0
2016-08-31T14:08:42Z
[ "python", "django", "virtualenv" ]
Command error makemigrations in a Python/Django project
39,251,806
<p>Python: <code>2.7</code></p> <p>Django: <code>1.6</code></p> <p>I'm using <code>virtualenv</code> to manage my projects.</p> <p>I have my app added to INSTALLED_APPS.</p> <p>Tried to run the following command:</p> <pre><code>(pythonenv-1.6)xxxxx@xxxx.com python manage.py makemigrations Unknown command: 'makemig...
0
2016-08-31T14:02:42Z
39,252,562
<p>Adding to Ninja Puppy comment, here's a formal answer for future reference:</p> <p>Django 1.6 relies on 3rd party add-on "South" and therefore we have to use this for initialising</p> <pre><code>./manage.py my_app_name southtut --initial </code></pre> <p>and then this for updating changes </p> <pre><code>./manag...
0
2016-08-31T14:38:07Z
[ "python", "django", "virtualenv" ]
UnsupportedAlgorithm: This backend does not support this key serialization. - Python cryptography load_pem_private_key
39,251,810
<p>I am trying to generate signed urls for AWS Cloudfront based on the example <a href="http://boto3.readthedocs.io/en/latest/reference/services/cloudfront.html#examples" rel="nofollow">here</a>. On the line </p> <pre><code>private_key = serialization.load_pem_private_key( key_file.read(), password=Non...
4
2016-08-31T14:03:00Z
39,268,177
<p>Unfortunately the python cryptography library cannot be used with google appengine(GAE) as this library needs to have C extensions and you cannot install C extensions in GAE. You can only use pure python packages.</p>
2
2016-09-01T09:47:52Z
[ "python", "google-app-engine", "boto3", "pem", "python-cryptography" ]
Python not taking picture at highest resolution from Raspberry Pi Camera
39,251,815
<p>I have a Raspberry Pi Camera version v2.1, capable of taking a picture with 3280x2464 resolution.</p> <p>I have taken a test with raspistill command, and this seems to work out fine:</p> <pre><code>raspistill -o 8mp.png -w 3280 -h 2464 </code></pre> <p>returns the info:</p> <pre><code>8mp.png JPEG 3280x2464 3280...
0
2016-08-31T14:03:12Z
40,000,497
<p>I ran into the same problem. I was able to solve it by adjusting the Pi's "Memory Split" setting to 256MB. This changes how much memory is available to the GPU. </p> <p>You can access this setting by running <code>sudo raspi-config</code>. "Memory Split" is under "Advanced Options".</p>
2
2016-10-12T13:54:46Z
[ "python", "camera", "raspberry-pi" ]
Find all items in a list that match a specific format
39,251,998
<p>I am trying to find everything in a list that has an format like "######-##"</p> <p>I thought I had the right idea in my following code, but it isn't printing anything. Some values in my list have that format, and I would think it should print it. Could you tell me what's wrong?</p> <pre><code>for line in list_num...
0
2016-08-31T14:11:19Z
39,252,304
<p>If you need to only match the pattern <code>######-##</code> (where <code>#</code> is a digit):</p> <pre><code>&gt;&gt;&gt; from re import compile, match &gt;&gt;&gt; regexp = compile(r'^\d{6}-\d{2}$') &gt;&gt;&gt; print([line for line in list_nums if regexp.match(line)]) ['132456-78'] </code></pre> <hr> <h1>Expl...
1
2016-08-31T14:25:12Z
[ "python", "loops", "for-loop" ]
Find all items in a list that match a specific format
39,251,998
<p>I am trying to find everything in a list that has an format like "######-##"</p> <p>I thought I had the right idea in my following code, but it isn't printing anything. Some values in my list have that format, and I would think it should print it. Could you tell me what's wrong?</p> <pre><code>for line in list_num...
0
2016-08-31T14:11:19Z
39,252,643
<p>Your code seems to be doing the right thing, with the exception that you want it to <strong>print</strong> the value of <em>line</em> instead of the value of <em>list_nums</em>. </p> <p>Another approach to the task at hand, would be to use regular expressions, which are ideal for pattern recognition.</p> <p><stron...
0
2016-08-31T14:41:21Z
[ "python", "loops", "for-loop" ]
Python - Checking if all and only the letters in a list match those in a string?
39,252,019
<p>I'm creating an <strong>Anagram Solver</strong> in <strong>Python 2.7</strong>.</p> <p>The solver takes a user inputted anagram, converts each letter to a list item and then checks the list items against lines of a '.txt' file, appending any words that match the anagram's letters to a <code>possible_words</code> li...
1
2016-08-31T14:12:25Z
39,252,113
<p>This is probably easiest to solve using a <code>collections.Counter</code></p> <pre><code>&gt;&gt;&gt; from collections import Counter &gt;&gt;&gt; Counter('Hello') == Counter('loleH') True &gt;&gt;&gt; Counter('Hello') == Counter('loleHl') False </code></pre> <p>The <code>Counter</code> will check that the letter...
3
2016-08-31T14:16:57Z
[ "python", "list", "python-2.7", "pattern-matching", "anagram" ]
Python - Checking if all and only the letters in a list match those in a string?
39,252,019
<p>I'm creating an <strong>Anagram Solver</strong> in <strong>Python 2.7</strong>.</p> <p>The solver takes a user inputted anagram, converts each letter to a list item and then checks the list items against lines of a '.txt' file, appending any words that match the anagram's letters to a <code>possible_words</code> li...
1
2016-08-31T14:12:25Z
39,252,176
<p>Your code does as it's expected. You haven't actually made it check whether a letter appears twice (or 3+ times), it just checks <code>if 'l' in word</code> twice, which will always be True for all words with at least one <code>l</code>.</p> <p>One method would be to count the letters of each word. If the letter co...
1
2016-08-31T14:19:53Z
[ "python", "list", "python-2.7", "pattern-matching", "anagram" ]
pygame - Snap Mouse to Grid
39,252,088
<p>I'm making a little platformer game using pygame, and decided that making a level editor for each level would be easier than typing each blocks' coordinate and size.</p> <hr> <p>I'm using a set of lines, horizontally and vertically to make a grid to make plotting points easier.</p> <p>Here's the code for my grid:...
1
2016-08-31T14:15:50Z
39,266,755
<p>First of all I think you're not far off.</p> <p>I think the problem is that the code runs quite fast through each game loop, so your mouse doesn't have time to move far before being set to the position return by your function. </p> <p>What I would have a look into is rather than to <code>pygame.mouse.set_pos()</co...
1
2016-09-01T08:44:50Z
[ "python", "python-2.7", "pygame", "grid-layout" ]
Using strings and byte-like objects compatibly in code to run in both Python 2 & 3
39,252,140
<p>I'm trying to modify the code shown far below, which works in Python 2.7.x, so it will also work unchanged in Python 3.x. However I'm encountering the following problem I can't solve in the first function, <code>bin_to_float()</code> as shown by the output below:</p> <pre class="lang-none prettyprint-override"><cod...
5
2016-08-31T14:18:21Z
39,252,964
<p>To make portable code that works with bytes in both Python 2 and 3 using libraries that literally use the different data types between the two, you need to explicitly declare them using the appropriate literal mark for every string (or add <a href="http://python-future.org/unicode_literals.html" rel="nofollow"><code...
3
2016-08-31T14:55:49Z
[ "python", "string", "python-2.7", "python-3.x", "bytestring" ]
Using strings and byte-like objects compatibly in code to run in both Python 2 & 3
39,252,140
<p>I'm trying to modify the code shown far below, which works in Python 2.7.x, so it will also work unchanged in Python 3.x. However I'm encountering the following problem I can't solve in the first function, <code>bin_to_float()</code> as shown by the output below:</p> <pre class="lang-none prettyprint-override"><cod...
5
2016-08-31T14:18:21Z
39,253,156
<p>I had a different approach from @metatoaster's answer. I just modified <code>int_to_bytes</code> to use and return a <code>bytearray</code>:</p> <pre><code>def int_to_bytes(n, minlen=0): # helper function """ Int/long to byte string. """ nbits = n.bit_length() + (1 if n &lt; 0 else 0) # plus one for any s...
1
2016-08-31T15:06:02Z
[ "python", "string", "python-2.7", "python-3.x", "bytestring" ]
Using strings and byte-like objects compatibly in code to run in both Python 2 & 3
39,252,140
<p>I'm trying to modify the code shown far below, which works in Python 2.7.x, so it will also work unchanged in Python 3.x. However I'm encountering the following problem I can't solve in the first function, <code>bin_to_float()</code> as shown by the output below:</p> <pre class="lang-none prettyprint-override"><cod...
5
2016-08-31T14:18:21Z
39,253,462
<p>In Python 3, integers have a <code>to_bytes()</code> method that can perform the conversion in a single call. However, since you asked for a solution that works on Python 2 and 3 unmodified, here's an alternative approach.</p> <p>If you take a detour via hexadecimal representation, the function <code>int_to_bytes(...
1
2016-08-31T15:21:59Z
[ "python", "string", "python-2.7", "python-3.x", "bytestring" ]
How to handle non-numeric entries in an integer valued column
39,252,170
<p>I have a dataframe <code>df</code> and one of the columns <code>count</code> is contains strings. These strings are mostly convertable to integers (e.g. <code>0006</code>) which is what I will do with them. However some of the entries in <code>count</code> are blank strings of spaces. How can I </p> <ul> <li>Drop a...
2
2016-08-31T14:19:39Z
39,253,837
<p>Use <code>dropna</code> or <code>fillna</code> after <code>pd.to_numeric(errosr='coerce')</code></p> <p>consider a pandas series <code>s</code></p> <pre><code>s = pd.Series(np.random.choice(('0001', ''), 1000000), name='intish') </code></pre> <p><strong><em>drop method 1</em></strong> (less robust)</p> <pre><cod...
3
2016-08-31T15:42:12Z
[ "python", "pandas" ]
How to handle non-numeric entries in an integer valued column
39,252,170
<p>I have a dataframe <code>df</code> and one of the columns <code>count</code> is contains strings. These strings are mostly convertable to integers (e.g. <code>0006</code>) which is what I will do with them. However some of the entries in <code>count</code> are blank strings of spaces. How can I </p> <ul> <li>Drop a...
2
2016-08-31T14:19:39Z
39,253,857
<p>It seems that you want two different things. But first, convert column <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_numeric.html#pandas.to_numeric" rel="nofollow">to numeric</a> and coerce errors:</p> <pre><code>df['count'] = pd.to_numeric(df['count'], errors='coerce') </code></pre> <p>...
3
2016-08-31T15:42:42Z
[ "python", "pandas" ]
Gensim: how to retrain doc2vec model using previous word2vec model
39,252,207
<p>With Doc2Vec modelling, I have trained a model and saved following files:</p> <pre><code>1. model 2. model.docvecs.doctag_syn0.npy 3. model.syn0.npy 4. model.syn1.npy 5. model.syn1neg.npy </code></pre> <p>However, I have a new way to label the documents and want to train the model again. since the word vectors alr...
0
2016-08-31T14:21:26Z
39,364,018
<p>I've figured out that, we can just load the model and continue to train. </p> <pre><code>model = Doc2Vec.load("old_model") model.train(sentences) </code></pre>
0
2016-09-07T07:42:51Z
[ "python", "gensim", "word2vec", "doc2vec" ]
How can I unit test a method using a datetime?
39,252,328
<p>I have the follow class and method:</p> <pre><code>class DateTimeHelper(object): @staticmethod def get_utc_millisecond_timestamp(): (dt, micro) = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f').split('.') return "%s.%03d" % (dt, int(micro) / 1000) # UTC time with millisecond </...
1
2016-08-31T14:26:32Z
39,252,463
<p>Use the <a href="https://docs.python.org/3/library/unittest.mock.html" rel="nofollow"><code>unittest.mock</code> library</a> (Python 3.3 and newer, backported as <a href="https://pypi.python.org/pypi/mock" rel="nofollow"><code>mock</code></a>), to replace calls to any code external to your code-under-test.</p> <p>H...
1
2016-08-31T14:32:49Z
[ "python", "unit-testing", "datetime" ]
Confusion with Fancy indexing (for non-fancy people)
39,252,370
<p>Let's assume a multi-dimensional array</p> <pre><code>import numpy as np foo = np.random.rand(102,43,35,51) </code></pre> <p>I know that those last dimensions represent a 2D space (35,51) of which I would like to index <strong>a range of rows</strong> of a <strong>column</strong> Let's say I want to have rows 8 to...
1
2016-08-31T14:28:51Z
39,255,017
<p>Instead of </p> <pre><code>foo[0][0][8::30][0] </code></pre> <p>try</p> <pre><code>foo[0, 0, 8:30, 0] </code></pre> <p>The <code>foo[0][0]</code> part is the same as <code>foo[0, 0, :, :]</code>, selecting a 2d array (35 x 51). But <code>foo[0][0][8::30]</code> selects a subset of those rows</p> <p>Consider wh...
2
2016-08-31T16:48:04Z
[ "python", "arrays", "numpy", "indexing", "scipy" ]
Make python for loop go only once
39,252,474
<p>Alright, so I'm trying to make a Facebook bot over here to do some stuff for me, But I don't really think that matters for you.</p> <p>Anyway, in order to achieve what I want to do I need to do some stuff. So, using the Facebook API I am getting some posts id with the following code:</p> <pre><code>for posts in pa...
-3
2016-08-31T14:33:25Z
39,252,506
<p>To get the last value (or first), simply use <code>"http://facebook.com/" + str(parsed_json[-1].get('id'))</code> (or parsed_json[0])</p> <p>If you want to use loop instead, to save just the last value, iterate and run the command afterwards:</p> <pre><code>post_url = '' for posts in parsed_json: post_id = pos...
3
2016-08-31T14:34:59Z
[ "python", "facebook" ]
Searching number of times a string (from file a) occurs in file b. Each string from file a is on a separate line
39,252,500
<p>I am a not new in Python but I am not an educated programmer and I use it very often for my work. So sorry in advance for any not elegant coding solutions. </p> <p>I have a file (.txt) with a unique string on each line. I want to know how many times each string occurs in another file. I build the following, which w...
-1
2016-08-31T14:34:36Z
39,252,722
<p><code>readlines()</code> does not remove the newline character. This should be clear if instead of <code>print y</code> you do <code>repr (y)</code> to reveal all the characters. So in your code you need:</p> <pre><code>y = Data_input_file_A[7].rstrip() </code></pre>
0
2016-08-31T14:44:32Z
[ "python", "search" ]
Recursion code not working as expected - Python 3
39,252,515
<p>I am a beginner to programming and in this case cannot understand why this Python code doesn't work as expected.</p> <p>I am trying to use recursion by calling a function within a function; calling the function n times, and reducing n by 1 to 0 with each loop at which point it will stop.</p> <p>Instead my code pri...
1
2016-08-31T14:35:27Z
39,252,609
<p>Recursion is not a loop!</p> <p>You should be <em>passing</em> <code>n - 1</code> to the recursive call instead of merely <code>n</code>, not subtracting one from <code>n</code> <em>after</em> this call.</p>
6
2016-08-31T14:39:48Z
[ "python", "recursion" ]
Recursion code not working as expected - Python 3
39,252,515
<p>I am a beginner to programming and in this case cannot understand why this Python code doesn't work as expected.</p> <p>I am trying to use recursion by calling a function within a function; calling the function n times, and reducing n by 1 to 0 with each loop at which point it will stop.</p> <p>Instead my code pri...
1
2016-08-31T14:35:27Z
39,252,689
<p>Passing <code>n-1</code> as parameter to recursive call fixes the problem.</p>
1
2016-08-31T14:43:11Z
[ "python", "recursion" ]
Recursion code not working as expected - Python 3
39,252,515
<p>I am a beginner to programming and in this case cannot understand why this Python code doesn't work as expected.</p> <p>I am trying to use recursion by calling a function within a function; calling the function n times, and reducing n by 1 to 0 with each loop at which point it will stop.</p> <p>Instead my code pri...
1
2016-08-31T14:35:27Z
39,291,844
<p>In the recursive call in line 6 you should pass print (do_n(arg,n-1)) .</p>
0
2016-09-02T11:55:43Z
[ "python", "recursion" ]
Using xpath to extract date
39,252,521
<p>I'm trying to extract the date from a webpage, '07/18/16' in the comment below. I'm not clear on the syntax for xpath, how would you grab just the date?</p> <pre><code>#&lt;p&gt;Opened &lt;a class="timeline" href="/trac3/timeline?from=2016-07- #18T14%3A46%3A43-04%3A00&amp;amp;precision=second" title="See timeli...
0
2016-08-31T14:35:37Z
39,252,887
<p>You cant do this. Xpath directly choose tag, not fields in it. So "//p/a[text()]" return all <code>&lt;a class="timeline" href="/trac3/timeline?from=2016-07-18T14%3A46%3A43-04%3A00&amp;amp;precision=second" title="See timeline at 07/18/16 14:46:43"&gt;6 weeks ago&lt;/a&gt;</code> Or you can choose by condition like ...
-1
2016-08-31T14:52:33Z
[ "python", "regex", "xpath", "python-requests", "lxml" ]
Using xpath to extract date
39,252,521
<p>I'm trying to extract the date from a webpage, '07/18/16' in the comment below. I'm not clear on the syntax for xpath, how would you grab just the date?</p> <pre><code>#&lt;p&gt;Opened &lt;a class="timeline" href="/trac3/timeline?from=2016-07- #18T14%3A46%3A43-04%3A00&amp;amp;precision=second" title="See timeli...
0
2016-08-31T14:35:37Z
39,252,900
<p>Here's one way only using xpath 1.0:</p> <pre><code>substring-before(substring-after(normalize-space(//a[contains(concat(' ',normalize-space(@class),' '),' timeline ')]/@title),'See timeline at '), ' ') </code></pre> <p>The <code>contains(concat(' ',normalize-space(@class),' '),' timeline ')</code> might seem like...
1
2016-08-31T14:52:57Z
[ "python", "regex", "xpath", "python-requests", "lxml" ]
Using xpath to extract date
39,252,521
<p>I'm trying to extract the date from a webpage, '07/18/16' in the comment below. I'm not clear on the syntax for xpath, how would you grab just the date?</p> <pre><code>#&lt;p&gt;Opened &lt;a class="timeline" href="/trac3/timeline?from=2016-07- #18T14%3A46%3A43-04%3A00&amp;amp;precision=second" title="See timeli...
0
2016-08-31T14:35:37Z
39,253,097
<p>XPath works by matching elements in an XML structured document.</p> <p>Your XPath will fail, because what you are saying is search the entire document ("//") for any elements called "Opened" (i.e. <code>&lt;Opened/&gt;</code>) and return their inner text ("text()").</p> <p>Assuming your HTML is consistent, what yo...
0
2016-08-31T15:02:58Z
[ "python", "regex", "xpath", "python-requests", "lxml" ]
Using xpath to extract date
39,252,521
<p>I'm trying to extract the date from a webpage, '07/18/16' in the comment below. I'm not clear on the syntax for xpath, how would you grab just the date?</p> <pre><code>#&lt;p&gt;Opened &lt;a class="timeline" href="/trac3/timeline?from=2016-07- #18T14%3A46%3A43-04%3A00&amp;amp;precision=second" title="See timeli...
0
2016-08-31T14:35:37Z
39,253,234
<p>Like this?</p> <pre><code>import re from lxml import html data = """&lt;p&gt;Opened &lt;a class="timeline" href="/trac3/timeline?from=2016-07-18T14%3A46%3A43-04%3A00&amp;amp;precision=second" title="See timeline at 07/18/16 14:46:43"&gt;6 weeks ago&lt;/a&gt;&lt;/p&gt;""" tree = html.fromstring(data) try: href...
2
2016-08-31T15:09:57Z
[ "python", "regex", "xpath", "python-requests", "lxml" ]
What is happning over here?Does python Override
39,252,542
<p><strong>Case 1:</strong></p> <pre><code>class A(object): def __init__(self): print "A" class B(A): pass c = b() #output: #A </code></pre> <p><strong>Case 2:</strong></p> <pre><code>class A(object): def __init__(self): print "A" class B(A): def __init__(self): print "B" c = b()...
0
2016-08-31T14:37:14Z
39,252,771
<p>According to the documentation, when a class is constructed the base class is always remembered. Thus, it will resolve all the dependencies if some attribute is not found, the process works in all base classes. In your case, the class B does not have a init method, so it calls its parent method. In the second exampl...
2
2016-08-31T14:47:06Z
[ "python", "oop", "constructor" ]
Using Python's multiprocessing to calculate the sum of integers from one long input line
39,252,595
<p>I want to use Python's multiprocessing module for the following: Map an input line to a list of integers and calculate the sum of this list.</p> <p>The input line is initially a string where the items to be summed are separated by spaces.</p> <p>What I have tried is this:</p> <pre><code>from itertools import imap...
1
2016-08-31T14:39:26Z
39,253,051
<p>So, this seems to roughly boil down to three steps:</p> <ol> <li>Make a <a href="https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool" rel="nofollow">pool</a></li> <li>Map int() across the list within that pool</li> <li>Sum the results.</li> </ol> <p>So:</p> <pre><code>if __name__ == '...
0
2016-08-31T15:00:56Z
[ "python", "python-2.7", "python-multiprocessing" ]
Using Python's multiprocessing to calculate the sum of integers from one long input line
39,252,595
<p>I want to use Python's multiprocessing module for the following: Map an input line to a list of integers and calculate the sum of this list.</p> <p>The input line is initially a string where the items to be summed are separated by spaces.</p> <p>What I have tried is this:</p> <pre><code>from itertools import imap...
1
2016-08-31T14:39:26Z
39,258,010
<p>Using a feature of Unix systems called <a href="https://en.wikipedia.org/wiki/Fork_(system_call)" rel="nofollow">forking</a>, you can read (not write) data from the parent process with zero overhead. Normally, you would have to copy the data over, but forking a process in Unix allows you to circumvent this.</p> <p>...
0
2016-08-31T19:57:37Z
[ "python", "python-2.7", "python-multiprocessing" ]
Caffe: Loading images and labels within python for fine-tuning
39,252,655
<p>I am having some problems when I try to load a batch of images + labels within python and try use it to train a network. I am working with pair of images, that I transform into one (for example, by averaging equivalent pixels from both images) and then I feed it to the network. As the number of pairs is too big (com...
1
2016-08-31T14:41:45Z
39,278,014
<p>The layer <code>ImageData</code> can only read images from a text file which holds the address of images on each line. You cannot use an <code>ImageData</code> layer and feed in images on the fly.</p> <p>If you are interested in loading images on the fly, checkout this <a href="http://stackoverflow.com/a/39097123/5...
0
2016-09-01T17:54:01Z
[ "python", "input", "batch-processing", "caffe", "pycaffe" ]