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
no pycharm database window
39,123,052
<p>I'm following a tutorial on Django. I'm using PyCharm 2016.2.1. There is a file in my project called db.sqlite3. The icon next to this file in the project explorer shows a question mark which indicates PyCharm does not know what this file is. In searching the web I find many references to clicking View > Tool Wi...
0
2016-08-24T12:15:00Z
39,127,976
<p>PyCharm Community Edition does not support database / SQL and many other features providerd by the Professional edition. For full list of differences between these editions see the <a href="https://www.jetbrains.com/pycharm/features/editions_comparison_matrix.html" rel="nofollow">edition comparison matrix</a> on the...
1
2016-08-24T15:57:42Z
[ "python", "django", "pycharm" ]
Invalid SMTPAPI Header: send_at must be a timestamp
39,123,099
<p>I am scheduling the emails through SMTP API. This is what I have tried uptil now: </p> <pre><code>from smtpapi import SMTPAPIHeader from django.core.mail import send_mail from django.core.mail import EmailMultiAlternatives from django.template.loader import get_template from django.template import Template, Context...
0
2016-08-24T12:16:55Z
39,135,948
<p><code>set_send_at()</code> takes an integer argument, but you are passing it a dictionary (<code>{"send_at": 1472058300}</code>). This is invalid and causes the error.</p> <p>Change it to:</p> <pre><code>header.set_send_at(1472058300) </code></pre>
1
2016-08-25T02:49:20Z
[ "python", "django", "email", "smtp", "sendgrid" ]
Java or Python way to extract a sub-XML from big XML depending on child text nodes
39,123,136
<p>I have a big XML to be handled, I need to extract all "Situation" TAGS if these ones have &lt;_0:roadNumber>A-52, &lt;_0:roadNumber>AP-9 or &lt;_0:roadNumber>A-55 values in theirs, because I don`t need the rest of XML. Then build a XML document with the XML substraction. I don´t need a implementation, only I would ...
0
2016-08-24T12:18:19Z
39,123,611
<p>For really big XML documents you should best use <a href="http://www.saxproject.org/" rel="nofollow">SAX</a> for streaming (not needing to have the full document in memory at once) but for finding elements easly <a href="https://www.w3.org/TR/xpath/" rel="nofollow">XPath</a> is really helpful.</p> <p>For Python you...
1
2016-08-24T12:40:21Z
[ "java", "python", "xml", "minidom", "xmldom" ]
OSError: [Errno 8] Exec format error when trying to run chromedriver for selenium
39,123,216
<p>I am trying to run Selenium based tests on an Ubuntu based server from Jenkins but get the following cryptic errors:</p> <p><strong>First:</strong></p> <pre><code>+ python manage.py jenkins --enable-coverage --settings=Modeling.settings.dev ......EException AttributeError: "'Service' object has no attribute 'proce...
1
2016-08-24T12:22:23Z
39,129,112
<blockquote> <p>OSError: [Errno 8] Exec format error</p> </blockquote> <p>ChromeDriver executable available here is not supported on Ubuntu platform. For Ubuntu use chromedriver for ubuntu <a href="http://chromedriver.storage.googleapis.com/2.23/chromedriver_linux32.zip" rel="nofollow">http://chromedriver.storage.go...
1
2016-08-24T16:59:11Z
[ "python", "selenium", "jenkins" ]
Apply a list of Python functions in order elegantly
39,123,375
<p>I have an input value <code>val</code> and a list of functions to be applied in the order:</p> <pre><code>funcs = [f1, f2, f3, ..., fn] </code></pre> <p>How to apply elegantly and not writing</p> <pre><code>fn( ... (f3(f2(f1(val))) ... ) </code></pre> <p>and also not using for loop:</p> <pre><code>tmp = val for...
4
2016-08-24T12:29:56Z
39,123,400
<p>Use the <a href="https://docs.python.org/2/library/functions.html#reduce" rel="nofollow"><code>reduce()</code> function</a>:</p> <pre><code># forward-compatible import from functools import reduce result = reduce(lambda res, f: f(res), funcs, val) </code></pre> <p><code>reduce()</code> applies the first argument,...
12
2016-08-24T12:31:07Z
[ "python", "functional-programming" ]
Apply a list of Python functions in order elegantly
39,123,375
<p>I have an input value <code>val</code> and a list of functions to be applied in the order:</p> <pre><code>funcs = [f1, f2, f3, ..., fn] </code></pre> <p>How to apply elegantly and not writing</p> <pre><code>fn( ... (f3(f2(f1(val))) ... ) </code></pre> <p>and also not using for loop:</p> <pre><code>tmp = val for...
4
2016-08-24T12:29:56Z
39,130,019
<p>MartijnPieters answer is excellent. The only thing I would add is that this is called <a href="https://en.wikipedia.org/wiki/Function_composition" rel="nofollow">function composition</a></p> <p>Giving names to these generics means you can use them whenever the need arises</p> <pre><code>from functools import reduc...
1
2016-08-24T17:55:30Z
[ "python", "functional-programming" ]
Image clustering by its similarity in python
39,123,421
<p>I have a collection of photos and I'd like to distinguish clusters of the similar photos. Which features of an image and which algorithm should I use to solve my task?</p>
-3
2016-08-24T12:31:41Z
39,124,272
<p>It is a too broad question.</p> <p>Generally speaking you can use any <a href="http://scikit-learn.org/stable/modules/classes.html#module-sklearn.cluster" rel="nofollow">clustering mechanism</a>, e.g. a popular k-means. To prepare your data for clustering you need to convert your collection into an array X, where e...
1
2016-08-24T13:09:31Z
[ "python", "machine-learning", "computer-vision", "cluster-analysis" ]
How to print 'tight' dots horizontally in python?
39,123,549
<p>I have a program which prints out its progress to the console. every 20 steps it prints the number of steps like 10 20 30 etc. but within this, it prints a dot. This was printed using the print statement with a comma at the end</p> <pre><code> if epoch % 10 == 0: print epoch, else: ...
1
2016-08-24T12:37:25Z
39,123,666
<p>If you want to get more control over the formatting then you need to use either:</p> <pre><code>import sys sys.stdout.write('.') </code></pre> <p>.. instead of <code>print</code>, or use the Python 3 print function. This is available as a future import in later builds of Python 2.x as:</p> <pre><code>from __futur...
4
2016-08-24T12:42:40Z
[ "python", "printing", "console", "comma", "semicolon" ]
How to print 'tight' dots horizontally in python?
39,123,549
<p>I have a program which prints out its progress to the console. every 20 steps it prints the number of steps like 10 20 30 etc. but within this, it prints a dot. This was printed using the print statement with a comma at the end</p> <pre><code> if epoch % 10 == 0: print epoch, else: ...
1
2016-08-24T12:37:25Z
39,123,791
<pre><code>import itertools import sys import time counter = itertools.count() def special_print(value): sys.stdout.write(value) sys.stdout.flush() while True: time.sleep(0.1) i = next(counter) if i % 10 == 0: special_print(str(i)) else: special_print('.') </code></pre>
1
2016-08-24T12:48:19Z
[ "python", "printing", "console", "comma", "semicolon" ]
How to print 'tight' dots horizontally in python?
39,123,549
<p>I have a program which prints out its progress to the console. every 20 steps it prints the number of steps like 10 20 30 etc. but within this, it prints a dot. This was printed using the print statement with a comma at the end</p> <pre><code> if epoch % 10 == 0: print epoch, else: ...
1
2016-08-24T12:37:25Z
39,123,800
<p>Here's a possible solution:</p> <pre><code>import time import sys width = 101 for i in xrange(width): time.sleep(0.001) if i % 10 == 0: sys.stdout.write(str(i)) sys.stdout.flush() else: sys.stdout.write(".") sys.stdout.flush() sys.stdout.write("\n") </code></pre>
1
2016-08-24T12:48:49Z
[ "python", "printing", "console", "comma", "semicolon" ]
Django Advanced tutorial: How to write reusable apps
39,123,557
<p>According to <a href="https://docs.djangoproject.com/en/1.10/intro/reusable-apps/" rel="nofollow">Django Advanced tutorial: How to write reusable apps</a>, "2. With luck, your Django project should now work correctly again. Run the server again to confirm this."</p> <p>How to run the server? Having moved polls app ...
0
2016-08-24T12:37:48Z
39,123,581
<p><code>django-polls</code> is the new reusable app, but <code>mysite</code> is still your site; the idea is that you can extract the polls app but <code>mysite</code> will still work. You run the server there.</p>
1
2016-08-24T12:39:01Z
[ "python", "django" ]
Migrating Python backend from Gitkit to to Firebase-Auth with python-jose for token verification
39,123,568
<p><a href="https://github.com/google/identity-toolkit-python-client/issues/20" rel="nofollow">Over on GitHub</a> a helpful Google dev told me that </p> <blockquote> <p>to create a user session, your python backend server only needs a JWT library to verify the Firebase Auth token (signature and audience) in the ...
1
2016-08-24T12:38:15Z
39,155,806
<p>The keys can be obtained</p> <p>for Firebase at <code>https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com</code></p> <p>and for Gitkit at <code>https://www.googleapis.com/identitytoolkit/v3/relyingparty/publicKeys</code></p> <p>Using Googles <a href="https://github.com/google/...
2
2016-08-25T22:37:30Z
[ "python", "migration", "jwt", "firebase-authentication", "gitkit" ]
Modifying duplicate subindex in MultiIndex dataframe in Pandas
39,123,606
<p>Hi I have a dataframe slice as below:</p> <pre><code>| | | Lemon | Orange | |------------|----------|-------|--------| | Date | Location | | | | 01/01/2016 | Park | 10 | 20 | | 01/01/2016 | Beach | 5 | 15 | | 01/01/2016 | Park | 2 | 4 | | 02/...
2
2016-08-24T12:40:04Z
39,123,794
<p>Indices are immutable, so if you want to change <code>index</code> labels you need to set a new <code>index</code> (thanks <a href="http://stackoverflow.com/questions/39123606/modifying-duplicate-subindex-in-multiindex-dataframe-in-pandas#comment65593081_39123794">IanS</a>).</p> <p>You can use <a href="http://panda...
2
2016-08-24T12:48:28Z
[ "python", "pandas", "dataframe", "multi-index", "removing-whitespace" ]
Loading only a list of rows using Panda read_csv function - Python
39,123,636
<p>I would like to know if there is an option for the <code>pandas.read_csv</code> function which allow me load only a certain list of rows from the original csv file.</p> <p>The csv file is really big, and I cant load the whole file due to a lack of memory.<br> Is there an option like:</p> <pre><code>df = pandas.re...
1
2016-08-24T12:40:58Z
39,123,709
<p>If you go over the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow">docs</a> for <code>read_csv</code> you will find the <code>nrows</code> kwarg:</p> <blockquote> <p>nrows : int, default None Number of rows of file to read. Useful for reading pieces of large f...
2
2016-08-24T12:44:13Z
[ "python", "csv", "pandas" ]
Loading only a list of rows using Panda read_csv function - Python
39,123,636
<p>I would like to know if there is an option for the <code>pandas.read_csv</code> function which allow me load only a certain list of rows from the original csv file.</p> <p>The csv file is really big, and I cant load the whole file due to a lack of memory.<br> Is there an option like:</p> <pre><code>df = pandas.re...
1
2016-08-24T12:40:58Z
39,124,539
<p>You may want to iteratively update the dataframe as you read through the file. This is not a fast process, but it will get only the rows of interest into a dataframe without pulling the entire file into memory.</p> <pre><code>import pandas as pd col_list = ['columnA', 'columnB', ... ] #fill in your data columns ...
0
2016-08-24T13:20:52Z
[ "python", "csv", "pandas" ]
Virtualenv gives different versions for different os
39,123,699
<p>I am working on a django project on two separate systems, Debian Jessie and Mac El Capitan. The project is hosted on github where both systems will pull from or push to.</p> <p>However, I noticed that on my Debian, when I run <code>python --version</code>, it gives me <code>Python 3.4.2</code> but on my Mac, it giv...
0
2016-08-24T12:43:48Z
39,124,070
<p>Thanks to @Oliver and @Daniel's comments that lead me to the answer why it did not work.</p> <p>I started the virtual environment on my Debian with python 3. <code>virtualenv</code> made the virtual environment but it was specifically for Debian.</p> <p>When I used it for mac, since it could not run the python exe...
0
2016-08-24T13:00:59Z
[ "python", "django", "virtualenv" ]
Virtualenv gives different versions for different os
39,123,699
<p>I am working on a django project on two separate systems, Debian Jessie and Mac El Capitan. The project is hosted on github where both systems will pull from or push to.</p> <p>However, I noticed that on my Debian, when I run <code>python --version</code>, it gives me <code>Python 3.4.2</code> but on my Mac, it giv...
0
2016-08-24T12:43:48Z
39,124,215
<p>Now you understand that virtual environments can't be transferred easily from machine to machine. It's common to use the</p> <pre><code>pip freeze </code></pre> <p>command and store its output in a file called <code>requirements.txt</code>. Then anyone else can rebuild your envirnment on their machine by running</...
0
2016-08-24T13:07:19Z
[ "python", "django", "virtualenv" ]
bind("<Button-2>",..) not working on tk.canvas
39,123,728
<p>I'm using the code shown by MonsterBat Doppelgänger in <a href="http://stackoverflow.com/questions/25787523/move-and-zoom-a-tkinter-canvas-with-mouse">Move and zoom a tkinter canvas with mouse</a></p> <p>It works great! But when I add a self.canvas.bind("<code>&lt;Button-2</code>>",self.find_nearest), the right bu...
0
2016-08-24T12:44:59Z
39,124,566
<blockquote> <p>... when I add ... <code>&lt;Button-2&gt;</code> ..., the right button click is ignored completely.</p> </blockquote> <p>It seems like <code>Button-2</code> is the <em>middle</em> mouse button (i.e. pressing down the scroll wheel). For the <em>right</em> mouse button, you have to use <code>Button-3</...
1
2016-08-24T13:22:20Z
[ "python", "tkinter", "tkinter-canvas" ]
Pandas: order values from dataframe
39,123,750
<p>I have data:</p> <pre><code>Third party unique identifier Qsex Qage Qfamilystatus QeducationSingle Qincomeevaluation Qjobstatus QRuCitySize QRuDistrict Qcountry 9ea3e3cb6719f3d336d324c446f486bd 1 32 1 5 1 1 1 1 cb570bb986808a5f4d2629287297b902 2 25 5 2 1 1...
3
2016-08-24T12:45:51Z
39,124,533
<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reindex.html" rel="nofollow"><code>reindex</code></a> by second DataFrame, but is necessary add last item <code>['Total']</code> to <code>list</code>:</p> <pre><code>print (df) a b 0 QRuDis...
0
2016-08-24T13:20:36Z
[ "python", "pandas", "indexing", "dataframe", "order" ]
I am getting an error <RuntimeWarning: invalid value encountered in sqrt>
39,123,766
<p>I am trying to run a quadratic equation in python. However, it keeps on giving me an error "RuntimeWarning: invalid value encountered in sqrt".</p> <p>Here's my code:</p> <pre><code>import numpy as np a = 0.75 + (1.25 - 0.75)*np.random.randn(10000) print a b = 8 + (12 - 8)*np.random.randn(10000) print b c = -12...
0
2016-08-24T12:46:54Z
39,123,873
<p>This is not 100% Python related. You can't calculate the square root of a negative number (when dealing with real numbers that is).</p> <p>You didn't take any precautions for when <code>b**2 - (4*a*c)</code> is a negative number.</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; &gt;&gt;&gt; np.sqrt(4) 2...
3
2016-08-24T12:52:15Z
[ "python", "python-2.7", "python-3.x", "numpy", "math" ]
Python static inheritance in class variable
39,123,822
<p>In python, is there a way to get the class name in the "static constructor"? I would like to initialize a class variable using an inherited class method.</p> <pre><code>class A(): @classmethod def _getInit(cls): return 'Hello ' + cls.__name__ class B(A): staticField = B._getInit() </code></pre>...
2
2016-08-24T12:50:22Z
39,123,894
<p>The name <code>B</code> is not assigned to until the full <code>class</code> suite has been executed and a class object has been created. For the same reason, the <code>__name__</code> attribute on the class is not set until the class object is created either.</p> <p>You'd have to assign that attribute afterwards:<...
6
2016-08-24T12:53:01Z
[ "python", "oop", "static" ]
Starting a Python script on a raspberry via plink (not responding crontab)
39,123,829
<p>I have written a <code>script.py</code>, which opens a tk window and draws with turtle in the canvas the window contains. I want to start this script via a plink using:</p> <pre><code>plink.exe -pw raspberry pi@pi-fisch00 python /home/pi/script.py </code></pre> <p>But I always receive an error:</p> <pre><code>scr...
0
2016-08-24T12:50:33Z
39,124,064
<p>Look at the error message you are getting:</p> <blockquote> <p>no display name and no $DISPLAY environment variable</p> </blockquote> <p>You are attempting to run something that requires an X11 display, which isn't going to be available from within cron's context (and likely not via plink either, unless you are ...
2
2016-08-24T13:00:53Z
[ "python", "crontab", "plink" ]
QComboBox item text truncated on Windows
39,124,182
<p>I have a standard QComboBox using PySide with fairly long item names, which gets truncated for some reason on Windows, but not in Ubuntu (Gnome). I have only set it with:</p> <pre><code>self.ConfChoose = QtGui.QComboBox() self.ConfChoose.addItem('blablablabla') </code></pre> <p>etc. No extra policy settings.</p> ...
0
2016-08-24T13:05:59Z
39,141,669
<p>Finally got a solution I can accept:</p> <pre><code>self.ConfChoose = QtGui.QComboBox() [self.ConfChoose.addItem(name) for name in self.listOfStrings] w=self.ConfChoose.fontMetrics().boundingRect(max(self.listOfStrings, key=len)).width() self.ConfChoose.view().setFixedWidth(w+10) </code></pre> <p>Thank you for the...
1
2016-08-25T09:36:10Z
[ "python", "qt", "pyside", "qcombobox" ]
A different run speed in python
39,124,265
<p>i want to get sampling from serial port in python. but if i run a test code to know the rate of it, python gives me different values! it is usually about 24000 time per second. but sometime this code runs only 14000 times. what is the big difference reason ? and if i want to get sampling 1 million what should i do?<...
0
2016-08-24T13:09:18Z
39,124,402
<p>Investigate the <code>timeit</code> module, which was designed for applications like this. Benchmarks have to be run under very controlled conditions to be anything like repeatable. <code>timeit</code> runs your code a number of times and gives you the best result. Usually slower performance will be an indication th...
3
2016-08-24T13:15:09Z
[ "python", "sampling", "cpu-speed" ]
A different run speed in python
39,124,265
<p>i want to get sampling from serial port in python. but if i run a test code to know the rate of it, python gives me different values! it is usually about 24000 time per second. but sometime this code runs only 14000 times. what is the big difference reason ? and if i want to get sampling 1 million what should i do?<...
0
2016-08-24T13:09:18Z
39,124,404
<p>You will have always some time discrepancies in running code in python, it's because of resources your CPU <code>gives</code> to running your script. You have to make couple of tries and calculate average time of it.</p>
0
2016-08-24T13:15:15Z
[ "python", "sampling", "cpu-speed" ]
A different run speed in python
39,124,265
<p>i want to get sampling from serial port in python. but if i run a test code to know the rate of it, python gives me different values! it is usually about 24000 time per second. but sometime this code runs only 14000 times. what is the big difference reason ? and if i want to get sampling 1 million what should i do?<...
0
2016-08-24T13:09:18Z
39,124,604
<p>I was @15000 at first execution and then arround 28000. In general the result depends mainly of </p> <ul> <li>your CPU load</li> <li>cache hit/miss</li> <li>RAM access time</li> </ul> <p>But in your case it is the print which takes most of the execution time. So print access time to stdout is the cause of your var...
0
2016-08-24T13:23:58Z
[ "python", "sampling", "cpu-speed" ]
Label recognition with Facebook's library Fasttext
39,124,338
<p>Ok so I have been playing with Facebook's newest text classification python library and I'm struggling a bit with label recognition. </p> <p>If I understood the input have to be lines in a txt file, each line containing both the features and the label. The label can be recognize by the classifier by it's prefix :"_...
0
2016-08-24T13:12:39Z
40,086,631
<p>You need to <strong>show the content of "toto.txt"</strong> in order to get some help.</p> <p>From what I can see now, there is no problem with the code you provided.</p> <p><strong>(btw, make sure your toto.txt is encoded in 'utf-8', otherwise, you need to set an encoding param in classifier)</strong></p>
0
2016-10-17T12:40:27Z
[ "python", "label" ]
Check if a directory is a mount point with python 2.7
39,124,363
<p>Is there a pythonic way and without shell commands (i.e. with subprocess module) to check if a directory is a mount point? </p> <p>Up to now I use:</p> <pre><code>import os import subprocess def is_mount_point(dir_path): try: check_output([ 'mountpoint', path.realpath(dir_name)...
0
2016-08-24T13:13:37Z
39,124,749
<p>There is an <a href="https://docs.python.org/2/library/os.path.html#os.path.ismount" rel="nofollow"><code>os.path.ismount(path)</code></a>.</p> <blockquote> <p>Return True if pathname path is a mount point: a point in a file system where a different file system has been mounted. The function checks whether pa...
2
2016-08-24T13:30:33Z
[ "python", "python-2.7" ]
NLTK RegexpParser, chunk phrase by matching exactly one item
39,124,492
<p>I'm using NLTK's <code>RegexpParser</code> to chunk a noun phrase, which I define with a grammar as </p> <pre><code> grammar = "NP: {&lt;DT&gt;?&lt;JJ&gt;*&lt;NN|NNS&gt;+}" cp = RegexpParser(grammar) </code></pre> <p>This is grand, it is matching a noun phrase as:</p> <ul> <li>DT if it exists</li> <li>JJ in what...
0
2016-08-24T13:19:06Z
39,179,019
<p>Grammer <code>grammar = "NP: {&lt;DT&gt;?&lt;JJ&gt;&lt;NN|NNS&gt;+}"</code> is correct for your mentioned requirement.</p> <p>The example which you gave in comment section, where you are not getting DT in output -</p> <pre><code>"This beautiful green skirt is for you." Tree('S', [('This', 'DT'), ('beautiful', 'JJ...
1
2016-08-27T08:21:18Z
[ "python", "regex", "nlp", "nltk" ]
Python & Google Places API | Want to get all Restaurants at a specific postion
39,124,510
<p>I want to get all restaurants in London by using python 3.5 and the module "googlePlaces" with the Google Places API. I read the "googleplaces" documentation and searched here. But I don't get it. Thats my Code so far:</p> <pre><code>from googleplaces import GooglePlaces, types, lang API_KEY = 'XXXCODEXXX' google...
1
2016-08-24T13:19:39Z
39,208,958
<p>It'll be better if you drop the <code>keyword</code> parameter, <code>types</code> already searches for restaurants.</p> <p>Bear in mind the Places API (as other Google Maps APIs) is not a database, it will not return all results that match. Actually returns only 20, and you can get an extra 40 or so, but that's al...
1
2016-08-29T14:41:40Z
[ "python", "python-3.x", "google-places-api", "google-places" ]
How I do connect oracle database with PyQt ? What's the procedure?
39,124,537
<p>I want to connect my project with PyQt. I searched a lot off in internet . But it's matter of sorrow that i don't any understandable or effective method or procedure.</p>
0
2016-08-24T13:20:49Z
39,124,785
<p>Refer to the following link, in which the author explains how to use <code>cx_Oracle</code> in Python.</p> <p><a href="https://www.youtube.com/watch?v=w3WVqn3WySs" rel="nofollow">https://www.youtube.com/watch?v=w3WVqn3WySs</a></p> <p>After fetching your data from your Oracle DB, you can update your PyQt widgets ba...
0
2016-08-24T13:32:04Z
[ "python", "database", "oracle", "pyqt" ]
recursive function in python but with strange return
39,124,558
<p>I am trying to solve a primary equation with several variables. For example:11x+7y+3z=20. non-negative integer result only.</p> <p>I use code below in python 3.5.1, but the result contains something like [...]. I wonder what is it? The code I have is to test every variables from 0 to max [total value divided by cor...
0
2016-08-24T13:22:09Z
39,125,898
<p>I see three layers of problems here.</p> <p>1) There seems to be a misunderstanding about recursion.</p> <p>2) There seems to be an underestimation of the complexity of the problem you are trying to solve (a modeling issue)</p> <p>3) Your main question exposes some lacking skills in python itself.</p> <p>I will ...
5
2016-08-24T14:18:44Z
[ "python", "recursion", "equation" ]
recursive function in python but with strange return
39,124,558
<p>I am trying to solve a primary equation with several variables. For example:11x+7y+3z=20. non-negative integer result only.</p> <p>I use code below in python 3.5.1, but the result contains something like [...]. I wonder what is it? The code I have is to test every variables from 0 to max [total value divided by cor...
0
2016-08-24T13:22:09Z
39,133,698
<p>Here is a solution built from your second one, but without the global variable. Instead, each call passes back a list of solutions; the parent call appends each solution to the current element, making a new list to return.</p> <pre><code>def equation (a, b): result = [] if len(a) &gt; 1: # For each...
0
2016-08-24T22:02:00Z
[ "python", "recursion", "equation" ]
Show progress bar for each epoch during batchwise training in Keras
39,124,676
<p>When I load the whole dataset in memory and train the network in Keras using following code:</p> <pre><code>model.fit(X, y, nb_epoch=40, batch_size=32, validation_split=0.2, verbose=1) </code></pre> <p>This generates a progress bar per epoch with metrics like ETA, accuracy, loss, etc</p> <p>When I train the netwo...
6
2016-08-24T13:26:43Z
39,192,224
<p>1.</p> <pre><code>model.fit(X, y, nb_epoch=40, batch_size=32, validation_split=0.2, verbose=1) </code></pre> <p>In the above change to <code>verbose=2</code>, as it is mentioned in the documentation: "verbose: 0 for no logging to stdout, 1 for progress bar logging, <code>2 for one log line per epoch</code>."</p> ...
2
2016-08-28T14:19:12Z
[ "python", "machine-learning", "keras" ]
Show progress bar for each epoch during batchwise training in Keras
39,124,676
<p>When I load the whole dataset in memory and train the network in Keras using following code:</p> <pre><code>model.fit(X, y, nb_epoch=40, batch_size=32, validation_split=0.2, verbose=1) </code></pre> <p>This generates a progress bar per epoch with metrics like ETA, accuracy, loss, etc</p> <p>When I train the netwo...
6
2016-08-24T13:26:43Z
39,199,930
<p>you can set verbose=0 and set callbacks that will update progress at the end of each fitting, </p> <pre><code>clf.fit(X, y, nb_epoch=1, batch_size=data.batch_size, verbose=0, callbacks=[some_callback]) </code></pre> <p><a href="https://keras.io/callbacks/#example-model-checkpoints" rel="nofollow">https://keras.io/...
0
2016-08-29T06:37:39Z
[ "python", "machine-learning", "keras" ]
I've created a simple calculator in OOP way in python. I get an error message, that my variables are not defined
39,124,900
<p>So that's my calc, I was trying to do it to understand class decorators better</p> <pre><code>class Calc(): @staticmethod def add(x, y): return x + y . . . @staticmethod def div(x, y): return x / y @staticmethod def get_numbers(): num1 = int(input("Enter first number...
0
2016-08-24T13:37:23Z
39,125,288
<p>There's a couple things wrong with your <code>calculate</code> method.</p> <p>First off, to get access to what your functions <code>get_numbers()</code> and <code>get_operator()</code> return, you need to store the values inside a variable.<br> Second, you also need to add <code>cls.</code> to your <code>add</code>...
1
2016-08-24T13:54:32Z
[ "python", "oop" ]
Can I store my own class object into hdf5?
39,124,934
<p>I have a class like this: </p> <pre><code>class C: def __init__(self, id, user_id, photo): self.id = id self.user_id = user_id self.photo = photo </code></pre> <p>I need to create millions of these objects. id is an integer as well as user_id but photo is a bool array of size 64. My...
0
2016-08-24T13:39:21Z
39,126,483
<p>Although you can store the whole data structure in a single HDF5 table, it is probably much easier to store the described class as three separate variables - two 1D arrays of integers and a data structure for storing your 'photo' attribute.</p> <p>If you care about file size and speed and do not care about human-re...
0
2016-08-24T14:44:10Z
[ "python", "hdf5" ]
Using subprocess to ping an address and get the average ping output in Python?
39,124,982
<p>With this:</p> <pre><code>import subprocess hostname = '104.160.142.3' pingResponse = subprocess.Popen(["ping", hostname, "-n", '1'], stdout=subprocess.PIPE).stdout.read() </code></pre> <p>I get a string pingResponse: </p> <pre><code>b'\r\nPinging 104.160.142.3 with 32 bytes of data:\r\nReply from 104.160.142.3:...
0
2016-08-24T13:41:27Z
39,125,090
<p>You are getting numbers because that is a binary string (note the <code>b</code> in the beginning).</p> <p>You will need to <code>decode</code> it first, then you can use <a href="https://regex101.com/r/zF5tZ4/1" rel="nofollow">regex</a>:</p> <pre><code>import re s = b'\r\nPinging 104.160.142.3 with 32 bytes of d...
2
2016-08-24T13:45:55Z
[ "python" ]
Is it possible to define a special sort key in MongoDB?
39,124,996
<p>I have a MongoDB collection that I want to display on a webpage using pymongo and flask. I want to display only N at a time on the webpage, but I don't want to load the entire set at once, sort, and then show entries a:(a+N).</p> <p>What I'd like to do is something like</p> <pre><code>db.jobs.find().sort({{"status...
0
2016-08-24T13:42:01Z
39,126,182
<p>Yes. Add the statusPriority field to your documents like you have defined in _JOB_PRIORITIES and then sort on that in the Mongo cursor.</p> <p><a href="https://docs.mongodb.com/manual/reference/method/cursor.sort/" rel="nofollow">https://docs.mongodb.com/manual/reference/method/cursor.sort/</a></p>
0
2016-08-24T14:31:48Z
[ "python", "mongodb", "sorting" ]
how to interpret interpret timeit command in Python
39,124,999
<p>For example I have a list:</p> <pre><code>L=[-13, -24, -21, -3, -23, -15, -14, -27, -13, -12] </code></pre> <ol> <li><p>if type in <code>%timeit -n 10 myList = [item for item in L if item &lt; 15]</code> The output is <code>10 loops, best of 3: 1.25 µs per loop</code></p></li> <li><p>if I type <code>myGen = (item...
0
2016-08-24T13:42:07Z
39,125,042
<p>You didn't include the <code>-n</code> argument to <code>%timeit</code> in your second example, so ipython varies the number of repetitions based on how long a trial-run takes; the faster the piece of code being tested, the more iterations are done to get a more accurate per-iteration time value.</p> <p>Moreover, t...
4
2016-08-24T13:44:24Z
[ "python", "time", "ipython", "generator", "python-2.x" ]
Ac2git giving Attribute Error
39,125,044
<p>I am trying to use ac2git to convert my Accurev Depot to Git Repository. I followed the steps given here: <a href="https://github.com/NavicoOS/ac2git" rel="nofollow">https://github.com/NavicoOS/ac2git</a>. I am getting this error when trying to run the python ac2git.py command and the operation is aborted:</p> <pre...
1
2016-08-24T13:44:27Z
39,126,762
<p>As commented, looks like you had a typo in your stream/depo name</p>
2
2016-08-24T14:55:43Z
[ "python", "git" ]
Django - add a function to an admin form under a particular field
39,125,093
<p>I've made a function that iIwant to be able to run on the fly in my admin form, also that it would be reusable for multiple fields.</p> <p>Basically, we have a dmvpn ip and a subnet. I would like to be able to click, find free ip/subnet then run my function against the current values other records have for the fiel...
0
2016-08-24T13:46:01Z
39,126,388
<p>in admin.py</p> <pre><code>from myproject.functions import FindFreeIP class MyAdmin(admin.ModelAdmin): actions = [FindFreeIP] </code></pre> <p>Full details can be found on the django documentation site under <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/admin/actions/#writing-actions" rel="nofol...
0
2016-08-24T14:40:12Z
[ "python", "django" ]
Django - add a function to an admin form under a particular field
39,125,093
<p>I've made a function that iIwant to be able to run on the fly in my admin form, also that it would be reusable for multiple fields.</p> <p>Basically, we have a dmvpn ip and a subnet. I would like to be able to click, find free ip/subnet then run my function against the current values other records have for the fiel...
0
2016-08-24T13:46:01Z
39,126,610
<p>The right way to do it is to create your custom Widget and pass it to change form in admin. </p> <p>Your widget could call a certain view via ajax to perform the IP lookup and fill the input with response.</p> <p>Have a look at the django's source code for the <a href="https://github.com/django/django/blob/master/...
0
2016-08-24T14:49:28Z
[ "python", "django" ]
Matlab to python logic difficulty for arrays
39,125,095
<p>I have created an m-by-n matrix in MATLAB and can easily select a range of values within a certain column and row. For instance, if I have matrix <code>A</code>:</p> <pre><code>A = 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 </code></pre> <p>I can isolate the values: 1,5 an...
0
2016-08-24T13:46:05Z
39,125,783
<p>This can be done using numpy</p> <p><code>a = numpy.matrix('0 0 0 0; 1 2 3 4; 5 6 7 8; 9 10 11 12')</code></p> <p>Required result is <code>a[1:,0]</code> or <code>a[1:4,0]</code></p> <p>Only difference is that the array indexing start from 0 instead of 1.</p>
0
2016-08-24T14:13:54Z
[ "python", "arrays", "matlab" ]
How open file by file in a list of files?
39,125,131
<p>How can I open every single file in a list of files, do something with the file and then go to the next file?</p> <p>I have a directory with 1000 text files. I have already created a list with all the files names and now I want to open file by file. Do someone has an idea how to do that? </p> <p>What I have so far...
-2
2016-08-24T13:47:34Z
39,125,202
<p>There's no need to create a separate list to hold filenames. Just iterate over the results of <code>listdir()</code> directly.</p> <pre><code>for fname in listdir('nes'): fname = join('nes', fname) if fname.endswith('.txt') and isfile(fname): with open(fname, 'r') as f: # do something ...
0
2016-08-24T13:51:09Z
[ "python" ]
How open file by file in a list of files?
39,125,131
<p>How can I open every single file in a list of files, do something with the file and then go to the next file?</p> <p>I have a directory with 1000 text files. I have already created a list with all the files names and now I want to open file by file. Do someone has an idea how to do that? </p> <p>What I have so far...
-2
2016-08-24T13:47:34Z
39,125,239
<pre><code>from os import listdir from os.path import isfile, join files_in_dir = [ f for f in listdir('nes') if isfile(join('nes',f)) ] for f in files_in_dir: if f.endswith(".txt"): with open(f, 'r') as in_file: for line in in_file: # Here you have access to lines of the opene...
1
2016-08-24T13:52:27Z
[ "python" ]
Trying to install Spacy English language model, getting urlopen error
39,125,177
<p>I'm trying to install spaCy using Windows 8 in an anaconda environment with python 3. Following the instructions on spaCy's website, I run the following commands.</p> <pre><code>$ pip install spacy $ python -m spacy.en.download </code></pre> <p>The first command works seemingly fine. However, the second command ca...
0
2016-08-24T13:49:48Z
39,787,506
<p>The 'python -m...' command should be used when running/upgrading an existing model. If you're downloading the model for the first time, use the sputnik package manager which should have been installed as a spaCy dependency:</p> <pre><code>sputnik --name spacy --repository-url http://index.spacy.io install en==1.1.0...
0
2016-09-30T08:55:30Z
[ "python", "python-3.x", "spacy" ]
Adding data to an iterator created with zip
39,125,200
<p>I am using python built-in function zip() to combine two lists:</p> <pre><code>l1 = [1,2,3] l2 = [4,5,6] zipped = zip(l1,l2) </code></pre> <p>Is it possible to 'add' to this zipped object, for example:</p> <pre><code>l3 = [7,8,9] zipped2 = zipped.add(l3) </code></pre> <p>Such that:</p> <pre><code>list(zipped2) ...
0
2016-08-24T13:51:05Z
39,125,301
<p>You cannot add anything to <code>zip</code> function, but you can do it in this way (there are many options):</p> <pre><code>l1 = [1,2,3] l2 = [4,5,6] l3 = [3,6,9] l4 = [10,11,12] l5 = [13,14,15] args = [l1, l2] print (zip(*args)) args.append(l3) print (zip(*args)) # Using a class class Zipped(): @staticmeth...
3
2016-08-24T13:55:11Z
[ "python", "python-3.x" ]
Adding data to an iterator created with zip
39,125,200
<p>I am using python built-in function zip() to combine two lists:</p> <pre><code>l1 = [1,2,3] l2 = [4,5,6] zipped = zip(l1,l2) </code></pre> <p>Is it possible to 'add' to this zipped object, for example:</p> <pre><code>l3 = [7,8,9] zipped2 = zipped.add(l3) </code></pre> <p>Such that:</p> <pre><code>list(zipped2) ...
0
2016-08-24T13:51:05Z
39,125,366
<p>One way would be to write your own generator:</p> <pre><code>def add_to_zip(zipped, lst): for tpl, elem in zip(zipped, lst): yield tpl + (elem,) zipped2 = add_to_zip(zipped, l3) list(zipped2) # OUT: [(1, 4, 7), (2, 5, 8), (3, 6, 9)] </code></pre> <p>If you want to extend it to an arbitrary number of l...
4
2016-08-24T13:57:34Z
[ "python", "python-3.x" ]
Adding data to an iterator created with zip
39,125,200
<p>I am using python built-in function zip() to combine two lists:</p> <pre><code>l1 = [1,2,3] l2 = [4,5,6] zipped = zip(l1,l2) </code></pre> <p>Is it possible to 'add' to this zipped object, for example:</p> <pre><code>l3 = [7,8,9] zipped2 = zipped.add(l3) </code></pre> <p>Such that:</p> <pre><code>list(zipped2) ...
0
2016-08-24T13:51:05Z
39,125,391
<p>if you have <code>zipped</code> but don't have the source <code>l1</code> and <code>l2</code> at this point, you would have to <em>unzip</em> the <code>zipped</code>, add the <code>l3</code> list and zip again:</p> <pre><code>&gt;&gt;&gt; zip(*(zip(*zipped) + [l3])) [(1, 4, 7), (2, 5, 8), (3, 6, 9)] </code></pre> ...
2
2016-08-24T13:58:26Z
[ "python", "python-3.x" ]
Python - Count consecutive frequencies by group
39,125,354
<p>I have a sequence of e-mails ordered by timestamp and user_id. </p> <p>I want to investigate how often email i was followed by email j. I'm going to display these frequencies across users in a heat map to show the most common path. </p> <pre><code>a = """timestamp,email,subject 2016-07-01 10:17:00,a@gmail.com,subj...
1
2016-08-24T13:57:14Z
39,128,019
<p>A two-liner (which you can compress to a one-liner):</p> <pre><code>df1['next_subject'] = df1.groupby('email')['subject'].shift(-1) res = pd.crosstab(df1['next_subject'], df1['subject']) print(res) # subject subject1 subject2 subject3 subject4 welcome # next_subject ...
1
2016-08-24T15:59:34Z
[ "python", "pandas", "sequence", "frequency", "itertools" ]
oTree: How to access the player's id from the player class in model.py?
39,125,370
<p>I would like to define a parameter variable via the default attribute id_in_group of the player. However, this attribute does not seem to be accessible via the ways I could think of (such as via BasePlayer.id_in_group).</p> <p>The code of the class player:</p> <pre><code>class Player(BasePlayer): investment_am...
-1
2016-08-24T13:57:40Z
39,125,655
<p>Have you tried accessing the variable via <code>super.id_in_group</code> or <code>self.id_in_group</code>? If it's a variable of the parent class, you wouldn't call the class directly like you are doing.</p> <p>Also, Google has a ton of results for how to access parent class variables, a lot of which are answers f...
-1
2016-08-24T14:09:08Z
[ "python", "django" ]
Using a progress bar for the output
39,125,406
<p>I'm extremely new to Python and have created a little password cracker, that uses a brute force attack, I'm trying to get my progress bar to output as the program runs, here's what I have so far:</p> <pre><code>import zipfile import sys import time def progress_bar(sleep_time): for i in range(101): ti...
2
2016-08-24T13:59:00Z
39,125,693
<p>What you are trying to do won't work, you must keep in mind you have only one thread.</p> <p>What you could do though, is get the numbers of line in your wordlist, and do the maths. It's surely much more precise than a timer by the way.</p> <p>I didn't test the code, though with something along these lines you'll ...
2
2016-08-24T14:10:29Z
[ "python", "loops" ]
Using a progress bar for the output
39,125,406
<p>I'm extremely new to Python and have created a little password cracker, that uses a brute force attack, I'm trying to get my progress bar to output as the program runs, here's what I have so far:</p> <pre><code>import zipfile import sys import time def progress_bar(sleep_time): for i in range(101): ti...
2
2016-08-24T13:59:00Z
39,125,880
<p>There are to ways of doing what you desire.</p> <ol> <li><p>Let your password-cracker update the progressbar once in a while</p> <pre><code> import time # Stores the time between updates in seconds. time_between_updates = 10 last_update = 0 def your_expensive_operation(): for i in range(10000000): ...
2
2016-08-24T14:18:02Z
[ "python", "loops" ]
How can I plot a pandas multiindex dataframe as 3d
39,125,423
<p>I have a dataframe <code>df</code> grouped like this:</p> <pre><code>Year Product Sales 2010 A 111 B 20 C 150 2011 A 10 B 28 C 190 … … </code></pre> <p>and I would like to plot this in <code>matplotlib</code> as 3d Chart...
3
2016-08-24T13:59:41Z
39,132,123
<p>You could plot a 3D Bar graph using <code>Pandas</code> as shown:</p> <p><strong>Setup:</strong></p> <pre><code>arrays = [[2010, 2010, 2010, 2011, 2011, 2011],['A', 'B', 'C', 'A', 'B', 'C']] tuples = list(zip(*arrays)) index = pd.MultiIndex.from_tuples(tuples, names=['Year', 'Product']) df = pd.DataFrame...
2
2016-08-24T20:02:33Z
[ "python", "pandas", "matplotlib", "3d", "seaborn" ]
Regex with columns pandas
39,125,455
<p>My question is how I can use the <code>re</code> to replace strings that included in a dataframe:</p> <p>when I use the <code>re.sub()</code>, it gives me an error:</p> <pre><code>p = re.compile('New') p.sub('old', df['Col1']) </code></pre> <p>Also, I tried using the for loop but the out put was unexpected and di...
3
2016-08-24T14:00:45Z
39,125,519
<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.replace.html" rel="nofollow"><code>str.replace</code></a>, which works also with <code>regex</code>:</p> <pre><code>df = pd.DataFrame({'Col1':['sss old','dd','old']}) print (df) Col1 0 sss old 1 dd 2 ...
2
2016-08-24T14:03:26Z
[ "python", "regex", "pandas", "dataframe", "series" ]
python atomic data types
39,125,486
<p>It was written <a href="https://ru.wikipedia.org/wiki/Python" rel="nofollow">here</a> that Python has both atomic and reference object types. Atomic objects are: int, long, complex. When assigning atomic object, it's value is copied, when assigning reference object it's reference is copied.</p> <p>My question is: w...
3
2016-08-24T14:01:39Z
39,126,074
<p>int types are immutable. what you see is the reference for the number 1234 and that will never change.</p> <p>for mutable object like list, dictionary you can use</p> <pre><code>import copy a = copy.deepcopy(b) </code></pre>
1
2016-08-24T14:27:25Z
[ "python", "types", "variable-assignment", "atomic" ]
python atomic data types
39,125,486
<p>It was written <a href="https://ru.wikipedia.org/wiki/Python" rel="nofollow">here</a> that Python has both atomic and reference object types. Atomic objects are: int, long, complex. When assigning atomic object, it's value is copied, when assigning reference object it's reference is copied.</p> <p>My question is: w...
3
2016-08-24T14:01:39Z
39,126,122
<p>Actually like @spectras said there are only references but there are immutable objects like <code>float</code>s, <code>int</code>s, <code>tuple</code>s. For immutable objects (apart from memory consumption) it just does not matter if you pass around references or create copies.</p> <p>The interpreter even does some...
0
2016-08-24T14:29:09Z
[ "python", "types", "variable-assignment", "atomic" ]
python atomic data types
39,125,486
<p>It was written <a href="https://ru.wikipedia.org/wiki/Python" rel="nofollow">here</a> that Python has both atomic and reference object types. Atomic objects are: int, long, complex. When assigning atomic object, it's value is copied, when assigning reference object it's reference is copied.</p> <p>My question is: w...
3
2016-08-24T14:01:39Z
39,126,768
<p>Assignment (binding) in Python NEVER copies data. It ALWAYS copies a reference to the value being bound.</p> <p>The interpreter computes the value on the right-hand side, and the left-hand side is bound to the new value by referencing it. If expression on the right-hand side is an existing value (in other words, if...
3
2016-08-24T14:56:00Z
[ "python", "types", "variable-assignment", "atomic" ]
How to click on confirmation button using Selenium with Python?
39,125,633
<p>I have the following Code that goes to a URL(www.example.com), and clicks on a link(Example 1). <strong>(This part works fine)</strong></p> <pre><code>from selenium import webdriver driver = webdriver.Firefox() driver.get("https://www.example.com") link = driver.find_element_by_link_text('Example 1') link.click()...
0
2016-08-24T14:08:01Z
39,126,251
<p>If it is an alert window, you need to use the Alert command.</p> <pre><code>#import Alert from selenium.webdriver.common.alert import Alert from selenium import webdriver driver = webdriver.Firefox() driver.get("https://www.example.com") link = driver.find_element_by_link_text('Example 1') link.click() Alert(driv...
1
2016-08-24T14:34:56Z
[ "python", "selenium" ]
How to click on confirmation button using Selenium with Python?
39,125,633
<p>I have the following Code that goes to a URL(www.example.com), and clicks on a link(Example 1). <strong>(This part works fine)</strong></p> <pre><code>from selenium import webdriver driver = webdriver.Firefox() driver.get("https://www.example.com") link = driver.find_element_by_link_text('Example 1') link.click()...
0
2016-08-24T14:08:01Z
39,129,510
<p>Try this code, hope it will help you</p> <pre><code>from selenium import webdriver import time driver = webdriver.Chrome('path to chromedriver\chromedriver.exe') driver.get('https://www.example.com') driver.maximize_window() link = driver.find_element_by_link_text('Example 1') link.click() handles =driver.window_...
0
2016-08-24T17:24:28Z
[ "python", "selenium" ]
How to click on confirmation button using Selenium with Python?
39,125,633
<p>I have the following Code that goes to a URL(www.example.com), and clicks on a link(Example 1). <strong>(This part works fine)</strong></p> <pre><code>from selenium import webdriver driver = webdriver.Firefox() driver.get("https://www.example.com") link = driver.find_element_by_link_text('Example 1') link.click()...
0
2016-08-24T14:08:01Z
39,146,661
<p>Based on the comment conversation, I would recommend both using an XPATH search (instead of Name or Id) and waiting for elements to be clickable or loaded. When web-driving or web-scraping, pages may intentionally or accidentally load slowly and this can cause issues if you have pauses or waits either hard coded or...
0
2016-08-25T13:27:37Z
[ "python", "selenium" ]
Cannot convert string to float in pandas (ValueError)
39,125,665
<p>I have a dataframe created form a JSON output that looks like this:</p> <pre><code> Total Revenue Average Revenue Purchase count Rate Date Monday 1,304.40 CA$ 20.07 CA$ 2,345 1.54 % </code></pre> <p>The value stored are received as string from the JSON. I am trying to:...
1
2016-08-24T14:09:38Z
39,125,710
<p>These strings have commas as thousands separators so you will have to remove them before the call to <code>float</code>:</p> <pre><code>df[column] = (df[column].str.split()).apply(lambda x: float(x[0].replace(',', ''))) </code></pre> <p>This can be simplified a bit by moving <code>split</code> inside the <code>lam...
0
2016-08-24T14:11:10Z
[ "python", "json", "pandas", "dataframe", "numeric" ]
Cannot convert string to float in pandas (ValueError)
39,125,665
<p>I have a dataframe created form a JSON output that looks like this:</p> <pre><code> Total Revenue Average Revenue Purchase count Rate Date Monday 1,304.40 CA$ 20.07 CA$ 2,345 1.54 % </code></pre> <p>The value stored are received as string from the JSON. I am trying to:...
1
2016-08-24T14:09:38Z
39,125,826
<p>Another solution with <code>list</code> comprehension, if need apply <code>string</code> <a href="http://pandas.pydata.org/pandas-docs/stable/text.html#method-summary" rel="nofollow">functions</a> working only with <code>Series</code> (columns of <code>DataFrame</code>) like <a href="http://pandas.pydata.org/pandas-...
0
2016-08-24T14:15:31Z
[ "python", "json", "pandas", "dataframe", "numeric" ]
Merge two dataframes with pandas
39,125,668
<p>I have two dataframes : </p> <pre><code>df_energy.info() </code></pre> <blockquote> <pre><code>&lt;class 'pandas.core.frame.DataFrame'&gt; Int64Index: 34673 entries, 1 to 43228 Data columns (total 6 columns): TIMESTAMP 34673 non-null datetime64[ns] P_ACT_KW 34673 non-null float64 PERIODE_TARIF 34...
1
2016-08-24T14:09:44Z
39,126,364
<p>Can you tell me the output after you try this? This should work:</p> <pre><code>merged_inner = pd.merge(left=df_energy, right=df1, left_on='TIMESTAMP', right_on='TIMESTAMP') </code></pre>
2
2016-08-24T14:39:16Z
[ "python", "pandas", "dataframe", "merge" ]
Merge two dataframes with pandas
39,125,668
<p>I have two dataframes : </p> <pre><code>df_energy.info() </code></pre> <blockquote> <pre><code>&lt;class 'pandas.core.frame.DataFrame'&gt; Int64Index: 34673 entries, 1 to 43228 Data columns (total 6 columns): TIMESTAMP 34673 non-null datetime64[ns] P_ACT_KW 34673 non-null float64 PERIODE_TARIF 34...
1
2016-08-24T14:09:44Z
39,126,496
<p>Try this:</p> <pre><code>import pandas result = pandas.merge(df_energy, df1, on='TIMESTAMP') </code></pre> <p>If you want to save it:</p> <pre><code>result.to_csv(path_or_buf='result.csv', sep=',') </code></pre> <p>Or check the columns:</p> <pre><code>result_fields = result.columns.tolist() print (result_field...
1
2016-08-24T14:45:03Z
[ "python", "pandas", "dataframe", "merge" ]
How to sum all values with index greater than X?
39,125,695
<p>Let's say I have this series:</p> <pre><code>&gt;&gt;&gt; s = pd.Series({1:10,2:5,3:8,4:12,5:7,6:3}) &gt;&gt;&gt; s 1 10 2 5 3 8 4 12 5 7 6 3 </code></pre> <p>I want to sum all the values for which the index is greater than X. So if e.g. X = 3, I want to get this:</p> <pre><code>&gt;&gt;&gt;...
1
2016-08-24T14:10:32Z
39,125,995
<p>Here's a possible solution:</p> <pre><code>import pandas as pd s = pd.Series({1: 10, 2: 5, 3: 8, 4: 12, 5: 7, 6: 3}) iv = s.index.values print s[iv &lt;= 3].append(pd.Series({'&gt;3': s[iv &gt; 3].sum()})) </code></pre>
1
2016-08-24T14:23:57Z
[ "python", "pandas" ]
How to sum all values with index greater than X?
39,125,695
<p>Let's say I have this series:</p> <pre><code>&gt;&gt;&gt; s = pd.Series({1:10,2:5,3:8,4:12,5:7,6:3}) &gt;&gt;&gt; s 1 10 2 5 3 8 4 12 5 7 6 3 </code></pre> <p>I want to sum all the values for which the index is greater than X. So if e.g. X = 3, I want to get this:</p> <pre><code>&gt;&gt;&gt;...
1
2016-08-24T14:10:32Z
39,126,339
<pre><code>s.groupby(np.where(s.index &gt; 3, '&gt;3', s.index)).sum() </code></pre> <p>Or,</p> <pre><code>s.groupby(s.index.to_series().mask(s.index &gt; 3, '&gt;3')).sum() Out: 1 10 2 5 3 8 &gt;3 22 dtype: int64 </code></pre>
4
2016-08-24T14:38:39Z
[ "python", "pandas" ]
how to scrape a page with javascript effects
39,125,815
<p>I am new to web scraping and so far I only know how to scrape basic html page using python beautiful soup. What I want is to extract the information on this <a href="http://insightdatascience.com/fellows" rel="nofollow">page</a>. Specifically, I would like to get the following data from all the fellows (around 700 o...
-1
2016-08-24T14:14:59Z
39,125,926
<p>Check the page source of the website.</p> <p>The information is already present in the in the DOM, just hidden using CSS. On a first glance, it seems like the JavaScript logic is only doing CSS manipulations.</p> <p>The fact that the information is hidden by CSS will not prevent you from scraping it from the sourc...
0
2016-08-24T14:20:30Z
[ "javascript", "jquery", "python", "html", "web-scraping" ]
Speed up numpy filtering
39,125,952
<p>I am making a music recognition program, and as part of it, I need to find the largest connected areas of a numpy array from a png (2200x1700 pixels). My current solution is the following.</p> <pre><code>labels, nlabels = ndimage.label(blobs) cutoff = len(blobs)*len(blobs[0]) / nlabels blobs_found = 0 x = [] t1 = t...
2
2016-08-24T14:21:57Z
39,130,071
<p>You can get the size (in pixels) of each labelled region with:</p> <pre><code>unique_labels = numpy.unique(labels) label_sizes = scipy.ndimage.measurement.sum(numpy.ones_like(blobs), labels, unique_labels) </code></pre> <p>The largest will then be:</p> <pre><code>unique_labels[label_size == numpy.max(label_size)]...
2
2016-08-24T17:58:17Z
[ "python", "numpy", "scipy", "png" ]
Speed up numpy filtering
39,125,952
<p>I am making a music recognition program, and as part of it, I need to find the largest connected areas of a numpy array from a png (2200x1700 pixels). My current solution is the following.</p> <pre><code>labels, nlabels = ndimage.label(blobs) cutoff = len(blobs)*len(blobs[0]) / nlabels blobs_found = 0 x = [] t1 = t...
2
2016-08-24T14:21:57Z
39,153,370
<p>The fastest would probably be to use <code>numpy.bincount</code> and work from there. Something like:</p> <pre><code>labels, nlabels = ndimage.label(blobs) cutoff = len(blobs)*len(blobs[0]) / float(nlabels) label_counts = np.bincount(labels) # Re-label, taking the cutoff into account cutoff_mask = (label_counts &...
2
2016-08-25T19:31:36Z
[ "python", "numpy", "scipy", "png" ]
Converting str object to int in dictionary
39,125,957
<p>I am currently making a scoreboard for a yatzhee game in python where I'm using a dictionary to associate where a player's points will be inserted into a table. The dictionary looks like this from the start:</p> <pre><code> self.lista={"aces":'',"twos":'',"threes":'',"fours":''} </code></pre> <p>When I associate f...
1
2016-08-24T14:22:05Z
39,126,004
<pre><code>self.lista = {"aces":'',"twos":'',"threes":'',"fours":''} self.lista['aces'] = 25 --&gt; # 25 self.lista['aces'] += 25 --&gt; # 50 </code></pre> <p>OT (for the future reference): You can initialize your dict with keys in this way:</p> <pre><code>keys = ['aces', 'twos', 'threes', 'fours'] self.lista = dict....
3
2016-08-24T14:24:17Z
[ "python", "dictionary" ]
Django - Static files not fetching in Heroku
39,125,963
<p>I made a webpage using Django, and hosted it in Heroku Cloud. This is my second app I successfully hosted one application earlier. But for this application the static files are creating some issues. It not fetching the static files in the production environment. I tried several things but still not working. The foll...
0
2016-08-24T14:22:13Z
39,127,631
<p>You should rename your <code>static/Promag</code> folder to <code>static/promag</code>, to match the case in the static tag, e.g. <code>"{% static 'promag/css/font-awesome.css' %}</code>.</p> <p>If your filesystem is case insensitive (e.g. Windows) or case preserving (e.g. Mac), then it doesn't matter whether you u...
1
2016-08-24T15:39:04Z
[ "python", "django", "heroku" ]
Error in using PyQt4 with python 3.5.2 for running a PyMoskito example
39,125,969
<p>I'm trying to get an example of <a href="https://github.com/cklb/pymoskito" rel="nofollow">PyMoskito</a> running under Python 3.5.2 Win7 64 bit<br> This library needs PyQt4 which in turn needs SIP. </p> <p><strong>1-</strong> I installed SIP using <code>pip3 install SIP</code> which ended up successfully (with a n...
1
2016-08-24T14:22:32Z
39,169,452
<p>The short answer, I believe is that you have pyqt4 (a python interface to the qt4 library), sip (an automated c++-to-python communication library) but not qt4 itself (the UI library). qt4 is it's own monolithic c++ project with its own build and dependency problems.</p> <p>You may be able to find the various pieces...
1
2016-08-26T15:10:12Z
[ "python", "python-3.x", "pyqt", "pyqt4" ]
How do i create new database in Tryton
39,125,976
<p>I have downloaded and installed Tryton 4.0(client 4.0.exe,windows). I have been playing around with the demo database that comes with it.My question is how do i create my own database and user profile. I went to manage profiles,Added new profile,input port number for postgres databse(5432) and input username.But it ...
0
2016-08-24T14:22:52Z
39,126,544
<p>First of all you have to install your custom server, you can not created databases on the demo server. Once you have <a href="http://doc.tryton.org/4.0/trytond/doc/topics/install.html#topics-install" rel="nofollow">installed</a> and <a href="http://doc.tryton.org/4.0/trytond/doc/topics/configuration.html#topics-conf...
0
2016-08-24T14:46:47Z
[ "python", "python-2.7", "tryton" ]
Efficient bookkeeping in heap
39,126,034
<p>I'm trying to implement a heap using list data structure. I'd also like to keep track of the position of elements in the list in order to enable easy deletion. My implementation involves looping through the entire list to update the positions after an insert/delete combo. I'm afraid this raises the time complexity f...
0
2016-08-24T14:25:30Z
39,129,293
<p>If you're building a binary heap, the best way I know of to speed up arbitrary removal or changing priority is to create a hash map. The key is the item in the priority queue, and the value is its current position in the array. When you insert an item into the queue, you add an entry to the hash map with the item's ...
0
2016-08-24T17:10:11Z
[ "python", "heap" ]
Python 2.7 - Unable to correctly decode email subject-header line
39,126,189
<p>I'm using Python 2.7, and I am trying to properly decode the subject header line of an email. The source of the email is: </p> <pre><code>Subject: =?UTF-8?B?VGkgw6ggcGlhY2l1dGEgbGEgZGVtbz8gU2NvcHJpIGFsdHJlIG4=?= </code></pre> <p>I use the function decode_header(header) from the email.header library, and the result...
0
2016-08-24T14:32:06Z
39,126,500
<p>You <em>are</em> getting the correct string. It's just encoded (using UTF-8 in the first case, and iso-8895-1 in the second); you need to decode it to get the actual unicode string.</p> <p>For example:</p> <pre><code>&gt;&gt;&gt; print unicode('Ti \xc3\xa8 piaciuta la demo? Scopri altre n', 'utf-8') Ti è piaciut...
1
2016-08-24T14:45:11Z
[ "python", "python-2.7", "email", "decode", "string-decoding" ]
Calculate distances in a kind of "bag of words" approach
39,126,249
<p>My code runs but the output of my function is always <code>0.0</code>. My code calls <code>.txt</code> files and creates a matrix where each <code>.txt</code> file represents a line in the matrix and each word in the <code>.txt</code> file has its own column in the respective line in the matrix.</p> <p>I compare th...
0
2016-08-24T14:34:48Z
39,126,305
<p>For the first sight I see two failures here:</p> <pre><code>a = ["a", "b", "c", "d"], &lt;----- comma here b = ["b", "c", "d", "e"] it works, but when I change to: a = ["word 1", "word 2", "word 3", "word 4"], &lt;----- and here b = ["word 2","word 3","word 4","word 5",] &lt;----- and here inside the list </code...
0
2016-08-24T14:37:21Z
[ "python", "count", "distance" ]
Reset new keys to a dictionary
39,126,272
<p>I have a python dictionary.</p> <pre><code>A=[0:'dog',1:'cat',3:'fly',4,'fish',6:'lizard'] </code></pre> <p>I want to reset the keys according to <code>range(len(A))</code>(the natural increment), which should look like:</p> <pre><code>new_A=[0:'dog',1:'cat',2:'fly',3:'fish',4:'lizard'] </code></pre> <p>How coul...
1
2016-08-24T14:35:36Z
39,126,434
<p>Here's a working example for both py2.x and py3.x:</p> <pre><code>A = {0: 'dog', 1: 'cat', 3: 'fly', 4: 'fish', 6: 'lizard'} B = {i: v for i, v in enumerate(A.values())} print(B) </code></pre>
2
2016-08-24T14:42:13Z
[ "python", "dictionary", "order", "key", "value" ]
Reset new keys to a dictionary
39,126,272
<p>I have a python dictionary.</p> <pre><code>A=[0:'dog',1:'cat',3:'fly',4,'fish',6:'lizard'] </code></pre> <p>I want to reset the keys according to <code>range(len(A))</code>(the natural increment), which should look like:</p> <pre><code>new_A=[0:'dog',1:'cat',2:'fly',3:'fish',4:'lizard'] </code></pre> <p>How coul...
1
2016-08-24T14:35:36Z
39,126,512
<p>If you want to assign new keys in the ascending order of old keys, then</p> <pre><code>new_A = {i: A[k] for i, k in enumerate(sorted(A.keys()))} </code></pre>
2
2016-08-24T14:45:47Z
[ "python", "dictionary", "order", "key", "value" ]
Reset new keys to a dictionary
39,126,272
<p>I have a python dictionary.</p> <pre><code>A=[0:'dog',1:'cat',3:'fly',4,'fish',6:'lizard'] </code></pre> <p>I want to reset the keys according to <code>range(len(A))</code>(the natural increment), which should look like:</p> <pre><code>new_A=[0:'dog',1:'cat',2:'fly',3:'fish',4:'lizard'] </code></pre> <p>How coul...
1
2016-08-24T14:35:36Z
39,126,640
<p>Dictionaries are not ordered. If your keys are incremental integers, you might as well use a list.</p> <p>new_A = list(A.values())</p>
1
2016-08-24T14:50:49Z
[ "python", "dictionary", "order", "key", "value" ]
Reset new keys to a dictionary
39,126,272
<p>I have a python dictionary.</p> <pre><code>A=[0:'dog',1:'cat',3:'fly',4,'fish',6:'lizard'] </code></pre> <p>I want to reset the keys according to <code>range(len(A))</code>(the natural increment), which should look like:</p> <pre><code>new_A=[0:'dog',1:'cat',2:'fly',3:'fish',4:'lizard'] </code></pre> <p>How coul...
1
2016-08-24T14:35:36Z
39,126,674
<p>If you want to keep the same order of keys </p> <pre><code>A={0:'dog',1:'cat',3:'fly',4,'fish',6:'lizard'} new_A=dict((i,A[k]) for i,k in enumerate(sorted(A.keys())) </code></pre>
2
2016-08-24T14:52:11Z
[ "python", "dictionary", "order", "key", "value" ]
Reset new keys to a dictionary
39,126,272
<p>I have a python dictionary.</p> <pre><code>A=[0:'dog',1:'cat',3:'fly',4,'fish',6:'lizard'] </code></pre> <p>I want to reset the keys according to <code>range(len(A))</code>(the natural increment), which should look like:</p> <pre><code>new_A=[0:'dog',1:'cat',2:'fly',3:'fish',4:'lizard'] </code></pre> <p>How coul...
1
2016-08-24T14:35:36Z
39,128,821
<p>If you want ordering by creation as well as access by key, then you want an <code>OrderedDict</code>.</p> <pre><code>&gt;&gt;&gt; from collections import OrderedDict &gt;&gt;&gt; d=OrderedDict() &gt;&gt;&gt; d['Cat'] = 'cool' &gt;&gt;&gt; d['Dog'] = 'best' &gt;&gt;&gt; d['Fish'] = 'cold' &gt;&gt;&gt; d['Norwegian B...
0
2016-08-24T16:41:39Z
[ "python", "dictionary", "order", "key", "value" ]
How can I check a file has been copied fully to a folder before moving it using python
39,126,411
<p>I'm currently working on a project that adds images to a folder. As they're added they also need to be moved (in groups of four) to a secondary folder overwriting the images that are already in there (if any). I have it sort of working using watchdog.py to monitor the first folder. When the 'on_created' event fires ...
0
2016-08-24T14:41:12Z
39,126,518
<p>I see multiple solutions :</p> <ol> <li>When you first create your images in the first folder, add a suffix to their name, for instance, <code>filexxx.jpg.part</code> and when they are fully written just rename them, removing the <code>.part</code>. Then in your watchdog, be sure not to work on files ending with <c...
1
2016-08-24T14:45:52Z
[ "python", "image", "filesystems" ]
Running code on Django application start
39,126,445
<p>I need to run some code every time my application starts. I need to be able to manipulate models, just like I would in actual view code. Specifically, I am trying to hack built-in User model to support longer usernames, so my code is like this</p> <pre> def username_length_hack(sender, *args, **kwargs): model =...
0
2016-08-24T14:42:37Z
39,127,214
<p>I agree with the comments; there are prettier approaches than this.</p> <p>You could add your code to the <code>__init__.py</code>of your app</p>
1
2016-08-24T15:17:24Z
[ "python", "django" ]
Partition list based on elements of another list as keys
39,126,516
<p>How can I combine these two lists and use <code>alist</code> as keys and <code>blist</code> as values? What I would like to do is group the values in <code>blist</code> with the corresponding keys. So let's say values <code>3, 4, 2, None, None, 1, 1, 1, 6, 1, 2, 4, 5, 5, 7, 1, 1, 2, 3, 4, 5</code> should have <code>...
0
2016-08-24T14:45:51Z
39,126,571
<p>Something like this:</p> <pre><code>res = {} for i in range(len(alist)): if alist[i] in res: res[alist[i]].append(blist[i]) else: res[alist[i]]=[blist[i]] </code></pre> <p>returns <code>{'Inner OD': [2, None, None, 1, 1, 1, 6, 1, 2, 4, 5, 5, 7, 1, 1, 2, 3, 4, 5, 1, None, 3, 4, 6], 'Outter O...
2
2016-08-24T14:48:05Z
[ "python", "python-2.7" ]
Partition list based on elements of another list as keys
39,126,516
<p>How can I combine these two lists and use <code>alist</code> as keys and <code>blist</code> as values? What I would like to do is group the values in <code>blist</code> with the corresponding keys. So let's say values <code>3, 4, 2, None, None, 1, 1, 1, 6, 1, 2, 4, 5, 5, 7, 1, 1, 2, 3, 4, 5</code> should have <code>...
0
2016-08-24T14:45:51Z
39,128,182
<p>It does nothing better than the @Gábor Erdős answer but I think it is a bit clearer:</p> <pre><code>&gt;&gt;&gt; alist = [u'Outter OD', u'Outter OD', u'Inner OD', u'Inner OD', u'Inner OD', u'Inner OD', u'Inner OD', u'Inner OD', u'Inner OD', u'Inner OD', u'Inner OD', u'Inner OD', u'Inner OD', u'Inner OD', u'Inn...
0
2016-08-24T16:07:05Z
[ "python", "python-2.7" ]
Partition list based on elements of another list as keys
39,126,516
<p>How can I combine these two lists and use <code>alist</code> as keys and <code>blist</code> as values? What I would like to do is group the values in <code>blist</code> with the corresponding keys. So let's say values <code>3, 4, 2, None, None, 1, 1, 1, 6, 1, 2, 4, 5, 5, 7, 1, 1, 2, 3, 4, 5</code> should have <code>...
0
2016-08-24T14:45:51Z
39,128,362
<p>Yet another solution. It does nothing better than @Tryph's answer (which does nothing better than the @Gábor Erdős's answer) but I think using <code>defaultdict</code> makes the logic a bit cleaner:</p> <pre><code>from collections import defaultdict res = defaultdict(list) for a, b in zip(alist, blist): res[...
1
2016-08-24T16:16:33Z
[ "python", "python-2.7" ]
Python treats "is" to pluralize string literal
39,126,532
<p>Python version 3.4.3</p> <p>Python converting string literal to plural. I cannot figure out how to solve this.</p> <p>When I enter:</p> <pre><code>&gt;&gt;&gt; x = ("The number % is incorrect" % 8) &gt;&gt;&gt; x 'The number 8s incorrect' </code></pre> <p>When I try to escape "is" I get an error.</p> <pre><co...
0
2016-08-24T14:46:24Z
39,126,547
<p>Just use <code>format</code> function instead:</p> <pre><code>x = "The number {} is incorrect".format(8) </code></pre>
9
2016-08-24T14:46:59Z
[ "python", "python-3.x" ]
Python treats "is" to pluralize string literal
39,126,532
<p>Python version 3.4.3</p> <p>Python converting string literal to plural. I cannot figure out how to solve this.</p> <p>When I enter:</p> <pre><code>&gt;&gt;&gt; x = ("The number % is incorrect" % 8) &gt;&gt;&gt; x 'The number 8s incorrect' </code></pre> <p>When I try to escape "is" I get an error.</p> <pre><co...
0
2016-08-24T14:46:24Z
39,126,593
<p>Try <code>'the number %d is incorrect' % 8</code></p> <p>The problem is that python is reading your <code>%</code> (with the space, thanks, Ashwini) , and thinking that is your format character.</p>
6
2016-08-24T14:48:52Z
[ "python", "python-3.x" ]
Python treats "is" to pluralize string literal
39,126,532
<p>Python version 3.4.3</p> <p>Python converting string literal to plural. I cannot figure out how to solve this.</p> <p>When I enter:</p> <pre><code>&gt;&gt;&gt; x = ("The number % is incorrect" % 8) &gt;&gt;&gt; x 'The number 8s incorrect' </code></pre> <p>When I try to escape "is" I get an error.</p> <pre><co...
0
2016-08-24T14:46:24Z
39,127,738
<p>The string:</p> <pre><code>'the number % is incorrect' % 8 </code></pre> <p>is actually interpreted as:</p> <pre><code>'the number [% i]s incorrect' % 8 # ^ conversion specifier </code></pre> <p>and according to the <a href="https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatt...
3
2016-08-24T15:45:02Z
[ "python", "python-3.x" ]
How to remove characters from multiple files in python
39,126,668
<p>I'm, trying to write a simple program to batch rename files in a folder. </p> <p>file format: </p> <pre><code>11170_tcd001-20160824-094716.txt 11170_tcd001-20160824-094716.rst 11170_tcd001-20160824-094716.raw </code></pre> <p>I have 48 of the above with a different 14 digit character configuration after the fir...
0
2016-08-24T14:52:00Z
39,126,812
<p>You should probably try using regular expressions, like</p> <pre><code>import re &lt;...&gt; newfilename = re.sub(r'-\d{8}-\d{6}\b', '', oldfilename) &lt;...&gt; </code></pre> <p>This will replace any 'hyphen, 8 digits, hyphen, 6 digits' not followed by letter, digit or underscore with empty string in your file...
2
2016-08-24T14:57:59Z
[ "python", "batch-rename" ]
How to remove characters from multiple files in python
39,126,668
<p>I'm, trying to write a simple program to batch rename files in a folder. </p> <p>file format: </p> <pre><code>11170_tcd001-20160824-094716.txt 11170_tcd001-20160824-094716.rst 11170_tcd001-20160824-094716.raw </code></pre> <p>I have 48 of the above with a different 14 digit character configuration after the fir...
0
2016-08-24T14:52:00Z
39,126,876
<p>If you are looking for a non-regex approach and considering your files all match that particular pattern you are expecting, what you can do first is get the extension of the file using <code>splitext</code>:</p> <pre><code>from os.path import splitext file_name = '11170_tcd001-20160824-094716.txt' extension = split...
4
2016-08-24T15:00:16Z
[ "python", "batch-rename" ]
"This session is in 'prepared' state; no further" error with SQLAlchemy using scoped_session in threaded mod_wsgi app
39,126,810
<p>I recently updated to SQLAlchemy 1.1, which I'm using under Django 1.10 (also recently updated from 1.6), and I keep getting sqlalchemy/mysql errors that <code>This session is in 'prepared' state; no further SQL can be emitted within this transaction.</code></p> <p>How do I debug this?</p> <p>It's running in a sin...
0
2016-08-24T14:57:58Z
39,131,561
<p>The RequestContainer was being accidentally assigned to a global API interface handler, causing one session to be mis-used among multiple threads, when it was intended to be created per thread.</p>
0
2016-08-24T19:27:24Z
[ "python", "mysql", "django", "sqlalchemy", "mod-wsgi" ]
Replacing multiple strings with regex in python for a file giving truncated string
39,126,870
<p>The following python code </p> <pre><code>import xml.etree.cElementTree as ET import time import fileinput import re ts = str(int(time.time())) modifiedline ='' for line in fileinput.input("singleoutbound.xml"): line = re.sub('OrderName=".*"','OrderName="'+ts+'"', line) line = re.sub('OrderNo=".*"','Order...
1
2016-08-24T15:00:02Z
39,127,439
<p><strong>Do not use Regexes for parsing XML if you don't have an important reason for doing so</strong></p> <p><code>*</code> does greedy matching but what you actually seem to want is <code>*?</code> for not matching until the last <code>"</code> in the line but the next <code>"</code>.</p> <p>So just replace each...
0
2016-08-24T15:29:43Z
[ "python", "regex", "xml", "elementtree" ]
Replacing multiple strings with regex in python for a file giving truncated string
39,126,870
<p>The following python code </p> <pre><code>import xml.etree.cElementTree as ET import time import fileinput import re ts = str(int(time.time())) modifiedline ='' for line in fileinput.input("singleoutbound.xml"): line = re.sub('OrderName=".*"','OrderName="'+ts+'"', line) line = re.sub('OrderNo=".*"','Order...
1
2016-08-24T15:00:02Z
39,138,529
<p>Here is how to use ElementTree to make modifications to an XML file without accidentally breaking it:</p> <pre><code>import xml.etree.cElementTree as ET import time ts = str(int(time.time())) doc = ET.parse('singleoutbound.xml') for elem in doc.iterfind('//*[@OrderName]'): elem.attrib['OrderName'] = ts # an...
1
2016-08-25T06:51:59Z
[ "python", "regex", "xml", "elementtree" ]
Why is Autobahn Twisted Websocket server is not completing handshake with javascript client?
39,126,916
<p>I'm trying to use a twisted websocket server and connect it to a javascript client on localhost, not through a network. The server and client see each other but they can't complete the handshake. Yes I'm using a Hixie-76 wrapper provided by txWS because of a systems requirement. </p> <p>I'm stumped on why they can'...
1
2016-08-24T15:02:02Z
39,131,156
<p>Okay I found the issue. As Michael S suggested it is probably in the Hixie-76 wrapper, it was. The dev must have let that protocol slip over time and it no longer is working. I could confirm this by tracing it back in the code. I will report it back to the dev of txWS.</p> <p>I found an alternate solution to th...
0
2016-08-24T19:01:49Z
[ "javascript", "python", "websocket", "twisted", "autobahn" ]
Appending several panda dataframes are not working
39,126,941
<p>I have this code</p> <pre><code>import os import pandas as pd path = r'c:\Temp\factory' os.chdir(path) files = os.listdir() files_csv = [f for f in files if f[-3:] == 'csv'] x = pd.DataFrame() for f in files_csv: data = pd.read_csv(f, sep=';', encoding='latin-1') x = x.append(data, ignore_index=True) </co...
-1
2016-08-24T15:03:15Z
39,127,216
<p>I've needed to do something similar before. My solution would be:</p> <pre><code>x = pd.DataFrame() for f in files_csv: data = pd.read_csv(f, sep=';', encoding='latin-1') x = pd.concat([x, data], ignore_index=True, axis=1) </code></pre>
0
2016-08-24T15:17:28Z
[ "python", "pandas" ]
s3cmd nodename nor servname provided, or not known
39,127,002
<p>I'm trying to access objects from my S3 bucket with s3cmd with path style urls. This is no problem with the Java SDK like.</p> <pre><code>s3Client.setS3ClientOptions(S3ClientOptions.builder() .setPathStyleAccess(true).build()); </code></pre> <p>I want to do the same with s3cmd. I have set this up in my...
0
2016-08-24T15:06:32Z
39,552,587
<p>Assuming that there is no other issue with your configuration, the value that you used for "host_bucket" is wrong.</p> <p>It should be:</p> <pre><code>host_bucket = %(bucket)s.s3.eu-central-1.amazonaws.com </code></pre> <p>or</p> <pre><code>host_bucket = s3.eu-central-1.amazonaws.com </code></pre> <p>The second...
0
2016-09-17T23:10:28Z
[ "python", "amazon-web-services", "amazon-s3", "s3cmd" ]
Unable to create a functional executable with PyInstaller and PyQt
39,127,097
<p>I have tried, for a lot of time now, to create an executable for a Python project. In this project, I need to use:</p> <ol> <li>PyQt(4) : for my GUI,</li> <li>PySerial : to communicate with an arduino,</li> <li>Subprocess : to launch some avr things with a .bat file</li> </ol> <p>In fact, the executable is created...
0
2016-08-24T15:11:29Z
39,146,888
<p>Maybe the "frozen" application does not find the "cmd.bat"!? You could test it by replacing it with the absolute path.</p> <p>Your executable unpacks the "cmd.bat" in a temporary folder accessible in python with <code>sys._MEIPASS</code>. You should find your files with something like <code>os.path.join(sys._MEIPAS...
0
2016-08-25T13:37:26Z
[ "python", "qt", "python-3.x", "subprocess", "pyinstaller" ]