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 get dictionary values from list of lists (any language)? | 38,689,547 | <p>I most interested in simplicity, so would appreciate solution in any language (also interesting how it would look using LINQ). I tried to do it in Python, but failed.</p>
<p>From these two lists:</p>
<pre><code>init_li1 = [[234,45,1,86,2,0],[324,6,1],[123,1111,3]]
init_li2 = ["Alpha", "Beta", "Gamma"]
</code></pre... | -1 | 2016-08-01T00:27:28Z | 38,689,705 | <p>Since you mentioned LINQ, you could do set something like this in C#:</p>
<pre><code> var list_1 = new List<List<int>>
{
new List<int> { 234, 45, 1, 86, 2, 0 },
new List<int> { 324, 6, 1 },
new List<int> { 123, 1111, 3 }
};
... | 0 | 2016-08-01T00:59:34Z | [
"c#",
"python",
"list",
"dictionary"
] |
How to get dictionary values from list of lists (any language)? | 38,689,547 | <p>I most interested in simplicity, so would appreciate solution in any language (also interesting how it would look using LINQ). I tried to do it in Python, but failed.</p>
<p>From these two lists:</p>
<pre><code>init_li1 = [[234,45,1,86,2,0],[324,6,1],[123,1111,3]]
init_li2 = ["Alpha", "Beta", "Gamma"]
</code></pre... | -1 | 2016-08-01T00:27:28Z | 38,697,194 | <pre><code>init_li1 = [[234,45,1,86,2,0],[324,6,1],[123,1111,3]]
init_li2 = ["Alpha", "Beta", "Gamma"]
new_dict = {}
for i in range(0, len(init_li1)):
new_dict[init_li2[i]] = init_li1[i]
print new_dict
</code></pre>
| 0 | 2016-08-01T11:03:38Z | [
"c#",
"python",
"list",
"dictionary"
] |
Use xpath and scrapy to go through STIX files? | 38,689,596 | <p>I'm hoping to use scrapy to go through STIX documents, basically setting the documents up like a RSS feed and then 'scraping' through it.
Currently, I'm just using ipython and scrapy shell to get the xpaths. </p>
<pre><code><FileObj:Hashes>
<cyboxCommon:Hash>
<cyboxCommon:Type condition=... | 0 | 2016-08-01T00:36:41Z | 38,695,464 | <p>Scrapy Selector (or now Parsel Selector) escapes and cleans up the tags etc when creating a tree for parsing.</p>
<p>In your case the xpath you are looking for is:</p>
<pre><code>response.xpath("//simple_hash_value[@condition='Equals']/text()").extract()
</code></pre>
<p>You can view the cleaned up tree simply wi... | 1 | 2016-08-01T09:34:41Z | [
"python",
"xpath",
"scrapy"
] |
Use xpath and scrapy to go through STIX files? | 38,689,596 | <p>I'm hoping to use scrapy to go through STIX documents, basically setting the documents up like a RSS feed and then 'scraping' through it.
Currently, I'm just using ipython and scrapy shell to get the xpaths. </p>
<pre><code><FileObj:Hashes>
<cyboxCommon:Hash>
<cyboxCommon:Type condition=... | 0 | 2016-08-01T00:36:41Z | 38,707,488 | <p>OK so apparently STIX has it's own namespace, this particular problem uses this one - </p>
<p>xmlns:cybox="http://cybox.mitre.org/cybox-2" </p>
<p>In order to grab the text from the STIX file I had to use name() or you can use local-name()</p>
<pre><code>response.xpath("//*[name()='cyboxCommon:Simple_Hash_Value']... | 0 | 2016-08-01T20:24:27Z | [
"python",
"xpath",
"scrapy"
] |
2 occurrences of a letter not spotted by indexing | 38,689,653 | <p>I am creating a game of hangman in python 3 and all seems to be working well apart from one part of the game. Take for example, the word 'hello'. Hello contains two 'l's. My game does not recognise that you can have more than one occurrence of a letter in a word and therefore does not update the game as it should. H... | 0 | 2016-08-01T00:48:13Z | 38,689,691 | <p>I think you're also misunderstanding the second parameter of <a href="https://docs.python.org/2/library/string.html#string.find" rel="nofollow">index</a>, which is the start index to search from, not the nth occurrence to look for. What's happening right now is you're replacing the first "L" twice.</p>
<pre><code>s... | 1 | 2016-08-01T00:57:53Z | [
"python",
"python-3.x",
"indexing"
] |
what is the difference between x[1,2] and x[1][2] in hierarchy indexing for series in python? | 38,689,743 | <p>I have a series </p>
<pre><code>x=pd.Series(np.random.random(16),index=[[1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4],['a','b','c','d','a','b','c','d','a','b','c','d','a','b','c','d']])
</code></pre>
<p>that looks like this:</p>
<pre><code>1 a -0.068167
b -1.036551
c -0.246619
d 1.318381
2 a -0.119061
... | 4 | 2016-08-01T01:06:15Z | 38,689,978 | <p>This explanation is from the <a href="http://docs.scipy.org/doc/numpy/user/basics.indexing.html" rel="nofollow">numpy docs</a>, however I believe a similar thing is happening in pandas (which uses numpy inside, using "indexers" to provide a mapping between a (possibly) named index and the underlying integer-based in... | 2 | 2016-08-01T01:49:59Z | [
"python",
"pandas",
"indexing",
"hierarchy"
] |
what is the difference between x[1,2] and x[1][2] in hierarchy indexing for series in python? | 38,689,743 | <p>I have a series </p>
<pre><code>x=pd.Series(np.random.random(16),index=[[1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4],['a','b','c','d','a','b','c','d','a','b','c','d','a','b','c','d']])
</code></pre>
<p>that looks like this:</p>
<pre><code>1 a -0.068167
b -1.036551
c -0.246619
d 1.318381
2 a -0.119061
... | 4 | 2016-08-01T01:06:15Z | 38,694,236 | <p>In the case of <code>x[1, 'a']</code>, pandas is taking the <code>1, 'a'</code> as a tuple <code>(1, 'a')</code> and returning the series value that corresponds to the <code>(1, 'a')</code> index label.</p>
<p>In the case of <code>x[1]['a']</code>, pandas is figuring out that what you passed within <code>[]</code> ... | 2 | 2016-08-01T08:31:08Z | [
"python",
"pandas",
"indexing",
"hierarchy"
] |
dataframe slicing and pivoting then into multiple dataframs | 38,689,770 | <p>Ultimately I want to run a parametric var on stock data below</p>
<p>I have data in the form:</p>
<pre><code> Date Symbol ClosingPrice Weight
0 7/22/2016 A 46.58 0.000002
1 7/25/2016 A 46.14 0.000002
2 7/26/2016 A 46.95 0.000002
... | 1 | 2016-08-01T01:10:57Z | 38,689,797 | <p>To get the first table, you can pivot your original data frame to transform it from long to wide format on the first three columns:</p>
<pre><code>import pandas as pd
df.iloc[:,0:3].pivot('Date', 'Symbol', 'ClosingPrice')
# Symbol A AA AAAP
# Date
#7/22/2016 46.58 10.57 30.51
#7/2... | 3 | 2016-08-01T01:16:32Z | [
"python",
"pandas",
"dataframe",
"pivot",
"slice"
] |
How to write lambda function for counting occurrence in a string in Python sort() | 38,689,777 | <p>I'm trying to write a lambda function (still new to functional programming style of Python). I have a list like this:</p>
<pre><code>cur_list = [b'1z1zzz\r\n', b'1z1z1zzz\r\n', b'1z1z1zzz\r\n', b'zzzz\r\n', b'1zzzz\r\n']
</code></pre>
<p>I want to sort the list by the number of occurrence of '1' in each of them. S... | 0 | 2016-08-01T01:12:26Z | 38,689,780 | <p>That would be:</p>
<pre><code>lambda x: x.count('1')
</code></pre>
<p>Of course, as what you have seems like an array of byte strings, you might want this:</p>
<pre><code>lambda x: x.count(b"1")
</code></pre>
| 3 | 2016-08-01T01:12:56Z | [
"python",
"sorting",
"lambda"
] |
Adding headers to processed dataframe in Panda's | 38,689,999 | <p><a href="http://github.com/ecenm/data/blob/master/sorted.csv.zip" rel="nofollow">Here</a> is my dataset.</p>
<p>I am creating a new pandas dataframe (ptocol) from a previous dataframe (data) using the .groupby and .size methods as shown below. This behaves as expected, however the result is a dataframe with no col... | 0 | 2016-08-01T01:53:39Z | 38,690,091 | <p><code>.size()</code> returns a Series object, you can use <code>reset_index()</code> to transform it to a data frame, try this instead:</p>
<pre><code>ptocol = data.groupby("Protocol").size().rename('NumOfPackets').reset_index()
ptocol.to_csv('protocol.cv', index = False)
</code></pre>
<p>This gives something like... | 0 | 2016-08-01T02:08:46Z | [
"python",
"csv",
"pandas"
] |
python : print the multiple lines on console in place | 38,690,083 | <p>I want to print multiple lines on console in place.
Like this,</p>
<pre><code>AAAAAA
BBBBBB
</code></pre>
<p>But, If I print above the strings using <code>'\r'</code> as below,</p>
<pre><code>for i in range(10):
time.sleep(1)
print("AAAA\r", end='')
time.sleep(1)
print("BBBB\r", end='')
</code></pre... | -1 | 2016-08-01T02:07:40Z | 38,691,134 | <p>is this what you want ..</p>
<pre><code>for i in range(10):
time.sleep(1)
print("AAAAA\n\n")
time.sleep(2)
print("BBBBB\n\n")
</code></pre>
| 0 | 2016-08-01T04:40:07Z | [
"python",
"printing"
] |
Making python text game invalid syntax error | 38,690,094 | <p>Right so I'm creating a text game in python as my first big project, but I'm confused about my syntax. It says invalid syntax, but I can see anything else. all help is appreciated in advance. </p>
<pre><code>def fight(playerhp, a1, a2, a3, a4, run, d1, d2, d3, d4, enemy, edamage, armor, attack, enemytype, rewar... | -3 | 2016-08-01T02:09:17Z | 38,690,182 | <p>You have a lot of syntax errors...</p>
<p>First, you forgot to indent all the code after the method definition. Second, you forgot a closing parentheses for this line of code,</p>
<pre><code>attack = input("would you like to " + a1 + a2 + a3 + a4 + "or " + run
</code></pre>
<p>Next, you forgot a colon after this ... | 0 | 2016-08-01T02:21:57Z | [
"python"
] |
in selenium can't switch handle new popup layer | 38,690,119 | <p>this is html part. it appear new layer popup in widows.</p>
<pre><code><div style="top: 20px;" id="appInstallSuggestLayer" class="ly_prm_app">
<div class="prm_app_wrap">
<div class="prm_app_header">
<strong class="blind">today news</strong>
</code></pre>
<p>but... | 0 | 2016-08-01T02:12:33Z | 38,690,489 | <p>If there is no <code>frame</code> or <code>iframe</code> no need to switch anywhere just need to implement <code>WebDriverWait</code> to wait until popup visible as below :</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_cond... | 1 | 2016-08-01T03:11:45Z | [
"python",
"selenium"
] |
How to handle stdout from command like "with open() as f:" in python | 38,690,201 | <p>I am trying to stream large files over ssh, and can currently stream raw files just fine; as in:</p>
<pre><code>with open('somefile','r') as f:
tx.send(filepath='somefile',stream=f.read())
</code></pre>
<p>tx is a higher level class instance that I have that can stream just fine this way, but I want to be able t... | 1 | 2016-08-01T02:25:10Z | 38,690,787 | <p>I think that the only issue is the <code>.readall()</code> method, that does not exist.</p>
<p>You can use <code>p.stdout.read()</code> to read the entire contents of stdout:</p>
<pre><code>p = subprocess.Popen(['tar','cfv','-','somefile'], stdout=subprocess.PIPE)
tx.send(filepath='somefile',stream=p.stdout.read()... | 0 | 2016-08-01T03:55:59Z | [
"python",
"streaming",
"paramiko"
] |
How to handle stdout from command like "with open() as f:" in python | 38,690,201 | <p>I am trying to stream large files over ssh, and can currently stream raw files just fine; as in:</p>
<pre><code>with open('somefile','r') as f:
tx.send(filepath='somefile',stream=f.read())
</code></pre>
<p>tx is a higher level class instance that I have that can stream just fine this way, but I want to be able t... | 1 | 2016-08-01T02:25:10Z | 38,691,396 | <p>I walked back and started with a basic example:</p>
<pre><code>calc_table_file = '/mnt/condor/proteinlab/1468300008.table'
import subprocess
class TarStream:
def open(self,filepath):
p = subprocess.Popen(['tar','cfv','-',filepath], stdout=subprocess.PIPE)
return(p.stdout)
import paramiko
def writer(s... | 0 | 2016-08-01T05:11:03Z | [
"python",
"streaming",
"paramiko"
] |
Python multi-threading/processing module for tasks with dependencies requiring sequencing | 38,690,202 | <p>I'm in the process of implementing a Python module that provides a thread (or process) pool that can handle processing tasks concurrently that are potentially dependent on each other. For example, in the case of an order management system, you could place an order, place another order, cancel the second order, plac... | 1 | 2016-08-01T02:25:11Z | 38,690,379 | <p>Yes, take a look at <a href="/questions/tagged/dask" class="post-tag" title="show questions tagged 'dask'" rel="tag">dask</a>. It has different schedulers for multithreaded, multiprocessing, and distributed computing which reuse threads and processes through <code>TaskPool</code> and <code>Pool</code> respec... | 1 | 2016-08-01T02:54:25Z | [
"python",
"multithreading",
"concurrency",
"dependencies",
"multiprocessing"
] |
Multiple if statement in list comprehension | 38,690,264 | <p>I have a python list that needs to be converted to a tuple, I also need to add a additional check to check the list element type and convert them to tuple</p>
<p>for example:</p>
<pre><code>row_data = ['map',[10,20]]
row_data = tuple(d._get_pk_val() if hasattr(d, '_get_pk_val') else d if type(d) is list else d fo... | 0 | 2016-08-01T02:34:53Z | 38,690,294 | <p>this should work - </p>
<pre><code>row_data = ['map',[10,20]]
row_data = tuple(d._get_pk_val() if hasattr(d, '_get_pk_val') else tuple(d) if type(d) is list else d for d in row_data)
print(row_data)
Output: ('map', (10, 20))
</code></pre>
| 0 | 2016-08-01T02:39:34Z | [
"python"
] |
React table with django namedtuple returns .map is not a function | 38,690,350 | <p>I want to make a table of with django <code>namedtuple</code> but getting an error. Headers(which is list) works fine though.</p>
<p><code>views.py</code>:</p>
<pre><code>info = [Info(id=5, location_id=861, f=None),Info(id=3, location_id=650, f=None)]
return render('index.html', {'info': info})
</code></pre>
<p><... | 0 | 2016-08-01T02:49:28Z | 39,220,837 | <p>I forgot to put <code>safe</code> when receiving the data. To someone who might encounter this problem too. Please refer to <a href="http://stackoverflow.com/questions/4056883/when-should-i-use-escape-and-safe-in-djangos-template-system">this</a> question too</p>
| 0 | 2016-08-30T07:01:10Z | [
"javascript",
"python",
"django",
"reactjs"
] |
Andrews Plot random numbers in corner | 38,690,358 | <p>I am trying trying to plot some country data in an Andrews Plot but the number '1e12' keeps showing up in the top right corner and I have no idea why its there or how to get rid of it. Here is the plot itself: </p>
<p><a href="http://i.stack.imgur.com/6PoTc.png" rel="nofollow"><img src="http://i.stack.imgur.com/6Po... | 2 | 2016-08-01T02:50:52Z | 38,691,604 | <p>That value is the scale on the axis. You'll have to divide your data by a factor of about 1e11. See the following example with iris data.</p>
<p><a href="https://raw.github.com/pydata/pandas/master/pandas/tests/data/iris.csv" rel="nofollow">iris data linked here</a></p>
<pre><code>from pandas.tools.plotting impo... | 2 | 2016-08-01T05:31:29Z | [
"python",
"pandas",
"matplotlib"
] |
Jupyter note matplotlib inline error in Anaconda | 38,690,433 | <p>I launched notebook in Anaconda, and had the code in screenshot. I don't know what's wrong with my code.</p>
<p><a href="http://i.stack.imgur.com/c9qhC.png" rel="nofollow">Link to code</a></p>
| 0 | 2016-08-01T03:03:14Z | 38,690,452 | <p>You need to actually run the first cell. Notebook is essentially a thin wrapper over a Python shell, and by default, it just executes one cell at a time. The <code>[1]</code> indicates that you only ran the second cell.</p>
| 0 | 2016-08-01T03:05:45Z | [
"python",
"python-3.x",
"jupyter-notebook"
] |
Python Openpyxl doesn't write to spreadsheet | 38,690,496 | <p>I'm trying to automate a task where it's get's the users location and turns them to latitude and longitude and write them to spreadsheet which I did. But it doesn't write anything to the spreadsheet. I tried adding the save too, another for loop and even to set it to write only but that didn't workout. Here is my co... | 0 | 2016-08-01T03:13:30Z | 38,690,522 | <p>Can't test this easily, but in the code you posted is the indent on the line below commen '5 Write to spreadsheet' correct? If it is correct then this line isn't in the loop, it is executed only once. I expect you should indent this line so it is in the for loop. </p>
| 2 | 2016-08-01T03:18:29Z | [
"python",
"xlsx",
"openpyxl"
] |
Kivy updating a widget image from outside the function that calls the layout | 38,690,541 | <p>I have a function scope issue. I need to update 'cardTableLayout' when the 'discard' button is pressed, after the evaluate function is called. How do I do this? I know this is a kv layout language issue. I'm not sure how to refrence 'cardTableLayout' from inside 'buttonClick_callback.'
python code
<code></p>
<pre><... | 0 | 2016-08-01T03:20:59Z | 38,693,781 | <p>The button has been added to the <code>cardTableLayout</code>. On press, it executes a function called <code>buttonClick_callback</code>, passing itself as the first parameter.</p>
<p>This allows to reference the <code>cardTableLayout</code> inside the <code>buttonClick_callback</code> by calling <code>self.parent<... | 0 | 2016-08-01T08:04:06Z | [
"python",
"image",
"layout",
"scope",
"kivy"
] |
Kivy updating a widget image from outside the function that calls the layout | 38,690,541 | <p>I have a function scope issue. I need to update 'cardTableLayout' when the 'discard' button is pressed, after the evaluate function is called. How do I do this? I know this is a kv layout language issue. I'm not sure how to refrence 'cardTableLayout' from inside 'buttonClick_callback.'
python code
<code></p>
<pre><... | 0 | 2016-08-01T03:20:59Z | 38,708,661 | <p>The problem was in the good_deal lib that was imported. The values being passed in were not updating correctly. Once rectified, the canvas is updating correctly. </p>
| 0 | 2016-08-01T21:47:55Z | [
"python",
"image",
"layout",
"scope",
"kivy"
] |
"which version" output differently with setting version in PyCharm | 38,690,596 | <p>I am using currently the latest version of PyCharm and python 2.7 (Home brew). I set python version in PyCharm like this: </p>
<p><a href="http://i.stack.imgur.com/z5uVT.png" rel="nofollow"><img src="http://i.stack.imgur.com/z5uVT.png" alt="enter image description here"></a></p>
<p>However, when I run codes in the... | 0 | 2016-08-01T03:30:36Z | 38,690,713 | <p>You shouldn't be using <code>which python</code> to find out which <code>python</code> you're using.
Try this instead:</p>
<pre><code>import sys
print(sys.executable)
</code></pre>
| 1 | 2016-08-01T03:46:24Z | [
"python",
"pycharm"
] |
Script to replace characters in file | 38,690,620 | <p>i'm facing trouble trying to replace characters in a file.</p>
<pre><code> #!/usr/bin/env python
with open("crypto.txt","r") as arquivo:
data = arquivo.read()
for caracter in data:
if "a" in data:
data = data.replace("a","c")
elif "b" in data:
data = data.replace("b","d")
elif "... | 0 | 2016-08-01T03:33:36Z | 38,690,811 | <p>What about python's <a href="https://docs.python.org/3/library/stdtypes.html#str.translate" rel="nofollow"> string translate</a></p>
<pre><code>import string
with open("crypto.txt","r") as arquivo:
data = arquivo.read()
out = data.translate(string.maketrans("abcdefghijklmnopqrstuvw","defghijklmnopqrstuvwx... | 1 | 2016-08-01T03:58:02Z | [
"python"
] |
Updating heroku django deployed site with new commits to github repo | 38,690,635 | <p>Say I have deployed a django website on heroku through a github repository. (For deployment I simply clicked on the deploy button here - <a href="https://github.com/AmmsA/theresumator#theresumator---using-django-resumator" rel="nofollow">https://github.com/AmmsA/theresumator#theresumator---using-django-resumator</a>... | 0 | 2016-08-01T03:35:54Z | 38,690,869 | <p>When you are pushing the fresh commits <code>git push heroku master</code> or via git hook <code>git push origin master</code> -- these nothing to do with heroku database.</p>
<p>But this will run this command when build <code>python manage.py migrate</code> so if you are changed something in the migrations definet... | 1 | 2016-08-01T04:06:00Z | [
"python",
"django",
"heroku",
"github"
] |
Python - Zero-Order Hold Interpolation (Nearest Neighbor) | 38,690,747 | <p>I will be shocked if there isn't some standard library function for this especially in numpy or scipy but no amount of Googling is providing a decent answer.</p>
<p>I am getting data from the Poloniex exchange - cryptocurrency. Think of it like getting stock prices - buy and sell orders - pushed to your computer. S... | 3 | 2016-08-01T03:51:46Z | 38,691,043 | <p>For your problem you can use <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html" rel="nofollow"><code>scipy.interpolate.interp1d</code></a>. It seems to be able to do everything that you want. It is able to do a zero order hold interpolation if you specify <code>kind="zero"<... | 4 | 2016-08-01T04:28:31Z | [
"python",
"numpy",
"interpolation"
] |
alternative for python Enum with duplicate values | 38,690,784 | <p>I like Enum a lot and I would like to do the following:</p>
<pre><code>class Color(Enum):
green = 0
red = 1
blue = 1
for color in Color:
print(color.name)
print(color.value)
</code></pre>
<p>As you can see, there are duplicate values in Color class. What class alternative can I use in this cas... | 2 | 2016-08-01T03:55:42Z | 38,691,346 | <p>Are you asking how you can have <code>Color.red</code> <em>and</em> <code>Color.blue</code> without <code>blue</code> being an alias for <code>red</code>?</p>
<p>If yes, you'll want to use the <a href="https://pypi.python.org/pypi/aenum" rel="nofollow"><code>aenum</code></a> library (built by the author of <a href=... | 1 | 2016-08-01T05:05:08Z | [
"python",
"enums"
] |
Python Dictionary Returning Only 1 Entry? | 38,690,840 | <p>I've written the following code to print an upper/lower case alphabet dictionary whose values can be shifted by an integer. It keeps returning only one entry (e.g., {Z:z}), even though when I use a print statement in the for loop, I see the entire dictionary printed as expected, no matter what the shift. Any though... | 2 | 2016-08-01T04:00:55Z | 38,690,888 | <p>Instead of setting alpha dict to be a new one entry dict with each use, start with an empty dict and add values at the keys you want.</p>
<pre><code>#build dictionary with shift
for i in range(len(letters)):
if letters[i].islower() == True:
alphaDict[letters[i]] = letters[(i + shift) % 26]
else:
... | 3 | 2016-08-01T04:08:27Z | [
"python",
"dictionary",
"return",
"caesar-cipher"
] |
Python Dictionary Returning Only 1 Entry? | 38,690,840 | <p>I've written the following code to print an upper/lower case alphabet dictionary whose values can be shifted by an integer. It keeps returning only one entry (e.g., {Z:z}), even though when I use a print statement in the for loop, I see the entire dictionary printed as expected, no matter what the shift. Any though... | 2 | 2016-08-01T04:00:55Z | 38,690,907 | <p>You are creating a new dictionary each loop rather than appending it. YOu want to create a new <code>key - value</code> pair for the dictionary each loop. </p>
<pre><code> for i in letters:
if i.islower() == True:
alphaDict[i] = letters[(letters.index(i) + shift) % 26]}
else:
... | 3 | 2016-08-01T04:10:50Z | [
"python",
"dictionary",
"return",
"caesar-cipher"
] |
Reconstruct the list of dict in python but the result is not in order | 38,690,905 | <pre><code>list_1 = [{'1': 'name_1', '2': 'name_2', '3': 'name_3',},
{'1': 'age_1', '2': 'age_2' ,'3': 'age_3',}]
</code></pre>
<p>I want to manipulate this list so that the dicts contain all the attributes for a particular ID. The ID itself must form part of the resulting dict. An example output is shown belo... | 0 | 2016-08-01T04:10:40Z | 38,691,051 | <p>Try using an OrderedDict:</p>
<pre><code>list_1 = [collections.OrderedDict([('1','name_1'), ('2', 'name_2'), ('3', 'name_3')]),
collections.OrderedDict([('1','age_1'),('2','age_2'),('3', 'age_3')])]
list_2=[collections.OrderedDict([('id',x), ('name',list_1[0][x]), ('age', list_1[1][x])])
for x in ... | 0 | 2016-08-01T04:29:27Z | [
"python",
"list",
"dictionary",
"order"
] |
Reconstruct the list of dict in python but the result is not in order | 38,690,905 | <pre><code>list_1 = [{'1': 'name_1', '2': 'name_2', '3': 'name_3',},
{'1': 'age_1', '2': 'age_2' ,'3': 'age_3',}]
</code></pre>
<p>I want to manipulate this list so that the dicts contain all the attributes for a particular ID. The ID itself must form part of the resulting dict. An example output is shown belo... | 0 | 2016-08-01T04:10:40Z | 38,691,099 | <p>To keep the order, you should use an <a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" rel="nofollow">ordered dictionary</a>. Using your sample:</p>
<pre><code>new_list = [OrderedDict([('id', x), ('name', list_1[0][x]), ('age', list_1[1][x])]) for x in list_1[0].keys()]
</code></p... | 1 | 2016-08-01T04:35:43Z | [
"python",
"list",
"dictionary",
"order"
] |
MySQL get multiple items from a table as a input for a single field of another table | 38,690,970 | <p>I have two tables one is teachers another is subjects and I need to link the subjects to the teachers , thats an easy one but the problem is that a single teacher can have multiple subjects.Thus I need a kind of array for that, so that when I do my queries with python it returns an array or should I say a 'tuple of ... | -1 | 2016-08-01T04:20:06Z | 38,691,037 | <p>Database Architecture is most important thing to decide. Here seems 2 approach one is decided by you or other to make a mapping table.</p>
<p>For your Approach:- </p>
<pre><code>id teacher_name Subject
1 XYZ 1,5,6,7
</code></pre>
<p>Query:-</p>
<pre><code>SELECT teacher_name, subject_name
FROM subje... | 1 | 2016-08-01T04:27:34Z | [
"python",
"mysql"
] |
python 3.5 copying excel sheet make loss of data | 38,690,974 | <p>below is the code I<code>m writing. But the result new.xls is broken and images and text in source file hasn</code>t been copied.The source file's text data are not links they are just text values.Is this something I can`t do with it or what?.thanks in advance.
outline of the code is simple.Just coping some sheets a... | 0 | 2016-08-01T04:20:16Z | 38,691,244 | <p>Have you tried to make the Excel file a CSV (Comma Separated Values) file?</p>
<p>I can read and write CSV files with Python with no problem - make sure the file is only one Excel sheet (i.e. not multiple Excel sheets).</p>
<p>Maybe this would solve your issue.</p>
| 0 | 2016-08-01T04:53:07Z | [
"python",
"excel",
"copy"
] |
module importing error exclusively when running a file | 38,690,996 | <p>I'm trying to import and use matplotlib.pyplot in a script and I'm getting the following error:</p>
<pre><code> Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
from matplotlib import pyplot as plt
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.... | 0 | 2016-08-01T04:23:01Z | 38,691,151 | <p>Your file called <code>fractions.py</code> is shadowing the builtin module of the same name, causing problems when other libraries try to use that library. Name your file something else.</p>
| 2 | 2016-08-01T04:42:26Z | [
"python",
"module"
] |
saving outlook attachments with different names in python | 38,691,009 | <p>I have been trying to save attachments from .msg file into PdF files but with different names. Could anyone please help me out how to proceed further? Here is my code. Error comes on the last line of the code. </p>
<pre><code>import win32com.client
import glob
import os
outlook = win32com.client.Dispatch("Outlook.... | -1 | 2016-08-01T04:24:00Z | 38,691,137 | <p>You are getting this error because path you are trying to save to is not valid for Windows. It may contain invalid characters. See <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions" rel="nofollow">this link on MSDN</a> for what is allowed in Windows filenames... | 1 | 2016-08-01T04:40:37Z | [
"python",
"python-3.x"
] |
Softlayer API -- how to check whether my order is accepted or not | 38,691,032 | <p>I placed a order to upgrade a virtual machine's hardware by api(python) "placeOrder", it returned successfully. And I used "wait_for_transaction"(function in VSManager) to wait this transaction to be finished. After a few minutes, it also returned successfully. However, when I login the website "control.softlayer.co... | 0 | 2016-08-01T04:26:57Z | 38,703,664 | <p>The "wait_for_transaction" function in VSManager only checks if the transaction status is not pending, that's why the result is successful despite a failed transaction.
To verify if the upgrade has effectively worked, is necessary to review the status of the last transaction.</p>
<p>You could review the next exampl... | 1 | 2016-08-01T16:23:48Z | [
"python",
"softlayer"
] |
how can I write function with optional output parameters in python | 38,691,069 | <p>how can I write function with optional output parameters.
In example</p>
<p>1) <code>mat = ReadBinFile(filename)</code>
or<br>
2) <code>[mat,titles] = ReadBinFile(filename)</code></p>
<p>if i finished the "ReadBinFile" function with </p>
<pre><code>return mat,titles
</code></pre>
<p>i have a tuple in "mat" in th... | 0 | 2016-08-01T04:32:17Z | 38,691,125 | <p>There are two ways to do this. One is to accept an argument that determines the return value. The second, (and more interesting) is to return a generator.</p>
<pre><code>def ReadBinFile(filename):
yield mat
yield titles
mat,titles = ReadBinFile(filename)
</code></pre>
<p>This will let you get only the first... | -1 | 2016-08-01T04:39:02Z | [
"python"
] |
how can I write function with optional output parameters in python | 38,691,069 | <p>how can I write function with optional output parameters.
In example</p>
<p>1) <code>mat = ReadBinFile(filename)</code>
or<br>
2) <code>[mat,titles] = ReadBinFile(filename)</code></p>
<p>if i finished the "ReadBinFile" function with </p>
<pre><code>return mat,titles
</code></pre>
<p>i have a tuple in "mat" in th... | 0 | 2016-08-01T04:32:17Z | 38,692,659 | <p>You cannot do this without indicating to the function which return type is required, or masking the function name (see my comment). </p>
<p>Let me demonstrate why.</p>
<p>In Perl we can do this, by testing the <em>context</em> of the call. The first (single return value) would be scalar context, and the second in... | 0 | 2016-08-01T06:54:39Z | [
"python"
] |
Morse code converter looping errors | 38,691,111 | <p>EDIT: Completely fixed now.</p>
<p>EDIT: Okay so now I got it to change '... --- ...' to 'sos' (yippee!) But for some reason, it gives me a KeyError when I input '... --- ... / ... --- ...'.
This should give me 'sos sos' but I get a KeyError for ' '.
I think this is because after the '/', there's a space which the ... | 0 | 2016-08-01T04:36:44Z | 38,691,230 | <p>According to your code try something like this:-</p>
<pre><code>def decode(text):
text += '$'
#I have it set up to trigger when there's a space, hence this.
global key
global decoded_text
#I thought maybe this would fix it, it didn't. :(
key = ''
decoded_text = ''
for i in text:
... | 0 | 2016-08-01T04:51:51Z | [
"python",
"loops",
"dictionary"
] |
Morse code converter looping errors | 38,691,111 | <p>EDIT: Completely fixed now.</p>
<p>EDIT: Okay so now I got it to change '... --- ...' to 'sos' (yippee!) But for some reason, it gives me a KeyError when I input '... --- ... / ... --- ...'.
This should give me 'sos sos' but I get a KeyError for ' '.
I think this is because after the '/', there's a space which the ... | 0 | 2016-08-01T04:36:44Z | 38,691,272 | <p>The for loop only considers the initial value of <code>text</code>. Your changes to <code>text</code> in the loop have no effect, because <code>text</code> is a string, and strings are immutable, so your modifications don't modify the original object that you're iterating over. The result is that your loop iterate... | 0 | 2016-08-01T04:56:58Z | [
"python",
"loops",
"dictionary"
] |
Morse code converter looping errors | 38,691,111 | <p>EDIT: Completely fixed now.</p>
<p>EDIT: Okay so now I got it to change '... --- ...' to 'sos' (yippee!) But for some reason, it gives me a KeyError when I input '... --- ... / ... --- ...'.
This should give me 'sos sos' but I get a KeyError for ' '.
I think this is because after the '/', there's a space which the ... | 0 | 2016-08-01T04:36:44Z | 38,691,302 | <p>Assuming space <code>' '</code> is a separator in the input you specify, you may use this:</p>
<pre><code>decoding_dict = {'...' : 's' , '---' : 'o'}
my_text = '... --- ...'
print(''.join(list(map(lambda x: decoding_dict.get(x, None),
</code></pre>
<hr>
<p>Output:</p>
<hr>
<pre><code>sos
</code></pre>
<p>As f... | 0 | 2016-08-01T05:00:21Z | [
"python",
"loops",
"dictionary"
] |
"'module' has no attribute" when working with namedtuples | 38,691,198 | <p>I've run into a bit of a wall here, so I'm going to do my best to explain the issue.</p>
<pre><code>def playGames(jobQueue, ...):
....
nextJob = jobQueue.get()
...
def runPool(fens, timesetting, ...):
...
for fen in fens:
jobQueue.put(Job(gamefen=fen, timecontrol=timesetting))
...
if __name__ == '... | 0 | 2016-08-01T04:47:28Z | 38,691,260 | <p>On Windows, the implementation of multiprocessing places additional constraints on code - effectively what happens is a different python interpreter is started for each process, and then these new interpreters load the python code as non-main - so, to use Job, the non-main processes need to have Job defined outside ... | 1 | 2016-08-01T04:55:35Z | [
"python",
"collections",
"queue",
"namedtuple"
] |
Python Selenium: How to get updated HTML DOM after scrolling down? | 38,691,218 | <p>I m accessing a <a href="https://steemit.com/trending/funny" rel="nofollow">page</a> which has implemented parallax scrolling. I am using the code to scroll bottom but <code>BeautifulSoup</code> it is not fetching updated DOM. Code is given below:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
from ge... | 0 | 2016-08-01T04:50:36Z | 38,691,668 | <p>You probably need to parse the page once the window is scrolled:</p>
<pre><code>driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
sleep(5)
soup = BeautifulSoup(driver.page_source, 'lxml')
entries = soup.select('.entry-... | 1 | 2016-08-01T05:37:42Z | [
"python",
"selenium"
] |
pygame.display.flip - gives this error: "pygame.error: video system not initialized" | 38,691,253 | <p>Hi I need help on Wing IDE 101 because when I try to run my code, the actual program works fine. But after I exit out of it, the shell gives me this error:</p>
<pre><code>Traceback (most recent call last):
File "/Users/kimh2/Desktop/project_1/projectcode_1.py", line 225, in <module>
main()
File "/User... | 0 | 2016-08-01T04:54:31Z | 38,810,766 | <p>The error on closing the application has nothing to do with Wing IDE but rather with using OpenGL alongside with pygame, which does not handle OpenGL contexts very well. A fix that I use while working with pygame + pyopengl is the use the sys module to exit the app instead.</p>
<p>The following code reproduces the ... | 0 | 2016-08-07T04:02:48Z | [
"python",
"python-3.x",
"pygame",
"pyopengl"
] |
How can I make these two threads run one after the other constantly python? | 38,691,273 | <p>so I have this code where I need these two threads to be run one after the other CONSTANTLY.</p>
<p>So, once thread 1 finishes, thread 2 goes and once thread 2 finishes, then thread 1 goes then thread 2 etc...like constantly as if it's an infinite loop.</p>
<pre><code>import httplib, urllib
import time, sys
import... | 1 | 2016-08-01T04:57:03Z | 38,691,315 | <p>This is what you wanted,</p>
<pre><code>while True:
t1 = Thread(target = rfWaterLevelFinal())
t1.start()
t1.join()
t2 = Thread(target = sendDataFinal())
t2.start()
t2.join()
</code></pre>
<p>But no need to run like that with threads, you can just call the methods.</p>
<pre><code>while True... | 1 | 2016-08-01T05:01:28Z | [
"python",
"multithreading",
"loops",
"raspberry-pi",
"threadpool"
] |
Django authenticate not keeping user logged in | 38,691,374 | <p>I am attempting to learn Django's authentication system by contriving a basic login scenario. My views are set up such that a view, <code>logIn</code>, either receives a user's credentials (and prints the success/failure of the login), or it renders a login form.</p>
<p>A second view, <code>privatePage</code>, is d... | 0 | 2016-08-01T05:07:57Z | 38,691,409 | <p>You've not actually logged in. You need to <em>login</em> the user after verifying their identity with <code>authenticate</code>:</p>
<pre><code>from django.contrib.auth import login
user = authenticate(email=email, password=password)
if user is not None:
login(request, user)
</code></pre>
<p><code>lo... | 4 | 2016-08-01T05:12:18Z | [
"python",
"django",
"authentication",
"web",
"login"
] |
Django authenticate not keeping user logged in | 38,691,374 | <p>I am attempting to learn Django's authentication system by contriving a basic login scenario. My views are set up such that a view, <code>logIn</code>, either receives a user's credentials (and prints the success/failure of the login), or it renders a login form.</p>
<p>A second view, <code>privatePage</code>, is d... | 0 | 2016-08-01T05:07:57Z | 38,704,185 | <p>To keep the user logged in a <code>session</code> must be provided to user with usage of <code>login()</code> method. Login is the process of providing user with a session and <code>authenticate() verifies that the given credentials corresponds to an existing user model object in database</code> . Import django's bu... | 0 | 2016-08-01T16:53:46Z | [
"python",
"django",
"authentication",
"web",
"login"
] |
Writing to XMP metadata in python platform agnostic | 38,691,491 | <p>The most common method for writing to XMP metadata in a given file with python appears to be the <code>Python XMP Toolkit</code> <a href="https://github.com/python-xmp-toolkit/python-xmp-toolkit" rel="nofollow">https://github.com/python-xmp-toolkit/python-xmp-toolkit</a></p>
<p>Unfortunately this toolkit doesn't ap... | 0 | 2016-08-01T05:20:31Z | 38,953,626 | <p><a href="http://tilloy.net/dev/pyexiv2/" rel="nofollow">http://tilloy.net/dev/pyexiv2/</a> is now marked obsolete, but it should hopefully work (if <a href="http://www.exiv2.org/" rel="nofollow">http://www.exiv2.org/</a> is also installed).</p>
| 0 | 2016-08-15T10:45:59Z | [
"python",
"python-3.x",
"metadata",
"xmp"
] |
Python: convert 'days since 1990' to datetime object | 38,691,545 | <p>I have a time series that I have pulled from a netCDF file and I'm trying to convert them to a datetime format. The format of the time series is in 'days since 1990-01-01 00:00:00 +10' (+10 being GMT: +10) </p>
<pre><code>time = nc_data.variables['time'][:]
time_idx = 0 # first timestamp
print time[time_idx]
946... | 2 | 2016-08-01T05:25:22Z | 38,691,649 | <p>The <code>datetime</code> module's <a href="https://docs.python.org/3/library/datetime.html#timedelta-objects" rel="nofollow"><code>timedelta</code></a> is probably what you're looking for.</p>
<p>For example:</p>
<pre><code>from datetime import date, timedelta
days = 9465 # This may work for floa... | 2 | 2016-08-01T05:36:29Z | [
"python",
"datetime"
] |
Python: convert 'days since 1990' to datetime object | 38,691,545 | <p>I have a time series that I have pulled from a netCDF file and I'm trying to convert them to a datetime format. The format of the time series is in 'days since 1990-01-01 00:00:00 +10' (+10 being GMT: +10) </p>
<pre><code>time = nc_data.variables['time'][:]
time_idx = 0 # first timestamp
print time[time_idx]
946... | 2 | 2016-08-01T05:25:22Z | 38,691,712 | <p>We can do this in a couple steps. First, we are going to use the <a href="https://dateutil.readthedocs.io/en/latest/" rel="nofollow"><code>dateutil</code></a> library to handle our work. It will make some of this easier.</p>
<p>The first step is to <a class='doc-link' href="http://stackoverflow.com/documentation/py... | 2 | 2016-08-01T05:42:20Z | [
"python",
"datetime"
] |
Python: convert 'days since 1990' to datetime object | 38,691,545 | <p>I have a time series that I have pulled from a netCDF file and I'm trying to convert them to a datetime format. The format of the time series is in 'days since 1990-01-01 00:00:00 +10' (+10 being GMT: +10) </p>
<pre><code>time = nc_data.variables['time'][:]
time_idx = 0 # first timestamp
print time[time_idx]
946... | 2 | 2016-08-01T05:25:22Z | 38,698,583 | <p><a href="http://unidata.github.io/netcdf4-python/#netCDF4.num2date" rel="nofollow">netCDF num2date</a> is the correct function to use here:</p>
<pre><code>import netCDF4
ncfile = netCDF4.Dataset('./foo.nc', 'r')
time = ncfile.variables['time'] # do not cast to numpy array yet
time_convert = netCDF4.num2date(time[... | 1 | 2016-08-01T12:13:22Z | [
"python",
"datetime"
] |
how to convert timedelta which is in days into string? | 38,691,701 | <p>I have taken difference between current week start and date week start where date is column of dates. This difference is in days. When I am trying to define function to convert these days into 1 week difference, 2 week difference and so on.</p>
<p>I am getting error as: </p>
<blockquote>
<p>Cannot compare type '... | 1 | 2016-08-01T05:41:11Z | 38,691,762 | <p>You need convert <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_timedelta.html" rel="nofollow"><code>to_timedelta</code></a> strings <code>0 days</code>, <code>7 days</code>...:</p>
<p>Then I little bit modify function - remove loop and <code>else</code>. You can <a href="http://pandas.pyd... | 1 | 2016-08-01T05:47:27Z | [
"python",
"string",
"pandas",
"dataframe",
"timedelta"
] |
process input image & make duplicate image,& store in another directory | 38,691,888 | <p>i want it to read input image from a directory & make duplicate image and store in another output directory.Now problem is input image,output image and script is in same path.I want input image directory and output image directory</p>
<p>This is what I have so far</p>
<pre><code>import pandas as pd
import os
i... | 0 | 2016-08-01T05:59:34Z | 38,692,298 | <p>Instead of copying by shutil.copy2, you have to indicate the input and output file path.</p>
<p>For example you have the paths defined as:</p>
<pre><code>input_path='D:\\New\\Input_ImageFolder\\'
output_path='D:\\New\\Output_ImageFolder\\'
</code></pre>
<p>Next, you have to issue the following codes BEFORE you ru... | 0 | 2016-08-01T06:32:25Z | [
"python"
] |
How to display an error message in mpl_connect() callback function | 38,691,900 | <p>My understanding is that: Normally, when an error happens, it's thrown down through all the calling functions, and then displayed in the console. Now there's some packages that do their own error handling, especially GUI related packages often don't show errors at all but just continue excecution. </p>
<p>How can w... | 0 | 2016-08-01T06:01:21Z | 38,950,668 | <p>Indeed, when the python interpreter encounters an exception that is never caught, it will print a so-called traceback to stdout before exciting. However, GUI packages usually catch and swallow all exceptions, in order to prevent the python interpreter from exciting. You would like to display that traceback somewhere... | 1 | 2016-08-15T07:06:57Z | [
"python",
"matplotlib",
"error-handling"
] |
How to select consecutive rows from a multi-index pandas dataframe? | 38,691,910 | <p>I have a multi-index pandas dataframe (groupbydataframe) as below:</p>
<pre><code>Store Year Month
1 2013 1 4922.0
2 5315.5
3 5603.0
4 4625.0
5 4995.0
6 4407.0
7 4421.0
... | 1 | 2016-08-01T06:01:55Z | 38,693,194 | <p>You can first convert second and third level of <code>Multiindex</code> <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DatetimeIndex.to_period.html" rel="nofollow"><code>to_period</code></a>:</p>
<pre><code>s = pd.Series({(1, 2013, 2): 5315.5, (1, 2014, 8): 4124.0, (1, 2014, 9): 3970.5, (1112... | 1 | 2016-08-01T07:29:54Z | [
"python",
"pandas",
"dataframe"
] |
How can I include dependencies from brew in a MacOS X python wheel? | 38,692,003 | <p>I built an application, Caffe, on Mac OS X. It has many dependencies in <code>brew</code>, a common package manager, and the build artifact is an importable Python module.</p>
<p>I believe I can package this module as a wheel, a module package of sorts. But I also want to ship all the dependencies. You can see the ... | 0 | 2016-08-01T06:11:15Z | 38,696,495 | <p>If you want to create a standalone executable (out of python project) you might want to use <a href="http://undefined.org/python/#py2app" rel="nofollow">py2app</a>.</p>
<p><a href="https://wiki.python.org/moin/DistributionUtilities" rel="nofollow">Here</a> you can find the documentation for all the Executable Appli... | 0 | 2016-08-01T10:26:14Z | [
"python",
"osx",
"machine-learning",
"compilation",
"caffe"
] |
How can I include dependencies from brew in a MacOS X python wheel? | 38,692,003 | <p>I built an application, Caffe, on Mac OS X. It has many dependencies in <code>brew</code>, a common package manager, and the build artifact is an importable Python module.</p>
<p>I believe I can package this module as a wheel, a module package of sorts. But I also want to ship all the dependencies. You can see the ... | 0 | 2016-08-01T06:11:15Z | 38,838,890 | <p>Adding to Armitage.apk's answer, using py2app an example of how you can actually convert python file to standalone application, this tutorial is great:
<a href="https://www.metachris.com/2015/11/create-standalone-mac-os-x-applications-with-python-and-py2app/" rel="nofollow">https://www.metachris.com/2015/11/create-s... | 0 | 2016-08-08T21:36:16Z | [
"python",
"osx",
"machine-learning",
"compilation",
"caffe"
] |
Difficulty parsing text file Python 2.7 | 38,692,160 | <p>Using Python 2.7, I want to take a file as input, remove some charachters from it, and write that to another file.
I'm not entirely succeeding with the below code:</p>
<pre><code>print 'processing .ujc file for transmit'
infile, outfile = open('app_code.ujc','r'), open('app_code_transmit.ujc','w')
data = infile.rea... | 0 | 2016-08-01T06:22:43Z | 38,692,392 | <p>@MKesper is right. When you read the file, there are \n or \r\n (line separators) depending on your OS. Looking at the expected output, I feel the better way would be to extract the data you need rather than delete the unwanted data. I would take some help from regular expression and here is my attempt:</p>
<pre><c... | 1 | 2016-08-01T06:37:40Z | [
"python",
"python-2.7",
"file",
"parsing"
] |
Difficulty parsing text file Python 2.7 | 38,692,160 | <p>Using Python 2.7, I want to take a file as input, remove some charachters from it, and write that to another file.
I'm not entirely succeeding with the below code:</p>
<pre><code>print 'processing .ujc file for transmit'
infile, outfile = open('app_code.ujc','r'), open('app_code_transmit.ujc','w')
data = infile.rea... | 0 | 2016-08-01T06:22:43Z | 38,692,393 | <p>Your input file is split on multiple lines and you are after a single line output.</p>
<p>You simply need to strip any newline characters before writing:</p>
<pre><code>data.strip("\n")
</code></pre>
| 1 | 2016-08-01T06:37:47Z | [
"python",
"python-2.7",
"file",
"parsing"
] |
How to make function from a list of tuples in Python? | 38,692,371 | <p>I'd like to make a function using the list of tuples, from the first element to the second element,</p>
<pre><code>Tuplelist = [(1, 17), (2, 13), (3, 17), (4, 4), (5, 12), (6, 10), (7, 20), (18, 36), (22, 12), (23, 39)]
</code></pre>
<p>I want the following result :</p>
<pre><code>func(1)=17
func(2)=13
func(3)=17... | -5 | 2016-08-01T06:36:22Z | 38,692,455 | <pre><code>def func(item):
return dict(Tuplelist)[item]
</code></pre>
<p>or better, if you do not want to create the dictionary every time you call the function,</p>
<pre><code>dictTuplelist = dict(Tuplelist)
def func(item):
return dictTuplelist[item]
print func(1), func(2), func(3)
# 17 13 17
</code></pre>
| 1 | 2016-08-01T06:42:12Z | [
"python",
"function",
"tuples"
] |
How to make function from a list of tuples in Python? | 38,692,371 | <p>I'd like to make a function using the list of tuples, from the first element to the second element,</p>
<pre><code>Tuplelist = [(1, 17), (2, 13), (3, 17), (4, 4), (5, 12), (6, 10), (7, 20), (18, 36), (22, 12), (23, 39)]
</code></pre>
<p>I want the following result :</p>
<pre><code>func(1)=17
func(2)=13
func(3)=17... | -5 | 2016-08-01T06:36:22Z | 38,692,716 | <p>if that is all the values-result that you are going to handle, then a <a href="https://docs.python.org/3/library/stdtypes.html#typesmapping" rel="nofollow">dictionary</a> is what you need</p>
<pre><code>>>> Tuplelist = [(1, 17), (2, 13), (3, 17), (4, 4), (5, 12), (6, 10), (7, 20), (18, 36), (22, 12), (23, ... | 0 | 2016-08-01T06:58:46Z | [
"python",
"function",
"tuples"
] |
Python Cannot find file although the error says it exists | 38,692,487 | <p>I have been trying to load the files in python but somehow I cant do so? any help or suggestions would be really helpful.</p>
<pre><code>import numpy as np
import pandas as pd
df=pd.read_csv('C:/Users/user/Desktop/Work/a.csv')
type(df)
print df
</code></pre>
<p>Error shown:</p>
<pre><code>File C:/Users/user/Deskt... | -4 | 2016-08-01T06:44:11Z | 38,692,791 | <p>Seems like you are using windows. Windows directory separator is <code>\</code> not <code>/</code>
try this way:</p>
<pre><code>df=pd.read_csv('C:\\Users\\user\\Desktop\\Work\\a.csv')
</code></pre>
<p>or </p>
<pre><code>import os
file_path = os.path.sep.join(["C:", "Users", "user", "Desktop", "Work", "a.csv"])
df... | 0 | 2016-08-01T07:04:34Z | [
"python"
] |
what is the difference between fit_transform and transform in sklearn countvectorizer? | 38,692,520 | <p><em>i have just started learning random forest , so if this sounds stupid i am very sorry for it</em></p>
<p>I was recently practicing <a href="https://www.kaggle.com/c/word2vec-nlp-tutorial/details/part-1-for-beginners-bag-of-words" rel="nofollow">bag of words introduction : kaggle</a> , i want to clear few thing... | 1 | 2016-08-01T06:46:27Z | 38,709,963 | <p>You do not do a <code>fit_transform</code> on the test data because, when you fit a Random Forest, the Random Forest learns the classification rules based on the values of the features that you provide it. If these rules are to be applied to classify the test set then you need to make sure that the test features are... | 0 | 2016-08-02T00:20:17Z | [
"python",
"scikit-learn",
"tokenize",
"random-forest"
] |
Python generating xml file by python | 38,692,544 | <p>The image below is the result of performance testing. One of my issue is: How can I transfer my result into a XML file? </p>
<p><a href="http://i.stack.imgur.com/J7PSu.png" rel="nofollow"><img src="http://i.stack.imgur.com/J7PSu.png" alt="testdata"></a></p>
<p>I've been trying file writing method. But what if the ... | 1 | 2016-08-01T06:47:40Z | 38,692,683 | <p>Have a look at the <a href="https://pypi.python.org/pypi/yattag/" rel="nofollow">yattag</a> library:</p>
<blockquote>
<p>Generate HTML or XML in a pythonic way. Pure python alternative to web template engines.Can fill HTML forms with default values and error messages.</p>
</blockquote>
<p>Here's an example based... | 0 | 2016-08-01T06:56:16Z | [
"python",
"xml",
"python-2.7",
"xml-parsing",
"ipython"
] |
Python generating xml file by python | 38,692,544 | <p>The image below is the result of performance testing. One of my issue is: How can I transfer my result into a XML file? </p>
<p><a href="http://i.stack.imgur.com/J7PSu.png" rel="nofollow"><img src="http://i.stack.imgur.com/J7PSu.png" alt="testdata"></a></p>
<p>I've been trying file writing method. But what if the ... | 1 | 2016-08-01T06:47:40Z | 38,692,704 | <p>Use this <a href="http://docs.python.org/library/xml.etree.elementtree.html" rel="nofollow">ElementTree</a>. An example of it is,</p>
<pre><code>from xml.etree import ElementTree, cElementTree
from xml.dom import minidom
root = ElementTree.Element('root')
child1 = ElementTree.SubElement(root, 'doc')
child1_1 = Ele... | 1 | 2016-08-01T06:57:49Z | [
"python",
"xml",
"python-2.7",
"xml-parsing",
"ipython"
] |
Django view is not loading changes | 38,692,693 | <p>I am a django beginner. I have a deployed django app with nginx, uwSGI and postgresql. When I try to change some code in a view, this one is reflected in the client side but the error continues existing, thanks.</p>
<p><strong>Here is the output failure:</strong> </p>
<pre><code>Django Version: 1.6.5
Exception Typ... | 0 | 2016-08-01T06:57:07Z | 38,693,744 | <p>Thanks, the problem was that, you have to restart uwsgi process to apply changes in the project</p>
| 1 | 2016-08-01T08:02:24Z | [
"python",
"django",
"postgresql",
"nginx"
] |
xml subelements in python query | 38,692,914 | <p>I am trying to replicate some XML code in python to put into a program I am currently working on which does some panoramic captures. At the end the idea is to export an XML file of the capture detail to allow for easier importing into one of the various panorama capture programs.</p>
<p>I am fairly new to Python, b... | 0 | 2016-08-01T07:13:01Z | 38,693,112 | <p>You must use the following command:</p>
<pre><code>title.text = "some text"
</code></pre>
| 2 | 2016-08-01T07:24:03Z | [
"python",
"xml"
] |
xml subelements in python query | 38,692,914 | <p>I am trying to replicate some XML code in python to put into a program I am currently working on which does some panoramic captures. At the end the idea is to export an XML file of the capture detail to allow for easier importing into one of the various panorama capture programs.</p>
<p>I am fairly new to Python, b... | 0 | 2016-08-01T07:13:01Z | 38,695,064 | <p>Text nodes and element nodes are two kinds of nodes and an XML element node can have any number of text and/or element child nodes in any order.</p>
<p>If you want to add text to a node, you can do it with the <code>.text</code> attribute </p>
<pre><code>title.text = "Sometext"
</code></pre>
<p>If you want to add... | 1 | 2016-08-01T09:15:58Z | [
"python",
"xml"
] |
xml subelements in python query | 38,692,914 | <p>I am trying to replicate some XML code in python to put into a program I am currently working on which does some panoramic captures. At the end the idea is to export an XML file of the capture detail to allow for easier importing into one of the various panorama capture programs.</p>
<p>I am fairly new to Python, b... | 0 | 2016-08-01T07:13:01Z | 38,701,464 | <pre><code>import xml.etree.ElementTree as ET
root = ET.Element("papywizard")
root.set("version", "c")
header = ET.SubElement(root,"header")
general = ET.SubElement(header, "general")
title = ET.SubElement(general,"title")
title.text = str('Test123') # This is how you set it
tree = ET.ElementTree(root) # This step wi... | 1 | 2016-08-01T14:31:08Z | [
"python",
"xml"
] |
How do I incorporate quotation marks into a user input? I want them to input a string but it is akward to say put in quotes | 38,692,931 | <pre><code>def palindrome(s):
s=input ("Enter a phrase (**use quotation marks for words**): ")
s.lower()
return s[::-1]==s
palindrome(s)
</code></pre>
<p>This is my code. How do I change it so I can take out the bolded section? I use python 2 and it won't accept string inputs without the quotation marks.<... | 2 | 2016-08-01T07:14:04Z | 38,693,021 | <p>Use <code>raw_input</code> instead of <code>input</code>. In Python 2 <code>input</code> tries to evaluate the user's input, so letters are evaluated as variables.</p>
| 1 | 2016-08-01T07:19:23Z | [
"python",
"python-2.x"
] |
How do I incorporate quotation marks into a user input? I want them to input a string but it is akward to say put in quotes | 38,692,931 | <pre><code>def palindrome(s):
s=input ("Enter a phrase (**use quotation marks for words**): ")
s.lower()
return s[::-1]==s
palindrome(s)
</code></pre>
<p>This is my code. How do I change it so I can take out the bolded section? I use python 2 and it won't accept string inputs without the quotation marks.<... | 2 | 2016-08-01T07:14:04Z | 38,693,043 | <p>A <a class='doc-link' href="http://stackoverflow.com/documentation/python/266/basic-input-and-output/973/using-input-and-raw-input#t=201608010718573153743"><code>raw_input</code></a> will do the job. <a href="http://stackoverflow.com/q/4915361/5018771">This question</a> about input differences in Python 2 and 3 migh... | 1 | 2016-08-01T07:20:42Z | [
"python",
"python-2.x"
] |
python accessing returned variable | 38,692,971 | <p>I'm still not comfortable with python. Experimenting with a deep learning open source code, I'm writting a test code and I can see it runs like below. (using datasets package and pascal_voc module in it, BTW, this is from py-faster-rcnn code)</p>
<pre><code>>>> import datasets
>>> import datasets.... | 1 | 2016-08-01T07:16:14Z | 38,693,083 | <p>I don't know your library at all, but from what you've shown, you probably want to assign the results of <code>_load_pascal_annotation</code> to a new variable, then access the <code>boxes</code> item in the dictionary. Try something like this:</p>
<pre><code>data = d._load_pascal_annotation('{0:06d}'.format(5))
pr... | 1 | 2016-08-01T07:22:20Z | [
"python",
"caffe",
"pycaffe"
] |
python accessing returned variable | 38,692,971 | <p>I'm still not comfortable with python. Experimenting with a deep learning open source code, I'm writting a test code and I can see it runs like below. (using datasets package and pascal_voc module in it, BTW, this is from py-faster-rcnn code)</p>
<pre><code>>>> import datasets
>>> import datasets.... | 1 | 2016-08-01T07:16:14Z | 38,693,084 | <p>You call the <code>_load_pascal_annotation</code> method but you don't keep a reference to its return value.</p>
<p>Try:</p>
<pre><code>r_value = d._load_pascal_annotation('{0:06d}'.format(5))
r_value['boxes']
</code></pre>
| 2 | 2016-08-01T07:22:21Z | [
"python",
"caffe",
"pycaffe"
] |
Python how to get function formula given it's inputs and results | 38,693,093 | <p>Assume we have a function with unknown formula, given few inputs and results of this function, how can we get the function's formula.</p>
<p>For example we have inputs x and y and result r in format (x,y,r)</p>
<pre><code>[ (2,4,8) , (3,6,18) ]
</code></pre>
<p>And the desired function can be</p>
<pre><code>f(x,... | -3 | 2016-08-01T07:22:44Z | 38,695,132 | <p>As you post the question, the problem is too generic. If you want to find <em>any</em> formula mapping the given inputs to the given result, there are simply too many possible formulas. In order to make sense of this, you need to somehow restrict the set of functions to consider. For example you could say that you'r... | 0 | 2016-08-01T09:18:54Z | [
"python",
"algorithm",
"math",
"interpolation"
] |
python counter with closure | 38,693,236 | <p>I'm trying to build a counter in python with the property of closure. The code in the following works:</p>
<pre><code>def generate_counter():
CNT = [0]
def add_one():
CNT[0] = CNT[0] + 1
return CNT[0]
return add_one
</code></pre>
<p>However when I change the list CNT to a var, it did no... | 0 | 2016-08-01T07:32:26Z | 38,693,333 | <p>Python determines the scope of a name by looking at name binding behaviour; assignment is one such behaviour (function parameters, importing, the target in <code>for target ...</code> or <code>while .. as target</code> are other examples). A name you bind to in a function is considered <em>local</em>. See the <a hre... | 3 | 2016-08-01T07:38:24Z | [
"python",
"closures"
] |
python counter with closure | 38,693,236 | <p>I'm trying to build a counter in python with the property of closure. The code in the following works:</p>
<pre><code>def generate_counter():
CNT = [0]
def add_one():
CNT[0] = CNT[0] + 1
return CNT[0]
return add_one
</code></pre>
<p>However when I change the list CNT to a var, it did no... | 0 | 2016-08-01T07:32:26Z | 38,693,347 | <p>It doesn't <em>have</em> to be a list, it just has to be an mutable object which you <em>mutate</em>, not reassign.</p>
<p>From the <a href="https://docs.python.org/3/faq/programming.html#what-are-the-rules-for-local-and-global-variables-in-python" rel="nofollow">docs</a>:</p>
<blockquote>
<p>If a variable is as... | 0 | 2016-08-01T07:39:19Z | [
"python",
"closures"
] |
What is the Python equivalent of RequestConfig in Java? | 38,693,254 | <p>I have the following piece of code in Java:</p>
<pre><code>RequestConfig.custom().setSocketTimeout(10).setConnectTimeout(20).build();
</code></pre>
<p>How do I achieve the same thing in Python?</p>
| 2 | 2016-08-01T07:33:37Z | 38,693,836 | <p>Please, take a look to this <a href="http://stackoverflow.com/a/3432222/3014866">answer</a> where is shown how to set <code>timeout</code>. </p>
<p>It results from <a href="https://docs.python.org/2/library/socket.html#socket.socket.settimeout" rel="nofollow">documentation</a> that <code>setSocketTimeout</code> and... | 1 | 2016-08-01T08:06:32Z | [
"java",
"python",
"apache",
"python-2.7",
"http"
] |
How to establish communication between a python script running on Linux with a .NET C# application running on windows? | 38,693,270 | <p>I am working on an application that requires me to interface a python script running on linux OS on a virtual machine with a .net c# application having wpf forms running on windows such that that the c# application sends files to the python script for processing. What are my options in light of this setting? </p>
<... | 0 | 2016-08-01T07:34:50Z | 38,693,427 | <p>Use sockets to send the file bytes and the result between them.</p>
<p>Some documentation here:</p>
<p><a href="https://msdn.microsoft.com/en-us/library/b6xa24z5(v=vs.110).aspx" rel="nofollow">C# Sockets</a></p>
<p><a href="https://docs.python.org/2/howto/sockets.html" rel="nofollow">Python Sockets</a></p>
<p>ED... | 1 | 2016-08-01T07:44:05Z | [
"c#",
"python",
".net",
"linux",
"cross-platform"
] |
How to establish communication between a python script running on Linux with a .NET C# application running on windows? | 38,693,270 | <p>I am working on an application that requires me to interface a python script running on linux OS on a virtual machine with a .net c# application having wpf forms running on windows such that that the c# application sends files to the python script for processing. What are my options in light of this setting? </p>
<... | 0 | 2016-08-01T07:34:50Z | 38,693,523 | <p>If you have network connection between machines (local network, host only or Internet) then you could listen for files on python using:</p>
<ol>
<li><a class='doc-link' href="http://stackoverflow.com/documentation/python/1309/python-networking/5718/creating-a-udp-server#t=201608010743374011557">UDP </a></li>
<li><a... | 0 | 2016-08-01T07:49:02Z | [
"c#",
"python",
".net",
"linux",
"cross-platform"
] |
Can't correctly parse cisco cli command output | 38,693,276 | <p>I am trying to parse Cisco <code>show ip interface vrf all</code> command output from txt file by reading line by line in loop.</p>
<p>The output is:</p>
<pre class="lang-none prettyprint-override"><code>IP Interface Status for VRF "default"
loopback1, Interface status: protocol-up/link-up/admin-up, iod: 212,
IP a... | 1 | 2016-08-01T07:35:11Z | 38,693,509 | <p>You can use this expression:</p>
<pre><code>^(Vlan\d+).+[\n\r]
.+?subnet:\ (.+)
</code></pre>
<p><hr>
In <code>Python</code> code:</p>
<pre><code>import re
rx = re.compile("""
^(Vlan\d+).+[\n\r] # capture Vlan, followed by digits at the beginning of line
.+?subnet:\ (.+) # match anything lazily, followe... | 0 | 2016-08-01T07:48:07Z | [
"python",
"regex",
"parsing"
] |
creating new numpy array dataset for each loop | 38,693,417 | <p>I need to create a new dataset variable everytime within a for loop
using .append as below wont work. Note the shape of each numpy array type variable is (56, 25000)</p>
<pre><code>ps=[1,2,3,4]
for subj in ps:
datapath = '/home/subj%d' % (subj)
mydata.append = np.genfromtext(datapath, mydatafile)
</cod... | 2 | 2016-08-01T07:43:32Z | 38,693,470 | <p>It's hard to say without more code, but <code>.append</code> is generally a method, and should be called like this:</p>
<pre><code>some_container.append(your_object)
</code></pre>
<p>Note I'm also initializing <code>mydata</code> to be an empty list -- you don't show how you initialize it (if you do at all), so ju... | 2 | 2016-08-01T07:46:24Z | [
"python",
"numpy"
] |
How do I extract data from a Bokeh ColumnDatasource | 38,693,444 | <p>I was trying to avoid using a ColumnDataSource and instead of that I was passing pandas dataframe columns directly to Bokeh plots.</p>
<p>Soon though I had to implement a HoverTool which requires to have the data in a ColumnDataSource. So, I started using ColumnDataSource.</p>
<p>Now, I was creating a box annotati... | 1 | 2016-08-01T07:44:51Z | 38,726,028 | <p>A ColumnDataSource object has an attribute <code>data</code> which will return the python dictionary used to create the object in the first place. </p>
<pre><code>from bokeh.plotting import ColumnDataSource
# define ColumnDataSource
source = ColumnDataSource(
data=dict(
x=[1, 2, 3, 4, 5],
y=[2,... | 1 | 2016-08-02T16:35:33Z | [
"python",
"pandas",
"data-visualization",
"bokeh"
] |
My user input takes uppercase letters different as lower case letters. It interferes with the results. Any tips? | 38,693,515 | <pre><code> def palindrome(): #Before I had parameter s, but it is repetitive.
s=raw_input ("Enter a phrase : ") #Raw input makes the input not considered as a variable but as a string
s.lower()
return s[::-1]==s
palindrome()
</code></pre>
<p>2 questions. </p>
<ol>
<li>Does the raw_input makes an i... | 1 | 2016-08-01T07:48:33Z | 38,693,538 | <p><code>lower()</code> is not in-place, it returns a new string.</p>
<p>You should either reassign it to <code>s</code> (<code>s = s.lower()</code>) or call <code>lower</code> on the input itself:</p>
<pre><code> s = raw_input("Enter a phrase : ").lower()
</code></pre>
| 1 | 2016-08-01T07:50:00Z | [
"python"
] |
My user input takes uppercase letters different as lower case letters. It interferes with the results. Any tips? | 38,693,515 | <pre><code> def palindrome(): #Before I had parameter s, but it is repetitive.
s=raw_input ("Enter a phrase : ") #Raw input makes the input not considered as a variable but as a string
s.lower()
return s[::-1]==s
palindrome()
</code></pre>
<p>2 questions. </p>
<ol>
<li>Does the raw_input makes an i... | 1 | 2016-08-01T07:48:33Z | 38,693,571 | <p>In python, the two main ways of taking input is through <code>raw_input</code>, which takes the input in as a string, and <code>input</code>, which takes the variable in as the type entered like a int.</p>
<p>The <code>s.lower()</code> function returns a string so the proper format would be</p>
<pre><code>s = s.lo... | 1 | 2016-08-01T07:52:02Z | [
"python"
] |
Softlayer API -- exception happened when calling softlayer api | 38,693,625 | <p>I got an exception: "TransportError: TransportError(0): ('Connection aborted.', error(110, 'Connection timed out'))" when I called the api: Virtual_Guest::getBandwidthTotal.</p>
<p>It happened in this situation:</p>
<ol>
<li><p>one <strong>same</strong> softlayer-api username and key</p></li>
<li><p>I called the f... | 0 | 2016-08-01T07:55:00Z | 38,699,490 | <p>The timeout errors are usually generated when the client is waiting a response of the API, this situation is documented <a href="https://sldn.softlayer.com/blog/phil/How-Solve-Error-fetching-http-headers" rel="nofollow">here</a>, in your case you can try to increase the timeout of your client, if you are using the S... | 1 | 2016-08-01T12:55:08Z | [
"python",
"softlayer"
] |
Softlayer API -- exception happened when calling softlayer api | 38,693,625 | <p>I got an exception: "TransportError: TransportError(0): ('Connection aborted.', error(110, 'Connection timed out'))" when I called the api: Virtual_Guest::getBandwidthTotal.</p>
<p>It happened in this situation:</p>
<ol>
<li><p>one <strong>same</strong> softlayer-api username and key</p></li>
<li><p>I called the f... | 0 | 2016-08-01T07:55:00Z | 38,880,747 | <p>There is a limit on the number of API calls that can be made by an account per second. I believe this limit is per username, however I would not recommend using a bunch of different users to get around this limit. </p>
<p>My suggestion would be to use an objectMask to get as much data as possible in one API call, i... | 0 | 2016-08-10T18:15:39Z | [
"python",
"softlayer"
] |
How to process a large text file to get part of this file more efficiently? | 38,693,716 | <p>I have a text file like this:</p>
<pre><code> A B C D E F ... X Y Z
a 1 0 1 2 1 0 ... 1 0 2
b 1 2 0 1 1 2 ... 1 0 0
c . . . . . . ..... . .
d . . . . . . ..... . .
e . . . . . . ..... . .
f . . . . . . ..... . .
. . . . . . . ..... . .
. . . . . . . ..... . .
. . . . . . . ..... . .
x 1 0 1 2 1 0 ... 1 0 2
y 0 0 1... | 2 | 2016-08-01T08:00:51Z | 38,694,223 | <p>You can use this code</p>
<pre><code>with open('a.txt','w') as fout:
with open('b.txt','r') as fin:
lines_done=0
fin.readline() # skip the first line (" A B C D E F ... X Y Z" in your example)
# fout.write("E F\n") # uncomment this line if you want the column headings in fout
fo... | 0 | 2016-08-01T08:30:35Z | [
"python",
"dataset"
] |
How to process a large text file to get part of this file more efficiently? | 38,693,716 | <p>I have a text file like this:</p>
<pre><code> A B C D E F ... X Y Z
a 1 0 1 2 1 0 ... 1 0 2
b 1 2 0 1 1 2 ... 1 0 0
c . . . . . . ..... . .
d . . . . . . ..... . .
e . . . . . . ..... . .
f . . . . . . ..... . .
. . . . . . . ..... . .
. . . . . . . ..... . .
. . . . . . . ..... . .
x 1 0 1 2 1 0 ... 1 0 2
y 0 0 1... | 2 | 2016-08-01T08:00:51Z | 38,694,467 | <p>Since columns are separated by ' ' You can use <a href="https://docs.python.org/3.6/library/stdtypes.html?highlight=split#str.split" rel="nofollow">str.split</a>.</p>
<pre><code>def extract(nin,nout,cidx,rows):
with open(nout,'w') as fout:
with open(nin,'r') as fin:
offest = 0
... | 0 | 2016-08-01T08:44:26Z | [
"python",
"dataset"
] |
Django - How to show dropdown value instead object? | 38,693,722 | <p>It seems i can't get dropdown value instead object.</p>
<p><a href="http://i.stack.imgur.com/2XzHW.png" rel="nofollow"><img src="http://i.stack.imgur.com/2XzHW.png" alt="enter image description here"></a></p>
<p>form.html</p>
<pre><code>{% extends "base.html" %}
{% load i18n %}
{% block content %}
<form metho... | 1 | 2016-08-01T08:01:08Z | 38,693,811 | <p>You should implement <code>__str__</code> (or <code>__unicode__</code> if Python 2) in the object's model.</p>
<p>From Django's <a href="https://docs.djangoproject.com/en/1.9/ref/models/instances/#str" rel="nofollow">docs</a>:</p>
<blockquote>
<p>Django uses str(obj) in a number of places. Most notably, to displ... | 3 | 2016-08-01T08:05:39Z | [
"python",
"django"
] |
Django - How to show dropdown value instead object? | 38,693,722 | <p>It seems i can't get dropdown value instead object.</p>
<p><a href="http://i.stack.imgur.com/2XzHW.png" rel="nofollow"><img src="http://i.stack.imgur.com/2XzHW.png" alt="enter image description here"></a></p>
<p>form.html</p>
<pre><code>{% extends "base.html" %}
{% load i18n %}
{% block content %}
<form metho... | 1 | 2016-08-01T08:01:08Z | 38,694,010 | <p>Update your models.py like this:</p>
<pre><code>class Campaign(models.Model):
user = models.ForeignKey(User)
campaign_name = models.CharField(max_length=50)
autoresponder_type = (
('Send replies to inbox messages','Send replies to inbox
messages'),
('Post replies to users comments','Post re... | 0 | 2016-08-01T08:18:53Z | [
"python",
"django"
] |
Python setup.py - install only modifed files | 38,693,968 | <p>Here is my setup.py:</p>
<pre><code>from setuptools import setup, find_packages
import sys
if sys.version_info < (2, 6):
sys.exit('requires python 2.6 and up')
package = '*****'
version_string = '0'
setup(name=package,
version=version_string,
author='*****',
author_email='*****',
u... | 1 | 2016-08-01T08:16:49Z | 38,694,142 | <p>If you are developing the code, this is preferable to use <code>python setup.py develop</code>. Regarding the files that have to be installed, they are handle by setuptools.</p>
| 1 | 2016-08-01T08:26:16Z | [
"python",
"installation",
"setup.py"
] |
install Jupyter extension | 38,694,087 | <p>I want to install check spelling jupyter's extension.
I followed <a href="http://www.simulkade.com/posts/2015-04-07-spell-checking-in-jupyter-notebooks.html" rel="nofollow">this instruction</a> but it required root privileges.
I want to do it on computing cluster so obviously I don't have it.
Is it a way to instal... | 1 | 2016-08-01T08:23:38Z | 38,694,323 | <p>Would using the newer command helps? The article uses <code>ipython</code> command, which is superceded by <code>jupyter</code>.</p>
<p>Download the tools using this in the terminal instead:-</p>
<pre><code>$ jupyter nbextension install https://bitbucket.org/ipre/calico/downloads/calico-spell-check-1.0.zip
$ jupyt... | -1 | 2016-08-01T08:35:56Z | [
"python",
"installation",
"jupyter"
] |
tuple one number with list of numbers python | 38,694,107 | <p>Suppose I have a number <code>15</code> and list of numbers: </p>
<pre><code>[5, 6, 7, 8]
</code></pre>
<p>Now I want to make a list of tuples like</p>
<pre><code>[(15,6), (15,5), (15,7), (15,8)]
</code></pre>
<p>How does one do that quickly?</p>
| 1 | 2016-08-01T08:24:39Z | 38,694,181 | <p>Use a <a href="https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a>:</p>
<pre><code>list_of_nums = [5, 6, 7, 8]
result = [(15, num) for num in list_of_nums]
</code></pre>
<p>Whenever you have a process producing a list based on the output of another sequ... | 2 | 2016-08-01T08:28:40Z | [
"python",
"python-3.x",
"tuples"
] |
tuple one number with list of numbers python | 38,694,107 | <p>Suppose I have a number <code>15</code> and list of numbers: </p>
<pre><code>[5, 6, 7, 8]
</code></pre>
<p>Now I want to make a list of tuples like</p>
<pre><code>[(15,6), (15,5), (15,7), (15,8)]
</code></pre>
<p>How does one do that quickly?</p>
| 1 | 2016-08-01T08:24:39Z | 38,694,584 | <p>You can also try the <code>zip</code> function</p>
<pre><code>result = zip([15]*len(list_of_nums),list_of_nums)
print(result)
[(15, 5), (15, 6), (15, 7), (15, 8)]
</code></pre>
| 1 | 2016-08-01T08:50:33Z | [
"python",
"python-3.x",
"tuples"
] |
Is it thread-safe when using tf.Session in inference service? | 38,694,111 | <p>Now we have used TensorFlow to train and export an model. We can implement the inference service with this model just like how <code>tensorflow/serving</code> does.</p>
<p>I have a question about whether the <code>tf.Session</code> object is thread-safe or not. If it's true, we may initialize the object after start... | 1 | 2016-08-01T08:24:48Z | 38,702,895 | <p>The <code>tf.Session</code> object is thread-safe for <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/client.html#Session.run" rel="nofollow"><code>Session.run()</code></a> calls from multiple threads. </p>
<p>Before TensorFlow 0.10 graph modification was not thread-safe. This was fixed in the 0.... | 2 | 2016-08-01T15:39:39Z | [
"python",
"multithreading",
"tensorflow",
"tensorflow-serving"
] |
input-output program doesn't output the correct integer in python 3 | 38,694,281 | <p>So i've designed a program that you write a football(soccer) stat and it prints you the number of the times you write it. Its been working but i have added the option to quit the function which caused me the follow promblems. If you havent write a stat at least once it would crash. So I fixed it but now when i try t... | 0 | 2016-08-01T08:33:40Z | 39,027,292 | <p>try to define the variable as False before they get called and then true </p>
| 0 | 2016-08-18T20:52:13Z | [
"python",
"python-3.x",
"input",
"int",
"output"
] |
F2PY cannot compile Fortran with print or write | 38,694,291 | <p>I'm having problems compiling Fortran into a Python extension module when the Fortran code includes print or write function calls.</p>
<p>I am on Windows 8.1 with gfortran (through mingw-w64) and the MSVC Compiler for Python 2.7 installed. The Python distribution in use is Anaconda.</p>
<p><strong>test.f</strong><... | 1 | 2016-08-01T08:34:27Z | 38,711,650 | <p>Answering my own question.</p>
<p>Steps to fix:</p>
<ol>
<li>Ignore or scrub the mingw-w64 install. It wasn't needed as Anaconda
comes with mingw</li>
<li>Add C_INCLUDE_PATH to the Windows system environment variables and point that to the include folder located within the anaconda path (e.g. <code>C:\userdata\[us... | 0 | 2016-08-02T04:13:24Z | [
"python",
"visual-c++",
"fortran",
"gfortran",
"f2py"
] |
run python script on vagrant up | 38,694,311 | <p>I'm trying to run a vagranfile that will result in a running python flask app. I've tried using this as the last command to achieve this -
<code>config.vm.provision :shell, :path => "python app.py"</code>
But it resulted with the following error - </p>
<p><code>*</code>path<code>for shell provisioner does not e... | 2 | 2016-08-01T08:35:30Z | 38,695,172 | <p>you have 2 options to run a script using the <a href="https://www.vagrantup.com/docs/provisioning/shell.html" rel="nofollow">vagrant shell provisioner</a> you must pass either the <code>inline</code> or <code>path</code> argument:</p>
<blockquote>
<p><em>inline</em> (string) - Specifies a shell command inline to ... | 2 | 2016-08-01T09:21:07Z | [
"python",
"vagrant",
"vagrantfile"
] |
run python script on vagrant up | 38,694,311 | <p>I'm trying to run a vagranfile that will result in a running python flask app. I've tried using this as the last command to achieve this -
<code>config.vm.provision :shell, :path => "python app.py"</code>
But it resulted with the following error - </p>
<p><code>*</code>path<code>for shell provisioner does not e... | 2 | 2016-08-01T08:35:30Z | 38,695,219 | <p>If you want to start app when the machine start, you can do that:</p>
<ol>
<li><p>move your <code>python app code directory</code> to the Vagrantfile's directory </p></li>
<li><p>Config the Vagrantfile like that:</p>
<pre><code>config.vm.provision "shell", inline: <<-SHELL
python /vagrant/<your python ... | 1 | 2016-08-01T09:23:00Z | [
"python",
"vagrant",
"vagrantfile"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.