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 |
|---|---|---|---|---|---|---|---|---|---|
How to access different data type element in a list? | 38,245,082 | <p>I have table varchar column with values, I'm trying to create & access list element in Python for data cleaning. I have list ( Column sample values) like this:</p>
<pre><code>Caller_ID = ['Ambulance',1,2,3,'Fire Crew',1,2]
</code></pre>
<p>i.e Ambulance followed by "1, 2, 3" means ambulance was contacted 3 tim... | -1 | 2016-07-07T12:08:12Z | 38,245,856 | <p>This is my solution, no imports needed, just an easy and clear-to-read for loop.</p>
<pre><code>Caller_ID = ['Ambulance',1,2,3,'Fire Crew',1,2]
new_list = []
for item in Caller_ID:
if type(item) == str:
current = item
else:
new_list.append(current)
>>> new_list
['Ambulance', 'Ambu... | 2 | 2016-07-07T12:46:16Z | [
"python"
] |
Django edit parent's fields inside child | 38,245,087 | <p>I'm facing a problem with django-admin. I have three objects:</p>
<ul>
<li>Description</li>
<li>Job</li>
<li>Project</li>
</ul>
<p>And I want to edit the Description directly inside Job and Project.</p>
<p>Here is my <code>model.py</code>:</p>
<pre><code>class Description(models.Model):
short_desc = models.T... | 1 | 2016-07-07T12:08:24Z | 38,247,338 | <p>You get this error because inlines are intended to be used in the other direction (See <a href="http://stackoverflow.com/q/35609183/1529346">this question</a>).</p>
<p>I think for your usecase you'd better use <a href="https://docs.djangoproject.com/en/stable/topics/db/models/#model-inheritance" rel="nofollow">mode... | 1 | 2016-07-07T13:54:22Z | [
"python",
"django",
"django-models",
"django-admin",
"python-3.5"
] |
How to set common prefix for all tables in SQLAlchemy | 38,245,145 | <p>I know there is a way to instrument SQLAlchemy to prepend common <code>prefix</code> to all <strong>columns</strong>, is it possible to add a common <code>prefix</code> to all <strong>table names</strong> derived from single <code>declarative_base</code>?</p>
| 2 | 2016-07-07T12:11:16Z | 38,245,575 | <p>Use <a href="http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/api.html#sqlalchemy.ext.declarative.declared_attr" rel="nofollow"><code>declared_attr</code></a> and a customized <code>Base</code> along the lines of:</p>
<pre><code>from sqlalchemy.ext.declarative import declared_attr
class PrefixerBase... | 3 | 2016-07-07T12:32:32Z | [
"python",
"sqlalchemy"
] |
Fetching data from external program | 38,245,159 | <p>I have an external program, <a href="https://github.com/opentrack/opentrack" rel="nofollow">opentrack</a>, that tracks head position using IR LED's. The position is updated in the program in real-time, but my problem is that I would like to get that data into my python code. Is it possible to do this? </p>
<p>I've ... | -1 | 2016-07-07T12:11:42Z | 38,245,297 | <p>The page you linked to clearly lists no fewer than 9 different ways in which opentrack can output the data.</p>
<p>So you need to figure out which one to use, and write Python code to act as a receiver for one of those methods. Perhaps UDP, since that sounds simple enough.</p>
<p>Hint: to decode any binary format,... | 2 | 2016-07-07T12:18:41Z | [
"python"
] |
Save function outputs (including pandas DataFrame) to workspace in Python | 38,245,175 | <p>Created a function in Python with filepath string as input. Function returns a list and a dataframe. How to call the function properly in order to save the dataframe to workspace?
Code works perfectly without the function but I need the output for further caluclations.
I want to save the whole dataframe, not just pa... | 1 | 2016-07-07T12:12:13Z | 38,245,233 | <pre><code>return column_list
return dataframe
</code></pre>
<p>Once you hit the first return statement the function returns, and the the second return statement is never reached. That's why the line <code>column_list, dataframe = import_r_data('filepathstring')</code> raises a <code>ValueError</code>:</p>
<p><code>i... | 0 | 2016-07-07T12:15:19Z | [
"python",
"pandas",
"dataframe",
"save",
"output"
] |
win32api.GetFileAttributes is thowing 'Access is denied.' error | 38,245,273 | <p>I am trying to get file attributes in python using win32api <code>GetFileAttributes</code> method and getting error access is denied.</p>
<pre><code>(5, 'GetFileAttributes', 'Access is denied.')
</code></pre>
<p>MSDN documentation doesn't contain an error section for <code>GetFileAttributes</code>.</p>
| 0 | 2016-07-07T12:17:35Z | 38,425,045 | <p>When the GetFileAttributes function is called, the kernel actualy attempts to open the file with FILE_READ_ATTRIBUTES access right. So, if the security descriptor of the file does not grant you that right, you get the access denied error (if some other conditions are not met).</p>
<p>Being an admin/system user on W... | 0 | 2016-07-17T19:18:51Z | [
"python",
"winapi",
"msdn"
] |
smtp = smtplib.SMTP(host) > (mail.host)? | 38,245,454 | <p>I have a scanning script that currently works by connecting to an SMTP server, printing the results and moving to the next server in the list. This is the first connect code:</p>
<pre><code>def sendchk(listindex, host, user, password): # seperated function for checking
try:
smtp = smtplib.SMTP(host)
smtp.... | 0 | 2016-07-07T12:26:28Z | 38,246,396 | <p>Without having tested it: if <em>sub1</em> is "mail." and <em>host</em> is "myhost.com" then <code>'{0}@{1}'.format(sub1, host)</code> will result in <em>mail.@myhost.com</em>. Is that really your subdomain name? I suppose it should be <em>mail.myhost.com</em>. If so then drop the "@" in your formatting string.</p>
| 0 | 2016-07-07T13:10:51Z | [
"python",
"smtp"
] |
Find point along line a specified distance from a polygon | 38,245,512 | <p>Given a 2-D closed polygon defined by a series of points and an infinite line, I would like to find points on that line a specified distance from the polygon. The polygon is known to be closed, not intersecting, and not containing 3 consecutive collinear points. In general there are many possible points along the ... | -2 | 2016-07-07T12:29:23Z | 38,253,772 | <p>If number of polygon edges is reasonable, you can use simple linear algorithm.</p>
<p>Let's parametric equation for line is</p>
<pre><code>L(u) = L0 + u * dL
</code></pre>
<p>where L0 is some base point, dL is direction vector, u is parameter</p>
<p>and parametric equation for i-th segment is</p>
<pre><code>P =... | 0 | 2016-07-07T19:27:20Z | [
"python",
"numpy",
"geometry"
] |
pandas: merge on column of ByteArray | 38,245,661 | <p>Any ideas on how I can join two pandas arrays on a commonly named bytearray field? The field in the source (Teradata) is an actual ByteArray, and from the Teradata Side, this cannot be forced to character or something usable outside of Teradata)</p>
<p>The Teradata Export reads into a Panda's array beautifully. Bu... | 2 | 2016-07-07T12:37:14Z | 38,248,242 | <p>Convert your <code>bytearray</code>s to their immutable cousin <code>bytes</code>.</p>
<pre><code>import pandas as pd
# Create your example `dbase`
DatabaseId_dbase = list(map(bytearray, [[2, 0, 243, 185], [2, 0, 168, 114],
[2, 0, 133, 153], [2, 0, 29, 184], [2, 0, 190, 183], [2, 0, 71, 55],
[2, 0, 169, 18... | 1 | 2016-07-07T14:34:01Z | [
"python",
"merge",
"bytearray",
"teradata"
] |
wxPython handling SIGTERM / SIGINT | 38,245,701 | <p>I have a wxPython app. I want it to respond to SIGTERM and SIGINT just like as if the "close" button had been clicked. However, when I bind the signals using <code>signal.signal(signal.SIGTERM, exit_handler)</code>, they only get executed after an event is sent to the main app graphically (clicking on a button, open... | 1 | 2016-07-07T12:39:18Z | 38,290,520 | <p>One way of doing it, is to add a 'timer' to fake an event.</p>
<pre><code>import wx
import signal, os
def signalUSR1_handler(sig,frame):
print "Signal Caught"
class ExampleFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
pid_no = str(os.getpid())
panel =... | 1 | 2016-07-10T09:37:37Z | [
"python",
"python-2.7",
"wxpython",
"signals"
] |
Using pandas.dataframe.pivot_table with non-numeric, non-unique values | 38,245,706 | <p>I am trying to call the pivot_table function on a pandas.dataframe object. This is an example of the object before calling the pivot_table function:</p>
<pre><code> Bid Symb Ask DateTime
0 201000 ESU6 201050 2016-06-19 18:59:58.337134544-05:00
1 201025 ESU6 201075 2016-06-19 ... | 1 | 2016-07-07T12:39:44Z | 38,245,778 | <p>You can simple set new <code>index</code> after pivoting by values of column <code>DateTime</code>:</p>
<pre><code>result = object.pivot_table(columns='Symb', values=['Bid','Ask'], index=object.index)
result.index = object.DateTime
#remove Multiindex in columns
result.columns = ['.'.join(col) for col in result.colu... | 1 | 2016-07-07T12:42:55Z | [
"python",
"datetime",
"pandas",
"dataframe"
] |
Mixing Queue Ops with regular Python for data loading | 38,245,711 | <p>I am working on sequence learning for audio and need to load my audio data. Currently I rely on <code>tf.decode_csv</code> to load pairs of filenames and labels into a Tensorflow Queue. However, I then would like to actually read the file and process it with other Python libs. Yet, the CSV decoder / dequeuing operat... | 0 | 2016-07-07T12:40:08Z | 38,246,513 | <p>To extract the content of a tensor, you have to "run it" into a session.</p>
<p><code>sound_path_value = sess.run(sound_path)</code></p>
| 0 | 2016-07-07T13:16:42Z | [
"python",
"tensorflow"
] |
Mixing Queue Ops with regular Python for data loading | 38,245,711 | <p>I am working on sequence learning for audio and need to load my audio data. Currently I rely on <code>tf.decode_csv</code> to load pairs of filenames and labels into a Tensorflow Queue. However, I then would like to actually read the file and process it with other Python libs. Yet, the CSV decoder / dequeuing operat... | 0 | 2016-07-07T12:40:08Z | 38,249,108 | <p>Let's assume your <code>read_wav</code> function expects a filename (string) as argument, and returns a numpy array of float values (the decoded file). </p>
<p>The computation of <code>read_wav</code> takes place outside of the tensorflow graph, in python. Instead of calling <code>sess.run(sound_path)</code>, which... | 2 | 2016-07-07T15:10:39Z | [
"python",
"tensorflow"
] |
Get list of sheets and latest sheet in google spreadsheet api v4 in Python | 38,245,714 | <p>I am trying to read and write values of different sheets in python 3 following the <a href="https://developers.google.com/sheets/quickstart/python" rel="nofollow">google official documentation</a>. Though I am able to read values from certain sheets using range property in <code>rangeName = 'Class Data!A2:E'</code> ... | 1 | 2016-07-07T12:40:21Z | 38,271,421 | <p>You can get a list of sheets by using the "get" method on spreadsheets:</p>
<pre><code>sheet_metadata = service.spreadsheets().get(spreadsheetId=spreadsheet_id).execute()
sheets = sheet_metadata.get('sheets', '')
title = sheets[0].get("properties", {}).get("title", "Sheet1")
sheet_id = sheets[0].get("properties", {... | 4 | 2016-07-08T16:23:24Z | [
"python",
"google-spreadsheet-api",
"google-sheets-api"
] |
Communicating with HSM python | 38,245,717 | <p>I'm attempting to establish a connection with a remote machine through this script. The script is being run on the remote machine attempting to open a session, which I believe I'm doing incorrectly. I'm trying to access slot zero in the library <code>opt/PTK/lib/libcryptoki.so</code> which contains a keystore via sm... | 0 | 2016-07-07T12:40:23Z | 38,246,907 | <p>This works perfectly for me. In terms of the connection. </p>
<pre><code>import subprocess
proc = subprocess.Popen(("ssh", "remoteuser@host", "echo", "1"),
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
</code></pre>
| 0 | 2016-07-07T13:34:35Z | [
"python",
"smartcard",
"pkcs#11",
"hsm"
] |
Gensim Doc2Vec - Pass corpus sentences to Doc2Vec function | 38,245,739 | <p>I used the <code>MySentences</code> class for extracting sentences from all files in a directory and use this sentences for train a <em>word2vec</em> model.
My dataset is unlabeled.</p>
<pre><code>class MySentences(object):
def __init__(self, dirname):
self.dirname = dirname
def __iter__(self):
... | 1 | 2016-07-07T12:41:04Z | 38,250,606 | <p>There is no reason to use extra classes to solve the problem. In new updates of library, a new function <code>TaggedLineDocument</code> added to transform sentence to vector.</p>
<pre><code>sentences = TaggedLineDocument(INPUT_FILE)
</code></pre>
<p>and then, train the model</p>
<pre><code>model = Doc2Vec(alpha=0... | 0 | 2016-07-07T16:20:06Z | [
"python",
"text-mining",
"gensim",
"word2vec",
"doc2vec"
] |
Opening a file based on user's input python | 38,245,852 | <p>How to open a file from the list of given files based on the user's input which is an integer </p>
<pre><code>print("Enter 1.tp.txt\n2.c17testpat.pat\n3.c432testpat.pat\n4.c499testpat.pat\n5.c1335testpat.pat\n6.c6228testpat.pat")
user = input("Enter a number")
if user == 1:
filename = "tp.txt"
elif user == 2:
... | -1 | 2016-07-07T12:46:08Z | 38,245,954 | <p>probably because you need to convert user to <code>int</code> first (might be a string as written). Also you should probably finish with a default case to throw an error if the user inputs a non sensical value...</p>
| 1 | 2016-07-07T12:50:00Z | [
"python",
"python-3.x"
] |
Opening a file based on user's input python | 38,245,852 | <p>How to open a file from the list of given files based on the user's input which is an integer </p>
<pre><code>print("Enter 1.tp.txt\n2.c17testpat.pat\n3.c432testpat.pat\n4.c499testpat.pat\n5.c1335testpat.pat\n6.c6228testpat.pat")
user = input("Enter a number")
if user == 1:
filename = "tp.txt"
elif user == 2:
... | -1 | 2016-07-07T12:46:08Z | 38,246,087 | <p>You could store the file list as a Python list, like so:</p>
<pre><code>files = ["filename_1", "filename_2", "filename_3"]
</code></pre>
<p>Then to print them, you would use a for loop:</p>
<pre><code>for i, s in enumerate(files): # Use enumerate because we need to know which element it was
print(str(i + 1) +... | 3 | 2016-07-07T12:56:41Z | [
"python",
"python-3.x"
] |
Opening a file based on user's input python | 38,245,852 | <p>How to open a file from the list of given files based on the user's input which is an integer </p>
<pre><code>print("Enter 1.tp.txt\n2.c17testpat.pat\n3.c432testpat.pat\n4.c499testpat.pat\n5.c1335testpat.pat\n6.c6228testpat.pat")
user = input("Enter a number")
if user == 1:
filename = "tp.txt"
elif user == 2:
... | -1 | 2016-07-07T12:46:08Z | 38,246,368 | <p>Not python but worth to know how to use it via bash.
A simple bash sample that list a folder content and let's user choose the file by the index. </p>
<pre><code># menu.sh
# usage: bash menu.sh FOLDER
select FILENAME in $1/*;
do
case $FILENAME in
"$QUIT")
echo "Exiting."
break
... | 0 | 2016-07-07T13:09:17Z | [
"python",
"python-3.x"
] |
Opening a file based on user's input python | 38,245,852 | <p>How to open a file from the list of given files based on the user's input which is an integer </p>
<pre><code>print("Enter 1.tp.txt\n2.c17testpat.pat\n3.c432testpat.pat\n4.c499testpat.pat\n5.c1335testpat.pat\n6.c6228testpat.pat")
user = input("Enter a number")
if user == 1:
filename = "tp.txt"
elif user == 2:
... | -1 | 2016-07-07T12:46:08Z | 38,246,378 | <p>As the question indicates a strong will to learn coding and already tried something, I offer a variant that works for python version 3 (in version 2 one would need raw_input instead of input and a future import to declare the print function):</p>
<pre><code>#! /usr/bin/env python3
import sys
names_known = ( # H... | 0 | 2016-07-07T13:09:42Z | [
"python",
"python-3.x"
] |
Cumulative Ranking of Values in Pandas with Ties | 38,246,058 | <p>I am trying to find a way to do a cumulative total that accounts for ties in Pandas.</p>
<p>Lets take hypothetical data from a track meet, where I have people, races, heats, and time.</p>
<p>Each person's placement is according to the following:</p>
<p>For a given race/heat combination:</p>
<ul>
<li>The person p... | 3 | 2016-07-07T12:55:06Z | 38,246,382 | <p>You could use:</p>
<pre><code>grouped = df.groupby(['Race','Heat'])
df['Place'] = grouped['Time'].transform(lambda x: pd.factorize(x, sort=True)[0]+1)
</code></pre>
<hr>
<pre><code>import pandas as pd
df = pd.DataFrame({'Heat': [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], 'Person': ['RUNNER1', 'RUNNER2',... | 7 | 2016-07-07T13:10:00Z | [
"python",
"pandas",
"dataframe",
"cumulative-sum"
] |
How to merge data from different df using pandas | 38,246,155 | <p>I have 2 dataframes and I want to get df, where in first file I have a lot of data and in the second file I have a list of <code>iD</code>, that I want get from first file.</p>
<p>I use </p>
<pre><code>merged = pd.merge(buys, chunk, left_on='id', right_on='ID')
</code></pre>
<p>where <code>chunk</code> - a part o... | 0 | 2016-07-07T12:59:49Z | 38,248,427 | <p>IIUC you want to merge your two dataframes and just keeping the <code>id</code> present in <code>buys</code>? Then you cann pass the <code>how</code> option in your <code>merge</code> like this:</p>
<pre><code>merged = pd.merge(buys, chunk, left_on='id', right_on='ID', how = 'left')
</code></pre>
<p>Note that if t... | 0 | 2016-07-07T14:41:34Z | [
"python",
"pandas"
] |
Efficient way to combine pandas data frames row-wise | 38,246,166 | <p>I've 14 data frames each with 14 columns and more than 250,000 rows.
The data frame have identical column headers and I would like to merge the data frames row-wise. I attempted to concatenate the data frames to a 'growing' DataFrame and it's taking several hours.</p>
<p>Essentially, I was doing something like belo... | 0 | 2016-07-07T13:00:26Z | 38,246,298 | <p>Create a list with all your data frames:</p>
<pre><code>dfs = []
for i in range(13):
df = ... # However it is that you create your dataframes
dfs.append(df)
</code></pre>
<p>Then concatenate them in one swoop:</p>
<pre><code>merged = pd.concat(dfs) # add ignore_index=True if appropriate
</code></pre>
... | 3 | 2016-07-07T13:06:07Z | [
"python",
"numpy",
"pandas"
] |
How can I take integer regex? | 38,246,360 | <p>I'm trying to use regex in Python for taking some parts of a text. From a text I need to take this kind of substring '2016-049172'. So what's the equivalent regex?
Thank you very much.</p>
<p>Here's a piece of code:</p>
<pre><code>import re
pattern = re.compile(r"\s-\s[0-9]+[0-9]$]")
my_string = 'Ticketing TSX - ... | -6 | 2016-07-07T13:08:54Z | 38,247,901 | <p>The regex to use is this:</p>
<pre><code>\d{4}-\d{6}
</code></pre>
<p>Updating your example code, this will do it for you:</p>
<pre><code>import re
pattern = re.compile(r"\d{4}-\d{6}")
my_string = 'Ticketing TSX - 2016-049172'
matches = re.findall(pattern,my_string)
print matches
</code></pre>
| 1 | 2016-07-07T14:20:01Z | [
"python",
"regex",
"integer"
] |
How can I take integer regex? | 38,246,360 | <p>I'm trying to use regex in Python for taking some parts of a text. From a text I need to take this kind of substring '2016-049172'. So what's the equivalent regex?
Thank you very much.</p>
<p>Here's a piece of code:</p>
<pre><code>import re
pattern = re.compile(r"\s-\s[0-9]+[0-9]$]")
my_string = 'Ticketing TSX - ... | -6 | 2016-07-07T13:08:54Z | 38,248,099 | <p>As others have posted, the regular expression you are looking for is:</p>
<pre><code>\d{4}-\d{6}
</code></pre>
<p>The full code I would use:</p>
<pre><code>import re
my_string = 'Ticketing TSX - 2016-049172'
matches = re.findall(r"\d{4}-\d{6}", my_string)
print matches
</code></pre>
<p>If, for example, the len... | 1 | 2016-07-07T14:28:15Z | [
"python",
"regex",
"integer"
] |
Python 3.4 - 'bytes' object has no attribute 'encode' | 38,246,412 | <p>I'm trying to store salt and hashed password before inserting each document into a collection.But on encoding the salt and password, it shows the following error : </p>
<pre><code> line 26, in before_insert
document['salt'] = bcrypt.gensalt().encode('utf-8')
AttributeError: 'bytes' object has no attribute 'encode... | -1 | 2016-07-07T13:11:23Z | 38,247,017 | <p>You're using : <pre>bcrypt.gensalt()</pre>
This method seems to generate a bytes object. These objects do not have any encode methods as they only work with ASCII compatible data. So you can try without <em>.encode('utf-8')</em></p>
<p><a href="https://docs.python.org/3/library/stdtypes.html#binary-sequence-types-... | 0 | 2016-07-07T13:39:29Z | [
"python",
"python-3.x",
"eve"
] |
Python re module prefix | 38,246,446 | <p>I'm learning Python3 now and have come to <code>re</code> module. I want to write a pattern that searches the given string for Mobile Numbers. For Indian Nos.,
<code>re.compile(r'\d\d\d\d\d\d\d\d\d\d')</code> should suffice. But Indian Nos. also
use <code>+91</code> and <code>0</code> as the country code and I wa... | 0 | 2016-07-07T13:13:34Z | 38,246,540 | <p>First off, you can use limitation in order to specify the number of digits instead of typing them all. Secondly you can use non-capture grouping (by adding <code>?:</code> at the leading of your group) if you don't want the result of captured group separately.</p>
<pre><code>r = re.compile(r'(?:0|\+91)?\d{9}')
</co... | 2 | 2016-07-07T13:17:58Z | [
"python"
] |
Python re module prefix | 38,246,446 | <p>I'm learning Python3 now and have come to <code>re</code> module. I want to write a pattern that searches the given string for Mobile Numbers. For Indian Nos.,
<code>re.compile(r'\d\d\d\d\d\d\d\d\d\d')</code> should suffice. But Indian Nos. also
use <code>+91</code> and <code>0</code> as the country code and I wa... | 0 | 2016-07-07T13:13:34Z | 38,246,743 | <p>Nice pattern for telefon numbers is</p>
<pre><code>_pattern = \
"""
^ # string start
[+]? # optional "+"
[\d \(\)]* # a number of digits, blanks or brackets
[/]? # an optional slash
[\d \(\)]* # number of digits, blanks, brackets an this rep... | 0 | 2016-07-07T13:26:31Z | [
"python"
] |
Python: How do I get user input in the middle of a sentence (fill-in-the-blank style) using the input function? | 38,246,529 | <p>I am trying to create a program that calculates sales tax. I first ask the user what was the total cost of their meal. I then ask them what is the sales tax of their area in the form of:</p>
<pre><code>y = input('What is the sales tax of your area? ')
</code></pre>
<p>I want to have a percent sign "%" at the end o... | 0 | 2016-07-07T13:17:33Z | 38,246,697 | <p>You can't do that with input() without knowing how long the input will be. You could just ask the user to answer in percent. You could use ANSI escape codes to put the percent sign after the place where you get input, but it will be overwritten if you type until you reach the percent sign. If you really need that, t... | 0 | 2016-07-07T13:25:00Z | [
"python",
"python-3.x",
"user-input",
"tax"
] |
Python: How do I get user input in the middle of a sentence (fill-in-the-blank style) using the input function? | 38,246,529 | <p>I am trying to create a program that calculates sales tax. I first ask the user what was the total cost of their meal. I then ask them what is the sales tax of their area in the form of:</p>
<pre><code>y = input('What is the sales tax of your area? ')
</code></pre>
<p>I want to have a percent sign "%" at the end o... | 0 | 2016-07-07T13:17:33Z | 38,247,213 | <p>you can do something like this</p>
<pre><code>x=input("What is the sales tax in your area? % \x1B[5D")
</code></pre>
<p>it first print the line and then the escape sequence <code>\x1B[5D</code> moves the cursor 5 place backwards. But what the 1st answer says, you can not do this without knowing beforehand how l... | 0 | 2016-07-07T13:48:40Z | [
"python",
"python-3.x",
"user-input",
"tax"
] |
Python: How do I get user input in the middle of a sentence (fill-in-the-blank style) using the input function? | 38,246,529 | <p>I am trying to create a program that calculates sales tax. I first ask the user what was the total cost of their meal. I then ask them what is the sales tax of their area in the form of:</p>
<pre><code>y = input('What is the sales tax of your area? ')
</code></pre>
<p>I want to have a percent sign "%" at the end o... | 0 | 2016-07-07T13:17:33Z | 38,247,928 | <p>I have a solution for you. Just a trick, didn't find direct solution even after searching for long. But one thing is for sure, you need to know the length of input, else for very long input the <code>!</code> will be overwritten. Code below:</p>
<pre><code>x = float(input("What is the cost of your meal? "))
y = inp... | 0 | 2016-07-07T14:21:06Z | [
"python",
"python-3.x",
"user-input",
"tax"
] |
How to create a heat map in python that ranges from green to red? | 38,246,559 | <p>I'm trying to plot log ratios from the range -3 to 3 and want negative ratios to be green and positive to be red, with a log ratio of 0 (center) to be white in color. None of the pre-existing color schemes in matplotlib provide this option, and I haven't been able to figure out how to output a nice gradient manually... | 3 | 2016-07-07T13:19:01Z | 38,246,905 | <p>How about the following that uses <a href="http://matplotlib.org/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap" rel="nofollow"><code>LinearSegmentedColormap</code></a>:</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
cmapGR = ... | 2 | 2016-07-07T13:34:34Z | [
"python",
"matplotlib",
"heatmap"
] |
How to create a heat map in python that ranges from green to red? | 38,246,559 | <p>I'm trying to plot log ratios from the range -3 to 3 and want negative ratios to be green and positive to be red, with a log ratio of 0 (center) to be white in color. None of the pre-existing color schemes in matplotlib provide this option, and I haven't been able to figure out how to output a nice gradient manually... | 3 | 2016-07-07T13:19:01Z | 38,247,002 | <p>you can create your own using a <a href="http://matplotlib.org/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap" rel="nofollow"><code>LinearSegmentedColormap</code></a>. I like to set the red and green channels to something less than 1.0 at the upper and lower limits so the colours aren't too bright (he... | 1 | 2016-07-07T13:38:44Z | [
"python",
"matplotlib",
"heatmap"
] |
PSQL & Python = how to have returned a list of "elements" | 38,246,637 | <p>i have this code:</p>
<pre><code>cur.execute("SELECT numbers FROM table")
supp = cur.fetchall()
for item in supp:
print item
</code></pre>
<p>and it prints:</p>
<pre><code>('one',)
('two',)
('three',)
</code></pre>
<p>how can i have?</p>
<pre><code>one
two
three
</code></pre>
| -2 | 2016-07-07T13:21:57Z | 38,246,669 | <p>Each <code>item</code> correspond to a row of a result of your query, each row is represented by a <em>tuple</em>. If you want to get the first items of every tuple, you can <a href="http://stackoverflow.com/questions/10867882/tuple-unpacking-in-for-loops">unpack them in the <code>for</code> loop</a>:</p>
<pre><cod... | 1 | 2016-07-07T13:23:33Z | [
"python",
"sql",
"postgresql",
"python-2.7",
"psql"
] |
PSQL & Python = how to have returned a list of "elements" | 38,246,637 | <p>i have this code:</p>
<pre><code>cur.execute("SELECT numbers FROM table")
supp = cur.fetchall()
for item in supp:
print item
</code></pre>
<p>and it prints:</p>
<pre><code>('one',)
('two',)
('three',)
</code></pre>
<p>how can i have?</p>
<pre><code>one
two
three
</code></pre>
| -2 | 2016-07-07T13:21:57Z | 38,303,658 | <pre><code>try:
supp = cur.fetchall()
for item in supp:
print ' | '.join(item)
return "values printed"
except:
return "Something went wrong!"
</code></pre>
<p>here the answer...
plz delete this post :)</p>
| 0 | 2016-07-11T09:37:12Z | [
"python",
"sql",
"postgresql",
"python-2.7",
"psql"
] |
using global variable in python among modules in different packages | 38,246,928 | <p>I'm new to Python and am trying to use a global counter from a module in a package in different modules in different packages. What I want to do is declare a variable in a module and import it to other modules in different packages. I made a simple test for the question and it's happening here too. I made all files ... | 0 | 2016-07-07T13:35:44Z | 38,247,082 | <p>If you're trying to update a global variable from another module, check this answer out: <a href="http://stackoverflow.com/a/15595447/3224629">http://stackoverflow.com/a/15595447/3224629</a></p>
| 1 | 2016-07-07T13:42:49Z | [
"python",
"python-2.7",
"global-variables"
] |
using global variable in python among modules in different packages | 38,246,928 | <p>I'm new to Python and am trying to use a global counter from a module in a package in different modules in different packages. What I want to do is declare a variable in a module and import it to other modules in different packages. I made a simple test for the question and it's happening here too. I made all files ... | 0 | 2016-07-07T13:35:44Z | 38,247,186 | <p>In test.py:</p>
<pre><code>if __name__ == '__main__':
glbcnt = 0
for i in xrange(0,4):
...
glbcnt += 1
</code></pre>
<p>You make a local glbcnt variable here, which is the one that gets incremented. Your glbfunc() does not see this variable and thus cannot print its value.</p>
<p>Try this:... | 1 | 2016-07-07T13:47:05Z | [
"python",
"python-2.7",
"global-variables"
] |
using global variable in python among modules in different packages | 38,246,928 | <p>I'm new to Python and am trying to use a global counter from a module in a package in different modules in different packages. What I want to do is declare a variable in a module and import it to other modules in different packages. I made a simple test for the question and it's happening here too. I made all files ... | 0 | 2016-07-07T13:35:44Z | 38,247,211 | <p>The way to do this is to keep the module where the variable is as a reference:</p>
<pre><code>import other_module
other_module.counter += 1
</code></pre>
<p>If you do that everywhere you use <code>counter</code> it will have a consitent value across modules.</p>
<p>That happens because each time you do an assign... | 2 | 2016-07-07T13:48:30Z | [
"python",
"python-2.7",
"global-variables"
] |
using global variable in python among modules in different packages | 38,246,928 | <p>I'm new to Python and am trying to use a global counter from a module in a package in different modules in different packages. What I want to do is declare a variable in a module and import it to other modules in different packages. I made a simple test for the question and it's happening here too. I made all files ... | 0 | 2016-07-07T13:35:44Z | 38,247,294 | <p>Note that <code>int</code> is immutable in python. That means doing something like</p>
<pre><code>a = 0
b = a # b = 0
b += 1 # b = 2
</code></pre>
<p>will still leave <code>a</code> as <code>0</code>.</p>
<p>When you do <code>from glbcntmod import glbcnt</code>, this basically equals</p>
<pre><code>import glbc... | 2 | 2016-07-07T13:52:22Z | [
"python",
"python-2.7",
"global-variables"
] |
JSON/Python - decoding | 38,247,013 | <p>I've got json formatted file, 'datastores.json' that looks like this:</p>
<pre><code>{
"{'ESXi_Host': 'elvis.lab.vsphere.com'}": {
"elvis.data": {
"capacity": 293131517952,
"uuid": "57431578-630f1322-7bf2-00212883a5b0",
"vmfs_version": "5.60",
"ssd": false,
... | 0 | 2016-07-07T13:39:13Z | 38,256,028 | <p>One problem is you do not have "ESXi_Host" key in your .json, it says</p>
<pre><code>"{'ESXi_Host': 'elvis.lab.vsphere.com'}"
</code></pre>
<p>notice <code>"</code> <code>"</code> around it, the key is <code>"{'ESXi_Host': 'elvis.lab.vsphere.com'}"</code> (this is a single string).</p>
<p>Second, loaded object wi... | 0 | 2016-07-07T22:05:44Z | [
"python",
"json",
"amazon-dynamodb",
"reformat",
"pyvmomi"
] |
Programmatically access one website from multiple locations? | 38,247,070 | <p>I have a hypothesis that you could increase your chances of getting tickets for sell-out events by attempting to access the website from multiple locations. Just to be clear i'm not trying to be that guy who buys ALL of the tickets for events and then sells them on at 10X the price, incidentally i'm talking specific... | 0 | 2016-07-07T13:42:15Z | 38,247,424 | <p>This has very little to do with <em>your</em> connection. The server is simply drowning in requests. More requests from different locations won't help you. A faster connection might help you get into the queue before anyone else, but multiple connections won't help. If you really want tickets, figure out how to move... | 1 | 2016-07-07T13:58:18Z | [
"python",
"vpn",
"tor"
] |
Adding stats code to a function in Python | 38,247,079 | <p>Im relatively new to Python and trying to learn how to write functions. The answer to <a href="http://stackoverflow.com/questions/38241478/statistics-based-on-number-of-matches-in-dataframe-column/38242765#38242765">this post</a> highlights how to get certain stats from a dataframe and I would like to use it in a f... | -1 | 2016-07-07T13:42:41Z | 38,249,035 | <p>Here you go:</p>
<pre><code>def repeat_stats(series, var):
isvar = series == var
wasntvar = series != series.shift()
cont_grps = (isvar & wasntvar).cumsum()
counts = isvar.loc[cont_grps.astype(bool)].groupby(cont_grps).sum()
return counts.value_counts() / cont_grps.max()
repeat_stats(rng.in... | 2 | 2016-07-07T15:07:34Z | [
"python",
"pandas"
] |
How to use Django HStore DictionaryField in schema and schemaless mode at the same time? | 38,247,129 | <p>When I use <code>hstore.DictionaryField()</code> in Django model passing no parameters and register my model in Djano admin I can create new key-value rows in admin interface on a fly.</p>
<p>When I use the same field in schema mode <code>hstore.DictionaryField(schema=['some schema description'])</code> I get fixed... | 2 | 2016-07-07T13:44:41Z | 38,643,612 | <p>The answer is no, you cannot have both with the current implementation of the hstore library. Take a look at the init function (this is from their source on github):</p>
<pre><code>class DictionaryField(HStoreField):
description = _("A python dictionary in a postgresql hstore field.")
def __init__(self, *a... | 0 | 2016-07-28T17:58:44Z | [
"python",
"django",
"django-models",
"django-admin",
"django-hstore"
] |
Django - How to check if an user is visiting the website everyday | 38,247,176 | <p>As per title, in Django, when and where i should store information about the user access? I'm already logging the user login/logout using Django built-in signals, but what if the user is already logged on that machine? How can i detect this? </p>
| 1 | 2016-07-07T13:46:47Z | 38,247,987 | <p>I wanted to do the same thing on my Django project. The problem is that the <code>last_login</code> variable doesn't helps since it is updated at the user login, and If the user cache his session the variable will never be updated.</p>
<p>One solution is to create a decorator, and use it on your view's. In that way... | 2 | 2016-07-07T14:23:58Z | [
"python",
"django"
] |
Leave only alphanumeric symbols in string in Python? | 38,247,183 | <p>I am using Python 2.7. On SO I found the following regexp for removing non-word characters:</p>
<pre><code>pat = re.compile('[\W]+', re.UNICODE)
</code></pre>
<p>I wrote the next function:</p>
<pre><code>def leave_only_alphanumeric(string):
pat = re.compile('[\W]+', re.UNICODE)
return re.sub(pat,' ',string)
... | 0 | 2016-07-07T13:47:02Z | 38,247,281 | <p>I believe regex might be a bit of an overkill here.</p>
<pre><code>def leave_only_alphanumeric(string):
return ''.join(ch if ch.isalnum() else ' ' for ch in string)
</code></pre>
<p><strong>EDIT</strong>: Your title says "alphanumeric" but your code removes digits as well. So there is a bit of unclarity.</p>
| 2 | 2016-07-07T13:51:49Z | [
"python",
"regex",
"unicode",
"python-2.x"
] |
Leave only alphanumeric symbols in string in Python? | 38,247,183 | <p>I am using Python 2.7. On SO I found the following regexp for removing non-word characters:</p>
<pre><code>pat = re.compile('[\W]+', re.UNICODE)
</code></pre>
<p>I wrote the next function:</p>
<pre><code>def leave_only_alphanumeric(string):
pat = re.compile('[\W]+', re.UNICODE)
return re.sub(pat,' ',string)
... | 0 | 2016-07-07T13:47:02Z | 38,247,678 | <p>You are confusing unicode codepoints and the utf-8 encoding.</p>
<p>The letter you are trying to handle is <code>é</code>, code point <a href="http://www.fileformat.info/info/unicode/char/e9/index.htm" rel="nofollow">u00e9</a>.<br>
It is encoded in utf-8 as two bytes, 0xc3 and 0xa9.</p>
<p>Try:</p>
<pre><code>&g... | 4 | 2016-07-07T14:10:19Z | [
"python",
"regex",
"unicode",
"python-2.x"
] |
Python 2: print out the consecutive days in a loop | 38,247,235 | <p>I have a script that prints out weather information. At the bottom of the script it is meant to print out the next eight days weather summary which it does. however I don't know how to print out consecutive days so the days match the description. </p>
<pre><code>import sys
import os
import time
import optparse
impo... | 0 | 2016-07-07T13:49:37Z | 38,247,371 | <p>Modify your <code>time</code> (not a good idea using this as a name) into a <code>datetime</code> instance, instead of <code>time</code> instance, and then you can use <a href="https://docs.python.org/2/library/datetime.html#timedelta-objects" rel="nofollow"><code>datetime.timedelta</code></a> to increment the <code... | 3 | 2016-07-07T13:55:36Z | [
"python",
"python-2.7",
"time"
] |
Python to PHP strange error | 38,247,262 | <p>I hope somebody can help me. :)</p>
<p>I am calling a python script from PHP, with the help from phpseclib/ssh2 i ssh into my server and it works fine.</p>
<p>My problem is that if i use "time.sleep(5)" in the loop of my python script i dont get a result back, but if i remove time.sleep(5) and time.sleep(3) it wor... | 0 | 2016-07-07T13:50:53Z | 38,248,687 | <p>It depends how long your script take time to execute. If your script (php + python) take longer than 30 second with the default config, them php kill it.</p>
<p>Just add <code>set_time_limit(120)</code> at the beginning of your php code</p>
<p>See <a href="http://php.net/manual/en/function.set-time-limit.php" rel=... | 0 | 2016-07-07T14:52:59Z | [
"php",
"python",
"ssh",
"phpseclib"
] |
Python to PHP strange error | 38,247,262 | <p>I hope somebody can help me. :)</p>
<p>I am calling a python script from PHP, with the help from phpseclib/ssh2 i ssh into my server and it works fine.</p>
<p>My problem is that if i use "time.sleep(5)" in the loop of my python script i dont get a result back, but if i remove time.sleep(5) and time.sleep(3) it wor... | 0 | 2016-07-07T13:50:53Z | 38,248,764 | <p>The script is now working as i should do :) Thanks to "neubert" for the answer.</p>
<p>If i set the $ssh->setTimeout() to unlimited, whould i still get a respons if the script halts at some point?</p>
| 0 | 2016-07-07T14:56:33Z | [
"php",
"python",
"ssh",
"phpseclib"
] |
Delete columns with extremely unequally distributed values from pandas dataframe | 38,247,334 | <p>Given the following code:</p>
<pre><code>import numpy as np
import pandas as pd
arr = np.array([
[1,2,9,1,1,1],
[2,3,3,1,0,1],
[1,4,2,1,2,1],
[2,3,1,1,2,1],
[1,2,3,1,8,1],
[2,2,5,1,1,1],
[1,3,8,7,4,1],
[2,4,7,8,3,3]
])
# 1,2,3,4,5,6 <- Number of the columns.
df = pd.DataFr... | 2 | 2016-07-07T13:53:59Z | 38,247,758 | <p>Another option is to do a value counts on each column and if the maximum of the count is smaller or equal to half of the number of rows of the data frame, then select it:</p>
<pre><code>df.loc[:, df.apply(lambda col: max(col.value_counts()) <= df.shape[0]/2)]
# 0 1 2 4
#0 1 2 9 1
#1 2 3 3 ... | 5 | 2016-07-07T14:13:51Z | [
"python",
"pandas",
"dataframe",
"distribution",
"data-cleaning"
] |
convert list with arrays from csv file into floats | 38,247,354 | <p>I have a csv file with list of samples of various parameters of accelerometer and gyroscopic data. It contains floats(IQR,Range,MAD,...) and arrays(ZCD values). When I read it back, they are returned as strings and for my processing,I need numbers (int/float).
I tried</p>
<pre><code> results = map(int, results)
... | 3 | 2016-07-07T13:54:51Z | 38,247,583 | <p>Your csv is malformed, or you are reading it incorrectly. What you have extracted aren't individual numbers, it's multiple numbers boxed into brackets. See the error message:</p>
<pre><code>ValueError: could not convert string to float: [ 53 73 79 139]
### This is your data ^ ... | 1 | 2016-07-07T14:05:44Z | [
"python",
"csv"
] |
convert list with arrays from csv file into floats | 38,247,354 | <p>I have a csv file with list of samples of various parameters of accelerometer and gyroscopic data. It contains floats(IQR,Range,MAD,...) and arrays(ZCD values). When I read it back, they are returned as strings and for my processing,I need numbers (int/float).
I tried</p>
<pre><code> results = map(int, results)
... | 3 | 2016-07-07T13:54:51Z | 38,247,646 | <p>Because your input consists of strings of floats AND strings of arrays, you need a way of differentiating between the two. One way is to perhaps check the string for spaces? Then, for float strings, simply use <code>float(i)</code> like you have been doing. Then for array strings, try splitting on the spaces to sepa... | 1 | 2016-07-07T14:08:37Z | [
"python",
"csv"
] |
Drawing a FacetGrid of QQ-plots with seaborn | 38,247,396 | <p>I am unable to draw a <a href="https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.FacetGrid.html#seaborn.FacetGrid" rel="nofollow">FacetGrid</a> of <a href="https://en.wikipedia.org/wiki/Q%E2%80%93Q_plot" rel="nofollow">QQ-plots</a> with <a href="https://stanford.edu/~mwaskom/software/seaborn/index.htm... | 0 | 2016-07-07T13:57:02Z | 38,248,374 | <p>I achieved this, and also changed the color to use the Seaborn color palette, with the following code:</p>
<pre><code>def qqplots(fpath, expr, title):
def quantile_plot(x, **kwargs):
x = ss.zscore(x)
ss.probplot(x, plot=plt)
expr_m = pd.melt(expr)
expr_m.columns = ["Feature", "Value"]
... | 0 | 2016-07-07T14:39:32Z | [
"python",
"matplotlib",
"plot",
"statistics",
"seaborn"
] |
Python>tkinter: How to get values from a panel inside a notebook frame | 38,247,491 | <p>I'm just beginning to program in python and I'm using it to make a little program with an GUI (using tkinter) that can take data from an excel file (using openpyxl). Let the user change things when necesarry and then use a button to write the data from the entries to a data file (.dat) (preferable by updating the va... | 0 | 2016-07-07T14:01:05Z | 38,307,821 | <p>I found something that worked on this question:
<a href="http://stackoverflow.com/questions/7300041/tkinter-create-labels-and-entrys-dynamically">tkinter create labels and entrys dynamically</a></p>
<p>I made a global entry for every entryfield</p>
| 0 | 2016-07-11T13:08:50Z | [
"python",
"tkinter"
] |
How do I extend the django oscar customer models fields? | 38,247,536 | <p>How do I extend the django-oscar customer models fields? I have extended the registration form to include more fields, in <code>apps/customer/forms.py</code></p>
<pre><code>class EmailUserCreationForm(forms.ModelForm):
email = forms.EmailField(label=_('Email address'))
password1 = forms.CharField(
l... | 2 | 2016-07-07T14:03:14Z | 38,299,031 | <p>There are a few issues that I can see, resolving which will hopefully fix your problem:</p>
<ol>
<li><p>Move your subclass of <code>AbstractUser</code> into <code>apps/customer/models.py</code> which is where Django looks for models. You've put it in <code>apps/customer/abstract_models.py</code> which is a non-stan... | 2 | 2016-07-11T04:07:18Z | [
"python",
"django",
"python-2.7",
"django-models",
"django-oscar"
] |
How to make VLC click through | 38,247,604 | <p>I have been all over the web looking for a solution to this problem!</p>
<p>I'm looking for a way to make my VLC window "click through" on linux.</p>
<p>I have found some python code here: <a href="http://stackoverflow.com/a/11917174/3426514">http://stackoverflow.com/a/11917174/3426514</a> that says it can solve t... | 0 | 2016-07-07T14:06:43Z | 38,506,536 | <p>You can have VLC write to the desktop background, then set all your app windows to be partially transparent. Output to Background is a VLC option. What you want is backwards from that, where VLC is overlayed on top of everything else, but ignored for user input, however if you don't mind going the other way, it's "a... | 1 | 2016-07-21T14:08:45Z | [
"python",
"bash",
"ubuntu",
"vlc"
] |
Array of tuples necessary for generate_from_frequencies method in Python wordcloud | 38,247,648 | <p>I am trying to make a word cloud in Python from the significance of strings and their corresponding data values in an Excel document. The generate_from_frequencies method takes a frequencies parameter which the docs say is supposed to take an array of tuples. </p>
<p>Partial code from <a href="https://github.com/am... | 1 | 2016-07-07T14:08:42Z | 39,121,529 | <p>From your test code
... <code># <=</code> what should go in this parentheses</p>
<p>I believe you should have a tuple <code>(("hi", float(6/(6+17)),("seven", float(17/(6+17))))</code> </p>
| 0 | 2016-08-24T11:02:47Z | [
"python",
"arrays",
"word-cloud"
] |
Array of tuples necessary for generate_from_frequencies method in Python wordcloud | 38,247,648 | <p>I am trying to make a word cloud in Python from the significance of strings and their corresponding data values in an Excel document. The generate_from_frequencies method takes a frequencies parameter which the docs say is supposed to take an array of tuples. </p>
<p>Partial code from <a href="https://github.com/am... | 1 | 2016-07-07T14:08:42Z | 39,172,275 | <p>Thanks to J Herron and selva for the answer to use tuples instead of a list object-- and I ended up with this:</p>
<pre><code>cloud.generate_from_frequencies((("hi", 3),("seven", 7))))
</code></pre>
<p><a href="http://i.stack.imgur.com/mHfs9.png" rel="nofollow"><img src="http://i.stack.imgur.com/mHfs9.png" alt="Wo... | 0 | 2016-08-26T18:05:01Z | [
"python",
"arrays",
"word-cloud"
] |
Change item in a list to a key in json | 38,247,703 | <p>I have a list of fields like so - </p>
<pre><code>required_fields = ["server['server_name']","server['server_info']['asset_type']['display_name']",
"server['asset_status']['display_name']", "server['record_owner']['group_name']",
"server['server_total_cost_of_ownership']['descr... | -1 | 2016-07-07T14:11:13Z | 38,247,858 | <p>What you are looking for is <a href="https://docs.python.org/2.7/library/functions.html#eval" rel="nofollow"><code>eval</code></a>:</p>
<pre><code>for server in server_list:
for item in required_fields:
print(eval(item))
</code></pre>
<p><code>eval</code> will "run" a string as if it were plain code. For exa... | -1 | 2016-07-07T14:17:43Z | [
"python",
"json",
"python-2.7"
] |
Change item in a list to a key in json | 38,247,703 | <p>I have a list of fields like so - </p>
<pre><code>required_fields = ["server['server_name']","server['server_info']['asset_type']['display_name']",
"server['asset_status']['display_name']", "server['record_owner']['group_name']",
"server['server_total_cost_of_ownership']['descr... | -1 | 2016-07-07T14:11:13Z | 38,261,707 | <p>This is an alternative approach. Note that it works on the assumption that your content is <em>always</em> of the form <code>server[<key>][<key>][...]</code>.</p>
<pre><code>import ast
def parse_fields(field):
field = field[6:] # remove leading "server"
field = field[1:-1] # remove leading/tr... | 3 | 2016-07-08T08:00:52Z | [
"python",
"json",
"python-2.7"
] |
Python pandas: case statement in agg function | 38,247,763 | <p>I have sql statment like this:</p>
<pre><code>select id
, avg(case when rate=1 then rate end) as "P_Rate"
, stddev(case when rate=1 then rate end) as "std P_Rate",
, avg(case when f_rate = 1 then f_rate else 0 end) as "A_Rate"
, stddev(case when f_rate = 1 then f_rate else 0 end) as... | 1 | 2016-07-07T14:14:02Z | 38,248,820 | <p>You should put a little DataFrame in your question to make it easier to answer.</p>
<p>For your need you might want to use <code>agg</code> method of groupby dataframes. Let's suppose you have the following dataframe:</p>
<pre><code> connected_date id number_of_clicks time_spent
0 Mon mat... | 1 | 2016-07-07T14:58:55Z | [
"python",
"numpy",
"pandas",
"dataframe"
] |
pygame event.key == pygame.K_d and l == 1 or 0 | 38,247,792 | <p>So I am making a program were you have to rapidly spam A and D on your keyboard to advance. This is my running system: </p>
<pre><code>if event.type == pygame.KEYDOWN:
if (event.key == pygame.K_a) and (i is 2 or 0):
y_change = display_height/200
i = 1
elif (event.key == pygame.K_d... | 0 | 2016-07-07T14:14:57Z | 38,248,148 | <p>I think you're alternating A and D, right? How about this?</p>
<pre><code>expected_key = pygame.K_a # somewhere in your initialization code
... other code ...
if event.type == pygame.KEYDOWN:
if (event.key == pygame.K_a) and (event.key == expected_key):
y_change = display_height/200
expecte... | 0 | 2016-07-07T14:30:19Z | [
"python",
"pygame"
] |
Given a function with widespread zero tails: Cut down the plotting range | 38,247,908 | <p>I'd like to plot (using <code>matplotlib.pyplot</code>) a probability density function (pdf), but hide their left and/or right tail whenever these are fairly close to zero.
E.g., the normal distribution when being apart some multiples of the standard deviation from the mean value.</p>
<p>The pdf is stored in two a... | 1 | 2016-07-07T14:20:18Z | 38,249,219 | <p>Why not look from the beginning of the <code>samplingPts</code> for when <code>functionVals</code> increases above the threshold, and cut it off there. Then look from the end of <code>samplingPts</code> backwards for when <code>functionVals</code> increases above the threshold and cut it off there too?</p>
<p>Somet... | 0 | 2016-07-07T15:15:34Z | [
"python",
"arrays",
"numpy",
"matplotlib",
"scipy"
] |
Merge GoogleTrends Data Reports in Python | 38,247,921 | <p>I'm quite new to Python and... well... let's say, not really an expert when it comes to coding. So apologies for the very amateurish question in advance. I'm trying to merge several googletrends report.csv files to use for my research.</p>
<p>Two problems I encounter:</p>
<ol>
<li><p>The report files aren't just a... | 0 | 2016-07-07T14:20:53Z | 38,250,604 | <p>It turned out that it does help to occasionally read the warnings python gives. </p>
<blockquote>
<p>ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support skip_footer; you can avoid this warning by specifying engine='python'.</p>
</blockquote>
<p>The problem I had, that the s... | 0 | 2016-07-07T16:20:05Z | [
"python",
"csv",
"google-trends"
] |
What is `/_ah/background` with Google Flex VM | 38,247,937 | <p>Started using <a href="https://cloud.google.com/appengine/docs/flexible/" rel="nofollow">Google Flex Vms</a> recently and in the logs there are multiple requests to <code>/_ah/background</code> that last ~1 hour each time. The only reference to these I could find is <a href="http://stackoverflow.com/questions/174505... | 2 | 2016-07-07T14:21:35Z | 38,272,157 | <p><code>/_ah/background</code> is used in flex for AE API calls that are called outside of an incoming request processing context (like threads, async-io, ...).</p>
<p>Even if you don't do that directly log flushing is still done asynchronously (not part of an income request processing). </p>
<p>This is an implement... | 5 | 2016-07-08T17:12:31Z | [
"python",
"google-app-engine",
"google-compute-engine",
"google-managed-vm"
] |
incorrect virtual memory report using ctypes in windows | 38,247,958 | <p>i am trying to get the total/available virtual memory in python using ctypes, but it seems to be returning a highly incorrect value. below is the code i currently have</p>
<pre><code>import ctypes
import ctypes.wintypes as wintypes
def _get_virtual_size():
class MEMORYSTATUSEX(ctypes.Structure):
_field... | 0 | 2016-07-07T14:22:46Z | 39,973,655 | <p>Try using this code. Not sure if it will work for you. I'm running 32-bit Python on a 64-bit windows 7 pc <em>{Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32}</em>. I have compared the values returned to what is reported in the Performance tab of my Windows Task Manager applicatio... | 0 | 2016-10-11T08:55:43Z | [
"python",
"windows",
"ctypes",
"virtual-memory",
"psutil"
] |
Python 3.5 Jupyter Notebook ggplot "name error" | 38,247,973 | <p>I am getting <code>NameError: name 'unicode' is not defined</code> when using yHat's ggplot library for Python (see full error below) in a Jupyter Notebook, running Python 3.5.2. with the following import statements:</p>
<pre><code> %matplotlib inline
from ggplot import *
</code></pre>
<p>The graph still renders,... | 1 | 2016-07-07T14:23:18Z | 38,314,494 | <p>If you have anaconda installed try installing the code-forge version. I was able to fix this same problem by switching to that version for python 3.5</p>
<p><code>conda install -c conda-forge ggplot</code></p>
<p>Hope that helps</p>
| 1 | 2016-07-11T19:15:43Z | [
"python",
"python-3.5",
"python-ggplot"
] |
Invalid Syntax with my "if statement" | 38,247,984 | <p>I have an issue with my if statement and I don't understand why. Here it is:</p>
<pre><code>if (first == 1 and second > -1 and third < 1 and (sign(phi[i]) == sign(phi[i-1]) or sign(phi[i]) == sign(phi[i-2])):
foo()
</code></pre>
<p>It keeps telling me <code>"invalid syntax"</code>.
Can you spot the invalid s... | -9 | 2016-07-07T14:23:50Z | 38,248,029 | <p>You have missed one parenthesis at the end:</p>
<pre><code>if (first == 1 and second > -1 and third < 1 and (sign(phi[i]) == sign(phi[i-1]) or sign(phi[i]) == sign(phi[i-2]))):
^
</code></pre>
| 2 | 2016-07-07T14:25:31Z | [
"python",
"syntax"
] |
Mixing Deferred and deferToThread to run blocking code in separate thread | 38,248,008 | <p>In my Python Twisted application I need to receive data from the client, perform some database operations and - depends on data - run some blocking code in separate thread.</p>
<p>So far I have:</p>
<pre><code>d = get_user(user_id)
d.addCallback(do_something_with_input_data, input_data)
d.addCallback(run_blocking... | 0 | 2016-07-07T14:24:28Z | 39,236,410 | <p>I'd say the general concept is fine. I'd add in some <code>errbacks</code>, and you also need to tweak your run_blocking_code function:</p>
<pre><code>@defer.inlineCallbacks
def run_blocking_code(results)
# the `deferToThread` returns a deferred
d = threads.deferToThread(run_in_separate_thread, results)
... | 1 | 2016-08-30T20:19:24Z | [
"python",
"twisted"
] |
How to compile my python code in cython with external python libs like pybrain | 38,248,017 | <p>I need more perfomance running my neural network, so I thinked that building it with cython will be good idea. I am building my code like this:</p>
<pre><code>from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("my_code.pyx")
)
</code></pre>
<p>But will it build ... | 2 | 2016-07-07T14:24:37Z | 38,248,572 | <p>No, external python files will not be cythonized and compiled unless you specifically add them to your <code>setup.py</code> as an extension. As far as I know there is no trivial way to do this.</p>
<p>This means that all calls to the external files will be handled in 'Python-space' and hence can not use the full p... | 1 | 2016-07-07T14:47:54Z | [
"python",
"python-2.7",
"cython",
"pybrain",
"cythonize"
] |
Image Not Found error when bundling pycups with pyinstaller | 38,248,068 | <p>I'm trying to create a one-file executable from a python file using pyinstaller. The executable fails when trying to <code>import cups</code> and gives the following error:</p>
<pre><code>Failed to execute script ImportPyCups
Traceback (most recent call last):
File "ImportPyCups.py", line 1, in <module>
imp... | 0 | 2016-07-07T14:26:57Z | 39,145,072 | <p>I've finally found the answer here: <a href="https://github.com/pyinstaller/pyinstaller/issues/1728" rel="nofollow">https://github.com/pyinstaller/pyinstaller/issues/1728</a></p>
<p>If you use easy_install to install PyCups, you'll get an .egg file. Pyinstaller doesn't look for C extensions inside zipped .egg files... | 0 | 2016-08-25T12:15:52Z | [
"python",
"osx",
"pyinstaller"
] |
Determine Error/Exception Type Python | 38,248,083 | <p>I am using the win32Com module to write data to an excel sheet on a Windows 7 machine with Python 3.5. While it is running I get thrown an error. I tried making a "try/except" block but the error type I attempted is apparently not an actual error type. Here is my code : </p>
<pre><code>import win32com.client as win... | 2 | 2016-07-07T14:27:30Z | 38,248,361 | <p>By importing "pywintypes" my error try/except functions properly. </p>
| 0 | 2016-07-07T14:39:04Z | [
"python",
"error-handling"
] |
Determine Error/Exception Type Python | 38,248,083 | <p>I am using the win32Com module to write data to an excel sheet on a Windows 7 machine with Python 3.5. While it is running I get thrown an error. I tried making a "try/except" block but the error type I attempted is apparently not an actual error type. Here is my code : </p>
<pre><code>import win32com.client as win... | 2 | 2016-07-07T14:27:30Z | 38,248,372 | <p>You need to add an import, more specifically</p>
<pre><code>from pywintypes import com_error
</code></pre>
<p>then use the following</p>
<pre><code>except com_error as e:
</code></pre>
| 3 | 2016-07-07T14:39:24Z | [
"python",
"error-handling"
] |
How can three double quotation marks be stored in a Python docstring? | 38,248,213 | <p>I have a large ASCII logo that I want to store in a docstring. This logo features multiple instances of three consecutive double quotation marks. The size and complexity is such that escaping individual characters isn't a realistic option. Given that at no point is an instance of three consecutive double quotation m... | 4 | 2016-07-07T14:32:53Z | 38,248,258 | <p>Just use the single-quotes.</p>
<pre><code>logo = '''
hello"""world
'''
</code></pre>
<p>If you don't want to violate PEP8, you can be a bit hackish</p>
<pre><code>logo = """
hello'''world
""".replace("'", '"')
</code></pre>
| 4 | 2016-07-07T14:34:54Z | [
"python",
"double-quotes",
"docstring"
] |
How can three double quotation marks be stored in a Python docstring? | 38,248,213 | <p>I have a large ASCII logo that I want to store in a docstring. This logo features multiple instances of three consecutive double quotation marks. The size and complexity is such that escaping individual characters isn't a realistic option. Given that at no point is an instance of three consecutive double quotation m... | 4 | 2016-07-07T14:32:53Z | 38,248,265 | <p>You can "violate" PEP8 and use <code>'''</code>:</p>
<pre><code>logo = '''
hello"""world
'''
</code></pre>
| 0 | 2016-07-07T14:35:10Z | [
"python",
"double-quotes",
"docstring"
] |
How can three double quotation marks be stored in a Python docstring? | 38,248,213 | <p>I have a large ASCII logo that I want to store in a docstring. This logo features multiple instances of three consecutive double quotation marks. The size and complexity is such that escaping individual characters isn't a realistic option. Given that at no point is an instance of three consecutive double quotation m... | 4 | 2016-07-07T14:32:53Z | 38,311,973 | <p>I seems backslashes work as well</p>
<pre><code>>>> """ \"\"\" """
' """ '
>>>
</code></pre>
| 0 | 2016-07-11T16:36:30Z | [
"python",
"double-quotes",
"docstring"
] |
Changing loop to organize and reduce XML output | 38,248,286 | <p>I have an XML output that is given to me that looks like this:</p>
<pre><code> <lsar030><head></head><body><group1></group1><Part></part><national_stock_number_cross_reference>
<federal_supply_classification>5310</federal_supply_class... | 0 | 2016-07-07T14:36:06Z | 38,249,986 | <p>You're creating a new <code><nsnindxrow></code> tag every time you cycle through the <code>national_stock_number_cross_reference</code> items (3rd <code>for</code> loop):</p>
<pre><code>for national_stock_number_cross_reference in body.findall('./' + junk + 'national_stock_number_cross_reference'):
</code></p... | 1 | 2016-07-07T15:51:08Z | [
"python",
"xml"
] |
Changing loop to organize and reduce XML output | 38,248,286 | <p>I have an XML output that is given to me that looks like this:</p>
<pre><code> <lsar030><head></head><body><group1></group1><Part></part><national_stock_number_cross_reference>
<federal_supply_classification>5310</federal_supply_class... | 0 | 2016-07-07T14:36:06Z | 38,253,090 | <p>Forgive me in suggesting another approach but consider an XSLT solution as your needs is the classic <a href="http://www.jenitennison.com/xslt/grouping/muenchian.html" rel="nofollow">Muenchian Method</a> involving grouping on the <code><federal_supply_classification></code> and <code><national_item_identifi... | 0 | 2016-07-07T18:44:42Z | [
"python",
"xml"
] |
Templating â Pass variable references in Python from a config file | 38,248,291 | <p>A ticketing script is accepting input from a config file. That config file contains an email body. How do I best enable the customer to reference a static list of variables within that email body?</p>
<p>The way I am doing it now is training the user which variables are allowed, and having the variables be "escaped... | 0 | 2016-07-07T14:36:15Z | 38,256,526 | <p>Use a mustache templating library like <a href="https://github.com/defunkt/pystache" rel="nofollow">pystache</a>.</p>
<pre><code>>>> import pystache
>>> renderer = pystache.Renderer()
>>> print renderer.render(parsed, {'who': 'Pops'})
Hey Pops!
>>> print renderer.render(parsed, {... | 0 | 2016-07-07T22:54:57Z | [
"python",
"configuration-files",
"template-engine"
] |
Jupyter not finding Python class | 38,248,325 | <p>Very basic Jupyter question:</p>
<p>I have two cells in a Jupyter notebook. Neither one has a name (neither is named Perceptron.py - I don't know how to name them )</p>
<p>One begins like this:</p>
<pre><code>class Perceptron(object):
</code></pre>
<p>and the other does this:</p>
<pre><code>from Perceptron impo... | 1 | 2016-07-07T14:37:43Z | 38,248,858 | <p>Since you don't have a file called <code>Perceptron.py</code>, you shouldn't need to do an <code>import</code> statement for that. Cells in Jupyter notebooks can use variables from one another. All you have to do is click on a cell, and press <code>shift</code> and <code>enter</code> to 'run' it. </p>
<p>If you hav... | 2 | 2016-07-07T15:00:17Z | [
"python",
"jupyter",
"jupyter-notebook"
] |
Jupyter not finding Python class | 38,248,325 | <p>Very basic Jupyter question:</p>
<p>I have two cells in a Jupyter notebook. Neither one has a name (neither is named Perceptron.py - I don't know how to name them )</p>
<p>One begins like this:</p>
<pre><code>class Perceptron(object):
</code></pre>
<p>and the other does this:</p>
<pre><code>from Perceptron impo... | 1 | 2016-07-07T14:37:43Z | 38,249,750 | <p>Your comment about "naming" the cells suggests that you consider cells as separate files; however, Jupyter notebook cells are not separate files - they are part of the same file. </p>
<p>If you were writing a python script, you would declare your class, and then execute your class like so:</p>
<pre><code>class Foo... | 2 | 2016-07-07T15:40:35Z | [
"python",
"jupyter",
"jupyter-notebook"
] |
PyQt - "tell" QFileDialog to ignore alias? | 38,248,360 | <p>I'm using OSX and i'm trying to load an image sequence using QFileDialog.
My image sequence is:</p>
<pre><code>image.000001.tif
image.000002.tif
image.000003.tif
...
</code></pre>
<p>However, all of the images in that sequences are aliases of another image, let's call it <code>original.tif</code></p>
<p>So when i... | 0 | 2016-07-07T14:39:00Z | 38,248,485 | <p>If those names are <em>symbolic links</em> to <code>original.tif</code> you may want to disable symlink resolution:</p>
<pre><code>dialog.setOptions(QFileDialog.DontResolveSymlinks);
</code></pre>
<p>The documentation for the <a href="http://doc.qt.io/qt-5/qfiledialog.html#options-prop" rel="nofollow"><code>option... | 3 | 2016-07-07T14:43:55Z | [
"python",
"qt",
"pyqt"
] |
How do I delete a similar alembic version? | 38,248,405 | <p>When I am trying to do </p>
<pre><code>alembic upgrade head
</code></pre>
<p>I am getting this error:</p>
<pre><code>ERROR [alembic.util.messaging] Online migration expected to match one row when updating '3aae6532b560' to 'a1d8dae7cc' in 'alembic_version'; 2 found
FAILED: Online migration expected to match one r... | 0 | 2016-07-07T14:40:37Z | 39,958,240 | <p>Alembic version is stored within your database in alembic_version table. I see that you have two self same rows inside the table.</p>
<p>You can do something like this:</p>
<pre><code>DELETE FROM alembic_version WHERE version_num='3aae6532b560';
INSERT INTO alembic_version VALUES ('3aae6532b560');
</code></pre>
<... | 0 | 2016-10-10T12:24:45Z | [
"python",
"flask",
"sqlalchemy",
"flask-sqlalchemy",
"alembic"
] |
Odoo How to make custom report, AttributeError | 38,248,573 | <p>I'm trying to make a custom report. I used this documentation <a href="https://www.odoo.com/documentation/8.0/reference/reports.html" rel="nofollow">https://www.odoo.com/documentation/8.0/reference/reports.html</a> and looked at the add-on "sale" to have an exemple of report. I wanted to do a first test so I used th... | 1 | 2016-07-07T14:47:58Z | 38,250,243 | <p>If i see it correct, then you've overriden the Odoo model/class <code>report</code>, which handles all the stuff for rendering documents, etc.</p>
<pre class="lang-xml prettyprint-override"><code><report
id="report_demand"
string="Propositions en cours"
model="report"
report_type="qweb-pdf"
n... | 1 | 2016-07-07T16:03:39Z | [
"python",
"xml",
"openerp",
"wkhtmltopdf",
"odoo-8"
] |
Likelihood ratio test in Python | 38,248,595 | <p>I am having trouble computing a likelihood ratio test in Python 2.7.</p>
<p>I have two models and the corresponding likelihood values. I believe the rule for comparing whether model L2 is better than model L1 (if the models are closely related) is to look at -2 * log(L2/L1).</p>
<p>I then want to find the p-value ... | 2 | 2016-07-07T14:48:51Z | 38,249,020 | <p>To calculate the likelihood ratio given the log-likelihoods, use this formula:</p>
<pre><code>def likelihood_ratio(llmin, llmax):
return(2*(llmax-llmin))
LR = likelihood_ratio(L1,L2)
p = chisqprob(LR, 1) # L2 has 1 DoF more than L1
print 'p: %.30f' % p
# p: 0.000000121315450836607258011741
</code></pre>
| 1 | 2016-07-07T15:06:59Z | [
"python",
"python-2.7",
"scipy",
"statistics"
] |
Why does simple 2-layer Neural Network cannot learn 0,0 sequence? | 38,248,657 | <p>While going through the <a href="http://iamtrask.github.io/2015/07/27/python-network-part2/" rel="nofollow">example</a> of a tiny 2-layer neural network I noticed the result that I cannot explain.</p>
<p>Imagine we have the following dataset with the corresponding labels: </p>
<pre><code>[0,1] -> [0]
[0,1] ->... | 5 | 2016-07-07T14:51:49Z | 38,253,140 | <p>The classification is right as well. You need to understand that the net was able to separate the test set. </p>
<p>Now You need to use an step function to classify the data between <code>0</code> or <code>1</code>.</p>
<p>In your case the <code>0.5</code> seems to be a good <code>threshold</code></p>
<p><strong>... | 5 | 2016-07-07T18:47:35Z | [
"python",
"machine-learning",
"neural-network"
] |
Reshaping numpy ndarray | 38,248,677 | <p>I have a numpy ndarray of 3D coordinates in the following form..</p>
<pre><code>array([[ 0., 0., 60.],
[ 0., 40., 60.],
[ 0., 40., 0.],
...,
[ 6., 0., 2.],
[ 4., 0., 2.],
[ 2., 0., 2.]])
</code></pre>
<p>I'm trying to reshape it so that rather th... | 2 | 2016-07-07T14:52:41Z | 38,248,769 | <pre><code>coords_reshaped = coords.reshape((21, 62, 3))
</code></pre>
| 3 | 2016-07-07T14:56:53Z | [
"python",
"numpy",
"multidimensional-array"
] |
skipping a json key if does not exist | 38,248,746 | <p>I'm running the following:</p>
<pre><code>for server in server_list:
for item in required_fields:
print item, eval(item)
</code></pre>
<p>There is a possibility that some keys may not exist, but worse it's represented on a parent key not the one I'm scanning for.</p>
<p>So I'm scanning the json for th... | 1 | 2016-07-07T14:55:42Z | 38,249,920 | <p>In fact you should avoid eval. After the json load since you know the key name, you can use a list to go deeper in the tree.</p>
<pre><code>server['server_management']['primary_business_owner']['name']" => ["server_management', 'primary_business_owner', 'name']
</code></pre>
<p>Here a snippet for a json validat... | 2 | 2016-07-07T15:48:16Z | [
"python",
"json",
"python-2.7"
] |
skipping a json key if does not exist | 38,248,746 | <p>I'm running the following:</p>
<pre><code>for server in server_list:
for item in required_fields:
print item, eval(item)
</code></pre>
<p>There is a possibility that some keys may not exist, but worse it's represented on a parent key not the one I'm scanning for.</p>
<p>So I'm scanning the json for th... | 1 | 2016-07-07T14:55:42Z | 38,249,943 | <p>Ignoring the context of the code and not understanding the use of eval here, the way to do this is to use .get() and seed it with reasonable defaults.</p>
<p>For example:</p>
<pre><code>server['server_management']['server_total_cost_of_ownership']['description']
</code></pre>
<p>Can be:</p>
<pre><code>server.get... | 0 | 2016-07-07T15:49:15Z | [
"python",
"json",
"python-2.7"
] |
skipping a json key if does not exist | 38,248,746 | <p>I'm running the following:</p>
<pre><code>for server in server_list:
for item in required_fields:
print item, eval(item)
</code></pre>
<p>There is a possibility that some keys may not exist, but worse it's represented on a parent key not the one I'm scanning for.</p>
<p>So I'm scanning the json for th... | 1 | 2016-07-07T14:55:42Z | 38,261,561 | <p>Your problem here is totally unrelated to using <code>eval</code>[1]. The exception you get is the same as if the code would have been there directly. What you are running (via <code>eval</code>) is:</p>
<pre><code>a = server['server_management']
b = a['server_total_cost_of_ownership']
c = b['description']
</code><... | 0 | 2016-07-08T07:53:12Z | [
"python",
"json",
"python-2.7"
] |
How to hide personal data in Python script | 38,248,928 | <p>I need to push <code>Python</code> script to <code>Git</code> repo. Script contains variables with personal data like <code>USER_NAME = "some_name"</code> and <code>USER_PASS = "some_password"</code>. This data could be accessible for other users. I want to hide this data.</p>
<p>I found following approach: </p>
<... | 3 | 2016-07-07T15:03:10Z | 38,248,976 | <p>Try using an YAML file and not pushing it to your repo, like from <a href="http://stackoverflow.com/questions/8190473/hiding-my-sensitive-information-e-g-password-from-github">here</a>. You can use the python module <code>yaml</code> to read the data. </p>
| 1 | 2016-07-07T15:05:10Z | [
"python",
"git"
] |
How to hide personal data in Python script | 38,248,928 | <p>I need to push <code>Python</code> script to <code>Git</code> repo. Script contains variables with personal data like <code>USER_NAME = "some_name"</code> and <code>USER_PASS = "some_password"</code>. This data could be accessible for other users. I want to hide this data.</p>
<p>I found following approach: </p>
<... | 3 | 2016-07-07T15:03:10Z | 38,249,044 | <p>Include in git repo code to read those things from environment variables. On the target machine, set those environment variables. This could be done by hand, or with a script that you don't include in your repo. Include instructions in your readme file</p>
| 2 | 2016-07-07T15:07:53Z | [
"python",
"git"
] |
How to hide personal data in Python script | 38,248,928 | <p>I need to push <code>Python</code> script to <code>Git</code> repo. Script contains variables with personal data like <code>USER_NAME = "some_name"</code> and <code>USER_PASS = "some_password"</code>. This data could be accessible for other users. I want to hide this data.</p>
<p>I found following approach: </p>
<... | 3 | 2016-07-07T15:03:10Z | 38,296,218 | <p>You should never put sensitive pieces of information inside your code neither store them into a public repository.</p>
<p>It's better to follow Joel Goldstick's suggestion and modify your code to get passwords from private sources, e.g. local environment variables or local modules.</p>
<p>Try googling for <em>"pyt... | 1 | 2016-07-10T20:31:44Z | [
"python",
"git"
] |
What does 0x%4x mean in python? | 38,248,949 | <p>I think I understand what % means in python. But I don't understand what the 0x and 4x means. Any help is great even if you just link the documentation for %.</p>
<p>Here is the example code:</p>
<pre><code>wr.write('Base Addr=0x%4x' %
(Base_Address))
</code></pre>
| 0 | 2016-07-07T15:04:14Z | 38,249,009 | <p><code>%4x</code> is a way of formatting a number in hexidecimal</p>
<pre><code>>>> '%4x' % 0xffff
'ffff'
>>> '%4x' % 0xffa1
'ffa1'
</code></pre>
<p>The leading <code>0x</code> will just be literal characters that end up carrying over into the string.</p>
<pre><code>>>> '0x%4x' % 0xffa1
... | 6 | 2016-07-07T15:06:24Z | [
"python",
"python-2.7"
] |
convert django table to dict | 38,248,986 | <p>I have a django model like this(for example):</p>
<pre><code>class Books(models.Model):
id = models.IntegerField(unique=True, null=False, primary_key=True)
name = models.CharField(null=True, max_length=255)
author = models.ForeignKey(Author)
</code></pre>
<p>And I need to convert all data in this model... | 0 | 2016-07-07T15:05:34Z | 38,260,731 | <p>I found a solution.</p>
<pre><code>authors = Books.objects.distinct('author')
authids = []
for a in authors:
authids.append(a.author.id)
data = []
for aid in authids:
adict = {}
books = Metro.objects.filter(author=aid)
blist = []
for b in books:
bo... | 0 | 2016-07-08T07:02:57Z | [
"python",
"json",
"django",
"django-models"
] |
cannot convert to egg file for panda3d | 38,249,110 | <p>I am a beginner in panda3d, recently i came across blender 2.77 for modelling. I was disapointed to find that it cannot export egg files supported by panda3d, i searched online and found yabee and chicken but after installing those addons to blender also, i did'nt find an egg file exporter in the exporter's list.</p... | 1 | 2016-07-07T15:10:41Z | 38,314,470 | <p>I am also new at Panda3d and I solved a Problem similar to yours just a few hours ago.</p>
<p>There are two ways to solve your Problem:</p>
<ol>
<li><p>Download another version of Blender the last Blender-Version working with YABEE is 2.66.</p></li>
<li><p>Just export your model as a .x - file(DirektX) this works ... | 1 | 2016-07-11T19:14:10Z | [
"python",
"panda3d"
] |
cannot convert to egg file for panda3d | 38,249,110 | <p>I am a beginner in panda3d, recently i came across blender 2.77 for modelling. I was disapointed to find that it cannot export egg files supported by panda3d, i searched online and found yabee and chicken but after installing those addons to blender also, i did'nt find an egg file exporter in the exporter's list.</p... | 1 | 2016-07-07T15:10:41Z | 40,102,258 | <p>Common error when using YABEE: Not only do you need to copy it into the addons directory, you also need to activate it in Blender.</p>
| 1 | 2016-10-18T07:37:31Z | [
"python",
"panda3d"
] |
Filter Text through list in Python | 38,249,215 | <p>i have a list of stopwords (in German) that i want to use to Filter out the same ones from an input Text, it looks like this:</p>
<pre><code>stopwortlist = ['ab', 'aber','abgesehen', 'alle', 'allein', 'aller', 'alles']
text = input('please put in a Text')
#i have found a way of controlling them online, but it doesn... | 0 | 2016-07-07T15:15:29Z | 38,249,312 | <p>Split your incoming text into words (otherwise you are iterating over characters), filter the stop words and then rejoin the resulting list.</p>
<pre><code>stopwortlist = ['ab', 'aber','abgesehen', 'alle', 'allein', 'aller', 'alles']
text = 'Some text ab aber with stopwords allein in'
def filterStopwords(eingabeTe... | 2 | 2016-07-07T15:19:56Z | [
"python",
"python-2.7",
"python-3.x"
] |
Filter Text through list in Python | 38,249,215 | <p>i have a list of stopwords (in German) that i want to use to Filter out the same ones from an input Text, it looks like this:</p>
<pre><code>stopwortlist = ['ab', 'aber','abgesehen', 'alle', 'allein', 'aller', 'alles']
text = input('please put in a Text')
#i have found a way of controlling them online, but it doesn... | 0 | 2016-07-07T15:15:29Z | 38,249,582 | <p>Here's a one liner using the filter and join methods.</p>
<pre><code>stopwortlist = ['ab', 'aber','abgesehen', 'alle', 'allein', 'aller', 'alles']
text = 'There are ab aber multiple allein abgesehen words in alles this ab list'
print " ".join(filter(lambda x: x not in stopwortlist, text.split()))
#Output
There ar... | -1 | 2016-07-07T15:32:01Z | [
"python",
"python-2.7",
"python-3.x"
] |
Store an unpacked list as variable in python | 38,249,249 | <p>Is there anyway to do this?</p>
<p>For clarity, here is a minimal example of what I am wondering about: given a scenario where I have function like the following (which I either can't or don't want to modify to accept a formal argument of a list instead of the variable number of arguments *args),</p>
<pre><code>&g... | -4 | 2016-07-07T15:17:00Z | 38,249,766 | <p>The <code>range</code> function returns a generator, which is a specific type of iterator. When you call a function with a <code>*</code> parameter the interpreter iterates over that argument (which has to be iterable) and the parameter name is bound to a tuple containing all the values. If you were to write</p>
<p... | 0 | 2016-07-07T15:41:33Z | [
"python",
"python-3.x"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.