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 |
|---|---|---|---|---|---|---|---|---|---|
Python BeautifulSoup scrape Yahoo Finance value | 39,197,977 | <p>I am attempting to scrape the 'Full Time Employees' value of 110,000 from the Yahoo finance website. </p>
<p>The URL is: <code>http://finance.yahoo.com/quote/AAPL/profile?p=AAPL</code></p>
<p>I have tried using Beautiful soup, but I can't find the value on the page. When I look in the DOM explorer in IE, I can se... | 0 | 2016-08-29T03:08:11Z | 39,198,005 | <p>The problem is in the "requests" related part - <em>the page you download with <code>requests</code> is not the same as you see in the browser</em>. Browser executed all of the javascript, made multiple asynchronous requests needed to load this page. And, this particular page is quite <em>dynamic</em> itself. There ... | 2 | 2016-08-29T03:14:24Z | [
"python",
"beautifulsoup"
] |
Python BeautifulSoup scrape Yahoo Finance value | 39,197,977 | <p>I am attempting to scrape the 'Full Time Employees' value of 110,000 from the Yahoo finance website. </p>
<p>The URL is: <code>http://finance.yahoo.com/quote/AAPL/profile?p=AAPL</code></p>
<p>I have tried using Beautiful soup, but I can't find the value on the page. When I look in the DOM explorer in IE, I can se... | 0 | 2016-08-29T03:08:11Z | 39,274,886 | <p>There are so many ways to download financial data, or any kind of data, from the web. The script below downloads stock prices and saves everything to a CSV file.</p>
<pre><code>import urllib2
listOfStocks = ["AAPL", "MSFT", "GOOG", "FB", "AMZN"]
urls = []
for company in listOfStocks:
urls.append('http://real... | 0 | 2016-09-01T14:56:29Z | [
"python",
"beautifulsoup"
] |
Executing a Python file from within Python, feeding it input and retrieving output | 39,197,999 | <p>I'm writing a web application where users may attempt to solve various programming problems. The user uploads an executable .py file and the application feeds it some pre-determined input and checks whether the output is correct. (similar to how <a href="http://www.codeforces.com/problemset" rel="nofollow">Codeforce... | 0 | 2016-08-29T03:12:52Z | 39,198,190 | <p>Figured it out.</p>
<p><em>Note</em>: If you are going to use this in a production environment, make sure you place restrictions on what the user can execute.</p>
<p><strong>executor.py</strong></p>
<pre><code>import subprocess
# create process
process = subprocess.Popen(
['python3.4','script_to_execute.... | 1 | 2016-08-29T03:42:51Z | [
"python",
"python-3.x",
"execution"
] |
Preserving order of occurrence with size() function | 39,198,023 | <p>I would like to preserve the order of my DataFrame when using the .size() function. My first DataFrame is created by choosing a subset of a larger one:</p>
<pre><code>df_South = df[df['REGION_NAME'] == 'South']
</code></pre>
<p>Here is an example of what the DataFrame looks like:</p>
<p><a href="http://i.stack.im... | 1 | 2016-08-29T03:16:11Z | 39,198,282 | <p>Try this: </p>
<pre><code>South_Count = df_South.groupby('TEMPBIN_CONS', sort=False ).size()
</code></pre>
<p>Looks as though your data is sorted as string. </p>
| 2 | 2016-08-29T03:57:30Z | [
"python",
"pandas",
"numpy",
"plot",
"dataframe"
] |
How to change which class variable is being called depending on user input? | 39,198,038 | <p>I've created a class called <code>Earthquake</code> which stores relevant earthquake data (its magnitude, time it hit, etc.) in class variables. I want to ask the user which data they'd like to see, then print out that data for them like so:</p>
<pre><code>earthquake1 = Earthquake()
answer = input("What data would... | 0 | 2016-08-29T03:19:08Z | 39,198,055 | <p>You could use <code>getattr</code> which is equivalent to <code>earthquake.attr_name</code>. The difference is that <code>getattr</code> allows you to use a variable to access the name and supply a default value if that is not found.</p>
<p>In short:</p>
<pre><code> print(getattr(earthquake1, answer))
</code></pre... | 2 | 2016-08-29T03:21:31Z | [
"python",
"class",
"python-3.x",
"class-variables"
] |
How to change which class variable is being called depending on user input? | 39,198,038 | <p>I've created a class called <code>Earthquake</code> which stores relevant earthquake data (its magnitude, time it hit, etc.) in class variables. I want to ask the user which data they'd like to see, then print out that data for them like so:</p>
<pre><code>earthquake1 = Earthquake()
answer = input("What data would... | 0 | 2016-08-29T03:19:08Z | 39,198,067 | <p>Just use <a href="http://effbot.org/zone/python-getattr.htm" rel="nofollow"><code>getattr</code></a>:</p>
<pre><code>earthquake1 = Earthquake()
answer = input("What data would you like to see?")
print(getattr(earthquake1, answer))
</code></pre>
| 4 | 2016-08-29T03:22:04Z | [
"python",
"class",
"python-3.x",
"class-variables"
] |
Peewee: Outer transaction does not roll back inner transaction (savepoints) | 39,198,041 | <p>Running the following python script twice throws this error:</p>
<pre><code>peewee.ProgrammingError: relation "test_table" already exists
</code></pre>
<p>because the table does not get removed on <em>.rollback()</em>. Removing the inner transaction (<em>with test_db.atomic()</em>) works. Why does the inner transa... | 0 | 2016-08-29T03:19:30Z | 39,210,809 | <p>Depending on the database you're using, DDL (schema changes) may or may not be possible to rollback.</p>
<p>Postgresql and SQLite both appear to support rolling back DDL, but MySQL does not.</p>
<p>However, the Python driver for SQLite has a bug which causes it to emit a COMMIT when you issue DDL. The first patch ... | 0 | 2016-08-29T16:21:23Z | [
"python",
"transactions",
"peewee"
] |
pandas standalone series and from dataframe different behavior | 39,198,108 | <p>Here is my code and warning message. If I change <code>s</code> to be a standalone <code>Series</code> by using <code>s = pd.Series(np.random.randn(5))</code>, there will no such errors. Using Python 2.7 on Windows.</p>
<p>It seems Series created from standalone and Series created from a column of a data frame are ... | 0 | 2016-08-29T03:28:31Z | 39,198,426 | <p>I suggest you use apply function instead:</p>
<pre><code>s.apply(lambda x:x+1 if x>0 else x-1)
</code></pre>
| 1 | 2016-08-29T04:17:22Z | [
"python",
"python-2.7",
"pandas",
"numpy",
"dataframe"
] |
pandas standalone series and from dataframe different behavior | 39,198,108 | <p>Here is my code and warning message. If I change <code>s</code> to be a standalone <code>Series</code> by using <code>s = pd.Series(np.random.randn(5))</code>, there will no such errors. Using Python 2.7 on Windows.</p>
<p>It seems Series created from standalone and Series created from a column of a data frame are ... | 0 | 2016-08-29T03:28:31Z | 39,199,050 | <p>By doing <code>s = sample['c_d']</code>, if you make a change to the value of <code>s</code> then your original Dataframe <code>sample</code> also changes. That's why you got the warning.</p>
<p>You can do <code>s = sample[c_d].copy()</code> instead, so that changing the value of <code>s</code> doesn't change the v... | 1 | 2016-08-29T05:31:07Z | [
"python",
"python-2.7",
"pandas",
"numpy",
"dataframe"
] |
why url cannot be generated after use blueprint | 39,198,413 | <p>My current project looks like this:</p>
<pre><code>âââ __init__.py
âââ pages
âââ settings.py
âââ static
âââ templates
â  âââ article.html
â  âââ base.html
â  âââ index.html
â  âââ posts.html
âââ view
â  âââ article.py
â  ... | 0 | 2016-08-29T04:16:11Z | 39,198,566 | <p>solved. change</p>
<pre><code><a href="{{ url_for('page', path=page.path) }}">More -></a>
</code></pre>
<p>to </p>
<pre><code><a href="{{ url_for('article.page', path=page.path) }}">More -></a>
</code></pre>
<p>forgot to add blueprint name </p>
| 2 | 2016-08-29T04:37:12Z | [
"python",
"flask",
"jinja2"
] |
Get path of all the elements in dictionary | 39,198,489 | <p>I have a dictionary in python and want to get path of values param1 or param2, ... to replace these with some other values. Say to get the value of param1 I need to get it like ['OptionSettings'][2]['Value']. Can I have some generic code to do this, which will print the path of all my nodes/leaves
below is the dic... | 0 | 2016-08-29T04:26:46Z | 39,198,539 | <p>You could try implementing something akin to a breadth-first search or depth-first search.</p>
| -1 | 2016-08-29T04:34:09Z | [
"python",
"python-2.7",
"python-3.x",
"dictionary",
"boto3"
] |
Get path of all the elements in dictionary | 39,198,489 | <p>I have a dictionary in python and want to get path of values param1 or param2, ... to replace these with some other values. Say to get the value of param1 I need to get it like ['OptionSettings'][2]['Value']. Can I have some generic code to do this, which will print the path of all my nodes/leaves
below is the dic... | 0 | 2016-08-29T04:26:46Z | 39,198,812 | <p>This is essentially the same question as this:</p>
<p><a href="http://stackoverflow.com/questions/34836777/print-complete-key-path-for-all-the-values-of-a-python-nested-dictionary">Print complete key path for all the values of a python nested dictionary</a></p>
<p>It is essentially the necessary code. What you are... | 1 | 2016-08-29T05:06:12Z | [
"python",
"python-2.7",
"python-3.x",
"dictionary",
"boto3"
] |
Get path of all the elements in dictionary | 39,198,489 | <p>I have a dictionary in python and want to get path of values param1 or param2, ... to replace these with some other values. Say to get the value of param1 I need to get it like ['OptionSettings'][2]['Value']. Can I have some generic code to do this, which will print the path of all my nodes/leaves
below is the dic... | 0 | 2016-08-29T04:26:46Z | 39,216,946 | <p>This worked for me</p>
<pre><code>def dict_traverse(self,obj,path):
if isinstance(obj, dict):
for k,v in obj.items():
if isinstance(v, str):
#if v.find('param')!=-1:
print(path+"["+"'"+k+"'"+"]",v)
elif isinstance(v, list):
... | 0 | 2016-08-30T00:02:09Z | [
"python",
"python-2.7",
"python-3.x",
"dictionary",
"boto3"
] |
Which one I have to use to read image in Django, StringIO or BytesIO? | 39,198,531 | <p>I'm trying to compress the image file before uploading in my <code>django</code> application.</p>
<p>I found nice code snippet site : <a href="https://djangosnippets.org/snippets/10460/" rel="nofollow">https://djangosnippets.org/snippets/10460/</a></p>
<p>but It doesn't work in <code>python3</code>. I think the pr... | 0 | 2016-08-29T04:33:19Z | 39,200,628 | <p>I modified the code to use the <code>with</code> statement so there is no need to close the files yourself.</p>
<pre><code>def save(self, *args, **kwargs):
if not self.id:
self.slug = self.slug + "주차"
if self.image:
with Img.open(BytesIO(self.image.read())) as img:
if img.mo... | 0 | 2016-08-29T07:24:40Z | [
"python",
"django",
"python-imaging-library"
] |
Color-coded syntax in terminal | 39,198,637 | <p>currently, the terminal I'm using to write my Python code is monochrome gray on black, but <a href="http://tstringer.github.io/vscode/2016/06/06/vscode-terminal.html" rel="nofollow">this</a> and <a href="https://code.visualstudio.com/docs/editor/integrated-terminal" rel="nofollow">this</a> example show that you can ... | 1 | 2016-08-29T04:47:45Z | 39,198,777 | <p>The default console REPL does not have syntax highlighting. However The IDLE IDE that ships with CPython has a syntax-highlighting REPL (interactive shell).</p>
<p><a href="https://ipython.org/install.html" rel="nofollow">IPython 5</a> also has <a href="http://stackoverflow.com/questions/25190889/syntax-highlightin... | 2 | 2016-08-29T05:02:38Z | [
"python",
"terminal"
] |
Why argument has been changed when using subprocess(python) to start application(windows)? | 39,199,060 | <p>I use the python code below to start debugger and the application(a simple code I write myself) with argument:</p>
<pre><code>debugger=r'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\windbg.exe'
exe='test.exe'
argument='\x01\x02...\xff'#from 0x01 to 0xff
subprocess.Popen(debugger+" "+exe+" "+argument)
</cod... | 2 | 2016-08-29T05:31:49Z | 39,199,218 | <p>Command with arguments shold be passed to <code>Popen</code> as list:</p>
<pre><code>subprocess.Popen([debugger, exe, argument])
</code></pre>
| 0 | 2016-08-29T05:45:26Z | [
"python",
"debugging",
"parameters",
"parameter-passing"
] |
Gunicorn giving syntax error for my configuration file | 39,199,070 | <p>my config file </p>
<pre><code>[loggers]
keys=root, gunicorn.error, gunicorn.access
[handlers]
keys=console, error_file, access_file
[formatters]
keys=generic, access
[logger_root]
level=INFO
handlers=console
[logger_gunicorn.error]
level=INFO
handlers=error_file
propagate=1
qualname=gunicorn.error
[logger_gun... | 0 | 2016-08-29T05:32:21Z | 39,200,343 | <p>Gunicorn config file looks like this: <a href="https://github.com/benoitc/gunicorn/blob/master/examples/example_config.py" rel="nofollow">https://github.com/benoitc/gunicorn/blob/master/examples/example_config.py</a></p>
<p>Your file is a logger configuration file.</p>
<p>Logger configuration is passed by <a href=... | 1 | 2016-08-29T07:06:29Z | [
"python",
"django",
"logging",
"celery",
"gunicorn"
] |
Gunicorn giving syntax error for my configuration file | 39,199,070 | <p>my config file </p>
<pre><code>[loggers]
keys=root, gunicorn.error, gunicorn.access
[handlers]
keys=console, error_file, access_file
[formatters]
keys=generic, access
[logger_root]
level=INFO
handlers=console
[logger_gunicorn.error]
level=INFO
handlers=error_file
propagate=1
qualname=gunicorn.error
[logger_gun... | 0 | 2016-08-29T05:32:21Z | 39,264,863 | <pre><code>[loggers]
keys=root, logstash.error, logstash.access
[handlers]
keys=console , logstash
[formatters]
keys=generic, access, json
[logger_root]
level=INFO
handlers=console
[logger_logstash.error]
level=DEBUG
handlers=logstash
propagate=1
qualname=gunicorn.error
[logger_logstash.access]
level=DEBUG
handler... | 0 | 2016-09-01T07:09:20Z | [
"python",
"django",
"logging",
"celery",
"gunicorn"
] |
ImportError: Cannot import name 'DurationField' | 39,199,209 | <p>I am trying to run an application that uses django (version 1.6.5) rest framework ( python version 3.4.5 ) .However I am getting the <strong>Import error "cannot import name DurationField"</strong>.How do I resolve this error ?</p>
<pre><code>File "/usr/src/app/Lab/models.py", line 8, in <module>
from Lab... | 2 | 2016-08-29T05:44:35Z | 39,199,565 | <p><code>DurationField</code> was <a href="https://docs.djangoproject.com/en/1.8/releases/1.8/#new-data-types" rel="nofollow">added in Django 1.8</a>. You are using Django 1.6, hence the error. </p>
<p>Your options are to upgrade (which is a good idea if you can, because Django 1.6 has reached end of life quite a whil... | 3 | 2016-08-29T06:11:52Z | [
"python",
"django",
"python-3.x",
"django-models",
"importerror"
] |
Python 3 - How to write specific row in same file csv? | 39,199,248 | <p>I want to update a fieldname called "done" in same file csv</p>
<p>This is structure of file csv:</p>
<p>Input:</p>
<pre><code>Email Done
1@gmail.com
2@gmail.com
3@gmail.com
4@gmail.com
</code></pre>
<p>Output:</p>
<pre><code>Email Done
1@gmail.com 1
2@gmail.com ... | -1 | 2016-08-29T05:49:04Z | 39,200,463 | <p>With a simple change like this you could use a simple pair of read and write files; read a line, and write it back out immediately with the addition.</p>
<pre><code>In [6]: with open('test.csv','r') as input:
...: with open('test1.csv','w') as output:
...: header=input.readline()
...: outp... | 3 | 2016-08-29T07:14:00Z | [
"python",
"python-3.x",
"csv"
] |
Plot a Data Set According to Counts of Categories of a Variable | 39,199,251 | <p>I have a dataset which has 14 columns (I had to only use 4 columns: travelling class, gender, age, and fare price) that I have split into train and test data sets. I need to create a vertical bar chart from the train data set for the distribution of the passengers by travelling class (1, 2, and 3 are the classes). I... | 1 | 2016-08-29T05:49:08Z | 39,201,705 | <p>Use <code>plt.hist</code>, which will plot a histogram <a href="https://plot.ly/matplotlib/histograms/" rel="nofollow">(more info here)</a></p>
<p>Example:</p>
<pre><code>import matplotlib.pyplot as plt
classes = [1, 2, 1, 1, 3, 3]
plt.hist(classes)
plt.show()
</code></pre>
<p>And this is the result:</p>
<p><a... | 0 | 2016-08-29T08:27:20Z | [
"python",
"bar-chart",
"categories",
"training-data",
"test-data"
] |
How to combine all the queued jobs(gerrit changes) and run as a single job in jenkins | 39,199,257 | <p>My Jenkins is configured with gerrit plug-in and build the code per each gerrit change when its merged. While my build is taking place there will be some more gerrits merged and those jobs will be in queue to build. My question is how to combine all those queued jobs and run as a single job once the current job is c... | -1 | 2016-08-29T05:49:26Z | 39,199,955 | <p>You can make a master job and make that job to run other jobs by setting Post-build Actions and set deploy other projects by giving names of jobs which you want to deploy.</p>
| 0 | 2016-08-29T06:39:05Z | [
"python",
"jenkins",
"jenkins-plugins"
] |
Pandas groupby sum using two DataFrames | 39,199,343 | <p>I have two very large Pandas DataFrames and would like to use them to guide each other in a fast sum operation. The two frames look like this:</p>
<p>Frame1:</p>
<pre><code>SampleName Gene1 Gene2 Gene3
Sample1 1 2 3
Sample2 4 5 6
Sample3 7 8 9
</cod... | 2 | 2016-08-29T05:55:22Z | 39,199,506 | <p>You can first create <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.MultiIndex.from_tuples.html" rel="nofollow"><code>MultiIndex.from_tuples</code></a>, then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reindex.html" rel="nofollow"><code>reindex</code></a> co... | 2 | 2016-08-29T06:07:52Z | [
"python",
"pandas",
"optimization",
"dataframe",
"sum"
] |
Pandas groupby sum using two DataFrames | 39,199,343 | <p>I have two very large Pandas DataFrames and would like to use them to guide each other in a fast sum operation. The two frames look like this:</p>
<p>Frame1:</p>
<pre><code>SampleName Gene1 Gene2 Gene3
Sample1 1 2 3
Sample2 4 5 6
Sample3 7 8 9
</cod... | 2 | 2016-08-29T05:55:22Z | 39,199,685 | <p>If you want to decrease the memory usage, I think your best option is to iterate over the first DataFrame since it has only 1k rows. </p>
<pre><code>dfs = []
frame1 = frame1.set_index('SampleName')
for idx, row in frame1.iterrows():
dfs.append(frame2.join(row, on='GeneID').groupby('FeatureName').sum())
pd.conca... | 3 | 2016-08-29T06:20:45Z | [
"python",
"pandas",
"optimization",
"dataframe",
"sum"
] |
Pandas groupby sum using two DataFrames | 39,199,343 | <p>I have two very large Pandas DataFrames and would like to use them to guide each other in a fast sum operation. The two frames look like this:</p>
<p>Frame1:</p>
<pre><code>SampleName Gene1 Gene2 Gene3
Sample1 1 2 3
Sample2 4 5 6
Sample3 7 8 9
</cod... | 2 | 2016-08-29T05:55:22Z | 39,199,723 | <h3>One obnoxious line</h3>
<pre><code>Frame1.set_index('SampleName') \
.rename_axis('GeneID', axis=1) \
.stack().rename('Value') \
.reset_index().merge(Frame2) \
.groupby(['SampleName', 'FeatureName']) \
.Value.sum().unstack()
</code></pre>
<p><a href="http://i.stack.imgur.com/TJsKo.png" rel="nof... | 1 | 2016-08-29T06:23:12Z | [
"python",
"pandas",
"optimization",
"dataframe",
"sum"
] |
OCR Hand written data showing error in svm.train() | 39,199,433 | <p>I am using OpenCV3.1.0 with Python2.7 .
I have implemented code of OCR Hand Written Data from <a href="https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_ml/py_svm/py_svm_opencv/py_svm_opencv.html#svm-opencv" rel="nofollow">here</a>.</p>
<pre><code>responses = np.float32(np.repeat(np.arange(10)... | 1 | 2016-08-29T06:01:41Z | 39,319,483 | <p>Try using <code>pytesseract</code>. It is much better than training an SVM classifier. If you want to check it out, follow this <a href="https://pypi.python.org/pypi/pytesseract/0.1)" rel="nofollow">link</a>. Also for an advanced example check out this <a href="https://realpython.com/blog/python/setting-up-a-simple-... | 0 | 2016-09-04T17:11:53Z | [
"python",
"opencv",
"svm",
"ocr",
"categorical-data"
] |
pexpect for terminal at local computer | 39,199,451 | <p>I am developing codes user interaction using pexpect for the <em>local terminal</em> on <em>Mac</em> (not remote SSH) instead of using subprocess. But I don't know what did I do wrong with following cases to receive empty outputs:</p>
<p>1)</p>
<pre><code>child = pexpect.spawn('ls')
child.expect(pexpect.EOF)
outpu... | 0 | 2016-08-29T06:02:33Z | 39,269,069 | <p>For running commands which does not require an interaction, spawn is not the right method. It is better to use <code>pexpect.run</code> method and get the output as return value.</p>
<p><code>pexpect.spawn</code> is more suited to spawn child process where you need to send commands and expect a response. Your code ... | 0 | 2016-09-01T10:27:22Z | [
"python",
"output",
"pexpect"
] |
Does anyone understand this error? | 39,199,553 | <blockquote>
<p>ValueError: Error parsing datetime string "2015-01-31:00:00" at position 10</p>
</blockquote>
<p>I am trying to call <code>np.datetime64('2015-01-31:00:00')</code>. </p>
| -5 | 2016-08-29T06:11:22Z | 39,200,152 | <p>A date in <code>ms</code> gives an idea of the string format it accepts</p>
<pre><code>In [74]: np.datetime64('2015-01-31','ms')
Out[74]: numpy.datetime64('2015-01-31T00:00:00.000')
</code></pre>
<p>See also the examples on the <code>numpy</code> doc page</p>
<p><a href="http://docs.scipy.org/doc/numpy/reference/... | 3 | 2016-08-29T06:52:45Z | [
"python",
"datetime",
"numpy"
] |
What is the equivalent of Java .get in python | 39,199,568 | <p>I am trying to code in python, with arrays, and I need to get the value of an element. In Java I would use <code>array.get(I)</code>, but I can't seem to find an equivalent in python.</p>
| -7 | 2016-08-29T06:11:59Z | 39,199,613 | <p>In Python you would do it exactly the same as in Java: <code>array[i]</code>.</p>
<p>BTW, Your <code>get(i)</code> is for <code>ArrayList</code> not for array in java.</p>
| 4 | 2016-08-29T06:16:10Z | [
"java",
"python"
] |
Convert a python list having a mix of unicode values and floating numbers | 39,199,596 | <p>So I am reading values from an excel and storing inside a list. But by default, it stored strings as unicode strings and numbers as floats. I want to convert unicode strings into normal strings and float to integer. How do I do that?</p>
<p>Here's my list:</p>
<pre><code>import xlrd
wb = xlrd.open_workbook("test.... | 0 | 2016-08-29T06:14:54Z | 39,199,999 | <p>Below is the <code>list</code> comprehension to convert items in list to:</p>
<ol>
<li><code>str</code> if it is <code>unicode</code></li>
<li><code>int</code> if it is <code>float</code></li>
<li>Else, append as it is:</li>
</ol>
<blockquote>
<p>Sample Example:</p>
</blockquote>
<pre><code>>>> my_list... | 0 | 2016-08-29T06:43:03Z | [
"python",
"unicode",
"xlrd"
] |
Convert a python list having a mix of unicode values and floating numbers | 39,199,596 | <p>So I am reading values from an excel and storing inside a list. But by default, it stored strings as unicode strings and numbers as floats. I want to convert unicode strings into normal strings and float to integer. How do I do that?</p>
<p>Here's my list:</p>
<pre><code>import xlrd
wb = xlrd.open_workbook("test.... | 0 | 2016-08-29T06:14:54Z | 39,200,010 | <p>You can use <a href="https://docs.python.org/2/library/functions.html#isinstance" rel="nofollow">isinstance</a> to check the type of the variable</p>
<pre><code>rows = [121090999.0, 3454554455.0, u'Shantharam', 121090999.0, 5645.0, u'Puranik']
def convert_rows(rows):
for kk,vv in enumerate(rows):
... | 0 | 2016-08-29T06:43:27Z | [
"python",
"unicode",
"xlrd"
] |
Convert a python list having a mix of unicode values and floating numbers | 39,199,596 | <p>So I am reading values from an excel and storing inside a list. But by default, it stored strings as unicode strings and numbers as floats. I want to convert unicode strings into normal strings and float to integer. How do I do that?</p>
<p>Here's my list:</p>
<pre><code>import xlrd
wb = xlrd.open_workbook("test.... | 0 | 2016-08-29T06:14:54Z | 39,200,065 | <p>Here is a short script that should do the trick:</p>
<pre><code>l=[121090999.0, 3454554455.0, u'Shantharam', 121090999.0, 5645.0, u'Puranik'];
i=0
for i in range(len(l)-1):
if isinstance(l[i], float):
l[i]=int(l[i])
else:
l[i]=str(l[i])
print(l)
</code></pre>
| 0 | 2016-08-29T06:47:19Z | [
"python",
"unicode",
"xlrd"
] |
Convert a python list having a mix of unicode values and floating numbers | 39,199,596 | <p>So I am reading values from an excel and storing inside a list. But by default, it stored strings as unicode strings and numbers as floats. I want to convert unicode strings into normal strings and float to integer. How do I do that?</p>
<p>Here's my list:</p>
<pre><code>import xlrd
wb = xlrd.open_workbook("test.... | 0 | 2016-08-29T06:14:54Z | 39,200,911 | <p>Below is the list comprehension code which does exactly what you want:</p>
<pre><code> [int(d) if isinstance(d, float) else str(d) if isinstance(d, unicode) else d for d in my_list]
</code></pre>
<p>Run this code on your <code>my_list</code> and you'll get the following response:</p>
<pre><code> new_list = [... | 0 | 2016-08-29T07:40:13Z | [
"python",
"unicode",
"xlrd"
] |
Error with two same views in different apps in django project | 39,199,621 | <p>Working on django project. There are two apps in my project one is custom defined "admin", and another is "home". I am using some views same in both app for eg:- My admin app urls.py file is</p>
<pre><code>from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'... | 2 | 2016-08-29T06:16:38Z | 39,199,732 | <p>The <code>admin</code> in your root urls.py specifies the django admin module, and not your custom application. You have not included your admin app's urls in the root url at all. </p>
| 0 | 2016-08-29T06:24:04Z | [
"python",
"django"
] |
Error with two same views in different apps in django project | 39,199,621 | <p>Working on django project. There are two apps in my project one is custom defined "admin", and another is "home". I am using some views same in both app for eg:- My admin app urls.py file is</p>
<pre><code>from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'... | 2 | 2016-08-29T06:16:38Z | 39,202,550 | <p>Okay so Django has something to solve this problem of yours.</p>
<p>What you can do is specify the <code>namespace</code> for the urls in your root <strong>urls.py</strong> and then when using then you can use this <code>namespace</code> value while <strong>reversing the url</strong> in your <strong>html templates<... | 1 | 2016-08-29T09:16:13Z | [
"python",
"django"
] |
Getting "TypeError: 'NoneType' object is not iterable" while doing parallel ssh | 39,199,781 | <p>I am trying to do parallel ssh on servers. While doing this, i am getting "TypeError: 'NoneType' object is not iterable" this error. Kindly help.</p>
<p>My script is below</p>
<pre><code>from pssh import ParallelSSHClient
from pssh.exceptions import AuthenticationException, UnknownHostException, ConnectionErrorExc... | 0 | 2016-08-29T06:27:48Z | 39,200,109 | <p>From reading the code and debugging a bit on my laptop, I believe the issue is that you don't have a file called <code>~/.ssh/config</code>. It seems that <code>parallel-ssh</code> has a dependency on OpenSSH configuration, and this is the error you get when that file is missing.</p>
<p><code>read_openssh_config</c... | 1 | 2016-08-29T06:50:23Z | [
"python",
"ssh",
"ssh-agent"
] |
Getting "TypeError: 'NoneType' object is not iterable" while doing parallel ssh | 39,199,781 | <p>I am trying to do parallel ssh on servers. While doing this, i am getting "TypeError: 'NoneType' object is not iterable" this error. Kindly help.</p>
<p>My script is below</p>
<pre><code>from pssh import ParallelSSHClient
from pssh.exceptions import AuthenticationException, UnknownHostException, ConnectionErrorExc... | 0 | 2016-08-29T06:27:48Z | 39,247,413 | <p>This <a href="https://github.com/pkittenis/parallel-ssh/issues/63" rel="nofollow">was seemingly a regression in the <code>0.92.0</code> version of the library</a> which is now resolved in <a href="https://github.com/pkittenis/parallel-ssh/releases/tag/0.92.1" rel="nofollow">0.92.1</a>. Previous versions also work. O... | 0 | 2016-08-31T10:41:47Z | [
"python",
"ssh",
"ssh-agent"
] |
unable to scrape text | 39,200,026 | <p>I was trying to get the title of the websites.
So, I used this snippet to do this</p>
<pre><code> sys.stdout = open("test_data.txt", "w")
url2 = "https://www.google.com/"
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.... | 1 | 2016-08-29T06:44:15Z | 39,200,126 | <p>Is this Flask? If so, you need to <code>return</code> the string you want to send to the user. A <code>print</code> statement writes to the web server log. You should replace the last line of your <code>get_title</code> function with this:</p>
<pre><code>return list1.encode('utf-8')
</code></pre>
| -2 | 2016-08-29T06:51:26Z | [
"python",
"web-services",
"scrape"
] |
Seaborn: Overlaying a box plot or mean with error bars on a histogram | 39,200,165 | <p>I am creating a histogram in Seaborn of my data in a pretty standard way, ie:</p>
<pre><code>rc = {'font.size': 32, 'axes.labelsize': 28.5, 'legend.fontsize': 32.0,
'axes.titlesize': 32, 'xtick.labelsize': 31, 'ytick.labelsize': 12}
sns.set(style="ticks", color_codes=True, rc = rc)
plt.figure(figsize=(25,20),d... | 1 | 2016-08-29T06:53:39Z | 39,208,219 | <p>The boxplot is drawn on a categorical axis and won't coexist nicely with the density axis of the histogram, but it's possible to do it with a twin x axis plot:</p>
<pre><code>import numpy as np
import seaborn as sns
x = np.random.randn(300)
ax = sns.distplot(x)
ax2 = ax.twinx()
sns.boxplot(x=x, ax=ax2)
ax2.set(yli... | 1 | 2016-08-29T14:02:33Z | [
"python",
"matplotlib",
"histogram",
"data-visualization",
"seaborn"
] |
Input file doesn't exist even though the file is mentioned in the correct location- pyspark | 39,200,177 | <p>I'm trying to read log lines by forming key-value pairs but I get an error.
This is my code:</p>
<pre><code>logLine=sc.textFile("C:\TestLogs\testing.log").cache()
lines = logLine.flatMap(lambda x: x.split('\n'))
rx = "(\\S+)=(\\S+)"
line_collect = lines.collect()
for line in line_collect :
d = dict([(x,y) ... | 1 | 2016-08-29T06:54:08Z | 39,200,260 | <p>Try replace <code>logLine=sc.textFile("C:\TestLogs\testing.log").cache()</code> with
<code>logLine=sc.textFile("C:\\TestLogs\\testing.log").cache()</code></p>
<p>The backslash character is not <code>'\'</code> in a string but rather <code>"\\"</code></p>
| 0 | 2016-08-29T07:00:24Z | [
"python",
"apache-spark",
"pyspark"
] |
Input file doesn't exist even though the file is mentioned in the correct location- pyspark | 39,200,177 | <p>I'm trying to read log lines by forming key-value pairs but I get an error.
This is my code:</p>
<pre><code>logLine=sc.textFile("C:\TestLogs\testing.log").cache()
lines = logLine.flatMap(lambda x: x.split('\n'))
rx = "(\\S+)=(\\S+)"
line_collect = lines.collect()
for line in line_collect :
d = dict([(x,y) ... | 1 | 2016-08-29T06:54:08Z | 39,200,284 | <p>When the character sequence <code>\t</code> is found in a string, it will be replaced by a TAB character. You can actually see this in the error message.</p>
<p>I'd recommend always using the forward slash <code>/</code> as the directory separator, even on Windows. Alternatively prefix the string with an r like thi... | 1 | 2016-08-29T07:02:13Z | [
"python",
"apache-spark",
"pyspark"
] |
Expecting value: line 1 column 1 (char 0) python | 39,200,229 | <p>I'm newbie in python and trying to parse data in my application using these lines of codes</p>
<pre><code>json_str = request.body.decode('utf-8')
py_str = json.loads(json_str)
</code></pre>
<p>But I'm getting this error on <code>json.loads</code></p>
<blockquote>
<p>Expecting value: line 1 column 1 (char 0)</p... | -1 | 2016-08-29T06:57:07Z | 39,200,564 | <p>Your data is not <a href="https://en.wikipedia.org/wiki/JSON" rel="nofollow">JSON-formatted</a>, not even the one you included in your updated answer. Your data is a JavaScript-object, not an encoded string. Please note the "N" in JSON: Notation -- it is a format inspired from how data is written in JavaScript cod... | 2 | 2016-08-29T07:20:47Z | [
"python",
"angularjs",
"json"
] |
How do I compare 2 lists and order 1 based on the number of matches | 39,200,256 | <p>Say you had a list, for example:</p>
<pre><code>first_list = ['a', 'b', 'c']
</code></pre>
<p>And you had the following list:</p>
<pre><code>second_list = ['a', 'a b c', 'abc zyx', 'ab cc ac']
</code></pre>
<p>How would you create a function that simply re-orders the second list based on the total number of time... | 0 | 2016-08-29T06:59:55Z | 39,200,393 | <p>Here's one unstable way to do it:</p>
<pre><code>>>> l1 = ['a', 'b', 'c']
>>> l2 = ['a', 'a b c', 'abc zyx', 'ab cc ac']
>>> [s for _, s in sorted(((sum(s2.count(s1) for s1 in l1), s2) for s2 in l2), reverse=True)]
['ab cc ac', 'abc zyx', 'a b c', 'a']
</code></pre>
<p>If stable sort is ... | 1 | 2016-08-29T07:09:27Z | [
"python"
] |
How do I compare 2 lists and order 1 based on the number of matches | 39,200,256 | <p>Say you had a list, for example:</p>
<pre><code>first_list = ['a', 'b', 'c']
</code></pre>
<p>And you had the following list:</p>
<pre><code>second_list = ['a', 'a b c', 'abc zyx', 'ab cc ac']
</code></pre>
<p>How would you create a function that simply re-orders the second list based on the total number of time... | 0 | 2016-08-29T06:59:55Z | 39,200,786 | <p>Similar answer:</p>
<pre><code>first_list = ['a', 'b', 'c']
second_list = ['a', 'a b c', 'abc zyx', 'ab cc ac']
#Find occurrences
list_for_sorting = []
for string in second_list:
occurrences = 0
for item in first_list:
occurrences += string.count(item)
list_for_sorting.append((occurrences,... | 2 | 2016-08-29T07:33:12Z | [
"python"
] |
How do I compare 2 lists and order 1 based on the number of matches | 39,200,256 | <p>Say you had a list, for example:</p>
<pre><code>first_list = ['a', 'b', 'c']
</code></pre>
<p>And you had the following list:</p>
<pre><code>second_list = ['a', 'a b c', 'abc zyx', 'ab cc ac']
</code></pre>
<p>How would you create a function that simply re-orders the second list based on the total number of time... | 0 | 2016-08-29T06:59:55Z | 39,200,876 | <p>The most straightforward approach would be to use the <a href="https://docs.python.org/3.5/library/functions.html#sorted" rel="nofollow"><code>key</code> parameter of the <code>sorted</code> built-in function</a>:</p>
<pre><code>>>> sorted(second_list, key = lambda s: sum(s.count(x) for x in first_list), r... | 3 | 2016-08-29T07:38:24Z | [
"python"
] |
deduplicate records in multiple CSV files with varying columns | 39,200,444 | <p>I have multiple CSV files in a directory. Some contain more columns (which would be OK to drop).</p>
<p>Is there an elegant way to deduplicate records between these CSV files and reduce columns to a common set of columns?</p>
<p>Currently, I will use python / pandas to accomplish this. I will load all the files in... | 0 | 2016-08-29T07:12:50Z | 39,201,499 | <p>I do not known how to make it simpler. I have an equal script done for some data of mine. It just runs twice, first to determine the min / max cols in all documents and finally to rewrite the csv files in an new folder, to keep the original data.</p>
<p>I am just using the csv lib from python.
<a href="https://docs... | 1 | 2016-08-29T08:14:59Z | [
"python",
"csv",
"pandas",
"duplicates"
] |
numpy 3 dimension array middle indexing bug | 39,200,644 | <p>I seems found a bug when I'm using python 2.7 with numpy module:</p>
<pre><code>import numpy as np
x=np.arange(3*4*5).reshape(3,4,5)
x
</code></pre>
<p>Here I got the full 'x' array as follows:</p>
<pre><code>array([[[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16... | 2 | 2016-08-29T07:25:30Z | 39,200,766 | <p>No, it's not a bug.</p>
<p>When you use <code>[:]</code> you are using <a class='doc-link' href="http://stackoverflow.com/documentation/python/289/indexing-and-slicing#t=201608290734003933874">slicing</a> notation and it takes all the list:</p>
<pre><code>l = ["a", "b", "c"]
l[:]
#output:
["a", "b", "c"]
</code></... | 2 | 2016-08-29T07:32:09Z | [
"python",
"arrays",
"numpy"
] |
numpy 3 dimension array middle indexing bug | 39,200,644 | <p>I seems found a bug when I'm using python 2.7 with numpy module:</p>
<pre><code>import numpy as np
x=np.arange(3*4*5).reshape(3,4,5)
x
</code></pre>
<p>Here I got the full 'x' array as follows:</p>
<pre><code>array([[[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16... | 2 | 2016-08-29T07:25:30Z | 39,200,843 | <p>This is not a bug. <code>x[1][:][0]</code> is not a multiple index ("give me the elements where first dimension is 1, second is any, third is 0"). Instead, you are indexing three times, three objects.</p>
<pre><code>x1 = x[1] # x1 is the first 4x5 subarray
x2 = x1[:] # x2 is same as x1
x3 = x2[0] # x3 is ... | 0 | 2016-08-29T07:36:50Z | [
"python",
"arrays",
"numpy"
] |
I can't able to push on heroku | 39,200,695 | <p>I have an app on heroku named as <code>floating-river-39482</code> .And I'm trying to deploy the app by giving the command <code>git push heroku master</code> .
But I got an error from terminal like this</p>
<pre><code>remote: ! No such app as sleepy-inlet-36834.
fatal: repository 'https://git.heroku.com/sleepy-... | 0 | 2016-08-29T07:28:29Z | 39,208,169 | <p>It looks like you've somehow got your Git repository referencing an old (or deleted) Heroku application.</p>
<p>What you can do most easily is open up your <code>.git/config</code> file in your project, and switch out the <code>https://git.heroku.com/sleepy-inlet-36834.git/</code> URL with the correct one for your ... | 0 | 2016-08-29T14:00:23Z | [
"python",
"git",
"heroku"
] |
Django - POST get options from select | 39,200,802 | <p>I have a html form that looks like this.</p>
<pre><code>{% url 'myapp:myapp_submit' as submit %}
<form name='main' method="POST" action={{submit}}>
{% csrf_token %}
<select class='form-control' size=10 id="test" name='test' multiple>
<option>Test</option>
</select>
<input type="su... | 0 | 2016-08-29T07:34:25Z | 39,200,939 | <p>Because you say you're doing weird things with <strong>Js</strong>, you can first check the <code>POST</code> request from your browser and what parameters you send with it. </p>
| 0 | 2016-08-29T07:42:01Z | [
"python",
"django"
] |
Django - POST get options from select | 39,200,802 | <p>I have a html form that looks like this.</p>
<pre><code>{% url 'myapp:myapp_submit' as submit %}
<form name='main' method="POST" action={{submit}}>
{% csrf_token %}
<select class='form-control' size=10 id="test" name='test' multiple>
<option>Test</option>
</select>
<input type="su... | 0 | 2016-08-29T07:34:25Z | 39,201,120 | <p>Try to change your <code>views.py</code>:</p>
<pre><code>def myapp_submit(request):
request.POST.getlist('test[]')
</code></pre>
| 1 | 2016-08-29T07:52:49Z | [
"python",
"django"
] |
How to print html output each on its line in python? | 39,200,873 | <p>so i'm making alittle project as i am a beginner and i'm doing some webscraping. I wanted to print the lyrics of a song each on it's line using beautifulsoup in python but instead it's printing like this:</p>
<p>I looked out this morning and the sun was goneTurned on some music to start my dayI lost myself in a fam... | 0 | 2016-08-29T07:38:16Z | 39,200,949 | <p>You need to remove the <code>strip = True</code> parameter to <code>get_text</code>. That strips the string resulting in the joined output you see. </p>
<p>By removing it:</p>
<pre><code>print("".join([p.get_text() for p in namelist]))
</code></pre>
<p>It prints fine.</p>
| 1 | 2016-08-29T07:42:53Z | [
"python",
"html",
"python-3.x",
"web-scraping",
"beautifulsoup"
] |
How to print html output each on its line in python? | 39,200,873 | <p>so i'm making alittle project as i am a beginner and i'm doing some webscraping. I wanted to print the lyrics of a song each on it's line using beautifulsoup in python but instead it's printing like this:</p>
<p>I looked out this morning and the sun was goneTurned on some music to start my dayI lost myself in a fam... | 0 | 2016-08-29T07:38:16Z | 39,201,027 | <p>Try writing it into a simple for loop</p>
<pre><code>for p in namelist:
print(p.get_text(strip=True))
</code></pre>
| 0 | 2016-08-29T07:48:24Z | [
"python",
"html",
"python-3.x",
"web-scraping",
"beautifulsoup"
] |
Creating a slot machine for school | 39,200,882 | <p>I'm programming a slot machine for school and cannot get the machine to re-run once it is finished. I am relatively new and would like some honest feedback. How can I get my program to re-run? This is the code I'm trying to do this with. I've just modified my code to look like this.</p>
<pre><code>import random
im... | 1 | 2016-08-29T07:38:45Z | 39,232,161 | <p>Having some spare time, I have modified your code.<br>
The code you supplied is riddled with small coding and logical errors. You would be best running the <code>diff</code> command between your original code and the code below, to see where the many differences are and there is no guarantee that is bug free now eit... | 0 | 2016-08-30T15:56:53Z | [
"python"
] |
Sort nested dictionaries and replace dictioary values with ordered numbers | 39,200,897 | <p>Not sure if my problem sound a bit tricky..my requirement is like this: I have three columns of data in txt file as below:</p>
<pre><code>col1,col2,col3/n
11,0.95,21/n
11,0.75,22/n
11,0.85,23/n
11,0.65,24/n
12,0.63,22/n
12,0.75,24/n
12,0.45,25/n
...
</code></pre>
<p>col1 can be viewed as dict keys which repeat for... | 0 | 2016-08-29T07:39:35Z | 39,201,189 | <p>Your input not defined here, I assumed as a list of list like this.</p>
<pre><code>[['col1', 'col2', 'col3'],
['11', '0.95', '21'],
['11', '0.75', '22'],
['11', '0.85', '23'],
['11', '0.65', '24'],
['12', '0.63', '22'],
['12', '0.75', '24'],
['12', '0.45', '25']]
</code></pre>
<p>Then you can do like this,<... | 0 | 2016-08-29T07:56:42Z | [
"python",
"sorting",
"dictionary"
] |
Sort nested dictionaries and replace dictioary values with ordered numbers | 39,200,897 | <p>Not sure if my problem sound a bit tricky..my requirement is like this: I have three columns of data in txt file as below:</p>
<pre><code>col1,col2,col3/n
11,0.95,21/n
11,0.75,22/n
11,0.85,23/n
11,0.65,24/n
12,0.63,22/n
12,0.75,24/n
12,0.45,25/n
...
</code></pre>
<p>col1 can be viewed as dict keys which repeat for... | 0 | 2016-08-29T07:39:35Z | 39,201,624 | <p>Well, here is a way to do it in basic Python:</p>
<pre><code>In [90]: col1
Out[90]: [11, 11, 11, 11, 12, 12, 12]
In [91]: col2
Out[91]: [0.95, 0.75, 0.85, 0.65, 0.63, 0.75, 0.45]
In [92]: col3
Out[92]: [21, 22, 23, 24, 22, 24, 25]
</code></pre>
<p>Let's create <code>data</code> consisting of items from each colu... | 0 | 2016-08-29T08:22:52Z | [
"python",
"sorting",
"dictionary"
] |
reading a GML file with networkx (python) without labels for the nodes | 39,200,898 | <p>I have a long GML file (Graph Modelling Language) that i am trying to read with Networkx in Python.
In the GML file, nodes don't have label, like this:</p>
<pre><code>graph [
node [
id 1
]
node [
id 2
]
edge [
source 2
target 1
]
]
</code></pre>
<p>I get an error when reading the fi... | 0 | 2016-08-29T07:39:41Z | 39,201,481 | <p>If you want to use <code>id</code> attribute in GML for labeling nodes, you can designate the label attribute for the <code>nx.read_gml</code> argument as follows.</p>
<pre><code>G = nx.read_gml('simple_graph.gml', label='id')
</code></pre>
| 1 | 2016-08-29T08:13:32Z | [
"python",
"networkx",
"graph-modelling-language"
] |
2d fft numpy/python confusion | 39,200,937 | <p>I have data in the form x-y-z and want to create a power spectrum along x-y. Here is a basic example I am posting to check where I might be going wrong with my actual data:</p>
<pre><code>import numpy as np
from matplotlib import pyplot as plt
fq = 10; N = 20
x = np.linspace(0,8,N); y = x
space = x[1] -x[0]
xx, y... | 0 | 2016-08-29T07:41:58Z | 39,201,385 | <p>One of your problems is that matplotlib's <code>imshow</code> using a different coordinate system to what you expect. Provide a <code>origin='lower'</code> argument, and the peaks now appear at <code>y=0</code>, as expected.</p>
<p>Another problem that you have is that <code>fftfreq</code> needs to be told your tim... | 2 | 2016-08-29T08:08:12Z | [
"python",
"numpy",
"fft"
] |
find max square with black border | 39,201,004 | <p>For a square matrix, each cell is either black (1) or white (0), trying to find the max sub-square whose border is black. Here is my code with Python 2.7, wondering if logically correct? And any performance improvements? Thanks.</p>
<p>My major ideas is, keep track of how many black nodes are on top (continuously) ... | 0 | 2016-08-29T07:46:41Z | 39,205,809 | <p>This isn't logically correct, as the following simple counterexample shows:</p>
<pre><code>011
101
111
</code></pre>
<p>This array contains no bordered square, but your code reports that it contains a square of edge length 3. You need either a third nested loop through <em>all</em> candidate square sizes down fro... | 1 | 2016-08-29T11:59:10Z | [
"python",
"algorithm",
"python-2.7"
] |
Pygame - Smoother Movement | 39,201,171 | <p>I have added an Object/Image on the <code>main_screen</code>, the object is called <code>cancer_cell</code>.
What I'm trying to do here is that I want the object move smoothly. I have to repeatedle press on the arrow keys to keep it moving.
How do I make it move <code>while</code> arrow keys are pressed ? </p>
<... | 1 | 2016-08-29T07:55:10Z | 39,201,830 | <p><strong>PROBLEM SOLVED</strong></p>
<p>I have solved the problem by just unindenting this part from the <code>FOR</code> loop
while not exitgame:</p>
<pre><code> for event in pygame.event.get():
if event.type == pygame.QUIT:
exitgame = True
quitgame()
key_pressed = pygam... | 0 | 2016-08-29T08:35:48Z | [
"python",
"pygame"
] |
Pygame - Smoother Movement | 39,201,171 | <p>I have added an Object/Image on the <code>main_screen</code>, the object is called <code>cancer_cell</code>.
What I'm trying to do here is that I want the object move smoothly. I have to repeatedle press on the arrow keys to keep it moving.
How do I make it move <code>while</code> arrow keys are pressed ? </p>
<... | 1 | 2016-08-29T07:55:10Z | 39,202,542 | <p>I see you've solved the indentation issue, here's another version of your example:</p>
<pre><code>import pygame
class Player(object):
def __init__(self, img_path):
self.image = pygame.image.load(img_path)
self.x = 0
self.y = self.image.get_rect().height*2
def handle_keys(self):
... | 0 | 2016-08-29T09:15:56Z | [
"python",
"pygame"
] |
Access Jupyter Notebook over Internet | 39,201,437 | <p>I have a Windows 7 computer that I use to host a Jupyter noteboks for use across my local network. However, I would like to be able to access these notebooks remotely over the internet.</p>
<p>Is this possible?</p>
<p>I've tried researching ways but haven't managed to understand anything. The closest I've got was ... | 0 | 2016-08-29T08:11:12Z | 39,201,523 | <p>You can use some of free/paid VPN solutions to make virtual network between you and jupyter-notebook host to workaround need of public DNS. <a href="http://logmein.com" rel="nofollow">Hamachi</a> for example. I'm talking about case when you just want to access jupyter notebook remotely, not when you want to share it... | 0 | 2016-08-29T08:16:31Z | [
"python",
"jupyter",
"jupyter-notebook"
] |
Python - Select "Save link as" and save a file using Selenium | 39,201,498 | <p>Newbie: There are different files on a webpage, which can be downloaded as follows:
1. Right click on a file link
2. Select "Save link as"
3. Click "Save" button on the new window.</p>
<p>I tried the following code(for first 2 steps), but it is not working:</p>
<pre><code> from selenium import webdriver
fro... | 1 | 2016-08-29T08:14:51Z | 39,220,537 | <p>Save Link As will open the system dialog which can not be controlled through selenium directly.</p>
<p>Having said that, download preferences can be configured in the profile, which can be used while launching the browser and in that case, any click to download will save the file as per preferences in the chrome pr... | 0 | 2016-08-30T06:46:15Z | [
"python",
"selenium"
] |
Python - Select "Save link as" and save a file using Selenium | 39,201,498 | <p>Newbie: There are different files on a webpage, which can be downloaded as follows:
1. Right click on a file link
2. Select "Save link as"
3. Click "Save" button on the new window.</p>
<p>I tried the following code(for first 2 steps), but it is not working:</p>
<pre><code> from selenium import webdriver
fro... | 1 | 2016-08-29T08:14:51Z | 39,221,139 | <p>As per java you can use following code for clicking save as link and click save in new window</p>
<pre><code>try {
Robot bot = new Robot();
//location of link on your page
bot.mouseMove(5, 12);
//instigate right click of mouse
bot.mousePress(InputEvent.B... | 0 | 2016-08-30T07:16:55Z | [
"python",
"selenium"
] |
pandas: pandas.DataFrame.describe returns information on only one column | 39,201,526 | <p>For a certain Kaggle dataset (rules prohibit me from sharing the data here, but is readily accessible <a href="https://www.kaggle.com/c/predicting-red-hat-business-value/data" rel="nofollow">here</a>), </p>
<pre><code>import pandas
df_train = pandas.read_csv(
"01 - Data/act_train.csv.zip"
)
df_train.describe()
... | 1 | 2016-08-29T08:16:35Z | 39,201,640 | <p>By default, <code>describe</code> only works on numeric dtype columns. Add a keyword-argument <code>include='all'</code>. <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.describe.html" rel="nofollow">From the documentation</a>:</p>
<blockquote>
<p>If include is the string âallâ... | 2 | 2016-08-29T08:23:39Z | [
"python",
"python-3.x",
"pandas"
] |
Python way of doing difference of lists containing lists | 39,201,610 | <p>Consider two lists A and B. I know that <code>list(set(A) - set(B))</code> will give the difference between A and B. What about the situation whereby elements in both A and B are lists. i.e. A and B are list of list? For e.g.</p>
<pre><code>A = [[1,2], [3,4], [5,6]]
B = [[3,4], [7,8]]
</code></pre>
<p>I wish to re... | 1 | 2016-08-29T08:22:19Z | 39,201,658 | <p>Here's a one-liner you could use:</p>
<pre><code>diff = [x for x in A if x not in B]
</code></pre>
<p>Or if you want to use filter:</p>
<pre><code>diff = list(filter(lambda x: x not in B, A))
</code></pre>
| 1 | 2016-08-29T08:24:56Z | [
"python"
] |
Python way of doing difference of lists containing lists | 39,201,610 | <p>Consider two lists A and B. I know that <code>list(set(A) - set(B))</code> will give the difference between A and B. What about the situation whereby elements in both A and B are lists. i.e. A and B are list of list? For e.g.</p>
<pre><code>A = [[1,2], [3,4], [5,6]]
B = [[3,4], [7,8]]
</code></pre>
<p>I wish to re... | 1 | 2016-08-29T08:22:19Z | 39,201,671 | <pre><code>>>> [i for i in A if i not in B]
[[1, 2], [5, 6]]
</code></pre>
| 1 | 2016-08-29T08:25:23Z | [
"python"
] |
Python way of doing difference of lists containing lists | 39,201,610 | <p>Consider two lists A and B. I know that <code>list(set(A) - set(B))</code> will give the difference between A and B. What about the situation whereby elements in both A and B are lists. i.e. A and B are list of list? For e.g.</p>
<pre><code>A = [[1,2], [3,4], [5,6]]
B = [[3,4], [7,8]]
</code></pre>
<p>I wish to re... | 1 | 2016-08-29T08:22:19Z | 39,201,689 | <p>The idea is to convert the list of lists to lists of tuples,<br>
which are hashable and are, thus, candidates of making sets themselves:</p>
<pre><code>In [192]: C = set(map(tuple, A)) - set(map(tuple, B))
In [193]: C
Out[193]: {(1, 2), (5, 6)}
</code></pre>
<p>And one more touch:</p>
<pre><code>In [196]: [*map(... | 1 | 2016-08-29T08:26:33Z | [
"python"
] |
Python way of doing difference of lists containing lists | 39,201,610 | <p>Consider two lists A and B. I know that <code>list(set(A) - set(B))</code> will give the difference between A and B. What about the situation whereby elements in both A and B are lists. i.e. A and B are list of list? For e.g.</p>
<pre><code>A = [[1,2], [3,4], [5,6]]
B = [[3,4], [7,8]]
</code></pre>
<p>I wish to re... | 1 | 2016-08-29T08:22:19Z | 39,202,133 | <pre><code>A = [[1, 2], [3, 4], [5, 6]]
B = [[3, 4], [7, 8]]
print[x for x in A if x not in B]
</code></pre>
| 1 | 2016-08-29T08:52:47Z | [
"python"
] |
select data based on a string criteria python | 39,201,631 | <p>I have a large database in which I want to select all the columns that meet a certain criteria:</p>
<p>My data looks like the following:</p>
<pre><code>Name a b c
target-01 5196 24 24
target-02 5950 150 150
target-03 5598 50 50
object-01 6558 44 -1
object-02 6190 60 ... | 1 | 2016-08-29T08:23:13Z | 39,201,771 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.startswith.html" rel="nofollow"><code>str.startswith</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a>:</p>
<pre><code>print (df[df.... | 1 | 2016-08-29T08:32:03Z | [
"python",
"string",
"pandas",
"dataframe",
"startswith"
] |
Parsing of list of bits in python | 39,201,679 | <p>I have a list of 64 bits.</p>
<pre><code>['11111111', '11111111', '10001111', '11111110', '11011011', '11111111', '01011011', '10000111']
</code></pre>
<p>Here each and every bit represents a feature. If a bit is 1 then that particular feature is supported else not.</p>
<p>Is there any way were i can check the bi... | 1 | 2016-08-29T08:25:52Z | 39,201,866 | <p>You may unwrap the string in variable for each feature as:</p>
<pre><code>>>> my_bit = '11111110'
>>> feat_1, feat_2, feat_3, feat_4, feat_5, feat_6, feat_7, feat_8 = my_bit
>>> print feat_1, feat_2, feat_3, feat_4, feat_5, feat_6, feat_7, feat_8
1 1 1 1 1 1 1 0
</code></pre>
<p>Now, you... | 0 | 2016-08-29T08:37:47Z | [
"python",
"python-2.7"
] |
Parsing of list of bits in python | 39,201,679 | <p>I have a list of 64 bits.</p>
<pre><code>['11111111', '11111111', '10001111', '11111110', '11011011', '11111111', '01011011', '10000111']
</code></pre>
<p>Here each and every bit represents a feature. If a bit is 1 then that particular feature is supported else not.</p>
<p>Is there any way were i can check the bi... | 1 | 2016-08-29T08:25:52Z | 39,201,876 | <p>I guess you could do something like:</p>
<pre><code>bits = ['11111111', '11111111', '10001111', '11111110', '11011011', '11111111', '01011011', '10000111']
# to produce features mapping dynamically:
# features = {i:"feature " + str(i) for i in range(0,64)}
features = {0: 'feature 0', 1: 'feature 1', 2: 'feature 2'... | 0 | 2016-08-29T08:38:08Z | [
"python",
"python-2.7"
] |
Parsing of list of bits in python | 39,201,679 | <p>I have a list of 64 bits.</p>
<pre><code>['11111111', '11111111', '10001111', '11111110', '11011011', '11111111', '01011011', '10000111']
</code></pre>
<p>Here each and every bit represents a feature. If a bit is 1 then that particular feature is supported else not.</p>
<p>Is there any way were i can check the bi... | 1 | 2016-08-29T08:25:52Z | 39,201,929 | <p>The solution depends on your way to enumerate the features. if you enumerate your features from 0 to 63 it would be something like this:</p>
<pre><code>import math
testdata = ['11111111', '11111111', '10001111', '11111110', '11011011', '11111111', '01011011', '10000111']
def test_feature(data, i):
block =... | 0 | 2016-08-29T08:41:47Z | [
"python",
"python-2.7"
] |
Parsing of list of bits in python | 39,201,679 | <p>I have a list of 64 bits.</p>
<pre><code>['11111111', '11111111', '10001111', '11111110', '11011011', '11111111', '01011011', '10000111']
</code></pre>
<p>Here each and every bit represents a feature. If a bit is 1 then that particular feature is supported else not.</p>
<p>Is there any way were i can check the bi... | 1 | 2016-08-29T08:25:52Z | 39,201,933 | <p>You can make a list of features first.</p>
<pre><code>feat_list = ['f1','f2','f3','f4','f6','f7','f8']
bit_list = ['11111111', '11111111', '10001111', '11111110', '11011011', '11111111', '01011011', '10000111']
</code></pre>
<p>Then make a function. </p>
<pre><code>def extract_feature(bit_string):
result = [... | 0 | 2016-08-29T08:42:11Z | [
"python",
"python-2.7"
] |
Parsing of list of bits in python | 39,201,679 | <p>I have a list of 64 bits.</p>
<pre><code>['11111111', '11111111', '10001111', '11111110', '11011011', '11111111', '01011011', '10000111']
</code></pre>
<p>Here each and every bit represents a feature. If a bit is 1 then that particular feature is supported else not.</p>
<p>Is there any way were i can check the bi... | 1 | 2016-08-29T08:25:52Z | 39,201,935 | <p>I don't know whether I've understood exactly :)</p>
<pre><code>def extract_features(x, f):
return [f[i] for i, elem in enumerate(x) if x[i] == '1']
features = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
x = '11111111'
y = '10101010'
print (extract_features(x, features))
print (extract_features(y, features))... | 0 | 2016-08-29T08:42:25Z | [
"python",
"python-2.7"
] |
Parsing of list of bits in python | 39,201,679 | <p>I have a list of 64 bits.</p>
<pre><code>['11111111', '11111111', '10001111', '11111110', '11011011', '11111111', '01011011', '10000111']
</code></pre>
<p>Here each and every bit represents a feature. If a bit is 1 then that particular feature is supported else not.</p>
<p>Is there any way were i can check the bi... | 1 | 2016-08-29T08:25:52Z | 39,202,060 | <pre><code>def f0(): print "executing feature0"
def f1(): print "executing feature1"
def f2(): print "executing feature2"
def f3(): print "executing feature3"
def f4(): print "executing feature4"
def f5(): print "executing feature5"
def f6(): print "executing feature6"
def f7(): print "executing feature7"
def run_fea... | 0 | 2016-08-29T08:48:15Z | [
"python",
"python-2.7"
] |
How to use str as list index in Python? | 39,201,749 | <p>I read the name and the points of each person from a database and I need to have something like that:</p>
<pre><code>myarray['Alex'] = 18
</code></pre>
<p>I've tried this :</p>
<pre><code>myArray = []
cur.execute("SELECT name, point FROM mytable WHERE name <> '' ")
for row in cur.fetchall():
name = row... | 0 | 2016-08-29T08:30:33Z | 39,201,787 | <p>You need to use a <a href="https://docs.python.org/2/tutorial/datastructures.html#dictionaries" rel="nofollow">dictionary</a>, not an array:</p>
<pre><code>myDict = {} # Here!
cur.execute("SELECT name, point FROM mytable WHERE name <> '' ")
for row in cur.fetchall():
name = row[0]
myDict[name] = row[... | 3 | 2016-08-29T08:33:04Z | [
"python"
] |
Speed up multilple matrix products with numpy | 39,201,783 | <p>In python I have 2 three dimensional arrays: </p>
<p><code>T</code> with size <code>(n,n,n)</code></p>
<p><code>U</code> with size <code>(k,n,n)</code></p>
<p><code>T</code> and <code>U</code> can be seen as many 2-D arrays one next to the other. I need to multiply all those matrices, ie I have to perform the fol... | 2 | 2016-08-29T08:32:40Z | 39,202,073 | <p>Carefully looking into the iterators and how they are involved in those dot product reductions, we could translate all of those into one <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.einsum.html" rel="nofollow"><code>np.einsum</code></a> implementation like so -</p>
<pre><code>H = np.einsum('ij... | 3 | 2016-08-29T08:48:52Z | [
"python",
"numpy"
] |
sqlalchemy orm - change column in a table depending on another table | 39,201,828 | <p>I have a 3 tables </p>
<p>table 1</p>
<pre><code>| id | name |
|:---:|:----:|
| 1 | name |
</code></pre>
<p>table 2</p>
<pre><code>| id | name | status |
|:---:|:----:|:------:|
| 1 | name | True |
</code></pre>
<p>table 3</p>
<pre><code>| id_table1 | id_table2 | datetime | status_table2 |
|:---------... | 2 | 2016-08-29T08:35:41Z | 39,352,326 | <p>solved problem by use ORM Events</p>
| 0 | 2016-09-06T15:06:18Z | [
"python",
"postgresql",
"orm",
"sqlalchemy"
] |
AWS Python Lambda with Oracle - OID Generation Failed | 39,201,869 | <p>I'm trying to connect to an Oracle DB using AWS Lambda Python code.</p>
<p>My code is below:</p>
<pre><code>import sys, os
import cx_Oracle
import traceback
def main_handler(event, context):
# Enter your database connection details here
host = "server_ip_or_name"
port = 1521
sid = "server_sid"
username... | 1 | 2016-08-29T08:37:53Z | 39,207,364 | <p>See the following other question for the resolution to this problem.</p>
<p><a href="http://stackoverflow.com/questions/31338916/sqlplus-remote-connection-giving-ora-21561">sqlplus remote connection giving ORA-21561</a></p>
<p>Effectively the client requires a host name in order to generate a unique identifier whi... | 0 | 2016-08-29T13:20:41Z | [
"python",
"amazon-web-services",
"aws-lambda",
"cx-oracle"
] |
Django display data in a table -- Sort of a table within a table (nested forloop?). Data needs to link as well | 39,201,892 | <p>I'm not sure the best way to explain it so I created an example picture and made up some data:</p>
<p><a href="http://i.stack.imgur.com/HclH8.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/HclH8.jpg" alt="Table"></a></p>
<p>I looked at this post and know I need to use some forloop template stuff: <a href="... | 0 | 2016-08-29T08:38:58Z | 39,202,241 | <blockquote>
<p>"A 'related manager' is a manager used in a one-to-many or many-to-many
related context."
<a href="https://docs.djangoproject.com/en/1.10/ref/models/relations/" rel="nofollow">https://docs.djangoproject.com/en/1.10/ref/models/relations/</a></p>
</blockquote>
<p>I can't see how your relation betw... | 0 | 2016-08-29T09:00:30Z | [
"python",
"django"
] |
Starting and stopping subprocess with Python | 39,202,206 | <p>I'm trying to start and stop a program on a device through <code>MQTT</code> commands, but it's not really working out the way I'm hoping..</p>
<p>To start the process, I'm using:</p>
<pre><code>p = subprocess.Popen(["sh", "process.sh"])
</code></pre>
<p>Which works out fine, it starts the program.</p>
<p>Furthe... | 3 | 2016-08-29T08:57:33Z | 39,202,259 | <p>You have to define p as global</p>
<pre><code>def on_message(...):
global p
</code></pre>
| 1 | 2016-08-29T09:01:20Z | [
"python"
] |
Starting and stopping subprocess with Python | 39,202,206 | <p>I'm trying to start and stop a program on a device through <code>MQTT</code> commands, but it's not really working out the way I'm hoping..</p>
<p>To start the process, I'm using:</p>
<pre><code>p = subprocess.Popen(["sh", "process.sh"])
</code></pre>
<p>Which works out fine, it starts the program.</p>
<p>Furthe... | 3 | 2016-08-29T08:57:33Z | 39,202,385 | <pre><code>p = None
def on_message(client, userdata, msg):
global p
if msg.payload == "start":
p = subprocess.Popen(["sh", "stream.sh"])
if msg.payload == "stop" and p:
p.terminate()
</code></pre>
| 2 | 2016-08-29T09:07:53Z | [
"python"
] |
SwigPyIterator value is always base class | 39,202,265 | <p>I have classes A, B, C in C++. B and C are derived from A. And I have function in c++ returns vector of B and C: like <code>std::vector<A*> getAllObjects()</code>. I use swig to generate Python wrapper. Then I call getAllObjects() in Python as below:</p>
<pre><code>objects = getAllObjects()
for obj in objects... | 0 | 2016-08-29T09:01:37Z | 39,236,767 | <p>You need <em>something</em> more to go on than just a type hierarchy. Typically in a Python/SWIG scenario one of the following is sufficient:</p>
<ol>
<li>a <code>virtual</code> function in the base class (i.e. RTTI)</li>
<li>some member variable or function that somehow identifies the most derived type of a given ... | 2 | 2016-08-30T20:43:29Z | [
"python",
"c++",
"swig"
] |
Django REST Framework how to add context to a ViewSet | 39,202,380 | <p>The ViewSets do everything that I want, but I am finding that if I want to pass extra context to a template (with TemplateHTMLRenderer) then I will have to get at the functions that give responses.. (like list(), create(), etc)</p>
<p>The only way I can see to get into these is to completely redefine them in my Vie... | 0 | 2016-08-29T09:07:34Z | 39,378,225 | <p>Although I disagree with 'pleasedontbelong' in principle, I agree with him on the fact that the extra contextual data ought to be emitted from the serializer. That seems to be the cleanest way since the serializer would be returning a native python data type which all renderers would know how to render.</p>
<p>Here... | 0 | 2016-09-07T20:09:51Z | [
"python",
"django",
"django-rest-framework"
] |
Indexing into the last axis of a 3D array with another 3D array | 39,202,509 | <p>if i have an array <strong>x</strong>, which value is as follow with shape <strong>(2,3,4)</strong>:</p>
<pre><code>array([[[ 0.15845319, 0.57808432, 0.05638804, 0.56237656],
[ 0.73164208, 0.80562342, 0.64561066, 0.15397456],
[ 0.34734043, 0.88063258, 0.4863103 , 0.09881028]],
[[ 0.... | 1 | 2016-08-29T09:14:26Z | 39,203,280 | <p>You could use <a href="http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#combining-advanced-and-basic-indexing" rel="nofollow"><code>fancy-indexing</code></a> -</p>
<pre><code>m,n = y.shape[:2]
out = x[np.arange(m)[:,None,None],np.arange(n)[:,None],y]
</code></pre>
| 1 | 2016-08-29T09:50:31Z | [
"python",
"arrays",
"numpy"
] |
Gunicorn logstash log handler | 39,202,520 | <p>my log config file</p>
<pre><code>[loggers]
keys=root, logstash
[handlers]
keys=console , logstash
[formatters]
keys=generic, access
[logger_root]
level=INFO
handlers=console
[logger_logstash]
level=DEBUG
handlers=logstash
propagate=1
qualname=logstash
[handler_console]
class=StreamHandler
formatter=generic
a... | 0 | 2016-08-29T09:15:00Z | 39,205,441 | <p>Based on <a href="https://github.com/vklochan/python-logstash#using-with-django" rel="nofollow">python-logstash documentation</a>:</p>
<pre><code>[handler_logstash]
class=logstash.TCPLogstashHandler
formatter=generic
host=localhost
port=5959
version=1
</code></pre>
| 0 | 2016-08-29T11:40:10Z | [
"python",
"django",
"logging",
"logstash",
"gunicorn"
] |
Gunicorn logstash log handler | 39,202,520 | <p>my log config file</p>
<pre><code>[loggers]
keys=root, logstash
[handlers]
keys=console , logstash
[formatters]
keys=generic, access
[logger_root]
level=INFO
handlers=console
[logger_logstash]
level=DEBUG
handlers=logstash
propagate=1
qualname=logstash
[handler_console]
class=StreamHandler
formatter=generic
a... | 0 | 2016-08-29T09:15:00Z | 39,264,895 | <pre><code>[loggers]
keys=root, logstash.error, logstash.access
[handlers]
keys=console , logstash
[formatters]
keys=generic, access, json
[logger_root]
level=INFO
handlers=console
[logger_logstash.error]
level=DEBUG
handlers=logstash
propagate=1
qualname=gunicorn.error
[logger_logstash.access]
level=DEBUG
handler... | 0 | 2016-09-01T07:10:32Z | [
"python",
"django",
"logging",
"logstash",
"gunicorn"
] |
Unique dictionary on basis of multiple keys | 39,202,572 | <p>I have a dict with different "types" -> modified and deleted.
I want do unique this.</p>
<pre><code>myDict =
[
{'type': 'deleted', 'target': {'id': u'1', 'foo': {'value': ''}}},
{'type': 'modified', 'target': {'id': u'1', 'foo': {'value': ''}}},
{'type': 'deleted', 'target': {'id': u'1', 'foo': {'value': ''}}},
{... | 0 | 2016-08-29T09:17:19Z | 39,202,755 | <p>Not sure I've understood your question, but, is this what you want?</p>
<pre><code>from collections import defaultdict
import json
my_list = [
{'type': 'deleted', 'target': {'id': u'1', 'foo': {'value': ''}}},
{'type': 'modified', 'target': {'id': u'1', 'foo': {'value': ''}}},
{'type': 'deleted', 'targ... | 1 | 2016-08-29T09:26:38Z | [
"python",
"dictionary"
] |
how to auto check check box by entering value in other field? | 39,202,584 | <p>I have made a module for hotel room management and I want to check room availability in Python. I have taken on checkbox named <code>available = fields.Boolean()</code>. Now, I want that it will be automatically checked when I enter check_in_time. so, how can I do this? I have taken
<code>check_in_time=fields. Date... | 0 | 2016-08-29T09:17:58Z | 39,205,130 | <p>Your code is right. The value will be saved upon "Save" action in the client. <code>onchange</code> will save the value virtually at clientside. <code>depends</code> will instead write directly into database. But <code>onchange</code> should be enough here.</p>
| 1 | 2016-08-29T11:25:44Z | [
"python",
"openerp"
] |
Numpy rolling window over 2D array, as a 1D array with nested array as data values | 39,202,636 | <p>When using <code>np.lib.stride_tricks.as_strided</code>, how can I manage 2D a array with the nested arrays as data values? Is there a preferable <strong>efficient</strong> approach?</p>
<p>Specifically, if I have a 2D <code>np.array</code> looking as follows, where each data item in a 1D array is an array of lengt... | 0 | 2016-08-29T09:20:44Z | 39,203,586 | <p>IIUC you could do something like this -</p>
<pre><code>def rolling_window2D(a,n):
# a: 2D Input array
# n: Group/sliding window length
return a[np.arange(a.shape[0]-n+1)[:,None] + np.arange(n)]
</code></pre>
<p>Sample run -</p>
<pre><code>In [110]: a
Out[110]:
array([[ 1, 2],
[ 3, 4],
... | 1 | 2016-08-29T10:05:19Z | [
"python",
"arrays",
"performance",
"numpy",
"sliding-window"
] |
Numpy rolling window over 2D array, as a 1D array with nested array as data values | 39,202,636 | <p>When using <code>np.lib.stride_tricks.as_strided</code>, how can I manage 2D a array with the nested arrays as data values? Is there a preferable <strong>efficient</strong> approach?</p>
<p>Specifically, if I have a 2D <code>np.array</code> looking as follows, where each data item in a 1D array is an array of lengt... | 0 | 2016-08-29T09:20:44Z | 39,210,101 | <p>What was wrong with your <code>as_strided</code> trial? It works for me.</p>
<pre><code>In [28]: x=np.arange(1,11.).reshape(5,2)
In [29]: x.shape
Out[29]: (5, 2)
In [30]: x.strides
Out[30]: (16, 8)
In [31]: np.lib.stride_tricks.as_strided(x,shape=(3,3,2),strides=(16,16,8))
Out[31]:
array([[[ 1., 2.],
[... | 1 | 2016-08-29T15:38:26Z | [
"python",
"arrays",
"performance",
"numpy",
"sliding-window"
] |
Can't run crontab without excecuting the programm once | 39,202,652 | <p>I wrote a <code>script.py</code> which should open a <code>Tkinter</code> window on a raspberry:</p>
<pre><code>from Tkinter import *
import turtle
import math
import time
import sys
import os
root = Tk()
root.config(cursor="none")
ccanvas = Canvas(root, width = 800, height = 480)
root.overrideredirect(1)
turtle_... | 1 | 2016-08-29T09:21:29Z | 39,221,366 | <p>Finally solved my problem. Everything was fine, but i was using the <code>root crontab</code>. The <code>root crontab</code> was not able to find the display, before the display was not mentioned/used by another command. I transferred my <code>cronjobs</code> to the "normal" <code>crontab</code> and everything works... | 0 | 2016-08-30T07:29:39Z | [
"python",
"tkinter",
"crontab",
"raspberry-pi3"
] |
I got an error while using "heroku open" command | 39,202,673 | <p>I'm created a python app on heroku.
After pushing I gave <code>heroku open</code> command and I got an error on browser like this</p>
<pre><code>Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your... | 0 | 2016-08-29T09:22:50Z | 39,210,363 | <p>It seems that <code>gunicorn</code> is missing. You should add <code>gunicorn</code> to your <code>requirements.txt</code> and deploy your project again to Heroku. </p>
| 0 | 2016-08-29T15:53:20Z | [
"python",
"git",
"heroku"
] |
Permutations of a list split into two strings | 39,202,734 | <p>Using the following list as an example :</p>
<pre><code>a = ["cat", "dog", "mouse", "rat", "horse"]
</code></pre>
<p>I can get all permutations using <code>itertools.permutations</code></p>
<pre><code>print (list(itertools.permutations(a, 2)))
[('cat', 'dog'), ('cat', 'mouse'), ('cat', 'rat'), ('cat', 'horse'), ... | 0 | 2016-08-29T09:25:30Z | 39,202,863 | <p>Slicing input list and joining string can do a job for you.</p>
<pre><code>seq = ["cat", "dog", "mouse", "rat", "horse"]
seq2 = [[' '.join(seq[:i+1]), ' '.join(seq[i+1:])] for i in range(len(seq)-1)]
# [['cat', 'dog mouse rat horse'], ['cat dog', 'mouse rat horse'], ['cat dog mouse', 'rat horse'], ['cat dog mouse r... | 1 | 2016-08-29T09:31:26Z | [
"python"
] |
Permutations of a list split into two strings | 39,202,734 | <p>Using the following list as an example :</p>
<pre><code>a = ["cat", "dog", "mouse", "rat", "horse"]
</code></pre>
<p>I can get all permutations using <code>itertools.permutations</code></p>
<pre><code>print (list(itertools.permutations(a, 2)))
[('cat', 'dog'), ('cat', 'mouse'), ('cat', 'rat'), ('cat', 'horse'), ... | 0 | 2016-08-29T09:25:30Z | 39,202,955 | <p>This would provide the desired output from the initial question:</p>
<pre><code>a = ["cat", "dog", "mouse", "rat", "horse"]
print[[" ".join(a[0:i]), " ".join(a[i:])] for i in range(1, len(a))]
</code></pre>
| 2 | 2016-08-29T09:35:21Z | [
"python"
] |
Permutations of a list split into two strings | 39,202,734 | <p>Using the following list as an example :</p>
<pre><code>a = ["cat", "dog", "mouse", "rat", "horse"]
</code></pre>
<p>I can get all permutations using <code>itertools.permutations</code></p>
<pre><code>print (list(itertools.permutations(a, 2)))
[('cat', 'dog'), ('cat', 'mouse'), ('cat', 'rat'), ('cat', 'horse'), ... | 0 | 2016-08-29T09:25:30Z | 39,202,959 | <p>You may use the below code to achieve this:</p>
<pre><code>>>> a = ["cat", "dog", "mouse", "rat", "horse"]
>>> my_perm_list = []
>>> for i in range(len(a)-1):
... my_perm_list.append((' '.join(a[:i+1]), ' '.join(a[i+1:])))
...
>>> my_perm_list
[('cat', 'dog mouse rat horse'),... | 1 | 2016-08-29T09:35:27Z | [
"python"
] |
Python automate key press of a QtGUI | 39,202,870 | <p>I have a python script with the section below:</p>
<pre><code>for index in range(1,10):
os.system('./test')
os.system('xdotool key Return')
</code></pre>
<p>What I want to do is to run the executable ./test, which brings up a QtGUI. In this GUI, a key press prompt buton comes up. I want to automate this key... | 0 | 2016-08-29T09:31:45Z | 39,204,653 | <p><code>os.system</code> doesn't return until the child process exits.
You need <code>subprocess.Popen</code>.
It's also a good idea to <code>sleep</code> a while before sending keystrokes
(it may take some time for the child process to get ready to accept user input):</p>
<pre><code>from subprocess import Popen
from... | 0 | 2016-08-29T11:01:54Z | [
"python",
"automation",
"qtgui",
"xdotool"
] |
Cannot initialize python function | 39,202,874 | <p>I have (re)wrote a back-test function in python using pandas</p>
<pre><code>def backtest(positions,price,initial_capital=10000):
#creating protfolio
portfolio =positions*price['price']
pos_diff=positions.diff()
#creating holidings
portfolio['holidings']=(positions*price['price'].sum(axis=1)... | 0 | 2016-08-29T09:31:55Z | 39,202,924 | <p>missing trailing parenthesis on line before:</p>
<pre><code>portfolio['holidings']=(positions*price['price'].sum(axis=1)
^ need ) here
</code></pre>
<p>should be:</p>
<pre><code>portfolio['holidings']=(positions*price['price']).sum(axis=1)
</code></pre>
<p>Whenever ... | 2 | 2016-08-29T09:34:19Z | [
"python",
"pandas"
] |
How to set result of future\add to queue from another thread in Cython? | 39,202,891 | <p>I have C++ dll which works with multiple threads.
So I wrapped this library with Cython and created special receiver callback-function, which must adds some results to asyncio.Queue.</p>
<pre><code>cdef void __cdecl NewMessage(char* message) nogil:
</code></pre>
<p>I marked it as nogil, this callback calls from an... | 1 | 2016-08-29T09:32:47Z | 39,204,446 | <p>This is a bit of a guess but you probably have a Cython/C/C++ loop running that's holding the GIL and never releasing it. The callback is then forced for wait forever for it.</p>
<p>In normal Python code the GIL is released every few instructions if another thread is waiting for it. In Cython that doesn't happen au... | 1 | 2016-08-29T10:51:01Z | [
"python",
"c++",
"multithreading",
"cython",
"gil"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.