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 - EOF while scanning triple-quoted string literal
39,543,231
<p>I am trying to write a basic Hangman game and whenever I try to execute it, I get the same error mentioned in the title. I have combed over my code a ton, and while I have fixed some issues I noticed, I still get the same error. Any help? Thanks.</p> <pre><code>import random HANGMANPICS = [''' +---+ | | | | ...
0
2016-09-17T05:38:10Z
39,543,435
<p>You don't end the list of HANGMANPICS - your code appears to be</p> <pre><code> #\/ starts a new list entry which never ends HANGMANPICS = ['''first''', '''second''', ''' words = 'ant baboon badger' .split() </code></pre> <p>and it needs to be</p> <pre><code> ...
0
2016-09-17T06:11:02Z
[ "python", "string", "syntax", "eof" ]
Python selenium - modifying the source code of a webpage
39,543,237
<p>I am using Python selenium to automate my attendance entry. It was working fine, now I wanted to try by modifying the source code. I have seen few posts stating that it can be modified using <code>driver.execute_script()</code> and it works for JavaScript, but in my case I need to modify a source code under the <cod...
2
2016-09-17T05:39:08Z
39,543,372
<p>The problem is that <code>execute_script</code> executes JavaScript inside the browser [1], which knows nothing about python variables in python script. In particuar <code>input_list</code> is not defined for JavaScript, since it's a python variable.</p> <p>To fix this, you can select the element inside the JavaScr...
2
2016-09-17T06:01:45Z
[ "python", "selenium" ]
Python selenium - modifying the source code of a webpage
39,543,237
<p>I am using Python selenium to automate my attendance entry. It was working fine, now I wanted to try by modifying the source code. I have seen few posts stating that it can be modified using <code>driver.execute_script()</code> and it works for JavaScript, but in my case I need to modify a source code under the <cod...
2
2016-09-17T05:39:08Z
39,543,399
<p>Try following solution and let me know if any issues occurs:</p> <pre><code>driver.execute_script("""document.querySelector("select[name='date1'] option").value="2016-09-07";""") </code></pre> <p>P.S. I advise you not to use absolute <code>XPath</code> in your selectors, but relative instead</p>
0
2016-09-17T06:06:03Z
[ "python", "selenium" ]
ValueError: too many values to unpack, while trying to unpack a simple.txt file
39,543,296
<p>I have this simple code to read and plot a .txt file </p> <pre><code>import sys import os import numpy import matplotlib.pyplot as plt from pylab import * exp_sum = 'exponential_sum.txt' Term, Absolute_error, Relative_error= numpy.loadtxt(exp_sum, unpack =True) plt.semilogy(Term,Absolute_error, 'm^-') plt.semilo...
1
2016-09-17T05:48:44Z
39,544,112
<p>You're trying to unpack four columns into three variables -- the <code>Exponential_sum</code> variable is missing!</p>
1
2016-09-17T07:29:13Z
[ "python", "numpy" ]
How to mock class used in separate namespace?
39,543,335
<p>Package Structure:</p> <pre><code>pqr/pq.py test.py </code></pre> <p><code>pqr/pq.py</code> has following structure</p> <p>Where lmn is globally installed pip module</p> <p>Structure of <code>pq.py</code></p> <pre><code>from lmn import Lm class Ab(): def __init__(self): self.lm = Lm() def ech...
2
2016-09-17T05:55:19Z
39,576,275
<p>It doesn't really matter where <code>Lm</code> came from. You imported <code>Lm</code> into the <code>pqr.pq</code> namespace as a global <em>there</em>, so you'd only have replace that name there and nowhere else. That's because the <code>Ab.__init__</code> method will look for it 'locally' in it's own module.</p> ...
3
2016-09-19T14:58:43Z
[ "python", "python-2.7", "namespaces", "mocking", "python-unittest" ]
How to mock class used in separate namespace?
39,543,335
<p>Package Structure:</p> <pre><code>pqr/pq.py test.py </code></pre> <p><code>pqr/pq.py</code> has following structure</p> <p>Where lmn is globally installed pip module</p> <p>Structure of <code>pq.py</code></p> <pre><code>from lmn import Lm class Ab(): def __init__(self): self.lm = Lm() def ech...
2
2016-09-17T05:55:19Z
39,576,637
<p>For testing, you can use the <code>mock</code> module (standard in newer python 3, downloadable from pypi for older versions) to create "fake" classes. There is a great article on the mock library that explains how to do this, which I will link <a href="https://www.toptal.com/python/an-introduction-to-mocking-in-py...
0
2016-09-19T15:16:36Z
[ "python", "python-2.7", "namespaces", "mocking", "python-unittest" ]
How to properly implement trees with n-branching factor in python?
39,543,347
<p>I am trying to implement a minimax algorithm in python, but I am having some issues creating the branching tree structure. I am still an amateur programmer so please don't mind if my code seems bad. Here is my Node Structure </p> <pre><code>class Node: parent = None state = None pmax = 0 #this re...
0
2016-09-17T05:56:39Z
39,543,554
<p>You're hitting the common trip-up with lists and variable bindings in Python - you make <code>children = []</code> a class variable, and that makes it <em>the same list</em> in every Node. There's one list in memory and every Node points to it. Change it, and all Nodes see the change. Move that into <code>__init__</...
0
2016-09-17T06:27:55Z
[ "python", "algorithm", "minimax" ]
Implement timeit() in extended class in python
39,543,357
<p>Naive programmer: I'm trying to use the timeit module but I don't know how. I have extended the class:</p> <pre><code>class Pt: def __init__(self, x,y): self.x = x self.y = y class pt_set(Pt): def __init__(self): self.pts = [] def distance(self): ... ... retur...
0
2016-09-17T05:59:10Z
39,543,577
<p>It is all explained in the <a href="https://docs.python.org/2/library/timeit.html" rel="nofollow">docs</a>, and this is an example taken from there:</p> <pre><code> def test(): """Stupid test function""" L = [] for i in range(100): L.append(i) if __name__ == '__main__': import timeit pr...
0
2016-09-17T06:30:24Z
[ "python", "ipython", "timeit" ]
Is there a way to include the same Mixin more than once in a subclass in Python?
39,543,420
<p>Normally a Python mixin would only be included once, like:</p> <pre><code>class MyMixin: pass class Child(Base, MyMixin): pass </code></pre> <p>However, in some situation it would be handy if we can use the same Mixin twice. For example, I have a Mixin in SQLAlchemy defining some Columns as follow:</p> <...
2
2016-09-17T06:08:33Z
39,552,507
<p>I would recommend using <a href="https://docs.python.org/2/glossary.html#term-decorator" rel="nofollow">python decorator</a>. </p> <p>Here is an example how to get this using plan python class:</p> <pre><code>def custom_fields(**kwargs): def wrap(original_class): """ Apply here your logic, coul...
1
2016-09-17T22:56:53Z
[ "python", "sqlalchemy", "mixins" ]
Python 3 Regex and Unicode Emotes
39,543,720
<p>Using Python 3, a simple script like the following should run as intended, but appears to choke on unicode emote strings:</p> <pre><code>import re phrase = "(╯°□°)╯ ︵ ┻━┻" pattern = r'\b{0}\b'.format(phrase) text = "The quick brown fox got tired of jumping over dogs and flipped a table: (╯°□Â...
2
2016-09-17T06:47:33Z
39,543,786
<pre><code>(╯°□°)╯ ︵ ┻━┻ </code></pre> <p>This expression has brackets in them, you need to escape them. Otherwise they are interpreted as group.</p> <pre><code>In [24]: re.search(r'\(╯°□°\)╯ ︵ ┻━┻', text, re.IGNORECASE) Out[24]: &lt;_sre.SRE_Match object; span=(72, 85), match='(╯°â...
2
2016-09-17T06:55:25Z
[ "python", "regex", "python-3.x", "unicode" ]
Cannot import installed python package
39,543,747
<p>I'm trying to install <strong>python-numpy</strong> package on my ubuntu 14.04 machine. I ran <code>sudo apt-get install python-numpy</code> command to install it and it says the package has been installed but when i try to access it, i'm unable to do so. </p> <p><a href="http://i.stack.imgur.com/HFgza.png" rel="no...
0
2016-09-17T06:51:53Z
39,543,891
<p>When you type:</p> <pre><code>sudo pip install package-name </code></pre> <p>It will default install <strong>python2</strong> version of package-name some packages might be supported in both python3 and python3 some might work might not</p> <p>I would suggest</p> <pre><code>sudo apt-get install python3-pip sudo ...
0
2016-09-17T07:06:18Z
[ "python" ]
Remove similar numbers in a list
39,543,779
<p>How do I remove numbers like 86.1 and 90.1 (or 86.2 and 90.2) from the following list?</p> <pre><code>86.1 86.2 90.1 90.2 </code></pre>
-1
2016-09-17T06:54:48Z
39,543,874
<p>Define a threshold, iterate over the sorted numbers and add up the numbers within the threshold:</p> <pre><code>numbers = [86.1, 86.2, 90.1,90.2] threshold = 1 numbers = iter(numbers) amount = last = next(numbers) count = 1 result = [] for number in sorted(numbers): if number - last &gt; threshold: res...
0
2016-09-17T07:04:28Z
[ "python", "list", "python-2.7" ]
Remove similar numbers in a list
39,543,779
<p>How do I remove numbers like 86.1 and 90.1 (or 86.2 and 90.2) from the following list?</p> <pre><code>86.1 86.2 90.1 90.2 </code></pre>
-1
2016-09-17T06:54:48Z
39,544,504
<p>Try this:</p> <pre><code>base = [86.1, 86.2, 90.1, 90.2] # remove = [86.2, 90.2] remove = [86.1, 90.1] new_list = [item for item in base if item not in remove] print(new_list) </code></pre> <p>In Stack Overflow post <em><a href="http://stackoverflow.com/questions/11434599/remove-list-from-list-in-python">Remove l...
0
2016-09-17T08:09:45Z
[ "python", "list", "python-2.7" ]
Remove similar numbers in a list
39,543,779
<p>How do I remove numbers like 86.1 and 90.1 (or 86.2 and 90.2) from the following list?</p> <pre><code>86.1 86.2 90.1 90.2 </code></pre>
-1
2016-09-17T06:54:48Z
39,545,464
<pre><code>inputList=[86.1, 86.2, 90.1, 90.2] tolerance=1.0 out=[] for num in inputList: if all([abs(num-outAlready)&gt;tolerance for outAlready in out]): out.append(num) print out </code></pre>
0
2016-09-17T10:00:52Z
[ "python", "list", "python-2.7" ]
Converting String of Tuple into Tuple
39,543,811
<p>How to convert a string in Python into a Tuple without splitting the words into characters?</p> <p>String: <code>"('name','value')"</code></p> <p>Expected Output: <code>('name', 'value')</code></p>
1
2016-09-17T06:58:27Z
39,543,842
<p>you can use module <code>ast</code></p> <pre><code>&gt;&gt;&gt; a = "('name','value')" &gt;&gt;&gt; import ast &gt;&gt;&gt; ast.literal_eval(a) ('name', 'value') </code></pre>
1
2016-09-17T07:01:18Z
[ "python" ]
how do i skip part of each line while reading from file in python
39,543,828
<p>I am new to python and not able to figure out how do i accomplish this.</p> <p>Suppose file.txt contains following</p> <pre><code>iron man 1 iron woman 2 man ant 3 woman wonder 4 </code></pre> <p>i want to read this file into dictionary in the below format</p> <pre><code>dict = { 'iron' : ['man', 'woman'], 'man'...
0
2016-09-17T07:00:11Z
39,543,962
<p>you can use <code>collections.defaultdict</code>:</p> <p>you 1st answer</p> <pre><code>import collections.defaultdict my_dict = cillections.defaultdict(list) with open('your_file') as f: for line in f: line = line.strip().split() my_dict[line[0]].append(line[1]) print my_dict </code></pre> ...
0
2016-09-17T07:14:21Z
[ "python" ]
how do i skip part of each line while reading from file in python
39,543,828
<p>I am new to python and not able to figure out how do i accomplish this.</p> <p>Suppose file.txt contains following</p> <pre><code>iron man 1 iron woman 2 man ant 3 woman wonder 4 </code></pre> <p>i want to read this file into dictionary in the below format</p> <pre><code>dict = { 'iron' : ['man', 'woman'], 'man'...
0
2016-09-17T07:00:11Z
39,544,060
<p>For the first question, what you want to do is read each line, split it using white spaces and use a simple if rule to control how you add it to your dictionary:</p> <pre><code>my_dict = {} with open('file.txt', 'r') as f: content = f.read() for line in content.split('\n'): item = line.split() if item[...
0
2016-09-17T07:24:10Z
[ "python" ]
how do i skip part of each line while reading from file in python
39,543,828
<p>I am new to python and not able to figure out how do i accomplish this.</p> <p>Suppose file.txt contains following</p> <pre><code>iron man 1 iron woman 2 man ant 3 woman wonder 4 </code></pre> <p>i want to read this file into dictionary in the below format</p> <pre><code>dict = { 'iron' : ['man', 'woman'], 'man'...
0
2016-09-17T07:00:11Z
39,544,065
<p>Here you go both the parts of your question...Being new to python just spend some time with it like your grilfriend and you will know how it behaves</p> <pre><code>with open ('file.txt','r') as data: k = data.read() lst = k.splitlines() print lst dic = {} dic2 = {} for i in lst: p=i.split(" ") if s...
0
2016-09-17T07:24:37Z
[ "python" ]
Django Task/Command Execution Best Practice/Understanding
39,543,851
<p>I've got a little problem with understanding the django management commands. I've got an Webapplication which displays some network traffic information through eth0. Therefore I've created a python class which analyse the traffic and create/update the specific data in the database. Something like this:</p> <pre><co...
0
2016-09-17T07:01:57Z
39,545,353
<p>What you're doing is not intended to do with management commands. In fact management commands are what the name implies, a command to manage something, do a quick action. Not keep a whole process running for the entire life time of the web app.</p> <p>To achieve what you want, you should write a simple python scrip...
0
2016-09-17T09:48:28Z
[ "python", "django", "django-manage.py", "django-management-command" ]
Python/Pygame: Can you run a program whilst having a Pygame window that can still update?
39,543,888
<p>this is my first question. What I would like to achieve is in a normal window for the text-based game to be running, however I would also like to have a pygame window running as well that shows a map that updates. Thank you in advance.</p>
0
2016-09-17T07:06:08Z
39,545,057
<p>Pygame only supports one display. However, you could divide the screen into multiple <a href="http://www.pygame.org/docs/ref/surface.html" rel="nofollow">Surfaces</a> where one Surface is for the map and the other for the game.</p> <p>Something like this:</p> <pre><code>screen = pygame.display.set_mode((100, 100))...
0
2016-09-17T09:16:07Z
[ "python", "pygame" ]
Python/Pygame: Can you run a program whilst having a Pygame window that can still update?
39,543,888
<p>this is my first question. What I would like to achieve is in a normal window for the text-based game to be running, however I would also like to have a pygame window running as well that shows a map that updates. Thank you in advance.</p>
0
2016-09-17T07:06:08Z
39,551,714
<p>The only way to have the text entries separate to the pygame window is to use <code>someVar = input("A string")</code> so the text input is in the python shell or the command window/Linux terminal and then have pygame reference that var.</p>
0
2016-09-17T21:02:36Z
[ "python", "pygame" ]
Python/Pygame: Can you run a program whilst having a Pygame window that can still update?
39,543,888
<p>this is my first question. What I would like to achieve is in a normal window for the text-based game to be running, however I would also like to have a pygame window running as well that shows a map that updates. Thank you in advance.</p>
0
2016-09-17T07:06:08Z
39,552,335
<p>By <em>normal window</em>, I guess you mean the console window from which your program runs.<br> You need a <em>thread</em>.<br> In the following example, that thread is the one reading the standard input from the command line. </p> <pre><code>from threading import Thread userInput= None def readInput(): whil...
0
2016-09-17T22:33:06Z
[ "python", "pygame" ]
Python/Pygame: Can you run a program whilst having a Pygame window that can still update?
39,543,888
<p>this is my first question. What I would like to achieve is in a normal window for the text-based game to be running, however I would also like to have a pygame window running as well that shows a map that updates. Thank you in advance.</p>
0
2016-09-17T07:06:08Z
39,573,442
<p>Likely in the case of Pygame, you can have simultaneous output to the graphical window and the standard text output.</p> <p>The challenge will be how to obtain user input asynchronously (without blocking).</p> <p>While <code>threads</code> are a good solution, there are others.</p> <p>There are several solutions ...
1
2016-09-19T12:39:52Z
[ "python", "pygame" ]
Python exercise: last letter / first letter
39,543,899
<p>I'm a newbie Python student and I'm going through some simple (but now, for me, complicated) exercises. I tried in many ways, but I decided to stop guessing, because I believe it won't be a sane routine of learning.</p> <p>I have to solve the following exercise:</p> <blockquote> <p>Write a <code>lastfirst(lst)</...
1
2016-09-17T07:06:47Z
39,544,021
<p>I think it will work (in python 3):</p> <pre><code>lst = ['sole','elmo','orco','alba','asta'] def lastfirst(lst): for i in range(len(lst)-1): if lst[i][-1] != lst[i+1][0] : return lst[i+1] return None print(lastfirst(lst)) </code></pre> <p>Output:</p> <pre><code>alba </code></pre> <b...
2
2016-09-17T07:20:17Z
[ "python", "list", "function", "for-loop" ]
Python exercise: last letter / first letter
39,543,899
<p>I'm a newbie Python student and I'm going through some simple (but now, for me, complicated) exercises. I tried in many ways, but I decided to stop guessing, because I believe it won't be a sane routine of learning.</p> <p>I have to solve the following exercise:</p> <blockquote> <p>Write a <code>lastfirst(lst)</...
1
2016-09-17T07:06:47Z
39,544,110
<p>You would use a double <code>for</code> loop when you need to test every word in <code>lst</code> against every other word in <code>lst</code>, but that's not what we want here. We just need a single <code>for</code> loop, and we need to store the previous word so we can test it against the current word. Like this:<...
1
2016-09-17T07:29:05Z
[ "python", "list", "function", "for-loop" ]
Python exercise: last letter / first letter
39,543,899
<p>I'm a newbie Python student and I'm going through some simple (but now, for me, complicated) exercises. I tried in many ways, but I decided to stop guessing, because I believe it won't be a sane routine of learning.</p> <p>I have to solve the following exercise:</p> <blockquote> <p>Write a <code>lastfirst(lst)</...
1
2016-09-17T07:06:47Z
39,544,262
<p>Here's a solution using itertools.</p> <p>First, define a function that returns a boolean if your condition is met:</p> <pre><code>def check_letters(apair): "In a pair, check last letter of first entry with first letter of second" return apair[0][-1] == apair[1][0] </code></pre> <p>Now we use the pairwise fun...
0
2016-09-17T07:43:32Z
[ "python", "list", "function", "for-loop" ]
Streaming mp3 files in Django through Nginx
39,543,946
<p>I have a website based on Django framework. I am running website via Nginx webserver (uWSGI,Django,Nginx). I want to stream mp3 files on my website with Accept-Ranges header. I want to serve my mp3 files with Nginx. I need my API to look like this</p> <pre><code>http://192.168.1.105/stream/rihanna </code></pre> <p...
0
2016-09-17T07:12:58Z
39,614,152
<p>First of all, I did not copy the Nginx configuration file to the available-sites path. And because of it,It didn't work. And in my views.py :</p> <pre><code>response = HttpResponse(mp3_data, content_type="audio/mpeg", status=206) response['X-Accel-Redirect'] = mp3_path </code></pre> <p>these 2 lines must be change...
0
2016-09-21T10:35:24Z
[ "python", "django", "nginx", "http-headers", "uwsgi" ]
Python 3: How to call function from another file and pass arguments to that function ?
39,543,961
<p>I want to call a function from another file and pass arguments from current file to that file. With below example, In file <strong>bye.py</strong> I want to call function "<strong>me</strong>" from "<strong>hi.py</strong>" file and pass "<strong>goodbye</strong>" string to function "<strong>me</strong>". How to do t...
1
2016-09-17T07:14:10Z
39,543,981
<p>Generally when you create files to be imported you must use <code>if __name__ == '__main__'</code> which evaluates to false in case you are importing the file from another file. So your hi.py may look as:</p> <pre><code>def me(string): print(string) if __name__ == '__main__': # Do some local work which sho...
1
2016-09-17T07:16:14Z
[ "python", "function", "python-3.x" ]
How can I access Python code from JavaScript in PyQT 5.7?
39,544,089
<p>I used to do it by attaching an object</p> <pre><code>self.page().mainFrame().addToJavaScriptWindowObject("js_interface", self.jsi) </code></pre> <p>In 5.7 I do:</p> <pre><code>self.page().setWebChannel(self.jsi) </code></pre> <p>But I understandibly get a JavaScript error when I try to access exposed functions:...
0
2016-09-17T07:27:01Z
39,593,748
<p>Take a look at <a href="http://doc.qt.io/qt-5/qtwebchannel-standalone-example.html" rel="nofollow">this page</a>. It contains a useful example (in c++ but easily translatable into python).</p> <p>First of all, you have to use a websocket to communicate from html to your app and viceversa.</p> <p>Then you can set u...
1
2016-09-20T12:11:01Z
[ "javascript", "python", "qt", "pyqt" ]
Python setting global variables in different ways in 2.7
39,544,100
<p>I was trying to practice a concept related to setting global variables using diff methods , but the following example is not working as per my understanding .</p> <pre><code>#Scope.py import os x = 'mod' def f1() : global x x = 'in f1' def f2() : import scope scop...
0
2016-09-17T07:28:11Z
39,545,627
<p>Check out this modified piece of code.</p> <pre><code>x = 'mod' def f1(): global x x = 'in f1' def f2(): import scope scope.x = 'in f2' return scope def print_x(): print(x) def f3(): import sys sc = sys.modules['__main__'] sc.x = 'in f3' return sc if __name__ == "__...
1
2016-09-17T10:17:53Z
[ "python", "scope" ]
collect text from web pages of a given site
39,544,123
<p>There is a site that I frequenly visit and read the "best advice". Here is how I can easily extract the text that I want...</p> <pre><code>import urllib2 from bs4 import BeautifulSoup mylist=list() myurl='http://www.apartmenttherapy.com/carols-east-side-cottage-house-tour-194787' s=urllib2.urlopen(myurl) soup =...
-2
2016-09-17T07:30:26Z
39,695,818
<p>You have to use a js-enabled scraping like the way explained here : <a href="http://koaning.io/dynamic-scraping-with-python.html" rel="nofollow">http://koaning.io/dynamic-scraping-with-python.html</a></p>
0
2016-09-26T06:14:46Z
[ "python", "beautifulsoup", "google-search-api" ]
collect text from web pages of a given site
39,544,123
<p>There is a site that I frequenly visit and read the "best advice". Here is how I can easily extract the text that I want...</p> <pre><code>import urllib2 from bs4 import BeautifulSoup mylist=list() myurl='http://www.apartmenttherapy.com/carols-east-side-cottage-house-tour-194787' s=urllib2.urlopen(myurl) soup =...
-2
2016-09-17T07:30:26Z
39,735,886
<p>You may read the <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow">BeautifulSoup</a> manual first and also learn to use web developper tool to inspect network flow.</p> <p>Once done, you may see that you can get the list of house with a GET request <a href="http://www.apartmenttherapy....
1
2016-09-27T23:37:00Z
[ "python", "beautifulsoup", "google-search-api" ]
Regexing help in python
39,544,125
<p>I am wondering if there is an efficient way to check if a number is in the format 1_2_3_4_5_6_7_8_9_0 , where the '_' is a number. For Example,</p> <p><strong>1</strong>9<strong>2</strong>9<strong>3</strong>7<strong>4</strong>2<strong>5</strong>4<strong>6</strong>2<strong>7</strong>4<strong>8</strong>8<strong>9</s...
0
2016-09-17T07:30:44Z
39,544,156
<blockquote> <p>My initial thought was string indexing, but I quickly discovered that it was too slow</p> </blockquote> <p>Most possibly you are not using the right approach</p> <p>You can always use regex but, string indexing with strides can have better performance than using regex</p> <pre><code>st = "1929374...
0
2016-09-17T07:33:32Z
[ "python", "regex", "string" ]
Regexing help in python
39,544,125
<p>I am wondering if there is an efficient way to check if a number is in the format 1_2_3_4_5_6_7_8_9_0 , where the '_' is a number. For Example,</p> <p><strong>1</strong>9<strong>2</strong>9<strong>3</strong>7<strong>4</strong>2<strong>5</strong>4<strong>6</strong>2<strong>7</strong>4<strong>8</strong>8<strong>9</s...
0
2016-09-17T07:30:44Z
39,544,167
<p>Let's define a string to test:</p> <pre><code>&gt;&gt;&gt; q = '1929374254627488900' </code></pre> <p>Now, let's test it:</p> <pre><code>&gt;&gt;&gt; q[::2] == '1234567890' True </code></pre> <p>That matches. Now, let's try one that doesn't match:</p> <pre><code>&gt;&gt;&gt; q = '1929374254627488901' &gt;&gt;&...
1
2016-09-17T07:34:30Z
[ "python", "regex", "string" ]
Regexing help in python
39,544,125
<p>I am wondering if there is an efficient way to check if a number is in the format 1_2_3_4_5_6_7_8_9_0 , where the '_' is a number. For Example,</p> <p><strong>1</strong>9<strong>2</strong>9<strong>3</strong>7<strong>4</strong>2<strong>5</strong>4<strong>6</strong>2<strong>7</strong>4<strong>8</strong>8<strong>9</s...
0
2016-09-17T07:30:44Z
39,544,190
<p>Here you go, indexing is fast O(1)</p> <pre><code>&gt;&gt;&gt; my_number = 1929374254627488900 &gt;&gt;&gt; int(str(my_number)[1::2]) 997242480 # actual number &gt;&gt;&gt; int(str(my_number)[0::2]) 1234567890 #format </code></pre>
0
2016-09-17T07:36:27Z
[ "python", "regex", "string" ]
Continuously attempt to connect bluetooth socket until connection is successful
39,544,127
<p>I want to keep trying to connect to a bluetooth device until the connection is successful. The code below uses a recursive call, and this could lead to the maximum level of recursion being met.</p> <p>Does <code>BluetoothSocket.connect()</code> return a value for success or failure?</p> <pre><code>def connect(self...
1
2016-09-17T07:30:48Z
39,582,778
<p><code>BluetoothSocket.connect()</code> does not explicitly return a value that signals success or failure. However, this can be achieved by returning an error flag when <code>bluetooth.btcommon.BluetoothError</code> exception is caught.</p> <p>So in the except block, instead of trying to connect again right there, ...
0
2016-09-19T21:59:42Z
[ "python", "bluetooth" ]
Setting values of an array without a loop
39,544,152
<p>I have arrays called <code>rad</code>, <code>relative_x</code>, <code>relative_y</code>, where <code>rad</code> is not of the same size as the other two. I want to create an array called <code>masking</code>, that will have the length of <code>rad</code> in the following way:</p> <pre><code>masking[i] = (relative_x...
0
2016-09-17T07:33:18Z
39,544,295
<p><code>zip()</code> and a list comprehension pretty much does it. You still have a loop, but it's somewhat hidden.</p> <pre><code>&gt;&gt;&gt; rad = [1.42, 4, 8] &gt;&gt;&gt; relative_x = [1, 2, 3, 4, 5] &gt;&gt;&gt; relative_y = [1, 2, 3, 4, 5] &gt;&gt;&gt; &gt;&gt;&gt; masking = [rad_**2 &gt;= relative_x_**2 + re...
0
2016-09-17T07:47:32Z
[ "python", "arrays" ]
IOError: [Errno 13] when installing virtualwrapper
39,544,184
<p>After successfully installling virtualenv in terminal with 'pip install virtualenv', I tried installing virtualwrapper with 'pip install virtualenvwrapper' and something seems to have gone wrong with some code presenting in red instead of the usual white. There was about 20-30 lines of code in essence it said the f...
0
2016-09-17T07:35:55Z
39,544,523
<p>when it's about permission problem you have try with sudo(super user).</p> <p>if Linux,</p> <p><code>$ sudo pip install virtualenvwrapper</code></p> <p>if Windows,</p> <p>open cmd with administration privilege and then,</p> <p><code>pip install virtualenvwrapper</code></p>
0
2016-09-17T08:12:26Z
[ "python", "virtualenvwrapper", "errno", "ioerror" ]
IOError: [Errno 13] when installing virtualwrapper
39,544,184
<p>After successfully installling virtualenv in terminal with 'pip install virtualenv', I tried installing virtualwrapper with 'pip install virtualenvwrapper' and something seems to have gone wrong with some code presenting in red instead of the usual white. There was about 20-30 lines of code in essence it said the f...
0
2016-09-17T07:35:55Z
39,568,398
<p>First, uninstall virtualenv</p> <pre><code># you might need to use sudo depending on how you installed it pip uninstall virtualenv </code></pre> <p>Then, install virtualenvwrapper with sudo</p> <pre><code>sudo pip install virtualenwrapper </code></pre> <p>Since virtualenvwrapper has virtualenv among its depend...
0
2016-09-19T08:19:36Z
[ "python", "virtualenvwrapper", "errno", "ioerror" ]
IOError: [Errno 13] when installing virtualwrapper
39,544,184
<p>After successfully installling virtualenv in terminal with 'pip install virtualenv', I tried installing virtualwrapper with 'pip install virtualenvwrapper' and something seems to have gone wrong with some code presenting in red instead of the usual white. There was about 20-30 lines of code in essence it said the f...
0
2016-09-17T07:35:55Z
39,568,497
<p>You should install virtualenvwrapper via system package manager.</p> <p>Either <code>dnf install python-virtualenvwrapper</code> on Fedora or <code>apt-get install virtualenvwrapper</code> on Debian/Ubuntu.</p>
0
2016-09-19T08:24:20Z
[ "python", "virtualenvwrapper", "errno", "ioerror" ]
Remove emojis from python string
39,544,235
<p>I need to remove emoji's from some strings using a python script. I found that someone already asked this <a href="http://stackoverflow.com/questions/33404752/removing-emojis-from-a-string-in-python">question</a>, and one of the answers was marked as successful, namely that the following code would do the trick:</p>...
1
2016-09-17T07:40:05Z
39,544,664
<p>Your Python build uses <a href="https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates" rel="nofollow">surrogate pairs</a> to represent unicode characters that can't be represented in 16 bits -- it's a so-called "narrow build". This means that any value at or above <code>u"\U00010000"</code> is ...
0
2016-09-17T08:33:52Z
[ "python", "python-2.7" ]
Changing values in column selectively. Python Pandas
39,544,270
<p>for example i have a fruit dataset that contains the name and colour. How do i change the values in colour column based on the fruit name that i select?</p> <pre><code> Name Color Apple NaN Pear Green Pear Green Banana Yellow Waterme...
0
2016-09-17T07:44:44Z
39,544,291
<p>One way is to use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html" rel="nofollow">.apply()</a>:</p> <pre><code>In [83]: df Out[83]: Name Color 0 Apple NaN 1 Pear Green 2 Pear Green 3 Banana Yellow 4 Watermelon Green In [84]...
1
2016-09-17T07:47:14Z
[ "python", "pandas" ]
ConfigParser instance has no attribute '__setitem__'
39,544,331
<p>i'm trying to initialize the config file </p> <pre><code>import ConfigParser config = ConfigParser.ConfigParser() config['Testing'] = {"name": "Yohannes", "age": 10} with open("test.ini", "w") as configFile: config.write(configFile) </code></pre> <p>but it keeps throwing this error </p> <pre><code>Traceback...
-1
2016-09-17T07:52:06Z
39,544,402
<pre><code>config.Testing = {"name": "Yohannes", "age": 10} </code></pre>
-1
2016-09-17T07:59:15Z
[ "python", "python-2.7", "file", "configuration" ]
ConfigParser instance has no attribute '__setitem__'
39,544,331
<p>i'm trying to initialize the config file </p> <pre><code>import ConfigParser config = ConfigParser.ConfigParser() config['Testing'] = {"name": "Yohannes", "age": 10} with open("test.ini", "w") as configFile: config.write(configFile) </code></pre> <p>but it keeps throwing this error </p> <pre><code>Traceback...
-1
2016-09-17T07:52:06Z
39,544,488
<p>You are simply not using it right. <a href="https://docs.python.org/2/library/configparser.html#examples" rel="nofollow">Here</a> you can find examples.</p> <pre><code>config = ConfigParser.ConfigParser() config.add_section('Testing') config.set('Testing', 'name', 'Yohannes') config.set('Testing', 'age', 10) </code...
0
2016-09-17T08:08:18Z
[ "python", "python-2.7", "file", "configuration" ]
Python Regex matching any order
39,544,344
<p>Lets say I have datetime in the format</p> <pre><code>12 September, 2016 September 12, 2016 2016 September, 12 </code></pre> <p>I need regex like it should return match in same order always for any dateformat given above</p> <pre><code>match-1 : 12 match-2 : September match-3 : 2016 </code></pre> <p>I need resul...
0
2016-09-17T07:53:13Z
39,544,382
<p>You cannot change group orderings. You need to do a "or" of 3 patterns and then pass through the result to determine which group mapped to what, which should be pretty simple.</p>
0
2016-09-17T07:57:34Z
[ "python", "regex", "datetime", "match" ]
Python Regex matching any order
39,544,344
<p>Lets say I have datetime in the format</p> <pre><code>12 September, 2016 September 12, 2016 2016 September, 12 </code></pre> <p>I need regex like it should return match in same order always for any dateformat given above</p> <pre><code>match-1 : 12 match-2 : September match-3 : 2016 </code></pre> <p>I need resul...
0
2016-09-17T07:53:13Z
39,546,729
<p>You can't switch the group order but you can name your groups:</p> <pre><code>(r'(?P&lt;day&gt;[\d]{2})(?:\s|,|\?|$)|(?P&lt;month&gt;[a-zA-Z]+)|(?P&lt;year&gt;[\d]{4})') </code></pre> <ul> <li><p><code>(?P&lt;day&gt;[\d]{2})(?:\s|,|\?|$)</code>: matches a day, can be accessed in python with <code>l.group("day")</c...
0
2016-09-17T12:18:22Z
[ "python", "regex", "datetime", "match" ]
Python Regex matching any order
39,544,344
<p>Lets say I have datetime in the format</p> <pre><code>12 September, 2016 September 12, 2016 2016 September, 12 </code></pre> <p>I need regex like it should return match in same order always for any dateformat given above</p> <pre><code>match-1 : 12 match-2 : September match-3 : 2016 </code></pre> <p>I need resul...
0
2016-09-17T07:53:13Z
39,546,970
<p>Named groups as suggested below is a good way of doing it (especially if you already have the regexes set up) but for completion's sake here's how to handle it with the <code>datetime</code> module.</p> <pre><code>from datetime import datetime as date def parse_date(s): formats = ["%d %B, %Y", "...
2
2016-09-17T12:44:52Z
[ "python", "regex", "datetime", "match" ]
Input and Output of function in pyspark
39,544,499
<p>I'd like to get some lesson about the input grammar in pyspark.</p> <p>My platform is below.</p> <pre><code>Red Hat Enterprise Linux Server release 6.8 (Santiago) spark version 1.6.2 python 2.6 </code></pre> <p>I have def defined in module <strong>basic_lib.py</strong> as below.</p> <pre><code>def selectRowByTim...
1
2016-09-17T08:09:16Z
39,546,601
<p>It looks like you're slightly confused about what exactly is the purpose of <code>lambda</code> expressions. In general <code>lambda</code> expression in Python are used to create anonymous, single expression functions. Other than than that, as far as we care here, there are not different than any other function you...
2
2016-09-17T12:04:51Z
[ "python", "apache-spark", "pyspark" ]
Python 3 installing tweepy
39,544,517
<p>I have looked at all the forums, but nothing has worked so far. I have spent hours trying to install it so any help would be appreciated. i have downloaded and unzipped tweepy, went on to the command prompt, typed "cd tweepy-master". This works, but when i type "python setup.py install" or "python setup.py build".</...
0
2016-09-17T08:12:05Z
39,544,668
<p><code>pip</code> is the good way to install a package. If you are not interested then you can install from source.</p> <p>But you have to remember that, If you are using <code>virtualenv</code> or <code>virtualenvwrapper</code> then you can use <code>python setup.py install</code> otherwise you should use <code>sud...
0
2016-09-17T08:34:13Z
[ "python", "python-3.x", "tweepy" ]
Python 3 installing tweepy
39,544,517
<p>I have looked at all the forums, but nothing has worked so far. I have spent hours trying to install it so any help would be appreciated. i have downloaded and unzipped tweepy, went on to the command prompt, typed "cd tweepy-master". This works, but when i type "python setup.py install" or "python setup.py build".</...
0
2016-09-17T08:12:05Z
39,544,778
<p>Have you installed Python using the Windows installer from <a href="https://www.python.org/downloads/windows/" rel="nofollow">python.org</a>?</p> <p>Cause this comes with pip already bundled into it. (I can not check the exact location atm, as I am on a Mac, but according to this <a href="http://stackoverflow.com/q...
0
2016-09-17T08:46:27Z
[ "python", "python-3.x", "tweepy" ]
TypeError in Python Programming
39,544,553
<p>I wrote the following program for square each digit of a number. But, it is showing an error as "int" object is not iterable.</p> <pre><code>def square_digits(num): a = 1 for i in num: a = i * i return a result = square_digits(12) print(result) </code></pre>
-2
2016-09-17T08:17:57Z
39,544,592
<p>You're looking for the <code>range(num)</code> function.</p> <p>You probably also want to use a <code>list</code> (denoted by <code>[brackets, and, commas]</code>).</p> <p>Try this for example:</p> <pre><code>my_list = [] # empty list for char in 'aword': my_list.append(char * 2) print(my_list) </code></pre> ...
2
2016-09-17T08:21:51Z
[ "python" ]
TypeError in Python Programming
39,544,553
<p>I wrote the following program for square each digit of a number. But, it is showing an error as "int" object is not iterable.</p> <pre><code>def square_digits(num): a = 1 for i in num: a = i * i return a result = square_digits(12) print(result) </code></pre>
-2
2016-09-17T08:17:57Z
39,545,176
<p>first off, this is how to fix your code:</p> <p>If you want a list of squared numbers beginning from 1 to num:</p> <pre><code>` def square_digits(num): # initialize an empty list a = [] # why num + 1 when you want numbers until num? check out this link for an explanation # on how to use and the dif...
1
2016-09-17T09:31:29Z
[ "python" ]
Convert Python generated protobuf to java without .proto file
39,544,595
<p>Today I receive some Python files (.py) generated from Protocol Buffer (v2). Is there anyway i can convert them to Java version without the original .proto file ? I know it sounds silly but it's just that i'm working on a project for a new client and this happens.</p>
3
2016-09-17T08:21:57Z
39,550,933
<p>Use the <a href="http://www.jython.org/archive/21/docs/jythonc.html" rel="nofollow">jythonc</a> tool supplied with Jython.</p>
0
2016-09-17T19:34:02Z
[ "java", "python", "protocol-buffers", "reverse-engineering", "google-protobuf" ]
Custom parameter in Flask-WTFoms field
39,544,715
<p><strong><em>forms.py</em></strong></p> <pre><code>my_field = TextField(u"Enter a number", validators=[Required('This Field is Required')]) </code></pre> <p><strong><em>my_form.html</em></strong></p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td colspan="4"&gt; {{form.my_field(placeholder= form.my_field....
1
2016-09-17T08:40:16Z
39,545,633
<p>You need to create a <a href="http://wtforms.simplecodes.com/docs/0.6.1/fields.html#custom-fields" rel="nofollow">custom field</a> with an extra <code>colspan</code> attribute.</p> <p>First define the custom field sub classing <code>TextField</code>:</p> <pre><code>class MyCustomTextField(TextField): def __ini...
1
2016-09-17T10:18:20Z
[ "python", "flask", "jinja2", "flask-wtforms" ]
How to implement a Telegram bot program that could handle multiple steps of input?
39,544,757
<p>I'm programming a telegram bot in Python3 using the Telegram bot API. I'm facing the problem of handling requests that need multiple steps to couplet. For example, for an airline search bot:</p> <ol> <li>the bot ask for departure city, </li> <li>the user input a name,</li> <li>the bot ask for destination,</li> <li...
0
2016-09-17T08:44:37Z
39,546,618
<p>You need to have a question tree that users can traverse it. you can use a linked list for it and saved this tree in the database. For each question there is a method that take some actions (like store in database) and send a question/result to the user. Each user has a <code>CurrentState</code> that contain state o...
0
2016-09-17T12:06:34Z
[ "python", "api", "python-3.x", "telegram" ]
pyspark,spark: how to select last row and also how to access pyspark dataframe by index
39,544,796
<p>from a pyspark sql dataframe like </p> <pre><code>name age city abc 20 A def 30 B </code></pre> <p>How to get the last row.(Like by df.limit(1) I can get first row of dataframe into new dataframe).</p> <p>And how can I access the dataframe rows by index.like row no. 12 or 200 .</p> <p>In pandas I can do</p...
2
2016-09-17T08:48:10Z
39,548,362
<blockquote> <p>How to get the last row.</p> </blockquote> <p>Long and ugly way which assumes that all columns are oderable:</p> <pre><code>from pyspark.sql.functions import ( col, max as max_, struct, monotonically_increasing_id ) last_row = (df .withColumn("_id", monotonically_increasing_id()) .selec...
2
2016-09-17T15:10:19Z
[ "python", "apache-spark", "pyspark", "pyspark-sql" ]
Get Flask to serve index.html in a directory
39,544,862
<p>I have 2 static directories in Flask.</p> <h3>static/</h3> <ul> <li><code>css/</code></li> <li><code>js/</code></li> </ul> <h3>results/</h3> <ul> <li><code>1/</code> <ul> <li><code>index.html</code></li> <li><code>details.json</code></li> </ul></li> <li><code>2/</code> <ul> <li><code>index.html</code></li> <li...
1
2016-09-17T08:53:42Z
39,545,134
<p>Try this:</p> <pre><code>@app.route('/results/&lt;path:file&gt;', defaults={'file': 'index.html'}) def serve_results(file): # Haven't used the secure way to send files yet return send_from_directory(app.config['RESULT_STATIC_PATH'], file) </code></pre> <p>This is how you pass a default value for that argum...
2
2016-09-17T09:25:17Z
[ "python", "flask" ]
Get Flask to serve index.html in a directory
39,544,862
<p>I have 2 static directories in Flask.</p> <h3>static/</h3> <ul> <li><code>css/</code></li> <li><code>js/</code></li> </ul> <h3>results/</h3> <ul> <li><code>1/</code> <ul> <li><code>index.html</code></li> <li><code>details.json</code></li> </ul></li> <li><code>2/</code> <ul> <li><code>index.html</code></li> <li...
1
2016-09-17T08:53:42Z
39,566,101
<p>I couldn't find a solution which only used one route. I ended up using this.</p> <pre><code>@app.route('/results/&lt;path:filename&gt;') def serve_static(filename): return send_from_directory("results/", filename) @app.route('/results/&lt;guid&gt;') def index(guid): return send_from_directory("results/" + gu...
0
2016-09-19T05:44:40Z
[ "python", "flask" ]
Python 3.5.2 variable Error
39,544,890
<p>I have installed python 3.5.2 but when i try to get the value from user it doesn't work it only shows the message but never get the value from user how can i solve this problem??</p> <p><img src="http://i.stack.imgur.com/ehBYZ.jpg" alt="enter image description here"></p>
-1
2016-09-17T08:57:17Z
39,545,369
<p>Like @Moses said, you have to use the <a href="https://docs.python.org/3/library/functions.html#input" rel="nofollow">input()</a> function:</p> <pre><code>&gt;&gt;&gt; d = input('Enter the num here: ') Enter the num here: 222 &gt;&gt;&gt; d '222' &gt;&gt;&gt; int(d) 222 </code></pre>
0
2016-09-17T09:49:22Z
[ "python", "python-3.x" ]
Check if an string has an integer in an if condition
39,544,924
<pre><code>file = open('Name.txt', 'r') name = str(file.read()) file.close() </code></pre> <p>In the file called 'Name.txt', the user will input a name. The program is to check whether or not the name is valid.</p> <p>E.g:</p> <p>1bob - is not valid</p> <p>bob - is valid</p> <p>Is it possible to do this with an i...
-1
2016-09-17T09:01:07Z
39,545,000
<pre><code>def validate(my_file): return not any(x.isdigit() for x in open(my_file).read().strip()) </code></pre> <p>The above function will return True when name is valid else False.</p>
2
2016-09-17T09:10:28Z
[ "python" ]
Check if an string has an integer in an if condition
39,544,924
<pre><code>file = open('Name.txt', 'r') name = str(file.read()) file.close() </code></pre> <p>In the file called 'Name.txt', the user will input a name. The program is to check whether or not the name is valid.</p> <p>E.g:</p> <p>1bob - is not valid</p> <p>bob - is valid</p> <p>Is it possible to do this with an i...
-1
2016-09-17T09:01:07Z
39,545,110
<p>You could use regular expression : </p> <p>i.e : </p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; regex = re.compile(r'.*[0-9]') &gt;&gt;&gt; names = ['Bob', 'John', '1Bob', 'John2'] &gt;&gt;&gt; for name in names: ... if not regex.match(name): ... print name ... Bob John </code></pre> <p><code>...
-1
2016-09-17T09:22:54Z
[ "python" ]
CancelledError: RunManyGraphs while running distributed tensorflow
39,544,926
<p>I am trying to distribute TensorBox ReInspect implementation (<a href="https://github.com/Russell91/TensorBox" rel="nofollow">https://github.com/Russell91/TensorBox</a>) over one ps and two workers. I have added the training code in a <code>sv.managed_session</code>.</p> <pre><code>def train(H, test_images, server)...
0
2016-09-17T09:01:36Z
39,577,790
<p>The <code>CancelledError</code> is relatively benign: I suspect that your main thread exits the <code>with sv.managed_session() as sess:</code> block, which closes the session and cancels all pending requests, including those made by your two pre-fetching threads.</p> <p>To avoid seeing this error, I'd recommend th...
1
2016-09-19T16:25:08Z
[ "python", "tensorflow" ]
Installing PyAutoGUI Error in pip.exe install pyautogui
39,544,944
<p>I have been installing PyautoGui on my WIN10 PC. But I am getting the following error, i have been getting a lot of errors jut to get this far. </p> <p>i have been reinstalling python so its destination folder is in <strong>C:\Python</strong> instead of <strong>C:\Users\Home\AppData\Local\Programs\Python\Python35-...
0
2016-09-17T09:03:30Z
39,563,987
<p>I encountered the same error message as you did. This workaround worked for me. Try these steps in order...</p> <ol> <li><p>Install PyScreeze 0.1.7. </p></li> <li><p>Update PyScreeze to 0.1.8.</p></li> <li>Install PyAutoGui.</li> </ol> <p>I hope this helps.</p>
0
2016-09-19T00:50:26Z
[ "python", "pip", "pyautogui" ]
Installing PyAutoGUI Error in pip.exe install pyautogui
39,544,944
<p>I have been installing PyautoGui on my WIN10 PC. But I am getting the following error, i have been getting a lot of errors jut to get this far. </p> <p>i have been reinstalling python so its destination folder is in <strong>C:\Python</strong> instead of <strong>C:\Users\Home\AppData\Local\Programs\Python\Python35-...
0
2016-09-17T09:03:30Z
39,574,692
<p>I also encountered the same error (albeit on Ubuntu 14.04). The missing module PIL is named Pillow (As said in <a href="http://stackoverflow.com/a/34512881/4335271">this answer</a>). So what I tried was (same in MacOS I think):</p> <pre><code>sudo pip3 install pillow </code></pre> <p>That translated to Windows wou...
0
2016-09-19T13:41:30Z
[ "python", "pip", "pyautogui" ]
Installing PyAutoGUI Error in pip.exe install pyautogui
39,544,944
<p>I have been installing PyautoGui on my WIN10 PC. But I am getting the following error, i have been getting a lot of errors jut to get this far. </p> <p>i have been reinstalling python so its destination folder is in <strong>C:\Python</strong> instead of <strong>C:\Users\Home\AppData\Local\Programs\Python\Python35-...
0
2016-09-17T09:03:30Z
40,112,934
<p>Instead of letting <strong>PyautoGUI</strong> get all the packages for you.</p> <p>Install all of them individually. Then, run the <code>pip install --upgrade _packageName_</code> </p> <p>Then run <code>pip install pyautogui</code>.</p> <p>Hope this helps. </p>
0
2016-10-18T15:59:49Z
[ "python", "pip", "pyautogui" ]
Shifting Column to the left Pandas Dataframe
39,544,975
<p>I have a fruit dataset that contains Name, Colour, Weight, Size, Seeds</p> <pre><code> Fruit dataset Name Colour Weight Size Seeds Unnamed Apple Apple Red 10.0 Big Yes Apple Apple Red 5.0 Small Yes Pear Pear Gr...
1
2016-09-17T09:07:39Z
39,545,062
<p>you can do it this way:</p> <pre><code>In [23]: df Out[23]: Name Colour Weight Size Seeds Unnamed 0 Apple Apple Red 10.0 Big Yes 1 Apple Apple Red 5.0 Small Yes 2 Pear Pear Green 11.0 Big Yes 3 Banana Banana Yellow 4.0 Small Yes 4 Orange Orange Or...
1
2016-09-17T09:16:51Z
[ "python", "pandas", "dataframe" ]
Multiple characters in a string return a false boolean when trying to find a character in the string
39,544,976
<pre><code>#Function takes a character and a string and returns a boolean reflecting if #the character is found in the string. def isItThereS(letter, word): letInWord = 0 for l in word: if l == letter: letInWord += 1 return letInWord == True </code></pre> <p>When I put it in the operato...
0
2016-09-17T09:07:43Z
39,545,023
<p>you can simply use the in operator</p> <pre><code>def isItThereS(letter, word): return letter in word </code></pre>
2
2016-09-17T09:12:06Z
[ "python", "string", "python-3.x", "character" ]
Multiple characters in a string return a false boolean when trying to find a character in the string
39,544,976
<pre><code>#Function takes a character and a string and returns a boolean reflecting if #the character is found in the string. def isItThereS(letter, word): letInWord = 0 for l in word: if l == letter: letInWord += 1 return letInWord == True </code></pre> <p>When I put it in the operato...
0
2016-09-17T09:07:43Z
39,545,046
<p>If you <strong>really</strong> want to use a custom function for that, change your return to <code>return letInWord &gt;= 1</code>. As everything but <code>1 == True</code> will evaluate to <code>False</code>. (So a more appropriate name for the function as is would be <code>is_it_there_only_once</code>).</p> <p>Ot...
0
2016-09-17T09:14:49Z
[ "python", "string", "python-3.x", "character" ]
How to automate interactive console applications in Python?
39,544,997
<p>I want to control running process/program by script in Python. I have a program `linphonec´ (You can install: apt-get install linphonec). My task is:</p> <ol> <li>Run <code>linphonec</code> (I'm using subprocess at the moment)</li> <li>When <code>linphonec</code> is running it has many commands to control this an...
0
2016-09-17T09:09:47Z
39,545,162
<p>There are actually 2 ways to communicate:</p> <p>Run your program with <code>myprogram.py | linphonec</code> to pass everything you <code>print</code> to linphonec</p> <p>Use <a href="https://docs.python.org/3/library/subprocess.html#popen-constructor" rel="nofollow">subprocess.Popen</a> with <a href="https://docs...
0
2016-09-17T09:28:55Z
[ "python", "linux", "shell", "subprocess", "linphone" ]
How to repeat an action in Python
39,545,031
<p>I want to repeat an action for n times. I've tried "if" but it does not work. </p> <pre><code>If actiontimes == n: Print text*n </code></pre> <p>Thanks for any advice</p>
-5
2016-09-17T09:13:17Z
39,545,038
<p>You have to write:</p> <pre><code>for x in range(times): #action to repeat </code></pre>
0
2016-09-17T09:13:58Z
[ "python" ]
Why and how am i supposed to use socket.accept() in python?
39,545,199
<p>This <code>accept()</code> method return a tuple with a new socket and an address but why do i need a new socket if i already have one, so why don't use it?</p> <pre><code>import socket sock = socket.socket() sock.bind(('', 9090)) sock.listen(1) conn, addr = sock.accept() print 'connected:', addr while True: ...
1
2016-09-17T09:33:33Z
39,545,528
<p>Seems like you haven't implemented TCP in Java before.</p> <p>The example you are providing with, uses a default <code>AF_INET</code> and <code>SOCK_STREAM</code> which <em>by default</em> is TCP:</p> <blockquote> <p>socket.socket([family[, type[, proto]]]) Create a new socket using the given address family, s...
1
2016-09-17T10:07:48Z
[ "java", "python", "sockets" ]
Why and how am i supposed to use socket.accept() in python?
39,545,199
<p>This <code>accept()</code> method return a tuple with a new socket and an address but why do i need a new socket if i already have one, so why don't use it?</p> <pre><code>import socket sock = socket.socket() sock.bind(('', 9090)) sock.listen(1) conn, addr = sock.accept() print 'connected:', addr while True: ...
1
2016-09-17T09:33:33Z
39,545,588
<p>You have one listening socket active while the server is running and one new connected socket for each accepted connection which is active until the connection is closed.</p>
2
2016-09-17T10:14:06Z
[ "java", "python", "sockets" ]
Calculate the average value of the numbers in a file
39,545,203
<p>I am having a problem of calculating the average value of numbers in a file. So far i have made a function that reads in files and calculate the number of lines. The file consists of many columns of numbers, but the column 8 is the one i need to calculate from. </p> <pre><code>def file_read(): fname = input("...
0
2016-09-17T09:33:42Z
39,545,255
<p>You could use <code>txt.readline()</code> to read the first line, but to stick with iterators way to do it, just drop the first line using iteration on file with <code>next</code></p> <pre><code>with open(fname) as txt: next(txt) # it returns the first line, we just ignore the return value # your iterator is...
0
2016-09-17T09:39:00Z
[ "python", "file", "numbers" ]
Calculate the average value of the numbers in a file
39,545,203
<p>I am having a problem of calculating the average value of numbers in a file. So far i have made a function that reads in files and calculate the number of lines. The file consists of many columns of numbers, but the column 8 is the one i need to calculate from. </p> <pre><code>def file_read(): fname = input("...
0
2016-09-17T09:33:42Z
39,546,814
<p>Try this</p> <pre><code>import re #regular expression for decimals digits_reg = re.compile(r"\d+\.\d+|\d+") with open('''file name''', "r") as file: allNum = [] #find numbers in each line and add them to the list for line in file: allNum.extend(digits_reg.findall(line)) #should be a list that ...
0
2016-09-17T12:27:21Z
[ "python", "file", "numbers" ]
Why isn't IDLE in the folder with the Python program?
39,545,314
<p>I am a complete beginner to programming. I downloaded Python 3.4.3. 64 bit for my Windows 10 OS. The download specified that it included IDLE. I opened Python with no issue, but IDLE was not in that folder. I searched for it on my C drive and it didn't match any file names.</p> <p>Did it save somewhere else? </p>
0
2016-09-17T09:44:24Z
39,545,380
<p>If you installed IDLE correctly, it will appear in your menu with a folder for IDLE. Look there. If not, attempt to reinstall IDLE. It will not affect anything.</p>
0
2016-09-17T09:50:30Z
[ "python", "installation" ]
Trying to run a python script via PHP button hosted on raspberry pi but failing
39,545,452
<p>I have a php script that should (I think) run a python script to control the energenie radio controlled plug sockets depending on which button is selected. It seems to work in that it echos back the correct message when the button is pressed but the python scripts don''t appear to run. I have added the line:</p> <p...
0
2016-09-17T09:58:43Z
39,545,497
<p>Have you tried setting the permissions of the <code>lampoff.py</code> and <code>lampon.py</code> to 777?</p> <p><code>chmod 777 /home/pi/lampoff.py &amp;&amp; chmod 777 /home/py/lampon.py</code></p>
0
2016-09-17T10:04:44Z
[ "php", "python", "raspberry-pi" ]
Trying to run a python script via PHP button hosted on raspberry pi but failing
39,545,452
<p>I have a php script that should (I think) run a python script to control the energenie radio controlled plug sockets depending on which button is selected. It seems to work in that it echos back the correct message when the button is pressed but the python scripts don''t appear to run. I have added the line:</p> <p...
0
2016-09-17T09:58:43Z
39,552,286
<p>I think you need add "sudo" the python script for it to work which means you have to add the www-data user to /etc/sudoers.</p> <pre><code>shell_exec("sudo python /home/pi/lampon.py"); </code></pre> <p>or</p> <pre><code>exec("sudo python /home/pi/lampon.py"); </code></pre> <p>There was another post that deal wit...
0
2016-09-17T22:27:00Z
[ "php", "python", "raspberry-pi" ]
PyGame - Take a screenshot of a certain part of the display
39,545,469
<p>How can I take a screenshot of a certain part of the pygame screen?</p> <p>For example, this is my screen</p> <p><a href="http://i.stack.imgur.com/VyEEY.png" rel="nofollow"><img src="http://i.stack.imgur.com/VyEEY.png" alt="screen"></a></p> <p>and I want to take a screenshot of the area between the top-left dot, ...
0
2016-09-17T10:01:26Z
39,561,058
<p>Your function has an error (size_f is not defined) but otherwise it's working. The function</p> <pre><code>def screenshot(obj, file_name, position, size): img = pygame.Surface(size) img.blit(obj, (0, 0), (position, size)) pygame.image.save(img, file_name) </code></pre> <p>takes the the topleft position...
0
2016-09-18T18:16:11Z
[ "python", "python-3.x", "pygame" ]
Unreachable code when using cython.inline
39,545,501
<p>I'm using Cython to compile a function to C, but get a "Unreachable code" warning. When I inspect the <code>pyx</code> file, I see an additional <code>return locals()</code> which I don't quite understand how it got there.</p> <p>The code is generated by <code>cython.inline</code>:</p> <pre><code>cython.inline('re...
0
2016-09-17T10:05:06Z
39,580,017
<p>I think it's so that if you don't add a return statement you get back a dictionary of local variables. E.g.</p> <pre><code>cython.inline('''x = a*b y = b+c z = a-c ''', a=1, b=2, c=3) </code></pre> <p>will give you back a dictionary of <code>x</code>, <code>y</code>, and <code>z</code>. Obviously it's a bit unnece...
1
2016-09-19T18:42:43Z
[ "python", "cython" ]
What is the GCS equivalent of the blobstore "Create_upload_url"?
39,545,529
<p>We currently use blobstore.create_upload_url to create upload urls to be used on the frontend see <a href="https://cloud.google.com/appengine/docs/python/blobstore/#Python_Uploading_a_blob" rel="nofollow">Uploading a blob</a>. However, with the push toward Google Cloud Storage (GCS) by Google, I'd like to use GCS in...
1
2016-09-17T10:07:52Z
39,546,064
<p>If you will provide <code>gs_bucket_name</code> to <code>blobstore.create_upload_url</code> file will be stored in GCS instead of blobstore, this is described in official documentation: <a href="https://cloud.google.com/appengine/docs/python/blobstore/" rel="nofollow">Using the Blobstore API with Google Cloud Storag...
2
2016-09-17T11:04:31Z
[ "python", "google-app-engine", "google-cloud-storage" ]
Python Combinations
39,545,543
<p>Suppose I have a Python list that looks like:</p> <pre><code>[1, 2, 3, 4] </code></pre> <p>I would like to be able to return a list of lists containing all combinations of two or more numbers. The order of the values doesn't matter so 1,2 is the same as 2,1. I would also like to return another list that contains ...
1
2016-09-17T10:09:33Z
39,545,613
<p>You can take the set difference:</p> <pre><code>l = set([1, 2, 3, 4]) for i in range(len(l)+1): for comb in itertools.combinations(l, i): print(comb, l.difference(comb)) () {1, 2, 3, 4} (1,) {2, 3, 4} (2,) {1, 3, 4} (3,) {1, 2, 4} (4,) {1, 2, 3} (1, 2) {3, 4} (1, 3) {2, 4} (1, 4) {2, 3} (2, 3) {1, 4} ...
2
2016-09-17T10:16:23Z
[ "python", "python-2.7", "combinations", "itertools" ]
Python Combinations
39,545,543
<p>Suppose I have a Python list that looks like:</p> <pre><code>[1, 2, 3, 4] </code></pre> <p>I would like to be able to return a list of lists containing all combinations of two or more numbers. The order of the values doesn't matter so 1,2 is the same as 2,1. I would also like to return another list that contains ...
1
2016-09-17T10:09:33Z
39,545,624
<p>Suppose you have this vector [1 6 3]</p> <p>You can generate all of the numbers from 0 to 2^3-1 where 3 is <code>len([1 6 3])</code></p> <pre><code>0 1 2 3 4 5 6 7 </code></pre> <p>After you can convert this numbers to binary:</p> <pre><code> 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 </code></pre> ...
1
2016-09-17T10:17:46Z
[ "python", "python-2.7", "combinations", "itertools" ]
Python Combinations
39,545,543
<p>Suppose I have a Python list that looks like:</p> <pre><code>[1, 2, 3, 4] </code></pre> <p>I would like to be able to return a list of lists containing all combinations of two or more numbers. The order of the values doesn't matter so 1,2 is the same as 2,1. I would also like to return another list that contains ...
1
2016-09-17T10:09:33Z
39,547,832
<p>Building upon the idea by <a href="http://stackoverflow.com/a/39545624/1639625">Nunzio</a>, but instead of converting numbers in a certain range to binary, you can just use <code>itertools.product</code> to get all combinations of <code>1</code> and <code>0</code> (or <code>True</code> and <code>False</code>) and th...
2
2016-09-17T14:18:31Z
[ "python", "python-2.7", "combinations", "itertools" ]
How do I create a new text file after every loop in a while loop?
39,545,549
<p>I have a piece of text which I want to write in different text files, so I'm using a while loop to create a new txt file after every loop. However I don't know how to create a new text file AFTER every loop has been completed. For the text, I have a variable outside the loop, so the text is not an issue. I just don'...
-1
2016-09-17T10:10:23Z
39,545,578
<p>just generate a different filename every time you open the file for writing that would do. Or best would be not to create multiple files. Just write into one file and create (no_of_copies-1) symlinks with different names. This would be efficient. </p>
0
2016-09-17T10:12:51Z
[ "python", "while-loop", "createfile" ]
Get same value for predictions by a Neural network implemented using python
39,545,562
<p>I want to predict whether a given passenger is survived or not, in the titanic disaster. I give 0 to the unsurvived ones and 1 to the survived ones. I used python scikit learn library and implemented the following neural network for classification. When predicting, I get only 0 for all the passengers. Can anyone hel...
0
2016-09-17T10:11:17Z
39,549,765
<p>Maybe it is related to the format of your training data, if you are using 2 output layers for a binary classification you will need to apply "one hot encoding" for your output variable, have you tried a logistic activation to see if it returns values between 0 and 1?</p>
0
2016-09-17T17:28:44Z
[ "python", "machine-learning", "scikit-learn", "neural-network", "prediction" ]
Get same value for predictions by a Neural network implemented using python
39,545,562
<p>I want to predict whether a given passenger is survived or not, in the titanic disaster. I give 0 to the unsurvived ones and 1 to the survived ones. I used python scikit learn library and implemented the following neural network for classification. When predicting, I get only 0 for all the passengers. Can anyone hel...
0
2016-09-17T10:11:17Z
39,560,713
<p>This type of problem is typically observed when data is not normalized/ standardized (at least I can not see that in your code). Neural net techniques are very susceptible of scale difference between different feature so standardization of data [mean =0 std =1] for all columns is a good practice. </p>
0
2016-09-18T17:37:54Z
[ "python", "machine-learning", "scikit-learn", "neural-network", "prediction" ]
An error appears saying a function was referenced before it was assigned but only when I enter the year above 2005 or 2004
39,545,565
<pre><code>x = 2 while x&gt;1: from random import randint import time fn = input("Hello, what is your first name?") while any (ltr.isdigit() for ltr in fn): fn = input("Sorry an integer was entered, please try again") firstname = (fn[0].upper()) ln = input("Hello, what is your last name?...
0
2016-09-17T10:11:26Z
39,545,619
<p>This whole programs is structured wrong...</p> <p>Anyway, <code>mob</code> is declared only inside the <code>else</code> scope and is called right after the <code>if-elif-else</code> statements.<br> You should declare it in each these scopes, or right before them.</p> <p>Beside that, I really suggest you read abou...
0
2016-09-17T10:17:16Z
[ "python", "python-3.x" ]
Variable n as an upper bound of a for loop
39,545,597
<p>I wanted to calculate the sum of (1+1+1+...+1)^2 with a for loop, but with a variable n as the upper bound so that the sum results in a function f(n) = n^2. With a non-negative integer x as the input, the loop could easily be coded as</p> <pre><code>p==0 def f(x): global p for i in range(0,x): p=p+1...
-1
2016-09-17T10:14:46Z
39,545,653
<p>Do you want to do something like <code>def('123')</code>?</p> <p>If so, cast the string to int before using it in <code>range</code>, as such:</p> <pre><code>for i in range(0,int(x)): </code></pre>
0
2016-09-17T10:19:53Z
[ "python", "iteration" ]
Variable n as an upper bound of a for loop
39,545,597
<p>I wanted to calculate the sum of (1+1+1+...+1)^2 with a for loop, but with a variable n as the upper bound so that the sum results in a function f(n) = n^2. With a non-negative integer x as the input, the loop could easily be coded as</p> <pre><code>p==0 def f(x): global p for i in range(0,x): p=p+1...
-1
2016-09-17T10:14:46Z
39,546,045
<p>You wrote:</p> <blockquote> <p>(String input - without assigning integer/float values to these strings first)</p> <pre><code>f(a) = a^2 f(df) = (df)^2 f(the_speed_of_an_unladen_swallow) = (the_speed_of_an_unladen_swallow)^2 </code></pre> </blockquote> <p>So, you have variables (<code>a</code>, <code>df</code>, ...
0
2016-09-17T11:02:56Z
[ "python", "iteration" ]
How to write a regex in Python with named groups to match this?
39,545,646
<p>I have a file which would contain the following lines.</p> <p>comm=adbd pid=11108 prio=120 success=1 target_cpu=001</p> <p>I have written the following regex to match.</p> <pre><code>_sched_wakeup_pattern = re.compile(r""" comm=(?P&lt;next_comm&gt;.+?) \spid=(?P&lt;next_pid&gt;\d+) \sprio=(?P&lt;next_prio&gt;\d+)...
1
2016-09-17T10:19:36Z
39,546,070
<p>Matching <code>0</code> or <code>1</code> repetitions do <code>(your_string)?</code>.</p> <pre><code>_sched_wakeup_pattern = re.compile(r""" comm=(?P&lt;next_comm&gt;.+?) \spid=(?P&lt;next_pid&gt;\d+) \sprio=(?P&lt;next_prio&gt;\d+) \s?(success=(?P&lt;success&gt;\d))? \starget_cpu=(?P&lt;target_cpu&gt;\d+) """, re...
2
2016-09-17T11:05:20Z
[ "python", "regex", "regex-group" ]
How to write a regex in Python with named groups to match this?
39,545,646
<p>I have a file which would contain the following lines.</p> <p>comm=adbd pid=11108 prio=120 success=1 target_cpu=001</p> <p>I have written the following regex to match.</p> <pre><code>_sched_wakeup_pattern = re.compile(r""" comm=(?P&lt;next_comm&gt;.+?) \spid=(?P&lt;next_pid&gt;\d+) \sprio=(?P&lt;next_prio&gt;\d+)...
1
2016-09-17T10:19:36Z
39,546,636
<p>The solution using regex <em>non-capturing group</em> and <code>regex.findAll</code> function:</p> <pre><code>import regex ... fh = open('lines.txt', 'r'); // considering 'lines.txt' is your initial file commlines = fh.read() _sched_wakeup_pattern = regex.compile(r""" comm=(?P&lt;next_comm&gt;[\S]+?) \spid=(?P&lt...
2
2016-09-17T12:09:34Z
[ "python", "regex", "regex-group" ]
Intergrating 2 dataframes based on specific column values
39,545,655
<p>I am not sure if my question is correct or not, but I will try to explain it clearly here.</p> <p>I have two dataframes, df and df2.</p> <p>df consist of country names and their short names</p> <pre><code> Country | Shortname England ENG United States USA China CN Thailand ...
0
2016-09-17T10:19:59Z
39,545,685
<p>I'd use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow">map()</a> method in this case:</p> <pre><code>In [49]: df Out[49]: Country Shortname 0 England ENG 1 United States USA 2 China CN 3 Thailand TH In ...
1
2016-09-17T10:22:51Z
[ "python", "pandas", "dataframe" ]
Intergrating 2 dataframes based on specific column values
39,545,655
<p>I am not sure if my question is correct or not, but I will try to explain it clearly here.</p> <p>I have two dataframes, df and df2.</p> <p>df consist of country names and their short names</p> <pre><code> Country | Shortname England ENG United States USA China CN Thailand ...
0
2016-09-17T10:19:59Z
39,548,018
<p>Alternatively, consider <a href="http://pandas.pydata.org/pandas-docs/stable/merging.html" rel="nofollow">merge</a>:</p> <pre><code>df2 = pd.merge(df2, df, on='Country') </code></pre> <p>Or join:</p> <pre><code>df2 = df2.join(df, on='Country') </code></pre>
0
2016-09-17T14:38:38Z
[ "python", "pandas", "dataframe" ]
Django Slugfield removing articles ('the', 'a', 'an', 'that')
39,545,657
<p>I'm using django 1.10 and I have this setup:</p> <pre><code>class Chapter(models.Model): title = models.CharField(max_length=200, unique=True) slug = models.SlugField(unique=True) date_completed = models.DateTimeField(blank=True, null=True) completed = models.BooleanField(default=False) def __...
1
2016-09-17T10:20:18Z
39,545,843
<p><strong>Why is this so?</strong></p> <p>Well, that's the default behaviour of the <a href="http://stackoverflow.com/questions/427102/what-is-a-slug-in-django">Slugfield,</a> in Django. Why is it like that? Because generally, <a href="http://stackoverflow.com/questions/9734970/better-seo-to-remove-stop-words-from-...
1
2016-09-17T10:39:33Z
[ "python", "django" ]
Display Dictionaries in Tkinter Python
39,545,732
<p>I am written a simple Tkinter program and i am trying to display both my stock name and stock Quantity, but i find that only my stock name displays. My code is as follows:</p> <pre><code>import sys from tkinter import * from tkinter import ttk import time from datetime import datetime now= datetime.now() x = [] d =...
1
2016-09-17T10:27:09Z
39,545,804
<p>Currently, in your <code>display()</code> function you are only changing <code>x_var</code> which refers to the stock.<br> Have you tried adding another <code>tk.Label</code> and bind a quantity variable to it?</p>
0
2016-09-17T10:35:35Z
[ "python", "tkinter" ]
How to I pass values into dependent models with Factory Boy in Django?
39,545,950
<p>Im' working on an open source django web app, and I'm looking to use Factory Boy to help me setting up models for some tests, but after a few hours reading the docs and looking at examples, I think I need to accept defeat and ask here.</p> <p>I have a Customer model which looks a bit like this:</p> <pre><code>clas...
0
2016-09-17T10:51:23Z
39,549,418
<p>In that case, the best way is to pick values from <a href="http://factoryboy.readthedocs.io/en/latest/reference.html#parents" rel="nofollow">the customer declarations</a>:</p> <pre><code>class CustomerFactory(DjangoModelFactory): class Meta: model = models.Customer full_name = factory.Faker('name'...
0
2016-09-17T16:56:57Z
[ "python", "django", "factory-boy" ]
odoo: write function save old data
39,546,019
<p>I created an onchange function that link some object lines to the current one</p> <pre><code>mo_lines_g1 = fields.One2many(comodel_name='object.order', inverse_name='mo_id1', copy=False ) @api.onchange('date') def change_date(self): if self.date: g1=self.env['object.order'].search(['&amp;'('date_orde...
0
2016-09-17T10:59:18Z
39,546,534
<p>The documentation on writing to related fields <a href="https://www.odoo.com/documentation/8.0/reference/orm.html" rel="nofollow">ORM Documentation</a> speaks of the (2,_,ids) as a method which cant be used in create. If you are writing you can do the following.</p> <p>If you overwrite the write() function you coul...
0
2016-09-17T11:56:32Z
[ "python", "openerp", "edit", "v8" ]
odoo: write function save old data
39,546,019
<p>I created an onchange function that link some object lines to the current one</p> <pre><code>mo_lines_g1 = fields.One2many(comodel_name='object.order', inverse_name='mo_id1', copy=False ) @api.onchange('date') def change_date(self): if self.date: g1=self.env['object.order'].search(['&amp;'('date_orde...
0
2016-09-17T10:59:18Z
39,546,842
<p><code>(6, _, ids)</code> can not be used with One2many field. </p> <p>It is described at <a href="http://odoo-development.readthedocs.io/en/latest/dev/py/x2many.html#x2many-values-filling" rel="nofollow">x2many values filling</a>. </p>
0
2016-09-17T12:31:26Z
[ "python", "openerp", "edit", "v8" ]
odoo: write function save old data
39,546,019
<p>I created an onchange function that link some object lines to the current one</p> <pre><code>mo_lines_g1 = fields.One2many(comodel_name='object.order', inverse_name='mo_id1', copy=False ) @api.onchange('date') def change_date(self): if self.date: g1=self.env['object.order'].search(['&amp;'('date_orde...
0
2016-09-17T10:59:18Z
39,550,815
<p>I think there is a bug on v8, it doesn't work automaticly <br/> I replaced the <code>(2,id,_)</code> in the vals with <code>(3,id,_)</code> on the <strong>write</strong> funciton </p> <pre><code>@api.multi def write(self, vals): if vals.has_key('mo_lines_g1'): g1=[] for line in vals['mo_lines_...
0
2016-09-17T19:21:18Z
[ "python", "openerp", "edit", "v8" ]
Python list comprehensions with regular expressions on a text
39,546,069
<p>I have a text file which includes integers in the text. There are one or more integers in a line or none. I want to find these integers with regular expressions and compute the sum.</p> <p>I have managed to write the code:</p> <pre><code>import re doc = raw_input("File Name:") text = open(doc) lst = list() total =...
0
2016-09-17T11:05:07Z
39,546,123
<p>Since you want to calculate the sum of the numbers after you find them It's better to use a generator expression with <code>re.finditer()</code> within <code>sum()</code>. Also if the size of file in not very huge you better to read it at once, rather than one line at a time. </p> <pre><code>import re doc = raw_inp...
1
2016-09-17T11:11:22Z
[ "python", "list-comprehension" ]