title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
How to determine wrong data type | 39,743,969 | <p>I use the following to see if the data is an integer, if not it tells me. Is there a way to determine which one is incorrect so can change it or would i have to create the same loop for every item?</p>
<pre><code>while i_input == True:
try:
i_pointstarget=int(pointstarget.get())
i_ap1=int(ap1.ge... | 0 | 2016-09-28T09:53:07Z | 39,746,263 | <p>Instead of trying to convert to <code>int</code> (btw <code>int(1.23)</code> works, returning <code>1</code>) you can also use <a href="https://docs.python.org/3/library/numbers.html" rel="nofollow">numbers</a> like</p>
<pre><code>import numbers
def is_integral(n): # actually not checking for int but also other int... | 0 | 2016-09-28T11:33:54Z | [
"python"
] |
How to determine wrong data type | 39,743,969 | <p>I use the following to see if the data is an integer, if not it tells me. Is there a way to determine which one is incorrect so can change it or would i have to create the same loop for every item?</p>
<pre><code>while i_input == True:
try:
i_pointstarget=int(pointstarget.get())
i_ap1=int(ap1.ge... | 0 | 2016-09-28T09:53:07Z | 39,746,473 | <p>To know the type of a variable you can use <code>isinstance(variable_name, int)</code>, this will return the Boolean value.</p>
| 0 | 2016-09-28T11:42:43Z | [
"python"
] |
Django redirecting everything to homepage | 39,743,993 | <p>I'm stuck with a Django project, I tried to add another app called login to make a login page but for some reason the page just redirects to the homepage except for the admin page</p>
<p>For example: 127.0.0.1:8000 will go to the homepage but 127.0.0.1:8000/login will also display the homepage even though I linked ... | 1 | 2016-09-28T09:53:45Z | 39,744,138 | <p>You don't terminate the portal index URL, so it matches everything. It should be:</p>
<pre><code>url(r'^$', views.index, name="portal"),
</code></pre>
| 3 | 2016-09-28T09:58:54Z | [
"python",
"django"
] |
Django redirecting everything to homepage | 39,743,993 | <p>I'm stuck with a Django project, I tried to add another app called login to make a login page but for some reason the page just redirects to the homepage except for the admin page</p>
<p>For example: 127.0.0.1:8000 will go to the homepage but 127.0.0.1:8000/login will also display the homepage even though I linked ... | 1 | 2016-09-28T09:53:45Z | 39,745,508 | <p>In addition, if the regex is login/$ but you enter http ://server/login, then it won't match wheras <a href="http://server/login/" rel="nofollow">http://server/login/</a> will.
You could try changing the regex to login/*$, which will match any number (even zero) / on the end of the url.</p>
<p>So http: //server/log... | 0 | 2016-09-28T10:56:58Z | [
"python",
"django"
] |
Django redirecting everything to homepage | 39,743,993 | <p>I'm stuck with a Django project, I tried to add another app called login to make a login page but for some reason the page just redirects to the homepage except for the admin page</p>
<p>For example: 127.0.0.1:8000 will go to the homepage but 127.0.0.1:8000/login will also display the homepage even though I linked ... | 1 | 2016-09-28T09:53:45Z | 39,745,636 | <p>I see 2 problems here:</p>
<ol>
<li>As @DanielRoseman mentioned above, the regular expression <code>^</code> matches anything, so you should change it to <code>^$</code>. </li>
<li>When you use an <code>include</code>, the rest of the path after what the <code>include</code> matched is passed to the included patte... | 1 | 2016-09-28T11:02:47Z | [
"python",
"django"
] |
Looks like base class constructor not initialized | 39,744,025 | <p>I am a newbie in python and trying my hands in oops programming here.
I am initializing base class constructor in derived class , but when trying to print its attribute in base class it gives me error<code>object has no attribute</code></p>
<pre><code>import random
import os
import sys
class Animal:
__name =""
... | 0 | 2016-09-28T09:54:44Z | 39,744,114 | <p>This is why you must not use double-underscore prefixes for your instance attributes. These are name mangled, and almost never do what you expect.</p>
<p>Just use <code>self.name</code> and <code>self.owner</code> everywhere.</p>
| 2 | 2016-09-28T09:57:50Z | [
"python",
"python-3.x",
"oop"
] |
Looks like base class constructor not initialized | 39,744,025 | <p>I am a newbie in python and trying my hands in oops programming here.
I am initializing base class constructor in derived class , but when trying to print its attribute in base class it gives me error<code>object has no attribute</code></p>
<pre><code>import random
import os
import sys
class Animal:
__name =""
... | 0 | 2016-09-28T09:54:44Z | 39,744,480 | <p>Variables starting with double underscores are said as private. They are mangled so they cannot be used in subclasses. Using CPython 3.5, you can confirm it simply with:</p>
<pre><code>>>> rocky.__dict__
{'_Animal__name': 'rocky', '_Dog__owner': 'Ronchi'}
>>>
</code></pre>
<p>When called from <co... | 0 | 2016-09-28T10:12:21Z | [
"python",
"python-3.x",
"oop"
] |
Looks like base class constructor not initialized | 39,744,025 | <p>I am a newbie in python and trying my hands in oops programming here.
I am initializing base class constructor in derived class , but when trying to print its attribute in base class it gives me error<code>object has no attribute</code></p>
<pre><code>import random
import os
import sys
class Animal:
__name =""
... | 0 | 2016-09-28T09:54:44Z | 39,744,784 | <p>Replace your method <code>get_name</code> of <code>Animal</code> with the following code</p>
<pre><code>@property
def name(self):
return self.__name
</code></pre>
<p>Also remember to update the <code>toString</code> of <code>Dog</code> to</p>
<pre><code>def toString(self):
return "{} is Animal. And owner ... | 2 | 2016-09-28T10:24:31Z | [
"python",
"python-3.x",
"oop"
] |
Resolution of the knapsack approach by bruteforce in python | 39,744,039 | <p>I'm actually trying to resolve the knapsack problem with bruteforce. I know it's not efficient at all, I just want to implement it in python.</p>
<p>The problem is it take long time. In my point of view too much time for a bruteforce. So maybe I make some mistakes in my code...</p>
<pre><code>def solve_it(input_da... | 0 | 2016-09-28T09:55:09Z | 39,745,354 | <p>Your issue, that solving the knapsack problem takes too long, is indeed frustrating, and it pops up in other places where algorithms are high-order polynomial or non-polynomial. You're seeing what it means for an algorithm to have exponential runtime ;) In other words, whether your python code is efficient or not,... | 0 | 2016-09-28T10:49:59Z | [
"python",
"brute-force",
"knapsack-problem"
] |
Index into vector field in 2 or 3 dimensions | 39,744,318 | <p>I have <code>vecfield</code> which is an <code>ndarray</code> with <code>m</code> entries for each spatial location in a (discrete) 2 or 3 dimensional space with shape <code>(w, h)</code> or <code>(w, h, d)</code>. Now I get an <code>ndarray</code> with a list of indices <code>(i, j)</code> or <code>(i, j, k)</code>... | 0 | 2016-09-28T10:05:47Z | 39,744,424 | <p>You should have a read about the way numpy advanced indexing works <a href="http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html</a>. I think what you want is:</p>
<pre><code>vecfield[zip(idx)]
</code></pre>
<p><code>zip(idx)<... | 1 | 2016-09-28T10:10:03Z | [
"python",
"numpy"
] |
Index into vector field in 2 or 3 dimensions | 39,744,318 | <p>I have <code>vecfield</code> which is an <code>ndarray</code> with <code>m</code> entries for each spatial location in a (discrete) 2 or 3 dimensional space with shape <code>(w, h)</code> or <code>(w, h, d)</code>. Now I get an <code>ndarray</code> with a list of indices <code>(i, j)</code> or <code>(i, j, k)</code>... | 0 | 2016-09-28T10:05:47Z | 39,752,799 | <pre><code>In [258]: vec=np.arange(24).reshape(4,3,2)
In [263]: idx=np.array([[0,0],[1,1],[3,2]])
In [264]: idx.shape
Out[264]: (3, 2)
In [265]: vec[idx,:].shape
Out[265]: (3, 2, 3, 2)
</code></pre>
<p>Indexing directly with <code>idx</code> effectively replaces that 1st dimension (of size 4) with this (3,2) array. ... | 0 | 2016-09-28T16:19:23Z | [
"python",
"numpy"
] |
Python, Pygame, Class object no longer callable | 39,744,404 | <p>I am writing a game using Pygame, now I am having this issue where I wanted to add a spawn timer on my monsters in the game. Now the timer works fine and the first spawn wave gets made and everything is great and terrific until the second wave where it says:</p>
<pre><code>Monster1 = Monster()
</code></pre>
<block... | 0 | 2016-09-28T10:09:00Z | 39,744,560 | <p>Somewhere in your code, you "overwrite" the name <code>Monster</code>, which then no longer points to your class.</p>
<p>Make sure you're not doing a <code>Monster = whatever</code> anywhere in your code.</p>
<p>Also, note that <code>Current_HP</code>, <code>Max_Hp</code> etc. are class members, not instance membe... | 1 | 2016-09-28T10:15:10Z | [
"python",
"pygame"
] |
Python enable logging for executable during run time | 39,744,546 | <p>I've created a python module with logging library displaying information. Example of logging output would be...</p>
<pre><code>2016-09-28 02:54:39,089 - INFO - dataServer - Listening for incoming connections...
2016-09-28 02:54:41,089 - INFO - dataServer - Listening for incoming connections...
</code></pre>
<p>I'v... | 0 | 2016-09-28T10:14:36Z | 39,746,686 | <p>You must have added a <em>FileHandler</em> to output the content to a file. Similarly to output the content to console add <em>StreamHandler</em> in this way <strong>sh = logging.StreamHandler(sys.stdout)</strong> and add this handler to logger by <strong>logger.addHandler(sh)</strong></p>
<p>Hope this helps, cheer... | 1 | 2016-09-28T11:52:19Z | [
"python",
"logging",
"exe",
"pyinstaller"
] |
Odoo ERP how to save lines when I press "Save & Close" button from Pop Up window? | 39,744,579 | <p>One of the most annoying feature of Open ERP is:<br>
I have to press main <strong>Save</strong> <em>button(picture 2, item 3)</em> on left top corner even though I already pressed <strong>Save and Close</strong> <em>picture 1, item 1</em> from Pop Up window of products.<br>
I included screenshot from Warehouse modul... | 1 | 2016-09-28T10:15:40Z | 39,784,432 | <p>You can't save One2many record without saving parent form.
As child(one2many) is dependent on Parent Form Class. and making any shortcut for saving one2many record without saving parent can affect system badly.</p>
<p>So Please follow the standard process.</p>
| 0 | 2016-09-30T05:40:30Z | [
"python",
"openerp"
] |
Serve protected media files with django | 39,744,587 | <p>I'd like Django to serve some media files (e.g. user-uploaded files) only for logged-in users. Since my site is quite low-traffic, I think I will keep things simple and do not use <code>django-sendfile</code> to tell Nginx when to serve a file. Instead I'll let Django/Gunicorn do the job. To me this seems a lot simp... | 0 | 2016-09-28T10:16:03Z | 39,749,214 | <p>I now came up with the following solution:</p>
<p>I have this in my Django settings:</p>
<pre><code>MEDIA_ROOT = "/projects/project/media/"
MEDIA_URL = "/media/
</code></pre>
<p>In my models I do either:</p>
<pre><code>document = models.FileField(upload_to="public/documents")
</code></pre>
<p>or</p>
<pre><code... | 0 | 2016-09-28T13:38:30Z | [
"python",
"django",
"python-3.x",
"nginx",
"nginx-location"
] |
How to create a Django superuser if it doesn't exist non-interactively? | 39,744,593 | <p>I want to automate creation of Django users via a Bash script. I found this snippet which almost suits my needs: </p>
<pre><code>echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', 'pass')" |\
python manage.py shell
</code></pre>
<p>How can I modify ... | 0 | 2016-09-28T10:16:22Z | 39,744,835 | <p>you can use <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#get-or-create" rel="nofollow">get_or_create()</a>. If it exists it will do nothing, else it will create one.</p>
<p>You'd have to set the <code>is_staff</code> and <code>is_superuser</code> to <code>True</code> manually</p>
| 0 | 2016-09-28T10:26:39Z | [
"python",
"django",
"django-users"
] |
How to create a Django superuser if it doesn't exist non-interactively? | 39,744,593 | <p>I want to automate creation of Django users via a Bash script. I found this snippet which almost suits my needs: </p>
<pre><code>echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', 'pass')" |\
python manage.py shell
</code></pre>
<p>How can I modify ... | 0 | 2016-09-28T10:16:22Z | 39,745,093 | <p>You can use <code>filter()</code> and <code>exists()</code> to check whether the a user with that username exists before you create it.</p>
<pre><code>if not User.objects.filter(username="admin").exists():
User.objects.create_superuser('admin', 'admin@example.com', 'pass')
</code></pre>
| 0 | 2016-09-28T10:39:01Z | [
"python",
"django",
"django-users"
] |
How to create a Django superuser if it doesn't exist non-interactively? | 39,744,593 | <p>I want to automate creation of Django users via a Bash script. I found this snippet which almost suits my needs: </p>
<pre><code>echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', 'pass')" |\
python manage.py shell
</code></pre>
<p>How can I modify ... | 0 | 2016-09-28T10:16:22Z | 39,745,576 | <p>Using some <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/" rel="nofollow">QuerySet API</a> methods and a heredoc for readability:</p>
<pre><code>cat <<EOF | python manage.py shell
from django.contrib.auth.models import User
User.objects.filter(username="admin").exists() or \
User.ob... | 0 | 2016-09-28T11:00:28Z | [
"python",
"django",
"django-users"
] |
Why Flask Migrate doesn't create an empty migration file? | 39,744,688 | <p>I am using Flask, Flask-SqlAlchemy and Flask-Migrate to manage my models. And I just realize that in my latest database state, when I create a new migration file, <code>python manage.py db migrate -m'test migration</code>, it will not create an empty migration file. Instead it tries to create and drop several unique... | 1 | 2016-09-28T10:20:32Z | 39,761,658 | <p>If you have made no changes to your model from the current migration, but you get a non-empty migration file generated, then it suggests for some reason your models became out of sync with the database, and the contents of this new migration are just the things that are mismatched.</p>
<p>If you say that the migrat... | 1 | 2016-09-29T04:51:56Z | [
"python",
"flask-sqlalchemy",
"flask-migrate"
] |
Python: shared methods and attributes in multiple inheritance | 39,744,693 | <p>I simply want to create a class which inherits attributes and methods from two parents. Let's just say the two parent classes are</p>
<pre><code>class A(object):
def __init__(self, a):
self.a = a
def method_a(self):
return self.a + 10
class B(object):
def __init__(self, b):
se... | -2 | 2016-09-28T10:20:44Z | 39,745,662 | <p>As far as I know, the way <code>super</code> works is that, based on the list of superclasses declared at the beginning of the subclass, an <code>mro</code> (method resolution order) list will be worked out. When you call <code>supper</code> (Python 3), the <code>__init__</code> of the first class in the <code>mro</... | 0 | 2016-09-28T11:04:19Z | [
"python",
"inheritance"
] |
IndexError when using Scrapy for absolute links | 39,744,845 | <p>I am scraping a webpage from Wikipedia (particularly <a href="https://en.wikipedia.org/wiki/Category:2013_films" rel="nofollow">this</a> one) using a Python library called <a href="https://doc.scrapy.org/en/1.2/" rel="nofollow">Scrapy</a>. Here was the original code which successfully crawled the page:</p>
<pre><co... | 0 | 2016-09-28T10:27:11Z | 39,745,183 | <p>I think you can just concatenate the two strings instead of using <code>urljoin</code>. Try this:</p>
<pre><code>for title in titles:
item = WikipediaItem()
item["title"] = title.xpath("a/text()").extract()
item["url"] = "http://en.wikipedia.org" + title.xpath("a/@href").extract()[0]
items.append(it... | 0 | 2016-09-28T10:42:29Z | [
"python",
"json",
"xpath",
"scrapy"
] |
IndexError when using Scrapy for absolute links | 39,744,845 | <p>I am scraping a webpage from Wikipedia (particularly <a href="https://en.wikipedia.org/wiki/Category:2013_films" rel="nofollow">this</a> one) using a Python library called <a href="https://doc.scrapy.org/en/1.2/" rel="nofollow">Scrapy</a>. Here was the original code which successfully crawled the page:</p>
<pre><co... | 0 | 2016-09-28T10:27:11Z | 39,745,959 | <p>On your first iteration of code with relative links, you used the <code>xpath</code> method: <code>item["url"] = title.xpath("a/@href").extract()</code>
The object returned is (I assume) a list of strings, so indexing it would be valid.</p>
<p>In the new iteration, you used the <code>select</code> method: <code>ur... | 0 | 2016-09-28T11:19:23Z | [
"python",
"json",
"xpath",
"scrapy"
] |
IndexError when using Scrapy for absolute links | 39,744,845 | <p>I am scraping a webpage from Wikipedia (particularly <a href="https://en.wikipedia.org/wiki/Category:2013_films" rel="nofollow">this</a> one) using a Python library called <a href="https://doc.scrapy.org/en/1.2/" rel="nofollow">Scrapy</a>. Here was the original code which successfully crawled the page:</p>
<pre><co... | 0 | 2016-09-28T10:27:11Z | 39,747,349 | <p>So after mirroring the code to the example given in the documentation <strong><a href="https://doc.scrapy.org/en/latest/topics/spiders.html" rel="nofollow">here</a></strong>, I was able to get the code to work:</p>
<pre><code>def parse(self, response):
for text in response.xpath('//div[@id="mw-pages"]//li/a/tex... | 0 | 2016-09-28T12:20:27Z | [
"python",
"json",
"xpath",
"scrapy"
] |
IndexError when using Scrapy for absolute links | 39,744,845 | <p>I am scraping a webpage from Wikipedia (particularly <a href="https://en.wikipedia.org/wiki/Category:2013_films" rel="nofollow">this</a> one) using a Python library called <a href="https://doc.scrapy.org/en/1.2/" rel="nofollow">Scrapy</a>. Here was the original code which successfully crawled the page:</p>
<pre><co... | 0 | 2016-09-28T10:27:11Z | 39,772,731 | <p>For better clarification, i am going to modify above code,</p>
<pre><code>for title in titles:
item = WikipediaItem()
item["title"] = title.xpath("a/text()").extract()
item["url"] = "http://en.wikipedia.org" + title.xpath("a/@href").extract()[0]
items.append(item)
return(items)
</code></pre>
| 0 | 2016-09-29T14:13:03Z | [
"python",
"json",
"xpath",
"scrapy"
] |
Flask Registration Form Condition if elif else doesn't work | 39,745,076 | <p>When I try to register an user, I don't know why, but if the email I'm trying to register does not exist in the db, the for loop ends, though there's an elif end else statement.</p>
<p>Someone know why?</p>
<p>This is the web.py file</p>
<pre><code>from flask import Flask, session, redirect, url_for, escape, requ... | -2 | 2016-09-28T10:38:17Z | 39,747,839 | <p>Like I said in the comment, this is hardly a programming problem, it's a logic problem.</p>
<pre><code>cur.execute("SELECT * FROM users WHERE email = (%s)", [email])
</code></pre>
<p>That will give you all users that already use this email. So there are 2 possibilities : </p>
<ol>
<li>There is at least one user (... | 2 | 2016-09-28T12:40:01Z | [
"python",
"if-statement",
"flask"
] |
ValueError: I/O operation on closed file - Already googled | 39,745,167 | <p>What is wrong with this error message? I googled for it and i still have no idea</p>
| -2 | 2016-09-28T10:41:50Z | 39,745,242 | <p>This is where you open the file:</p>
<pre><code>with open("rofl.csv", "rb") as f, open("out.csv", "wb") as out:
</code></pre>
<p>The <code>with</code> block establishes the context. As soon as this context is left, the file will be closed. This:</p>
<pre><code>writer.writerow([id_, name, combinedaddress, dateprin... | 0 | 2016-09-28T10:44:44Z | [
"python"
] |
JIRA API error when trying to pull details when field is empty | 39,745,246 | <p>I am using the JIRA API to pull ticket details and put it in a separate database that I can connect Tableau to.
My problem is that when pulling in a ticket details (using python) where e.g. it has no priority, that I get an error.
How do I get around that error? How can I handle this error?</p>
<p>Just currently te... | 0 | 2016-09-28T10:44:53Z | 39,745,502 | <p>Catch the AttributeError</p>
<pre><code>for issue in issues:
if verbose:
try:
print( "issue.key: ", issue.key );
print( "issue.fields.project.id: ", issue.fields.project.id );
except AttributeError:
pass
</code></pre>
| 1 | 2016-09-28T10:56:42Z | [
"python",
"jira",
"jira-rest-api"
] |
JIRA API error when trying to pull details when field is empty | 39,745,246 | <p>I am using the JIRA API to pull ticket details and put it in a separate database that I can connect Tableau to.
My problem is that when pulling in a ticket details (using python) where e.g. it has no priority, that I get an error.
How do I get around that error? How can I handle this error?</p>
<p>Just currently te... | 0 | 2016-09-28T10:44:53Z | 39,747,370 | <p>Thanks @Karimtabet.
It seems though that the following worked better:</p>
<pre><code>if verbose:
try:
print( "issue.key: ", issue.key );
print( "issue.fields.project.id: ", issue.fields.project.id );
except AttributeError:
key = None
</code></pre>
| 0 | 2016-09-28T12:21:29Z | [
"python",
"jira",
"jira-rest-api"
] |
Python logs working on one pycharm and not on another | 39,745,322 | <p>I've created this python script to help me create log files while running my script and it works perfectly in my own machine. But for some reason the exact code does not work on other machines.
In my machine it shows the logs in pycharm console and also saves them in a file. In other machines it doesn't do anything ... | 0 | 2016-09-28T10:48:12Z | 39,803,396 | <p>Try to explicitly set the logging level, for example:</p>
<pre><code>log.setLevel(logging.DEBUG)
</code></pre>
<p>Otherwise you're relying on the default value which <em>might</em> be different on different python versions that may be installed on different machines. For example on 2.7.12 the default level is set... | 0 | 2016-10-01T05:38:02Z | [
"python",
"logging",
"pycharm"
] |
Python 2.7 Anaconda2 installed in windows | 39,745,371 | <p>My Python 2 environmental path:</p>
<pre><code>C:\Python27
C:\Python27\Scripts
</code></pre>
<p>My Python 3 environmental path:</p>
<pre><code>C:\Python35
C:\Python35\Scripts
</code></pre>
<p>I set the environmental path for Anaconda2</p>
<pre><code>C:\Users\User\Anaconda2\Scripts
C:\Users\User\Anaconda2
</code... | 0 | 2016-09-28T10:50:50Z | 39,745,580 | <p>Each Python installation has its own libraries. As you will see, you are not running the same Python 2.7 interpreter when you run with Anaconda active as you are without (I assume that's either the system Python or one you installed yourself).</p>
<p>Libraries installed in one interpreter aren't available to others... | 0 | 2016-09-28T11:00:34Z | [
"python",
"anaconda"
] |
How to parse different parts of a JSON file in Python? | 39,745,396 | <p>I'm making a program in Python that gets bus times from a server and prints them. The JSON file looks like this:</p>
<pre><code>{
"errorcode": "0",
"errormessage": "",
"numberofresults": 4,
"stopid": "175",
"timestamp": "28/09/2016 10:32:44",
"results": [
{
"arrivaldatetime": "28/09/2016 10:43:36",
"duetime": "10",... | -2 | 2016-09-28T10:52:02Z | 39,745,511 | <pre><code>print info['results']['routes']
</code></pre>
<p>Try above.</p>
| 0 | 2016-09-28T10:57:04Z | [
"python",
"json",
"parsing",
"python-requests"
] |
Python: classify text into the categories | 39,745,431 | <p>I have a part of training set</p>
<pre><code>url category
ebay.com/sch/Mens-Clothing-/1059/i.html?_from=R40&LH_BIN=1&Bottoms%2520Size%2520%2528Men%2527s%2529=33&Size%2520Type=Regular&_nkw=ÐжинÑÑ&_dcat=11483&Inseam=33&rt=nc&_trksid=p2045573.m1684 Ðнлайн-магазин
goo... | 1 | 2016-09-28T10:53:14Z | 39,745,701 | <p>Basically you will classify strings into categories. Therefore you will to use a classifier. But you will not just use one classifier but rather test several and chose the most accurate. </p>
<p>Yet firstly, you will have to think about features of each url. I expect that you will not achieve great accuracy if you ... | 2 | 2016-09-28T11:06:30Z | [
"python",
"url",
"machine-learning",
"scikit-learn",
"text-classification"
] |
How to keep specific element indexs in an array | 39,745,545 | <p>Suppose I have two arrays:</p>
<pre><code>a = [1, 4, 9, 16, 25, 36, 49, 64, 81]
b = [2,5,7]
</code></pre>
<p>And I want to keep the elements indexed in a that are listed in b so the 2nd, 5th and 7th index of a:</p>
<pre><code>a_new = [4, 25, 49]
</code></pre>
<p>I will then plot b against a_new / perform analysi... | -1 | 2016-09-28T10:58:52Z | 39,746,059 | <p>There are two possible problems that you may be encountering, both of which have been somewhat mentioned in the comments. From what I see, you either have a problem reading the or you have an invalid index in <code>b</code>.</p>
<p>For the former, you may actually want</p>
<pre><code>a = [1, 4, 9, 16, 25, 36, 49, ... | 1 | 2016-09-28T11:24:10Z | [
"python",
"arrays",
"list",
"indexing"
] |
How to keep specific element indexs in an array | 39,745,545 | <p>Suppose I have two arrays:</p>
<pre><code>a = [1, 4, 9, 16, 25, 36, 49, 64, 81]
b = [2,5,7]
</code></pre>
<p>And I want to keep the elements indexed in a that are listed in b so the 2nd, 5th and 7th index of a:</p>
<pre><code>a_new = [4, 25, 49]
</code></pre>
<p>I will then plot b against a_new / perform analysi... | -1 | 2016-09-28T10:58:52Z | 39,746,820 | <p>First remember that the first element of an array (or in this case a list) is number 0 and not number 1:</p>
<pre><code>a = [1, 4, 9, 16, 25, 36, 49, 64, 81]
a[0] = 1 # How to adress the first element
a[1] = 4 # How to adress the second element
a[2] = 9 # ...
</code></pre>
<p>So the elements you want (as spe... | 2 | 2016-09-28T11:58:51Z | [
"python",
"arrays",
"list",
"indexing"
] |
Is there a pythonic way of permuting a list of list? | 39,745,571 | <p>I have a list of lists containing unique strings and I want to produce an arbitrary number of different ways of sorting it. The list might look like the following:</p>
<pre><code>list = [[a], [b,c], [d], [e,f,g]]
</code></pre>
<p>The order of the lists need to be the same but I want to shuffle the ordering within ... | 1 | 2016-09-28T10:59:55Z | 39,745,708 | <p>You can flatten the list then simply generate its permutations:</p>
<pre><code>from itertools import chain, permutations
li = [['a'], ['b','c'], ['d'], ['e','f','g']]
flattened = list(chain.from_iterable(li))
for perm in permutations(flattened, r=len(flattened)):
print(perm)
>> ('a', 'b', 'c', 'd', 'e',... | -1 | 2016-09-28T11:06:47Z | [
"python",
"list",
"python-2.7",
"permutation"
] |
Is there a pythonic way of permuting a list of list? | 39,745,571 | <p>I have a list of lists containing unique strings and I want to produce an arbitrary number of different ways of sorting it. The list might look like the following:</p>
<pre><code>list = [[a], [b,c], [d], [e,f,g]]
</code></pre>
<p>The order of the lists need to be the same but I want to shuffle the ordering within ... | 1 | 2016-09-28T10:59:55Z | 39,745,867 | <pre><code>from itertools import permutations, product
L = [['a'], ['b','c'], ['d'], ['e', 'f', 'g']]
for l in product(*map(lambda l: permutations(l), L)):
print([item for s in l for item in s])
</code></pre>
<p>produces:</p>
<pre><code>['a', 'b', 'c', 'd', 'e', 'f', 'g']
['a', 'b', 'c', 'd', 'e', 'g', 'f']
['a... | 2 | 2016-09-28T11:14:45Z | [
"python",
"list",
"python-2.7",
"permutation"
] |
Is there a pythonic way of permuting a list of list? | 39,745,571 | <p>I have a list of lists containing unique strings and I want to produce an arbitrary number of different ways of sorting it. The list might look like the following:</p>
<pre><code>list = [[a], [b,c], [d], [e,f,g]]
</code></pre>
<p>The order of the lists need to be the same but I want to shuffle the ordering within ... | 1 | 2016-09-28T10:59:55Z | 39,745,940 | <pre><code>from itertools import chain, permutations
your_list = [[a], [b,c], [d], [e,f,g]]
flattened = chain.from_iterable(your_list)
perms = permutations(flattened)
for perm in perms:
print perm
</code></pre>
<p>References:</p>
<ul>
<li><a href="https://docs.python.org/2/library/itertools.html#itertools.permut... | -1 | 2016-09-28T11:18:04Z | [
"python",
"list",
"python-2.7",
"permutation"
] |
Is there a pythonic way of permuting a list of list? | 39,745,571 | <p>I have a list of lists containing unique strings and I want to produce an arbitrary number of different ways of sorting it. The list might look like the following:</p>
<pre><code>list = [[a], [b,c], [d], [e,f,g]]
</code></pre>
<p>The order of the lists need to be the same but I want to shuffle the ordering within ... | 1 | 2016-09-28T10:59:55Z | 39,746,045 | <p>You can do this by taking the Cartesian product of the permutations of the sub-lists, and then flattening the resulting nested tuples. </p>
<pre><code>from itertools import permutations, product, chain
lst = [['a'], ['b', 'c'], ['d'], ['e', 'f', 'g']]
for t in product(*[permutations(u) for u in lst]):
print([... | 3 | 2016-09-28T11:23:28Z | [
"python",
"list",
"python-2.7",
"permutation"
] |
Is there a pythonic way of permuting a list of list? | 39,745,571 | <p>I have a list of lists containing unique strings and I want to produce an arbitrary number of different ways of sorting it. The list might look like the following:</p>
<pre><code>list = [[a], [b,c], [d], [e,f,g]]
</code></pre>
<p>The order of the lists need to be the same but I want to shuffle the ordering within ... | 1 | 2016-09-28T10:59:55Z | 39,746,162 | <p>This might not be the most elegant solution, but I think it does what you want</p>
<pre><code>from itertools import permutations
import numpy as np
def fac(n):
if n<=1:
return 1
else:
return n * fac(n-1)
lists = [['a'], ['b','c'], ['d'], ['e','f','g']]
combined = [[]]
for perm in [perm... | 0 | 2016-09-28T11:29:14Z | [
"python",
"list",
"python-2.7",
"permutation"
] |
Setting a row index on and querying a pandas dataframe with multi-index columns | 39,745,627 | <p>Starting from a <code>pandas</code> dataframe with a multi-dimensional column heading structure such as the following, is there a way I can transform the <code>Area Names</code> and <code>Area Codes</code> headings so they span each level (i.e. so single <code>Area Names</code> and <code>Area Codes</code> labels spa... | 1 | 2016-09-28T11:02:25Z | 39,745,756 | <p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a> with tuples for set by <code>MultiIndex</code>:</p>
<pre><code>df.set_index([('Area Codes','Area Codes','Area Codes'),
('Area Names','Area Names','... | 1 | 2016-09-28T11:09:08Z | [
"python",
"pandas",
"indexing",
"multiple-columns",
"multi-index"
] |
Change dictionary values from int to string | 39,745,633 | <p>This is what my dictionary looks like.</p>
<pre><code>phoneBook = {"Skywalker": 55511243, "Solo": 55568711, "Vader": 55590858}
</code></pre>
<p>I need to change each phonenumber into a string and add <code>"+1-"</code> in front of it. But, I'm not sure how to do it.</p>
| -1 | 2016-09-28T11:02:42Z | 39,745,692 | <p>Use a dictionary comprehension</p>
<pre><code>{k:'+1-'+str(phoneBook[k]) for k in phoneBook}
</code></pre>
| 1 | 2016-09-28T11:06:08Z | [
"python",
"string",
"python-3.x",
"dictionary",
"int"
] |
Change dictionary values from int to string | 39,745,633 | <p>This is what my dictionary looks like.</p>
<pre><code>phoneBook = {"Skywalker": 55511243, "Solo": 55568711, "Vader": 55590858}
</code></pre>
<p>I need to change each phonenumber into a string and add <code>"+1-"</code> in front of it. But, I'm not sure how to do it.</p>
| -1 | 2016-09-28T11:02:42Z | 39,745,735 | <p>With a simple dictionary comprehension:</p>
<pre><code>r = {k: "+1-{}".format(v) for k,v in phoneBook.items()}
</code></pre>
<p>Where <code>"+1-{}".format(v)</code> converts to a string and prepends <code>+1-</code> to it. Similarly you could use <code>"+1-" + str(v)</code> as noted in the other answer but I <em>p... | 2 | 2016-09-28T11:08:03Z | [
"python",
"string",
"python-3.x",
"dictionary",
"int"
] |
C++ code not exiting when wrapped in python | 39,745,751 | <p>I am having an issue with my python code exiting while running my c++ code lib. I can't seem to figure out if its the python code doing it or my c++. Any help would be greatly appreciated. </p>
<p>Here is my cpp</p>
<pre><code>class Led {
public:
void snowled()
{
LinuxGPIO gpio23(23);
gpio23... | -1 | 2016-09-28T11:08:53Z | 39,746,285 | <p>The call <code>sys.exit()</code> actually raise a <a href="https://docs.python.org/2/library/exceptions.html#exceptions.SystemExit" rel="nofollow">SystemExit</a> exception. Without parameters, the exit status is zero. </p>
<p>Why do you catch it?</p>
| 0 | 2016-09-28T11:34:59Z | [
"python",
"c++",
"cpython"
] |
Speed-up cython code | 39,745,881 | <p>I have code that is working in python and want to use cython to speed up the calculation. The function that I've copied is in a .pyx file and gets called from my python code. V, C, train, I_k are 2-d numpy arrays and lambda_u, user, hidden are ints.
I don't have any experience in using C or cython. What is an effic... | 1 | 2016-09-28T11:15:25Z | 39,747,088 | <p>The first thing that comes to mind is you haven't typed the function arguments and specified the data type and number of dimensions like so :</p>
<pre><code>def u_update(np.ndarray[np.float64, ndim=2]V, np.ndarray[np.float64, ndim=2]\
C, np.ndarray[np.float64, ndim=2] train, np.ndarray[np.float64, ndim=2] \
I_k, in... | 1 | 2016-09-28T12:09:49Z | [
"python",
"numpy",
"cython"
] |
Speed-up cython code | 39,745,881 | <p>I have code that is working in python and want to use cython to speed up the calculation. The function that I've copied is in a .pyx file and gets called from my python code. V, C, train, I_k are 2-d numpy arrays and lambda_u, user, hidden are ints.
I don't have any experience in using C or cython. What is an effic... | 1 | 2016-09-28T11:15:25Z | 39,752,528 | <p>You are trying to use <code>cython</code> by diving into the deep end of pool. You should start with something small, such as some of the numpy examples. Or even try to improve on <code>np.diag</code>.</p>
<pre><code> i = 0
C_i = np.zeros((m, m), dtype=float)
for j in range(m):
C_i[j,j]=C[i,j]
... | 2 | 2016-09-28T16:04:59Z | [
"python",
"numpy",
"cython"
] |
Incorrect line number returned on specifying Start parameter in enumerate Python | 39,745,985 | <p>I have slight confusion regarding the start parameter in enumerate function,as i recently started working on python i don't have much idea how it is supposed to work.
Suppose i have an example file below:</p>
<pre><code>Test 1
Test 2
Test 3
</code></pre>
<p>This is the first line <code>[SB WOM]|[INTERNAL REQUEST]|... | 1 | 2016-09-28T11:20:46Z | 39,746,150 | <p>Since the file iterator object has read the first four lines, when running the second <code>for</code> loop, it starts from where it stopped. The previous iteration stopped at line 3 (assuming we start counting from 0), the next for loop starts at line 4. </p>
<p>Therefore, the <code>enumerate</code> of the second ... | 0 | 2016-09-28T11:28:38Z | [
"python"
] |
Incorrect line number returned on specifying Start parameter in enumerate Python | 39,745,985 | <p>I have slight confusion regarding the start parameter in enumerate function,as i recently started working on python i don't have much idea how it is supposed to work.
Suppose i have an example file below:</p>
<pre><code>Test 1
Test 2
Test 3
</code></pre>
<p>This is the first line <code>[SB WOM]|[INTERNAL REQUEST]|... | 1 | 2016-09-28T11:20:46Z | 39,746,372 | <p>Try this code</p>
<pre><code>x = range(10)
for i, e in enumerate(x):
if i == 4:
print i
st = i
break
for i, e in enumerate(x, st):
print i
</code></pre>
<p>And you will see this output:</p>
<pre><code>4
4 5 6 7 8 9 10 11 12 13
</code></pre>
<p>So, what does the second parameter o... | 0 | 2016-09-28T11:38:59Z | [
"python"
] |
One-to-One relationship SQLAlchemy with multiple files | 39,746,035 | <p>i have a problem with my relationship(...) and i don't understand why.</p>
<p>The error : </p>
<p>"InvalidRequestError: When initializing mapper Mapper|User|users, expression 'BannedUser' failed to locate a name ("name 'BannedUser' is not defined"). If this is a class name, consider adding this relationship() to t... | 0 | 2016-09-28T11:23:01Z | 39,750,778 | <p>On the <code>back_populates</code> (<a href="http://docs.sqlalchemy.org/en/latest/orm/relationship_api.html#sqlalchemy.orm.relationship.params.back_populates" rel="nofollow">doc</a>) you need to specify the property which is related on the other end of the relationship, while you specified the table name ... of the ... | 0 | 2016-09-28T14:43:41Z | [
"python",
"sqlalchemy",
"foreign-keys",
"relationship"
] |
merging the time stamps of file if label is the same | 39,746,043 | <p>I have file with three columns, the Ist and 2nd column are the start and end of time while the 3rd is label. I want to merge the time stamps of consecutive rows ( 2 or more) if the label in the 3rd column is the same.</p>
<h1>inputs1:</h1>
<p><code>
0.000000 0.551875 x
0.551875 0.586875 ... | 1 | 2016-09-28T11:23:20Z | 39,751,258 | <p>In Groovy, given:</p>
<pre><code>def inputs = [
[0.000000, 0.551875, 'x'],
[0.551875, 0.586875, 'x'],
[0.586875, 0.676188, 't'],
[0.676188, 0.721875, 't'],
[0.721875, 0.821250, 't'],
[0.821250, 0.872063, 'p'],
[0.872063, 0.968625, 'q'],
[0.968625, 1.112250, 'q']
]
</code></pre>
<p>J... | 0 | 2016-09-28T15:04:58Z | [
"java",
"python",
"algorithm",
"groovy"
] |
How to start Python file (filename.py, which have appeal to oracle ) from sikuli? | 39,746,061 | <p>I tried to import os, then import my module..
[error] ImportError ( No module named filename )</p>
| 0 | 2016-09-28T11:24:17Z | 39,757,098 | <p>If I take your question quite literal, this would do it:</p>
<pre><code>run("C:\Path\To\Python\python.exe C:\Path\To\Script\script.py")
</code></pre>
<p>This would require Python to be installed in <code>C:\Path\To\Python\</code>.</p>
<p>If you want to import the python script this only works if the Python code i... | 0 | 2016-09-28T20:30:18Z | [
"python",
"oracle",
"jython",
"sikuli"
] |
I want this function to loop through both lists and return the object that is the same in both | 39,746,115 | <p>These are the lists; note how the second list is made up of objects that need splitting first. </p>
<pre><code>gaps = ['__1__', '__2__', '__3__']
questions = ['Bruce Wayne is __1__', 'Clark Kent is __2__', 'Barry Allen is __3__']
</code></pre>
<p>Here's the code. It seems to work only for the first (zeroth) objec... | -5 | 2016-09-28T11:26:34Z | 39,746,208 | <p>Python stops executing as soon as it hits a return statement. If you return inside a loop, it'll stop running after one iteration, when it hits the first return statement.</p>
| 0 | 2016-09-28T11:31:30Z | [
"python",
"list"
] |
Getting for line in plaintext.split('\n'): UnicodeDecodeError: 'ascii' codec can't decode byte 0x96 in position 2: ordinal not in range(128) | 39,746,190 | <p>I'm going to design sentimental analysis on twitter data using nltk tutorials but not able to run following code</p>
<pre><code>import pickle
import random
import nltk
from nltk import pos_tag
from nltk.classify import ClassifierI
from nltk.classify.scikitlearn import SklearnClassifier
from nltk.tokenize import wo... | -1 | 2016-09-28T11:30:41Z | 39,746,467 | <p>Open the files in text mode with the right encoding, e.g.:</p>
<pre><code>with io.open("positive.txt", "r", encoding="UTF8") as fd:
short_pos = fd.read()
</code></pre>
| 0 | 2016-09-28T11:42:32Z | [
"python",
"python-2.7",
"python-3.x",
"nltk",
"nltk-trainer"
] |
How to check through the whole user input and not just the first word | 39,746,191 | <p>I try to check through user input but it only checks the first word. Any suggestions of how I can get the program to check through the whole string against a 2D list instead of just checking the first word and outputting missing.
Code below:</p>
<pre><code>my_list = [['noisey','pc','broken']['smashed','window','gla... | -2 | 2016-09-28T11:30:43Z | 39,750,756 | <p>This should do the trick</p>
<pre><code>#!/usr/bin/python3
my_list = [['noisey','pc','broken'],['smashed','window','glass']]
search = input('Enter what is going wrong: ')
for word in search.split():
if word in my_list[0]:
print(word,'Found in PC');
elif word in my_list[1]:
print(word,'Found... | 0 | 2016-09-28T14:42:49Z | [
"python",
"python-3.x"
] |
python + sqlite: How to use Order by for column with special letters? | 39,746,215 | <p>I want to use <code>order by</code> to sort one of the column. This column, lets say its name is ColA, contains many <strong>special letters</strong>. Here is an example what ColA looks like:</p>
<pre><code>ColA
Abc
D6
(8)
-s
'st
9-57
6s
A&C
5
Ãber
ÑÑÌÑÑкий
W/WO
</code></pre>
<p>I tried with the follo... | 0 | 2016-09-28T11:31:57Z | 39,747,898 | <p>A SELECT statement does not modify the database.</p>
<p>To reorder the table, you must sort the rows when you actually write the new table:</p>
<pre><code>INSERT INTO MyTable (ColA, ColB, ColC)
SELECT ColA, ColB, ColC
FROM TempOldTable
ORDER BY ColA;
</code></pre>
| 0 | 2016-09-28T12:42:34Z | [
"python",
"sqlite"
] |
sys.stdin.readline() with if else (Python) | 39,746,223 | <p>I am new at Python and need a little help.
I am trying to use the next command in order to get user input from screen:
sys.stdin.readline()</p>
<p>All is fine when I want to print something but when I am trying to combine an if else statement it seems that the user input is ignoring the case sensitive string that ... | 0 | 2016-09-28T11:32:16Z | 39,746,273 | <p>The line will include the end of line character <code>'\n'</code> (<a href="https://docs.python.org/2/tutorial/inputoutput.html#methods-of-file-objects" rel="nofollow">docs</a>). So it's never equal to <code>'Sam'</code> (except possibly at the end of the file).</p>
<p>Maybe use <code>name = name.strip()</code> to ... | 1 | 2016-09-28T11:34:20Z | [
"python"
] |
python dataframe std deviation of a column/row containing all Nan values except one element | 39,746,316 | <p>I have a python dataframe like this </p>
<pre><code>In [212]: d3
Out[212]:
a b c d e
a 0.0 0.0 0.0 0.0 0.0
b 1.0 1.0 1.0 1.0 1.0
c 2.0 2.0 2.0 2.0 2.0
d 3.0 3.0 3.0 3.0 3.0
e 3.0 4.0 4.0 4.0 4.0
f 5.0 5.0 5.0 5.0 0.0
p NaN 3.0 NaN 3.0 NaN
q Na... | 1 | 2016-09-28T11:36:23Z | 39,746,529 | <p>Use arg <code>ddof=0</code> to make <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.std.html" rel="nofollow"><code>df.std</code></a> behave like <code>np.std</code> as it always leaves the last value while calculating standard deviation by default (<em>ddof=1</em>):</p>
<pre><code>df... | 0 | 2016-09-28T11:45:08Z | [
"python",
"pandas",
"dataframe",
"standard-deviation"
] |
Is there a keyboard shortcut in Pycharm for rename a specific variable? | 39,746,405 | <p>I'm using <strong>Pycharm</strong> for Python coding, and I want to change the name of a <strong>specific variable</strong> all over the code. is there any keyboard shortcut for this operation?</p>
<p>In Matlab I can use <em>ctrl</em> + <em>shift</em>.</p>
<p>For example:</p>
<pre><code>old_name=5
x=old_name*123
... | 0 | 2016-09-28T11:40:08Z | 39,746,546 | <p>Highlight your <code>old_name</code> and hit <kbd>Shift</kbd>+<kbd>F6</kbd></p>
| 2 | 2016-09-28T11:45:53Z | [
"python",
"python-2.7",
"keyboard",
"pycharm",
"keyboard-shortcuts"
] |
Is there a keyboard shortcut in Pycharm for rename a specific variable? | 39,746,405 | <p>I'm using <strong>Pycharm</strong> for Python coding, and I want to change the name of a <strong>specific variable</strong> all over the code. is there any keyboard shortcut for this operation?</p>
<p>In Matlab I can use <em>ctrl</em> + <em>shift</em>.</p>
<p>For example:</p>
<pre><code>old_name=5
x=old_name*123
... | 0 | 2016-09-28T11:40:08Z | 39,746,600 | <p>I don't know about a shortcut for this special purpose, but I simply use <kbd>Ctrl</kbd>+<kbd>R</kbd> to replace the old variable names with new ones. You can also set settings such as <em>Match case</em>, <em>Regex</em> or <em>In selection</em>.</p>
<p>Note that this won't work, if you have a variable name includi... | 0 | 2016-09-28T11:48:38Z | [
"python",
"python-2.7",
"keyboard",
"pycharm",
"keyboard-shortcuts"
] |
connect to ms-sql from python, tried in several ways but no luck | 39,746,411 | <p>I am trying with <code>pyodbc</code> and <code>freetds</code>, but <code>freetds</code> can't be installed. I got an error like:</p>
<pre><code>==> Installing homebrew/versions/freetds091
==> Downloading ftp://ftp.freetds.org/pub/freetds/stable/freetds-0.91.112.tar.gz
curl: (28) Operation timed out after 0 ... | 1 | 2016-09-28T11:40:31Z | 39,832,576 | <p>You'll want to edit the formula to replace the ftp address with an http address..</p>
<pre><code>brew edit freetds
</code></pre>
<p>This will open the FreeTDS formula. Replace the line starting with <code>url</code> with:</p>
<pre><code>url "https://fossies.org/linux/privat/freetds-1.00.15.tar.bz2"
</code></pre>
... | 0 | 2016-10-03T13:15:25Z | [
"python",
"freetds"
] |
Sense up arrow in Python? | 39,746,463 | <p>I have this script</p>
<pre><code>import sys, os, termios, tty
home = os.path.expanduser("~")
history = []
if os.path.exists(home+"/.incro_repl_history"):
readhist = open(home+"/.incro_repl_history", "r+").readlines()
findex = 0
for j in readhist:
if j[-1] == "\n":
readhist[findex] =... | 0 | 2016-09-28T11:42:28Z | 39,746,654 | <p>The <code>raw_input</code> function always read a string until ENTER, not a single character (arrow, etc.)</p>
<p>You need to define your own <code>getch</code> function, see: <a href="http://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user">Python read a single character from the use... | 0 | 2016-09-28T11:51:07Z | [
"python",
"arrow-keys",
"getch"
] |
How to perform action when QCalendarWidget popup closes? | 39,746,664 | <p>I am using a <code>QDateEdit</code> widget with <code>QDateEdit.setCalendarPopup(True)</code>. I am trying to connect a slot to the event when the calendar popup closes. See my example below for my attempts so far, found in <code>MyCalendarWidget</code>. None of my attempts so far have worked. What can I do to perfo... | 0 | 2016-09-28T11:51:27Z | 39,747,045 | <p>Figured it out - turns out I need to use the <code>clicked</code> signal in <code>QCalendarWidget</code>. This removes the need to sub-class <code>QCalendarWidget</code> as well.</p>
<pre><code>from PyQt4 import QtGui, QtCore
import sys
class MainWindow(QtGui.QMainWindow):
def __init__(self, *args):
su... | 0 | 2016-09-28T12:08:28Z | [
"python",
"qt",
"qt4",
"pyqt4"
] |
Python GUI not updating info after program has launched | 39,746,721 | <p>This is what I've written (alot of inspiration from online, since im a student and just started learning python). When I open the program, theres a GUI with one button. When I press the button it displays the time as it should. But if i close the popup window, and press it again, the time is the same as it was last ... | 1 | 2016-09-28T11:54:04Z | 39,746,909 | <p>Try this:</p>
<pre><code>import Tkinter as tk
import tkMessageBox
import datetime
top = tk.Tk()
def showInfo():
ctime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
tkMessageBox.showinfo( "Today:", str(ctime))
B = tk.Button(top, text ="Click to show current time", command = showInfo)
B.pack()
t... | 3 | 2016-09-28T12:02:40Z | [
"python",
"python-3.x",
"user-interface",
"tkinter"
] |
Python GUI not updating info after program has launched | 39,746,721 | <p>This is what I've written (alot of inspiration from online, since im a student and just started learning python). When I open the program, theres a GUI with one button. When I press the button it displays the time as it should. But if i close the popup window, and press it again, the time is the same as it was last ... | 1 | 2016-09-28T11:54:04Z | 39,747,057 | <p>You can use a method to get the current time every time you click the button: </p>
<pre><code>import Tkinter as tk
import tkMessageBox
import datetime
def getTime():
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
top = tk.Tk()
def showInfo():
tkMessageBox.showinfo( "Today:", getTime())
B... | 2 | 2016-09-28T12:08:50Z | [
"python",
"python-3.x",
"user-interface",
"tkinter"
] |
How to pass keywords list to pathos.multiprocessing? | 39,746,758 | <p>I am using pathos.multiprocessing to parallelize a program that requires using instance methods. Here is a minimum working example:</p>
<pre><code>import time
import numpy as np
from pathos.multiprocessing import Pool, ProcessingPool, ThreadingPool
class dummy(object):
def __init__(self, arg, key1=None, key2=-... | 1 | 2016-09-28T11:55:59Z | 39,757,488 | <p>I'm the <code>pathos</code> author. Yeah, you hit on something that I have known needs a little work. Currently, the <code>map</code> and <code>pipe</code> (i.e. <code>apply</code>) methods from <code>ProcessPool</code>, <code>ThreadPool</code>, and <code>ParallelPool</code> cannot take <code>kwds</code> -- you ha... | 2 | 2016-09-28T20:55:36Z | [
"python",
"dictionary",
"multiprocessing",
"keyword-argument",
"pathos"
] |
Using Logging with Multiprocessing Module | 39,746,768 | <p>I need to create a single logger that can be used throughout my python package, but some of the functions implement multiprocessing. I want all those functions to write to the same log file just like everything else.</p>
<p>I know at Python 3.2+ there is a built in way to do this, but I need to back port to Python... | 1 | 2016-09-28T11:56:33Z | 39,759,109 | <p>The functionality to do this in Python >= 3.2 (via the <code>QueueHandler</code> and <code>QueueListener</code> classes, as described <a href="http://plumberjack.blogspot.co.uk/2010/09/using-logging-with-multiprocessing.html" rel="nofollow">here</a>) is available for Python 2.7 through the <a href="https://pypi.pyth... | 0 | 2016-09-28T23:24:36Z | [
"python",
"python-2.7",
"logging"
] |
Response streamed [200 OK]> is not JSON serializable stream image python | 39,746,893 | <p>I am looking for a way to serve some images from the bing map without sharing the URL (because it contains the secret key) and return it to the client (without saving to disk first). I'm using this method from <a href="http://flask.pocoo.org/snippets/118/" rel="nofollow">here</a></p>
<pre><code>def get_stream_from... | 0 | 2016-09-28T12:01:44Z | 39,748,980 | <p><code>Flask</code> is overkill for this. I've created a library called <code>wsinfo</code>, which is available here: <a href="https://github.com/linusg/wsinfo" rel="nofollow">https://github.com/linusg/wsinfo</a>.</p>
<p>With it, the code is as simple as:</p>
<pre><code>import base64
import wsinfo
import sys
def ... | 1 | 2016-09-28T13:29:11Z | [
"python",
"json",
"python-2.7",
"bing-maps",
"bing"
] |
Response streamed [200 OK]> is not JSON serializable stream image python | 39,746,893 | <p>I am looking for a way to serve some images from the bing map without sharing the URL (because it contains the secret key) and return it to the client (without saving to disk first). I'm using this method from <a href="http://flask.pocoo.org/snippets/118/" rel="nofollow">here</a></p>
<pre><code>def get_stream_from... | 0 | 2016-09-28T12:01:44Z | 39,775,897 | <p>There is no need to hide a Bing Maps key. Anyone can create on and use it under the free terms of use. As such there is little incentive for them to steal your key. In majority of cases where a key appeared to be stolen, the root cause was code being handed off that contained the key or the key being posted in code ... | 0 | 2016-09-29T16:49:37Z | [
"python",
"json",
"python-2.7",
"bing-maps",
"bing"
] |
Control-C not stopping thread/spinning cursor | 39,746,897 | <p>I have code that copies files. When it is doing so a cursor spins. This all works fine. However if I use <kbd>Ctrl</kbd>+<kbd>C</kbd> to stop the copy I expect the <code>KeyboardInterrupt</code> to set the event and the cursor to stop spinning. The copy stops however the cursor spins forever, why is this?</p>
<p>I ... | 0 | 2016-09-28T12:01:51Z | 39,750,980 | <p>It is not really an answer, because I cannot explain what really happens, but I could partially reproduce. It looks like <code>copy_file</code> <em>swallows</em> the KeyboardInterrupt and raises another exception. If that happens, as the <code>processing_flag.set()</code> is only in the normal and <code>except Keybo... | 1 | 2016-09-28T14:52:09Z | [
"python",
"multithreading"
] |
Egg_info error when installing rpy2 windows 10 | 39,746,961 | <p>I want to install <code>rpy2</code> and next install <code>anaconda</code> with <code>spyder</code> to use python. </p>
<p>I tried this command</p>
<pre><code>py -m pip install rpy2
</code></pre>
<p>but it gave me this error</p>
<pre><code>Command "python setup.py egg_info" failed with error code 1 in C:\Users\R... | 0 | 2016-09-28T12:04:28Z | 39,796,785 | <p>Use precompiled binaries.</p>
<p>See: <a href="http://rpy2.readthedocs.io/en/default/overview.html#microsoft-s-windows-precompiled-binaries" rel="nofollow">http://rpy2.readthedocs.io/en/default/overview.html#microsoft-s-windows-precompiled-binaries</a></p>
<p>The main page for rpy2 will be updated to indicate that... | 0 | 2016-09-30T17:18:28Z | [
"python",
"rpy2"
] |
CSV split rows into lists | 39,747,047 | <p>So i would like to split string from list into multiple lists
like rows[1] should be splited into another list contained in list m
i saw this here and it hsould be accesable m[0][0] to get first item form first list .
import csv</p>
<pre><code>reader = csv.reader(open("alerts.csv"), delimiter=',')
)
rows=[]
f... | 0 | 2016-09-28T12:08:32Z | 39,747,197 | <p>you can do this pretty easily with pandas</p>
<pre><code>import pandas as pd
A = pd.read_csv('yourfile.csv')
for x in A.values:
for y in x:
print y
</code></pre>
<p>so the 'print y' statement access each element in the row. but I mean, after the "for x in A.values" you can do just about anything</p>... | 1 | 2016-09-28T12:13:23Z | [
"python",
"list",
"csv"
] |
CSV split rows into lists | 39,747,047 | <p>So i would like to split string from list into multiple lists
like rows[1] should be splited into another list contained in list m
i saw this here and it hsould be accesable m[0][0] to get first item form first list .
import csv</p>
<pre><code>reader = csv.reader(open("alerts.csv"), delimiter=',')
)
rows=[]
f... | 0 | 2016-09-28T12:08:32Z | 39,747,430 | <p>Exact solution to your question; you almost got it right (note the <code>delimiter</code> value):</p>
<pre><code>reader = csv.reader(open("alerts.csv"), delimiter=';')
table = [row for row in reader]
print(table[0][0])
>>> priority
</code></pre>
<p>For easy data handling, it is often nice to explicitly e... | 0 | 2016-09-28T12:24:07Z | [
"python",
"list",
"csv"
] |
CSV split rows into lists | 39,747,047 | <p>So i would like to split string from list into multiple lists
like rows[1] should be splited into another list contained in list m
i saw this here and it hsould be accesable m[0][0] to get first item form first list .
import csv</p>
<pre><code>reader = csv.reader(open("alerts.csv"), delimiter=',')
)
rows=[]
f... | 0 | 2016-09-28T12:08:32Z | 39,747,476 | <p>Here's how to do it:</p>
<pre><code>import csv
with open('alerts.csv') as f:
reader = csv.reader(f, delimiter=';')
next(reader) # skip over the first header row
rows = [row for row in reader]
>>> print(rows[0][0])
P2
</code></pre>
<p>This uses a list comprehension to read all rows from th... | 0 | 2016-09-28T12:25:52Z | [
"python",
"list",
"csv"
] |
Looping through an 8-byte hex code in python | 39,747,141 | <p>I have an 8-byte hex code and i'm trying to loop through 00-FF for each byte starting from the last to the first but i'm new to python and i'm stuck. </p>
<p>here's the code for looping through 00-FF:</p>
<pre><code>for h in range(0, 256):
return "{:02x}".format(h)
</code></pre>
<p>Essentially what i have is... | 1 | 2016-09-28T12:11:15Z | 39,752,707 | <p>Here's a quick way to break a string into chunks. We assume it has even length.</p>
<pre><code>hexcode = 'f20bdba6ff29eed7'
l = len(hexcode)
for n in range(0, len(hexcode)/2):
index = n * 2
print hexcode[index:index+2]
</code></pre>
<p>If you need to operate on the string representations, you could easily ... | 0 | 2016-09-28T16:13:48Z | [
"python",
"loops",
"hex"
] |
Why does tensorlow LSTM takes only the hidden size as input? | 39,747,170 | <p>In the tensorflow <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/rnn_cell.html#LSTMCell" rel="nofollow">LSTM</a> cell we only initialize it by number of units (<code>num_units</code>) which is the hidden size of the cell. However, the cell should also take an input <code>x</code>. And since the un... | 0 | 2016-09-28T12:12:12Z | 39,747,366 | <p>LSTM cell (or other types of RNN cells) is just an object you pass to the function such as <code>tf.nn.rnn</code>. <code>tf.nn.rnn</code> takes cell and data for input. Cell is called inside of rnn function with the data you've passed to <code>tf.nn.rnn</code>. </p>
| 1 | 2016-09-28T12:21:21Z | [
"python",
"tensorflow",
"lstm"
] |
Add column to dataframe based on date column range | 39,747,222 | <p>I have a <code>df</code> containing <code>n</code> <code>columns</code>. One of these is a <code>column</code> named <code>date</code> which contains values formatted as <code>mm-dd-yy</code>. Now I want to add a <code>column</code> <code>interval</code> to my <code>df</code>. This <code>column</code> should return ... | 1 | 2016-09-28T12:14:22Z | 39,747,412 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.quarter.html" rel="nofollow"><code>dt.quarter</code></a> or <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.month.html" rel="nofollow"><code>dt.month</code></a>.</p>
<p>First convert <code>int... | 1 | 2016-09-28T12:23:21Z | [
"python",
"date",
"datetime",
"pandas",
"time-series"
] |
Add column to dataframe based on date column range | 39,747,222 | <p>I have a <code>df</code> containing <code>n</code> <code>columns</code>. One of these is a <code>column</code> named <code>date</code> which contains values formatted as <code>mm-dd-yy</code>. Now I want to add a <code>column</code> <code>interval</code> to my <code>df</code>. This <code>column</code> should return ... | 1 | 2016-09-28T12:14:22Z | 39,747,419 | <p>is the 'date' column a string? you can't really compare strings like that</p>
<p>convert the last two elements in the string to an int</p>
<pre><code>A = [x[6:]+'H1' if int(x[6:]+)< 7 else 'H2' for x in df['date'].values]
</code></pre>
<p>and finally</p>
<pre><code>df['interval'] = A
</code></pre>
| 1 | 2016-09-28T12:23:29Z | [
"python",
"date",
"datetime",
"pandas",
"time-series"
] |
for-loop over tuple in Python: ValueError | 39,747,305 | <p>I have a tuple of arrays like the following:</p>
<pre><code>z = (array( [ [1], [2], [3]] ),
array( [[10],[11],[12]] )
)
</code></pre>
<p>I want to iterate over them with a simple for loop using two variables:</p>
<pre><code>for x, y in z:
print("it worked")
self.doStuff(x, y)
</code></pre>
<p>..... | 1 | 2016-09-28T12:18:17Z | 39,747,395 | <p>The line </p>
<pre><code>for x, y in z:
</code></pre>
<p>assumes (at least in Python2.7), that each element in <code>z</code> can be <a href="https://www.python.org/dev/peps/pep-3113/" rel="nofollow">tuple unpacked</a>. This would be the case if each element in <code>z</code> is, say, a pair tuple:</p>
<pre><code... | 2 | 2016-09-28T12:22:28Z | [
"python",
"for-loop"
] |
for-loop over tuple in Python: ValueError | 39,747,305 | <p>I have a tuple of arrays like the following:</p>
<pre><code>z = (array( [ [1], [2], [3]] ),
array( [[10],[11],[12]] )
)
</code></pre>
<p>I want to iterate over them with a simple for loop using two variables:</p>
<pre><code>for x, y in z:
print("it worked")
self.doStuff(x, y)
</code></pre>
<p>..... | 1 | 2016-09-28T12:18:17Z | 39,747,424 | <p>Reading the other answer it might be that I misunderstood what you want. </p>
<p>You can also use</p>
<pre><code>for x,y in zip(*z):
</code></pre>
<p>to unzip the z tuple.</p>
<p>The output then is:</p>
<pre><code>it worked
[1] [10]
it worked
[2] [11]
it worked
[3] [12]
</code></pre>
| 2 | 2016-09-28T12:23:41Z | [
"python",
"for-loop"
] |
Can I use PyCharm windows with VirtualBox ubuntu | 39,747,344 | <p>Can I use PyCharm (non-professional version) to develop code in windows and SSH or integrate virtualbox into PyCharm so it can send to my host in virtualbox Ubuntu server? </p>
| -2 | 2016-09-28T12:20:10Z | 39,747,441 | <p>Yes you can. Share you code folder from windows using Vagrant or your virtual box into ubuntu and edit the code from pycharm windows. You can even debug code from ubuntu using pycharm. I have done this for months with Vagrant VMs.</p>
| 0 | 2016-09-28T12:24:31Z | [
"python",
"ssh",
"pycharm",
"virtualbox"
] |
How to change map into a loop? | 39,747,403 | <p>this question is probably really simple but it will help me to understand the difference between loop and map.
In the first example I managed to change it from:</p>
<pre><code> nrs = list(map(lambda x: int( open("img_" + str(x) + ".csv").readline().split(",")[1] ) , range(82))
</code></pre>
<p>to:</p>
<pre><co... | 1 | 2016-09-28T12:22:59Z | 39,747,639 | <p>You should iterate over keys, not values.</p>
<pre><code> srednia = []
for x in list(avg_si.keys()):
srednia.append(ages[x], list(avg_si.values()))
plt.plot(srednia, "ro", label = "size")
</code></pre>
| 0 | 2016-09-28T12:31:53Z | [
"python"
] |
How to change map into a loop? | 39,747,403 | <p>this question is probably really simple but it will help me to understand the difference between loop and map.
In the first example I managed to change it from:</p>
<pre><code> nrs = list(map(lambda x: int( open("img_" + str(x) + ".csv").readline().split(",")[1] ) , range(82))
</code></pre>
<p>to:</p>
<pre><co... | 1 | 2016-09-28T12:22:59Z | 39,750,281 | <p>The expression</p>
<pre><code>plt.plot(list(map(lambda x: ages[x], list(avg_si.keys() ))), list(avg_si.values()), 'ro', label='size')
</code></pre>
<p>is somewhat hard to parse. In addition to the last two string arguments you are passing it two lists:</p>
<pre><code>1) list(map(lambda x: ages[x], list(avg_si.key... | 0 | 2016-09-28T14:22:02Z | [
"python"
] |
python replace will not replace "'" with "\'" | 39,747,440 | <pre><code> dctLineItems = InvFunctions.dctLineItems
for value in dctLineItems.values():
iORDER_ID = value[0]
iITEM_No = value[1]
iQUANTITY = value[2]
sTmp = value[3]
sTmp2 = sTmp.replace("'", "\'", 1)
#sTmp2 = connPy.escape(sTmp)
sITEM_Name = sTmp2
... | -2 | 2016-09-28T12:24:31Z | 39,747,680 | <p>My best guess is that the backslash is known in Python as an escape sequence. Python doesn't recognize this as a literal, so you would have to put <code>\\</code> instead. The same applies to the single quote (<code>\'</code>)</p>
<p>So where you're using your replace function (I'm guessing the 5th line from the to... | 0 | 2016-09-28T12:33:42Z | [
"python"
] |
python replace will not replace "'" with "\'" | 39,747,440 | <pre><code> dctLineItems = InvFunctions.dctLineItems
for value in dctLineItems.values():
iORDER_ID = value[0]
iITEM_No = value[1]
iQUANTITY = value[2]
sTmp = value[3]
sTmp2 = sTmp.replace("'", "\'", 1)
#sTmp2 = connPy.escape(sTmp)
sITEM_Name = sTmp2
... | -2 | 2016-09-28T12:24:31Z | 39,747,728 | <p>Another option: using Python's raw strings:</p>
<pre><code>>>> "'hello'".replace("'", "\'")
>>> "'hello'"
>>>
>>> "'hello'".replace("'", "\\'")
>>> "\\'hello\\'"
>>>
>>> "'hello'".replace("'", r"\'") # <- Note the starting r
>>> "\\'hello\\... | 0 | 2016-09-28T12:36:02Z | [
"python"
] |
Read the Docs: Distutils2 error during installation | 39,747,527 | <p>I try to install local instance of Read the Docs on my Win10</p>
<p>When I follow this documentation:<br>
<a href="http://docs.readthedocs.io/en/latest/install.html" rel="nofollow">http://docs.readthedocs.io/en/latest/install.html</a></p>
<p>and type:</p>
<pre><code>pip install -r requirements.txt
</code></pre>
... | 0 | 2016-09-28T12:28:09Z | 39,747,948 | <p>Is it possible you are running the Python 2 <code>pip</code>? The error message clearly indicates that the code is being executed under Python 3 but has Python 2 syntax. Do you get better results with</p>
<pre><code>python -m pip install -r requirements.txt
</code></pre>
<p>I wonder? If not then verify that</p>
<... | 1 | 2016-09-28T12:44:33Z | [
"python",
"read-the-docs"
] |
Converting CSV to XML with Hierarchies using Python to feed through API | 39,747,534 | <p>I've seen a couple of answers of how to convert a csv (or SQL table) to XML, but I haven't seen one that includes hierarchies and isn't overtly complicated. I need to map a csv file into a pre-existing XML format to feed it to an API using Python. I can already send a valid XML to the website, but I'm having issues ... | 0 | 2016-09-28T12:28:21Z | 39,747,761 | <p>There is no generic library to directly convert your CSV to a required XML. You will need to build the XML using xml functions provided by python or using something like <a href="https://docs.python.org/2/library/xml.etree.elementtree.html" rel="nofollow">xml.etree API</a> </p>
<p><a href="http://stackoverflow.com/... | 0 | 2016-09-28T12:37:23Z | [
"python",
"xml",
"csv"
] |
Converting CSV to XML with Hierarchies using Python to feed through API | 39,747,534 | <p>I've seen a couple of answers of how to convert a csv (or SQL table) to XML, but I haven't seen one that includes hierarchies and isn't overtly complicated. I need to map a csv file into a pre-existing XML format to feed it to an API using Python. I can already send a valid XML to the website, but I'm having issues ... | 0 | 2016-09-28T12:28:21Z | 39,783,287 | <p>I actually figured out a SQL solution for this...but it is ridiculously manual and specific for my case. I hope the format still helps someone solve a similar issue.</p>
<p>If you notice from the code below, the XML tags will assume the name of the column if you don't include an alias. You can use the format 'Paren... | 0 | 2016-09-30T03:38:38Z | [
"python",
"xml",
"csv"
] |
My beginner python project (calculator) is having trouble with inputs | 39,747,635 | <p>Whenever I test my calculator to see how it deals with inputs that are not numbers, it flags up a ValueError. More precisely, this one "ValueError: could not convert string to float: 'a'". I have tried to amend this so there is a solution to dealing with non-integers but to no avail... Help is much appreciated.</p>
... | -2 | 2016-09-28T12:31:44Z | 39,747,784 | <p>Please read the docs for handling exceptions:</p>
<p><a href="https://docs.python.org/2/tutorial/errors.html#handling-exceptions" rel="nofollow">https://docs.python.org/2/tutorial/errors.html#handling-exceptions</a></p>
<p>for a float:</p>
<pre><code>try:
x = float(input("Please enter a number: "))
break
... | 0 | 2016-09-28T12:38:01Z | [
"python"
] |
My beginner python project (calculator) is having trouble with inputs | 39,747,635 | <p>Whenever I test my calculator to see how it deals with inputs that are not numbers, it flags up a ValueError. More precisely, this one "ValueError: could not convert string to float: 'a'". I have tried to amend this so there is a solution to dealing with non-integers but to no avail... Help is much appreciated.</p>
... | -2 | 2016-09-28T12:31:44Z | 39,747,788 | <p>Exception handling is what are you looking for.
Smthng like this:</p>
<pre><code>input = 'a'
try:
int(a)
except ValueError:
print 'Input is not integer'
</code></pre>
| 1 | 2016-09-28T12:38:08Z | [
"python"
] |
My beginner python project (calculator) is having trouble with inputs | 39,747,635 | <p>Whenever I test my calculator to see how it deals with inputs that are not numbers, it flags up a ValueError. More precisely, this one "ValueError: could not convert string to float: 'a'". I have tried to amend this so there is a solution to dealing with non-integers but to no avail... Help is much appreciated.</p>
... | -2 | 2016-09-28T12:31:44Z | 39,747,928 | <p>Note: You should name your variables in lower case according to PEP8, see: <a href="http://stackoverflow.com/questions/159720/what-is-the-naming-convention-in-python-for-variable-and-function-names">What is the naming convention in Python for variable and function names?</a>.</p>
<p>If you want to retry an input un... | 0 | 2016-09-28T12:43:34Z | [
"python"
] |
Airflow unable to execute all the dependent tasks in one go from UI | 39,747,645 | <p>My DAG has 3 tasks and we are using Celery executor as we have to trigger individual tasks from UI.We are able to execute the individual task from UI.</p>
<p>The problem which we are facing currently, is that we are unable to execute all the steps of DAG from UI in one go, although we have set the task dependencies... | 0 | 2016-09-28T12:32:05Z | 39,801,249 | <p>could it be that you just need to restart the <em>webserver</em> and the <em>scheduler</em>? It happens when you change your code, like adding new tasks.
Please post more details and some code.</p>
| 0 | 2016-09-30T23:02:03Z | [
"python",
"airflow"
] |
Download specific file in url using PHP/Python | 39,747,730 | <p>I previously used to use <code>wget -r</code> on the linux terminal for downloading files with certain extensions:</p>
<pre><code>wget -r -A Ext URL
</code></pre>
<p>But now I was assigned by my lecturer to do the same thing using PHP or Python. Who can help?</p>
| 1 | 2016-09-28T12:36:02Z | 39,747,825 | <p>I guess urllib pretty well for you</p>
<pre><code>import urllib
urllib.urlretrieve (URL, file)
</code></pre>
| 2 | 2016-09-28T12:39:36Z | [
"php",
"python",
"web-crawler",
"wget"
] |
Download specific file in url using PHP/Python | 39,747,730 | <p>I previously used to use <code>wget -r</code> on the linux terminal for downloading files with certain extensions:</p>
<pre><code>wget -r -A Ext URL
</code></pre>
<p>But now I was assigned by my lecturer to do the same thing using PHP or Python. Who can help?</p>
| 1 | 2016-09-28T12:36:02Z | 39,747,874 | <p>You can use PHP function <code>file_get_contents()</code> to retrieve the contents of a documents. The first argument of the function is filename which can either be a local path to a file or a URL.<br>
See example from PHP <a href="http://php.net/manual/en/function.file-get-contents.php" rel="nofollow">docs</a> ... | 1 | 2016-09-28T12:41:13Z | [
"php",
"python",
"web-crawler",
"wget"
] |
Download specific file in url using PHP/Python | 39,747,730 | <p>I previously used to use <code>wget -r</code> on the linux terminal for downloading files with certain extensions:</p>
<pre><code>wget -r -A Ext URL
</code></pre>
<p>But now I was assigned by my lecturer to do the same thing using PHP or Python. Who can help?</p>
| 1 | 2016-09-28T12:36:02Z | 39,748,094 | <p>Alternatively, you can use <a href="http://docs.python-requests.org/en/master/" rel="nofollow">Requests</a>: Requests is the only Non-GMO HTTP library for Python, safe for human consumption.</p>
<p>Example (from the doc):</p>
<pre><code>>>> r = requests.get('https://api.github.com/user', auth=('user', 'pa... | 0 | 2016-09-28T12:50:44Z | [
"php",
"python",
"web-crawler",
"wget"
] |
Download specific file in url using PHP/Python | 39,747,730 | <p>I previously used to use <code>wget -r</code> on the linux terminal for downloading files with certain extensions:</p>
<pre><code>wget -r -A Ext URL
</code></pre>
<p>But now I was assigned by my lecturer to do the same thing using PHP or Python. Who can help?</p>
| 1 | 2016-09-28T12:36:02Z | 39,782,286 | <p>For Python, use a web-crawler library such as scrapy.</p>
<p>It has <a href="https://doc.scrapy.org/en/latest/topics/spiders.html" rel="nofollow">classes</a> that do all the work when passed arguments similar to those you put on the <code>wget</code> command line.</p>
<p>You can use scrapy <a href="https://doc.scr... | 0 | 2016-09-30T01:20:16Z | [
"php",
"python",
"web-crawler",
"wget"
] |
The efficient way of Array transformation by using numpy | 39,747,900 | <p>How to change the ARRAY U(Nz,Ny, Nx) to U(Nx,Ny, Nz) by using numpy? thanks</p>
| 0 | 2016-09-28T12:42:40Z | 39,747,938 | <p>Just <code>numpy.transpose(U)</code> or <code>U.T</code>.</p>
| 5 | 2016-09-28T12:44:07Z | [
"python",
"numpy"
] |
The efficient way of Array transformation by using numpy | 39,747,900 | <p>How to change the ARRAY U(Nz,Ny, Nx) to U(Nx,Ny, Nz) by using numpy? thanks</p>
| 0 | 2016-09-28T12:42:40Z | 39,748,990 | <p>In general, if you want to change the order of data in numpy array, see <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/routines.array-manipulation.html#rearranging-elements" rel="nofollow">http://docs.scipy.org/doc/numpy-1.10.1/reference/routines.array-manipulation.html#rearranging-elements</a>.</p>
<p>T... | 2 | 2016-09-28T13:29:35Z | [
"python",
"numpy"
] |
Passing arg to subprocess.call | 39,748,061 | <p>I have a series of scripts that get called in an explicit order by another <code>run.py</code>. </p>
<p>Inside <code>run.py</code> I have the following:</p>
<pre><code>script1 = str(sys.path[0]) + "\\script1.py"
subprocess.call(["Python", script1])
</code></pre>
<p>And so on for 3 scripts. If I would like to pass... | 0 | 2016-09-28T12:49:27Z | 39,748,170 | <p>Subprocesses takes a list of arguments, which it then turns into a command it executes.</p>
<p>So:</p>
<pre><code>subprocess.call(["Python", script1, 'arg1', 'arg2'])
</code></pre>
<p>To <code>subprocess.call</code>, <em>all</em> the parts of its list are arguments. You just happen to be specifying "Python" and s... | 2 | 2016-09-28T12:54:06Z | [
"python",
"subprocess",
"exec",
"call",
"sys"
] |
How to extract certain strings when they occur adjacently with BeautifulSoup | 39,748,092 | <p>I'm parsing an HTML page's result from BeautifulSoup and the part(s) I'm interested in looks like this:</p>
<pre><code><i class="fa fa-circle align-middle font-80" style="color: #45C414; margin-right: 15px"></i>Departure for <a href="/en/ais/details/ports/17787/port_name:TEKIRDAG/_:3525d580eade08cfdb... | 2 | 2016-09-28T12:50:37Z | 39,748,141 | <p>You can locate the text node and get the <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#next-sibling-and-previous-sibling" rel="nofollow">next sibling</a>:</p>
<pre><code>In [1]: from bs4 import BeautifulSoup
In [2]: data = """<i class="fa fa-circle align-middle font-80" style="color: #45C414; ... | 1 | 2016-09-28T12:52:39Z | [
"python",
"html",
"beautifulsoup"
] |
Converting a str to an int | 39,748,223 | <p>My Problem is that the type <code>'ip'</code> is str, but i need integer.</p>
<p>So i did the convert <code>int(ip)</code>. Then i got error </p>
<blockquote>
<p>invalid literal for int() with base 10:</p>
</blockquote>
<p>So i did a little bit of research and found that i had to put int <code>int(float(ip))</c... | -4 | 2016-09-28T12:56:14Z | 39,748,401 | <p>According to the <a href="https://docs.python.org/3/library/socket.html#socket.socket.connect" rel="nofollow">documentation</a>, <code>connect</code> expects a tuple <code>(string, int)</code>, with the string being the ip address and the int being the port. You can modify your code this way to fix it :</p>
<pre><c... | 0 | 2016-09-28T13:03:56Z | [
"python"
] |
Converting a str to an int | 39,748,223 | <p>My Problem is that the type <code>'ip'</code> is str, but i need integer.</p>
<p>So i did the convert <code>int(ip)</code>. Then i got error </p>
<blockquote>
<p>invalid literal for int() with base 10:</p>
</blockquote>
<p>So i did a little bit of research and found that i had to put int <code>int(float(ip))</c... | -4 | 2016-09-28T12:56:14Z | 39,748,750 | <p>To convert a dotted notation IP address in a string to an integer you need:</p>
<pre><code>i_ip = socket.inet_aton(ip)
</code></pre>
<p>"aton" is short for "ASCII to number". This is for IPv4 addresses.</p>
| 0 | 2016-09-28T13:19:14Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.