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 |
|---|---|---|---|---|---|---|---|---|---|
Setting Order of Columns with matplotlib bar chart | 39,135,472 | <p>I produce a bar graph with the following code: </p>
<pre><code>Temp_Counts = Counter(weatherDFConcat['TEMPBIN_CON'])
df = pd.DataFrame.from_dict(Temp_Counts, orient = 'index')
df.plot(kind = 'bar')
</code></pre>
<p>It produces the following bar chart: </p>
<p><a href="http://i.stack.imgur.com/4sWHw.png" rel="nofo... | 2 | 2016-08-25T01:45:53Z | 39,135,642 | <p>I think 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> and last <a hr... | 2 | 2016-08-25T02:07:56Z | [
"python",
"pandas",
"numpy",
"matplotlib",
"bar-chart"
] |
Send commands to twisted server | 39,135,509 | <p>I have a simple twisted TCP server that I am using to send and receive data from another application. I am able to communicate and send messages to this application once a connection has been established. </p>
<p>What I want to be able to do have an external module command when and what to send to the 3rd party app... | 0 | 2016-08-25T01:50:49Z | 39,147,570 | <p>Your 3rd party call will happen <strong>from within <code>connectionMade</code></strong> and should not call it directly. The <code>connectionMade</code> is a Twisted callback and it's there to signal that a client is on the other side. It's up to you to dictate what happens after that. So you can do something li... | 0 | 2016-08-25T14:08:53Z | [
"python",
"tcp",
"twisted"
] |
Threading inside For Loop And While Using Events In Tkinter~Python | 39,135,649 | <p>Trying a scenario where in I wanted to proceed in the for loop based on threading mechanism [for syncing/wait mechanism] as shown in the code below.</p>
<pre><code>#!/tools/bin/python
# Global Import Variables
import Tkinter
from Tkinter import *
import subprocess
import shlex
import os
from PIL import Image, Ima... | 0 | 2016-08-25T02:08:49Z | 39,161,303 | <p>If I have undertood you correctly I dont think that you need to use threading at all. Consider the following:</p>
<pre><code>from Tkinter import *
class test_template:
def __init__(self, master):
self.master = master
self.loop_count = IntVar()
self.loop_count.set(1)
l = Label... | 0 | 2016-08-26T08:03:06Z | [
"python",
"python-2.7",
"tkinter"
] |
Remove row from dataframe if column value | 39,135,698 | <p>If I have a dataframe like this:</p>
<pre><code>index col1 col2
a a1 a2
b b1 b2
c c1 b2
</code></pre>
<p>Is it possible to use the <code>.drop()</code> to delete rows which have a sudden value in one of their columns?</p>
<p>Something like: <code>df.drop(col2 = 'b2')</code></... | 2 | 2016-08-25T02:13:21Z | 39,135,709 | <p>You need <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a>:</p>
<pre><code>df = df[df.col2 != 'b2']
</code></pre>
| 3 | 2016-08-25T02:15:19Z | [
"python",
"pandas",
"indexing",
"dataframe",
"filter"
] |
Remove row from dataframe if column value | 39,135,698 | <p>If I have a dataframe like this:</p>
<pre><code>index col1 col2
a a1 a2
b b1 b2
c c1 b2
</code></pre>
<p>Is it possible to use the <code>.drop()</code> to delete rows which have a sudden value in one of their columns?</p>
<p>Something like: <code>df.drop(col2 = 'b2')</code></... | 2 | 2016-08-25T02:13:21Z | 39,135,732 | <p>You can use a boolean filter. For example:</p>
<pre><code>df = df[df['col1'] != 'a1']
</code></pre>
<p>Would drop all rows with the value a1 in column col1. See <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html" rel="nofollow">this page of the Pandas docs</a> for more details. It's a very long pag... | 1 | 2016-08-25T02:18:04Z | [
"python",
"pandas",
"indexing",
"dataframe",
"filter"
] |
python url with unexpected "amp" and ";" | 39,135,716 | <p>Hi all I'm in a problem when doing web scraping with python.
code </p>
<pre><code>from urllib.request import urlopen
from urllib.request import urlretrieve
from bs4 import BeautifulSoup
import urllib.error
import http.cookiejar,requests,pymysql,json ,re
session = requests.Session()
monthurl = 'http://search.proqu... | 0 | 2016-08-25T02:16:52Z | 39,135,825 | <p>What you get back is apparently supposed to be injected on the website. <code>&amp;</code> is just <code>&</code> escaped for html usage. They're equivalent, but you have to unescape it first. You've got the function posted in <a href="https://wiki.python.org/moin/EscapingHtml" rel="nofollow">https://wiki.py... | 0 | 2016-08-25T02:34:00Z | [
"python",
"amp"
] |
python load zip with modules from memory | 39,135,750 | <p>So lets say I have a zip file with modules/classes inside. I then read this file - read binary ("rb") to store it into memory. How would I take this zip file in memory and load a module from it. Would I need to write an import hook for this? One cannot simply run exec on binary zip data from memory, can they?</p... | 5 | 2016-08-25T02:22:04Z | 39,136,299 | <p>read a test.txt from zip(not unzip or write to disk):</p>
<p>python 3(if you use py2.x, you should change the py3 zip API to py2)</p>
<pre><code>import zipfile
file_rst = []
with zipfile.ZipFile('/test/xxx.zip') as my_zip:
with my_zip.open('test.txt') as my_file:
for line in my_file:
file_... | 0 | 2016-08-25T03:37:23Z | [
"python"
] |
python load zip with modules from memory | 39,135,750 | <p>So lets say I have a zip file with modules/classes inside. I then read this file - read binary ("rb") to store it into memory. How would I take this zip file in memory and load a module from it. Would I need to write an import hook for this? One cannot simply run exec on binary zip data from memory, can they?</p... | 5 | 2016-08-25T02:22:04Z | 39,136,473 | <p><strong>EDIT:</strong> Fixed the ZipImporter to work for everything (I think)</p>
<p>Test Data:</p>
<pre><code>mkdir mypkg
vim mypkg/__init__.py
vim mypkg/test_submodule.py
</code></pre>
<p><code>__init__.py</code> Contents:</p>
<pre><code>def test():
print("Test")
</code></pre>
<p><code>test_submodule.py</... | 1 | 2016-08-25T03:57:32Z | [
"python"
] |
python: type error and index error (2.7.6) | 39,135,756 | <p>I am fairly new to python and I am having a problem on 2.7.6 that is not a problem on 3.4.4</p>
<p>The code:</p>
<pre><code>def answer(population, x, y, strength):
# make sure Z is infectable
if population[x][y] > strength:
return population
else:
population[x][y] = -1
# get array dimentions
rows = le... | -2 | 2016-08-25T02:22:49Z | 39,135,812 | <p>Edit: this response was for an older version of the question's code.</p>
<p>Assuming that all of your code is supposed to be within funk():</p>
<p>You need to terminate your while loop once toCheck is empty. The original version tries to index an empty list after you've popped off all of the values. Try this:</p>
... | 0 | 2016-08-25T02:32:13Z | [
"python",
"list",
"indexing",
"typeerror"
] |
Alternative way to using for loop | 39,135,968 | <p>Suppose a file looks like this:</p>
<pre><code>abcd 1
abcd 2
abcd 3
xyz 1
xyz 2
</code></pre>
<p>My code:</p>
<pre><code>if "abcd" in line:
do something
elif "xyz" in line:
do something
</code></pre>
<p>If both "abcd" and "xyz" dynamically change, how would I capture them by writing the same loop?</p>
<p... | -1 | 2016-08-25T02:52:46Z | 39,136,051 | <p>You can always use variables for matching, using your example:</p>
<pre><code>pattern1 = "abcd"
pattern2 = "xyz"
for line in lines_list:
if pattern1 in line:
do_smth
elif pattern2 in line:
do_smth2
pattern1 = get_new_pattern1()
pattern2 = get_new_pattern2()
</code></pre>
<p>Also you... | 0 | 2016-08-25T03:03:54Z | [
"python"
] |
Alternative way to using for loop | 39,135,968 | <p>Suppose a file looks like this:</p>
<pre><code>abcd 1
abcd 2
abcd 3
xyz 1
xyz 2
</code></pre>
<p>My code:</p>
<pre><code>if "abcd" in line:
do something
elif "xyz" in line:
do something
</code></pre>
<p>If both "abcd" and "xyz" dynamically change, how would I capture them by writing the same loop?</p>
<p... | -1 | 2016-08-25T02:52:46Z | 39,136,064 | <p>I don't know whether I catch your intention, but I hope the following code will help you. <code>keywords</code> simulates the <strong>dynamically changing</strong> variable.</p>
<pre><code>keywords = ['abcd', 'xyz', '123']
data = ['abcd',
'xyz',
'asdf',
'asdf',
'456',
'abcd',... | 0 | 2016-08-25T03:05:03Z | [
"python"
] |
Alternative way to using for loop | 39,135,968 | <p>Suppose a file looks like this:</p>
<pre><code>abcd 1
abcd 2
abcd 3
xyz 1
xyz 2
</code></pre>
<p>My code:</p>
<pre><code>if "abcd" in line:
do something
elif "xyz" in line:
do something
</code></pre>
<p>If both "abcd" and "xyz" dynamically change, how would I capture them by writing the same loop?</p>
<p... | -1 | 2016-08-25T02:52:46Z | 39,136,075 | <p>From your question (And making an assumption), it seems as though you want to go through each line in a file and than check if the text at that line matches something else. Say you have a file file.txt that is:</p>
<pre><code>abcd 1
abcd 2
abcd 3
xyz 1
xyz 2
</code></pre>
<p>To read that file, you would do:</p>
<... | 0 | 2016-08-25T03:06:39Z | [
"python"
] |
Alternative way to using for loop | 39,135,968 | <p>Suppose a file looks like this:</p>
<pre><code>abcd 1
abcd 2
abcd 3
xyz 1
xyz 2
</code></pre>
<p>My code:</p>
<pre><code>if "abcd" in line:
do something
elif "xyz" in line:
do something
</code></pre>
<p>If both "abcd" and "xyz" dynamically change, how would I capture them by writing the same loop?</p>
<p... | -1 | 2016-08-25T02:52:46Z | 39,136,113 | <p>Not sure I've understood correctly your question, but here's a possible way to gather key & values from your file:</p>
<pre><code>import re
from collections import defaultdict
file = """
abcd 1
abcd 2
abcd 3
xyz 1
xyz 2
"""
output = defaultdict(list)
for line in file.spli... | 0 | 2016-08-25T03:10:48Z | [
"python"
] |
Alternative way to using for loop | 39,135,968 | <p>Suppose a file looks like this:</p>
<pre><code>abcd 1
abcd 2
abcd 3
xyz 1
xyz 2
</code></pre>
<p>My code:</p>
<pre><code>if "abcd" in line:
do something
elif "xyz" in line:
do something
</code></pre>
<p>If both "abcd" and "xyz" dynamically change, how would I capture them by writing the same loop?</p>
<p... | -1 | 2016-08-25T02:52:46Z | 39,136,239 | <p>You probably want this (some kind of dynamic-keyword counter):</p>
<pre><code>with open("filename.txt") as f:
d=dict()
for line in f:
line=line.rstrip("\n")
s=line.split(" ") # works iff you have only space as delimeter
if s[0] in d:
d[s[0]]+=int(s[1]) # replace by 1 if n... | 0 | 2016-08-25T03:30:30Z | [
"python"
] |
Can a python dictionary be created and updated on the go | 39,136,022 | <p>I have to create a nested dictionary on the go inside a for loop. I have the parent dictionary <code>data</code> initialized to empty. Now inside the loop, I get the key to be added to the parent dictionary. And each key being again a dictionary.</p>
<pre><code>data = {}
for condition
Get x, y # x is the ne... | 1 | 2016-08-25T03:00:35Z | 39,136,127 | <p>It can also be achieved <code>data[x] = {y :1}</code> or <code>data.update({x: {y:1})</code> as mentioned by @karthikr</p>
| 0 | 2016-08-25T03:13:45Z | [
"python",
"python-2.7"
] |
Can a python dictionary be created and updated on the go | 39,136,022 | <p>I have to create a nested dictionary on the go inside a for loop. I have the parent dictionary <code>data</code> initialized to empty. Now inside the loop, I get the key to be added to the parent dictionary. And each key being again a dictionary.</p>
<pre><code>data = {}
for condition
Get x, y # x is the ne... | 1 | 2016-08-25T03:00:35Z | 39,136,500 | <p>Are you trying to do automatic nested dictionary insertion? If so, you could try using a <a href="https://docs.python.org/2/library/collections.html#collections.defaultdict" rel="nofollow">defaultdict</a>:</p>
<pre><code>from collections import defaultdict
data = defaultdict(dict)
for i in range(10):
x = "..."... | 2 | 2016-08-25T04:00:08Z | [
"python",
"python-2.7"
] |
Python3.4 error - Cannot enable executable stack as shared object requires: Invalid argument | 39,136,040 | <p>I've been trying to install <a href="http://opencv.org/" rel="nofollow">OpenCV</a> in a Bash on Windows (Windows Subsystem for Linux, wsl) environment and it's been proving very difficult.</p>
<p>I think I'm getting very close, but upon entering python, <code>import cv2</code> gives the following error:</p>
<pre><... | 0 | 2016-08-25T03:03:05Z | 39,223,317 | <p>There are lots of things that simply don't work at the moment, because there are either unimplemented syscalls (WSL only has partial coverage, only about 70% of syscalls are implemented, some of them only partially), or missing socket modes and options (WSL does not yet support Unix datagram sockets, although it sho... | 1 | 2016-08-30T09:12:37Z | [
"python",
"windows",
"python-3.x",
"opencv",
"wsl"
] |
Python Pandas with sqlalchemy | Bulk Insert Error | 39,136,120 | <p>I was try to Insert my millions of records from <strong>CSV</strong> File to <strong>MySQL</strong> Database, by using <strong>Python</strong> | <strong>Pandas</strong> with <strong>sqlalchemy</strong>. Some time this insertion is interrupted before the completion or not even insert single row to Database.</p>
<p>M... | 0 | 2016-08-25T03:12:09Z | 39,136,153 | <p>From the error raised your arguments in to the query aren't all strings so what you would have to do is go and convert each of the elements of data frame to string. <code>df =df.astype(str)</code></p>
| 0 | 2016-08-25T03:17:38Z | [
"python",
"mysql",
"csv",
"pandas",
"sqlalchemy"
] |
change image names from a text file python | 39,136,126 | <p>I know that there are python scripts that can change a file name But i have a little problem
I am trying to bulk upload some images into yahoo store, The names for the images has to be the same as the product id for the server to link the images to the proper product. (I still cant understand why they don't just hav... | -2 | 2016-08-25T03:13:13Z | 39,136,147 | <p>Renaming files:</p>
<pre><code>import os
os.rename("filename.jpg","newname.jpg")
</code></pre>
<p>If you want to read from list and rename</p>
<pre><code>with open("listname") as f:
for line in f:
os.rename(line,"newname.jpg")
</code></pre>
| 0 | 2016-08-25T03:16:23Z | [
"python",
"excel",
"image"
] |
change image names from a text file python | 39,136,126 | <p>I know that there are python scripts that can change a file name But i have a little problem
I am trying to bulk upload some images into yahoo store, The names for the images has to be the same as the product id for the server to link the images to the proper product. (I still cant understand why they don't just hav... | -2 | 2016-08-25T03:13:13Z | 39,176,702 | <pre><code>import os
import csv
keys{}
with open('product_image.csv',rU) as csvfile:
reader = csv.reader(csvfile, delimiter = ',')
for rowDict in reader:
keys[ rowDict[0] ] = rowDict[1]
print (rowDict)
for fileName in (os.listdir('.') & keys.keys() ):
try:
os... | 0 | 2016-08-27T01:47:21Z | [
"python",
"excel",
"image"
] |
importlib can't find module | 39,136,134 | <p><strong>cat test.py</strong> </p>
<pre><code>from importlib import import_module
bar = import_module('bar', package='project')
</code></pre>
<p><strong>ls project/</strong></p>
<pre><code>__init__.py
__init__.pyc
bar.py
bar.pyc
</code></pre>
<p><strong>python test.py</strong></p>
<pre><code>Traceback (most r... | 0 | 2016-08-25T03:14:54Z | 39,136,163 | <p>It needs a dot in front of bar .. :-(</p>
<pre><code>bar = import_module('.bar', package='project')
</code></pre>
| 0 | 2016-08-25T03:18:45Z | [
"python",
"python-importlib"
] |
importlib can't find module | 39,136,134 | <p><strong>cat test.py</strong> </p>
<pre><code>from importlib import import_module
bar = import_module('bar', package='project')
</code></pre>
<p><strong>ls project/</strong></p>
<pre><code>__init__.py
__init__.pyc
bar.py
bar.pyc
</code></pre>
<p><strong>python test.py</strong></p>
<pre><code>Traceback (most r... | 0 | 2016-08-25T03:14:54Z | 39,136,654 | <p>The documentation for <a href="https://docs.python.org/2/library/importlib.html" rel="nofollow">import_lib</a> says that </p>
<blockquote>
<p>If the name is specified in relative terms, then the package argument must be specified to the package which is to act as the anchor for resolving the package name (e.g. im... | 0 | 2016-08-25T04:20:16Z | [
"python",
"python-importlib"
] |
Program that prints one word per line | 39,136,165 | <p>Need to create a program that prints one word per line, but only if that word is less than 4 character. I have this so far</p>
<p>The input will be a list such as ['Not','very','good','at','python']</p>
<pre><code>string = input("Enter word list:")
txt = string.split()
for words in txt:
print(words)
</code... | -1 | 2016-08-25T03:18:58Z | 39,136,224 | <p>well, check the length of the word. </p>
<pre><code>string = input('Enter word list:\n')
txt = string.split()
for word in txt:
if len(word) < 4:
print('{0}'.format(word))
else:
continue
</code></pre>
| 1 | 2016-08-25T03:28:29Z | [
"python"
] |
Program that prints one word per line | 39,136,165 | <p>Need to create a program that prints one word per line, but only if that word is less than 4 character. I have this so far</p>
<p>The input will be a list such as ['Not','very','good','at','python']</p>
<pre><code>string = input("Enter word list:")
txt = string.split()
for words in txt:
print(words)
</code... | -1 | 2016-08-25T03:18:58Z | 39,136,243 | <p>Use the built-in function <code>len()</code> to count the length of each word. I have also included a simple parsing if statement to detect if your input is a list. </p>
<pre><code>string = raw_input('Enter word list: ')
if string[0] == "[" and string[-1] == "]": # simple method to parse
print(string)
else:
... | 0 | 2016-08-25T03:30:49Z | [
"python"
] |
Program that prints one word per line | 39,136,165 | <p>Need to create a program that prints one word per line, but only if that word is less than 4 character. I have this so far</p>
<p>The input will be a list such as ['Not','very','good','at','python']</p>
<pre><code>string = input("Enter word list:")
txt = string.split()
for words in txt:
print(words)
</code... | -1 | 2016-08-25T03:18:58Z | 39,136,247 | <p>When you input['Not','very','good','at','python'],there has âï¼â. But when you input "Not very good at python", there not has ','.</p>
| 0 | 2016-08-25T03:31:21Z | [
"python"
] |
Program that prints one word per line | 39,136,165 | <p>Need to create a program that prints one word per line, but only if that word is less than 4 character. I have this so far</p>
<p>The input will be a list such as ['Not','very','good','at','python']</p>
<pre><code>string = input("Enter word list:")
txt = string.split()
for words in txt:
print(words)
</code... | -1 | 2016-08-25T03:18:58Z | 39,136,287 | <p>Is the input you are providing literally ['Not','very','good','at','python']?<br>
If so that's your problem. The input is being seen as a literal string, not a list. Calling split on that input will produce a single item list of your input "list", as there are no white spaces in that string to split on.
I'm also s... | 0 | 2016-08-25T03:35:46Z | [
"python"
] |
Script waits for input when importing the webbrowser module | 39,136,176 | <p>I'm having a small yet quite annoying issue with Python. When I import the webbrowser module in a Python script that is run from IDLE, it works perfectly fine. However, if the script is run outside of IDLE, importing the webbrowser module makes the program stop and wait for user input. </p>
<p>I made the following ... | -2 | 2016-08-25T03:19:55Z | 39,156,409 | <p>Found the problem! there was a 'copy.py' script in the folder in which I store my scripts. The webbrowser module has to import a module named copy. Deleted 'copy.py' from the directory, everything works fine.</p>
| 2 | 2016-08-25T23:50:58Z | [
"python",
"windows",
"python-3.x",
"windows-console"
] |
Using python, how to use collect tweets (using tweepy) between two dates? | 39,136,226 | <p>How can i use python and tweepy in order to collect tweets from twitter that are between two given dates?</p>
<p>is there a way to pass from...until... values to the search api?</p>
<p><br/>
Note:
I need to be able to search back but WITHOUT limitation to a specific user</p>
<p>i am using python and I know that t... | -2 | 2016-08-25T03:28:40Z | 39,137,390 | <p>You have to use max_id parameters as described in <a href="https://dev.twitter.com/rest/public/timelines" rel="nofollow">twitter documentation</a></p>
<p>tweepy is a wrapper around twitter API so you should be able to use this parameter.</p>
<p>As per geolocation, take look at <a href="https://dev.twitter.com/rest... | -1 | 2016-08-25T05:34:24Z | [
"python",
"twitter",
"tweepy",
"tweets"
] |
Using python, how to use collect tweets (using tweepy) between two dates? | 39,136,226 | <p>How can i use python and tweepy in order to collect tweets from twitter that are between two given dates?</p>
<p>is there a way to pass from...until... values to the search api?</p>
<p><br/>
Note:
I need to be able to search back but WITHOUT limitation to a specific user</p>
<p>i am using python and I know that t... | -2 | 2016-08-25T03:28:40Z | 39,185,427 | <p>After long hours of investigations and stabilization i can gladly share my findings.
<br/></p>
<ul>
<li><p>search by geocode: pass the geocode parameter in the 'q' parameter in this format: <em>geocode:"37.781157,-122.398720,500mi"</em> , <strong>the double quotes are important</strong>. notice that the parameter... | 0 | 2016-08-27T20:22:54Z | [
"python",
"twitter",
"tweepy",
"tweets"
] |
How to add/drop items from a list | 39,136,260 | <p>I see plenty of posts adding and subtracting strings from a list but I need help with keeping count of those items.</p>
<p>I would like to couple those items so there are no repeats just a counter.</p>
<p>Ex:
3 Apples 4 Oranges 2 Bananas</p>
<p>I want to be able to "take" one item at a time so if I were to call:
... | 2 | 2016-08-25T03:32:47Z | 39,136,627 | <p>Consider using a <code>dictionary</code> instead of a <code>list</code>. Dictionaries are ideal for maintaining <code>counts</code> of <code>things</code>:</p>
<pre><code>from random import choice
def get_rooms(file_name):
rooms = {}
with open(file_name) as f:
for l in f:
room = l.split... | 0 | 2016-08-25T04:17:14Z | [
"python",
"list"
] |
uWSGI: Override default harakiri duration in flask/python | 39,136,396 | <p>For most requests/routes a standard harakiri value of 15s or 30s will be fine.</p>
<p>But a few endpoints are long running (such as when generating reports) and I want the client to wait synchronously while they are prepared and returned.</p>
<p>Can I set a default harakiri value in uwsgi.ini and then override it ... | 0 | 2016-08-25T03:48:53Z | 39,136,614 | <p>Well, if project you're writing could be written in different way, then you can do the generating process. It's one of many options:</p>
<p>Create a link which will fire up backend process. After user page refresh, there will be wording that generating is in progress. Then you have two options, first is to tell end... | 0 | 2016-08-25T04:15:23Z | [
"python",
"flask",
"uwsgi"
] |
Multiprocessing to speed up for loop | 39,136,575 | <p>Just trying to learn and I"m wondering if multiprocessing would speed
up this for loop ,.. trying to compare
alexa_white_list(1,000,000 lines) and
dnsMISP (can get up to 160,000 lines)</p>
<p>Code checks each line in dnsMISP and looks for it in alexa_white_list.
if it doesn't see it, it adds it to blacklist. </p>... | -1 | 2016-08-25T04:09:40Z | 39,136,644 | <p>You tried to read a variable named <code>dnsMISP</code> to pass as an argument to <code>Pool.map</code>. It doesn't exist in local or global scope (where do you think it's coming from?), so you got a <code>NameError</code>. This has nothing to do with <code>multiprocessing</code>; you could just type a line with not... | 0 | 2016-08-25T04:19:32Z | [
"python"
] |
Multiprocessing to speed up for loop | 39,136,575 | <p>Just trying to learn and I"m wondering if multiprocessing would speed
up this for loop ,.. trying to compare
alexa_white_list(1,000,000 lines) and
dnsMISP (can get up to 160,000 lines)</p>
<p>Code checks each line in dnsMISP and looks for it in alexa_white_list.
if it doesn't see it, it adds it to blacklist. </p>... | -1 | 2016-08-25T04:09:40Z | 39,136,828 | <p>There's no need for multiprocessing here. In fact this code can be greatly simplified:</p>
<pre><code>def get_host_form_line(line):
return line.strip().split(".", 1)[-1]
def dns_check():
with open('alexa.txt') as alexa:
awl = {get_host_from_line(line) for line in alexa}
blacklist = []
with... | 1 | 2016-08-25T04:44:21Z | [
"python"
] |
Retrieve data from hardware(eg CCTV,RFID) if library/API is not available | 39,136,621 | <p>I want to access data from devices like <strong>RFID reader</strong>,<strong>CCTV camera</strong> which will be connected to a device which has <strong><em>SUSE Linux</em></strong> in it.This is a proprietary device --> <strong>Huawei AR515</strong>. </p>
<p>But, I am not sure in what format, data will be produced... | -1 | 2016-08-25T04:16:38Z | 39,137,018 | <p>In python, maybe this way can helps you </p>
<p><a href="http://stackoverflow.com/questions/19908167/reading-serial-data-in-realtime-in-python">Reading serial data in realtime in Python</a></p>
<p>In C/C++ for linux platform, you can read directly in /dev/.
In both cases, is mandatory knows whats commands and sequ... | 1 | 2016-08-25T05:03:17Z | [
"python",
"c++",
"embedded",
"hardware",
"embedded-linux"
] |
I am new at this and am trying to figure out how to use timers and loops. I am trying to loop this with a timer. Can you help me? | 39,136,660 | <pre><code>for i in xrange(5):
abc()
time.sleep(3)
print('?~~~~~')
print('~?~~~~')
print('~~?~~~')
print('~~~?~~')
print('~~~~?~')
print('~~~~~?')
print('?~~~~~')
print('~?~~~~')
print('~~?~~~')
print('~~~?~~')
print('~~~~?~')
print('~~~~~?')
</code></pre>
| -2 | 2016-08-25T04:21:11Z | 39,138,016 | <p>In this answer I am assuming that you want to move the question mark along the line as the timer advances, with a three second gap in between.</p>
<p>This code nearly needs to be rewritten completely. Don't fret, it's not too bad and it's easy to fix.</p>
<p>The first thing that is wrong here is that you haven't i... | 0 | 2016-08-25T06:20:03Z | [
"python",
"loops",
"timer",
"python-2.x"
] |
confused about numpy.c_ document and sample code | 39,136,730 | <p>I read the document about numpy.c_ many times but still confused. It is said -- "Translates slice objects to concatenation along the second axis." in the following document. Could anyone clarify in the example below, what is slice objects, and what is 2nd axis? I see they are all one dimension and confused where the... | 0 | 2016-08-25T04:32:14Z | 39,137,008 | <p><code>np.c_</code> is another way of doing array concatenate</p>
<pre><code>In [701]: np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
Out[701]: array([[1, 2, 3, 0, 0, 4, 5, 6]])
In [702]: np.concatenate([np.array([[1,2,3]]), [[0]], [[0]], np.array([[4,5,6]])],
axis=1)
Out[702]: array([[1, 2, 3, 0, 0, 4... | 2 | 2016-08-25T05:02:13Z | [
"python",
"python-2.7",
"numpy",
"machine-learning"
] |
How can I get axis of different length but same scale for subplots in matplotlib? | 39,136,786 | <p>If I have, for example, these 3 datasets to plot:</p>
<pre><code>a = np.arange(0,10,1)
b = np.arange(2,6,1)
c = np.arange(5,10,1)
</code></pre>
<p>and obviously, I don't want them to share the same axis, because some of them would basically just have a big empty graph with a few datapoints somewhere in the corner.... | 0 | 2016-08-25T04:39:05Z | 39,137,050 | <p>Well after an hour:</p>
<pre><code>__author__ = 'madevelasco'
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
def group(x, max, min, iters):
total_range = max - min
for i in range(0, iters):
if (x > min + i*total_range/iters and x <= min + (i+1)*total_range/iters):
... | 0 | 2016-08-25T05:05:37Z | [
"python",
"matplotlib"
] |
How can I get axis of different length but same scale for subplots in matplotlib? | 39,136,786 | <p>If I have, for example, these 3 datasets to plot:</p>
<pre><code>a = np.arange(0,10,1)
b = np.arange(2,6,1)
c = np.arange(5,10,1)
</code></pre>
<p>and obviously, I don't want them to share the same axis, because some of them would basically just have a big empty graph with a few datapoints somewhere in the corner.... | 0 | 2016-08-25T04:39:05Z | 39,239,438 | <p>After doing a lot of research, it looks like there really isn't any simple command to do this. But first, giving a thought of the range of both x and y values of each subplot and their ratios, and the layout, GridSpec will do the job.</p>
<p>So for our example, the layout is as presented in the question, i.e. the b... | 0 | 2016-08-31T01:36:59Z | [
"python",
"matplotlib"
] |
How can I split an integer into a list of n length evenly in Python 3.5? | 39,136,825 | <p>I need to be able to split an integer into a list of n-length evenly.</p>
<p>For example n = 4,</p>
<pre><code>12 -> [0, 0, 1, 2]
1234 -> [1, 2, 3, 4]
12345 -> [1, 2, 3, 45]
123456 -> [1, 2, 34, 56]
1234567 -> [1, 23, 45, 67]
12345678 -> 12, 34, 56, 78]
123456789 -> [12, 34, 56, 789]
</code></... | 2 | 2016-08-25T04:43:51Z | 39,137,047 | <p>sorry - for faulty code
It is working according to the spec</p>
<pre><code>def split(s, list_size):
s = str(s)
assert len(s) >= list_size, "assertion failed"
r, rem = divmod(len(s), list_size)
lst = []
for i in range(list_size):
lst.append(s[i*r:(i+1)*r])
for j in range(rem):
... | -1 | 2016-08-25T05:05:21Z | [
"python",
"python-3.x"
] |
How can I split an integer into a list of n length evenly in Python 3.5? | 39,136,825 | <p>I need to be able to split an integer into a list of n-length evenly.</p>
<p>For example n = 4,</p>
<pre><code>12 -> [0, 0, 1, 2]
1234 -> [1, 2, 3, 4]
12345 -> [1, 2, 3, 45]
123456 -> [1, 2, 34, 56]
1234567 -> [1, 23, 45, 67]
12345678 -> 12, 34, 56, 78]
123456789 -> [12, 34, 56, 789]
</code></... | 2 | 2016-08-25T04:43:51Z | 39,137,072 | <pre><code>def split(seq, n):
"""Partitions `seq` into `n` successive slices of roughly equal size.
The sizes of each yielded slice shall differ by at most one.
"""
q, r = divmod(len(seq), n)
start = 0
for i in range(n):
size = q + (i < r)
yield seq[start : start + size]
... | 4 | 2016-08-25T05:08:13Z | [
"python",
"python-3.x"
] |
How can I split an integer into a list of n length evenly in Python 3.5? | 39,136,825 | <p>I need to be able to split an integer into a list of n-length evenly.</p>
<p>For example n = 4,</p>
<pre><code>12 -> [0, 0, 1, 2]
1234 -> [1, 2, 3, 4]
12345 -> [1, 2, 3, 45]
123456 -> [1, 2, 34, 56]
1234567 -> [1, 23, 45, 67]
12345678 -> 12, 34, 56, 78]
123456789 -> [12, 34, 56, 789]
</code></... | 2 | 2016-08-25T04:43:51Z | 39,137,319 | <p>Variant on Ahsan's answer that should distribute to the remainder across the end of the sequence correctly:</p>
<pre><code>from itertools import accumulate
def split(s, parts):
s = str(s)
r, rem = divmod(len(s), parts)
norem = parts - rem
counts = [r]*norem + [r+1]*rem
# Prepend 0 to counts onl... | 1 | 2016-08-25T05:28:36Z | [
"python",
"python-3.x"
] |
How can I split an integer into a list of n length evenly in Python 3.5? | 39,136,825 | <p>I need to be able to split an integer into a list of n-length evenly.</p>
<p>For example n = 4,</p>
<pre><code>12 -> [0, 0, 1, 2]
1234 -> [1, 2, 3, 4]
12345 -> [1, 2, 3, 45]
123456 -> [1, 2, 34, 56]
1234567 -> [1, 23, 45, 67]
12345678 -> 12, 34, 56, 78]
123456789 -> [12, 34, 56, 789]
</code></... | 2 | 2016-08-25T04:43:51Z | 39,137,377 | <p>The selected answer has its advantage, but I did it in a more straightforward way:</p>
<pre><code>def chunk(s, n):
return [s[i:i+n] for i in range(0, len(s), n)]
def split(s0, numberOfChunks):
s = ('0' * max(0, numberOfChunks - len(s0))) + s0
sizeOfChunk = len(s) / numberOfChunks
numberOfSmallChunk... | 0 | 2016-08-25T05:33:38Z | [
"python",
"python-3.x"
] |
how scikit learn figure out logistic regression for classification or regression | 39,136,833 | <p>I think logistic regression could be used for both regression (get number between 0 and 1, e.g. using logistic regression to predict a probability between 0 and 1) and classification. The question is, it seems after we provide the training data and target, logistic regression could automatically figure out if we are... | 0 | 2016-08-25T04:45:02Z | 39,150,081 | <p>Logistic regression often uses a cross-entropy cost function, which models loss according to a binary error. Also, the output of logistic regression usually follows a sigmoid at the decision boundary, meaning that while the decision boundary may be linear, the output (often viewed as a probability of the point repre... | 1 | 2016-08-25T16:11:23Z | [
"python",
"python-2.7",
"machine-learning",
"scikit-learn",
"logistic-regression"
] |
Django: Redirecting to another url based on user input in form | 39,136,861 | <p>I am trying to achieve something really simple and having no luck after reviewing the Django forms documentation as well as the section in the Django Tutorial on Forms (Part 4), and several SO threads.</p>
<p>I have a home page which has a form in which the user should be able to enter the name of some basketball p... | 1 | 2016-08-25T04:48:55Z | 39,137,292 | <p>You should use name given in <code>form.cleaned_data</code> not <code>form.name</code>.
So your code should be </p>
<pre><code>return HttpResponseRedirect(reverse('desk:player_stats',
args=(form.cleaned_data['name'],)))
</code></pre>
| 3 | 2016-08-25T05:27:06Z | [
"python",
"django",
"forms"
] |
Going through words in a list in a python for loop and it says that it's out of range? | 39,137,033 | <p>I am writing a python script and at one point I use the following for loop:</p>
<pre><code>word=raw_input("Pick one of the words above. ")
print(sentence.split())
number = len(sentence.split()) + 1
for y in range (0, number):
if sentence.split()[y] == word:
global wordNumber
... | 0 | 2016-08-25T05:04:24Z | 39,137,085 | <p>You are iterating past the end of the list. Since the list has <code>len(sentence.split())</code> items, that means its indices go from <code>0</code> to <code>len(sentence.split()) - 1</code>. So, you want to iterate over <code>range(0, len(sentence_split())</code> so that the last iterated index is <code>len(sente... | 0 | 2016-08-25T05:09:13Z | [
"python"
] |
Scraping Restaurant Details from Trip Advisor | 39,137,066 | <p>I am trying to make a script to scrap Restaurant details from TripAdvisor site. Just for learning.</p>
<p>The problem here is I cant find restaurant names in Source page from the second page. Well, actually there is no correct second link. But when I check live site and inspect, I can see the restaurant name.</p>
... | 0 | 2016-08-25T05:07:45Z | 39,138,363 | <p>I think you had a typo in the second part of your code:</p>
<pre><code>url1 = "https://www.tripadvisor.in/RestaurantSearch-g294003-oa120-Kuwait_City.html"
r=requests.get(url)
#Change this to:
r=requests.get(url1)
</code></pre>
| 1 | 2016-08-25T06:42:20Z | [
"python",
"screen-scraping",
"bs4"
] |
How to Run a Python Script from a Rails Application? | 39,137,179 | <p>I am working on a rails application now that needs to run a single python script whenever a button is clicked on our apps home page. I am trying to figure out a way to have rails run this script, and both of my attempts so far have failed. </p>
<p>My first try was to use the exec(..) command to just run the "pyt... | 0 | 2016-08-25T05:16:50Z | 39,137,328 | <p><code>exec</code> replaces the current process with the new one. You want to run it as a subprocess. See <a href="http://stackoverflow.com/questions/7212573/when-to-use-each-method-of-launching-a-subprocess-in-ruby">When to use each method of launching a subprocess in Ruby</a> for an overview; I suggest using either... | 1 | 2016-08-25T05:29:24Z | [
"python",
"ruby-on-rails",
"ruby"
] |
How to fix TypeError: __init__() takes at least 2 arguments (1 given) Error | 39,137,214 | <p>I am trying to split the uploaded pdf file into images but i am getting error like take at least 2 arguments(1given).</p>
<p>I know this error is already asked but i confused to fix in my program.</p>
<pre><code>from pyPdf import PdfFileWriter, PdfFileReader
from wand.image import Image
import os
from Tkinter imp... | -2 | 2016-08-25T05:19:50Z | 39,137,747 | <p><code>Tkinter</code> has it's own <code>Image</code> class <code>Tkinter.Image</code>.
When you import all from Tkinter after import <code>wand.image.Image</code>, you start to use <code>Image</code> class from <code>Tkinter</code>.
You should import <code>Tkinter</code> as <code>import Tkinter as tk</code> and use ... | 2 | 2016-08-25T06:03:25Z | [
"python",
"tkinter",
"wand"
] |
Django exception : django.core.exceptions.ImproperlyConfigured: | 39,137,339 | <p>When i run the same code in django shell it works fine for me. but when I fire up the Python interpreter (Python 2) to check some things, I get the an error when I try importing - from django.contrib.auth.models import User </p>
<pre><code>import os
import django
django.setup()
import smtplib
import sys
sys.path.in... | 0 | 2016-08-25T05:30:03Z | 39,137,386 | <p>When you open a shell, <code>django</code> automatically sets itself up. </p>
<p>With Python interpreter you have to do this manually:</p>
<pre><code>import django
django.setup()
</code></pre>
| 0 | 2016-08-25T05:34:12Z | [
"python",
"django"
] |
Django exception : django.core.exceptions.ImproperlyConfigured: | 39,137,339 | <p>When i run the same code in django shell it works fine for me. but when I fire up the Python interpreter (Python 2) to check some things, I get the an error when I try importing - from django.contrib.auth.models import User </p>
<pre><code>import os
import django
django.setup()
import smtplib
import sys
sys.path.in... | 0 | 2016-08-25T05:30:03Z | 39,137,721 | <p>Django needs to be setup, in order to run fine, when you run it through manage.py shell, manage.py takes care or setting it up for you, but doing it via a python script, needs manual setup.</p>
<p>You also seem to have used your defined models, to be able to import them into your python script, you need to add the ... | 1 | 2016-08-25T06:01:42Z | [
"python",
"django"
] |
Short Unique Hexadecimal String in Python | 39,137,344 | <p>I need to generate a unique hexadecimal string in Python 3 that meets following requirements:</p>
<ol>
<li>It should contain 6 characters</li>
<li>it should not contain just digits. There must be at least one character. </li>
<li>These generated strings should be random. They should not be in any order.</li>
<li>Th... | 0 | 2016-08-25T05:30:18Z | 39,137,997 | <p><strong>Note:</strong> Updated the answer for hexadecimal unique string. Earlier I assumed for alhanumeric string.</p>
<p>You may create your own unique function using <code>uuid</code> and <code>random</code> library</p>
<pre><code>>>> import uuid
>>> import random
# Step 1: Slice uuid with 5 i.... | 1 | 2016-08-25T06:19:05Z | [
"python",
"python-3.x",
"uuid"
] |
Short Unique Hexadecimal String in Python | 39,137,344 | <p>I need to generate a unique hexadecimal string in Python 3 that meets following requirements:</p>
<ol>
<li>It should contain 6 characters</li>
<li>it should not contain just digits. There must be at least one character. </li>
<li>These generated strings should be random. They should not be in any order.</li>
<li>Th... | 0 | 2016-08-25T05:30:18Z | 39,138,110 | <p>Here's a simple method that samples evenly from all allowed strings. Sampling uniformly makes conflicts as rare as possible, short of keeping a log of previous keys or using a hash based on a counter (see below).</p>
<pre><code>import random
digits = '0123456789'
letters = 'abcdef'
all_chars = digits + letters
leng... | 3 | 2016-08-25T06:26:34Z | [
"python",
"python-3.x",
"uuid"
] |
Short Unique Hexadecimal String in Python | 39,137,344 | <p>I need to generate a unique hexadecimal string in Python 3 that meets following requirements:</p>
<ol>
<li>It should contain 6 characters</li>
<li>it should not contain just digits. There must be at least one character. </li>
<li>These generated strings should be random. They should not be in any order.</li>
<li>Th... | 0 | 2016-08-25T05:30:18Z | 39,139,235 | <p>The following approach works as follows, first pick one random letter to ensure rule 2, then select 4 random entries from the list of all available characters. Shuffle the resulting list. Lastly prepend one value taken from the list of all entries except <code>0</code> to ensure the string has 6 characters.</p>
<pr... | 1 | 2016-08-25T07:32:05Z | [
"python",
"python-3.x",
"uuid"
] |
Short Unique Hexadecimal String in Python | 39,137,344 | <p>I need to generate a unique hexadecimal string in Python 3 that meets following requirements:</p>
<ol>
<li>It should contain 6 characters</li>
<li>it should not contain just digits. There must be at least one character. </li>
<li>These generated strings should be random. They should not be in any order.</li>
<li>Th... | 0 | 2016-08-25T05:30:18Z | 39,139,679 | <p>This function returns the nth string conforming to your requirements, so you can simply generate unique integers and convert them using this function.</p>
<pre><code>def inttohex(number, digits):
# there must be at least one character:
fullhex = 16**(digits - 1)*6
assert number < fullhex
partialn... | 0 | 2016-08-25T07:56:43Z | [
"python",
"python-3.x",
"uuid"
] |
Vtk inserts incorrect color between nodes when mapping texture to mesh | 39,137,374 | <p>Hi I am trying to map a texture to 3d mesh using Mayavi and Python bindings of vtk. I am visualising an .obj wavefront. This obj is 3D photograph of a face. The texture image is a composite of three 2D photographs.</p>
<p><a href="http://i.stack.imgur.com/KNNGr.png" rel="nofollow"><img src="http://i.stack.imgur.com... | 0 | 2016-08-25T05:33:30Z | 39,237,979 | <p>You can turn off all interpolation (change <code>interpolate = 1</code> to <code>interpolate = 0</code> in your example), but there is not a way to turn off interpolation at just the places where it would interpolate across sub-images of the texture â at least not without writing your own fragment shader. This wil... | 1 | 2016-08-30T22:22:00Z | [
"python",
"vtk",
"texture-mapping",
"wavefront"
] |
Loading css in python web app using jinja2 | 39,137,499 | <p>I'm trying to make a little bioinformatics web app. I had it working with CGI, I am trying to tweak it so I can serve it on pythonanywhere or heroku. </p>
<p>The problem I am having is that the stylesheet and javascript aren't loading. I'm pretty new to programming, but I have searched extensively before posting. ... | 3 | 2016-08-25T05:43:04Z | 39,137,725 | <p>If you are not using a WSGI server that also provides support for hosting static files, such as mod_wsgi with Apache, the best thing to do is to use a WSGI middleware to handle serving up static files. The main such WSGI middleware people use is called Whitenoise.</p>
<ul>
<li><a href="https://pypi.python.org/pypi/... | 2 | 2016-08-25T06:01:54Z | [
"python",
"html",
"css",
"jinja2",
"wsgi"
] |
Map to List error: Series object not callable | 39,137,506 | <pre><code>from nsepy import get_history
from datetime import date
import datetime
import pandas as pd
import numpy as np
file = r'C:\Users\Raspberry-Pi\Desktop\Desktop\List.xlsx'
list = pd.read_excel(file)
list = list['SYMBOL']
start = date.today()-datetime.timedelta(days = 10)
end = date.today()
symb = get_history(sy... | 3 | 2016-08-25T05:43:46Z | 39,137,601 | <p>But I think you can omit <code>map</code> and use simple subtract and then convert to <code>list</code>:</p>
<pre><code>symb = get_history(symbol='INFY',start = start,end = end)
print ((symb.tail(3).High - symb.tail(3).Low).tolist())
</code></pre>
<p>Also don't use variable <code>list</code> (reserved word in pyth... | 2 | 2016-08-25T05:52:02Z | [
"python",
"list",
"pandas",
"dictionary",
"dataframe"
] |
Map to List error: Series object not callable | 39,137,506 | <pre><code>from nsepy import get_history
from datetime import date
import datetime
import pandas as pd
import numpy as np
file = r'C:\Users\Raspberry-Pi\Desktop\Desktop\List.xlsx'
list = pd.read_excel(file)
list = list['SYMBOL']
start = date.today()-datetime.timedelta(days = 10)
end = date.today()
symb = get_history(sy... | 3 | 2016-08-25T05:43:46Z | 39,137,723 | <p>The problem is that you have reassigned reserve word </p>
<pre><code>list = pd.read_excel(file)
list = list['SYMBOL']
</code></pre>
<p>hence list here is just a list of <code>['S', 'Y', 'M', 'B'..]</code>. Use another name for this definition the program will work fine</p>
| 0 | 2016-08-25T06:01:48Z | [
"python",
"list",
"pandas",
"dictionary",
"dataframe"
] |
Map to List error: Series object not callable | 39,137,506 | <pre><code>from nsepy import get_history
from datetime import date
import datetime
import pandas as pd
import numpy as np
file = r'C:\Users\Raspberry-Pi\Desktop\Desktop\List.xlsx'
list = pd.read_excel(file)
list = list['SYMBOL']
start = date.today()-datetime.timedelta(days = 10)
end = date.today()
symb = get_history(sy... | 3 | 2016-08-25T05:43:46Z | 39,138,151 | <p><code>list(x)</code> normally means turn <code>x</code> into a <code>list</code> object. It's a function that creates a list object. But near the top you redefined <code>list</code>:</p>
<pre><code>list = pd.read_excel(file)
</code></pre>
<p>Now <code>list</code> is now a pandas <code>series</code> object (as t... | 2 | 2016-08-25T06:29:29Z | [
"python",
"list",
"pandas",
"dictionary",
"dataframe"
] |
Installing PyMongo and bottle in cloud9 IDE | 39,137,507 | <p>How to install PyMongo and bottle in cloud9 IDE?</p>
| 0 | 2016-08-25T05:44:01Z | 39,144,674 | <p>The best method to install PyMongo and Bottle in Cloud9 is via <strong>Python-pip</strong>. Get pip first. Open your C9 terminal and run the following commands:</p>
<pre><code>sudo apt-get install python-pip
</code></pre>
<p>After pip is installed you can get PyMongo and Bottle by running the following commands:</... | 1 | 2016-08-25T11:56:54Z | [
"python",
"mongodb",
"bottle",
"cloud9-ide"
] |
How do I set up Scrapy to deal with a captcha | 39,137,559 | <p>I'm trying to scrape a site that requires the user to enter the search value and a captcha. I've got an optical character recognition (OCR) routine for the captcha that succeeds about 33% of the time. Since the captchas are always alphabetic text, I want to reload the captcha if the OCR function returns non-alphabet... | 2 | 2016-08-25T05:48:28Z | 39,140,393 | <p>It's a really deep topic with a bunch of solutions. But if you want to apply the logic you've defined in your post you can use scrapy <a href="http://doc.scrapy.org/en/latest/topics/downloader-middleware.html" rel="nofollow">Downloader Middlewares</a>.</p>
<p>Something like:</p>
<pre><code>class CaptchaMiddleware(... | 2 | 2016-08-25T08:34:42Z | [
"python",
"web-scraping",
"scrapy",
"captcha"
] |
Renaming file name by incrementing them | 39,137,574 | <p>I would like to rename a list of pictures in the same folder(For e.g <code>001.jpg</code> to <code>020.jpg</code> , <code>002.jpg</code> to <code>021.jpg</code> and increment).I was thinking of using Python. Recommendations?</p>
| -4 | 2016-08-25T05:49:33Z | 39,137,621 | <p>Refer <a href="https://docs.python.org/2/library/os.html" rel="nofollow">os</a> library. You'll get all what you need. You have to use <code>rename</code> method to rename the file.</p>
<p>Below is the sample code to rename all the files in the directory to <code>0-N.jpg</code>.</p>
<pre><code>>>> import ... | 1 | 2016-08-25T05:53:40Z | [
"python"
] |
Renaming file name by incrementing them | 39,137,574 | <p>I would like to rename a list of pictures in the same folder(For e.g <code>001.jpg</code> to <code>020.jpg</code> , <code>002.jpg</code> to <code>021.jpg</code> and increment).I was thinking of using Python. Recommendations?</p>
| -4 | 2016-08-25T05:49:33Z | 39,137,694 | <pre><code>import os, sys
files = os.listdir()
counter = 0
for file in files:
if file[-4:] == '.jpg':
os.rename(file, "{0}.jpg".format(counter))
counter += 1
</code></pre>
| 0 | 2016-08-25T05:59:32Z | [
"python"
] |
How to deal with repeated letters in arabic | 39,137,851 | <p>I want to normalize arabic string by replacing repeated characters with only one character. For example: the word </p>
<pre><code> رااااائع
</code></pre>
<p>will be normalized as </p>
<pre><code>رائع
</code></pre>
<p>I found a regular expression suitable for english (python):</p>
<pre><code>s="I loo... | 0 | 2016-08-25T06:09:49Z | 39,138,200 | <p>Try the following:</p>
<pre><code>import itertools
string = u"رااااائع"
''.join(char for char, _ in itertools.groupby(string))
</code></pre>
<p>I can't test it with arabic but it works with normal strings</p>
<p>reference: <a href="https://docs.python.org/2/library/itertools.html#itertools.groupby" rel="n... | 0 | 2016-08-25T06:32:09Z | [
"python",
"arabic"
] |
How to deal with repeated letters in arabic | 39,137,851 | <p>I want to normalize arabic string by replacing repeated characters with only one character. For example: the word </p>
<pre><code> رااااائع
</code></pre>
<p>will be normalized as </p>
<pre><code>رائع
</code></pre>
<p>I found a regular expression suitable for english (python):</p>
<pre><code>s="I loo... | 0 | 2016-08-25T06:09:49Z | 39,140,438 | <p>Now, I want to do normalization for each line in a file.</p>
<pre><code>mon_fichier = open("./file.txt", "r")
my_file = open("./normalisation/file_norm.txt", "w")
contenu = mon_fichier.read()
liste = contenu.split('\n')
for var in liste:
v= var.encode('utf-8')
s ="".join(c for c, _ in itertools.groupby(v))
... | 0 | 2016-08-25T08:37:16Z | [
"python",
"arabic"
] |
How to deal with repeated letters in arabic | 39,137,851 | <p>I want to normalize arabic string by replacing repeated characters with only one character. For example: the word </p>
<pre><code> رااااائع
</code></pre>
<p>will be normalized as </p>
<pre><code>رائع
</code></pre>
<p>I found a regular expression suitable for english (python):</p>
<pre><code>s="I loo... | 0 | 2016-08-25T06:09:49Z | 39,140,580 | <p>You are converting a character that cannot be converted to utf-8.</p>
<blockquote>
<p>UnicodeDecodeError: 'ascii' codec can't decode byte 0xd8 in position
0: ordinal not in range(128)</p>
</blockquote>
<p>I suggest you use either ignore or replace:</p>
<pre><code>v= var.encode('utf-8', 'ignore')
</code></pre>... | 0 | 2016-08-25T08:43:39Z | [
"python",
"arabic"
] |
How to deal with repeated letters in arabic | 39,137,851 | <p>I want to normalize arabic string by replacing repeated characters with only one character. For example: the word </p>
<pre><code> رااااائع
</code></pre>
<p>will be normalized as </p>
<pre><code>رائع
</code></pre>
<p>I found a regular expression suitable for english (python):</p>
<pre><code>s="I loo... | 0 | 2016-08-25T06:09:49Z | 39,140,877 | <p>You need to add this line to your code :
<code>from __future__ import unicode_literals</code></p>
<pre><code># encoding: utf-8
from __future__ import unicode_literals
import re
s="رااااائع"
s = re.sub(r'(.)\1+', r'\1', s)
print s
</code></pre>
<p>Out put :</p>
<pre><code>رائع
</code></pre>
| 1 | 2016-08-25T08:59:27Z | [
"python",
"arabic"
] |
How to deal with repeated letters in arabic | 39,137,851 | <p>I want to normalize arabic string by replacing repeated characters with only one character. For example: the word </p>
<pre><code> رااااائع
</code></pre>
<p>will be normalized as </p>
<pre><code>رائع
</code></pre>
<p>I found a regular expression suitable for english (python):</p>
<pre><code>s="I loo... | 0 | 2016-08-25T06:09:49Z | 39,142,114 | <p>the code that works for a string is the following:</p>
<pre><code>#!/usr/bin/python
# -*-coding:utf-8 -*
import re, string,sys
import itertools
my_file = open("./out.txt", "w")
ch= u"ÙØªØ§Ø¨ راااااائع جداااا"
s ="".join(c for c, _ in itertools.groupby(ch))
a=s.encode('utf-8')
my_file.write(a +"\n")... | 0 | 2016-08-25T09:57:34Z | [
"python",
"arabic"
] |
Calling functions from external python file throws 500 error | 39,137,874 | <p>I am trying to call a function from another python file. I have imported that function. When i call the function externally it works as expected.</p>
<p>But when i try to call the function before returning a render_template or a redirect , i get a 500 error.
I know i am doing something wrong but i am not sure what... | -1 | 2016-08-25T06:11:24Z | 39,138,382 | <p>You import a function named <code>trigger</code>, but you also a define a function named <code>trigger</code> in the module where you do the import. When <code>trigger</code> calls <code>trigger</code>, it is calling itself, and it accepts no arguments. You need to rename one of the functions, or do the import as ... | 1 | 2016-08-25T06:43:17Z | [
"python",
"flask"
] |
Iterating through capture fields in a Rust regex | 39,137,905 | <p>I'm playing around with the frowns parser available from http:// frowns.sourceforge.net, a parser that tokenizes SMILES standard chemical formula strings. Specifically I'm trying to port it to Rust.</p>
<p>The original regex for an "atom" token in the parser looks like this (Python):</p>
<pre><code>element_symbols... | 3 | 2016-08-25T06:13:08Z | 39,138,538 | <p>You are iterating on each character of your input string and trying to match the regex on a string composed of a single character. However, this regex is not designed to match individual characters. Indeed, the regex will match <code>[S]</code> as a whole.</p>
<p>If you want to be able to find multiple matches in a... | 5 | 2016-08-25T06:52:35Z | [
"python",
"regex",
"parsing",
"rust"
] |
build dynamic filters in sqlalchemy python | 39,137,911 | <p>I need to generate/build sqlalchemy query dynamically using dynamic columns and their values.</p>
<p>Example -
I have a table in SQL called "Convo" and it has columns like - UserID, ConvoID, ContactID.</p>
<p>I need to get rows based on the below criteria.</p>
<pre><code>criteria = (('UserID', 2), ('ConvoID', 1)... | 1 | 2016-08-25T06:13:27Z | 39,138,179 | <pre><code>criteria = (('UserID', 2), ('ConvoID', 1) ,('ContactID', 353))
query = session.query(tablename)
for _filter, value in criteria:
query = query.filter(getattr(tablename, _filter) == value)
result = query.all()
</code></pre>
| 1 | 2016-08-25T06:31:02Z | [
"python",
"sqlalchemy"
] |
build dynamic filters in sqlalchemy python | 39,137,911 | <p>I need to generate/build sqlalchemy query dynamically using dynamic columns and their values.</p>
<p>Example -
I have a table in SQL called "Convo" and it has columns like - UserID, ConvoID, ContactID.</p>
<p>I need to get rows based on the below criteria.</p>
<pre><code>criteria = (('UserID', 2), ('ConvoID', 1)... | 1 | 2016-08-25T06:13:27Z | 39,138,227 | <p>If you're using dynamic keys and "simple" equality checks, the <a href="http://docs.sqlalchemy.org/en/rel_1_0/orm/query.html?highlight=filter_by#sqlalchemy.orm.query.Query.filter_by" rel="nofollow">filter_by</a> method might be more convenient, as it takes keyword arguments that match you property names and assemble... | 1 | 2016-08-25T06:33:35Z | [
"python",
"sqlalchemy"
] |
Dataframe SMA Calculation | 39,138,299 | <p>Is there any simple tool/lib that can help me easily calculate the sma(..) of dataframe ?</p>
<pre><code> GLD SMA(5)
Date
2005-01-03 00:00:00+00:00 43.020000 Nan
2005-01-04 00:00:00+00:00 42.740002 Nan
2005-01-05 00:00:00+00:00 42.669998 Nan
20... | 2 | 2016-08-25T06:38:23Z | 39,138,436 | <pre><code>df['SMA(5)'] = df.GLD.rolling(5).mean()
df
</code></pre>
<p><a href="http://i.stack.imgur.com/Li6Ke.png" rel="nofollow"><img src="http://i.stack.imgur.com/Li6Ke.png" alt="enter image description here"></a></p>
| 3 | 2016-08-25T06:46:46Z | [
"python",
"pandas"
] |
How to protect some files from the Jinja template processor? | 39,138,386 | <p>I am using cookiecutter to create a tornado project, using <a href="https://github.com/luizalabs/tornado-cookiecutter" rel="nofollow">this template</a> (it has several bugs, so you'll probably won't be able to use it out of the box). I have hit a problem which I do not know how to solve:</p>
<pre><code>jinja2.excep... | 0 | 2016-08-25T06:43:23Z | 39,151,217 | <p>By default cookiecutter will try to process every file as a jinja template which produces wrong results if you have something that looks like a jinja template but is only supposed to be taken literal. Starting with cookiecutter 1.1 one can tell cookiecutter to only copy some files without interpreting them as jinja ... | 1 | 2016-08-25T17:19:16Z | [
"python",
"cookiecutter"
] |
Increment a char given a sequence | 39,138,533 | <p>Given a sequence of characters, return next following in alphabetical order. </p>
<p><code>Example: given 'A' it should return 'B', 'Z' -> 'AA', 'ZYZ' -> 'ZZA'</code> etc. </p>
<p>One relevant reference using modulo and math i have found <a href="http://stackoverflow.com/a/4583231/1256112">is in c#</a>.
In... | 0 | 2016-08-25T06:52:11Z | 39,138,668 | <p>Here is the simple elegant recursive solution, but be careful when the number is divisible by 26. Before passing to function check if it divisible by 26. </p>
<pre><code>def convert(num,a):
if(num<=26):
a+=chr(64+num)
return a
a+=convert(int(num/26),a)
num=num%26
if(num>0)... | 0 | 2016-08-25T07:00:02Z | [
"python",
"string",
"algorithm"
] |
Increment a char given a sequence | 39,138,533 | <p>Given a sequence of characters, return next following in alphabetical order. </p>
<p><code>Example: given 'A' it should return 'B', 'Z' -> 'AA', 'ZYZ' -> 'ZZA'</code> etc. </p>
<p>One relevant reference using modulo and math i have found <a href="http://stackoverflow.com/a/4583231/1256112">is in c#</a>.
In... | 0 | 2016-08-25T06:52:11Z | 39,139,733 | <p>Try:</p>
<pre><code>def increment_excel(s=''):
arr = list(s.upper().replace(' ', ''))
if arr:
arr.reverse()
n = 1
for i in range(len(arr)):
if ord(arr[i])+n <= ord('Z'):
arr[i] = chr(ord(arr[i]) + n)
n = 0
else:
... | 1 | 2016-08-25T07:59:20Z | [
"python",
"string",
"algorithm"
] |
Increment a char given a sequence | 39,138,533 | <p>Given a sequence of characters, return next following in alphabetical order. </p>
<p><code>Example: given 'A' it should return 'B', 'Z' -> 'AA', 'ZYZ' -> 'ZZA'</code> etc. </p>
<p>One relevant reference using modulo and math i have found <a href="http://stackoverflow.com/a/4583231/1256112">is in c#</a>.
In... | 0 | 2016-08-25T06:52:11Z | 39,152,192 | <p>Here's a solution which just uses string manipulation.</p>
<p>Leaving aside the normalization of the string (uppercase it, strip blanks), the function essentially finds the suffix consisting of an optional letter other than <kbd>Z</kbd> followed by any number of <kbd>Z</kbd>s (including none). The trailing <kbd>Z</... | 1 | 2016-08-25T18:16:20Z | [
"python",
"string",
"algorithm"
] |
Extract the data specified in brackets '[ ]' from a string message in python | 39,138,999 | <p>I want to extract fields from below Log message.</p>
<p>Example:</p>
<blockquote>
<p>Ignoring entry, Affected columns [column1:column2], reason[some reason], Details[some entry details]</p>
</blockquote>
<p>I need to extract the data specified in the brackets <code>[ ]</code> for "Affected columns,reason, Deta... | 1 | 2016-08-25T07:19:10Z | 39,139,293 | <p>If you are free to change the log format, it's easiest to use a common data format - I'd recommend JSON for such data. It is structured, but lightweight enough to write it even from custom bash scripts. The <a href="https://docs.python.org/3.5/library/json.html" rel="nofollow"><code>json</code> module</a> allows you... | 2 | 2016-08-25T07:35:37Z | [
"python",
"python-3.x"
] |
Reading input file and processing it in flask | 39,139,009 | <p>I'm trying to write a simple flask program that will create a web page in which it receives a file (by uploading it), and then using that file's data and displaying a filtered part of it in my web page, I just cant seem to understand how to do that.</p>
<p>This is the code I used to upload the file, which worked fi... | 0 | 2016-08-25T07:19:39Z | 39,140,025 | <p>You already saved it here </p>
<pre><code>file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
</code></pre>
<p>just open it up and read as you work with any other files, example:</p>
<pre><code>@app.route('/read_file', methods=['GET'])
def read_uploaded_file():
filename = secure_filename(request.ar... | 1 | 2016-08-25T08:15:29Z | [
"python",
"flask"
] |
create step spark python, amazon hadoop | 39,139,057 | <p>I am creating a Spark step with Hadoop on Amazon, but I left thinking all the time. Not if it's because I'm bad code or sending bad judgment, but can not find a way out.</p>
<p>I pass code</p>
<pre><code>spark-submit --deploy-mode cluster --master yarn --num-executors 5 --executor-cores 5 --executor-memory 1g s3:/... | 0 | 2016-08-25T07:21:58Z | 39,139,433 | <p>You application is waiting for yarn resources. Goto resource manager URL and see if you enough resources and using right queue. If you look at yarn resourcemanager logs will know the reason.</p>
| 1 | 2016-08-25T07:43:27Z | [
"python",
"hadoop",
"hive",
"pyspark",
"amazon-emr"
] |
create step spark python, amazon hadoop | 39,139,057 | <p>I am creating a Spark step with Hadoop on Amazon, but I left thinking all the time. Not if it's because I'm bad code or sending bad judgment, but can not find a way out.</p>
<p>I pass code</p>
<pre><code>spark-submit --deploy-mode cluster --master yarn --num-executors 5 --executor-cores 5 --executor-memory 1g s3:/... | 0 | 2016-08-25T07:21:58Z | 39,140,724 | <p>I don't work on Amazon EMR, but in Hadoop this happens when your YARN is waiting for resources for too long.</p>
<p>The resource negotiator couldn't allocate the required resources, try to reduce the resources required by your code. Also check the logs.</p>
<p>Read through: <a href="https://spark.apache.org/docs/1... | 1 | 2016-08-25T08:52:04Z | [
"python",
"hadoop",
"hive",
"pyspark",
"amazon-emr"
] |
create step spark python, amazon hadoop | 39,139,057 | <p>I am creating a Spark step with Hadoop on Amazon, but I left thinking all the time. Not if it's because I'm bad code or sending bad judgment, but can not find a way out.</p>
<p>I pass code</p>
<pre><code>spark-submit --deploy-mode cluster --master yarn --num-executors 5 --executor-cores 5 --executor-memory 1g s3:/... | 0 | 2016-08-25T07:21:58Z | 39,194,277 | <p>And locate the error.</p>
<p>Boto3 module was not installed, install it from console, but the steps do not work, because they would have to install it in all instances. So what I did was create another claster running a boostrap-action update python I installed the module boto3</p>
| 0 | 2016-08-28T18:03:44Z | [
"python",
"hadoop",
"hive",
"pyspark",
"amazon-emr"
] |
Running simple python script consinuously on Heroku | 39,139,165 | <p>I have simple python script which I would like to host it on Heroku and run it every 10 minutes using Heroku scheduler. So can someone explain me what should I type on the rake command at the scheduler and how I should change the Procfile of Heroku?</p>
| 1 | 2016-08-25T07:27:57Z | 39,170,561 | <p>Sure, you need to do a few things:</p>
<ol>
<li><p>Define a <code>requirements.txt</code> file in the root of your project that lists your dependencies. This is what Heroku will use to 'detect' you're using a Python app.</p></li>
<li><p>In the Heroku scheduler addon, just define the command you need to run to launc... | 1 | 2016-08-26T16:13:16Z | [
"python",
"heroku"
] |
django authorization without using request.user.is_authenticated() | 39,139,248 | <p>I am working on django website and I am using django Auth for user authentication and for authorization of user i am using request.user.is_authenticated() code in django view but using this i have to write this code in each and every view, because in my site there is only homepage, registration page and login page w... | 0 | 2016-08-25T07:32:46Z | 39,139,290 | <p>Yes, just use the <a href="https://docs.djangoproject.com/en/1.10/topics/auth/default/#django.contrib.auth.decorators.login_required" rel="nofollow"><code>login_required</code></a> decorator or <a href="https://docs.djangoproject.com/en/1.10/topics/auth/default/#the-loginrequired-mixin" rel="nofollow"><code>LoginReq... | 0 | 2016-08-25T07:35:35Z | [
"python",
"django"
] |
django authorization without using request.user.is_authenticated() | 39,139,248 | <p>I am working on django website and I am using django Auth for user authentication and for authorization of user i am using request.user.is_authenticated() code in django view but using this i have to write this code in each and every view, because in my site there is only homepage, registration page and login page w... | 0 | 2016-08-25T07:32:46Z | 39,139,303 | <p>You can use <strong>@login_required</strong> instead. See <a href="https://docs.djangoproject.com/en/1.10/topics/auth/default/" rel="nofollow">here</a></p>
| 0 | 2016-08-25T07:36:13Z | [
"python",
"django"
] |
Read and write data to new file Python | 39,139,306 | <p>I have to write substrings to a new file by reading from another file. The problem I am facing is that it only writes the last found substring.
Here is what I've tried.</p>
<pre><code>def get_fasta(site):
with open('file1.txt', 'r') as myfile:
data=myfile.read()
site = site-1
str1 = data[s... | 0 | 2016-08-25T07:36:24Z | 39,139,386 | <p>That's because you've opened the inner file in <code>w</code> mode which recreates the file each time. So the end result is that only last write persists. You want to use <code>a</code> mode (which stands for "append").</p>
<p>Also there are some other issues with your code. For example you open and close both file... | 2 | 2016-08-25T07:41:02Z | [
"python",
"file"
] |
Python - How to create a folder with a user entered name? | 39,139,329 | <p>I have a python script which runs to take screenshots in a loop and save all those images. However currently, all images are stored in Python35 folder.</p>
<p>Therefore I want the user to enter a name for a folder and create one by this name.</p>
<p>I know to use makedirs function and specify a path by <code>newpa... | 0 | 2016-08-25T07:37:38Z | 39,139,537 | <p>If you mean building the path at which the file should be saved, use <a href="https://docs.python.org/2/library/os.path.html#os.path.join" rel="nofollow"><code>os.path.join</code></a> with the base directory first and the custom directory name second (the filename can be provided as a third argument). Just be very c... | 3 | 2016-08-25T07:49:19Z | [
"python",
"python-3.x",
"mkdir"
] |
How can I get this series to a pandas dataframe? | 39,139,359 | <p>I have some data and after using a groupby function I now have a series that looks like this:</p>
<pre><code>year
1997 15
1998 22
1999 24
2000 24
2001 28
2002 11
2003 15
2004 19
2005 10
2006 10
2007 21
2008 26
2009 23
2010 16
2011 33
2012 19
2013 26
2014 25
</co... | 2 | 2016-08-25T07:39:17Z | 39,139,408 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html" rel="nofollow"><code>reset_index</code></a> and <code>rename</code> columns:</p>
<pre><code>print (df.reset_index())
index year
0 1997 15
1 1998 22
2 1999 24
3 2000 24
4 2001... | 2 | 2016-08-25T07:42:13Z | [
"python",
"pandas",
"dataframe",
"multiple-columns",
"series"
] |
How can I get this series to a pandas dataframe? | 39,139,359 | <p>I have some data and after using a groupby function I now have a series that looks like this:</p>
<pre><code>year
1997 15
1998 22
1999 24
2000 24
2001 28
2002 11
2003 15
2004 19
2005 10
2006 10
2007 21
2008 26
2009 23
2010 16
2011 33
2012 19
2013 26
2014 25
</co... | 2 | 2016-08-25T07:39:17Z | 39,140,251 | <pre><code>s.rename('sightings').reset_index()
</code></pre>
<p><a href="http://i.stack.imgur.com/JaaFK.png" rel="nofollow"><img src="http://i.stack.imgur.com/JaaFK.png" alt="enter image description here"></a></p>
| 1 | 2016-08-25T08:27:27Z | [
"python",
"pandas",
"dataframe",
"multiple-columns",
"series"
] |
Waiting for condition without loop Python | 39,139,422 | <p>I just created a script which triggers a report from specific API and then loads it into my database.
I have already built something that works but I would like to know if there is something a bit more "precise" or efficient without the need of making my script loop over and over again.</p>
<p>My current script is... | 0 | 2016-08-25T07:42:44Z | 39,139,461 | <p>Rather use events, not polling. There are a lot of options for how to implement events in Python. There was a discussion <a href="http://stackoverflow.com/questions/1092531/event-system-in-python">here already on stack overflow</a>. </p>
<p>Here is a synthetic example uses zope.event and an event handler</p>
<pre>... | -3 | 2016-08-25T07:45:10Z | [
"python",
"while-loop",
"sleep"
] |
Waiting for condition without loop Python | 39,139,422 | <p>I just created a script which triggers a report from specific API and then loads it into my database.
I have already built something that works but I would like to know if there is something a bit more "precise" or efficient without the need of making my script loop over and over again.</p>
<p>My current script is... | 0 | 2016-08-25T07:42:44Z | 39,139,722 | <p>While this post doesn't hold any relevance anymore as you said, it' a soap API. But I put the work into it, so I'll post it anyway. :)</p>
<p>To answer your question. I don't see any more efficient methods than polling (aka. looping over and over again)</p>
<hr>
<p>There are multiple ways to do it.</p>
<p>The fi... | 0 | 2016-08-25T07:58:49Z | [
"python",
"while-loop",
"sleep"
] |
How to automatically call a text file with today's date in Python | 39,139,437 | <p>I have a text file that is generated everyday and is named in the following format: "year-month-date.txt" (e.g. 2016-08-25.txt).</p>
<p>Now I would like to open the text file with python and read some data from it. But I would like to do this without manually changing the name of text file inside the code everytime... | 0 | 2016-08-25T07:43:44Z | 39,139,489 | <p>You will have to extract a string in the correct format from <code>todays_date</code>. </p>
<p>Use <code>strftime</code> for that (see the <a href="https://docs.python.org/3.4/library/datetime.html#strftime-strptime-behavior" rel="nofollow">docs</a>):</p>
<pre><code>filename = todays_date.strftime('%Y-%m-%d') + '.... | 5 | 2016-08-25T07:47:01Z | [
"python",
"datetime",
"import",
"text-files"
] |
How to automatically call a text file with today's date in Python | 39,139,437 | <p>I have a text file that is generated everyday and is named in the following format: "year-month-date.txt" (e.g. 2016-08-25.txt).</p>
<p>Now I would like to open the text file with python and read some data from it. But I would like to do this without manually changing the name of text file inside the code everytime... | 0 | 2016-08-25T07:43:44Z | 39,139,491 | <p>filename should be a string, you are now trying to access the attribut .txt of todays date...</p>
<p>replace by:</p>
<pre><code>todays_date=datetime.date.today()
filename = str(todays_date)+'.txt'
</code></pre>
<p>Also make sure that todays_date exactly matches the name of the txt file, you may need to shuffle t... | 3 | 2016-08-25T07:47:12Z | [
"python",
"datetime",
"import",
"text-files"
] |
Plotting a heatmap of temperatures | 39,139,444 | <p>I have a matrix of which a smaller version looks like this</p>
<pre>
318.3 318.3 318.3
318.3 318.3 318.3
318.3 318.3 318.3
</pre>
<p>These are the temperatures of a grid of processors. I want to plot a heat map by assigning regular colors i.e. blue to cool and red to hot cores.</p>
<p>An example of wh... | -1 | 2016-08-25T07:44:12Z | 39,139,880 | <p>Looks like the <code>rainbow</code> palette could be used with <code>image</code></p>
<pre><code>m <- matrix(c(1, 1,1,1,1,1,1,
1,2,2,3,2,2,1,
1,2,3,4,3,2,1,
1,2,2,3,2,2,1,
1,1,1,1,1,1, 1), 5,7, byrow=TRUE)
image(m, col=rev(rainbow(100))[ 70:100]) # need to reverse it to have high values red.
</code></pre>
<p>(... | 2 | 2016-08-25T08:07:41Z | [
"python",
"plot",
"heatmap"
] |
How to use list comprehension with list of variable number of filenames? | 39,139,620 | <p>Given the list of filenames <code>filenames = [...]</code>.</p>
<p>Is it possibly rewrite the next list comprehension for I/O-safety: <code>[do_smth(open(filename, 'rb').read()) for filename in filenames]</code>? Using <code>with</code> statement, <code>.close</code> method or something else.</p>
<p>Another proble... | 4 | 2016-08-25T07:53:54Z | 39,139,727 | <p>You can put the <code>with</code> statement/block to a function and call that in the list comprehension:</p>
<pre><code>def slurp_file(filename):
with open(filename, 'rb') as f:
return f.read()
results = [do_smth(slurp_file(f)) for f in filenames]
</code></pre>
| 9 | 2016-08-25T07:58:57Z | [
"python",
"python-3.x",
"file-io",
"list-comprehension",
"contextmanager"
] |
How to use list comprehension with list of variable number of filenames? | 39,139,620 | <p>Given the list of filenames <code>filenames = [...]</code>.</p>
<p>Is it possibly rewrite the next list comprehension for I/O-safety: <code>[do_smth(open(filename, 'rb').read()) for filename in filenames]</code>? Using <code>with</code> statement, <code>.close</code> method or something else.</p>
<p>Another proble... | 4 | 2016-08-25T07:53:54Z | 39,140,026 | <p>You can use the <a href="https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack" rel="nofollow"><code>ExitStack</code></a> introduced in Python 3.3 for this purpose:</p>
<pre><code>with ExitStack() as stack:
files = [stack.enter_context(open(name, "rb")) for name in filenames]
results = [do_... | 3 | 2016-08-25T08:15:38Z | [
"python",
"python-3.x",
"file-io",
"list-comprehension",
"contextmanager"
] |
Adding tracks to a playlist in Spotify using Spotipy | 39,139,688 | <p>I'm using the Python bindings for the Spotify API to list an artists top tracks and add them to a playlist, but it fails every time, as if it excepts a different type of input.</p>
<p>New_Track_List is a string containing the output of the top tracks lookup as either:</p>
<h1>1: URIs:</h1>
<p>Example: "spotify:tr... | 1 | 2016-08-25T07:57:06Z | 39,153,639 | <p>This looks like a problem with duck typing in python and bad error message in the api. I guess that the api requires you to send a list and not a string, but doesn't actually check that. The problem is that a string is also iterable.</p>
<pre><code>>>> tracks = "spotify:track:1pAyyxlkPuGnENdj4g7Y4f, spotif... | 2 | 2016-08-25T19:50:04Z | [
"python",
"spotify",
"spotipy"
] |
Motion tracker using Raspberry pi 3, OpenCV and Python | 39,139,771 | <p>I have tried to change the parameters of variables.</p>
<h1>The error tells me "too many values to unpack".</h1>
<p>This code is written for OpenCV 2.0, however I am using <strong>OpenCV3.1.</strong>
Am I encountering a reverse compatibility issue here or is it something more trivial?</p>
<h1>Here is my error mes... | 3 | 2016-08-25T08:01:36Z | 39,141,625 | <p>The line
<code>contours, hierarchy = cv2.findContours(thresholdimage,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)</code>
is giving the error as cv2.findContours returns 3 values but you are assigning them to two variables.
So, correct code is
<code>-,contours, hierarchy = cv2.findContours(thresholdimage,cv2.RETR_EXTER... | 2 | 2016-08-25T09:34:06Z | [
"python",
"c++",
"opencv",
"computer-vision",
"raspberry-pi3"
] |
ImportError: no module named gravatar | 39,139,870 | <p>I am using Django1.10, when I process <code>python manage.py migrate</code>.</p>
<p>I get: </p>
<blockquote>
<p>ImportError: no module named gravatar.</p>
</blockquote>
<p>Before that, I have installed <strong>python2.7</strong> and run it in virtual environment, as well as <strong>django_gravatar</strong>. </p... | -1 | 2016-08-25T08:07:02Z | 39,139,931 | <p>You have to activate the virtual environment first. See this section of the <a href="https://virtualenv.pypa.io/en/stable/userguide/?highlight=activate#activate-script" rel="nofollow">docs</a>:</p>
<p>In a newly created virtualenv there will also be a activate shell script. For Windows systems, activation scripts a... | 0 | 2016-08-25T08:10:35Z | [
"python",
"django"
] |
Settin general defaults for named arguments in python | 39,139,935 | <p>I have the following problem:
I have to set some values for special entities (points, lines, faces, volumes, spheres,...), via an API into a database.</p>
<p>Some values are unique for every entity, others are always the same.
So my idea was to do something like (SetValues is the API command i have to use putting s... | 6 | 2016-08-25T08:10:48Z | 39,140,046 | <p>You can change default value for <code>Move</code> argument in your methods, by using <code>func_defaults</code> tuple, which holds values from kwargs:</p>
<pre><code># CreateLineEntity.func_defaults --> ('no', 0.0, 'yes')
defaults = list(CreateLineEntity.func_defaults)
# You're modyfying first one which is for... | 1 | 2016-08-25T08:17:16Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.