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 |
|---|---|---|---|---|---|---|---|---|---|
Debugging a Python Prime Number Program | 38,567,337 | <p>I wrote the code for a Python prime number generator, to generate the first 100 primes. But, somehow, I get non-primes like 22, 25, etc. in my output. I've rechecked it over and over again for hours now and still can't figure out where I went wrong... Please help!</p>
<p>Here's my code:</p>
<pre><code>from math im... | 2 | 2016-07-25T12:06:17Z | 38,567,679 | <p>I would have done it this way; a bit more Pythonic:</p>
<pre><code>y = [2]
x = 3
while len(y) < 100:
if all(x % i != 0 for i in range(2, int(round(sqrt(x) + 1)))):
y.append(x)
x = x + 1
print(y)
</code></pre>
<p>The <code>all()</code> function is very useful, read about <a class='doc-link' href... | 6 | 2016-07-25T12:23:04Z | [
"python",
"debugging"
] |
Debugging a Python Prime Number Program | 38,567,337 | <p>I wrote the code for a Python prime number generator, to generate the first 100 primes. But, somehow, I get non-primes like 22, 25, etc. in my output. I've rechecked it over and over again for hours now and still can't figure out where I went wrong... Please help!</p>
<p>Here's my code:</p>
<pre><code>from math im... | 2 | 2016-07-25T12:06:17Z | 38,567,768 | <p>The other answers are correct, but none of them show that you can actually use an <code>else</code> clause on the <code>for</code> loop. Read more about this <a href="http://python-notes.curiousefficiency.org/en/latest/python_concepts/break_else.html" rel="nofollow">here</a>. So you don't need the <code>if is_prime:... | 4 | 2016-07-25T12:26:49Z | [
"python",
"debugging"
] |
Writting several files according to an element of an original file | 38,567,536 | <p>I need to read a file in bed format that contains coordinates of all chr in a genome, into different files according with the chr. I tried this approach but it doesn't work, it doesn't create any files. Any idees why this happens or alternative approaches to solve this problem?</p>
<pre><code>import sys
def make_o... | 0 | 2016-07-25T12:16:28Z | 38,567,909 | <p>This line:</p>
<pre><code>for line in file_content[:0]:
</code></pre>
<p>says to iterate over an empty list. The empty list comes from the slice <code>[:0]</code> which says to slice from the beginning of the list to just before the first element. Here's a demonstration:</p>
<pre><code>>>> l = ['line 1\n... | 1 | 2016-07-25T12:32:22Z | [
"python",
"file"
] |
Where should I clone into when cloning a python packages from github? | 38,567,555 | <p>Problem: the package I want to install is outdated on pip, and conda doesn't have it in the repo. So, when I install a python package from github using, </p>
<pre><code>git clone package_url
cd package_name
python setup.py
</code></pre>
<p>should I DOWNLOAD the package from within the directory that is the direct... | 0 | 2016-07-25T12:17:41Z | 38,567,632 | <p>Run it from the folder containing <code>setup.py</code>.</p>
<p>Doing:</p>
<pre><code>python setup.py install
</code></pre>
<p>Will install the package in the appropriate directory. The file already contains the logic that puts the package in the right installation directory, so you don't need to worry about how ... | 0 | 2016-07-25T12:21:04Z | [
"python",
"git",
"github",
"packages",
"setup.py"
] |
Where should I clone into when cloning a python packages from github? | 38,567,555 | <p>Problem: the package I want to install is outdated on pip, and conda doesn't have it in the repo. So, when I install a python package from github using, </p>
<pre><code>git clone package_url
cd package_name
python setup.py
</code></pre>
<p>should I DOWNLOAD the package from within the directory that is the direct... | 0 | 2016-07-25T12:17:41Z | 38,567,667 | <p>You can run the setup.py file as you stated, and you follow it by install as follow: </p>
<pre><code>python setup.py install
</code></pre>
<p>Usually, this would lead to installing the package you want to the python path.</p>
| 0 | 2016-07-25T12:22:38Z | [
"python",
"git",
"github",
"packages",
"setup.py"
] |
Where should I clone into when cloning a python packages from github? | 38,567,555 | <p>Problem: the package I want to install is outdated on pip, and conda doesn't have it in the repo. So, when I install a python package from github using, </p>
<pre><code>git clone package_url
cd package_name
python setup.py
</code></pre>
<p>should I DOWNLOAD the package from within the directory that is the direct... | 0 | 2016-07-25T12:17:41Z | 38,567,698 | <p>It can be simpler to use <code>pip</code> for this package as well, by pointing <code>pip</code> directly at the URL:</p>
<pre><code>pip install git+http://....git
</code></pre>
<p>The <code>git+</code> in front of the URL is required.</p>
<p>You can even go a step further and install a specific branch:</p>
<pre... | 0 | 2016-07-25T12:23:52Z | [
"python",
"git",
"github",
"packages",
"setup.py"
] |
What is the issue with inheritance in this code? | 38,567,613 | <pre><code>class a(object):
def __init__(self):
self.num1=0
self.num2=0
def set1(self,score1,score2):
self.num1=score1
self.num2=score2
def show1(self):
print("num1",self.num1,"num2",self.num2)
class b(a):
def __init__(self):
super().__init__()
def ... | 0 | 2016-07-25T12:20:24Z | 38,567,678 | <p>You wrote <code>super.__init__()</code> instead of <code>super().__init__()</code> in <code>__init__</code> of class <code>c</code>.</p>
<p>If you are using Python 2 you will need to call <code>super</code> in the following way: <br/><code>super(ClassName, self).__init__()</code>.</p>
| 0 | 2016-07-25T12:23:03Z | [
"python"
] |
What is the issue with inheritance in this code? | 38,567,613 | <pre><code>class a(object):
def __init__(self):
self.num1=0
self.num2=0
def set1(self,score1,score2):
self.num1=score1
self.num2=score2
def show1(self):
print("num1",self.num1,"num2",self.num2)
class b(a):
def __init__(self):
super().__init__()
def ... | 0 | 2016-07-25T12:20:24Z | 38,567,725 | <p>You need to call super, right now its just a reference.</p>
<pre><code>class c(b):
super().__init__()
</code></pre>
<p>The other thing is that if you wanted to make this inheritance more robust, you could pass through all args and kwargs to <code>__init__</code> like so:</p>
<pre><code>def __init__(self, *ar... | 0 | 2016-07-25T12:25:02Z | [
"python"
] |
What is the issue with inheritance in this code? | 38,567,613 | <pre><code>class a(object):
def __init__(self):
self.num1=0
self.num2=0
def set1(self,score1,score2):
self.num1=score1
self.num2=score2
def show1(self):
print("num1",self.num1,"num2",self.num2)
class b(a):
def __init__(self):
super().__init__()
def ... | 0 | 2016-07-25T12:20:24Z | 38,567,974 | <p>I think it's how you used the <code>super()</code> built-in <a href="https://docs.python.org/2/library/functions.html#super" rel="nofollow">Here the doc</a></p>
<p>In your case, super need two argument: the class and an instance of the class.</p>
<p>In your <code>b.__init__</code> the synthax will be:</p>
<pre><c... | 0 | 2016-07-25T12:35:29Z | [
"python"
] |
Recursive to iterative using a systematic method | 38,567,618 | <p>I've started reading the book <em><a href="https://www.amazon.com/gp/search?index=books&linkCode=qs&keywords=9781107036604" rel="nofollow">Systematic Program Design: From Clarity to Efficiency</a></em> few days ago. Chapter 4 talks about a systematic method to convert any recursive algorithm into its counter... | -19 | 2016-07-25T12:20:48Z | 39,128,242 | <p>So, to restate the question. We have a function <em>f</em>, in our case <code>fac</code>. </p>
<pre><code>def fac(n):
if n==0:
return 1
else:
return n*fac(n-1)
</code></pre>
<p>It is implemented recursively. We want to implement a function <code>facOpt</code> that does the same thing but it... | 3 | 2016-08-24T16:09:43Z | [
"python",
"recursion"
] |
Efficient way to Reshape Data for Time Series Prediction Machine Learning (Numpy) | 38,567,631 | <p>Lets say I have a data set (numpy array) X of N samples of time series each with T time steps of a D-dimensional vector so that:</p>
<pre><code>X.shape == (N,T,D)
</code></pre>
<p>Now I want to reshape it into x (data set) and y (labels) to apply a machine learning to predict the step in the times series.</p>
<p>... | 0 | 2016-07-25T12:21:03Z | 38,568,460 | <p>So I have the following method, but it has a for loop, and I am not sure that I cannot do better:</p>
<pre><code> def reshape_data(self, X, n):
"""
Reshape a data set of N time series samples of T time steps each
Args:
data: Time series data of shape (N,T,D)
n: int, length of time win... | 0 | 2016-07-25T12:59:46Z | [
"python",
"numpy",
"machine-learning",
"time-series",
"reshape"
] |
PyCharm - Django settings honoured in run config but not in python console | 38,567,641 | <p>While setting up my django project in PyCharms I am having trouble configuring the python shell for django. My project structure is as follows:</p>
<pre><code>- mysite_root
- deployment
- ...ansible files
- mysite
- __init__.py
- manage.py
- mysite
- __init__.py
... | 0 | 2016-07-25T12:21:26Z | 39,659,756 | <p>Found the resolution myself.</p>
<p>The issue was that under <kbd>Build, Execution, Deployment</kbd> -> <kbd>Console</kbd> -> <kbd>Django Console</kbd> both Content & Sources root were included & hence <code>mysite_root/mysite</code> came before <code>mysire_root/mysite/mysite</code> due to which PyCharm fa... | 1 | 2016-09-23T11:32:57Z | [
"python",
"django",
"pycharm"
] |
Produce new data frame from extracted grouped data | 38,567,693 | <p>I'm a Python novice. I'm trying to extract trip duration from a series of GPS fixes. There are multiple different tracks that I am trying to get information from and put the results into seperate data frame. The data looks like this (latitude and longitude columns excluded): </p>
<pre><code> track_id DateTime ... | 1 | 2016-07-25T12:23:37Z | 38,567,810 | <p>You were nearly there, basically you can call <code>reset_index</code> with <code>name</code> param to to restore the 'track_id' column and name the aggregated column:</p>
<pre><code>In [44]:
(df.groupby('track_id')['DateTime'].max() - df.groupby('track_id')['DateTime'].min()).reset_index(name='trip_dur')
Out[44]:... | 1 | 2016-07-25T12:28:32Z | [
"python",
"datetime",
"pandas",
"dataframe"
] |
Is it safe to "finally" drop a table just after a fetchall with psycopg2 | 38,567,787 | <p>Give a cursor variable curr over a connection conn, is it safe to "finally" drop a table after fetching all results from it? Something like the following</p>
<pre><code>curr.execute(some_select_query)
try:
results = curr.fetchall()
except:
some_error_handling()
finally:
curr.execute(drop_table_query)
... | 0 | 2016-07-25T12:27:38Z | 38,567,934 | <p>yes, all the rows will be fetched as a list of tuples but, maybe, you want to use <code>else</code> instead of <code>finally</code></p>
<p><code>Else</code> is executed only if <code>try</code> was succesfull, in this way you avoid deleting the table in case of errors during fetching (connection drops, etc...).</p>... | 1 | 2016-07-25T12:33:36Z | [
"python",
"postgresql",
"psycopg2"
] |
Is it possible to have icon in tkinter menubar in python | 38,567,830 | <p>What I get:</p>
<p><img src="http://i.imgur.com/tc0xN71.jpg" alt="Icons not displayed in menu"></p>
<p>My code:</p>
<pre><code>self.menu_bar = tk.Menu(self)
...
self.read_menu = tk.Menu(self.menu_bar, tearoff=False)
self.menu_bar.add_cascade(label='Read', underline=0, state=tk.DISABLED, menu=self.read_menu)
self.... | 0 | 2016-07-25T12:29:16Z | 38,568,066 | <p>It is impossible to do what you want if you are on Windows. Tkinter won't allow you to add icons to the menubar. I think this is related to limitations in the windows API that the underlying tk library uses.</p>
<p>Note: menubars are designed for menus, not commands. Placing a command on a menubar will likely frust... | 1 | 2016-07-25T12:39:48Z | [
"python",
"python-3.x",
"tkinter",
"menu"
] |
Is it possible to have icon in tkinter menubar in python | 38,567,830 | <p>What I get:</p>
<p><img src="http://i.imgur.com/tc0xN71.jpg" alt="Icons not displayed in menu"></p>
<p>My code:</p>
<pre><code>self.menu_bar = tk.Menu(self)
...
self.read_menu = tk.Menu(self.menu_bar, tearoff=False)
self.menu_bar.add_cascade(label='Read', underline=0, state=tk.DISABLED, menu=self.read_menu)
self.... | 0 | 2016-07-25T12:29:16Z | 38,571,943 | <p>It is not possible to add an image to menubar, so the submenus of this menubar will have images instead of string names. However, you can use <code>Menubutton</code> widgets, and set their position close to the left top corner of the parent window to have a visually same view with a <code>Menu</code> object. Here's ... | 1 | 2016-07-25T15:33:55Z | [
"python",
"python-3.x",
"tkinter",
"menu"
] |
Codingbat make_bricks timed out with while loop in python | 38,567,853 | <p>My goal is:
We want to make a row of bricks that is goal inches long. We have a number of small bricks (1 inch each) and big bricks (5 inches each). Return True if it is possible to make the goal by choosing from the given bricks.</p>
<p>My code is:</p>
<pre><code>def make_bricks(small, big, goal):
if small + 5*... | 0 | 2016-07-25T12:30:11Z | 38,568,548 | <p>Okay I know why it doesn't work. Your code would work. But if there is a <code>loop</code> with about ~229500 (I tried to find the limit value on codebat, but sometime it timeout at this value, sometimes it doesn't. But the value is arround 230k) And as you said : One time out, and every value becomes time out. So t... | 0 | 2016-07-25T13:02:56Z | [
"python",
"python-3.x"
] |
Selenium is not working with firefox and python webdriver on ububtu | 38,567,872 | <p>I am trying to write test cases for my webapp using selenium, firefox and python webdrivers while my development environment is setup on ubuntu 16.04 LTS but I am getting Exception,</p>
<pre><code>WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in... | 0 | 2016-07-25T12:31:01Z | 38,569,808 | <p>Selenium is moving away from using FirefoxDriver in favor of <a href="https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver" rel="nofollow">Marionette</a>. I had this issue a few weeks ago when moving to Firefox 47.0 and made the switch to at that time. </p>
<p>The following <a href="https://gith... | 1 | 2016-07-25T14:00:48Z | [
"python",
"python-2.7",
"selenium",
"selenium-webdriver",
"selenium-firefoxdriver"
] |
Is there any way setting font size in Reportlab? | 38,567,880 | <p>I am trying to make simple chart using reportlab with python.</p>
<p>I made chart with title of x and y, but the font seems like small.</p>
<p>I wanna change font to be bold and increase font size.</p>
<p>here is my code.</p>
<pre><code>def DrawPowerChart(self):
arrX = [0]*6
arrY = [0]*3
for i in ra... | 1 | 2016-07-25T12:31:14Z | 38,569,335 | <p>See page 95 of the <a href="https://www.reportlab.com/docs/reportlab-userguide.pdf" rel="nofollow">ReportLab User Guide</a> for details. Here's an example of how you can change the font size <em>and</em> colour:</p>
<pre><code>d.add(String(150,100, 'Hello World', fontSize=18, fillColor=colors.red))
</code></pre>
| 0 | 2016-07-25T13:39:55Z | [
"python",
"pdf",
"reportlab"
] |
How to convert 4D array to another 4D with switched dimentions in Python | 38,567,949 | <p>I'm trying to get Image data from convolution layer in TensorFlow.
I have an array like:</p>
<pre><code>data = [N, Width, Height, Channel]
</code></pre>
<p>where N is the image number, Width and Height are image dimensions and Channel in the index of channel.</p>
<p>What do I need is another 4D array like:</p>
<... | 0 | 2016-07-25T12:34:05Z | 38,568,128 | <p>Just use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html" rel="nofollow"><code>np.transpose</code></a>:</p>
<pre><code>x = np.zeros((32, 10, 10, 3)) # image with 3 channels, size 10x10
res = np.tranpose(x, (0, 3, 1, 2))
print res.shape # prints (32, 3, 10, 10)
</code></pre>
| 1 | 2016-07-25T12:42:58Z | [
"python",
"arrays",
"image",
"numpy",
"tensorflow"
] |
How to convert 4D array to another 4D with switched dimentions in Python | 38,567,949 | <p>I'm trying to get Image data from convolution layer in TensorFlow.
I have an array like:</p>
<pre><code>data = [N, Width, Height, Channel]
</code></pre>
<p>where N is the image number, Width and Height are image dimensions and Channel in the index of channel.</p>
<p>What do I need is another 4D array like:</p>
<... | 0 | 2016-07-25T12:34:05Z | 38,568,134 | <p>Use the transpose function to reorder the dimensions.</p>
<p><a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/array_ops.html#transpose" rel="nofollow">https://www.tensorflow.org/versions/r0.9/api_docs/python/array_ops.html#transpose</a></p>
<p>You would do something like this in the tensorflow cod... | 1 | 2016-07-25T12:43:05Z | [
"python",
"arrays",
"image",
"numpy",
"tensorflow"
] |
customize Django Rest Framework serializers output? | 38,567,969 | <p>I have a Django model like this:</p>
<pre><code>class Sections(models.Model):
section_id = models.CharField(max_length=127, null=True, blank=True)
title = models.CharField(max_length=255)
description = models.TextField(null=True, blank=True)
class Risk(models.Model):
title = models.CharField(max_le... | 1 | 2016-07-25T12:35:10Z | 38,568,493 | <p>You could override <code>to_representation()</code> method of your serializer: </p>
<pre><code>class RiskActionPerSectionsSerializer(serializers.ModelSerializer):
class Meta:
model = Sections
fields = ('section_id', 'risks', 'actions')
depth = 1
def to_representation(self, instance):
... | 2 | 2016-07-25T13:01:05Z | [
"python",
"json",
"django",
"django-rest-framework"
] |
How to ADD OBR to the HL7 message? | 38,567,996 | <p>I am trying to generate the HL7 message using the Python library hl7apy, but when HL7 message is generate it does not gives the OBR segment in the output, please try to solve this query.</p>
<p>The code is </p>
<pre><code>from hl7apy import core
hl7 = core.Message("ORM_O01")
hl7.msh.msh_3 = "SendingApp"
hl7.msh.ms... | 1 | 2016-07-25T12:36:26Z | 38,611,477 | <p>You should add a OrderDetailGroup before adding and populating the OBR segment.</p>
| 0 | 2016-07-27T11:17:59Z | [
"python",
"hl7",
"hl7-v2",
"hl7-v3"
] |
Trouble importing Numpy into Grass GIS 7.0 on Windows 10 | 38,568,072 | <p>I recently installed Grass GIS 7 on my Windows 10. Upon loading the program, I receive an error in the terminal window stating: </p>
<blockquote>
<p>'This module requires the Numeric/numarray or NumPy module, which
could not be imported. It probably is not installed (it's part of the
standard Python distribut... | 0 | 2016-07-25T12:40:05Z | 38,568,302 | <p>I'm guessing that GRASS brings its own Python interpreter with it rather than using the Anaconda version that you installed. As the <a href="https://grasswiki.osgeo.org/wiki/GRASS_and_Python#Using_a_version_of_Python_different_from_the_default_installation" rel="nofollow">notes on GRASS and Python</a> remark "On Win... | 1 | 2016-07-25T12:51:53Z | [
"python",
"numpy",
"module",
"anaconda",
"grass"
] |
Trouble importing Numpy into Grass GIS 7.0 on Windows 10 | 38,568,072 | <p>I recently installed Grass GIS 7 on my Windows 10. Upon loading the program, I receive an error in the terminal window stating: </p>
<blockquote>
<p>'This module requires the Numeric/numarray or NumPy module, which
could not be imported. It probably is not installed (it's part of the
standard Python distribut... | 0 | 2016-07-25T12:40:05Z | 39,773,207 | <p>In OSGeo4W installer, upgrading python-numpy to 1.11.0-1 caused this error in GRASS 7.0.4 for me. Backing python-numpy to 2.7-1.7.0-1 solved the Problem</p>
| 0 | 2016-09-29T14:33:58Z | [
"python",
"numpy",
"module",
"anaconda",
"grass"
] |
How do I get minimum and maximum epoch time from python dictionary? | 38,568,174 | <p>I'm having one python dictionary. In this dictionary I saved value as a epoch times. I want to know which is maximum epoch time and which is minimum epoch time, Further I want to split those epoch times into different time-slots.</p>
<p><strong>Program-Code-</strong></p>
<pre><code>for key,value in self.key_dict.i... | 0 | 2016-07-25T12:45:44Z | 38,568,293 | <p>Max and min can be determined using functions <code>min()</code> and <code>max()</code> on <code>dict.values()</code> which returns a list of the dictionary's values:</p>
<pre><code>minimum = min(self.key_dict.values())
maximum = max(self.key_dict.values())
</code></pre>
| 0 | 2016-07-25T12:51:16Z | [
"python",
"dictionary",
"max",
"min",
"epoch"
] |
How do I get minimum and maximum epoch time from python dictionary? | 38,568,174 | <p>I'm having one python dictionary. In this dictionary I saved value as a epoch times. I want to know which is maximum epoch time and which is minimum epoch time, Further I want to split those epoch times into different time-slots.</p>
<p><strong>Program-Code-</strong></p>
<pre><code>for key,value in self.key_dict.i... | 0 | 2016-07-25T12:45:44Z | 38,568,354 | <p>In case you want both the key and the value to be returned, use <code>min</code> and <code>max</code> function, together with the <code>key</code> kwarg:</p>
<pre><code>key_dict = {'a': 1, 'b': 2}
print min(key_dict.iteritems(), key=lambda item: item[1])
# ('a', 1)
print max(key_dict.iteritems(), key=lambda item: ... | 0 | 2016-07-25T12:54:16Z | [
"python",
"dictionary",
"max",
"min",
"epoch"
] |
How do I get minimum and maximum epoch time from python dictionary? | 38,568,174 | <p>I'm having one python dictionary. In this dictionary I saved value as a epoch times. I want to know which is maximum epoch time and which is minimum epoch time, Further I want to split those epoch times into different time-slots.</p>
<p><strong>Program-Code-</strong></p>
<pre><code>for key,value in self.key_dict.i... | 0 | 2016-07-25T12:45:44Z | 38,568,503 | <p>If you have access to <code>numpy</code>, then you can use it to help you bin the data. First, lets compute the minimum and maximum of our values.</p>
<pre><code>mn = min(self.key_dict.values())
mx = max(self.key_dict.values())
</code></pre>
<p>Now create some bins for plotting that equally divide these:</p>
<pr... | 0 | 2016-07-25T13:01:23Z | [
"python",
"dictionary",
"max",
"min",
"epoch"
] |
Pandas: transpose dataframe | 38,568,197 | <p>I have df:</p>
<pre><code>ID url visits count_sec buys
0012ea90a6deb4eeb2924fb13e844136 aliexpress.com 3438 33067 25
0012ea90a6deb4eeb2924fb13e844136 ebay.com 9 44
001342afb153e2775649dc5ae0460605 ozon.ru 1 6
0019b08bc9bb8da21f3b8ecc945a67d3 aliexpress.com 24 2196
0019b08bc9b... | 2 | 2016-07-25T12:46:35Z | 38,568,396 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html" rel="nofollow"><code>pivot_table</code></a>, but there is missing top <code>url</code> in <code>MultiIndex</code> in columns. Also values are only random, because it is not clear which each column contain values:</p>
... | 2 | 2016-07-25T12:56:24Z | [
"python",
"pandas",
"dataframe",
"pivot-table",
"transpose"
] |
OSError: [Errno 45] Operation not supported: '/home/samuelchin' - Mac | 38,568,322 | <p><br>
I am trying to run this code: <a href="https://github.com/jkschin/svhn" rel="nofollow">https://github.com/jkschin/svhn</a> .. <br> when I run svn_train.py I get this error</p>
<pre><code>Traceback (most recent call last): File "svhn_train.py", line 93, in
<module>
tf.app.run() File "/Users/n/ana... | 0 | 2016-07-25T12:52:44Z | 38,568,509 | <p><a href="https://github.com/jkschin/svhn/blob/master/svhn_flags.py#L7" rel="nofollow">https://github.com/jkschin/svhn/blob/master/svhn_flags.py#L7</a> hardcodes the author's local home directory, which is definitely not portable. Like the README says, you need to be able to hack the code in order to get it to work.... | 0 | 2016-07-25T13:01:33Z | [
"python",
"python-2.7",
"tensorflow"
] |
Wait for python script to return 0 | 38,568,373 | <p>I'am trying to write a script that is waiting for a database to be online.
The script that checks the database connection is written in python and should be excited every 5 seconds. If the script returns 0 the main script should continue.</p>
<p>I have never written in shell, so i can only guess how to get the pyt... | 0 | 2016-07-25T12:55:23Z | 38,569,559 | <p>I have improved my Scripts, now the bash is only calling the python script and waits for it to finish, as Kristof mentioned. This is working so far, but i try to improve it further more.</p>
<pre><code>#!/usr/bin/python3
#
import psycopg2
import time
import sys
db = None
sys.stdout.write('waiting ')
while db is No... | 0 | 2016-07-25T13:49:44Z | [
"python",
"sh"
] |
Wait for python script to return 0 | 38,568,373 | <p>I'am trying to write a script that is waiting for a database to be online.
The script that checks the database connection is written in python and should be excited every 5 seconds. If the script returns 0 the main script should continue.</p>
<p>I have never written in shell, so i can only guess how to get the pyt... | 0 | 2016-07-25T12:55:23Z | 38,570,187 | <p>The shell script would simply be</p>
<pre><code>while ! python /root/psqltest.py; do
sleep 5
done
</code></pre>
<p>or the lesser known</p>
<pre><code>until python /root/psqltest.py; do
sleep 5
done
</code></pre>
| 2 | 2016-07-25T14:16:24Z | [
"python",
"sh"
] |
Code Study-New to programming | 38,568,404 | <p>i am new to programming and have been studying some code to get to know about OOP.Here is what i have understood and need help on,
1) import gym and env=gym.make('String') : This means gym is a library, and make is a class under it? Have we created an object instance?</p>
<p>I understood classes contains methods in... | -3 | 2016-07-25T12:56:49Z | 38,568,563 | <p><code>gym</code> can be a package or a module. The <code>import</code> statement doesn't tell you what <code>gym</code> is. </p>
<p>gym.make means that you are calling a method called 'make' from gym. </p>
<p><code>env</code> is then whatever <code>make('CartPole-v0')</code> returns, which may or may not be an obj... | -1 | 2016-07-25T13:03:23Z | [
"python",
"class",
"libraries"
] |
Code Study-New to programming | 38,568,404 | <p>i am new to programming and have been studying some code to get to know about OOP.Here is what i have understood and need help on,
1) import gym and env=gym.make('String') : This means gym is a library, and make is a class under it? Have we created an object instance?</p>
<p>I understood classes contains methods in... | -3 | 2016-07-25T12:56:49Z | 38,568,601 | <p>Here's the basic structure of the above program:</p>
<p><code>import</code> statements bring modules into the program. These modules contain functions. The module is able to use these functions. For example,</p>
<pre><code>import myMod as mM
mM.fooFunc()
</code></pre>
<p>imports a module <code>myMod</code> and g... | 0 | 2016-07-25T13:05:20Z | [
"python",
"class",
"libraries"
] |
Code Study-New to programming | 38,568,404 | <p>i am new to programming and have been studying some code to get to know about OOP.Here is what i have understood and need help on,
1) import gym and env=gym.make('String') : This means gym is a library, and make is a class under it? Have we created an object instance?</p>
<p>I understood classes contains methods in... | -3 | 2016-07-25T12:56:49Z | 38,568,831 | <p><code>gym</code>can be a package or module. There is no way to tell what it is by its import statement.</p>
<p><code>env = gym.make('CartPole-v0')</code> can either assign the return value of the call of function <code>make</code> from <code>gym</code> to variable <code>env</code>, or create an item of class <code>... | 0 | 2016-07-25T13:16:14Z | [
"python",
"class",
"libraries"
] |
Code Study-New to programming | 38,568,404 | <p>i am new to programming and have been studying some code to get to know about OOP.Here is what i have understood and need help on,
1) import gym and env=gym.make('String') : This means gym is a library, and make is a class under it? Have we created an object instance?</p>
<p>I understood classes contains methods in... | -3 | 2016-07-25T12:56:49Z | 38,569,159 | <p>gym.make('CartPole-v0') returns an object.</p>
<p>Therefore, <strong>'env'</strong> is an <strong>object</strong>.</p>
<p>'env' contains a property, <strong>'monitor'</strong>, which is also an <strong>object</strong>. </p>
<p>The <strong>'start'</strong> method is a method of the <strong>'monitor' object</strong... | 0 | 2016-07-25T13:31:25Z | [
"python",
"class",
"libraries"
] |
How to get column types of an existing, named table from SQLAlchemy | 38,568,412 | <p>How can I represent this query in SQLAlchemy?</p>
<pre><code>SELECT COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'foo'
</code></pre>
| 0 | 2016-07-25T12:57:08Z | 38,570,148 | <p>Mb, I didn't understood you meant the database types. If it's a mapped table you can iterate columns like this:</p>
<pre><code>for c in foo.__table__.columns:
print(c.type)
</code></pre>
| 0 | 2016-07-25T14:15:02Z | [
"python",
"orm",
"sqlalchemy"
] |
get the subplot from pick event with matplotlib and python | 38,568,646 | <p>I have a figure with four subplots, two of which are binded on a pick event, by doing <code>canvas.mpl_connect('pick_event', onpick)</code> where onpick is onpick(event) handler.</p>
<p>Now, based on which of the two suplot the click come in, I must activate a different behaviour (ie if pick come from 1st subplot d... | 0 | 2016-07-25T13:07:13Z | 38,570,307 | <p>Here is a short example:</p>
<pre><code>import matplotlib.pyplot as plt
from random import random
def onpick(event):
if event.artist == plt1:
print("Picked on top plot")
elif event.artist == plt2:
print("Picked on bottom plot")
first = [random()*i for i in range(10)]
second = [random()*i f... | 1 | 2016-07-25T14:21:33Z | [
"python",
"matplotlib"
] |
Tensorflow: why is zip() function used in the steps involving applying the gradients? | 38,568,673 | <p>I am working through Assignment 6 of the Udacity Deep Learning course. I am unsure why the zip() function is used in these steps to apply the gradients. </p>
<p>Here is the relevant code: </p>
<pre><code># define the loss function
logits = tf.nn.xw_plus_b(tf.concat(0, outputs), w, b)
loss = tf.reduce_mean(tf.nn.s... | 1 | 2016-07-25T13:08:49Z | 38,568,886 | <p>I don't know Tensorflow, but presumably <code>optimizer.compute_gradients(loss)</code> yields (gradient, value) tuples.</p>
<pre><code>gradients, v = zip(*optimizer.compute_gradients(loss))
</code></pre>
<p>performs a <em>transposition</em>, creating a list of gradients and a list of values.</p>
<pre><code>gradie... | 1 | 2016-07-25T13:19:10Z | [
"python",
"machine-learning",
"tensorflow",
"deep-learning"
] |
remove none value on a dict in python won't work | 38,568,687 | <p>I want to modify my mongo DB collection data with removing the <code>None</code> value. I have a nested dict.</p>
<p>I did a query to get all the db on my db:</p>
<pre><code>doc = db.events.find()
for document in doc:
print document
</code></pre>
<p>One printed document looks like this:</p>
<pre><code>{ u'_... | -1 | 2016-07-25T13:09:21Z | 38,568,751 | <p>In your example, the parentheses are missing when you call <code>replace_none_values</code></p>
<p>use:</p>
<pre><code>replace_none_values()
</code></pre>
<p>instead of:</p>
<pre><code>replace_none_values
</code></pre>
| 0 | 2016-07-25T13:12:44Z | [
"python",
"mongodb",
"list",
"dictionary",
"nonetype"
] |
remove none value on a dict in python won't work | 38,568,687 | <p>I want to modify my mongo DB collection data with removing the <code>None</code> value. I have a nested dict.</p>
<p>I did a query to get all the db on my db:</p>
<pre><code>doc = db.events.find()
for document in doc:
print document
</code></pre>
<p>One printed document looks like this:</p>
<pre><code>{ u'_... | -1 | 2016-07-25T13:09:21Z | 38,568,777 | <p>Use the <code>items</code> method again since what you have is a <em>nested dictionary</em>. And note that the values in the dictionary are not the constant <code>None</code>, but string <code>'None'</code> so <code>if value1 is None</code> isn't going to do what you intend:</p>
<pre><code>for key1, value1 in event... | 0 | 2016-07-25T13:13:32Z | [
"python",
"mongodb",
"list",
"dictionary",
"nonetype"
] |
How to solve a equation of the form (A'A - yBB')x = 0 with numpy | 38,568,699 | <p>Using numpy if I had a system of equations: </p>
<pre><code>3x + 2y = 5
1x + 4y = 10
</code></pre>
<p>I could solve them with <code>numpy.linalg.solve</code>: </p>
<pre><code>a = [[3,2],[1,4]]
b = [5,10]
solution = numpy.linalg.solve(a,b)
</code></pre>
<p>Now, what if I had two matrices, A and B each of shape (1... | 1 | 2016-07-25T13:09:56Z | 38,568,913 | <p>This specific equation has an analytical solution:</p>
<ol>
<li>either <code>x</code> is 0 and <code>y</code> can be anything</li>
</ol>
<p>either</p>
<ol start="2">
<li><code>x</code> can be anything and then <code>A'A - yBB' = 0</code> which <strong>can</strong> be linear and solved using <code>numpy.linalg.sol... | 1 | 2016-07-25T13:20:23Z | [
"python",
"numpy",
"scipy"
] |
How to solve a equation of the form (A'A - yBB')x = 0 with numpy | 38,568,699 | <p>Using numpy if I had a system of equations: </p>
<pre><code>3x + 2y = 5
1x + 4y = 10
</code></pre>
<p>I could solve them with <code>numpy.linalg.solve</code>: </p>
<pre><code>a = [[3,2],[1,4]]
b = [5,10]
solution = numpy.linalg.solve(a,b)
</code></pre>
<p>Now, what if I had two matrices, A and B each of shape (1... | 1 | 2016-07-25T13:09:56Z | 38,574,409 | <p>This looks like you are trying to solve the <a href="https://en.wikipedia.org/wiki/Eigendecomposition_of_a_matrix#Generalized_eigenvalue_problem" rel="nofollow">generalized eigenvalue problem</a>, with <code>y</code> being the unknown generalized eigenvalue λ and <code>x</code> being the corresponding generalized e... | 3 | 2016-07-25T17:53:19Z | [
"python",
"numpy",
"scipy"
] |
lambda unexpected results | 38,568,796 | <p>I have the following simple python code</p>
<pre><code>numbers = range(1,100)
print (list(numbers))
numbers_over_30 = filter(lambda x: x>>30,numbers)
print (list(numbers_over_30))
</code></pre>
<p>I create a list of numbers from 1 to 99 and that works fine giving me</p>
<pre><code>[1,2,3,4,5.....97,98,99]
<... | -1 | 2016-07-25T13:14:36Z | 38,569,043 | <p>You need just to delete one >, so your code will be : </p>
<pre><code>numbers = range(1,100)
print (list(numbers))
numbers_over_30 = filter(lambda x: x>30,numbers) # here your error
print (list(numbers_over_30))
</code></pre>
| 0 | 2016-07-25T13:26:13Z | [
"python",
"lambda"
] |
Python open html file, take screenshot, crop and save as image | 38,568,804 | <p>I am using the Bokeh package to generate maps to show the results of a simulation. The output is individual maps in html format with interactivity. The interactivity is needed for individual maps. </p>
<p>See this link for an example:</p>
<p><a href="http://bokeh.pydata.org/en/0.10.0/docs/gallery/texas.html" rel=... | 1 | 2016-07-25T13:14:58Z | 38,569,146 | <p>If you're running Linux, you may have to do the following steps. </p>
<p>First open the html file via <a href="http://askubuntu.com/questions/15354/how-to-open-file-with-default-application-from-command-line">command line</a> in the default app. You'll probably have to do something like</p>
<pre><code>import os
o... | 0 | 2016-07-25T13:31:04Z | [
"python",
"html",
"selenium",
"bokeh"
] |
Python open html file, take screenshot, crop and save as image | 38,568,804 | <p>I am using the Bokeh package to generate maps to show the results of a simulation. The output is individual maps in html format with interactivity. The interactivity is needed for individual maps. </p>
<p>See this link for an example:</p>
<p><a href="http://bokeh.pydata.org/en/0.10.0/docs/gallery/texas.html" rel=... | 1 | 2016-07-25T13:14:58Z | 38,569,320 | <p>You can use <a href="https://docs.python.org/2/library/simplehttpserver.html" rel="nofollow" title="SimpleHTTPServer">SimpleHTTPServer</a> to create a basic webserver and expose your local file. </p>
<p>You should run this in the path where is the htmt <code>python -m SimpleHTTPServer 8000
</code></p>
<p>Then just... | 1 | 2016-07-25T13:39:10Z | [
"python",
"html",
"selenium",
"bokeh"
] |
Python open html file, take screenshot, crop and save as image | 38,568,804 | <p>I am using the Bokeh package to generate maps to show the results of a simulation. The output is individual maps in html format with interactivity. The interactivity is needed for individual maps. </p>
<p>See this link for an example:</p>
<p><a href="http://bokeh.pydata.org/en/0.10.0/docs/gallery/texas.html" rel=... | 1 | 2016-07-25T13:14:58Z | 38,585,327 | <p>hgazibara comment proved to be the simplest fix. Some simplified code is below to provide the answer. It would be nice if the web page didn't actually have to show itself for the screen shot to be taken. I will see if I can add this later.</p>
<pre><code>import glob
from PIL import Image
from selenium import webdri... | 0 | 2016-07-26T08:57:06Z | [
"python",
"html",
"selenium",
"bokeh"
] |
Different models in one view | 38,568,899 | <p>Hi I am very new in django. I wonder if I could user different models in one view.
So I looked this page <a href="https://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newforms/" rel="nofollow">https://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newform... | 0 | 2016-07-25T13:19:41Z | 38,569,161 | <p>You've sent two variables to your template, with the keys <code>UserRegisterForm</code> and <code>ContactForm</code>. You have to use those names in your template, not just <code>form</code>.</p>
| 0 | 2016-07-25T13:31:27Z | [
"python",
"django"
] |
Different models in one view | 38,568,899 | <p>Hi I am very new in django. I wonder if I could user different models in one view.
So I looked this page <a href="https://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newforms/" rel="nofollow">https://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newform... | 0 | 2016-07-25T13:19:41Z | 38,569,205 | <p>You are using the variable <code>form</code> in your template, but you are passing <code>UserRegisterForm</code> and <code>ContactForm</code> as template context.</p>
<p>Try something like:</p>
<pre><code><form...>
{{ UserRegisterForm }}
{% for form in ContactForm %}
{{ form }}
{% endfor %}
</form>
</... | 1 | 2016-07-25T13:33:59Z | [
"python",
"django"
] |
Pandas: add values to dataframe | 38,568,931 | <p>I have df</p>
<pre><code>ID,"url","used_at","active_seconds"
9e871f65d402254b15470881c79cec94,"mvideo.ru/smartfony-sotovye-telefony/smartfony-205",2016-04-01 00:00:00,10
8fe968e88d209b2854c47f812211cd2d,"group.aliexpress.com/ruNew.htm?spm=2114.7749990.120000116.87.rxes4x&catId=0&page=17#product-list-tab",20... | 0 | 2016-07-25T13:21:18Z | 38,572,443 | <p>You can use <code>pd.concat</code> on a list of the dfs with <code>fillna(0)</code>:</p>
<pre><code>In [68]:
new_df = pd.concat([df,df2], ignore_index=True).fillna(0)
new_df
Out[68]:
ID active_seconds \
0 9e871f65d402254b15470881c79cec94 10.0
1 8fe968e88d209b28... | 0 | 2016-07-25T15:58:11Z | [
"python",
"pandas"
] |
Why am I not getting any output in the below code? | 38,568,970 | <p>There are no errors while compiling the code. I am calling the function as: <code>pattern('abc')</code>. Expecting output as <code>'A-Bb-Ccc'</code></p>
<pre><code>def pattern(s):
v = []
v = list(s)
strlen = len(v)
i = 0
cntr = 0
strng = []
while i < strlen:
j = 0
whil... | 1 | 2016-07-25T13:23:33Z | 38,569,178 | <p><strong>UPDATE</strong> using <code>enumerate</code> instead of <code>zip</code></p>
<pre><code>source = 'abc'
'-'.join([(x*i).capitalize() for i, x in enumerate(source, 1)])
</code></pre>
<hr>
<pre><code>source = 'abc'
'-'.join([(x*i).capitalize() for x,i in zip(source, range(1, len(source)+1))])
</code></p... | 3 | 2016-07-25T13:32:40Z | [
"python",
"python-2.7"
] |
Why am I not getting any output in the below code? | 38,568,970 | <p>There are no errors while compiling the code. I am calling the function as: <code>pattern('abc')</code>. Expecting output as <code>'A-Bb-Ccc'</code></p>
<pre><code>def pattern(s):
v = []
v = list(s)
strlen = len(v)
i = 0
cntr = 0
strng = []
while i < strlen:
j = 0
whil... | 1 | 2016-07-25T13:23:33Z | 38,569,674 | <p>You have no print statement. To test it, fill in </p>
<p><code>print(z)</code>. </p>
<p>Also you have to put the return outside of the while loop. </p>
| 1 | 2016-07-25T13:54:48Z | [
"python",
"python-2.7"
] |
Why am I not getting any output in the below code? | 38,568,970 | <p>There are no errors while compiling the code. I am calling the function as: <code>pattern('abc')</code>. Expecting output as <code>'A-Bb-Ccc'</code></p>
<pre><code>def pattern(s):
v = []
v = list(s)
strlen = len(v)
i = 0
cntr = 0
strng = []
while i < strlen:
j = 0
whil... | 1 | 2016-07-25T13:23:33Z | 38,570,774 | <p>Well first, you need to indent <code>return z</code> so it is not in any of the loops:</p>
<pre><code>def pattern(s):
#Rest of the code
return z
</code></pre>
<p>Then you need to assign the result of the function to a variable and print it:</p>
<pre><code>result = pattern('abc')
print result
</code></pre>... | 0 | 2016-07-25T14:42:10Z | [
"python",
"python-2.7"
] |
Why am I not getting any output in the below code? | 38,568,970 | <p>There are no errors while compiling the code. I am calling the function as: <code>pattern('abc')</code>. Expecting output as <code>'A-Bb-Ccc'</code></p>
<pre><code>def pattern(s):
v = []
v = list(s)
strlen = len(v)
i = 0
cntr = 0
strng = []
while i < strlen:
j = 0
whil... | 1 | 2016-07-25T13:23:33Z | 38,570,942 | <p>You have an infinite loop. You need to have <code>j</code> increment in the inner <code>while</code> loop or <code>j</code> will always be less then <code>i</code> if you call <code>print(pattern("abc"))</code> after you fix the indentation it should return what you are looking for.</p>
<p>TL;DR, add an indent befo... | 0 | 2016-07-25T14:49:39Z | [
"python",
"python-2.7"
] |
Install dependencies based on condition | 38,568,971 | <p>I am using Travis-ci.org as continuous integration server developing some Python packages. I would like to install project dependencies from PyPi server conditionally. Builds from master branch should install dependencies from the real PyPI server while builds from other branches should install dependencies from Tes... | 1 | 2016-07-25T13:23:35Z | 38,570,862 | <p>The problem was with the execution of the Bash script from the .travis.yml.
It needs to be executed like this:</p>
<pre><code>bash ./install_dependencies.sh
</code></pre>
<p>Below file works fine:</p>
<p><strong>.travis.yml</strong></p>
<pre><code>language: python
python:
- "2.7"
install:
- bash ./inst... | 0 | 2016-07-25T14:45:56Z | [
"python",
"bash",
"continuous-integration",
"containers",
"travis-ci"
] |
Trouble piping output from python script | 38,568,995 | <p>I am having trouble getting the output from a python script, that I didn't write, redirected to grep. Below are my experiments including the base cases. "myPythonCmd" is long running and streams to stdout.</p>
<p>Any suggestions?</p>
<hr>
<pre><code>/myPythonCmd.py arg1 arg2
</code></pre>
<p>Outputs both stderr ... | 0 | 2016-07-25T13:24:27Z | 38,569,397 | <p>python's -u option is what was needed. Thanks @PM_2Ring</p>
<pre><code>python -u myPythonCmd.py arg1 arg2 2>/dev/null | grep searchTerm
</code></pre>
| 0 | 2016-07-25T13:42:47Z | [
"python",
"unix",
"grep",
"pipe",
"command-line-interface"
] |
How do I invert key and value in RDD in Python 3 pyspark? | 38,569,052 | <p>This works in Python 2.7, but in Python 3.5 it returns</p>
<blockquote>
<p>SyntaxError: invalid syntax.</p>
</blockquote>
<p>I'm not sure if this has to do with the fact that "tuple unpacking" was removed from Python 3, as I read on another post, or is a different issue. </p>
<pre><code>rddInverted = rdd.map(l... | 0 | 2016-07-25T13:26:47Z | 38,569,339 | <p>Try something like this:</p>
<pre><code>rddInverted = rdd.map(lambda x: (x[1], x[0]))
</code></pre>
<p>I hope it will work</p>
| 1 | 2016-07-25T13:40:10Z | [
"python",
"python-3.x",
"rdd",
"invert"
] |
How do I invert key and value in RDD in Python 3 pyspark? | 38,569,052 | <p>This works in Python 2.7, but in Python 3.5 it returns</p>
<blockquote>
<p>SyntaxError: invalid syntax.</p>
</blockquote>
<p>I'm not sure if this has to do with the fact that "tuple unpacking" was removed from Python 3, as I read on another post, or is a different issue. </p>
<pre><code>rddInverted = rdd.map(l... | 0 | 2016-07-25T13:26:47Z | 38,569,361 | <p>Your lambda function is on the row of the RDD, which is a tuple. Below is what you want.</p>
<pre><code>rddInverted = rdd.map(lambda x: (x[1],x[0]))
</code></pre>
| 1 | 2016-07-25T13:41:04Z | [
"python",
"python-3.x",
"rdd",
"invert"
] |
How do I invert key and value in RDD in Python 3 pyspark? | 38,569,052 | <p>This works in Python 2.7, but in Python 3.5 it returns</p>
<blockquote>
<p>SyntaxError: invalid syntax.</p>
</blockquote>
<p>I'm not sure if this has to do with the fact that "tuple unpacking" was removed from Python 3, as I read on another post, or is a different issue. </p>
<pre><code>rddInverted = rdd.map(l... | 0 | 2016-07-25T13:26:47Z | 38,570,437 | <p>The solution is: </p>
<pre><code>rddInverted=rdd.map(lambda xy: (xy[1],xy[0]))
</code></pre>
| 0 | 2016-07-25T14:27:37Z | [
"python",
"python-3.x",
"rdd",
"invert"
] |
Module urllib.request not getting data | 38,569,115 | <p>I am trying to test this demo program from lynda using Python 3. I am using Pycharm as my IDE. I already added and installed the request package, but when I run the program, it runs cleanly and shows a message "Process finished with exit code 0", but does not show any output from print statement. Where am I going wr... | 0 | 2016-07-25T13:29:53Z | 38,569,784 | <p>Not sure if you left this out on purpose, but this script isn't actually executing any code beyond the imports and function definition. Assuming you didn't leave it out on purpose, you would need the following at the end of your file.</p>
<pre><code>if __name__ == '__main__':
data = "" # your data
printResu... | 0 | 2016-07-25T13:59:53Z | [
"python",
"pycharm",
"urllib2",
"urllib",
"python-3.5"
] |
Module urllib.request not getting data | 38,569,115 | <p>I am trying to test this demo program from lynda using Python 3. I am using Pycharm as my IDE. I already added and installed the request package, but when I run the program, it runs cleanly and shows a message "Process finished with exit code 0", but does not show any output from print statement. Where am I going wr... | 0 | 2016-07-25T13:29:53Z | 38,570,114 | <p>I had to restart the IDE after installing the module. I just realized and tried it now with "Run as Admin". Strangely seems to work now.But not sure if it was a temp error, since even without restart, it was able to detect the module and its methods. </p>
| 0 | 2016-07-25T14:13:23Z | [
"python",
"pycharm",
"urllib2",
"urllib",
"python-3.5"
] |
Module urllib.request not getting data | 38,569,115 | <p>I am trying to test this demo program from lynda using Python 3. I am using Pycharm as my IDE. I already added and installed the request package, but when I run the program, it runs cleanly and shows a message "Process finished with exit code 0", but does not show any output from print statement. Where am I going wr... | 0 | 2016-07-25T13:29:53Z | 38,570,302 | <p>Your comments re: having to restart your IDE makes me think that pycharm might not automatically detect newly installed python packages. This SO answer seems to offer a solution.</p>
<p><a href="http://stackoverflow.com/a/26069398/3264217">SO answer</a></p>
| 0 | 2016-07-25T14:21:11Z | [
"python",
"pycharm",
"urllib2",
"urllib",
"python-3.5"
] |
Access a function present in C# dll using Python | 38,569,185 | <p>I want to access a function <strong>my_function()</strong> present in a c# file which is compiled into a .net dll - <strong>abc.dll</strong>. </p>
<p><strong>C# file</strong></p>
<pre><code> using System;
using System.Collections.Generic;
using System.Linq;
using Syst... | -1 | 2016-07-25T13:33:08Z | 38,569,699 | <p>You haven't made the function visible in the DLL.</p>
<p>There are a few different ways you can do this. The easiest is probably to use the <a href="https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports" rel="nofollow">unmanagedexports</a> package. It allows you to call C# functions directly ... | 1 | 2016-07-25T13:55:48Z | [
"c#",
"python",
".net",
"ctypes",
"dllimport"
] |
Can't access functions in Excel.Application().Workbooks from Python 2.7/3.5: '__ComObject' object has no attribute X | 38,569,229 | <p>I am trying to use Microsoft.Office.Interop.Excel from a Python script:</p>
<pre><code>import msvcrt
import clr
clr.AddReference("Microsoft.Office.Interop.Excel")
import Microsoft.Office.Interop.Excel as Excel
excel = Excel.ApplicationClass()
excel.Visible = True # makes the Excel application visible to... | 1 | 2016-07-25T13:34:49Z | 39,046,725 | <p>You can only get to COM objects from pythonnet using reflection currently:</p>
<pre><code>clr.AddReference("System.Reflection")
from System.Reflection import BindingFlags
excel.Workbooks.GetType().InvokeMember("Count",
BindingFlags.GetProperty |
... | 0 | 2016-08-19T19:50:53Z | [
"python",
".net",
"excel",
"interop",
"python.net"
] |
List of sub-strings search returns multiple conditions at once | 38,569,291 | <p>I have a large list of sub-strings that I want to search through and find if two particular sub-strings can be found in a row. The logic is intended to look for the first sequence, then if it is found, look at the second sub-string and return all the matches (based off the first 15 characters of the 16 character seq... | 0 | 2016-07-25T13:37:46Z | 38,569,695 | <p>Your code confuses me. But I think I understand your issue:</p>
<pre><code>#!/usr/env/env python
dataA = ['0100101010001000',
'1001010100010001',
'0010101000100010',
'0101010001000110',
'1010100010001110',
'0101000100011100',
'1010001000111010',
'0100010001110100',
'1000100011101000',
'0001000111010000']
A_vein_1... | 0 | 2016-07-25T13:55:38Z | [
"python",
"list",
"if-statement",
"for-loop",
"substring"
] |
List of sub-strings search returns multiple conditions at once | 38,569,291 | <p>I have a large list of sub-strings that I want to search through and find if two particular sub-strings can be found in a row. The logic is intended to look for the first sequence, then if it is found, look at the second sub-string and return all the matches (based off the first 15 characters of the 16 character seq... | 0 | 2016-07-25T13:37:46Z | 38,569,934 | <p>Input :</p>
<pre><code>dataA = ['0100101010001000',
'1001010100010001',
'0010101000100010',
'0101010001000110',
'1010100010001110',
'0101000100011100',
'1010001000111010',
'0100010001110100',
'1000100011101000',
'0001000111010000']
A_vein_1 = [0,1,0,0,1,0,1,0,1,0,0,0,1,0,0,0]
A_vein_2 = [1,0,0,1,0,1,0,1,0,0,0,1,0,0... | 0 | 2016-07-25T14:06:39Z | [
"python",
"list",
"if-statement",
"for-loop",
"substring"
] |
Read Value from a list in another list | 38,569,350 | <p>i'd like to know how to read out values from a list like that:</p>
<pre><code>fragen = [["Frage?",{"ValueOne": 1, "ValueTwo": 0, "ValueThree": 0, "ValueFour": 5}]]
</code></pre>
<p>i'm a complete beginner in python, any help would be kind.</p>
<p>Originally, it looked like that:</p>
<pre><code>fragen = []
frage... | 0 | 2016-07-25T13:40:36Z | 38,569,418 | <p><code>fragen</code> is a list of lists. The inner list happen to contain a string and a dictionary.</p>
<p><code>fragen[0]</code> returns the inner list, ie <code>["Frage?",{"ValueOne": 1, "ValueTwo": 0, "ValueThree": 0, "ValueFour": 5}]</code>.</p>
<p><code>fragen[0][1]</code> returns the dictionary, ie <code>{"V... | 4 | 2016-07-25T13:43:26Z | [
"python",
"list",
"multidimensional-array",
"value"
] |
Read Value from a list in another list | 38,569,350 | <p>i'd like to know how to read out values from a list like that:</p>
<pre><code>fragen = [["Frage?",{"ValueOne": 1, "ValueTwo": 0, "ValueThree": 0, "ValueFour": 5}]]
</code></pre>
<p>i'm a complete beginner in python, any help would be kind.</p>
<p>Originally, it looked like that:</p>
<pre><code>fragen = []
frage... | 0 | 2016-07-25T13:40:36Z | 38,569,447 | <p>The list contains string and <a href="http://learnpythonthehardway.org/book/ex39.html" rel="nofollow">dictionary</a> data types.</p>
<p>You want to try using</p>
<p><code>fragen[0][1]['ValueOne']</code> to print 1. </p>
<p>This is how you access dictionaries in Python.</p>
| 0 | 2016-07-25T13:44:35Z | [
"python",
"list",
"multidimensional-array",
"value"
] |
Read Value from a list in another list | 38,569,350 | <p>i'd like to know how to read out values from a list like that:</p>
<pre><code>fragen = [["Frage?",{"ValueOne": 1, "ValueTwo": 0, "ValueThree": 0, "ValueFour": 5}]]
</code></pre>
<p>i'm a complete beginner in python, any help would be kind.</p>
<p>Originally, it looked like that:</p>
<pre><code>fragen = []
frage... | 0 | 2016-07-25T13:40:36Z | 38,592,467 | <p>@DeepSpace has already answered your question . but for future reference and easier access for multidimensional arrays</p>
<p>you could use </p>
<pre><code>import numpy
fragen=numpy.ndarray((x,y,z,..))
</code></pre>
<p>x,y,z are dimensions of your n dimensional array</p>
| 0 | 2016-07-26T14:21:24Z | [
"python",
"list",
"multidimensional-array",
"value"
] |
Using Crontab in a Python Script | 38,569,365 | <p>I am trying to use the contents of a crontab inside a python script. I want to do everything using python. In the end I hope to take the contents of the crontab, convert it to a temporary textfile, read in the lines of the text file and manipulate it.</p>
<p>Is there any way i can use the contents of the crontab fi... | 0 | 2016-07-25T13:41:09Z | 38,569,423 | <p>If you were to try <code>crontab -h</code>, which is usually the help option, you'll get this:</p>
<pre><code>$ crontab -h
crontab: invalid option -- 'h'
crontab: usage error: unrecognized option
Usage:
crontab [options] file
crontab [options]
crontab -n [hostname]
Options:
-u <user> define user
-e ... | 2 | 2016-07-25T13:43:47Z | [
"python",
"subprocess",
"crontab"
] |
Type hint for a file or file-like object? | 38,569,401 | <p>Is there any correct type hint to use for a file or file-like object in Python? For example, how would I type-hint the return value of this function?</p>
<pre><code>def foo():
return open('bar')
</code></pre>
| 2 | 2016-07-25T13:42:50Z | 38,569,536 | <p>Use either the <code>typing.TextIO</code> or <code>typing.BinaryIO</code> types, for files opened in text mode or binary mode respectively.</p>
<p>From <a href="https://docs.python.org/3/library/typing.html#typing.io" rel="nofollow">the docs</a>:</p>
<blockquote>
<h3><em>class</em> <code>typing.io</code></h3>
... | 4 | 2016-07-25T13:48:47Z | [
"python"
] |
Named string format arguments in Python | 38,569,579 | <p>I am using Python 2.x, and trying to understand the logic of string formatting using named arguments. I understand:</p>
<p><code>"{} and {}".format(10, 20)</code> prints <code>'10 and 20'</code>.</p>
<p>In like manner <code>'{name} and {state}'.format(name='X', state='Y')</code> prints <code>X and Y</code></p>
<p... | 4 | 2016-07-25T13:50:42Z | 38,569,648 | <p><a href="https://docs.python.org/2/library/stdtypes.html#str.format"><code>format</code></a> doesn't alter the string you call it on; it returns a new string. If you do</p>
<pre><code>my_string = "Hi! My name is {name}. I live in {state}"
new_string = my_string.format(name='Xi', state='Xo')
print(new_string)
</code... | 6 | 2016-07-25T13:53:34Z | [
"python",
"python-2.7"
] |
How do I print out just the values of keys in a dictionary? | 38,569,603 | <p>I'm trying to create a function that prints out just the value of the key given in the parameter. But it isn't quite doing what I want it to do. Please have a look at my code and see where I'm wrong? Thanks</p>
<pre><code>list = {
"David": 42,
"John": 11,
"Jack": 278
}
def get_marks(student_name):
... | -2 | 2016-07-25T13:51:42Z | 38,569,638 | <p>You are trying this:</p>
<pre><code>def get_marks(student_name):
print(list.get(student_name))
</code></pre>
| 0 | 2016-07-25T13:53:14Z | [
"python"
] |
How do I print out just the values of keys in a dictionary? | 38,569,603 | <p>I'm trying to create a function that prints out just the value of the key given in the parameter. But it isn't quite doing what I want it to do. Please have a look at my code and see where I'm wrong? Thanks</p>
<pre><code>list = {
"David": 42,
"John": 11,
"Jack": 278
}
def get_marks(student_name):
... | -2 | 2016-07-25T13:51:42Z | 38,569,641 | <p>You can access the value at a key using <code>my_dict[student_name]</code> but using the <code>get</code> method of the dictionary is much safer as it returns <code>None</code> when the key is not found:</p>
<pre><code>def get_marks(student_name):
print my_dict.get(student_name)
</code></pre>
<p>I have rename... | 0 | 2016-07-25T13:53:20Z | [
"python"
] |
How do I print out just the values of keys in a dictionary? | 38,569,603 | <p>I'm trying to create a function that prints out just the value of the key given in the parameter. But it isn't quite doing what I want it to do. Please have a look at my code and see where I'm wrong? Thanks</p>
<pre><code>list = {
"David": 42,
"John": 11,
"Jack": 278
}
def get_marks(student_name):
... | -2 | 2016-07-25T13:51:42Z | 38,569,696 | <pre><code>list = {
"David": 42,
"John": 11,
"Jack": 278
}
def get_marks(student_name):
print list[student_name]
get_marks("David")
</code></pre>
| 0 | 2016-07-25T13:55:40Z | [
"python"
] |
How do I print out just the values of keys in a dictionary? | 38,569,603 | <p>I'm trying to create a function that prints out just the value of the key given in the parameter. But it isn't quite doing what I want it to do. Please have a look at my code and see where I'm wrong? Thanks</p>
<pre><code>list = {
"David": 42,
"John": 11,
"Jack": 278
}
def get_marks(student_name):
... | -2 | 2016-07-25T13:51:42Z | 38,569,817 | <p>You can either use the <a href="http://www.tutorialspoint.com/python/dictionary_get.htm" rel="nofollow">get()</a> method of the dictionary like so:</p>
<pre><code>def get_marks(student_name):
return list.get(student_name)
</code></pre>
<p>or you can just use <a href="https://docs.python.org/3/tutorial/datastru... | 0 | 2016-07-25T14:01:03Z | [
"python"
] |
Can't connect MongoDb on AWS EC2 using python | 38,569,626 | <p>I have installed Mongodb 3.0 using this tutorial -</p>
<p><a href="https://docs.mongodb.com/v3.0/tutorial/install-mongodb-on-amazon/" rel="nofollow">https://docs.mongodb.com/v3.0/tutorial/install-mongodb-on-amazon/</a></p>
<p>It has installed fine. I have also given permissions to 'ec2-user' to all the data and lo... | 1 | 2016-07-25T13:52:59Z | 38,569,890 | <p>When you run <code>sudo mongod</code> it does not load a config file at all, it literally starts with the compiled in defaults - port <a href="https://docs.mongodb.org/manual/reference/configuration-options/#net.port" rel="nofollow">27017</a>, <a href="https://docs.mongodb.org/manual/reference/configuration-options/... | 1 | 2016-07-25T14:04:16Z | [
"python",
"mongodb",
"amazon-web-services",
"amazon-ec2"
] |
How to read in sequence of images as 3d tensor? | 38,569,663 | <p>As an input to a CNN I am working on, I want to use a sequence of images (with 3D convolution in the conv layers).</p>
<p>However, I already fail in reading in the images as a 3D tensor that I can use for the computation.</p>
<p>Here is my primitive attempt:</p>
<pre><code>def get_sequence_as_tensor(folder):
... | 0 | 2016-07-25T13:54:20Z | 38,573,206 | <p>I would recommend combining the images into a numpy array outside of tensorflow and then passing them in to a placeholder.</p>
<p>Something like this should work.</p>
<pre><code>filename = tf.placeholder("string")
png_string = tf.read_file(filename)
img = tf.image.decode_png(png_string)
img_float = tf.cast(img, tf... | 0 | 2016-07-25T16:38:11Z | [
"python",
"tensorflow"
] |
django-debug-toolbar: 'Template' object has no attribute 'engine' | 38,569,760 | <p>I've just tried running an existing Django project on a new computer, and I'm having trouble with django-debug-toolbar. It seems to be something to do with Jinja2. Here's the stack trace:</p>
<pre><code>Traceback:
File "/path/to/myrepo/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_respo... | 1 | 2016-07-25T13:58:57Z | 39,036,820 | <p>I get this too, you can hack it fixed based on your suggestion without hacking core by supplying your own panel class:</p>
<p><strong>debug.py</strong></p>
<pre><code>from debug_toolbar.panels.templates import TemplatesPanel as BaseTemplatesPanel
class TemplatesPanel(BaseTemplatesPanel):
def generate_stats(se... | 1 | 2016-08-19T10:33:01Z | [
"python",
"django",
"templates",
"django-debug-toolbar"
] |
Handling Timeout Error(python) | 38,569,771 | <pre><code>import multiprocessing.pool
import functools
import time
import sys
def timeout(max_timeout):
def timeout_decorator(item):
@functools.wraps(item)
def func_wrapper(*args, **kwargs):
pool = multiprocessing.pool.ThreadPool(processes=1)
async_result = pool.apply_async(... | 0 | 2016-07-25T13:59:23Z | 38,569,988 | <p>You can wrap an error, using a try/except :</p>
<pre><code>try:
do_something_that_can_raise_error_X()
except X:
do_something_when_error_X_is_raised()
</code></pre>
| 0 | 2016-07-25T14:08:42Z | [
"python"
] |
Handling Timeout Error(python) | 38,569,771 | <pre><code>import multiprocessing.pool
import functools
import time
import sys
def timeout(max_timeout):
def timeout_decorator(item):
@functools.wraps(item)
def func_wrapper(*args, **kwargs):
pool = multiprocessing.pool.ThreadPool(processes=1)
async_result = pool.apply_async(... | 0 | 2016-07-25T13:59:23Z | 38,570,674 | <p>You need to wrap the code that might raise this exception in "try" and then except the exception that you expect.</p>
<pre><code>from multiprocessing import TimeoutError
try:
# actions that raise TimeoutError
except TimeoutError:
# handle TimeoutError
else:
# (optional) actions for when there is no Tim... | 0 | 2016-07-25T14:37:46Z | [
"python"
] |
executing OS commands from python using modules | 38,569,772 | <p>I want to run a python script that can execute OS (linux) commands , I got few modules that helps me in doing that like os, subprocess . In OS module am not able to redirect the output to a variable . In subprocess.popen am not able to use variable in the arguments. Need someone help in finding the alternative . </p... | 0 | 2016-07-25T13:59:24Z | 38,569,963 | <p>You can use the <code>subprocess</code> method <code>check_output</code></p>
<pre><code>import subprocess
output = subprocess.check_output("your command", shell=True)
</code></pre>
<p>see previously answered SO question here for more info: <a href="http://stackoverflow.com/a/8659333/3264217">http://stackoverflow.c... | 0 | 2016-07-25T14:07:42Z | [
"python",
"scripting"
] |
executing OS commands from python using modules | 38,569,772 | <p>I want to run a python script that can execute OS (linux) commands , I got few modules that helps me in doing that like os, subprocess . In OS module am not able to redirect the output to a variable . In subprocess.popen am not able to use variable in the arguments. Need someone help in finding the alternative . </p... | 0 | 2016-07-25T13:59:24Z | 38,570,460 | <p>Use either subprocess or pexpect depending on what is your exact use case.</p>
<p>subprocess can do what os.system does and much more. If you need to start some command, wait for it to exit and then get the output, subprocess can do it:</p>
<pre><code>import subprocess
res = subprocess.check_output('ls -l')
</code... | 0 | 2016-07-25T14:28:38Z | [
"python",
"scripting"
] |
How to run maven command in a python script in Windows | 38,569,785 | <p>How do I write a maven command in python? I saw this example online, but it doesn't seem to be working in Windows.</p>
<pre><code>def local2(command, print_command=False):
from subprocess import Popen, PIPE
p = Popen(command, stdout=PIPE, stderr=PIPE)
if print_command: print " ".join(command)
output... | -1 | 2016-07-25T13:59:55Z | 38,569,836 | <p>I prefer to use fabric (<a href="http://www.fabfile.org/" rel="nofollow">http://www.fabfile.org/</a>):</p>
<pre><code>from fabric import local
def maven_start():
local('<cmd>')
$ fab maven_start
</code></pre>
| 0 | 2016-07-25T14:02:01Z | [
"python",
"windows",
"maven"
] |
Initial node's ids when creating graph from edge list | 38,569,831 | <p>I wonder, where does the function <a href="http://igraph.org/python/doc/igraph.GraphBase-class.html#Read_Edgelist">Read_Edgelist</a> store the original id's from the the edge list? or under which attribute name? </p>
<p>Assume that I am reading an edge list like:</p>
<pre><code>1 2
2 1
1 3
</code></pre>
<p>where... | 6 | 2016-07-25T14:01:46Z | 39,524,908 | <p><a href="http://igraph.org/python/doc/igraph.GraphBase-class.html#Read_Edgelist" rel="nofollow"><code>Read_Edgelist</code></a> assumes the node ids are the consecutive integers from 0 to m, where m is the maximum integer in the edge list. So there is "no need to store node ids."</p>
<p>For example, if your edgelis... | 1 | 2016-09-16T06:19:57Z | [
"python",
"igraph"
] |
Pandas: replace empty cell to 0 when write to file | 38,569,851 | <p>I have df and there are empty cells. I want to write it to excel and need to print there <code>0</code> instead empty. I try <code>result.fillna(0)</code> and <code>result.replace(r'\s+', np.nan, regex=True)</code> but it doesn't help.</p>
| 0 | 2016-07-25T14:02:43Z | 38,571,108 | <p>You are creating a copy of the dataframe but the original one is not keeping the changes, you need to specify "inplace=True" if you want the dataframe to persist the changes</p>
<pre><code>result.fillna(0, inplace=True)
</code></pre>
| 0 | 2016-07-25T14:56:32Z | [
"python",
"pandas"
] |
Python 3.5 tkinter: resizing widgets to window | 38,569,862 | <p>I am reading, reading and reading but still unable to find the appropriate answer to my issue. I plan to create a 'Masterwindow' in which I implement several frames (currently a Navigation Panel to the left, a 'RootFrame', which shows up, when no process is running, a Statusbar at the bottom, which is for alerts and... | 0 | 2016-07-25T14:03:18Z | 38,570,633 | <p>You are neglecting to give a weight to any rows or columns in the root window. Without it, tkinter doesn't know how to allocate extra space when you resize the window.</p>
<pre><code>def main(cls):
...
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
</code></pre>
<p>Since you... | 0 | 2016-07-25T14:35:45Z | [
"python",
"tkinter",
"resize",
"grid-layout"
] |
Authentication issue using requests on aspx site | 38,569,906 | <p>I am trying to use requests (python) to grab some pages from a website that requires me to be logged in.
I did inspect the login page to check out the username and password headers. But I found the names for those fields are not the standard 'username', 'password' used by most sites as you can see from the below scr... | -1 | 2016-07-25T14:05:15Z | 38,570,149 | <p>You need to use strings for the keys, the $ will cause a syntax error if you don't:</p>
<pre><code> data = {"ctl00$MainContent$txtPassword":password, "ctl00$MainContent$txtEmailID":email}
</code></pre>
<p>There are evenvalidation fileds etc.. to be filled in also, follow the logic from this <a href="http://stacko... | 1 | 2016-07-25T14:15:03Z | [
"python",
"authentication",
"python-requests"
] |
Detect the green lines in this image and calculate their lengths | 38,569,938 | <p><a href="http://i.stack.imgur.com/ZqHix.png" rel="nofollow"><img src="http://i.stack.imgur.com/ZqHix.png" alt="enter image description here"></a>Sample Images</p>
<p><img src="http://i.stack.imgur.com/NFEQi.png" alt=""></p>
<p>The image can be more noisy at times where more objects intervene from the background. R... | 2 | 2016-07-25T14:06:50Z | 38,601,225 | <p>You should use the fact that you know you are trying to detect a line by using the line hough transform.
<a href="http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html" rel="nofollow">http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html</a></p>
<ul>... | 0 | 2016-07-26T23:01:24Z | [
"python",
"opencv",
"image-processing",
"rgb",
"hsv"
] |
Detect the green lines in this image and calculate their lengths | 38,569,938 | <p><a href="http://i.stack.imgur.com/ZqHix.png" rel="nofollow"><img src="http://i.stack.imgur.com/ZqHix.png" alt="enter image description here"></a>Sample Images</p>
<p><img src="http://i.stack.imgur.com/NFEQi.png" alt=""></p>
<p>The image can be more noisy at times where more objects intervene from the background. R... | 2 | 2016-07-25T14:06:50Z | 38,623,769 | <p><strong>STILL IN PROGRESS</strong></p>
<p>First of all, an RGB image consists of 3 grayscale images. Since you need the green color you will deal only with one channel. The green one. To do so, you can split the image, you can use <code>b,g,r = cv2.split('Your Image')</code>. You will get an output like that if you... | 0 | 2016-07-27T21:49:06Z | [
"python",
"opencv",
"image-processing",
"rgb",
"hsv"
] |
pandas dataframe: meaning of .index | 38,569,952 | <p>I am trying to understand the meaning of the output of the following code:</p>
<pre><code>import pandas as pd
index = ['index1','index2','index3']
columns = ['col1','col2','col3']
df = pd.DataFrame([[1,2,3],[1,2,3],[1,2,3]], index=index, columns=columns)
print df.index
</code></pre>
<p>I would expect just a list ... | 0 | 2016-07-25T14:07:09Z | 38,569,986 | <p>This is the pretty output of the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.html#pandas.Index" rel="nofollow"><code>pandas.Index</code></a> object, if you look at the type it shows the class type:</p>
<pre><code>In [45]:
index = ['index1','index2','index3']
columns = ['col1','col2',... | 0 | 2016-07-25T14:08:28Z | [
"python",
"pandas",
"dataframe"
] |
Python: How does string.replace("\n", " ") behave in- and outside a function? | 38,569,964 | <p>The aim of my code is to put the string <code>datastr</code> into the two-dimensional list <code>matrix</code>. This works perfectly in Code_v1 but when I put the same code into a function <code>datastr = datastr.replace("\n", " ")</code> doesn't replace the <code>\n</code> the same way it did in Code_v1 (form one <... | 1 | 2016-07-25T14:07:45Z | 38,570,014 | <p>You <strong>indented</strong> the lines of <code>datastr</code>. Those spaces at the start of each line are <em>significant</em>:</p>
<pre><code> datastr = """08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93... | 6 | 2016-07-25T14:09:33Z | [
"python",
"string"
] |
Pycharm import RuntimeWarning after updating to 2016.2 | 38,569,992 | <p>After updating to new version 2016.2, I am getting</p>
<pre><code>RuntimeWarning: Parent module 'tests' not found while handling absolute import
import unittest
RuntimeWarning: Parent module 'tests' not found while handling absolute import
import datetime as dt
</code></pre>
<p>'tests' is a package inside my m... | 28 | 2016-07-25T14:08:50Z | 38,670,988 | <p>On OS X I've fixed this by replacing </p>
<pre><code>Applications/PyCharm.app/Contents/helpers/pycharm/utrunner.py
</code></pre>
<p>with an older version that can be found at
<a href="http://code.metager.de/source/xref/jetbrains/intellij/community/python/helpers/pycharm/utrunner.py">http://code.metager.de/so... | 5 | 2016-07-30T06:21:41Z | [
"python",
"import",
"pycharm"
] |
Pycharm import RuntimeWarning after updating to 2016.2 | 38,569,992 | <p>After updating to new version 2016.2, I am getting</p>
<pre><code>RuntimeWarning: Parent module 'tests' not found while handling absolute import
import unittest
RuntimeWarning: Parent module 'tests' not found while handling absolute import
import datetime as dt
</code></pre>
<p>'tests' is a package inside my m... | 28 | 2016-07-25T14:08:50Z | 38,724,508 | <p>This is a known issue with the 2016.2 release. Progress can be followed on the JetBrains website <a href="https://youtrack.jetbrains.com/issue/PY-20171">here</a>. According to this page it's due to be fixed in the 2016.3 release but you can follow the utrunner.py workaround that others have mentioned in the meantime... | 29 | 2016-08-02T15:21:38Z | [
"python",
"import",
"pycharm"
] |
Make a list of dicts by iterating over two lists (list comprehensions) | 38,569,999 | <p>The lists have the same number of elements, and the names are unique.
I wonder, how can I make a dict in one action. </p>
<p>This is my current code:</p>
<pre><code> fees = [fee for fee in fees]
names = [name for name in names]
mdict = [
{'fees': fee[i], 'names': names[i]}
for i, val in ... | 1 | 2016-07-25T14:09:01Z | 38,570,042 | <p>Try this:</p>
<pre><code>result = dict(zip(fees, names))
</code></pre>
| 1 | 2016-07-25T14:10:34Z | [
"python",
"list-comprehension"
] |
Make a list of dicts by iterating over two lists (list comprehensions) | 38,569,999 | <p>The lists have the same number of elements, and the names are unique.
I wonder, how can I make a dict in one action. </p>
<p>This is my current code:</p>
<pre><code> fees = [fee for fee in fees]
names = [name for name in names]
mdict = [
{'fees': fee[i], 'names': names[i]}
for i, val in ... | 1 | 2016-07-25T14:09:01Z | 38,570,045 | <p>You mean zip?</p>
<pre><code>dict(zip(fees, names))
</code></pre>
| 1 | 2016-07-25T14:10:40Z | [
"python",
"list-comprehension"
] |
Make a list of dicts by iterating over two lists (list comprehensions) | 38,569,999 | <p>The lists have the same number of elements, and the names are unique.
I wonder, how can I make a dict in one action. </p>
<p>This is my current code:</p>
<pre><code> fees = [fee for fee in fees]
names = [name for name in names]
mdict = [
{'fees': fee[i], 'names': names[i]}
for i, val in ... | 1 | 2016-07-25T14:09:01Z | 38,570,064 | <p>You can use <code>zip</code> on both lists in a <em>list comprehension</em>:</p>
<pre><code>mdict = [{'fees': f, 'names': n} for f, n in zip(fees, names)]
</code></pre>
| 4 | 2016-07-25T14:11:29Z | [
"python",
"list-comprehension"
] |
Make a list of dicts by iterating over two lists (list comprehensions) | 38,569,999 | <p>The lists have the same number of elements, and the names are unique.
I wonder, how can I make a dict in one action. </p>
<p>This is my current code:</p>
<pre><code> fees = [fee for fee in fees]
names = [name for name in names]
mdict = [
{'fees': fee[i], 'names': names[i]}
for i, val in ... | 1 | 2016-07-25T14:09:01Z | 38,570,171 | <p>You want this</p>
<pre><code>{fees[i]:y[i] for i in range(len(fees))}
</code></pre>
<p>or more quite :</p>
<pre><code>dict(zip(fees, names))
</code></pre>
| 1 | 2016-07-25T14:15:54Z | [
"python",
"list-comprehension"
] |
Fixing different id having same images in a csv column by renaming? | 38,570,025 | <p>As a new Python programmer, I'm having trouble figuring out how to accomplish the following. </p>
<p>Given this input data from a csv file: </p>
<pre class="lang-none prettyprint-override"><code>Sku Image_Name
B001 a.jpg
B002 a.jpg
B001 b.jpg
B002 c.jpg
B003 x.jpg
</code></pre>
<p>Where multip... | -1 | 2016-07-25T14:10:00Z | 38,572,713 | <p>OK, you've got quite a ways to go, but this should give you some hints on how to proceed (assuming a reasonable number of files):</p>
<pre><code>import csv
from os.path import splitext
with open("/tmp/test.csv", 'rb') as csvfile:
itemList = []
renamedList = []
keyList = []
spamreader = csv.reader(c... | 0 | 2016-07-25T16:12:41Z | [
"python"
] |
Fixing different id having same images in a csv column by renaming? | 38,570,025 | <p>As a new Python programmer, I'm having trouble figuring out how to accomplish the following. </p>
<p>Given this input data from a csv file: </p>
<pre class="lang-none prettyprint-override"><code>Sku Image_Name
B001 a.jpg
B002 a.jpg
B001 b.jpg
B002 c.jpg
B003 x.jpg
</code></pre>
<p>Where multip... | -1 | 2016-07-25T14:10:00Z | 38,603,339 | <pre><code>import csv
import os
from os.path import splitext # splits name & extension from a file
import shutil #making a duplicate copy of a file
from os import rename
#open and read csv
with open('test.csv') as csvfile:
#create list for sku,old_imagename and new imagename
itemList = []
renamedList =... | 0 | 2016-07-27T03:42:32Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.