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
listlengths
1
5
Google AppEngine: Date Range not returning correct results
722,728
<p>Im trying to search for some values within a date range for a specific type, but content for dates that exist in the database are not being returned by the query.</p> <p>Here is an extract of the python code:</p> <pre><code>deltaDays = timedelta(days= 20) endDate = datetime.date.today() startDate = endDate - delta...
0
2009-04-06T19:03:21Z
723,372
<p>nothing looks wrong to me. are you sure that the missing dates also have mytype == type?</p> <p>i have observed some funny behaviour with indexes in the past. I recommend writing a handler to iterate through all of your records and just put() them back in the database. maybe something with the bulk uploader isn'...
1
2009-04-06T21:46:37Z
[ "python", "google-app-engine", "gql" ]
Env Variables in Python (v3.0) on Windows
722,739
<p>I'm using Python 3.0. </p> <p>How to expand an environment variable given the %var_name% syntax?</p> <p>Any help is much appreciated! Thanks!</p>
3
2009-04-06T19:07:17Z
722,758
<p>I'm guessing you mean "How do I get environment variables?":</p> <pre><code>import os username = os.environ['UserName'] </code></pre> <p>Alternatively, you can use:</p> <pre><code>username = os.getenv('UserName') </code></pre> <p>And to add/change your own variables, you can use:</p> <pre><code>os.putenv('MyVar...
2
2009-04-06T19:13:37Z
[ "python", "windows", "scripting", "shell" ]
Env Variables in Python (v3.0) on Windows
722,739
<p>I'm using Python 3.0. </p> <p>How to expand an environment variable given the %var_name% syntax?</p> <p>Any help is much appreciated! Thanks!</p>
3
2009-04-06T19:07:17Z
722,871
<p>It's in a slightly unexpected place: <a href="http://docs.python.org/3.0/library/os.path.html#os.path.expanduser" rel="nofollow">os.path.expandvars()</a>. Admittedly it is quite often used for processing paths:</p> <pre><code>&gt;&gt;&gt; import os.path &gt;&gt;&gt; os.path.expandvars('%APPDATA%\\MyApp') 'C:\\Docum...
3
2009-04-06T19:41:20Z
[ "python", "windows", "scripting", "shell" ]
pythonic way to compare compound classes?
722,741
<p>I have a class that acts as an item in a tree:</p> <pre><code>class CItem( list ): pass </code></pre> <p>I have two trees, each with CItem as root, each tree item has some dict members (like item._test = 1). Now i need to compare this trees. I can suggest to overload a comparison operator for CItem:</p> <pre><c...
2
2009-04-06T19:07:55Z
722,786
<p>My feeling would be something like</p> <pre><code>class CItem(list): def __eq__(self, other): return list.__eq__(self, other) and self.__dict__ == other.__dict__ </code></pre> <p>but it's basically the same code you have, just expressed in shorter notation. I can't think of any more substantial changes...
3
2009-04-06T19:22:44Z
[ "python" ]
Using paver and nose together with an atypical directory structure
722,992
<p>I'm trying to write a task for <code>Paver</code> that will run <code>nosetests</code> on my files.</p> <p>My directory structure looks like this:</p> <pre><code>project/ file1.py file2.py file3.py build/ pavement.py subproject/ file4.py test/ file5.py file6.py </code></pr...
3
2009-04-06T20:08:06Z
1,942,991
<p>Is this at all close to what you're trying to get at?</p> <pre><code>from paver.easy import sh, path __path__ = path(__file__).abspath().dirname() @task def setup_nose_plugin(): # ... do your plugin setup here. @task @needs('setup_nose_plugin') def nosetests(): nose_options = '--with-doctest' # Put your c...
2
2009-12-21T22:15:04Z
[ "python", "nose", "paver" ]
Inserting object with ManyToMany in Django
723,293
<p>I have a blog-like application with stories and categories:</p> <pre><code>class Category(models.Model): ... class Story(models.Model): categories = models.ManyToManyField(Category) ... </code></pre> <p>Now I know that when you save a new instance of a model with a many-to-many field, problems come up ...
1
2009-04-06T21:23:22Z
723,514
<p>"As far as I can fathom, any insert of an object with a many-to-many field will require two database hits,..."</p> <p>So what?</p> <p>Micromanaging each individual database access generally isn't worth all the thinking. Do the simplest, most obvious thing so that Django can optimize cache for you. </p> <p>Your...
3
2009-04-06T22:34:55Z
[ "python", "django", "many-to-many" ]
Inserting object with ManyToMany in Django
723,293
<p>I have a blog-like application with stories and categories:</p> <pre><code>class Category(models.Model): ... class Story(models.Model): categories = models.ManyToManyField(Category) ... </code></pre> <p>Now I know that when you save a new instance of a model with a many-to-many field, problems come up ...
1
2009-04-06T21:23:22Z
723,586
<p>I commented on S.Lott's post that I feel his answer is the best. He's right: if the goal is just to avoid two database hits, then you're just in for a world of unnecessary pain.</p> <p>Reading your reference to ModelForm, however, if you are looking instead for a solution to that allows you to defer official saving...
2
2009-04-06T23:04:11Z
[ "python", "django", "many-to-many" ]
Controlling a Windows Console App w/ stdin pipe
723,424
<p>I am trying to control a console application (JTAG app from Segger) from Python using the subprocess module. The application behaves correctly for stdout, but stdin doesn't seem to be read. If enable the shell, I can type into the input and control the application, but I need to do this programmatically. The same...
1
2009-04-06T22:01:25Z
723,536
<pre><code>I'm guessing that the keyboard is being read directly instead of stdin </code></pre> <p>This is a pretty strong assumption and before stitching a solution you should try to verify it somehow. There are different levels of doing this. Actually two I can think of right now:</p> <ul> <li>Waiting for keyboard ...
2
2009-04-06T22:40:50Z
[ "python", "command-line", "subprocess", "jtag" ]
Controlling a Windows Console App w/ stdin pipe
723,424
<p>I am trying to control a console application (JTAG app from Segger) from Python using the subprocess module. The application behaves correctly for stdout, but stdin doesn't seem to be read. If enable the shell, I can type into the input and control the application, but I need to do this programmatically. The same...
1
2009-04-06T22:01:25Z
723,724
<p>As shoosh says, I'd try to verify that the application really is looking for keyboard input. If it is, you can try Win32 message passing, or sending it keyboard input via automation.</p> <p>For the message passing route, you could use the <a href="http://msdn.microsoft.com/en-us/library/ms633497.aspx" rel="nofollow...
3
2009-04-07T00:16:30Z
[ "python", "command-line", "subprocess", "jtag" ]
How do you send an Ethernet frame with a corrupt FCS?
723,635
<p>I'm not sure if this is even possible since this might be handled in hardware, but I need to send some Ethernet frames with errors in them. I'd like to be able to create runts, jabber, misalignment, and bad FCS errors. I'm working in Python.</p>
6
2009-04-06T23:30:16Z
724,009
<p>It <em>can</em> be handled in hardware, but isn't always -- and even if it is, you can turn that off; see the <A HREF="http://linux.die.net/man/8/ethtool">ethtool</A> offload parameters.</p> <p>With regard to getting full control over the frames you create -- look into <A HREF="http://swoolley.org/man.cgi/7/packet"...
8
2009-04-07T02:50:09Z
[ "python", "networking", "automated-tests", "ethernet" ]
How do you send an Ethernet frame with a corrupt FCS?
723,635
<p>I'm not sure if this is even possible since this might be handled in hardware, but I need to send some Ethernet frames with errors in them. I'd like to be able to create runts, jabber, misalignment, and bad FCS errors. I'm working in Python.</p>
6
2009-04-06T23:30:16Z
6,382,971
<p>First, you disable your ethernet card's checksumming:</p> <pre><code>sudo ethtool -K eth1 tx off </code></pre> <p>Then, you send the corrupt frames from python:</p> <pre><code>#!/usr/bin/env python from socket import * # # Ethernet Frame: # [ # [ Destination address, 6 bytes ] # [ Source address, 6 bytes ...
3
2011-06-17T08:02:35Z
[ "python", "networking", "automated-tests", "ethernet" ]
How do you send an Ethernet frame with a corrupt FCS?
723,635
<p>I'm not sure if this is even possible since this might be handled in hardware, but I need to send some Ethernet frames with errors in them. I'd like to be able to create runts, jabber, misalignment, and bad FCS errors. I'm working in Python.</p>
6
2009-04-06T23:30:16Z
8,356,862
<p>try using scapy for python, there are examples to generate jumbo frames, a runt frames too. <a href="http://www.dirk-loss.de/scapy-doc/usage.html" rel="nofollow">http://www.dirk-loss.de/scapy-doc/usage.html</a></p>
2
2011-12-02T13:15:42Z
[ "python", "networking", "automated-tests", "ethernet" ]
How do you send an Ethernet frame with a corrupt FCS?
723,635
<p>I'm not sure if this is even possible since this might be handled in hardware, but I need to send some Ethernet frames with errors in them. I'd like to be able to create runts, jabber, misalignment, and bad FCS errors. I'm working in Python.</p>
6
2009-04-06T23:30:16Z
25,922,139
<p>The program did not work as intended for me to generate FCS errors.</p> <p>The network driver added the correct checksum at the end of the generated frame again. Of course it's quite possible that the solution is working for some cards, but I'm sure not with any from Intel. (It's also working without any ethtool ch...
1
2014-09-18T20:55:09Z
[ "python", "networking", "automated-tests", "ethernet" ]
Python/Django plugin for Dreamweaver
723,652
<p>Does a plugin exists for Python/Django into Dreamweaver? Just wondering since Dreamweaver is a great web dev tool.</p>
5
2009-04-06T23:38:22Z
723,657
<p>As far as I know there's no Django-specific IDE plugins out there.</p> <p>However I use <a href="http://www.eclipse.org/" rel="nofollow">Eclipse</a> with <a href="http://pydev.sourceforge.net/" rel="nofollow">PyDev</a> for my Django/Python needs and it is quite nice.</p>
3
2009-04-06T23:41:55Z
[ "python", "django", "dreamweaver" ]
Python/Django plugin for Dreamweaver
723,652
<p>Does a plugin exists for Python/Django into Dreamweaver? Just wondering since Dreamweaver is a great web dev tool.</p>
5
2009-04-06T23:38:22Z
723,674
<p><a href="http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&amp;loc=en%5Fus&amp;extid=1557518" rel="nofollow">Found one</a> from some guy named Beshr Kayali, but I can't try it myself, since I don't have Dreamweaver.</p>
2
2009-04-06T23:49:06Z
[ "python", "django", "dreamweaver" ]
Python/Django plugin for Dreamweaver
723,652
<p>Does a plugin exists for Python/Django into Dreamweaver? Just wondering since Dreamweaver is a great web dev tool.</p>
5
2009-04-06T23:38:22Z
723,682
<p>I remember looking for a plugin too, but came across <a href="http://www.djangobook.com/en/beta/chapter04/">this</a> stumbling block:</p> <blockquote> <p><strong>Designers are assumed to be comfortable with HTML code</strong>. The template system isn’t designed so that templates necessarily are displayed nicely...
5
2009-04-06T23:54:16Z
[ "python", "django", "dreamweaver" ]
Python/Django plugin for Dreamweaver
723,652
<p>Does a plugin exists for Python/Django into Dreamweaver? Just wondering since Dreamweaver is a great web dev tool.</p>
5
2009-04-06T23:38:22Z
5,149,029
<p>Beshir Kayali's plugin fails installation for DW CS5 and Extension Manager CS4. Irony that it asks for DW CS4 or better, else "upgrade" Extension manager to CS3.</p> <p>I could put some effort in to make this work, yet this is the sole review of the extension:</p> <blockquote> <p>I allows you to insert 6 kinds o...
0
2011-02-28T23:58:14Z
[ "python", "django", "dreamweaver" ]
Is it possible to update a Google calendar from App Engine without logging in as the owner?
723,719
<p>I'd like to be able to use the Google Data API from an AppEngine application to update a calendar while not logged in as the calendar's owner or the a user that the calendar is shared with. This is in contrast to the examples here:</p> <p><a href="http://code.google.com/appengine/articles/more_google_data.html" re...
1
2009-04-07T00:13:07Z
723,999
<p>It should be possible using OAuth, i havent used it myself but my understanding is the user logs in and then gives your app permission to access their private data (e.g. Calendar records). Once they have authorised your app you will be able to access their data without them logging in.</p> <p>Here is an article ex...
3
2009-04-07T02:44:17Z
[ "python", "web-services", "google-app-engine" ]
Is it possible to update a Google calendar from App Engine without logging in as the owner?
723,719
<p>I'd like to be able to use the Google Data API from an AppEngine application to update a calendar while not logged in as the calendar's owner or the a user that the calendar is shared with. This is in contrast to the examples here:</p> <p><a href="http://code.google.com/appengine/articles/more_google_data.html" re...
1
2009-04-07T00:13:07Z
740,081
<p>It's possible to use ClientLogin as described here:</p> <p><a href="http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Response" rel="nofollow">http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Response</a></p> <p>Note the section at the bottom of the document that mentions handl...
1
2009-04-11T13:25:19Z
[ "python", "web-services", "google-app-engine" ]
Import XML into SQL database
723,757
<p>I'm working with a 20 gig XML file that I would like to import into a SQL database (preferably MySQL, since that is what I am familiar with). This seems like it would be a common task, but after Googling around a bit I haven't been able to figure out how to do it. What is the best way to do this? </p> <p>I know thi...
5
2009-04-07T00:39:25Z
723,824
<p>I've done this several times with Python, but never with such a big XML file. <a href="http://effbot.org/zone/element-index.htm" rel="nofollow">ElementTree</a> is an excellent XML library for Python that would be of assistance. If it was possible, I would divide the XML up into smaller files to make it easier to loa...
1
2009-04-07T01:11:28Z
[ "python", "sql", "xml" ]
Import XML into SQL database
723,757
<p>I'm working with a 20 gig XML file that I would like to import into a SQL database (preferably MySQL, since that is what I am familiar with). This seems like it would be a common task, but after Googling around a bit I haven't been able to figure out how to do it. What is the best way to do this? </p> <p>I know thi...
5
2009-04-07T00:39:25Z
723,903
<p>You can use the getiterator() function to iterate over the XML file without parsing the whole thing at once. You can do this with <a href="http://docs.python.org/library/xml.etree.elementtree.html" rel="nofollow">ElementTree</a>, which is included in the standard library, or with <a href="http://codespeak.net/lxml/"...
4
2009-04-07T01:51:15Z
[ "python", "sql", "xml" ]
Import XML into SQL database
723,757
<p>I'm working with a 20 gig XML file that I would like to import into a SQL database (preferably MySQL, since that is what I am familiar with). This seems like it would be a common task, but after Googling around a bit I haven't been able to figure out how to do it. What is the best way to do this? </p> <p>I know thi...
5
2009-04-07T00:39:25Z
723,931
<p>It may be a common task, but maybe 20GB isn't as common with MySQL as it is with SQL Server.</p> <p>I've done this using SQL Server Integration Services and a bit of custom code. Whether you need either of those depends on what you need to do with 20GB of XML in a database. Is it going to be a single column of a si...
0
2009-04-07T02:04:11Z
[ "python", "sql", "xml" ]
Import XML into SQL database
723,757
<p>I'm working with a 20 gig XML file that I would like to import into a SQL database (preferably MySQL, since that is what I am familiar with). This seems like it would be a common task, but after Googling around a bit I haven't been able to figure out how to do it. What is the best way to do this? </p> <p>I know thi...
5
2009-04-07T00:39:25Z
724,602
<p>Take a look at the <code>iterparse()</code> function from <code>ElementTree</code> or <code>cElementTree</code> (I guess cElementTree would be best if you can use it)</p> <p>This piece describes more or less what you need to do: <a href="http://effbot.org/zone/element-iterparse.htm#incremental-parsing" rel="nofollo...
2
2009-04-07T08:13:20Z
[ "python", "sql", "xml" ]
Import XML into SQL database
723,757
<p>I'm working with a 20 gig XML file that I would like to import into a SQL database (preferably MySQL, since that is what I am familiar with). This seems like it would be a common task, but after Googling around a bit I haven't been able to figure out how to do it. What is the best way to do this? </p> <p>I know thi...
5
2009-04-07T00:39:25Z
737,002
<p>The <a href="http://dev.mysql.com/tech-resources/articles/xml-in-mysql5.1-6.0.html" rel="nofollow">MySQL documentation</a> does not seem to indicate that XML import is restricted to version 6. It apparently works with 5, too.</p>
0
2009-04-10T07:56:12Z
[ "python", "sql", "xml" ]
WSGI Authentication: Homegrown, Authkit, OpenID...?
723,856
<p>I want basic authentication for a very minimal site, all I personally need is a single superuser. While hard-coding a password and username in one of my source files is awfully tempting, especially since I'm hosting the site on my own server, I feel I'm breaking the law of the internets and I should just use a datab...
6
2009-04-07T01:23:45Z
723,890
<p>AuthKit includes a built-in OpenID module, if that helps.</p> <p>The AuthKit cookbook includes a simple example here... <a href="http://wiki.pylonshq.com/display/authkitcookbook/OpenID+Passurl" rel="nofollow">http://wiki.pylonshq.com/display/authkitcookbook/OpenID+Passurl</a> </p> <p>That said, if you only need a ...
2
2009-04-07T01:44:51Z
[ "python", "authentication", "wsgi" ]
WSGI Authentication: Homegrown, Authkit, OpenID...?
723,856
<p>I want basic authentication for a very minimal site, all I personally need is a single superuser. While hard-coding a password and username in one of my source files is awfully tempting, especially since I'm hosting the site on my own server, I feel I'm breaking the law of the internets and I should just use a datab...
6
2009-04-07T01:23:45Z
723,904
<p>You can adapt this.</p> <p><a href="http://code.activestate.com/recipes/302378/" rel="nofollow">http://code.activestate.com/recipes/302378/</a></p> <p>Or, better, adapt this.</p> <p><a href="http://devel.almad.net/trac/django-http-digest/" rel="nofollow">http://devel.almad.net/trac/django-http-digest/</a></p> <p...
0
2009-04-07T01:51:22Z
[ "python", "authentication", "wsgi" ]
WSGI Authentication: Homegrown, Authkit, OpenID...?
723,856
<p>I want basic authentication for a very minimal site, all I personally need is a single superuser. While hard-coding a password and username in one of my source files is awfully tempting, especially since I'm hosting the site on my own server, I feel I'm breaking the law of the internets and I should just use a datab...
6
2009-04-07T01:23:45Z
1,050,184
<p>also look at repose.who</p> <p><a href="http://static.repoze.org/whodocs/" rel="nofollow">http://static.repoze.org/whodocs/</a></p>
4
2009-06-26T17:06:48Z
[ "python", "authentication", "wsgi" ]
WSGI Authentication: Homegrown, Authkit, OpenID...?
723,856
<p>I want basic authentication for a very minimal site, all I personally need is a single superuser. While hard-coding a password and username in one of my source files is awfully tempting, especially since I'm hosting the site on my own server, I feel I'm breaking the law of the internets and I should just use a datab...
6
2009-04-07T01:23:45Z
1,448,922
<p>Opid is a very small and simple to use WSGI OpenID app: <a href="http://code.google.com/p/python-opid/" rel="nofollow">python-opid</a></p>
1
2009-09-19T16:43:04Z
[ "python", "authentication", "wsgi" ]
What's the best way to propagate information from my wx.Process back to my main thread?
723,984
<p>I'm trying to subclass <code>wx.Process</code> such that I have a customized process launcher that fires events back to the main thread with data collected from the stdout stream. Is this a good way of doing things?</p> <pre><code>class BuildProcess(wx.Process): def __init__(self, cmd, notify=None): wx....
0
2009-04-07T02:38:47Z
724,491
<p>From looking the the wxProcess docs, I don't think it works that way: wxProcess will create a new, seperate process running as a child of you current process. It is not possible to run methods connected to a message in such a process.</p> <p>Maybe you can connect your idle event to a function or method in you main ...
0
2009-04-07T07:28:52Z
[ "python", "multithreading", "events", "process", "wxpython" ]
What's the best way to propagate information from my wx.Process back to my main thread?
723,984
<p>I'm trying to subclass <code>wx.Process</code> such that I have a customized process launcher that fires events back to the main thread with data collected from the stdout stream. Is this a good way of doing things?</p> <pre><code>class BuildProcess(wx.Process): def __init__(self, cmd, notify=None): wx....
0
2009-04-07T02:38:47Z
725,462
<p>The objective is not to call methods of another process, the objective is to redirect the stdout of another process back to the parent process via "update" events fired periodically as the process executes. </p> <p>One solution is to use wx.Timer to periodically poll the output stream of the process, so that we don...
1
2009-04-07T12:32:47Z
[ "python", "multithreading", "events", "process", "wxpython" ]
How to handle unicode of an unknown encoding in Django?
724,212
<p>I want to save some text to the database using the Django ORM wrappers. The problem is, this text is generated by scraping external websites and many times it seems they are listed with the wrong encoding. I would like to store the raw bytes so I can improve my encoding detection as time goes on without redoing the ...
1
2009-04-07T05:18:27Z
724,955
<p>You can store data, encoded into base64, for example. Or try to analize HTTP headers from browser, may be it is simplier to get proper encoding from there.</p>
1
2009-04-07T10:18:10Z
[ "python", "django", "unicode" ]
How to handle unicode of an unknown encoding in Django?
724,212
<p>I want to save some text to the database using the Django ORM wrappers. The problem is, this text is generated by scraping external websites and many times it seems they are listed with the wrong encoding. I would like to store the raw bytes so I can improve my encoding detection as time goes on without redoing the ...
1
2009-04-07T05:18:27Z
724,957
<p>Create a File with the data. Use a Django <code>models.FileField</code> to hold a reference to the file.</p> <p>No it does not involve a ton of I/O. If your file is small it adds 2 or 3 I/O's (the directory read, the iNode read and the data read.) </p>
1
2009-04-07T10:20:20Z
[ "python", "django", "unicode" ]
ctypes bindings for Subversion in windows
724,580
<p>Is there a binary installer or a faq for the new ctypes bindings for Subversion 1.6 in Windows (32 and 64bit)?</p> <p>What library would you use to make an easy to deploy (both win32 and x64) svn client in python for svn version >= 1.5?</p>
0
2009-04-07T08:07:46Z
724,756
<p>You have the <a href="http://pysvn.tigris.org/project%5Fdownloads.html" rel="nofollow">pysvn</a> module which will allow you to do that:</p> <p>Binary installer based on subversion 1.5.5</p>
1
2009-04-07T09:07:13Z
[ "python", "windows", "svn", "ctypes" ]
Python distutils, how to get a compiler that is going to be used?
724,664
<p>For example, I may use <code>python setup.py build --compiler=msvc</code> or <code>python setup.py build --compiler=mingw32</code> or just <code>python setup.py build</code>, in which case the default compiler (say, <code>bcpp</code>) will be used. How can I get the compiler name inside my setup.py (e. g. <code>msvc...
22
2009-04-07T08:36:07Z
724,745
<p>import distutils.ccompiler</p> <p>compiler_name = distutils.ccompiler.get_default_compiler()</p>
0
2009-04-07T09:04:37Z
[ "python", "compiler-construction", "installation", "distutils" ]
Python distutils, how to get a compiler that is going to be used?
724,664
<p>For example, I may use <code>python setup.py build --compiler=msvc</code> or <code>python setup.py build --compiler=mingw32</code> or just <code>python setup.py build</code>, in which case the default compiler (say, <code>bcpp</code>) will be used. How can I get the compiler name inside my setup.py (e. g. <code>msvc...
22
2009-04-07T08:36:07Z
1,671,060
<p>You can subclass the <code>distutils.command.build_ext.build_ext</code> command.</p> <p>Once <code>build_ext.finalize_options()</code> method has been called, the compiler type is stored in <code>self.compiler.compiler_type</code> as a string (the same as the one passed to the <code>build_ext</code>'s <code>--compi...
5
2009-11-04T00:37:28Z
[ "python", "compiler-construction", "installation", "distutils" ]
Python distutils, how to get a compiler that is going to be used?
724,664
<p>For example, I may use <code>python setup.py build --compiler=msvc</code> or <code>python setup.py build --compiler=mingw32</code> or just <code>python setup.py build</code>, in which case the default compiler (say, <code>bcpp</code>) will be used. How can I get the compiler name inside my setup.py (e. g. <code>msvc...
22
2009-04-07T08:36:07Z
2,002,999
<pre> #This should work pretty good def compilerName(): import re import distutils.ccompiler comp = distutils.ccompiler.get_default_compiler() getnext = False for a in sys.argv[2:]: if getnext: comp = a getnext = False continue #separated by space if a == '--compiler' or re.se...
1
2010-01-04T23:16:04Z
[ "python", "compiler-construction", "installation", "distutils" ]
Python distutils, how to get a compiler that is going to be used?
724,664
<p>For example, I may use <code>python setup.py build --compiler=msvc</code> or <code>python setup.py build --compiler=mingw32</code> or just <code>python setup.py build</code>, in which case the default compiler (say, <code>bcpp</code>) will be used. How can I get the compiler name inside my setup.py (e. g. <code>msvc...
22
2009-04-07T08:36:07Z
5,192,738
<p>This is an expanded version of Luper Rouch's answer that worked for me to get an openmp extension to compile using both mingw and msvc on windows. After subclassing build_ext you need to pass it to setup.py in the cmdclass arg. By subclassing build_extensions instead of finalize_options you'll have the actual compil...
17
2011-03-04T10:49:56Z
[ "python", "compiler-construction", "installation", "distutils" ]
Python distutils, how to get a compiler that is going to be used?
724,664
<p>For example, I may use <code>python setup.py build --compiler=msvc</code> or <code>python setup.py build --compiler=mingw32</code> or just <code>python setup.py build</code>, in which case the default compiler (say, <code>bcpp</code>) will be used. How can I get the compiler name inside my setup.py (e. g. <code>msvc...
22
2009-04-07T08:36:07Z
8,168,576
<pre><code>import sys sys.argv.extend(['--compiler', 'msvc']) </code></pre>
0
2011-11-17T14:17:00Z
[ "python", "compiler-construction", "installation", "distutils" ]
Python distutils, how to get a compiler that is going to be used?
724,664
<p>For example, I may use <code>python setup.py build --compiler=msvc</code> or <code>python setup.py build --compiler=mingw32</code> or just <code>python setup.py build</code>, in which case the default compiler (say, <code>bcpp</code>) will be used. How can I get the compiler name inside my setup.py (e. g. <code>msvc...
22
2009-04-07T08:36:07Z
10,051,724
<pre><code>class BuildWithDLLs(build): # On Windows, we install the git2.dll too. def _get_dlls(self): # return a list of of (FQ-in-name, relative-out-name) tuples. ret = [] bld_ext = self.distribution.get_command_obj('build_ext') compiler_type = bld_ext.compiler.compiler_type <...
0
2012-04-07T04:22:45Z
[ "python", "compiler-construction", "installation", "distutils" ]
Picking out items from a python list which have specific indexes
724,856
<p>I'm sure there's a nice way to do this in Python, but I'm pretty new to the language, so forgive me if this is an easy one!</p> <p>I have a list, and I'd like to pick out certain values from that list. The values I want to pick out are the ones whose indexes in the list are specified in another list.</p> <p>For ex...
9
2009-04-07T09:43:33Z
724,869
<pre><code>t = [] for i in indexes: t.append(main_list[i]) return t </code></pre>
2
2009-04-07T09:47:29Z
[ "python", "list", "list-comprehension" ]
Picking out items from a python list which have specific indexes
724,856
<p>I'm sure there's a nice way to do this in Python, but I'm pretty new to the language, so forgive me if this is an easy one!</p> <p>I have a list, and I'd like to pick out certain values from that list. The values I want to pick out are the ones whose indexes in the list are specified in another list.</p> <p>For ex...
9
2009-04-07T09:43:33Z
724,880
<p>I think Yuval A's solution is a pretty clear and simple. But if you actually want a one line list comprehension:</p> <pre><code>[e for i, e in enumerate(main_list) if i in indexes] </code></pre>
1
2009-04-07T09:50:51Z
[ "python", "list", "list-comprehension" ]
Picking out items from a python list which have specific indexes
724,856
<p>I'm sure there's a nice way to do this in Python, but I'm pretty new to the language, so forgive me if this is an easy one!</p> <p>I have a list, and I'd like to pick out certain values from that list. The values I want to pick out are the ones whose indexes in the list are specified in another list.</p> <p>For ex...
9
2009-04-07T09:43:33Z
724,881
<pre><code>[main_list[x] for x in indexes] </code></pre> <p>This will return a list of the objects, using a list comprehension.</p>
41
2009-04-07T09:50:52Z
[ "python", "list", "list-comprehension" ]
Picking out items from a python list which have specific indexes
724,856
<p>I'm sure there's a nice way to do this in Python, but I'm pretty new to the language, so forgive me if this is an easy one!</p> <p>I have a list, and I'd like to pick out certain values from that list. The values I want to pick out are the ones whose indexes in the list are specified in another list.</p> <p>For ex...
9
2009-04-07T09:43:33Z
726,038
<pre><code>map(lambda x:main_list[x],indexes) </code></pre>
0
2009-04-07T14:33:09Z
[ "python", "list", "list-comprehension" ]
How to make pdb recognize that the source has changed between runs?
724,924
<p>From what I can tell, pdb does not recognize when the source code has changed between "runs". That is, if I'm debugging, notice a bug, fix that bug, and rerun the program in pdb (i.e. without exiting pdb), pdb will not recompile the code. I'll still be debugging the old version of the code, even if pdb lists the new...
4
2009-04-07T10:09:09Z
725,271
<p>What do you mean by "rerun the program in pdb?" If you've imported a module, Python won't reread it unless you explicitly ask to do so, i.e. with <code>reload(module)</code>. However, <code>reload</code> is far from bulletproof (see <a href="http://svn.python.org/projects/sandbox/trunk/xreload/xreload.py" rel="nofo...
2
2009-04-07T11:44:45Z
[ "python", "debugging", "pdb" ]
How to make pdb recognize that the source has changed between runs?
724,924
<p>From what I can tell, pdb does not recognize when the source code has changed between "runs". That is, if I'm debugging, notice a bug, fix that bug, and rerun the program in pdb (i.e. without exiting pdb), pdb will not recompile the code. I'll still be debugging the old version of the code, even if pdb lists the new...
4
2009-04-07T10:09:09Z
23,207,689
<p>The following mini-module may help. If you import it in your pdb session, then you can use:</p> <pre><code>pdb&gt; pdbs.r() </code></pre> <p>at any time to force-reload all non-system modules except <strong>main</strong>. The code skips that because it throws an ImportError('Cannot re-init internal module <stron...
3
2014-04-21T23:22:56Z
[ "python", "debugging", "pdb" ]
String manipulation in Python
725,364
<p>I am converting some code from another language to python. That code reads a rather large file into a string and then manipulates it by array indexing like:</p> <pre><code>str[i] = 'e' </code></pre> <p>This does not work directly in python due to the strings being immutable. What is the preferred way of doing this...
1
2009-04-07T12:10:57Z
725,382
<pre><code>l = list(str) l[i] = 'e' str = ''.join(l) </code></pre>
9
2009-04-07T12:14:38Z
[ "python", "string", "replace" ]
String manipulation in Python
725,364
<p>I am converting some code from another language to python. That code reads a rather large file into a string and then manipulates it by array indexing like:</p> <pre><code>str[i] = 'e' </code></pre> <p>This does not work directly in python due to the strings being immutable. What is the preferred way of doing this...
1
2009-04-07T12:10:57Z
725,388
<p>Assuming you're not using a variable-length text encoding such as UTF-8, you can use <code>array.array</code>:</p> <pre><code>&gt;&gt;&gt; import array &gt;&gt;&gt; a = array.array('c', 'foo') &gt;&gt;&gt; a[1] = 'e' &gt;&gt;&gt; a array('c', 'feo') &gt;&gt;&gt; a.tostring() 'feo' </code></pre> <p>But since you're...
12
2009-04-07T12:15:39Z
[ "python", "string", "replace" ]
String manipulation in Python
725,364
<p>I am converting some code from another language to python. That code reads a rather large file into a string and then manipulates it by array indexing like:</p> <pre><code>str[i] = 'e' </code></pre> <p>This does not work directly in python due to the strings being immutable. What is the preferred way of doing this...
1
2009-04-07T12:10:57Z
725,392
<p>Try:</p> <pre><code>sl = list(s) sl[i] = 'e' s = ''.join(sl) </code></pre>
0
2009-04-07T12:16:05Z
[ "python", "string", "replace" ]
String manipulation in Python
725,364
<p>I am converting some code from another language to python. That code reads a rather large file into a string and then manipulates it by array indexing like:</p> <pre><code>str[i] = 'e' </code></pre> <p>This does not work directly in python due to the strings being immutable. What is the preferred way of doing this...
1
2009-04-07T12:10:57Z
726,197
<p>Others have answered the string manipulation part of your question, but I think you ought to think about whether it would be better to parse the file and modify the data structure the text represents rather than manipulating the text directly.</p>
1
2009-04-07T14:57:50Z
[ "python", "string", "replace" ]
Finding all *rendered* images in a HTML file
725,756
<p>I need a way to find only <strong>rendered</strong> IMG tags in a HTML snippet. So, I can't just regex the HTML snippet to find all IMG tags because I'd also get IMG tags that are shown as text in the HTML (not rendered).</p> <p>I'm using Python on AppEngine.</p> <p>Any ideas?</p> <p>Thanks, Ivan</p>
0
2009-04-07T13:40:41Z
725,944
<p>The source code for rendered img tag are something like this:</p> <pre><code>&lt;img src="img.jpg"&gt;&lt;/img&gt; </code></pre> <p>If the img tag is displayed as text(not rendered), the html code would be like this:</p> <pre><code> &amp;lt;img src=&amp;quot;styles/BWLogo.jpg&amp;quot;&amp;gt;&amp;lt;/img&amp;gt;...
2
2009-04-07T14:11:57Z
[ "python", "html", "regex", "parsing" ]
Finding all *rendered* images in a HTML file
725,756
<p>I need a way to find only <strong>rendered</strong> IMG tags in a HTML snippet. So, I can't just regex the HTML snippet to find all IMG tags because I'd also get IMG tags that are shown as text in the HTML (not rendered).</p> <p>I'm using Python on AppEngine.</p> <p>Any ideas?</p> <p>Thanks, Ivan</p>
0
2009-04-07T13:40:41Z
727,015
<p>As image tags might be in between some &lt;pre&gt; or &lt;xmp&gt; tag you probably have to walk through the dom (= convert the html to a xml/dom tree and search through it) and find all the &lt;img&gt; nodes. There is a xml.dom class in the python standard library: <a href="http://docs.python.org/library/xml.dom.htm...
0
2009-04-07T18:28:30Z
[ "python", "html", "regex", "parsing" ]
Finding all *rendered* images in a HTML file
725,756
<p>I need a way to find only <strong>rendered</strong> IMG tags in a HTML snippet. So, I can't just regex the HTML snippet to find all IMG tags because I'd also get IMG tags that are shown as text in the HTML (not rendered).</p> <p>I'm using Python on AppEngine.</p> <p>Any ideas?</p> <p>Thanks, Ivan</p>
0
2009-04-07T13:40:41Z
727,028
<p>Use <a href="http://www.crummy.com/software/BeautifulSoup" rel="nofollow">BeautifulSoup</a>. It is an HTML/XML parser for Python that provides simple, idiomatic ways of navigating, searching, and modifying the parse tree. It probably won't be mistaken by fake img tags.</p>
2
2009-04-07T18:31:30Z
[ "python", "html", "regex", "parsing" ]
Finding all *rendered* images in a HTML file
725,756
<p>I need a way to find only <strong>rendered</strong> IMG tags in a HTML snippet. So, I can't just regex the HTML snippet to find all IMG tags because I'd also get IMG tags that are shown as text in the HTML (not rendered).</p> <p>I'm using Python on AppEngine.</p> <p>Any ideas?</p> <p>Thanks, Ivan</p>
0
2009-04-07T13:40:41Z
727,122
<p>Sounds like a job for <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a>:</p> <pre><code>&gt;&gt;&gt; from BeautifulSoup import BeautifulSoup &gt;&gt;&gt; doc = """ ... &lt;html&gt; ... &lt;body&gt; ... &lt;img src="test.jpg"&gt; ... &amp;lt;img src="yay.jpg"&amp;gt; ... &lt;!-...
2
2009-04-07T18:51:01Z
[ "python", "html", "regex", "parsing" ]
Dynamic use of a class method defined in a Cython extension module
725,777
<p>I would like to use the C implementation of a class method (generated from <a href="http://www.cython.org/" rel="nofollow">Cython</a>) if it is present, or use its Python equivalent if the C extension is not present. I first tried this:</p> <pre><code>class A(object): try: import c_ext method = ...
3
2009-04-07T13:44:09Z
726,259
<p>Ok I just found the answer...</p> <p>The problem comes from the way Cython <a href="http://docs.cython.org/docs/limitations.html#behaviour-of-class-scopes" rel="nofollow">wraps the functions it exports</a>: every method is unbound regardless from where it is referenced.</p> <p>The solution is to explicitly declare...
3
2009-04-07T15:11:47Z
[ "python", "methods", "cython" ]
In Python, what is the difference between ".append()" and "+= []"?
725,782
<p>What is the difference between:</p> <pre><code>some_list1 = [] some_list1.append("something") </code></pre> <p>and</p> <pre><code>some_list2 = [] some_list2 += ["something"] </code></pre>
88
2009-04-07T13:44:24Z
725,818
<p>In the example you gave, there is no difference, in terms of output, between <code>append</code> and <code>+=</code>. But there is a difference between <code>append</code> and <code>+</code> (which the question originally asked about).</p> <pre><code>&gt;&gt;&gt; a = [] &gt;&gt;&gt; id(a) 11814312 &gt;&gt;&gt; a.a...
44
2009-04-07T13:51:17Z
[ "python", "list", "concatenation" ]
In Python, what is the difference between ".append()" and "+= []"?
725,782
<p>What is the difference between:</p> <pre><code>some_list1 = [] some_list1.append("something") </code></pre> <p>and</p> <pre><code>some_list2 = [] some_list2 += ["something"] </code></pre>
88
2009-04-07T13:44:24Z
725,853
<pre><code> some_list2 += ["something"] </code></pre> <p>is actually </p> <pre><code> some_list2.extend(["something"]) </code></pre> <p>for one value, there is no difference. Documentation states, that:</p> <blockquote> <p><code>s.append(x)</code> same as <code>s[len(s):len(s)] = [x]</code> <br/> <code>s.ex...
19
2009-04-07T13:54:49Z
[ "python", "list", "concatenation" ]
In Python, what is the difference between ".append()" and "+= []"?
725,782
<p>What is the difference between:</p> <pre><code>some_list1 = [] some_list1.append("something") </code></pre> <p>and</p> <pre><code>some_list2 = [] some_list2 += ["something"] </code></pre>
88
2009-04-07T13:44:24Z
725,863
<pre><code>&gt;&gt;&gt; a=[] &gt;&gt;&gt; a.append([1,2]) &gt;&gt;&gt; a [[1, 2]] &gt;&gt;&gt; a=[] &gt;&gt;&gt; a+=[1,2] &gt;&gt;&gt; a [1, 2] </code></pre> <p>See that append adds a single element to the list, which may be anything. <code>+=[]</code> joins the lists.</p>
36
2009-04-07T13:57:37Z
[ "python", "list", "concatenation" ]
In Python, what is the difference between ".append()" and "+= []"?
725,782
<p>What is the difference between:</p> <pre><code>some_list1 = [] some_list1.append("something") </code></pre> <p>and</p> <pre><code>some_list2 = [] some_list2 += ["something"] </code></pre>
88
2009-04-07T13:44:24Z
725,882
<p>For your case the only difference is performance: append is twice as fast.</p> <pre><code>Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; import timeit &gt;&gt;&gt; timeit.Timer('s.append("somethin...
130
2009-04-07T14:00:24Z
[ "python", "list", "concatenation" ]
In Python, what is the difference between ".append()" and "+= []"?
725,782
<p>What is the difference between:</p> <pre><code>some_list1 = [] some_list1.append("something") </code></pre> <p>and</p> <pre><code>some_list2 = [] some_list2 += ["something"] </code></pre>
88
2009-04-07T13:44:24Z
726,321
<p>In addition to the aspects described in the other answers, append and +[] have very different behaviors when you're trying to build a list of lists.</p> <pre><code>&gt;&gt;&gt; list1=[[1,2],[3,4]] &gt;&gt;&gt; list2=[5,6] &gt;&gt;&gt; list3=list1+list2 &gt;&gt;&gt; list3 [[1, 2], [3, 4], 5, 6] &gt;&gt;&gt; list1.ap...
3
2009-04-07T15:24:17Z
[ "python", "list", "concatenation" ]
In Python, what is the difference between ".append()" and "+= []"?
725,782
<p>What is the difference between:</p> <pre><code>some_list1 = [] some_list1.append("something") </code></pre> <p>and</p> <pre><code>some_list2 = [] some_list2 += ["something"] </code></pre>
88
2009-04-07T13:44:24Z
726,349
<p>+= is an assignment. When you use it you're really saying ‘some_list2= some_list2+['something']’. Assignments involve rebinding, so:</p> <pre><code>l= [] def a1(x): l.append(x) # works def a2(x): l= l+[x] # assign to l, makes l local # so attempt to read l for addition gives UnboundLocalE...
25
2009-04-07T15:29:12Z
[ "python", "list", "concatenation" ]
In Python, what is the difference between ".append()" and "+= []"?
725,782
<p>What is the difference between:</p> <pre><code>some_list1 = [] some_list1.append("something") </code></pre> <p>and</p> <pre><code>some_list2 = [] some_list2 += ["something"] </code></pre>
88
2009-04-07T13:44:24Z
8,701,544
<p>The performance tests here are not correct:</p> <ol> <li>You shouldn't run the profile only once.</li> <li>If comparing append vs. += [] number of times you should declare append as a local function.</li> <li>time results are different on different python versions: 64 and 32 bit</li> </ol> <p>e.g. </p> <blockquo...
4
2012-01-02T13:42:10Z
[ "python", "list", "concatenation" ]
In Python, what is the difference between ".append()" and "+= []"?
725,782
<p>What is the difference between:</p> <pre><code>some_list1 = [] some_list1.append("something") </code></pre> <p>and</p> <pre><code>some_list2 = [] some_list2 += ["something"] </code></pre>
88
2009-04-07T13:44:24Z
9,694,555
<p>The rebinding behaviour mentioned in other answers does matter in certain circumstances:</p> <pre><code>&gt;&gt;&gt; a = ([],[]) &gt;&gt;&gt; a[0].append(1) &gt;&gt;&gt; a ([1], []) &gt;&gt;&gt; a[1] += [1] Traceback (most recent call last): File "&lt;interactive input&gt;", line 1, in &lt;module&gt; TypeError: '...
1
2012-03-14T01:03:43Z
[ "python", "list", "concatenation" ]
In Python, what is the difference between ".append()" and "+= []"?
725,782
<p>What is the difference between:</p> <pre><code>some_list1 = [] some_list1.append("something") </code></pre> <p>and</p> <pre><code>some_list2 = [] some_list2 += ["something"] </code></pre>
88
2009-04-07T13:44:24Z
24,136,781
<p>The difference is that <i><b>concatenate</b></i> will flatten the resulting list, whereas <i><b>append</b></i> will keep the levels intact:</p> <p>So for example with:</p> <pre><code>myList = [ ] listA = [1,2,3] listB = ["a","b","c"] </code></pre> <p>Using append, you end up with a list of lists:</p> <pre><code>...
2
2014-06-10T08:56:48Z
[ "python", "list", "concatenation" ]
Installing ipython with readline on the mac
726,449
<p>I am using ipython on Mac OS 10.5 with python 2.5.1 (I would actually like to use ipython for 2.6.1, but it doesn't seem to be available?)</p> <p>I installed ipython via easy_install. It works but is missing gnu readline (needed for nice searching of command line history with ctrl-R, etc.)</p> <p>I found a <a href...
16
2009-04-07T15:55:16Z
726,611
<p>You can install everything you need with essentially one command using MacPorts. First download and install MacPorts from <a href="http://www.macports.org/">http://www.macports.org/</a>. </p> <p>Then just do the following in the terminal: 1) sudo port -v selfupdate<br /> 2) sudo port -v install py26-ipython</p> <p...
3
2009-04-07T16:46:17Z
[ "python", "osx", "readline", "ipython" ]
Installing ipython with readline on the mac
726,449
<p>I am using ipython on Mac OS 10.5 with python 2.5.1 (I would actually like to use ipython for 2.6.1, but it doesn't seem to be available?)</p> <p>I installed ipython via easy_install. It works but is missing gnu readline (needed for nice searching of command line history with ctrl-R, etc.)</p> <p>I found a <a href...
16
2009-04-07T15:55:16Z
727,539
<p>"I would actually like to use ipython for 2.6.1"</p> <p>It is available. I'm using it with 2.6.1 on os x. You just need to install the official python 2.6.1 distribution, then install ipython with easy_install.</p>
0
2009-04-07T20:51:21Z
[ "python", "osx", "readline", "ipython" ]
Installing ipython with readline on the mac
726,449
<p>I am using ipython on Mac OS 10.5 with python 2.5.1 (I would actually like to use ipython for 2.6.1, but it doesn't seem to be available?)</p> <p>I installed ipython via easy_install. It works but is missing gnu readline (needed for nice searching of command line history with ctrl-R, etc.)</p> <p>I found a <a href...
16
2009-04-07T15:55:16Z
1,840,304
<p>To install ipython on Snow Leopard or Lion without using MacPorts, you can simply do:</p> <pre><code>sudo easy_install readline ipython </code></pre> <p>(Note that if you use the "pip" to install readline, then ipython won't see the readline library, not sure why).</p> <p><em>Edit:</em></p> <p>If you had ipython...
34
2009-12-03T14:43:38Z
[ "python", "osx", "readline", "ipython" ]
Installing ipython with readline on the mac
726,449
<p>I am using ipython on Mac OS 10.5 with python 2.5.1 (I would actually like to use ipython for 2.6.1, but it doesn't seem to be available?)</p> <p>I installed ipython via easy_install. It works but is missing gnu readline (needed for nice searching of command line history with ctrl-R, etc.)</p> <p>I found a <a href...
16
2009-04-07T15:55:16Z
4,483,997
<p>An alternative if you don't want to use ports. <strong>Caution: This is not upgrade safe.</strong></p> <p>Install <code>ipython</code> and <code>readline</code> as normal:</p> <pre><code>sudo easy_install -f http://ipython.scipy.org/dist/ readline ipython </code></pre> <p>Find the full path to your <code>readline...
1
2010-12-19T16:54:38Z
[ "python", "osx", "readline", "ipython" ]
Installing ipython with readline on the mac
726,449
<p>I am using ipython on Mac OS 10.5 with python 2.5.1 (I would actually like to use ipython for 2.6.1, but it doesn't seem to be available?)</p> <p>I installed ipython via easy_install. It works but is missing gnu readline (needed for nice searching of command line history with ctrl-R, etc.)</p> <p>I found a <a href...
16
2009-04-07T15:55:16Z
8,749,044
<p>this worked for me (I'm using python 2.7, for other versions you'll need to edit):</p> <pre><code>cd /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload sudo mv readline.so readline.so.bak </code></pre> <p>install readline however you want (pip, homebrew, macports, etc)</p> <pre><co...
13
2012-01-05T20:09:03Z
[ "python", "osx", "readline", "ipython" ]
Installing ipython with readline on the mac
726,449
<p>I am using ipython on Mac OS 10.5 with python 2.5.1 (I would actually like to use ipython for 2.6.1, but it doesn't seem to be available?)</p> <p>I installed ipython via easy_install. It works but is missing gnu readline (needed for nice searching of command line history with ctrl-R, etc.)</p> <p>I found a <a href...
16
2009-04-07T15:55:16Z
21,585,404
<p>The only working way on MacOS Mavericks is to:</p> <ol> <li>switch to your virtualenv <code>workon myproject_name</code></li> <li>delete readline and ipython (if you installed it before) <code>pip uninstall readline ipython</code></li> <li>install readline only via easy_install (pip - no work!) <code>easy_install r...
2
2014-02-05T18:25:23Z
[ "python", "osx", "readline", "ipython" ]
How do I write to the console in Google App Engine?
727,410
<p>Often when I am coding I just like to print little things (mostly the current value of variables) out to console. I don't see anything like this for Google App Engine, although I note that the Google App Engine Launcher does have a Log terminal. Is there any way to write to said Terminal, or to some other terminal, ...
42
2009-04-07T20:14:52Z
727,438
<p>See <a href="https://cloud.google.com/appengine/docs/python/requests#Python_Logging">https://cloud.google.com/appengine/docs/python/requests#Python_Logging</a> <br/> and <a href="http://docs.python.org/library/logging.html">http://docs.python.org/library/logging.html</a></p> <p>You probably want to use something li...
31
2009-04-07T20:23:22Z
[ "python", "google-app-engine", "logging" ]
How do I write to the console in Google App Engine?
727,410
<p>Often when I am coding I just like to print little things (mostly the current value of variables) out to console. I don't see anything like this for Google App Engine, although I note that the Google App Engine Launcher does have a Log terminal. Is there any way to write to said Terminal, or to some other terminal, ...
42
2009-04-07T20:14:52Z
728,027
<p>You should also give FirePython a look. It allows you to get server log messages in firebug.</p> <p><a href="http://appengine-cookbook.appspot.com/recipe/firepython-logger-console-inside-firebug/" rel="nofollow">http://appengine-cookbook.appspot.com/recipe/firepython-logger-console-inside-firebug/</a></p>
2
2009-04-07T23:49:16Z
[ "python", "google-app-engine", "logging" ]
How do I write to the console in Google App Engine?
727,410
<p>Often when I am coding I just like to print little things (mostly the current value of variables) out to console. I don't see anything like this for Google App Engine, although I note that the Google App Engine Launcher does have a Log terminal. Is there any way to write to said Terminal, or to some other terminal, ...
42
2009-04-07T20:14:52Z
4,380,470
<p>@Manjoor</p> <p>You can do the same thing in java.</p> <pre><code>import java.util.logging.Logger; // ... public class MyServlet extends HttpServlet { private static final Logger log = Logger.getLogger(MyServlet.class.getName()); public void doGet(HttpServletRequest req, HttpServletResponse resp) ...
9
2010-12-07T18:54:45Z
[ "python", "google-app-engine", "logging" ]
How do I write to the console in Google App Engine?
727,410
<p>Often when I am coding I just like to print little things (mostly the current value of variables) out to console. I don't see anything like this for Google App Engine, although I note that the Google App Engine Launcher does have a Log terminal. Is there any way to write to said Terminal, or to some other terminal, ...
42
2009-04-07T20:14:52Z
7,239,145
<p>Check out my online Python interpreter running on Google App Engine on my website, <a href="http://www.learnpython.org" rel="nofollow">Learn Python</a>. It might be what you're looking for. Just use print repr(variable) on things you want to look at, and execute as many times as you want.</p>
1
2011-08-30T05:46:09Z
[ "python", "google-app-engine", "logging" ]
How do I write to the console in Google App Engine?
727,410
<p>Often when I am coding I just like to print little things (mostly the current value of variables) out to console. I don't see anything like this for Google App Engine, although I note that the Google App Engine Launcher does have a Log terminal. Is there any way to write to said Terminal, or to some other terminal, ...
42
2009-04-07T20:14:52Z
9,660,319
<p>You'll want to use the Python's standard <code>logging</code> module.</p> <pre><code>import logging logging.info("hello") logging.debug("hi") # this won't show up by default </code></pre> <p>To see calls to <code>logging.debug()</code> in the GoogleAppEngineLauncher Logs console, you have to first add the flag <c...
58
2012-03-12T00:23:48Z
[ "python", "google-app-engine", "logging" ]
How do I write to the console in Google App Engine?
727,410
<p>Often when I am coding I just like to print little things (mostly the current value of variables) out to console. I don't see anything like this for Google App Engine, although I note that the Google App Engine Launcher does have a Log terminal. Is there any way to write to said Terminal, or to some other terminal, ...
42
2009-04-07T20:14:52Z
17,842,828
<p>GAE will capture standard error and print it to the console or to a log.</p> <pre><code>print &gt;&gt; sys.stderr, "Something to log." </code></pre>
0
2013-07-24T19:10:40Z
[ "python", "google-app-engine", "logging" ]
How do I write to the console in Google App Engine?
727,410
<p>Often when I am coding I just like to print little things (mostly the current value of variables) out to console. I don't see anything like this for Google App Engine, although I note that the Google App Engine Launcher does have a Log terminal. Is there any way to write to said Terminal, or to some other terminal, ...
42
2009-04-07T20:14:52Z
18,987,161
<p><strong>Use log.setLevel(Level.ALL) to see messages</strong></p> <p>The default message filtering level seems to be 'error'. I didn't see any useful log messages until I used the setLevel() method to make the .info and .warning messages visible. </p> <p>Text printed to System.out wasn't showing up either. It see...
0
2013-09-24T16:30:44Z
[ "python", "google-app-engine", "logging" ]
How do I write to the console in Google App Engine?
727,410
<p>Often when I am coding I just like to print little things (mostly the current value of variables) out to console. I don't see anything like this for Google App Engine, although I note that the Google App Engine Launcher does have a Log terminal. Is there any way to write to said Terminal, or to some other terminal, ...
42
2009-04-07T20:14:52Z
20,152,111
<p>Hello I'm using the version 1.8.6 of GoogleAppEngineLauncher, you can use a flag to set the messages log level you want to see, for example for debug messages:</p> <p><code>--dev_appserver_log_level debug</code></p> <p>Use it instead of <code>--debug</code> (see @Christopher answer).</p>
1
2013-11-22T18:37:23Z
[ "python", "google-app-engine", "logging" ]
How do I write to the console in Google App Engine?
727,410
<p>Often when I am coding I just like to print little things (mostly the current value of variables) out to console. I don't see anything like this for Google App Engine, although I note that the Google App Engine Launcher does have a Log terminal. Is there any way to write to said Terminal, or to some other terminal, ...
42
2009-04-07T20:14:52Z
22,467,787
<p>If you're using a more recent version of the Python Development Server (releases > 1.7.6, or Mar 2013 and later), these seem to be the right steps to use:</p> <ol> <li><p>Include the following in your script,</p> <p><code>import logging logging.debug("something I want to log")</code></p></li> <li><p>And per <a hre...
4
2014-03-17T23:53:34Z
[ "python", "google-app-engine", "logging" ]
How do I write to the console in Google App Engine?
727,410
<p>Often when I am coding I just like to print little things (mostly the current value of variables) out to console. I don't see anything like this for Google App Engine, although I note that the Google App Engine Launcher does have a Log terminal. Is there any way to write to said Terminal, or to some other terminal, ...
42
2009-04-07T20:14:52Z
34,630,984
<p>I hope i am answering the question. The logging messages print to the AppEngine log rather than the terminal. </p> <p>You can launch it <a href="http://i.stack.imgur.com/I9wXa.png" rel="nofollow">by clicking on the logs button of the AppEngine Launcher</a></p>
0
2016-01-06T10:36:49Z
[ "python", "google-app-engine", "logging" ]
How can I convert Unicode to uppercase to print it?
727,507
<p>I have this:</p> <pre><code>&gt;&gt;&gt; print 'example' example &gt;&gt;&gt; print 'exámple' exámple &gt;&gt;&gt; print 'exámple'.upper() EXáMPLE </code></pre> <p>What I need to do to print:</p> <pre><code>EXÁMPLE </code></pre> <p><em>(Where the 'a' gets its accute accent, but in uppercase.)</em></p> <p>I...
28
2009-04-07T20:41:46Z
727,517
<p>I think it's as simple as <strong>not</strong> converting to ASCII first.</p> <pre><code> &gt;&gt;&gt; print u'exámple'.upper() EXÁMPLE </code></pre>
47
2009-04-07T20:45:53Z
[ "python", "unicode", "python-2.x", "case-sensitive", "uppercase" ]
How can I convert Unicode to uppercase to print it?
727,507
<p>I have this:</p> <pre><code>&gt;&gt;&gt; print 'example' example &gt;&gt;&gt; print 'exámple' exámple &gt;&gt;&gt; print 'exámple'.upper() EXáMPLE </code></pre> <p>What I need to do to print:</p> <pre><code>EXÁMPLE </code></pre> <p><em>(Where the 'a' gets its accute accent, but in uppercase.)</em></p> <p>I...
28
2009-04-07T20:41:46Z
727,571
<p>In python 2.x, just convert the string to unicode before calling upper(). Using your code, which is in utf-8 format on this webpage:</p> <pre><code>&gt;&gt;&gt; s = 'exámple' &gt;&gt;&gt; s 'ex\xc3\xa1mple' # my terminal is not utf8. c3a1 is the UTF-8 hex for á &gt;&gt;&gt; s.decode('utf-8').upper() u'EX\xc1MPLE...
15
2009-04-07T21:00:48Z
[ "python", "unicode", "python-2.x", "case-sensitive", "uppercase" ]
How can I convert Unicode to uppercase to print it?
727,507
<p>I have this:</p> <pre><code>&gt;&gt;&gt; print 'example' example &gt;&gt;&gt; print 'exámple' exámple &gt;&gt;&gt; print 'exámple'.upper() EXáMPLE </code></pre> <p>What I need to do to print:</p> <pre><code>EXÁMPLE </code></pre> <p><em>(Where the 'a' gets its accute accent, but in uppercase.)</em></p> <p>I...
28
2009-04-07T20:41:46Z
727,938
<p>I think there's a bit of background we're missing here:</p> <pre><code>&gt;&gt;&gt; type('hello') &lt;type 'str'&gt; &gt;&gt;&gt; type(u'hello') &lt;type 'unicode'&gt; </code></pre> <p>As long as you're using "unicode" strings instead of "native" strings, the operators like upper() will operate with unicode in mi...
4
2009-04-07T23:09:10Z
[ "python", "unicode", "python-2.x", "case-sensitive", "uppercase" ]
How can I convert Unicode to uppercase to print it?
727,507
<p>I have this:</p> <pre><code>&gt;&gt;&gt; print 'example' example &gt;&gt;&gt; print 'exámple' exámple &gt;&gt;&gt; print 'exámple'.upper() EXáMPLE </code></pre> <p>What I need to do to print:</p> <pre><code>EXÁMPLE </code></pre> <p><em>(Where the 'a' gets its accute accent, but in uppercase.)</em></p> <p>I...
28
2009-04-07T20:41:46Z
3,691,817
<p>first off, i only use python 3.1 these days; its central merit is to have disambiguated byte strings from unicode objects. this makes the vast majority of text manipulations much safer than used to be the case. weighing in the trillions of user questions regarding python 2.x encoding problems, the <code>u'äbc</code...
7
2010-09-11T16:52:59Z
[ "python", "unicode", "python-2.x", "case-sensitive", "uppercase" ]
Python __str__ and lists
727,761
<p>In Java, if I call List.toString(), it will automatically call the toString() method on each object inside the List. For example, if my list contains objects o1, o2, and o3, list.toString() would look something like this:</p> <pre><code>"[" + o1.toString() + ", " + o2.toString() + ", " + o3.toString() + "]" </code>...
58
2009-04-07T21:57:59Z
727,779
<p>Calling string on a python list calls the <code>__repr__</code> method on each element inside. For some items, <code>__str__</code> and <code>__repr__</code> are the same. If you want that behavior, do:</p> <pre><code>def __str__(self): ... def __repr__(self): return self.__str__() </code></pre>
84
2009-04-07T22:03:00Z
[ "python" ]
Python __str__ and lists
727,761
<p>In Java, if I call List.toString(), it will automatically call the toString() method on each object inside the List. For example, if my list contains objects o1, o2, and o3, list.toString() would look something like this:</p> <pre><code>"[" + o1.toString() + ", " + o2.toString() + ", " + o3.toString() + "]" </code>...
58
2009-04-07T21:57:59Z
727,780
<p>You can use a <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions">list comprehension</a> to generate a new list with each item str()'d automatically:</p> <pre><code>print([str(item) for item in mylist]) </code></pre>
14
2009-04-07T22:03:09Z
[ "python" ]
Python __str__ and lists
727,761
<p>In Java, if I call List.toString(), it will automatically call the toString() method on each object inside the List. For example, if my list contains objects o1, o2, and o3, list.toString() would look something like this:</p> <pre><code>"[" + o1.toString() + ", " + o2.toString() + ", " + o3.toString() + "]" </code>...
58
2009-04-07T21:57:59Z
727,783
<p>Two easy things you can do, use the <code>map</code> function or use a comprehension.</p> <p>But that gets you a list of strings, not a string. So you also have to join the strings together.</p> <pre><code>s= ",".join( map( str, myList ) ) </code></pre> <p>or</p> <pre><code>s= ",".join( [ str(element) for eleme...
3
2009-04-07T22:03:47Z
[ "python" ]
Python __str__ and lists
727,761
<p>In Java, if I call List.toString(), it will automatically call the toString() method on each object inside the List. For example, if my list contains objects o1, o2, and o3, list.toString() would look something like this:</p> <pre><code>"[" + o1.toString() + ", " + o2.toString() + ", " + o3.toString() + "]" </code>...
58
2009-04-07T21:57:59Z
727,786
<p>Something like this?</p> <pre><code>a = [1, 2 ,3] [str(x) for x in a] # ['1', '2', '3'] </code></pre>
0
2009-04-07T22:04:09Z
[ "python" ]
Python __str__ and lists
727,761
<p>In Java, if I call List.toString(), it will automatically call the toString() method on each object inside the List. For example, if my list contains objects o1, o2, and o3, list.toString() would look something like this:</p> <pre><code>"[" + o1.toString() + ", " + o2.toString() + ", " + o3.toString() + "]" </code>...
58
2009-04-07T21:57:59Z
727,793
<p>Depending on what you want to use that output for, perhaps <code>__repr__</code> might be more appropriate:</p> <pre><code>import unittest class A(object): def __init__(self, val): self.val = val def __repr__(self): return repr(self.val) class Test(unittest.TestCase): def testMain(sel...
2
2009-04-07T22:06:53Z
[ "python" ]
Python __str__ and lists
727,761
<p>In Java, if I call List.toString(), it will automatically call the toString() method on each object inside the List. For example, if my list contains objects o1, o2, and o3, list.toString() would look something like this:</p> <pre><code>"[" + o1.toString() + ", " + o2.toString() + ", " + o3.toString() + "]" </code>...
58
2009-04-07T21:57:59Z
727,944
<p>I agree with the previous answer about using list comprehensions to do this, but you could certainly hide that behind a function, if that's what floats your boat.</p> <pre><code>def is_list(value): if type(value) in (list, tuple): return True return False def list_str(value): if not is_list(value): ret...
2
2009-04-07T23:11:57Z
[ "python" ]
Transferring Python modules
727,791
<p>Basically for this case, I am using the _winreg module in Python v2.6 but the python package I have to use is v2.5. When I try to use:</p> <pre><code>_winreg.ExpandEnvironmentStrings </code></pre> <p>it complains about not having this attribute in this module. I have successfully transferred other modules like com...
0
2009-04-07T22:05:47Z
727,808
<p>It's a compiled C extension, not pure Python, so you generally can't simply copy the DLL/so file across from one installation to another: the Python binary interface changes on 0.1 version number updates (but not 0.0.1 updates). In any case, _winreg seems to be statically build into Python.exe on the current officia...
2
2009-04-07T22:11:50Z
[ "python" ]
Display some free text in between Django Form fields
727,917
<p>I have a form like the following:</p> <pre><code>class MyForm(Form): #personal data firstname = CharField() lastname = CharField() #education data university = CharField() major = CharField() #foobar data foobar = ChoiceField() </code></pre> <p>Since some fields (like foobar) are populated from ...
11
2009-04-07T22:59:06Z
727,963
<p>Since each section is a collection of multiple, independent form fields, I recommend using a custom form template. This gives you absolute full control over the layout with minimal extra work. Django's <a href="http://docs.djangoproject.com/en/dev/topics/forms/#customizing-the-form-template" rel="nofollow">Customizi...
3
2009-04-07T23:19:00Z
[ "python", "django", "django-forms" ]
Display some free text in between Django Form fields
727,917
<p>I have a form like the following:</p> <pre><code>class MyForm(Form): #personal data firstname = CharField() lastname = CharField() #education data university = CharField() major = CharField() #foobar data foobar = ChoiceField() </code></pre> <p>Since some fields (like foobar) are populated from ...
11
2009-04-07T22:59:06Z
727,964
<p>Even though your form is populated from a database, you should still be able to manually write out the form, or use a template. Check out the <a href="http://docs.djangoproject.com/en/dev/topics/forms/#customizing-the-form-template" rel="nofollow">Django form documentation</a> for more details.</p>
0
2009-04-07T23:19:03Z
[ "python", "django", "django-forms" ]
Display some free text in between Django Form fields
727,917
<p>I have a form like the following:</p> <pre><code>class MyForm(Form): #personal data firstname = CharField() lastname = CharField() #education data university = CharField() major = CharField() #foobar data foobar = ChoiceField() </code></pre> <p>Since some fields (like foobar) are populated from ...
11
2009-04-07T22:59:06Z
729,388
<p>Remember also that a Django Form object is just a collection of fields; there is no need for a 1:1 correspondence between HTML form tags and Django Form objects. If the various sections of the form are actually logically separate, you could consider splitting it up into three Forms, which you could then render in y...
1
2009-04-08T10:29:34Z
[ "python", "django", "django-forms" ]
Display some free text in between Django Form fields
727,917
<p>I have a form like the following:</p> <pre><code>class MyForm(Form): #personal data firstname = CharField() lastname = CharField() #education data university = CharField() major = CharField() #foobar data foobar = ChoiceField() </code></pre> <p>Since some fields (like foobar) are populated from ...
11
2009-04-07T22:59:06Z
862,987
<p>If you want to customize the form, you don't have to render it <code>form.as_ul</code>. Django knows how to render foobar if you have set up the forms model properly...try it...no worries.</p> <p>Look at what python on the server sent your page. For example if it sent a django form like this:</p> <p><code>return ...
8
2009-05-14T12:15:26Z
[ "python", "django", "django-forms" ]
Display some free text in between Django Form fields
727,917
<p>I have a form like the following:</p> <pre><code>class MyForm(Form): #personal data firstname = CharField() lastname = CharField() #education data university = CharField() major = CharField() #foobar data foobar = ChoiceField() </code></pre> <p>Since some fields (like foobar) are populated from ...
11
2009-04-07T22:59:06Z
1,705,229
<p>One way to do this without displaying your form in the template using form.as_ul, is with django-uni-form. First you'll have to download it <a href="http://github.com/pydanny/django-uni-form" rel="nofollow">here</a> and install it. Then the code for setting up your form could looks something like this:</p> <pre><co...
14
2009-11-10T02:07:41Z
[ "python", "django", "django-forms" ]
Display some free text in between Django Form fields
727,917
<p>I have a form like the following:</p> <pre><code>class MyForm(Form): #personal data firstname = CharField() lastname = CharField() #education data university = CharField() major = CharField() #foobar data foobar = ChoiceField() </code></pre> <p>Since some fields (like foobar) are populated from ...
11
2009-04-07T22:59:06Z
2,043,716
<p>There is a <code>help_text</code> field in forms you know.</p> <p>in <em>forms.py</em>:</p> <ul> <li><code>myField = forms.myFieldType(help_text="Helping friendly text to put in your form", otherStuff=otherStuff)</code></li> </ul> <p>in <em>forms.html</em>:</p> <ul> <li><code>{{form.myField.help_text}}</code></l...
1
2010-01-11T17:55:35Z
[ "python", "django", "django-forms" ]
Display some free text in between Django Form fields
727,917
<p>I have a form like the following:</p> <pre><code>class MyForm(Form): #personal data firstname = CharField() lastname = CharField() #education data university = CharField() major = CharField() #foobar data foobar = ChoiceField() </code></pre> <p>Since some fields (like foobar) are populated from ...
11
2009-04-07T22:59:06Z
3,343,691
<p>For those into a similar situation as the author, I recommend falling back to CSS and the <code>:before</code> and/or <code>:after</code> pseudoselectors either on the <code>input</code> or the <code>label</code> elements of the form. They work just as well and could make your life a lot easier as you can still use ...
0
2010-07-27T12:41:15Z
[ "python", "django", "django-forms" ]
Display some free text in between Django Form fields
727,917
<p>I have a form like the following:</p> <pre><code>class MyForm(Form): #personal data firstname = CharField() lastname = CharField() #education data university = CharField() major = CharField() #foobar data foobar = ChoiceField() </code></pre> <p>Since some fields (like foobar) are populated from ...
11
2009-04-07T22:59:06Z
30,424,331
<p>agreed with @mipadi, seems it's the easiest way. </p> <p>So something like </p> <pre><code>$('.selector').append('&lt;html&gt;&lt;/html&gt;') </code></pre>
1
2015-05-24T13:59:26Z
[ "python", "django", "django-forms" ]
Python: Downloading a large file to a local path and setting custom http headers
728,118
<p>I am looking to download a file from a http url to a local file. The file is large enough that I want to download it and save it chunks rather than <code>read()</code> and <code>write()</code> the whole file as a single giant string.</p> <p>The interface of <code>urllib.urlretrieve</code> is essentially what I want...
5
2009-04-08T00:44:01Z
728,214
<p>If you want to use urllib and urlretrieve, subclass <code>urllib.URLopener</code> and use its <code>addheader()</code> method to adjust the headers (ie: <code>addheader('Accept', 'sound/basic')</code>, which I'm pulling from the docstring for urllib.addheader).</p> <p>To install your URLopener for use by urllib, se...
1
2009-04-08T01:46:37Z
[ "python", "http", "download", "urllib2", "urllib" ]
Python: Downloading a large file to a local path and setting custom http headers
728,118
<p>I am looking to download a file from a http url to a local file. The file is large enough that I want to download it and save it chunks rather than <code>read()</code> and <code>write()</code> the whole file as a single giant string.</p> <p>The interface of <code>urllib.urlretrieve</code> is essentially what I want...
5
2009-04-08T00:44:01Z
2,028,750
<p>What is the harm in writing your own function using urllib2?</p> <pre><code>import os import sys import urllib2 def urlretrieve(urlfile, fpath): chunk = 4096 f = open(fpath, "w") while 1: data = urlfile.read(chunk) if not data: print "done." break f.write...
2
2010-01-08T15:53:49Z
[ "python", "http", "download", "urllib2", "urllib" ]