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
pass array of dictionaries to python
38,970,840
<p>I have a bash script that builds a dictionary kind of structure for multiple iterations as shown below:</p> <pre><code>{ "a":"b", "c":"d", "e":"f"} { "a1":"b1", "c1":"d1", "e1":"f1", "g1":"h1" } </code></pre> <p>I have appended all of them to an array in shell script and they are to be fed as an input to python sc...
-1
2016-08-16T09:10:08Z
38,971,826
<p>If I understand well, you want a concatenated dictionary with all keys. See <a href="http://stackoverflow.com/questions/1781571/how-to-concatenate-two-dictionaries-to-create-a-new-one-in-python">how to concatenate two dictionaries to create a new one in Python?</a></p>
0
2016-08-16T09:55:35Z
[ "python", "arrays", "dictionary" ]
Run Python script, build with pycharm, with shell
38,970,960
<p>I've write a simple script in python with pycharm. In this script I use tkinter. If I run the script in pycharm everything it's ok, but if I run the script using shell with command <code>python script.py</code> I receive the error </p> <blockquote> <p>ImportError: No module named tkinter</p> </blockquote>
-1
2016-08-16T09:15:37Z
38,971,062
<p>PyCharm and your sysytem python interpreters may have different versions and different modules installed. Check PyCaharm python version and use it by defaul or just write full version name. For example:</p> <pre><code>python3.4 script.py </code></pre>
0
2016-08-16T09:20:42Z
[ "python", "python-3.x", "pycharm", "python-3.4" ]
Run Python script, build with pycharm, with shell
38,970,960
<p>I've write a simple script in python with pycharm. In this script I use tkinter. If I run the script in pycharm everything it's ok, but if I run the script using shell with command <code>python script.py</code> I receive the error </p> <blockquote> <p>ImportError: No module named tkinter</p> </blockquote>
-1
2016-08-16T09:15:37Z
38,972,142
<blockquote> <p>ImportError: No module named tkinter</p> </blockquote> <p>Simply put, the module named <code>tkinter</code> is not visible to the python binary that you are using to run the script. Possible areas to investigate maybe </p> <ol> <li>Check whether you are using the same python executable as pyCharm is...
0
2016-08-16T10:11:00Z
[ "python", "python-3.x", "pycharm", "python-3.4" ]
Accessing youtube video stream map (python)
38,970,994
<p>I'm trying to write a python script that will download a youtube video, using this line of code for getting the download url:</p> <pre><code>download_url = "http://www.youtube.com/get_video?video_id={0}&amp;t={1}&amp;fmt=22&amp;asv=2".format(video_id, token_value) </code></pre> <p>(video_id and token_values being ...
0
2016-08-16T09:17:30Z
39,099,544
<p>I solved my problem (to some extent) in the meantime. I just had to access youtube video stream map and grab one of the URLs stored there and download the file. However, this works only on videos that don't have their signature encrypted. I'm still working on a solution for videos with encrypted signatures.</p>
0
2016-08-23T11:09:38Z
[ "python", "url", "download", "youtube" ]
__init__() takes exactly 4 arguments (1 given)
38,971,022
<p>form.py</p> <pre><code>class InvoiceForm(ModelForm,): def __init__(self,em,first,last): self.email=em self.first=first self.last=last super(InvoiceForm,self).__init__(self,em,first,last) self.fields['email']=forms.ChoiceField(choices=[x.email for x in AuthUser.objects.fi...
-1
2016-08-16T09:18:41Z
38,971,076
<p>We don't have the stacktrace in the question but problem is probably here:</p> <pre><code>else: print "d" cform=CustomerForm() iform=InvoiceForm() pform=PaymentForm() </code></pre> <p>Here you are creating objects without passing any parameters. Since the instance itself is always passed, the m...
1
2016-08-16T09:21:33Z
[ "python", "django" ]
Getting all existing fields of a received FIX message with QuickFIX
38,971,133
<p>Does QuickFIX provide the possibility of getting ALL existing fields of an incoming FIX message in a single step? (I use version 1.14.3 for Python.)</p> <p>According to QuickFIX documentation, it's possible to get a field value in a certain way:</p> <pre><code>price = quickfix.Price() field = message.getField(pric...
1
2016-08-16T09:24:15Z
38,978,514
<p>I'm not aware of a method. This is what I do, with <code>message</code> the incoming FIX message:</p> <p><code>tags = re.findall(r'(?&lt;=\x01).*?(?==)', str(message))</code></p> <p>Then, where <code>FIX = {'1':fix.Account(), '2':fix.AdvId(), ...}</code>, you can get all values by doing </p> <pre><code>for tag in...
0
2016-08-16T15:11:59Z
[ "python", "quickfix", "fix" ]
Python pandas selction of rows on unknown number of parameters
38,971,158
<p>I'm having an that I can simplify to the following situation in which I introduce a dataframe, I make a selection in a loop and make a new dataframe containing the subset of the old one that satisfy the conditions:</p> <pre><code>import pandas as pd import intertools g = ['M', 'M', 'F', 'F'] a = [20, 33, 20, 50] Zi...
-3
2016-08-16T09:25:34Z
38,971,557
<p>IIUC you need <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.logical_and.html" rel="nofollow"><code>numpy.logical_and</code></a>:</p> <pre><code>parameters = (g, a, Zip) names = ['gender', 'age', 'Zip'] df = pd.DataFrame({'age':a, 'gender':g, 'd':d, 'Zip':Zip}) print (df) for values in product...
0
2016-08-16T09:44:13Z
[ "python", "pandas", "indexing", "itertools" ]
flask argument in render_template
38,971,263
<p>The name as an argument to hello function is assigned None, but why the name in render_template will take the value of the name if provided in the url? Basically my question is how Python knows which name is None and which name is given in the url?</p> <pre><code> from flask import render_template @app.route('/hel...
0
2016-08-16T09:30:07Z
38,975,826
<p>Flask is a framework and there is a lot of code behind the scenes (especially <code>werkzeug</code>) which does all the request processing, then it calls your view function and then it prepares a complete response.</p> <p>So the answer is, that Python does not know the URL, but Flask does and calls your view functi...
1
2016-08-16T13:07:06Z
[ "python", "methods", "flask" ]
Get class labels from Keras functional model
38,971,293
<p>I have a functional model in Keras (Resnet50 from repo examples). I trained it with <code>ImageDataGenerator</code> and <code>flow_from_directory</code> data and saved model to <code>.h5</code> file. When I call <code>model.predict</code> I get an array of class probabilities. But I want to associate them with class...
0
2016-08-16T09:31:18Z
40,051,843
<p>The functional API models have just the <code>predict()</code> function which for classification would return the class probabilities. You can then select the most probable classes using the <code>probas_to_classes()</code> utility function. Example:</p> <pre><code>y_proba = model.predict(x) y_classes = keras.np_ut...
0
2016-10-14T20:55:44Z
[ "python", "keras" ]
python stack method for reverse string code
38,971,465
<p>I want to use the stack method to get reverse string in this revers question.<br> "Write a function revstring(mystr) that uses a stack to reverse the characters in a string."<br> This is my code.<br></p> <pre><code>from pythonds.basic.stack import Stack def revstring(mystr): myStack = Stack() //this is how i...
2
2016-08-16T09:39:27Z
38,971,622
<ul> <li>the <code>while</code> should not be in the <code>for</code></li> <li>the <code>return</code> should be outside, not in the <code>while</code></li> </ul> <p><strong>code:</strong></p> <pre><code>from pythonds.basic.stack import Stack def revstring(mystr): myStack = Stack() # this is how i have myS...
0
2016-08-16T09:46:46Z
[ "python", "python-2.7" ]
python stack method for reverse string code
38,971,465
<p>I want to use the stack method to get reverse string in this revers question.<br> "Write a function revstring(mystr) that uses a stack to reverse the characters in a string."<br> This is my code.<br></p> <pre><code>from pythonds.basic.stack import Stack def revstring(mystr): myStack = Stack() //this is how i...
2
2016-08-16T09:39:27Z
38,971,811
<p>Here's 3 solutions to the same problem, just pick one:</p> <p><strong>1ST SOLUTION</strong></p> <p>Fixing your solution, you almost got it, you just need to indent properly your blocks like this:</p> <pre><code>from pythonds.basic.stack import Stack def revstring(mystr): myStack = Stack() # this is how i h...
1
2016-08-16T09:54:59Z
[ "python", "python-2.7" ]
Insert large amount of data to BigQuery via bigquery-python library
38,971,523
<p>I have large csv files and excel files where I read them and create the needed create table script dynamically depending on the fields and types it has. Then insert the data to the created table.</p> <p>I have read <a href="http://stackoverflow.com/questions/23770799/loading-a-lot-of-data-into-google-bigquery-from-...
5
2016-08-16T09:42:17Z
39,111,381
<p>When handling large files don't use streaming, but batch load: Streaming will easily handle up to 100,000 rows per second. That's pretty good for streaming, but not for loading large files.</p> <p>The sample code linked is doing the right thing (batch instead of streaming), so what we see is a different problem: Th...
1
2016-08-23T22:03:31Z
[ "python", "python-2.7", "google-bigquery", "large-data" ]
How to get image from dynamic url using urllib2?
38,971,571
<p>I have generated a url from product code like,</p> <pre><code>code: 2555-525 url : www.example.com/2555-525.png </code></pre> <p>But when fetching a url, it might be a different name format on server,like </p> <pre><code>www.example.com/2555-525.png www.example.com/2555-525_TEXT.png www.example.com/2555-525_TEXT_...
0
2016-08-16T09:44:50Z
38,972,779
<p>Using wildcards in URLs is useless in most cases because </p> <ul> <li><p>the interpretation of the part of the URL after <code>http://www.example.com/</code> is totally up to the server - so <code>http://www.example.com/2555-525*.png</code> might have a meaning to the server but but propably has not</p></li> <li><...
0
2016-08-16T10:42:31Z
[ "python", "urllib2", "urllib3" ]
Getting value from list in Python
38,971,627
<p>I'm writing a simple script in Python, that creates a list of 10000 instances of <code>test</code> class. Then I'm looping through every element in the list and changing value of variable <code>x</code> to random string generated using <code>id_generator</code> method.</p> <pre><code>import string import random d...
0
2016-08-16T09:47:05Z
38,971,763
<p>Because you are not creating an instance of your class and you are directly referencing the class attribute <code>x</code> of the <code>test</code> class. You also have to declare your attributes as instance attributes, hence defining them inside <code>__init__()</code>:</p> <pre><code>import string import random ...
6
2016-08-16T09:52:55Z
[ "python" ]
Getting value from list in Python
38,971,627
<p>I'm writing a simple script in Python, that creates a list of 10000 instances of <code>test</code> class. Then I'm looping through every element in the list and changing value of variable <code>x</code> to random string generated using <code>id_generator</code> method.</p> <pre><code>import string import random d...
0
2016-08-16T09:47:05Z
38,971,796
<p>You are making three different mistakes:</p> <ol> <li><p>You should use instance attributes, and not class attributes:</p> <pre><code>class test: def __init__(self): self.x = None self.y = None </code></pre></li> <li><p>You should instantiate the <code>test</code> class. You should write:</p> ...
1
2016-08-16T09:54:13Z
[ "python" ]
add students in loop
38,971,652
<pre><code>void addStudent(char* lastName, char* firstName, char* studentId, smartresponse_classV1_t* signInClass) { sr_student_t *student = sr_student_create( lastName, sizeof lastName + 1, firstName, sizeof firstName + 1, ...
0
2016-08-16T09:48:14Z
38,971,978
<p>You assigned less bytes to your id and studentId pointers</p> <pre><code> char *id =""; //1 byte assigned 0x00 at string "" end char *studentId ="1"; // 2 bytes assigned but in code you will need 3 ("10"+null) </code></pre> <p>Your code should look like this:</p> <pre><code>void addStudent(char* lastName, char* ...
0
2016-08-16T10:03:09Z
[ "python", "c" ]
SWIG Cmake inconsistent DLL linkage
38,971,681
<p>I am using CMake to build a c++ project to a DLL on Windows. I then wish to wrap this for python using SWIG, but in doing so I am receiving warnings about 'Inconsistent DLL linkage'. I gather this refers to incorrect usage of dllexport/dllimport and I need to specify a #define for SWIG? How can I do this in CMake?</...
0
2016-08-16T09:49:31Z
38,976,793
<p>Here is the full recipe to what I do to completely avoid warnings on Windows:</p> <pre><code># We don't have Python with debug information installed if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4127") add_definitions(-DSWIG_PYTHON_INTERPRETER_NO_DEBUG) endif() find_package(SWIG REQUIRED) include(${SWIG...
1
2016-08-16T13:52:59Z
[ "python", "c++", "dll", "cmake", "swig" ]
How to partially override/extend a Declarative class's constructor?
38,971,742
<p>These are the relevant bits of what I have:</p> <pre><code>import sqlalchemy as db import sqlalchemy.ext.declarative Base = db.ext.declarative.declarative_base() class Product(Base): __tablename__ = 'product' id = db.Column(db.Integer, primary_key=True) class Bin(Base): __tablename__ = 'bin' id...
0
2016-08-16T09:51:56Z
38,981,953
<p>A superclass call should be invoked like this:</p> <pre><code>super(PurchaseItem, self).__init__(**kwargs) </code></pre>
1
2016-08-16T18:22:25Z
[ "python", "sqlalchemy" ]
Understanding evaluation order of nested list comprehensions
38,971,774
<p>I am preparing for my exam and I decided to start solving past exams. One of the requirements is to understand what a code does. But I am having troubles with this annotation.</p> <p>I do not understand which the structure of this nested loop and which loop is executed first.</p> <pre><code>n = 10 p = [q for q in ...
1
2016-08-16T09:53:21Z
38,971,975
<p>It starts by evaluating:</p> <pre><code>[r for i in range(2, int(n**0.5)) for r in range(i * 2, n, i)] </code></pre> <p>which boils down to:</p> <pre><code>[r for r in range(4, 10, 2)] </code></pre> <p>since <code>range(2, int(n * 0.5))</code> reduces to a list with a single element <code>[2]</code> that is used...
1
2016-08-16T10:03:06Z
[ "python", "list", "python-3.x", "for-loop", "nested-loops" ]
Understanding evaluation order of nested list comprehensions
38,971,774
<p>I am preparing for my exam and I decided to start solving past exams. One of the requirements is to understand what a code does. But I am having troubles with this annotation.</p> <p>I do not understand which the structure of this nested loop and which loop is executed first.</p> <pre><code>n = 10 p = [q for q in ...
1
2016-08-16T09:53:21Z
38,972,090
<p>As a rule of thumb, the innermost loops are going to be executed first.</p> <p>Having this in mind, let's break the problem down :</p> <pre><code>[r for i in range(2, int(n**0.5)) for r in range(i * 2, n, i)] </code></pre> <p><code>n**0.5</code> is 3.xxx, so <code>range(2, int(n**0.5))</code> is in fact range(2, ...
0
2016-08-16T10:08:15Z
[ "python", "list", "python-3.x", "for-loop", "nested-loops" ]
Understanding evaluation order of nested list comprehensions
38,971,774
<p>I am preparing for my exam and I decided to start solving past exams. One of the requirements is to understand what a code does. But I am having troubles with this annotation.</p> <p>I do not understand which the structure of this nested loop and which loop is executed first.</p> <pre><code>n = 10 p = [q for q in ...
1
2016-08-16T09:53:21Z
38,972,313
<p>I'm gonna give you a little tip which will help you for sure, if you're having a hard time understanding inner loops, run this code:</p> <pre><code>resultA = [] for x in ['x1', 'x2', 'x3']: for y in ['y1', 'y2', 'y3']: for z in ['z1', 'z2', 'z3']: resultA.append(''.join([x, y, z])) print re...
-1
2016-08-16T10:19:22Z
[ "python", "list", "python-3.x", "for-loop", "nested-loops" ]
Understanding evaluation order of nested list comprehensions
38,971,774
<p>I am preparing for my exam and I decided to start solving past exams. One of the requirements is to understand what a code does. But I am having troubles with this annotation.</p> <p>I do not understand which the structure of this nested loop and which loop is executed first.</p> <pre><code>n = 10 p = [q for q in ...
1
2016-08-16T09:53:21Z
38,972,717
<p>This equivalent to :</p> <pre><code>list_i=[] for i in range(2, int(n**0.5)): for r in range(i*2, n, i): list_i.append(r) res=[] for q in range(2, n) : if q not in list_i: res.append(q) print res </code></pre>
0
2016-08-16T10:39:16Z
[ "python", "list", "python-3.x", "for-loop", "nested-loops" ]
Draw a rectangle with SimpleDocTemplate (ReportLab)
38,971,898
<p>I have used <code>SimpleDocTemplate</code> for making a table and now I want to draw a <code>rect</code> on this same page, but I don't know how to do.</p> <p>I have tried this :</p> <pre><code>draw = Drawing(100, 1) draw.add(Rect(0, 100, 500, 100)) </code></pre> <p>But it don't works...</p>
0
2016-08-16T10:00:12Z
39,016,545
<p>The reason you code is not working is mostly likely because you are creating a <code>Drawing</code> of just 1 pixel high and 100 pixels wide. Which could never fit a <code>Rect</code> of 500 by 100 pixels.</p> <p>So your code should be something like this:</p> <pre><code>draw = Drawing(500, 200) draw.add(Rect(0, 1...
0
2016-08-18T11:02:28Z
[ "python", "python-3.x", "reportlab" ]
How to adjust a color to a preferred visual range?
38,971,926
<p>What I'm trying to do is apply a dynamic background color to black text. The color is calculated as a result of a hash of the text.</p> <p>The problem is, all too often the color comes out too dark to be able to read the text.</p> <p>How can I lighten the color to keep it <strong>in a decent visual range</strong> ...
3
2016-08-16T10:01:15Z
38,983,335
<p><code>QColor</code> supports the HSL representation. You want to limit the range of lightness:</p> <pre><code>QColor limitLightness(const QColor &amp; color) { auto hsl = src.toHsl(); auto h = hsl.hslHueF(); auto s = hsl.hslSaturationF(); auto l = hsl.lightnessF(); qreal const lMin = 0.25; qreal const l...
2
2016-08-16T19:52:01Z
[ "python" ]
How to adjust a color to a preferred visual range?
38,971,926
<p>What I'm trying to do is apply a dynamic background color to black text. The color is calculated as a result of a hash of the text.</p> <p>The problem is, all too often the color comes out too dark to be able to read the text.</p> <p>How can I lighten the color to keep it <strong>in a decent visual range</strong> ...
3
2016-08-16T10:01:15Z
38,985,310
<p>You can pick the color in the HSL space</p> <pre><code>def color(Hmin=0.0, Hmax=360.0, Smin=0.0, Smax=1.0, Lmin=0.0, Lmax=1.0): H = (Hmin + random.random()*(Hmax - Hmin)) % 360.0 S = Smin + random.random()*(Smax - Smin) L = Lmin + random.random()*(Lmax - Lmin) # Compute full-bri...
2
2016-08-16T22:13:23Z
[ "python" ]
How can I share a global dictionary with tuple key between various Python muliprocessing cores?
38,972,011
<p>I have the following code: (simplified)</p> <pre><code>def main_func(): anotherDic = {} dic = {(1,2):44, (4,6):33, (1,1):4, (2,3):4} ks = dic.keys() for i in ks: func_A(anotherDic, i[0], i[1], dic[i], 5) </code></pre> <p>The main dictionary (dic) is quite big, and the for loops goes for 50...
2
2016-08-16T10:04:37Z
38,972,273
<p>A general answer involves using a <code>Manager</code> object. Adapted from the docs:</p> <pre><code>from multiprocessing import Process, Manager def f(d): d[1] += '1' d['2'] += 2 if __name__ == '__main__': manager = Manager() d = manager.dict() d[1] = '1' d['2'] = 2 p1 = Process(tar...
2
2016-08-16T10:17:26Z
[ "python", "multithreading", "dictionary", "multiprocessing", "threadpool" ]
How to start jupyter in an environment created by conda?
38,972,209
<p>I use <code>conda</code> created an environment called <code>testEnv</code> and activated it, after that I use the command <code>jupyter notebook</code> to call the jupyter editor. It works, but the problem is that, I can only create file in the root environment. How can I create file in <code>testEnv</code> environ...
2
2016-08-16T10:14:18Z
38,972,519
<p>The answer is that you probably shouldn't do this. Python virtualenvs and Conda environments are intended to determine the resources available to the Python system, which are completely independent of your working directory.</p> <p>You can use the same environment to work on multiple projects, as long as they have ...
1
2016-08-16T10:29:12Z
[ "python", "anaconda", "jupyter", "conda" ]
How to start jupyter in an environment created by conda?
38,972,209
<p>I use <code>conda</code> created an environment called <code>testEnv</code> and activated it, after that I use the command <code>jupyter notebook</code> to call the jupyter editor. It works, but the problem is that, I can only create file in the root environment. How can I create file in <code>testEnv</code> environ...
2
2016-08-16T10:14:18Z
38,982,381
<p>You have two options. You can install the Jupyter Notebook into each environment, and run the Notebook from that environment:</p> <pre><code>conda create -n testEnv python=3.5 notebook source activate testEnv jupyter notebook </code></pre> <p>or you need to install the IPython kernel from <code>testEnv</code> into...
2
2016-08-16T18:48:33Z
[ "python", "anaconda", "jupyter", "conda" ]
3D Harmonics library on windows - pyshtools failed building wheel + fatal error with fftw3.lib
38,972,245
<p>We need a tool to work with 3D-Harmonics and we've come across <a href="https://github.com/SHTOOLS/SHTOOLS" rel="nofollow">https://github.com/SHTOOLS/SHTOOLS</a> - which fits all of our needs, but could not be installed properly on our windows computers (as it's intended for linux\osx).</p> <p>When we tried to run ...
0
2016-08-16T10:16:04Z
38,972,647
<p>It's a shame when you find something ready to go but very time consuming to make it work on windows. My advice would be avoid the hazzle of installing that non-ready-to-go-on-windows library and just looking for another alternative, there are few ones dealing with spherical harmonics. What about this one? <a href="h...
1
2016-08-16T10:35:08Z
[ "python", "windows", "python-2.7", "fortran", "gfortran" ]
python scripts showing different result( with one error ) in two similar input files
38,972,419
<p>The script, originally taken and modified from (<a href="http://globplot.embl.de/" rel="nofollow">http://globplot.embl.de/</a>):</p> <pre><code>#!/usr/bin/env python # Copyright (C) 2003 Rune Linding - EMBL # GlobPlot TM # GlobPlot is licensed under the Academic Free license from string import * from sys import ar...
0
2016-08-16T10:24:27Z
38,972,588
<p>UPDATE: After trying to reproduce the error on linux it's showing a similar behavior, working fine with the first file but with the second is returning Errno32. Traceback:</p> <pre><code>Traceback (most recent call last): File "Glob.py", line 207, in &lt;module&gt; runGlobPlot() File "Glob.py", line 179, in...
0
2016-08-16T10:32:43Z
[ "python" ]
python ) google spread sheet : update api does not work with 403
38,972,452
<p>I'm following the tutorial from this official link : <a href="https://developers.google.com/sheets/quickstart/python" rel="nofollow">https://developers.google.com/sheets/quickstart/python</a></p> <p>I did execute 'quickstart.py' to authenticated. After that, I ran 'quickstart.py' again and saw the data from '<a hre...
0
2016-08-16T10:26:00Z
38,986,144
<p>The quickstart.py example sets the scope to:</p> <pre><code>https://www.googleapis.com/auth/spreadsheets.readonly </code></pre> <p>To update the spreadsheet you need to set the scope to:</p> <pre><code>https://www.googleapis.com/auth/spreadsheets </code></pre> <p>You can do this by first deleting the existing au...
0
2016-08-16T23:50:27Z
[ "python", "excel", "google-spreadsheet", "google-spreadsheet-api" ]
How to insert data in flex table in vertica using python 3
38,972,493
<p>I am planning to save my unstructured data in flex tables in vertica. I am receiving lists of data (type of data in list may vary in every call) from client, i want to save this in vertica flex table using python 3. How this can be done?</p> <p>I found stuff on google, but there data is being loaded in flex table d...
0
2016-08-16T10:28:08Z
38,989,666
<p>Vertica-Python supports INSERT INTO. </p> <p>Unless you need frequent and very small inserts, writing your data to a file and using COPY would most likely give better performance. If you do it through python, does that still not meet your idea of 'programmatically' ?</p> <ul> <li><a href="https://github.com/uber/v...
1
2016-08-17T06:37:58Z
[ "python", "vertica" ]
How to insert data in flex table in vertica using python 3
38,972,493
<p>I am planning to save my unstructured data in flex tables in vertica. I am receiving lists of data (type of data in list may vary in every call) from client, i want to save this in vertica flex table using python 3. How this can be done?</p> <p>I found stuff on google, but there data is being loaded in flex table d...
0
2016-08-16T10:28:08Z
38,995,575
<p>I found a way to copy/insert data from list to flex table (in vertica) using python:</p> <h1>For list</h1> <pre><code># for python list tempList = list() tempList.append('{ "_id" : "01011", "city" : "CHESTER-APL21", "loc" : [ -72.988761, 42.279421 ], "pop" : 1688, "state" : "MA" }') tempList.append('{ "_id" : ...
2
2016-08-17T11:37:52Z
[ "python", "vertica" ]
Best way to upload large csv files using python flask
38,972,562
<p><strong>Requirement</strong>: To Upload files using flask framework. Once uploaded to the server user should be able to see the file in UI.</p> <p><strong>Current code</strong>: In order to meet above requirement i wrote the code to upload sufficiently large files and its working fine with (~30 MB file, yes ofcours...
0
2016-08-16T10:31:23Z
39,009,730
<p>On the flask side make sure you have the MAX_CONTENT_LENGTH config value set high enough:</p> <pre><code>app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024 # 100MB limit </code></pre> <p>Also you may want to look into the <a href="http://pythonhosted.org/Flask-Uploads/" rel="nofollow" title="Flask-Upload extens...
0
2016-08-18T03:52:53Z
[ "python", "csv", "flask", "large-files" ]
Pandas: get json from data frame
38,972,609
<p>I have data frame</p> <pre><code>member_id,2015-05-01,2015-05-02,2015-05-03,2015-05-04,2015-05-05,2015-05-06,2015-05-07,2015-05-08,2015-05-09,2015-05-10,2015-05-11,2015-05-12,2015-05-13,2015-05-14,2015-05-15,2015-05-16,2015-05-17,2015-05-18,2015-05-19,2015-05-20,2015-05-21,2015-05-22,2015-05-23,2015-05-24,2015-05-2...
-2
2016-08-16T10:33:40Z
38,973,890
<p>You can use:</p> <pre><code>#convert int xolum to string df['member_id'] = df.member_id.astype(str) #reshaping and convert to months period df.set_index('member_id', inplace=True) df = df.unstack().reset_index(name='val').rename(columns={'level_0':'date'}) df['date'] = pd.to_datetime(df.date).dt.to_period('m').dt.s...
1
2016-08-16T11:36:18Z
[ "python", "json", "pandas" ]
Python: Comparing empty string to False is False, why?
38,972,645
<p>If <code>not ''</code> evaluates to <code>True</code>, why does <code>'' == False</code> evaluates to <code>False</code>?</p> <p>For example, the "voids" of the other types (e.g. 0, 0.0) will return <code>True</code> when compared to <code>False</code>:</p> <pre><code>&gt;&gt;&gt; 0 == False True &gt;&gt;&gt; 0.0 ...
1
2016-08-16T10:34:59Z
38,972,724
<p>Because <code>int(False) == 0</code> and <code>int(True) == 1</code>. This is what Python is doing when it tries to evaluate <code>0 == False</code>. </p> <p>On the other hand, <code>bool('') == False</code>. The same goes for <code>bool([])</code> and <code>bool({})</code>.</p> <p>The fact that <code>x</code> eva...
0
2016-08-16T10:39:51Z
[ "python", "string", "boolean", "logic" ]
Python: Comparing empty string to False is False, why?
38,972,645
<p>If <code>not ''</code> evaluates to <code>True</code>, why does <code>'' == False</code> evaluates to <code>False</code>?</p> <p>For example, the "voids" of the other types (e.g. 0, 0.0) will return <code>True</code> when compared to <code>False</code>:</p> <pre><code>&gt;&gt;&gt; 0 == False True &gt;&gt;&gt; 0.0 ...
1
2016-08-16T10:34:59Z
38,972,758
<p>It doesn't make sense for <code>''</code> and <code>[]</code> to actually equal <code>False</code>, because they are clearly different values: a string and a list. If they both equalled <code>False</code> they would have to be equal to each other*. They are just "falsey", which means they come out as false when they...
5
2016-08-16T10:41:01Z
[ "python", "string", "boolean", "logic" ]
Python: Comparing empty string to False is False, why?
38,972,645
<p>If <code>not ''</code> evaluates to <code>True</code>, why does <code>'' == False</code> evaluates to <code>False</code>?</p> <p>For example, the "voids" of the other types (e.g. 0, 0.0) will return <code>True</code> when compared to <code>False</code>:</p> <pre><code>&gt;&gt;&gt; 0 == False True &gt;&gt;&gt; 0.0 ...
1
2016-08-16T10:34:59Z
38,972,878
<p>If you want to check the <a href="https://docs.python.org/3/library/stdtypes.html#truth-value-testing" rel="nofollow">official explanation</a>, just cast your values like this:</p> <pre><code>print(bool(None) == False) print(False == False) print(bool(0) == False) print(bool(0.0) == False) print(bool(0j) == False) ...
0
2016-08-16T10:47:01Z
[ "python", "string", "boolean", "logic" ]
Python: Comparing empty string to False is False, why?
38,972,645
<p>If <code>not ''</code> evaluates to <code>True</code>, why does <code>'' == False</code> evaluates to <code>False</code>?</p> <p>For example, the "voids" of the other types (e.g. 0, 0.0) will return <code>True</code> when compared to <code>False</code>:</p> <pre><code>&gt;&gt;&gt; 0 == False True &gt;&gt;&gt; 0.0 ...
1
2016-08-16T10:34:59Z
38,973,019
<p>Such a comparison isn't "Pythonic" (<em>i.e.</em> it isn't what an experienced Python programmer would naturally do).</p> <p>In some respects unfortunately, Python's designer decided that <code>True</code> and <code>False</code> would be instances of <code>bool</code>, and that <code>bool</code> would be a subclass...
0
2016-08-16T10:54:07Z
[ "python", "string", "boolean", "logic" ]
Python: Comparing empty string to False is False, why?
38,972,645
<p>If <code>not ''</code> evaluates to <code>True</code>, why does <code>'' == False</code> evaluates to <code>False</code>?</p> <p>For example, the "voids" of the other types (e.g. 0, 0.0) will return <code>True</code> when compared to <code>False</code>:</p> <pre><code>&gt;&gt;&gt; 0 == False True &gt;&gt;&gt; 0.0 ...
1
2016-08-16T10:34:59Z
38,973,058
<blockquote> <p>In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: <code>False</code>, <code>None</code>, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets a...
2
2016-08-16T10:56:09Z
[ "python", "string", "boolean", "logic" ]
Identify binary state of data set (frequency on/off)
38,972,690
<p>I have a large data set that has values ranging from [-3,3] and I'm using a hard limit at 0 as the boundary.</p> <p>The data has a binary value of 1 when its oscillating from -3,3 at a 56kHz frequency. What this means is that the data will be changing from -3 to 3 and back every N data values where N is typically &...
0
2016-08-16T10:37:30Z
38,977,801
<p>I've finally found a solution. I spent far too long getting my head around, what appears to be, a fairly simple problem but it works now.</p> <p>It won't pick up the last group in the data set but that's fine.</p> <pre><code>previousBinaryState = "X" x = 0 sinceLastChange = 0 previousGroup = inputBinaryState(data[...
0
2016-08-16T14:37:33Z
[ "python", "frequency", "modulation" ]
py2exe and cx_Oracle failed loading cx_Oracle.pyd
38,972,714
<p>Given the following python program</p> <p>testconnect.py</p> <pre><code>from sqlalchemy.dialects import oracle from sqlalchemy import create_engine url = 'oracle+cx_oracle://user:password@oracle-rds-01.....amazonaws.com:1521/orcl' e = create_engine(url) e.connect() print('Connected') </code></pre> <p>setup.py<...
0
2016-08-16T10:39:06Z
39,019,551
<p>The Oracle instant client (or equivalent) needs to be installed on the target machine. cx_Oracle will not work without it. The DLL it is (likely) trying to find is OCI.DLL.</p>
0
2016-08-18T13:30:41Z
[ "python", "py2exe", "cx-oracle" ]
py2exe and cx_Oracle failed loading cx_Oracle.pyd
38,972,714
<p>Given the following python program</p> <p>testconnect.py</p> <pre><code>from sqlalchemy.dialects import oracle from sqlalchemy import create_engine url = 'oracle+cx_oracle://user:password@oracle-rds-01.....amazonaws.com:1521/orcl' e = create_engine(url) e.connect() print('Connected') </code></pre> <p>setup.py<...
0
2016-08-16T10:39:06Z
39,077,450
<p>I finally figured out what was going on</p> <p>The machine we were deploying to was windows 2008 Server 64 Bit But It had Oracle 32 bit client on it</p> <p>I was trying to deploy py2exe python 3.4 app 64 bit with Cx_Oracle 64bit this was finding the 32 bit OCI.dll and failing to load</p> <p>My solution was to pac...
0
2016-08-22T10:41:41Z
[ "python", "py2exe", "cx-oracle" ]
slicing data in pandas
38,972,790
<p>This is likely a really simple question, but it's one I've been confused about and stuck on for a while, so I'm hoping I might get some help. </p> <p>I'm using cross validation to test my data set, but I'm finding that indexing the pandas df is not working as I'm expecting. Specifically, when I print out x_test, I ...
-1
2016-08-16T10:43:00Z
38,972,958
<p>Why don't you use <a href="http://scikit-learn.org/stable/modules/generated/sklearn.cross_validation.KFold.html#sklearn.cross_validation.KFold" rel="nofollow">sklearn.cross_validation.KFold</a>? There is a clear example on this site...</p> <hr> <p><strong>UPDATE:</strong></p> <p>At all subsets you have to specify...
0
2016-08-16T10:51:31Z
[ "python", "pandas", "cross-validation" ]
How to convert cumulative data to daily one?
38,972,799
<p>I have a list of cumulative transferred data by link and periods when data transfer is started and ended. In other words, elements of <code>times</code> is periods of days; elements of <code>data</code> are sum of <strong>all</strong> data transferred by this link to the end of current transfer:</p> <pre><code>data...
1
2016-08-16T10:43:27Z
38,973,072
<p>IIUC you can do soomething like this -</p> <pre><code>lims = np.arange(data.size)+1 col0 = lims - times[:,0] col1 = times[:,1] - lims lens = times[:,1] - times[:,0] out = data*col0/lens shares = data*(col1/lens) out[1:] += shares.cumsum()[:-1] </code></pre> <p>Sample run -</p> <pre><code>In [144]: data Out[144]:...
1
2016-08-16T10:56:52Z
[ "python", "numpy", "inverse", "cumulative-sum" ]
How to convert cumulative data to daily one?
38,972,799
<p>I have a list of cumulative transferred data by link and periods when data transfer is started and ended. In other words, elements of <code>times</code> is periods of days; elements of <code>data</code> are sum of <strong>all</strong> data transferred by this link to the end of current transfer:</p> <pre><code>data...
1
2016-08-16T10:43:27Z
38,973,148
<p>You can use <code>np.split</code> to chunk the data into daily arrays. First you need the indices that define the edges of each day; for this you can use <code>np.histogram</code> where you define the bins that represent the edges of your days. Then cumsum to get indices of the edges of each day.</p> <pre><code>his...
1
2016-08-16T10:59:53Z
[ "python", "numpy", "inverse", "cumulative-sum" ]
How to convert cumulative data to daily one?
38,972,799
<p>I have a list of cumulative transferred data by link and periods when data transfer is started and ended. In other words, elements of <code>times</code> is periods of days; elements of <code>data</code> are sum of <strong>all</strong> data transferred by this link to the end of current transfer:</p> <pre><code>data...
1
2016-08-16T10:43:27Z
38,973,157
<p>@Divakar has already posted the correct numpy solution, here's a simple python one:</p> <pre><code>import math data = [0.85, 1.6, 1.85, 2.89, 3.56, 4.05, 5.56, 7.89] times = [0.5, 1.3, 1.8, 2.9, 3.5, 3.6, 4.2, 4.65] daily = [0] * 7 for i, t in enumerate(times): daily[int(math.floor(t))] += data[i] print daily...
1
2016-08-16T11:00:14Z
[ "python", "numpy", "inverse", "cumulative-sum" ]
Broadcasting logical operators along a different axis
38,972,934
<p>I have a DataFrame and a Series:</p> <pre><code>np.random.seed(0) df = pd.DataFrame(np.random.binomial(1, 0.3, (5, 4)).astype(bool)) ser = pd.Series(np.random.binomial(1, 0.3, 5).astype(bool)) </code></pre> <pre>df Out: 0 1 2 3 0 False True False False 1 False False False True 2 ...
1
2016-08-16T10:50:07Z
38,974,330
<p>Since this computation is array-based (no alignment of index labels necessary), you could compute this with NumPy arrays and NumPy broadcasting:</p> <pre><code>np.logical_and(df.values, ser.values[:, None]) </code></pre> <hr> <p>Here is a speed comparison of a few alternatives:</p> <pre><code>import numpy as np ...
2
2016-08-16T11:57:23Z
[ "python", "pandas" ]
Need advice, remove widget for kivy
38,973,030
<p>New in the world of programming for about months now.</p> <p>need a help, regarding remove_widget.</p> <p>please find my simple code for troubleshooting. I've been working on this for about 2 weeks and i cant find a work around to it.</p> <p>basically this code add a button object and should also remove the obj. ...
0
2016-08-16T10:54:56Z
38,973,792
<p>A simple example of add remove buttons I can think of right now, could look like this.</p> <pre class="lang-py prettyprint-override"><code>from kivy.app import App from kivy.uix.button import Button from kivy.uix.boxlayout import BoxLayout class MyBox(BoxLayout): def __init__(self,**kwargs): super(My...
0
2016-08-16T11:31:48Z
[ "python", "kivy" ]
Keeping a Selenium Driver alive across multiple Python scripts
38,973,052
<p>I'm working on a series of tests using Fitnesse. Due to Fitnesse only allowing me to return one value at a time, I have a series of assertion tests e.g. check to see if a particular element exists on the page. Each test in fitnesse runs one after the other, which means my driver instance gets destroyed after each te...
0
2016-08-16T10:55:47Z
38,974,256
<p>My recommendation would be to organise the tests better and adapt to the practice that each test case has it's own instance. If you have really small &amp; fast cases, i would recommend nesting them. </p> <p>Otherwise i recommend reading about Singleton pattern which allows us to have one instance of webdriver. You...
0
2016-08-16T11:54:04Z
[ "python", "selenium" ]
Keeping a Selenium Driver alive across multiple Python scripts
38,973,052
<p>I'm working on a series of tests using Fitnesse. Due to Fitnesse only allowing me to return one value at a time, I have a series of assertion tests e.g. check to see if a particular element exists on the page. Each test in fitnesse runs one after the other, which means my driver instance gets destroyed after each te...
0
2016-08-16T10:55:47Z
38,986,467
<p>It should have something like @BeforeSuite annotation in TestNG. If it has, you can leverage it to instantiate the driver creation which will be utilized by all tests.</p> <p>We have successfully implemented it using BaseTestClass which has driver variable, we are setting this driver in @BeforeSuite method and then...
0
2016-08-17T00:36:59Z
[ "python", "selenium" ]
Pandas: convert days to months
38,973,116
<p>I have dataframe</p> <pre><code>member_id,2015-05-01,2015-05-02,2015-05-03,2015-05-04,2015-05-05,2015-05-06,2015-05-07,2015-05-08,2015-05-09,2015-05-10,2015-05-11,2015-05-12,2015-05-13,2015-05-14,2015-05-15,2015-05-16,2015-05-17,2015-05-18,2015-05-19,2015-05-20,2015-05-21,2015-05-22,2015-05-23,2015-05-24,2015-05-25...
0
2016-08-16T10:58:31Z
38,973,152
<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.to_period.html" rel="nofollow"><code>to_period</code></a>:</p> <pre><code>df['member_id'] = df.member_id.astype(str) df.set_index('member_id', inplace=True) df = df.unstack().reset_index(name='val').rename(columns={'...
1
2016-08-16T11:00:02Z
[ "python", "pandas" ]
Why does RobotParser block this result?
38,973,168
<p>I have been using Python's robotparser for a while now and it's working fine. This morning I ran across a website with a very permissive looking robots.txt file:</p> <pre><code>User-agent: * Disallow: /wp-admin/ Allow: /wp-admin/admin-ajax.php </code></pre> <p>However, for some reason, the parser thinks all URLs a...
0
2016-08-16T11:00:41Z
38,974,257
<p>According to the Robot Exclusion Standard found at <a href="https://www.w3.org/TR/html4/appendix/notes.html#h-B.4.1.1" rel="nofollow">https://www.w3.org/TR/html4/appendix/notes.html#h-B.4.1.1</a> and <a href="https://en.wikipedia.org/wiki/Robots_exclusion_standard" rel="nofollow">https://en.wikipedia.org/wiki/Robots...
0
2016-08-16T11:54:05Z
[ "python", "web-crawler", "robots.txt" ]
Change picture when tkinter button clicked
38,973,173
<p>I'm using tkinter in python 3 to produce some buttons and some labels which change colour when the button is clicked (and turn on a GPIO pin on the Rasp pi too)</p> <p>Is it possible to change the .gif that the button uses when the button is clicked? I want it to say ON when the GPIO pin is off, and OFF when the GP...
-2
2016-08-16T11:00:50Z
39,024,699
<p>Solved it:</p> <pre><code>#BCM17 GPIO.setup(17,GPIO.OUT) colour17=StringVar() pinstate17=GPIO.input(17) if pinstate17==1: colour17.set('red') else: colour17.set('green') BCM17L = Label(clock, text="GPIO 0\nBCM 17", font=(fontname,12), fg='white', bg=colour17.get(), width=10, height=2) BCM17L.grid(column=0, ...
0
2016-08-18T17:58:43Z
[ "python", "tkinter", "raspberry-pi3" ]
OpenCV python environment set up on Mac
38,973,217
<p>I am trying to set up OpenCV environmnet on my Mac El Capitan 10.11.5 using this tutorial: <a href="http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/" rel="nofollow">http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/</a> </p> <p>I constantly get en erro...
0
2016-08-16T11:03:04Z
38,988,042
<p>I had that Problem too, but in the end </p> <p><code>brew install opencv3 --with-python3</code></p> <p>did the trick for me. </p>
0
2016-08-17T04:16:46Z
[ "python", "osx", "opencv", "curl" ]
clustering of tweets using k means algorithm as positive or negative
38,973,218
<p>i have some movie reviews, i need to cluster them on the basis of positive or negative clusters. Using Kmeans is possible. Can anyone give me basic outline of how to start with it. In Python is preferable.</p>
-3
2016-08-16T11:03:07Z
38,973,436
<p>You can start with sklearn package, one of well-known machine learning package. There you can use sklearn.cluster.KMeans.</p> <p>Here is an exmaple from <a href="http://%20http://scikit-learn.org/stable/auto_examples/cluster/plot_kmeans_digits.html" rel="nofollow">scikit-learn website</a>. </p> <p>Though you prefe...
-1
2016-08-16T11:13:31Z
[ "python", "twitter", "machine-learning", "cluster-analysis", "k-means" ]
clustering of tweets using k means algorithm as positive or negative
38,973,218
<p>i have some movie reviews, i need to cluster them on the basis of positive or negative clusters. Using Kmeans is possible. Can anyone give me basic outline of how to start with it. In Python is preferable.</p>
-3
2016-08-16T11:03:07Z
38,973,790
<h2>you cannot cluster "as positive or negative"</h2> <p>You have labels. Use <strong>classification</strong>.</p> <p>k-means will not be able to identify what is "positive". It may find any pattern, e.g. short vs. long, english vs. spanish tweets etc. - if you are lucky you can identify what it did.</p>
0
2016-08-16T11:31:47Z
[ "python", "twitter", "machine-learning", "cluster-analysis", "k-means" ]
Better alternative to lots of IF statements? Table of values
38,973,433
<p>I have a table of moves that decide whether or not the player wins based on their selection against the AI. Think Rock, Paper, Scissors with a lot more moves. I'll be eventually coding it in Python, but before I begin, I want to know if there is a better way of doing this rather than LOTS and LOTS of IF statements?<...
7
2016-08-16T11:13:22Z
38,973,575
<p>You could use a dict? Something like this: </p> <pre><code>#dict of winning outcomes, the first layer represents the AI moves, and the inner #layer represent the player move and the outcome ai = { 'punch' : { 'punch' : 'tie', 'kick' : 'wins', }, 'stab' : { 'punch' : 'loses', ...
8
2016-08-16T11:21:39Z
[ "python", "algorithm", "if-statement", "dictionary" ]
Better alternative to lots of IF statements? Table of values
38,973,433
<p>I have a table of moves that decide whether or not the player wins based on their selection against the AI. Think Rock, Paper, Scissors with a lot more moves. I'll be eventually coding it in Python, but before I begin, I want to know if there is a better way of doing this rather than LOTS and LOTS of IF statements?<...
7
2016-08-16T11:13:22Z
38,973,624
<p>Yes, store the decisions as key/value pairs in a dictionary with all the possible combinations as the key and decision as result. Basically make a lookup table for the possible moves. </p> <p>This speeds up decision making at the expense of having to store all possible combinations.</p> <pre><code>def tie(): p...
0
2016-08-16T11:23:35Z
[ "python", "algorithm", "if-statement", "dictionary" ]
Better alternative to lots of IF statements? Table of values
38,973,433
<p>I have a table of moves that decide whether or not the player wins based on their selection against the AI. Think Rock, Paper, Scissors with a lot more moves. I'll be eventually coding it in Python, but before I begin, I want to know if there is a better way of doing this rather than LOTS and LOTS of IF statements?<...
7
2016-08-16T11:13:22Z
38,973,682
<p>You could try a dictionary of dictionaries (nested dictionary). Keep values and keys in text form, rather than map to numbers, to improve readability.</p> <pre><code>outcome = {} outcome['punch'] = {} outcome['punch']['punch'] = 'Tie' outcome['punch']['kick'] = 'Lose' ... outcome['kick'] = {} outcome['kick']['punch...
0
2016-08-16T11:26:22Z
[ "python", "algorithm", "if-statement", "dictionary" ]
Better alternative to lots of IF statements? Table of values
38,973,433
<p>I have a table of moves that decide whether or not the player wins based on their selection against the AI. Think Rock, Paper, Scissors with a lot more moves. I'll be eventually coding it in Python, but before I begin, I want to know if there is a better way of doing this rather than LOTS and LOTS of IF statements?<...
7
2016-08-16T11:13:22Z
38,973,828
<p>You could use a python dictionary to map moves to numbers:</p> <pre><code>move = {'Punch': 0, 'Kick': 1} </code></pre> <p>And then use a matrix to determine the outcome. Numpy can be used for that</p> <pre><code>import numpy move = {'Punch': 0, 'Kick': 1} outcome = numpy.matrix([['Tie','Loses'],['Wins','Tie']]) ...
0
2016-08-16T11:33:29Z
[ "python", "algorithm", "if-statement", "dictionary" ]
Better alternative to lots of IF statements? Table of values
38,973,433
<p>I have a table of moves that decide whether or not the player wins based on their selection against the AI. Think Rock, Paper, Scissors with a lot more moves. I'll be eventually coding it in Python, but before I begin, I want to know if there is a better way of doing this rather than LOTS and LOTS of IF statements?<...
7
2016-08-16T11:13:22Z
38,973,896
<p>I'd use a 2-dimensional list for this. Each attack is decoded to an index 0 to 5 and win tie and loss are decoded as 1, 0 and -1.</p> <p>So the list will look something like this (not based on your example, I just put some random numbers):</p> <pre><code>table = [[1,0,-1,0,1,-1],[1,1,0,1,0,-1],...,etc.] </code></p...
1
2016-08-16T11:36:27Z
[ "python", "algorithm", "if-statement", "dictionary" ]
Better alternative to lots of IF statements? Table of values
38,973,433
<p>I have a table of moves that decide whether or not the player wins based on their selection against the AI. Think Rock, Paper, Scissors with a lot more moves. I'll be eventually coding it in Python, but before I begin, I want to know if there is a better way of doing this rather than LOTS and LOTS of IF statements?<...
7
2016-08-16T11:13:22Z
38,973,897
<p>You can create a map of attacks similar to your table above like this</p> <pre><code>map = [ [0,-1,-1,1,1,-1], [1,0,-1,-1,1,-1], [1,1,0,-1,-1,1], [-1,1,1,0,-1,1], [-1,-1,1,1,0,-1], [1,1,-1,-1,1,0] ] </code></pre> <p>Here, 0 is a draw, 1 is a win and -1 is a loss.</p> <p>Now create an array...
5
2016-08-16T11:36:29Z
[ "python", "algorithm", "if-statement", "dictionary" ]
How to get the output from a kyword using robot.api?
38,973,452
<p>I hope you can help me, I am quite stuck with this issue :(</p> <p>I am trying to create all the tests using the robot api with python, I followed the example in the documentation, but I need to capture the output from a keyword and I dont find how can I do it</p> <p>I tried as usual in rf-ride syntax:</p> <pre><...
0
2016-08-16T11:14:19Z
38,974,250
<p>The call to <code>test.keywords.create(...)</code> doesn't <em>call</em> the keyword, it merely creates one to be called later. If you want the results to be assigned to a variable, use the <code>assign</code> attribute when calling <code>create</code>. This argument takes a list of variable names. </p> <p>For exam...
1
2016-08-16T11:53:55Z
[ "python", "robotframework" ]
Save .csv file in the same directory as .py file
38,973,487
<p>I am tring to save my .csv file which is a result of some queries in the same location as the .py file. </p> <pre><code>import os with open(os.path.dirname(os.path.abspath(__file__))+'MyCSVFile.csv','wb') as output_file: dict_writer = csv.DictWriter(output_file, keys) dict_writer.writeheader() dict_wri...
0
2016-08-16T11:16:42Z
38,973,524
<p>Remove the call to <code>os.path.dirname</code> since you are already calling <code>os.path.abspath</code>. Calling <code>dirname</code> returns the directory component thus you are getting the directory up in the hierarchy. BTW: use <code>os.path.join</code> to join parts of a directory.</p>
1
2016-08-16T11:19:03Z
[ "python", "csv" ]
Save .csv file in the same directory as .py file
38,973,487
<p>I am tring to save my .csv file which is a result of some queries in the same location as the .py file. </p> <pre><code>import os with open(os.path.dirname(os.path.abspath(__file__))+'MyCSVFile.csv','wb') as output_file: dict_writer = csv.DictWriter(output_file, keys) dict_writer.writeheader() dict_wri...
0
2016-08-16T11:16:42Z
38,973,614
<p>You have to use os.path.join to save the csv file in the same directory</p> <pre><code>import os dirname = os.path.dirname(os.path.abspath(__file__)) csvfilename = os.path.join(dirname, 'MyCSVFile.csv') with open(csvfilename, 'wb') as output_file: dict_writer = csv.DictWriter(output_file, keys) dict_write...
2
2016-08-16T11:23:17Z
[ "python", "csv" ]
£ Sign on python SQLAlchemy query
38,973,489
<p>I am trying to inject into a query, a string in the following way:</p> <pre><code>value = '£' query = """select * from table where condition = '{0}';""".format(value) </code></pre> <p>the problem is the result of this formatting is:</p> <blockquote> <p>select * from table where condition = '\xc2\xa3';</p> </bl...
0
2016-08-16T11:16:45Z
38,973,997
<p>The Unicode for a pound sign is 163 (decimal) or A3 in hex, so the following should work.</p> <pre><code>print u"\xA3" </code></pre> <p>Oirigin answer: <a href="http://stackoverflow.com/questions/705434/what-encoding-do-i-need-to-display-a-gbp-sign-pound-sign-using-python-on-cygwi">What encoding do I need to displ...
0
2016-08-16T11:41:54Z
[ "python", "postgresql", "sqlalchemy", "encode" ]
Process finished with exit code -1073741819 (0xC0000005) (Cython, TeamSpeak3)
38,973,604
<p>My aim for now is creating team speak 3 manager service (that switches the users by channels an others): So I created wrapper of TS3 SDK lib (wrapped with Cython for Python): <a href="https://mega.nz/#!pQdFjIwD!1vg8DPsFtYR4icVqWXzvpdbAQ47-n-aPz2niRkTU4fY" rel="nofollow">https://mega.nz/#!pQdFjIwD!1vg8DPsFtYR4icVqWXz...
1
2016-08-16T11:22:43Z
38,984,545
<p>Due to lack of a verifiable example, this is a little bit of guessing.</p> <p>If those handler functions are called from a thread that is created by the C library (ts3client_*), the <a href="https://wiki.python.org/moin/GlobalInterpreterLock" rel="nofollow">GIL</a> has not been properly acquired by the time python ...
0
2016-08-16T21:09:33Z
[ "python", "sdk", "cython", "access-violation", "teamspeak" ]
Adding Columns from different dataframes (with matching date) stored in a python dictionary
38,973,635
<p>I have columns with the same name in several dataframes. these dataframes are stored in a dictionary. now i want to add the columns with the same name (and the respective date) across those dataframes in the dictionary and store the result in a new dataframe. </p> <p>The code I have so far doest get me very far...<...
1
2016-08-16T11:24:02Z
38,974,298
<pre><code># Initialize 'sum_df' sum_df = pd.DataFrame(columns=['date']) # Iterate over dataframes of dictionary for i, tables in enumerate(frames_dict): # Create dataframe df = frames_dict[tables] # Filter rows by 'date' df = df[(df['date'] &gt;= '01.01.2010') &amp; (df['date'] &lt;'01.01.2011')] ...
0
2016-08-16T11:56:13Z
[ "python", "pandas", "dataframe" ]
Pip3 not working on OS X
38,973,737
<p>I recently redownloaded Python 3 to update it to the latest (3.5.2?) and I must have done something wrong. Pip3 in my terminal is not responding anymore. When I type "pip3 install <em>some module</em>" it gives me back:</p> <pre><code>-bash pip3: command not found </code></pre> <p>I went into /usr/local/bin/ and s...
2
2016-08-16T11:29:02Z
38,973,787
<p>This is only a guess, but <code>/usr/local/bin/pip3</code> etc. are probably only symbolic link to the real binary. You could run <code>ls -l /usr/local/bin/pip3</code> to see where the symbolic link points to.</p>
1
2016-08-16T11:31:27Z
[ "python", "python-3.x", "pip" ]
Pip3 not working on OS X
38,973,737
<p>I recently redownloaded Python 3 to update it to the latest (3.5.2?) and I must have done something wrong. Pip3 in my terminal is not responding anymore. When I type "pip3 install <em>some module</em>" it gives me back:</p> <pre><code>-bash pip3: command not found </code></pre> <p>I went into /usr/local/bin/ and s...
2
2016-08-16T11:29:02Z
38,974,012
<p>You can try out the <code>ensurepip</code> module.</p> <pre><code>python -m ensurepip --upgrade </code></pre>
0
2016-08-16T11:42:35Z
[ "python", "python-3.x", "pip" ]
Put a variable in a specific array position Python
38,973,742
<p>I am trying to solve a problem and I am not able to do it. So the problem is that I have a function in Python. And I have 3 cases and I want my function to be general for all these cases. So my function needs an argument which is a array like this <code>a = [a1, a2, a3]</code> and for each case 2 of the elements in ...
0
2016-08-16T11:29:23Z
38,973,825
<p>Use <code>insert()</code> to insert an element before a given position.</p> <p>For instance, with</p> <pre><code>arr = ['A','B','C'] arr.insert(0,'D') arr becomes ['D','A','B','C'] </code></pre> <p>because 'D' is inserted before the element at index 0.</p> <p>Now, for</p> <pre><code>arr = ['A','B','C'] arr.ins...
0
2016-08-16T11:33:22Z
[ "python", "arrays", "function" ]
Put a variable in a specific array position Python
38,973,742
<p>I am trying to solve a problem and I am not able to do it. So the problem is that I have a function in Python. And I have 3 cases and I want my function to be general for all these cases. So my function needs an argument which is a array like this <code>a = [a1, a2, a3]</code> and for each case 2 of the elements in ...
0
2016-08-16T11:29:23Z
38,974,692
<p>I have found I way of doing it:</p> <pre><code> #if I define a as: a = [a1, True, a3] # I can use np.place(a, a==True, r[z]) </code></pre> <p>In this way it will replace the value where a[i] = true by r[z]</p>
0
2016-08-16T12:13:32Z
[ "python", "arrays", "function" ]
How can I remove a list element from a list which is inside a dictionary?
38,973,796
<p>I have following dictionary of lists:-</p> <pre><code>myDict = {"A": [4, 8, 10, 9], "B": [6, 9, 10]} </code></pre> <p>I want to remove value 10 from the list that corresponds to key 'A' of myDict.</p> <p>Please suggest how can I achieve this in python?</p>
-1
2016-08-16T11:32:01Z
38,973,839
<pre><code>myDict['A'].remove(10) </code></pre> <p>because the list is modified in place</p>
4
2016-08-16T11:34:05Z
[ "python", "list", "dictionary" ]
How can I remove a list element from a list which is inside a dictionary?
38,973,796
<p>I have following dictionary of lists:-</p> <pre><code>myDict = {"A": [4, 8, 10, 9], "B": [6, 9, 10]} </code></pre> <p>I want to remove value 10 from the list that corresponds to key 'A' of myDict.</p> <p>Please suggest how can I achieve this in python?</p>
-1
2016-08-16T11:32:01Z
38,973,899
<p>You can access your list as follows:</p> <pre><code>myDict['A'] [4, 8, 10, 9] </code></pre> <p>then remove it or whatever you need to do with the list:</p> <pre><code>mydict['A'].remove(10) </code></pre>
0
2016-08-16T11:36:34Z
[ "python", "list", "dictionary" ]
Adjusting gridlines and ticks in matplotlib imshow
38,973,868
<p>I'm trying to plot a matrix of values and would like to add gridlines to make the boundary between values clearer. Unfortunately, imshow decided to locate the tick marks in the middle of each voxel. Is it possible to </p> <p>a) remove the ticks but leave the label in the same location and<br> b) add gridlines bet...
1
2016-08-16T11:35:17Z
38,974,577
<p>Try to shift axises' ticks:</p> <pre><code>ax.set_xticks(np.arange(-.5, 10, 1)); ax.set_yticks(np.arange(-.5, 10, 1)); ax.set_xticklabels(np.arange(1, 12, 1)); ax.set_yticklabels(np.arange(1, 12, 1)); </code></pre> <p><a href="http://i.stack.imgur.com/ffHrp.png" rel="nofollow"><img src="http://i.stack.imgur.com/ff...
2
2016-08-16T12:08:26Z
[ "python", "matplotlib", "imshow" ]
Adjusting gridlines and ticks in matplotlib imshow
38,973,868
<p>I'm trying to plot a matrix of values and would like to add gridlines to make the boundary between values clearer. Unfortunately, imshow decided to locate the tick marks in the middle of each voxel. Is it possible to </p> <p>a) remove the ticks but leave the label in the same location and<br> b) add gridlines bet...
1
2016-08-16T11:35:17Z
38,994,970
<p>Code for solution as suggested by Serenity: </p> <pre><code>plt.figure() im = plt.imshow(np.reshape(np.random.rand(100), newshape=(10,10)), interpolation='none', vmin=0, vmax=1, aspect='equal'); ax = plt.gca(); ax = plt.gca(); # Major ticks ax.set_xticks(np.arange(0, 10, 1)); ax.set_yticks(np.aran...
1
2016-08-17T11:09:30Z
[ "python", "matplotlib", "imshow" ]
How to make pricelist_id.id return the specific id
38,973,888
<p>Hi i am trying to give a return a specific pricelist id in odoo in sale order:</p> <pre><code>@api.onchange('product_uom', 'product_uom_qty') def product_uom_change(self): if not self.product_uom: self.price_unit = 0.0 return if self.order_id.pricelist_id and self.order_id.partner_id: ...
0
2016-08-16T11:36:12Z
38,991,666
<p>There is a flaw in logic here. The <code>self.order_id.pricelist_id</code> points to a <em>single</em> pricelist and there are no first or last options. </p> <p>If you would like to get a list of pricelists and take the last of them, you could do something like:</p> <pre><code>domain = [] # returns all records in...
1
2016-08-17T08:29:02Z
[ "python", "openerp", "odoo-9" ]
Permutations in list of lists
38,974,000
<p>So, say I have a list of lists like</p> <pre><code>l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] </code></pre> <p>How do I get all possible permutations with the restriction that I can only pick 1 item per list? Meaning that 147 or 269 would be possible permutations, whereas 145 would be wrong since 4 and 5 are in the sam...
0
2016-08-16T11:42:08Z
38,974,244
<p>this worked in python 3, see the comment on the last line for python 2</p> <pre><code>l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] row1, row2, row3 = l # get all the permutations as lists [1,4,7], etc. permutations = ([x, y, z] for x in row1 for y in row2 for z in row3) # get strings to have a more easily readable outpu...
0
2016-08-16T11:53:46Z
[ "python", "list", "permutation" ]
Permutations in list of lists
38,974,000
<p>So, say I have a list of lists like</p> <pre><code>l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] </code></pre> <p>How do I get all possible permutations with the restriction that I can only pick 1 item per list? Meaning that 147 or 269 would be possible permutations, whereas 145 would be wrong since 4 and 5 are in the sam...
0
2016-08-16T11:42:08Z
38,974,424
<p>This works for me in Python 2.7 and 3.5</p> <pre><code>import itertools l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] print(list(itertools.product(*l))) </code></pre> <p>it returns</p> <pre><code>[(1, 4, 7), (1, 4, 8), (1, 4, 9), (1, 5, 7), (1, 5, 8), (1, 5, 9), (1, 6, 7), (1, 6, 8), (1, 6, 9), (2, 4, 7), (2, 4, 8), (2, ...
2
2016-08-16T12:01:41Z
[ "python", "list", "permutation" ]
Permutations in list of lists
38,974,000
<p>So, say I have a list of lists like</p> <pre><code>l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] </code></pre> <p>How do I get all possible permutations with the restriction that I can only pick 1 item per list? Meaning that 147 or 269 would be possible permutations, whereas 145 would be wrong since 4 and 5 are in the sam...
0
2016-08-16T11:42:08Z
38,974,439
<p>I wouldn't call what you are looking for permutations, but the following recursive algorithm should return what I assume you would like to see</p> <pre><code>def get_all_possibilities(S, P=[]): if S == []: return P s = S[0] if P == []: for x in s: P.append(str(x)) re...
0
2016-08-16T12:02:11Z
[ "python", "list", "permutation" ]
Permutations in list of lists
38,974,000
<p>So, say I have a list of lists like</p> <pre><code>l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] </code></pre> <p>How do I get all possible permutations with the restriction that I can only pick 1 item per list? Meaning that 147 or 269 would be possible permutations, whereas 145 would be wrong since 4 and 5 are in the sam...
0
2016-08-16T11:42:08Z
38,974,470
<p>You could use recursion.</p> <pre><code>l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] def permutate(w, l): for x in l[0]: if len(l) &gt; 1: permutate(w + str(x), l[1:]) else: print w + str(x) permutate("", l) </code></pre>
0
2016-08-16T12:03:39Z
[ "python", "list", "permutation" ]
Permutations in list of lists
38,974,000
<p>So, say I have a list of lists like</p> <pre><code>l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] </code></pre> <p>How do I get all possible permutations with the restriction that I can only pick 1 item per list? Meaning that 147 or 269 would be possible permutations, whereas 145 would be wrong since 4 and 5 are in the sam...
0
2016-08-16T11:42:08Z
38,974,523
<p>You can use <a href="https://docs.python.org/2.7/library/itertools.html" rel="nofollow">itertools</a> for this!</p> <pre><code>from itertools import product l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] print(list(product(*l))) </code></pre> <p>A few things to note:</p> <ul> <li><p>I'm passing <code>*l</code> instead of ...
0
2016-08-16T12:05:59Z
[ "python", "list", "permutation" ]
Rename many files sequentially Python
38,974,166
<p>My training on Python is ongoing and I'm currently trying to rename sequentially many files that have this kind of root and extension:</p> <p>Ite_1_0001.eps</p> <p>Ite_2_0001.eps</p> <p>Ite_3_0001.eps</p> <p>Ite_4_0001.eps</p> <p>However, I'm trying to rename all these files as follows:</p> <p>Ite_0001.eps</p>...
3
2016-08-16T11:50:20Z
38,974,203
<p>You can dynamically change the thing you're substituting in within your loop, like so</p> <pre><code>import os, re n = 1 for i in os.listdir('.'): os.rename(i, re.sub(r'\(\d{4}\)', '(Ite_) ({n})'.format(n=n), i)) n += 1 </code></pre>
2
2016-08-16T11:52:06Z
[ "python" ]
Rename many files sequentially Python
38,974,166
<p>My training on Python is ongoing and I'm currently trying to rename sequentially many files that have this kind of root and extension:</p> <p>Ite_1_0001.eps</p> <p>Ite_2_0001.eps</p> <p>Ite_3_0001.eps</p> <p>Ite_4_0001.eps</p> <p>However, I'm trying to rename all these files as follows:</p> <p>Ite_0001.eps</p>...
3
2016-08-16T11:50:20Z
38,974,531
<p>I write a function that if you give in input your basename it returns the correct name.</p> <pre><code>def newname(old_name): num = old_name[4] return (old_name[0:3] + old_name[5:-1] + num) </code></pre>
0
2016-08-16T12:06:17Z
[ "python" ]
Rename many files sequentially Python
38,974,166
<p>My training on Python is ongoing and I'm currently trying to rename sequentially many files that have this kind of root and extension:</p> <p>Ite_1_0001.eps</p> <p>Ite_2_0001.eps</p> <p>Ite_3_0001.eps</p> <p>Ite_4_0001.eps</p> <p>However, I'm trying to rename all these files as follows:</p> <p>Ite_0001.eps</p>...
3
2016-08-16T11:50:20Z
38,974,729
<p>You could test the approach with a list of strings. So you do not run the risk of deleting the files. ;-)</p> <pre><code>files = ["Ite_1_0001.eps", "Ite_2_0001.eps", "Ite_3_0001.eps", "Ite_4_0001.eps",] for f in files: # Get the value between underscores. This is the index. index = int(f[4:f.index('_', 4)]...
2
2016-08-16T12:14:50Z
[ "python" ]
How to insert/append unstructured data to bigquery table
38,974,176
<p><strong>Background</strong></p> <p>I want to insert/append newline formatted JSON into <code>bigquery</code> table through python client API.</p> <p>Eg:</p> <pre><code>{"name":"xyz",mobile:xxx,location:"abc"} {"name":"xyz",mobile:xxx,age:22} </code></pre> <p>Issue is, all fields in a row are optional and there i...
1
2016-08-16T11:50:39Z
38,978,809
<p>You can use autodetect with BigQuery load API, i.e. your example using bq cli tool will look like following:</p> <pre><code>~$ cat /tmp/x.json {"name":"xyz","mobile":"xxx","location":"abc"} {"name":"xyz","mobile":"xxx","age":"22"} ~$ bq load --autodetect --source_format=NEWLINE_DELIMITED_JSON tmp.x /tmp/x.json Upl...
2
2016-08-16T15:26:39Z
[ "python", "python-2.7", "api", "google-app-engine", "google-bigquery" ]
File seperation
38,974,207
<pre><code>with open('C:\Users\craig\Downloads\folder\test.txt', 'r') as myfile: test = myfile.read().replace('', '') </code></pre> <p>test.txt is:</p> <pre><code>hugh:ted mark:mike ethan:jay </code></pre> <p>how would I get python to remove the : and everything past :? For example, how would I remove :ted, :mik...
-3
2016-08-16T11:52:13Z
38,974,697
<pre><code>import fileinput for line in fileinput.input('C:\Users\craig\Downloads\folder\test.txt', inplace=True): if ':' in line: print line.replace(line[line.index(':'):], '') </code></pre>
0
2016-08-16T12:13:51Z
[ "python", "file" ]
File seperation
38,974,207
<pre><code>with open('C:\Users\craig\Downloads\folder\test.txt', 'r') as myfile: test = myfile.read().replace('', '') </code></pre> <p>test.txt is:</p> <pre><code>hugh:ted mark:mike ethan:jay </code></pre> <p>how would I get python to remove the : and everything past :? For example, how would I remove :ted, :mik...
-3
2016-08-16T11:52:13Z
38,975,089
<p>you can try the following code snippet.</p> <pre><code>import re import fileinput for line in fileinput.FileInput("/home/dma3node/test.txt", inplace=1): line = re.sub(r"\:(.*)", "", line) print line </code></pre>
0
2016-08-16T12:34:01Z
[ "python", "file" ]
WSGI application raised an exception
38,974,253
<p>I am facing a wsgi exception while running my flask application code in the server. </p> <p>Here is my manage.py </p> <pre><code>from app import app1, db from flask_script import Manager, Shell from flask_migrate import Migrate, MigrateCommand migrate = Migrate(app1, db) manager = Manager(app1) manager.add_comma...
0
2016-08-16T11:54:01Z
38,977,526
<p>Import the Flask application as the application to run, not the Flask-Script manager.</p> <pre><code>from app import app1 as application </code></pre> <p>A Flask-Script manager is for running commands on the command line. It is not a WSGI application. You can still use it to run other commands, but the WSGI serv...
2
2016-08-16T14:25:12Z
[ "python", "python-2.7", "flask", "passenger", "flask-sqlalchemy" ]
How reverse works in python
38,974,416
<p>I have an array which contains some elements. </p> <p>How by doing <code>arr[::-1]</code> sort the entire array? </p> <p>What is the logic behind that?</p>
0
2016-08-16T12:01:18Z
38,974,477
<p>This is <a href="https://docs.python.org/2/whatsnew/2.3.html#extended-slices" rel="nofollow">extended slice</a> syntax. It works by doing [begin:end:step] - by leaving begin and end off and specifying a step of -1, it reverses a string. Example: </p> <pre><code>&gt;&gt;&gt; 'hello world'[::-1] 'dlrow olleh' </code>...
5
2016-08-16T12:04:00Z
[ "python", "reverse" ]
Python generator to list
38,974,429
<p>I have a Python generator <code>lexg</code> which produces a list at each iteration. The code seems to work in the traditional <code>for</code>-loop sense, that is, </p> <pre><code>for i in lexg(2,2): print(i) </code></pre> <p>produces:</p> <pre><code>[2, 0] [1, 1] [1, 0] [0, 2] [0, 1] [0, 0] </code></pre> <p>bu...
0
2016-08-16T12:01:44Z
38,974,585
<p>As pointed out by <a href="http://stackoverflow.com/users/476/deceze">deceze</a> you essentially end up with a list of lists pointing to the same instance </p> <p>To make it more clear, try that </p> <pre><code>a = list(lexg(2,2)) a[0][0] = 3 print(a) </code></pre> <p>which results in</p> <pre><code>[[3, 0], [...
4
2016-08-16T12:08:58Z
[ "python", "recursion", "generator", "yield-keyword" ]
Pandas: read csv file with UCS-2 LE coding
38,974,446
<p>I would like to import 10K csv files generated by 3rd party app with UCS-2 LE coding. I wouldn't like to use csv reader as in example <a href="http://stackoverflow.com/questions/9177820/python-utf-16-csv-reader">Python UTF-16</a> as there are so many files.</p> <p>Below you can find my code, where I'm trying to rea...
1
2016-08-16T12:02:31Z
38,977,201
<p>Actually I don't know how your expected output might be, but I'm reading your files with:</p> <pre><code>df = pd.read_csv('1.csv', encoding="utf-16", skip_blank_lines=True, error_bad_lines=False, decimal=',', sep='\s+', skiprows=5) </code></pre> <p>obtaining something like:</p> <pre><code>In [17]: df.head() Out[1...
1
2016-08-16T14:10:01Z
[ "python", "csv", "pandas" ]
Regex search and replace: How to move characters in a block of text
38,974,589
<p>I'm having a search and replace problem. Take this example.</p> <p>I want to go from:</p> <pre><code>"Word1 word2 =word3 *word4 word5= word6 word7* (*word8)" </code></pre> <p>To this:</p> <pre><code>"Word1 word2 word3= word4* word5= word6 word7* word8*" </code></pre> <p>i.e. To replace any word starting a * or ...
3
2016-08-16T12:09:18Z
38,974,683
<p>You need 2 capture group and replace them together:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; &gt;&gt;&gt; s = "Word1 word2 =word3 *word4 word5= word6 word7* (*word8)" &gt;&gt;&gt; &gt;&gt;&gt; re.sub(r'(\*|=)(\b\w+\b)', r'\2\1', s) 'Word1 word2 word3= word4* word5= word6 word7* (word8*)' </code></pre>
3
2016-08-16T12:13:18Z
[ "python", "regex", "replace" ]
Regex search and replace: How to move characters in a block of text
38,974,589
<p>I'm having a search and replace problem. Take this example.</p> <p>I want to go from:</p> <pre><code>"Word1 word2 =word3 *word4 word5= word6 word7* (*word8)" </code></pre> <p>To this:</p> <pre><code>"Word1 word2 word3= word4* word5= word6 word7* word8*" </code></pre> <p>i.e. To replace any word starting a * or ...
3
2016-08-16T12:09:18Z
38,975,121
<p>Use a <strong><em>verbose</em></strong> expression like the following:</p> <pre><code>import re rx = re.compile(''' \(? # opening parenthesis or not ([*=]) # capture one of * or = to Group 1 (\w+) # at least one word chararacter to Group 2 \)? # a closing parenthesis ''', re.VERBOSE) string ...
2
2016-08-16T12:36:13Z
[ "python", "regex", "replace" ]
How does one reorder information in an XML document in python 3?
38,974,656
<p>Let's suppose I have the following <em>XML structure</em>:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;Document&gt; &lt;CstmrCdtTrfInitn&gt; &lt;GrpHdr&gt; &lt;other_tags&gt;a&lt;/other_tags&gt; &lt;!--here there might be other nested tags inside &lt;other_tags&gt;&lt;/o...
0
2016-08-16T12:12:13Z
38,992,273
<p>I'm not going to give you the code you want. Instead I'll say how you can go about doing what you want.</p> <p>First things first you want to read your xml. So I'll be using <a href="https://docs.python.org/3.5/library/xml.etree.elementtree.html" rel="nofollow"><code>xml.etree.ElementTree</code></a>.</p> <pre><cod...
1
2016-08-17T09:02:47Z
[ "python", "xml", "python-3.x" ]
How do I access my google plus content and the things that have been shared with me via the API
38,974,740
<p>I wish to get a listing of all my posts as well as of any and all shares sent to me on my Google+ page, I want to do that from a python script that has no html or other front end.However I am confused as to how I can get access to the content. According to the google developers site I can not get an OAuth token for ...
0
2016-08-16T12:15:24Z
38,974,779
<p>There is a <a href="https://github.com/googleplus/gplus-quickstart-python" rel="nofollow">Github repo</a> that can help you</p> <ul> <li>Using the Google+ Sign-In button to get an OAuth 2.0 refresh token.</li> <li>Exchanging the refresh token for an access token.</li> <li>Making Google+ API requests with the access...
1
2016-08-16T12:18:20Z
[ "python", "json", "oauth-2.0", "google-plus" ]
How to SSH from one system to another using python
38,974,822
<p>I am trying to perform SSH from one system to another using paramiko in python </p> <pre><code>import paramiko ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy()) ssh.connect('127.0.0.1', username='jesse', password='lol') </code></pre> <p>using this reference (<a href="http://jes...
0
2016-08-16T12:20:13Z
38,974,911
<p><code>SSHClient.connect</code> accepts a kwarg <code>key_filename</code>, which is a path to the local private key file (or files, if given a list of paths). See the <a href="http://docs.paramiko.org/en/2.0/api/client.html#paramiko.client.SSHClient.connect" rel="nofollow">docs</a>.</p> <blockquote> <p>key_filenam...
4
2016-08-16T12:24:50Z
[ "python", "ssh", "paramiko" ]
How to SSH from one system to another using python
38,974,822
<p>I am trying to perform SSH from one system to another using paramiko in python </p> <pre><code>import paramiko ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy()) ssh.connect('127.0.0.1', username='jesse', password='lol') </code></pre> <p>using this reference (<a href="http://jes...
0
2016-08-16T12:20:13Z
38,975,102
<p>Adding the key to a configured SSH agent would make paramiko use it automatically with no changes to your code.</p> <pre><code>ssh-add &lt;your private key&gt; </code></pre> <p>Your code will work as is. Alternatively, the private key can be provided programmatically with </p> <pre><code>key = paramiko.RSAKey.fro...
0
2016-08-16T12:34:55Z
[ "python", "ssh", "paramiko" ]
How to SSH from one system to another using python
38,974,822
<p>I am trying to perform SSH from one system to another using paramiko in python </p> <pre><code>import paramiko ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy()) ssh.connect('127.0.0.1', username='jesse', password='lol') </code></pre> <p>using this reference (<a href="http://jes...
0
2016-08-16T12:20:13Z
38,977,022
<p>This code should work:</p> <pre><code>import paramiko host = "&lt;your-host&gt;" client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(host, username='&lt;your-username&gt;', key_filename="/path/to/.ssh/id_rsa" , port=22) # Just to test a command stdin, stdout,...
0
2016-08-16T14:02:12Z
[ "python", "ssh", "paramiko" ]