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 |
|---|---|---|---|---|---|---|---|---|---|
Python Win32 - equivalent function to DriveInfo.IsReady | 1,290,515 | <p>I'm trying to find an equivalent Python function to the Windows function <a href="http://msdn.microsoft.com/en-us/library/system.io.driveinfo.isready.aspx" rel="nofollow">DriveInfo.IsReady</a>. I've spent a while searching through the functions provided by win32api and win32file but I can't find anything (though pe... | 1 | 2009-08-17T21:19:06Z | 1,290,729 | <p>I've used <code>GetVolumeInformation</code> in the past to determine this. For example, something like:</p>
<pre><code>def is_drive_ready(drive_name):
try:
win32api.GetVolumeInformation(drive_name)
return True
except:
return False
print 'ready:', is_drive_ready('c:\\') # true
print... | 1 | 2009-08-17T22:02:27Z | [
"python",
"winapi"
] |
UnicodeDecodeError when using socket.gethostname() result | 1,290,601 | <p>Some of my users report that the following code may raise a UnicodeDecodeError when the hostname contains non-ascii characters (however I haven't been able to replicate this on my Windows Vista machine):</p>
<pre><code> self.path = path
self.lock_file = os.path.abspath(path) + ".lock"
self.hostname = soc... | 1 | 2009-08-17T21:36:53Z | 1,290,675 | <p>Yes, if either the hostname or the dirname is a unicode string, it is likely to give you that error. The best solution is typically to make sure both are unicode, and not just one of them.</p>
| 0 | 2009-08-17T21:50:43Z | [
"python",
"unicode"
] |
UnicodeDecodeError when using socket.gethostname() result | 1,290,601 | <p>Some of my users report that the following code may raise a UnicodeDecodeError when the hostname contains non-ascii characters (however I haven't been able to replicate this on my Windows Vista machine):</p>
<pre><code> self.path = path
self.lock_file = os.path.abspath(path) + ".lock"
self.hostname = soc... | 1 | 2009-08-17T21:36:53Z | 1,291,186 | <p>You want a unique string based on the hostname, but it's got Unicode characters in it. There are a variety of ways to reduce a Unicode string to an ascii string, depending on how you want to deal with non-ascii characters. Here's one:</p>
<pre><code>self.hostname = socket.gethostname().encode('ascii', 'replace').... | 0 | 2009-08-18T00:23:40Z | [
"python",
"unicode"
] |
UnicodeDecodeError when using socket.gethostname() result | 1,290,601 | <p>Some of my users report that the following code may raise a UnicodeDecodeError when the hostname contains non-ascii characters (however I haven't been able to replicate this on my Windows Vista machine):</p>
<pre><code> self.path = path
self.lock_file = os.path.abspath(path) + ".lock"
self.hostname = soc... | 1 | 2009-08-17T21:36:53Z | 1,292,026 | <p>I don't think that there is a problem with the actual code that you've posted, even if <code>socket.gethostname()</code> returns a unicode object. There will be a problem when you attempt to use <code>name</code> such that it is converted to a string first:</p>
<pre><code>import os
hostname = u'\u1306blah'
pid = os... | 0 | 2009-08-18T05:47:35Z | [
"python",
"unicode"
] |
UnicodeDecodeError when using socket.gethostname() result | 1,290,601 | <p>Some of my users report that the following code may raise a UnicodeDecodeError when the hostname contains non-ascii characters (however I haven't been able to replicate this on my Windows Vista machine):</p>
<pre><code> self.path = path
self.lock_file = os.path.abspath(path) + ".lock"
self.hostname = soc... | 1 | 2009-08-17T21:36:53Z | 1,762,626 | <p>I don't think gethostname() is necessarily giving you a unicode object. It could be the directory name of lockfile. Regardless, one of them is a standard string with a non-ASCII (higher than 127) char in it and the other is a unicode string.</p>
<p>The problem is that the join function in the ntpath module (the mod... | 1 | 2009-11-19T11:20:23Z | [
"python",
"unicode"
] |
Running a python script from the command line in Windows | 1,290,659 | <p>I'm trying to run <a href="http://furius.ca/snakefood/" rel="nofollow">SnakeFood</a>, to analyze a python project. I'm on a Windows machine and so far I've been able to figure out how to:</p>
<ul>
<li>install Tortoise for Mercurial to download the SnakeFood code from the site</li>
<li>set the windows Path to accept... | 4 | 2009-08-17T21:47:51Z | 1,290,677 | <p>Would this work?</p>
<pre><code>python "DriveLetter:\path\to\sfood.py" "DriveLetter:\path\to\your\project"
</code></pre>
| 4 | 2009-08-17T21:51:22Z | [
"python",
"windows"
] |
Running a python script from the command line in Windows | 1,290,659 | <p>I'm trying to run <a href="http://furius.ca/snakefood/" rel="nofollow">SnakeFood</a>, to analyze a python project. I'm on a Windows machine and so far I've been able to figure out how to:</p>
<ul>
<li>install Tortoise for Mercurial to download the SnakeFood code from the site</li>
<li>set the windows Path to accept... | 4 | 2009-08-17T21:47:51Z | 1,290,678 | <p>Considering the documentation says "sfood /path/to/my/project" it most likely assumes a *nix environment. That leads me to the assumption that sfood probably has a shebang line.</p>
<p>On Windows you probably need to use "python sfood ". If "sfood" isn't in your PATH, you'll need to write the full path rather than ... | 1 | 2009-08-17T21:51:27Z | [
"python",
"windows"
] |
Running a python script from the command line in Windows | 1,290,659 | <p>I'm trying to run <a href="http://furius.ca/snakefood/" rel="nofollow">SnakeFood</a>, to analyze a python project. I'm on a Windows machine and so far I've been able to figure out how to:</p>
<ul>
<li>install Tortoise for Mercurial to download the SnakeFood code from the site</li>
<li>set the windows Path to accept... | 4 | 2009-08-17T21:47:51Z | 19,482,391 | <p>I was able to resolve this issue, on my Windows 7 machine with Python 2.7.3 installed, like so:</p>
<pre><code>C:\> cd \path\to\snakefood\installation\folder
C:\path\to\snakefood\installation\folder> python setup.py install
...
C:\path\to\snakefood\installation\folder> cd C:\Python27\Scripts
C:\Python27\Sc... | 1 | 2013-10-20T20:19:38Z | [
"python",
"windows"
] |
list of duplicate dictionaries copy single entry to another list | 1,290,717 | <p>newbie question again.</p>
<p>Let's say i have a list of nested dictionaries.</p>
<pre><code>a = [{"value1": 1234, "value2": 23423423421, "value3": norway, "value4": charlie},
{"value1": 1398, "value2": 23423412221, "value3": england, "value4": alpha},
{"value1": 1234, "value2": 23234231221, "value3": no... | 1 | 2009-08-17T21:59:35Z | 1,290,758 | <p>There was a similar question on this recently. Try this <a href="http://stackoverflow.com/questions/1279805/remove-duplicates-from-nested-dictionaries-in-list">entry</a>.</p>
<p>In fact, you asked that question: "Let's say there exists multiple entries where value3 and value4 are identical to other nested dictionar... | 2 | 2009-08-17T22:08:29Z | [
"python",
"dictionary",
"list"
] |
scrollbar for statictext in wxpython? | 1,290,736 | <p>is possible to add a scrollbar to a statictext in wxpython?</p>
<p>the thing is that i'm creating this statictext:</p>
<pre><code>self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,label=u'some text here',name='staticText1', parent=self.panel1, pos=wx.Point(16, 96),
size=wx.Size(408, 216),style=wx.... | 1 | 2009-08-17T22:03:43Z | 1,291,608 | <p><code>wx.StaticText</code> is designed to never respond to mouse events and never take user focus. Given that this is its role in life, it seems that a scrollbar would be inconsistent with its purpose.</p>
<p>There are two ways to get what you want: <strong>1)</strong> You could use a regular <code>TextCtrl</code... | 4 | 2009-08-18T03:16:16Z | [
"python",
"wxpython",
"scrollbar"
] |
IsPointInsideSegment(pt, line) in Python | 1,290,779 | <p>Is there a nice way to determine if a point lies within a 3D line segment?</p>
<p>I know there are algorithms that determine the distance between a point and line segment, but I'm wondering if there's something more compact or efficient.</p>
| 1 | 2009-08-17T22:13:55Z | 1,290,858 | <p>First, find the distance from the point to the line. If the distance from the point to the line is zero, then it's on the line.</p>
| 0 | 2009-08-17T22:35:44Z | [
"python",
"geometry"
] |
IsPointInsideSegment(pt, line) in Python | 1,290,779 | <p>Is there a nice way to determine if a point lies within a 3D line segment?</p>
<p>I know there are algorithms that determine the distance between a point and line segment, but I'm wondering if there's something more compact or efficient.</p>
| 1 | 2009-08-17T22:13:55Z | 1,290,934 | <p>Given three points A, B, and C -- where AB is your line and C is your other point, you can also restate your problem as two lines, AB and AC. If the angle between AB and AC is zero (i.e. if the area of the triangle ABC is zero) then your point C is on the line.</p>
<p>If you think about this in terms of angles, yo... | 4 | 2009-08-17T22:52:38Z | [
"python",
"geometry"
] |
IsPointInsideSegment(pt, line) in Python | 1,290,779 | <p>Is there a nice way to determine if a point lies within a 3D line segment?</p>
<p>I know there are algorithms that determine the distance between a point and line segment, but I'm wondering if there's something more compact or efficient.</p>
| 1 | 2009-08-17T22:13:55Z | 1,291,118 | <p>One way to restate your question is to ask of the point is a solution to the equation which contains the line segment in question, and (if so) if it lies between the end points of the segment.</p>
<p>Since you don't describe the details of how you're representing your line segments and don't mention any modules or ... | 1 | 2009-08-18T00:01:36Z | [
"python",
"geometry"
] |
Can I store objects in Python class members? | 1,290,798 | <p>I'm writing a game in Python with the Pygame2 multimedia library, but I'm more accustomed to developing games with ActionScript 3. In AS3, I don't think it was possible to store an object in a static variable, because static variables were initialized before objects could be instantiated. </p>
<p>However, in Python... | 0 | 2009-08-17T22:19:47Z | 1,290,827 | <p>You can do this:</p>
<pre><code>class Test:
counter = 0
def __init__(self):
Test.counter += 1
print Test.counter
</code></pre>
<p>And it works as expected.</p>
| 3 | 2009-08-17T22:28:30Z | [
"python",
"actionscript-3",
"pygame",
"instantiation"
] |
Can I store objects in Python class members? | 1,290,798 | <p>I'm writing a game in Python with the Pygame2 multimedia library, but I'm more accustomed to developing games with ActionScript 3. In AS3, I don't think it was possible to store an object in a static variable, because static variables were initialized before objects could be instantiated. </p>
<p>However, in Python... | 0 | 2009-08-17T22:19:47Z | 1,290,903 | <p>Yes.<br>
As with most python try it and see.</p>
<p>It will be instantiated when a Test object is created. ie your assignment to test1<br>
The counter object is created per class</p>
<p>Run the following to see (to access the class variable you need the self</p>
<pre><code>class Counter:
def __init__(self):
... | 2 | 2009-08-17T22:43:36Z | [
"python",
"actionscript-3",
"pygame",
"instantiation"
] |
Can't get Beaker sessions to work (KeyError) | 1,290,840 | <p>I'm a newb to the Python world and am having the dangest time with getting sessions to work in my web frameworks. I've tried getting Beaker sessions to work with the webpy framework and the Juno framework. And in both frameworks I always get a KeyError when I try to start the session.</p>
<p>Here is the error me... | 0 | 2009-08-17T22:30:26Z | 1,295,549 | <p>You haven't created the session object yet, so you can't find it in the environment (the <code>KeyError</code> simply means "<code>beaker.session</code> is not in this dictionary").</p>
<p>Note that I don't know either webpy nor beaker very well, so I can't give you deeper advice, but from what I understand from th... | 2 | 2009-08-18T18:04:53Z | [
"python",
"django",
"session",
"web.py"
] |
Django MVC pattern for non database driven models? | 1,290,891 | <p>I'm just working my way through Django, and really liking it so far, but I have an issue and I'm not sure what the typical way to solve it.</p>
<p>Suppose I have a View which is supposed to be updated when some complex Python object is updated, but this object is not driven by the database, say it is driven by AJAX... | 20 | 2009-08-17T22:40:35Z | 1,290,978 | <p>Your <code>models.py</code> can be (and sometimes is) empty. You are not obligated to have a model which maps to a database. </p>
<p>You should still have a <code>models.py</code> file, to make Django's admin happy. The <code>models.py</code> file name is important, and it's easier to have an empty file than to ... | 31 | 2009-08-17T23:07:15Z | [
"python",
"django",
"model-view-controller",
"models"
] |
Python capture output from wget? | 1,290,910 | <p>Is it possible to capture output from wget and other command line programs that use curses?
Here is what I have right now:</p>
<pre><code>p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=0)
for line in p.stdout:
print "a"
</code></pre>
<p>This works fine for programs that have simple output, but not f... | 1 | 2009-08-17T22:45:08Z | 1,290,984 | <p>I don't believe that <code>wget</code> is using curses.</p>
<p>Normally when I want to use <code>wget</code> in a script I'd use the <strong><code>-O -</code></strong> option to force its output to <i>stdout</i>. I suspect you're trying to capture the text that you <strong>normally</strong> see on your console whe... | 6 | 2009-08-17T23:09:14Z | [
"python"
] |
Phonon VideoWidget error: "the video widget could not be initialized correctly" | 1,291,068 | <p>I asked this question on the PyQt mailing list, and didn't get any responses, so I'll try my luck here.</p>
<p>I've encountered a frustrating issue (on Windows only): when trying to create a VideoWidget instance, I'm getting the error message "the video widget could not be initialized correctly". Oddly, this just s... | 0 | 2009-08-17T23:42:35Z | 1,291,283 | <p>The code that generates that message is in <code>3rdparty/phonon/ds9/videorenderer_vmr9.cpp</code>:</p>
<pre><code>m_filter = Filter(CLSID_VideoMixingRenderer9, IID_IBaseFilter);
if (!m_filter) {
qWarning("the video widget could not be initialized correctly");
return;
}
</code></pre>
<p>Filter is type <co... | 3 | 2009-08-18T00:56:12Z | [
"python",
"qt",
"pyqt",
"phonon"
] |
Phonon VideoWidget error: "the video widget could not be initialized correctly" | 1,291,068 | <p>I asked this question on the PyQt mailing list, and didn't get any responses, so I'll try my luck here.</p>
<p>I've encountered a frustrating issue (on Windows only): when trying to create a VideoWidget instance, I'm getting the error message "the video widget could not be initialized correctly". Oddly, this just s... | 0 | 2009-08-17T23:42:35Z | 1,764,250 | <p>Hate to answer my own question, but if anyone else encounters this:</p>
<p>The solution to this ended up being hardware-specific. Phonon appears to have issues with the video drivers for particular virtual machines - Parallels in my case. Physical hardware doesn't exhibit the issue. There is no workaround I've b... | 0 | 2009-11-19T15:47:58Z | [
"python",
"qt",
"pyqt",
"phonon"
] |
Checking for group membership (Many to Many in Django) | 1,291,167 | <p>I have two models in Django: groups and entries. Groups has a many-to-many field that connects it to entries. I want to select all entries that have a group (as not all do!) and be able to access their group.title field.</p>
<p>I've tried something along the lines of: </p>
<pre><code>t = Entries.objects.select_rel... | 2 | 2009-08-18T00:17:10Z | 1,291,202 | <p>You don't show the model code, so I can't be sure, but instead of t[0].groups, I think you want:</p>
<pre><code>for g in t[0].groups.all():
print g.title
</code></pre>
| 3 | 2009-08-18T00:27:49Z | [
"python",
"django"
] |
Abstraction and client/server architecture questions for Python game program | 1,291,179 | <p>Here is where I am at presently. I am designing a card game with the aim of utilizing major components for future work. The part that is hanging me up is creating a layer of abstraction between the server and the client(s). A server is started, and then one or more clients can connect (locally or remotely). I am des... | 2 | 2009-08-18T00:21:00Z | 1,291,227 | <p>Read up on RESTful architectures.</p>
<p>Your fat client can use REST. It will use <code>urllib2</code> to make RESTful requests of a server. It can exchange data in JSON notation.</p>
<p>A web client can use REST. It can make simple browser HTTP requests or a Javascript component can make more sophisticated RE... | 2 | 2009-08-18T00:35:39Z | [
"python",
"client-server",
"abstraction"
] |
Abstraction and client/server architecture questions for Python game program | 1,291,179 | <p>Here is where I am at presently. I am designing a card game with the aim of utilizing major components for future work. The part that is hanging me up is creating a layer of abstraction between the server and the client(s). A server is started, and then one or more clients can connect (locally or remotely). I am des... | 2 | 2009-08-18T00:21:00Z | 1,291,243 | <p>I would consider basing all server / client interactions on HTTP -- probably with JSON payloads. This doesn't directly allow server-initiated interactions ("server push"), but the (newish but already traditional;-) workaround for that is AJAX-y (even though the X makes little sense as I suggest JSON payloads, not X... | 2 | 2009-08-18T00:39:44Z | [
"python",
"client-server",
"abstraction"
] |
Abstraction and client/server architecture questions for Python game program | 1,291,179 | <p>Here is where I am at presently. I am designing a card game with the aim of utilizing major components for future work. The part that is hanging me up is creating a layer of abstraction between the server and the client(s). A server is started, and then one or more clients can connect (locally or remotely). I am des... | 2 | 2009-08-18T00:21:00Z | 1,291,311 | <p>First of all, regardless of the locality or type of the client, you will be communicating through an established message-based interface. All clients will be operating based on a common set of requests and responses, and the server will handle and reject these based on their validity according to game state. Whether... | 2 | 2009-08-18T01:08:35Z | [
"python",
"client-server",
"abstraction"
] |
Confused by Django's claim to MVC, what is it exactly? | 1,291,213 | <p>So what exactly is Django implementing?</p>
<p>Seems like there are</p>
<pre><code>Models
Views
Templates
</code></pre>
<blockquote>
<p>Models = Database mappings</p>
<p>Views = Grab relevant data from the
models and formats it via templates</p>
<p>Templates = Display HTML depending on data given by... | 6 | 2009-08-18T00:30:28Z | 1,291,223 | <p>Django's developers have a slightly non-traditional view on the MVC paradigm. They actually address this question in their FAQs, which you can read <a href="http://docs.djangoproject.com/en/dev/faq/general/#django-appears-to-be-a-mvc-framework-but-you-call-the-controller-the-view-and-the-view-the-template-how-come-y... | 14 | 2009-08-18T00:33:51Z | [
"python",
"django",
"model-view-controller",
"design-patterns"
] |
When I catch an exception, how do I get the type, file, and line number of the previous frame? | 1,291,438 | <p>From <a href="http://stackoverflow.com/questions/1278705/python-when-i-catch-an-exception-how-do-i-get-the-type-file-and-line-number/1278740#1278740">this question</a>, I'm now doing error handling one level down. That is, I call a function which calls another larger function, and I want where it failed in that larg... | 6 | 2009-08-18T02:08:47Z | 1,291,463 | <p>Add a line:</p>
<pre><code> tb = tb.tb_next
</code></pre>
<p>just after your call to <code>sys.exc_info</code>.</p>
<p>See the docs <a href="http://docs.python.org/reference/datamodel.html" rel="nofollow">here</a> under "Traceback objects".</p>
| 4 | 2009-08-18T02:18:45Z | [
"python",
"exception",
"exception-handling",
"error-handling"
] |
When I catch an exception, how do I get the type, file, and line number of the previous frame? | 1,291,438 | <p>From <a href="http://stackoverflow.com/questions/1278705/python-when-i-catch-an-exception-how-do-i-get-the-type-file-and-line-number/1278740#1278740">this question</a>, I'm now doing error handling one level down. That is, I call a function which calls another larger function, and I want where it failed in that larg... | 6 | 2009-08-18T02:08:47Z | 1,291,469 | <p>You need to find the bottom of the traceback, so you need to loop along until there are no more frames. Do this to find the frame you want:</p>
<pre><code>while tb.tb_next:
tb = tb.tb_next
</code></pre>
<p>after sys.exc_info. This will find the exception no matter how many call frames down it happened.</p>
| 2 | 2009-08-18T02:21:09Z | [
"python",
"exception",
"exception-handling",
"error-handling"
] |
When I catch an exception, how do I get the type, file, and line number of the previous frame? | 1,291,438 | <p>From <a href="http://stackoverflow.com/questions/1278705/python-when-i-catch-an-exception-how-do-i-get-the-type-file-and-line-number/1278740#1278740">this question</a>, I'm now doing error handling one level down. That is, I call a function which calls another larger function, and I want where it failed in that larg... | 6 | 2009-08-18T02:08:47Z | 1,291,491 | <p><code>tb.tb_next</code> is your friend:</p>
<pre><code>import sys, os
def workerFunc():
return 4/0
def runTest():
try:
print workerFunc()
except:
ty,val,tb = sys.exc_info()
print "Error: %s,%s,%s" % (
ty.__name__,
os.path.split(tb.tb_frame.f_code.co_file... | 3 | 2009-08-18T02:26:16Z | [
"python",
"exception",
"exception-handling",
"error-handling"
] |
Django : get entries of today and SplitDateTime Widget? | 1,291,537 | <p>I used : SplitDateTimeWidget to split DateTime field ,</p>
<pre><code>appointment = forms.DateTimeField(widget=forms.SplitDateTimeWidget)
</code></pre>
<p>In the template side i manage to use datePicker and TimePicker for each field , using jQuery .</p>
<p>When i try to filter the entries regarding to today date... | 0 | 2009-08-18T02:42:59Z | 1,291,628 | <p>Fix your timezone settings, in <code>settings.py TIME_ZONE</code></p>
<p><strong>Default:</strong> <code>'America/Chicago'</code></p>
<p>Some excerpts of useful info from <a href="http://docs.djangoproject.com/en/dev/ref/settings/#time-zone" rel="nofollow">the docs</a>:</p>
<blockquote>
<p>A string representin... | 2 | 2009-08-18T03:23:54Z | [
"python",
"django",
"django-forms"
] |
microcrontroller output to python cgi script | 1,291,624 | <p>I bought this temperature sensor logger kit: <a href="http://quozl.netrek.org/ts/" rel="nofollow">http://quozl.netrek.org/ts/</a>. It works great with the supplied C code, I like to use python because of its simplicity, so I wrote a script in python that displays the output from the microcontroller. I only have one ... | 1 | 2009-08-18T03:22:26Z | 1,291,762 | <p>I'm guessing that the execution context under which your CGI is running is unable to complete the <code>read()</code> from the serial port.</p>
<p>Incidentally the Python standard libraries have MUCH better ways for writing CGI scripts than what you're doing here; and even the basic string handling offers a better ... | 2 | 2009-08-18T04:11:53Z | [
"python",
"serial-port",
"cgi"
] |
microcrontroller output to python cgi script | 1,291,624 | <p>I bought this temperature sensor logger kit: <a href="http://quozl.netrek.org/ts/" rel="nofollow">http://quozl.netrek.org/ts/</a>. It works great with the supplied C code, I like to use python because of its simplicity, so I wrote a script in python that displays the output from the microcontroller. I only have one ... | 1 | 2009-08-18T03:22:26Z | 1,303,699 | <p>one more time:</p>
<pre><code># Added to allow cgi-bin to execute cgi, python and perl scripts
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
AddHandler cgi-script .cgi .py .pl
<Directory /var/www>
Options +Execcgi
AddHandler cgi-script .cgi .py .pl
</Directory>
</code></pre>
| 0 | 2009-08-20T02:48:55Z | [
"python",
"serial-port",
"cgi"
] |
microcrontroller output to python cgi script | 1,291,624 | <p>I bought this temperature sensor logger kit: <a href="http://quozl.netrek.org/ts/" rel="nofollow">http://quozl.netrek.org/ts/</a>. It works great with the supplied C code, I like to use python because of its simplicity, so I wrote a script in python that displays the output from the microcontroller. I only have one ... | 1 | 2009-08-18T03:22:26Z | 1,320,294 | <p>Michael,</p>
<p>It looks like the issue is definitely permissions, however, you shouldn't try to make your script have the permission of /dev/ttyS0. What you will probably need to do is spawn another process where the first thing you do is change your group to the group of the /dev/ttyS0 device. On my box that's 'd... | 0 | 2009-08-24T02:56:48Z | [
"python",
"serial-port",
"cgi"
] |
How can I tell whether my Django application is running on development server or not? | 1,291,755 | <p>How can I be certain that my application is running on development server or not? I suppose I could check value of <code>settings.DEBUG</code> and assume if <code>DEBUG</code> is <code>True</code> then it's running on development server, but I'd prefer to know for sure than relying on convention.</p>
| 36 | 2009-08-18T04:10:26Z | 1,291,769 | <p>settings.DEBUG could be True and running under Apache or some other non-development server. It will still run. As far as I can tell, there is nothing in the run-time environment short of examining the pid and comparing to pids in the OS that will give you this information.</p>
| 1 | 2009-08-18T04:14:19Z | [
"python",
"django",
"wsgi"
] |
How can I tell whether my Django application is running on development server or not? | 1,291,755 | <p>How can I be certain that my application is running on development server or not? I suppose I could check value of <code>settings.DEBUG</code> and assume if <code>DEBUG</code> is <code>True</code> then it's running on development server, but I'd prefer to know for sure than relying on convention.</p>
| 36 | 2009-08-18T04:10:26Z | 1,291,819 | <p>One difference between the development and deployment environment is going to be the server that itâs running on. What exactly is different will depend on your dev and deployment environments.</p>
<p>Knowing your own dev and deploy environments, the HTTP request variables could be used to distinguish between the ... | 0 | 2009-08-18T04:32:07Z | [
"python",
"django",
"wsgi"
] |
How can I tell whether my Django application is running on development server or not? | 1,291,755 | <p>How can I be certain that my application is running on development server or not? I suppose I could check value of <code>settings.DEBUG</code> and assume if <code>DEBUG</code> is <code>True</code> then it's running on development server, but I'd prefer to know for sure than relying on convention.</p>
| 36 | 2009-08-18T04:10:26Z | 1,291,858 | <pre><code>server = request.META.get('wsgi.file_wrapper', None)
if server is not None and server.__module__ == 'django.core.servers.basehttp':
print('inside dev')
</code></pre>
<p>Of course, <code>wsgi.file_wrapper</code> might be set on META, and have a class from a module named <code>django.core.servers.basehttp... | 16 | 2009-08-18T04:49:39Z | [
"python",
"django",
"wsgi"
] |
How can I tell whether my Django application is running on development server or not? | 1,291,755 | <p>How can I be certain that my application is running on development server or not? I suppose I could check value of <code>settings.DEBUG</code> and assume if <code>DEBUG</code> is <code>True</code> then it's running on development server, but I'd prefer to know for sure than relying on convention.</p>
| 36 | 2009-08-18T04:10:26Z | 1,291,864 | <p>Typically I set an variable called <code>environment</code> and set it to "DEVELOPMENT", "STAGING" or "PRODUCTION". Within the settings file I can then add basic logic to change which settings are being used, based on environment.</p>
<p><strong>EDIT:</strong> Additionally, you can simply use this logic to include... | 9 | 2009-08-18T04:54:41Z | [
"python",
"django",
"wsgi"
] |
How can I tell whether my Django application is running on development server or not? | 1,291,755 | <p>How can I be certain that my application is running on development server or not? I suppose I could check value of <code>settings.DEBUG</code> and assume if <code>DEBUG</code> is <code>True</code> then it's running on development server, but I'd prefer to know for sure than relying on convention.</p>
| 36 | 2009-08-18T04:10:26Z | 1,292,019 | <p>Relying on settings.DEBUG is the most elegant way AFAICS as it is also used in Django code base on occasion. </p>
<p>I suppose what you really want is a way to set that flag automatically without needing you update it manually everytime you upload the project to production servers. </p>
<p>For that I check the pat... | 4 | 2009-08-18T05:44:47Z | [
"python",
"django",
"wsgi"
] |
How can I tell whether my Django application is running on development server or not? | 1,291,755 | <p>How can I be certain that my application is running on development server or not? I suppose I could check value of <code>settings.DEBUG</code> and assume if <code>DEBUG</code> is <code>True</code> then it's running on development server, but I'd prefer to know for sure than relying on convention.</p>
| 36 | 2009-08-18T04:10:26Z | 4,277,798 | <p>I put the following in my settings.py to distinguish between the standard dev server and production:</p>
<pre><code>import sys
RUNNING_DEVSERVER = (len(sys.argv) > 1 and sys.argv[1] == 'runserver')
</code></pre>
<p>This also relies on convention, however. </p>
<p>(Amended per Daniel Magnusson's comment)</p>
| 22 | 2010-11-25T13:54:22Z | [
"python",
"django",
"wsgi"
] |
How can I tell whether my Django application is running on development server or not? | 1,291,755 | <p>How can I be certain that my application is running on development server or not? I suppose I could check value of <code>settings.DEBUG</code> and assume if <code>DEBUG</code> is <code>True</code> then it's running on development server, but I'd prefer to know for sure than relying on convention.</p>
| 36 | 2009-08-18T04:10:26Z | 8,900,872 | <p>I came across this problem just now, and ended up writing a solution similar to Aryeh Leib Taurog's. My main difference is that I want to differentiate between a production and dev environments when running the server, but also when running some one-off scripts for my app (which I run like DJANGO_SETTINGS_MODULE=set... | 3 | 2012-01-17T19:58:10Z | [
"python",
"django",
"wsgi"
] |
How can I tell whether my Django application is running on development server or not? | 1,291,755 | <p>How can I be certain that my application is running on development server or not? I suppose I could check value of <code>settings.DEBUG</code> and assume if <code>DEBUG</code> is <code>True</code> then it's running on development server, but I'd prefer to know for sure than relying on convention.</p>
| 36 | 2009-08-18T04:10:26Z | 10,732,264 | <p>Inspired by Aryeh's answer, the trick I devised for my own use is to just look for the name of my management script in <code>sys.argv[0]</code>:</p>
<pre><code>USING_DEV_SERVER = "pulpdist/manage_site.py" in sys.argv[0]
</code></pre>
<p>(My use case is to automatically enable Django native authentication when runn... | 0 | 2012-05-24T06:28:47Z | [
"python",
"django",
"wsgi"
] |
How can I tell whether my Django application is running on development server or not? | 1,291,755 | <p>How can I be certain that my application is running on development server or not? I suppose I could check value of <code>settings.DEBUG</code> and assume if <code>DEBUG</code> is <code>True</code> then it's running on development server, but I'd prefer to know for sure than relying on convention.</p>
| 36 | 2009-08-18T04:10:26Z | 11,232,206 | <p>I use:</p>
<pre><code>DEV_SERVERS = [
'mymachine.local',
]
DEVELOPMENT = platform.node() in DEV_SERVERS
</code></pre>
<p>which requires paying attention to what is returned by <code>.node()</code> on your machines. It's important that the default be non-development so that you don't accidentally expose sensi... | 0 | 2012-06-27T17:53:33Z | [
"python",
"django",
"wsgi"
] |
How can I tell whether my Django application is running on development server or not? | 1,291,755 | <p>How can I be certain that my application is running on development server or not? I suppose I could check value of <code>settings.DEBUG</code> and assume if <code>DEBUG</code> is <code>True</code> then it's running on development server, but I'd prefer to know for sure than relying on convention.</p>
| 36 | 2009-08-18T04:10:26Z | 12,706,200 | <p>If you want to switch your settings files automatically dependent on the runtime environment
you could just use something that differs in environ, e.g.</p>
<pre><code>from os import environ
if environ.get('_', ''):
print "This is dev - not Apache mod_wsgi"
</code></pre>
| 1 | 2012-10-03T10:04:27Z | [
"python",
"django",
"wsgi"
] |
How can I tell whether my Django application is running on development server or not? | 1,291,755 | <p>How can I be certain that my application is running on development server or not? I suppose I could check value of <code>settings.DEBUG</code> and assume if <code>DEBUG</code> is <code>True</code> then it's running on development server, but I'd prefer to know for sure than relying on convention.</p>
| 36 | 2009-08-18T04:10:26Z | 37,880,897 | <p>Usually this works:</p>
<pre><code>import sys
if 'runserver' in sys.argv:
# you use runserver
</code></pre>
| 1 | 2016-06-17T11:52:44Z | [
"python",
"django",
"wsgi"
] |
Django ImageField validation & PIL | 1,292,061 | <p>On sunday, I had problems with python modules, when I installed stackless
python. Now I have compiled and installed : </p>
<p>setuptools & python-mysqldb and i got my django project up and running
again. (i also reinstalled django-1.1), </p>
<p>Then I compiled and installed, jpeg, freetype2 and PIL. I also st... | 1 | 2009-08-18T05:59:17Z | 2,776,304 | <p>Might want to check out this blog post and see if it addresses your problem.</p>
<p><a href="http://www.chipx86.com/blog/2008/07/25/django-tips-pil-imagefield-and-unit-tests/" rel="nofollow">http://www.chipx86.com/blog/2008/07/25/django-tips-pil-imagefield-and-unit-tests/</a></p>
| 0 | 2010-05-05T19:52:13Z | [
"python",
"django",
"python-imaging-library",
"mod-wsgi",
"python-stackless"
] |
Is there a quick way to tell if an app is in Django's installed_apps? | 1,292,074 | <p>I'm writing a quick Django module and want to check for another module. Is there's a shortcut to check if another module is in the installed_apps list in Django's settings?</p>
| 1 | 2009-08-18T06:04:12Z | 1,292,103 | <pre><code>from settings import INSTALLED_APPS
if 'appname' in INSTALLED_APPS:
print 'we have app'
</code></pre>
<p>And this way is somewhat <a href="http://code.djangoproject.com/browser/django/trunk/django/db/models/loading.py?rev=10088#L55" rel="nofollow">how Django itself does</a>. Also check the <code>load_ap... | 4 | 2009-08-18T06:19:44Z | [
"python",
"django"
] |
Is it possible to filter on a related item in Django annotations? | 1,292,081 | <p>I have the following 2 models:</p>
<pre><code>class Job(models.Model):
title = models.CharField(_('title'), max_length=50)
description = models.TextField(_('description'))
category = models.ForeignKey(JobCategory, related_name='jobs')
created_date = models.DateTimeField(auto_now_add=True)
class Job... | 1 | 2009-08-18T06:09:56Z | 1,292,300 | <p>Just a guess... but would this work?</p>
<pre><code>def job_categories():
thritydaysago = datetime.datetime.now() - datetime.timedelta(days=30)
categories = JobCategory.objects.filter(job__created_date__gte=thritydaysago).annotate(num_postings=Count('jobs'))
return {'categories': categories}
</code></pr... | 4 | 2009-08-18T07:18:26Z | [
"python",
"django",
"annotations",
"django-queryset"
] |
Is it possible to filter on a related item in Django annotations? | 1,292,081 | <p>I have the following 2 models:</p>
<pre><code>class Job(models.Model):
title = models.CharField(_('title'), max_length=50)
description = models.TextField(_('description'))
category = models.ForeignKey(JobCategory, related_name='jobs')
created_date = models.DateTimeField(auto_now_add=True)
class Job... | 1 | 2009-08-18T06:09:56Z | 1,310,533 | <p>I decided to approach this differently and chose not to use annotations at all. I added a manager to the Job model that returned only active (30 days or less old) jobs, and created a property on the JobCategory model that queried for the instance's job count. My templatetag simply returned all categories. Here is th... | 0 | 2009-08-21T07:41:27Z | [
"python",
"django",
"annotations",
"django-queryset"
] |
google python data example: pizza party | 1,292,095 | <p>hey i started learning python and am quite confused as how the google data library works.
google has a pizza party example over at this <a href="http://code.google.com/p/gdata-python-client/wiki/WritingDataModelClasses" rel="nofollow">link</a></p>
<p>can anyone here please take the time to explain how it is being d... | 0 | 2009-08-18T06:17:00Z | 1,292,124 | <p>%s is a string placeholder, and % is the string interpolation operator. See the <a href="http://docs.python.org/library/stdtypes.html#string-formatting-operations" rel="nofollow">Python docs on string formatting</a> for more information.</p>
<p><a href="http://gdata-python-client.googlecode.com/svn/trunk/pydocs/ato... | 2 | 2009-08-18T06:27:23Z | [
"python",
"xml"
] |
google python data example: pizza party | 1,292,095 | <p>hey i started learning python and am quite confused as how the google data library works.
google has a pizza party example over at this <a href="http://code.google.com/p/gdata-python-client/wiki/WritingDataModelClasses" rel="nofollow">link</a></p>
<p>can anyone here please take the time to explain how it is being d... | 0 | 2009-08-18T06:17:00Z | 1,292,522 | <p>Given that this question is about Python and involves a pizza party, I'd say you were biting off more than you can chew ...</p>
<p>But seriously, if you're just learning Python, start with something simpler.</p>
| 0 | 2009-08-18T08:20:00Z | [
"python",
"xml"
] |
How does Python for loop work? | 1,292,189 | <p>I am used to the C++ way of for loops, but the Python loops have left me confused.</p>
<pre><code>for party in feed.entry:
print party.location.address.text
</code></pre>
<p>Here <code>party</code> in <code>feed.entry</code>. What does it signify and how does it actually work?</p>
| 4 | 2009-08-18T06:44:12Z | 1,292,205 | <p>feed.entry is something that allows iteration, and contains objects of some type. This is roughly similar to c++:</p>
<pre><code>for (feed::iterator party = feed.entry.begin(); party != feed.entry.end(); ++party) {
cout << (*party).location.address.text;
}
</code></pre>
| 5 | 2009-08-18T06:50:53Z | [
"python",
"for-loop"
] |
How does Python for loop work? | 1,292,189 | <p>I am used to the C++ way of for loops, but the Python loops have left me confused.</p>
<pre><code>for party in feed.entry:
print party.location.address.text
</code></pre>
<p>Here <code>party</code> in <code>feed.entry</code>. What does it signify and how does it actually work?</p>
| 4 | 2009-08-18T06:44:12Z | 1,292,214 | <p>feed.entry is property of feed and it's value is (if it's not, this code will fail) object implementing iteration protocol (array, for example) and has <strong>iter</strong> method, which returns iterator object</p>
<p>Iterator has next() method, returning next element or raising exception, so python for loop is ac... | 20 | 2009-08-18T06:53:46Z | [
"python",
"for-loop"
] |
How does Python for loop work? | 1,292,189 | <p>I am used to the C++ way of for loops, but the Python loops have left me confused.</p>
<pre><code>for party in feed.entry:
print party.location.address.text
</code></pre>
<p>Here <code>party</code> in <code>feed.entry</code>. What does it signify and how does it actually work?</p>
| 4 | 2009-08-18T06:44:12Z | 1,292,215 | <p><strong>party</strong> simply iterates over the list <strong>feed.entry</strong></p>
<p>Take a look at <a href="http://diveintopython-cached.muellerware.org/file%5Fhandling/for%5Floops.html">Dive into Python</a> explainations.</p>
| 5 | 2009-08-18T06:54:10Z | [
"python",
"for-loop"
] |
How does Python for loop work? | 1,292,189 | <p>I am used to the C++ way of for loops, but the Python loops have left me confused.</p>
<pre><code>for party in feed.entry:
print party.location.address.text
</code></pre>
<p>Here <code>party</code> in <code>feed.entry</code>. What does it signify and how does it actually work?</p>
| 4 | 2009-08-18T06:44:12Z | 1,292,309 | <p>In Python, <em>for</em> bucles aren't like the C/C++ ones, they're most like PHP's <em>foreach</em>. What you do isn't iterate like in a <em>while</em> with "(initialization; condition; increment)", it simply iterates over each element in a list (strings are ITERABLE like lists).</p>
<p>For example:</p>
<pre><code... | 3 | 2009-08-18T07:20:36Z | [
"python",
"for-loop"
] |
How does Python for loop work? | 1,292,189 | <p>I am used to the C++ way of for loops, but the Python loops have left me confused.</p>
<pre><code>for party in feed.entry:
print party.location.address.text
</code></pre>
<p>Here <code>party</code> in <code>feed.entry</code>. What does it signify and how does it actually work?</p>
| 4 | 2009-08-18T06:44:12Z | 1,292,388 | <p>To add my 0.05$ to the previous answers you might also want to take a look at the <a href="http://docs.python.org/library/functions.html#enumerate">enumerate builtin function</a></p>
<pre><code>for i, season in enumerate(['Spring', 'Summer', 'Fall', 'Winter']):
print i, season
0 Spring
1 Summer
2 Fall
3 Winter... | 5 | 2009-08-18T07:45:23Z | [
"python",
"for-loop"
] |
How does Python for loop work? | 1,292,189 | <p>I am used to the C++ way of for loops, but the Python loops have left me confused.</p>
<pre><code>for party in feed.entry:
print party.location.address.text
</code></pre>
<p>Here <code>party</code> in <code>feed.entry</code>. What does it signify and how does it actually work?</p>
| 4 | 2009-08-18T06:44:12Z | 1,292,952 | <p>Python's <code>for</code> loop works with <code>iterators</code>, which must implement the <code>iterator</code> protocol. For more details see:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/19151/build-a-basic-python-iterator/24377#24377">Build a Basic Python Iterator</a></li>
</ul>
| 0 | 2009-08-18T10:02:07Z | [
"python",
"for-loop"
] |
How does Python for loop work? | 1,292,189 | <p>I am used to the C++ way of for loops, but the Python loops have left me confused.</p>
<pre><code>for party in feed.entry:
print party.location.address.text
</code></pre>
<p>Here <code>party</code> in <code>feed.entry</code>. What does it signify and how does it actually work?</p>
| 4 | 2009-08-18T06:44:12Z | 19,322,006 | <p>I just wanted to provide a more generic explanation for people new to this.</p>
<p>Syntactically, the <code>for</code> loop looks like...</p>
<pre><code>for <name to be assigned to> in <some sequence>:
<block of code, optionally referencing the name>
</code></pre>
<p>The interpreter runs th... | 1 | 2013-10-11T15:35:23Z | [
"python",
"for-loop"
] |
How to open a file and find the longest length of a line and then print it out | 1,292,630 | <p>Here's is what I have done so far but the length function isn't working.</p>
<pre><code>import string
def main():
print " This program reads from a file and then prints out the"
print " line with the longest length the line ,or with the highest sum"
print " of ASCII values , or the line with the greate... | 1 | 2009-08-18T08:46:06Z | 1,292,665 | <p>Try this:</p>
<pre><code>def main():
print " This program reads from a file and then prints out the"
print " line with the longest length the line ,or with the highest sum"
print " of ASCII values , or the line with the greatest number of words"
length()
def length():
maxlength = 0
maxlinet... | 1 | 2009-08-18T08:52:55Z | [
"python"
] |
How to open a file and find the longest length of a line and then print it out | 1,292,630 | <p>Here's is what I have done so far but the length function isn't working.</p>
<pre><code>import string
def main():
print " This program reads from a file and then prints out the"
print " line with the longest length the line ,or with the highest sum"
print " of ASCII values , or the line with the greate... | 1 | 2009-08-18T08:46:06Z | 1,292,676 | <pre><code>large_line = ''
large_line_len = 0
filename = r"C:\tmp\TestFile.txt"
with open(filename, 'r') as f:
for line in f:
if len(line) > large_line_len:
large_line_len = len(line)
large_line = line
print large_line
</code></pre>
<p>output:</p>
<pre><code>This Should Be Lar... | 4 | 2009-08-18T08:55:54Z | [
"python"
] |
How to open a file and find the longest length of a line and then print it out | 1,292,630 | <p>Here's is what I have done so far but the length function isn't working.</p>
<pre><code>import string
def main():
print " This program reads from a file and then prints out the"
print " line with the longest length the line ,or with the highest sum"
print " of ASCII values , or the line with the greate... | 1 | 2009-08-18T08:46:06Z | 1,292,696 | <pre><code>linelength = lengthofline # bug?
</code></pre>
<p>It should be:</p>
<pre><code>linelength = len(line) # fix
</code></pre>
| 0 | 2009-08-18T08:58:49Z | [
"python"
] |
How to open a file and find the longest length of a line and then print it out | 1,292,630 | <p>Here's is what I have done so far but the length function isn't working.</p>
<pre><code>import string
def main():
print " This program reads from a file and then prints out the"
print " line with the longest length the line ,or with the highest sum"
print " of ASCII values , or the line with the greate... | 1 | 2009-08-18T08:46:06Z | 1,292,741 | <p>Python might not be the right tool for this job.</p>
<pre><code>$ awk 'length() > n { n = length(); x = $0 } END { print x }' 30075165.txt
</code></pre>
| 0 | 2009-08-18T09:06:53Z | [
"python"
] |
How to open a file and find the longest length of a line and then print it out | 1,292,630 | <p>Here's is what I have done so far but the length function isn't working.</p>
<pre><code>import string
def main():
print " This program reads from a file and then prints out the"
print " line with the longest length the line ,or with the highest sum"
print " of ASCII values , or the line with the greate... | 1 | 2009-08-18T08:46:06Z | 1,292,743 | <p>For Python 2.5 and up</p>
<pre><code>print max(open(your_filename, 'r'), key=len)
</code></pre>
| 19 | 2009-08-18T09:06:59Z | [
"python"
] |
How to open a file and find the longest length of a line and then print it out | 1,292,630 | <p>Here's is what I have done so far but the length function isn't working.</p>
<pre><code>import string
def main():
print " This program reads from a file and then prints out the"
print " line with the longest length the line ,or with the highest sum"
print " of ASCII values , or the line with the greate... | 1 | 2009-08-18T08:46:06Z | 1,292,751 | <p>My solution (also works in Python 2.5):</p>
<pre><code>import os.path
def getLongestLineFromFile(fileName):
longestLine = ""
if not os.path.exists(fileName):
raise "File not found"
file = open(fileName, "r")
for line in file:
if len(line) > len(longestLine):
longest... | 0 | 2009-08-18T09:07:45Z | [
"python"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 1,292,854 | <p>You likely want <a href="http://docs.python.org/library/urllib2.html" rel="nofollow">urllib2</a>. It can handle things like HTTPS, cookies, and authentication. You will probably also want <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> to help parse the HTML pages.</p>
| 0 | 2009-08-18T09:31:19Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 1,292,876 | <p>There are plenty of built in python modules that whould help with this. For example <a href="http://docs.python.org/library/urllib.html" rel="nofollow">urllib</a> and <a href="http://docs.python.org/library/htmllib.html" rel="nofollow">htmllib</a>.</p>
<p>The problem will be simpler if you change the way you're app... | 2 | 2009-08-18T09:38:11Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 1,292,892 | <p>You can also take a look at <a href="http://wwwsearch.sourceforge.net/mechanize/">mechanize</a>. Its meant to handle <em>"stateful programmatic web browsing"</em> (as per their site).</p>
| 13 | 2009-08-18T09:43:36Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 1,292,894 | <p>You may have a look at these slides from the <a href="http://www.pycon.it/static/stuff/slides/tecniche-di-scraping-in-python.pdf" rel="nofollow">last italian pycon</a> (pdf):
The author listed most of the library for doing scraping and autoted browsing in python. so you may have a look at it.</p>
<p>I like very muc... | 0 | 2009-08-18T09:44:37Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 1,293,086 | <p>Internet Explorer specific, but rather good:</p>
<p><a href="http://pamie.sourceforge.net/" rel="nofollow">http://pamie.sourceforge.net/</a></p>
<p>The advantage compared to urllib/BeautifulSoup is that it executes Javascript as well since it uses IE.</p>
| 0 | 2009-08-18T10:36:51Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 3,486,971 | <p>selenium will do exactly what you want and it handles javascript</p>
| 14 | 2010-08-15T10:19:57Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 3,988,708 | <p>httplib2 + beautifulsoup</p>
<p>Use firefox + firebug + httpreplay to see what the javascript passes to and from the browser from the website. Using httplib2 you can essentially do the same via post and get</p>
| 0 | 2010-10-21T14:45:39Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 6,295,138 | <p><a href="http://code.google.com/p/selenium/" rel="nofollow">Selenium2</a> includes webdriver, which has <a href="http://pypi.python.org/pypi/selenium/2.0rc2" rel="nofollow">python bindings</a> and allows one to use the headless htmlUnit driver, or switch to firefox or chrome for graphical debugging.</p>
| 1 | 2011-06-09T15:14:40Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 19,256,265 | <p>All answers are old, I recommend and I am a big fan of <a href="http://docs.python-requests.org/en/latest/" rel="nofollow">requests</a></p>
<p>From homepage:</p>
<blockquote>
<p>Pythonâs standard urllib2 module provides most of the HTTP
capabilities you need, but the API is thoroughly broken. It was built
... | 7 | 2013-10-08T19:11:27Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 19,666,844 | <p>I think the best solutions is the mix of <a href="http://www.python-requests.org/en/latest/">requests</a> and <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a>, I just wanted to update the question so it can be kept updated.</p>
| 6 | 2013-10-29T18:55:48Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 20,245,252 | <p>Selenium <a href="http://www.seleniumhq.org/" rel="nofollow">http://www.seleniumhq.org/</a> is the best solution for me. you can code it with python, java, or anything programming language you like with ease. and easy simulation that convert into program.</p>
| 2 | 2013-11-27T14:36:59Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 20,679,640 | <p>The best solution that i have found (and currently implementing) is :
- scripts in python using selenium webdriver
- PhantomJS headless browser (if firefox is used you will have a GUI and will be slower)</p>
| 1 | 2013-12-19T10:48:59Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 21,130,760 | <p>Do not forget <a href="https://pypi.python.org/pypi/zope.testbrowser" rel="nofollow">zope.testbrowser</a> which is wrapper around <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize</a> .</p>
<blockquote>
<p>zope.testbrowser provides an easy-to-use programmable web browser with special ... | 2 | 2014-01-15T06:46:06Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 27,397,694 | <p>HTMLUNIT is the package if you're a java developer.
<a href="http://htmlunit.sourceforge.net/apidocs/index.html" rel="nofollow">http://htmlunit.sourceforge.net/apidocs/index.html</a></p>
| 1 | 2014-12-10T09:43:08Z | [
"python",
"browser-automation"
] |
How to automate browsing using python? | 1,292,817 | <p>suppose, I need to perform a set of procedure on a particular website
say, fill some forms, click submit button, send the data back to server, receive the response, again do something based on the response and send the data back to the server of the website.
I know there is a webbrowser module in python, but I want ... | 17 | 2009-08-18T09:23:10Z | 28,440,512 | <p>I have found the <a href="https://addons.mozilla.org/en-US/firefox/addon/imacros-for-firefox/" rel="nofollow">iMacros Firefox plugin</a> (which is free) to work very well.</p>
<p>It can be automated with Python using Windows COM object interfaces. Here's some example code from <a href="http://wiki.imacros.net/Pytho... | 1 | 2015-02-10T19:48:20Z | [
"python",
"browser-automation"
] |
Renaming objects with Wing IDE | 1,292,931 | <p>I am just transitioning from Eclipse to Wing IDE for my Python code. In Eclipse I had an option to "rename" objects. I could take any object defined in my code, it could be a variable or a function or a method or whatever, and I could rename it automatically in all the files that referenced it.</p>
<p>Is there a si... | 3 | 2009-08-18T09:56:38Z | 1,293,438 | <p>The refactoruing is a feature asked for <a href="http://wingware.com/pipermail/wingide-users/2002-May/001102.html" rel="nofollow">since 2002</a>, but even then, the answer was already:</p>
<p>"<a href="http://www.wingware.com/doc/intro/tutorial-search" rel="nofollow">search and replace</a>"</p>
<blockquote>
<p>B... | 4 | 2009-08-18T12:05:26Z | [
"python",
"eclipse",
"ide"
] |
Renaming objects with Wing IDE | 1,292,931 | <p>I am just transitioning from Eclipse to Wing IDE for my Python code. In Eclipse I had an option to "rename" objects. I could take any object defined in my code, it could be a variable or a function or a method or whatever, and I could rename it automatically in all the files that referenced it.</p>
<p>Is there a si... | 3 | 2009-08-18T09:56:38Z | 5,147,647 | <p>WingIDE 4 now has support for refactoring.</p>
| 0 | 2011-02-28T21:14:01Z | [
"python",
"eclipse",
"ide"
] |
Display Django form inputs on thanks page | 1,292,951 | <p>I'm attempting to take 4-5 fields from a large django form and display them on the thanks page.</p>
<p>I want to disply the values with a good degree of control, as i'll be building an iFrame with parameterd querystrings based on the form inputs.</p>
<p>Currently I have:</p>
<p>forms.py ----</p>
<pre><code>-*- e... | 0 | 2009-08-18T10:02:02Z | 1,293,021 | <p>The values available to the template are provided by the view.</p>
<p>The <code>render_to_response</code> function provides a dictionary of values that are passed to the template. See <a href="http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render-to-response" rel="nofollow">this</a>.</p>
<p>For no go... | 0 | 2009-08-18T10:16:29Z | [
"python",
"django",
"forms"
] |
Display Django form inputs on thanks page | 1,292,951 | <p>I'm attempting to take 4-5 fields from a large django form and display them on the thanks page.</p>
<p>I want to disply the values with a good degree of control, as i'll be building an iFrame with parameterd querystrings based on the form inputs.</p>
<p>Currently I have:</p>
<p>forms.py ----</p>
<pre><code>-*- e... | 0 | 2009-08-18T10:02:02Z | 1,332,943 | <p>I'm not sure if I understand what you are trying to do.</p>
<p>But if you want to render form values in plain text you can try <a href="http://github.com/muhuk/django-renderformplain/tree/master" rel="nofollow">django-renderformplain</a>. Just initalize your form with POST (or GET) data as you would in any other fo... | 0 | 2009-08-26T07:30:28Z | [
"python",
"django",
"forms"
] |
Storing dynamically generated code as string or as code object? | 1,292,994 | <p>I'm hacking a little template engine. I've a class (pompously named the <em>template compiler</em>) that produce a string of dynamically generated code.</p>
<p>for instance :</p>
<pre><code>def dynamic_function(arg):
#statement
return rendered_template
</code></pre>
<p>At rendering time, I call the built-in f... | 0 | 2009-08-18T10:10:41Z | 1,293,039 | <p>Mako template library caches the compiled template as a python module and uses the built in <code>imp</code> module to handle byte-code caching and code loading. This seems reasonably robust to changes in the interpreter, fast and easily debuggable (you can view the source of the generated code in the cache).</p>
<... | 0 | 2009-08-18T10:22:21Z | [
"python",
"exec"
] |
Storing dynamically generated code as string or as code object? | 1,292,994 | <p>I'm hacking a little template engine. I've a class (pompously named the <em>template compiler</em>) that produce a string of dynamically generated code.</p>
<p>for instance :</p>
<pre><code>def dynamic_function(arg):
#statement
return rendered_template
</code></pre>
<p>At rendering time, I call the built-in f... | 0 | 2009-08-18T10:10:41Z | 1,293,107 | <p>You don't mention where you are going to store these templates, but if you are persisting them "permanently", keep in mind that Python doesn't guarantee byte-code compatibility across major versions. So either choose a method that does guarantee compatibility (like storing the source code), or also store enough inf... | 2 | 2009-08-18T10:42:21Z | [
"python",
"exec"
] |
Storing dynamically generated code as string or as code object? | 1,292,994 | <p>I'm hacking a little template engine. I've a class (pompously named the <em>template compiler</em>) that produce a string of dynamically generated code.</p>
<p>for instance :</p>
<pre><code>def dynamic_function(arg):
#statement
return rendered_template
</code></pre>
<p>At rendering time, I call the built-in f... | 0 | 2009-08-18T10:10:41Z | 1,293,209 | <p>Personally, i'd store text. You can look at text with an editor or whatever, which will make debugging and mucking about easier. It's also vastly easier to write unit tests for, if you want to test that the contents of the cache file are what you expect.</p>
<p>Later, <em>if</em> you find that your system isn't fa... | 1 | 2009-08-18T11:07:18Z | [
"python",
"exec"
] |
bulk insert in db table | 1,293,056 | <p>I'm having an array I want to insert in a single query in a table. Any idea?</p>
| -2 | 2009-08-18T10:26:36Z | 1,293,159 | <p>If you are using PostgreSQL, you can use the <a href="http://www.postgresql.org/docs/8.1/interactive/sql-copy.html" rel="nofollow">COPY statement</a>.</p>
| 0 | 2009-08-18T10:57:01Z | [
"python",
"database"
] |
bulk insert in db table | 1,293,056 | <p>I'm having an array I want to insert in a single query in a table. Any idea?</p>
| -2 | 2009-08-18T10:26:36Z | 1,293,223 | <p>If you are using dbapi to access the database, then the connection.executemany() method works.</p>
<pre><code>con.executemany("INSERT INTO some_table (field) VALUES (?)", [(v,) for v in your_array])
</code></pre>
<p>The format of the bindparameter depends on the database, sqlite uses ?, mysql uses %s, postgresl us... | 3 | 2009-08-18T11:11:13Z | [
"python",
"database"
] |
bulk insert in db table | 1,293,056 | <p>I'm having an array I want to insert in a single query in a table. Any idea?</p>
| -2 | 2009-08-18T10:26:36Z | 1,293,245 | <p>As uneffective (individual inserts) one-liner:</p>
<pre><code>data = [{'id': 1, 'x': 2, 'y': 4}, {'somethig': 'other', 'otherfield': 5, 'y': 6}]
table = 'table_name'
connection = connect() # DBAPI connection
map(connection.cursor().execute, ('INSERT INTO %s (%s) VALUES (%s)' % ('table', ','.join(x), ','.join(['%s'... | 1 | 2009-08-18T11:16:37Z | [
"python",
"database"
] |
Replace AppEngine Devserver With Spawning (BaseHTTPRequestHandler as WSGI) | 1,293,249 | <p>I'm looking to replace AppEngine's devserver with <a href="http://pypi.python.org/pypi/Spawning/0.8.10" rel="nofollow">spawning</a>. Spawning handles standard wsgi handlers, just like appengine, so running your app on it is easy.</p>
<p>But the devserver takes into account your app.yaml file that has url redirects ... | 1 | 2009-08-18T11:16:57Z | 1,366,653 | <p>I don't think you're going to be able to pull out a part of the dev_appserver and use it in a custom WSGI server quite so easily. The dev_appserver does a lot of 'magic', and it isn't really structured to be pulled out and used as a WSGI wrapper in another server (more's the pity).</p>
<p>You may want to check out ... | 2 | 2009-09-02T09:24:15Z | [
"python",
"google-app-engine",
"wsgi"
] |
How to convince my boss to use Django? | 1,293,361 | <p>I have an unusual problem: I have to convince my superiors to use Django for our new project. Alternative is some PHP framework. I've programmed in PHP for 2 years and then switched to Python and have about 3 years of experience in it. However I'm not too good in business speech. </p>
<p>I know all the technical pr... | 18 | 2009-08-18T11:47:10Z | 1,293,401 | <p>People like to see tangible results. <em>On your own time</em> implement a small portion of the project using Django that can demonstrate what you believe to be some of the advantages of switching the project to Django. Besides demonstrating technical advantages, it will demonstrate your commitment to the idea.</p... | 7 | 2009-08-18T11:57:46Z | [
"php",
"python",
"django"
] |
How to convince my boss to use Django? | 1,293,361 | <p>I have an unusual problem: I have to convince my superiors to use Django for our new project. Alternative is some PHP framework. I've programmed in PHP for 2 years and then switched to Python and have about 3 years of experience in it. However I'm not too good in business speech. </p>
<p>I know all the technical pr... | 18 | 2009-08-18T11:47:10Z | 1,293,405 | <p>Why do you <em>have</em> to convince your boss to use Django?</p>
<p>Your boss should understand that it's in his best interest to work in what the people he'll be employing know best. </p>
<p>But, how can you tell that Django is really the best suit all things considered? </p>
<p>For example:</p>
<ul>
<li>Are t... | 13 | 2009-08-18T11:58:26Z | [
"php",
"python",
"django"
] |
How to convince my boss to use Django? | 1,293,361 | <p>I have an unusual problem: I have to convince my superiors to use Django for our new project. Alternative is some PHP framework. I've programmed in PHP for 2 years and then switched to Python and have about 3 years of experience in it. However I'm not too good in business speech. </p>
<p>I know all the technical pr... | 18 | 2009-08-18T11:47:10Z | 1,293,450 | <p>You want to know how to convince a business person?</p>
<p>Two words: "<a href="http://blog.cusec.net/2009/01/05/zed-shaw-the-acl-is-dead-cusec-2008/" rel="nofollow">steaks and strippers</a>" (Zed Shaw).</p>
| 2 | 2009-08-18T12:08:32Z | [
"php",
"python",
"django"
] |
How to convince my boss to use Django? | 1,293,361 | <p>I have an unusual problem: I have to convince my superiors to use Django for our new project. Alternative is some PHP framework. I've programmed in PHP for 2 years and then switched to Python and have about 3 years of experience in it. However I'm not too good in business speech. </p>
<p>I know all the technical pr... | 18 | 2009-08-18T11:47:10Z | 1,293,588 | <p>If you have the possibility, you could create a prototype in Django.<br />
Your boss will see it, and will be able to measure the advantages. A good presentation in powerpoint with explained required effort, advantages, etc. may be also a way to increase the chances of success. </p>
<p>And, over all, make sure to ... | 2 | 2009-08-18T12:44:43Z | [
"php",
"python",
"django"
] |
How to convince my boss to use Django? | 1,293,361 | <p>I have an unusual problem: I have to convince my superiors to use Django for our new project. Alternative is some PHP framework. I've programmed in PHP for 2 years and then switched to Python and have about 3 years of experience in it. However I'm not too good in business speech. </p>
<p>I know all the technical pr... | 18 | 2009-08-18T11:47:10Z | 1,293,613 | <p>It would be unfair on your fellow programmers to move to django, if they happen to only know php.</p>
| 2 | 2009-08-18T12:49:37Z | [
"php",
"python",
"django"
] |
How to convince my boss to use Django? | 1,293,361 | <p>I have an unusual problem: I have to convince my superiors to use Django for our new project. Alternative is some PHP framework. I've programmed in PHP for 2 years and then switched to Python and have about 3 years of experience in it. However I'm not too good in business speech. </p>
<p>I know all the technical pr... | 18 | 2009-08-18T11:47:10Z | 1,293,893 | <p>The problem is your Boss who knows PHP but doesn't know Python. And I can imagine that he doesn't want to spend valuable time learning to become familiar with a new technique.</p>
<p>About 16 years ago, I've tried to convince my employer to use Delphi (then a new product) instead of some other RAD tools that he was... | 2 | 2009-08-18T13:35:27Z | [
"php",
"python",
"django"
] |
How to convince my boss to use Django? | 1,293,361 | <p>I have an unusual problem: I have to convince my superiors to use Django for our new project. Alternative is some PHP framework. I've programmed in PHP for 2 years and then switched to Python and have about 3 years of experience in it. However I'm not too good in business speech. </p>
<p>I know all the technical pr... | 18 | 2009-08-18T11:47:10Z | 1,293,964 | <p>Bottom line is what it is all about really. How much money does a move to python/django save the company overall in terms of dev effort, testing and support? </p>
<p>If you can demonstrate that python out performs php in these areas then its going to make a saving for the company. More savings means better profit m... | 1 | 2009-08-18T13:45:07Z | [
"php",
"python",
"django"
] |
How to convince my boss to use Django? | 1,293,361 | <p>I have an unusual problem: I have to convince my superiors to use Django for our new project. Alternative is some PHP framework. I've programmed in PHP for 2 years and then switched to Python and have about 3 years of experience in it. However I'm not too good in business speech. </p>
<p>I know all the technical pr... | 18 | 2009-08-18T11:47:10Z | 1,294,098 | <p>The best way to persuade people (coworkers, pointy-haired-bosses, peers, etc) is to help them reach their own conclusions by continually demonstrating your awesomeness.</p>
<p>Implement a cool prototype-demo of a cool technology on your own time, using the tools you want to use. Then show it off as a "check-out-wh... | 1 | 2009-08-18T14:02:29Z | [
"php",
"python",
"django"
] |
How to convince my boss to use Django? | 1,293,361 | <p>I have an unusual problem: I have to convince my superiors to use Django for our new project. Alternative is some PHP framework. I've programmed in PHP for 2 years and then switched to Python and have about 3 years of experience in it. However I'm not too good in business speech. </p>
<p>I know all the technical pr... | 18 | 2009-08-18T11:47:10Z | 1,297,544 | <p>I agree with the 'just hack out a demo' school. The beauty of Django is that you can set up a quick project with SQLite, define the models, and then instantly have a database API, a slick admin and databrowse to play with. If databrowse doesn't cut it, write just enough views to demonstrate django's benefits. </p>
... | 0 | 2009-08-19T02:28:15Z | [
"php",
"python",
"django"
] |
How to convince my boss to use Django? | 1,293,361 | <p>I have an unusual problem: I have to convince my superiors to use Django for our new project. Alternative is some PHP framework. I've programmed in PHP for 2 years and then switched to Python and have about 3 years of experience in it. However I'm not too good in business speech. </p>
<p>I know all the technical pr... | 18 | 2009-08-18T11:47:10Z | 1,298,877 | <p>You can check-out my <a href="http://www.flickr.com/photos/dibau%5Fnaum%5Fh/3501239850/sizes/o/" rel="nofollow">summary</a> from a talk on this subject by Justin Lilly, in last EuroDjangoCon.</p>
| 1 | 2009-08-19T09:57:23Z | [
"php",
"python",
"django"
] |
How to convince my boss to use Django? | 1,293,361 | <p>I have an unusual problem: I have to convince my superiors to use Django for our new project. Alternative is some PHP framework. I've programmed in PHP for 2 years and then switched to Python and have about 3 years of experience in it. However I'm not too good in business speech. </p>
<p>I know all the technical pr... | 18 | 2009-08-18T11:47:10Z | 1,310,879 | <p>Google uses Django with the <a href="http://en.wikipedia.org/wiki/Google%5FApp%5FEngine" rel="nofollow">App Engine</a>. And nobody ever
got fired for choosing Google...</p>
<p>Like:
"<a href="http://www.barrypopik.com/index.php/new%5Fyork%5Fcity/entry/no%5Fone%5Fever%5Fgot%5Ffired%5Ffor%5Fbuying%5Fibm%5Fmicrosoft%... | 1 | 2009-08-21T09:12:28Z | [
"php",
"python",
"django"
] |
How to find the sum of a ASCII value in a file to find the max number of ASCII and to print out the name of the highest sum of ASCII value | 1,293,404 | <p>Here is the code I'm working with</p>
<pre><code>def ascii_sum():
x = 0
infile = open("30075165.txt","r")
for line in infile:
return sum([ord(x) for x in line])
infile.close()
</code></pre>
<p>This code only prints out the first ASCII value in the file not the max ASCII value</p>
| -1 | 2009-08-18T11:58:13Z | 1,293,439 | <pre><code>max(open(fname), key=lambda line: sum(ord(i) for i in line))
</code></pre>
| 1 | 2009-08-18T12:05:40Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.