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 do I make an exe file from a python code under Ubuntu? | 38,627,071 | <p>I'm using Ubuntu 16 64-bit and python 3.5</p>
<p>I made a program on python and I want to distribute it as an EXE for Windows users.</p>
<p>The program I made depends on pandas and matplotlib</p>
<p>I downloaded PyInstaller.tar.gz and extracted it, but I can't find any clear info on how to make make an EXE.</p>
... | 0 | 2016-07-28T04:23:40Z | 38,627,995 | <p>Did you read the <a href="https://pythonhosted.org/PyInstaller/usage.html" rel="nofollow">pyinstaller Manual</a>?</p>
| 1 | 2016-07-28T05:49:08Z | [
"python",
"exe",
"pyinstaller"
] |
Not able to find file using ssh on another server using python pexpect on linux | 38,627,127 | <p>I created the simple python script using pexpect, created one spwan process using </p>
<pre><code> CurrentCommand = "ssh " + serverRootUserName + "@" + serverHostName
child = pexpect.spawn(CurrentCommand)
</code></pre>
<p>Now I am running some command like ls-a or "find /opt/license/ -name '*.xml'"
using code</... | 0 | 2016-07-28T04:30:07Z | 38,629,922 | <p>As a suggestion, have a look at the paramiko library (or fabric, which uses it, but has a specific purpose), as this is a python interface to ssh. It might make your code a bit better and more resilient against bugs or attacks. </p>
<p>However, I think the issue comes from your use of <code>run</code>. </p>
<block... | 0 | 2016-07-28T07:37:00Z | [
"python",
"python-2.7",
"ssh",
"terminal",
"pexpect"
] |
Trying to extract portion of csv to numpy array | 38,627,130 | <p>I've been at this problem for a few days and tried a couple of different approaches, but I can't seem to get it quite right. This is the a simplified version of my csv data file: testme.csv</p>
<pre><code> "Name", "City", "State", "1996-04", "1996-05", "1996-06", "1996-07"
"Bob", "Portland", "OR", 100000, 120... | 3 | 2016-07-28T04:30:10Z | 38,627,282 | <p>If -- and that's a big if (I kid) -- you can use <a href="http://pandas.pydata.org/" rel="nofollow">pandas</a>:</p>
<pre><code>from StringIO import StringIO
s = StringIO(''' "Name", "City", "State", "1996-04", "1996-05", "1996-06", "1996-07"
"Bob", "Portland", "OR", 100000, 120000, 140000, 1600... | 1 | 2016-07-28T04:45:25Z | [
"python",
"csv",
"numpy"
] |
Trying to extract portion of csv to numpy array | 38,627,130 | <p>I've been at this problem for a few days and tried a couple of different approaches, but I can't seem to get it quite right. This is the a simplified version of my csv data file: testme.csv</p>
<pre><code> "Name", "City", "State", "1996-04", "1996-05", "1996-06", "1996-07"
"Bob", "Portland", "OR", 100000, 120... | 3 | 2016-07-28T04:30:10Z | 38,627,409 | <p>You can use <strong>pandas</strong>, it has the options that you need.</p>
<p><a href="http://pandas.pydata.org/pandas-docs/version/0.18.1/10min.html#min" rel="nofollow">http://pandas.pydata.org/pandas-docs/version/0.18.1/10min.html#min</a></p>
| -1 | 2016-07-28T05:00:14Z | [
"python",
"csv",
"numpy"
] |
Trying to extract portion of csv to numpy array | 38,627,130 | <p>I've been at this problem for a few days and tried a couple of different approaches, but I can't seem to get it quite right. This is the a simplified version of my csv data file: testme.csv</p>
<pre><code> "Name", "City", "State", "1996-04", "1996-05", "1996-06", "1996-07"
"Bob", "Portland", "OR", 100000, 120... | 3 | 2016-07-28T04:30:10Z | 38,627,434 | <p>With your sample, <code>numpy</code> <code>genfromtxt</code> works:</p>
<pre><code>In [166]: np.genfromtxt('stack38627130.csv',names=True,delimiter=',',dtype=None)
Out[166]:
array([(b'"Bob"', b' "Portland"', b' "OR"', 100000, 120000, 140000, 160000),
(b'"Sally"', b' "Eugene"', b' "OR"', 50000, 75000, 80000... | 2 | 2016-07-28T05:02:07Z | [
"python",
"csv",
"numpy"
] |
Returning to the main menu in my game - Python | 38,627,140 | <p>I am creating a Rock, Paper, Scissors game. The game has a main menu which I need to be able to return to from each sub menu. I've tried a few different method I could think of as well as looked here and elsewhere online to determine a method of solving my problem.</p>
<p>I want the user to be able to select an opt... | 0 | 2016-07-28T04:31:19Z | 38,627,249 | <p>Do a try and except command. If they say no your code should be quit(). If they say yes put a continue command and it will restart the whole thing.</p>
| 0 | 2016-07-28T04:42:25Z | [
"python",
"menu"
] |
Returning to the main menu in my game - Python | 38,627,140 | <p>I am creating a Rock, Paper, Scissors game. The game has a main menu which I need to be able to return to from each sub menu. I've tried a few different method I could think of as well as looked here and elsewhere online to determine a method of solving my problem.</p>
<p>I want the user to be able to select an opt... | 0 | 2016-07-28T04:31:19Z | 38,627,481 | <p>You are using <code>player</code> variable for two works, instead of that you can use another variable to just check the condition and another to take user input.</p>
<p>Also you can check the condition like : <strong><em><code>if again in ["yes","y"]</code></em></strong></p>
<pre><code>def main():
menuSelect ... | 0 | 2016-07-28T05:05:52Z | [
"python",
"menu"
] |
Returning to the main menu in my game - Python | 38,627,140 | <p>I am creating a Rock, Paper, Scissors game. The game has a main menu which I need to be able to return to from each sub menu. I've tried a few different method I could think of as well as looked here and elsewhere online to determine a method of solving my problem.</p>
<p>I want the user to be able to select an opt... | 0 | 2016-07-28T04:31:19Z | 38,627,660 | <p>put your main method in a <code>while (True):</code> loop, and if option 4 is called, use <code>break</code> like this: </p>
<pre><code>elif menuSelect == 4:
break
</code></pre>
<p>add an indent to </p>
<pre><code>again = input("Would you like to play again? Yes or no\n")
again = again.lower()
if again =... | 0 | 2016-07-28T05:21:40Z | [
"python",
"menu"
] |
How to turn a txt file to csv | 38,627,161 | <p>I have a txt file that has 214 columns(with the data separated by spaces) and about half a million rows.</p>
<p>I want to convert txt to csv, and have used this code:</p>
<pre><code>import csv
txt_file = r"myfile.txt"
csv_file = r"myfile.csv"
in_txt = csv.reader(open(txt_file, "r"), delimiter = " ", quotechar=" ... | 0 | 2016-07-28T04:33:46Z | 38,627,234 | <p>You must set the delimiter of the <code>writer</code> to a comma.</p>
<pre><code>import csv
txt_file = r"myfile.txt"
csv_file = r"myfile.csv"
in_txt = csv.reader(open(txt_file, "r"), delimiter = " ", quotechar=" ")
out_csv = csv.writer(open(csv_file, 'w', newline='\n'),delimiter=',', quotechar=' ', quoting=csv.QU... | 1 | 2016-07-28T04:41:01Z | [
"python",
"csv"
] |
How to turn a txt file to csv | 38,627,161 | <p>I have a txt file that has 214 columns(with the data separated by spaces) and about half a million rows.</p>
<p>I want to convert txt to csv, and have used this code:</p>
<pre><code>import csv
txt_file = r"myfile.txt"
csv_file = r"myfile.csv"
in_txt = csv.reader(open(txt_file, "r"), delimiter = " ", quotechar=" ... | 0 | 2016-07-28T04:33:46Z | 38,627,250 | <p>You have to change </p>
<pre><code>out_csv = csv.writer(open(csv_file, 'w', newline='\n'),delimiter=' ', quotechar=' ', quoting=csv.QUOTE_MINIMAL)
</code></pre>
<p>to</p>
<pre><code>out_csv = csv.writer(open(csv_file, 'w', newline='\n'),delimiter=';', quotechar=' ', quoting=csv.QUOTE_MINIMAL)
</code></pre>
<p>si... | 0 | 2016-07-28T04:42:32Z | [
"python",
"csv"
] |
Docker Django 404 for web static files, but fine for admin static files | 38,627,393 | <p>please help me on this docker django configuration for serving static files. </p>
<p>my <code>Django</code> project running on <code>Docker</code> got some issues with delivering <code>static files</code>. </p>
<blockquote>
<p>All static files for <strong>admin view</strong> is loading fine, but static files for... | 0 | 2016-07-28T04:58:21Z | 38,627,667 | <p>As you have moved your project to another directory, there is a possibility that the path of your static directories are also different now. <code>Django in most scenarios use apache, nginx or some other web servers to serve static files</code>. One point to notice is that your static directory should be accessed pu... | 0 | 2016-07-28T05:22:20Z | [
"python",
"django",
"docker",
"dockerfile",
"docker-machine"
] |
Docker Django 404 for web static files, but fine for admin static files | 38,627,393 | <p>please help me on this docker django configuration for serving static files. </p>
<p>my <code>Django</code> project running on <code>Docker</code> got some issues with delivering <code>static files</code>. </p>
<blockquote>
<p>All static files for <strong>admin view</strong> is loading fine, but static files for... | 0 | 2016-07-28T04:58:21Z | 38,634,556 | <p>This was issue with the <strong><code>STATICFILES_DIRS</code></strong> configuration in the <strong><code>settings.py</code></strong> file.</p>
<blockquote>
<p>This setting defines the additional locations the <strong>staticfiles</strong> app will traverse if the <strong>FileSystemFinder</strong> finder is enable... | 0 | 2016-07-28T11:05:26Z | [
"python",
"django",
"docker",
"dockerfile",
"docker-machine"
] |
Python eve ?where query returns empty result | 38,627,492 | <p>I have a mongo collection called Case which has the following records:</p>
<pre><code>{
_updated: "Tue, 26 Jul 2016 10:47:34 GMT",
user_id: "ronaldo",
client: "webapp",
_links: {
self: {
href: "case/57972a253d73f156b5427ac3",
title: "case"
}
},
_create... | 1 | 2016-07-28T05:06:47Z | 38,628,142 | <p>It looks like your <code>user_id</code> can sometimes contain objectid-like strings. Try setting <code>query_objectid_as_string</code> in your resource settings. Quoting the <a href="http://python-eve.org/config" rel="nofollow">docs</a>:</p>
<blockquote>
<p>When [query_objectid_as_string is] enabled the Mongo par... | 1 | 2016-07-28T05:57:39Z | [
"python",
"mongodb",
"rest",
"eve"
] |
What does "== RESTART <path> ==" in the IDLE Shell mean? | 38,627,504 | <p>I have a simple script I wrote, and when trying to run it (F5) , I get this msg:</p>
<blockquote>
<p>================== RESTART: C:\Users\***\Desktop\tst.py ==================</p>
</blockquote>
<p>I restarted the shell, reopened the script, but still, the same msg appears.
I use python 3.5.1 and I tried to simpl... | 0 | 2016-07-28T05:07:34Z | 38,627,619 | <blockquote>
<p>I have a simple script I wrote, and when trying to run it (F5) </p>
</blockquote>
<p>That's the hotkey for IDLE to run a file. It is not ordering to do anything. It's a log statement to explicitly declare that your namespace is being cleared and the file is going to be ran fresh again. </p>
<blockqu... | 1 | 2016-07-28T05:18:19Z | [
"python",
"python-idle"
] |
What does "== RESTART <path> ==" in the IDLE Shell mean? | 38,627,504 | <p>I have a simple script I wrote, and when trying to run it (F5) , I get this msg:</p>
<blockquote>
<p>================== RESTART: C:\Users\***\Desktop\tst.py ==================</p>
</blockquote>
<p>I restarted the shell, reopened the script, but still, the same msg appears.
I use python 3.5.1 and I tried to simpl... | 0 | 2016-07-28T05:07:34Z | 38,867,924 | <p>The same thing is happening with my shell. In the older versions, this does not happen. I've also noticed that when I press Python 3.5.2 Module Docs, I have my Internet browser open up and I see my directory being displayed onscreen. It looks like:</p>
<p>C:\Users\mycomputername\AppData\Local\Programs\Python\Python... | 0 | 2016-08-10T08:23:51Z | [
"python",
"python-idle"
] |
How to open .fif file format? | 38,627,520 | <p>I want to open a .fif file of size around 800MB. I googled and found that these kind of files can be opened with photoshop. Is there a way to extract the images and store in some other standard format using python or c++. </p>
| -2 | 2016-07-28T05:09:07Z | 38,628,604 | <p>FIF stands for Fractal Image Format and seems to be output of the Genuine Fractals Plugin for Adobe's Photoshop. Unfortunately, there is no format specification available and the plugin claims to use patented algorithms so you won't be able to read these files from within your own software.</p>
<p>There however are... | 0 | 2016-07-28T06:28:25Z | [
"python",
"c++",
"file-io"
] |
Optimization on Python list comprehension | 38,627,620 | <pre><code>[getattr(x, contact_field_map[communication_type])
for x in curr_role_group.contacts if
getattr(x, contact_field_map[communication_type])]
</code></pre>
<p>The above is my list comprehension. The initial function and the filter clause call getattr twic... | 0 | 2016-07-28T05:18:20Z | 38,627,661 | <p>Python will run the <code>getattr</code> twice -- It doesn't do any optimization (after all, how does it know that the first attribute fetch doesn't change the value of the second one?)</p>
<p>To optimize the query, you can do it in 2 stages. The first stage computes the values using a generator expression, the se... | 3 | 2016-07-28T05:21:43Z | [
"python"
] |
Optimization on Python list comprehension | 38,627,620 | <pre><code>[getattr(x, contact_field_map[communication_type])
for x in curr_role_group.contacts if
getattr(x, contact_field_map[communication_type])]
</code></pre>
<p>The above is my list comprehension. The initial function and the filter clause call getattr twic... | 0 | 2016-07-28T05:18:20Z | 38,627,709 | <p>Give this a try:</p>
<pre><code>[res for x in curr_role_group.contacts
for res in [getattr(x, contact_field_map[communication_type])] if res]
</code></pre>
<p>For example, instead of</p>
<pre><code>[i**2 for i in range(10) if i**2 < 10]
Out: [0, 1, 4, 9]
</code></pre>
<p>You can do</p>
<pre><code>[res ... | 1 | 2016-07-28T05:25:38Z | [
"python"
] |
Optimization on Python list comprehension | 38,627,620 | <pre><code>[getattr(x, contact_field_map[communication_type])
for x in curr_role_group.contacts if
getattr(x, contact_field_map[communication_type])]
</code></pre>
<p>The above is my list comprehension. The initial function and the filter clause call getattr twic... | 0 | 2016-07-28T05:18:20Z | 38,627,770 | <p>Could you use a generator for the entire thing? Something like:</p>
<pre><code>def gen():
for x in curr_role_group.contacts:
value = getattr(x, contact_field_map[communication_type])
if value:
yield value
result = list(gen())
</code></pre>
| 0 | 2016-07-28T05:31:12Z | [
"python"
] |
How to avoid circular reference in python - a class member creating an object of another class and passing self as parameter? | 38,627,644 | <p>I need some help in terms of 'pythonic' way of handling a specific scenario.</p>
<p>I'm writing an Ssh class (wraps paramiko) that provides the capability to connect to and executes commands on a device under test (DUT) over ssh. </p>
<pre><code>class Ssh:
def connect(some_params):
# establishes connec... | 0 | 2016-07-28T05:20:16Z | 38,628,077 | <p>In general, circular references aren't a bad thing. Many programs will have them, and people just don't notice because there's another instance in-between like <code>A->B->C->A</code>. Python's garbage collector will properly take care of such constructs (unless you <strike>use</strike> implement <code>__de... | 0 | 2016-07-28T05:54:19Z | [
"python",
"python-2.7",
"python-3.x",
"design-patterns",
"design"
] |
PLY/YACC parsing conflicts on PDF | 38,627,699 | <p>I'm trying to parse PDFs with PLY lex/yacc, and Ive hit a snag regarding yacc parsing rule that govern <code>NUMBER</code> tokens, arrays, and indirect_references. </p>
<p>The relevant source:</p>
<pre><code>def p_value_list(t):
r'''value_list : value_list value
| value'''
if t.slice[0] == '... | 1 | 2016-07-28T05:25:17Z | 38,629,038 | <p>It's not really an ambiguity; the grammar is perfectly unambiguous. However, it is not LR(1), and an LR(1) parser cannot figure out whether to shift or reduce an integer if it is followed by another integer. (The grammar is LR(2) since the second-next token is sufficient to decide; if it is <code>R</code>, the integ... | 1 | 2016-07-28T06:52:15Z | [
"python",
"pdf",
"yacc",
"ply"
] |
Pythonic way to check if a set in list is present in a different set | 38,627,760 | <p>I have a list of sets</p>
<pre><code>lst = [s1, s2, s3]
</code></pre>
<p>where </p>
<pre><code>s1 = set([1, 2, 3])
s2 = set([2, 3, 4])
s3 = set([2, 4, 6])
</code></pre>
<p>and I have another set</p>
<pre><code>set1 = set([1, 2, 3, 5])
</code></pre>
<p>So when I do <code>lst - set1</code> I should get <code>se... | -2 | 2016-07-28T05:30:09Z | 38,627,799 | <p>You can use the <code>in</code> operator. It works with any array-like container including lists, tuples, sets and dictionary keys.</p>
<pre><code>set_list = [set(1, 2, 3), set(2, 3, 4), set(2, 4, 6)]
# returns True
set([1,2,3]) in set_list
# returns False
set([5, 6, 7]) in set_list
# returns False, just to show... | 1 | 2016-07-28T05:33:28Z | [
"python",
"set"
] |
Pythonic way to check if a set in list is present in a different set | 38,627,760 | <p>I have a list of sets</p>
<pre><code>lst = [s1, s2, s3]
</code></pre>
<p>where </p>
<pre><code>s1 = set([1, 2, 3])
s2 = set([2, 3, 4])
s3 = set([2, 4, 6])
</code></pre>
<p>and I have another set</p>
<pre><code>set1 = set([1, 2, 3, 5])
</code></pre>
<p>So when I do <code>lst - set1</code> I should get <code>se... | -2 | 2016-07-28T05:30:09Z | 38,627,938 | <p>To get a list of differences between sets you could use a <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk" rel="nofollow">list comprehension</a>.</p>
<pre><code>my_set = set([1, 2, 3, 5])
set_list = [
set([1, 2, 3]),
set([2, 3, 4]),
set([2, 4, 6]),
]
# find differences between set... | 0 | 2016-07-28T05:44:31Z | [
"python",
"set"
] |
Matrix Multiplication TypeError | 38,627,780 | <p>I'm attempting to write a backpropagation algorithm and I'm encountering an error when attempting to perform a matrix multiplication. </p>
<p>I've created the following simple example to work with</p>
<pre><code># necessary functions for this example
def sigmoid(z):
return 1.0/(1.0+np.exp(-z))
def prime(z):
... | 0 | 2016-07-28T05:31:32Z | 38,627,927 | <p>There is a misplaced parenthesis on your last line. It should be</p>
<pre><code>print(np.dot(np.transpose(weights[-1]), delta))
</code></pre>
<p>instead of</p>
<pre><code>print(np.dot(np.transpose(weights[-1])), delta)
</code></pre>
| 2 | 2016-07-28T05:43:34Z | [
"python",
"numpy",
"matrix"
] |
How should I configure BitBake to cross compile my python module? | 38,627,785 | <p>I have inherited an Open Embedded / Yocto based project for which I need to amend the OS image. I would like to add a new python module - pycrypto. The project builds just fine before I make changes.</p>
<p>I have added the following BitBake recipe for pycrypto:</p>
<pre><code>DESCRIPTION = "Python crypto"
S... | 0 | 2016-07-28T05:32:35Z | 38,631,531 | <p>layers.openembedded.org is your friend: <a href="http://git.yoctoproject.org/cgit/cgit.cgi/meta-security/tree/recipes-devtools/python/python-pycrypto_2.6.1.bb?h=master" rel="nofollow">http://git.yoctoproject.org/cgit/cgit.cgi/meta-security/tree/recipes-devtools/python/python-pycrypto_2.6.1.bb?h=master</a></p>
<p>Th... | 1 | 2016-07-28T08:55:08Z | [
"python",
"cross-compiling",
"distutils",
"bitbake",
"openembedded"
] |
How do I programmatically send encrypted emails in Outlook Express using Python? | 38,627,812 | <p>I'm a new programmer and I've reached the point where my lack of knowledge (of the C# and VBA language) and experience is preventing me from continuing with my program. I only know Python and all the documentation that I've tried digging into is in C# and VB.</p>
<p>My story: I'm working on a GUI that automates and... | 0 | 2016-07-28T05:34:09Z | 38,664,367 | <ol>
<li><p>First you need a Secure Email certificate issued to the email address you want to use.
Lets say thisis mymail.somecompany.com. Your cert should have this in the subject name
and should be enabled for secure email. </p></li>
<li><p>Next you need to programatically get the certificate or load from a pfx fil... | 0 | 2016-07-29T17:26:33Z | [
"c#",
"python",
"email",
"encryption",
"outlook"
] |
Python : How to read all files in the directory with some specific condition? | 38,627,853 | <p>I want to read all the files in one directory. Directory contains following files: </p>
<pre><code>ABC11_1.csv
ABC11_3.csv
ABC11_2.csv
ABC13_4.csv
ABC13_1.csv
ABC17_6.csv
ABC17_2.csv
ABC17_4.csv
ABC17_8.csv
</code></pre>
<p>When I'm running my script I want to give this file name on the console in the format as : ... | 0 | 2016-07-28T05:37:21Z | 38,629,227 | <p>According to your question, following pseudo code should work</p>
<pre><code>import os
# Read all files from a directory, and read your input argument
files = os.listdir("your_input_directory_path")
input_argument = "ABC11"
# Sort file names by name
files = sorted(files)
relevant_files = []
for file_name in fi... | 0 | 2016-07-28T07:02:39Z | [
"python",
"file",
"directory",
"glob"
] |
Sort within a group and add a columns indicating rows below and above | 38,627,854 | <p>I have a pandas dataframe that contains something like</p>
<p><code>+------+--------+-----+-------+
| Team | Gender | Age | Name |
+------+--------+-----+-------+
| A | M | 22 | Sam |
| A | F | 25 | Annie |
| B | M | 33 | Fred |
| B | M | 18 | James |
| A | M | 56 | ... | 2 | 2016-07-28T05:37:21Z | 38,631,348 | <pre><code>import pandas as pd
df = pd.DataFrame({'Team':['A','A','B','B','A','B','A'], 'Gender':['M','F','M','M','M','F','M'],
'Age':[22,25,33,18,56,28,33], 'Name':['Sam','Annie','Fred','James','Alan','Julie','Greg']}).sort_values(['Team','Age'])
for idx, data in df.groupby(['Team'], as_index=False):
... | 2 | 2016-07-28T08:46:52Z | [
"python",
"pandas",
"dataframe"
] |
Sort within a group and add a columns indicating rows below and above | 38,627,854 | <p>I have a pandas dataframe that contains something like</p>
<p><code>+------+--------+-----+-------+
| Team | Gender | Age | Name |
+------+--------+-----+-------+
| A | M | 22 | Sam |
| A | F | 25 | Annie |
| B | M | 33 | Fred |
| B | M | 18 | James |
| A | M | 56 | ... | 2 | 2016-07-28T05:37:21Z | 38,631,403 | <p>You can apply custom function <code>f</code> with <code>groupby</code> by column <code>Team</code>.</p>
<p>In function <code>f</code> for each row first filter above and below values by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.ix.html" rel="nofollow"><code>ix</code></a>, then ... | 1 | 2016-07-28T08:49:27Z | [
"python",
"pandas",
"dataframe"
] |
How to paste a PNG image with transparency to another image in PIL without white pixels? | 38,627,870 | <p>I have two images, a background and a PNG image with transparent pixels. I am trying to paste the PNG onto the background using Python-PIL but when I paste the two images I get white pixels around the PNG image where there were transparent pixels. </p>
<p>My code: </p>
<pre><code>import os
from PIL import Image,... | 0 | 2016-07-28T05:38:25Z | 38,629,258 | <p>You just need to specify the image as the mask as follows in the paste function:</p>
<pre><code>import os
from PIL import Image, ImageDraw, ImageFont
filename='pikachu.png'
ironman = Image.open(filename, 'r')
filename1='bg.png'
bg = Image.open(filename1, 'r')
text_img = Image.new('RGBA', (600,320), (0, 0, 0, 0))
t... | 3 | 2016-07-28T07:05:00Z | [
"python",
"python-imaging-library"
] |
Add elements of two list of dictionaries based on a key value pair match | 38,627,930 | <p>Given n lists with m dictionaries as their elements, I would like to produce a new list, with a joined set of dictionaries.</p>
<pre><code>l1 = [{"index":'a', "b":2,'c':9}, {"index":'b', "b":3,"c":5}, {"index":'c', "b":8,"c":8}]
l2 = [{"index":'a', "b":4,'c':8}, {"index":'b', "b":9,"c":10},{"index":None, "b":11,"c"... | 0 | 2016-07-28T05:43:44Z | 38,628,039 | <p>You can use a <code>Counter</code> for something like this pretty easily...</p>
<pre><code>from collections import defaultdict, Counter
def merge_lists(l1, l2):
d = defaultdict(Counter)
for sdict in l1 + l2:
counter = Counter(sdict)
d[counter.pop('index')] += counter
lists = []
... | 4 | 2016-07-28T05:51:45Z | [
"python",
"list"
] |
How can I turn dataframe rows into headers? | 38,627,981 | <p>I have some data on each of the first 151 pokemon in 151 different dataframes.</p>
<pre><code> id identifier pokemon_id stat_id base_stat local_language_id name
36 7 Squirtle 7 1 44 9 HP
37 7 Squirtle 7 2 48 9 Attack
38 7 Squirtle 7 3 65 9 Defense
39 7 Squirtle ... | 1 | 2016-07-28T05:47:56Z | 38,628,068 | <p>I believe this will do what you're after:</p>
<pre><code>df.groupby(['id', 'identifier', 'name']).base_stat.first().unstack('name')
</code></pre>
| 4 | 2016-07-28T05:53:47Z | [
"python",
"pandas"
] |
How can I turn dataframe rows into headers? | 38,627,981 | <p>I have some data on each of the first 151 pokemon in 151 different dataframes.</p>
<pre><code> id identifier pokemon_id stat_id base_stat local_language_id name
36 7 Squirtle 7 1 44 9 HP
37 7 Squirtle 7 2 48 9 Attack
38 7 Squirtle 7 3 65 9 Defense
39 7 Squirtle ... | 1 | 2016-07-28T05:47:56Z | 38,628,185 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html" rel="nofollow"><code>pivot_table</code></a>:</p>
<pre><code>df = df.pivot_table(index=['id','identifier'],
columns='name',
values='base_stat',
aggfunc='f... | 1 | 2016-07-28T06:00:07Z | [
"python",
"pandas"
] |
How to update a dictionary in python with another dictionary to a specific key | 38,628,054 | <p>I have two dictionaries in python, one contains three keys and one with one key. One of the key is common to both of the dictioaries but have different data within the key. I want to update that one key to the dictionary with the three keys. The one key have to replace the existing key from the other dictionary. I d... | -1 | 2016-07-28T05:52:44Z | 38,628,301 | <p>This is the reply from smarx:</p>
<p>"@SpeedDemo Looks like the issue is that the second dictionary has '34512340' as a key (a string), and the first dictionary has 34512340 as a key (an int). If you make them both the same type, dict.update should work fine for you. â smarx 3 mins ago"</p>
<p>Thank you it worke... | 1 | 2016-07-28T06:07:42Z | [
"python",
"dictionary"
] |
load CSV into MySQL table with ODO python package - date error 1292 | 38,628,135 | <p>I'm trying to import a simple CSV file that I downloaded from Quandl into a MySQL table with the odo python package</p>
<pre><code>t = odo('C:\ProgramData\MySQL\MySQL Server 5.6\Uploads\WIKI_20160725.partial.csv', 'mysql+pymysql://' + self._sql._user+':'
+ self._sql._password +'@localhost/testDB::QUANDL... | 0 | 2016-07-28T05:57:17Z | 38,967,298 | <p>mysql has problems with date conversions. I noticed when I defined the date field as a varchar </p>
<pre><code>Date varchar(255) NOT NULL
</code></pre>
<p>then the csv file was read properly</p>
<p>in my SQL the conversion of the string to date format then looks like this: </p>
<pre><code>STR_TO_DATE(Date, "%m/%... | 0 | 2016-08-16T05:36:28Z | [
"python",
"mysql",
"csv",
"sqlalchemy",
"odo"
] |
Regular expression to find the http:// link out of the provided google search results link | 38,628,165 | <p>I have</p>
<pre><code>/url?q=http://dl.mytehranmusic.com/1392/Poya/New/1392/7/8/1/&sa=U&ved=0ahUKEwjIhcufvJXOAhWKrY8KHWjQBgQQFggTMAA&usg=AFQjCNF4phMtVM1Gmm1_kTpNOM6CXO0wIw
/url?q=http://mp3lees.org/index.php%3Fq%3DSia%2B-%2BElastic%2BHeart%2B(Feat.%2BThe%2BWeeknd%2B%2B%2BDiplo)&sa=U&ved=0ahUKEw... | -5 | 2016-07-28T05:59:08Z | 38,629,034 | <p>You do not really need a regex to parse query strings. Use <code>urlparse</code>:</p>
<pre><code>import urlparse
s = '/url?q=http://dl.mytehranmusic.com/1392/Poya/New/1392/7/8/1/&sa=U&ved=0ahUKEwjIhcufvJXOAhWKrY8KHWjQBgQQFggTMAA&usg=AFQjCNF4phMtVM1Gmm1_kTpNOM6CXO0wIw'
res = urlparse.parse_qs(urlparse.ur... | 0 | 2016-07-28T06:51:57Z | [
"python",
"regex"
] |
Return a string outside of a class or function with Python | 38,628,210 | <p>I'm new to OOP and am trying to figure out how to get the result of something outside of a class in order to decide what to do next in my program. </p>
<p>I'm unzipping a file, and if it takes too long then I want the process to terminate. This code will do just that:</p>
<pre><code>class Command(object):
def ... | 0 | 2016-07-28T06:01:35Z | 38,628,741 | <p>This line <code>self.tmp = self.proc.stdout.read()</code> puts some data into a member variable. You can then use it outside of the class by simple using a reference to the object:</p>
<pre><code>...
command.run(timeout = 300)
print(command.tmp)
</code></pre>
| 1 | 2016-07-28T06:35:59Z | [
"python"
] |
Return a string outside of a class or function with Python | 38,628,210 | <p>I'm new to OOP and am trying to figure out how to get the result of something outside of a class in order to decide what to do next in my program. </p>
<p>I'm unzipping a file, and if it takes too long then I want the process to terminate. This code will do just that:</p>
<pre><code>class Command(object):
def ... | 0 | 2016-07-28T06:01:35Z | 38,629,142 | <p>Your problem seems to be that the identifier <code>self</code> is not defined in function <code>unzip_file</code>. Try replacing </p>
<pre><code>print(self.tmp) #print the command line output (doesn't work)
</code></pre>
<p>with </p>
<pre><code>print(command.tmp)
</code></pre>
<p>Identifier <code>self</cod... | 1 | 2016-07-28T06:57:30Z | [
"python"
] |
string mismatch in Python even if they have same value | 38,628,222 | <p>Instead of keeping keys in my application I intent to read the keys from local file system into a variable (array of strings) and use those array elements in my oAuth APIs. However, when i used keys (in plaintext) as argument to OAuth APIs, authentication succeeds. BUT authentication failed when same value in read i... | 0 | 2016-07-28T06:02:25Z | 38,628,457 | <p>You should <a href="https://docs.python.org/3.4/library/stdtypes.html#str.strip" rel="nofollow"><code>strip</code></a> the key that you read from the file, as it has a trailing <code>\n</code>:</p>
<pre><code>print(secret_keys[0].strip() == "jFOMZ0bI60fDAEKw53lYCj2r4")
</code></pre>
<p>Or do it when reading it:</p... | 1 | 2016-07-28T06:19:22Z | [
"python",
"string",
"python-2.7",
"comparison"
] |
string mismatch in Python even if they have same value | 38,628,222 | <p>Instead of keeping keys in my application I intent to read the keys from local file system into a variable (array of strings) and use those array elements in my oAuth APIs. However, when i used keys (in plaintext) as argument to OAuth APIs, authentication succeeds. BUT authentication failed when same value in read i... | 0 | 2016-07-28T06:02:25Z | 38,628,458 | <p>If leading-trailing characters are bugging you, remove them with slicing, i.e <code>[1:-1]</code> to remove first-last quotations.</p>
<p>I also refactored your function a bit:</p>
<pre><code>def keys_io():
with open('.keys', 'r+') as f:
for line in f:
secret_keys.append(line.split('=')[1].... | 1 | 2016-07-28T06:19:24Z | [
"python",
"string",
"python-2.7",
"comparison"
] |
string mismatch in Python even if they have same value | 38,628,222 | <p>Instead of keeping keys in my application I intent to read the keys from local file system into a variable (array of strings) and use those array elements in my oAuth APIs. However, when i used keys (in plaintext) as argument to OAuth APIs, authentication succeeds. BUT authentication failed when same value in read i... | 0 | 2016-07-28T06:02:25Z | 38,629,009 | <p>When you read a text file from Python, you need to escape the new line character first. Another problem is you have single quote in between the input text. So you need to make change to:</p>
<pre><code>secret_keys.append(key_file.readline().strip().split("=")[1])
</code></pre>
<p>and</p>
<pre><code>if(secret_keys... | 0 | 2016-07-28T06:51:04Z | [
"python",
"string",
"python-2.7",
"comparison"
] |
Python, how to move dict under itself with a new attribute? Eg dict['key'] = dict | 38,628,290 | <p>I have an array of very large dictionaries, and need to put each dict itself under a new key. </p>
<p>I know <code>dict['key'] = dict</code> won't work and will result a recursive dict in python. Currently, I'm doing something like:</p>
<pre><code>new_dict['key'] = old_dict
</code></pre>
<p>and it will waste memo... | 0 | 2016-07-28T06:07:09Z | 38,628,318 | <p>A <code>dict</code> <em>can</em> hold a reference to itself:</p>
<pre><code>>>> d = {'foo': 'bar'}
>>> d['self'] = d
>>> d
{'self': {...}, 'foo': 'bar'}
>>> d['self']['self']['self']['self']['foo']
'bar'
</code></pre>
<p>Of course, there are <em>some</em> things that you can't d... | 3 | 2016-07-28T06:09:01Z | [
"python",
"dictionary"
] |
Python, how to move dict under itself with a new attribute? Eg dict['key'] = dict | 38,628,290 | <p>I have an array of very large dictionaries, and need to put each dict itself under a new key. </p>
<p>I know <code>dict['key'] = dict</code> won't work and will result a recursive dict in python. Currently, I'm doing something like:</p>
<pre><code>new_dict['key'] = old_dict
</code></pre>
<p>and it will waste memo... | 0 | 2016-07-28T06:07:09Z | 38,628,367 | <p>Adding a small bit to mgilson's answer:</p>
<pre><code>new_dict['key'] = old_dict
</code></pre>
<p>will not be a waste of memory. This assignment operator only assigns <em>a reference</em> to old_dict. Elements from old_dict aren't copied.</p>
<p>But regardless of how you do it - directly or via a different varia... | 2 | 2016-07-28T06:13:03Z | [
"python",
"dictionary"
] |
Python - Calculating frequency of products with respect to given query | 38,628,446 | <p>Suppose we are given 100 rows in a DataFrame with two columns. One is <code>QUERY</code> and other is <code>PRODUCT</code>. Both <code>QUERY</code> values and <code>PRODUCT</code> values can be repeating. like</p>
<pre><code>Sr.No QUERY PRODUCT
1 mobile samsung
2 mobile sony
3 mobile ... | 1 | 2016-07-28T06:18:19Z | 38,628,510 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.transform.html" rel="nofollow"><code>transform</code></a>:</p>
<pre><code>df['FREQUENCY'] = df.groupby(['QUERY', 'PRODUCT'])['PRODUCT'].transform('size')
print (df)
RangeIndex(start=0, stop=5, step=1)
Sr.No QUERY PR... | 0 | 2016-07-28T06:22:28Z | [
"python",
"pandas"
] |
Python - Selecting Specific Results to Place in Excel | 38,628,499 | <p>EDIT: I'm making a lot of head way, I am now trying to parse out single columns from my JSON file, not the entire row. I am getting an error however whenever I try to manipulate my DataFrame to get the results I want.</p>
<p>The error is:
line 52, in
df = pd.DataFrame.from_dict(mlbJson['stats_sortable_player']['q... | 0 | 2016-07-28T06:21:51Z | 38,629,173 | <p>It looks like the website loads the data asynchronously through another request to a different URL. The response you're getting has empty <code><datagrid><\datagrid></code> tag, and <code>soup2.select_one("#datagrid").find_next("table")</code> returns <code>None</code>.</p>
<p>You can use the developer ... | 0 | 2016-07-28T06:59:05Z | [
"python",
"json",
"excel",
"pandas",
"beautifulsoup"
] |
OpenCV exception after 1 day calculation | 38,628,504 | <p>I am using opencv_traincascade for object detection. I try to find glasses on photo. For this, I've downloaded 830 pictures like this:
<a href="http://pi1.lmcdn.ru/product/V/I/VI060DWIHZ27_1_v2.jpg">http://pi1.lmcdn.ru/product/V/I/VI060DWIHZ27_1_v2.jpg</a></p>
<p>Then I've downloaded many pictures with model in dr... | 9 | 2016-07-28T06:22:13Z | 38,777,673 | <p>That's a pretty common error. There is not much I know about this error and I can only guess a solution, since there are a lot of possible reasons for that error.</p>
<p>It could be relative to the directories structure (just notice that the path for negative examples should be relative to the current directory) </... | 3 | 2016-08-04T21:27:41Z | [
"python",
"algorithm",
"opencv"
] |
OpenCV exception after 1 day calculation | 38,628,504 | <p>I am using opencv_traincascade for object detection. I try to find glasses on photo. For this, I've downloaded 830 pictures like this:
<a href="http://pi1.lmcdn.ru/product/V/I/VI060DWIHZ27_1_v2.jpg">http://pi1.lmcdn.ru/product/V/I/VI060DWIHZ27_1_v2.jpg</a></p>
<p>Then I've downloaded many pictures with model in dr... | 9 | 2016-07-28T06:22:13Z | 38,802,845 | <p>If you look at the error you'll find that it stopped at 'NEG count' which means there was an issue with reading the negative training data set images at stage-5. So you need to fix the path to the negative training samples for it to work.</p>
<p>Here is a detailed discussion on this issue which might be helpful: <... | 3 | 2016-08-06T09:43:57Z | [
"python",
"algorithm",
"opencv"
] |
How can I GROUP BY "identical" strings of different lengths? | 38,628,620 | <p>I have a database of hymn instances as they appear in various hymnbooks.
The table is set up roughly like this:</p>
<pre><code>CREATE TABLE `Hymns` (
`HymnID` int(11) unsigned NOT NULL AUTO_INCREMENT,
`HymnbookID` int(11) DEFAULT NULL,
`HyNumber` int(11) DEFAULT NULL,
`HyName` varchar(255) COLLATE utf8mb4_u... | 0 | 2016-07-28T06:29:00Z | 38,629,116 | <p><strong>EDIT</strong>: This is for MSSQL, not mySQL. My apologies. Hope the reference below could help you though.</p>
<p>Not tested but you'd probably need a stored procedure with something like this:</p>
<pre><code>DECLARE @HyFirstLine varchar(255);
DECLARE @StoredHyFirstLine varchar(255);
DECLARE @OutputTable ... | 0 | 2016-07-28T06:56:05Z | [
"python",
"mysql",
"group-by"
] |
How to save files to database in django | 38,628,770 | <p>I am trying to upload files using django forms and save those files in the database itself.
I have been able to save the link of the file in database and save the file itself in a directory which i specified in Media_root.Can you please help me and tell me what can i change in my code so that files are saved in the ... | 0 | 2016-07-28T06:37:39Z | 38,629,040 | <p>Django provides <a href="https://docs.djangoproject.com/en/1.9/ref/models/fields/#binaryfield" rel="nofollow">BinaryField</a> that lets you store any binary data, including file contents. </p>
<p>Please do note that the documentation also says:</p>
<blockquote>
<p>Although you might think about storing files in ... | 3 | 2016-07-28T06:52:21Z | [
"python",
"django"
] |
Django- Jquery loops through all options | 38,628,873 | <p>Im doing server side rendering with the help of Django. In my django templates Im looping through all the values obtained from my Database. In jquery while selecting a single value, JS gives me all the values obtained from database, but I wanted only selected values</p>
<p>Views.py</p>
<pre><code>def theme(request... | 2 | 2016-07-28T06:43:38Z | 38,629,251 | <p>First of all, id of each HTML element should be unique. And you are creating multiple <code>li</code> and <code>span</code> elements with the same id. Make sure it's unique to prevent undesired bugs. it's better to use class and data attributes if needed.</p>
<p>Second, you need to get text of selected element, not... | 1 | 2016-07-28T07:04:41Z | [
"javascript",
"jquery",
"python",
"django",
"django-templates"
] |
Django- Jquery loops through all options | 38,628,873 | <p>Im doing server side rendering with the help of Django. In my django templates Im looping through all the values obtained from my Database. In jquery while selecting a single value, JS gives me all the values obtained from database, but I wanted only selected values</p>
<p>Views.py</p>
<pre><code>def theme(request... | 2 | 2016-07-28T06:43:38Z | 38,629,417 | <p>In your template, you're giving every <code><span></code> element the same identifier (<em>item_cat_name</em>). Your second jQuery selector selects all <code><span></code> elements with that identifier.</p>
<p>To resolve this, change your jQuery to something like:</p>
<pre><code>$('li').on('click', fun... | 1 | 2016-07-28T07:12:30Z | [
"javascript",
"jquery",
"python",
"django",
"django-templates"
] |
Merging dataframes by date range & repeating a categorical column in python | 38,628,924 | <p>I have two dataframes:</p>
<p>df1 :</p>
<pre><code>Time A B
1469510289000 1.5 2.4
1469510290000 2.5 7.1
1469510291000 2.2 6.4
1469510292000 1.4 2.3
1469510293000 1.6 1.8
1469510294000 2.2 4.1
1469510295000 1.2 0.6
</code></pre>
<p>and so on...</p>
<p>df2:</p>
<pre><code>start ... | 0 | 2016-07-28T06:46:24Z | 38,630,288 | <p>Not sure what do you mean "object" but .. I think if you mean that the category is in string type, you can convert those data frame into list, in a list the string part will automatically become this form --> 'string', and append the category label to the corresponding list , probably may get you what you want.</p>
... | 1 | 2016-07-28T07:54:58Z | [
"python",
"python-2.7"
] |
Merging dataframes by date range & repeating a categorical column in python | 38,628,924 | <p>I have two dataframes:</p>
<p>df1 :</p>
<pre><code>Time A B
1469510289000 1.5 2.4
1469510290000 2.5 7.1
1469510291000 2.2 6.4
1469510292000 1.4 2.3
1469510293000 1.6 1.8
1469510294000 2.2 4.1
1469510295000 1.2 0.6
</code></pre>
<p>and so on...</p>
<p>df2:</p>
<pre><code>start ... | 0 | 2016-07-28T06:46:24Z | 38,668,708 | <p>Will this help you ?</p>
<pre><code>list = []
for time in df1['Time']:
category = None
count=-1
for start,end in zip(df2['start'],df2['end']):
count += 1
if ( time>=start and time <= end):
break
if count != -1:
category = df2.ix[count]['Category']
... | 0 | 2016-07-29T23:11:46Z | [
"python",
"python-2.7"
] |
finding number of root determined interval | 38,628,952 | <p>I have n degree polynomial system ,just I want to learn number of root between previously determined interval .But I do not want to find root.I need number of root.I need to write python code.
For example :
x^8+2x^6+5x^4+x^2+45x+1=0
How many root have we between 3-5?
emphasize=I do not want to find root,just I want ... | -1 | 2016-07-28T06:47:53Z | 38,634,455 | <p>You can do this with <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.roots.html" rel="nofollow">numpy</a></p>
<pre><code>import numpy as np
coeff = [1,0,2,0,5,0,1,45,1] #for the polynomial x^8+2x^6+5x^4+x^2+45x+1=0
np.roots(coeff)
# array([ 1.37234708+0.91495949j, 1.37234708-0.91495949j,
# ... | 0 | 2016-07-28T11:01:27Z | [
"python",
"numerical-analysis"
] |
How to figure out http and ssl version using python | 38,629,338 | <p>Is there a good way in python to check if a website/url supports http2 and which SSL versions does it support. </p>
<p>What I am looking for is achievable by the use of commands </p>
<pre><code>openssl s_client Âconnect domain:443 Ânextprotoneg ''
</code></pre>
<p>output of this openssl command contains this li... | 0 | 2016-07-28T07:08:48Z | 38,631,557 | <p>You can use the <a href="https://github.com/Lukasa/hyper" rel="nofollow">Hyper</a> lib.</p>
<pre><code>from hyper import HTTPConnection
conn = HTTPConnection('google.com:443')
# If request made over http/1.1 then result will be None
if conn.request('HEAD', '/') is not None:
# Return a string identifying the pr... | 0 | 2016-07-28T08:56:18Z | [
"python",
"ssl",
"http2",
"spdy"
] |
Why does the regex (.*?(?: *?\n)) capture newlines? | 38,629,424 | <p>Consider the text below: </p>
<pre><code>foobar¬
nextline
</code></pre>
<p>The regex <code>(.*?(?: *?\n))</code> matches <code>foobar¬</code>
where <code>¬</code> denotes a newline \n. </p>
<p>Why does the regex match it? shouldn't the non-capture group exclude it? </p>
<p>Tested on <a href="https://regex101.... | 0 | 2016-07-28T07:12:50Z | 38,629,523 | <p>The <code>\n</code> is captured because the non-capturing group is <strong>inside</strong> the capturing group:</p>
<pre><code>>>> s = 'foobar\nnextline'
>>> re.search(r'(.*?(?: *?\n))', s).groups()
('foobar\n',)
</code></pre>
<p>If you don't want that, place the non-capturing group <strong>outsi... | 2 | 2016-07-28T07:17:55Z | [
"python",
"regex"
] |
Why does the regex (.*?(?: *?\n)) capture newlines? | 38,629,424 | <p>Consider the text below: </p>
<pre><code>foobar¬
nextline
</code></pre>
<p>The regex <code>(.*?(?: *?\n))</code> matches <code>foobar¬</code>
where <code>¬</code> denotes a newline \n. </p>
<p>Why does the regex match it? shouldn't the non-capture group exclude it? </p>
<p>Tested on <a href="https://regex101.... | 0 | 2016-07-28T07:12:50Z | 38,629,584 | <p>âNon-capturing groupâ refers to the fact that matches within that group will not be available as separate groups in the resulting match object. For example:</p>
<pre><code>>>> re.search('(foo)(bar)', 'foobarbaz').groups()
('foo', 'bar')
>>> re.search('(foo)(?:bar)', 'foobarbaz').groups()
('foo... | 6 | 2016-07-28T07:20:32Z | [
"python",
"regex"
] |
Matching a number in a file with Python | 38,629,459 | <p>I have about 15,000 files I need to parse which <em>could</em> contain one or more strings/numbers from a list I have. I need to separate the files with matching strings.</p>
<p>Given a string: 3423423987, it could appear independently as "3423423987", or as "3423423987_1" or "3423423987_1a", "3423423987-1a", but i... | 3 | 2016-07-28T07:14:46Z | 38,629,931 | <p>You can use this pattern:</p>
<pre><code>(?:\b|^)3423423987(?!\.)(?=\b|_|$)
</code></pre>
<p><code>(?:\b|^)</code> asserts that there are no other numbers to the left</p>
<p><code>(?!\.)</code> asserts the number isn't followed by a dot</p>
<p><code>(?=\b|_|$)</code> asserts the number is followed by a non word ... | 1 | 2016-07-28T07:37:24Z | [
"python",
"regex",
"python-3.4"
] |
Matching a number in a file with Python | 38,629,459 | <p>I have about 15,000 files I need to parse which <em>could</em> contain one or more strings/numbers from a list I have. I need to separate the files with matching strings.</p>
<p>Given a string: 3423423987, it could appear independently as "3423423987", or as "3423423987_1" or "3423423987_1a", "3423423987-1a", but i... | 3 | 2016-07-28T07:14:46Z | 38,630,388 | <p>It seems you just want to make sure the number is not matched as part of a, say, float number. You then need to use lookarounds, a lookbehind and a lookahead to disallow dots with digits before and after.</p>
<pre><code>(?<!\d\.)(?:\b|_)3423423987(?:\b|_)(?!\.\d)
</code></pre>
<p>See the <a href="https://regex1... | 3 | 2016-07-28T07:59:59Z | [
"python",
"regex",
"python-3.4"
] |
I want to pip install myFile.env | 38,629,720 | <p>I have a .env file that I used to create a virtual environment. </p>
<p>I want to install the same packages (as specified in the .env file), but this time
I dont want it to be a virtual environment. How can I do this?</p>
<p>Many thanks.</p>
<p>Note:
A .env file can be used by miniconda or anaconda to create vi... | 0 | 2016-07-28T07:27:07Z | 38,630,966 | <p>If you have access to your original virtual env or can create a new one as you describe I think a very simple solution would be to simply create a requirements.txt file. This is simply a file that names all the packages that you have installed in a specific python environment. </p>
<p>The file can be created by sim... | 0 | 2016-07-28T08:28:35Z | [
"python",
"pip",
"anaconda",
"miniconda"
] |
Python datetime weekday number code - dynamically? | 38,629,754 | <p>to get the weekday no,</p>
<pre><code>import datetime
print datetime.datetime.today().weekday()
</code></pre>
<p>The output is an Integer which is within the range of <strong>0 - 6</strong> indicating Monday as 0 at <a href="https://docs.python.org/2/library/datetime.html#datetime.date.weekday" rel="nofollow">doc-... | 0 | 2016-07-28T07:28:49Z | 38,629,996 | <p>The following code will create a dict d with the required values</p>
<pre><code>>>> import calendar
>>> d=dict(enumerate(calendar.day_name))
>>> d
{0: 'Monday', 1: 'Tuesday', 2: 'Wednesday', 3: 'Thursday', 4: 'Friday', 5: 'Saturday', 6: 'Sunday'}
</code></pre>
<p>Edit: The comment below ... | 1 | 2016-07-28T07:40:48Z | [
"python",
"datetime",
"weekday"
] |
Python datetime weekday number code - dynamically? | 38,629,754 | <p>to get the weekday no,</p>
<pre><code>import datetime
print datetime.datetime.today().weekday()
</code></pre>
<p>The output is an Integer which is within the range of <strong>0 - 6</strong> indicating Monday as 0 at <a href="https://docs.python.org/2/library/datetime.html#datetime.date.weekday" rel="nofollow">doc-... | 0 | 2016-07-28T07:28:49Z | 38,630,022 | <p>It is unclear what you are asking for. If you want the day of the week for today, in text form, you could do this:</p>
<pre><code>import datetime
print datetime.datetime.today().strftime('%A')
</code></pre>
<p>If you want to create a dictionary like the one you showed, you could do something like this:</p>
<pre><... | 0 | 2016-07-28T07:42:00Z | [
"python",
"datetime",
"weekday"
] |
Python datetime weekday number code - dynamically? | 38,629,754 | <p>to get the weekday no,</p>
<pre><code>import datetime
print datetime.datetime.today().weekday()
</code></pre>
<p>The output is an Integer which is within the range of <strong>0 - 6</strong> indicating Monday as 0 at <a href="https://docs.python.org/2/library/datetime.html#datetime.date.weekday" rel="nofollow">doc-... | 0 | 2016-07-28T07:28:49Z | 38,630,644 | <p>The simple way to do this is with a dictionary comprehension and the <code>calendar</code> module.</p>
<pre><code>import calendar
days = {name: i for i, name in enumerate(calendar.day_name)}
print(days)
</code></pre>
<p><strong>output</strong></p>
<pre><code>{'Thursday': 3, 'Friday': 4, 'Tuesday': 1, 'Monday': 0,... | 0 | 2016-07-28T08:12:19Z | [
"python",
"datetime",
"weekday"
] |
How to turn off autoscaling in matplotlib.pyplot | 38,629,830 | <p>I am using matplotlib.pyplot in python to plot my data. The problem is the image it generates seems to be autoscaled. How can I turn this off so that when I plot something at (0,0) it will be placed fixed in the center?</p>
| 0 | 2016-07-28T07:32:30Z | 38,629,943 | <p>You can use <code>xlim()</code> and <code>ylim()</code> to set the limits. If you know your data goes from, say -10 to 20 on X and -50 to 30 on Y, you can do:</p>
<pre><code>plt.xlim((-20, 20))
plt.ylim((-50, 50))
</code></pre>
<p>to make 0,0 centered.</p>
<p>If your data is dynamic, you could try allowing the au... | 0 | 2016-07-28T07:37:52Z | [
"python",
"matplotlib"
] |
How to turn off autoscaling in matplotlib.pyplot | 38,629,830 | <p>I am using matplotlib.pyplot in python to plot my data. The problem is the image it generates seems to be autoscaled. How can I turn this off so that when I plot something at (0,0) it will be placed fixed in the center?</p>
| 0 | 2016-07-28T07:32:30Z | 38,630,201 | <p>You want the <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.autoscale" rel="nofollow"><code>autoscale</code></a> function:</p>
<pre><code>from matplotlib import pyplot as plt
# Set the limits of the plot
plt.xlim(-1, 1)
plt.ylim(-1, 1)
# Don't mess with the limits!
plt.autoscale(False)
# Pl... | 1 | 2016-07-28T07:50:53Z | [
"python",
"matplotlib"
] |
Need help making Django + Ajax like button | 38,629,848 | <p>I am new to coding and have currently implemented the like button from the online book - Tango with django: </p>
<p><a href="http://www.tangowithdjango.com/book17/chapters/ajax.html#add-a-like-button" rel="nofollow">http://www.tangowithdjango.com/book17/chapters/ajax.html#add-a-like-button</a></p>
<p>However for ... | 0 | 2016-07-28T07:33:27Z | 38,630,112 | <p>If you want to make sure no <code>User</code> likes the same <code>UserProject</code> twice, you can not simply store the number of likes in the <code>project_likes</code> field, but you should rather create a separate model (e.g. <code>UserLikes</code>) with <code>ForeignKeys</code> to <code>User</code> and <code>U... | 0 | 2016-07-28T07:45:57Z | [
"jquery",
"python",
"ajax",
"django"
] |
Python: renaming files returns the wrong name | 38,629,902 | <p>Say I have a folder with 1000 csv files which names are <code>event_1.csv</code>, <code>event_2.csv</code>,..., <code>event_1000.csv</code>.</p>
<p>I in fact have 25 folders like this and want to rename those files in such a way that the first 4 characters are <code>0001</code> for the first folder, <code>0002</cod... | 0 | 2016-07-28T07:36:06Z | 38,630,504 | <p>If you're sure about all the names of your files, you could considerably simplify your code (as M.T said). Try maybe something like :</p>
<pre><code>for n,i in enumerate(subdir):
os.chdir(r''+i) # Or whatever your folders are named
for m,file in enumerate(glob.glob("*.csv")):
newname =... | 1 | 2016-07-28T08:05:15Z | [
"python",
"csv",
"directory",
"renaming"
] |
adding spaces inside string using regex sub | 38,630,228 | <p>I have a string I want to split into 2-digit pieces. I tried using regex like so:</p>
<pre><code>import re
s = "123456789"
t = re.sub('..', ".. ", s)
print(t)
</code></pre>
<p>I expected to get <code>12 34 56 78 9</code> but instead I got <code>'.. .. .. .. 9'</code>. The <code>9</code> does not bother me, because... | 1 | 2016-07-28T07:52:17Z | 38,630,285 | <p>In a regex, <code>.</code> means any character. In replacement text, it means a period. If you want to capture characters as a group in your regex, you need to put parens around them. You can reference the first such group in the replacement text by using <code>\1</code>:</p>
<pre><code>>>> re.sub('(..)... | 2 | 2016-07-28T07:54:53Z | [
"python",
"regex"
] |
adding spaces inside string using regex sub | 38,630,228 | <p>I have a string I want to split into 2-digit pieces. I tried using regex like so:</p>
<pre><code>import re
s = "123456789"
t = re.sub('..', ".. ", s)
print(t)
</code></pre>
<p>I expected to get <code>12 34 56 78 9</code> but instead I got <code>'.. .. .. .. 9'</code>. The <code>9</code> does not bother me, because... | 1 | 2016-07-28T07:52:17Z | 38,630,324 | <p>You can just refer to the whole match with <code>\g<0></code> <strong>backreference</strong> in the replacement string pattern (where you cannot use <em>regular expression</em> patterns):</p>
<pre><code>re.sub('..', r"\g<0> ", s)
</code></pre>
<p><a href="https://ideone.com/a1Lisg" rel="nofollow">Pytho... | 3 | 2016-07-28T07:56:46Z | [
"python",
"regex"
] |
adding spaces inside string using regex sub | 38,630,228 | <p>I have a string I want to split into 2-digit pieces. I tried using regex like so:</p>
<pre><code>import re
s = "123456789"
t = re.sub('..', ".. ", s)
print(t)
</code></pre>
<p>I expected to get <code>12 34 56 78 9</code> but instead I got <code>'.. .. .. .. 9'</code>. The <code>9</code> does not bother me, because... | 1 | 2016-07-28T07:52:17Z | 38,630,475 | <p>You may use <code>re.findall</code> also,</p>
<pre><code>>>> s = "123456789"
>>> ' '.join(re.findall(r'..|.', s))
'12 34 56 78 9'
>>>
</code></pre>
<p><code>r'..|.'</code> regex matches two chars or a single character (first preference goes to <code>..</code> and then <code>.</code>)</p... | 4 | 2016-07-28T08:04:11Z | [
"python",
"regex"
] |
adding spaces inside string using regex sub | 38,630,228 | <p>I have a string I want to split into 2-digit pieces. I tried using regex like so:</p>
<pre><code>import re
s = "123456789"
t = re.sub('..', ".. ", s)
print(t)
</code></pre>
<p>I expected to get <code>12 34 56 78 9</code> but instead I got <code>'.. .. .. .. 9'</code>. The <code>9</code> does not bother me, because... | 1 | 2016-07-28T07:52:17Z | 38,630,797 | <p>You can use List Comprehensions too,</p>
<pre><code>>>> s='123456789'
>>> res=[s[index:index+2] for index,x in enumerate(s) if index % 2==0]
['12', '34', '56', '78', '9']
</code></pre>
| 0 | 2016-07-28T08:20:40Z | [
"python",
"regex"
] |
Selenium Error: Element is not clickable at point(X,Y), other element would receive the click | 38,630,254 | <p>I am using python and selenium. On <a href="https://steemit.com/steem/@cheolwoo-kim/what-is-steemit" rel="nofollow">this</a> link I would to click <code>Reply</code> to add comment</p>
<blockquote>
<p>Element is not clickable at point (933.9500122070312,
16.666671752929688). Other element would receive the clic... | 1 | 2016-07-28T07:53:12Z | 38,632,255 | <p>Your css is correct, the problem with the long content is that it scrolls the element to below of the <code>.Header</code> that why it can't click the element.</p>
<p>You can get the location of the element and scroll to 100px less than Y coordinate since the height of <code>.Header</code> is 49.5px and it is bette... | 1 | 2016-07-28T09:25:35Z | [
"python",
"selenium"
] |
Selenium Error: Element is not clickable at point(X,Y), other element would receive the click | 38,630,254 | <p>I am using python and selenium. On <a href="https://steemit.com/steem/@cheolwoo-kim/what-is-steemit" rel="nofollow">this</a> link I would to click <code>Reply</code> to add comment</p>
<blockquote>
<p>Element is not clickable at point (933.9500122070312,
16.666671752929688). Other element would receive the clic... | 1 | 2016-07-28T07:53:12Z | 38,634,058 | <p>You are trying to click on <code>span</code> element while actually it should be <code>a</code> element. Here you should try to locate <code>a</code> element using <code>WebDriverWait</code> to wait until element visible and clickable on <code>DOM</code> then perform click as below :-</p>
<pre><code>from selenium i... | 0 | 2016-07-28T10:43:37Z | [
"python",
"selenium"
] |
Maya Python: Accessing outer function variable from inner funtion | 38,630,356 | <p>I want to write a UI window using python, the following is my code, the function is running correctly, but there is a problem, when I choose an item in the textScrollList, it should call the inner funtion 'update()' and highlight the corresponding object in the scene.
However, the object cannot be chosen correctly a... | 0 | 2016-07-28T07:58:20Z | 38,631,128 | <p>You can try with a global variable "global tsl" at the top of your code. That isn't the most beautiful however, it works :)</p>
| 0 | 2016-07-28T08:36:21Z | [
"python",
"maya"
] |
Maya Python: Accessing outer function variable from inner funtion | 38,630,356 | <p>I want to write a UI window using python, the following is my code, the function is running correctly, but there is a problem, when I choose an item in the textScrollList, it should call the inner funtion 'update()' and highlight the corresponding object in the scene.
However, the object cannot be chosen correctly a... | 0 | 2016-07-28T07:58:20Z | 38,645,112 | <p>You need to define your inner functions first, then just reference them, no need to use a string for <code>command=</code> :</p>
<pre><code>def alertWindow(obj):
def update():
cmds.select(cmds.textScrollList(tsl, q=True, selectItem = True))
def remove():
cmds.DeleteHistory()
cmds.te... | 0 | 2016-07-28T19:25:06Z | [
"python",
"maya"
] |
How to execute shell command and stream output with Python and Flask upon HTTP request? | 38,630,421 | <p>Following <a href="http://stackoverflow.com/questions/15092961/how-to-continuously-display-python-output-in-a-webpage">this post</a>, I am able to <code>tail -f</code> a log file to a webpage:</p>
<pre><code>from gevent import sleep
from gevent.wsgi import WSGIServer
import flask
import subprocess
app = flask.Flas... | 0 | 2016-07-28T08:01:46Z | 38,643,387 | <p>Here is some code that should do the job. Some notes:</p>
<ol>
<li><p>You need to detect when the request disconnects, and then terminate the proc. The try/except code below will do that. However, after inner() reaches its end, Python will try to close the socket normally, which will raise an exception (I think it'... | 0 | 2016-07-28T17:46:59Z | [
"python",
"linux",
"flask",
"subprocess"
] |
Error while installing GDAL | 38,630,474 | <p>I'm trying to install GDAL through pip. But I'm getting this error:</p>
<pre><code>extensions/gdal_wrap.cpp:3089:27: fatal error: cpl_vsi_error.h: No such file or directory
#include "cpl_vsi_error.h"
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit sta... | 0 | 2016-07-28T08:04:09Z | 38,630,941 | <p>Check that you installed GDAL using this command</p>
<pre><code>gdal-config --version
</code></pre>
<p>Then run this commands:</p>
<pre><code>pip install --download="some_path" GDAL
cd some_path
tar -xvzf GDAL-<version>.tar.gz
cd GDAL-<version>
python setup.py build_ext --include-dirs=/usr/include/gda... | 0 | 2016-07-28T08:27:04Z | [
"python",
"pip",
"gdal"
] |
Best way to avoid copy-paste and hardcoding | 38,630,613 | <p>' Hello, SO community.</p>
<p><strong>Problem:</strong> I have many regEx patterns, such as</p>
<pre><code>r'to.*school', r'built.*in'
</code></pre>
<p>and etc. In every case, I should execute a code, that varies from situation to situation.</p>
<p><strong>Example:</strong> If pattern is 'to.*school', I want to ... | 0 | 2016-07-28T08:10:39Z | 38,634,940 | <p>If there is sufficient regularity in the code you need to write a function which accepts sentence and the other things which determine what to do with it. This is sometimes called parametrisation. For example with your above, presumably simplified examples, you'd have</p>
<pre><code>def process(sentence, parttest, ... | 1 | 2016-07-28T11:23:22Z | [
"python",
"design-patterns"
] |
Issue creating a Numpy NDArray from PyArray_SimpleNewFromData | 38,630,716 | <p>I try to do a python wrapper to bind some C++ functions and types to python. My issue is when I try to convert a custom matrix type to a numpy ndarray. The most convincing solution is to use <code>PyArray_SimpleNewFromData</code>.</p>
<p>To test its behaviour, as I didn't manage to do what I wanted I tried to imple... | 0 | 2016-07-28T08:16:03Z | 38,631,409 | <p>I would try with an array that has been allocated by malloc, and then perhaps settings some flag named <code>OWNDATA</code> in order to avoid a memory leak. </p>
<p>At least the garbage data can be explained if the instance of <code>numpy.ndarray</code> does not copy the data but just stores a pointer to the suppli... | 2 | 2016-07-28T08:49:46Z | [
"python",
"c++",
"numpy",
"wrapper"
] |
Python import error no module named bz2 | 38,630,720 | <p>I have libbz2-dev installed however I am still getting the following import error while importing gensim :</p>
<pre><code>>>> import gensim
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/krishna/gensimenv/lib/python2.7/site-packages/gensim/__init__.py", ... | -1 | 2016-07-28T08:16:09Z | 38,631,498 | <p>you can try to do </p>
<pre><code>pip install bz2file
</code></pre>
| 1 | 2016-07-28T08:53:30Z | [
"python",
"gensim"
] |
Python: concatenate 2 list | 38,630,766 | <p>I have 2 lists in python:</p>
<pre><code>list1 [1,1,0,0,1,1,0,0,1,1]
list2 [a,b,c,d,e,f,-,-,-,-]
</code></pre>
<p>I would like to output the follow:</p>
<p>output</p>
<pre><code>[a,b,-,-,c,d,-,-,e,f]
</code></pre>
<p>I am lost, tried multiple things without any luck.
Anyone have an idea how to do it? Here's my... | -2 | 2016-07-28T08:18:50Z | 38,630,875 | <pre><code>out = []
for i in list1:
out.append(list2.pop(0) if i else '-')
</code></pre>
| 0 | 2016-07-28T08:24:26Z | [
"python",
"arraylist"
] |
Python: concatenate 2 list | 38,630,766 | <p>I have 2 lists in python:</p>
<pre><code>list1 [1,1,0,0,1,1,0,0,1,1]
list2 [a,b,c,d,e,f,-,-,-,-]
</code></pre>
<p>I would like to output the follow:</p>
<p>output</p>
<pre><code>[a,b,-,-,c,d,-,-,e,f]
</code></pre>
<p>I am lost, tried multiple things without any luck.
Anyone have an idea how to do it? Here's my... | -2 | 2016-07-28T08:18:50Z | 38,631,074 | <p>Try this:</p>
<pre><code>output = [list2.pop(b-1) for b in list1]
</code></pre>
| 3 | 2016-07-28T08:33:26Z | [
"python",
"arraylist"
] |
Python: concatenate 2 list | 38,630,766 | <p>I have 2 lists in python:</p>
<pre><code>list1 [1,1,0,0,1,1,0,0,1,1]
list2 [a,b,c,d,e,f,-,-,-,-]
</code></pre>
<p>I would like to output the follow:</p>
<p>output</p>
<pre><code>[a,b,-,-,c,d,-,-,e,f]
</code></pre>
<p>I am lost, tried multiple things without any luck.
Anyone have an idea how to do it? Here's my... | -2 | 2016-07-28T08:18:50Z | 38,631,095 | <p>Or even this one liner:</p>
<pre><code>list1 = [1,1,0,0,1,1,0,0,1,1]
list2 = ['a','b','c','d','e','f','-','-','-','-']
output = [list2[i] if v else '-' for i, v in enumerate(list1)]
print(output)
</code></pre>
<p><strong>UPDATE Not quite a one liner and could be more efficient in the for loop - but I prefer thi... | 0 | 2016-07-28T08:34:37Z | [
"python",
"arraylist"
] |
Python: concatenate 2 list | 38,630,766 | <p>I have 2 lists in python:</p>
<pre><code>list1 [1,1,0,0,1,1,0,0,1,1]
list2 [a,b,c,d,e,f,-,-,-,-]
</code></pre>
<p>I would like to output the follow:</p>
<p>output</p>
<pre><code>[a,b,-,-,c,d,-,-,e,f]
</code></pre>
<p>I am lost, tried multiple things without any luck.
Anyone have an idea how to do it? Here's my... | -2 | 2016-07-28T08:18:50Z | 38,631,179 | <p>Based on your code, I think this is what you want.</p>
<p>For each element in list1, if the element is a 1, add the next element in list2 to newList. If it's a 0, add a hyphen to newList.</p>
<pre><code>list1 = [ 0, 0, 1, 1, 1, 0 ]
list2 = [ 'a', 'b', 'c', 'd', 'e', 'f' ] # idk why you needed hyphens i... | 0 | 2016-07-28T08:39:13Z | [
"python",
"arraylist"
] |
Python: concatenate 2 list | 38,630,766 | <p>I have 2 lists in python:</p>
<pre><code>list1 [1,1,0,0,1,1,0,0,1,1]
list2 [a,b,c,d,e,f,-,-,-,-]
</code></pre>
<p>I would like to output the follow:</p>
<p>output</p>
<pre><code>[a,b,-,-,c,d,-,-,e,f]
</code></pre>
<p>I am lost, tried multiple things without any luck.
Anyone have an idea how to do it? Here's my... | -2 | 2016-07-28T08:18:50Z | 38,631,479 | <p>The logic for this program should be as follow:
1. If the current element in list1 is 1, pop the first element from list2
2. If not, pop the last element from list2</p>
<p>Here is a sample code for your reference:</p>
<pre><code>list1 = [1,1,0,0,1,1,0,0,1,1]
list2 = ["a","b","c","d","e","f","-","-","-","-"]
outLis... | 0 | 2016-07-28T08:52:39Z | [
"python",
"arraylist"
] |
Python: concatenate 2 list | 38,630,766 | <p>I have 2 lists in python:</p>
<pre><code>list1 [1,1,0,0,1,1,0,0,1,1]
list2 [a,b,c,d,e,f,-,-,-,-]
</code></pre>
<p>I would like to output the follow:</p>
<p>output</p>
<pre><code>[a,b,-,-,c,d,-,-,e,f]
</code></pre>
<p>I am lost, tried multiple things without any luck.
Anyone have an idea how to do it? Here's my... | -2 | 2016-07-28T08:18:50Z | 38,631,778 | <p>I can think of 2 scenarios how the output described comes:</p>
<p>1) If the first list has 0, just add '-'</p>
<pre><code>list1 = [1,1,0,0,1,1,0,0,1,1]
list2 = ['a', 'b', 'c', 'd', 'e', 'f', '-', '-', '-']
index =0
output = []
for element in list1:
if element != 0:
element = list2[index]
index ... | 0 | 2016-07-28T09:06:14Z | [
"python",
"arraylist"
] |
PYTHON Is there a way I can get the year difference between two dates? | 38,630,956 | <p>I'm developing a small program for an insurance company to see how old a person is (this changes the ranges of cover we can offer). I can easily calculate the different in the years but it does not take into account the days/months. I there any way of doing this without importing things from elsewhere?</p>
<p>Thank... | 0 | 2016-07-28T08:28:05Z | 38,631,782 | <p>as you are working with python you <strong>must</strong> use the datetime module. Lets have a look.</p>
<pre><code>from datetime import datetime
bday = '1978/11/21'
dt = datetime.strptime(bday, '%Y/%m/%d')
diff = datetime.now() - dt
diff.days
</code></pre>
<p>Gives you 13764</p>
| 0 | 2016-07-28T09:06:28Z | [
"python",
"date"
] |
Send one file at a time? | 38,630,992 | <p>My python script:</p>
<pre><code>#!/usr/bin/python
import CameraID
import time
import os
image="/tmp/image/frame.png"
count = 1
while (count==1):
# make sure file file exists, else show an error
if ( not os.path.isfile(image)):
print("Error: %s file not found" %image)
else:
print("Sending file %s ..... | -1 | 2016-07-28T08:29:38Z | 38,631,149 | <p>maybe can use list to save file, like: image=["/tmp/image/frame.png",""]
then use for x in image:</p>
| 0 | 2016-07-28T08:37:35Z | [
"python",
"python-2.7"
] |
Send one file at a time? | 38,630,992 | <p>My python script:</p>
<pre><code>#!/usr/bin/python
import CameraID
import time
import os
image="/tmp/image/frame.png"
count = 1
while (count==1):
# make sure file file exists, else show an error
if ( not os.path.isfile(image)):
print("Error: %s file not found" %image)
else:
print("Sending file %s ..... | -1 | 2016-07-28T08:29:38Z | 38,631,471 | <p>Just make a list of files you want to transfer, then iterate over that list to send the files one by one.</p>
<p>Here a simple function to get the list of files:</p>
<pre><code>def list_of_files(folder, extension):
'''
Return a list of file-paths for each file into a folder with the target extension.
'... | 0 | 2016-07-28T08:52:22Z | [
"python",
"python-2.7"
] |
assign values to list of variables in python | 38,631,003 | <p>I have made a small demo of a more complex problem</p>
<pre><code>def f(a):
return tuple([x for x in range(a)])
d = {}
[d['1'],d['2']] = f(2)
print d
# {'1': 0, '2': 1}
# Works
</code></pre>
<p>Now suppose the keys are programmatically generated<br>
How do i achieve the same thing for this case?</p>
<pre><c... | 0 | 2016-07-28T08:30:17Z | 38,631,107 | <p>You can't, it's a syntactical feature of the assignment statement. If you do something dynamic, it'll use different syntax, and thus not work.</p>
<p>If you have some function results <code>f()</code> and a list of keys <code>keys</code>, you can use <code>zip</code> to create an iterable of keys and results, and l... | 1 | 2016-07-28T08:35:17Z | [
"python"
] |
How can i remove overlap in list? | 38,631,355 | <p>I made example python list.</p>
<pre><code>list_1 = [1,3,2,2,3,4,5,1]
print(list_1)
</code></pre>
<blockquote>
<p>[1, 3, 2, 2, 3, 4, 5, 1]</p>
</blockquote>
<p>To remove overlap, i tried to use set().</p>
<pre><code>print(set(list_1))
</code></pre>
<blockquote>
<p>{1, 2, 3, 4, 5}</p>
</blockquote>
<p>but i... | 1 | 2016-07-28T08:47:10Z | 38,765,726 | <p>To have distinct values in your list, just use the following snippet:</p>
<pre><code>l = [1,3,2,2,3,4,5,1]
result = list()
map(lambda x: not x in result and result.append(x), l)
print(result) #[1,3,2,4,5]
</code></pre>
<p>As you already found out, <code>set()</code> doesn't preserve the order of your sequence. The... | 0 | 2016-08-04T11:10:30Z | [
"python"
] |
How can i remove overlap in list? | 38,631,355 | <p>I made example python list.</p>
<pre><code>list_1 = [1,3,2,2,3,4,5,1]
print(list_1)
</code></pre>
<blockquote>
<p>[1, 3, 2, 2, 3, 4, 5, 1]</p>
</blockquote>
<p>To remove overlap, i tried to use set().</p>
<pre><code>print(set(list_1))
</code></pre>
<blockquote>
<p>{1, 2, 3, 4, 5}</p>
</blockquote>
<p>but i... | 1 | 2016-07-28T08:47:10Z | 38,765,825 | <p>You could (ab)use <a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" rel="nofollow"><code>collections.OrderedDict</code></a> to get just the unique elements in order:</p>
<pre><code>>>> list_1 = [1,3,2,2,3,4,5,1]
>>> from collections import OrderedDict
>>>... | 1 | 2016-08-04T11:14:46Z | [
"python"
] |
How can i remove overlap in list? | 38,631,355 | <p>I made example python list.</p>
<pre><code>list_1 = [1,3,2,2,3,4,5,1]
print(list_1)
</code></pre>
<blockquote>
<p>[1, 3, 2, 2, 3, 4, 5, 1]</p>
</blockquote>
<p>To remove overlap, i tried to use set().</p>
<pre><code>print(set(list_1))
</code></pre>
<blockquote>
<p>{1, 2, 3, 4, 5}</p>
</blockquote>
<p>but i... | 1 | 2016-07-28T08:47:10Z | 38,765,967 | <p>Try This You can do this using reversing a <code>list</code>.without using any python libraries.</p>
<pre><code>>>> list_1 = [1,3,2,2,3,4,5,1]
>>> list_1.reverse()
>>> for i in list_1:
... if(list_1.count(i)>1):
... list_1.remove(i)
...
>>> list_1.reverse()
>>... | 0 | 2016-08-04T11:20:56Z | [
"python"
] |
How can i remove overlap in list? | 38,631,355 | <p>I made example python list.</p>
<pre><code>list_1 = [1,3,2,2,3,4,5,1]
print(list_1)
</code></pre>
<blockquote>
<p>[1, 3, 2, 2, 3, 4, 5, 1]</p>
</blockquote>
<p>To remove overlap, i tried to use set().</p>
<pre><code>print(set(list_1))
</code></pre>
<blockquote>
<p>{1, 2, 3, 4, 5}</p>
</blockquote>
<p>but i... | 1 | 2016-07-28T08:47:10Z | 38,767,033 | <p>I would probably do something like this:</p>
<pre><code>seen = set()
result
for i in the_list:
if i not in seen:
seen.add(i)
result.append(i)
</code></pre>
<p>I use <code>seen</code> for fast lookups, still unknown time complexity from the <code>result.append</code> method call.</p>
<p>It's possible to ... | 0 | 2016-08-04T12:13:52Z | [
"python"
] |
How can i remove overlap in list? | 38,631,355 | <p>I made example python list.</p>
<pre><code>list_1 = [1,3,2,2,3,4,5,1]
print(list_1)
</code></pre>
<blockquote>
<p>[1, 3, 2, 2, 3, 4, 5, 1]</p>
</blockquote>
<p>To remove overlap, i tried to use set().</p>
<pre><code>print(set(list_1))
</code></pre>
<blockquote>
<p>{1, 2, 3, 4, 5}</p>
</blockquote>
<p>but i... | 1 | 2016-07-28T08:47:10Z | 38,768,638 | <p>You can use list-comprehension with filter (initialize the empty list first, ignore the resulting list)</p>
<pre><code>list_u = []
[list_u.append(v) for v in list_1 if v not in list_u]
</code></pre>
| 0 | 2016-08-04T13:24:50Z | [
"python"
] |
In Scrapy, How to set time limit for each url? | 38,631,414 | <p>I am trying to crawl multiple websites using Scrapy link extractor and follow as TRUE (recursive) .. Looking for a solution to set the time limit to crawl for each url in start_urls list.</p>
<p>Thanks</p>
<pre><code>import scrapy
class DmozItem(scrapy.Item):
title = scrapy.Field()
link = scrapy.Field()
... | 0 | 2016-07-28T08:49:59Z | 38,631,626 | <p>Use a Timeout object!</p>
<pre><code>import signal
class Timeout(object):
"""Timeout class using ALARM signal."""
class TimeoutError(Exception):
pass
def __init__(self, sec):
self.sec = sec
def __enter__(self):
signal.signal(signal.SIGALRM, self.raise_timeout)
sign... | -1 | 2016-07-28T08:59:57Z | [
"python",
"scrapy"
] |
In Scrapy, How to set time limit for each url? | 38,631,414 | <p>I am trying to crawl multiple websites using Scrapy link extractor and follow as TRUE (recursive) .. Looking for a solution to set the time limit to crawl for each url in start_urls list.</p>
<p>Thanks</p>
<pre><code>import scrapy
class DmozItem(scrapy.Item):
title = scrapy.Field()
link = scrapy.Field()
... | 0 | 2016-07-28T08:49:59Z | 38,634,075 | <p>You need to use <code>download_timeout</code> meta parameter for <code>scrapy.Request</code>.</p>
<p>To use it in starting urls, you need to overload <code>self.start_requests(self)</code> function, something like:</p>
<pre><code>def start_requests(self):
# 10 seconds for first url
yield Request(self.start... | 0 | 2016-07-28T10:44:12Z | [
"python",
"scrapy"
] |
Python3: Continuous variable update within Mainframe | 38,631,427 | <p>Basically, I have created a thread which continuously writes a global variable in an infinite loop. Then I have the mainframe which should read and display that variable.</p>
<p>The problem is that once the mainframe runs, it only displays the value of the variable which it read at the time of startup, and does not... | 0 | 2016-07-28T08:50:39Z | 38,636,370 | <p>Save a reference to the label, and then set up a function that updates the label and then arranges for itself to be called again. In the following example the label will be updated once a second.</p>
<pre><code>class Example(Frame):
def __init__(self, parent):
...
# call this once, after the UI ... | 0 | 2016-07-28T12:28:01Z | [
"python",
"multithreading",
"python-3.x",
"tkinter"
] |
Using $* as part of a parameter for os.system in python | 38,631,461 | <p>The command:</p>
<pre><code>make foo -f $*
</code></pre>
<p>Has different functionality when called from the command line versus when it is called from a python script as follows:</p>
<pre><code>import os
os.system(make foo -f $*)
</code></pre>
<p>As stated here: <a href="http://tldp.org/LDP/abs/html/internalvar... | 0 | 2016-07-28T08:52:02Z | 38,631,763 | <p>As you point out, $* has no special meaning in python. The comprehension is done entirely by whatever shell you are using. If you want to pass all positional parameters passed to your script to some command, then you can try the following</p>
<pre><code>import os, sys
os.system("make foo -f {}".format(" ".join(sys.... | 1 | 2016-07-28T09:05:46Z | [
"python",
"os.system"
] |
Python NameError: name 'encrypt' is not defined | 38,631,474 | <p>When I attempt to run this it says NameError: name 'encrypt' is not defined.</p>
<pre><code>MAX_KEY_SIZE = 26
def getMode():
while True:
print('Do you wish to encrypt or decrypt a message?')
mode = input().lower()
if mode in "encrypt" 'e' 'decrypt' 'd'.split():
r... | 0 | 2016-07-28T08:52:31Z | 38,631,641 | <p>From what I understand of your code, 'encrypt' is a string value. You need to create a list with your required string values and check whether the mode variable matches with a value in that list.</p>
<pre><code>MAX_KEY_SIZE=26
def getMode():
while True:
mode=input().lower()
if mode in ['encrypt'... | 2 | 2016-07-28T09:00:47Z | [
"python",
"nameerror"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.