title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
How to use css styling in html with multiple directories?
39,282,466
<p>I'm trying to make a simple webapp using Google Appengine with Python, HTML, and CSS. I know that to put a .css styling from separate file into html one should use a link tag, however I can't seem to get it to work. Here is the general directory config:</p> <p>Main<br> ├── app.yaml<br> ├── files.py<br> ...
0
2016-09-01T23:54:16Z
39,282,934
<p>You need a url handler in your app.yaml:</p> <pre><code>- url: /Static static_dir: Static/ secure: optional </code></pre> <p>I am not sure about your directory tree. If Static is nested inside Folder, then it would be:</p> <pre><code>- url: /Folder/Static static_dir: Folder/Static/ secure: optional </c...
0
2016-09-02T01:05:54Z
[ "python", "html", "css", "google-app-engine" ]
Passing an object method to an external function in python
39,282,483
<p>Ok, so the task Im trying to accomplish is a bit dense to post in full here, but Ive written an example that shows what Im trying to do.</p> <pre><code>import random class Dog: def __init__(self, height, weight, length, age): self.Height = height self.Weight = weight self.Length = leng...
1
2016-09-01T23:56:54Z
39,282,692
<p>FIrst of all : methods of instance are named <strong>methods</strong> because they are in fact <strong>bound function</strong> thats mean python is automatically passing to them it first param which is instance on which You call them. So if you are acessing method from class You must provide this <em>self</em> by yo...
1
2016-09-02T00:29:35Z
[ "python", "methods" ]
Python list to csv throws error: iterable expected, not numpy.int64
39,282,516
<p>I want to write a list into a csv,When trying to do it I receive the below error </p> <pre><code>out.writerows(fin_city_ids) _csv.Error: iterable expected, not numpy.int64 </code></pre> <p>My code is as below </p> <pre><code>org_id.append([pol_id,bldest_id]) fin_ids=list(org_city_id['org_id'].unique()) print(fin_...
1
2016-09-02T00:00:34Z
39,282,731
<p>You can get this done in many ways. But if you wish to <code>writerows</code> from the <code>csv</code> module, then you will have to turn your list <code>fin_ids</code> into a sequence of lists first:</p> <pre><code>fin_ids = [1002774, 0, 1000702, 1000339, 1001620, 1000710, 1000202, 1003143, 147897, 31018,...
3
2016-09-02T00:36:51Z
[ "python", "csv" ]
python importing file on virtual environment
39,282,612
<p>I am writing a web app using python3, venv and c9.io PAAS. I have the following structure of my code:</p> <pre><code>batch_runner.py logic/ __init__.py parsers/ __init__.py time_parser.py abstract_parser.py </code></pre> <p>here <code>batch_runner</code> imports <code>abstract_parse...
2
2016-09-02T00:14:33Z
39,283,243
<p>Change this:</p> <pre><code>from abstract_parser import abstract </code></pre> <p>To</p> <pre><code>from logic.parsers.abstract_parser import abstract </code></pre>
2
2016-09-02T01:56:32Z
[ "python", "python-venv", "c9.io" ]
python importing file on virtual environment
39,282,612
<p>I am writing a web app using python3, venv and c9.io PAAS. I have the following structure of my code:</p> <pre><code>batch_runner.py logic/ __init__.py parsers/ __init__.py time_parser.py abstract_parser.py </code></pre> <p>here <code>batch_runner</code> imports <code>abstract_parse...
2
2016-09-02T00:14:33Z
39,283,449
<p>Do read about importing from the <a href="https://docs.python.org/2/tutorial/modules.html#packages" rel="nofollow">python documentation</a> on modules.</p> <p>In this case, one possible solution is to use relative imports inside your package:</p> <p>That is, in <code>logic/parsers/__init__.py</code>, use:</p> <pr...
2
2016-09-02T02:27:10Z
[ "python", "python-venv", "c9.io" ]
JSON dump for User defined class in python
39,282,652
<p>Here is how I want my data to be : (key=name, value=[dob,[misc1, misc2,..]])</p> <pre><code> # my sample code inputNames = [ ('james', ['1990-01-19', ['james1', 'james2', 'james3'] ]), ('julie', ['1991-08-07', ['julie1', 'julie2'] ]), ('mikey', ['1989-01-23', ['mikey1'] ]), ('sarah', ['1988-02-05', ['sarah1', 's...
1
2016-09-02T00:22:57Z
39,282,881
<p>Before you can dump to <code>json</code> you need explicitly convert your data to a serializable type like <code>dict</code> or <code>list</code>. You could do this using a list comprehension:</p> <pre><code>&gt;&gt;&gt; d = [{'key':ea.nm, 'value':[ea.details.dob, ea.details]} for ea in emps] &gt;&gt;&gt; json.dump...
0
2016-09-02T00:57:52Z
[ "python", "json", "dictionary", "dump", "user-defined-types" ]
Parsing key-value log in Python
39,282,736
<p>I have a system log that looks like the following:</p> <pre><code>{ a = 1 b = 2 c = [ x:1, y:2, z:3, ] d = 4 } </code></pre> <p>I want to parse this in Python into a dictionary object with = splitting key-value pairs. At the same time, the array that is e...
0
2016-09-02T00:37:16Z
39,283,017
<p>There is probably a better answer, but I would take advantage of all your dictionary keys being at the same indentation level. There's not an obvious way to be to do this with newline splitting, JSON loading, or that sort of thing since the list structure is a bit weird (it seems like a cross between a list and a di...
1
2016-09-02T01:19:52Z
[ "python" ]
Parsing key-value log in Python
39,282,736
<p>I have a system log that looks like the following:</p> <pre><code>{ a = 1 b = 2 c = [ x:1, y:2, z:3, ] d = 4 } </code></pre> <p>I want to parse this in Python into a dictionary object with = splitting key-value pairs. At the same time, the array that is e...
0
2016-09-02T00:37:16Z
39,283,252
<p>This could be pretty easily simplified to YAML. <code>pip install pyyaml</code>, then set up like so:</p> <pre><code>import string, yaml data = """ { a = 1 b = 2 c = [ x:1, y:2, z:3, ] d = 4 } """ </code></pre> <p>With this setup, you can use the followi...
0
2016-09-02T01:57:15Z
[ "python" ]
How can I tell/specify which version of the postgres client/libs psycopg2 is using?
39,282,745
<p>I have psycopg2 for a python program, but the computer the program is running on has two version of postgres installed: 9.2 in the 'main' system, and 9.5 in /opt. The postgres DB is hosted elsewhere, and is 9.5. The 9.2 psql client will still happily connect to the 9.5 DB, with a warning. How can I tell which versio...
0
2016-09-02T00:39:13Z
39,286,677
<p>Should be able to force it by putting the 9.5 client binaries at the start of the path for the user that is running your python program. To test:</p> <pre><code>export PATH=/opt/&lt;path-to-your-9.5&gt;;$PATH which psql #ensure the 9.5 one is returned psql -h &lt;remote-host&gt; -p &lt;remote-port&gt; -U &lt;user&g...
0
2016-09-02T07:28:56Z
[ "python", "postgresql", "psycopg2" ]
How can I tell/specify which version of the postgres client/libs psycopg2 is using?
39,282,745
<p>I have psycopg2 for a python program, but the computer the program is running on has two version of postgres installed: 9.2 in the 'main' system, and 9.5 in /opt. The postgres DB is hosted elsewhere, and is 9.5. The 9.2 psql client will still happily connect to the 9.5 DB, with a warning. How can I tell which versio...
0
2016-09-02T00:39:13Z
39,600,423
<p>In psycopg 2.6.x <code>ldd</code> is the way to go. In 2.7 there will be a function to return that information, but it's not been released yet.</p>
0
2016-09-20T17:34:33Z
[ "python", "postgresql", "psycopg2" ]
Restore postrgres without ending connections
39,282,825
<p>I run a number of queries for adhoc analysis against a postgres database. Many times I will leave the connection open through the day instead of ending after each query.</p> <p>I receive a postgres dump over scp through a shell script every five minutes and I would like to restore the database without cutting the c...
0
2016-09-02T00:49:32Z
39,286,433
<p>One of the few activities that you cannot perform while a user is connected is dropping the database.<br> So &ndash; if that is what you are doing during restore &ndash; you'll have to change your approach. Don't drop the database (don't use the <code>-C</code> option in <code>pg_dump</code> or <code>pg_restore</cod...
1
2016-09-02T07:16:04Z
[ "python", "database", "postgresql", "restore" ]
Python error in Mac OS X 10.11.6
39,282,848
<p>I have homebrew installed as well as the system python under 10.11.6. When I try to use pip (or pip3) pip does not run and gives the following error. Does anyone have any suggestions as to how to fix it?</p> <p>Here are the error messages</p> <pre><code>echo $PYTHON_PATH /Users/paulfons/ase: axion:~ paulfons$ ech...
-1
2016-09-02T00:53:55Z
39,283,104
<p>You can try to reinstall your pip, or upgrade it using easyinstall. On your MacBook you can run this command on your terminal:</p> <pre><code>sudo easy_install-3.5 --upgrade pip </code></pre>
0
2016-09-02T01:32:40Z
[ "python" ]
Django TypeError: allow_migrate() got an unexpected keyword argument 'model_name'
39,282,860
<p>So I copied over my Django project to a new server, replicated the environment and imported the tables to the local mysql database.</p> <p>But when I try to run makemigrations it gives me the TypeError: allow_migrate() got an unexpected keyword argument 'model_name'</p> <p>This is the full stack trace:</p> <pre><...
1
2016-09-02T00:55:49Z
39,408,774
<p>I meet the same problem when i move from 1.6.* to 1.10.Finally i found the problem cause by the <strong>DATABASE_ROUTERS</strong> </p> <p>the old version i write like this </p> <pre><code>class OnlineRouter(object): # ... def allow_migrate(self, db, model): if db == 'myonline': return ...
2
2016-09-09T09:52:52Z
[ "python", "mysql", "django" ]
Unable to install Snap7 Library on Ubuntu 16.04 (64-bit)
39,282,877
<p>I'm new to Linux based OS's (and very new to Snap7). Trying to install Snap7 library on Ubuntu machine following instructions at - <a href="http://python-snap7.readthedocs.io/en/latest/installation.html" rel="nofollow">http://python-snap7.readthedocs.io/en/latest/installation.html</a>. However I'm getting the follow...
0
2016-09-02T00:57:34Z
39,282,917
<p>You missed this part on the very page you linked to:</p> <pre><code>If you are using Ubuntu you can use the Ubuntu packages from our launchpad PPA. To install: $ sudo add-apt-repository ppa:gijzelaar/snap7 $ sudo apt-get update $ sudo apt-get install libsnap71 libsnap7-dev </code></pre> <p>Execute all three comma...
1
2016-09-02T01:03:13Z
[ "python", "linux", "ubuntu", "scada" ]
Heroku/python failed to detect set buildpack
39,282,911
<p>I'm a Django newbie, I created an app and want to deploy it using Heroku. However, when I do <code>git push heroku master</code> (I follow Heroku's getting started), this is what I got:</p> <pre><code>Counting objects: 36, done. Delta compression using up to 4 threads. Compressing objects: 100% (33/33), done. Writi...
1
2016-09-02T01:02:11Z
39,283,046
<p>You need to add a <code>requirements.txt</code> file which contains all of the modules required to run your application.</p> <p>You can do <code>pip freeze &gt; requirements.txt</code> to freeze all of your modules into a file. I would only recommend doing this if you're using a virtualenv because otherwise it will...
2
2016-09-02T01:23:34Z
[ "python", "django", "git", "heroku", "deployment" ]
Python get bash double-tab completion output
39,282,925
<p>I am programming a Ros interface in python, and I would like to be able to select the node I want to run from a list showing all available nodes once I choose a package.</p> <p>In other words I would like to create the list of all nodes contained in a package getting the output I would have in the terminal if I typ...
0
2016-09-02T01:04:09Z
39,298,132
<p>Finally I solved this by myself, I went right throw Ros own code and found out how it generates the bash completion output.</p> <p>My code now is like this:</p> <pre><code>from subprocess import Popen, PIPE package = "&lt;package&gt;" comm = str("catkin_find --first-only --without-underlays --libexec " + package)....
0
2016-09-02T17:46:32Z
[ "python", "bash", "subprocess", "ros" ]
NoSuchElement exception with Selenium even after using Wait and checking page_soure
39,282,930
<p>I have this simple scraper that I am running. I am trying to scrape the search results for letter q from sam.gov:</p> <pre><code>from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditio...
0
2016-09-02T01:05:28Z
39,283,907
<p>Id locator of the element looks like dynamically generated, you should try some different locator.</p> <p>You can try using <code>css_selector</code> as below:-</p> <pre><code>driver.find_element_by_css_selector("a.button[title='Search Records']").click() </code></pre> <p>Or using <code>WebDriverWait</code> as:-<...
0
2016-09-02T03:33:21Z
[ "python", "selenium", "exception", "phantomjs" ]
Pandas parallel groupBy consumes tons of memory
39,282,945
<p>I have a medium sized file (~300MB) containing a list of individuals (~300k) and actions they performed. I'm trying to apply an operation for each individuals using <code>groupBy</code> and the paralellized version of <code>apply</code> described <a href="http://stackoverflow.com/questions/26187759/parallelize-apply...
2
2016-09-02T01:07:59Z
39,283,764
<p>Some comments and then the solution I've found:</p> <ul> <li><p>I've tried <code>dask</code> and it didn't made much difference. I guess it is because the file is not big enough to use the secondary memory.</p></li> <li><p>The memory performance improves significantly if you perform the garbage collection inside th...
0
2016-09-02T03:12:46Z
[ "python", "pandas", "group-by" ]
Pandas parallel groupBy consumes tons of memory
39,282,945
<p>I have a medium sized file (~300MB) containing a list of individuals (~300k) and actions they performed. I'm trying to apply an operation for each individuals using <code>groupBy</code> and the paralellized version of <code>apply</code> described <a href="http://stackoverflow.com/questions/26187759/parallelize-apply...
2
2016-09-02T01:07:59Z
39,284,194
<p>Try this (<strong>without</strong> parallelization):</p> <pre><code>In [87]: df Out[87]: ID Timestamp Action 0 1 0 A 1 1 10 B 2 1 20 C 3 2 0 B 4 2 15 C In [88]: df.set_index('ID').astype(str).sum(axis=1).groupby(level=0).sum().to_fram...
2
2016-09-02T04:13:14Z
[ "python", "pandas", "group-by" ]
Qt with PyQt. Is it possible to view the object hierarchy of a running window?
39,282,963
<p>I am currently working on a project using PyQt5, and am using several windows that will dynamically change their widgets, depending on the data I supply.</p> <p>For the purposes of debugging, would it be possible to view the object structure of a window as it is running? I am using Qt Designer to design many of my ...
0
2016-09-02T01:11:28Z
39,283,595
<p>I don't know if it's possible to do this in Qt Creator while the application is running, but you can definitely insert statements into the source code which will print out the entire object hierarchy. Just pick your base object and recursively print the output of <code>QWidget.children()</code>.</p> <p>One problem ...
0
2016-09-02T02:47:10Z
[ "python", "qt", "pyqt" ]
Flask data storage in session with javascript or jquery
39,282,989
<p>I have a lot of data (about 30 columns) from different HTML pages to store:</p> <ol> <li>a string (can be retrieved by id) randomly generated with Javascript</li> <li>a form with data from user input</li> <li>a list of values generated with Javascript</li> </ol> <p>With Flask framework, most of the sessions are do...
0
2016-09-02T01:15:45Z
39,283,069
<p>You can use <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API" rel="nofollow">web storage</a>. There are two kinds:</p> <p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage" rel="nofollow">Session Storage</a>:</p> <blockquote> <p>Maintains a separate storage ...
1
2016-09-02T01:27:37Z
[ "javascript", "jquery", "python", "flask", "session-cookies" ]
Python checking sql database column for value
39,282,991
<p>How would one check an entire column in sqlite database for a given value and if found set a variable to true</p> <p>something like</p> <pre><code>hasvalue = 'false' cur = con.cursor() cur.execute("SELECT id FROM column WHERE hasvalue = '1' LIMIT 1;") ***IF execute returned rows set hasvalue = true here*** if ha...
0
2016-09-02T01:16:18Z
39,283,198
<p>I'm a little confused by your question. The SQL query suggests that you are using a <em>table</em> named <code>column</code>? If I can ignore that and assume you have a table named <code>test</code> which has columns <code>id</code> (an int) and <code>name</code> (a string). Then the query:</p> <pre><code>SELECT id...
0
2016-09-02T01:50:08Z
[ "python", "database", "sqlite" ]
Using python in math
39,282,995
<p>Ok so i want to solve this equation through python but cant figure out what to do! I tried using for loops but that didn't work so well</p> <p>Im new to python so can anyone suggest what I should do</p> <pre><code>RWBG-(WBR^2)-WBR-(BR^3)-(3BR^2)+2BR-(R^3)-(6R^2)+11R-6 = 0 </code></pre> <p>R,W,B,G are different va...
-2
2016-09-02T01:16:39Z
39,283,050
<p>Assuming each letter is a variable, and that you simply want to evaluate the expression, an easy Python script would be:</p> <pre><code>def equation (R,W,B,G,R): return R*W*B*G - W*B*(R**2) - W*B*R - B(R**3) - 3*B*(R**2) + 2*B*R - R**3 - 6*(R**2) + 11*R - 6 </code></pre>
1
2016-09-02T01:23:53Z
[ "python", "math", "equation", "polynomials", "quadratic" ]
Why is this Haskell code so slow?
39,283,047
<p>I'm kind of new to Haskell and tried making a scrabble solver. It takes in the letters you currently have, finds all permutations of them and filters out those that are dictionary words. The code's pretty simple: </p> <pre><code>import Data.List main = do dict &lt;- readFile "words" letters &lt;- getLin...
6
2016-09-02T01:23:37Z
39,283,078
<p>Checking if <code>x</code> is an element of <code>dictWords</code> is likely to be very slow. I would assume that your similar python implementation stores <code>dictWords</code> in a set or sorted vector (using binary search in the latter case)? Seems like you probably want to do the same here.</p> <p>Using <a h...
5
2016-09-02T01:28:50Z
[ "python", "haskell", "optimization", "language-comparisons" ]
Why is this Haskell code so slow?
39,283,047
<p>I'm kind of new to Haskell and tried making a scrabble solver. It takes in the letters you currently have, finds all permutations of them and filters out those that are dictionary words. The code's pretty simple: </p> <pre><code>import Data.List main = do dict &lt;- readFile "words" letters &lt;- getLin...
6
2016-09-02T01:23:37Z
39,283,994
<blockquote> <p>I'm kind of new to Haskell and tried making a scrabble solver.</p> </blockquote> <p>You can substantially improve things by using a better algorithm.</p> <p>Instead of testing every permutation of the input letters, if you sort them first you can make only one dictionary lookup and get all of the po...
7
2016-09-02T03:44:02Z
[ "python", "haskell", "optimization", "language-comparisons" ]
Division & Modulo Operator
39,283,112
<p>I just started learning how to code, and I've been assigned a problem that I've been stuck on for many hours now and was hoping I could receive some hints at the very least to solve the problem. The main point of this exercise is to practice division and modulus. We can use basic statements, but nothing fancy like ...
0
2016-09-02T01:34:17Z
39,313,730
<p>This problem would be easier if everything were countrd from 0 instead of from 1. That is, if the row and unit numbers were 0 to 4 instead of 1 to 5 and if the input value were 0 to 24 instead of 1 to 25.</p> <p>In that case, we'd just write:</p> <pre><code>row = shelfNumber / 5 unit = shelfNumber % 5 </code></pre...
1
2016-09-04T05:12:37Z
[ "python", "python-2.x", "division", "modulo", "modulus" ]
Displaying text when a button is clicked in python
39,283,206
<p>Here i create a 9 buttons and when button is clicked hello must be displayed on the button....i know its simple but i'm not getting where did i get wrong.Thanks in advance. Here's the code</p> <pre><code>from Tkinter import * class Design: def __init__(self): self.button={} self.root=Tk() self.root.titl...
1
2016-09-02T01:51:40Z
39,286,634
<p>Right now i can't test the your code, but i see the problem here: <code>self.button[i,j]=Button(self.root,text="*",padx=12,pady=12).grid(row=i,column=j)</code>! You are calling <code>.grid()</code>, which has no return. So your self.button[i,j] is <code>None</code>!</p> <p>Just do it in 2 lines: <code>self.button[i...
0
2016-09-02T07:26:28Z
[ "python", "button", "tkinter" ]
Using Python to kick off Python subprocesses without delay
39,283,306
<p>I want to launch multiple instances of a python script using <code>subprocess.call</code>, but the kick off script waits for each to complete. How do I prevent it from waiting from going one by one, without waiting for the previous job to complete?</p> <pre><code>step = 5 for n in range(5, 11, step): subprocess...
1
2016-09-02T02:05:54Z
39,283,326
<p>From the <code>subprocess</code> documentation (emphasis mine):</p> <ul> <li>Run command with arguments. <strong>Wait for command to complete</strong>, then return the returncode attribute.</li> </ul> <p>Consider using <a href="https://docs.python.org/2.6/library/subprocess.html#subprocess.Popen" rel="nofollow"><c...
1
2016-09-02T02:09:30Z
[ "python", "concurrency", "subprocess" ]
Using Python to kick off Python subprocesses without delay
39,283,306
<p>I want to launch multiple instances of a python script using <code>subprocess.call</code>, but the kick off script waits for each to complete. How do I prevent it from waiting from going one by one, without waiting for the previous job to complete?</p> <pre><code>step = 5 for n in range(5, 11, step): subprocess...
1
2016-09-02T02:05:54Z
39,283,351
<p>That's the documented behaviour of <a href="https://docs.python.org/3/library/subprocess.html#subprocess.call" rel="nofollow"><code>subprocess.call()</code></a> so you can't use it that way. Instead you can use <a href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen" rel="nofollow"><code>subproce...
3
2016-09-02T02:13:21Z
[ "python", "concurrency", "subprocess" ]
Python to view and manipulate web page
39,283,333
<p>I want to use Python to edit an element on a webpage. I've been trying to figure out how to use selenium to do that. Right now, this is what I have so far...</p> <pre><code>driver = webdriver.Chrome() driver.get('https://www.website.com') elem = driver.find_element_by_id('id') print(elem) </code></pre> <p>Readin...
0
2016-09-02T02:10:29Z
39,283,359
<p>Selenium isn't a tool to edit elements on website. It used commonly to automate tests imitating user behavior on website. </p>
2
2016-09-02T02:14:59Z
[ "python", "google-chrome", "selenium" ]
how to understand axis = 0 or 1 in Python
39,283,339
<p>From the documentation, "the first running vertically downwards across rows (axis 0), and the second running horizontally across columns (axis 1)" And the code is </p> <pre><code>df1 = pd.DataFrame({"x":[1, 2, 3, 4, 5], "y":[3, 4, 5, 6, 7]}, index=['a', 'b', 'c', 'd', 'e']) ...
1
2016-09-02T02:11:13Z
39,283,657
<p>Interpret axis=0 to apply the algorithm down each column, or to the row labels (the index).. A more detailed schema <a href="http://stackoverflow.com/a/25774395/624829">here</a>.</p> <p>If you apply that general interpretation to your case, the algorithm here is <code>concat</code>. Thus for axis=0, it means: </p> ...
0
2016-09-02T02:57:03Z
[ "python", "pandas", "axis" ]
how to understand axis = 0 or 1 in Python
39,283,339
<p>From the documentation, "the first running vertically downwards across rows (axis 0), and the second running horizontally across columns (axis 1)" And the code is </p> <pre><code>df1 = pd.DataFrame({"x":[1, 2, 3, 4, 5], "y":[3, 4, 5, 6, 7]}, index=['a', 'b', 'c', 'd', 'e']) ...
1
2016-09-02T02:11:13Z
39,284,007
<p>Data:</p> <pre><code>In [55]: df1 Out[55]: x y a 1 3 b 2 4 c 3 5 d 4 6 e 5 7 In [56]: df2 Out[56]: y z b 1 9 c 3 8 d 5 7 e 7 6 f 9 5 </code></pre> <p>Concatenated <strong>horizontally</strong> (axis=1), using <strong>index elements</strong> found in both DFs (aligned by indexes for joi...
0
2016-09-02T03:47:10Z
[ "python", "pandas", "axis" ]
Keras: how to record validation loss
39,283,358
<p>Note: this is a <a href="http://stackoverflow.com/questions/37664783/how-to-plot-a-learning-curve-for-a-keras-experiment">duplicate question</a>, but I'm not looking for the answer. Rather, how better to find the answer myself. </p> <p>How do I record loss, training accuracy, testing loss and testing accuracy, from...
0
2016-09-02T02:14:51Z
39,291,417
<p>As detailed in the doc <a href="https://keras.io/models/sequential/#fit" rel="nofollow">https://keras.io/models/sequential/#fit</a>, when you call <code>model.fit</code>, it returns a <code>callbacks.History</code> object. You can get loss and other metrics from it:</p> <pre><code>... train_history = model.fit(X_tr...
2
2016-09-02T11:35:22Z
[ "python", "keras" ]
Python script to convert strings from hex to bin contained in a txt
39,283,382
<p>I am looking for a simple script possibly in python that can: -convert a list of 4 bytes Hexadecimal strings to Decimal</p> <p>Something that would look like" script.py infile.txt outfile.txt</p>
-8
2016-09-02T02:17:47Z
39,284,783
<pre><code>filename = "infile.txt" with open(filename, 'r') as f: content = f.read() out = int(content, 16) f = open('outfile.txt', 'w') f.write(str(out)) f.close() </code></pre> <p>This is what I came up with so far... It works well if infile contains only one line... I still need to figure out to do it line by ...
2
2016-09-02T05:20:20Z
[ "python", "hex", "decimal" ]
How to move the turtle where I want to go
39,283,423
<p>So I'm trying to complete this question on my programming course, and it involves drawing stuff with the turtle. Basically, I'm trying to draw a city skyline, so the program needs to read multiple inputs from the user on one line (the heights of the buildings). I can get it to draw a building, but it only uses the l...
-2
2016-09-02T02:23:03Z
39,283,459
<p>Take out your second <code>for</code> loop:</p> <pre><code>from turtle import * h = input("Heights: ") y = h.split() nxc = -200 #Code for the background fillcolor("darkslategray") for i in y: nyc = i pencolor("black") pendown() begin_fill() goto(nxc, nyc) right(90) forward(20) right(90) forward(...
-1
2016-09-02T02:27:45Z
[ "python", "turtle-graphics" ]
Conway's game of life rules not operating properly in python
39,283,491
<p>I am attempting to do a list based implementation of Conway's game of life without using any add-ons or lists of lists in python 3.5.2. The issue I am running into now is that the number of "neighbors" that each point has is incorrect. I have left my print statement in the code below. In this example, an occupied ce...
0
2016-09-02T02:32:30Z
39,285,213
<p>I found two mistakes:</p> <ol> <li>At <code>board = editPoint(x,y,board, rows)</code> you should pass <code>columns</code> instead of <code>rows</code>.</li> <li><p>In <code>nextTurn</code>, <code>prevBoard = board</code> doesn't do what you think it does. An assignment does not create a copy of the list. Both vari...
0
2016-09-02T05:55:19Z
[ "python", "list", "conways-game-of-life" ]
Save and reset parameters of multilayer networks in theano
39,283,560
<p>We can save and load object in python using <code>six.moves.cPickle</code>. </p> <p>I saved and reset the parameters for LeNet using the following code.</p> <pre><code># save model # params = layer3.params + layer2.params + layer1.params + layer0.params import six.moves.cPickle as pickle f = file('best_cnnmodel.sa...
0
2016-09-02T02:41:18Z
39,284,235
<p>You can consider to use json format. It is human readable and easy to work with.</p> <p>Here is an example:</p> <h1>Prepare the data</h1> <pre><code>import json data = { 'L1' : { 'W': layer1.W, 'b': layer1.b }, 'L2' : { 'W': layer2.W, 'b': layer2.b }, 'L3' : { 'W': layer3.W, 'b': layer3.b }, } json_...
0
2016-09-02T04:17:34Z
[ "python", "save", "load", "theano", "conv-neural-network" ]
How do i run python script on all files in a directory?
39,283,608
<pre><code>import pyfits file = input('Enter file name as string: ') newfile = file.replace('.fits','.dat') f = pyfits.getdata(file) h = pyfits.getheader(file) g = open(newfile,'w') ref = h['JD_REF'] for x in range (len(f)): deltat = (f[x][0]-ref)/86400 refday = ref/86400 time = refday + ...
1
2016-09-02T02:48:35Z
39,283,631
<p>Use <code>os.listdir()</code>. If you only want to return the files that match the <code>'.fits'</code> pattern, you can use <code>glob.glob('*.fits')</code>.</p> <p>This will return all files in the current directory, or whatever directory you supply it as an argument. You can loop over these names, and use those ...
1
2016-09-02T02:52:26Z
[ "python", "scripting", "directory", "save" ]
Python word length
39,283,611
<p>Is there a way that I can set only some variables.</p> <pre><code>l1, l2, l3, l4, l5, l6, l7, l8, l9, = (' ',)*9 word = input("Choose up to a 9 letter word: ") wordlist = list(word) wordl = len(word) l1, l2, l3, l4, l5, l6, l7, l8, l9, = (wordlist) </code></pre> <p>More specifically is there a way that if someone ...
0
2016-09-02T02:49:14Z
39,283,693
<p>You can pad the input iterable with something like <code>None</code>, then slice the padded iterable to the expected length.</p> <pre><code>l1, l2, l3, l4, l5, l6, l7, l8, l9 = (list(word) + [None]*8)[:9] </code></pre> <p>No matter how short <code>word</code> is, the combined word/<code>None</code> list has at lea...
0
2016-09-02T03:03:18Z
[ "python", "python-3.x" ]
Python word length
39,283,611
<p>Is there a way that I can set only some variables.</p> <pre><code>l1, l2, l3, l4, l5, l6, l7, l8, l9, = (' ',)*9 word = input("Choose up to a 9 letter word: ") wordlist = list(word) wordl = len(word) l1, l2, l3, l4, l5, l6, l7, l8, l9, = (wordlist) </code></pre> <p>More specifically is there a way that if someone ...
0
2016-09-02T02:49:14Z
39,283,703
<p>You don't need to do any of that. If you want to fill unused characters with a space, you can use <code>str.ljust</code> or string formatting.</p> <pre><code>&gt;&gt;&gt; 'word'.ljust(9) 'word ' &gt;&gt;&gt; '{:&lt;9}'.format('word') 'word ' </code></pre>
1
2016-09-02T03:04:43Z
[ "python", "python-3.x" ]
Python word length
39,283,611
<p>Is there a way that I can set only some variables.</p> <pre><code>l1, l2, l3, l4, l5, l6, l7, l8, l9, = (' ',)*9 word = input("Choose up to a 9 letter word: ") wordlist = list(word) wordl = len(word) l1, l2, l3, l4, l5, l6, l7, l8, l9, = (wordlist) </code></pre> <p>More specifically is there a way that if someone ...
0
2016-09-02T02:49:14Z
39,284,034
<p>I really don't understand what you are trying to do, but if you want to assign values to <code>l1</code>, <code>l2</code>... <code>l9</code> based on the suffix(number) where the suffix corresponds to the length word then here's the code:</p> <pre><code>&gt;&gt;&gt; l1, l2, l3, l4, l5, l6, l7, l8, l9, = (' ',)*9 .....
1
2016-09-02T03:50:40Z
[ "python", "python-3.x" ]
Python word length
39,283,611
<p>Is there a way that I can set only some variables.</p> <pre><code>l1, l2, l3, l4, l5, l6, l7, l8, l9, = (' ',)*9 word = input("Choose up to a 9 letter word: ") wordlist = list(word) wordl = len(word) l1, l2, l3, l4, l5, l6, l7, l8, l9, = (wordlist) </code></pre> <p>More specifically is there a way that if someone ...
0
2016-09-02T02:49:14Z
39,284,071
<p>You really should use a list. If <code>l</code> were a list (so you have <code>l[0], l[1], ..., l[9] = ...</code>), this does what you want:</p> <pre><code>for (index, letter) in enumerate(word): l[index] = letter </code></pre> <p>(I assume you have some reason to want to leave later variables unassigned. if you...
1
2016-09-02T03:56:37Z
[ "python", "python-3.x" ]
Converting double slash utf-8 encoding
39,283,689
<p>I cannot get this to work! I have a text file from a save game file parser with a bunch of UTF-8 Chinese names in it in byte form, like this in the source.txt:</p> <p>\xe6\x89\x8e\xe5\x8a\xa0\xe6\x8b\x89</p> <p>But, no matter how I import it into Python (3 or 2), I get this string, at best:</p> <p>\\xe6\\x89\\x8...
0
2016-09-02T03:02:56Z
39,283,815
<p>at the end of day, what you get back is a string right? i would use string.replace method to convert double slash to single slash and add b prefix to make it work. </p>
0
2016-09-02T03:21:39Z
[ "python", "unicode", "encoding", "utf-8" ]
Converting double slash utf-8 encoding
39,283,689
<p>I cannot get this to work! I have a text file from a save game file parser with a bunch of UTF-8 Chinese names in it in byte form, like this in the source.txt:</p> <p>\xe6\x89\x8e\xe5\x8a\xa0\xe6\x8b\x89</p> <p>But, no matter how I import it into Python (3 or 2), I get this string, at best:</p> <p>\\xe6\\x89\\x8...
0
2016-09-02T03:02:56Z
39,283,826
<p>You can do some silly things like <code>eval</code>uating the string:</p> <pre><code>import ast s = r'\xe6\x89\x8e\xe5\x8a\xa0\xe6\x8b\x89' print ast.literal_eval('"%s"' % s).decode('utf-8') </code></pre> <ul> <li>note use <code>ast.literal_eval</code> if you don't want attackers to gain access to your system :-P<...
0
2016-09-02T03:22:47Z
[ "python", "unicode", "encoding", "utf-8" ]
Converting double slash utf-8 encoding
39,283,689
<p>I cannot get this to work! I have a text file from a save game file parser with a bunch of UTF-8 Chinese names in it in byte form, like this in the source.txt:</p> <p>\xe6\x89\x8e\xe5\x8a\xa0\xe6\x8b\x89</p> <p>But, no matter how I import it into Python (3 or 2), I get this string, at best:</p> <p>\\xe6\\x89\\x8...
0
2016-09-02T03:02:56Z
39,283,837
<p>So there are several different ways to interpret having the data "in byte form." Let's assume you really do:</p> <pre class="lang-py prettyprint-override"><code>s = b'\xe6\x89\x8e\xe5\x8a\xa0\xe6\x8b\x89' </code></pre> <p>The <code>b</code> prefix indicates those are bytes. Without getting into the whole mess tha...
0
2016-09-02T03:23:54Z
[ "python", "unicode", "encoding", "utf-8" ]
Converting double slash utf-8 encoding
39,283,689
<p>I cannot get this to work! I have a text file from a save game file parser with a bunch of UTF-8 Chinese names in it in byte form, like this in the source.txt:</p> <p>\xe6\x89\x8e\xe5\x8a\xa0\xe6\x8b\x89</p> <p>But, no matter how I import it into Python (3 or 2), I get this string, at best:</p> <p>\\xe6\\x89\\x8...
0
2016-09-02T03:02:56Z
39,283,896
<p>I'm assuming you're using Python 3. In Python 2, strings are bytes by default, so it would just work for you. But in Python 3, strings are unicode and interpretted as unicode, which is what makes this problem harder if you have a byte string being read as unicode.</p> <p>This solution was inspired by mgilson's answ...
1
2016-09-02T03:32:23Z
[ "python", "unicode", "encoding", "utf-8" ]
Converting double slash utf-8 encoding
39,283,689
<p>I cannot get this to work! I have a text file from a save game file parser with a bunch of UTF-8 Chinese names in it in byte form, like this in the source.txt:</p> <p>\xe6\x89\x8e\xe5\x8a\xa0\xe6\x8b\x89</p> <p>But, no matter how I import it into Python (3 or 2), I get this string, at best:</p> <p>\\xe6\\x89\\x8...
0
2016-09-02T03:02:56Z
39,283,941
<p>The problem is that <a href="https://docs.python.org/3/library/codecs.html#python-specific-encodings" rel="nofollow">the <code>unicode_escape</code> codec is implicitly decoding the result of the escape fixes by assuming the bytes are <code>latin-1</code>, not <code>utf-8</code></a>. You can fix this by:</p> <pre><...
3
2016-09-02T03:37:49Z
[ "python", "unicode", "encoding", "utf-8" ]
django register multiple admin link to each other
39,283,729
<p>Hi im still new to django. im planning to create an admin where i can add a Quiz,Question and choice. a Quiz has a Question and a Question has a choice. I can only do (Quiz and Question) and (Question and Choice). </p> <p>here is my model.</p> <pre><code>class Quiz(models.Model): quiz_title = models.CharField(...
0
2016-09-02T03:07:49Z
39,284,489
<p>Django doesn't support nested inlines without building this functionality yourself or using an admin nested inline app for which I am not up to date.</p> <p>A common pattern is to link directly to your child object as a new <code>ModelAdmin</code> view.</p> <p>Create a readonly field which renders the link.</p> ...
0
2016-09-02T04:46:49Z
[ "python", "django", "django-admin" ]
Split a string into unevenly sized chunks in a repeating pattern
39,283,744
<p>I have a string representing a series of bits:</p> <pre><code>bit_stream = "10100101011101011101011" # ...(so on) </code></pre> <p>I need to split this into unevenly sized chunks in a repeating pattern. The first chunk should be length 1, followed by a chunk of length 8, then a chunk of length 2, and so on until ...
-2
2016-09-02T03:09:46Z
39,283,892
<p>One way is to use a class to track state and an iterator to return groups of bits. <code>itertools.cycle</code> is used to generate the bit counts repeatedly:</p> <pre><code>from itertools import cycle class Bits(object): def __init__(self,input_bits,bit_counts): self.bits = input_bits self.c...
2
2016-09-02T03:31:47Z
[ "python", "python-2.7", "split" ]
Split a string into unevenly sized chunks in a repeating pattern
39,283,744
<p>I have a string representing a series of bits:</p> <pre><code>bit_stream = "10100101011101011101011" # ...(so on) </code></pre> <p>I need to split this into unevenly sized chunks in a repeating pattern. The first chunk should be length 1, followed by a chunk of length 8, then a chunk of length 2, and so on until ...
-2
2016-09-02T03:09:46Z
39,283,911
<p>I did this similarly to the other answer posted about a minute ago but I didn't use a class to track state.</p> <pre><code>import itertools def alternating_size_chunks(iterable, steps): n = 0 step = itertools.cycle(steps) while n &lt; len(iterable): next_step = next(step) yield iterable...
2
2016-09-02T03:33:40Z
[ "python", "python-2.7", "split" ]
Split a string into unevenly sized chunks in a repeating pattern
39,283,744
<p>I have a string representing a series of bits:</p> <pre><code>bit_stream = "10100101011101011101011" # ...(so on) </code></pre> <p>I need to split this into unevenly sized chunks in a repeating pattern. The first chunk should be length 1, followed by a chunk of length 8, then a chunk of length 2, and so on until ...
-2
2016-09-02T03:09:46Z
39,284,219
<pre><code>bit_stream = "10100101011101011101011" fmt = [1,8,2] i = 0 j = 0 lenb = len( bit_stream ) result = [] while True: l = j + fmt[i] if l &lt; lenb: result.append( bit_stream[j:l] ) else: result.append( bit_stream[j:lenb] ) break j = l i = i + 1 if i &gt; 2: ...
0
2016-09-02T04:15:26Z
[ "python", "python-2.7", "split" ]
Django NoReverseMatch wrong number of arguments
39,283,760
<p>I am getting a NoReverseMatch error after having added a new argument to one of my URLs. Initially, the URL in <code>urlpatterns</code> had been</p> <pre><code>url(r'^(?P&lt;myID&gt;[0-9]+)/go/(?P&lt;otherID&gt;[0-9]+)/$', views.go, name='go') </code></pre> <p>and this worked. I changed it to </p> <pre><code>url(...
0
2016-09-02T03:12:15Z
39,284,435
<p>Your error isn't related to your function arguments. It explicitly states the error is a <code>reverse</code> error.</p> <p>The traceback will tell you exactly where <code>reverse</code> was called from, and that function needs to be updated to use 3 arguments, not 2.</p> <p>It would be a <code>reverse()</code> ca...
1
2016-09-02T04:40:27Z
[ "python", "django" ]
Django NoReverseMatch wrong number of arguments
39,283,760
<p>I am getting a NoReverseMatch error after having added a new argument to one of my URLs. Initially, the URL in <code>urlpatterns</code> had been</p> <pre><code>url(r'^(?P&lt;myID&gt;[0-9]+)/go/(?P&lt;otherID&gt;[0-9]+)/$', views.go, name='go') </code></pre> <p>and this worked. I changed it to </p> <pre><code>url(...
0
2016-09-02T03:12:15Z
39,286,020
<p>Post a complete stack trace of error so that it can be known which file is the cause for issue.</p> <p>Check your templates. There is a possibility that django is trying to call the url in templates using only two args. Try calling url in templates using namespaces and names as given below.</p> <pre><code>{% url '...
0
2016-09-02T06:51:38Z
[ "python", "django" ]
Run anaconda through bash file
39,283,908
<p>I have made a script in python that crops an image. I am using Anaconda for that and Python 2.7 in Windows</p> <p>What i want to do is to run this script for a whole folder with images, so i was thinking of making a bash file. I followed <a href="http://www.howtogeek.com/249966/how-to-install-and-use-the-linux-bas...
0
2016-09-02T03:33:26Z
39,284,973
<p>This may not be what you're looking for as you asked for assistance with your bash script. However, you could modify your python script to crop all the images in a specified folder using the glob function. You can run it on windows with anaconda installed.</p> <p>glob returns a list of all the file names matching t...
1
2016-09-02T05:35:55Z
[ "python", "linux", "bash", "shell", "anaconda" ]
DJANGO Adding a User
39,284,032
<p>When I am trying to add a user for in my django admin site I get this error:</p> <p><strong>The above exception (NOT NULL constraint failed: auth_user.last_login) was the direct cause of the following exception: /usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py in get_response</strong></p> <p>I c...
0
2016-09-02T03:50:33Z
39,284,113
<p>Based on <a href="http://tutorial.djangogirls.org/en/django_admin/" rel="nofollow">this</a> tutorial:</p> <pre><code>$ python manage.py createsuperuser </code></pre> <p>And fill up the rest. Maybe try to add more details for I'm just guessing that you want to add superuser</p>
0
2016-09-02T04:02:45Z
[ "python", "django-admin" ]
Error tokenizing data
39,284,060
<p>This is my code:</p> <pre><code>import pandas import datetime from decimal import Decimal file_ = open('myfile.csv', 'r') result = pandas.read_csv( file_, header=None, names=('sec', 'date', 'sale', 'buy'), usecols=('date', 'sale', 'buy'), parse_dates=['date'], iterator=True, chunksize=100, ...
0
2016-09-02T03:55:12Z
39,287,343
<pre><code>#try this code import pandas as pd import numpy as np import csv # To print only three columns , create a data frame,to do that give names to columns in csv file with ',' as seperator myfile.csv: sec,date,sale,buy EUR/USD,20160701 00:00:00.071,1.11031,1.11033 EUR/USD,20160701 00:00:00.255,1.11031,1.11033 EU...
1
2016-09-02T08:06:31Z
[ "python", "pandas" ]
Why Eigen values of adajcency matrix are actually the sentence scores in Textrank
39,284,362
<p>Here is the route for TextRank:</p> <ol> <li>Document to be summarized expressed as tf-idf matrix</li> <li>(tf-idf matrix)*(tf-idf matrix).Transpose = Adjacency matrix of some graph whose vertices are actually the sentences of above document</li> <li>Page rank is applied on this graph -> returns PR values of each s...
4
2016-09-02T04:33:19Z
39,295,580
<p>To begin with, your question is a bit mistaken. The eignevalues are <em>not</em> the scores. Rather, the <em>entries of the stationary eigenvector</em> are the scores.</p> <p>Textrank works on a <a href="https://web.eecs.umich.edu/~mihalcea/papers/mihalcea.emnlp04.pdf" rel="nofollow">graphical approach to words</a>...
2
2016-09-02T15:06:50Z
[ "python", "nlp", "eigenvector", "pagerank", "summarization" ]
Adding nodes and edges to graph data structure dynamically in Matlab
39,284,401
<p>I usually create graphs in matlab as follows:</p> <pre><code>g=sparse(5,5); g(2,3)=1; </code></pre> <p>and so on.</p> <p>This works very well if i have the graph created in advance and given to me figuratively so that i have to make a adjacency matrix representing that graph. But now i have a different kind of pr...
1
2016-09-02T04:37:41Z
39,293,162
<p>Have you tried looking into MATLAB's new-ish <code>graph</code> class? It was introduced in R2015b and has methods you can use to do these steps efficiently. Specifically, it has <code>addnode</code>, <code>addedge</code>, <code>rmedge</code>, etc. You can also extract the adjacency matrix from the <code>graph</c...
0
2016-09-02T13:04:15Z
[ "python", "algorithm", "matlab", "graph" ]
How was this Python Turtle graphic made?
39,284,448
<p>My friend showed me this amazing image that she made using Python's inbuilt <a href="https://docs.python.org/2/library/turtle.html" rel="nofollow">Turtle module</a> and challenged me to find out how it was made. She gave me one hint: the image was produced with 10 lines of code. </p> <p><img src="http://i.imgur.com...
1
2016-09-02T04:41:44Z
39,285,344
<p>Thanks to @citaret and @JerryJeremiah's suggestions, I was able to put together something that produces similar results to the image, in less than 10 lines:</p> <pre><code>from turtle import Turtle, Screen mr_turtle = Turtle() screen = Screen() mr_turtle.speed(0) for i in range(1800): mr_turtle.forward(300) ...
1
2016-09-02T06:05:39Z
[ "python", "graphics", "turtle-graphics" ]
How was this Python Turtle graphic made?
39,284,448
<p>My friend showed me this amazing image that she made using Python's inbuilt <a href="https://docs.python.org/2/library/turtle.html" rel="nofollow">Turtle module</a> and challenged me to find out how it was made. She gave me one hint: the image was produced with 10 lines of code. </p> <p><img src="http://i.imgur.com...
1
2016-09-02T04:41:44Z
39,285,356
<p>Here is what I believe your looking for:</p> <pre><code>Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; import turtle &gt;&gt;&gt; t = turtle.Pen() &gt;&gt;&gt; for i i...
1
2016-09-02T06:06:24Z
[ "python", "graphics", "turtle-graphics" ]
How was this Python Turtle graphic made?
39,284,448
<p>My friend showed me this amazing image that she made using Python's inbuilt <a href="https://docs.python.org/2/library/turtle.html" rel="nofollow">Turtle module</a> and challenged me to find out how it was made. She gave me one hint: the image was produced with 10 lines of code. </p> <p><img src="http://i.imgur.com...
1
2016-09-02T04:41:44Z
39,294,579
<p>After some tuning, I find this, which, I think, is very close to the image, with exact 10 lines.</p> <pre><code>import turtle bob = turtle.Turtle() bob.speed(0) for i in range(632): bob.forward(200) bob.right(1) bob.forward(100) bob.setpos(0,0) bob.left(1.57) turtle.done() </code></pre> <p><a h...
2
2016-09-02T14:16:23Z
[ "python", "graphics", "turtle-graphics" ]
Absolute linking in Python
39,284,599
<p>How can I make my links relative to the home directory (absolute linking)? I have a program that will use a file given anywhere in my user account. Code:</p> <pre><code>file_name = input("Enter file path") try: file = open("../" + file_name) print(file) except: print("Failed to open") </code></pre> <p>...
0
2016-09-02T05:01:11Z
39,284,720
<pre><code>import os </code></pre> <p>home_dir = os.path.expanduser('~')</p> <pre><code>file_name = input("Enter file path") try: file = open(os.path.join(home_dir, file_name)) print(file) except: print("Failed to open") </code></pre> <p><code>os.path.expanduser('~')</code> should return the home directo...
1
2016-09-02T05:14:35Z
[ "python", "python-3.x", "absolute-path" ]
Sort duplicate values column A from csv file
39,284,717
<p>I am trying to sort duplicate values column A from csv file but not getting expected result in python.</p> <p>Input File: (.csv)</p> <p>Column names:</p> <pre><code>Uniprot Acc, PDB ID, Ligand ID, Structure Title, Uniprot Recommended Name, Gene Name, Macromolecular Name </code></pre> <p>I want to sort duplicates...
1
2016-09-02T05:14:06Z
39,285,225
<p>You can first store all the values in a list then you can easily find the duplicate values in a sorted order. see my below code.</p> <pre><code> import csv import re import sys import os f1 = csv.reader(open('one.csv', 'rb')) writer = csv.writer(open("Output_file_1.csv", "wb")) def has_duplicates(f1...
1
2016-09-02T05:56:31Z
[ "python" ]
Rerun code block in Python
39,284,758
<p>I was looking to try to figure out a way to write something like this:</p> <pre><code>code_that_should_not_be_run_again() with rerun_code_that_may_fail(): another_method(x) run_me_again_if_i_fail(y) code_that_should_only_be_run_if_above_succeeds() </code></pre> <p>Where the above would run that code, and catch...
1
2016-09-02T05:18:00Z
39,285,112
<p>I hope someone posts a better solution than this but I would use exactly that method, and perhaps with a decorator:</p> <pre><code>def retry_if_fails(fn, exception=Exception, *args, **kwargs): try: fn(*args, **kwargs) except exception: fn(*args, **kwargs) # if this fails again here, the exc...
0
2016-09-02T05:47:43Z
[ "python", "python-2.7", "generator", "yield", "with-statement" ]
Rerun code block in Python
39,284,758
<p>I was looking to try to figure out a way to write something like this:</p> <pre><code>code_that_should_not_be_run_again() with rerun_code_that_may_fail(): another_method(x) run_me_again_if_i_fail(y) code_that_should_only_be_run_if_above_succeeds() </code></pre> <p>Where the above would run that code, and catch...
1
2016-09-02T05:18:00Z
39,285,140
<p>Using the retry decorator - <a href="https://pypi.python.org/pypi/retry/" rel="nofollow">https://pypi.python.org/pypi/retry/</a> - and under the scenario that you want to catch any <code>TypeError</code>, with a maximum of 3 tries, with a delay of 5 seconds:</p> <pre><code>from retry import retry @retry(TypeError,...
1
2016-09-02T05:50:06Z
[ "python", "python-2.7", "generator", "yield", "with-statement" ]
How "File not open a bytes-like object is required, not 'int' " could be solved?
39,284,781
<p>I am writing a simple http server code using socket-network-programming as a way of connection between client-server nodes.</p> <p>simply, I used my browser as client and I coded server side using python. </p> <p>Now, everything seems right but when I run the server plus browser with specific path 'filename',like ...
-1
2016-09-02T05:20:06Z
39,317,116
<p>The problem was very simple. All what I did after a lot of digging on the Internet is the following: client_socket.send("HTTP/1.1 200 OK\n".encode())</p> <p>Sincerely</p>
0
2016-09-04T12:54:01Z
[ "python", "http", "networking" ]
Order dictionary index in python
39,284,842
<p>I have created a order dictionary and could not get the index out of it. I have gone through the below url but not working.</p> <blockquote> <p><a href="http://stackoverflow.com/questions/15114843/accessing-dictionary-value-by-index-in-python">Accessing dictionary value by index in python</a></p> </blockquote> <...
0
2016-09-02T05:25:37Z
39,284,909
<blockquote> <p>TypeError: 'odict_values' object does not support indexing</p> </blockquote> <p>You need to make it into a <code>list</code> first and then access it:</p> <pre><code>print(list(line_1.values())[1]) # or print([*line_1.values()][1]) </code></pre> <p>These <code>view</code> (new in Python 3) objects ...
2
2016-09-02T05:31:18Z
[ "python", "python-3.x", "dictionary" ]
Order dictionary index in python
39,284,842
<p>I have created a order dictionary and could not get the index out of it. I have gone through the below url but not working.</p> <blockquote> <p><a href="http://stackoverflow.com/questions/15114843/accessing-dictionary-value-by-index-in-python">Accessing dictionary value by index in python</a></p> </blockquote> <...
0
2016-09-02T05:25:37Z
39,284,955
<p>In Python 3, dictionaries (including <code>OrderedDict</code>) return "view" objects from their <code>keys()</code> and <code>values()</code> methods. Those are iterable, but don't support indexing. The answer you linked appears to have been written for Python 2, where <code>keys()</code> and <code>values()</code> r...
1
2016-09-02T05:33:55Z
[ "python", "python-3.x", "dictionary" ]
How to use `.split()` for importing tab-delimited text from a large `gzip` file? Chunks?
39,284,925
<p>I have huge <code>gzip</code> file (several GB) of tab-delimited text which I would like to parse into a pandas dataframe. </p> <p>If the contents of this file were text, one would simply use <code>.split()</code>, e.g. </p> <pre><code>file_text = """abc 123 cat 456 dog 678 bird 111 fish ... moon...
0
2016-09-02T05:31:54Z
39,285,035
<p><code>read_csv()</code> supports <code>GZIP</code>ped files, so you can simply do the following:</p> <pre><code>for chunk in pd.read_csv('/path/to/file.csv.gz', sep='\s*', chunksize=10**5): # process chunk DF </code></pre> <p>if you are sure that you have a TSV (<strong>TAB</strong> separated file), you can us...
1
2016-09-02T05:42:12Z
[ "python", "pandas", "dataframe", "split", "gzip" ]
Parallelize pandas apply
39,284,989
<p>New to pandas, I already want to parallelize a row-wise apply operation. So far I found <a href="http://stackoverflow.com/questions/26187759/parallelize-apply-after-pandas-groupby">Parallelize apply after pandas groupby</a> However, that only seems to work for grouped data frames.</p> <p>My use case is different: I...
3
2016-09-02T05:37:27Z
39,315,192
<p>I think going down the route of trying stuff in parallel is probably over complicating this. I haven't tried this approach on a large sample so your mileage may vary, but it should give you an idea...</p> <p>Let's just start with some dates...</p> <pre><code>import pandas as pd dates = pd.to_datetime(['2016-01-03...
2
2016-09-04T08:55:46Z
[ "python", "pandas", "parallel-processing", "apply", "embarrassingly-parallel" ]
Parallelize pandas apply
39,284,989
<p>New to pandas, I already want to parallelize a row-wise apply operation. So far I found <a href="http://stackoverflow.com/questions/26187759/parallelize-apply-after-pandas-groupby">Parallelize apply after pandas groupby</a> However, that only seems to work for grouped data frames.</p> <p>My use case is different: I...
3
2016-09-02T05:37:27Z
39,316,680
<p>For the parallel approach this is the answer based on <a href="http://stackoverflow.com/questions/26187759/parallelize-apply-after-pandas-groupby">Parallelize apply after pandas groupby</a>:</p> <pre><code>from joblib import Parallel, delayed import multiprocessing def get_nearest_dateParallel(df): df['daysBef...
0
2016-09-04T11:59:45Z
[ "python", "pandas", "parallel-processing", "apply", "embarrassingly-parallel" ]
Translate code matlab to python numpy
39,285,004
<p>I don't understand about matlab programming, I just understand coding in python...</p> <p><img src="http://i.stack.imgur.com/ww2zr.jpg" alt="here my matrix want to solve "></p> <h3>Matlab Code:</h3> <pre><code> x = ones(3,1). con = [0.505868045540458,0.523598775598299]. series = [1,2,3] for j = 1:2 #here stu...
2
2016-09-02T05:38:59Z
39,285,269
<p>Here's a solution that entirely removes the loop which resizes the array, which <strong>for large <code>len(con)</code></strong> should make this more efficient than the matlab solution , and by association hpaulj's direct translation - this is linear in len(con) rather than quadratic.</p> <pre><code>import numpy a...
0
2016-09-02T05:59:49Z
[ "python", "matlab", "numpy", "math", "computer-science" ]
Translate code matlab to python numpy
39,285,004
<p>I don't understand about matlab programming, I just understand coding in python...</p> <p><img src="http://i.stack.imgur.com/ww2zr.jpg" alt="here my matrix want to solve "></p> <h3>Matlab Code:</h3> <pre><code> x = ones(3,1). con = [0.505868045540458,0.523598775598299]. series = [1,2,3] for j = 1:2 #here stu...
2
2016-09-02T05:38:59Z
39,285,371
<p>My recreation in an Ipython session (having first tested your code in an Octave session):</p> <pre><code>In [649]: con = np.array([0.505868, 0.5235897]) In [650]: series = np.array([1,2,3]) In [651]: x = [np.ones((3,))] In [652]: for j in range(2): ...: x.extend([np.cos(con[j]*series), np.sin(con[j]*series...
1
2016-09-02T06:07:39Z
[ "python", "matlab", "numpy", "math", "computer-science" ]
Mac os El Capitan recording sound with python
39,285,145
<p>I'm trying to record sound from mic. Firstly as used PyAudio then sounddevice but both failed.</p> <p>Here is code for PyAudio:</p> <pre><code>import pyaudio def _recording_loop(samples_queue, running, stream, chunk_size): stream.start_stream() while running.is_set(): samples_queue.put(stream.re...
1
2016-09-02T05:50:32Z
39,299,532
<p><a href="http://python-sounddevice.readthedocs.io/en/latest/#sounddevice.rec" rel="nofollow">sounddevice.rec()</a> is not meant to be used like that. You just call it with the number of frames you want to record and that's it (see the <a href="http://python-sounddevice.readthedocs.io/en/latest/#recording" rel="nofol...
0
2016-09-02T19:30:23Z
[ "python", "osx", "osx-elcapitan", "pyaudio", "python-sounddevice" ]
Mac os El Capitan recording sound with python
39,285,145
<p>I'm trying to record sound from mic. Firstly as used PyAudio then sounddevice but both failed.</p> <p>Here is code for PyAudio:</p> <pre><code>import pyaudio def _recording_loop(samples_queue, running, stream, chunk_size): stream.start_stream() while running.is_set(): samples_queue.put(stream.re...
1
2016-09-02T05:50:32Z
39,805,131
<p>Yesterday I ran into similar problem. It seems that it's caused by using multiprocessing with sounddevice. When I do <code>import sounddevice</code> at the top of the module I get <code>||PaMacCore (AUHAL)|| Warning on line 530: err=''who?'', msg=Audio Hardware: Unknown Property</code> and then the app just hangs wh...
0
2016-10-01T09:44:14Z
[ "python", "osx", "osx-elcapitan", "pyaudio", "python-sounddevice" ]
AttributeError: 'unicode' object has no attribute 'regex' while upgrading Django from 1.7.11 to 1.9.2
39,285,232
<p>I'm working with the "third_party" example project of pybb (<a href="https://github.com/hovel/pybbm" rel="nofollow">https://github.com/hovel/pybbm</a>) [test folder] which works fine in django 1.7.11 but I've built the rest of my website in django 1.9.2. It gives me the following traceback in 1.9.2 and I'm not able ...
1
2016-09-02T05:56:49Z
39,285,632
<p>Just try it. Remove empty string in urlpatterns.</p> <pre><code>urlpatterns = [ url(r'^admin/', include(admin.site.urls)), # aliases to match original django-registration urls url(r"^accounts/password/$", ChangePasswordView.as_view(), name="auth_password_change"), url(r"^accounts/signup/$", SignupV...
3
2016-09-02T06:27:56Z
[ "python", "django", "version" ]
I want to print specific line just one time in for loop using python 3.4
39,285,257
<p>I want to print specific in line just one time in for loop but insted of result in one line it gives same result four time please help me how to stop for loop after printing one line </p> <p>Here is complete html and python code also with result of this script</p> <p><div class="snippet" data-lang="js" data-hide="...
0
2016-09-02T05:58:48Z
39,285,334
<pre><code>printed_countries = list() ulpart = soup.find_all("ul", {"class": "breadcrumbs"}) for unorder in ulpart: div2 = soup.find_all("li", {"class": "breadcrumb_item "}) for listitem in div2[0:]: country = soup.select_one("li.breadcrumb...
0
2016-09-02T06:04:49Z
[ "python", "html", "html5", "python-3.4" ]
I want to print specific line just one time in for loop using python 3.4
39,285,257
<p>I want to print specific in line just one time in for loop but insted of result in one line it gives same result four time please help me how to stop for loop after printing one line </p> <p>Here is complete html and python code also with result of this script</p> <p><div class="snippet" data-lang="js" data-hide="...
0
2016-09-02T05:58:48Z
39,286,086
<p>since you are using unordered lists you can use python set datatype(if you need order use list):</p> <pre><code>printed = set() ulpart = soup.find_all("ul", {"class": "breadcrumbs"}) for unorder in ulpart: div2 = soup.find_all("li", {"class": "breadcrumb_item "}) ...
0
2016-09-02T06:55:36Z
[ "python", "html", "html5", "python-3.4" ]
Mapping coordinates to screen in PyGame
39,285,506
<p>Ok, lots of explaining to follow, so bear with me.</p> <p>I'm making a 2D top-down game in PyGame, and I have a "chunk loading" system set up. The system is as follows...</p> <p>I have a "world" object, made up of "chunks". Each chunk is 16x16 "tiles" and contains data for each one of those tiles. In the world obj...
0
2016-09-02T06:17:37Z
39,285,964
<p>If I understand your problem right, TomTsagk explained it really good:</p> <p><a href="http://stackoverflow.com/questions/19746552/pygame-camera-follow-in-a-2d-tile-game">Pygame camera follow in a 2d tile game</a></p> <p>Hope this helps. </p>
0
2016-09-02T06:48:16Z
[ "python", "pygame", "coordinates", "chunks" ]
How to extend/overload range() function from Python 2.7 to accept floats?
39,285,559
<p>Our core application changed from Python 2.6 to Python 2.7 maybe to Python 3 in later release.</p> <p>Range function from python is changed (quote from the Python 2.7 changelog).</p> <blockquote> <p>The <code>range()</code> function processes its arguments more consistently; it will now call <code>__int__()</c...
0
2016-09-02T06:21:33Z
39,286,239
<p>You have a serious migration issue. If you want to switch to Python 2.7 and even Python 3, there is basically no easy way around refactoring the existing (user) code base eventually. IMHO, you have the following options.</p> <ol> <li><p>Provide a permanent (non-optional) 2.6 compatible interface to your users. That...
3
2016-09-02T07:04:53Z
[ "python", "python-2.7", "python-2.6" ]
How to extend/overload range() function from Python 2.7 to accept floats?
39,285,559
<p>Our core application changed from Python 2.6 to Python 2.7 maybe to Python 3 in later release.</p> <p>Range function from python is changed (quote from the Python 2.7 changelog).</p> <blockquote> <p>The <code>range()</code> function processes its arguments more consistently; it will now call <code>__int__()</c...
0
2016-09-02T06:21:33Z
39,289,158
<p>The change is not that calling <code>__int__</code> on non-float. The change affecting you is that float arguments are not accepted any more in Python 2.7:</p> <pre><code>Python 2.6.9 (default, Sep 15 2015, 14:14:54) [GCC 5.2.1 20150911] on linux2 Type "help", "copyright", "credits" or "license" for more informati...
2
2016-09-02T09:36:12Z
[ "python", "python-2.7", "python-2.6" ]
Return c++ object (not a pointer preferably) in cython
39,285,591
<p>I have two classes (let's assume the most simple ones, implementation is not important). My <code>defs.pxd</code> file (with cython defs) looks like this:</p> <pre><code>cdef extern from "A.hpp": cdef cppclass A: A() except + cdef extern from "B.hpp": cdef cppclass B: B() except + A func () </code>...
0
2016-09-02T06:24:37Z
39,300,256
<p>Your issue is that your wrapper class requires a pointer (to a <code>new</code> allocated object) but your function returns an C++ object on the stack. To solve this you have to copy or move the object from the stack.</p> <p>First ensure that your C++ class <code>A</code> has a working copy or move constructor. A m...
1
2016-09-02T20:28:15Z
[ "python", "c++", "cython" ]
What is the best way to use a two value pair as a key in python?
39,286,012
<p>I am basically attempting to use a matrix in pythons. I have heard about things like a list of lists, but I wasn't sure what the easiest way to manipulate these values would be. I would essentially want there to be a value stored at coordinates (x,y) on a grid, that could only be accessed by having both x and y. Som...
1
2016-09-02T06:51:19Z
39,286,041
<p>You can store a tuple of (x, y) as a key in the dictionary:</p> <pre><code>matrix = {(1, 1): value1, (1, 2): value2, ...} </code></pre> <p>You can retrieve a value associated by a coordinate like follows:</p> <pre><code>value = matrix[(1, 2)] </code></pre>
4
2016-09-02T06:53:23Z
[ "python", "list", "matrix" ]
python - Pass by value or by reference
39,286,036
<p>I have an object with an attribute that is a list. For example:</p> <pre><code>obj.a = [3, 4, 5] </code></pre> <p>I would like to get the following behavior (but I can't manage to find a solution using magics/etc.) :</p> <pre><code>l = obj.a obj.a[0] = 2 print(l) --&gt; [3, 4, 5] print(obj.a) ---&gt; [2, 4, 5] <...
1
2016-09-02T06:53:04Z
39,286,262
<p>It's not possible to make the assignment <code>l = obj.a</code> make a copy of <code>obj.a</code>. As deceze said in a comment, you could make <code>a</code> a property that returns a copy of the value every time you access it, but that would, well, make a copy every time you access it, not just when you assign it ...
1
2016-09-02T07:06:22Z
[ "python", "reference" ]
python - Pass by value or by reference
39,286,036
<p>I have an object with an attribute that is a list. For example:</p> <pre><code>obj.a = [3, 4, 5] </code></pre> <p>I would like to get the following behavior (but I can't manage to find a solution using magics/etc.) :</p> <pre><code>l = obj.a obj.a[0] = 2 print(l) --&gt; [3, 4, 5] print(obj.a) ---&gt; [2, 4, 5] <...
1
2016-09-02T06:53:04Z
39,286,305
<p>Simply use the following code...</p> <pre><code>l = list(obj.a) </code></pre> <p>this will allow you to copy a list to a new list</p>
0
2016-09-02T07:09:02Z
[ "python", "reference" ]
python - Pass by value or by reference
39,286,036
<p>I have an object with an attribute that is a list. For example:</p> <pre><code>obj.a = [3, 4, 5] </code></pre> <p>I would like to get the following behavior (but I can't manage to find a solution using magics/etc.) :</p> <pre><code>l = obj.a obj.a[0] = 2 print(l) --&gt; [3, 4, 5] print(obj.a) ---&gt; [2, 4, 5] <...
1
2016-09-02T06:53:04Z
39,290,499
<p>This is not possible without actually cloning the list to another list, you have to use copy() or deepcopy() depending on your requirement. </p>
0
2016-09-02T10:45:21Z
[ "python", "reference" ]
How to check if 2-D array is in another 2-D array
39,286,058
<p>consider the two dataframes <code>df1</code> and <code>df2</code></p> <pre><code>df1 = pd.DataFrame(np.zeros((6, 6)), list('abcdef'), list('abcdef'), dtype=int) df1.iloc[2:4, 2:4] = np.array([[1, 2], [3, 4]]) df1 </code></pre> <p><a href="http://i.stack.imgur.com/UEWbP.png" rel="nofollow"><img src="http://i.stack...
2
2016-09-02T06:54:20Z
39,286,107
<p>Assuming the dataframes contain <code>0's</code> and <code>1s</code> only, you can use <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.convolve2d.html" rel="nofollow"><code>2D convolution</code></a> and look if any element in the convoluted output is equal to the number of elements in <code...
3
2016-09-02T06:56:42Z
[ "python", "pandas", "numpy", "scipy" ]
How to check if 2-D array is in another 2-D array
39,286,058
<p>consider the two dataframes <code>df1</code> and <code>df2</code></p> <pre><code>df1 = pd.DataFrame(np.zeros((6, 6)), list('abcdef'), list('abcdef'), dtype=int) df1.iloc[2:4, 2:4] = np.array([[1, 2], [3, 4]]) df1 </code></pre> <p><a href="http://i.stack.imgur.com/UEWbP.png" rel="nofollow"><img src="http://i.stack...
2
2016-09-02T06:54:20Z
39,289,049
<h3>Brute force</h3> <pre><code>def isin2d(small_df, large_df): di, dj = small_df.shape mi, mj = large_df.shape for i in range(mi - di + 1): for j in range(mj - dj + 1): if (small_df.values == large_df.values[i:i + di, j:j + dj]).all(): return True return False isi...
1
2016-09-02T09:31:26Z
[ "python", "pandas", "numpy", "scipy" ]
python class behaves like dictionary-or-list-data-like
39,286,116
<p>In python3 console, input those:</p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; sys.version_info sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0) &gt;&gt;&gt; type(sys.version_info) # this is class type &lt;class 'sys.version_info'&gt; &gt;&gt;&gt; sys.version_info[0:2] # ?? But it...
0
2016-09-02T06:57:19Z
39,286,168
<p>It's quite easy ... All you need to do is define a <code>__getitem__</code> method that handles slicing or integer/string lookup. You can do pretty much whatever you want...</p> <pre><code>class Foo(object): def __init__(self, bar, baz): self.bar = bar self.baz = baz def __getitem__(self, i...
2
2016-09-02T07:00:06Z
[ "python", "list", "class", "dictionary" ]
python class behaves like dictionary-or-list-data-like
39,286,116
<p>In python3 console, input those:</p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; sys.version_info sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0) &gt;&gt;&gt; type(sys.version_info) # this is class type &lt;class 'sys.version_info'&gt; &gt;&gt;&gt; sys.version_info[0:2] # ?? But it...
0
2016-09-02T06:57:19Z
39,286,207
<p>Python contains several methods for <a href="https://docs.python.org/3/reference/datamodel.html#emulating-container-types" rel="nofollow">emulating container types</a> such as dictionaries and lists. </p> <p>In particular, consider the following class:</p> <pre><code> class MyDict(object): def __getitem__(sel...
2
2016-09-02T07:02:49Z
[ "python", "list", "class", "dictionary" ]
python class behaves like dictionary-or-list-data-like
39,286,116
<p>In python3 console, input those:</p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; sys.version_info sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0) &gt;&gt;&gt; type(sys.version_info) # this is class type &lt;class 'sys.version_info'&gt; &gt;&gt;&gt; sys.version_info[0:2] # ?? But it...
0
2016-09-02T06:57:19Z
39,287,007
<p>i think in python like ECMAScript (aka javascript) class is a dictionary or <strong>associative array</strong>(<a href="https://en.wikipedia.org/wiki/Associative_array" rel="nofollow">associative array</a>). since you can add a property or method to your class at runtime.(<a href="http://slides.com/alirezaafzalaghae...
0
2016-09-02T07:46:11Z
[ "python", "list", "class", "dictionary" ]
python class behaves like dictionary-or-list-data-like
39,286,116
<p>In python3 console, input those:</p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; sys.version_info sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0) &gt;&gt;&gt; type(sys.version_info) # this is class type &lt;class 'sys.version_info'&gt; &gt;&gt;&gt; sys.version_info[0:2] # ?? But it...
0
2016-09-02T06:57:19Z
39,290,115
<p>You can achieve the same behaviour by overriding <strong>getitem</strong>() and <strong>setitem</strong>() in your class.</p> <pre><code> class Example: def __getitem__(self, index): return index ** 2 &gt;&gt;&gt; X = Example() &gt;&gt;&gt; X[2] &g...
0
2016-09-02T10:24:09Z
[ "python", "list", "class", "dictionary" ]
Pass custom value to the logger instead of to every message
39,286,145
<p>I want to log the user session. Currently the code is as follows (setting formatter and handlers is omitted):</p> <pre><code>logger = logging.getLogger("component") logger.info("message", extra={"session": 123}) logger.debug("debug", extra={"session": 123}) </code></pre> <p>If there are several messages to be logg...
0
2016-09-02T06:58:56Z
39,286,315
<p>In Java we have Mapped Diagnostic Context (<code>MDC</code>) in <code>Log4j</code> framework.</p> <p>Basically it is a map. You can put values there which can be used in logger output pattern.</p> <p>Please take a look at: <a href="https://gist.github.com/mdaniel/8347533" rel="nofollow">https://gist.github.com/mda...
-1
2016-09-02T07:09:34Z
[ "python", "python-3.x", "logging" ]
Pass custom value to the logger instead of to every message
39,286,145
<p>I want to log the user session. Currently the code is as follows (setting formatter and handlers is omitted):</p> <pre><code>logger = logging.getLogger("component") logger.info("message", extra={"session": 123}) logger.debug("debug", extra={"session": 123}) </code></pre> <p>If there are several messages to be logg...
0
2016-09-02T06:58:56Z
39,286,357
<p>Use function factories for instance like that</p> <pre><code>def get_logger_with_context(name, context=None): extra = context or {} logger = logging.getLogger(name) def log(level, message, **kwargs): getattr(logger, level)(message, extra=context) return log </code></pre>
1
2016-09-02T07:11:42Z
[ "python", "python-3.x", "logging" ]
Pass custom value to the logger instead of to every message
39,286,145
<p>I want to log the user session. Currently the code is as follows (setting formatter and handlers is omitted):</p> <pre><code>logger = logging.getLogger("component") logger.info("message", extra={"session": 123}) logger.debug("debug", extra={"session": 123}) </code></pre> <p>If there are several messages to be logg...
0
2016-09-02T06:58:56Z
39,286,514
<p>Such <a href="https://docs.python.org/2/howto/logging-cookbook.html#adding-contextual-information-to-your-logging-output" rel="nofollow">custom logging</a> is feasible in python logging class, using logging.loggerAdapters which modify the logging behaviour.</p> <blockquote> <p>An easy way in which you can pass co...
1
2016-09-02T07:20:31Z
[ "python", "python-3.x", "logging" ]
Pass custom value to the logger instead of to every message
39,286,145
<p>I want to log the user session. Currently the code is as follows (setting formatter and handlers is omitted):</p> <pre><code>logger = logging.getLogger("component") logger.info("message", extra={"session": 123}) logger.debug("debug", extra={"session": 123}) </code></pre> <p>If there are several messages to be logg...
0
2016-09-02T06:58:56Z
39,286,671
<p>Create a <code>LoggerAdapter</code> as @DhruvPathak specified. According to <a href="https://docs.python.org/3/library/logging.html#logging.LoggerAdapter" rel="nofollow"><code>LoggerAdapter</code>s signature</a>:</p> <pre><code>class logging.LoggerAdapter(logger, extra) </code></pre> <p>you do that by providing yo...
1
2016-09-02T07:28:27Z
[ "python", "python-3.x", "logging" ]
Excel or Access change some rows to columns
39,286,158
<p>I have some long data I need to convert into a wide fixed width text format. </p> <p>I have a large spreadsheet of rows that are duplicated for each person where the only difference, where the person is the same, are two columns. </p> <p>I want to remove the duplicates and instead of having multiple rows where t...
1
2016-09-02T06:59:33Z
39,286,838
<p>You can do that using a pivot table:</p> <ul> <li>put name then DOB as row labels</li> <li>put type then process as column labels</li> <li>put count of process in values</li> <li>right-click your pivot table, select expand/collapse and expand by process</li> <li>go to design, report layout, and select tabular layou...
2
2016-09-02T07:37:39Z
[ "python", "excel" ]
handing qwidget.winid to DLL in Python
39,286,164
<p>I have a dll, which use OpenGl to draw on window. Dll get window by HWMD.</p> <p>DLL:</p> <pre><code>extern "C" __declspec(dllexport) int Init(HWND hWnd); extern "C" __declspec(dllexport) void Resize(HWND hWnd, int w, int h); extern "C" __declspec(dllexport) void Paint(HWND hWnd); </code></pre> <p>The c++ qt appl...
2
2016-09-02T06:59:48Z
39,288,498
<p>It'd be easier to check having the dll, so I'll speak out the blue. In your c++ code you got this initialization code:</p> <pre><code>bool load_opengl_library(){ QLibrary lib("engine3d"); lib.load(); c_Init = (InitPrototype)lib.resolve("Init"); c_Paint = (PaintPrototype)lib.resolve("Paint"); c_R...
0
2016-09-02T09:06:40Z
[ "python", "dll", "ctypes", "hwnd" ]
Running a python script from shell
39,286,331
<p>I want to run a python script from a shell script. I have been able to run it from the "command window" (Cygwin), but now I want to be able to call it from a shell script. It does not work the way I thought it would and the Internet has not really helped me with it.</p> <p>My code so far:</p> <pre><code>#!/bin/bas...
0
2016-09-02T07:10:31Z
39,286,535
<p>Just make sure the python executable is in your PATH environment variable, then add in your script</p> <p>In the file job.sh,</p> <p><code>#!/bin/sh python &lt;path/to/python/script&gt;/python_script.py</code></p> <p>Execute this command to make the script runnable for you : <code>chmod u+x job.sh</code> Run it ...
1
2016-09-02T07:21:58Z
[ "python", "shell" ]
Running a python script from shell
39,286,331
<p>I want to run a python script from a shell script. I have been able to run it from the "command window" (Cygwin), but now I want to be able to call it from a shell script. It does not work the way I thought it would and the Internet has not really helped me with it.</p> <p>My code so far:</p> <pre><code>#!/bin/bas...
0
2016-09-02T07:10:31Z
39,287,160
<p>A Bash script needs to use the Unix EOL (End Of Line) convention, which terminates each line with <code>\n</code>. But it looks like your test.sh shell script file uses the Windows / DOS EOL convention, which terminates each line with <code>\r\n</code>. </p> <p>You need to get rid of those <code>\r</code> character...
1
2016-09-02T07:55:18Z
[ "python", "shell" ]