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
tf.contrib.learn.RunConfig(save_checkpoints_secs=1)) throws unexpected keyword TypeError
39,827,664
<p>As per the instructions at <a href="https://www.tensorflow.org/versions/r0.10/tutorials/monitors/index.html" rel="nofollow">https://www.tensorflow.org/versions/r0.10/tutorials/monitors/index.html</a> I have added a monitor to the training script as such:</p> <pre><code>tf.contrib.learn.DNNClassifier(model_dir=model...
0
2016-10-03T08:48:38Z
39,827,799
<p>Apparently, you're running a version of tensorflow that is &lt; <code>0.10</code>. Versions below <code>0.10</code> do not take a <code>save_checkpoints_secs</code> keyword for <code>RunConfig</code> initialization.</p> <p>You should upgrade your <code>tensorflow</code> installation:</p> <p><a href="http://stackov...
0
2016-10-03T08:55:49Z
[ "python", "tensorflow" ]
Cryptography with ASCII in python 3
39,827,719
<p>Hello there and thanks in advance.</p> <p>i'm trying to making a cryptography program i have to do for school. i'm not a advanced python expert, so i'm sorry if this is a silly question. when i run this program and insert for example abc with shift 2 it will return cde which is good. but i tried to insert xyz aswel...
0
2016-10-03T08:51:18Z
39,827,937
<p>It is because your logic expression is wrong. Here is an example that will allow any positive integer as right shift, beginning again at a again. And it can be very much optimized (hint: use modulo operator), but this is with minor changes to your code and numerics written out loud.</p> <pre><code>for x in alf: a...
0
2016-10-03T09:03:40Z
[ "python", "python-3.x", "loops", "ascii" ]
global and local variables misconception
39,827,768
<p>I have a question regarding the output from the following code:</p> <pre><code>def f(): global s print(s) s = "That's clear." print(s) s = "Python is great!" f() print(s) </code></pre> <p>The output is this:</p> <blockquote> <p>Python is great!</p> <p>That's clear.</p> <p>That's ...
-2
2016-10-03T08:54:15Z
39,828,091
<p>Assuming you have declared the variable <code>s = "Python is great!"</code> globally. You may not have indented the code properly, the below code:</p> <pre><code>def f(): global s print(s) s = "That's clear." print(s) s = "Python is great!" f() print(s) </code></pre> <p>Will give you the ...
-1
2016-10-03T09:12:50Z
[ "python", "global-variables" ]
global and local variables misconception
39,827,768
<p>I have a question regarding the output from the following code:</p> <pre><code>def f(): global s print(s) s = "That's clear." print(s) s = "Python is great!" f() print(s) </code></pre> <p>The output is this:</p> <blockquote> <p>Python is great!</p> <p>That's clear.</p> <p>That's ...
-2
2016-10-03T08:54:15Z
39,828,216
<p>To see the output you do, the structure of you code has to be:</p> <pre><code>def f(): global s print(s) # s outside the function s = "That's clear." # new global s created print(s) # print the new s s = "Python is great!" # s before you call the function/get to s = "That's clear." f() # f gets cal...
0
2016-10-03T09:19:28Z
[ "python", "global-variables" ]
How to run Spark Java code in Airflow?
39,827,804
<p>Hello people of the Earth! I'm using Airflow to schedule and run Spark tasks. All I found by this time is python DAGs that Airflow can manage. <br> DAG example:</p> <pre><code>spark_count_lines.py import logging from airflow import DAG from airflow.operators import PythonOperator from datetime import datetime ar...
1
2016-10-03T08:56:09Z
39,833,103
<p>You should be able to use <code>BashOperator</code>. Keeping the rest of your code as is, import required class and system packages:</p> <pre><code>from airflow.operators.bash_operator import BashOperator import os import sys </code></pre> <p>set required paths:</p> <pre><code>os.environ['SPARK_HOME'] = '/path/t...
0
2016-10-03T13:41:08Z
[ "java", "python", "apache-spark", "directed-acyclic-graphs", "airflow" ]
python json object array not serializable
39,827,862
<p>I have a class and array in a loop. I'm filling the object and appending it to the array. How do I pass array data to web side through JSON? I have an error that says JSON is not serializable. How can I serialize to a JSON?</p> <pre><code>class myclass(object): def __init__(self,vehicle,mng01): self.ve...
1
2016-10-03T09:00:03Z
39,828,172
<p>Does it say myclass object is not JSON serializable? This is because there is no way for <code>json.dumps(..)</code> to know how to JSON-serialize your class. You will need to write your <a href="https://docs.python.org/2/library/json.html#json.JSONEncoder" rel="nofollow">custom encoder to do that</a>.</p> <p>Below...
2
2016-10-03T09:16:45Z
[ "python", "json", "ajax", "serialization" ]
python json object array not serializable
39,827,862
<p>I have a class and array in a loop. I'm filling the object and appending it to the array. How do I pass array data to web side through JSON? I have an error that says JSON is not serializable. How can I serialize to a JSON?</p> <pre><code>class myclass(object): def __init__(self,vehicle,mng01): self.ve...
1
2016-10-03T09:00:03Z
39,828,178
<p>It doesn't say that JSON is not serializable, it says that your instances of <code>myclass</code> are not JSON serializable. I.e. they cannot be represented as JSON, because it is really not clear what do you expect as an output.</p> <p>To find out how to make a class JSON serializable, check this question: <a href...
0
2016-10-03T09:16:54Z
[ "python", "json", "ajax", "serialization" ]
Get dataframe columns from a list using isin
39,827,897
<p>I have a dataframe <code>df1</code>, and I have a list which contains names of several columns of <code>df1</code>.</p> <pre><code>df1: User_id month day Age year CVI ZIP sex wgt 0 1 7 16 1977 2 NA M NaN 1 2 7 16 1977 3 NA M NaN 2 ...
1
2016-10-03T09:01:30Z
39,828,023
<p>You can try :</p> <pre><code>df2 = df1[list] # it does a projection on the columns contained in the list df3 = df1[[col for col in df1.columns if col not in list]] </code></pre>
1
2016-10-03T09:09:04Z
[ "python", "list", "pandas", "condition", "multiple-columns" ]
Get dataframe columns from a list using isin
39,827,897
<p>I have a dataframe <code>df1</code>, and I have a list which contains names of several columns of <code>df1</code>.</p> <pre><code>df1: User_id month day Age year CVI ZIP sex wgt 0 1 7 16 1977 2 NA M NaN 1 2 7 16 1977 3 NA M NaN 2 ...
1
2016-10-03T09:01:30Z
39,828,114
<p>Solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.difference.html" rel="nofollow"><code>Index.difference</code></a>:</p> <pre><code>L = [u"User_id", u"day", u"ZIP", u"sex"] df2 = df1[L] df3 = df1[df1.columns.difference(df2.columns)] print (df2) User_id day ZIP sex 0 ...
1
2016-10-03T09:13:44Z
[ "python", "list", "pandas", "condition", "multiple-columns" ]
Get dataframe columns from a list using isin
39,827,897
<p>I have a dataframe <code>df1</code>, and I have a list which contains names of several columns of <code>df1</code>.</p> <pre><code>df1: User_id month day Age year CVI ZIP sex wgt 0 1 7 16 1977 2 NA M NaN 1 2 7 16 1977 3 NA M NaN 2 ...
1
2016-10-03T09:01:30Z
39,828,564
<p>never name a list as "list"</p> <pre><code>my_list= [u"User_id", u"day", u"ZIP", u"sex"] df2 = df1[df1.keys()[df1.keys().isin(my_list)]] </code></pre>
1
2016-10-03T09:36:19Z
[ "python", "list", "pandas", "condition", "multiple-columns" ]
Get dataframe columns from a list using isin
39,827,897
<p>I have a dataframe <code>df1</code>, and I have a list which contains names of several columns of <code>df1</code>.</p> <pre><code>df1: User_id month day Age year CVI ZIP sex wgt 0 1 7 16 1977 2 NA M NaN 1 2 7 16 1977 3 NA M NaN 2 ...
1
2016-10-03T09:01:30Z
39,828,659
<p>never name a list as "list"</p> <pre><code>my_list= [u"User_id", u"day", u"ZIP", u"sex"] df2 = df1[df1.keys()[df1.keys().isin(my_list)]] </code></pre> <p>or</p> <pre><code>df2 = df1[df1.columns[df1.columns.isin(my_list)]] </code></pre>
1
2016-10-03T09:41:45Z
[ "python", "list", "pandas", "condition", "multiple-columns" ]
using python to read a column vector from excel
39,827,924
<p>OK i think this must be a super simple thing to do, but i keep getting index error messages no matter how i try to format this. my professor is making us multiply a 1X3 row vector by a 3x1 column vector, and i cant get python to read the column vector. the row vector is from cells A1-C1, and the column vector is f...
0
2016-10-03T09:02:40Z
39,828,590
<p>Something like this should work. The way you iterate over <code>i</code> and <code>j</code> are wrong (plus the initalization of <code>a</code> and <code>b</code>)</p> <pre><code> #initialize vectors a = np.zeros((1,3)) b = np.zeros((3,1)) n=3 #Read a and b vectors from excel for i in range(0,n): a[0,i] = xw...
0
2016-10-03T09:38:00Z
[ "python", "excel", "vector" ]
using python to read a column vector from excel
39,827,924
<p>OK i think this must be a super simple thing to do, but i keep getting index error messages no matter how i try to format this. my professor is making us multiply a 1X3 row vector by a 3x1 column vector, and i cant get python to read the column vector. the row vector is from cells A1-C1, and the column vector is f...
0
2016-10-03T09:02:40Z
39,828,597
<p>Remember, Python use 0-based indexing and Excel use 1-based indexing. </p> <p>This code will read out the vectors properly, and then you can check on numpy "scalar product" to produce the multiplication. You can also assign the whole vectors immediately without loop.</p> <pre><code>import xlwings as xw import nump...
0
2016-10-03T09:38:13Z
[ "python", "excel", "vector" ]
Python program to match string based on user input
39,828,202
<p>I need to write a python program that allows user to enter input like <code>Apple,Ball</code> and it if matches the line in the file print it. so far I am able to get this.</p> <pre><code>import re import sys print('Enter the values') value1=input() try: filenm1="D:\names.txt" t=open(filenm1,'r') regex...
0
2016-10-03T09:18:31Z
39,830,847
<p>You can change your loop into this:</p> <pre><code>import sys print('Enter the values') value1=input() value1=value1.split(',') try: filenm1="D:\names.txt" t=open(filenm1,'r') for line in t: alreadyPrinted = False for value in value1: if value in line: if not...
0
2016-10-03T11:46:19Z
[ "python", "python-3.x" ]
How to get For loops to communicate with a While loop
39,828,257
<p>I need to write a program that takes the last number from the for loop ( if it exceeds a certain number) and places it in the while loop. I have left the unfinished code below.</p> <pre><code>t=0 num=int(input("How many presents do you want to buy?: ")) for i in range(num): t=t+int(input("Please enter the price...
-1
2016-10-03T09:21:40Z
39,828,586
<p>U need to use a list.</p> <p>Ex</p> <pre><code>t = 0 num=int(input("How many presents do you want to buy?: ")) prices = [] for i in range(num): prices.append(int(input("Please enter the price of a present"))) t += prices[-1] while t &gt; 200: print("Limit Exceeded.") print("You need to ...
0
2016-10-03T09:37:48Z
[ "python", "for-loop", "while-loop" ]
Using grep to compare two lists of Python packages
39,828,366
<p>I want to generate the list of packages install in Python 3, the list of all packages in Python 2.7 and find all entries in the 2.7 list <em>not</em> in the Python 3 list.</p> <p>Generating the list is easy: <code>pip freeze</code> or <code>pip3.4 freeze</code>.</p> <p>Searching for a package in the list is equall...
3
2016-10-03T09:26:31Z
39,829,092
<p>you can use also comm command as below</p> <pre><code>comm -12 &lt;(pip freeze) &lt;(pip3.4 freeze) </code></pre> <p>to search for intersections;</p> <pre><code>grep -f &lt;(pip freeze) &lt;(pip3.4 freeze) </code></pre>
1
2016-10-03T10:06:09Z
[ "python", "bash", "list", "shell", "grep" ]
SLURM with python multiprocessing give inconsistent results
39,828,425
<p>We have a small HPC with 4*64 cores, and it has SLURM installed in it.</p> <p>The nodes are:</p> <pre><code>sinfo -N -l Mon Oct 3 08:58:12 2016 NODELIST NODES PARTITION STATE CPUS S:C:T MEMORY TMP_DISK WEIGHT FEATURES REASON dlab-node1 1 dlab* idle 64 2:16:2 257847 ...
0
2016-10-03T09:29:22Z
39,834,957
<p>From sbatch man page:</p> <blockquote> <p>SLURM_JOB_CPUS_PER_NODE</p> <p>Count of processors available to the job <strong>on this node</strong>. Note the select/linear plugin allocates entire nodes to jobs, so the value indicates the total count of CPUs on the node. The select/cons_res plugin allocates ind...
2
2016-10-03T15:17:39Z
[ "python", "python-3.x", "multiprocessing", "slurm" ]
how to get ALL your channel-IDs - youtube api v3
39,828,449
<p>I was wondering if it was possible to gain your other channel-IDs, this code under is only getting one channelID (the one channel i clicked on during the authorization).</p> <pre><code> def gaining_channelID(youtube): channels_list_response = youtube.channels().list( part="id", mine=True ).execu...
1
2016-10-03T09:30:31Z
39,828,790
<p>When you authenticate to the YouTube API you pick a channel. In my case I have 6 channels I think. If I authenticate to the first channel I will only have access to the first channels data. </p> <p>Yes you need to authenticate for each of the channels. The access you get will be channel specific. </p>
2
2016-10-03T09:48:54Z
[ "python", "api", "youtube", "youtube-api", "youtube-data-api" ]
Finding dimensions of a keras intermediate expression
39,828,691
<p>I am implementing a custom keras layer. The call method in my class is as follows.</p> <pre><code> def call(self, inputs, mask=None): if type(inputs) is not list or len(inputs) &lt;= 1: raise Exception('Merge must be called on a list of tensors ' '(at least 2). Got: ' + str(inputs))...
0
2016-10-03T09:43:23Z
39,863,014
<p>If you are using the theano backend, you can define Theano functions. (<a href="https://github.com/fchollet/keras/issues/41" rel="nofollow">like François suggested</a>)</p> <p>E.g. </p> <pre class="lang-py prettyprint-override"><code>import theano from keras import layers input = layers.Input(params) layer = You...
1
2016-10-04T22:58:08Z
[ "python", "keras", "keras-layer" ]
Visual studio code interactive python console
39,828,744
<p>I'm using visual studio code with DonJayamanne python extension. It's working fine but I want to have an interactive session just like the one in Matlab, where after code execution every definition and computational result remains and accessible in the console. </p> <p>For example after running this code: </p> <pr...
0
2016-10-03T09:45:53Z
39,846,499
<p>I'm the author of the extension. There are two options:</p> <ol> <li><p>Use the integrated terminal window (I guess you already knew this)<br> Launch the terminal window and type in <code>python</code>.<br> Every statement executed in the REPL is within the same session. </p></li> <li><p>Next version will add suppo...
1
2016-10-04T07:25:51Z
[ "python", "ipython", "vscode" ]
Copy number of rows for n number of times using Python and write them in other file
39,828,791
<p>Hi I'm writing a simple script to copy a set of rows from a <strong>csv</strong> file and paste them for N number of times in other file. </p> <p>I'm not able to write the result into other file.</p> <p>Please find the code below:</p> <pre><code>import csv for i in range(2): with open('C:\\Python\\CopyPaste\\...
-1
2016-10-03T09:48:55Z
39,829,026
<p>I guess your question is : read a .csv file and then write the data to another .csv file for N times?</p> <p>If my recognition is right, my suggestion would be using pandas library, that's very convenient.</p> <p>Something like:</p> <pre><code>import pandas as pd df = pd.read_csv('origin.csv') df.to_csv('output....
0
2016-10-03T10:02:04Z
[ "python", "csv" ]
Copy number of rows for n number of times using Python and write them in other file
39,828,791
<p>Hi I'm writing a simple script to copy a set of rows from a <strong>csv</strong> file and paste them for N number of times in other file. </p> <p>I'm not able to write the result into other file.</p> <p>Please find the code below:</p> <pre><code>import csv for i in range(2): with open('C:\\Python\\CopyPaste\\...
-1
2016-10-03T09:48:55Z
39,829,207
<p>Assuming that the format of the input and output CSV files is the same, just read the input file into a string and then write it to an output file <code>N</code> times:</p> <pre><code>N = 3 with open('C:\\Python\\CopyPaste\\result2.csv', 'r') as infile,\ open('C:\\Python\\CopyPaste\\mydata.csv', 'w') as o...
1
2016-10-03T10:12:50Z
[ "python", "csv" ]
How can I correct my ORM statement to show all friends not associated with a user in Django?
39,828,805
<p>In my Django application, I've got two models, one Users and one Friendships. There is a Many to Many relationship between the two, as Users can have many Friends, and Friends can have many other Friends that are Users.</p> <p>How can I return all friends (first and last name) whom are NOT friends with the user wit...
0
2016-10-03T09:49:41Z
39,830,356
<p>Try this,In the place of friend_of_daniel.friend.id , You should exclude the results from User model.</p> <p>Something like this :</p> <pre><code> def index(req): friends_of_daniel = Friendships.objects.filter(user__first_name='Daniel') daniels_friends = [] for friend_of_daniel in frien...
1
2016-10-03T11:18:40Z
[ "python", "django", "orm", "many-to-many" ]
How can I correct my ORM statement to show all friends not associated with a user in Django?
39,828,805
<p>In my Django application, I've got two models, one Users and one Friendships. There is a Many to Many relationship between the two, as Users can have many Friends, and Friends can have many other Friends that are Users.</p> <p>How can I return all friends (first and last name) whom are NOT friends with the user wit...
0
2016-10-03T09:49:41Z
39,830,397
<p>I guess something like this will do. Just then take the list <code>users</code>, and get the first and last name of those users.</p> <pre><code>daniels = Users.objects.filter(first_name="Daniel") # There may be more than one Daniel users = Friendships.objects.exclude(friend__in=daniels) </code></pre> <p>Note here,...
1
2016-10-03T11:20:44Z
[ "python", "django", "orm", "many-to-many" ]
How can I correct my ORM statement to show all friends not associated with a user in Django?
39,828,805
<p>In my Django application, I've got two models, one Users and one Friendships. There is a Many to Many relationship between the two, as Users can have many Friends, and Friends can have many other Friends that are Users.</p> <p>How can I return all friends (first and last name) whom are NOT friends with the user wit...
0
2016-10-03T09:49:41Z
39,837,106
<p>Firstly as a general comment: a cleaner way of populating a list of ids is using the <a href="https://docs.djangoproject.com/es/1.10/ref/models/querysets/#django.db.models.query.QuerySet.values_list" rel="nofollow">.value_list() method from django</a> (part of the .values() method in previous versions of Django). It...
1
2016-10-03T17:25:13Z
[ "python", "django", "orm", "many-to-many" ]
Python: three levels of nesting with list comprehension
39,828,865
<p>I am trying to achieve a nesting of three levels because I need to group some data.</p> <p>I have a list of matches, and each of these matches belong to particular rounds. I want to regroup these matches into separate nested lists for each round, except I don't want to store the whole match in these lists, but only...
0
2016-10-03T09:54:10Z
39,828,977
<p>You can expand each match getting the required attributes from your current result using a nested <em>list comprehension</em>: </p> <pre><code>[[[m.home_score, m.away_score] for m in matches] for _, matches in groupby(all_matches, key=attrgetter('round'))] </code></pre>
1
2016-10-03T09:59:30Z
[ "python", "python-2.7" ]
apache failed to start with no error logs
39,828,871
<p>this day i got an issue</p> <p>my apache has failed to restart my django app, i dont know why. and the worst is , it doesnt out with any error log , just blank!</p> <p>this problem make me confuse ,need help.</p> <blockquote> <p>alif@alif-VirtualBox:/var/www/mywebsite/website$ service apache2 restart<br> * R...
0
2016-10-03T09:54:38Z
39,833,672
<p>Check to make sure nothing is listening on port 80. I'm not sure what the <code>website.settings</code> contains but it is possible that either this apache instance is trying to use the same port as another, or something else is running on port 80. (this is the default port). You can check if something might be usin...
0
2016-10-03T14:10:39Z
[ "python", "django", "apache", "wsgi", "error-log" ]
Surprising behaviour of enumerate function
39,828,904
<p>I wrote some Python code using the enumerate function. </p> <pre><code>A = [2,3,5,7] for i, x in enumerate(A): # calculate product with each element to the right for j, y in enumerate(A, start=i+1): print(x*y) </code></pre> <p>I expected it to calculate 6 products: 2*3, 2*5, 2*7, 3*5, 3*7, 5*7</p>...
0
2016-10-03T09:56:25Z
39,829,021
<p>The <code>start</code> parameter of <code>enumerate</code> solely influences the first value of the yielded tuple (i.e. <code>i</code> and <code>j</code>), it does not influence at which index the enumeration starts. As <a href="https://docs.python.org/3/library/functions.html#enumerate">the manual</a> puts it, <cod...
7
2016-10-03T10:01:42Z
[ "python" ]
Surprising behaviour of enumerate function
39,828,904
<p>I wrote some Python code using the enumerate function. </p> <pre><code>A = [2,3,5,7] for i, x in enumerate(A): # calculate product with each element to the right for j, y in enumerate(A, start=i+1): print(x*y) </code></pre> <p>I expected it to calculate 6 products: 2*3, 2*5, 2*7, 3*5, 3*7, 5*7</p>...
0
2016-10-03T09:56:25Z
39,829,065
<p>The question here is firstly what enumerate did, and secondly why you're using it. The base function of enumerate is to convert an iterable of the form <code>(a,b,c)</code> to an iterable of the form <code>((start,a), (start+1,b), (start+2,c))</code>. It adds a new column which is typically used as an index; in your...
2
2016-10-03T10:04:51Z
[ "python" ]
How to find QButton created with a loop?
39,829,223
<p>in maya one creates a button with:</p> <pre><code> cmds.button('buttonname', label='click me') </code></pre> <p>where buttonname is the name of the button object. At a later stage i can edit the button simply by calling:</p> <pre><code> cmds.button('buttonname', e=1, label='click me again') </code></pre> <p...
1
2016-10-03T10:13:42Z
39,829,404
<p>Assuming you already have access to their parent widget, you can find them by <code>findChild</code> method.</p> <p>In C++ syntax, it would be something like this:</p> <pre><code>QPushButton *button = parentWidget-&gt;findChild&lt;QPushButton *&gt;("button1"); </code></pre> <p>where <code>button1</code> is the na...
4
2016-10-03T10:23:41Z
[ "python", "qt", "button", "pyside", "maya" ]
How do I perform error handling with two files?
39,829,233
<p>So , I am having two files , so to checks its validity I am performing <code>try</code> and <code>except</code> two times . But I don't thinks this is a good method, can you suggest a better way?</p> <p>Here is my code:</p> <pre><code>def form_density_dictionary(self,word_file,fp_exclude): self.freq_dictionary=...
0
2016-10-03T10:14:02Z
39,829,443
<p>Exceptions thrown that involve a file system path have a <code>filename</code> attribute that can be used instead of explicit attributes <code>word_file</code> and <code>fp_exclude</code> as you do. </p> <p>This means you can wrap these IO operations in the same <code>try-except</code> and use the <code>exception_i...
1
2016-10-03T10:26:06Z
[ "python", "python-3.x", "error-handling" ]
How do I perform error handling with two files?
39,829,233
<p>So , I am having two files , so to checks its validity I am performing <code>try</code> and <code>except</code> two times . But I don't thinks this is a good method, can you suggest a better way?</p> <p>Here is my code:</p> <pre><code>def form_density_dictionary(self,word_file,fp_exclude): self.freq_dictionary=...
0
2016-10-03T10:14:02Z
39,829,548
<p>To be more 'pythonic' you could use something what is callec Counter, from collections library.</p> <pre><code>from collections import Counter def form_density_dictionary(self, word_file, fp_exclude): success_msg = '*Read file succesfully : {filename}' fail_msg = '**Could not read file: {filename}: Please...
1
2016-10-03T10:32:28Z
[ "python", "python-3.x", "error-handling" ]
How do I perform error handling with two files?
39,829,233
<p>So , I am having two files , so to checks its validity I am performing <code>try</code> and <code>except</code> two times . But I don't thinks this is a good method, can you suggest a better way?</p> <p>Here is my code:</p> <pre><code>def form_density_dictionary(self,word_file,fp_exclude): self.freq_dictionary=...
0
2016-10-03T10:14:02Z
39,830,065
<p>The first thing that jumps out is the lack of consistency and readability: in some lines you indent with 4 spaces, on others you only use two; in some places you put a space after a comma, in others you don't, in most places you don't have spaces around the assignment operator (<code>=</code>)...</p> <p>Be consiste...
1
2016-10-03T11:02:19Z
[ "python", "python-3.x", "error-handling" ]
Messenger account linking authentication flow in Django
39,829,354
<p>How can I complete the authentication flow of the account linking in Django?</p> <p>I send the login template to user. When the user clicks on it, she is redirect to <a href="https://example.ngork.io/authenticate" rel="nofollow">https://example.ngork.io/authenticate</a> with the parameters account_linking_token and...
0
2016-10-03T10:20:12Z
39,854,245
<p>I resolved the issue. Details are in the question after the tag RESOLVED</p>
0
2016-10-04T13:57:16Z
[ "python", "django", "facebook", "bots", "facebook-messenger" ]
SimpleBool, Python Package
39,829,359
<p>I have been trying to use SimpleBool, which uses Python Language. I downloaded the python scripts to use SimpleBool.When I tried to execute the Python file Boolmutation, I get the following error:</p> <pre><code>%run "/home/JPJ/Priya_Ph.D/simple_bool/simplebool/SimpleBool-master /BoolMutation.py" </code></pre> <...
0
2016-10-03T10:20:35Z
39,858,989
<p>In Python in general and in Canopy in particular, you cannot assume that your current directory is the same as the directory where the script that you are running is located. But without looking at this package, it seems likely that it does make such an assumption. If so, you can do so with the "Keep Directory Synce...
0
2016-10-04T18:06:23Z
[ "python", "python-2.7", "boolean", "enthought", "canopy" ]
Is it safe to remove google's "unused_argv" from forked python projects?
39,829,431
<p>On projects that google share on the web, they use:</p> <p>def main(unused_argv):</p> <p><a href="https://github.com/tensorflow/models/blob/master/im2txt/im2txt/train.py" rel="nofollow">(see example)</a> , where <code>unused_argv</code> is never used. I couldn't find why do they do it and it annoys me to have warn...
0
2016-10-03T10:25:22Z
39,830,034
<p>In that case it's presumably, because the tf.app.run function expects the main function to have a positional argument</p> <p>This is the code that will call your main function: <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/platform/app.py" rel="nofollow">Source</a></p> <pre><code>...
1
2016-10-03T11:00:46Z
[ "python" ]
cryptography AssertionError: sorry, but this version only supports 100 named groups
39,829,473
<p>I'm installing several python packages via <code>pip install</code> on travis, </p> <pre><code>language: python python: - '2.7' install: - pip install -r requirements/env.txt </code></pre> <p>Everything worked fine, but today I started getting following error:</p> <pre><code> Running setup.py install for cryptogr...
13
2016-10-03T10:28:14Z
39,830,224
<p>There is a bug with PyCParser - See <a href="https://github.com/pyca/cryptography/issues/3187">https://github.com/pyca/cryptography/issues/3187</a></p> <p>The work around is to use another version or to not use the binary distribution.</p> <pre><code>pip install git+https://github.com/eliben/pycparser@release_v2.1...
22
2016-10-03T11:11:24Z
[ "python", "python-2.7", "travis-ci", "python-cryptography" ]
Iterate over two lists, execute function and return values
39,829,490
<p>I am trying to iterate over two lists of the same length, and for the pair of entries per index, execute a function. The function aims to cluster the entries according to some requirement X on the value the function returns.</p> <p>The lists in questions are:</p> <pre><code>e_list = [-0.619489,-0.465505, 0.124281,...
1
2016-10-03T10:29:17Z
39,833,406
<p>This is finding connected components of a graph, which is very easy and well documented, once you revisit the problem from that view.</p> <p>The data being in two lists is a distraction. I am going to consider the data to be zip(e_list, p_list). Consider this as a graph, which in this case has 5 nodes (but could ha...
2
2016-10-03T13:56:45Z
[ "python" ]
Using IVI-COM drivers with python via comtypes
39,829,502
<p>I am trying to get my IVI drivers working using comtypes. So far I have been successful in initializing the instrument thanks to <a href="http://stackoverflow.com/questions/13840997/python-instrument-drivers">Python instrument drivers</a> more specifically Jorenko's post, as he is using the same instrument as me (I'...
0
2016-10-03T10:29:51Z
39,852,314
<p>Answered my own question (after much trial and error)</p> <p>For anyone interested, I had a bit of success with the following</p> <pre><code>import comtypes from comtypes import client dmm = client.CreateObject('VTEXDmm.VTEXDmm') dmm.Initialize('TCPIP::10.20.30.40::INSTR', True, True) dmm.Configure(Function=comty...
0
2016-10-04T12:25:59Z
[ "python", "com", "driver", "visa" ]
Seeking help to improve a crawler
39,829,574
<p>I'm a beginner with <strong>Scrapy/Python</strong>, I developed a crawler that can find <strong>expired domains</strong> and scan each on a <strong>SEO API</strong>.<br /> My crawler work fine but I pretty sure the crawler isn't 100% optimized for the job.<br/><br/> Could it be possible to have some tricks to improv...
-1
2016-10-03T10:33:17Z
39,829,861
<p>The biggest issue in your code is urllib requests that are blocking whole async scrapy routine. You can easily replace those with scrapy request chain by yielding a <code>scrapy.Request</code>.</p> <p>Something like this:</p> <pre><code>def errback_httpbin(self, failure): if not failure.check(DNSLookupError): ...
1
2016-10-03T10:50:43Z
[ "python", "python-2.7", "web-scraping", "scrapy" ]
Video Stitching from multiple cameras
39,829,582
<p>I wanted to stitch a video from multiple cameras. While stitching I wanted to switch view from one camera to another. Is it possible to do it in OpenCv? </p> <p>For example I have 3 video paths(videos having same duration) and wanted to create a single video summary by switching between the videos. To start with I ...
1
2016-10-03T10:33:30Z
39,831,576
<p>yes you can do this by first finding the fps of your videos using</p> <pre><code>int fps = (int) cvGetCaptureProperty(capture1, CV_CAP_PROP_FPS); </code></pre> <p>now calculate the number of frames you want to capture, </p> <pre><code>numberOfFrames = fps*time </code></pre> <p>this time is the time for which you...
0
2016-10-03T12:23:43Z
[ "python", "opencv", "video", "video-capture" ]
Video Stitching from multiple cameras
39,829,582
<p>I wanted to stitch a video from multiple cameras. While stitching I wanted to switch view from one camera to another. Is it possible to do it in OpenCv? </p> <p>For example I have 3 video paths(videos having same duration) and wanted to create a single video summary by switching between the videos. To start with I ...
1
2016-10-03T10:33:30Z
39,831,855
<p>Since you have written while stitching so I assume you want to make a sort of gui and see the results of switching at different time, otherwise Garvita Tiwari answer's seems to be correct.</p> <p>One way of doing is to use createTrackbar of a variable(say) vid_no with its value ranging from 0 to num_Cams - 1.Now u ...
0
2016-10-03T12:36:47Z
[ "python", "opencv", "video", "video-capture" ]
Verbose_name and helptext lost when using django autocomplete light
39,829,584
<p>I have the below model that includes a field called boxnumber When i don't use DAL, the verbose_name and help_text appear and get translated when needed.</p> <p>But when adding DAL (see modelform below), it only shows the name, not translated and with no help text.</p> <p>Any suggestions?</p> <p>control/models.py...
0
2016-10-03T10:33:53Z
40,127,486
<p>It's not specific to dal. You're re-instanciating a new widget class, so you need to copy help_text and verbose_name yourself.</p>
0
2016-10-19T09:32:17Z
[ "python", "django", "django-autocomplete-light" ]
How to call from function to another function
39,829,660
<p>I am making a minesweeper game within python with pygame.</p> <pre><code>import pygame, math, sys def bomb_check(): if check in BOMBS: print("You hit a bomb!") sys.exit def handle_mouse(mousepos): x, y = mousepos x, y = math.ceil(x / 40), math.ceil(y / 40) check = print("("+"{0}, {1}".form...
-1
2016-10-03T10:39:31Z
39,829,738
<p>Just use it as an argument:</p> <pre><code>import pygame, math, sys def bomb_check(check): if check in BOMBS: print("You hit a bomb!") sys.exit def handle_mouse(mousepos): x, y = mousepos x, y = math.ceil(x / 40), math.ceil(y / 40) check = x, y print(check) bomb_check(check) </code...
0
2016-10-03T10:44:10Z
[ "python" ]
Attain a tally of a column of a 2d array
39,829,712
<p>I have a 2d array data. And would like to attain a tally every time the jth iteration is a 1. Where i = rows and j = columns. How do I go about doing this without a for loop? </p> <p>Conceptually something like this:</p> <pre><code>for r in range(row): if(data[r][j] == 1) amount += 1 </code></pre>
1
2016-10-03T10:42:24Z
39,830,113
<p>I interprete this question such that you want to iterate over both, rows and columns, and add 1 to <code>amount</code> for each entry in data that is 1. This can be done without looping as follows.</p> <pre><code>import numpy as np data = np.ones((6,8)) amount = data[data == 1].sum() print amount </code></pre> <p...
0
2016-10-03T11:04:53Z
[ "python", "arrays", "numpy", "multidimensional-array", "scipy" ]
Attain a tally of a column of a 2d array
39,829,712
<p>I have a 2d array data. And would like to attain a tally every time the jth iteration is a 1. Where i = rows and j = columns. How do I go about doing this without a for loop? </p> <p>Conceptually something like this:</p> <pre><code>for r in range(row): if(data[r][j] == 1) amount += 1 </code></pre>
1
2016-10-03T10:42:24Z
39,830,251
<p>You can do as follow:</p> <pre><code>import numpy as np a = np.array([[0, 1], [1, 1]]) j = 1 np.sum(a[:, j] == 1) </code></pre> <p>will give you 2 as a result , while <code>np.sum(a[:, 0] == 1)</code> will give 1</p> <p>If as mentioned in your comment you want to use a condition on multiple arrays, you can use <c...
1
2016-10-03T11:12:51Z
[ "python", "arrays", "numpy", "multidimensional-array", "scipy" ]
How to get rid of extra + sign in print statement, Python
39,829,827
<pre><code>print('2**', n, ' + ', sep='', end='') </code></pre> <p>Hi the print statement above is in a loop so the output ends up being </p> <pre><code>2 ** 10 + 2 ** 7 + 2 ** 6 + 2 ** 4 + 2 ** 1 + </code></pre> <p>I need to get rid of the last plus in the statement but have no idea how to go about doing so.</p>
1
2016-10-03T10:48:37Z
39,829,901
<p>You can store the string to be printed in a variable in the loop and then after the loop ends, remove the extra plus by slicing using <code>to_print[:len(to_print)-1]</code> And then print to_print. Here to_print is the text you need to store in the loop Instead of printing it and then print it at the end after slic...
0
2016-10-03T10:53:05Z
[ "python", "python-3.x", "printing" ]
How to get rid of extra + sign in print statement, Python
39,829,827
<pre><code>print('2**', n, ' + ', sep='', end='') </code></pre> <p>Hi the print statement above is in a loop so the output ends up being </p> <pre><code>2 ** 10 + 2 ** 7 + 2 ** 6 + 2 ** 4 + 2 ** 1 + </code></pre> <p>I need to get rid of the last plus in the statement but have no idea how to go about doing so.</p>
1
2016-10-03T10:48:37Z
39,829,904
<p>Either check if you're at the last element and use a different print statement (without the final <code>'+'</code>), or construct your output in a list first and join the list before printing.</p> <pre><code>output = [] some_loop: output.append('2**%i' % n) print(' + '.join(output)) </code></pre>
0
2016-10-03T10:53:14Z
[ "python", "python-3.x", "printing" ]
How to get rid of extra + sign in print statement, Python
39,829,827
<pre><code>print('2**', n, ' + ', sep='', end='') </code></pre> <p>Hi the print statement above is in a loop so the output ends up being </p> <pre><code>2 ** 10 + 2 ** 7 + 2 ** 6 + 2 ** 4 + 2 ** 1 + </code></pre> <p>I need to get rid of the last plus in the statement but have no idea how to go about doing so.</p>
1
2016-10-03T10:48:37Z
39,829,920
<p>It is pretty 'common' 'problem', and it is often solved by using ''.join method. I assume that you've a list of integers, so all you need to do is:</p> <pre><code>powers = [10, 7, 6, 4] print(' + '.join(['2 ** {n}'.format(n= n) for n in powers])) </code></pre>
1
2016-10-03T10:54:03Z
[ "python", "python-3.x", "printing" ]
How to get rid of extra + sign in print statement, Python
39,829,827
<pre><code>print('2**', n, ' + ', sep='', end='') </code></pre> <p>Hi the print statement above is in a loop so the output ends up being </p> <pre><code>2 ** 10 + 2 ** 7 + 2 ** 6 + 2 ** 4 + 2 ** 1 + </code></pre> <p>I need to get rid of the last plus in the statement but have no idea how to go about doing so.</p>
1
2016-10-03T10:48:37Z
39,829,972
<p>If you separate the exponents, as you have probably done, you can use <a href="https://docs.python.org/3/library/stdtypes.html#str.join" rel="nofollow"><code>str.join()</code></a>:</p> <pre><code>&gt;&gt;&gt; exponents = (10, 7, 6, 4, 1) &gt;&gt;&gt; print(' + '.join('2**{}'.format(n) for n in exponents)) 2**10 + 2...
2
2016-10-03T10:57:14Z
[ "python", "python-3.x", "printing" ]
How to get rid of extra + sign in print statement, Python
39,829,827
<pre><code>print('2**', n, ' + ', sep='', end='') </code></pre> <p>Hi the print statement above is in a loop so the output ends up being </p> <pre><code>2 ** 10 + 2 ** 7 + 2 ** 6 + 2 ** 4 + 2 ** 1 + </code></pre> <p>I need to get rid of the last plus in the statement but have no idea how to go about doing so.</p>
1
2016-10-03T10:48:37Z
39,829,991
<p>You could do the following, and adapting it to your loop length</p> <pre><code>n = 1 for i in range(0,10): if i &lt; 9: print('2**', n, ' + ', sep='', end = '') else: print('2**', n, sep='', end = '') </code></pre>
0
2016-10-03T10:58:05Z
[ "python", "python-3.x", "printing" ]
How to get rid of extra + sign in print statement, Python
39,829,827
<pre><code>print('2**', n, ' + ', sep='', end='') </code></pre> <p>Hi the print statement above is in a loop so the output ends up being </p> <pre><code>2 ** 10 + 2 ** 7 + 2 ** 6 + 2 ** 4 + 2 ** 1 + </code></pre> <p>I need to get rid of the last plus in the statement but have no idea how to go about doing so.</p>
1
2016-10-03T10:48:37Z
39,830,120
<p><a href="http://www.tutorialspoint.com/python/string_join.htm" rel="nofollow">join()</a> helps a lot in this case:</p> <pre><code>exponents = [10, 7, 6, 4, 1] out = [] for n in exponents: out.append('2 ** %d' % n) print ' + '.join(out) </code></pre>
0
2016-10-03T11:05:04Z
[ "python", "python-3.x", "printing" ]
Python - unittests: compare some objects using their attributes instead if they are really the same object?
39,829,946
<p>I have method that sets data into class attribute.</p> <p>So let say I run:</p> <pre><code>self._set_data(some_data) print self._data </code></pre> <p>It prints me this information:</p> <pre><code>{'c2': { 'column': 1, 'style': &lt;xlwt.Style.XFStyle object at 0x7f4668a18dd0&gt;, 'value': u'Argenti...
0
2016-10-03T10:55:31Z
39,830,190
<p>In your tests you can create a mock style object which is initialized with the expected values, then compare it's <code>__dict__</code> attribute to the <code>__dict__</code> attribute of the tested style object.</p> <pre><code>if mock_style.__dict__ == tested_style.__dict__ : print('The styles are set correctl...
0
2016-10-03T11:09:30Z
[ "python", "python-2.7", "object", "python-unittest", "xlwt" ]
set value from filepicker to dialog that called it
39,830,040
<p>i have a action button that calls an dialog that i've made:</p> <pre><code>class MainPanelManager(QtWidgets.QMainWindow, Ui_MainWindow): def __init__(self): super().__init__() self.setupUi(self) self.actionLocation.triggered.connect(self.editsettings) def editsettings(self): ...
0
2016-10-03T11:01:05Z
39,830,169
<p>A simple solution would be declaring the <code>dialog</code> variable a property of <code>self</code> object. So, you can then use it class-widely in all methods.</p> <pre><code>class MainPanelManager(QtWidgets.QMainWindow, Ui_MainWindow): def __init__(self): super().__init__() self.setupUi(self...
0
2016-10-03T11:08:01Z
[ "python", "qt", "python-3.x", "pyqt", "qt-creator" ]
cPickle: UnpicklingError: invalid load key, 'A'
39,830,198
<p>I have a pickle file which upon unpickling throws an <code>UnpicklingError: invalid load key, 'A'.</code> exception. The exception gets thrown regardless of whether I try to analyse it on the Ubuntu 14.04 machine on which the file was generated or on my Windows machine. It contains 26 data points and the exception g...
1
2016-10-03T11:09:52Z
39,835,073
<p>When storing multiple objects (by repeated <code>dump</code>, not from containers) Pickle will store objects sequentially in pickle files, so if an object is broken it can be removed without corrupting the others.</p> <p>In principle, the pickle format is pseudo-documented in <code>pickle.py</code>. For most cases,...
1
2016-10-03T15:23:04Z
[ "python", "python-2.7", "pickle" ]
Celery workers wait
39,830,235
<p>I am writing an application with using Celery framework. Some of my tasks are pretty heavyweight and can execute for a long time.</p> <p>I've noticed that when I run 5-6 workers and then put 10-20 tasks they may be distributed by workers randomly and sometimes if one get free of tasks, it does not start remaining o...
6
2016-10-03T11:12:07Z
39,830,304
<p>It is not a bug or a feature (more likely a feature), it is just misconfiguration. </p> <p>As the <a href="http://docs.celeryproject.org/en/latest/userguide/optimizing.html#prefetch-limits">documentation</a> says, the worker can reserve some tasks for himself to hasten the processing messages. But this makes sense ...
5
2016-10-03T11:16:01Z
[ "python", "celery" ]
How to perform two functions in a single for loop in python
39,830,241
<p>I wanna split a sentence and also replace quotes from it. I did:</p> <pre><code>sentences = read_data.split('\n') sentences_no_quotes = [sentence.replace('"', '') for sentence in sentences] splited_sentences = [sentence.split(',') for sentence in sentences_no_quotes] </code></pre> <p>How can I do it in a single ...
-3
2016-10-03T11:12:29Z
39,831,171
<p>Just do it, it's straightforward.</p> <pre><code>splited_sentences = [sentence.split(',') for sentence in [sentence.replace('"', '') for sentence in read_data.split('\n')]] </code></pre> <p>Probably you'd better use generators instead of lists but that's beyond your quest...
1
2016-10-03T12:04:34Z
[ "python", "python-3.x" ]
Ubuntu Server Python Pandas “SVD did not converge”
39,830,257
<p>I have the following code.</p> <pre><code>#!/usr/bin/python # -*- coding: utf-8 -*- # cadf.py import datetime import MySQLdb as mdb import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates import pandas as pd import pprint import statsmodels.tsa.stattools as ts from pandas.stats.api imp...
1
2016-10-03T11:13:10Z
39,870,212
<p>After some testing with other data, my first thought was the quantity of rows being tested. This was not the case. </p> <p>The problem was a missing data point which can be seen from the snipping above. Row '2006-12-31 22:00:00' was missing from the 'EUR-USD' sample causing the calculation to NaN, the calculation c...
-1
2016-10-05T09:27:03Z
[ "python", "ubuntu", "pandas", "quantitative-finance" ]
Parse args to json elements in python
39,830,277
<p>i have a data structure that i want to fill with cmd args</p> <pre><code>params = { ... ... "blockX": "{\"nameX\":["\Arg1\","\Arg2\",\"Arg3\"........"\ArgX\"]}", ... ... } </code></pre> <p>Then i run a post request with the params as data:</p> <pre><code>r = requests.post("https://url", data=params) </c...
0
2016-10-03T11:14:30Z
39,830,424
<p>If you have your arguments in <code>args</code> list, then you can try this:</p> <pre><code>import json params['blockX'] = json.dumps({'nameX': args}) </code></pre>
0
2016-10-03T11:22:33Z
[ "python", "json", "args" ]
Parse args to json elements in python
39,830,277
<p>i have a data structure that i want to fill with cmd args</p> <pre><code>params = { ... ... "blockX": "{\"nameX\":["\Arg1\","\Arg2\",\"Arg3\"........"\ArgX\"]}", ... ... } </code></pre> <p>Then i run a post request with the params as data:</p> <pre><code>r = requests.post("https://url", data=params) </c...
0
2016-10-03T11:14:30Z
39,834,055
<p>Your example suggest you want to <code>join</code> the arguments. You can convert any list into a single string by merging with a separator:</p> <pre><code>args = ['foo', 'bar', 'hold the mustard'] print('", "'.join(args)) </code></pre> <p>So to get your list <code>'"Arg1", "Arg2"'</code> etc, join them with the '...
0
2016-10-03T14:29:16Z
[ "python", "json", "args" ]
For Loop doesn't spit out needed results
39,830,446
<p>I got this piece of code to spit out the unique "area number" in the URL. However, the loop doesn't work. It spits out the same number, please see below:</p> <pre><code>import urllib3 from bs4 import BeautifulSoup http = urllib3.PoolManager() url = open('MS Type 1 URL.txt',encoding='utf-8-sig') links = [] for li...
0
2016-10-03T11:23:41Z
39,830,592
<p>There's a typo in your code. You iterate over <code>links</code> list and bind its elements to <code>x</code> variable, but print a slice of <code>link</code> variable, so you get the same string printed on each loop iteration. So you can change <code>print(link[j:g])</code> to <code>print(x[j:g])</code>, but it's b...
1
2016-10-03T11:32:03Z
[ "python", "python-3.x", "loops", "beautifulsoup", "urllib3" ]
For Loop doesn't spit out needed results
39,830,446
<p>I got this piece of code to spit out the unique "area number" in the URL. However, the loop doesn't work. It spits out the same number, please see below:</p> <pre><code>import urllib3 from bs4 import BeautifulSoup http = urllib3.PoolManager() url = open('MS Type 1 URL.txt',encoding='utf-8-sig') links = [] for li...
0
2016-10-03T11:23:41Z
39,830,862
<blockquote> <p>You need to change: </p> </blockquote> <pre><code>print(link[j:g]) to print(x[j:g]) </code></pre>
0
2016-10-03T11:47:21Z
[ "python", "python-3.x", "loops", "beautifulsoup", "urllib3" ]
how to return data from python to php and display it on php page
39,830,522
<p>My python code gets data from php it takes value in text_content variable and then execute its script. But i dont understand to how to return back the results to php. help me please.</p> <pre><code>&lt;body&gt; &lt;?php // define variables and set to empty values $text_content=""; $hello=""; if ($_SERVER["REQUE...
0
2016-10-03T11:28:22Z
39,830,821
<p>I think you have got the data, but you're tried to print it as a string, and not an array. Try:</p> <pre><code>$command="\Users\jonii\AppData\Local\Programs\Python\Python35\python splitter.py $hello "; exec($command , $out,$ret ); //echo $out; /*Loop through each line of data returned*/ foreach ($out as $line){ ...
0
2016-10-03T11:44:52Z
[ "php", "python", "nltk" ]
How to rebuild project after SWIG files changed?
39,830,598
<p>Given the below makefile:</p> <pre><code>TARGET = _example.pyd OFILES = example.obj example_wrap.obj HFILES = CC = cl CXX = cl LINK = link CPPFLAGS = -DNDEBUG -DUNICODE -DWIN32 -I. -Id:\virtual_envs\py351\include CFLAGS = -nologo -Zm200 -Zc:wchar_t- -FS -Zc:strictStrings -O2 -MD -W3 -w44456 -w44457 -w44458 CXXFLAG...
4
2016-10-03T11:32:23Z
39,876,573
<p>I have solved this using CMake and this translates directly to using <code>autoconf</code> and <code>automake</code> and thereby makefiles.</p> <p>The idea is to introduce the following variable</p> <pre><code>DEPENDENCIES = `swig -M -python -c++ -I. example.i | sed 's/\//g'` </code></pre> <p>and make your target...
1
2016-10-05T14:22:15Z
[ "python", "c++", "makefile", "visual-studio-2015", "swig" ]
How to rebuild project after SWIG files changed?
39,830,598
<p>Given the below makefile:</p> <pre><code>TARGET = _example.pyd OFILES = example.obj example_wrap.obj HFILES = CC = cl CXX = cl LINK = link CPPFLAGS = -DNDEBUG -DUNICODE -DWIN32 -I. -Id:\virtual_envs\py351\include CFLAGS = -nologo -Zm200 -Zc:wchar_t- -FS -Zc:strictStrings -O2 -MD -W3 -w44456 -w44457 -w44458 CXXFLAG...
4
2016-10-03T11:32:23Z
39,877,121
<p>Producing any kind of target from any kind of source, that's the essence of a makefile:</p> <pre><code>.i.cpp: swig -python -c++ $&lt; </code></pre> <p>This elegance will, however, break with <code>nmake</code> (<a href="https://www.gnu.org/software/make/manual/html_node/Chained-Rules.html" rel="nofollow">as o...
3
2016-10-05T14:44:42Z
[ "python", "c++", "makefile", "visual-studio-2015", "swig" ]
How to apply multiprocessing technique in python for-loop?
39,830,676
<p>I have a long list of user(about 200,000) and a corresponding data frame <code>df</code> with their attributes. Now I'd like to write a for loop to measure pair-wise similarity of the users. The code is following:</p> <pre><code>df2record = pd.DataFrame(columns=['u1', 'u2', 'sim']) for u1 in reversed(user_list): ...
1
2016-10-03T11:37:31Z
39,831,594
<p>1st of all i would not recommend to use multiprocessing on such a small data. and especially when you are working with data frame. because data frame has it's own lot functionality which can help you in many ways. you just need to write proper loop.</p> <p>Use: multiprocessing.Pool</p> <p>just pass list of user as...
0
2016-10-03T12:24:28Z
[ "python", "multiprocessing" ]
How to apply multiprocessing technique in python for-loop?
39,830,676
<p>I have a long list of user(about 200,000) and a corresponding data frame <code>df</code> with their attributes. Now I'd like to write a for loop to measure pair-wise similarity of the users. The code is following:</p> <pre><code>df2record = pd.DataFrame(columns=['u1', 'u2', 'sim']) for u1 in reversed(user_list): ...
1
2016-10-03T11:37:31Z
39,831,601
<p>You can use <a href="https://docs.python.org/3.5/library/multiprocessing.html#multiprocessing.pool.Pool" rel="nofollow">multiprocessing.Pool</a> which provides method <code>map</code> that maps pool of processes over given iterable. Here's some example code:</p> <pre><code>def pairGen(): for u1 in reversed(user...
1
2016-10-03T12:24:56Z
[ "python", "multiprocessing" ]
Python: NoneType object has no attribute __getitem__. But its not nonetype
39,830,681
<p>So I have this piece of code:</p> <pre><code> key = val_cfg['src_model'] print "key: ", key print "objects dict: ", objects print "before Nonetype" print "accessing objects dict: ", objects[key] # line 122 print "after" method = self._handle_object( val_cfg, objects[val_cfg['src_...
1
2016-10-03T11:37:44Z
39,831,994
<p>Well I made stupid mistake, though that error got me confused, because of traceback. So I was looking in a wrong direction.</p> <p>The problem was in another method, that is used to update objects dictionary. Its purpose is to update value for specific key, if some current iter item (from iteration) needs to be ass...
1
2016-10-03T12:45:04Z
[ "python", "python-2.7", "dictionary", "nonetype" ]
Python: Reading text file and splitting into different lists
39,830,781
<p>I have a text file which contains two lines of text. Each line contains student names separated by a comma.</p> <p>I'm trying to write a program which will read each line and convert it to a list. My solution seems to make two lists but I don't know how to differentiate between the two as both lists are called "fil...
0
2016-10-03T11:42:36Z
39,830,871
<p>You will have to create a multi-dimensional array like this:</p> <pre><code>text = open("file.txt") lines = text.split("\n") entries = [] for line in lines: entries.append(line.split(",")) </code></pre> <p>If your file is</p> <pre><code>John,Doe John,Smith </code></pre> <p>then entries will be:</p> <pre><c...
2
2016-10-03T11:47:53Z
[ "python", "list", "file", "text" ]
Python: Reading text file and splitting into different lists
39,830,781
<p>I have a text file which contains two lines of text. Each line contains student names separated by a comma.</p> <p>I'm trying to write a program which will read each line and convert it to a list. My solution seems to make two lists but I don't know how to differentiate between the two as both lists are called "fil...
0
2016-10-03T11:42:36Z
39,830,873
<p>in your code, filelist will be considered as a list of list because you append a list to it, not an element, consider doing <code>filelist += line.strip().split(",")</code> which will concatenate the lists</p>
0
2016-10-03T11:48:04Z
[ "python", "list", "file", "text" ]
Python: Reading text file and splitting into different lists
39,830,781
<p>I have a text file which contains two lines of text. Each line contains student names separated by a comma.</p> <p>I'm trying to write a program which will read each line and convert it to a list. My solution seems to make two lists but I don't know how to differentiate between the two as both lists are called "fil...
0
2016-10-03T11:42:36Z
39,831,510
<p>two lines to done</p> <pre><code>with open("file.txt") as f: qlist = map(lambda x:x.strip().split(","), f.readlines()) </code></pre> <p>or </p> <pre><code>with open("file.txt") as f: qlist = [i.strip().split(",") for i in f.readlines()] </code></pre>
0
2016-10-03T12:20:21Z
[ "python", "list", "file", "text" ]
Python: Reading text file and splitting into different lists
39,830,781
<p>I have a text file which contains two lines of text. Each line contains student names separated by a comma.</p> <p>I'm trying to write a program which will read each line and convert it to a list. My solution seems to make two lists but I don't know how to differentiate between the two as both lists are called "fil...
0
2016-10-03T11:42:36Z
39,901,969
<p>If you are looking to have a list for each line, you can use a dictionary where the key is the line number and the value of the dictionary entry is the list of names for that line. Something like this</p> <pre><code>with open('my_file.txt', 'r') as fin: students = {k:line[:-1].split(',') for k,line in enumerate...
0
2016-10-06T17:11:50Z
[ "python", "list", "file", "text" ]
Django/Python: How to get the latest value from a model queryset?
39,830,810
<p>I have created a model 'VehicleDetails' in which a user can fill the details of a vehicle and another model 'TripStatus' in which he can update the vehicle location. I wanted to get the latest location for which I did as in my below code. But when i running the server, it returns all the values not the latest value....
-1
2016-10-03T11:44:08Z
39,830,867
<p>Should just have to remove the .all():</p> <pre><code>tripstatus = TripStatus.objects.latest('statustime') </code></pre> <p>Or maybe:</p> <pre><code>tripstatus = TripStatus.order_by('-statustime').first() </code></pre>
0
2016-10-03T11:47:50Z
[ "python", "django", "django-models", "django-templates", "django-views" ]
Change DNA sequences in fasta file using Biopython
39,830,826
<p>I have a file in fasta format with several DNA sequences. I want to change the content of each sequence for another smaller sequence, keeping the same sequence id. The new sequences are in a list.</p> <pre><code>with open("outfile.fa", "w") as f: for seq_record in SeqIO.parse("ma-all-mito.fa", "fasta"): ...
1
2016-10-03T11:45:04Z
39,851,540
<p>I think that this <em>might</em> work:</p> <pre><code>records = SeqIO.parse("ma-all-mito.fa", "fasta") with open("outfile.fa", "w") as f: for r, s in zip(records,newSequences_ok): f.write(r.seq.seq.split('\n')[0] + '\n') f.write(s + '\n') </code></pre> <p>If not (and even if it does) -- you rea...
1
2016-10-04T11:49:51Z
[ "python", "biopython", "fasta" ]
Use LeaveOneGroupOut strategy on cross_val_score in sklearn
39,830,848
<p>I'd like to use <code>LeaveOneGroupOut</code> strategy to evaluate my model. According to <a href="http://scikit-learn.org/stable/modules/cross_validation.html#computing-cross-validated-metrics" rel="nofollow">sklearn's document</a>, <code>cross_val_score</code> seems convenient. </p> <p>However, the following code...
0
2016-10-03T11:46:31Z
39,831,546
<p>You do not define your <strong>groups</strong> parameter which is the group according to which you are going to split your data.</p> <p>The error comes from <strong>cross_val_score</strong> that takes this parameter in argument : in your case it is equal to <strong>None</strong>.</p> <p>Try to follow the example b...
1
2016-10-03T12:22:21Z
[ "python", "machine-learning", "scikit-learn" ]
Can I create a Google Drive folder using service account with Python?
39,830,956
<p>I can create a folder using account Owner but cannot share it with service account.</p> <p>Is there a way for My Python script to create a folder using service account and then upload a file?</p>
0
2016-10-03T11:53:23Z
39,848,117
<p>You can create a folder and upload file, same process flow as a real user when you using a service account.</p> <h3>BUT</h3> <p>As stated in this <a href="http://www.riskcompletefailure.com/2015/03/understanding-service-accounts.html" rel="nofollow">blog</a>, you have to remember that:</p> <blockquote> <p>A ser...
0
2016-10-04T08:56:52Z
[ "python", "google-drive-sdk" ]
combine two id into a new table?
39,831,016
<p>i had a task about text processing and i don't know how to combine some columns from separate tables into one table</p> <p>so here is the case: i have a table named <code>list</code> with <code>id_doc</code>, and <code>title</code> columns then i create a new table named <code>term_list</code> which contains a list...
1
2016-10-03T11:56:20Z
39,832,416
<p>You can iterate over rows in <code>term_list</code>:</p> <pre><code>SELECT id_term, term FROM term_list </code></pre> <p>for each <code>term</code> make:</p> <pre><code>SELECT id_doc FROM list WHERE titles LIKE "term" </code></pre> <p>and saves pairs <code>id_term</code> and <code>id_doc</code> in the table <cod...
0
2016-10-03T13:06:13Z
[ "python", "mysql", "database", "text-processing", "information-retrieval" ]
Binary to Hexadecimal converter
39,831,062
<p>I have written a code to try and convert a 4-bit binary number into Hexadecimal. Only thing is, when I type a value that begins with a '1' it comes up with the conversion, whereas if I type a value that starts with a '0' it doesn't work. Any help?</p> <pre><code>print ("""Here's how the program will work. You need ...
0
2016-10-03T11:59:11Z
39,831,184
<p>When you input an integer starting with an leading 0, python interprets it as being in base 8:</p> <pre><code>a = 0110 print a </code></pre> <p>will output</p> <pre><code>72 </code></pre> <p>Therefore, drop the leading 0 in your input, or remove them before casting <code>int()</code> on it</p>
0
2016-10-03T12:05:17Z
[ "python", "binary", "hex" ]
Binary to Hexadecimal converter
39,831,062
<p>I have written a code to try and convert a 4-bit binary number into Hexadecimal. Only thing is, when I type a value that begins with a '1' it comes up with the conversion, whereas if I type a value that starts with a '0' it doesn't work. Any help?</p> <pre><code>print ("""Here's how the program will work. You need ...
0
2016-10-03T11:59:11Z
39,831,194
<p>Instead of just coercing a string to integer, you need to pass the second parameter to <a href="https://docs.python.org/3/library/functions.html#int" rel="nofollow"><code>int</code> constructor</a> called <code>base</code>:</p> <pre><code>BINARY = int(input('Please enter your binary number here: '), 2) if BINARY ...
-1
2016-10-03T12:05:39Z
[ "python", "binary", "hex" ]
Binary to Hexadecimal converter
39,831,062
<p>I have written a code to try and convert a 4-bit binary number into Hexadecimal. Only thing is, when I type a value that begins with a '1' it comes up with the conversion, whereas if I type a value that starts with a '0' it doesn't work. Any help?</p> <pre><code>print ("""Here's how the program will work. You need ...
0
2016-10-03T11:59:11Z
39,831,200
<p>replace,</p> <pre><code>HEXADECIMAL = int(input("Please enter your binary number here: ")) </code></pre> <p>with,</p> <pre><code>temp = input("Please enter your binary number here: ") HEXADECIMAL = int (temp) </code></pre> <p>plus remove sleep time if there is an error.</p>
-1
2016-10-03T12:05:52Z
[ "python", "binary", "hex" ]
Binary to Hexadecimal converter
39,831,062
<p>I have written a code to try and convert a 4-bit binary number into Hexadecimal. Only thing is, when I type a value that begins with a '1' it comes up with the conversion, whereas if I type a value that starts with a '0' it doesn't work. Any help?</p> <pre><code>print ("""Here's how the program will work. You need ...
0
2016-10-03T11:59:11Z
39,831,373
<p>You dont have to use the <code>if/else</code> statements evertime. There is a cool way you can use <code>int()</code> in python, if you using a string, <code>int()</code> function can directly convert it to any base for you.</p> <pre><code>HEXADECIMAL = str(input()) base = 16 # for Hex and 2 for binary msg = "Your...
1
2016-10-03T12:13:04Z
[ "python", "binary", "hex" ]
Python: write list to csv, transposing the first row into a column
39,831,083
<p>Using python, I have data stored in a list:</p> <pre><code>a = [['a', 'b', 'c'], [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] </code></pre> <p>I want to write this list to a csv that looks like the following:</p> <pre><code>a, 1, 2, 3, 4 b, 5, 6, 7, 8 c, 9, 10, 11, 12 </code></pre> <p>This is the code I came up ...
2
2016-10-03T12:00:37Z
39,831,300
<p>use pandas library for playing with dataframe and writing to csv easily. It will be quit easy.</p>
-2
2016-10-03T12:10:17Z
[ "python", "csv", "transpose" ]
Python: write list to csv, transposing the first row into a column
39,831,083
<p>Using python, I have data stored in a list:</p> <pre><code>a = [['a', 'b', 'c'], [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] </code></pre> <p>I want to write this list to a csv that looks like the following:</p> <pre><code>a, 1, 2, 3, 4 b, 5, 6, 7, 8 c, 9, 10, 11, 12 </code></pre> <p>This is the code I came up ...
2
2016-10-03T12:00:37Z
39,831,324
<p>Maybe something like:</p> <pre><code>a = [['a', 'b', 'c'], [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] for header, data in zip(a[0], a[1:]): result = "{header}, {data}".format(header= header, data= ', '.join((str(n) for n in data))) print(result) a, 1, 2, 3, 4 b, 5, ...
0
2016-10-03T12:10:58Z
[ "python", "csv", "transpose" ]
Python: write list to csv, transposing the first row into a column
39,831,083
<p>Using python, I have data stored in a list:</p> <pre><code>a = [['a', 'b', 'c'], [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] </code></pre> <p>I want to write this list to a csv that looks like the following:</p> <pre><code>a, 1, 2, 3, 4 b, 5, 6, 7, 8 c, 9, 10, 11, 12 </code></pre> <p>This is the code I came up ...
2
2016-10-03T12:00:37Z
39,832,101
<p>You just need to pull the first <em>sublist</em> and <em>zip</em> with the remainder then use <em>writerows</em> after combining into a single list:</p> <pre><code>a = [['a', 'b', 'c'], [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] import csv with open('test.csv', 'w') as test_file: file_writer = csv.writer(tes...
0
2016-10-03T12:50:08Z
[ "python", "csv", "transpose" ]
How do I avoid cycles across two columns within a DataFrame to render a Sankey diagram with Google Charts?
39,831,103
<p>I have a DataFrame with source and destination IPs, and bytes,</p> <pre><code>[ 1.2.3.4, 8.8.8.8, 123456 ] ... [ 8.8.8.8, 1.2.3.4, 1234 ] </code></pre> <p>My problem is that I am using this DataFrame for a <a href="https://developers.google.com/chart/interactive/docs/gallery/sankey" rel="nofollow">JS visualization...
2
2016-10-03T12:01:40Z
39,831,925
<p>Without having any extra information would something like this be sufficient? :</p> <pre><code>for index in range(df1): if df1[a] == df2[b]: if df1[b] == df2[a]: df1.drop(df1.index[index]) pass </code></pre>
1
2016-10-03T12:41:14Z
[ "python", "pandas", "google-visualization" ]
Opening non-utf-8 csv file Python 3
39,831,197
<p>I have a csv file that is not <code>utf-8</code> encoded. And it seems impossible to open it in Python 3. I've tried all kinds of <code>.encode()</code> <code>Windows-1252</code>, <code>ISO-8859-1</code>, <code>latin-1</code> – every time I get</p> <pre><code>UnicodeDecodeError: 'utf-8' codec can't decode byte 0x...
1
2016-10-03T12:05:45Z
39,831,317
<p>Simply specify encoding when <strong>opening</strong> the file:</p> <pre><code>with open("xxx.csv", encoding="latin-1") as fd: rd = csv.reader(fd) ... </code></pre> <p>or with your own code:</p> <pre><code>csv.reader(open('myFile.csv', 'r', encoding='latin1'), delimiter = ';') </code></pre>
3
2016-10-03T12:10:51Z
[ "python", "csv", "utf-8" ]
How to decode a numpy array of dtype=numpy.string_?
39,831,230
<p>I need to decode, with Python 3, a string that was encoded the following way:</p> <pre><code>&gt;&gt;&gt; s = numpy.asarray(numpy.string_("hello\nworld")) &gt;&gt;&gt; s array(b'hello\nworld', dtype='|S11') </code></pre> <p>I tried:</p> <pre><code>&gt;&gt;&gt; str(s) "b'hello\\nworld'" &gt;&gt;&gt; s.deco...
2
2016-10-03T12:06:49Z
39,831,375
<p>If my understanding is correct, you can do this with <code>astype</code> which, if <code>copy = False</code> will return the array with the contents in the corresponding type:</p> <pre><code>&gt;&gt;&gt; s = numpy.asarray(numpy.string_("hello\nworld")) &gt;&gt;&gt; r = s.astype(str, copy=False) &gt;&gt;&gt; r arra...
1
2016-10-03T12:13:13Z
[ "python", "string", "python-3.x", "numpy" ]
How to decode a numpy array of dtype=numpy.string_?
39,831,230
<p>I need to decode, with Python 3, a string that was encoded the following way:</p> <pre><code>&gt;&gt;&gt; s = numpy.asarray(numpy.string_("hello\nworld")) &gt;&gt;&gt; s array(b'hello\nworld', dtype='|S11') </code></pre> <p>I tried:</p> <pre><code>&gt;&gt;&gt; str(s) "b'hello\\nworld'" &gt;&gt;&gt; s.deco...
2
2016-10-03T12:06:49Z
39,831,542
<p>In Python 3, there are two types that represent sequences of characters: <code>bytes</code> and <code>str</code> (contain Unicode characters). When you use <code>string_</code> as your type, numpy will return <code>bytes</code>. If you want the regular <code>str</code> you should use <code>unicode_</code> type in...
0
2016-10-03T12:22:08Z
[ "python", "string", "python-3.x", "numpy" ]
How to decode a numpy array of dtype=numpy.string_?
39,831,230
<p>I need to decode, with Python 3, a string that was encoded the following way:</p> <pre><code>&gt;&gt;&gt; s = numpy.asarray(numpy.string_("hello\nworld")) &gt;&gt;&gt; s array(b'hello\nworld', dtype='|S11') </code></pre> <p>I tried:</p> <pre><code>&gt;&gt;&gt; str(s) "b'hello\\nworld'" &gt;&gt;&gt; s.deco...
2
2016-10-03T12:06:49Z
39,836,043
<p>Another option is the <code>np.char</code> collection of string operations.</p> <pre><code>In [255]: np.char.decode(s) Out[255]: array('hello\nworld', dtype='&lt;U11') </code></pre> <p>It accepts the <code>encoding</code> keyword if needed. But <code>.astype</code> is probably better if you don't need thi...
1
2016-10-03T16:18:01Z
[ "python", "string", "python-3.x", "numpy" ]
I'm confused by pip installations
39,831,263
<p>I have recently begun having troubles using pip to install python packages. I have always used pip but never really understood how it actually works, my experience with it is basically limited to "pip install pkg". </p> <p>Recently when trying to install openCV on my machine, I followed a few guides that involved c...
0
2016-10-03T12:08:32Z
39,847,573
<p>Because you have 2 versions of python installed, the best solution is to install and use <a href="http://%20https://pypi.python.org/pypi/virtualenv" rel="nofollow" title="virtualenv">virtualenv</a></p> <p>A Virtual Environment is a tool to keep all dependencies required by different projects and python versions in ...
0
2016-10-04T08:28:27Z
[ "python", "terminal", "pip" ]
Multi-variable for loop with a tuple and a array
39,831,267
<pre><code>Cols = [(10,11),(8,9),(6,7),(4,5),(2,3),(0,1)] Index = [1,2,3,4,5,6] Temp = ['RT','85C','125C','175C','220C','260C'] for i,c,t in Index, Cols, Temp: print(i,c,t) </code></pre> <p>I wish to have i as a tuple, c as an integer and t as a string. When i try the above I keep getting a: </p> <p><strong>Val...
0
2016-10-03T12:08:40Z
39,831,310
<p>You need to use the <a href="https://docs.python.org/3/library/functions.html#zip" rel="nofollow"><code>zip</code></a> function to iterate through your lists element-wise</p> <pre><code>for i,c,t in zip(Index, Cols, Temp): print(i,c,t) </code></pre> <p>Output</p> <pre><code>1 (10, 11) RT 2 (8, 9) 85C 3 (6, 7)...
3
2016-10-03T12:10:33Z
[ "python", "python-3.x", "jupyter-notebook" ]
Multi-variable for loop with a tuple and a array
39,831,267
<pre><code>Cols = [(10,11),(8,9),(6,7),(4,5),(2,3),(0,1)] Index = [1,2,3,4,5,6] Temp = ['RT','85C','125C','175C','220C','260C'] for i,c,t in Index, Cols, Temp: print(i,c,t) </code></pre> <p>I wish to have i as a tuple, c as an integer and t as a string. When i try the above I keep getting a: </p> <p><strong>Val...
0
2016-10-03T12:08:40Z
39,831,331
<p>All you need is a <code>zip()</code></p> <pre><code>Cols = [(10,11),(8,9),(6,7),(4,5),(2,3),(0,1)] Index = [1,2,3,4,5,6] Temp = ['RT','85C','125C','175C','220C','260C'] for i,c,t in zip(Index, Cols, Temp): print(i,c,t) </code></pre>
2
2016-10-03T12:11:19Z
[ "python", "python-3.x", "jupyter-notebook" ]
Multi-variable for loop with a tuple and a array
39,831,267
<pre><code>Cols = [(10,11),(8,9),(6,7),(4,5),(2,3),(0,1)] Index = [1,2,3,4,5,6] Temp = ['RT','85C','125C','175C','220C','260C'] for i,c,t in Index, Cols, Temp: print(i,c,t) </code></pre> <p>I wish to have i as a tuple, c as an integer and t as a string. When i try the above I keep getting a: </p> <p><strong>Val...
0
2016-10-03T12:08:40Z
39,831,561
<blockquote> <p>you can do like this</p> </blockquote> <pre><code>Cols = [(10,11),(8,9),(6,7),(4,5),(2,3),(0,1)] Index = [1,2,3,4,5,6] Temp = ['RT','85C','125C','175C','220C','260C'] loops_value = ['First','Second','Third','Fourth','Fifth','Sixth'] for j, i, c, t in zip(loops_value, Index, Cols, Temp): print "%...
2
2016-10-03T12:23:14Z
[ "python", "python-3.x", "jupyter-notebook" ]
Multi-variable for loop with a tuple and a array
39,831,267
<pre><code>Cols = [(10,11),(8,9),(6,7),(4,5),(2,3),(0,1)] Index = [1,2,3,4,5,6] Temp = ['RT','85C','125C','175C','220C','260C'] for i,c,t in Index, Cols, Temp: print(i,c,t) </code></pre> <p>I wish to have i as a tuple, c as an integer and t as a string. When i try the above I keep getting a: </p> <p><strong>Val...
0
2016-10-03T12:08:40Z
39,833,053
<p>Basically the for statement iterates over the contents, one by one, so in each iteration, one value is available.</p> <p>When using</p> <pre><code> for i,c,t in Index, Cols, Temp: </code></pre> <p>you are trying to unpack one value into three variables that's why your are getting <strong>Too many values to un...
1
2016-10-03T13:38:28Z
[ "python", "python-3.x", "jupyter-notebook" ]
Python pandas check if the last element of a list in a cell contains specific string
39,831,410
<pre><code>my dataframe df: index url 1 [{'url': 'http://bhandarkarscollegekdp.org/'}] 2 [{'url': 'http://cateringinyourhome.com/'}] 3 NaN 4 [{'url': 'http://muddyjunction.com/'}] 5 [...
1
2016-10-03T12:14:59Z
39,831,687
<p>I think you can first replace <code>NaN</code> to <code>empty url</code> and then use <code>apply</code>:</p> <pre><code>df = pd.DataFrame({'url':[[{'url': 'http://bhandarkarscollegekdp.org/'}], np.nan, [{'url': 'http://cateringinyourhome.com/'}], ...
1
2016-10-03T12:29:14Z
[ "python", "loops", "pandas", "contain" ]
Python pandas check if the last element of a list in a cell contains specific string
39,831,410
<pre><code>my dataframe df: index url 1 [{'url': 'http://bhandarkarscollegekdp.org/'}] 2 [{'url': 'http://cateringinyourhome.com/'}] 3 NaN 4 [{'url': 'http://muddyjunction.com/'}] 5 [...
1
2016-10-03T12:14:59Z
39,831,789
<p>not sure url is str or other types</p> <p>you can do like this:</p> <pre><code>"https" in str(df.url[len(df)-1]) </code></pre> <p>or </p> <pre><code>str(df.ix[len(df)-1].url).__contains__("https") </code></pre>
0
2016-10-03T12:34:01Z
[ "python", "loops", "pandas", "contain" ]
Python - GUI (TKinter), getting variables from other functions without running the whole function agan
39,831,418
<p>I do have an problem i can't realy get solved. The problem is, i do have two separate buttons. In one button I want to load a selected file. And with the other one i want to do some searching. However i can't get de variables from one function to the otherone without running the whole function again. So that means, ...
-1
2016-10-03T12:15:31Z
39,835,190
<p>Two methods</p> <ol> <li>Use a global variable for txtFile</li> <li>Use OO and create the functions as part of a class so that they can share variables. </li> </ol> <p>I've given you an example of option 2. Since It is my preferred method of working.</p> <p>If you click "Run !" and haven't clicked on "Select .txt...
1
2016-10-03T15:29:03Z
[ "python", "function", "variables", "tkinter" ]
snimpy.snmp.SNMPNoSuchObject: No such object was found
39,831,446
<p>I'm having an exception raised, but I don't get why</p> <pre><code>snimpy.snmp.SNMPNoSuchObject: No such object was found </code></pre> <h3>Code</h3> <pre><code>from snimpy import manager as snimpy def snmp(hostname, oids, mibs): logger.debug(hostname) logger.debug(oids) logger.debug(mibs) for mi...
0
2016-10-03T12:16:43Z
39,832,038
<p>One of the <code>oid</code> seem to trigger the error (cf. <code>'.1.3.6.1.2.1.43.10.2.1.4.1.1' # SNMPv2-SMI::mib-2.43.10.2.1.4.1.1 page count</code>), moving it to last fix the error. But this is a dubious solution.</p> <pre><code>oids = [ '.1.3.6.1.2.1.25.3.2.1.3.1', # HOST-RESOURCES-MIB::hrDeviceDescr.1 ...
0
2016-10-03T12:47:15Z
[ "python", "snmp", "snimpy" ]
Dynamic parameters in JSON serializable class
39,831,794
<p>I am trying to create a JSON object with <code>json</code> library from Python 2.7. I am creating a class with needed parameters to serialize like:</p> <pre><code>class DataMessage: channelID = 0 messageID = 0 timestamp = 0 voltageRMS = 0 currentRMS = 0 voltageDC = [] currentDC = [] </co...
0
2016-10-03T12:34:14Z
39,832,051
<p>You will have to implement a custom <a href="https://docs.python.org/2/library/json.html#json.JSONEncoder" rel="nofollow"><code>JSONEncoder</code></a> for your class that unpacks each array:</p> <pre><code>from json import JSONEncoder class MyEncoder(JSONEncoder): def default(self, o): result = { ...
1
2016-10-03T12:47:42Z
[ "python", "json", "serialization" ]
json2html, python: json data not converted to html
39,831,894
<p>I'm trying to format json data to html using json2html. The json data look like this:</p> <pre><code>json_obj = [{"Agent Status": "status1", "Last backup": "", "hostId": 1234567, "hostfqdn": "test1.example.com", "username": "user1"}, {"Agent Status": "status2", "Last backup": "", "hostId": 2345678, "hostfqdn": "tes...
0
2016-10-03T12:39:22Z
39,832,966
<p>Make sure that <code>json_obj</code> is an array of objects and not a string (<code>str</code>).</p> <p>I put your code to a complete sample:</p> <pre><code>from json2html import * json_obj = [{"Agent Status": "status1", "Last backup": "", "hostId": 1234567, "hostfqdn": "test1.example.com", "username": "user1"}, {...
0
2016-10-03T13:34:45Z
[ "python", "html", "json", "json2html" ]