title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Model and Validation Confusion - Looking for advice
606,782
<p>I'm somewhat new to Python, Django, and I'd like some advice on how to layout the code I'd like to write.</p> <p>I have the model written that allows a file to be uploaded. In the models save method I'm checking if the file has a specific extension. If it has an XML extension I'm opening the file and grabbing some ...
0
2009-03-03T15:15:16Z
607,034
<p>I guess the best way would be to implement a special field class that extends <code>FileField</code> with custom validation of the uploaded file. </p> <p>The validation is implemented in the field's <code>clean</code> method. It should check the XML file and raise <code>ValidationError</code>s if it encounters erro...
1
2009-03-03T16:14:08Z
[ "python", "django", "validation" ]
Model and Validation Confusion - Looking for advice
606,782
<p>I'm somewhat new to Python, Django, and I'd like some advice on how to layout the code I'd like to write.</p> <p>I have the model written that allows a file to be uploaded. In the models save method I'm checking if the file has a specific extension. If it has an XML extension I'm opening the file and grabbing some ...
0
2009-03-03T15:15:16Z
607,586
<p>You can provide a form that will be used by the admin site. You can then perform validations in the form code that will be displayed in the admin area.</p> <p>See the docs on the admin site, and in particular <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#form" rel="nofollow">the form attribute of...
1
2009-03-03T18:34:30Z
[ "python", "django", "validation" ]
Model and Validation Confusion - Looking for advice
606,782
<p>I'm somewhat new to Python, Django, and I'd like some advice on how to layout the code I'd like to write.</p> <p>I have the model written that allows a file to be uploaded. In the models save method I'm checking if the file has a specific extension. If it has an XML extension I'm opening the file and grabbing some ...
0
2009-03-03T15:15:16Z
608,100
<p>"I'm throwing an custom "Exception" error " - Where exactly are you throwing the exception ? In your model or in your view ?</p> <p>I am confused with your question, so I am assuming that you should be asking 'Where should I catch input errors if any ? ' to yourself.</p> <p>The Model and View as I see are like pie...
0
2009-03-03T20:45:21Z
[ "python", "django", "validation" ]
Django Override form
606,946
<p>Another question on some forms</p> <p>Here is my model</p> <pre><code>class TankJournal(models.Model): user = models.ForeignKey(User) tank = models.ForeignKey(TankProfile) ts = models.IntegerField(max_length=15) title = models.CharField(max_length=50) body = models.TextField() </code></pre> <p...
2
2009-03-03T15:55:21Z
607,022
<p>Why are you overriding the definition of tank?</p> <pre><code>class JournalForm(ModelForm): tank = forms.IntegerField(widget=forms.HiddenInput()) </code></pre> <p>If you omit this override, Django handles the foreign key reference for you.</p> <p>"how can I override the form object to make tank a TankProfile?...
2
2009-03-03T16:11:01Z
[ "python", "django", "forms" ]
Django Override form
606,946
<p>Another question on some forms</p> <p>Here is my model</p> <pre><code>class TankJournal(models.Model): user = models.ForeignKey(User) tank = models.ForeignKey(TankProfile) ts = models.IntegerField(max_length=15) title = models.CharField(max_length=50) body = models.TextField() </code></pre> <p...
2
2009-03-03T15:55:21Z
607,051
<p>I think you want this:</p> <pre><code>class JournalForm(ModelForm): tank = forms.ModelChoiceField(label="", queryset=TankProfile.objects.all(), widget=forms.HiddenInput) </code></pre>
5
2009-03-03T16:17:01Z
[ "python", "django", "forms" ]
How does Python's "super" do the right thing?
607,186
<p>I'm running Python 2.5, so this question may not apply to Python 3. When you make a diamond class hierarchy using multiple inheritance and create an object of the derived-most class, Python does the Right Thing (TM). It calls the constructor for the derived-most class, then its parent classes as listed from left to ...
43
2009-03-03T16:45:37Z
607,287
<p>just guessing:</p> <p><code>self</code> in all the four methods refer to the same object, that is, of class <code>D</code>. so, in <code>B.__init__()</code>, the call to to <code>super(B,self)</code> knows the whole diamond ancestry of <code>self</code> and it has to fetch the method from 'after' <code>B</code>. in...
6
2009-03-03T17:14:45Z
[ "python", "constructor", "multiple-inheritance", "super", "python-2.5" ]
How does Python's "super" do the right thing?
607,186
<p>I'm running Python 2.5, so this question may not apply to Python 3. When you make a diamond class hierarchy using multiple inheritance and create an object of the derived-most class, Python does the Right Thing (TM). It calls the constructor for the derived-most class, then its parent classes as listed from left to ...
43
2009-03-03T16:45:37Z
607,298
<p>Change your code to this and I think it'll explain things (presumably <code>super</code> is looking at where, say, <code>B</code> is in the <code>__mro__</code>?):</p> <pre><code>class A(object): def __init__(self): print "A init" print self.__class__.__mro__ class B(A): def __init__(self):...
33
2009-03-03T17:17:53Z
[ "python", "constructor", "multiple-inheritance", "super", "python-2.5" ]
How does Python's "super" do the right thing?
607,186
<p>I'm running Python 2.5, so this question may not apply to Python 3. When you make a diamond class hierarchy using multiple inheritance and create an object of the derived-most class, Python does the Right Thing (TM). It calls the constructor for the derived-most class, then its parent classes as listed from left to ...
43
2009-03-03T16:45:37Z
607,448
<p>I have provided a bunch of links below, that answer your question in more detail and more precisely than I can ever hope to. I will however give an answer to your question in my own words as well, to save you some time. I'll put it in points -</p> <ol> <li>super is a builtin function, not an attribute.</li> <li>Eve...
14
2009-03-03T17:58:41Z
[ "python", "constructor", "multiple-inheritance", "super", "python-2.5" ]
How does Python's "super" do the right thing?
607,186
<p>I'm running Python 2.5, so this question may not apply to Python 3. When you make a diamond class hierarchy using multiple inheritance and create an object of the derived-most class, Python does the Right Thing (TM). It calls the constructor for the derived-most class, then its parent classes as listed from left to ...
43
2009-03-03T16:45:37Z
13,941,387
<p><code>super()</code> knows the <strong>full</strong> class hierarchy. This is what happens inside B's init:</p> <pre><code>&gt;&gt;&gt; super(B, self) &lt;super: &lt;class 'B'&gt;, &lt;D object&gt;&gt; </code></pre> <p>This resolves the central question,</p> <blockquote> <p>how does the object returned by supe...
3
2012-12-18T20:57:49Z
[ "python", "constructor", "multiple-inheritance", "super", "python-2.5" ]
Preserving last new line when reading a file
607,375
<p>I´m reading a file in Python where each record is separated by an empty new line. If the file ends in two or more new lines, the last record is processed as expected, but if the file ends in a single new line it´s not processed. Here´s the code:</p> <pre><code>def fread(): record = False for line in open...
2
2009-03-03T17:38:44Z
607,432
<p>line.strip() will result in an empty string on an empty line. An empty string is False, so you swallow the empty line</p> <pre><code>&gt;&gt;&gt; bool("\n".strip()) False &gt;&gt;&gt; bool("\n") True </code></pre>
0
2009-03-03T17:56:02Z
[ "python", "file" ]
Preserving last new line when reading a file
607,375
<p>I´m reading a file in Python where each record is separated by an empty new line. If the file ends in two or more new lines, the last record is processed as expected, but if the file ends in a single new line it´s not processed. Here´s the code:</p> <pre><code>def fread(): record = False for line in open...
2
2009-03-03T17:38:44Z
607,444
<p>If you call <code>readline</code> repeatedly (in a loop) on your file object (instead of using <code>in</code>) it should work as you expect. Compare these:</p> <pre><code>&gt;&gt;&gt; x = open('/tmp/xyz') &gt;&gt;&gt; x.readline() 'x\n' &gt;&gt;&gt; x.readline() '\n' &gt;&gt;&gt; x.readline() 'y\n' &gt;&gt;&gt; x...
0
2009-03-03T17:58:16Z
[ "python", "file" ]
Preserving last new line when reading a file
607,375
<p>I´m reading a file in Python where each record is separated by an empty new line. If the file ends in two or more new lines, the last record is processed as expected, but if the file ends in a single new line it´s not processed. Here´s the code:</p> <pre><code>def fread(): record = False for line in open...
2
2009-03-03T17:38:44Z
607,508
<p>You might find a slight twist in a more classically pythonic direction improves the predicability of the code:</p> <pre><code>def fread(): for line in open('text.txt'): if line.strip(): d = SomeObject() yield d raise StopIteration for record in fread(): print record </c...
5
2009-03-03T18:14:17Z
[ "python", "file" ]
Preserving last new line when reading a file
607,375
<p>I´m reading a file in Python where each record is separated by an empty new line. If the file ends in two or more new lines, the last record is processed as expected, but if the file ends in a single new line it´s not processed. Here´s the code:</p> <pre><code>def fread(): record = False for line in open...
2
2009-03-03T17:38:44Z
607,515
<p>The way it's written now probably doesn't work anyway; with <code>d = SomeObject()</code> inside your loop, a new SomeObject is being created for every line. Yet, if I understand correctly, what you want is for all of the lines in between empty lines to contribute to that one object. You could do something like th...
6
2009-03-03T18:16:43Z
[ "python", "file" ]
Preserving last new line when reading a file
607,375
<p>I´m reading a file in Python where each record is separated by an empty new line. If the file ends in two or more new lines, the last record is processed as expected, but if the file ends in a single new line it´s not processed. Here´s the code:</p> <pre><code>def fread(): record = False for line in open...
2
2009-03-03T17:38:44Z
607,565
<p>replace <code>open('somefile.txt'):</code> with <code>open('somefile.txt').read().split('\n'):</code> and your code will work. <br><br> But Jarret Hardie's answer is better.</p>
0
2009-03-03T18:28:41Z
[ "python", "file" ]
Integrate postfix mail into my (python)webapp
607,548
<p>I have a postfix server listening and receiving all emails received at mywebsite.com Now I want to show these postfix emails in a customized interface and that too for each user</p> <p>To be clear, all the users of mywebsite.com will be given mail addresses like someguy@mywebsite.com who receives email on my produc...
4
2009-03-03T18:23:31Z
607,588
<p>I'm not sure that I understand the question.</p> <p>If you want your remote web application to be able to view users' mailbox, you could install a pop or imap server and use a mail client (you should be able to find one off the shelf) to read the emails. Alternatively, you could write something to interrogate the ...
0
2009-03-03T18:35:07Z
[ "python", "email", "message", "postfix-mta" ]
Integrate postfix mail into my (python)webapp
607,548
<p>I have a postfix server listening and receiving all emails received at mywebsite.com Now I want to show these postfix emails in a customized interface and that too for each user</p> <p>To be clear, all the users of mywebsite.com will be given mail addresses like someguy@mywebsite.com who receives email on my produc...
4
2009-03-03T18:23:31Z
607,622
<p>You want to have postfix deliver to a local mailbox, and then use a webmail system for people to access that stored mail.</p> <p>Don't get hung up on postfix - it just a transfer agent - it takes messages from one place, and puts them somewhere else, it doesn't store messages. So postfix will take the messages over...
9
2009-03-03T18:50:21Z
[ "python", "email", "message", "postfix-mta" ]
Integrate postfix mail into my (python)webapp
607,548
<p>I have a postfix server listening and receiving all emails received at mywebsite.com Now I want to show these postfix emails in a customized interface and that too for each user</p> <p>To be clear, all the users of mywebsite.com will be given mail addresses like someguy@mywebsite.com who receives email on my produc...
4
2009-03-03T18:23:31Z
607,741
<p>First of all, Postfix mail routing rules can be very complex and your presumably preferred solution involves a lot of trickery in the wrong places. You do not want to accidentally show some user anothers mails, do you? Second, although Postfix can do almost anything, it shouldn't as it only is a MDA (mail delivery a...
7
2009-03-03T19:17:57Z
[ "python", "email", "message", "postfix-mta" ]
Python parsing
607,760
<p>I'm trying to parse the title tag in an RSS 2.0 feed into three different variables for each entry in that feed. Using ElementTree I've already parsed the RSS so that I can print each title [minus the trailing <code>)</code>] with the code below:</p> <blockquote> <pre><code>feed = getfeed("http://www.tourfilter.co...
4
2009-03-03T19:25:17Z
607,803
<p>Don't let regex scare you off... it's well worth learning.</p> <p>Given the examples above, you might try putting the trailing parenthesis back in, and then using this pattern:</p> <pre><code>import re pat = re.compile('([\w\s]+)\(([\w\s]+)(\d+/\d+)\)') info = pat.match(s) print info.groups() ('Michael Schenker G...
16
2009-03-03T19:35:41Z
[ "python", "regex", "parsing", "text-parsing" ]
Python parsing
607,760
<p>I'm trying to parse the title tag in an RSS 2.0 feed into three different variables for each entry in that feed. Using ElementTree I've already parsed the RSS so that I can print each title [minus the trailing <code>)</code>] with the code below:</p> <blockquote> <pre><code>feed = getfeed("http://www.tourfilter.co...
4
2009-03-03T19:25:17Z
607,804
<p>Regular expressions are a great solution to this problem:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; s = 'Michael Schenker Group (House of Blues Dallas 3/26' &gt;&gt;&gt; re.match(r'(.*) \((.*) (\d+/\d+)', s).groups() ('Michael Schenker Group', 'House of Blues Dallas', '3/26') </code></pre> <p>As a side n...
7
2009-03-03T19:35:51Z
[ "python", "regex", "parsing", "text-parsing" ]
Python parsing
607,760
<p>I'm trying to parse the title tag in an RSS 2.0 feed into three different variables for each entry in that feed. Using ElementTree I've already parsed the RSS so that I can print each title [minus the trailing <code>)</code>] with the code below:</p> <blockquote> <pre><code>feed = getfeed("http://www.tourfilter.co...
4
2009-03-03T19:25:17Z
607,997
<p>Regarding the <code>repr(item.title[0:-1])</code> part, not sure where you got that from but I'm pretty sure you can simply use <code>item.title</code>. All you're doing is removing the last char from the string and then calling <code>repr()</code> on it, which does nothing.</p> <p>Your code should look something l...
0
2009-03-03T20:22:36Z
[ "python", "regex", "parsing", "text-parsing" ]
Django email
607,819
<p>I am using the Gmail SMTP server to send out emails from users of my website.</p> <p>These are the default settings in my settings.py</p> <pre><code>EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = 'example@example.com' EMAIL_HOST_PASSWORD = 'pwd' EMAIL_PORT = 587 EMAIL_USE_TLS = True SERVER_EMAIL = EMAIL_HOST_USER...
11
2009-03-03T19:40:23Z
608,218
<p>Django only uses <strong>settings.DEFAULT_FROM_EMAIL</strong> when any of the mail sending functions pass <code>None</code> or empty string as the <em>sender address</em>. This can be verified in <code>django/core/mail.py</code>.</p> <p>When there is an unhandled exception Django calls the <code>mail_admins()</cod...
21
2009-03-03T21:15:14Z
[ "python", "django", "email", "django-email" ]
What will I lose or gain from switching database APIs? (from pywin32 and pysqlite to QSql)
608,098
<p>I am writing a Python (2.5) GUI Application that does the following:</p> <ul> <li>Imports from Access to an Sqlite database </li> <li>Saves ui form settings to an Sqlite database</li> </ul> <p>Currently I am using pywin32 to read Access, and pysqlite2/dbapi2 to read/write Sqlite.</p> <p>However, certain Qt object...
1
2009-03-03T20:45:14Z
608,262
<p>When dealing with databases and PyQt UIs, I'll use something similar to model-view-controller model to help organize and simplify the code. </p> <p><strong>View module</strong></p> <ul> <li>uses/holds any QObjects that are necessary for the UI </li> <li>contain simple functions/methods for updating your QTG...
1
2009-03-03T21:22:54Z
[ "python", "qt", "sqlite", "pyqt4", "pywin32" ]
is there COMMIT analog in python for writing into a file?
608,316
<p>I have a file open for writing, and a process running for days -- something is written into the file in relatively random moments. My understanding is -- until I do file.close() -- there is a chance nothing is really saved to disk. Is that true?</p> <p>What if the system crashes when the main process is not finishe...
5
2009-03-03T21:33:02Z
608,322
<p>You should be able to use <code>file.flush()</code> to do this.</p>
15
2009-03-03T21:34:57Z
[ "python", "file-io", "commit", "buffering" ]
is there COMMIT analog in python for writing into a file?
608,316
<p>I have a file open for writing, and a process running for days -- something is written into the file in relatively random moments. My understanding is -- until I do file.close() -- there is a chance nothing is really saved to disk. Is that true?</p> <p>What if the system crashes when the main process is not finishe...
5
2009-03-03T21:33:02Z
608,373
<p>If you don't want to kill the current process to add <code>f.flush()</code> (it sounds like it's been running for days already?), you should be OK. If you see the file you are writing to getting bigger, you will not lose that data...</p> <p>From Python docs:</p> <blockquote> <p><strong>write(str)</strong> ...
3
2009-03-03T21:51:08Z
[ "python", "file-io", "commit", "buffering" ]
is there COMMIT analog in python for writing into a file?
608,316
<p>I have a file open for writing, and a process running for days -- something is written into the file in relatively random moments. My understanding is -- until I do file.close() -- there is a chance nothing is really saved to disk. Is that true?</p> <p>What if the system crashes when the main process is not finishe...
5
2009-03-03T21:33:02Z
608,518
<p>To make sure that you're data is written to disk, use <code>file.flush()</code> followed by <code>os.fsync(file.fileno())</code>.</p>
1
2009-03-03T22:34:33Z
[ "python", "file-io", "commit", "buffering" ]
is there COMMIT analog in python for writing into a file?
608,316
<p>I have a file open for writing, and a process running for days -- something is written into the file in relatively random moments. My understanding is -- until I do file.close() -- there is a chance nothing is really saved to disk. Is that true?</p> <p>What if the system crashes when the main process is not finishe...
5
2009-03-03T21:33:02Z
609,465
<p>As has already been stated use the .flush() method to force the write out of the buffer, but avoid using a lot of calls to flush as this can actually slow your writing down (if the application relies on fast writes) as you'll be forcing your filesystem to write changes that are smaller than it's buffer size which ca...
2
2009-03-04T06:41:06Z
[ "python", "file-io", "commit", "buffering" ]
Python port binding
608,558
<p>I've recently been learning python and I just started playing with networking using python's <code>socket</code> library. Everything has been going well until recently when my script terminated without closing the connection. The next time I ran the script, I got:</p> <pre><code>File "./alert_server.py", line 9, in...
5
2009-03-03T22:46:08Z
608,589
<p>What you want to do is just before the <code>bind</code>, do:</p> <pre><code>s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) </code></pre> <p>The reason you are seeing the behaviour you are is that the OS is reserving that particular port for some time after the last connection terminated. This is so that ...
13
2009-03-03T22:55:10Z
[ "python" ]
Monitoring user idle time
608,710
<p>Developing a mac app, how can I tell whether the user is currently at their computer or not? Or how long ago they last pressed a key or moved the mouse?</p>
3
2009-03-03T23:41:47Z
608,833
<p>You can use Quartz event taps and an NSTimer. Any time one of your event taps lights up, postpone the timer by setting its fire date. When the timer fires, the user is idle.</p> <p>I'm not sure whether Quartz event taps are exposed to Python, though. The drawing APIs are, but I'm not sure about event taps.</p>
0
2009-03-04T00:36:22Z
[ "python", "cocoa", "osx", "idle-processing" ]
Monitoring user idle time
608,710
<p>Developing a mac app, how can I tell whether the user is currently at their computer or not? Or how long ago they last pressed a key or moved the mouse?</p>
3
2009-03-03T23:41:47Z
608,955
<p>it turns out the answer was here</p> <p><a href="http://osdir.com/ml/python.pyobjc.devel/2006-09/msg00013.html" rel="nofollow">http://osdir.com/ml/python.pyobjc.devel/2006-09/msg00013.html</a></p>
1
2009-03-04T01:40:48Z
[ "python", "cocoa", "osx", "idle-processing" ]
django- run a script from admin
608,789
<p>I would like to write a script that is not activated by a certain URL, but by clicking on a link from the admin interface. How do I do this? Thanks!</p>
4
2009-03-04T00:17:13Z
608,823
<p>But a link has to go to a URL, so I think what you mean is you want to have a view function that is only visible in the admin interface, and that view function runs a script?</p> <p>If so, override <code>admin/base_site.html</code> template with something this simple:</p> <pre><code>{% extends "admin/base.html" %}...
10
2009-03-04T00:31:24Z
[ "python", "django" ]
Getting the name of the active window
608,809
<p>I want to write a python script on Windows that saves the title of the program that the user uses at a given time like the <a href="http://www.rescuetime.com">http://www.rescuetime.com</a> . I don't want to use rescuetime because of privacy consideration but instead write a script that does something similar myself ...
5
2009-03-04T00:24:57Z
608,814
<p><a href="http://www.daniweb.com/forums/thread134111.html">From daniweb</a></p> <pre><code> import win32gui w=win32gui w.GetWindowText (w.GetForegroundWindow()) </code></pre>
7
2009-03-04T00:27:40Z
[ "python", "windows" ]
python PIL install on shared hosting
608,854
<p>I'm going to deploy a django app on a shared hosting provider. I installed my own python in my home, it works fine. My promblem comes with the installation of PIL, i have no support for JPEG after the compile process.</p> <p>I know that the compiler dont find "libjpeg", so i tried to install it at my home, i downlo...
2
2009-03-04T00:50:22Z
608,988
<p>Does the machine actually have libjpeg available on it?</p> <p>Look for /usr/lib/libjpeg.so, and /usr/include/jpeglib.h; they may possibly be in a different lib and include directory. If you can't find them you'll have to also download and compile libjpeg into your home (typically prefix ~/.local).</p> <p>Then you...
2
2009-03-04T01:56:50Z
[ "python", "compilation", "python-imaging-library" ]
python PIL install on shared hosting
608,854
<p>I'm going to deploy a django app on a shared hosting provider. I installed my own python in my home, it works fine. My promblem comes with the installation of PIL, i have no support for JPEG after the compile process.</p> <p>I know that the compiler dont find "libjpeg", so i tried to install it at my home, i downlo...
2
2009-03-04T00:50:22Z
614,073
<p>I'm not sure where your problem comes from,</p> <p>you can use PIL without compiling anything! just drop the folder in a place that's in PYTHONPATH, and you're all set. </p>
-1
2009-03-05T09:21:23Z
[ "python", "compilation", "python-imaging-library" ]
Excluding a top-level directory from a setuptools package
608,855
<p>I'm trying to put a Python project into a tarball using setuptools. The problem is that setuptools doesn't appear to like the way that the source tree was originally setup (not by me, I must add). Everything that I actually want to distribute is in the top-level directory, rather than in a subdirectory like the se...
7
2009-03-04T00:50:23Z
609,067
<p>Ug, setuptools makes this really tricky :(</p> <p>I don't know if this is what you want, but one project I work on uses a combination of two things:</p> <pre><code>from setuptools import setup, find_packages ... packages = find_packages(exclude=['tests']), data_files = os.walk(path_to_files), </code></pre>
3
2009-03-04T02:41:14Z
[ "python", "setuptools" ]
Excluding a top-level directory from a setuptools package
608,855
<p>I'm trying to put a Python project into a tarball using setuptools. The problem is that setuptools doesn't appear to like the way that the source tree was originally setup (not by me, I must add). Everything that I actually want to distribute is in the top-level directory, rather than in a subdirectory like the se...
7
2009-03-04T00:50:23Z
1,000,702
<p>For similar purpose, my collegue wrote setuptools-dummy package: <a href="http://github.com/ella/setuptools-dummy/tree/master" rel="nofollow">http://github.com/ella/setuptools-dummy/tree/master</a></p> <p>Take a look at setuptools_dummy, modify excludes to your needs and it should work. If not, open an issue ;)</p>...
0
2009-06-16T10:33:39Z
[ "python", "setuptools" ]
Excluding a top-level directory from a setuptools package
608,855
<p>I'm trying to put a Python project into a tarball using setuptools. The problem is that setuptools doesn't appear to like the way that the source tree was originally setup (not by me, I must add). Everything that I actually want to distribute is in the top-level directory, rather than in a subdirectory like the se...
7
2009-03-04T00:50:23Z
9,769,754
<p>We use the following convention to exclude 'tests' from packages.</p> <pre><code>setup( name="project", packages=find_packages(exclude=("tests",)), include_package_data=True, test_suite='nose.collector', ) </code></pre> <p>We also use MANIFEST.in to better control what 'include_package_data=True' does...
5
2012-03-19T11:59:20Z
[ "python", "setuptools" ]
Excluding a top-level directory from a setuptools package
608,855
<p>I'm trying to put a Python project into a tarball using setuptools. The problem is that setuptools doesn't appear to like the way that the source tree was originally setup (not by me, I must add). Everything that I actually want to distribute is in the top-level directory, rather than in a subdirectory like the se...
7
2009-03-04T00:50:23Z
28,267,311
<p>I have the following in my <code>setup.py</code>...</p> <pre><code>setup(name='pyfoo', version="1.0.2", description='Example for stack overflow', url='http://stackoverflow.com/', author='David Michael Pennington', author_email='mike /|at|\ pennington.net', license='GPL', pl...
0
2015-02-01T20:11:07Z
[ "python", "setuptools" ]
Excluding a top-level directory from a setuptools package
608,855
<p>I'm trying to put a Python project into a tarball using setuptools. The problem is that setuptools doesn't appear to like the way that the source tree was originally setup (not by me, I must add). Everything that I actually want to distribute is in the top-level directory, rather than in a subdirectory like the se...
7
2009-03-04T00:50:23Z
32,726,439
<p>This is what I found in <a href="https://pythonhosted.org/setuptools/setuptools.html#using-find-packages" rel="nofollow">setuptools manual</a>:</p> <pre><code>from setuptools import setup, find_packages ... packages = find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), </code></pre> <p>In my case ...
1
2015-09-22T20:38:46Z
[ "python", "setuptools" ]
Creating lists using yield in Ruby and Python
608,951
<p>I'm trying to come up with an elegant way of creating a list from a function that yields values in both Python and Ruby.</p> <p>In Python:</p> <pre><code>def foo(x): for i in range(x): if bar(i): yield i result = list(foo(100)) </code></pre> <p>In Ruby:</p> <pre><code>def foo(x) x.times {|i| yield...
3
2009-03-04T01:39:33Z
608,965
<p>I know it's not exactly what you were looking for, but a more elegant way to express your example in ruby is:</p> <pre><code>result = Array.new(100) {|x| x*x} </code></pre>
1
2009-03-04T01:46:43Z
[ "python", "ruby", "list", "yield" ]
Creating lists using yield in Ruby and Python
608,951
<p>I'm trying to come up with an elegant way of creating a list from a function that yields values in both Python and Ruby.</p> <p>In Python:</p> <pre><code>def foo(x): for i in range(x): if bar(i): yield i result = list(foo(100)) </code></pre> <p>In Ruby:</p> <pre><code>def foo(x) x.times {|i| yield...
3
2009-03-04T01:39:33Z
608,966
<pre><code>def squares(x) (0..x).map { |i| i * i } end </code></pre> <p>Anything involving a range of values is best handled with, well, a range, rather than <code>times</code> and array generation.</p>
1
2009-03-04T01:47:00Z
[ "python", "ruby", "list", "yield" ]
Creating lists using yield in Ruby and Python
608,951
<p>I'm trying to come up with an elegant way of creating a list from a function that yields values in both Python and Ruby.</p> <p>In Python:</p> <pre><code>def foo(x): for i in range(x): if bar(i): yield i result = list(foo(100)) </code></pre> <p>In Ruby:</p> <pre><code>def foo(x) x.times {|i| yield...
3
2009-03-04T01:39:33Z
609,059
<p>So, for your new example, try this:</p> <pre><code>def foo(x) (0..x).select { |i| bar(i) } end </code></pre> <p>Basically, unless you're writing an iterator of your own, you don't need <code>yield</code> very often in Ruby. You'll probably do a lot better if you stop trying to write Python idioms using Ruby syn...
10
2009-03-04T02:34:45Z
[ "python", "ruby", "list", "yield" ]
Creating lists using yield in Ruby and Python
608,951
<p>I'm trying to come up with an elegant way of creating a list from a function that yields values in both Python and Ruby.</p> <p>In Python:</p> <pre><code>def foo(x): for i in range(x): if bar(i): yield i result = list(foo(100)) </code></pre> <p>In Ruby:</p> <pre><code>def foo(x) x.times {|i| yield...
3
2009-03-04T01:39:33Z
609,077
<p>For the Python version I would use a generator expression like:</p> <pre><code>(i for i in range(x) if bar(i)) </code></pre> <p>Or for this specific case of filtering values, even more simply</p> <pre><code>itertools.ifilter(bar,range(x)) </code></pre>
7
2009-03-04T02:53:40Z
[ "python", "ruby", "list", "yield" ]
Creating lists using yield in Ruby and Python
608,951
<p>I'm trying to come up with an elegant way of creating a list from a function that yields values in both Python and Ruby.</p> <p>In Python:</p> <pre><code>def foo(x): for i in range(x): if bar(i): yield i result = list(foo(100)) </code></pre> <p>In Ruby:</p> <pre><code>def foo(x) x.times {|i| yield...
3
2009-03-04T01:39:33Z
610,782
<p>For the Python list comprehension version posted by stbuton use <a href="http://docs.python.org/library/functions.html#xrange" rel="nofollow">xrange</a> instead of range if you want a generator. range will create the entire list in memory.</p>
1
2009-03-04T14:21:07Z
[ "python", "ruby", "list", "yield" ]
Creating lists using yield in Ruby and Python
608,951
<p>I'm trying to come up with an elegant way of creating a list from a function that yields values in both Python and Ruby.</p> <p>In Python:</p> <pre><code>def foo(x): for i in range(x): if bar(i): yield i result = list(foo(100)) </code></pre> <p>In Ruby:</p> <pre><code>def foo(x) x.times {|i| yield...
3
2009-03-04T01:39:33Z
610,840
<p><code>yield</code> means different things ruby and python. In ruby, you have to specify a callback block if I remember correctly, whereas generators in python can be passed around and yield to whoever holds them.</p>
1
2009-03-04T14:34:17Z
[ "python", "ruby", "list", "yield" ]
Creating lists using yield in Ruby and Python
608,951
<p>I'm trying to come up with an elegant way of creating a list from a function that yields values in both Python and Ruby.</p> <p>In Python:</p> <pre><code>def foo(x): for i in range(x): if bar(i): yield i result = list(foo(100)) </code></pre> <p>In Ruby:</p> <pre><code>def foo(x) x.times {|i| yield...
3
2009-03-04T01:39:33Z
3,781,210
<p>The exact equivalent of your Python code (using Ruby Generators) would be:</p> <pre><code>def foo(x) Enumerator.new do |yielder| (0..x).each { |v| yielder.yield(v) if bar(v) } end end result = Array(foo(100)) </code></pre> <p>In the above, the list is lazily generated (just as in the Python exampl...
5
2010-09-23T17:58:46Z
[ "python", "ruby", "list", "yield" ]
Is there anything that cannot appear inside parentheses?
609,169
<p>I was intrigued by <a href="http://stackoverflow.com/questions/542929/highlighting-unmatched-brackets-in-vim/543881#543881">this answer</a> to my question about <a href="http://stackoverflow.com/questions/542929/highlighting-unmatched-brackets-in-vim">getting vim to highlight unmatched brackets</a> in python code. ...
1
2009-03-04T03:58:35Z
609,176
<p>I'm not sure what are you trying to do, but how about "def" or "class"?</p> <p>this snippet is valid when it's not inside parenthesis</p> <pre><code>class dummy: pass </code></pre>
0
2009-03-04T04:03:26Z
[ "python", "vim", "syntax", "syntax-highlighting" ]
Is there anything that cannot appear inside parentheses?
609,169
<p>I was intrigued by <a href="http://stackoverflow.com/questions/542929/highlighting-unmatched-brackets-in-vim/543881#543881">this answer</a> to my question about <a href="http://stackoverflow.com/questions/542929/highlighting-unmatched-brackets-in-vim">getting vim to highlight unmatched brackets</a> in python code. ...
1
2009-03-04T03:58:35Z
609,675
<p>Any Python statement (import, if, for, while, def, class etc.) cannot be in the parentheses:</p> <pre><code>In [1]: (import sys) ------------------------------------------------------------ File "&lt;ipython console&gt;", line 1 (import sys) ^ &lt;type 'exceptions.SyntaxError'&gt;: invalid syntax </code></...
5
2009-03-04T08:17:45Z
[ "python", "vim", "syntax", "syntax-highlighting" ]
Is there anything that cannot appear inside parentheses?
609,169
<p>I was intrigued by <a href="http://stackoverflow.com/questions/542929/highlighting-unmatched-brackets-in-vim/543881#543881">this answer</a> to my question about <a href="http://stackoverflow.com/questions/542929/highlighting-unmatched-brackets-in-vim">getting vim to highlight unmatched brackets</a> in python code. ...
1
2009-03-04T03:58:35Z
609,731
<p>Here's an exact answer:</p> <ul> <li><a href="http://docs.python.org/reference/expressions.html#grammar-token-expression%5Flist" rel="nofollow">http://docs.python.org/reference/expressions.html#grammar-token-expression_list</a></li> <li><a href="http://docs.python.org/reference/compound%5Fstmts.html#function" rel="...
4
2009-03-04T08:42:09Z
[ "python", "vim", "syntax", "syntax-highlighting" ]
How can I stop IDLE from printing giant lists?
609,190
<p>Sometimes I'll be working with, say, a list of thousands of items in IDLE, and accidently print it out to the shell. When this happens, it crashes or at least very significaly slows down IDLE. As you can imagine, this is extremely inconvenient. Is there a way to make it, rather than printing the entire thing, just g...
1
2009-03-04T04:10:12Z
609,670
<p>Use <a href="http://ipython.scipy.org/moin/FrontPage" rel="nofollow">IPython</a> as shell instead. </p>
0
2009-03-04T08:14:28Z
[ "python", "ide", "editor", "python-idle" ]
How can I stop IDLE from printing giant lists?
609,190
<p>Sometimes I'll be working with, say, a list of thousands of items in IDLE, and accidently print it out to the shell. When this happens, it crashes or at least very significaly slows down IDLE. As you can imagine, this is extremely inconvenient. Is there a way to make it, rather than printing the entire thing, just g...
1
2009-03-04T04:10:12Z
612,104
<p>You could use custom print function.</p>
0
2009-03-04T19:37:20Z
[ "python", "ide", "editor", "python-idle" ]
How can I stop IDLE from printing giant lists?
609,190
<p>Sometimes I'll be working with, say, a list of thousands of items in IDLE, and accidently print it out to the shell. When this happens, it crashes or at least very significaly slows down IDLE. As you can imagine, this is extremely inconvenient. Is there a way to make it, rather than printing the entire thing, just g...
1
2009-03-04T04:10:12Z
636,913
<p>As above, try a custom print function like:</p> <pre><code>def my_print(obj): if hasattr(obj, '__len__') and len(obj) &gt; 100: print '... omitted object of %s with length %d ...' % (type(obj), len(obj)) else: print obj </code></pre>
2
2009-03-12T00:21:44Z
[ "python", "ide", "editor", "python-idle" ]
How can I stop IDLE from printing giant lists?
609,190
<p>Sometimes I'll be working with, say, a list of thousands of items in IDLE, and accidently print it out to the shell. When this happens, it crashes or at least very significaly slows down IDLE. As you can imagine, this is extremely inconvenient. Is there a way to make it, rather than printing the entire thing, just g...
1
2009-03-04T04:10:12Z
991,877
<p>In Python 3, since print is a function, you should be able to "override" it. (I don't have it installed so I can't try it out to make sure.) Probably not recommended for real applications but if you're just trying things out, it would be okay I suppose.</p> <p>It would go something like:</p> <pre><code>def myprint...
0
2009-06-14T00:56:35Z
[ "python", "ide", "editor", "python-idle" ]
How can I stop IDLE from printing giant lists?
609,190
<p>Sometimes I'll be working with, say, a list of thousands of items in IDLE, and accidently print it out to the shell. When this happens, it crashes or at least very significaly slows down IDLE. As you can imagine, this is extremely inconvenient. Is there a way to make it, rather than printing the entire thing, just g...
1
2009-03-04T04:10:12Z
8,237,338
<p>The <a href="http://pypi.python.org/pypi/Squeezer/1.0" rel="nofollow">Squeezer</a> extension for IDLE was written to do just this. From the description on Pypi:</p> <blockquote> <p>IDLE can hang if very long output is printed. To avoid this, the Squeezer extensions catches any output longer than 80 lines of tex...
0
2011-11-23T04:27:36Z
[ "python", "ide", "editor", "python-idle" ]
PY: Url Encode without variable name
609,212
<p>Is there a way in python to url encode list without variables names? for example <BR> q=['with space1', 'with space2'] <BR> into qescaped=['with%20space1', 'with%20space2']</p>
3
2009-03-04T04:23:36Z
609,228
<p>You can use <a href="http://docs.python.org/library/urllib.html#urllib.quote" rel="nofollow">urllib.quote</a> together with <a href="http://docs.python.org/library/functions.html#map" rel="nofollow">map</a>:</p> <pre><code>import urllib q = ['with space1', 'with space2'] qescaped = map(urllib.quote, q) </code></pre...
7
2009-03-04T04:31:00Z
[ "python" ]
PY: Url Encode without variable name
609,212
<p>Is there a way in python to url encode list without variables names? for example <BR> q=['with space1', 'with space2'] <BR> into qescaped=['with%20space1', 'with%20space2']</p>
3
2009-03-04T04:23:36Z
13,743,452
<p>Nowadays list comprehensions are the Pythonic way to do this:</p> <pre><code>q = [ 'with space1', 'with space2' ] qescaped = [ urllib.quote(u) for u in q ] </code></pre> <p>Often you do not even have to build that list but can use the generator itself instead:</p> <pre><code>qescapedGenerator = (urllib.quote(u) f...
0
2012-12-06T12:15:43Z
[ "python" ]
pysqlite user types in select statement
609,516
<p>Using pysqlite how can a user-defined-type be used as a value in a comparison, e. g: “... WHERE columnName > userType”?</p> <p>For example, I've defined a bool type with the requisite registration, converter, etc. Pysqlite/Sqlite responds as expected for INSERT and SELECT operations (bool 'True' stored as an in...
0
2009-03-04T07:08:06Z
610,761
<p>You probably have to cast it to the correct type. Try "SELECT * FROM tasks WHERE (display = CAST ('True' AS bool))".</p>
0
2009-03-04T14:17:11Z
[ "python", "sqlite", "pysqlite" ]
pysqlite user types in select statement
609,516
<p>Using pysqlite how can a user-defined-type be used as a value in a comparison, e. g: “... WHERE columnName > userType”?</p> <p>For example, I've defined a bool type with the requisite registration, converter, etc. Pysqlite/Sqlite responds as expected for INSERT and SELECT operations (bool 'True' stored as an in...
0
2009-03-04T07:08:06Z
611,619
<p>Use the correct way of passing variables to queries: <strong>Don't build the query, use question marks and pass the parameters as a tuple to <code>execute()</code>.</strong></p> <pre><code>myvar = True cur.execute('SELECT * FROM tasks WHERE display = ?', (myvar,)) </code></pre> <p>That way the sqlite driver will u...
1
2009-03-04T17:27:33Z
[ "python", "sqlite", "pysqlite" ]
<class> has no foreign key to <class> in Django when trying to inline models
609,556
<p>I need to be able to create a quiz type application with 20 some odd multiple choice questions. </p> <p>I have 3 models: <code>Quizzes</code>, <code>Questions</code>, and <code>Answers</code>. </p> <p>I want in the admin interface to create a quiz, and inline the quiz and answer elements.</p> <p>The goal is to cl...
6
2009-03-04T07:22:27Z
609,591
<p>Correct: trying to pull too much out of admin app :) Inline models need a foreign key to the parent model.</p>
2
2009-03-04T07:41:15Z
[ "python", "django", "django-admin" ]
<class> has no foreign key to <class> in Django when trying to inline models
609,556
<p>I need to be able to create a quiz type application with 20 some odd multiple choice questions. </p> <p>I have 3 models: <code>Quizzes</code>, <code>Questions</code>, and <code>Answers</code>. </p> <p>I want in the admin interface to create a quiz, and inline the quiz and answer elements.</p> <p>The goal is to cl...
6
2009-03-04T07:22:27Z
610,083
<p>Let's follow through step by step.</p> <p>The error: "Answer has no FK to Quiz".</p> <p>That's correct. The Answer model has no FK to Quiz. It has an FK to Question, but not Quiz.</p> <p>Why does Answer need an FK to quiz? </p> <p>The QuizAdmin has an AnswerInline and a QuestionInline. For an admin to have i...
3
2009-03-04T10:51:57Z
[ "python", "django", "django-admin" ]
<class> has no foreign key to <class> in Django when trying to inline models
609,556
<p>I need to be able to create a quiz type application with 20 some odd multiple choice questions. </p> <p>I have 3 models: <code>Quizzes</code>, <code>Questions</code>, and <code>Answers</code>. </p> <p>I want in the admin interface to create a quiz, and inline the quiz and answer elements.</p> <p>The goal is to cl...
6
2009-03-04T07:22:27Z
611,145
<p>You can't do <a href="http://code.djangoproject.com/ticket/9025">"nested" inlines</a> in the Django admin (i.e. you can't have a Quiz with inline Questions, with each inline Question having inline Answers). So you'll need to lower your sights to just having inline Questions (then if you navigate to view a single Qu...
14
2009-03-04T15:46:04Z
[ "python", "django", "django-admin" ]
Problems title-casing a string in Python
609,830
<p>I have a name as a string, in this example "markus johansson".</p> <p>I'm trying to code a program that makes 'm' and 'j' uppercase:</p> <pre><code>name = "markus johansson" for i in range(1, len(name)): if name[0] == 'm': name[0] = "M" if name[i] == " ": count = name[i] + 1 if count == 'j':...
2
2009-03-04T09:24:35Z
609,854
<p>Strings are immutable. They can't be changed. You must create a new string with the changed content. If you want to make every 'j' uppercase:</p> <pre><code>def make_uppercase_j(char): if char == 'j': return 'J' else: return char name = "markus johansson" ''.join(make_uppercase_j(c) for c in...
5
2009-03-04T09:31:16Z
[ "python" ]
Problems title-casing a string in Python
609,830
<p>I have a name as a string, in this example "markus johansson".</p> <p>I'm trying to code a program that makes 'm' and 'j' uppercase:</p> <pre><code>name = "markus johansson" for i in range(1, len(name)): if name[0] == 'm': name[0] = "M" if name[i] == " ": count = name[i] + 1 if count == 'j':...
2
2009-03-04T09:24:35Z
609,857
<p>I guess that what you're trying to achieve is:</p> <pre><code>from string import capwords capwords(name) </code></pre> <p>Which yields:</p> <pre><code>'Markus Johansson' </code></pre> <p>EDIT: OK, I see you want to tear down a open door. Here's low level implementation.</p> <pre><code>''.join([char.upper() if p...
8
2009-03-04T09:31:19Z
[ "python" ]
Problems title-casing a string in Python
609,830
<p>I have a name as a string, in this example "markus johansson".</p> <p>I'm trying to code a program that makes 'm' and 'j' uppercase:</p> <pre><code>name = "markus johansson" for i in range(1, len(name)): if name[0] == 'm': name[0] = "M" if name[i] == " ": count = name[i] + 1 if count == 'j':...
2
2009-03-04T09:24:35Z
609,873
<p>If I understand your original algorithm correctly, this is what you want to do:</p> <pre><code>namn = list("markus johansson") if namn[0] == 'm': namn[0] = "M" count = 0 for i in range(1, len(namn)): if namn[i] == " ": count = i + 1 if count and namn[count] == 'j': namn[count] = '...
1
2009-03-04T09:37:03Z
[ "python" ]
Problems title-casing a string in Python
609,830
<p>I have a name as a string, in this example "markus johansson".</p> <p>I'm trying to code a program that makes 'm' and 'j' uppercase:</p> <pre><code>name = "markus johansson" for i in range(1, len(name)): if name[0] == 'm': name[0] = "M" if name[i] == " ": count = name[i] + 1 if count == 'j':...
2
2009-03-04T09:24:35Z
610,095
<pre><code>&gt;&gt;&gt; "markus johansson".title() 'Markus Johansson' </code></pre> <p>Built in string methods are the way to go.</p> <p>EDIT: I see you want to re-invent the wheel. Any particular reason ? You can choose from any number of convoluted methods like:</p> <pre><code>' '.join(j[0].upper()+j[1:] for j in...
9
2009-03-04T10:55:15Z
[ "python" ]
Problems title-casing a string in Python
609,830
<p>I have a name as a string, in this example "markus johansson".</p> <p>I'm trying to code a program that makes 'm' and 'j' uppercase:</p> <pre><code>name = "markus johansson" for i in range(1, len(name)): if name[0] == 'm': name[0] = "M" if name[i] == " ": count = name[i] + 1 if count == 'j':...
2
2009-03-04T09:24:35Z
610,120
<p>"real programming"?</p> <p>I would use .title(), and I'm a real programmer.</p> <p>Or I would use regular expressions</p> <pre><code>re.sub(r"(^|\s)[a-z]", lambda m: m.group(0).upper(), "this is a set of words") </code></pre> <p>This says "If the start of the text or a whitespace character is followed by a lo...
0
2009-03-04T11:07:10Z
[ "python" ]
Problems title-casing a string in Python
609,830
<p>I have a name as a string, in this example "markus johansson".</p> <p>I'm trying to code a program that makes 'm' and 'j' uppercase:</p> <pre><code>name = "markus johansson" for i in range(1, len(name)): if name[0] == 'm': name[0] = "M" if name[i] == " ": count = name[i] + 1 if count == 'j':...
2
2009-03-04T09:24:35Z
610,204
<p>Plenty of good suggestions, so I'll be in good company adding my own 2 cents :-)</p> <p>I'm assuming you want something a little more generic that can handle more than just names starting with 'm' and 'j'. You'll probably also want to consider hyphenated names (like Markus Johnson-Smith) which have caps after the h...
1
2009-03-04T11:42:23Z
[ "python" ]
Problems title-casing a string in Python
609,830
<p>I have a name as a string, in this example "markus johansson".</p> <p>I'm trying to code a program that makes 'm' and 'j' uppercase:</p> <pre><code>name = "markus johansson" for i in range(1, len(name)): if name[0] == 'm': name[0] = "M" if name[i] == " ": count = name[i] + 1 if count == 'j':...
2
2009-03-04T09:24:35Z
610,281
<h3><code>string.capwords()</code> (defined in <a href="http://svn.python.org/view/python/trunk/Lib/string.py?view=markup" rel="nofollow"><code>string.py</code></a>)</h3> <pre><code># Capitalize the words in a string, e.g. " aBc dEf " -&gt; "Abc Def". def capwords(s, sep=None): """capwords(s, [sep]) -&gt; string ...
5
2009-03-04T12:08:36Z
[ "python" ]
Problems title-casing a string in Python
609,830
<p>I have a name as a string, in this example "markus johansson".</p> <p>I'm trying to code a program that makes 'm' and 'j' uppercase:</p> <pre><code>name = "markus johansson" for i in range(1, len(name)): if name[0] == 'm': name[0] = "M" if name[i] == " ": count = name[i] + 1 if count == 'j':...
2
2009-03-04T09:24:35Z
610,572
<p>If you're looking into more generic solution for names, you should also look at following examples:</p> <ul> <li>John Adams-Smith</li> <li>Joanne d'Arc</li> <li>Jean-Luc de'Breu</li> <li>Donatien Alphonse François de Sade</li> </ul> <p>Also some parts of the names shouldn't start with capital letters, like:</p> ...
1
2009-03-04T13:35:03Z
[ "python" ]
Charts in django Web Applications
609,944
<p>I want to Embed a chart in a Web Application developed using django.</p> <p>I have come across <a href="http://code.google.com/p/google-chartwrapper/">Google charts API</a>, <a href="http://code.djangoproject.com/wiki/Charts">ReportLab</a>, <a href="http://home.gna.org/pychart/">PyChart</a>, <a href="http://matplot...
20
2009-03-04T10:08:21Z
610,019
<p>Another choice is <a href="http://linil.wordpress.com/2008/09/16/cairoplot-11/" rel="nofollow">CairoPlot</a>.</p> <p>We picked matplotlib over the others for some serious graphing inside one of our django apps, primarily because it was the only one that gave us exactly the kind of control we needed.</p> <p>Perform...
7
2009-03-04T10:29:38Z
[ "python", "django", "charts" ]
Charts in django Web Applications
609,944
<p>I want to Embed a chart in a Web Application developed using django.</p> <p>I have come across <a href="http://code.google.com/p/google-chartwrapper/">Google charts API</a>, <a href="http://code.djangoproject.com/wiki/Charts">ReportLab</a>, <a href="http://home.gna.org/pychart/">PyChart</a>, <a href="http://matplot...
20
2009-03-04T10:08:21Z
610,272
<p>Open Flash Chart 2</p> <p><a href="http://teethgrinder.co.uk/open-flash-chart-2/" rel="nofollow">http://teethgrinder.co.uk/open-flash-chart-2/</a></p> <p>python library <a href="http://btbytes.github.com/pyofc2/" rel="nofollow">http://btbytes.github.com/pyofc2/</a></p> <p>kybi</p>
3
2009-03-04T12:06:15Z
[ "python", "django", "charts" ]
Charts in django Web Applications
609,944
<p>I want to Embed a chart in a Web Application developed using django.</p> <p>I have come across <a href="http://code.google.com/p/google-chartwrapper/">Google charts API</a>, <a href="http://code.djangoproject.com/wiki/Charts">ReportLab</a>, <a href="http://home.gna.org/pychart/">PyChart</a>, <a href="http://matplot...
20
2009-03-04T10:08:21Z
611,528
<p>Well, I'm involved in an open source project, <a href="http://djime.github.com/" rel="nofollow">Djime</a>, that uses <a href="http://teethgrinder.co.uk/open-flash-chart-2/" rel="nofollow">OpenFlashChart 2</a>.</p> <p>As you can see from <a href="http://github.com/mikl/djime/blob/e6832c6e8d2aa8a3801b16121a0499f3b6d6...
5
2009-03-04T17:04:50Z
[ "python", "django", "charts" ]
Charts in django Web Applications
609,944
<p>I want to Embed a chart in a Web Application developed using django.</p> <p>I have come across <a href="http://code.google.com/p/google-chartwrapper/">Google charts API</a>, <a href="http://code.djangoproject.com/wiki/Charts">ReportLab</a>, <a href="http://home.gna.org/pychart/">PyChart</a>, <a href="http://matplot...
20
2009-03-04T10:08:21Z
1,385,804
<p>I have used <a href="http://www.fusioncharts.com/free/" rel="nofollow">FusionCharts Free</a> with Django.</p> <p>Its flash based, open source, multi-licensed and it's well documented. It's ActionScript 1, but AS version wasn't really a criteria for me, though it could be for others.</p>
0
2009-09-06T14:37:36Z
[ "python", "django", "charts" ]
Charts in django Web Applications
609,944
<p>I want to Embed a chart in a Web Application developed using django.</p> <p>I have come across <a href="http://code.google.com/p/google-chartwrapper/">Google charts API</a>, <a href="http://code.djangoproject.com/wiki/Charts">ReportLab</a>, <a href="http://home.gna.org/pychart/">PyChart</a>, <a href="http://matplot...
20
2009-03-04T10:08:21Z
1,386,926
<p>One package I've wanted to try is <a href="http://graphite.wikidot.com/" rel="nofollow">graphite</a>. It's a graphing server / platform built with Django. It's specialized for "numeric time-series data" though, like stock prices or bandwidth utilization. If that fits your need I would check it out. Here are some scr...
3
2009-09-06T22:44:31Z
[ "python", "django", "charts" ]
Charts in django Web Applications
609,944
<p>I want to Embed a chart in a Web Application developed using django.</p> <p>I have come across <a href="http://code.google.com/p/google-chartwrapper/">Google charts API</a>, <a href="http://code.djangoproject.com/wiki/Charts">ReportLab</a>, <a href="http://home.gna.org/pychart/">PyChart</a>, <a href="http://matplot...
20
2009-03-04T10:08:21Z
3,997,250
<p>I like client side charts because you can get full page plotting. </p> <p>A good options seems to be Jquery Flot : <a href="http://code.google.com/p/flot/" rel="nofollow">http://code.google.com/p/flot/</a> which can load JSON data. However, you won't get pdf support.</p>
1
2010-10-22T13:29:06Z
[ "python", "django", "charts" ]
Charts in django Web Applications
609,944
<p>I want to Embed a chart in a Web Application developed using django.</p> <p>I have come across <a href="http://code.google.com/p/google-chartwrapper/">Google charts API</a>, <a href="http://code.djangoproject.com/wiki/Charts">ReportLab</a>, <a href="http://home.gna.org/pychart/">PyChart</a>, <a href="http://matplot...
20
2009-03-04T10:08:21Z
5,781,231
<p>Perhaps you might want to have a look here: <a href="http://www.rotareeclub.de/?p=312" rel="nofollow">Django Plotting app</a>. The HowTo describes how to embed matplotlib plots into the admin interface and create a PDF view.</p>
1
2011-04-25T17:43:37Z
[ "python", "django", "charts" ]
Yahoo Pipes, simplejson and slashes
610,205
<p>Im trying to use <a href="http://www.javarants.com/2008/04/13/using-google-app-engine-to-extend-yahoo-pipes/" rel="nofollow">http://www.javarants.com/2008/04/13/using-google-app-engine-to-extend-yahoo-pipes/</a> as inspiration, but I'm having some troubles with the output.</p> <p>Its obvious when testing with the c...
0
2009-03-04T11:42:25Z
677,751
<p>Nothing here to see. The ticket is there, but thats it, as far as I can see</p>
0
2009-03-24T14:53:50Z
[ "python", "yahoo-pipes", "simplejson" ]
Catching Python exceptions using 'expect' method?
610,403
<pre><code>import sys try: file = open("words.txt") expect(IOError): if file: print "%s" % file else: print "Cant the %s file" % "words.txt" </code></pre> <p>this gives me an a error - </p> <pre><code>File "main.py", line 4 expect(IOError): SyntaxError: invaild syntax </code></pre> <p>What im ...
1
2009-03-04T12:52:33Z
610,412
<p>Actually, it is except as in exception:</p> <p>For instance:</p> <pre><code>except IOError: print "Error opening file!" </code></pre>
12
2009-03-04T12:54:46Z
[ "python" ]
Catching Python exceptions using 'expect' method?
610,403
<pre><code>import sys try: file = open("words.txt") expect(IOError): if file: print "%s" % file else: print "Cant the %s file" % "words.txt" </code></pre> <p>this gives me an a error - </p> <pre><code>File "main.py", line 4 expect(IOError): SyntaxError: invaild syntax </code></pre> <p>What im ...
1
2009-03-04T12:52:33Z
610,417
<p>It's <code>except</code>. Read <a href="http://docs.python.org/tutorial/index.html" rel="nofollow">this</a>.</p>
1
2009-03-04T12:55:52Z
[ "python" ]
Catching Python exceptions using 'expect' method?
610,403
<pre><code>import sys try: file = open("words.txt") expect(IOError): if file: print "%s" % file else: print "Cant the %s file" % "words.txt" </code></pre> <p>this gives me an a error - </p> <pre><code>File "main.py", line 4 expect(IOError): SyntaxError: invaild syntax </code></pre> <p>What im ...
1
2009-03-04T12:52:33Z
610,426
<p>I think you're looking for <a href="http://docs.python.org/reference/compound%5Fstmts.html#except" rel="nofollow">except</a>. The <a href="http://docs.python.org/tutorial/errors.html" rel="nofollow">error handling</a> part of the python tutorial explains it well.</p> <p>-John</p>
1
2009-03-04T12:57:38Z
[ "python" ]
Catching Python exceptions using 'expect' method?
610,403
<pre><code>import sys try: file = open("words.txt") expect(IOError): if file: print "%s" % file else: print "Cant the %s file" % "words.txt" </code></pre> <p>this gives me an a error - </p> <pre><code>File "main.py", line 4 expect(IOError): SyntaxError: invaild syntax </code></pre> <p>What im ...
1
2009-03-04T12:52:33Z
610,431
<p>I assume you are trying to handle exceptions. In that case, use <strong>except</strong>, not <strong>expect</strong>. In any case except is <strong>not a function</strong>, rather it precedes a block of error handling code. When using files, you may want to look at the <strong>with statement</strong> and <strong>try...
4
2009-03-04T12:58:38Z
[ "python" ]
Catching Python exceptions using 'expect' method?
610,403
<pre><code>import sys try: file = open("words.txt") expect(IOError): if file: print "%s" % file else: print "Cant the %s file" % "words.txt" </code></pre> <p>this gives me an a error - </p> <pre><code>File "main.py", line 4 expect(IOError): SyntaxError: invaild syntax </code></pre> <p>What im ...
1
2009-03-04T12:52:33Z
610,457
<pre> <code> >>> try: ... f = open('words.txt') ... except IOError: ... print "Cant the %s file" % "words.txt" ... else: ... print "%s" % f </code> </pre>
1
2009-03-04T13:05:25Z
[ "python" ]
Is there something like CherryPy or Cerise in the Java world?
610,516
<p><a href="http://www.cherrypy.org/" rel="nofollow">CherryPy</a> and <a href="http://cerise.rubyforge.org/" rel="nofollow">Cerise</a> are two small frameworks that implement nothing but the barebones of a web-framework and I love their simplicity: in fact I reckon that if Classic ASP was implemented that way (and didn...
2
2009-03-04T13:21:36Z
610,538
<p><a href="http://www.stripesframework.org/display/stripes/Home" rel="nofollow">Stripes</a></p> <p>URLs to methods, check, form validation, check. Powerful but stays out of your way unless you need it.</p>
2
2009-03-04T13:27:23Z
[ "java", "python" ]
Is there something like CherryPy or Cerise in the Java world?
610,516
<p><a href="http://www.cherrypy.org/" rel="nofollow">CherryPy</a> and <a href="http://cerise.rubyforge.org/" rel="nofollow">Cerise</a> are two small frameworks that implement nothing but the barebones of a web-framework and I love their simplicity: in fact I reckon that if Classic ASP was implemented that way (and didn...
2
2009-03-04T13:21:36Z
610,544
<p>Groovy and <a href="http://www.grails.org" rel="nofollow">Grails</a>. If you like MVC or even have a existing library written in Java/JVM, that are the tools you're looking for! </p> <blockquote> <p>Grails aims to bring the "coding by convention" paradigm to Groovy. It's an open-source web application frame...
0
2009-03-04T13:29:01Z
[ "java", "python" ]
Is there something like CherryPy or Cerise in the Java world?
610,516
<p><a href="http://www.cherrypy.org/" rel="nofollow">CherryPy</a> and <a href="http://cerise.rubyforge.org/" rel="nofollow">Cerise</a> are two small frameworks that implement nothing but the barebones of a web-framework and I love their simplicity: in fact I reckon that if Classic ASP was implemented that way (and didn...
2
2009-03-04T13:21:36Z
612,435
<p><a href="http://ooweb.sourceforge.net/tutorial.html" rel="nofollow">OOWeb</a>, essentially a port of CherryPy.</p>
2
2009-03-04T21:10:29Z
[ "java", "python" ]
How to know if an object has an attribute in Python
610,883
<p>Is there a way in Python to determine if an object has some attribute? For example:</p> <pre><code>&gt;&gt;&gt; a = SomeClass() &gt;&gt;&gt; a.someProperty = value &gt;&gt;&gt; a.property Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: SomeClass instance has no ...
737
2009-03-04T14:45:59Z
610,893
<p>Try hasattr():</p> <pre><code>if hasattr(a, 'property'): a.property </code></pre> <p>EDIT: See <a href="http://stackoverflow.com/a/610923/117030">zweiterlinde's answer</a> below, who offers good advice about asking forgiveness! A very pythonic approach! </p> <p>The general practice in python is that, if the p...
1,006
2009-03-04T14:48:43Z
[ "python", "attributes" ]
How to know if an object has an attribute in Python
610,883
<p>Is there a way in Python to determine if an object has some attribute? For example:</p> <pre><code>&gt;&gt;&gt; a = SomeClass() &gt;&gt;&gt; a.someProperty = value &gt;&gt;&gt; a.property Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: SomeClass instance has no ...
737
2009-03-04T14:45:59Z
610,907
<p>I think what you are looking for is <strong>hasattr</strong>. However, I'd recommend something like this if you want to detect <strong>python properties</strong>-</p> <pre><code>try: getattr(someObject, 'someProperty') except AttributeError: print "Doesn't exist" else print "Exists" </code></pr...
23
2009-03-04T14:52:26Z
[ "python", "attributes" ]
How to know if an object has an attribute in Python
610,883
<p>Is there a way in Python to determine if an object has some attribute? For example:</p> <pre><code>&gt;&gt;&gt; a = SomeClass() &gt;&gt;&gt; a.someProperty = value &gt;&gt;&gt; a.property Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: SomeClass instance has no ...
737
2009-03-04T14:45:59Z
610,922
<p>According to pydoc, hasattr(obj, prop) simply calls getattr(obj, prop) and catches exceptions. So, it is just as valid to wrap the attribute access with a try statement and catch AttributeError as it is to use hasattr() beforehand.</p> <pre><code>a = SomeClass() try: return a.fake_prop except AttributeError: ...
15
2009-03-04T14:56:26Z
[ "python", "attributes" ]
How to know if an object has an attribute in Python
610,883
<p>Is there a way in Python to determine if an object has some attribute? For example:</p> <pre><code>&gt;&gt;&gt; a = SomeClass() &gt;&gt;&gt; a.someProperty = value &gt;&gt;&gt; a.property Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: SomeClass instance has no ...
737
2009-03-04T14:45:59Z
610,923
<p>As <a href="http://stackoverflow.com/questions/610883/how-to-know-if-an-object-has-an-attribute-in-python/610893#610893">Jarret Hardie</a> answered, <code>hasattr</code> will do the trick. I would like to add, though, that many in the Python community recommend a strategy of "easier to ask for forgiveness than perm...
322
2009-03-04T14:56:28Z
[ "python", "attributes" ]
How to know if an object has an attribute in Python
610,883
<p>Is there a way in Python to determine if an object has some attribute? For example:</p> <pre><code>&gt;&gt;&gt; a = SomeClass() &gt;&gt;&gt; a.someProperty = value &gt;&gt;&gt; a.property Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: SomeClass instance has no ...
737
2009-03-04T14:45:59Z
611,122
<p>Depending on the situation you can check with <code>isinstance</code> what kind of object you have, and then use the corresponding attributes. With the introduction of <a href="http://www.python.org/dev/peps/pep-3119/">abstract base classes</a> in Python 2.6/3.0 this approach has also become much more powerful (basi...
8
2009-03-04T15:41:04Z
[ "python", "attributes" ]
How to know if an object has an attribute in Python
610,883
<p>Is there a way in Python to determine if an object has some attribute? For example:</p> <pre><code>&gt;&gt;&gt; a = SomeClass() &gt;&gt;&gt; a.someProperty = value &gt;&gt;&gt; a.property Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: SomeClass instance has no ...
737
2009-03-04T14:45:59Z
611,708
<p>You can use <code>hasattr()</code> or catch <code>AttributeError</code>, but if you really just want the value of the attribute with a default if it isn't there, the best option is just to use <code>getattr()</code>:</p> <pre><code>getattr(a, 'property', 'default value') </code></pre>
251
2009-03-04T17:54:29Z
[ "python", "attributes" ]
How to know if an object has an attribute in Python
610,883
<p>Is there a way in Python to determine if an object has some attribute? For example:</p> <pre><code>&gt;&gt;&gt; a = SomeClass() &gt;&gt;&gt; a.someProperty = value &gt;&gt;&gt; a.property Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: SomeClass instance has no ...
737
2009-03-04T14:45:59Z
39,167,034
<p>I would like to suggest avoid this:</p> <pre><code>try: doStuff(a.property) except AttributeError: otherStuff() </code></pre> <p>The user @jpalecek mentioned it: If an <code>AttributeError</code> occurs inside <code>doStuff()</code>, you are lost.</p> <p>Maybe this approach is better:</p> <pre><code>try:...
2
2016-08-26T13:04:30Z
[ "python", "attributes" ]
What is a good strategy for constructing a directed graph for a game map (in Python)?
610,892
<p>I'm developing a procedurally-generated game world in Python. The structure of the world will be similar to the MUD/MUSH paradigm of rooms and exits arranged as a directed graph (rooms are nodes, exits are edges). (Note that this is <em>not</em> necessarily an acyclic graph, though I'm willing to consider acyclic so...
9
2009-03-04T14:48:19Z
611,124
<p>First, you need some sense of Location. Your various objects occupy some amount of coordinate space.</p> <p>You have to decide how regular these various things are. In the trivial case, you can drop them into your coordinate space as simple rectangles (or rectangular solids) to make locations simpler to plan out....
7
2009-03-04T15:41:51Z
[ "python", "graph", "procedural-generation" ]
What is a good strategy for constructing a directed graph for a game map (in Python)?
610,892
<p>I'm developing a procedurally-generated game world in Python. The structure of the world will be similar to the MUD/MUSH paradigm of rooms and exits arranged as a directed graph (rooms are nodes, exits are edges). (Note that this is <em>not</em> necessarily an acyclic graph, though I'm willing to consider acyclic so...
9
2009-03-04T14:48:19Z
612,730
<p>Check out the discussions on <a href="http://www.mudconnector.com" rel="nofollow">The MUD Connector</a> - there are some great discussions about world layout and generation, and different types of coordinate / navigation systems in the "Advanced Coding and Design" (or similar) forum.</p>
2
2009-03-04T22:20:48Z
[ "python", "graph", "procedural-generation" ]
Django Model Inheritance. Hiding or removing fields
611,691
<p>I want to inherit a model class from some 3rd party code. I won't be using some of the fields but want my client to be able to edit the model in Admin. Is the best bet to hide them from Admin or can I actually prevent them being created in the first place?</p> <p>Additionally - what can I do if one of the unwanted ...
10
2009-03-04T17:49:26Z
611,725
<p>If you are inheriting the model then it is probably not wise to attempt to hide or disable any existing fields. The best thing you could probably do is exactly what you suggested: override <code>save()</code> and handle your logic in there. </p>
4
2009-03-04T17:57:34Z
[ "python", "django", "django-models", "django-admin" ]
Django Model Inheritance. Hiding or removing fields
611,691
<p>I want to inherit a model class from some 3rd party code. I won't be using some of the fields but want my client to be able to edit the model in Admin. Is the best bet to hide them from Admin or can I actually prevent them being created in the first place?</p> <p>Additionally - what can I do if one of the unwanted ...
10
2009-03-04T17:49:26Z
611,813
<p>Rather than inherit, consider using customized Forms.</p> <ol> <li><p>You can eliminate fields from display that are still in the model.</p></li> <li><p>You can validate and provide default values in the form's <code>clean()</code> method.</p></li> </ol> <p>See <a href="http://docs.djangoproject.com/en/dev/ref/con...
4
2009-03-04T18:20:55Z
[ "python", "django", "django-models", "django-admin" ]
Django Model Inheritance. Hiding or removing fields
611,691
<p>I want to inherit a model class from some 3rd party code. I won't be using some of the fields but want my client to be able to edit the model in Admin. Is the best bet to hide them from Admin or can I actually prevent them being created in the first place?</p> <p>Additionally - what can I do if one of the unwanted ...
10
2009-03-04T17:49:26Z
611,972
<p>You can control the fields that are editable in admin.</p> <p>From the Django docs:</p> <p>"If you want a form for the Author model that includes only the name and title fields, you would specify fields or exclude like this:</p> <pre><code>class AuthorAdmin(admin.ModelAdmin): fields = ('name', 'title') class...
4
2009-03-04T19:02:41Z
[ "python", "django", "django-models", "django-admin" ]
Can you give a Django app a verbose name for use throughout the admin?
612,372
<p>In the same way that you can give fields and models verbose names that appear in the Django admin, can you give an app a custom name?</p>
95
2009-03-04T20:51:03Z
612,955
<p>No, but you can copy admin template and define app name there.</p>
6
2009-03-04T23:22:05Z
[ "python", "django" ]
Can you give a Django app a verbose name for use throughout the admin?
612,372
<p>In the same way that you can give fields and models verbose names that appear in the Django admin, can you give an app a custom name?</p>
95
2009-03-04T20:51:03Z
615,760
<p>Give them a verbose_name property.</p> <p>Don't get your hopes up. You will also need to copy the index view from django.contrib.admin.sites into your own ProjectAdminSite view and include it in your own custom admin instance:</p> <pre><code>class ProjectAdminSite(AdminSite): def index(self, request, extra_con...
11
2009-03-05T17:29:30Z
[ "python", "django" ]
Can you give a Django app a verbose name for use throughout the admin?
612,372
<p>In the same way that you can give fields and models verbose names that appear in the Django admin, can you give an app a custom name?</p>
95
2009-03-04T20:51:03Z
3,164,163
<p><strong>Prior to Django 1.7</strong></p> <p>You can give your application a custom name by defining app_label in your model definition. But as django builds the admin page it will hash models by their app_label, so if you want them to appear in one application, you have to define this name in all models of your app...
85
2010-07-02T08:20:34Z
[ "python", "django" ]
Can you give a Django app a verbose name for use throughout the admin?
612,372
<p>In the same way that you can give fields and models verbose names that appear in the Django admin, can you give an app a custom name?</p>
95
2009-03-04T20:51:03Z
3,628,988
<p>Well I started an app called <strong>todo</strong> and have now decided I want it to be named <strong>Tasks</strong>. The problem is that I already have data within my table so my work around was as follows. Placed into the models.py:</p> <pre><code> class Meta: app_label = 'Tasks' db_table = 'myto...
10
2010-09-02T16:08:22Z
[ "python", "django" ]