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
python: handling an array of XML items with element tree preferably "merge"
39,007,027
<p>I have an array called projectDet[]. It contains about 350 items.</p> <p><strong>EACH</strong> item in the array is xml information (single item below). The xml for each item is the same format but different id's and values. What I'd prefer is to have all of these into one big XML variable that I can pull Elements...
0
2016-08-17T22:10:28Z
39,008,710
<p>Consider using <a href="https://docs.python.org/2/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.append" rel="nofollow"><code>append()</code></a> to append all children of the <code>&lt;root&gt;</code> iteratively across the list. But initially capture the first full element of <code>&lt;root&gt;</...
1
2016-08-18T01:41:23Z
[ "python", "arrays", "xml", "elementtree" ]
Python: Replacing arbitrary substrings with substrings
39,007,082
<p>Sorry if this has been asked before, but I've been struggling with this for weeks now.</p> <p>I'm trying to figure out how to replace a particular substring within an arbitrary string with another particular substring.</p> <p>IE:</p> <p>If I get user to type in an arbitrary string, I want to replace any instance ...
-1
2016-08-17T22:14:17Z
39,007,119
<p>You can use the <code>String replace</code> method like this:</p> <p><code>cstring.replace("MAA,"UOP")</code></p> <p>However, if you want to code it yourself, this works:</p> <pre><code>cstring = input("Enter a character string: ") for i in range (0, len(cstring)): if (len(cstring[i:]) &gt;= 3 and cstring[i...
0
2016-08-17T22:17:54Z
[ "python", "string", "indexing", "slice" ]
Python: Replacing arbitrary substrings with substrings
39,007,082
<p>Sorry if this has been asked before, but I've been struggling with this for weeks now.</p> <p>I'm trying to figure out how to replace a particular substring within an arbitrary string with another particular substring.</p> <p>IE:</p> <p>If I get user to type in an arbitrary string, I want to replace any instance ...
-1
2016-08-17T22:14:17Z
39,007,238
<p>As other users have noted you can use <code>str.replace</code>. Here are some other options:</p> <h3>Regular Expressions</h3> <p>This is probably the way to go since you'll be able to replace any regex with your replacement string with all the advantages of the various re flags.</p> <pre><code>import re re.sub("...
0
2016-08-17T22:30:34Z
[ "python", "string", "indexing", "slice" ]
Not sure how to use sklearn with feature vectors which contain both text and numbers
39,007,083
<p>I just started to use sklearn and I want to categorize products. The products appear on order lines and have properties like, a description, a price, a manufacturer, order quantity etc. Some of these properties are text and others are numbers (integers or floats). I want to use these properties to predict if the pro...
0
2016-08-17T22:14:23Z
39,012,920
<p>I would suggest not to make predictions on different feature types and then combining. You're better off using <code>FeatureUnion</code> as you suggest, which allows you to create separate preprocessing pipelines for each feature type. A construction I often use is the following...</p> <p>Let's define a toy example...
1
2016-08-18T08:06:17Z
[ "python", "machine-learning", "scikit-learn" ]
Pythonic way to handle config file installation when in a virtualenv?
39,007,132
<p>Assuming I am installing a python application from setup.py, and doing so within a virtualenv. Also, assuming that I have a need to provide the application sensitive configurations such as API keys / URIs.</p> <p>My virtualenv might be in a path such as:</p> <pre><code>/opt/appname/venv </code></pre> <p>I believ...
-3
2016-08-17T22:19:09Z
39,108,700
<p>Assuming the config file alters Virtual Environment Variables and that is why it must be modified before the launch of the virtual environment, then you can modify the <code>activate</code> bash script located in <code>./venv/bin</code> to accomplish this. So if you want to add a global path from a config file, then...
1
2016-08-23T18:52:43Z
[ "python", "pip", "virtualenv", "setuptools", "packaging" ]
Pythonic way to handle config file installation when in a virtualenv?
39,007,132
<p>Assuming I am installing a python application from setup.py, and doing so within a virtualenv. Also, assuming that I have a need to provide the application sensitive configurations such as API keys / URIs.</p> <p>My virtualenv might be in a path such as:</p> <pre><code>/opt/appname/venv </code></pre> <p>I believ...
-3
2016-08-17T22:19:09Z
39,170,378
<p>Have you tried using Python's <a href="https://docs.python.org/3/library/site.html" rel="nofollow">site-specific configuration</a> options? It seems to me like <code>.pth</code> files and a <code>sitecustomize.py</code> file might be helpful.<br> See also: <a href="http://stackoverflow.com/a/15209116/6051861">Accept...
0
2016-08-26T16:02:20Z
[ "python", "pip", "virtualenv", "setuptools", "packaging" ]
Cx_freeze TypeError can only concatenate list (not "NoneType") to list using numpy dependency when pandas is an import
39,007,134
<p>I am trying to use cxfreeze to turn the following script into an executable</p> <pre><code>import datetime from calendar import monthrange from tia.bbg import LocalTerminal as Lt import pandas as pd from pypyodbc import connect, DatabaseError print 'Hello World!' </code></pre> <p>When running the following line i...
1
2016-08-17T22:19:23Z
39,122,902
<p>I had this problem. You can explicitly exclude all offending modules, but by debugging I think I found the responsible code and a small bugfix :). The following should help you get over this problem (and may lead you to the next one of missing dependencies ;) )</p> <p>Checking the code for freeze.py, there is a cas...
2
2016-08-24T12:08:08Z
[ "python", "pandas", "numpy", "executable", "cx-freeze" ]
Python 'yield' statements cause JSON not serializable errors in LAMBDA AWS test case
39,007,142
<p>I'm learning how to use Python in the Amazon AWS Lambda service. I'm trying to read characters from an S3 object, and write them to another S3 object. I realize I can copy the S3 object to a local tmp file, but I wanted to "stream" the S3 input into the script, process and output, without the local copy stage if p...
0
2016-08-17T22:20:44Z
39,008,923
<p>A function includes <code>yield</code> is actually a <a href="https://wiki.python.org/moin/Generators" rel="nofollow">generator</a>, whereas the lambda handler needs to be a <a href="http://docs.aws.amazon.com/lambda/latest/dg/python-programming-model-handler-types.html" rel="nofollow">function</a> that optionally r...
1
2016-08-18T02:13:55Z
[ "python", "json", "amazon-s3", "lambda" ]
Python 'yield' statements cause JSON not serializable errors in LAMBDA AWS test case
39,007,142
<p>I'm learning how to use Python in the Amazon AWS Lambda service. I'm trying to read characters from an S3 object, and write them to another S3 object. I realize I can copy the S3 object to a local tmp file, but I wanted to "stream" the S3 input into the script, process and output, without the local copy stage if p...
0
2016-08-17T22:20:44Z
39,022,621
<p>Thanks to Lei Shi for answering the specific point I was asking about. Also Thanks to FujiApple for pointing out a missed coding mistake in the original code. I was able to develop a solution without using yield that seemed to work copying the input file to output. But with Lei Shi and FujiApples comments I was abl...
0
2016-08-18T15:52:39Z
[ "python", "json", "amazon-s3", "lambda" ]
Binning by value, except last bin
39,007,172
<p>I am trying to bin data as follows:</p> <pre><code>pd.cut(df['col'], np.arange(0,1.2, 0.2),include_lowest=True)) </code></pre> <p>But I would like to ensure that any data greater than 1 is also included in that last bin. I can do this in a couple lines, but wondering if anyone knows a one-liner/more pythonic way o...
1
2016-08-17T22:23:42Z
39,007,334
<p><strong>Solution 1:</strong> prepare <code>labels</code> (using first 5 rows of the DF) and replace <code>1</code> with <code>np.inf</code> in the <code>bins</code> parameter: </p> <pre><code>In [67]: df Out[67]: a b c 0 1.698479 0.337989 0.002482 1 0.903344 1.830499 0.095253 2 0....
2
2016-08-17T22:41:00Z
[ "python", "pandas", "dataframe", "categorical-data", "binning" ]
Python: write df to json
39,007,190
<p>I have dataframe</p> <pre><code>month 2015-05 2015-06 2015-07 2015-08 2015- 09 \ ID 00051f002f5a0c179d7ce191ca2c6401 0 0 0 1 1 0011ec51ddb5a41abb2d451fdfa0996a ...
1
2016-08-17T22:25:52Z
39,007,270
<p>Try <code>df.to_json(orient="index")</code>, where <code>df</code> is your <code>DataFrame</code> object.</p> <p>For example,</p> <pre><code>In [32]: df Out[32]: a b c deadbeef foo 1 2.5 f005ba11 bar 3 4.5 7e1eca57 baz 5 6.5 In [33]: df.to_json(orient="index") Out[33]: '{"deadbeef":{"a"...
0
2016-08-17T22:33:56Z
[ "python", "json", "pandas", "dictionary" ]
python lxml etree applet information from yahoo
39,007,227
<p>Yahoo finance updated their website. I had an lxml/etree script that used to extract the analyst recommendations. Now, however, the analyst recommendations are there, but only as a graphic. You can see an example on <a href="https://finance.yahoo.com/quote/CSX/analysts?p=CSX">this page</a>. The graph called Recommen...
8
2016-08-17T22:29:29Z
39,178,177
<p>The page is <em>quite dynamic</em> and involves a lot of javascript executed in a browser. To follow the @Padraic's advice about switching to <a href="http://selenium-python.readthedocs.io/" rel="nofollow"><code>selenium</code></a>, here is a complete sample working code that produces a month-to-trend dictionary at ...
4
2016-08-27T06:28:21Z
[ "python", "python-3.x", "web-scraping", "lxml" ]
python lxml etree applet information from yahoo
39,007,227
<p>Yahoo finance updated their website. I had an lxml/etree script that used to extract the analyst recommendations. Now, however, the analyst recommendations are there, but only as a graphic. You can see an example on <a href="https://finance.yahoo.com/quote/CSX/analysts?p=CSX">this page</a>. The graph called Recommen...
8
2016-08-17T22:29:29Z
39,276,275
<p>As comments say they have moved to ReactJS, so <code>lxml</code> is no longer to the point because there's no data in the HTML page. Now you need to look around and find the endpoint where they are pulling the data from. In case of <em>Recommendation Trends</em> it's there.</p> <pre><code>#!/usr/bin/env python3 i...
2
2016-09-01T16:07:33Z
[ "python", "python-3.x", "web-scraping", "lxml" ]
Python how to solve Unicode Error in string
39,007,232
<p>I'm getting the classical error:</p> <blockquote> <p>ascii' codec can't decode byte 0xc3 in position 28: ordinal not in range(128)</p> </blockquote> <p>This time, I can't solve it. The error comes from this line:</p> <pre><code>mensaje_texto_inmobiliaria = "%s, con el email %s y el teléfono %s está se ha co...
0
2016-08-17T22:30:19Z
39,007,419
<p>This is in response to why this solves the issue OP is having, and somebackground on the issue OP is trying describe</p> <pre><code>from __future__ import unicode_literals from builtins import str </code></pre> <p>In the default iPython 2.7 kernel : </p> <p>(iPython session)</p> <pre><code>In [1]: type("é") # B...
3
2016-08-17T22:50:13Z
[ "python", "unicode", "utf-8" ]
JSON file with input from filename using bash
39,007,279
<p>I am very new to bash scripting. </p> <p>I have set of JSON files as follows:</p> <pre><code>sub-285345_task-EMOTION_acq-LR_idir-acq-LR_epi.json sub-285345_task-EMOTION_acq-LR_idir-acq-RL_epi.json sub-285345_task-EMOTION_acq-RL_idir-acq-LR_epi.json sub-285345_task-EMOTION_acq-RL_idir-acq-RL_epi.json </code></pre> ...
0
2016-08-17T22:34:47Z
39,007,685
<p>You try below node js script</p> <pre><code>var fs = require('fs'); fs.readdir('.', function(err, files) { if (err) console.log(err); files.forEach(function(file) { var obj = { "TotalReadoutTime": 0.08346, }; if (file.indexOf("idir-acq-LR") &gt; -1) { conso...
0
2016-08-17T23:22:06Z
[ "python", "json", "bash", "terminal" ]
assign variable to multiple argparse attributes
39,007,318
<p>I'm trying to assign multiple argument attributes based on their location in the attribute list. To give an example;</p> <pre><code>import argparse import sys def args_options: parser = argparse.ArgumentParser() parser.add_argument('-s', help='-s argument help', nargs=3) parser.add_argument('-k', help=...
1
2016-08-17T22:39:49Z
39,007,724
<p>Run the parser with various inputs, and look at the results:</p> <pre><code>In [108]: def args_options(argv=None): ...: parser = argparse.ArgumentParser() ...: parser.add_argument('-s', help='-s argument help', nargs=3) ...: parser.add_argument('-k', help='-k argument help', nargs=3) ...
0
2016-08-17T23:26:48Z
[ "python", "namespaces", "argparse" ]
Python Tkinter visually display seating arrangements
39,007,368
<p>I am doing a school project, the purpose of the program is to sell tickets, the only problem i have is "Available and unavailable seats should be coloured/displayed differently and change when seat(s) are sold or returned.", i have a total of 250 seats, how to display them all on the screen? should i use a table or ...
0
2016-08-17T22:44:32Z
39,007,577
<p>I just approached this problem with a different scenario. You want some way to track the variables of each seat so you can come back and change the color. One way is to create a name for the tkinter widget, i.e. <code>seat1</code> Where <code>1</code> would change for the seat number. You probably want the layout si...
0
2016-08-17T23:06:58Z
[ "python", "tkinter" ]
offset randomforestclassifier scikit learn
39,007,386
<p>I wrote a program in python to use a machine learning algorithm to make predictions on data. I use the function RandomForestClassifier from Scikit Learn to create a random forest to make predictions. </p> <p>The purpose of the program is to predict if an unknown astrophysical source is a pulsar or an agn; so it tra...
0
2016-08-17T22:46:39Z
39,066,941
<p>Thanks for answering, guys.</p> <p>As suggested, I did plots of the predictors in the “test” data and in the “unknown” data; the distributions are generally similar, but I prefer to make histograms to say it. So I tried to do histograms, but I couldn’t both for the test and the unknown data, using:</p> <...
0
2016-08-21T17:29:23Z
[ "python", "machine-learning", "scikit-learn", "random-forest" ]
Run Django workers servers with supervisor?
39,007,410
<p>I'm trying to deploy my Django application with supervisor. When I launch supervisor it starts daphne correctly, however the worker servers are not launched.</p> <p>Here's a code sample of supervisor.conf (the workers block): </p> <pre><code>[program:runworker] command=python /home/django/environment/myproject/man...
3
2016-08-17T22:49:02Z
39,007,629
<p>You probably need to set the DJANGO_SETTINGS_MODULE environment variable.</p> <p>This answer provides an example: <a href="http://stackoverflow.com/a/26732916/4193">http://stackoverflow.com/a/26732916/4193</a></p>
1
2016-08-17T23:15:06Z
[ "python", "django", "django-channels" ]
How to take an integer array and convert it into other types?
39,007,441
<p>I'm currently trying to take integer arrays that actually represent other data types and convert them into the correct datatype.</p> <p>So for example, if I had the integer array [1196773188, 542327116], I discover that this integer array represents a string from some other function, convert it, and realize it repr...
-3
2016-08-17T22:54:02Z
39,008,382
<p>It seems that the struct module is the best way to go when converting between different types like this:</p> <pre><code>import struct bufferstr = "" dougarray = [1196773188, 542327116] for num in dougarray: bufferstr += struct.pack("i", num) print bufferstr # Result is 'DOUGLAS' </code></pre> <p>From thi...
2
2016-08-18T00:55:51Z
[ "python", "arrays", "python-2.7" ]
Best way to read a (ba)sh config file in python 2 or 3
39,007,551
<p>I have the the following config file </p> <pre><code># originally this was a (ba)sh config file, now read by python TEST=123 BAK=.bak # comment for next line TEST_2="cool spaced Value" MY_VAR2="space value" # With a Comment for the value </code></pre> <p>I have managed to read this with the following code</p> ...
0
2016-08-17T23:04:10Z
39,007,711
<p>Implementing a real shell interpreter in Python is beyond feasibility -- but you can cheat:</p> <pre><code>#!/usr/bin/env python import subprocess import os script=''' set -a # export all variable definitions to the environment # record prior names declare -A prior_names=( ) while IFS= read -r varname; do prior...
1
2016-08-17T23:25:33Z
[ "python", "bash", "config" ]
Running Jupyter with multiple Python and iPython paths
39,007,571
<p>I'd like to work with Jupyter notebooks, but have had difficulty doing basic imports (such as import matplotlib). I think this was because I have several user-managed python installations. For instance: </p> <pre><code>&gt; which -a python /usr/bin/python /usr/local/bin/python &gt; which -a ipython /Library/Framew...
5
2016-08-17T23:06:12Z
39,022,003
<p>This is fairly straightforward to fix, but it involves understanding three different concepts:</p> <ol> <li>How Unix/Linux/OSX use <code>$PATH</code> to find executables</li> <li>How Python installs and finds packages</li> <li>How Jupyter knows what Python to use</li> </ol> <p>For the sake of completeness, I'll tr...
16
2016-08-18T15:23:59Z
[ "python", "ipython", "jupyter", "jupyter-notebook" ]
web2py python - ImportError cannot import name
39,007,601
<p>I keep getting this error: <code>&lt;type 'exceptions.ImportError'&gt; cannot import name get_cert_infos</code>. I'm pretty sure I'm importing everything correctly. The file with the problem is <code>participant.py</code> and has:</p> <pre><code>from datetime import date from widgets import SelectOrAdd, LabelSorte...
0
2016-08-17T23:10:04Z
39,007,878
<p>Try double checking the spelling, I know it's dumb, but it happens.</p> <p>if it's not that, try writing this method in export </p> <pre><code>def hello_world(): print 'hello world' </code></pre> <p>then </p> <pre><code>import export export.hello_world() </code></pre> <p>if that works, it may be something ...
1
2016-08-17T23:43:56Z
[ "python", "python-2.7", "import", "web2py", "importerror" ]
Production version of Django?
39,007,610
<p>So I have been working on a Badgr server for another department. I have built it using Python 2.7 and django. From what I have heard Django is only used for dev websites.</p> <p>I want to take this project and convert it to run on something meant for a production environment. But I really have no idea how to procee...
-1
2016-08-17T23:11:38Z
39,007,736
<p>First of all, you should really be using a "long term support" version of Django, not 1.7.1. The current LTS release is 1.8.14; see <a href="https://www.djangoproject.com/download/" rel="nofollow">https://www.djangoproject.com/download/</a> for details.</p> <p>The Django documentation link you were given is just on...
0
2016-08-17T23:27:48Z
[ "python", "django", "apache", "production" ]
Production version of Django?
39,007,610
<p>So I have been working on a Badgr server for another department. I have built it using Python 2.7 and django. From what I have heard Django is only used for dev websites.</p> <p>I want to take this project and convert it to run on something meant for a production environment. But I really have no idea how to procee...
-1
2016-08-17T23:11:38Z
39,009,755
<p>I recommend you to use gunicorn and Nginx to run a Django project on your production server. Both are easy to google for official docs and recipes, and their combination is one of the fastest, as long as your code is not to slow. (Nginx+uWSGI is another good option, but a bit harder for beginners).</p> <p>Gunicorn ...
0
2016-08-18T03:57:32Z
[ "python", "django", "apache", "production" ]
Showing a few figures without stopping calculations in matplotlib
39,007,654
<p>Hi I would like to show a few figures in matplotlib without stopping calculations. I would like the figure to show up right after the calculations that concern it are finished for example:</p> <pre><code>import numpy as np import pylab as py x=np.linspace(0,50,51) y=x fig, axs = plt.subplots(1, 1) cs = axs.plot(x,...
0
2016-08-17T23:17:39Z
39,009,462
<p>The following code should do what you want. I did this in an IPython Notebook.</p> <pre><code>from IPython import display import matplotlib.pyplot as plt def stream_plot(iterable, plotlife=10.): for I in iterable: display.clear_output(wait=True) output = do_calculations_on_i(I) ...
0
2016-08-18T03:17:44Z
[ "python", "c++", "matplotlib" ]
How to turn my if statement into a while or for loop?
39,007,681
<p>So the program I'm trying to make is that an user can enter a path WHICH HAS TO BE CORRECT to continue. I thought that I would make a simple prompt to tell the user it is either a valid path or not.</p> <p>This is my prompt code:</p> <pre><code>if Path.find("Global") == -1: continue else: print "Not a vali...
0
2016-08-17T23:21:46Z
39,007,721
<p>Try this:</p> <pre><code>Path = raw_input("Please enter a valid Path") while Path.find("Global") == -1: print "This is not a valid Path." Path = raw_input("Please enter a valid Path") </code></pre>
-2
2016-08-17T23:26:23Z
[ "python" ]
How to turn my if statement into a while or for loop?
39,007,681
<p>So the program I'm trying to make is that an user can enter a path WHICH HAS TO BE CORRECT to continue. I thought that I would make a simple prompt to tell the user it is either a valid path or not.</p> <p>This is my prompt code:</p> <pre><code>if Path.find("Global") == -1: continue else: print "Not a vali...
0
2016-08-17T23:21:46Z
39,007,766
<pre><code>def get_path(): Path = raw_input("Please select the correct path: ") if Path.find("Global") == -1: # "Tell the user a message and tell the program to stop". print('{0} is not a correct path.'.format(Path)) return # "the program continues with another action." print('{0...
2
2016-08-17T23:30:45Z
[ "python" ]
How to turn my if statement into a while or for loop?
39,007,681
<p>So the program I'm trying to make is that an user can enter a path WHICH HAS TO BE CORRECT to continue. I thought that I would make a simple prompt to tell the user it is either a valid path or not.</p> <p>This is my prompt code:</p> <pre><code>if Path.find("Global") == -1: continue else: print "Not a vali...
0
2016-08-17T23:21:46Z
39,007,787
<p>You can break the loop unless your input matches condition, like this:</p> <pre><code>while True: if 'Global' in raw_input('Enter a valid path: '): continue else: print 'Not a valid path.' break </code></pre>
-1
2016-08-17T23:32:37Z
[ "python" ]
Exact string search in XML files?
39,007,743
<p>I need to search into some XML files (all of them have the same name, pom.xml) for the following text sequence exactly (also in subfolders), so in case somebody write some text or even a blank, I must get an alert:</p> <pre><code> &lt;!-- | Startsection |--&gt; &lt;!-- | Endsection ...
-1
2016-08-17T23:28:20Z
39,007,836
<p>The "|()" characters must be escaped, also add re.MULTILINE to the regex.</p> <p><code>comment=re.compile(r"&lt;!--\s+\| Start of user code \(user defined modules\)\s+\|--&gt;\s+&lt;!--\s+\| End of user code\s+\|--&gt;", re.MULTILINE)</code></p> <p>Edit: you can also place newline characters in your regex expressi...
0
2016-08-17T23:38:11Z
[ "python", "xml" ]
Exact string search in XML files?
39,007,743
<p>I need to search into some XML files (all of them have the same name, pom.xml) for the following text sequence exactly (also in subfolders), so in case somebody write some text or even a blank, I must get an alert:</p> <pre><code> &lt;!-- | Startsection |--&gt; &lt;!-- | Endsection ...
-1
2016-08-17T23:28:20Z
39,015,211
<p>Don't parse a XML file with regular expression. <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">The best Stackoverflow answer ever can explain you why</a></p> <p>You can use BeautifulSoup to help on that task</p> <p>Look how simple would b...
1
2016-08-18T09:58:15Z
[ "python", "xml" ]
Can't find ghostscript in NLTK?
39,007,755
<p>I'm playing around with NLTK, when I try to use the chunk module </p> <pre><code>enter import nltk as nk Sentence = "Betty Botter bought some butter, but she said the butter is bitter, I f I put it in my batter, it will make my batter bitter." tokens = nk.word_tokenize(Sentence) tagged = nk.pos_tag(tokens) entiti...
1
2016-08-17T23:30:00Z
39,028,327
<p><strong>In short</strong>:</p> <p>Instead of <code>&gt;&gt;&gt; entities</code>, do this:</p> <pre><code>&gt;&gt;&gt; print entities.__repr__() </code></pre> <p>Or:</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; from nltk import word_tokenize, pos_tag, ne_chunk &gt;&gt;&gt; path_to_gs = "C:\Program Files\gs\...
1
2016-08-18T22:16:03Z
[ "python", "environment-variables", "ipython", "nltk", "ghostscript" ]
PyQt - Tabbed dialog not displaying embedded widgets
39,007,773
<p>I am trying to create a dialog with three tabs using PyQt. However, I am annoyed because although the dialog is displayed, the embedded widgets are not displayed!. I suppose this is a very simple problem with a correspondingly very simple solution, but I am struck! Can anyone give a hint? Thanks in advance!</p> <p>...
0
2016-08-17T23:31:48Z
39,007,926
<p>here is my solution to the problem</p> <p>On the <strong>init</strong> method, I declared a layout, then added the 'tabWidget' widget to that layout and set that layout as the layout of your QDialog.</p> <pre><code>def __init__(self, parent = None): super(TabbedDialog, self).__init__(parent) self.tabWidget = ...
1
2016-08-17T23:50:03Z
[ "python", "pyqt4", "tabwidget" ]
jpype accessing java mehtod/variable whose name is reserved name in python
39,007,823
<p>Any idea how this can be done? ie, if we have a variable defined in java as below</p> <p><code>public Class Foo { String pass = "foo"; }</code></p> <p>how can I access this via jpype since pass is a reserved keyword? I tried <code>getattr(Jpype.JClass(Foo)(), "pass")</code> but it fails to find the attribute na...
0
2016-08-17T23:37:01Z
39,007,952
<p>unfortunally Fields or methods conflicting with a python keyword can’t be accessed</p>
0
2016-08-17T23:52:18Z
[ "java", "python", "type-conversion", "reserved-words", "jpype" ]
jpype accessing java mehtod/variable whose name is reserved name in python
39,007,823
<p>Any idea how this can be done? ie, if we have a variable defined in java as below</p> <p><code>public Class Foo { String pass = "foo"; }</code></p> <p>how can I access this via jpype since pass is a reserved keyword? I tried <code>getattr(Jpype.JClass(Foo)(), "pass")</code> but it fails to find the attribute na...
0
2016-08-17T23:37:01Z
39,027,662
<p>Figured out that jpype appends an <code>"_"</code> at the end for those methods/fields in its source code. So you can access it by Jpype.JClass("Foo").pass_</p> <p>Wish it's documented somewhere </p>
0
2016-08-18T21:17:35Z
[ "java", "python", "type-conversion", "reserved-words", "jpype" ]
How to send a Python Variable to shell commands?
39,007,826
<p>I am trying to send a variable from my code in Python to a shell command in Ubuntu. Can anyone help me with how to do that? Currently, I have</p> <pre><code>import os s=5 command = os.popen('stress -c 5 -i 1 -m 1 --vm-bytes 128M -t s') </code></pre> <p>I want to send the <code>s</code> variable to this command ins...
0
2016-08-17T23:37:18Z
39,007,855
<p>This is a string replacement operation which you can get all the info <a href="https://docs.python.org/2/library/stdtypes.html#string-formatting" rel="nofollow">here</a>.</p> <p>Or you can just concatenate the strings together. (<a href="http://www.pythonforbeginners.com/concatenation/string-concatenation-and-forma...
-2
2016-08-17T23:40:40Z
[ "python", "bash", "shell" ]
How to send a Python Variable to shell commands?
39,007,826
<p>I am trying to send a variable from my code in Python to a shell command in Ubuntu. Can anyone help me with how to do that? Currently, I have</p> <pre><code>import os s=5 command = os.popen('stress -c 5 -i 1 -m 1 --vm-bytes 128M -t s') </code></pre> <p>I want to send the <code>s</code> variable to this command ins...
0
2016-08-17T23:37:18Z
39,007,863
<p>I'm assuming the 's' in your command string is what you want to assume the value of your variable 's'? All you need to do is this:</p> <pre><code>command = os.popen('stress -c 5 -i 1 -m 1 --vm-bytes 128M -t ' + str(s)) </code></pre> <p>If I misread it and you are trying to replace the 5, it is basically the same<...
0
2016-08-17T23:41:43Z
[ "python", "bash", "shell" ]
How to send a Python Variable to shell commands?
39,007,826
<p>I am trying to send a variable from my code in Python to a shell command in Ubuntu. Can anyone help me with how to do that? Currently, I have</p> <pre><code>import os s=5 command = os.popen('stress -c 5 -i 1 -m 1 --vm-bytes 128M -t s') </code></pre> <p>I want to send the <code>s</code> variable to this command ins...
0
2016-08-17T23:37:18Z
39,007,922
<p>Use the standard subprocess module:</p> <pre><code>import subprocess s = 5 cmd = ['stress', '-c', '5', '-i', '1', '-m', '1', '--vm-bytes', '128M', '-t', str(s)] subprocess.call(cmd) </code></pre> <p>Using the subprocess module, allows each argument to be passed separately and distinctly. You only have to co...
4
2016-08-17T23:49:37Z
[ "python", "bash", "shell" ]
Python webscraping script on AWS keeps failing after 1.5 hours/fetching 10,000 xmls
39,007,827
<p>I wrote a Python script that runs from an AWS instance and fetches xml files off an S3 server to place in a folder on the instance. The script works fine, except for the fact that after about an hour and a half, or about the time it takes to fetch 10,000-15,000 xmls, I get the following error:</p> <pre><code>HTTP E...
1
2016-08-17T23:37:30Z
39,009,701
<p>I don't know the first thing about python, but the problem seems apparent enough, all the same.</p> <p>When the S3 error occurs, you <a href="https://docs.python.org/3/reference/simple_stmts.html#continue" rel="nofollow"><code>continue</code></a>, which skips the rest of the instructions within the closest loop, an...
2
2016-08-18T03:49:05Z
[ "python", "linux", "amazon-web-services", "amazon-s3", "nohup" ]
Dynamically Update WTForm with SQL-Alchemy query
39,007,862
<p>I am trying to have a form dynamically update by retrieving information from my table then display one of the columns in a SelectField. When I type an asset tag, select a Task Title and hit submit simply nothing happens.</p> <p><strong>EDIT: I should add the form is updating fine - all my selections are there and b...
0
2016-08-17T23:41:37Z
39,008,940
<p>Try the following. <a href="http://hastebin.com/obojivosar.py" rel="nofollow">http://hastebin.com/obojivosar.py</a></p> <p>You don't need to check <code>if request.method == "POST":</code> I simply moved the populating of the choices to the bottom of the view. I never touch the form before <code>validate_on_submit<...
1
2016-08-18T02:15:31Z
[ "python", "flask", "sqlalchemy", "flask-wtforms" ]
Dynamically Update WTForm with SQL-Alchemy query
39,007,862
<p>I am trying to have a form dynamically update by retrieving information from my table then display one of the columns in a SelectField. When I type an asset tag, select a Task Title and hit submit simply nothing happens.</p> <p><strong>EDIT: I should add the form is updating fine - all my selections are there and b...
0
2016-08-17T23:41:37Z
39,009,284
<p>I found the issue,</p> <p>WTForms wants to handle the returned data from the query as a string, however the IDs (integers) obviously are not strings, which must be why validation fails.</p> <p>By adding <code>coerce=int</code> to my <code>task_title</code> object in my form definition WTForms now knows to handle i...
0
2016-08-18T02:55:43Z
[ "python", "flask", "sqlalchemy", "flask-wtforms" ]
getting article text using xpath but omit some tags
39,007,866
<p>I'm trying to parse (article) text only using xpath.</p> <p>I want to get all text which are direct children and all nested descendants text of a node, except for the following nodes/tags: <code>&lt;script&gt;, &lt;ul class="pager pagenav"&gt;, &lt;style&gt;</code>.</p> <p>Example html to match using xpath:</p> <...
1
2016-08-17T23:42:25Z
39,007,929
<p>Use the <a href="https://www.w3.org/TR/xpath/#location-paths" rel="nofollow"><code>child::node()</code></a> to match both regular children and text child nodes: </p> <blockquote> <p><code>child::node()</code> selects all the children of the context node, whatever their node type</p> </blockquote> <p><code>self::...
1
2016-08-17T23:50:24Z
[ "python", "xpath" ]
Python array manipulation, pi*[n+1]^2 - pi*[n]^2
39,007,880
<p>I'm writing a script to subtract the inside cylinder from the outside cylinder for multiple cylinders.</p> <p>for example: <code>x = pi*[n+1]**2 - pi*[n]**2</code> </p> <p>However I'm not sure how to get n to change each time from for example 1 - 4, i want to be able to change n and have the code run through the n...
1
2016-08-17T23:44:22Z
39,007,912
<p>Try this:</p> <pre><code>for n in range(4): # 0 to 3 x = pi*[n+1]**2 - pi*[n]**2 #[1] - [0], [2] - [1] and so on... # doSomething </code></pre> <p>If <code>[n]</code> is an index of an array with name <code>num</code>, replace <code>[n]</code> with <code>num[n]</code> like so:</p> <pre><code>for n in ran...
2
2016-08-17T23:48:25Z
[ "python", "arrays", "loops" ]
Python array manipulation, pi*[n+1]^2 - pi*[n]^2
39,007,880
<p>I'm writing a script to subtract the inside cylinder from the outside cylinder for multiple cylinders.</p> <p>for example: <code>x = pi*[n+1]**2 - pi*[n]**2</code> </p> <p>However I'm not sure how to get n to change each time from for example 1 - 4, i want to be able to change n and have the code run through the n...
1
2016-08-17T23:44:22Z
39,007,951
<p>I think this should provide the results you are looking for:</p> <pre><code>rs = 0.2 # Radius of first cylinder rc = 0.4 # Radius of each cylinder (concrete) rg = 1 # Radius of each cylinder (soil) BW = 3 ...
-1
2016-08-17T23:52:15Z
[ "python", "arrays", "loops" ]
Python array manipulation, pi*[n+1]^2 - pi*[n]^2
39,007,880
<p>I'm writing a script to subtract the inside cylinder from the outside cylinder for multiple cylinders.</p> <p>for example: <code>x = pi*[n+1]**2 - pi*[n]**2</code> </p> <p>However I'm not sure how to get n to change each time from for example 1 - 4, i want to be able to change n and have the code run through the n...
1
2016-08-17T23:44:22Z
39,008,152
<p>How about this:</p> <pre><code>for i, value in enumerate(n[:-1]): print(np.pi * (n[i + 1] ** 2) - np.pi * (value ** 2)) </code></pre> <p>For me it prints:</p> <pre><code>0.157079632679 0.219911485751 0.628318530718 2.0106192983 </code></pre> <p>Perhaps you want this:</p> <pre><code>&gt;&gt;&gt; values = [np...
1
2016-08-18T00:21:31Z
[ "python", "arrays", "loops" ]
Python array manipulation, pi*[n+1]^2 - pi*[n]^2
39,007,880
<p>I'm writing a script to subtract the inside cylinder from the outside cylinder for multiple cylinders.</p> <p>for example: <code>x = pi*[n+1]**2 - pi*[n]**2</code> </p> <p>However I'm not sure how to get n to change each time from for example 1 - 4, i want to be able to change n and have the code run through the n...
1
2016-08-17T23:44:22Z
39,008,303
<p>Since your numbers are in a numpy array, it's much more efficient to use broadcast operations across the array (or slices of it), rather than writing a explicit loop and operating on individual items. This is the main reason to use numpy!</p> <p>Try something like this:</p> <pre><code># compute your `n` array as b...
2
2016-08-18T00:44:20Z
[ "python", "arrays", "loops" ]
Removing List view for ArrayField Django
39,007,892
<p>How would I display the ArrayField in a template without the quotes and brackets. currently it looks like ['django']. I would like to have it look like: django</p> <p>Any suggestions would be great. </p>
0
2016-08-17T23:46:15Z
39,009,360
<p>If you need only the first value:</p> <pre><code>{{ object.arrya_field_name.0 }} </code></pre> <p>or with filter</p> <pre><code>{{ object.arrya_field_name|first }} </code></pre> <p>If you need all values, use loop:</p> <pre><code>{% for item in object.arrya_field_name %} {{ item }} {% endfor %} </code></pre...
0
2016-08-18T03:05:37Z
[ "python", "django" ]
5 most common words in text file python
39,007,968
<p>i have this code to search for the 5 most common words in a text file but i cant use the sort and reverse functions at the end of the program... how would i avoid using them?</p> <pre><code>words = open('romeo.txt').read().lower().split() uniques = [] for word in words: if word not in uniques: uniques.appen...
0
2016-08-17T23:53:57Z
39,008,023
<p>Use the <code>sorted()</code> function and save the results in a variable then reverse it like this:</p> <pre><code>counts = sorted(counts, reverse=True) </code></pre> <p>That line of code will sort the list and reverse it for you and save the results in counts. Then you can use your count as required.</p>
0
2016-08-18T00:00:44Z
[ "python" ]
5 most common words in text file python
39,007,968
<p>i have this code to search for the 5 most common words in a text file but i cant use the sort and reverse functions at the end of the program... how would i avoid using them?</p> <pre><code>words = open('romeo.txt').read().lower().split() uniques = [] for word in words: if word not in uniques: uniques.appen...
0
2016-08-17T23:53:57Z
39,008,054
<pre><code>from collections import Counter c = Counter(words) c.most_common(5) </code></pre>
4
2016-08-18T00:06:14Z
[ "python" ]
Parsing mutual fund JSON data
39,008,044
<p>I am trying to pull out data from interactive chart and I have the JSON file from this link</p> <p><a href="https://www.tadawul.com.sa/Charts/MutualFundChartDataDownloader?actionTarget=mutualFundChartData&amp;mutualFundSymbol=006038&amp;format=json" rel="nofollow">http://www.tadawul.com.sa/Charts/MutualFundChartDat...
0
2016-08-18T00:04:36Z
39,008,675
<p>Running your (slightly modified) code shows the website data you are actually getting.</p> <pre><code>import urllib htmltext = urllib.urlopen("https://www.tadawul.com.sa/Charts/MutualFundChartDataDownloader?actionTarget=mutualFundChartData&amp;mutualFundSymbol=006038&amp;format=json") print htmltext.read() </code>...
0
2016-08-18T01:37:18Z
[ "python", "json", "finance", "stocks" ]
R and Python in one Jupyter notebook
39,008,069
<p>Is it possible to run R and Python code in the same Jupyter notebook. What are all the alternatives available?</p> <ol> <li>Install r-essentials and create R notebooks in Jupyter.</li> <li>Install rpy2 and use rmagic functions.</li> <li>Use a beaker notebook.</li> </ol> <p>Which of above 3 options is reliable to r...
2
2016-08-18T00:09:03Z
39,008,107
<p>It will be hard for you to use both R and Python syntax in the same notebook, mostly because the underlying representation of objects in the two languages are different. That said, there is a project that does try to allow conversion of objects and different languages in the same notebook: <a href="http://beakernote...
0
2016-08-18T00:15:33Z
[ "python", "python-2.7", "ipython", "jupyter-notebook" ]
Retrieve image from method called by URL in python
39,008,074
<p>I'm trying to retrieve an image that is returned through a given URL using python, for example this one:</p> <p><a href="http://fundamentus.com.br/graficos3.php?codcvm=2453&amp;tipo=108" rel="nofollow">http://fundamentus.com.br/graficos3.php?codcvm=2453&amp;tipo=108</a></p> <p>I am trying to do this by using urlli...
1
2016-08-18T00:09:42Z
39,008,140
<p>You need to use a session which you can do with <a href="http://docs.python-requests.org/en/master/" rel="nofollow">requests</a>:</p> <pre><code>import requests with requests.Session() as s: s.get("http://fundamentus.com.br/graficos.php?papel=CMIG4&amp;tipo=2") with open("out.png", "wb") as f: f.wri...
2
2016-08-18T00:20:07Z
[ "python", "python-2.7", "urllib" ]
Retrieve image from method called by URL in python
39,008,074
<p>I'm trying to retrieve an image that is returned through a given URL using python, for example this one:</p> <p><a href="http://fundamentus.com.br/graficos3.php?codcvm=2453&amp;tipo=108" rel="nofollow">http://fundamentus.com.br/graficos3.php?codcvm=2453&amp;tipo=108</a></p> <p>I am trying to do this by using urlli...
1
2016-08-18T00:09:42Z
39,008,373
<p>While more verbose than @PadraicCunningham response. This should also do the trick. I'd run into a similar problem (host would only support certain browsers), so i had to start using urllib2 instead of just urllib. pretty powerful and is a module which comes with python.</p> <p>Basically, you capture all the inform...
0
2016-08-18T00:53:14Z
[ "python", "python-2.7", "urllib" ]
"E1101" - Instance of "Class" has no "method" member
39,008,121
<p>I have classes organized like so:</p> <pre><code>class One: def funcOne(self): doSomething() class Two(One): def funcTwo(self): self.funcOne() </code></pre> <p>When I ran this, it worked, and Python's inheritance model allows for <code>Two</code> to be able to call <code>funcOne</code>. </...
1
2016-08-18T00:18:19Z
39,008,169
<p>call <code>self.funcOne()</code></p> <p>also class One should inherit from object</p> <pre><code>class One(object): ... </code></pre>
0
2016-08-18T00:23:18Z
[ "python", "python-2.7", "pylint" ]
"E1101" - Instance of "Class" has no "method" member
39,008,121
<p>I have classes organized like so:</p> <pre><code>class One: def funcOne(self): doSomething() class Two(One): def funcTwo(self): self.funcOne() </code></pre> <p>When I ran this, it worked, and Python's inheritance model allows for <code>Two</code> to be able to call <code>funcOne</code>. </...
1
2016-08-18T00:18:19Z
39,008,272
<p>It turns out that my version of <code>pylint</code> was severely out of date. I was running version <code>1.1.0</code>, and updated to the newest version <code>1.6.4</code>, and the warnings were gone!</p> <p>I assume this is a bug in <code>pylint</code> that was fixed between the versions</p>
0
2016-08-18T00:40:32Z
[ "python", "python-2.7", "pylint" ]
how to avoid typeerror while returning result from php to python
39,008,124
<p>I have the following code in php and python,I return $result from php to a python handler and running into below error..how should I return in python so that I don't run into this error?</p> <p>php</p> <pre><code> $result = [ "TRIGGER_STATUS" =&gt; "SUCCESS", "PW_LINK" =&gt; "https://pw.company.co...
0
2016-08-18T00:18:32Z
39,009,452
<p>The issue is with <code>kv[1]['Order']</code> being passed to the <code>lambda</code> function being passed to <code>key</code>. Assuming the dict which Python has after doing <code>json.decode()</code> is this:</p> <pre><code>&gt;&gt;&gt; result = {'result': { ... "TRIGGER_STATUS": "SUCCESS", ...
1
2016-08-18T03:16:35Z
[ "php", "python" ]
Plotting lines over an image using the same projection
39,008,262
<p>I want to make a plot using .fits files (astronomical images) and I am experiencing two issues which I think they are related:</p> <p>Using this example from astropy:</p> <pre><code>from matplotlib import pyplot as plt from astropy.io import fits from astropy.wcs import WCS from astropy.utils.data import download_...
1
2016-08-18T00:39:12Z
39,020,724
<p>It is very easy to plot given coordinates. All you have to do is apply a <a href="http://wcsaxes.readthedocs.io/en/latest/overlays.html#world-coordinates" rel="nofollow"><code>transform</code></a>.</p> <p>I copied your example and added comments where I changed something and why.</p> <pre><code>from matplotlib imp...
3
2016-08-18T14:23:57Z
[ "python", "image", "matplotlib", "astronomy", "astropy" ]
python dictionary (unordered selections key)
39,008,296
<p>I have a question about dic.has_key</p> <p>my code is </p> <pre><code>def insertToDic(dic,comSick): for datum in comSick : if dic.has_key(datum): dic[datum]+=1 else : dic[datum] =1 </code></pre> <p>if comSick is</p> <pre><code>comSick=[(A,B),(A,...
-1
2016-08-18T00:43:28Z
39,008,356
<p>Try this:</p> <pre><code>def insertToDic(dic,comSick): for datum in comSick : sorted_datum = tuple(sorted(datum)) dic[sorted_datum] = dic.get(sorted_datum, 0) + 1 comSick=[('A', 'B'), ('A', 'C'), ('B', 'A')] dic = {} insertToDic(dic, comSick) print(dic) </code></pre> <p>I made some changes. I...
1
2016-08-18T00:50:36Z
[ "python", "dictionary", "unordered" ]
python dictionary (unordered selections key)
39,008,296
<p>I have a question about dic.has_key</p> <p>my code is </p> <pre><code>def insertToDic(dic,comSick): for datum in comSick : if dic.has_key(datum): dic[datum]+=1 else : dic[datum] =1 </code></pre> <p>if comSick is</p> <pre><code>comSick=[(A,B),(A,...
-1
2016-08-18T00:43:28Z
39,010,406
<p>Use</p> <p>frozenset(('A', 'B')) </p> <p>as the key.</p>
1
2016-08-18T05:12:36Z
[ "python", "dictionary", "unordered" ]
Error in Vim: "YouCompleteMe unavailable: This package should not be accessible on Python 3"
39,008,318
<p>When I attempt to use the YouCompleteMe plugin in vim, I get the following error: </p> <p><code>YouCompleteMe unavailable: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted</code></p> <p>However, I o...
2
2016-08-18T00:46:22Z
39,009,346
<p>It sounds as if you are using using python 3 inside virtualenv. As far as vim is concerned, you are running python 3 which is not supported by ycm</p> <p><a href="https://github.com/Valloric/YouCompleteMe/issues/1140" rel="nofollow">https://github.com/Valloric/YouCompleteMe/issues/1140</a></p> <p>A workaround woul...
0
2016-08-18T03:04:07Z
[ "python", "python-3.x", "vim", "virtualenv", "youcompleteme" ]
Error in Vim: "YouCompleteMe unavailable: This package should not be accessible on Python 3"
39,008,318
<p>When I attempt to use the YouCompleteMe plugin in vim, I get the following error: </p> <p><code>YouCompleteMe unavailable: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted</code></p> <p>However, I o...
2
2016-08-18T00:46:22Z
39,022,588
<p>Looks like it's a bug:</p> <p><a href="https://github.com/Valloric/ycmd/pull/578" rel="nofollow">https://github.com/Valloric/ycmd/pull/578</a></p> <blockquote> <p>In PR #448, I made the assumption that the site-packages paths are always placed after the standard library path so that if we insert the python-futur...
1
2016-08-18T15:51:07Z
[ "python", "python-3.x", "vim", "virtualenv", "youcompleteme" ]
How to transform Dask.DataFrame to pd.DataFrame?
39,008,391
<p>How can I transform my resulting dask.DataFrame into pandas.DataFrame (let's say I am done with heavy lifting, and just want to apply sklearn to my aggregate result)?</p>
0
2016-08-18T00:56:53Z
39,008,635
<p>You can call the .compute() method to transform a dask.dataframe to a pandas dataframe:</p> <pre><code>df = df.compute() </code></pre>
3
2016-08-18T01:32:58Z
[ "python", "pandas", "dask" ]
Two strings and unicodes that are exactly the same do not return true when evaluated with each other
39,008,407
<p>This makes no sense to me. The ultimate goal of what I need to do is break down a very long string into respective words and compare each word with something.. I am only posting a snippet of the total output not to overwhelm and clutter this post with unnecessary data.</p> <p>I created a simple setup to compare if ...
0
2016-08-18T00:59:37Z
39,008,478
<p>You need to use <code>==</code> to check for equality instead of <code>is</code> which checks if they occupy the same memory location.</p> <pre><code>s1 = 'abc' * 10000 s2 = 'abc' * 10000 &gt;&gt;&gt; id(s1) 4480540672 &gt;&gt;&gt; id(s2) 4480570880 &gt;&gt;&gt; s1 is s2 False &gt;&gt;&gt; s1 == s2 True </code>...
0
2016-08-18T01:10:56Z
[ "python", "unicode", "formatting" ]
How do I launch Powershell locally on NanoServer?
39,008,462
<p>I have created NS image with 'Development' switch using Windows 2016 Technical Preview 5. I am deploying the NS image onto a physical machine.I want to run Python interactive shell on local Powershell but it appears that there is no local PS console on NanoServer.</p>
0
2016-08-18T01:08:11Z
39,020,077
<p>Nano Server is designed to be administered remotely, the local 'console' only allows you to set firewall rules and network config.</p> <p>You'll need to do everything via a remote session with Nano Server. If that's not suitable for you the only option is to move to the full Server 2016 OS instead as this has the s...
0
2016-08-18T13:54:35Z
[ "python", "powershell", "window-server", "nano-server" ]
When to use a database depending on need to filter/sort data?
39,008,463
<p>I'm currently building a Flask web app, and I am trying to figure out if I need a database for the information that I'm displaying. I have looked at other posts, and found that depending on the size of data, it could better to just use objects instead. I started using objects, however I need to have the ability to f...
0
2016-08-18T01:08:42Z
39,008,499
<p>It might be worthwhile taking a look at the following. <a href="http://programmers.stackexchange.com/questions/190482/why-use-a-database-instead-of-just-saving-your-data-to-disk">http://programmers.stackexchange.com/questions/190482/why-use-a-database-instead-of-just-saving-your-data-to-disk</a></p> <p>Reiterating ...
0
2016-08-18T01:14:16Z
[ "python", "mysql" ]
Print function in python giving strings with brackets?
39,008,491
<p>When I print a statement in python it is given in the form ['Hello World']. I'm not certain why and am looking to fix this problem and I believe it may be related to the formatting of the code.</p> <pre><code>query = input("Enter your query: ").lower() brands = ["apple", "android", "windows"] brand = set(brands).in...
0
2016-08-18T01:13:24Z
39,008,621
<p>Curly braces '{' and '}' are used for sets and dictionaries.</p> <pre><code># e.g. print(set(brands)) {'apple', 'android', 'windows'} </code></pre> <p>In your case you create a set by intersecting set(brands) with the query, then you convert the set to a string, which will include the curly braces.</p> <p>One sim...
0
2016-08-18T01:30:17Z
[ "python", "arrays", "string", "brackets" ]
How can I redirect without revealing URI fields in flask?
39,008,497
<p>I would like to make a post request sending a username and password to a page named showInternal; I currently accomplish this via:</p> <pre><code>username = "johnsmith" password = "password1234" return redirect(url_for('showInternal', username=username, password=password)) </code></pre> <p>for the redirect and</p>...
0
2016-08-18T01:13:46Z
39,008,563
<p>Import the JSON and requests module: <code>import json, request</code></p> <p>Use the request module to send a post request:</p> <pre><code>requests.post('&lt;full-url&gt;', data=json.dumps({'username': 'johnsmith', 'password': 'password1234'})) </code></pre> <p>Then edit your route:</p> <pre><code>@app.route('...
0
2016-08-18T01:22:02Z
[ "python", "redirect", "post", "flask" ]
Most efficient way to modify variables within a custom grammar?
39,008,505
<p>I'm working with a propriety driving simulator which generates "scenario" files in a customised version of <a href="http://www.scilab.org/" rel="nofollow">Scilab</a>. I am provided a single 11,000 line long "master" file, and from this I need to replace certain values to generate <em>n</em> versions of the scenario....
1
2016-08-18T01:15:22Z
39,019,639
<p>May be you can transform your file to a Scilab Script which generate a file with the new values.</p> <p>The transformation is quite simple First in Scilab (to be done once)</p> <pre><code> T=mgetl("Task_file");mputl(sci2exp(T),"Task_file.sce") </code></pre> <p>For each experiment, with a text editor modify the ge...
0
2016-08-18T13:34:09Z
[ "python", "grammar", "scilab" ]
Python statefull socket programming
39,008,558
<p>I have a client-server socket python script. I want to keep the state of each connection, such that i identify whether or not the client is its first connection. I unsuccessfully wrote the following code:</p> <p>` </p> <pre><code>import socket,sys,SocketServer from threading import Thread class EchoReq...
0
2016-08-18T01:21:39Z
39,009,212
<p>The threaded socket server creates a new instance of <code>EchoRequestHandler</code> for each connection, so storing the clients in that class instance would not be correct.</p> <p>Each request handler instance has a <code>self.server</code> member that knows its server, so you can store it there instead.</p> <p>B...
1
2016-08-18T02:47:49Z
[ "python", "sockets", "python-sockets" ]
Count vectorizing into bigrams for one document, and then taking the average
39,008,652
<p>I'm trying to write a function that takes in one document, count vectorizes the bigrams for that document. This shouldn't have any zeroes, as I'm only doing this to one document at a time. Then I want to take the average of those numbers to get a sense of bigram repetition.</p> <p>Any problems with this code?</p> ...
0
2016-08-18T01:35:06Z
39,008,774
<p><code>CountVectorizer</code> expects a corpus, while you are giving a single doc. Just wrap your doc in a <code>list</code>. E.g:</p> <pre><code>model = bigram_vectorizer.fit_transform([x]) </code></pre>
1
2016-08-18T01:51:05Z
[ "python", "nlp", "scikit-learn" ]
i am getting need more than one value to unpack value error
39,008,742
<p>Help me out..This is my pgm</p> <pre><code>from sys import argv script, first, second, third = argv print ("the script is:", script) print("the first variable is:", first) print("the second variable is:", second) print ("the third variable is:", third) </code></pre> <p>=============================================...
-1
2016-08-18T01:46:14Z
39,008,780
<p>That code works just <em>fine,</em> assuming that you actually <em>give</em> it three arguments to unpack, as with:</p> <pre><code>c:\pax&gt; python yourProg.py A B C the script is: yourProg.py the first variable is: A the second variable is: B the third variable is: C </code></pre> <p>The problem occurs when you ...
1
2016-08-18T01:51:35Z
[ "python" ]
i am getting need more than one value to unpack value error
39,008,742
<p>Help me out..This is my pgm</p> <pre><code>from sys import argv script, first, second, third = argv print ("the script is:", script) print("the first variable is:", first) print("the second variable is:", second) print ("the third variable is:", third) </code></pre> <p>=============================================...
-1
2016-08-18T01:46:14Z
39,008,874
<p><code>argv</code> is a list:</p> <pre><code>&gt;&gt;&gt; from sys import argv &gt;&gt;&gt; type(argv) &lt;type 'list'&gt; </code></pre> <p>So you're attempting to do a conversion from a list to a tuple, which only works if the number of elements in the tuple <strong>exactly</strong> matches the list length:</p> <...
2
2016-08-18T02:05:06Z
[ "python" ]
Create Nested JSON from Pandas for Org Chart
39,008,860
<p>I'm trying to create a nested JSON object from a hierarchical DataFrame (python 3.5) to feed into JavaScript to render an Org Chart. I'm essentially trying to create the structure found in the answer of this question: <a href="http://stackoverflow.com/questions/30926539/organization-chart-tree-online-dynamic-collap...
0
2016-08-18T02:03:15Z
39,021,065
<p>Consider filtering out dataframe by Level and converting dfs to dictionary with pandas <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_dict.html" rel="nofollow"><code>to_dict()</code></a> which are continually rolled into one list across levels. Below defined function walks from la...
0
2016-08-18T14:38:03Z
[ "python", "json", "python-3.x" ]
How to remove apostrophes and parathenses in output?
39,009,098
<pre><code>a=str(input("Enter string: ")) b=str(input("Enter another: ")) def switch(x, y): x, y = y, x return x, y print (switch(a, b)) </code></pre> <p>output is for example: ('there', 'hello') I want to remove parathenses and ''</p>
0
2016-08-18T02:34:02Z
39,009,123
<p>Assuming you want to keep the output of your function the same (a tuple), you can use use <a href="https://docs.python.org/3/library/stdtypes.html#str.join" rel="nofollow"><code>join</code></a> to print the tuple separated by a space:</p> <pre><code>a = input("Enter string: ") b = input("Enter another: ") def swit...
1
2016-08-18T02:37:48Z
[ "python", "python-3.x", "output" ]
How to remove apostrophes and parathenses in output?
39,009,098
<pre><code>a=str(input("Enter string: ")) b=str(input("Enter another: ")) def switch(x, y): x, y = y, x return x, y print (switch(a, b)) </code></pre> <p>output is for example: ('there', 'hello') I want to remove parathenses and ''</p>
0
2016-08-18T02:34:02Z
39,011,001
<p>The return value of <code>switch</code> is a tuple of 2 items (a pair), which is passed to the <code>print</code> function as a single argument. And <code>print</code> converts each of its arguments to a string with implicit <code>str</code>, and the <code>('', '')</code> come from the string representation of this ...
1
2016-08-18T06:09:02Z
[ "python", "python-3.x", "output" ]
Iterating Over Every Item in a Series in Pandas With A Custom Function
39,009,122
<p>I have a dataframe in Pandas that lists its information like this:</p> <pre><code> Player Year Height 1 Stephen Curry 2015-16 6-3 2 Mirza Teletovic 2015-16 6-10 3 C.J. Miles 2015-16 6-7 4 Robert Covington 2015-16 6-9 </code></pre> <p>Right now data['Height'] stores its values...
1
2016-08-18T02:37:45Z
39,009,170
<p>You can use apply on the <code>Height</code> column after it gets splitted into lists and pass a lambda function to it for conversion:</p> <pre><code>df['Height'] = df.Height.str.split("-").apply(lambda x: int(x[0]) * 12 + int(x[1])) df # Player Year Height # 1 Stephen Curry 2015-16 ...
1
2016-08-18T02:44:12Z
[ "python", "pandas" ]
Iterating Over Every Item in a Series in Pandas With A Custom Function
39,009,122
<p>I have a dataframe in Pandas that lists its information like this:</p> <pre><code> Player Year Height 1 Stephen Curry 2015-16 6-3 2 Mirza Teletovic 2015-16 6-10 3 C.J. Miles 2015-16 6-7 4 Robert Covington 2015-16 6-9 </code></pre> <p>Right now data['Height'] stores its values...
1
2016-08-18T02:37:45Z
39,009,308
<pre><code>df['feet'], df['inches'] = zip(*df.Height.str.split('-')) df['feet'] = df.feet.astype(int) df['inches'] = df.inches.astype(float) df['height_inches'] = df.feet * 12 + df.inches &gt;&gt;&gt; df Player Year Height feet inches height_inches 1 Stephen Curry 2015-16 6-3 6 ...
1
2016-08-18T02:59:00Z
[ "python", "pandas" ]
Scraping eBay featured collections for product page links
39,009,134
<p>I'm attempting to build a web scraping tool using Python and BeautifulSoup that enters an eBay Featured Collection and retrieves the URLs of all the products within the collection (most collections have 17 products, although some have a few more or less). Here's the URL for the collection I attempt to scrape in my c...
1
2016-08-18T02:38:42Z
39,017,753
<p>The last few are generated through an <em>ajax</em> request to <em><a href="http://www.ebay.com/cln/_ajax/2/ebayhomeeditor/324079803018" rel="nofollow">http://www.ebay.com/cln/_ajax/2/ebayhomeeditor/324079803018</a></em>:</p> <p><a href="http://i.stack.imgur.com/2gENp.png" rel="nofollow"><img src="http://i.stack.im...
0
2016-08-18T12:03:15Z
[ "python", "xml", "web-scraping", "beautifulsoup", "ebay" ]
Download a picture from certain URL with Python
39,009,195
<p>I learned how to download a picture from a certain URL with python as:</p> <pre><code>import urllib imgurl="http://www.digimouth.com/news/media/2011/09/google-logo.jpg" resource = urllib.urlopen(imgurl) output = open("test.jpg","wb") output.write(resource.read()) output.close() </code></pre> <p>and it worked well,...
0
2016-08-18T02:46:15Z
39,009,434
<p>I looked up both of the addresses and the second one does not lead anywhere. That is probably the problem. </p> <pre><code>import urllib imgurl="webpage url" openimg = urllib.urlopen(imgurl) #opens image (prepares it) img = open("test.jpg","wb") #opens the img to read it img.write(openimg.read()) #prints it to the ...
0
2016-08-18T03:14:23Z
[ "python", "image" ]
Download a picture from certain URL with Python
39,009,195
<p>I learned how to download a picture from a certain URL with python as:</p> <pre><code>import urllib imgurl="http://www.digimouth.com/news/media/2011/09/google-logo.jpg" resource = urllib.urlopen(imgurl) output = open("test.jpg","wb") output.write(resource.read()) output.close() </code></pre> <p>and it worked well,...
0
2016-08-18T02:46:15Z
39,010,340
<p>You can try using <strong>requests</strong> module. The response will be some bytes. So, you can iterate over those byte chunks and write to the file.</p> <pre><code>import requests url = "http://farm1.static.flickr.com/96/242125326_607a826afe_o.jpg" r = requests.get(url) path = "filename.jpg" with open(path, 'wb'...
1
2016-08-18T05:04:00Z
[ "python", "image" ]
Flip bits in array using python
39,009,304
<p>You are given an integer array with <code>N</code> elements: <code>d[0], d[1], ... d[N - 1]</code>. You can perform AT MOST one move on the array: choose any two integers <code>[L, R]</code>, and flip all the elements between (and including) the <code>L</code>-th and <code>R</code>-th bits. <code>L</code> and <code...
3
2016-08-18T02:58:41Z
39,011,421
<h3> Cleaned up and made Pythonic </h3> <pre><code>arr1 = [1, 0, 0, 1, 0, 0, 1, 0] arr2 = [1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1] arr3 = [0,0,0,1,1,0,1,0,1,1,0,0,1,1,1] def maximum_ones(arr): """ Returns max possible number of ones after flipping a span of bit array """ total_one = ...
3
2016-08-18T06:37:18Z
[ "python", "algorithm", "list", "bit-manipulation", "bits" ]
Flip bits in array using python
39,009,304
<p>You are given an integer array with <code>N</code> elements: <code>d[0], d[1], ... d[N - 1]</code>. You can perform AT MOST one move on the array: choose any two integers <code>[L, R]</code>, and flip all the elements between (and including) the <code>L</code>-th and <code>R</code>-th bits. <code>L</code> and <code...
3
2016-08-18T02:58:41Z
39,017,130
<p>Traverse the whole array. Keep a <code>count</code> in the following way:</p> <ul> <li><p>Do <code>+1</code> for every 0 bit encountered.</p></li> <li><p>Do <code>-1</code> for every 1.</p></li> </ul> <p>If this count reaches -ve at any stage, reset it to 0. Keep track of <code>max</code> value of this <code>count...
1
2016-08-18T11:32:39Z
[ "python", "algorithm", "list", "bit-manipulation", "bits" ]
replace previous print output with new print output or add characters to previous output
39,009,312
<p>I'm pretty new to Python programming, and I'm attempting to create a simple little game with a little "initialization" on boot up.</p> <p>I pretty much want it to spell out "Welcome", but with all of the letters popping up every <strong>100ms</strong>.</p> <p>I've got the <code>sleep</code> function down pat, howe...
1
2016-08-18T02:59:22Z
39,009,350
<p>Use <code>end=''</code> when calling <code>print()</code>:</p> <pre><code>import time for c in "Welcome": print(c, end='') time.sleep(0.1) </code></pre>
2
2016-08-18T03:04:32Z
[ "python" ]
replace previous print output with new print output or add characters to previous output
39,009,312
<p>I'm pretty new to Python programming, and I'm attempting to create a simple little game with a little "initialization" on boot up.</p> <p>I pretty much want it to spell out "Welcome", but with all of the letters popping up every <strong>100ms</strong>.</p> <p>I've got the <code>sleep</code> function down pat, howe...
1
2016-08-18T02:59:22Z
39,009,364
<p>Python's <code>print()</code> function normally prints outputs on a new line, meaning that every time you print something, it appears on another line. To print everything on the same line, as you're asking, use the <code>print()</code> function like this:</p> <pre><code>print("W", end="") </code></pre> <p>Notice t...
1
2016-08-18T03:06:07Z
[ "python" ]
replace previous print output with new print output or add characters to previous output
39,009,312
<p>I'm pretty new to Python programming, and I'm attempting to create a simple little game with a little "initialization" on boot up.</p> <p>I pretty much want it to spell out "Welcome", but with all of the letters popping up every <strong>100ms</strong>.</p> <p>I've got the <code>sleep</code> function down pat, howe...
1
2016-08-18T02:59:22Z
39,009,726
<p>How about this - </p> <pre><code>for c in "Welcome": print '\b%s' % c, time.sleep(0.1) </code></pre>
0
2016-08-18T03:52:20Z
[ "python" ]
Is it possible to use an argument's value in a default argument value assignment in Python?
39,009,317
<p>I am trying to use the left-side argument's value in the below function inside of the default argument value to the right. </p> <pre><code>def function(var, vartwo = var*2): return vartwo print(function(7)) #should print 14 print(function(7,6)) #should print 6 </code></pre> <p>However I am getting NameError:...
0
2016-08-18T03:00:03Z
39,009,372
<p>It's not possible; how about this?</p> <pre><code>def function(var, vartwo = None): if vartwo is None: vartwo = var*2 return vartwo print(function(7)) print(function(7,6)) </code></pre> <p>The hack is to set the default value to <code>None</code>, then set it internally. If not none, then return w...
3
2016-08-18T03:07:26Z
[ "python" ]
Is it possible to use an argument's value in a default argument value assignment in Python?
39,009,317
<p>I am trying to use the left-side argument's value in the below function inside of the default argument value to the right. </p> <pre><code>def function(var, vartwo = var*2): return vartwo print(function(7)) #should print 14 print(function(7,6)) #should print 6 </code></pre> <p>However I am getting NameError:...
0
2016-08-18T03:00:03Z
39,009,399
<p>What your doing won't work because var hasn't been declared. Here's a different approach:</p> <pre><code>def function(var, multiply=False): if multiply: return var * 2 else: return var print(function(7, True)) # 14 print(function(6)) # 6 </code></pre>
0
2016-08-18T03:10:54Z
[ "python" ]
Is it possible to use an argument's value in a default argument value assignment in Python?
39,009,317
<p>I am trying to use the left-side argument's value in the below function inside of the default argument value to the right. </p> <pre><code>def function(var, vartwo = var*2): return vartwo print(function(7)) #should print 14 print(function(7,6)) #should print 6 </code></pre> <p>However I am getting NameError:...
0
2016-08-18T03:00:03Z
39,009,405
<p>Pass the buck:</p> <pre><code>def function(var, *args): return (lambda var, vartwo=var * 2: vartwo)(var, *args) print(function(7)) # should print 14 print(function(7, 6)) # should print 6 </code></pre> <blockquote> <p>I know about lambda functions but mind adding explanation?</p> </blockquote> <p>Since ...
2
2016-08-18T03:11:42Z
[ "python" ]
Is it possible to use an argument's value in a default argument value assignment in Python?
39,009,317
<p>I am trying to use the left-side argument's value in the below function inside of the default argument value to the right. </p> <pre><code>def function(var, vartwo = var*2): return vartwo print(function(7)) #should print 14 print(function(7,6)) #should print 6 </code></pre> <p>However I am getting NameError:...
0
2016-08-18T03:00:03Z
39,010,353
<p>No, it is not possible to use a value that is not defined outside of the function as a argument value for that function.</p> <p>For an alternative, I'm late to the party, but how about something short and simple that will work if <code>None</code> is the second parameter?</p> <pre><code>def function(var, *args): ...
0
2016-08-18T05:05:25Z
[ "python" ]
Is it possible to use an argument's value in a default argument value assignment in Python?
39,009,317
<p>I am trying to use the left-side argument's value in the below function inside of the default argument value to the right. </p> <pre><code>def function(var, vartwo = var*2): return vartwo print(function(7)) #should print 14 print(function(7,6)) #should print 6 </code></pre> <p>However I am getting NameError:...
0
2016-08-18T03:00:03Z
39,010,825
<p>It is not possible to use the value of another argument in default value. The reason is very simple: the default values are evaluated exactly once: at the time when the function definition was executed.</p> <p>One common pattern to use is to have the second argument be set to a special sentinel value by default, th...
0
2016-08-18T05:55:17Z
[ "python" ]
new to coding and python. trying to force type (int) for a float answer
39,009,379
<pre><code>balance = 50 - 0.12 * 15 tracks_left = balance / 0.12 round (tracks_left, 0) print 'you have', tracks_left,"to download" </code></pre> <p>The answer is <code>you have 401.666666667 to download</code> I've tried <code>round(tracks_left, 0)</code> and <code>int (tracks_left)</code>. What am I doing wrong?</p>...
0
2016-08-18T03:08:26Z
39,009,427
<p><code>round(tracks_left, 0)</code> does not mutate tracks_left, but instead returns a new value. Likewise with <code>int(tracks_left)</code>. </p> <p>Try:</p> <pre><code>tracks_left = round(tracks_left, 0) </code></pre> <p>Or:</p> <pre><code>tracks_left = int(tracks_left) </code></pre> <p>Note: <code>int</code>...
2
2016-08-18T03:13:46Z
[ "python" ]
new to coding and python. trying to force type (int) for a float answer
39,009,379
<pre><code>balance = 50 - 0.12 * 15 tracks_left = balance / 0.12 round (tracks_left, 0) print 'you have', tracks_left,"to download" </code></pre> <p>The answer is <code>you have 401.666666667 to download</code> I've tried <code>round(tracks_left, 0)</code> and <code>int (tracks_left)</code>. What am I doing wrong?</p>...
0
2016-08-18T03:08:26Z
39,009,438
<p><code>round(tracks_left, 0)</code> doesn't change <code>tracks_left</code>. It just returns the value. You have to assign it to something.</p> <pre><code>&gt;&gt;&gt; balance = 50 - 0.12 * 15 &gt;&gt;&gt; tracks_left = balance / 0.12 &gt;&gt;&gt; tracks_left_rounded = round(tracks_left, 0) &gt;&gt;&gt; print('You h...
1
2016-08-18T03:14:27Z
[ "python" ]
Execute a code at some point of time
39,009,564
<p>I am creating a web app made of python flask.. What I want is if I created an invoice it automatically send an e-mail on its renewal date to notify that the invoice is renewed and so on.. Please take note that renewal occurs every 3 months The code is something like:</p> <pre><code>def some_method(): // An API Enpo...
0
2016-08-18T03:34:10Z
39,009,812
<p>You can use crontab in Linux, The syntax look like this</p> <pre><code>crontab -e 1 2 3 4 5 /path/to/command arg1 arg2 </code></pre> <p>Or maybe you can have a look at Celery, Which I think is a good tool to handle Task Queue, and you may find something useful here.<a href="http://docs.celeryproject.org/en/latest/...
1
2016-08-18T04:04:15Z
[ "python", "flask" ]
Execute a code at some point of time
39,009,564
<p>I am creating a web app made of python flask.. What I want is if I created an invoice it automatically send an e-mail on its renewal date to notify that the invoice is renewed and so on.. Please take note that renewal occurs every 3 months The code is something like:</p> <pre><code>def some_method(): // An API Enpo...
0
2016-08-18T03:34:10Z
39,009,883
<p>If I understand correctly, you'll want to get the date when you generate the invoice, then add 3 months (90 days). You can use <code>datetime.timedelta(days=90)</code> in Python for this. Take a look at: <a href="http://stackoverflow.com/questions/6871016/adding-5-days-to-a-date-in-python">Adding 5 days to a date in...
0
2016-08-18T04:13:10Z
[ "python", "flask" ]
Execute a code at some point of time
39,009,564
<p>I am creating a web app made of python flask.. What I want is if I created an invoice it automatically send an e-mail on its renewal date to notify that the invoice is renewed and so on.. Please take note that renewal occurs every 3 months The code is something like:</p> <pre><code>def some_method(): // An API Enpo...
0
2016-08-18T03:34:10Z
39,010,982
<p>"Write it yourself." No, really.</p> <p>Keep a database table of invoices to be sent. Every invoice has a status (values such as <code>pending</code>, <code>sent</code>, <code>paid</code>, ...) and an invoice date (which may be in the future). Use <code>cron</code> or similar to periodically run (e.g. 1/hour, 1/da...
2
2016-08-18T06:07:23Z
[ "python", "flask" ]
Trying to read a file and loop through at the same time
39,009,633
<p>I'm pretty new to this so please move this topic if it's in the wrong place or something else. </p> <p><strong>Problem:</strong> <em>(Quick note: This is all in Python)</em> I am trying to go through these 100 or so files, each with the same number of columns, and take certain columns of the input (the same ones fo...
0
2016-08-18T03:41:22Z
39,009,721
<p>You could do it like this:</p> <pre><code>filec = open (filename, 'r') lines = filec.readlines () for line in lines: words = line.split(',') # Your code here </code></pre> <p>Excuse me if there are any errors, I'm doing this on mobile.</p>
0
2016-08-18T03:51:51Z
[ "python" ]
Trying to read a file and loop through at the same time
39,009,633
<p>I'm pretty new to this so please move this topic if it's in the wrong place or something else. </p> <p><strong>Problem:</strong> <em>(Quick note: This is all in Python)</em> I am trying to go through these 100 or so files, each with the same number of columns, and take certain columns of the input (the same ones fo...
0
2016-08-18T03:41:22Z
39,009,818
<p>As you are just looking for the count of rows, then how about this -</p> <pre><code>t = tuple(open(filepath\filename.txt, 'r')) print len(t) </code></pre>
0
2016-08-18T04:05:14Z
[ "python" ]
Trying to read a file and loop through at the same time
39,009,633
<p>I'm pretty new to this so please move this topic if it's in the wrong place or something else. </p> <p><strong>Problem:</strong> <em>(Quick note: This is all in Python)</em> I am trying to go through these 100 or so files, each with the same number of columns, and take certain columns of the input (the same ones fo...
0
2016-08-18T03:41:22Z
39,009,824
<p>I tried to keep the code clear, it is very possible to do with fewer lines. take in a list of file names, give out a dictionary, mapping the filename to the column you wanted (as a list).</p> <pre><code>def read_col_from_files(file_names, column_number): ret = {} for file_name in file_names: with op...
0
2016-08-18T04:06:05Z
[ "python" ]
How to combine flask and requests in python?
39,009,752
<p>On the page <code>internallogin</code>, if the user authenticates, I'd like to make a post request. To that effect, I have the following code.</p> <pre><code>@app.route('/internallogin', methods=['POST', "GET"]) def showInternallogin(): uname = request.form.get("name") passw = request.form.get("pass") ...
-2
2016-08-18T03:57:22Z
39,009,875
<p>You can issue a post using <a href="http://docs.python-requests.org/en/master/user/quickstart/" rel="nofollow"><code>requests</code></a> like so:</p> <pre><code>response = requests.post('http://localhost:5000/internal', data={...}) </code></pre> <p>However, it's generally unnecessary to call a server from itself. ...
3
2016-08-18T04:12:26Z
[ "python", "flask", "python-requests" ]
How to combine flask and requests in python?
39,009,752
<p>On the page <code>internallogin</code>, if the user authenticates, I'd like to make a post request. To that effect, I have the following code.</p> <pre><code>@app.route('/internallogin', methods=['POST', "GET"]) def showInternallogin(): uname = request.form.get("name") passw = request.form.get("pass") ...
-2
2016-08-18T03:57:22Z
39,011,851
<p>The following is right from @Karin answer</p> <pre><code>response = requests.post('http://localhost:5000/internal', data={...}) </code></pre> <p>Here might be the reason why you are receiving that error.</p> <p><a href="http://stackoverflow.com/questions/19568950/return-a-requests-response-object-from-flask">Retu...
0
2016-08-18T07:03:30Z
[ "python", "flask", "python-requests" ]