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 |
|---|---|---|---|---|---|---|---|---|---|
Run Python function with input arguments form command line | 38,993,606 | <p>New to Python, used to use MATLAB.</p>
<p>My function convert.py is:</p>
<pre><code>def convert(a,b)
factor = 2194.2
return (a-b)*factor
</code></pre>
<p>How do I run it from the command line with input arguments 'a' and 'b' ?
I tried:</p>
<pre><code>python convert.py 32 46
</code></pre>
<p>But got an error... | -2 | 2016-08-17T10:05:56Z | 38,993,808 | <p>You could do:</p>
<pre><code>import sys
def convert(a,b):
factor = 2194.2
return (a-b)*factor
print(convert(int(sys.argv[1]), int(sys.argv[2])))
</code></pre>
<p>If that is all what should do the script, you dont have to define a function:</p>
<pre><code>import sys
factor = 2194.2
print((int(sys.argv[1]),... | 0 | 2016-08-17T10:15:04Z | [
"python",
"function",
"input",
"command-line",
"arguments"
] |
accessing client's x509 certificate from within twisted web WSGI app | 38,993,831 | <p>I have set up a twisted + flask https server that also does certificate-based client authentication by following the documentation at the Twisted site <a href="http://twistedmatrix.com/documents/current/core/howto/ssl.html#tls-server-with-client-authentication-via-client-certificate-verification" rel="nofollow">here... | 0 | 2016-08-17T10:16:21Z | 38,999,544 | <p><strong>Updated</strong>: using <code>HTTPChannel.allHeadersReceived</code> instead of <code>Protocol.dataReceived</code> for support of chunked requests.</p>
<p>You can use HTTP headers to store connection information: set them up in <code>HTTPChannel.allHeadersReceived</code> method and retrieve from <code>flask.... | 0 | 2016-08-17T14:32:38Z | [
"python",
"flask",
"openssl",
"twisted"
] |
How to join a list while preserving previous structure? | 38,993,845 | <p>I am having trouble joining a pre-split string after modification while preserving the previous structure.</p>
<p>say I have a string like this:</p>
<pre><code>string = """
This is a nice piece of string isn't it?
I assume it is so. I have to keep typing
to use up the space. La-di-da-di-da.
This is a spa... | 0 | 2016-08-17T10:16:50Z | 38,993,890 | <p>The <code>split</code> method takes an optional argument to specify the delimiter. If you only want to split words using space (<code>' '</code>) characters, you can pass that as an argument:</p>
<pre><code>>>> string = """
...
... This is a nice piece of string isn't it?
... I assume it is so. I have to k... | 1 | 2016-08-17T10:19:19Z | [
"python",
"list",
"formatting"
] |
How to join a list while preserving previous structure? | 38,993,845 | <p>I am having trouble joining a pre-split string after modification while preserving the previous structure.</p>
<p>say I have a string like this:</p>
<pre><code>string = """
This is a nice piece of string isn't it?
I assume it is so. I have to keep typing
to use up the space. La-di-da-di-da.
This is a spa... | 0 | 2016-08-17T10:16:50Z | 38,993,892 | <p>The split method will split your string based on all white-spaces by default. If you want to split the lies separately, you can first split your string with new-lines then split the lines with white-space:</p>
<pre><code>>>> [line.split() for line in string.strip().split('\n')]
[['This', 'is', 'a', 'nice',... | 1 | 2016-08-17T10:19:25Z | [
"python",
"list",
"formatting"
] |
How to join a list while preserving previous structure? | 38,993,845 | <p>I am having trouble joining a pre-split string after modification while preserving the previous structure.</p>
<p>say I have a string like this:</p>
<pre><code>string = """
This is a nice piece of string isn't it?
I assume it is so. I have to keep typing
to use up the space. La-di-da-di-da.
This is a spa... | 0 | 2016-08-17T10:16:50Z | 38,993,901 | <p>just do <code>string.split(' ')</code> (note the space argument to the split method).</p>
<p>this will keep your precious new lines within the strings that go into the resulting array...</p>
| 0 | 2016-08-17T10:19:59Z | [
"python",
"list",
"formatting"
] |
How to join a list while preserving previous structure? | 38,993,845 | <p>I am having trouble joining a pre-split string after modification while preserving the previous structure.</p>
<p>say I have a string like this:</p>
<pre><code>string = """
This is a nice piece of string isn't it?
I assume it is so. I have to keep typing
to use up the space. La-di-da-di-da.
This is a spa... | 0 | 2016-08-17T10:16:50Z | 38,994,000 | <p>Just split with a delimiter:</p>
<pre><code>>>> string.split(' ')
['\n\nThis', 'is', 'a', 'nice', 'piece', 'of', 'string', "isn't", 'it?\nI', 'assume', 'it', 'is', 'so.', 'I', 'have', 'to', 'keep', 'typing\nto', 'use', 'up', 'the', 'space.', 'La-di-da-di-da.\n\nThis', '', '', 'is', '', '', '', 'a', '', '',... | 1 | 2016-08-17T10:24:23Z | [
"python",
"list",
"formatting"
] |
How to join a list while preserving previous structure? | 38,993,845 | <p>I am having trouble joining a pre-split string after modification while preserving the previous structure.</p>
<p>say I have a string like this:</p>
<pre><code>string = """
This is a nice piece of string isn't it?
I assume it is so. I have to keep typing
to use up the space. La-di-da-di-da.
This is a spa... | 0 | 2016-08-17T10:16:50Z | 38,994,548 | <p>You can save the spaces in another list then after modifying the words list you join them together. </p>
<pre><code>In [1]: from nltk.tokenize import RegexpTokenizer
In [2]: spacestokenizer = RegexpTokenizer(r'\s+', gaps=False)
In [3]: wordtokenizer = RegexpTokenizer(r'\s+', gaps=True)
In [4]: string = """
...... | 0 | 2016-08-17T10:49:16Z | [
"python",
"list",
"formatting"
] |
Fetching collection inside a subquery | 38,994,074 | <p>Supposing we have two tables, linked by a many-to-many relationship.</p>
<pre><code>class Student(db.Model):
id = db.Column(UUIDType, primary_key=True)
name = db.Column(db.String(255))
courses = db.relationship('Course',
secondary=student_courses,
... | 1 | 2016-08-17T10:28:05Z | 38,998,629 | <p>You can use <a href="https://www.postgresql.org/docs/9.5/static/functions-aggregate.html" rel="nofollow"><code>array_agg</code></a> function in PostgreSQL</p>
<pre><code>from sqlalchemy import func
db.session.query(Student.id, Student.name, func.array_agg(Course.name))\
.join(Student.courses)\
... | 0 | 2016-08-17T13:52:01Z | [
"python",
"sqlalchemy",
"flask-sqlalchemy"
] |
django change list display column name with foreign field value | 38,994,195 | <p>I am using <code>django 1.9</code> , i have following model which have two foreing fields,</p>
<p><strong>models.py</strong></p>
<pre><code>class Mobile(models.Model):
name = models.CharField(max_length=100)
product = models.ForeignKey(Product)
owner = model.ForeignKey(Customer)
</code></pre>
<p>now i... | 0 | 2016-08-17T10:33:39Z | 38,994,470 | <p>I think you have to do</p>
<pre><code>list_display = ('name','related_product', 'related_owner') #means method name what you are given.
</code></pre>
| 0 | 2016-08-17T10:45:42Z | [
"python",
"django"
] |
Storing numpy array in sqlite3 database with python issue | 38,994,218 | <p>I have a problem with storing a numpy array in sqlite database. I have 1 table with Name and Data.</p>
<pre><code>import sqlite3 as sql
from DIP import dip # function to caclculate numpy array
name = input('Enter your full name\t')
data = dip()
con = sql.connect('Database.db')
c = con.cursor()
c.execute("CREA... | 0 | 2016-08-17T10:34:36Z | 39,004,777 | <p>On the assumption that it is saving <code>data.tostring()</code> to the database, I tried decoding it with <code>fromstring</code>.</p>
<p>Using your displayed string, and trimming off a few bytes I got:</p>
<pre><code>In [79]: np.fromstring(b'\xccX+\xa8.\x03\xa4?\xf7\xda[\x1f\x10l\xc7?', float)
Out[79]: array([ 0... | 0 | 2016-08-17T19:27:41Z | [
"python",
"arrays",
"sqlite",
"numpy",
"sqlite3"
] |
Split a list of dictionary if the value is empty? | 38,994,257 | <p>I want to split a list of dictionary <code>if the value is empty</code> and create new list of list.</p>
<p>Input : </p>
<pre><code>[{'k':'a'},{'k':'b'},{'k':''},{'k':'d'},{'k':''},{'k':'f'},{'k':'g'}]
</code></pre>
<p>Output : </p>
<pre><code>[[{'k': 'a'}, {'k': 'b'}, {'k': ''}], [{'k': 'd'}, {'k': ''}], [{'k':... | 1 | 2016-08-17T10:36:01Z | 38,994,332 | <p>You can use a <a href="https://docs.python.org/dev/library/itertools.html#itertools.groupby" rel="nofollow"><em>groupby</em></a>:</p>
<pre><code>from itertools import groupby, chain
l = [{'k':'a'},{'k':'b'},{'k':''},{'k':'d'},{'k':''},{'k':'f'},{'k':'g'}]
grps = groupby(l, lambda d: d["k"] == "")
print([list(ch... | 2 | 2016-08-17T10:39:26Z | [
"python",
"list",
"loops",
"dictionary"
] |
Split a list of dictionary if the value is empty? | 38,994,257 | <p>I want to split a list of dictionary <code>if the value is empty</code> and create new list of list.</p>
<p>Input : </p>
<pre><code>[{'k':'a'},{'k':'b'},{'k':''},{'k':'d'},{'k':''},{'k':'f'},{'k':'g'}]
</code></pre>
<p>Output : </p>
<pre><code>[[{'k': 'a'}, {'k': 'b'}, {'k': ''}], [{'k': 'd'}, {'k': ''}], [{'k':... | 1 | 2016-08-17T10:36:01Z | 38,994,453 | <p>This is another Pythonic way of doing it:</p>
<pre><code>>>> d = [{'k':'a'}, {'k':'b'}, {'k':''}, {'k':'d'}, {'k':''}, {'k':'f'}, {'k':'g'}]
>>> index_list = [i + 1 for i, x in enumerate(d) if x == {'k': ''}]
>>> [d[i:j] for i, j in zip([0] + index_list, index_list + [len(d)])]
[[{'k': 'a... | 2 | 2016-08-17T10:44:57Z | [
"python",
"list",
"loops",
"dictionary"
] |
How to create this sequence in ruby? | 38,994,265 | <p>When we
input : 10</p>
<p>output :01 02 03 04 05 06 07 08 09 10</p>
<p>When we
input :103</p>
<p>output :001 002 003...010 011 012 013.....100 101 002 103</p>
<p>How to create this sequence in ruby or python ?</p>
| -2 | 2016-08-17T10:36:29Z | 38,994,494 | <p>A very basic Python implementation. Note that it's a generator so it returns one value at a time.</p>
<pre><code>def get_range(n):
len_n = len(str(n))
for num in range(1, n + 1):
output = str(num)
while len(output) < len_n:
output = '0' + output
yield output
for i in ... | 1 | 2016-08-17T10:47:00Z | [
"python",
"ruby"
] |
How to create this sequence in ruby? | 38,994,265 | <p>When we
input : 10</p>
<p>output :01 02 03 04 05 06 07 08 09 10</p>
<p>When we
input :103</p>
<p>output :001 002 003...010 011 012 013.....100 101 002 103</p>
<p>How to create this sequence in ruby or python ?</p>
| -2 | 2016-08-17T10:36:29Z | 38,994,510 | <p>Using <code>zfill</code> you can add leading zeroes. </p>
<pre><code>num=input()
for i in range(1,int(num)+1):
print (str(i).zfill(len(num)))
</code></pre>
| 1 | 2016-08-17T10:47:42Z | [
"python",
"ruby"
] |
How to create this sequence in ruby? | 38,994,265 | <p>When we
input : 10</p>
<p>output :01 02 03 04 05 06 07 08 09 10</p>
<p>When we
input :103</p>
<p>output :001 002 003...010 011 012 013.....100 101 002 103</p>
<p>How to create this sequence in ruby or python ?</p>
| -2 | 2016-08-17T10:36:29Z | 38,995,017 | <p>Ruby implementation:</p>
<pre><code>n = gets
p (1..n.to_i).map{ |i| i.to_s.rjust(n.to_s.length, "0") }.join(" ")
</code></pre>
<p>Here <code>rjust</code> will add leading zeros.</p>
| 3 | 2016-08-17T11:11:42Z | [
"python",
"ruby"
] |
How to create this sequence in ruby? | 38,994,265 | <p>When we
input : 10</p>
<p>output :01 02 03 04 05 06 07 08 09 10</p>
<p>When we
input :103</p>
<p>output :001 002 003...010 011 012 013.....100 101 002 103</p>
<p>How to create this sequence in ruby or python ?</p>
| -2 | 2016-08-17T10:36:29Z | 38,996,553 | <p>Another one in Ruby:</p>
<pre><code>n = gets.chomp
'1'.rjust(n.size, '0').upto(n) { |s| puts s }
</code></pre>
<p><a href="http://ruby-doc.org/core-2.3.1/String.html#method-i-upto" rel="nofollow"><code>String#upto</code></a> handles numeric strings in a special way:</p>
<pre><code>'01'.upto('10').to_a
#=> ["01... | 2 | 2016-08-17T12:22:48Z | [
"python",
"ruby"
] |
WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not available (error: cuda unavailable) | 38,994,291 | <p>in Ubuntu MATE 16.04 I'm trying to run the deep-learning python examples here using the GPU:</p>
<p><a href="http://deeplearning.net/software/theano/tutorial/using_gpu.html" rel="nofollow">testing Theano with GPU</a></p>
<p>I did run the example code, </p>
<pre><code>THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=f... | 2 | 2016-08-17T10:37:50Z | 39,017,165 | <p>Finally I solved!
This post
<a href="https://github.com/Theano/Theano/issues/4430" rel="nofollow">Ubuntu 16.04, Theano and Cuda</a></p>
<p>suggests to add flag </p>
<pre><code>nvcc.flags=-D_FORCE_INLINES
</code></pre>
<p>to command line, so the command line becomes:</p>
<pre><code>THEANO_FLAGS=floatX=float32,d... | 1 | 2016-08-18T11:34:02Z | [
"python",
"theano",
"theano-cuda"
] |
Receive push data in R Shiny application | 38,994,377 | <p>I have a simple python program, which should push its data into an R Shiny application. These lines in Shiny parse the "GET" input:</p>
<pre><code> # Parse the GET query string
output$queryText <- renderText({
query <- parseQueryString(session$clientData$url_search)
eventList[query$eventid] <<... | 0 | 2016-08-17T10:41:39Z | 39,000,116 | <p>My complete solution using websockets with httpuv: </p>
<pre><code>library(httpuv)
startWSServer <- function(){
if(exists('server')){
stopDaemonizedServer(server)
}
app <- list(
onWSOpen = function(ws) {
ws$onMessage(function(binary, message) {
#handle your message, f... | 1 | 2016-08-17T14:58:55Z | [
"python",
"get",
"shiny",
"shiny-server"
] |
I can't encode my input | 38,994,379 | <pre><code>if wb == 'Encode a sentence' or wb == 'encode a sentence':
print("Please enter the Sentence...")
str = input()
str = str.encode('base64','strict')
print(str)
</code></pre>
<p>It tells me that it can't be bytes, They should be string...Any help is appreciated!</p>
| 0 | 2016-08-17T10:41:43Z | 38,994,571 | <p>try this:</p>
<pre><code>from base64 import b64encode
b64encode(wb.encode())
</code></pre>
<p>also for your if line use this </p>
<pre><code>if wb.lower() == 'encode a sentence':
</code></pre>
| 1 | 2016-08-17T10:50:04Z | [
"python",
"byte",
"encode"
] |
I can't encode my input | 38,994,379 | <pre><code>if wb == 'Encode a sentence' or wb == 'encode a sentence':
print("Please enter the Sentence...")
str = input()
str = str.encode('base64','strict')
print(str)
</code></pre>
<p>It tells me that it can't be bytes, They should be string...Any help is appreciated!</p>
| 0 | 2016-08-17T10:41:43Z | 38,994,616 | <p>You can try this:</p>
<pre><code>import base64
if wb == 'Encode a sentence' or wb == 'encode a sentence':
print("Please enter the Sentence...")
str = input()
base64.b64encode(bytes(str, 'utf-8'))
print(str)
</code></pre>
| 1 | 2016-08-17T10:52:15Z | [
"python",
"byte",
"encode"
] |
Optimize Query in django | 38,994,381 | <p>I want to optimize the looping code using django orm as it is taking 41 queries because of the loop was shown in django-debug-toolbar, I have stated my models with the django ORM and there is a loop where i need to optimize using ORM approach so that i can avoid a loop. </p>
<pre><code>class Bills(models.Model):
... | 0 | 2016-08-17T10:41:51Z | 38,995,037 | <p>In this specific scenario you can use <code>prefetch_related</code> with custom <code>Prefetch</code> object/s to prefetch the necessary data and not make any queries inside the loop.</p>
<pre><code>customers = Customer.objects.filter(library="1").exclude(customer_status='2')
bills = Bills.objects.filter(library="1... | 0 | 2016-08-17T11:12:50Z | [
"python",
"mysql",
"django",
"django-models",
"orm"
] |
Optimize Query in django | 38,994,381 | <p>I want to optimize the looping code using django orm as it is taking 41 queries because of the loop was shown in django-debug-toolbar, I have stated my models with the django ORM and there is a loop where i need to optimize using ORM approach so that i can avoid a loop. </p>
<pre><code>class Bills(models.Model):
... | 0 | 2016-08-17T10:41:51Z | 38,995,061 | <pre><code>not_processed_order = LibraryOrder.objects.filter(bill__library="1", bill__book_category_type="1", order_status="1", bill__customer__library='1').exclude(bill__customer__status='2')
processing_order = LibraryOrder.objects.filter(bill__library="1", bill__book_category_type="1", order_status="2", bill__custome... | 3 | 2016-08-17T11:13:59Z | [
"python",
"mysql",
"django",
"django-models",
"orm"
] |
Python pandas with lambda apply difficulty | 38,994,408 | <p>I am running the following function but somehow struggling to have it take the length condition into account (the if part). It simply runs the first part if the function only:</p>
<p><code>stringDataFrame.apply(lambda x: x.str.replace(r'[^0-9]', '') if (len(x) >= 7) else x)</code></p>
<p>it somehow only runs th... | 1 | 2016-08-17T10:43:11Z | 38,994,686 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.applymap.html" rel="nofollow"><code>applymap</code></a> if need works by each value separately, because <code>apply</code> works with <code>all column</code> (<code>Series</code>).</p>
<p>Then istead <a href="http://pandas.p... | 1 | 2016-08-17T10:55:47Z | [
"python",
"pandas",
"dataframe",
"lambda",
"apply"
] |
Pandas DataFrame.to_csv last column missing when field is empty | 38,994,458 | <p>I am extracting data from a database into a csv file.</p>
<p>I realize that each time the last field of a row in Null, then DataFrame.to_csv omit it.
This only happens when the empty field is at the last position.</p>
<p>Here is an exemple :</p>
<pre><code>dframe_iterator = pandas.read_sql_query(request, engine, ... | 0 | 2016-08-17T10:45:20Z | 38,996,898 | <p>Have you tried parameter <code>na_rep</code>? <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html" rel="nofollow">Doc</a></p>
<pre><code> na_rep : string, default ââ
Missing data representation
</code></pre>
| 0 | 2016-08-17T12:38:30Z | [
"python",
"pandas",
"dataframe"
] |
Pandas DataFrame.to_csv last column missing when field is empty | 38,994,458 | <p>I am extracting data from a database into a csv file.</p>
<p>I realize that each time the last field of a row in Null, then DataFrame.to_csv omit it.
This only happens when the empty field is at the last position.</p>
<p>Here is an exemple :</p>
<pre><code>dframe_iterator = pandas.read_sql_query(request, engine, ... | 0 | 2016-08-17T10:45:20Z | 38,997,453 | <p>Hemm, well, I apologie but my question was wrong.</p>
<p>Actually, the pandas behaviour is perfectly good :</p>
<pre><code>'blabla','blabla',Null, 'blabla', Null
</code></pre>
<p>would be :</p>
<pre><code>blabla|blabla||blabla|
</code></pre>
<p>I have been troubled by a dataset having lots of Null field at last... | 2 | 2016-08-17T13:03:11Z | [
"python",
"pandas",
"dataframe"
] |
Autostart Python script and run in background with Ubuntu | 38,994,530 | <p>I'm running Ubuntu server 16.04 and still getting to grips with it. I have a python script that runs in an endless loop, performing a task related to fetching data from an external source.</p>
<p>What I'm trying to do, is make this python script start after (or during) boot and then run in the background.</p>
<p>I... | 0 | 2016-08-17T10:48:38Z | 38,994,864 | <p>tmux is a great utility for background desktops. You can use it for this:</p>
<pre><code>sudo apt get install tmux
</code></pre>
<p>Then add it to your rc.local:</p>
<pre><code>/usr/bin/tmux new-session -d 'python /path/to/your/script'
</code></pre>
<p>After boot you can use it as follow:</p>
<pre><code>tmux at... | 0 | 2016-08-17T11:05:12Z | [
"python",
"ubuntu",
"background",
"boot",
"autostart"
] |
Autostart Python script and run in background with Ubuntu | 38,994,530 | <p>I'm running Ubuntu server 16.04 and still getting to grips with it. I have a python script that runs in an endless loop, performing a task related to fetching data from an external source.</p>
<p>What I'm trying to do, is make this python script start after (or during) boot and then run in the background.</p>
<p>I... | 0 | 2016-08-17T10:48:38Z | 38,994,915 | <p>As one of the comments mentions, you can use cronjobs to start scripts at certain times such as at startup(as you would like to do). It also would not halt execution like you mentioned with rc.local</p>
<p>The line that you need to add to the chronjob list is - </p>
<p><code>@reboot python /home/MyPythonScript.py<... | 0 | 2016-08-17T11:07:14Z | [
"python",
"ubuntu",
"background",
"boot",
"autostart"
] |
SSIS Execute Process Task Hanging when Standard Error Variable Provided | 38,994,725 | <p>I am using SSIS's Execute Process Task to execute a compiled python script.</p>
<p>The script executes as expected and completes as expected with either success or failure.</p>
<p>However, when I configure a variable to catch Standard Error or Standard Output, the application hangs. The command prompt flashes up a... | 0 | 2016-08-17T10:58:01Z | 38,997,349 | <p>This is actually now solved - or rather, never actually broken; I was writing to a parent package variable (i.e. by creating the variable in the child package, configuring the task, setting delay validation to true and then deleting the variable) - it appears when I do this, it takes SSIS a long time to write to it!... | 0 | 2016-08-17T12:58:56Z | [
"python",
"ssis"
] |
How to find values that don't belong to sample in Python? | 38,994,770 | <p>I need to take a sample from a dataframe but also I need the values that don't belong to that sample. For examle:</p>
<pre><code>data = [[1,2,3,55], [1,2,34,5], [13,2,3,5], [1,2,32,5], [1,2,22,5]]
df = DataFrame(data=data, index=[0, 0, 1, 1, 1], columns=['A', 'B', 'C', 'D'])
</code></pre>
<p>Output:</p>
<pre><cod... | 1 | 2016-08-17T11:00:48Z | 38,994,954 | <p>With duplicates index it is problematic, so need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html" rel="nofollow"><code>reset_index</code></a> firstly, then use <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>bo... | 1 | 2016-08-17T11:08:50Z | [
"python",
"pandas",
"indexing",
"dataframe",
"sample"
] |
parsing PDB header information with python (protein structure files)? | 38,994,845 | <p>Is there a parser for PDB-files (Protein Data Bank) that can extract (most) information from the header/REMARK-section, like refinement statistics, etc.?</p>
<p>It might be worthwhile to note that I am mainly interested in accessing data from files right after they have been produced, not from structures that have ... | -1 | 2016-08-17T11:04:12Z | 38,995,570 | <p>Maybe you should try that library?
<a href="https://pypi.python.org/pypi/bioservices" rel="nofollow">https://pypi.python.org/pypi/bioservices</a></p>
| -1 | 2016-08-17T11:37:38Z | [
"python",
"bioinformatics",
"biopython"
] |
Blender Script not working | 38,994,871 | <p>I want to make a Side Scroller in Blender with python. Could someone please explain to me why this script is not working?</p>
<pre><code>import bge
def main():
cont = bge.logic.getCurrentController()
player = cont.owner
scene = bge.logic.getCurrentScene()
keyboard = bge.logic.keyboard
if bg... | 0 | 2016-08-17T11:05:27Z | 39,014,612 | <p>Going by the script working for me and the error you say you get, it would appear that you are using the script the wrong way. The bge module is only available when the game engine is running and it sounds like you are trying to run it as a normal blender script by clicking the run script button in blender's text ed... | 0 | 2016-08-18T09:29:40Z | [
"python",
"blender"
] |
How do I store a string in ArrayField? (Django and PostgreSQL) | 38,994,883 | <p>I am unable to store a string in ArrayField. There are no exceptions thrown when I try to save something in it, but the array remains empty.
Here is some code from models.py :</p>
<pre><code># models.py
from django.db import models
import uuid
from django.contrib.auth.models import User
from django.contrib.postgres... | 1 | 2016-08-17T11:06:14Z | 38,995,288 | <h2>Solution to the append problem.</h2>
<p>You haven't demonstrated how your <code>usersearch[0]</code> I suspect it's something like this:</p>
<pre><code>usersearch = UserDetail.objects.all()
</code></pre>
<p>If that is so you are making changes to a resultset, those things are immutable. Try this you will see tha... | 0 | 2016-08-17T11:23:34Z | [
"python",
"django",
"postgresql"
] |
Python: replace string with regex | 38,994,930 | <p>my problem here is that I have a huge amount of files. Each xml file contains ID. And I got set of source and target files. Source files has name A and ID = B. Target file has name B and ID=B
What I need to do is to match source ID B with Target name B and then replace target ID=B with source name A. Hope its clear<... | 0 | 2016-08-17T11:08:00Z | 38,995,207 | <p>You <code>read()</code> from <code>each_targ</code> but you don't store the string anywhere. </p>
<p>Instead you pass the file handle <code>each_targ</code> to <code>.sub</code> and that causes the type mismatch here. You could just say:</p>
<pre><code>findtargetID = re.sub('id="\w{3}\d{13}"',str(IDtoreplace), eac... | 1 | 2016-08-17T11:19:23Z | [
"python",
"replace"
] |
Clustat command not found error in python script | 38,995,008 | <p>Hi I am trying to create a script using python to log on to a server and to check the status of the cluster by running a clustat command. When I do this I get the following error:
/bin/sh: clustat: command not found
As I understand it, it's not able to run the command as this is a non standard bash command that is b... | 0 | 2016-08-17T11:11:13Z | 38,995,255 | <p><code>subprocess</code> runs the commands <strong>locally</strong>. </p>
<p>You will have to use <code>paramiko.SSHClient</code> to run commands on the remote machine.</p>
<pre><code>ssh_client = paramiko.SSHClient()
ssh_client.connect(host='some_host', username='username', password='password')
ssh_client.exec_co... | 1 | 2016-08-17T11:21:48Z | [
"python",
"bash"
] |
Python 3 - Data mining from PDF | 38,995,050 | <p>I'm working on a project that requires obtaining data from some PDF documents.</p>
<p>Currently I'm using <code>Foxit toolkit</code> (calling it from the script) to convert the document to txt and then I iterate through it. I'm pretty happy with it, but <code>100$</code> it's just something I can't afford for such ... | 2 | 2016-08-17T11:13:25Z | 38,995,341 | <p>I don't believe that there is a good free python pdf converter sadly, however pdf2html although it is not a python module, works extremely well and provides you with much more structured data(html) compared to a simple text file. And from there you can use python tools such as beautiful soup to scrape the html file.... | 1 | 2016-08-17T11:26:15Z | [
"python",
"python-3.x",
"pdf",
"toolkit",
"foxit"
] |
Python 3 - Data mining from PDF | 38,995,050 | <p>I'm working on a project that requires obtaining data from some PDF documents.</p>
<p>Currently I'm using <code>Foxit toolkit</code> (calling it from the script) to convert the document to txt and then I iterate through it. I'm pretty happy with it, but <code>100$</code> it's just something I can't afford for such ... | 2 | 2016-08-17T11:13:25Z | 38,995,348 | <p>Here is an example of pyPDF2 codes:</p>
<pre><code>from PyPDF2 import PdfFileReader
pdfFileObj = open("FileName", "rb")
pdfReader = PdfFileReader(pdfFileObj,strict = False)
data=[page.extractText() for page in pdfReader.pages]
</code></pre>
<p>more information on pyPDF2 <a href="https://pythonhosted.org/PyPDF2/"... | 0 | 2016-08-17T11:26:38Z | [
"python",
"python-3.x",
"pdf",
"toolkit",
"foxit"
] |
Python 3 - Data mining from PDF | 38,995,050 | <p>I'm working on a project that requires obtaining data from some PDF documents.</p>
<p>Currently I'm using <code>Foxit toolkit</code> (calling it from the script) to convert the document to txt and then I iterate through it. I'm pretty happy with it, but <code>100$</code> it's just something I can't afford for such ... | 2 | 2016-08-17T11:13:25Z | 38,995,633 | <p>The <a href="https://pythonhosted.org/PyPDF2/index.html" rel="nofollow">PyPDF2</a> seems to be the best one available for Python3
It's well documented and the API is simple to use.</p>
<p>It also can work with encrypted files, retrieve metadata, merge documents, etc</p>
<p>A simple use case for extracting the text... | 0 | 2016-08-17T11:40:14Z | [
"python",
"python-3.x",
"pdf",
"toolkit",
"foxit"
] |
Python 3 - Data mining from PDF | 38,995,050 | <p>I'm working on a project that requires obtaining data from some PDF documents.</p>
<p>Currently I'm using <code>Foxit toolkit</code> (calling it from the script) to convert the document to txt and then I iterate through it. I'm pretty happy with it, but <code>100$</code> it's just something I can't afford for such ... | 2 | 2016-08-17T11:13:25Z | 39,056,694 | <p>I had the same problem when I wanted to do some deep inspection of PDFs for security analysis - I had to write my own utility that parses the low-level objects and literals, unpacks streams, etc so I could get at the "raw data":</p>
<p><a href="https://github.com/opticaliqlusion/pypdf" rel="nofollow">https://github... | 0 | 2016-08-20T17:03:13Z | [
"python",
"python-3.x",
"pdf",
"toolkit",
"foxit"
] |
Python Generic Exception Vs Specific Exceptions | 38,995,091 | <p>I'm writing a small production level Flask application that runs on IIS. I've wrapped all of my functions inside <code>try catch</code> blocks and it looks like this.</p>
<pre><code>try:
#Do Something
except Exception,e:
logger.error('Exception in Function X of type : %s ,for Image %s : %s'%(str(type(e)... | 2 | 2016-08-17T11:15:18Z | 38,995,223 | <p>If the goal is to log <em>all</em> exceptions, then no, you don't have to catch specific ones.</p>
<p>As you noted, there'd be no point as you'd only repeat the same piece of logging.</p>
| 1 | 2016-08-17T11:19:59Z | [
"python",
"exception",
"exception-handling"
] |
Is there a specific use of pdist function of scipy for some particular indexes? | 38,995,263 | <p>my question is about use of pdist function of scipy.spatial.distance. Although I have to calculate the hamming distances between a 1x64 vector with each and every one of other millions of 1x64 vectors that are stored in a 2D-array, I cannot do it with pdist. Because it returns hamming distances between any two vecto... | 0 | 2016-08-17T11:22:05Z | 38,997,940 | <p>You can use <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html" rel="nofollow"><code>cdist</code></a>. For example,</p>
<pre><code>In [101]: from scipy.spatial.distance import cdist
In [102]: x
Out[102]:
array([[0, 1, 1, 1, 1, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 1, 0],... | 0 | 2016-08-17T13:23:11Z | [
"python",
"scipy",
"pdist"
] |
Cant import module in site packages directory? | 38,995,296 | <p>i have been trying to import a module named requests, it is located in site-packages folder. It was installed via pip but every time i try to import it i get the error "<em>ImportError: No module named 'request'</em>" </p>
<p>I am using "import requests" to import.</p>
<pre><code>import requests
from bs4 import Be... | -1 | 2016-08-17T11:24:01Z | 38,995,368 | <p>You have a typo.</p>
<p><code>import request</code> should be <code>import requests</code></p>
| 0 | 2016-08-17T11:27:31Z | [
"python",
"python-3.x"
] |
Cant import module in site packages directory? | 38,995,296 | <p>i have been trying to import a module named requests, it is located in site-packages folder. It was installed via pip but every time i try to import it i get the error "<em>ImportError: No module named 'request'</em>" </p>
<p>I am using "import requests" to import.</p>
<pre><code>import requests
from bs4 import Be... | -1 | 2016-08-17T11:24:01Z | 38,997,238 | <p>I guess you have installed <a href="http://docs.python-requests.org/en/master/user/install/" rel="nofollow"><code>requests</code></a> module for <code>Python 2</code> but you are working on <code>Python 3</code>. Use the below command to install it for Python 3:</p>
<pre><code>python3 -m pip install requests
</code... | 0 | 2016-08-17T12:54:25Z | [
"python",
"python-3.x"
] |
Generate unique barcodes without race conditions | 38,995,304 | <p>For our customers, I need to generate unique barcodes. No customer shall have two identical barcodes. The barcodes are built up as follows:</p>
<ul>
<li>Customer prefix</li>
<li>Index number</li>
<li>Check digit</li>
</ul>
<p>I want to keep track per customer which was the latest index number used, and when genera... | 0 | 2016-08-17T11:24:21Z | 38,995,443 | <p>That's one of the tools backed into database engines, so how about using it for that purpose? It is a <a href="https://www.postgresql.org/docs/9.1/static/sql-createsequence.html" rel="nofollow">sequence</a>. It is the very same tool that is used for generating primary key values (which I assume are not an option for... | 2 | 2016-08-17T11:31:35Z | [
"python",
"django",
"postgresql",
"barcode",
"race-condition"
] |
Unable to import child from parent package python | 38,995,363 | <p>I'm currently writing a web application in python that needs unit tests, however whenever I try to import a child module that's in another parent directory I get the following error:</p>
<pre><code>$ python my_package/tests/main.py
Traceback (most recent call last):
File "my_package/tests/test.py", line 1, in <... | 1 | 2016-08-17T11:27:19Z | 38,995,409 | <p>Your my_package is not in PYTHONPATH. At the top of your test.py add the below. Note that any change in location of test.py would affect package_path</p>
<pre><code>from os.path import dirname, abspath
import sys
package_path = dirname(dirname(abspath(__file__)))
sys.path.append(package_path)
</code></pre>
| 0 | 2016-08-17T11:29:57Z | [
"python",
"packages"
] |
Unable to import child from parent package python | 38,995,363 | <p>I'm currently writing a web application in python that needs unit tests, however whenever I try to import a child module that's in another parent directory I get the following error:</p>
<pre><code>$ python my_package/tests/main.py
Traceback (most recent call last):
File "my_package/tests/test.py", line 1, in <... | 1 | 2016-08-17T11:27:19Z | 38,996,210 | <p>It is <strong><a href="https://github.com/amontalenti/elements-of-python-style#avoid-syspath-hacks" rel="nofollow">considered an anti-pattern</a></strong> to modify <code>sys.path</code>. If you want your package to be available to all subpackages, it's better to use <code>setup.py</code> development mode.
Create <c... | 4 | 2016-08-17T12:07:24Z | [
"python",
"packages"
] |
Add two variables in django templates? | 38,995,503 | <pre><code>{% with a=pro_details.product_quantity|add:product_details.product_quantity %}
</code></pre>
<p>I need to add two variables in django templates using with and add.</p>
| -2 | 2016-08-17T11:34:20Z | 38,997,576 | <p>You can use custom template tags for this to achieve.</p>
<p><strong>The templatetags/custom_tags.py file:</strong></p>
<pre><code>from django import template
register = template.Library()
@register.simple_tag
def add(a, b):
return a+b
</code></pre>
<p><strong>The template part, with our tag call:</strong><... | 3 | 2016-08-17T13:08:28Z | [
"python",
"django",
"templates"
] |
How to detect when pytest test case got AssertionError? | 38,995,522 | <p>I am using pytest to automate project test. I want to take some unique actions like "save_snapshot()" only when a test case fails. </p>
<p>Do we have something like that in pytest?</p>
<p>I have tried to achieve this using the teardown_method() But this method is not getting executed when a test case fails.</p>
<... | 1 | 2016-08-17T11:35:22Z | 39,249,323 | <p>I found a solution for this issue by using python decorator for each test in class:</p>
<pre><code>def is_failed_decorator(func):
def wrapper(*args, **kwargs):
try:
func(*args, **kwargs)
except AssertionError:
cls_obj = args[0]
cur_time = datetime.datetime.now... | 0 | 2016-08-31T12:12:12Z | [
"python",
"python-2.7",
"testing",
"py.test"
] |
Built a list of functions | 38,995,590 | <p>I post simple code in order to understand how solve my problem. The while loop have 2 cycle but in real case have billion cycle.</p>
<pre><code>def uno_trov():
if(1==1):
return True
else:
return False
def due_trov():
if(1==0):
... | -2 | 2016-08-17T11:38:55Z | 38,995,734 | <pre><code> condizioneV.append(uno_trov)
</code></pre>
<p>appends the function address you're missing the <code>()</code></p>
<p>correction:</p>
<pre><code>condizioneV.append(uno_trov())
</code></pre>
<p>General remark: your code is very poorly written and confusing. look at your <code>first_time</code> condition w... | 1 | 2016-08-17T11:45:39Z | [
"python",
"python-3.x"
] |
Built a list of functions | 38,995,590 | <p>I post simple code in order to understand how solve my problem. The while loop have 2 cycle but in real case have billion cycle.</p>
<pre><code>def uno_trov():
if(1==1):
return True
else:
return False
def due_trov():
if(1==0):
... | -2 | 2016-08-17T11:38:55Z | 38,995,770 | <p>That's some pretty convoluted code you have there. I can't imagine what it is trying to do. I'll presume you are a beginner.</p>
<p>But the reason your arrays contains functions is that these two lines are appending the functions themselves into the arrays, the functions are not being executed.</p>
<p>Instead of t... | 0 | 2016-08-17T11:47:17Z | [
"python",
"python-3.x"
] |
Built a list of functions | 38,995,590 | <p>I post simple code in order to understand how solve my problem. The while loop have 2 cycle but in real case have billion cycle.</p>
<pre><code>def uno_trov():
if(1==1):
return True
else:
return False
def due_trov():
if(1==0):
... | -2 | 2016-08-17T11:38:55Z | 38,996,709 | <p>Yes, this is a solution to one cycle but if you try to use it by pass a parameter to a function doesn't work anymore. I add "t=i" in the first if:</p>
<pre><code>def uno_trov(t):
if(1==t):
return True
else:
return False
def due_trov():
if(1==0):
... | 0 | 2016-08-17T12:29:24Z | [
"python",
"python-3.x"
] |
How to stop Python Websocket client "ws.run_forever" | 38,995,640 | <p>I'm starting my Python Websocket using "ws.run_forever", another <a href="https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.run_until_complete" rel="nofollow">source</a> stated that I should use "run_until_complete()" but these functions only seem available to Python asyncio.</p>
<p... | 0 | 2016-08-17T11:40:29Z | 38,995,641 | <p>In python websockets, you can use "ws.keep_running = False" to stop the "forever running" websocket.</p>
<p>This may be a little unintuitive and you may choose another library which may work better overall.</p>
<p>The code below was working for me (using ws.keep_running = False).</p>
<pre><code>class testingThrea... | 0 | 2016-08-17T11:40:29Z | [
"python",
"websocket"
] |
ImportError: No module named 'ase.build' | 38,995,718 | <p>In ubuntu 16.04 i installed python and modules:</p>
<pre><code>sudo apt install python3 python3-scipy python3-numpy python3-ase
</code></pre>
<p>then i try to follow <a href="https://wiki.fysik.dtu.dk/ase/tutorials/surface.html" rel="nofollow">the first tutorial</a> on the <a href="https://wiki.fysik.dtu.dk/ase/in... | 0 | 2016-08-17T11:44:43Z | 38,996,237 | <p>Check what version of the library you have.</p>
<pre><code>import ase
print(ase.__version__)
</code></pre>
<p>If the version is <code>3.10.0</code> then that is the problem since the <code>build</code> module appeared (as far as I know) in the <code>3.11.0</code> version.</p>
| 0 | 2016-08-17T12:08:35Z | [
"python",
"python-3.x"
] |
ImportError: No module named 'ase.build' | 38,995,718 | <p>In ubuntu 16.04 i installed python and modules:</p>
<pre><code>sudo apt install python3 python3-scipy python3-numpy python3-ase
</code></pre>
<p>then i try to follow <a href="https://wiki.fysik.dtu.dk/ase/tutorials/surface.html" rel="nofollow">the first tutorial</a> on the <a href="https://wiki.fysik.dtu.dk/ase/in... | 0 | 2016-08-17T11:44:43Z | 38,996,892 | <p>Due to <a href="http://packages.ubuntu.com/search?keywords=python3-ase" rel="nofollow">this link</a> - you have installed the 3.9.1.4567-3 version on your computer.</p>
<p>But The <strong>asu.build</strong> has been added in:</p>
<blockquote>
<p>commit 71c9563e423e2add645c26f8d0a722f3db13e135</p>
<p>Author:... | 0 | 2016-08-17T12:38:13Z | [
"python",
"python-3.x"
] |
detecting wrong file format with csv reader | 38,995,968 | <p>I like to read in a list of ASCII files (utf-8) with the csv reader.
For error handling i like to detect if a user has seleted by accident a file which cannot be read.
The source is like this:</p>
<pre><code> for File in Filenames:
print ('... processing file :',File)
with open(File, 'r') as csvfile:
... | 0 | 2016-08-17T11:56:22Z | 38,996,039 | <p>How about this: </p>
<pre><code>for File in Filenames:
print ('... processing file :',File)
with open(File, 'r') as csvfile:
try:
Reader = csv.reader(csvfile, delimiter = ';')
for Line in Reader:
print(Line)
except UnicodeDecodeError as e... | 1 | 2016-08-17T11:59:44Z | [
"python",
"csv"
] |
detecting wrong file format with csv reader | 38,995,968 | <p>I like to read in a list of ASCII files (utf-8) with the csv reader.
For error handling i like to detect if a user has seleted by accident a file which cannot be read.
The source is like this:</p>
<pre><code> for File in Filenames:
print ('... processing file :',File)
with open(File, 'r') as csvfile:
... | 0 | 2016-08-17T11:56:22Z | 38,996,040 | <p>Use exception handling - <a href="https://docs.python.org/3/tutorial/errors.html" rel="nofollow">https://docs.python.org/3/tutorial/errors.html</a></p>
<p>Your code would then look like:</p>
<pre><code>for File in Filenames:
print ('... processing file :',File)
try:
with open(File, 'r', encoding='u... | 0 | 2016-08-17T11:59:47Z | [
"python",
"csv"
] |
Python : Compare two csv files and print out differences | 38,996,033 | <p>I need to compare two CSV files and print out differences in a third CSV file.
In my case, the first CSV is a old list of hash named old.csv and the second CSV is the new list of hash which contains both old and new hash.</p>
<p>Here is my code :</p>
<pre><code>import csv
t1 = open('old.csv', 'r')
t2 = open('new.c... | 1 | 2016-08-17T11:59:36Z | 38,996,349 | <p>I assumed your new file was just like your old one, except that some lines were added in between the old ones. The old lines in both files are stored in the same order.</p>
<p>Try this :</p>
<pre><code>with open('old.csv', 'r') as t1:
old_csv = t1.readlines()
with open('new.csv', 'r') as t2:
new_csv = t2.r... | 0 | 2016-08-17T12:13:24Z | [
"python",
"csv"
] |
Python : Compare two csv files and print out differences | 38,996,033 | <p>I need to compare two CSV files and print out differences in a third CSV file.
In my case, the first CSV is a old list of hash named old.csv and the second CSV is the new list of hash which contains both old and new hash.</p>
<p>Here is my code :</p>
<pre><code>import csv
t1 = open('old.csv', 'r')
t2 = open('new.c... | 1 | 2016-08-17T11:59:36Z | 38,996,374 | <p>The problem is that you are comparing each line in <code>fileone</code> to the same line in <code>filetwo</code>. As soon as there is an extra line in one file you will find that the lines are never equal again. Try this:</p>
<pre><code>with open('old.csv', 'r') as t1, open('new.csv', 'r') as t2:
fileone = t1... | 1 | 2016-08-17T12:14:29Z | [
"python",
"csv"
] |
Reading python variables during a running job | 38,996,051 | <p>I have launched a python script that takes a long time to finish, and silly me I forgot to print out the values of important variables every now and then in my script, to for example estimate the progress of the computation I'm doing.
So now, I was wondering if there's a way to access the current values of certain ... | 5 | 2016-08-17T12:00:26Z | 38,996,231 | <p>Without editing your program, you're going to have a bad time. What you are looking for is some form of remote debugger, but anything that gives you python specific things will probably have to be at least somehow given a hook into your program. That being said, if you feel like fiddling around in a stack, you can a... | 7 | 2016-08-17T12:08:14Z | [
"python",
"shell"
] |
Python multiprocessing: process a list of input files with error logging | 38,996,137 | <p>I want to use python multiprocessing to conduct the following:</p>
<ul>
<li>process a long list of input files </li>
<li>include error logging </li>
<li>set a limit on the concurrent CPU cores in use (number of processes)</li>
</ul>
<p>The <a href="https://docs.python.org/3/howto/logging-cookbook.html#logging-to-a... | 0 | 2016-08-17T12:04:17Z | 39,966,621 | <p>I found that using python multiprocessing Pool instead of Queue allowed me to process a long list of files, and limit the number of concurrent cores.</p>
<p>Although logging is not compatible with Pool, I found that it is possible to collect the return values. The return values can be logged after all files have be... | 0 | 2016-10-10T20:56:13Z | [
"python",
"logging",
"python-multiprocessing",
"error-logging"
] |
Merging of two lists following certain patterns | 38,996,316 | <p>I have two lists:</p>
<pre><code>a = ['a', 'b', 'c', 'd']
b = ['e', 'f', 'g', 'h']
</code></pre>
<p>which I want to merge to one list which contains element nr. 1 of list a as first element, element nr.1 of list b as second element, element nr. 2 of list a as third element and so on, looking like this:</p>
<pre><... | 0 | 2016-08-17T12:12:17Z | 38,996,411 | <p>Borrowing from <a href="http://stackoverflow.com/a/952946/2285236">this answer</a>:</p>
<pre><code>list(sum(zip(a, b), ()))
Out: ['a', 'e', 'b', 'f', 'c', 'g', 'd', 'h']
</code></pre>
| 9 | 2016-08-17T12:16:13Z | [
"python"
] |
Merging of two lists following certain patterns | 38,996,316 | <p>I have two lists:</p>
<pre><code>a = ['a', 'b', 'c', 'd']
b = ['e', 'f', 'g', 'h']
</code></pre>
<p>which I want to merge to one list which contains element nr. 1 of list a as first element, element nr.1 of list b as second element, element nr. 2 of list a as third element and so on, looking like this:</p>
<pre><... | 0 | 2016-08-17T12:12:17Z | 38,996,416 | <p>Just <a href="https://docs.python.org/3/library/functions.html#zip"><code>zip</code></a> them into pairs and then flatten the list using <a href="https://docs.python.org/3.5/library/itertools.html#itertools.chain.from_iterable"><code>itertools.chain.from_iterable</code></a>:</p>
<pre><code>In [1]: a=['a','b','c','d... | 5 | 2016-08-17T12:16:36Z | [
"python"
] |
Merging of two lists following certain patterns | 38,996,316 | <p>I have two lists:</p>
<pre><code>a = ['a', 'b', 'c', 'd']
b = ['e', 'f', 'g', 'h']
</code></pre>
<p>which I want to merge to one list which contains element nr. 1 of list a as first element, element nr.1 of list b as second element, element nr. 2 of list a as third element and so on, looking like this:</p>
<pre><... | 0 | 2016-08-17T12:12:17Z | 38,997,009 | <p>Here's an answer comparing some of the possible methods with 2 differents datasets, one will consist of many little arrays, the other one will be few large arrays:</p>
<p>import timeit
import random
from itertools import chain</p>
<pre><code>def f1(a, b):
return list(chain.from_iterable(zip(a, b)))
d... | 2 | 2016-08-17T12:43:41Z | [
"python"
] |
Pearson multiple correlation with Scipy | 38,996,366 | <p>I am trying to do something quite simple compute a Pearson correlation matrix of several variables that are given as columns of a DataFrame. I want it to ignore nans and provide also the p-values. <code>scipy.stats.pearsonr</code> is insufficient because it works only for two variables and cannot account for nans. T... | 0 | 2016-08-17T12:14:19Z | 38,999,002 | <p>If you have your data in a pandas DataFrame, you can simply use <code>df.corr()</code>.</p>
<p>From the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.corr.html" rel="nofollow">docs</a>:</p>
<pre><code>DataFrame.corr(method='pearson', min_periods=1)
Compute pairwise correlation of ... | 1 | 2016-08-17T14:07:28Z | [
"python",
"scipy",
"pearson-correlation"
] |
sorting list of tuple based on engineering unit | 38,996,396 | <p>I am trying to sort list into following way.</p>
<pre><code>data = [('18.3G', 'pgaur'), ('29.6G', 'adsoni'), ('5.51G', 'keyur'), ('10.8G', 'adityac')]
sorted(data, key= lambda x:x[0])
</code></pre>
<p>but it is not sorting data.</p>
| 1 | 2016-08-17T12:15:28Z | 38,996,622 | <p>To sort numbers in the way that makes sense to humans, you have to make sure that they are presented as numbers and not as text:</p>
<ul>
<li>e.g., '5' is a string representing a number, not a number so
<code>example_list = ['5', '10']</code> if sorted would yield `['10', '5']
because what's compared is '5' against... | 2 | 2016-08-17T12:25:34Z | [
"python",
"python-2.7"
] |
sorting list of tuple based on engineering unit | 38,996,396 | <p>I am trying to sort list into following way.</p>
<pre><code>data = [('18.3G', 'pgaur'), ('29.6G', 'adsoni'), ('5.51G', 'keyur'), ('10.8G', 'adityac')]
sorted(data, key= lambda x:x[0])
</code></pre>
<p>but it is not sorting data.</p>
| 1 | 2016-08-17T12:15:28Z | 38,996,737 | <pre><code>sorted(data, key= lambda x:float(x[0][:][:-1]))
</code></pre>
<p>Will give you what you want.</p>
<p>This is sorting by the first element of the tuple x[0]
[:] copies the rest of the tuple, [:-1] up to the last digit (excludes G)</p>
| 1 | 2016-08-17T12:30:50Z | [
"python",
"python-2.7"
] |
sorting list of tuple based on engineering unit | 38,996,396 | <p>I am trying to sort list into following way.</p>
<pre><code>data = [('18.3G', 'pgaur'), ('29.6G', 'adsoni'), ('5.51G', 'keyur'), ('10.8G', 'adityac')]
sorted(data, key= lambda x:x[0])
</code></pre>
<p>but it is not sorting data.</p>
| 1 | 2016-08-17T12:15:28Z | 38,996,750 | <p>Ideally you need a key function that returns a numeric value. Let's suppose that you can use <code>k</code>, <code>m</code> and <code>g</code> as multipliers. This code does no error checking which is, as usual, left as an exercise for the reader.</p>
<pre><code>def sortkey(pair):
num = pair[0][:-1]
mult = ... | 1 | 2016-08-17T12:31:25Z | [
"python",
"python-2.7"
] |
Parameter restrictions for Nelson-Siegel yield curve in quantlib | 38,996,422 | <p>I am using QL in Python and have translated parts of the example file
<a href="http://quantlib.org/reference/_fitted_bond_curve_8cpp-example.html#_a25" rel="nofollow">http://quantlib.org/reference/_fitted_bond_curve_8cpp-example.html#_a25</a>;
of how to fit a yield curve with bonds in order to fit a Nelson-Siegel
yi... | 1 | 2016-08-17T12:16:46Z | 39,012,011 | <p>Thanks to Andres Hernandez for the answer:</p>
<p>Currently it is not possible. However, it is very easy to extend QL to allow it, but I think it needs to be done on the c++. So even though you are using QL in python, can you modify the c++ code and export a new binding? If yes, then you can use the following code,... | 1 | 2016-08-18T07:13:26Z | [
"python",
"quantlib"
] |
Error with backquotes when import parser from dateutil with Python3.5 | 38,996,464 | <p>I used Tensorflow. It was working.
After I installed Caffe (with all dependencies) my old TF projects stopped working.</p>
<p>The root cause is:</p>
<pre><code>from dateutil import parser as _date_parser
</code></pre>
<p>gives</p>
<pre><code>/usr/bin/python3.5 /data/PycharmProjects/tensorflow/test/test1.py
Trace... | 0 | 2016-08-17T12:18:25Z | 38,996,589 | <p>Is it possible that installing your Caffe updated Python? A L-O-O-N-G time ago Python used backticks as a shortcut for calling the <code>repr</code> function on its argument. Replacing the backtick-quoted expression with <code>repr(value)</code> might be all you need.</p>
| 0 | 2016-08-17T12:24:19Z | [
"python",
"parsing",
"tensorflow",
"python-module"
] |
How do I access a custom reverse model manager in a template? | 38,996,580 | <p>Given the following models:</p>
<pre><code>class Author(models.Model):
name = models.CharField(max_length=20)
class CustomQuerySet1(models.QuerySet):
def some_method(self):
return 'custom queryset 1'
class CustomQuerySet2(models.QuerySet):
def some_method(self):
return 'custom queryset... | 1 | 2016-08-17T12:23:48Z | 38,996,852 | <p>There is none and I think it won't (because it shouldn't).
Template is a place where data is finally presented, so it should all be prepared and template markup only used to present it in a convenient way.</p>
<p>However, it can be a nice idea for a template filter.</p>
| 0 | 2016-08-17T12:36:37Z | [
"python",
"django"
] |
Quick sort using median as pivot working (but shows incorrect count for comaprisons) | 38,996,606 | <p>I am using Quick sort in python to sort a list of numbers.This has to be done using the median as the pivot.
How am i finding the median ?
It is the second largest no.(out of a list of 3 numbers which are first,middle and last element of the original list)</p>
<p>If the list is of length even(2j),the middle no will... | 0 | 2016-08-17T12:24:54Z | 39,024,597 | <p>I believe I've found the critical problem: <strong>find_median</strong> grabs the left and right elements of the given list, but then adds the middle element of the <em>original</em> list. Thus, if you're looking to sort list positions 5:7, you grab elements 5, 7, and 3. The last should be element 6. This is like... | 1 | 2016-08-18T17:51:04Z | [
"python",
"recursion",
"quicksort",
"median"
] |
What does _com_interfaces_ do? | 38,996,617 | <p>I'm trying to understand the COM server examples of <a href="/questions/tagged/pywin32" class="post-tag" title="show questions tagged 'pywin32'" rel="tag">pywin32</a>, and in <code>win32comext/shell/demos/servers/icon_handler.py</code> I saw the line</p>
<pre><code>_com_interfaces_ = [shell.IID_IExtractIcon... | 1 | 2016-08-17T12:25:21Z | 38,996,764 | <p><code>_com_interfaces_</code> is an optional attribute a <a href="http://docs.activestate.com/activepython/2.6/pywin32/html/com/win32com/HTML/QuickStartServerCom.html#Policies" rel="nofollow">Server Policy</a> looks for:</p>
<blockquote>
<p><code>_com_interfaces_</code></p>
<p>Optional list of IIDs exposed b... | 2 | 2016-08-17T12:32:04Z | [
"python",
"pywin32",
"shell-extensions",
"com-server",
"icon-handler"
] |
Python mmap object complains of a string pattern on Python 3.5.2 (not in Python 2.6.6) | 38,996,646 | <p>I have the following code:</p>
<pre><code>def grep(pattern, file_path):
with io.open(file_path, "r", encoding="utf-8") as f:
file_size = os.path.getsize(file_path)
mm = mmap.mmap(f.fileno(), file_size, access=mmap.ACCESS_READ)
return re.search(pattern, mm)
</code></pre>
<p>With P... | 2 | 2016-08-17T12:26:53Z | 39,007,514 | <p>The simplest way would probably be to just encode to utf-8:</p>
<pre><code>def grep(pattern, file_path):
pattern = pattern.encode("utf-8")
with io.open(file_path, "r", encoding="utf-8") as f:
file_size = os.path.getsize(file_path)
mm = mmap.mmap(f.fileno(), file_size, access=mmap.ACCESS_REA... | 2 | 2016-08-17T23:01:24Z | [
"python",
"regex",
"performance",
"mmap"
] |
Python mmap object complains of a string pattern on Python 3.5.2 (not in Python 2.6.6) | 38,996,646 | <p>I have the following code:</p>
<pre><code>def grep(pattern, file_path):
with io.open(file_path, "r", encoding="utf-8") as f:
file_size = os.path.getsize(file_path)
mm = mmap.mmap(f.fileno(), file_size, access=mmap.ACCESS_READ)
return re.search(pattern, mm)
</code></pre>
<p>With P... | 2 | 2016-08-17T12:26:53Z | 39,537,491 | <p><code>bytes</code> can be raw literals too. If your pattern is only used with the <code>mmap</code> (or other <code>bytes</code>-like things), you can just use <code>br'approved="no"'</code>, which is supported on 2.6 and later just fine (the <code>b</code> is redundant on Py2.x normally, but it means something to t... | 1 | 2016-09-16T17:54:41Z | [
"python",
"regex",
"performance",
"mmap"
] |
From a sentence group all words that start with same alphabet and and sort it according to first character of the word | 38,996,697 | <p>suppose I take a string input from the user , and if will then group all the words in that sentence with respect to first character of the word and later we have to display the o/p as dictionary , No repetition of words is allowed .
For example consider i/p string <code>a="A cat ran after the dog and died due to i... | 1 | 2016-08-17T12:28:46Z | 38,996,889 | <p>You could simplify your code a little but apart from that it's ok</p>
<pre><code>from collections import defaultdict
a="A cat ran after the dog and died due to injury"
c=defaultdict(list)
for x in set(a.split()): # no need to sort unless you create an OrderedDict which you didn't
c[x[0]].append(x)
print (c)
<... | 3 | 2016-08-17T12:37:54Z | [
"python",
"algorithm",
"python-3.x"
] |
From a sentence group all words that start with same alphabet and and sort it according to first character of the word | 38,996,697 | <p>suppose I take a string input from the user , and if will then group all the words in that sentence with respect to first character of the word and later we have to display the o/p as dictionary , No repetition of words is allowed .
For example consider i/p string <code>a="A cat ran after the dog and died due to i... | 1 | 2016-08-17T12:28:46Z | 38,997,510 | <pre><code>res = {}
for a in "A cat ran after the dog and died due to injury".split():
k = a[0]
try: res[k].add(a)
except KeyError: res[k] = {a}
print(res)
</code></pre>
| 1 | 2016-08-17T13:05:29Z | [
"python",
"algorithm",
"python-3.x"
] |
Find list items in excel sheet with Python | 38,996,708 | <p>I've the following code below which finds non-blank values in Column J of an Excel worksheet. It does some things with it, including getting the value's email address in column K. Then it emails the member using smtp.</p>
<p>What I'd like instead is to get the person's email from a Python list, which can be decla... | 0 | 2016-08-17T12:29:23Z | 38,997,154 | <p>This is my attempt at an answer.</p>
<p><code>memlist</code> is not a <code>list</code>, rather it is a <code>dict</code> because it contains <code>key : value</code> pairs.</p>
<p>If you want to check that a certain key exists in a <code>dict</code>, you can use <code>dict.has_key(key)</code> method.</p>
<p>In <... | 0 | 2016-08-17T12:51:06Z | [
"python",
"excel",
"smtp"
] |
Find list items in excel sheet with Python | 38,996,708 | <p>I've the following code below which finds non-blank values in Column J of an Excel worksheet. It does some things with it, including getting the value's email address in column K. Then it emails the member using smtp.</p>
<p>What I'd like instead is to get the person's email from a Python list, which can be decla... | 0 | 2016-08-17T12:29:23Z | 38,998,760 | <p>Shubham,
I used a part of your response in finding my own answer. Instead of the has_key method, I just used another for/in statement with a subsequent if statement.</p>
<p>My fear, however, is that with these multiple for's and if's, the code takes a long time to run and maybe not the most efficient/optimal. But ... | 0 | 2016-08-17T13:56:42Z | [
"python",
"excel",
"smtp"
] |
Django 1.10 RequestContext processors not working | 38,996,878 | <p>After updating to django 1.10, processors stop working.</p>
<p>This menu context for many views:</p>
<pre><code>def menu_category(request):
category_parent = Category.objects.filter(parent__isnull=True, is_active=True).order_by('mass')
category_child = Category.objects.filter(parent__isnull=False, is_activ... | 1 | 2016-08-17T12:37:24Z | 38,997,190 | <p>You should never have been passing a RequestContext to <code>render_to_response</code>, and Django 1.10 has made that an error. Instead use the <code>render</code> shortcut:</p>
<pre><code>return render(request, 'news/news_main.html', {'posts': posts})
</code></pre>
<p>Note that whenever you upgrade a version you ... | 1 | 2016-08-17T12:52:29Z | [
"python",
"django"
] |
Tensorflow CSV decode error | 38,996,904 | <p>I am using TensorFlow 0.10.0rc0. I have CUDA Driver Version = 7.5 and CUDNN 4 on Ubuntu 14.04.</p>
<p>I have a simple CSV file which has a single line like this:</p>
<pre><code>"field with
newline",0
</code></pre>
<p>where the newline has been added by pressing the enter key in VIM on Ubuntu.
I am able to read th... | 0 | 2016-08-17T12:38:45Z | 38,998,494 | <p>TensorFlow's CSV reader is pretty strict, in my experience with it, with regards to RFC4180.</p>
<p>Making sure your files use CRLF at the end of each line, as well as in quoted fields, should allow processing.</p>
<p>Note: I have been using this up to 0.9 so far. I did not try on RCs from 0.10.</p>
| 0 | 2016-08-17T13:47:00Z | [
"python",
"csv",
"tensorflow"
] |
Set a condition from inside of a loop Jinja2 | 38,996,912 | <pre><code> <ul>
{% for bm in user.bookmarks %}
<li>
<a href="{{ bm.url }}">{{ bm.description }}</a>
</li>
{% else %}
<li>This user has not added any bookmarks yet.</li>
{% endfor %}
</ul>... | 0 | 2016-08-17T12:38:59Z | 38,997,000 | <p>You can put the <code>ul</code> tags inside the loop, and use the <code>loop.first</code> and <code>loop.last</code> variables to control them.</p>
<pre><code>{% for bm in user.bookmarks %}
{% if loop.first %}
<ul>
{% endif %}
<li>
<a href="{{ bm.url }}">{{ bm.description }... | 1 | 2016-08-17T12:43:22Z | [
"python",
"templates",
"jinja2"
] |
Set a condition from inside of a loop Jinja2 | 38,996,912 | <pre><code> <ul>
{% for bm in user.bookmarks %}
<li>
<a href="{{ bm.url }}">{{ bm.description }}</a>
</li>
{% else %}
<li>This user has not added any bookmarks yet.</li>
{% endfor %}
</ul>... | 0 | 2016-08-17T12:38:59Z | 39,208,578 | <pre><code>{% if user.bookmarks %}
<ul>
{% for bm in user.bookmarks %}
<li>
<a href="{{ bm.url }}">{{ bm.description }}</a>
</li>
{% else %}
<li>This user has not added any bookmarks yet.</li>
{% endfo... | 0 | 2016-08-29T14:21:37Z | [
"python",
"templates",
"jinja2"
] |
Pandas: get some data from dataframe | 38,996,921 | <p>I have dataframe <code>ID,"month","type"
0896cbe25bb8aec86ff93dd1bf20fa80,2013-12,desktop
0896cbe25bb8aec86ff93dd1bf20fa80,2014-01,desktop
0896cbe25bb8aec86ff93dd1bf20fa80,2014-02,desktop
0896cbe25bb8aec86ff93dd1bf20fa80,2014-03,desktop
0ce926c4c33e63aeef04a55dc204cb1a,2014-06,desktop
0ce926c4c33e63aeef04a55dc204cb1... | -1 | 2016-08-17T12:39:39Z | 38,997,498 | <p>Not sure it'll be very effective on big dataframes,
but you may add a special "merge" column to df2:</p>
<pre><code> >>> df2['year_month'] = df2.year.astype(str) + '-' + df2.month.astype(int).apply(lambda s: '%02d' % s)
>>> df2
idp year month year_month
... | 0 | 2016-08-17T13:05:01Z | [
"python",
"pandas"
] |
Django multiple sites : Prevent cross-site authentification | 38,997,004 | <p>I'm currently developing 2 different sites at the same time: one of them is a heavily customized django-admin interface, and the other a "stand-alone" website that will share it's database with the previous one .</p>
<p>Even though they are related, I'd like my users not to loosely identify between the two sites : ... | 0 | 2016-08-17T12:43:30Z | 38,998,750 | <p>Put different <code>SESSION_COOKIE_DOMAIN</code> and <code>SESSION_COOKIE_NAME</code> for each appication. Hope this solve your issue.</p>
<pre><code>SESSION_COOKIE_DOMAIN = 'site1.com' #site2.com for other
SESSION_COOKIE_NAME = 'sid1' #sid2 for other
</code></pre>
| 1 | 2016-08-17T13:56:16Z | [
"python",
"django",
"django-admin",
"django-authentication"
] |
sqlalchemy insert data does not work | 38,997,016 | <p>In models.py I have define:</p>
<pre><code>class slidephoto(db.Model):
__tablename__ = 'slide_photo'
id = db.Column(db.Integer, primary_key=True)
uid = db.Column(db.Integer, nullable=False)
photo = db.Column(db.String(collation='utf8_bin'), nullable=False)
def __init__(self, uid, photo):
... | 2 | 2016-08-17T12:44:02Z | 39,014,748 | <p>I write a simple demo that do insert work, you can take it as a reference:</p>
<pre><code>from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class FirstTest(db.Model):
__tablename__ = "first_test"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String,... | 0 | 2016-08-18T09:36:17Z | [
"python",
"database",
"insert",
"sqlalchemy"
] |
sqlalchemy insert data does not work | 38,997,016 | <p>In models.py I have define:</p>
<pre><code>class slidephoto(db.Model):
__tablename__ = 'slide_photo'
id = db.Column(db.Integer, primary_key=True)
uid = db.Column(db.Integer, nullable=False)
photo = db.Column(db.String(collation='utf8_bin'), nullable=False)
def __init__(self, uid, photo):
... | 2 | 2016-08-17T12:44:02Z | 39,014,848 | <p>You should use query as a method. Like 'query()'</p>
| 0 | 2016-08-18T09:40:45Z | [
"python",
"database",
"insert",
"sqlalchemy"
] |
sqlalchemy insert data does not work | 38,997,016 | <p>In models.py I have define:</p>
<pre><code>class slidephoto(db.Model):
__tablename__ = 'slide_photo'
id = db.Column(db.Integer, primary_key=True)
uid = db.Column(db.Integer, nullable=False)
photo = db.Column(db.String(collation='utf8_bin'), nullable=False)
def __init__(self, uid, photo):
... | 2 | 2016-08-17T12:44:02Z | 39,019,137 | <p>I hope that my answer will help you solving the problem.</p>
<pre><code>from sqlalchemy import create_engine, MetaData, Table, insert
# I have tested this using my local postgres db.
engine = create_engine('postgresql://localhost/db', convert_unicode=True)
metadata = MetaData(bind=engine)
con = engine.connect()
act... | 0 | 2016-08-18T13:09:49Z | [
"python",
"database",
"insert",
"sqlalchemy"
] |
Profit and loss using pandas | 38,997,043 | <p>I have a dataframe containing data like this:</p>
<pre><code> open close signal
date_time
2011-01-03 01:04:00 1.5560 1.5556 0.0
2011-01-03 01:05:00 1.5557 1.5556 0.0
2011-01-03 01:06:00 1.5557 1.5556 1.0
2011-01-03 01:... | 1 | 2016-08-17T12:45:18Z | 39,005,976 | <p>I don't quite understand the buy/sell hold (perhaps you have an error in your sell time?), but this should get you close as an idea. The key is to compute an array 'units' that indicates if you are holding stock or not. Then the rest should work OK. Each day you either change value (.99 or 1.01, e.g. based on sto... | 0 | 2016-08-17T20:45:30Z | [
"python",
"pandas",
"numpy"
] |
add new column and remove duplicates in that replace null values column wise | 38,997,069 | <pre><code>Duplication type:
Check this column only (default)
Check other columns only
Check all columns
Use Last Value:
True - retain the last duplicate value
False - retain the first of the duplicates (default)
</code></pre>
<p>This rule should add a new column to the dataframe which contains the same as the source... | 4 | 2016-08-17T12:46:37Z | 38,998,853 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.duplicated.html" rel="nofollow"><code>DF.duplicated</code></a> and assign the values of column C where the first occurence of values appears along columns A and B. </p>
<p>You could then fill the <code>Nans</code> produced w... | 1 | 2016-08-17T14:00:43Z | [
"python",
"pandas"
] |
Differences between `open(fname, 'r').close()` and `os.path.isfile(fname)` | 38,997,213 | <p>I have to check the presence and readable of multiple files. Which is the most efficient way to do it?</p>
<pre><code>list_of_files = [fname1,fname2,fname3]
for fname in list_of_files:
try:
open(fname, 'r').close()
except IOError:
raise YourCustomError
</code></pre>
<p>or</p>
<pre><code>li... | 1 | 2016-08-17T12:53:11Z | 38,997,305 | <p>There is a common philosophy - execute and ask for forgiveness than asking for permission before hand. </p>
<p>The first approach tries to open the file in readable mode and fails if it doesn't exist or not readable. Here we're asking for forgiveness after the operation fails. </p>
<p>In the second approach, we ar... | 1 | 2016-08-17T12:57:34Z | [
"python",
"file-processing"
] |
Differences between `open(fname, 'r').close()` and `os.path.isfile(fname)` | 38,997,213 | <p>I have to check the presence and readable of multiple files. Which is the most efficient way to do it?</p>
<pre><code>list_of_files = [fname1,fname2,fname3]
for fname in list_of_files:
try:
open(fname, 'r').close()
except IOError:
raise YourCustomError
</code></pre>
<p>or</p>
<pre><code>li... | 1 | 2016-08-17T12:53:11Z | 38,997,311 | <blockquote>
<p>I have to check the presence and readable of multiple files. Which is the most efficient way to do it?</p>
</blockquote>
<p>It's not just a question of efficiency, as your two approaches don't do the same thing. A file might <a href="https://www.linux.com/learn/understanding-linux-file-permissions" r... | 1 | 2016-08-17T12:57:43Z | [
"python",
"file-processing"
] |
Differences between `open(fname, 'r').close()` and `os.path.isfile(fname)` | 38,997,213 | <p>I have to check the presence and readable of multiple files. Which is the most efficient way to do it?</p>
<pre><code>list_of_files = [fname1,fname2,fname3]
for fname in list_of_files:
try:
open(fname, 'r').close()
except IOError:
raise YourCustomError
</code></pre>
<p>or</p>
<pre><code>li... | 1 | 2016-08-17T12:53:11Z | 38,997,577 | <p>If you plan on <em>using</em> those files then <strong>neither</strong>. Files may be deleted or permissions changed between your call and when you use the file, making that information obsolete. Instead just try to use the file and handle the exception there:</p>
<pre><code>try:
with open(fname, 'r') as f:
... | 2 | 2016-08-17T13:08:29Z | [
"python",
"file-processing"
] |
Python: Convert map in kilometres to degrees | 38,997,228 | <p>I have a pandas Dataframe with a few million rows, each with an X and Y attribute with their location in kilometres according to the WGS 1984 World Mercator projection (created using ArcGIS).</p>
<p>What is the easiest way to project these points back to degrees, without leaving the Python/pandas environment?</p>
| -2 | 2016-08-17T12:53:43Z | 39,000,572 | <p>There is already a python module that can do these kind of transformations for you called <a href="https://github.com/jswhit/pyproj" rel="nofollow">pyproj</a>. I will agree it is actually not the simplest module to find via google. Some examples of its use can be seen <a href="http://gis.stackexchange.com/questions/... | 0 | 2016-08-17T15:19:51Z | [
"python",
"pandas",
"projection",
"degrees"
] |
Django-tinyMCE Submit button not working | 38,997,237 | <p>I've implemented TinyMCE with the django-tinymce package. However, my submit button which worked fine without TinyMCE now has become rather useless since I can't submit the form, once everything is filled out. </p>
<p>I can use Ctrl + S inside of TinyMCE (I discovered that by accident) and everything will get submi... | 0 | 2016-08-17T12:54:21Z | 39,836,162 | <p>I also had the same issue as yours, and I just removed for instance: "wiki_page" charfield from the subclass of Modelform, and put Tinymce widget in the Meta class. </p>
<pre><code>class MediwikiForm(ModelForm):
class Meta:
model = Mediwikiâ
fields = '__all__'
widgets = {
'wiki_page': Ti... | -1 | 2016-10-03T16:25:03Z | [
"javascript",
"jquery",
"python",
"django",
"django-tinymce"
] |
Permission error when installing textblob | 38,997,459 | <p>This command:</p>
<pre><code>python -m pip install textblob
</code></pre>
<p>gave this error: </p>
<blockquote>
<p>error: could not create '/Library/Python/2.7/site-packages/nltk': Permission denied</p>
</blockquote>
<p>and </p>
<p><code>Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__... | -2 | 2016-08-17T13:03:32Z | 38,997,526 | <p>Try with permission.</p>
<pre><code>sudo pip install textblob
</code></pre>
| 0 | 2016-08-17T13:06:20Z | [
"python",
"python-2.7",
"pip",
"nltk"
] |
Permission error when installing textblob | 38,997,459 | <p>This command:</p>
<pre><code>python -m pip install textblob
</code></pre>
<p>gave this error: </p>
<blockquote>
<p>error: could not create '/Library/Python/2.7/site-packages/nltk': Permission denied</p>
</blockquote>
<p>and </p>
<p><code>Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__... | -2 | 2016-08-17T13:03:32Z | 38,997,566 | <p>The error is caused because the user you logged-in doesn't have appropriate permissions to do this, so do it with sudo or su</p>
<pre><code>sudo pip install textblob
</code></pre>
<p>or you can first switch as root user and then fire the command: </p>
<pre><code>su
pip install textblob
</code></pre>
| 0 | 2016-08-17T13:07:57Z | [
"python",
"python-2.7",
"pip",
"nltk"
] |
mean of the probability activation for each day of a week with python | 38,997,548 | <p>I have a dataframe df with this structure : </p>
<pre><code>TIMESTAMP probab-activ1 probab-activ3 probab-activ5
2015-07-31 23:00:00 90.0 90.0 90.0
2015-07-31 23:10:00 0.0 0.0 0.0
2015-07-31 23:20:00 0.0 0.0 0.0
2015-07-31 23:30:00 0.0 0.0 0.0
2015-07-31 23:40:00 0.0 0.0 0.0
...
2015-10-31 23:20:00 0.0 0.0... | -3 | 2016-08-17T13:07:25Z | 38,997,985 | <p>You can use the <code>datetime</code> module and convert your timestamp to a format that is useful for your purpose. For example, you could do:</p>
<pre><code>import datetime
timestamp = '2015-07-31 23:00:00'
day_of_week = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S').strftime('%a')
day_of_week
'Fri'... | 0 | 2016-08-17T13:25:05Z | [
"python",
"dataframe"
] |
Reuse a logistic regression object for different fitted models | 38,997,591 | <p>I have a <code>Pipeline</code> object that I want to fit on different combinations of training and test labels and thus using the <code>fit</code> objects, create different predictions. But I believe that <code>fit</code> using the same classifier object gets rid of previous <code>fit</code> objects.</p>
<p>An exam... | 0 | 2016-08-17T13:09:24Z | 38,998,464 | <p>I would try</p>
<pre><code>text_clf0=copy.deepcopy(text_clf)
open_multi_logit_threshold_words = text_clf0.fit(train_wordlist, train_property_labels_threshold)
</code></pre>
<p>EDIT: you can use a list</p>
<pre><code>text_clf_list=[copy.deepcopy(text_clf) for _ in range(16)]
</code></pre>
<p>or directly</p>
<pre... | 1 | 2016-08-17T13:45:51Z | [
"python",
"scikit-learn",
"logistic-regression",
"text-classification"
] |
Django tutorial part 3 - NoReverseMatch at /polls/ | 38,997,600 | <p>I have been following the <a href="https://docs.djangoproject.com/en/1.10/intro/tutorial03/" rel="nofollow">Django tutorial part 3</a> and am getting the following error when I attempt to view <a href="http://localhost:8000/polls/" rel="nofollow">http://localhost:8000/polls/</a>:</p>
<pre><code>**Reverse for 'detai... | 2 | 2016-08-17T13:09:37Z | 38,999,003 | <p>This was the problem:</p>
<p>polls/templates/polls/index.html should have been:</p>
<pre><code>{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
{% ... | 1 | 2016-08-17T14:07:30Z | [
"python",
"html",
"django",
"python-2.7"
] |
NLTK Lemmatizing with list comprehension | 38,997,658 | <p>How can I verify whether I am correctly using the NLTK lemmatizer in this list comprehension, specifically whether it is taking account of the POS tags?</p>
<pre><code>clean_article_string = (article_db.loc[0,'clean_text']) # pandas dataframe cell containing string.
tokens = word_tokenize(clean_article_string)
tree... | 0 | 2016-08-17T13:12:00Z | 39,081,102 | <p>Answer by ewcz in comments. Labelled as community wiki. This helped me, might help others.</p>
<hr>
<p>You use <code>lemmatizer.lemmatize(w)</code>, then it will use the default POS tag n, the error suggests that some of the tags are empty - in this case, perhaps one could use a fallback to nouns, i.e., to use
<c... | 0 | 2016-08-22T13:38:14Z | [
"python",
"nltk",
"wordnet"
] |
Else not working in IPython | 38,997,873 | <p><a href="http://i.stack.imgur.com/C8XLQ.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/C8XLQ.jpg" alt="enter image description here"></a>I'm new in Python. I'm trying to use an else statement in IPython but I get an error message:
"Identation error: unindent does not match any outer identation level." I have... | -4 | 2016-08-17T13:20:00Z | 38,998,030 | <p>IPython auto-indents blocks for compound statements, so to enter the <code>else:</code> line you have to manually <em>unindent</em> again.</p>
<p>I can only reproduce your error if I do not un-indent properly; hitting backspace between 1 and 3 times, instead of 4.</p>
<p>Note the extra space before <code>else:</co... | 1 | 2016-08-17T13:27:02Z | [
"python",
"ipython"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.