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
Is regex the best way to extract data from log
39,565,603
<p>I've got a file full of log and I'm trying to extract some data from those log, a log look like:</p> <pre><code>IP_adress - - [Date_time] "method" response_nb time "page" "UA" "IP_adress" </code></pre> <p>I want to extract the IP_adress and UA. Is using a regex a good idea to extract data from those log or is ther...
-1
2016-09-19T04:52:36Z
39,565,616
<p>Just split the string and get last two elements.</p> <pre><code>&gt;&gt;&gt; &gt;&gt;&gt; str = 'IP_adress - - [Date_time] "method" response_nb time "page" "UA" "IP_a dress"' &gt;&gt;&gt; tmp_list = str.split() &gt;&gt;&gt; &gt;&gt;&gt; tmp_list ['IP_adress', '-', '-', '[Date_time]', '"method"', 'response_nb', 'tim...
2
2016-09-19T04:55:03Z
[ "python", "regex", "python-2.7" ]
Simple Python web crawler
39,565,730
<p>I'm following a python tutorial on youtube and got up to where we make a basic web crawler. I tried making my own to do a very simple task. Go to my cities car section on craigslist and print the title/link of every entry, and jump to the next page and repeat if needed. It works for the first page, but won't continu...
0
2016-09-19T05:06:48Z
39,565,808
<p>Looks like you have a problem with your indentation, you need to do <code>page += 100</code> in the main while block and <strong>not</strong> inside the for loop.</p> <pre><code>def widow(max_pages): page = 0 # craigslist starts at page 0 while page &lt;= max_pages: url = 'http://orlando.craigslist...
1
2016-09-19T05:15:10Z
[ "python", "web-crawler" ]
Select specific fields in Django get_object_or_404
39,565,749
<p>I have a model in Django with too many fields. Ex:</p> <pre><code>class MyModel(models.Model): param_1 = models.CharField(max_length=100) ... param_25 = models.CharField(max_length=100) </code></pre> <p>Now I need to get the detail view based on an id. I have seen may methods like,</p> <pre><code>obj ...
0
2016-09-19T05:09:04Z
39,565,807
<p>The first argument to is the class name of the model and all other arguments are parameters that will be passed to get. So it cannot be used here, but it's quite simple to mimic it's functionality. </p> <pre><code>def get_object_or_404_custom(klass,fields = None, *args, **kwargs): queryset = _get_queryset(klass...
1
2016-09-19T05:15:09Z
[ "python", "sql", "django", "model" ]
Select specific fields in Django get_object_or_404
39,565,749
<p>I have a model in Django with too many fields. Ex:</p> <pre><code>class MyModel(models.Model): param_1 = models.CharField(max_length=100) ... param_25 = models.CharField(max_length=100) </code></pre> <p>Now I need to get the detail view based on an id. I have seen may methods like,</p> <pre><code>obj ...
0
2016-09-19T05:09:04Z
39,565,956
<p>The first argument to <code>get_object_or_404</code> can be <a href="https://docs.djangoproject.com/en/1.10/topics/http/shortcuts/#django.shortcuts.get_object_or_404" rel="nofollow">a Model, a Manager or a QuerySet</a>:</p> <blockquote> <p>Required arguments</p> <p><strong>klass</strong></p> <p>A Model ...
3
2016-09-19T05:29:15Z
[ "python", "sql", "django", "model" ]
zshell pip can't find package autobahn[serialization]
39,565,867
<p>I was trying to install <code>serialization</code> variant of autobahn. However, when I do that in <code>zsh</code>, I get an error. </p> <p><code>zsh: no matches found: autobahn[serialization]</code></p> <p>However, as soon as I use <code>bash</code>, it works. Below is my command line log:</p> <pre><code>kapil@...
0
2016-09-19T05:20:47Z
39,653,120
<p>Square brackets are special characters in zsh, you can escape them with backslash:</p> <pre><code>pip install autobahn\[serialization\] </code></pre> <p>Or <a href="http://kinopyo.com/en/blog/escape-square-bracket-by-default-in-zsh" rel="nofollow">escape square brackets by default in zsh</a>.</p>
0
2016-09-23T05:21:20Z
[ "python", "pip", "zsh", "autobahn", "msgpack" ]
How can I make a python thread count down and then perform an action?
39,565,933
<p>I have a script that accesses the api for Telegram bots, but it unfortunately can only process one message at a time.</p> <p>My end goal is to have it start a timer thread when someone starts a game, and after a certain time (if they haven't already won the game) it would reset the game to avoid preventing another ...
0
2016-09-19T05:27:37Z
39,566,098
<p>Haven't worked over python-telegram-bot yet, But all I know about the timer use in Python is using <code>sched</code> gives you leverage to timer abilities to your python code. Since in your app <code>multithreading</code> will make more sense and for that you can look out for <code>threading.Timer</code> class.</p>...
0
2016-09-19T05:44:24Z
[ "python", "multithreading", "python-telegram-bot" ]
Script to print names in Python modules
39,565,937
<p>The following script isn't printing names contained within each Python module in the list. When I run it, each dir(mod) command returns the same list of names. It's like the 'mod' variable isn't being understood by dir. The for loop doesn't appear to be the problem. Any ideas how to fix?</p> <pre><code>#!/usr/bin/p...
0
2016-09-19T05:27:45Z
39,566,153
<p>Problem is you are passing module name as variable to <code>dir</code> function. Since module name is passed in variable, it is considering as string and <code>dir</code> is giving output for string.</p> <pre><code>&gt;&gt;&gt; &gt;&gt;&gt; &gt;&gt;&gt; mod = 'os' &gt;&gt;&gt; &gt;&gt;&gt; dir(mod) ['__add__', '__c...
1
2016-09-19T05:50:56Z
[ "python", "module", "directory", "names" ]
Django ModelAdmin custom method obj parameter
39,566,087
<p>In Django's document <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/admin/" rel="nofollow">Django Document</a></p> <p>It has following code.</p> <pre><code>from django.contrib import admin class AuthorAdmin(admin.ModelAdmin): fields = ('name', 'title', 'view_birth_date') def view_birth_date...
0
2016-09-19T05:43:08Z
39,566,129
<blockquote> <p>I don't understand in the custom method <code>view_birth_date(self, obj)</code> where this <code>obj</code> parameter came from?</p> </blockquote> <p>This method is called by Django's machinery and <code>obj</code> is passed also by it. It's just a predefined interface.</p> <blockquote> <p><code>v...
2
2016-09-19T05:48:18Z
[ "python", "django" ]
SoftLayer API: How to get the blockDevice information from a image template?
39,566,113
<p><a href="http://i.stack.imgur.com/dSjqz.png" rel="nofollow"><img src="http://i.stack.imgur.com/dSjqz.png" alt="enter image description here"></a></p> <p>I have a image template as shown in the picture. I want to get the disk space and the virtual disks list as marked in the Figure. I used:</p> <p><code>http://sldn...
0
2016-09-19T05:46:46Z
39,566,776
<p>Please try the following <code>mask</code> (This a Rest example):</p> <pre><code> https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest_Block_Device_Template_Group/[imageId]/getObject?objectMask=mask[id,name,children[id,name,blockDevices[diskSpace,units,diskImage[localDiskFlag]]]] Method:GE...
0
2016-09-19T06:37:28Z
[ "python", "api", "softlayer" ]
Keras shape of features for training
39,566,123
<p>I'm trying to train nn with keras <code>train_on_batch</code> function. I have 39 features and want a batch to contain 32 samples. So I have a list of 32 numpy arrays for every training iteration. </p> <p>So here is my code(here every batch_x is a list of 32 numpy array each containing 39 features):</p> <pre><code...
0
2016-09-19T05:47:46Z
39,568,178
<p>You don't want 32 arrays of size 39, you want one array of size (32, 39). </p> <p>So you must change input_shape to (None, 39), the None allowing you to dynamically change your batch_size, and change batch_x to be a numpy array of shape (32, 39).</p>
3
2016-09-19T08:04:46Z
[ "python", "python-2.7", "machine-learning", "keras", "training-data" ]
Keras shape of features for training
39,566,123
<p>I'm trying to train nn with keras <code>train_on_batch</code> function. I have 39 features and want a batch to contain 32 samples. So I have a list of 32 numpy arrays for every training iteration. </p> <p>So here is my code(here every batch_x is a list of 32 numpy array each containing 39 features):</p> <pre><code...
0
2016-09-19T05:47:46Z
39,602,126
<p>In Keras, the <strong>output</strong> not the <strong>input</strong> dimension is the first arg. The <a href="http://keras.io" rel="nofollow">Keras docs</a> front-page example is pretty clear:</p> <pre><code>model.add(Dense(output_dim=64, input_dim=100)) </code></pre> <p>Adjusting that example to match what I gues...
1
2016-09-20T19:15:56Z
[ "python", "python-2.7", "machine-learning", "keras", "training-data" ]
Correct way to extend AbstractUser in Django?
39,566,144
<p>I'm trying to integrate two django apps where each had their individual auths working. To do that, I'm trying to subclass AbstractUser instead of User. I'm following the <a href="https://pybbm.readthedocs.io/en/latest/customuser.html" rel="nofollow">PyBB docs</a> and <a href="https://docs.djangoproject.com/en/1.9/to...
0
2016-09-19T05:50:04Z
39,567,793
<p>You can't have a one-to-one relationship with an abstract model; by definition, an abstract model is never actually instantiated.</p> <p>AbstractUser is supposed to be <em>inherited</em>. Your structure should be:</p> <pre><code>class Student_User(AbstractUser): ... </code></pre>
0
2016-09-19T07:41:11Z
[ "python", "mysql", "django", "authorization", "django-authentication" ]
float precision in numpy arrays differ from their elements
39,566,194
<p>I have values of <code>numpy.float32</code> type, and a numpy array with <code>dtype="float32"</code>.</p> <p>When outputting the representation of the values directly using the individual array element references, I get a difference in precision than when I output the representation of the array object itself.</p>...
0
2016-09-19T05:54:13Z
39,566,846
<p>These are just differences in the string representation, the values are the same and calculations are not off.</p> <pre><code>&gt;&gt;&gt; (t * elementx) == (t * arrayx)[0] True </code></pre>
2
2016-09-19T06:42:02Z
[ "python", "numpy", "floating-point", "precision" ]
Is there a way to bind a session object to MetaData.create_all method in SQLAlchemy?
39,566,286
<p>I have an application that creates tables on demand using <strong>SQLAlchemy</strong>. More precisely <strong>Flask-SQLAlchemy</strong> and <strong>PostgreSQL</strong> as database. </p> <p>To do that, <strong>(1)</strong> I create a PostgreSQL schema to hold the new tables:</p> <pre><code># extra checks on the sch...
0
2016-09-19T06:01:30Z
39,571,930
<p><a href="http://docs.sqlalchemy.org/en/latest/orm/session_transaction.html#joining-a-session-into-an-external-transaction-such-as-for-test-suites" rel="nofollow">"Joining a Session into an External Transaction (such as for test suites)"</a> from the SQLAlchemy docs is a good starting point in this case. I would refa...
1
2016-09-19T11:18:55Z
[ "python", "postgresql", "sqlalchemy" ]
Derive extra column from Pandas dataframe columns
39,566,311
<p>Given a dataframe, how to add an extra column which is derived from the columns in the dataframe i.e.</p> <pre><code>data = {'date': ['2016-01-01', '2016-01-01', '2016-01-02'], 'number': [10, 21, 20], 'location': ['CA', 'NY', 'NJ'] } print pd.DataFrame(data) location number date ...
0
2016-09-19T06:04:07Z
39,567,872
<p>You can write a function do to the manipulation with the current columns and just add the column to the <code>DataFrame</code>. See the code below:</p> <pre><code>import pandas as pd data = {'date': ['2016-01-01', '2016-01-01', '2016-01-02'], 'number': [10, 21, 20], 'location': ['CA', 'NY', 'NJ'] ...
1
2016-09-19T07:45:50Z
[ "python", "pandas" ]
Forbid Python from writing anything to disk
39,566,470
<p>Are there any command-line options or configurations that forbids Python from writing to disk?</p> <p>I know I can hack <code>open</code> but it doesn't sound very safe.</p> <hr> <p>I've hosted some Python tutorials I wrote myself on my website for friends who want to learn Python, and I want them to have access ...
2
2016-09-19T06:15:13Z
39,566,721
<p>I doubt there's a way to do this in the interpreter itself: there are way too many things to patch (<code>open</code>, <code>subprocess</code>, <code>os.system</code>, <code>file</code>, and probably others). I'd suggest looking into a way of containerizing the python runtime via something like Docker. The container...
5
2016-09-19T06:33:34Z
[ "python", "linux" ]
Fastest way to insert a 2D array into a (larger) 2D array
39,566,474
<p>Say there's two 2D arrays, <code>a</code> and <code>b</code></p> <pre><code>import numpy as np a = np.random.rand(3, 4) b = np.random.zeros(8, 8) </code></pre> <p>and <code>b</code> is always larger than <code>a</code> over both axes.</p> <p><em>(Edit: <code>b</code> is initialized as an array of zeros, to reflec...
0
2016-09-19T06:15:28Z
39,568,478
<p>What about :</p> <pre><code>b[:a.shape[0],:a.shape[1]] = a </code></pre> <p>Note I assumed <code>a</code> is to be placed at the begining of <code>b</code> but you could refine it a bit to put <code>a</code> anywhere:</p> <pre><code>a0,a1=1,1 b[a0:a0+a.shape[0],a1:a1+a.shape[1]] = a </code></pre>
2
2016-09-19T08:23:26Z
[ "python", "numpy" ]
Fastest way to insert a 2D array into a (larger) 2D array
39,566,474
<p>Say there's two 2D arrays, <code>a</code> and <code>b</code></p> <pre><code>import numpy as np a = np.random.rand(3, 4) b = np.random.zeros(8, 8) </code></pre> <p>and <code>b</code> is always larger than <code>a</code> over both axes.</p> <p><em>(Edit: <code>b</code> is initialized as an array of zeros, to reflec...
0
2016-09-19T06:15:28Z
39,568,653
<p>More generally you can determine the position where you want to insert the array if you create a tuple of slices (this works for arbitary dimensions):</p> <pre><code>&gt;&gt;&gt; a = np.random.random((5,5)) &gt;&gt;&gt; b = np.ones((3,3)) &gt;&gt;&gt; edge_coordinate = (0,0) &gt;&gt;&gt; slicer = tuple(slice(edge,...
2
2016-09-19T08:32:44Z
[ "python", "numpy" ]
Fastest way to insert a 2D array into a (larger) 2D array
39,566,474
<p>Say there's two 2D arrays, <code>a</code> and <code>b</code></p> <pre><code>import numpy as np a = np.random.rand(3, 4) b = np.random.zeros(8, 8) </code></pre> <p>and <code>b</code> is always larger than <code>a</code> over both axes.</p> <p><em>(Edit: <code>b</code> is initialized as an array of zeros, to reflec...
0
2016-09-19T06:15:28Z
39,583,342
<p>I think the best way is to use padding.</p> <p>if you want to place a in the top left corner:</p> <pre><code>np.pad(a,((0,5),(0,4)),'constant') </code></pre> <p>if you want to place a in centre:</p> <pre><code>np.pad(a,((2,3),(2,2)),'constant') </code></pre>
0
2016-09-19T23:02:36Z
[ "python", "numpy" ]
find the index of values that satisfy A + B =C + D
39,566,527
<p>Working on below problem, using Python 2.7. Post my code and wondering if any further smart ideas to make it run faster? I thought there might be some ideas which sort the list first, and leveraging sorting behavior, but cannot figure out so far. My code is <code>O(n^2)</code> time complexity.</p> <p><strong>Proble...
1
2016-09-19T06:19:19Z
39,566,702
<p>Consider the case where all the elements of the array are equal. Then we know the answer beforehand but merely printing the result will take <code>O(n^2)</code> time since there are <code>n*(n-1)/2</code> number of such pairs. So I think it is safe to say that there is no approach with a better complexity than <code...
2
2016-09-19T06:32:47Z
[ "python", "algorithm", "python-2.7" ]
find the index of values that satisfy A + B =C + D
39,566,527
<p>Working on below problem, using Python 2.7. Post my code and wondering if any further smart ideas to make it run faster? I thought there might be some ideas which sort the list first, and leveraging sorting behavior, but cannot figure out so far. My code is <code>O(n^2)</code> time complexity.</p> <p><strong>Proble...
1
2016-09-19T06:19:19Z
39,567,138
<p>Yes it can be done in a way with complexity less than O(n^2). The algo is:</p> <ol> <li>Create a duplicate array suppose indexArr[] storing the index of the element of the original array say origArr[].</li> <li>Sort the origArr[] in ascending order using some algo having complexity O(nLogn). Likewise also shuffle t...
1
2016-09-19T07:01:35Z
[ "python", "algorithm", "python-2.7" ]
find the index of values that satisfy A + B =C + D
39,566,527
<p>Working on below problem, using Python 2.7. Post my code and wondering if any further smart ideas to make it run faster? I thought there might be some ideas which sort the list first, and leveraging sorting behavior, but cannot figure out so far. My code is <code>O(n^2)</code> time complexity.</p> <p><strong>Proble...
1
2016-09-19T06:19:19Z
39,570,006
<p>faster, more Pythonic approach using <code>itertools.combinations:</code></p> <pre><code>from collections import defaultdict from itertools import combinations def get_combos(l): d = defaultdict(list) for indices in combinations(range(len(l)),2): d[(l[indices[0]] + l[indices[1]])].append(indices) ...
1
2016-09-19T09:43:46Z
[ "python", "algorithm", "python-2.7" ]
.pyc file gets created when it is not even imported
39,566,724
<p>I have 2 Python files called <code>numbers.py</code> and <code>numpyBasicOps.py</code>. <code>numbers.py</code> is a simple Python file, not importing any module. <code>numpyBasicOps.py</code> imports the <code>numpy</code> library.</p> <p>Whenever I run <code>numpyBasicOps.py</code>, <code>numbers.py</code>'s out...
2
2016-09-19T06:33:44Z
39,566,871
<p><code>numpy</code> registers their own integer-like objects as implementing the Abstract Base Class <a href="https://docs.python.org/2/library/numbers.html#numbers.Integral" rel="nofollow"><code>numbers.Integral</code></a>. To do this, it must use <code>import numbers</code> to get access to that object.</p> <p>Or ...
1
2016-09-19T06:43:29Z
[ "python", "python-2.7", "numpy" ]
Install npm packages in Python virtualenv
39,566,769
<p>There are some npm packages which I would like to install in a Python virtualenv. For example: </p> <ul> <li><a href="https://www.npmjs.com/package/pdfjs-dist" rel="nofollow">https://www.npmjs.com/package/pdfjs-dist</a></li> <li><a href="https://www.npmjs.com/package/jquery-ui" rel="nofollow">https://www.npmjs.com/...
0
2016-09-19T06:36:59Z
39,567,927
<p>NPM and pip have nothing to do with each other, so you won't be able to install NPM packages inside a virtualenv.</p> <p>However: <a href="https://docs.npmjs.com/files/folders" rel="nofollow">NPM installs packages in <code>./node_modules</code></a>.</p> <p>So if you created a virtualenv and installed npm modules i...
2
2016-09-19T07:49:11Z
[ "python", "npm", "installation", "pip" ]
Using two environment in Anaconda - issue with importing matplotlib
39,566,777
<p>I am using two environments in Anaconda (Mac OS X). When I use Python 2.7 environment I can't import matplotlib: </p> <pre><code>%matplotlib inline import numpy as np import matplotlib.pyplot as plt </code></pre> <p>It tells me that there is no module name like that. </p> <p>I installed matplotlib using <code>pip...
0
2016-09-19T06:37:29Z
39,567,018
<p>You have to make sure matplotlib is installed in the env you've activated. If you need to use it in both envs, you need to install matplotlib into both envs. </p>
0
2016-09-19T06:53:24Z
[ "python", "matplotlib" ]
Writing Dask partitions into single file
39,566,809
<p>New to <code>dask</code>,I have a <code>1GB</code> CSV file when I read it in <code>dask</code> dataframe it creates around 50 partitions after my changes in the file when I write, it creates as many files as partitions.<br> <strong>Is there a way to write all partitions to single CSV file and is there a way access ...
2
2016-09-19T06:39:10Z
39,573,112
<h3>Short answer</h3> <p>No, Dask.dataframe.to_csv only writes CSV files to different files, one file per partition. However, there are ways around this.</p> <h3>Concatenate Afterwards</h3> <p>Perhaps just concatenate the files after dask.dataframe writes them? This is likely to be near-optimal in terms of perform...
2
2016-09-19T12:24:15Z
[ "python", "dask" ]
Python script not deleting Git files in Windows
39,566,812
<p>I'm using the following code to delete a directory containing a git repo:</p> <pre><code>import errno import os import stat import shutil def clear_dir(path): shutil.rmtree(path, ignore_errors=False, onerror=handle_remove_readonly) def handle_remove_readonly(func, path, exc): excvalue = exc[1] if func i...
1
2016-09-19T06:39:23Z
39,566,888
<p>If that file is being used by another process then it would not be possible to delete it. cross check it by using 'unlocker' OR any other similar software.</p>
1
2016-09-19T06:44:30Z
[ "python", "windows", "git", "delete-file" ]
How can I hide an id sequence and provide a "friendly" url using pyramid?
39,566,919
<p>I have a list of things in a database and would like to hide the sequence of the primary key from being shown in the url when being accessed. So I would like to turn something like this:</p> <pre><code>example.com/post/9854 </code></pre> <p>into this:</p> <pre><code>example.com/post/one-two-three-four </code></pr...
1
2016-09-19T06:47:07Z
39,582,862
<p>This "user friendly URL fragment" is usually called a "slug", which I think comes from the times when newspapers were typeset in lead.</p> <p>What you usually do is have an additional field in your model which stores the slug. The field should be unique and indexed (you may even consider having it as your model's p...
1
2016-09-19T22:09:43Z
[ "python", "url", "url-rewriting", "url-routing", "pyramid" ]
convert translation output into a string
39,566,935
<p>The translated output text that I get using Google Translate API seems only to be made available in a browser and in html format. How can I get output as a string that can be analyzed using Python, for example. </p> <h2>I would also like to understand how larger blocks of text can be translated in this way. Examp...
1
2016-09-19T06:48:12Z
39,646,771
<p>This is just the way the browser displays what the API has sent you, it's the browser's kind interpretation of it, not how it actually looks. It's json. You need to use the Python json module I expect, although I haven't attempted to use the API myself.</p>
0
2016-09-22T18:49:23Z
[ "python", "api", "text", "translate" ]
Mapping data from other dataset. Python Pandas
39,566,992
<p>So i got 2 datasets, <code>df1</code> has the colour for all fruits and <code>df2</code> don't. How do I map the color values for <code>df2</code> based on the color data from <code>d1</code>, according to the fruit names? </p> <pre><code> df1 df2 Name Co...
1
2016-09-19T06:51:48Z
39,567,024
<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow"><code>map</code></a>, but first need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.drop_duplicates.html" rel="nofollow"><code>Series.drop_duplicates</code></a>:</p>...
1
2016-09-19T06:54:05Z
[ "python", "pandas", "merge", "mapping", "multiple-columns" ]
Mapping data from other dataset. Python Pandas
39,566,992
<p>So i got 2 datasets, <code>df1</code> has the colour for all fruits and <code>df2</code> don't. How do I map the color values for <code>df2</code> based on the color data from <code>d1</code>, according to the fruit names? </p> <pre><code> df1 df2 Name Co...
1
2016-09-19T06:51:48Z
39,567,063
<p>You can do this with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html" rel="nofollow">merge</a>:</p> <pre><code>df2 = df2.merge(df1, on="Name", how="left", suffixes=('_1','_2')) </code></pre> <p>if name is your index column you can just do a <a href="http://pandas.pydata.o...
1
2016-09-19T06:56:49Z
[ "python", "pandas", "merge", "mapping", "multiple-columns" ]
display items in a database in a webpage and edit
39,567,072
<p>I am getting the below error when I tried to run the edit part.</p> <p>Displaying the contents of database in webpage is working fine. I have put up code for just the edit part.</p> <blockquote> <p>TypeError at /edit/ <br/> <code>__init__()</code> takes exactly 1 argument (2 given)</p> </blockquote> <p>views....
0
2016-09-19T06:57:30Z
39,567,902
<p>Class-based views need to be referenced in urls.py via their <code>as_view</code> method:</p> <pre><code>url(r'^edit/', views.userUpdate.as_view(), name = 'user_update_form'), </code></pre>
1
2016-09-19T07:47:41Z
[ "python", "django" ]
using mkdir and touch sub-processes sequentially doesn't work
39,567,154
<p>I have an error that I keep encountering repeatedly, sadly without being able to find solution to at the site.</p> <pre><code>try: #create working dir if it doens't exist already if not os.path.isdir(WORKINGDIR): print '&gt;&gt;&gt;mdkir ',WORKINGDIR subprocess.Popen(['mkdir',WORKINGDIR]).wa...
1
2016-09-19T07:02:36Z
39,567,672
<p>I suppose you have file permission problems. In your path it appears that you are using NFS. Did you already try it on the local file system?</p> <p>Anyway, you should avoid to use sub processes for simple file operations. </p> <p>To create a directory:</p> <pre><code>if not os.path.exists(WORKINGDIR): os.ma...
0
2016-09-19T07:34:05Z
[ "python", "python-2.7", "unix" ]
Buttons overlap each other
39,567,158
<p>I have the following code:</p> <pre><code> self.btn1 = wx.Button(self, -1, _("a")) self.btn2 = wx.Button(self, -1, _("b")) btnSizer = wx.BoxSizer(wx.HORIZONTAL) btnSizer.Add(self.btn1 , 0, wx.RIGHT, 10) btnSizer.Add(self.btn2 , 0, wx.RIGHT, 10) </code></pre> <p>This works well. However there is ...
0
2016-09-19T07:02:49Z
39,569,732
<p>You can use <code>self.Layout()</code> but in this case it really shouldn't be necessary. There must be some issue that you are having with your code.</p> <pre><code>import wx class ButtonFrame(wx.Frame): def __init__(self, value): wx.Frame.__init__(self,None) self.btn1 = wx.Button(self, -1, ("...
1
2016-09-19T09:29:50Z
[ "python", "wxpython" ]
iterate through nltk dictionaries
39,567,162
<p>I'd like to know whether it's possible to iterate through some of the available nltk dictionaries, ie: Spanish dictionary. I'd like to find certain words matching some requirements.</p> <p>Let's say I got this list <code>["tv", "tb", "tp", "dv", "db", "dp"]</code>, the algorithm would give me words like <code>["tap...
0
2016-09-19T07:02:59Z
39,569,950
<p>The nltk has plenty of Spanish language resources, but I'm not aware of a dictionary. So I'll leave the choice of wordlist up to you, and go on from there.</p> <p>In general, the nltk represents wordlists as corpus readers with the usual method <code>words()</code> for the individual words. So here's how you could ...
1
2016-09-19T09:40:32Z
[ "python", "nltk" ]
re.findall() returns extra data when using optionals in between Regex expressions
39,567,168
<p>I seem to be getting additional variables that I do not want stored into this array. What I expected to return after running the following code is this </p> <pre><code>[('999-999-9999'), ('999 999 9999'), ('999.999.9999')] </code></pre> <p>However what I end up with is the following</p> <pre><code>[('999-999-9999...
0
2016-09-19T07:03:11Z
39,567,200
<p>Turn the inner capturing groups to non-capturing groups.</p> <pre><code>(?:-|\s|\.) </code></pre> <p>or</p> <pre><code>[-\s.] </code></pre> <p>Example:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; teststr = ''' Phone: 999-999-9999, 999 999 9999, 999.999.9999 ''' &gt;&gt;&gt; re.f...
3
2016-09-19T07:05:20Z
[ "python" ]
Export an excel file using a variable name in Python
39,567,236
<p>I am new to python, trying to figure out dynamic naming of exported files. Right now, I am exporting an xlsx file in a traditional way:</p> <p>data_subset.to_csv('Destination/existing_process.csv')</p> <p>I have a string called 'user_name' and the resultant tuple for every user is exported into an excel file calle...
-5
2016-09-19T07:07:13Z
39,567,343
<p>You can use <code>string concatenation</code> for that.</p> <pre><code>name = 'Matt' with open(name + '.txt', 'w') as f: f.write('test') </code></pre> <p>The same you can use with <code>xlsx</code> but you will you using it slightly different, but the concatenation process is same. Kindly let me know if you wa...
1
2016-09-19T07:13:19Z
[ "python", "python-2.7", "python-3.x" ]
Check if variable is None or numpy.array
39,567,422
<p>I look up in a table if keys have associated arrays, or not. By design, my <code>table.__getitem__()</code> somtimes returns <code>None</code> rather than <code>KeyError</code>-s. I would like this value to be either <code>None</code>, or the numpy array associated with <code>w</code>.</p> <pre><code>value = table...
0
2016-09-19T07:18:26Z
39,567,645
<p>Use <a href="https://docs.python.org/3.5/library/stdtypes.html#dict.get" rel="nofollow"><code>dict.get</code></a>.</p> <blockquote> <p>Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to None, so that this method never raises a KeyError.</p> </blockquote> <...
1
2016-09-19T07:32:30Z
[ "python", "numpy" ]
Check if variable is None or numpy.array
39,567,422
<p>I look up in a table if keys have associated arrays, or not. By design, my <code>table.__getitem__()</code> somtimes returns <code>None</code> rather than <code>KeyError</code>-s. I would like this value to be either <code>None</code>, or the numpy array associated with <code>w</code>.</p> <pre><code>value = table...
0
2016-09-19T07:18:26Z
39,567,684
<pre><code>if type(value) is numpy.ndarray: #do numpy things else # Handle None </code></pre> <p>Though the above would work, I would suggest to keep signatures simple and consistent, ie table[w] should always return numpy array. In case of None, return empty array. </p>
0
2016-09-19T07:34:44Z
[ "python", "numpy" ]
Check if variable is None or numpy.array
39,567,422
<p>I look up in a table if keys have associated arrays, or not. By design, my <code>table.__getitem__()</code> somtimes returns <code>None</code> rather than <code>KeyError</code>-s. I would like this value to be either <code>None</code>, or the numpy array associated with <code>w</code>.</p> <pre><code>value = table...
0
2016-09-19T07:18:26Z
39,567,970
<p>IIUC this should work:</p> <pre><code>value = table[w] if value is None: value = table[w.lower()] </code></pre>
2
2016-09-19T07:52:10Z
[ "python", "numpy" ]
python UI app hangs while updating stdout output to UI using subprocess.Popen in a for loop
39,567,467
<p>I'm running subprocess.Popen() to call a commandline tool which prints it's output to console like so:</p> <pre><code>[app] : Initializing... [app] : Starting process [app] : ............. [app] : ............. [app] : Extracting information [app] : Downloading information [app] : 100% completed [app]...
0
2016-09-19T07:21:17Z
39,643,978
<p>Run the worker process in a separate thread and send the data back to the gui using a custom signal. Here's a very basic demo script:</p> <pre><code>import sys from PyQt4 import QtCore, QtGui class Thread(QtCore.QThread): dataReceived = QtCore.pyqtSignal(str) def run(self): # subprocess stuff goes...
1
2016-09-22T16:10:32Z
[ "python", "loops", "subprocess", "pyqt4", "hang" ]
Pandas operations on selected columns
39,567,528
<p>I want to standardize certain columns in my pandas dataframe.</p> <pre><code>dfTest = pd.DataFrame({ 'A':[14.00,90.20,90.95,96.27,91.21], 'B':[103.02,107.26,110.35,114.23,114.68], 'C':['big','small','big','small','small'] }) </code></pre> <p>This does not work as only a ...
0
2016-09-19T07:25:27Z
39,568,157
<p>You could concatenate the scaled columns to the original <code>DF</code> as shown:</p> <pre><code>scaler = StandardScaler() scaled_data = pd.DataFrame(data=scaler.fit_transform(dfTest[['A', 'B']]), columns=['A_scaled', 'B_scaled']) pd.concat([dfTest, scaled_data], axis=1) </code></pre> ...
1
2016-09-19T08:03:12Z
[ "python", "pandas", "scikit-learn" ]
File as input in python netaddr
39,567,577
<p>Im trying to supernet list of IP networks using netaddr in python.</p> <p><strong>Code:</strong></p> <pre><code>import netaddr from netaddr import * iplist = [IPNetwork('10.105.205.8/29'),IPNetwork('10.105.205.16/28'),IPNetwork('10.105.205.0/29')] print '%s' % netaddr.cidr_merge(iplist) </code></pre> <p>**Output:...
0
2016-09-19T07:28:20Z
39,567,697
<p>I am not familiar with the netaddr module but to me it seems you are just building a list from inputs. If you have an input file with a network in each line, would this work:</p> <pre><code>with open ("inputfile", "r") as fp: iplist = [IPNetwork(q) for q in fp.read().splitlines()] </code></pre> <p>Hannu</p>
0
2016-09-19T07:35:13Z
[ "python", "linux", "bash", "ip" ]
Node.js to Python communication - server or child process?
39,567,607
<p>I am currently at a project that is mainly written in Node.js, which involves non-linear curve fitting. After trying to do this task with Node.js itself, I gave up on it, because it is simply impractical. So I was looking for a high level language for solving mathmatical problems like that one I am facing. I had to ...
2
2016-09-19T07:30:27Z
39,568,675
<p>There are pros and cons of both approaches.</p> <h2>Separate server</h2> <p>Setting up a server is more time consuming, you need to make sure that the Python server is started before the Node app needs to talk with it, you have to restart it if it stops etc.</p> <p>On the other hand you have a nicely separated se...
2
2016-09-19T08:33:44Z
[ "python", "node.js", "client-server", "ipc" ]
Add streaming step to MR job in boto3 running on AWS EMR 5.0
39,567,608
<p>I'm trying to migrate a couple of MR jobs that I have written in python from AWS EMR 2.4 to AWS EMR 5.0. Till now I was using boto 2.4, but it doesn't support EMR 5.0, so I'm trying to shift to boto3. Earlier, while using boto 2.4, I used the <code>StreamingStep</code> module to specify input location and output loc...
7
2016-09-19T07:30:31Z
39,763,973
<p>It's unfortunate that boto3 and EMR API are rather poorly documented. Minimally, the word counting example would look as follows:</p> <pre><code>import boto3 emr = boto3.client('emr') resp = emr.run_job_flow( Name='myjob', ReleaseLabel='emr-5.0.0', Instances={ 'InstanceGroups': [ {...
2
2016-09-29T07:26:17Z
[ "python", "amazon-web-services", "emr", "boto3" ]
Python - text file with all values 0 to 2^24 in HEX
39,567,700
<p>I am trying to create a file with all possible values for 0 up to 2^24 in HEX.</p> <p>This is what I have so far:</p> <pre><code>file_name = "values.txt" counter = 0 value = 0x0000000000 with open (file_name, 'w') as writer: while counter &lt; 16777216: data_to_write = str(value) + '\n' writer...
-2
2016-09-19T07:35:18Z
39,567,805
<p>just use the format method from string when writting:</p> <pre><code>writer.write("{:#X}".format(data_to_write)) </code></pre> <p>Example:</p> <pre><code>&gt;&gt;&gt; "{:#x}".format(123324) '0x1e1bc' &gt;&gt;&gt; "{:#X}".format(123324) '0X1E1BC' </code></pre>
0
2016-09-19T07:41:37Z
[ "python" ]
Python - text file with all values 0 to 2^24 in HEX
39,567,700
<p>I am trying to create a file with all possible values for 0 up to 2^24 in HEX.</p> <p>This is what I have so far:</p> <pre><code>file_name = "values.txt" counter = 0 value = 0x0000000000 with open (file_name, 'w') as writer: while counter &lt; 16777216: data_to_write = str(value) + '\n' writer...
-2
2016-09-19T07:35:18Z
39,568,050
<p>Thank you for your help.</p> <p>It is working now:</p> <pre><code>file_name = "value.txt" counter = 0 value = 0x0000000000 with open (file_name, 'w') as writer: while counter &lt; 10000: data_to_write = str(hex(value)[2:].zfill(6)) + '\n' writer.write(data_to_write) counter = counter +...
0
2016-09-19T07:56:38Z
[ "python" ]
Python Pandas - how is 25 percentile calculated by describe function
39,567,712
<p>For a given dataset in a data frame, when I apply the <code>describe</code> function, I get the basic stats which include min, max, 25%, 50% etc.</p> <p>For example:</p> <pre><code>data_1 = pd.DataFrame({'One':[4,6,8,10]},columns=['One']) data_1.describe() </code></pre> <p>The output is:</p> <pre><code> O...
2
2016-09-19T07:36:23Z
39,568,222
<p>In the <a href="https://github.com/pydata/pandas/blob/master/pandas/core/series.py">pandas documentation</a> there is information about hte computation of quantiles, where a reference to numpy.percentile is made: </p> <blockquote> <p>Return value at the given quantile, a la numpy.percentile.</p> </blockquote> <p...
5
2016-09-19T08:07:16Z
[ "python", "pandas", "percentile" ]
sympy: how to evaluate integral of absolute value
39,568,077
<p>When I try to simplify the following integral in <code>sympy</code>, it will not evaluate, i.e. the output is $\int_{-1}^1 |z| dz$ while the output I expect is 1.</p> <pre><code>z = symbols('z', real=True) a = integrate(abs(z), (z, -1, 1)) simplify(a) </code></pre> <p>Similar integral without the absolute value on...
2
2016-09-19T07:57:56Z
39,568,244
<p>I believe you should use Sympy's built in <a href="http://docs.sympy.org/0.7.0/modules/functions.html" rel="nofollow">Abs()</a> function.</p> <p>Enjoy!</p>
-3
2016-09-19T08:09:02Z
[ "python", "sympy", "integral", "absolute-value" ]
sympy: how to evaluate integral of absolute value
39,568,077
<p>When I try to simplify the following integral in <code>sympy</code>, it will not evaluate, i.e. the output is $\int_{-1}^1 |z| dz$ while the output I expect is 1.</p> <pre><code>z = symbols('z', real=True) a = integrate(abs(z), (z, -1, 1)) simplify(a) </code></pre> <p>Similar integral without the absolute value on...
2
2016-09-19T07:57:56Z
39,622,177
<p><code>integrate</code> already does all it can to evaluate an integral. If you get an <code>Integral</code> object back, that means it couldn't evaluate it. The only thing that might help is rewriting the integrand in a way that SymPy can recognize. </p> <p>Looking at <a href="https://github.com/sympy/sympy/issues/...
2
2016-09-21T16:44:17Z
[ "python", "sympy", "integral", "absolute-value" ]
Error when trying to install PyCrypto
39,568,110
<p>I'm using Mac with latest OS X update. I've trying to install PyCrypto over Terminal but I'm getting error which is shown on image below. The command I used is <code>sudo pip install pycrypto</code>. Can you please help me with this issue? How do I resolve this? Thanks for your answers.</p> <p><a href="http://i.sta...
1
2016-09-19T08:00:00Z
39,571,648
<p>You need to install the Python development files. I think it will work. Try </p> <pre><code>apt-get install autoconf g++ python2.7-dev </code></pre> <p>Or</p> <pre><code>sudo apt-get install python-dev </code></pre> <p>Either one of the above and then this below one </p> <pre><code>pip install pycrypto </code>...
0
2016-09-19T11:04:29Z
[ "python", "pip", "pycrypto" ]
Scraping a specific table in selenium
39,568,186
<p>I am trying to scrape a table found inside a div on a page. </p> <p>Basically here's my attempt so far:</p> <pre><code># NOTE: Download the chromedriver driver # Then move exe file on C:\Python27\Scripts from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.b...
0
2016-09-19T08:05:06Z
39,570,311
<p>you can use Xpath As Follow:</p> <pre><code>//div[@class="line-chart"]/div/div[1]/div/div/table/tbody/tr </code></pre> <p>Here I will Refine my answer and make some changes in your code not it's work.</p> <pre><code># NOTE: Download the chromedriver driver # Then move exe file on C:\Python27\Scripts from selenium...
0
2016-09-19T09:57:48Z
[ "python", "selenium", "xpath", "web-scraping" ]
How can I print a string depending on the list value?
39,568,197
<p>I want to print a string depending on the values in the list. Values can be 0 or 1. For example:</p> <pre><code># Example [a,b,c] = [0,0,1] -- &gt; print str c # [1,0,1] -- print str a and str c index_list = [0,0,1] # Example str_a = "str_a" str_b = "str_b" str_c = "str_c" print str </code></pre>
0
2016-09-19T08:05:41Z
39,568,262
<pre><code>for condition, string in zip(index_list, [str_a, str_b, str_c]): if condition: print string </code></pre> <p>Since the question is tagged as <a href="/questions/tagged/python-2.7" class="post-tag" title="show questions tagged &#39;python-2.7&#39;" rel="tag">python-2.7</a>, <a href="https://docs....
4
2016-09-19T08:10:17Z
[ "python", "python-2.7" ]
How can I print a string depending on the list value?
39,568,197
<p>I want to print a string depending on the values in the list. Values can be 0 or 1. For example:</p> <pre><code># Example [a,b,c] = [0,0,1] -- &gt; print str c # [1,0,1] -- print str a and str c index_list = [0,0,1] # Example str_a = "str_a" str_b = "str_b" str_c = "str_c" print str </code></pre>
0
2016-09-19T08:05:41Z
39,568,324
<pre><code>&gt;&gt;&gt; a = [str_a,str_b,str_c] &gt;&gt;&gt; b= [0,0,1] &gt;&gt;&gt; ','.join(i for i,j in zip(a,b) if j) 'str_c' </code></pre>
2
2016-09-19T08:14:30Z
[ "python", "python-2.7" ]
How can I print a string depending on the list value?
39,568,197
<p>I want to print a string depending on the values in the list. Values can be 0 or 1. For example:</p> <pre><code># Example [a,b,c] = [0,0,1] -- &gt; print str c # [1,0,1] -- print str a and str c index_list = [0,0,1] # Example str_a = "str_a" str_b = "str_b" str_c = "str_c" print str </code></pre>
0
2016-09-19T08:05:41Z
39,568,508
<p>Here's an elegant way. Use the compress function in itertools:</p> <pre><code>import itertools as it l1 = [1, 0, 1] l2 = ["a", "b", "c"] for item in it.compress(l2, l1): print item </code></pre> <p>Output:</p> <pre><code>=================== RESTART: C:/Users/Joe/Desktop/stack.py =================== a c &gt;&g...
7
2016-09-19T08:24:34Z
[ "python", "python-2.7" ]
read_sql and redshift giving error on unicode
39,568,229
<p>Query 1: Using pandas read_sql to read from MySQL. The resulting dataframe has a column whose datatype is unicode strings. This column is converted to a tuple and used in the following query.</p> <p>Query 2: Using pandas read_sql to read from Redshift. The query is something like </p> <pre><code>select b.a from b ...
0
2016-09-19T08:07:48Z
39,568,585
<p>I suspect that that error message is being generated by someone replacing a marker (I've used <code>{something}</code>) a template like</p> <pre><code>'syntax error at or near "{something}"' </code></pre> <p>This means you should instead see it as a complaint about a single string whose value would appear to be</p...
0
2016-09-19T08:28:47Z
[ "python", "mysql", "pandas", "unicode", "amazon-redshift" ]
Python > Connection with JDBC to Oracle service name (jaydebeapi)
39,568,378
<p>This sample code is used to connect in Python to Oracle SID. </p> <pre><code>import jpype import jaydebeapi jHome = jpype.getDefaultJVMPath() jpype.startJVM(jHome, '-Djava.class.path=/path/to/ojdbc6.jar') conn = jaydebeapi.connect('oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:user/password@DB_HOST_IP:1521:DB_...
1
2016-09-19T08:18:32Z
39,569,187
<p>Regarding your connection string, you could use <code>TNS</code> syntax (<a href="https://docs.oracle.com/cd/B28359_01/java.111/b31224/jdbcthin.htm" rel="nofollow">read on, here</a>), as opposed to <code>host:port:sid</code> syntax you're using now. In that case you would describe <code>SERVICE_NAME</code> inside ...
0
2016-09-19T09:00:38Z
[ "java", "python", "oracle", "jdbc", "jaydebeapi" ]
Python > Connection with JDBC to Oracle service name (jaydebeapi)
39,568,378
<p>This sample code is used to connect in Python to Oracle SID. </p> <pre><code>import jpype import jaydebeapi jHome = jpype.getDefaultJVMPath() jpype.startJVM(jHome, '-Djava.class.path=/path/to/ojdbc6.jar') conn = jaydebeapi.connect('oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:user/password@DB_HOST_IP:1521:DB_...
1
2016-09-19T08:18:32Z
39,633,617
<p>This way should work</p> <pre><code> conn = jaydebeapi.connect('oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:user/password@//DB_HOST_IP:1521/DB_NAME') </code></pre>
0
2016-09-22T08:10:35Z
[ "java", "python", "oracle", "jdbc", "jaydebeapi" ]
web.py select returning no results, but length of that list does (also manual query in sql promt returns results)
39,568,499
<p>I am working on my first (bigger) python application but I am running into some issues. I am trying to select entries from a table using the web.py import (I am using this since I will be using a web front-end later).</p> <p>Below is my (simplified) code:</p> <pre><code>db = web.database(dbn='mysql', host='xxx', p...
0
2016-09-19T08:24:21Z
39,575,441
<p>Thanks to the people over at reddit I was able to solve the issue: <a href="https://www.reddit.com/r/learnpython/comments/53hdq1/webpy_select_returning_no_results_but_length_of/" rel="nofollow">https://www.reddit.com/r/learnpython/comments/53hdq1/webpy_select_returning_no_results_but_length_of/</a></p> <p>Bottom li...
0
2016-09-19T14:18:15Z
[ "python", "mysql", "database", "select", "web.py" ]
Get GUI element value from QThread
39,568,543
<p>How can a QThread get text from a QLineEdit?</p> <p>i tried <code>self.t.updateSignal.connect(self.inputedittext.text)</code> to get the QLineEdit value, but I get an error:</p> <blockquote> <p>TypeError: unsupported operand type(s) for +=: PyQt4.QtCore.pyqtBoundSignal' and 'int'</p> </blockquote> <p>or I get...
1
2016-09-19T08:26:33Z
39,573,444
<p>Use signals to communicate from thread to gui, and from gui to thread:</p> <pre><code>class mc(QtGui.QWidget): ... def initUI(self): ... self.t = test_QThread() self.t.progressSignal.connect(self.setlable) self.t.requestSignal.connect(self.sendText) self.startbutto...
0
2016-09-19T12:39:58Z
[ "python", "pyqt4", "signals-slots", "qthread" ]
accessing MySQL database in XAMPP through flask framework
39,568,579
<p>I just started looking into Flask framework for a pet project of mine, and so, I have been working on a tutorial in envato tutsplus. I build the database in MySQL present in the XAMPP server and I am trying to access it, but I do not know how to go about doing it.</p> <p>I get this error in the chrome console <code...
0
2016-09-19T08:28:39Z
39,568,905
<p>MYSQL_DATABASE_HOST should be the address of your <em>database host</em>, hence the name, not your web app. </p> <p>Looking at <a href="http://flask-mysql.readthedocs.io/en/latest/" rel="nofollow">the docs</a>, the default is "localhost" and the matching port setting is 3306, which should be fine for your setup; yo...
0
2016-09-19T08:46:09Z
[ "python", "mysql", "xampp" ]
Timer issue in Python/Pygame game
39,568,593
<p>I am relatively new to Python. I have been modifying this game code and included a start screen etc. The problem I'm having is that when the game ends I am trying to have it start again when a user inputs y at 12. I have got the key press down but there seems to be an issue with the timer. In 6.4 it is using get.tic...
-1
2016-09-19T08:29:25Z
39,569,002
<p>I can unfortunately not test my suggestion, but the logic here will help. If there is somewhere to download the code it would help - there are resources missing that prevent me from running the code.</p> <p>Your #12 isn't restarting the game because it's taking place inside the <code>rungame()</code> def. Try mov...
0
2016-09-19T08:51:01Z
[ "python" ]
exposing multiple databases in django admin
39,568,636
<p>My use case requires me to expose multiple databases in the admin site of my django project. Did that following this link: <a href="https://docs.djangoproject.com/en/dev/topics/db/multi-db/#exposing-multiple-databases-in-django-s-admin-interface" rel="nofollow">https://docs.djangoproject.com/en/dev/topics/db/multi-d...
0
2016-09-19T08:31:48Z
39,568,753
<p>You need to add a url pattern for your admin site, similar to how you enable the regular site:</p> <pre><code># urls.py from django.conf.urls import url from django.contrib import admin from myapp.admin import othersite urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^otheradmin/', othersite.urls),...
0
2016-09-19T08:37:25Z
[ "python", "django", "django-admin" ]
Regex to return set of words from file that can be spelled with letters passed as parameter (python)
39,568,651
<p>I have a list of words such as </p> <pre><code>name age abhor apple ape </code></pre> <p>I want to do regex on a list by passing a random set of letters such as 'apbecd'</p> <p>Now all those words from the list having the set of letters must be returned.</p> <p>eg: <code>python retun_words.py apbelcdg</code></p...
0
2016-09-19T08:32:37Z
39,568,887
<p>There's no need to use regex. Following code works.</p> <pre><code>import sys word_list = ['name', 'age', 'abhor', 'apple', 'ape'] letter_list = sys.argv[1] for word in word_list: for letter in word: if letter not in letter_list: break elif letter == word[-1]: print word...
0
2016-09-19T08:45:09Z
[ "python", "regex" ]
Regex to return set of words from file that can be spelled with letters passed as parameter (python)
39,568,651
<p>I have a list of words such as </p> <pre><code>name age abhor apple ape </code></pre> <p>I want to do regex on a list by passing a random set of letters such as 'apbecd'</p> <p>Now all those words from the list having the set of letters must be returned.</p> <p>eg: <code>python retun_words.py apbelcdg</code></p...
0
2016-09-19T08:32:37Z
39,568,991
<p>Here, using set and returning the item is also a way, if you do not want to use regex.</p> <pre><code>string_list = ["name", "age", "abhor", "apple", "ape"] allowed_characters = "apbelcdg" character_set = set(allowed_charcters) print [item for item in string_list if not set(item)-character_set] </code></pre> <p>Th...
1
2016-09-19T08:50:49Z
[ "python", "regex" ]
Regex to return set of words from file that can be spelled with letters passed as parameter (python)
39,568,651
<p>I have a list of words such as </p> <pre><code>name age abhor apple ape </code></pre> <p>I want to do regex on a list by passing a random set of letters such as 'apbecd'</p> <p>Now all those words from the list having the set of letters must be returned.</p> <p>eg: <code>python retun_words.py apbelcdg</code></p...
0
2016-09-19T08:32:37Z
39,570,992
<p>I believe shellmode's method needs a minor fix, since it would not work for cases when the examined letter is the same as the last letter in the word, but the word itself contains letters that are not from the letter list. I believe that this code would work:</p> <pre><code>import sys word_list = ['name', 'age', 'a...
0
2016-09-19T10:30:57Z
[ "python", "regex" ]
Crawl a large number of web pages
39,568,727
<p>I want to use Scrappy to crawl a large selection of web pages. Because I have to use proxy, and the proxy is bad, lots of time is wasted on changing IPs. How can I use multi-threading to speed this along?</p> <p>(Ps: I use a HttpProxyMiddleware.py to get proxyIP from a redis database.</p> <pre><code> proxy_conf...
0
2016-09-19T08:36:06Z
39,569,060
<p>Use lots of proxies.</p> <p>For instance for a similar project, I've installed tor.</p> <p>You can run multiple instances of tor, thus having multiple dedicated proxies available.</p> <p>Run an instance on 127.0.0.1:9050, another on 127.0.0.1:9051, and so on and so forth.</p> <p>Script the launch of all these in...
0
2016-09-19T08:53:55Z
[ "python", "scrapy" ]
Load extracted vectors to TfidfVectorizer
39,568,774
<p>I am looking for a way to load vectors I generated previously using scikit-learn's TfidfVectorizer. In general what I wish is to get a better understanding of the TfidfVectorizer's data persistence.</p> <p>For instance, what I did so far is:</p> <pre><code>vectorizer = TfidfVectorizer(stop_words=stop) vect_train =...
0
2016-09-19T08:38:51Z
39,620,729
<p>The result of your <code>vect_train = vectorizer.fit_transform(corpus)</code> is twofold: (i) the vectorizer fits your data, that is it learns the corpus vocabulary and the idf for each term, and (ii) <code>vect_train</code> is instantiated with the vectors of your corpus.</p> <p>The <code>save_model</code> and <co...
0
2016-09-21T15:27:08Z
[ "python", "machine-learning", "scikit-learn", "persistence", "tf-idf" ]
Python: read files from directory and concatenate that
39,568,925
<p>I have a folder <code>et</code> with <code>.csv</code> files and I try to read that and next concatenate that and get one file. I try </p> <pre><code>import os path = 'et/' for filename in os.listdir(path): et = open(filename) print et </code></pre> <p>but I get an error </p> <pre><code>Traceback (most r...
1
2016-09-19T08:47:30Z
39,568,980
<p>You probably want to use <code>et = open(path+filename)</code>, instead of just <code>et = open(filename)</code>.</p> <p>Edit : as suggested by @thiruvenkadam best practice would be to use <code>et = open(os.path.join(path,filename))</code></p>
0
2016-09-19T08:50:27Z
[ "python", "pandas", "directory" ]
Python: read files from directory and concatenate that
39,568,925
<p>I have a folder <code>et</code> with <code>.csv</code> files and I try to read that and next concatenate that and get one file. I try </p> <pre><code>import os path = 'et/' for filename in os.listdir(path): et = open(filename) print et </code></pre> <p>but I get an error </p> <pre><code>Traceback (most r...
1
2016-09-19T08:47:30Z
39,569,067
<p>Maybe it's the coding problem</p> <p>You can try to add following code at the top of your code</p> <pre><code># -*- coding: utf-8 -*- </code></pre>
-1
2016-09-19T08:54:05Z
[ "python", "pandas", "directory" ]
Python: read files from directory and concatenate that
39,568,925
<p>I have a folder <code>et</code> with <code>.csv</code> files and I try to read that and next concatenate that and get one file. I try </p> <pre><code>import os path = 'et/' for filename in os.listdir(path): et = open(filename) print et </code></pre> <p>but I get an error </p> <pre><code>Traceback (most r...
1
2016-09-19T08:47:30Z
39,569,260
<p>Using glob.glob will be a better option, along with using os.path.join to get to the full path:</p> <pre><code>from glob import glob from os.path import join, abspath from os import listdir, getcwd import pandas as pd data_frame = pd.DataFrame() dir_path = "et" full_path = join(abspath(getcwd()), dir_path, "*.csv...
0
2016-09-19T09:04:32Z
[ "python", "pandas", "directory" ]
Tail file till process exits
39,568,941
<p>Going through the answers at <a href="http://superuser.com/questions/270529/monitoring-a-file-until-a-string-is-found">superuser</a>.</p> <p>I'm trying to modify this to listen for multiple strings and echo custom messages such as ; 'Your server started successfully' etc</p> <p>I'm also trying to tack it to anothe...
1
2016-09-19T08:48:28Z
39,569,332
<p>Following is general answer and <code>tail</code> could be replaced by any command that result in stream of lines. </p> <p>IF different string needs <strong>different</strong> actions then use following: </p> <pre><code>tail -f var/log/pip/dump.log |awk '/condition1/ {action for condition-1} /condition-2/ {action ...
3
2016-09-19T09:08:21Z
[ "python", "linux", "bash", "shell", "pip" ]
How to open a thread whose target is in another file?
39,568,975
<p>I need to open a thread whose target is defined in a different file.</p> <p>I would like to pass the target name through a string containing, of course, the name of the function I want to run on thread. Is that impossible, or am I missing something? </p> <p>For instance, here is my code:</p> <p>Here is the code t...
1
2016-09-19T08:50:14Z
39,570,586
<p>From the <a href="https://docs.python.org/3/library/threading.html#threading.Thread" rel="nofollow">python docs</a> the <code>target</code> has to be a callable object. From your example you should be able to just put </p> <p><code>target=command.hello</code></p>
0
2016-09-19T10:12:19Z
[ "python", "multithreading" ]
how to make logging.logger to behave like print
39,569,020
<p>Let's say I got this <a href="https://docs.python.org/2/library/logging.html" rel="nofollow">logging.logger</a> instance:</p> <pre><code>import logging logger = logging.getLogger('root') FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s" logging.basicConfig(format=FORMAT) logger.setLevel(logging.D...
2
2016-09-19T08:51:33Z
39,569,095
<p>Set sys.stdout as the stream for your logging.</p> <p>e.g. <code>logging.basicConfig(level=logging.INFO, stream=sys.stdout</code>)</p>
0
2016-09-19T08:55:44Z
[ "python", "python-3.x", "logging" ]
how to make logging.logger to behave like print
39,569,020
<p>Let's say I got this <a href="https://docs.python.org/2/library/logging.html" rel="nofollow">logging.logger</a> instance:</p> <pre><code>import logging logger = logging.getLogger('root') FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s" logging.basicConfig(format=FORMAT) logger.setLevel(logging.D...
2
2016-09-19T08:51:33Z
39,570,939
<p>Alternatively, define a function that accepts <code>*args</code> and then <code>join</code> them in your call to <code>logger</code>:</p> <pre><code>def log(*args, logtype='debug', sep=' '): getattr(logger, logtype)(sep.join(str(a) for a in args)) </code></pre> <p>I added a <code>logtype</code> for flexibility...
1
2016-09-19T10:28:34Z
[ "python", "python-3.x", "logging" ]
how to make logging.logger to behave like print
39,569,020
<p>Let's say I got this <a href="https://docs.python.org/2/library/logging.html" rel="nofollow">logging.logger</a> instance:</p> <pre><code>import logging logger = logging.getLogger('root') FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s" logging.basicConfig(format=FORMAT) logger.setLevel(logging.D...
2
2016-09-19T08:51:33Z
39,571,473
<p>Wrapper based on @Jim's original answer:</p> <pre><code>import logging import sys _logger = logging.getLogger('root') FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s" logging.basicConfig(format=FORMAT) _logger.setLevel(logging.DEBUG) class LogWrapper(): def __init__(self, logger): ...
1
2016-09-19T10:56:28Z
[ "python", "python-3.x", "logging" ]
Python: slow nested for loop
39,569,120
<p>I need to find out an optimal selection of media, based on certain constraints. I am doing it in FOUR nested for loop and since it would take about O(n^4) iterations, it is slow. I had been trying to make it faster but it is still damn slow. My variables can be as high as couple of thousands. </p> <p>Here is a smal...
0
2016-09-19T08:57:09Z
39,569,545
<p>From the comments, I got that you're working on a problem that can be rewritten as an <a href="https://en.wikipedia.org/wiki/Integer_programming" rel="nofollow">ILP</a>. You have several constraints, and need to find a (near) optimal solution.</p> <p>Now, ILPs are quite difficult to solve, and brute-forcing them qu...
2
2016-09-19T09:20:26Z
[ "python", "performance", "linear-programming", "constraint-programming" ]
Python: slow nested for loop
39,569,120
<p>I need to find out an optimal selection of media, based on certain constraints. I am doing it in FOUR nested for loop and since it would take about O(n^4) iterations, it is slow. I had been trying to make it faster but it is still damn slow. My variables can be as high as couple of thousands. </p> <p>Here is a smal...
0
2016-09-19T08:57:09Z
39,569,618
<p>Doing any operation in Python a trillion times is going to be slow. However, that's not all you're doing. By attempting to store all the trillion items in a single list you are storing lots of data in memory and manipulating it in a way that creates a lot of work for the computer to swap memory in and out once it no...
0
2016-09-19T09:24:32Z
[ "python", "performance", "linear-programming", "constraint-programming" ]
Using arg parser in python in another class
39,569,170
<p>I'm trying to write a test in Selenium using python,</p> <p>I managed to run the test and it passed, But now I want add arg parser so I can give the test a different URL as an argument.</p> <p>The thing is that my test is inside a class, So when I'm passing the argument I get an error:</p> <pre><code> app_url=...
0
2016-09-19T08:59:44Z
39,570,287
<p>Put the <code>parser = argparse.ArgumentParser(...)</code> and <code>parser.add_argument()</code> outside <code>if __name__ == "__main__":</code> so that it always gets created but not evaluated. Keep <code>args = vars(parser.parse_args())</code> inside <code>__main__</code>.</p> <p>That way you can import it from ...
0
2016-09-19T09:56:50Z
[ "python", "selenium", "argparse" ]
API access authentication/application key (django/nginx/gunicorn)
39,569,286
<p>I have a web app created in django, running in gunicorn app server behind nginx webserver/reverse-proxy. I need to have external application to access some processed data (csv/json), for which I need some sort of authentication. The basic django auth/login is not optimal as a simple script needs to pull the data wit...
0
2016-09-19T09:05:58Z
39,573,345
<p>There are many authentication methods beside of session/cookie based ones. For your case I will suggest simple token authentication. Just save same token in your django app and external app and on each request from external app to django, send additional header:</p> <pre><code>Authentication: Token YOUR_TOKEN_KEY <...
1
2016-09-19T12:35:27Z
[ "python", "django", "nginx" ]
ggplot multiple plots in one object
39,569,306
<p>I've created a script to create multiple plots in one object. The results I am looking for are two plots one over the other such that each plot has different y axis scale but x axis is fixed - dates. However, only one of the plots (the top) is properly created, the bottom plot is visible but empty i.e the <code>geom...
3
2016-09-19T09:06:56Z
39,741,321
<p>Your calls to the plot directives <code>geom_line()</code>, <code>scale_x_date()</code>, etc. are standing on their own in your script; you do not connect them to your plot object. Thus, they do not have any effect on your plot.</p> <p>In order to apply a plot directive to an existing plot object, use the <em>graph...
0
2016-09-28T07:55:24Z
[ "python", "plot", "python-ggplot" ]
How to change NLTK default wordnet language to zsm?
39,569,307
<p>I'm new to NLTK and I'm doing the Python 3 Text Processing with NLTK 3 Cookbook: Chapter 4. I've done "Using WordNet for tagging" and works fine in default language English. I've download Language Bahasa (zsm) to omw and want to try in Bahasa using other datasets. Using the same approach, how can I change the langua...
0
2016-09-19T09:06:58Z
39,572,071
<p>After some trial I just figured:</p> <pre><code>def choose_tag(self, tokens, index, history): word = tokens[index] fd = FreqDist() for synset in wordnet.synsets(word, lang='zsm'): fd[synset.pos()] += 1 if not fd: return None return self.wordnet_tag_map.get(fd.max()) </code></pre> <p>K...
0
2016-09-19T11:26:47Z
[ "python", "nltk" ]
How to change NLTK default wordnet language to zsm?
39,569,307
<p>I'm new to NLTK and I'm doing the Python 3 Text Processing with NLTK 3 Cookbook: Chapter 4. I've done "Using WordNet for tagging" and works fine in default language English. I've download Language Bahasa (zsm) to omw and want to try in Bahasa using other datasets. Using the same approach, how can I change the langua...
0
2016-09-19T09:06:58Z
39,578,212
<p>As you seem to have figured out, you don't change the <em>default</em> language; you explicitly specify the language you want, whenever you don't want the default. If you find this onerous, you could wrap the <code>wordnet</code> object in your own custom class that provides its own defaults. </p> <pre><code>class ...
0
2016-09-19T16:49:22Z
[ "python", "nltk" ]
Skipping the unmatched Index lines pyspark
39,569,405
<p>I want to skip the lines which are out of list index, i.e keep only the lines which are matching to given index. </p> <p>Following is my data,</p> <pre><code>12,34,5,6,7,8,....... 23,45,657,78,34,....... 0,2,34 15,78,65,78,9,... </code></pre> <p><strong>I want to extract the fields x[0],x[1],x[2],x[3]</strong>...
0
2016-09-19T09:12:59Z
39,569,957
<p>If the data is single dimensional, following is the code you need:</p> <pre><code>def takeOnly3fields(data): return ",".join(data) if len(data)&gt;3 else None </code></pre> <p>map will iterate the entire data for you and you just need a transformation function on the data set.</p>
1
2016-09-19T09:40:56Z
[ "python", "list", "apache-spark", "pyspark" ]
XPath in scrapy returns elements which don't exist
39,569,480
<p>I am creating a new scrapy spider and everything is going pretty good, although I have a problem with one of the websites, where response.xpath is returning objects in the list which doesn't exist in html code:</p> <pre><code>{"pdf_name": ["\n\t\t\t\t\t\t\t\t\t", "ZZZZZZ", "\n\t\t\t\t\t\t\t\t\t", "PDF", "\n\t\t\t\t...
0
2016-09-19T09:16:45Z
39,569,686
<p>Whitespace is part of the document. Just because <em>you</em> think it is unimportant does not make it go away.</p> <p>A text node is a text node, whether it consists of <code>' '</code> (the space character) or any other character makes no difference at all.</p> <p>You can normalize the whitespace with the <code>...
2
2016-09-19T09:27:47Z
[ "python", "xpath", "scrapy" ]
Where do I place the XlsxWriter file in Python?
39,569,497
<p>I downloaded XlsxWriter zip file as I cannot use pip because of organisational restrictions. I extracted the zip file. Where inside the python directory should I place the XlsxWriter folder now ?</p>
-2
2016-09-19T09:17:33Z
39,569,631
<p>For most of the cases use <code>pip</code> to install Python modules. It is very easy.</p> <p>Just do:</p> <pre><code>pip install XlsxWriter </code></pre> <p>And then in your script you can do the following:</p> <pre><code>import xlsxwriter {...your code goes here} </code></pre> <p>If somehow you are not able ...
2
2016-09-19T09:25:09Z
[ "python", "xlsxwriter" ]
Seaborn tsplot shows nothing
39,569,582
<p>I have a data frame called <code>amounts_month</code> of such a type:</p> <pre><code> product accounting_month amount 0 A 201404 204748.0 1 A 201405 445064.0 2 B 201404 649326.0 3 B 201405 876738.0 4 C 201404 ...
0
2016-09-19T09:22:27Z
39,570,865
<p>You can try add one more data for product <code>C</code></p> <pre><code>product accounting_month amount A 201404 204748.0 A 201405 445064.0 B 201404 649326.0 B 201405 876738.0 C 201404 1046336.0 C 201405 1046336.0 </code></...
1
2016-09-19T10:24:57Z
[ "python", "matplotlib", "seaborn" ]
How to use sqoop command in python code for incremental import
39,569,733
<p>I want to do incremental import from user_location_history and after incremental import want to save the last id of in the user_location_updated,so that it can get automated for future.</p> <pre><code>#!/usr/bin/python import subprocess import time import subprocess import MySQLdb import datetime import sys import ...
0
2016-09-19T09:29:56Z
39,586,561
<p>Wrap <code>--last-value</code> in single quotes.</p> <p>Use <code>--last-value '2016-08-04 19:00:36'</code></p>
0
2016-09-20T05:47:08Z
[ "python", "hadoop", "pyspark", "data-warehouse", "sqoop" ]
'filters' is not a registered tag library
39,569,832
<p>I have an issue regarding template filter. I have used <strong>django allauth</strong> for user registration. I have edited its signup.html and used loop to iterate over the fields to show them dynamically. I could show the fields but could not define the type field. </p> <p>What i did is </p> <p><strong>account/s...
0
2016-09-19T09:34:52Z
39,570,069
<p>The tag library should be placed in a <code>templatetags</code> directory in the root directory of the app:</p> <p>See code layout from the <a href="https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#code-layout" rel="nofollow">docs</a>:</p> <blockquote> <p>When a Django app is added to <code>INS...
2
2016-09-19T09:46:33Z
[ "python", "django", "python-3.x", "django-allauth" ]
Custom user model permissions
39,569,857
<p>So everything works fine, but I can't add permissions to my users through admin. When I change an user the box with User permissions appears in place but all the permissions I add have no effect. When I log in as that user I don't have permission to do anything.</p> <p><a href="http://i.stack.imgur.com/7TuNI.png" r...
0
2016-09-19T09:35:44Z
39,570,433
<p>Please check at your db , whether your UserID is mapped with "auth_user_groups" table.</p> <p>For example: </p> <p>id: 2155 user_id: 2447276 group_id: 45</p>
2
2016-09-19T10:04:20Z
[ "python", "django", "django-custom-user" ]
Custom user model permissions
39,569,857
<p>So everything works fine, but I can't add permissions to my users through admin. When I change an user the box with User permissions appears in place but all the permissions I add have no effect. When I log in as that user I don't have permission to do anything.</p> <p><a href="http://i.stack.imgur.com/7TuNI.png" r...
0
2016-09-19T09:35:44Z
39,578,825
<p>I have redone the custom user model following this <a href="https://www.caktusgroup.com/blog/2013/08/07/migrating-custom-user-model-django/" rel="nofollow">article</a>, and now it works as expected.</p>
0
2016-09-19T17:26:36Z
[ "python", "django", "django-custom-user" ]
Specify 'pip' version in requirements.txt
39,569,911
<p>I develop a Python/Django application, which runs from a virtual environment (created by <code>virtualenv</code>). </p> <p>When the virtual environment is created, the global version of <code>pip</code> is copied to the newly created environment by default, which might be quite outdated (for example, version <code>...
0
2016-09-19T09:38:24Z
39,570,152
<p>What you experience is caused by an old version of <code>python-virtualenv</code> delivered with Ubuntu 14.04. You should remove the Ubuntu package and install via pip: </p> <pre><code>sudo pip install virtualenv </code></pre> <p>Then make sure you have the newest pip installed as well. </p> <pre><code>sudo pip i...
0
2016-09-19T09:51:08Z
[ "python", "pip", "virtualenv", "requirements.txt" ]
Specify 'pip' version in requirements.txt
39,569,911
<p>I develop a Python/Django application, which runs from a virtual environment (created by <code>virtualenv</code>). </p> <p>When the virtual environment is created, the global version of <code>pip</code> is copied to the newly created environment by default, which might be quite outdated (for example, version <code>...
0
2016-09-19T09:38:24Z
39,570,844
<p>Please note that <code>pip</code> version listed in <code>requirements.txt</code> is going to be installed along with other requirements. So all requirements are going to be installed by old version of <code>pip</code> and the version specified in <code>requirements.txt</code> will be available afterwards. </p> <p...
2
2016-09-19T10:24:12Z
[ "python", "pip", "virtualenv", "requirements.txt" ]
BigQuery Standard SQL using Python cannot use OFFSET keyword
39,569,928
<p>I am trying to use BigQuery Standard SQL with Python API, though I cannot execute the query that ran successfully in WEB UI.</p> <p>Basically, I am splitting a string and then using OFFSET keyword to get the value at a particular index. As follows:</p> <pre><code>CASE WHEN t.depth = 1 THEN '' WHEN t.depth = 2 THEN...
0
2016-09-19T09:39:19Z
39,577,282
<p>It looks like the query is being executed using legacy SQL based on the error message. I see the same message when I try to execute this using legacy SQL, for instance:</p> <pre><code>SELECT CASE s WHEN 'first' THEN SPLIT(arr, ',')[OFFSET(0)] WHEN 'second' THEN SPLIT(arr, ',')[OFFSET(1)] ELSE NULL E...
0
2016-09-19T15:56:10Z
[ "python", "google-bigquery" ]
ImportError: No module named hmmlearn.hmm python 2.7
39,570,126
<ul> <li><ol> <li>I got this error in python script:</li> </ol></li> <li>from hmmlearn.hmm import </li> <li><p>GaussianHMM I know I need some libraries thats why I ran following</p> <pre><code> git clone git://github.com/hmmlearn/hmmlearn.git pip install -U --user hmmlearn </code></pre></li> </ul> <p>I getting stu...
0
2016-09-19T09:50:04Z
39,570,402
<p>It seems like according to the git-hub page of the repo it requires specific versions of some packages. Make sure you do a pip upgrade for all those packages</p> <ul> <li>Python >=2.6 </li> <li>numpy >= 1.9.3 </li> <li>scipy >= 0.16.0 </li> <li>scikit-learn >= 0.16</li> </ul> <p>then try it will work</p> <p>to up...
0
2016-09-19T10:02:51Z
[ "python", "ubuntu-14.04", "hmmlearn" ]
ImportError: No module named hmmlearn.hmm python 2.7
39,570,126
<ul> <li><ol> <li>I got this error in python script:</li> </ol></li> <li>from hmmlearn.hmm import </li> <li><p>GaussianHMM I know I need some libraries thats why I ran following</p> <pre><code> git clone git://github.com/hmmlearn/hmmlearn.git pip install -U --user hmmlearn </code></pre></li> </ul> <p>I getting stu...
0
2016-09-19T09:50:04Z
39,572,768
<p>I solved this by cloning the repository and running:</p> <pre><code>sudo python setup.py install </code></pre>
0
2016-09-19T12:05:56Z
[ "python", "ubuntu-14.04", "hmmlearn" ]
python def creation within a .py
39,570,190
<p>I am trying to create a def file within a py file that is external eg.</p> <p><code>calls.py</code>:</p> <pre><code>def printbluewhale(): whale = animalia.whale("Chordata", "", "Mammalia", "Certariodactyla", "Balaenopteridae", ...
0
2016-09-19T09:52:38Z
39,574,257
<p>What you're trying to do here seems a bit of a workaround, at least in the way you're trying to handle it.</p> <p>If i understood the question correctly, you're trying to make a python script that takes input from the user, then if that input is equal to "new", have it be able to define a new animal name.</p> <p>Y...
0
2016-09-19T13:19:49Z
[ "python", "python-3.x" ]
What process is using a given file?
39,570,207
<p>I'm having trouble with one of my scripts, where it erratically seems to have trouble writing to its own log, throwing the error "This file is being used by another process."</p> <p>I know there are ways to handle this with try excepts, but I'd like to find out <em>why</em> this is happening rather than just paperi...
0
2016-09-19T09:53:20Z
39,637,414
<p>You can use Microsoft's <a href="https://technet.microsoft.com/en-us/sysinternals/handle.aspx" rel="nofollow">handle.exe</a> command-line utility. For example: </p> <pre><code>import re import subprocess _handle_pat = re.compile(r'(.*?)\s+pid:\s+(\d+).*[0-9a-fA-F]+:\s+(.*)') def open_files(name): """return a ...
1
2016-09-22T11:10:41Z
[ "python", "windows", "file" ]
How to render output of cartridge API's on custom HTML page?
39,570,221
<p>I am working on a cartridge project. I have created custom html templates for better visual and now I want to render all data which is coming through cartridge's built in APIs on my custom html pages. For.ex. I have a product.html, on which I want to show all products stored in db (category wise). </p> <p>Actually,...
0
2016-09-19T09:54:00Z
39,570,291
<p>When you hit <strong>shop</strong> url, your application will try to use an empty url from your cartridge.shop.urls file. So basically when you would like to check which API / view is called, go to this file and look for something similar to this:</p> <pre><code>url(r'^$', 'your-view', name='your-view'), </code></p...
0
2016-09-19T09:57:04Z
[ "python", "html", "django", "mezzanine", "cartridge" ]
How to partially remove content from cell in a dataframe using Python
39,570,240
<p>I have the following dataframe:</p> <pre><code>import pandas as pd df = pd.DataFrame([ ['\nSOVAT\n', 'DVR', 'MEA', '\n195\n'], ['PINCO\nGALLO ', 'DVR', 'MEA\n', '195'], ]) </code></pre> <p>which looks like this:</p> <p><a href="http://i.stack.imgur.com/ldKxo.png" rel="nofollow"><img src="h...
0
2016-09-19T09:54:54Z
39,570,434
<p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html" rel="nofollow"><code>df.replace</code></a> and some regex.</p> <pre><code>In [1]: import pandas as pd ...: df = pd.DataFrame([ ...: ['\nSOVAT\n', 'DVR', 'MEA', '\n195\n'], ...: ['PINCO\nGALLO ', 'D...
1
2016-09-19T10:04:22Z
[ "python", "pandas", "dataframe", "removing-whitespace" ]