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 do I get the google username and email when someone login my site use google openid. (I used pinax)
2,264,193
<p><img src="http://omploader.org/vM2s2MA" alt="alt text"></p> <p>thanks</p> <p>the next is mysite1\django_openid\registration.py:</p> <pre><code>from django.http import HttpResponseRedirect from django.core.mail import send_mail from django.conf import settings from django_openid.auth import AuthConsumer from djan...
0
2010-02-15T05:39:44Z
2,264,211
<p>You ask the user. OpenID is inherently designed to not require providing anything <em>except</em> a user-unique identifier for authenticated users; any information beyond that is in the realm of application-specific.</p>
2
2010-02-15T05:43:09Z
[ "python", "django", "openid", "pinax" ]
String manipulation in Python
2,264,202
<p>I have a <strong>randomly</strong> generated string from 6 letters in this form, example:</p> <pre><code>A' B F2 E' B2 A2 C' D2 C D' E2 F </code></pre> <p>Some letters have " ' " added to them some have number "2". What i want is to add letter "x" to every letter that is on its own.</p> <p>So it would look like t...
1
2010-02-15T05:42:02Z
2,264,225
<p>Transform your string into list with split()</p> <pre><code>s = """A' B F2 E' B2 A2 C' D2 C D' E2 F""" L = s.split(' ') for i in xrange(len(L)): if len(L[i]) == 1: L[i] += 'x' str_out = ' '.join(L) </code></pre>
5
2010-02-15T05:45:44Z
[ "python" ]
String manipulation in Python
2,264,202
<p>I have a <strong>randomly</strong> generated string from 6 letters in this form, example:</p> <pre><code>A' B F2 E' B2 A2 C' D2 C D' E2 F </code></pre> <p>Some letters have " ' " added to them some have number "2". What i want is to add letter "x" to every letter that is on its own.</p> <p>So it would look like t...
1
2010-02-15T05:42:02Z
2,264,226
<p>With a regular expression,</p> <pre><code>import re newstring = re.sub(r"\b(\w)(?![2'])", r'\1x', oldstring) </code></pre> <p>should be fine. If you're allergic to <code>re</code>s,</p> <pre><code>news = ' '.join(x + 'x' if len(x)==1 else x for x in olds.split()) </code></pre> <p>is a concise way of expressing ...
2
2010-02-15T05:46:18Z
[ "python" ]
String manipulation in Python
2,264,202
<p>I have a <strong>randomly</strong> generated string from 6 letters in this form, example:</p> <pre><code>A' B F2 E' B2 A2 C' D2 C D' E2 F </code></pre> <p>Some letters have " ' " added to them some have number "2". What i want is to add letter "x" to every letter that is on its own.</p> <p>So it would look like t...
1
2010-02-15T05:42:02Z
2,264,230
<pre><code>' '.join(n if len(n) == 2 else n + 'x' for n in s.split(' ')) </code></pre>
1
2010-02-15T05:47:53Z
[ "python" ]
String manipulation in Python
2,264,202
<p>I have a <strong>randomly</strong> generated string from 6 letters in this form, example:</p> <pre><code>A' B F2 E' B2 A2 C' D2 C D' E2 F </code></pre> <p>Some letters have " ' " added to them some have number "2". What i want is to add letter "x" to every letter that is on its own.</p> <p>So it would look like t...
1
2010-02-15T05:42:02Z
2,264,236
<pre><code>&gt;&gt;&gt; s="A' B F2 E' B2 A2 C' D2 C D' E2 F".split() &gt;&gt;&gt; import string &gt;&gt;&gt; letters=list(string.letters) &gt;&gt;&gt; for n,i in enumerate(s): ... if i in letters: ... s[n]=i+"x" ... &gt;&gt;&gt; ' '.join(s) "A' Bx F2 E' B2 A2 C' D2 Cx D' E2 Fx" &gt;&gt;&gt; </code></pre>
1
2010-02-15T05:51:04Z
[ "python" ]
String manipulation in Python
2,264,202
<p>I have a <strong>randomly</strong> generated string from 6 letters in this form, example:</p> <pre><code>A' B F2 E' B2 A2 C' D2 C D' E2 F </code></pre> <p>Some letters have " ' " added to them some have number "2". What i want is to add letter "x" to every letter that is on its own.</p> <p>So it would look like t...
1
2010-02-15T05:42:02Z
2,264,238
<p>The split-comprehend-join version:</p> <pre><code>' '.join(n+'x' if len(n)==1 else n for n in inputstr.split(' ')) </code></pre> <p>The regex version:</p> <pre><code>&gt;&gt;&gt; inputstr = "A' F B2 C" &gt;&gt;&gt; re.sub(r'([A-Z])(?=\s|$)', r'\1x', inputstr) "A' Fx B2 Cx" </code></pre> <p>In essence, find any u...
4
2010-02-15T05:52:24Z
[ "python" ]
String manipulation in Python
2,264,202
<p>I have a <strong>randomly</strong> generated string from 6 letters in this form, example:</p> <pre><code>A' B F2 E' B2 A2 C' D2 C D' E2 F </code></pre> <p>Some letters have " ' " added to them some have number "2". What i want is to add letter "x" to every letter that is on its own.</p> <p>So it would look like t...
1
2010-02-15T05:42:02Z
2,264,264
<p>Ugly or Pythonic?</p> <pre><code>items = "A' B F2 E' B2 A2 C' D2 C D' E2 F".split() itemsx = ((a+'x' if len(a)==1 else a) for a in items) out = ' '.join(itemsx) </code></pre>
3
2010-02-15T06:02:39Z
[ "python" ]
String manipulation in Python
2,264,202
<p>I have a <strong>randomly</strong> generated string from 6 letters in this form, example:</p> <pre><code>A' B F2 E' B2 A2 C' D2 C D' E2 F </code></pre> <p>Some letters have " ' " added to them some have number "2". What i want is to add letter "x" to every letter that is on its own.</p> <p>So it would look like t...
1
2010-02-15T05:42:02Z
2,265,059
<pre><code>&gt;&gt;&gt; ' '.join((i+'x')[:2] for i in items.split()) "A' Bx F2 E' B2 A2 C' D2 Cx D' E2 Fx" </code></pre>
1
2010-02-15T09:52:37Z
[ "python" ]
Help generate Facebook API "Sig" in Python
2,264,333
<p>I have been struggling with this for over two days and I could use your help. Here's the problem:</p> <p>Whenever a request is made to the Facebook REST server, we have to send an additional parameter called "sig". This sig is generated using the following algorithm:</p> <pre><code>&lt;?php $secret = 'Secret Key'...
0
2010-02-15T06:25:55Z
2,271,763
<p>List had to be sorted.</p>
1
2010-02-16T09:33:10Z
[ "python", "google-app-engine", "facebook" ]
Creating a GUI Calculator in python similar to MS Calculator
2,264,371
<p>I need to write a code that runs similar to normal calculators in such a way that it displays the first number I type in, when i press the operand, the entry widget still displays the first number, but when i press the numbers for my second number, the first one gets replaced. I'm not to the point in writing the who...
1
2010-02-15T06:41:23Z
2,264,618
<p>What you need here is a concept of state. Each time a key is pressed, you check the state and determine what action to take.</p> <p>In the initial state, you take input of numbers.</p> <p>When an operand button is pressed, you store the operand, and change the state.</p> <p>When another number is pressed, you sto...
2
2010-02-15T08:03:44Z
[ "python", "user-interface", "calculator" ]
How do I prevent Qt buttons from appearing in a separate frame?
2,264,482
<p>I'm working on a PyQt application. Currently, there's a status panel (defined as a <code>QWidget</code>) which contains a <code>QHBoxLayout</code>. This layout is frequently updated with <code>QPushButton</code>s created by another portion of the application.</p> <p>Whenever the buttons which appear need to chan...
3
2010-02-15T07:26:32Z
2,264,592
<p>You should call the button's <code>close()</code> method. If you want it to be deleted when you close it, you can set the <code>Qt.WA_DeleteOnClose</code> attribute:</p> <pre><code>button.setAttribute(Qt.WA_DeleteOnClose) </code></pre>
2
2010-02-15T07:58:48Z
[ "python", "qt", "qt4", "pyqt", "pyqt4" ]
How do I prevent Qt buttons from appearing in a separate frame?
2,264,482
<p>I'm working on a PyQt application. Currently, there's a status panel (defined as a <code>QWidget</code>) which contains a <code>QHBoxLayout</code>. This layout is frequently updated with <code>QPushButton</code>s created by another portion of the application.</p> <p>Whenever the buttons which appear need to chan...
3
2010-02-15T07:26:32Z
2,265,975
<p>Try calling <code>QWidget::hide()</code> on the button before removing from the layout if you don't want to delete your button.</p>
2
2010-02-15T12:47:27Z
[ "python", "qt", "qt4", "pyqt", "pyqt4" ]
Permission problem of .egg of easy_install under windows7/vista
2,264,488
<p>I use the easy_install to install python packages in a virtuaenv under windows7. Due to the UAV, I have to run the CMD as administrator for installing packages. Here comes the problem, I notice that I can't import the package from a normal user account.</p> <pre><code>&gt;&gt;&gt; import tempita Traceback (most ...
1
2010-02-15T07:28:28Z
2,265,935
<p>I've started using <a href="http://pypi.python.org/pypi/distribute" rel="nofollow">distribute</a> in lieu of setuptools, because the distribute team has been much more proactive in tracking down problems. Curiously, it appears as if distribute no longer creates zip eggs on my Windows 7 system, perhaps for the permis...
0
2010-02-15T12:40:58Z
[ "python", "windows", "virtualenv", "easy-install" ]
Permission problem of .egg of easy_install under windows7/vista
2,264,488
<p>I use the easy_install to install python packages in a virtuaenv under windows7. Due to the UAV, I have to run the CMD as administrator for installing packages. Here comes the problem, I notice that I can't import the package from a normal user account.</p> <pre><code>&gt;&gt;&gt; import tempita Traceback (most ...
1
2010-02-15T07:28:28Z
2,265,951
<p>You might be able to use ICACLS to reset the file permissions.</p> <pre><code>ICACLS c:\Python26\lib\site-packages\*.egg /reset </code></pre> <p>I suggest trying it with one file first before doing <code>*.egg</code>. Note that <code>*.egg</code> will likely match egg folders as well.</p>
0
2010-02-15T12:43:00Z
[ "python", "windows", "virtualenv", "easy-install" ]
why i can't alert this string which is return from django render_to_response
2,264,503
<p>django code:</p> <pre><code>return render_to_response(template_name, { "form": form, }, context_instance=RequestContext(request)) </code></pre> <p>and html:</p> <pre><code>&lt;script type="text/javascript"&gt; var a='{{form}}' alert(a) &lt;/script&gt; </code></pre> <p>it's error is...
0
2010-02-15T07:33:31Z
2,264,569
<p>I am unable to reproduce this error, pasting the above into a javascript console works without problems. Is it possible that there is something else done with <code>a</code>? Is above a simplification or exact javascript? Maybe you can show the entire HTML?</p>
0
2010-02-15T07:52:49Z
[ "javascript", "python", "django" ]
why i can't alert this string which is return from django render_to_response
2,264,503
<p>django code:</p> <pre><code>return render_to_response(template_name, { "form": form, }, context_instance=RequestContext(request)) </code></pre> <p>and html:</p> <pre><code>&lt;script type="text/javascript"&gt; var a='{{form}}' alert(a) &lt;/script&gt; </code></pre> <p>it's error is...
0
2010-02-15T07:33:31Z
2,264,604
<p>Maybe try putting in semi-colons at the ends of the lines in your Django template file?</p> <pre><code>&lt;script type="text/javascript"&gt; var a='{{form}}'; alert(a); &lt;/script&gt; </code></pre> <p>Odd though, I’m pretty sure semi-colons are optional there. Could you do a View Source in Firefox (ins...
1
2010-02-15T08:00:21Z
[ "javascript", "python", "django" ]
why i can't alert this string which is return from django render_to_response
2,264,503
<p>django code:</p> <pre><code>return render_to_response(template_name, { "form": form, }, context_instance=RequestContext(request)) </code></pre> <p>and html:</p> <pre><code>&lt;script type="text/javascript"&gt; var a='{{form}}' alert(a) &lt;/script&gt; </code></pre> <p>it's error is...
0
2010-02-15T07:33:31Z
2,265,571
<p>Check the HTML source of the page using "View source" rather than Firebug. I predict your <code>{{form}}</code> value has a line break in it, which will cause the error you're seeing.</p>
1
2010-02-15T11:32:46Z
[ "javascript", "python", "django" ]
processing text from a non-flat file (to extract information as if it *were* a flat file)
2,264,504
<p>I have a longitudinal data set generated by a computer simulation that can be represented by the following tables ('var' are variables):</p> <pre><code>time subject var1 var2 var3 t1 subjectA ... t2 subjectB ... </code></pre> <p>and</p> <pre><code>subject name subjectA nameA subjectB nameB </code></pre>...
4
2010-02-15T07:33:49Z
2,264,593
<p>If all you want is var1, var2, var3 upon matching a particular subject then you could try the following command:<pre><code> grep -A 1 'subjectB' </code></pre></p> <p>The <code>-A 1</code> command line argument instructs grep to print out the matched line and one line after the matched line (and in this case the v...
2
2010-02-15T07:58:50Z
[ "python", "perl", "awk", "text-processing", "flat-file" ]
processing text from a non-flat file (to extract information as if it *were* a flat file)
2,264,504
<p>I have a longitudinal data set generated by a computer simulation that can be represented by the following tables ('var' are variables):</p> <pre><code>time subject var1 var2 var3 t1 subjectA ... t2 subjectB ... </code></pre> <p>and</p> <pre><code>subject name subjectA nameA subjectB nameB </code></pre>...
4
2010-02-15T07:33:49Z
2,264,679
<p>If you are lazy and have enough RAM, then I would work on a RAM disk instead of the file system as long as you need them immediately.<br> I do not think that Perl or awk will be faster than Python if you are just recoding your current algorithm into a different language.</p>
1
2010-02-15T08:16:46Z
[ "python", "perl", "awk", "text-processing", "flat-file" ]
processing text from a non-flat file (to extract information as if it *were* a flat file)
2,264,504
<p>I have a longitudinal data set generated by a computer simulation that can be represented by the following tables ('var' are variables):</p> <pre><code>time subject var1 var2 var3 t1 subjectA ... t2 subjectB ... </code></pre> <p>and</p> <pre><code>subject name subjectA nameA subjectB nameB </code></pre>...
4
2010-02-15T07:33:49Z
2,264,838
<pre><code>awk '/time/{f=0}/subjectB/{f=1;next}f' file </code></pre>
1
2010-02-15T09:03:48Z
[ "python", "perl", "awk", "text-processing", "flat-file" ]
processing text from a non-flat file (to extract information as if it *were* a flat file)
2,264,504
<p>I have a longitudinal data set generated by a computer simulation that can be represented by the following tables ('var' are variables):</p> <pre><code>time subject var1 var2 var3 t1 subjectA ... t2 subjectB ... </code></pre> <p>and</p> <pre><code>subject name subjectA nameA subjectB nameB </code></pre>...
4
2010-02-15T07:33:49Z
2,265,958
<p>The best option would be to modify the computer simulation to produce rectangular output. Assuming you can't do that, here's one approach:</p> <p>In order to be able to use the data in R, SQL, etc. you need to convert it from hierarchical to rectangular one way or another. If you already have a parser that can conv...
2
2010-02-15T12:43:56Z
[ "python", "perl", "awk", "text-processing", "flat-file" ]
processing text from a non-flat file (to extract information as if it *were* a flat file)
2,264,504
<p>I have a longitudinal data set generated by a computer simulation that can be represented by the following tables ('var' are variables):</p> <pre><code>time subject var1 var2 var3 t1 subjectA ... t2 subjectB ... </code></pre> <p>and</p> <pre><code>subject name subjectA nameA subjectB nameB </code></pre>...
4
2010-02-15T07:33:49Z
2,266,122
<p>This is what Python generators are all about.</p> <pre><code>def read_as_flat( someFile ): line_iter= iter(someFile) time_header= None for line in line_iter: words = line.split() if words[0] == 'time': time_header = [ words[1:] ] # the "time" line description= lin...
4
2010-02-15T13:14:27Z
[ "python", "perl", "awk", "text-processing", "flat-file" ]
Python csv tags
2,264,567
<p>I have a csv file with different headers. </p> <pre><code>name,city john doe,chicago </code></pre> <p>Have headers as</p> <pre><code>reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers = reader.fieldnames </code></pre> <p>How will you run a regex that whenever a tag [name] was to be proceesed...
0
2010-02-15T07:52:35Z
2,264,712
<p>You <em>could</em> use <a href="http://docs.python.org/library/re.html#re.sub" rel="nofollow"><code>re.sub()</code></a> with a function passed as <code>repl</code>, or you could just use <a href="http://docs.python.org/library/stdtypes.html#string-formatting-operations" rel="nofollow">string interpolation</a> with a...
0
2010-02-15T08:26:24Z
[ "python", "csv" ]
how to build a python proxy server on google appengine
2,264,583
<p>I live in China and the Great Firewall blocked Youtube and twitter. So I want to build a proxy server on google appengine in python to bypass that. Does anyone know any open source GAE project on that? Thx~</p>
4
2010-02-15T07:55:43Z
2,264,602
<p>You may try gappproxy <a href="http://code.google.com/p/gappproxy/" rel="nofollow">http://code.google.com/p/gappproxy/</a></p> <p>But since the keyword <strong>gappproxy</strong> is blocked by censors, which means you cannot visit any url containing the keyword in China, you may first find a web proxy like <a href=...
4
2010-02-15T08:00:13Z
[ "python", "google-app-engine", "proxy" ]
how to build a python proxy server on google appengine
2,264,583
<p>I live in China and the Great Firewall blocked Youtube and twitter. So I want to build a proxy server on google appengine in python to bypass that. Does anyone know any open source GAE project on that? Thx~</p>
4
2010-02-15T07:55:43Z
4,219,347
<p>please try to use <a href="http://proxy202.appspot.com" rel="nofollow">http://proxy202.appspot.com</a></p>
1
2010-11-18T20:38:48Z
[ "python", "google-app-engine", "proxy" ]
Ready implementation of multivariate Spearman rank correlation
2,264,609
<p>I'm looking for a way to calculate multivariate version of Spearman rank correlation $\rho$. Are there any ready to use Python implementation I can use?</p>
1
2010-02-15T08:01:12Z
2,264,675
<p>There is one in <a href="http://www.scipy.org/doc/api_docs/SciPy.stats.stats.html#spearmanr" rel="nofollow">scipy</a>.</p>
2
2010-02-15T08:16:00Z
[ "python", "statistics", "correlation" ]
Ready implementation of multivariate Spearman rank correlation
2,264,609
<p>I'm looking for a way to calculate multivariate version of Spearman rank correlation $\rho$. Are there any ready to use Python implementation I can use?</p>
1
2010-02-15T08:01:12Z
2,271,536
<p>If now or in the future you will want access to some advanced statistical packages, also consider calling R libraries from Python when needed via the <a href="http://rpy.sourceforge.net/rpy2/doc-2.1/html/index.html" rel="nofollow">RPy2</a>. </p> <p>And then you can compute spearman using a package such as <a href="...
1
2010-02-16T08:45:01Z
[ "python", "statistics", "correlation" ]
Python: Draw a 2d grid and allow coloring of cells
2,264,631
<p>I want to simulate the game of life problem using python. I want to draw a grid and be able to color its cells as the simulation progresses. How do I do that in Python?</p>
5
2010-02-15T08:06:25Z
2,264,651
<p>I suggest taking a look at the Python Imaging Library (PIL) <a href="http://www.pythonware.com/library/pil/handbook/index.htm" rel="nofollow">documentation</a></p>
1
2010-02-15T08:09:10Z
[ "python" ]
Python: Draw a 2d grid and allow coloring of cells
2,264,631
<p>I want to simulate the game of life problem using python. I want to draw a grid and be able to color its cells as the simulation progresses. How do I do that in Python?</p>
5
2010-02-15T08:06:25Z
2,264,662
<p>Take a look at <a href="http://www.pygame.org" rel="nofollow">PyGame</a> too.</p>
4
2010-02-15T08:12:04Z
[ "python" ]
Python: Draw a 2d grid and allow coloring of cells
2,264,631
<p>I want to simulate the game of life problem using python. I want to draw a grid and be able to color its cells as the simulation progresses. How do I do that in Python?</p>
5
2010-02-15T08:06:25Z
2,264,666
<p>You can use <a href="http://www.pygame.org/">pygame</a> to do that.</p> <p>To display the state of your simulation, you should create an 8 bit surface with a palette, and access it with the <a href="http://www.pygame.org/docs/ref/surfarray.html">pygame.surfarray</a> module.</p>
8
2010-02-15T08:13:06Z
[ "python" ]
Python: Draw a 2d grid and allow coloring of cells
2,264,631
<p>I want to simulate the game of life problem using python. I want to draw a grid and be able to color its cells as the simulation progresses. How do I do that in Python?</p>
5
2010-02-15T08:06:25Z
2,264,710
<p>I suggest <a href="http://www.tuxradar.com/gloss" rel="nofollow">Gloss</a>, it's like PyGame except hardware accelerated. It also provides many other game-programming goodies.</p>
2
2010-02-15T08:26:05Z
[ "python" ]
Python: Draw a 2d grid and allow coloring of cells
2,264,631
<p>I want to simulate the game of life problem using python. I want to draw a grid and be able to color its cells as the simulation progresses. How do I do that in Python?</p>
5
2010-02-15T08:06:25Z
27,118,000
<p>I know this is an old post, but in the name of building the perfect QA site, I would suggest <a href="http://matplotlib.org/" rel="nofollow">matplotlib</a>.</p> <p>As of this writing, it looks like matplotlib development is getting more attention than <a href="https://bitbucket.org/pygame/pygame/src" rel="nofollow"...
1
2014-11-25T02:48:14Z
[ "python" ]
How do i get the username and email when someone logins to my site using google or openid? What does google return?
2,264,669
<p>i used pinax, the user who login my site, use openid, is successful now. i only want to get the username and email when they return .</p> <p>the google openid url is :https://www.google.com/accounts/o8/id</p> <p>and yahoo openid url is :http://yahoo.com/</p> <p>How can i get it?</p>
-1
2010-02-15T08:13:57Z
2,264,682
<p>Use <a href="http://code.google.com/p/django-openid/" rel="nofollow">http://code.google.com/p/django-openid/</a> (documentation available at <a href="http://django-openid.googlecode.com/svn/trunk/openid.html" rel="nofollow">http://django-openid.googlecode.com/svn/trunk/openid.html</a>)</p>
1
2010-02-15T08:17:42Z
[ "python", "django", "openid", "pinax" ]
How do i get the username and email when someone logins to my site using google or openid? What does google return?
2,264,669
<p>i used pinax, the user who login my site, use openid, is successful now. i only want to get the username and email when they return .</p> <p>the google openid url is :https://www.google.com/accounts/o8/id</p> <p>and yahoo openid url is :http://yahoo.com/</p> <p>How can i get it?</p>
-1
2010-02-15T08:13:57Z
2,264,686
<p>There are two main methods to do this. One is using the "simple registration" (sreg) extension of OpenID. This seems like the easiest way, and while it worked when using myopenid.net as my endpoint, but I couldn't get it to work with Google.</p> <p>The second method is by using the "attribute exchange" (ax) extens...
1
2010-02-15T08:19:51Z
[ "python", "django", "openid", "pinax" ]
How do i get the username and email when someone logins to my site using google or openid? What does google return?
2,264,669
<p>i used pinax, the user who login my site, use openid, is successful now. i only want to get the username and email when they return .</p> <p>the google openid url is :https://www.google.com/accounts/o8/id</p> <p>and yahoo openid url is :http://yahoo.com/</p> <p>How can i get it?</p>
-1
2010-02-15T08:13:57Z
4,221,708
<p>@jamieb - maybe you meant myopenid.com?</p> <p>Even if late, I wish to share my experience on the question to help others. I spent a day on these!</p> <p>I used <a href="https://github.com/flashingpumpkin/django-socialregistration" rel="nofollow">https://github.com/flashingpumpkin/django-socialregistration</a> an...
0
2010-11-19T02:55:59Z
[ "python", "django", "openid", "pinax" ]
Embed Google Docs PDF viewer in IFRAME
2,264,684
<p>When I upload PDF to Google Docs (using Python's gdata library), I get link to the document:</p> <pre><code>&gt;&gt;&gt; e.GetAlternateLink().href Out[14]: 'http://docs.google.com/a/my.dom.ain/fileview id=&lt;veery-long-doc-id&gt;&amp;hl=en' </code></pre> <p>Unfortunately using that link in IFRAME is not working f...
4
2010-02-15T08:18:32Z
2,311,327
<p>Just for the record - I haven't found any way to force "internal" google google pdf viewer to not go out of the iframe. And as I mentioned in the question, I found this nice standalone viewer: <a href="http://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html" rel="nofollow">http://googlesystem...
7
2010-02-22T14:05:42Z
[ "python", "gdata-api", "google-docs" ]
Embed Google Docs PDF viewer in IFRAME
2,264,684
<p>When I upload PDF to Google Docs (using Python's gdata library), I get link to the document:</p> <pre><code>&gt;&gt;&gt; e.GetAlternateLink().href Out[14]: 'http://docs.google.com/a/my.dom.ain/fileview id=&lt;veery-long-doc-id&gt;&amp;hl=en' </code></pre> <p>Unfortunately using that link in IFRAME is not working f...
4
2010-02-15T08:18:32Z
2,314,353
<p>To embed pdf files present in your google docs into your website use the below code:</p> <pre><code>&lt;iframe src="http://docs.google.com/gview?a=v&amp;pid=explorer&amp;chrome=false&amp;api=true&amp;embedded=true&amp;srcid=&lt;id of your pdf&gt;&amp;hl=en&amp;embedded=true" style="width:600px; height:500px;" frame...
2
2010-02-22T21:29:39Z
[ "python", "gdata-api", "google-docs" ]
Embed Google Docs PDF viewer in IFRAME
2,264,684
<p>When I upload PDF to Google Docs (using Python's gdata library), I get link to the document:</p> <pre><code>&gt;&gt;&gt; e.GetAlternateLink().href Out[14]: 'http://docs.google.com/a/my.dom.ain/fileview id=&lt;veery-long-doc-id&gt;&amp;hl=en' </code></pre> <p>Unfortunately using that link in IFRAME is not working f...
4
2010-02-15T08:18:32Z
2,944,522
<p>The Google Docs embedding in iframes via the viewer is problematic in IE8 if not already cached, and is is just not equal to the much better Scribd's facility that allows you to simply make a simple html page with the document embeded via their supplied object code for the document. I then use it as the source file ...
1
2010-05-31T15:36:56Z
[ "python", "gdata-api", "google-docs" ]
if i have the key of google openid when someone who login my site,how do i get the username
2,264,833
<p>if the key is <a href="https://www.google.com/accounts/o8/id?id=AItOawmqS0V2RR5FihojGdC90vXJpjcukoZ" rel="nofollow">https://www.google.com/accounts/o8/id?id=AItOawmqS0V2RR5FihojGdC90vXJpjcukoZ</a></p> <p>how do i get the username who login my site ?</p> <p>thanks</p>
0
2010-02-15T09:03:16Z
2,264,850
<p>I am afraid, that with OpenID, the URL really is the closest thing to a user name. According to <a href="http://en.wikipedia.org/wiki/OpenID" rel="nofollow">Wikipedia</a>:</p> <blockquote> <p>Unlike a typical login form with fields for the user name and password, the OpenID login form has only one field—for the...
1
2010-02-15T09:05:34Z
[ "python", "django", "openid" ]
if i have the key of google openid when someone who login my site,how do i get the username
2,264,833
<p>if the key is <a href="https://www.google.com/accounts/o8/id?id=AItOawmqS0V2RR5FihojGdC90vXJpjcukoZ" rel="nofollow">https://www.google.com/accounts/o8/id?id=AItOawmqS0V2RR5FihojGdC90vXJpjcukoZ</a></p> <p>how do i get the username who login my site ?</p> <p>thanks</p>
0
2010-02-15T09:03:16Z
2,264,877
<p>Yup, the point with OpenID if you still need them to have an identifier to your page / site is to have a backend DB that attributes that key (openid url) with their identifier (key / username) on your site.</p> <p>So googles A410d314 OpenID URL key is your 'superuser23' username. It can be a many to one correlation...
0
2010-02-15T09:15:10Z
[ "python", "django", "openid" ]
What statically typed languages are similar to Python?
2,264,889
<p>Python is the nicest language I currently know of, but static typing is a big advantage due to auto-completion (although there is limited support for dynamic languages, it is nothing compared to that supported in static). I'm curious if there are any languages which try to add the benefits of Python to a statically ...
36
2010-02-15T09:17:44Z
2,264,900
<p><a href="https://github.com/bamboo/boo/wiki" rel="nofollow">Boo</a> is a statically typed language for the Common Language Infrastructure (aka. the Microsoft .NET platform). The syntax is <em>highly</em> inspired by Python, and hashes/lists/array are part of the syntax:</p> <pre><code>i = 5 if i &gt; 5: print "...
34
2010-02-15T09:20:09Z
[ "python", "programming-languages" ]
What statically typed languages are similar to Python?
2,264,889
<p>Python is the nicest language I currently know of, but static typing is a big advantage due to auto-completion (although there is limited support for dynamic languages, it is nothing compared to that supported in static). I'm curious if there are any languages which try to add the benefits of Python to a statically ...
36
2010-02-15T09:17:44Z
2,264,904
<p>It may not match all your needs, but have a look at <a href="http://boo.codehaus.org/" rel="nofollow">Boo - The wristfriendly language for the CLI</a></p> <p>If you do, I highly recommend <a href="http://www.manning.com/rahien/" rel="nofollow">DSLs in Boo: Domain-Specific Languages in .NET</a> which apart from the ...
7
2010-02-15T09:20:57Z
[ "python", "programming-languages" ]
What statically typed languages are similar to Python?
2,264,889
<p>Python is the nicest language I currently know of, but static typing is a big advantage due to auto-completion (although there is limited support for dynamic languages, it is nothing compared to that supported in static). I'm curious if there are any languages which try to add the benefits of Python to a statically ...
36
2010-02-15T09:17:44Z
2,265,030
<p>Autocompletion is still possible in a dynamically typed language; nothing prevents the IDE from doing type inference or inspection, even if the language implementation doesn't.</p>
1
2010-02-15T09:49:13Z
[ "python", "programming-languages" ]
What statically typed languages are similar to Python?
2,264,889
<p>Python is the nicest language I currently know of, but static typing is a big advantage due to auto-completion (although there is limited support for dynamic languages, it is nothing compared to that supported in static). I'm curious if there are any languages which try to add the benefits of Python to a statically ...
36
2010-02-15T09:17:44Z
2,265,062
<p>If auto-completion is the thing you are looking for, then you might wanna stick with Python and use a great IDE instead.</p> <p>Try PyCharm: <a href="http://www.jetbrains.com/pycharm/index.html" rel="nofollow">http://www.jetbrains.com/pycharm/index.html</a></p> <p>Unless you are coding some extremely dynamic stuff...
1
2010-02-15T09:52:59Z
[ "python", "programming-languages" ]
What statically typed languages are similar to Python?
2,264,889
<p>Python is the nicest language I currently know of, but static typing is a big advantage due to auto-completion (although there is limited support for dynamic languages, it is nothing compared to that supported in static). I'm curious if there are any languages which try to add the benefits of Python to a statically ...
36
2010-02-15T09:17:44Z
2,266,037
<p><a href="http://cobra-language.com/">Cobra</a> is a statically typed language for the CLR (as Boo). From its web page:</p> <blockquote> <p>Cobra is a general purpose programming language with:</p> <pre><code> - a clean, high-level syntax - static and dynamic binding - first class support for unit tests and c...
12
2010-02-15T12:59:54Z
[ "python", "programming-languages" ]
What statically typed languages are similar to Python?
2,264,889
<p>Python is the nicest language I currently know of, but static typing is a big advantage due to auto-completion (although there is limited support for dynamic languages, it is nothing compared to that supported in static). I'm curious if there are any languages which try to add the benefits of Python to a statically ...
36
2010-02-15T09:17:44Z
2,268,450
<p>The D programming language is a statically typed, natively compiled language that has some significant features inspired by Python.</p> <p>Arrays and associative arrays are built into the language. There are no list comprehensions, but the std.range and std.algorithm libraries fill much of that void. For example,...
3
2010-02-15T19:39:14Z
[ "python", "programming-languages" ]
What statically typed languages are similar to Python?
2,264,889
<p>Python is the nicest language I currently know of, but static typing is a big advantage due to auto-completion (although there is limited support for dynamic languages, it is nothing compared to that supported in static). I'm curious if there are any languages which try to add the benefits of Python to a statically ...
36
2010-02-15T09:17:44Z
2,269,515
<p>Although it is not object-oriented, <a href="http://www.haskell.org/"><strong>Haskell</strong></a> offers a significant number of the features that interest you:</p> <ul> <li><p>Syntax support for list comprehensions, plus <code>do</code> notation for a wide variety of sequencing/binding constructs. (Syntax suppor...
8
2010-02-15T22:53:28Z
[ "python", "programming-languages" ]
What statically typed languages are similar to Python?
2,264,889
<p>Python is the nicest language I currently know of, but static typing is a big advantage due to auto-completion (although there is limited support for dynamic languages, it is nothing compared to that supported in static). I'm curious if there are any languages which try to add the benefits of Python to a statically ...
36
2010-02-15T09:17:44Z
2,269,524
<p>try the Go programming language ? I've seen some similar paradigm.</p>
7
2010-02-15T22:56:05Z
[ "python", "programming-languages" ]
What statically typed languages are similar to Python?
2,264,889
<p>Python is the nicest language I currently know of, but static typing is a big advantage due to auto-completion (although there is limited support for dynamic languages, it is nothing compared to that supported in static). I'm curious if there are any languages which try to add the benefits of Python to a statically ...
36
2010-02-15T09:17:44Z
7,788,014
<p>I think Eric and PyScripter have nice autocompletion on Windows, but maybe not as good as PyTools for Visual Studio (Express).</p> <p>For static typing in Python, i'd use Cython: <a href="http://docs.cython.org/src/quickstart/cythonize.html" rel="nofollow">http://docs.cython.org/src/quickstart/cythonize.html</a></p...
0
2011-10-16T23:13:09Z
[ "python", "programming-languages" ]
What statically typed languages are similar to Python?
2,264,889
<p>Python is the nicest language I currently know of, but static typing is a big advantage due to auto-completion (although there is limited support for dynamic languages, it is nothing compared to that supported in static). I'm curious if there are any languages which try to add the benefits of Python to a statically ...
36
2010-02-15T09:17:44Z
13,959,384
<p>Rpython is a subset of python that is statically typed.</p>
3
2012-12-19T19:08:28Z
[ "python", "programming-languages" ]
How can I install django-stdimage in my django project, rather than as a module (jailed shell, no path access)
2,264,959
<p>The question about covers it. I'm using dreamhost, and need to utilize the stdimagefield rather than image field so I can do this:</p> <pre><code> image3 = StdImageField(upload_to='path/to/img', size=(640, 480)) </code></pre> <p>If there is a better way to do this, please let me know.</p> <p>Edit: Trying it like ...
0
2010-02-15T09:36:22Z
2,265,000
<p>Just put the <code>django-stdimage</code> folder into your project folder (it should already be a package).</p>
0
2010-02-15T09:43:44Z
[ "python", "django", "module", "dreamhost" ]
How can I install django-stdimage in my django project, rather than as a module (jailed shell, no path access)
2,264,959
<p>The question about covers it. I'm using dreamhost, and need to utilize the stdimagefield rather than image field so I can do this:</p> <pre><code> image3 = StdImageField(upload_to='path/to/img', size=(640, 480)) </code></pre> <p>If there is a better way to do this, please let me know.</p> <p>Edit: Trying it like ...
0
2010-02-15T09:36:22Z
2,265,001
<p>Just copy the module contents into your project, making it a package if necessary. I put "external" modules in an <code>external</code> package.</p>
0
2010-02-15T09:44:02Z
[ "python", "django", "module", "dreamhost" ]
How to read from stdin or from a file if no data is piped in Python?
2,264,991
<p>I have a CLI script and want it to read data from a file. It should be able to read it in two ways :</p> <ul> <li><code>cat data.txt | ./my_script.py</code></li> <li><code>./my_script.py data.txt</code></li> </ul> <p>—a bit like <code>grep</code>, for example.</p> <p>What I know:</p> <ul> <li><code>sys.argv</c...
16
2010-02-15T09:42:17Z
2,265,010
<p>There is no reliable way to detect if <code>sys.stdin</code> is connected to anything, nor is it appropriate do so (e.g., the user wants to paste the data in). Detect the presence of a filename as an argument, and use stdin if none is found.</p>
3
2010-02-15T09:46:03Z
[ "python", "pipe", "stdin", "command-line-interface" ]
How to read from stdin or from a file if no data is piped in Python?
2,264,991
<p>I have a CLI script and want it to read data from a file. It should be able to read it in two ways :</p> <ul> <li><code>cat data.txt | ./my_script.py</code></li> <li><code>./my_script.py data.txt</code></li> </ul> <p>—a bit like <code>grep</code>, for example.</p> <p>What I know:</p> <ul> <li><code>sys.argv</c...
16
2010-02-15T09:42:17Z
2,265,114
<p>For unix/linux you can detect whether data is being piped in by looking at <code>os.isatty(0)</code></p> <pre><code>$ date | python -c "import os;print os.isatty(0)" False $ python -c "import os;print os.isatty(0)" True </code></pre> <p>I'm not sure there is an equivalent for Windows.</p> <p><strong>edit</strong>...
7
2010-02-15T10:00:54Z
[ "python", "pipe", "stdin", "command-line-interface" ]
How to read from stdin or from a file if no data is piped in Python?
2,264,991
<p>I have a CLI script and want it to read data from a file. It should be able to read it in two ways :</p> <ul> <li><code>cat data.txt | ./my_script.py</code></li> <li><code>./my_script.py data.txt</code></li> </ul> <p>—a bit like <code>grep</code>, for example.</p> <p>What I know:</p> <ul> <li><code>sys.argv</c...
16
2010-02-15T09:42:17Z
2,265,246
<p><a href="http://code.google.com/p/argparse/">Argparse</a> allows this to be done in a fairly easy manner, and you really should be using it instead of <code>optparse</code> unless you have compatibility issues.</p> <p>The code would go something like this:</p> <pre><code>import argparse parser = argparse.ArgumentP...
16
2010-02-15T10:26:15Z
[ "python", "pipe", "stdin", "command-line-interface" ]
How to read from stdin or from a file if no data is piped in Python?
2,264,991
<p>I have a CLI script and want it to read data from a file. It should be able to read it in two ways :</p> <ul> <li><code>cat data.txt | ./my_script.py</code></li> <li><code>./my_script.py data.txt</code></li> </ul> <p>—a bit like <code>grep</code>, for example.</p> <p>What I know:</p> <ul> <li><code>sys.argv</c...
16
2010-02-15T09:42:17Z
2,265,277
<p>Process your non-filename arguments however you'd like, so you wind up with an array of non-option arguments, then pass that array as the parameter to fileinput.input():</p> <pre><code>import fileinput for line in fileinput.input(remaining_args): process(line) </code></pre>
10
2010-02-15T10:32:30Z
[ "python", "pipe", "stdin", "command-line-interface" ]
How to read from stdin or from a file if no data is piped in Python?
2,264,991
<p>I have a CLI script and want it to read data from a file. It should be able to read it in two ways :</p> <ul> <li><code>cat data.txt | ./my_script.py</code></li> <li><code>./my_script.py data.txt</code></li> </ul> <p>—a bit like <code>grep</code>, for example.</p> <p>What I know:</p> <ul> <li><code>sys.argv</c...
16
2010-02-15T09:42:17Z
11,431,733
<p>You can use this function to detect if the input is from a pipeline or not.</p> <pre><code>sys.stdin.isatty() </code></pre> <p>It returns false if the input is from pipeline or true otherwise.</p>
2
2012-07-11T11:32:10Z
[ "python", "pipe", "stdin", "command-line-interface" ]
How to read from stdin or from a file if no data is piped in Python?
2,264,991
<p>I have a CLI script and want it to read data from a file. It should be able to read it in two ways :</p> <ul> <li><code>cat data.txt | ./my_script.py</code></li> <li><code>./my_script.py data.txt</code></li> </ul> <p>—a bit like <code>grep</code>, for example.</p> <p>What I know:</p> <ul> <li><code>sys.argv</c...
16
2010-02-15T09:42:17Z
14,653,679
<p>I'm a noob, so this might not be a good answer, but I'm trying to do the same thing (allow one or more files on the command line, default to STDIN otherwise).</p> <p>The final combo I put together:</p> <pre><code>parser = argparse.ArgumentParser() parser.add_argument("infiles", nargs="*") args = parser.parse_args(...
3
2013-02-01T19:33:31Z
[ "python", "pipe", "stdin", "command-line-interface" ]
How can I write a Python list to persistent storage?
2,265,016
<p>I am currently trying to solve this problem in MySQL. I have MySQLdb installed. What is the best way to write a list in Python, e.g.</p> <pre><code>[1, 2, -1, -2] </code></pre> <p>to a column of a MySQL database table? I would like each consecutive entry of the list to be put into consecutive rows of a MySQL colum...
1
2010-02-15T09:46:39Z
2,265,033
<p>You're looking for <a href="http://www.python.org/dev/peps/pep-0249/" rel="nofollow"><code>executemany()</code></a>.</p>
2
2010-02-15T09:49:26Z
[ "python", "mysql", "storage" ]
How can I write a Python list to persistent storage?
2,265,016
<p>I am currently trying to solve this problem in MySQL. I have MySQLdb installed. What is the best way to write a list in Python, e.g.</p> <pre><code>[1, 2, -1, -2] </code></pre> <p>to a column of a MySQL database table? I would like each consecutive entry of the list to be put into consecutive rows of a MySQL colum...
1
2010-02-15T09:46:39Z
2,265,042
<p>Caution: There is no notion of consecutive rows in SQL.</p> <p>The order of input is not recorded in the SQL database unless you also have an auto increment column that is automatically updated as you insert data or some other way to order the data on input, and the order of output depends on your ORDER BY clause.<...
2
2010-02-15T09:49:50Z
[ "python", "mysql", "storage" ]
Python: How to access parent class object through derived class instance?
2,265,060
<p>I'm sorry for my silly question, but... let's suppose I have these classes:</p> <pre><code>class A(): msg = 'hehehe' class B(A): msg = 'hohoho' class C(B): pass </code></pre> <p>and an instance of B or C. How do I get the variable 'msg' from the parent's class object through this instance? I've tried...
2
2010-02-15T09:52:51Z
2,265,084
<p>Try with:</p> <pre><code>class A(object): msg = 'hehehe' </code></pre> <p>EDIT:</p> <p>For the 'msg' attribute you would need:</p> <pre><code>foo = B() bar = super(foo.__class__, foo) print bar.msg </code></pre>
1
2010-02-15T09:56:11Z
[ "python" ]
Python: How to access parent class object through derived class instance?
2,265,060
<p>I'm sorry for my silly question, but... let's suppose I have these classes:</p> <pre><code>class A(): msg = 'hehehe' class B(A): msg = 'hohoho' class C(B): pass </code></pre> <p>and an instance of B or C. How do I get the variable 'msg' from the parent's class object through this instance? I've tried...
2
2010-02-15T09:52:51Z
2,265,097
<p>As <code>msg</code> is a class variable, you can just do:</p> <pre><code>print C.msg # prints hohoho </code></pre> <p>If you overwrite the variable (as you do in class <code>B</code>), you have to find the right parent class. Remember that Python supports <strong>multiple inheritance</strong>.</p> <p>But as yo...
1
2010-02-15T09:58:22Z
[ "python" ]
Python: How to access parent class object through derived class instance?
2,265,060
<p>I'm sorry for my silly question, but... let's suppose I have these classes:</p> <pre><code>class A(): msg = 'hehehe' class B(A): msg = 'hohoho' class C(B): pass </code></pre> <p>and an instance of B or C. How do I get the variable 'msg' from the parent's class object through this instance? I've tried...
2
2010-02-15T09:52:51Z
2,265,131
<p>If the class is single-inherited:</p> <pre><code>foo = B() print foo.__class__.__bases__[0].msg # 'hehehe' </code></pre> <p>If the class is multiple-inherited, the question makes no sense because there may be multiple classes defining the 'msg', and they could all be meaningful. You'd better provide the actual par...
6
2010-02-15T10:03:29Z
[ "python" ]
Python: How to access parent class object through derived class instance?
2,265,060
<p>I'm sorry for my silly question, but... let's suppose I have these classes:</p> <pre><code>class A(): msg = 'hehehe' class B(A): msg = 'hohoho' class C(B): pass </code></pre> <p>and an instance of B or C. How do I get the variable 'msg' from the parent's class object through this instance? I've tried...
2
2010-02-15T09:52:51Z
2,265,136
<pre><code>#for B() you can use __bases__ print foo.__class__.__bases__[0].msg </code></pre> <p>But this is not gonna be easy when there are multiple base classes and/or the depth of hierarchy is not one.</p>
0
2010-02-15T10:05:37Z
[ "python" ]
Python: How to access parent class object through derived class instance?
2,265,060
<p>I'm sorry for my silly question, but... let's suppose I have these classes:</p> <pre><code>class A(): msg = 'hehehe' class B(A): msg = 'hohoho' class C(B): pass </code></pre> <p>and an instance of B or C. How do I get the variable 'msg' from the parent's class object through this instance? I've tried...
2
2010-02-15T09:52:51Z
2,265,159
<p>Not sure why you want to do this</p> <pre><code>&gt;&gt;&gt; class A(object): ... msg = 'hehehe' ... &gt;&gt;&gt; class B(A): ... msg = 'hohoho' ... &gt;&gt;&gt; foo=B() &gt;&gt;&gt; foo.__class__.__mro__[1].msg 'hehehe' &gt;&gt;&gt; </code></pre>
2
2010-02-15T10:08:50Z
[ "python" ]
Python: How to access parent class object through derived class instance?
2,265,060
<p>I'm sorry for my silly question, but... let's suppose I have these classes:</p> <pre><code>class A(): msg = 'hehehe' class B(A): msg = 'hohoho' class C(B): pass </code></pre> <p>and an instance of B or C. How do I get the variable 'msg' from the parent's class object through this instance? I've tried...
2
2010-02-15T09:52:51Z
2,265,207
<p>You actually want to use</p> <pre><code>class A(object): ... ... b = B() bar = super(b.__class__, b) print bar.msg </code></pre> <p>Base classes must be new-style classes (inherit from <code>object</code>)</p>
14
2010-02-15T10:17:47Z
[ "python" ]
How to notify user when django's custom action doesn't behave as expected?
2,265,101
<p>I am writing a custom action for django admin. This action should only work for records having particular state. </p> <p>For example "Approve Blog" custom action should approve user blog only when blog is not approved. <strong>And it must not appove rejected blogs</strong>. </p> <p>One option is to filter non appr...
0
2010-02-15T09:58:51Z
2,265,950
<p>The documentation on admin actions is quite helpful, so go <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/" rel="nofollow">take a look</a>!</p> <p>I think just writing an action that only updates non-rejected blogs ought to do.</p> <p>The following code assumes you've got variables <code>r...
1
2010-02-15T12:42:59Z
[ "python", "django", "django-admin" ]
Design pattern to organize non-trivial ORM queries?
2,265,234
<p>I am developing a web API with 10 tables or so in the backend, with several one-to-many and many-to-many associations. The API essentially is a database wrapper that performs validated updates and conditional queries. It's written in Python, and I use SQLAlchemy for ORM and CherryPy for HTTP handling.</p> <p>So far...
2
2010-02-15T10:24:04Z
2,265,519
<p>SQLAlchemy strongly suggests that the session maker be part of some global configuration.</p> <blockquote> <p>It is intended that the sessionmaker() function be called within the global scope of an application, and the returned class be made available to the rest of the application as the single class u...
1
2010-02-15T11:21:54Z
[ "python", "design-patterns", "orm", "refactoring", "sqlalchemy" ]
Design pattern to organize non-trivial ORM queries?
2,265,234
<p>I am developing a web API with 10 tables or so in the backend, with several one-to-many and many-to-many associations. The API essentially is a database wrapper that performs validated updates and conditional queries. It's written in Python, and I use SQLAlchemy for ORM and CherryPy for HTTP handling.</p> <p>So far...
2
2010-02-15T10:24:04Z
2,268,603
<p>The standard way to have global access to the current session in a threaded environment is <a href="http://www.sqlalchemy.org/docs/session.html#contextual-thread-local-sessions" rel="nofollow">ScopedSession</a>. There are some important aspects to get right when integrating with your framework, mainly transaction co...
1
2010-02-15T20:08:04Z
[ "python", "design-patterns", "orm", "refactoring", "sqlalchemy" ]
Python - codec encoding ascii to unicode: error
2,265,270
<p>:) I am trying to go about the process of reversing transliteration of an input file(currently in english) back to its original form(in hindi)</p> <p>A sample or a part of the input file looks like this:</p> <pre><code>E-k- b-u-d-z*dhi-m-aan- p-ksii# E-k- ghn-e- j-ngg-l- m-e-ng E-k- b-h-u-t- UUNNc-aa p-e-dr thaa#...
0
2010-02-15T10:31:15Z
2,265,327
<blockquote> <p>f1.write(' '.join(list1))</p> </blockquote> <p><code>list1</code>, at this point, contains Unicode strings. You can't write Unicode directly to a file, it's a byte interface. You should either encode it explicitly <code>(' '.join(list1).encode('utf-8'))</code>, or, as Ignacio suggests, use a <code>co...
1
2010-02-15T10:43:53Z
[ "python", "transliteration" ]
Python - codec encoding ascii to unicode: error
2,265,270
<p>:) I am trying to go about the process of reversing transliteration of an input file(currently in english) back to its original form(in hindi)</p> <p>A sample or a part of the input file looks like this:</p> <pre><code>E-k- b-u-d-z*dhi-m-aan- p-ksii# E-k- ghn-e- j-ngg-l- m-e-ng E-k- b-h-u-t- UUNNc-aa p-e-dr thaa#...
0
2010-02-15T10:31:15Z
2,268,304
<p>Are you sure you want to remove all the hyphens(-)? Looking at your input file, it looks like all replacements are two- or three-character codes, such as u'I-':u'इ'. If this is so, you could do something like below, but make sure you're using Unicode strings for all your keys and values in the dictionary:</p> <...
1
2010-02-15T19:09:29Z
[ "python", "transliteration" ]
Python - codec encoding ascii to unicode: error
2,265,270
<p>:) I am trying to go about the process of reversing transliteration of an input file(currently in english) back to its original form(in hindi)</p> <p>A sample or a part of the input file looks like this:</p> <pre><code>E-k- b-u-d-z*dhi-m-aan- p-ksii# E-k- ghn-e- j-ngg-l- m-e-ng E-k- b-h-u-t- UUNNc-aa p-e-dr thaa#...
0
2010-02-15T10:31:15Z
2,270,214
<p>You have a few problems other than the one which you asked about.</p> <p>(1) A conceptual problem: "E-k- b-u-d-z*dhi-m-aan- p-ksii#" is <strong>not</strong> "english". It is Hindi language written in ASCII using some romanization scheme. It looks like ITRAN but ITRAN doesn't have AA and A, it has only aa and a. Doe...
4
2010-02-16T02:04:54Z
[ "python", "transliteration" ]
How to make an axes occupy multiple subplots with pyplot (Python)
2,265,319
<p>I would like to have three plots in single figure. The figure should have a subplot layout of two by two, where the first plot should occupy the first two subplot cells (i.e. the whole first row of plot cells) and the other plots should be positioned underneath the first one in cells 3 and 4. I know that matlab allo...
14
2010-02-15T10:42:14Z
2,265,506
<p>You can simply do:</p> <pre><code>x = numpy.arange(0, 7, 0.01) subplot(2, 1, 1) plot(x, sin(x)) subplot(2, 2, 3) plot(x, cos(x)) subplot(2, 2, 4) plot(x, sin(x)*cos(x)) </code></pre> <p>i.e., the first plot is really a plot in the upper half (the figure is only divided into 2*1 = 2 cells), and the following two...
24
2010-02-15T11:18:21Z
[ "python", "matplotlib" ]
How to make an axes occupy multiple subplots with pyplot (Python)
2,265,319
<p>I would like to have three plots in single figure. The figure should have a subplot layout of two by two, where the first plot should occupy the first two subplot cells (i.e. the whole first row of plot cells) and the other plots should be positioned underneath the first one in cells 3 and 4. I know that matlab allo...
14
2010-02-15T10:42:14Z
16,542,886
<p>To have multiple subplots with an axis occupy, you can simply do:</p> <pre><code>from matplotlib import pyplot as plt import numpy as np b=np.linspace(-np.pi, np.pi, 100) a1=np.sin(b) a2=np.cos(b) a3=a1*a2 plt.subplot(221) plt.plot(b, a1) plt.title('sin(x)') plt.subplot(222) plt.plot(b, a2) plt.title('cos(x)'...
10
2013-05-14T12:15:34Z
[ "python", "matplotlib" ]
How to make an axes occupy multiple subplots with pyplot (Python)
2,265,319
<p>I would like to have three plots in single figure. The figure should have a subplot layout of two by two, where the first plot should occupy the first two subplot cells (i.e. the whole first row of plot cells) and the other plots should be positioned underneath the first one in cells 3 and 4. I know that matlab allo...
14
2010-02-15T10:42:14Z
24,747,323
<p>For finer-grained control you might want to use the <code>subplot2grid</code> module of <code>matplotlib.pyplot</code>.</p> <p><a href="http://matplotlib.org/users/gridspec.html" rel="nofollow">http://matplotlib.org/users/gridspec.html</a></p>
1
2014-07-14T22:51:01Z
[ "python", "matplotlib" ]
Parse date string and change format
2,265,357
<p>I have a date string with the format 'Mon Feb 15 2010'. I want to change the format to '15/02/2010'. How can I do this?</p>
50
2010-02-15T10:49:25Z
2,265,383
<p><a href="http://docs.python.org/library/datetime.html"><code>datetime</code></a> module could help you with that:</p> <pre><code>datetime.datetime.strptime(date_string, format1).strftime(format2) </code></pre>
61
2010-02-15T10:54:34Z
[ "python", "datetime" ]
Parse date string and change format
2,265,357
<p>I have a date string with the format 'Mon Feb 15 2010'. I want to change the format to '15/02/2010'. How can I do this?</p>
50
2010-02-15T10:49:25Z
2,265,466
<p>use datetime library <a href="http://docs.python.org/library/datetime.html" rel="nofollow">http://docs.python.org/library/datetime.html</a> look up 9.1.7. especiall strptime() strftime() Behavior¶ examples <a href="http://pleac.sourceforge.net/pleac_python/datesandtimes.html" rel="nofollow">http://pleac.sourcef...
0
2010-02-15T11:11:38Z
[ "python", "datetime" ]
Parse date string and change format
2,265,357
<p>I have a date string with the format 'Mon Feb 15 2010'. I want to change the format to '15/02/2010'. How can I do this?</p>
50
2010-02-15T10:49:25Z
2,265,499
<pre><code>&gt;&gt;&gt; from_date="Mon Feb 15 2010" &gt;&gt;&gt; import time &gt;&gt;&gt; conv=time.strptime(from_date,"%a %b %d %Y") &gt;&gt;&gt; time.strftime("%d/%m/%Y",conv) '15/02/2010' </code></pre>
16
2010-02-15T11:16:40Z
[ "python", "datetime" ]
Parse date string and change format
2,265,357
<p>I have a date string with the format 'Mon Feb 15 2010'. I want to change the format to '15/02/2010'. How can I do this?</p>
50
2010-02-15T10:49:25Z
16,115,575
<p>You can install the <a href="http://labix.org/python-dateutil">dateutil</a> library. Its <a href="http://labix.org/python-dateutil#head-a23e8ae0a661d77b89dfb3476f85b26f0b30349c"><code>parse</code></a> function can figure out what format a string is in without having to specify the format like you do with <code>date...
25
2013-04-20T01:25:52Z
[ "python", "datetime" ]
Parse date string and change format
2,265,357
<p>I have a date string with the format 'Mon Feb 15 2010'. I want to change the format to '15/02/2010'. How can I do this?</p>
50
2010-02-15T10:49:25Z
36,236,080
<p>convert string to datetime object</p> <pre><code>from datetime import datetime s = "2016-03-26T09:25:55.000Z" f = "%Y-%m-%dT%H:%M:%S.%fZ" datetime = datetime.strptime(s, f) print(datetime) output: 2016-03-26 09:25:55 </code></pre>
4
2016-03-26T13:54:08Z
[ "python", "datetime" ]
Parse date string and change format
2,265,357
<p>I have a date string with the format 'Mon Feb 15 2010'. I want to change the format to '15/02/2010'. How can I do this?</p>
50
2010-02-15T10:49:25Z
38,644,675
<p>Just for the sake of completion: when parsing a date using <code>strptime()</code> and the date contains the <em>name</em> of a day, month, etc, be aware that you have to account for the locale.</p> <p>It's mentioned as a footnote in the <a href="https://docs.python.org/3.5/library/datetime.html#strftime-and-strpti...
1
2016-07-28T18:59:44Z
[ "python", "datetime" ]
Parse date string and change format
2,265,357
<p>I have a date string with the format 'Mon Feb 15 2010'. I want to change the format to '15/02/2010'. How can I do this?</p>
50
2010-02-15T10:49:25Z
39,828,829
<p>As this question comes often, here is the simple explanation.</p> <p><code>datetime</code> or <code>time</code> module has two important functions. </p> <ul> <li><strong>strftime</strong> - creates a string representation of date or time from a datetime or time object.</li> <li><strong>strptime</strong> - creates ...
0
2016-10-03T09:51:11Z
[ "python", "datetime" ]
Adding class attributes using a for loop in Python
2,265,402
<p>I was trying to generate a class from a dictionary:</p> <pre><code>class attr: for key in objects_type: setattr(attr, key, lambda cl: list()) </code></pre> <p>This gives the error that attr is not defined during the for loop. I know I could write:</p> <pre><code>class attr: pass for key in objects...
8
2010-02-15T10:58:56Z
2,265,425
<p>I don't exactly know, what you are doing. I can give you example of adding class attributes to a class in a for loop:</p> <pre><code>attributes = ('x', 5), ('y', 6), ('name', 'Cls') class Cls: pass for key, value in attributes: setattr(Cls, key, value) </code></pre> <p>Remember that for must be run after whol...
2
2010-02-15T11:02:36Z
[ "python", "metaprogramming" ]
Adding class attributes using a for loop in Python
2,265,402
<p>I was trying to generate a class from a dictionary:</p> <pre><code>class attr: for key in objects_type: setattr(attr, key, lambda cl: list()) </code></pre> <p>This gives the error that attr is not defined during the for loop. I know I could write:</p> <pre><code>class attr: pass for key in objects...
8
2010-02-15T10:58:56Z
2,265,442
<pre><code>class Attr: def __init__(self): for key in objects_type: setattr(Attr, key, lambda cl: list()) </code></pre>
1
2010-02-15T11:05:26Z
[ "python", "metaprogramming" ]
Adding class attributes using a for loop in Python
2,265,402
<p>I was trying to generate a class from a dictionary:</p> <pre><code>class attr: for key in objects_type: setattr(attr, key, lambda cl: list()) </code></pre> <p>This gives the error that attr is not defined during the for loop. I know I could write:</p> <pre><code>class attr: pass for key in objects...
8
2010-02-15T10:58:56Z
2,265,479
<p>Although it's not very elegant, you can use <code>locals()</code>:</p> <pre><code>&gt;&gt;&gt; class c(object): ... for i in range(10): ... locals()['A' + str(i)] = i ... &gt;&gt;&gt; c.A0 0 &gt;&gt;&gt; c.A7 7 </code></pre>
6
2010-02-15T11:14:06Z
[ "python", "metaprogramming" ]
Adding class attributes using a for loop in Python
2,265,402
<p>I was trying to generate a class from a dictionary:</p> <pre><code>class attr: for key in objects_type: setattr(attr, key, lambda cl: list()) </code></pre> <p>This gives the error that attr is not defined during the for loop. I know I could write:</p> <pre><code>class attr: pass for key in objects...
8
2010-02-15T10:58:56Z
2,265,511
<pre><code>newmeths = { 'two': lambda self: 2, } class MC(type): def __init__(cls, name, bases, dict): for k, v in newmeths.iteritems(): setattr(cls, k, v) super(MC, cls).__init__(name, bases, dict) class C(object): __metaclass__ = MC pass c=C() print c.two() </code></pre>
2
2010-02-15T11:19:36Z
[ "python", "metaprogramming" ]
Adding class attributes using a for loop in Python
2,265,402
<p>I was trying to generate a class from a dictionary:</p> <pre><code>class attr: for key in objects_type: setattr(attr, key, lambda cl: list()) </code></pre> <p>This gives the error that attr is not defined during the for loop. I know I could write:</p> <pre><code>class attr: pass for key in objects...
8
2010-02-15T10:58:56Z
2,265,584
<p>suppose you want to dynamically add class attributes such as these</p> <pre><code>classDict = {} for i in range(2): classDict["func%s"%(i+1)] = lambda self:"X" </code></pre> <p>you can do this in several ways e.g. just add attributes after class has been created because you can'y easily access class name insid...
2
2010-02-15T11:35:23Z
[ "python", "metaprogramming" ]
How to init twisted reactor in the right way?
2,265,555
<p>i have a class MyJabber which init a basic jabber account that print the incoming messages to stdout + put them into a queue.</p> <p>The code that add the client to the reactor is this:</p> <pre><code>def addReactor(self): print 'inside AddReactor' factory = client.basicClientFactory(self.jid, self.option...
3
2010-02-15T11:29:01Z
2,266,052
<p>This doesn't seem to really be a question about how to "init twisted reactor". Rather, it seems to be more about how to use Twisted Words' XMPP support to send and respond to XMPP messages.</p> <p>You can find a couple examples which do this in the Twisted Words examples directory:</p> <p><a href="http://twistedm...
4
2010-02-15T13:02:13Z
[ "python", "twisted", "xmpp", "twisted.words" ]
How to init twisted reactor in the right way?
2,265,555
<p>i have a class MyJabber which init a basic jabber account that print the incoming messages to stdout + put them into a queue.</p> <p>The code that add the client to the reactor is this:</p> <pre><code>def addReactor(self): print 'inside AddReactor' factory = client.basicClientFactory(self.jid, self.option...
3
2010-02-15T11:29:01Z
2,269,247
<p>Fixed, there were 2 errors.</p> <p>1) I accidentally forgot that a JID is name@domain.tld/extra</p> <p>2) Forgot to add <code>self.</code> to <code>gotMessage/gotSomething</code></p> <p>I've also made addReactor return the factory and in the main() wrote:</p> <pre><code>jabber = MyJabber(options, to_irc) factory...
0
2010-02-15T22:03:19Z
[ "python", "twisted", "xmpp", "twisted.words" ]
How would you solve this GPS/location problem and scale it? Would you use a Database? R-tree?
2,265,775
<p>Suppose I have a people and their GPS coordinates:</p> <pre><code>User1, 52.99, -41.0 User2, 91.44, -21.4 User3, 5.12, 24.5 ... </code></pre> <p><strong>My objective is: Given a set of coordinates,</strong></p> <ol> <li>Out of all those users, find the ones within 20 meters. (how to do a SELECT statement like thi...
2
2010-02-15T12:08:38Z
2,265,798
<ol> <li><p>Create a <code>MyISAM</code> table with a column of datatype <code>Point</code></p></li> <li><p>Create a <code>SPATIAL</code> index on this column</p></li> <li><p>Convert the <code>GPS</code> coords into <code>UTM</code> (grid) coords and store them in your table</p></li> <li><p>Issue this query:</p> <pre>...
3
2010-02-15T12:17:29Z
[ "python", "mysql", "database", "computer-science" ]
How would you solve this GPS/location problem and scale it? Would you use a Database? R-tree?
2,265,775
<p>Suppose I have a people and their GPS coordinates:</p> <pre><code>User1, 52.99, -41.0 User2, 91.44, -21.4 User3, 5.12, 24.5 ... </code></pre> <p><strong>My objective is: Given a set of coordinates,</strong></p> <ol> <li>Out of all those users, find the ones within 20 meters. (how to do a SELECT statement like thi...
2
2010-02-15T12:08:38Z
2,265,806
<p><a href="http://my.safaribooksonline.com/9780123746306/chapter_11_modeling_and_queryi" rel="nofollow">Chapter 11</a> "Database Design Know it All" has some thoughts on how to design such a database.</p>
0
2010-02-15T12:18:48Z
[ "python", "mysql", "database", "computer-science" ]
How would you solve this GPS/location problem and scale it? Would you use a Database? R-tree?
2,265,775
<p>Suppose I have a people and their GPS coordinates:</p> <pre><code>User1, 52.99, -41.0 User2, 91.44, -21.4 User3, 5.12, 24.5 ... </code></pre> <p><strong>My objective is: Given a set of coordinates,</strong></p> <ol> <li>Out of all those users, find the ones within 20 meters. (how to do a SELECT statement like thi...
2
2010-02-15T12:08:38Z
2,265,824
<p>Well, the naive approach would be to do an <em>O(n)</em> pass over all points, get their distance from the current point, and find the top 20. This is perfectly Ok for small datasets (say &lt;= 500 points), but on larger sets it's going to be quite slow. In SQL, this would be along the lines of:</p> <pre><code>SELE...
2
2010-02-15T12:22:23Z
[ "python", "mysql", "database", "computer-science" ]
showing list item in python
2,265,871
<p>I want to manipulate feed which contains frequently updated (with time) contents using feed parser. Goal is to show all the contents of the updated feed.</p> <pre><code>import feedparser d = feedparser.parse("some URL") print "Information of user" i = range(10) for i in d: print d.entries[i].summary print ...
1
2010-02-15T12:29:55Z
2,265,893
<p><code>i</code> is not an integer. I guess <code>i</code> is already an entry of the feed but better rename it:</p> <p>Try: </p> <pre><code>for entry in d.entries: print entry.summary </code></pre> <p>If you want the first 10 entries you have to do:</p> <pre><code>try: for i in range(10): print d.entries[...
4
2010-02-15T12:34:44Z
[ "python", "feedparser" ]
showing list item in python
2,265,871
<p>I want to manipulate feed which contains frequently updated (with time) contents using feed parser. Goal is to show all the contents of the updated feed.</p> <pre><code>import feedparser d = feedparser.parse("some URL") print "Information of user" i = range(10) for i in d: print d.entries[i].summary print ...
1
2010-02-15T12:29:55Z
2,265,899
<p>You first assign a list of integers to i (<code>i = range(10)</code>) and then just lose the reference to this list. Are you sure you didn't mean:</p> <pre><code>r = range(10) for i in r: </code></pre> <p>or simply:</p> <pre><code>for i in range(10): </code></pre>
1
2010-02-15T12:35:29Z
[ "python", "feedparser" ]
showing list item in python
2,265,871
<p>I want to manipulate feed which contains frequently updated (with time) contents using feed parser. Goal is to show all the contents of the updated feed.</p> <pre><code>import feedparser d = feedparser.parse("some URL") print "Information of user" i = range(10) for i in d: print d.entries[i].summary print ...
1
2010-02-15T12:29:55Z
2,265,901
<pre><code>for i in range(10): print d.entries[i].summary </code></pre>
4
2010-02-15T12:35:45Z
[ "python", "feedparser" ]
showing list item in python
2,265,871
<p>I want to manipulate feed which contains frequently updated (with time) contents using feed parser. Goal is to show all the contents of the updated feed.</p> <pre><code>import feedparser d = feedparser.parse("some URL") print "Information of user" i = range(10) for i in d: print d.entries[i].summary print ...
1
2010-02-15T12:29:55Z
2,265,923
<p>for all entries make:</p> <pre><code>import feedparser d = feedparser.parse("some URL") print "Information of user" for i in range(len(d['entries'])): print d.entries[i].summary print " " </code></pre>
1
2010-02-15T12:39:15Z
[ "python", "feedparser" ]
showing list item in python
2,265,871
<p>I want to manipulate feed which contains frequently updated (with time) contents using feed parser. Goal is to show all the contents of the updated feed.</p> <pre><code>import feedparser d = feedparser.parse("some URL") print "Information of user" i = range(10) for i in d: print d.entries[i].summary print ...
1
2010-02-15T12:29:55Z
2,266,149
<pre><code>import feedparser from StringIO import StringIO d = feedparser.parse("some URL") buff = StringIO() print &gt;&gt;buff, "Information of user" for i,e in enumerate(d.entries): print &gt;&gt;buff, i, e.summary print &gt;&gt;buff," " print buff </code></pre> <p>If you need the index, I suggest also to u...
1
2010-02-15T13:18:59Z
[ "python", "feedparser" ]
showing list item in python
2,265,871
<p>I want to manipulate feed which contains frequently updated (with time) contents using feed parser. Goal is to show all the contents of the updated feed.</p> <pre><code>import feedparser d = feedparser.parse("some URL") print "Information of user" i = range(10) for i in d: print d.entries[i].summary print ...
1
2010-02-15T12:29:55Z
2,266,212
<p>Say you want to print the 10 first elements of the list if there is 10 or more, or what it contains otherwise. Felix allready proposed a working solution with exception management. You could also use itertools like below. </p> <pre><code>import feedparser d = feedparser.parse('http://feedparser.org/docs/examples/at...
0
2010-02-15T13:30:31Z
[ "python", "feedparser" ]
moving to Django 1.1 problem
2,265,914
<p>I'm trying to move from django 1.0.2 to 1.1 and I am getting the </p> <p>following error in one of my templates: </p> <p>Request Method: GET </p> <p>Request URL: <a href="http://localhost:8000/conserv/media_assets/vod/" rel="nofollow">http://localhost:8000/conserv/media_assets/vod/</a> </p> <p>Exception Type:...
1
2010-02-15T12:37:21Z
2,266,169
<p>there's an error in your form class. The fields should be an iterable, but a tuple with one element should be written <code>('thumb',)</code> instead of <code>('thumb')</code>. Change your form class to :</p> <pre><code>class UploadImageForm(ModelForm): class Meta: model = ImageUpload fields = ('thumb',...
0
2010-02-15T13:22:27Z
[ "python", "django-templates" ]
Reading a binary file in Python: takes a very long time to read certain bytes
2,265,930
<p>This is very odd</p> <p>I'm reading some (admittedly very large: ~2GB each) binary files using numpy libraries in Python. I'm using the:</p> <pre><code>thingy = np.fromfile(fileObject, np.int16, 1) </code></pre> <p>method. This is right in the middle of a nested loop - I'm doing this loop 4096 times per 'channe...
0
2010-02-15T12:40:25Z
2,266,002
<p>Although it's hard to say without some kind of reproducible sample, this sounds like a buffering problem. The First part is buffered and until you reach the end of the buffer, it is fast; then it slows down until the next buffer is filled, and so on.</p>
3
2010-02-15T12:52:19Z
[ "python", "binary", "numpy", "binaryfiles" ]