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 |
|---|---|---|---|---|---|---|---|---|---|
How to get 280slides.com functionality? | 1,385,722 | <p>I have seen 280slides.com and it is really impresive. But its developers had to create their own language.</p>
<p>Which platform or language would you use to have an as similar as possible functionality?
Is it possible to do something similar in python?
Could you give any working examples?</p>
| 3 | 2009-09-06T13:51:26Z | 1,385,753 | <p>From memory, that language (Objective-J) compiles into javascript, so it's just the old HTML + CSS + Javascript + <code><</code><em>insert server-side language here</em><code>></code>. Python could easily be the server-side language. If you want examples of python web frameworks, look at <a href="http://www.dj... | 0 | 2009-09-06T14:01:30Z | [
"python",
"rich-internet-application"
] |
How to get 280slides.com functionality? | 1,385,722 | <p>I have seen 280slides.com and it is really impresive. But its developers had to create their own language.</p>
<p>Which platform or language would you use to have an as similar as possible functionality?
Is it possible to do something similar in python?
Could you give any working examples?</p>
| 3 | 2009-09-06T13:51:26Z | 1,385,927 | <p>Inventing our own language was a miniscule part of the problem. What was important was developing the right framework, which is now available as Cappuccino (cappuccino.org). </p>
<p>You ask what platform/language you could use to develop something similar? I assume you already know that the answer to what platform ... | 8 | 2009-09-06T15:29:29Z | [
"python",
"rich-internet-application"
] |
SQLCODE -1829 on connect using informixdb | 1,385,731 | <p>While trying to connect to the database I get a strange error:</p>
<pre><code>DatabaseError: SQLCODE -1829 in CONNECT:
ìæà : Cannot open file 'os.iem'
ìæà : Cannot open file 'os.iem'
</code></pre>
<p>I can confirm that the file is present in $INFORMIXDIR/msg/en_us/0333/ directory. The environment v... | 1 | 2009-09-06T13:54:07Z | 1,386,274 | <p>ok figured this one out! It appears only the env values set before the import of the informixdb module affect the way the module works. So the following does not work:</p>
<pre><code>import informixdb
os.environ["INFORMIXDIR"] = "/opt/informix"
...
def conn(db):
informixdb.connect(db, self.username, self.passw... | 1 | 2009-09-06T18:03:57Z | [
"python",
"informix"
] |
Should __init__() call the parent class's __init__()? | 1,385,759 | <p>I'm used that in Objective-C I've got this construct:</p>
<pre><code>- (void)init {
if (self = [super init]) {
// init class
}
return self;
}
</code></pre>
<p>Should Python also call the parent class's implementation for <code>__init__</code>?</p>
<pre><code>class NewClass(SomeOtherClass):
... | 61 | 2009-09-06T14:04:23Z | 1,385,767 | <p><strong>Edit</strong>: (after the code change)<br />
There is no way for us to tell you whether you need or not to call your parent's <code>__init__</code> (or any other function). Inheritance obviously would work without such call. It all depends on the logic of your code: for example, if all your <code>__init__</c... | 14 | 2009-09-06T14:11:23Z | [
"python"
] |
Should __init__() call the parent class's __init__()? | 1,385,759 | <p>I'm used that in Objective-C I've got this construct:</p>
<pre><code>- (void)init {
if (self = [super init]) {
// init class
}
return self;
}
</code></pre>
<p>Should Python also call the parent class's implementation for <code>__init__</code>?</p>
<pre><code>class NewClass(SomeOtherClass):
... | 61 | 2009-09-06T14:04:23Z | 1,385,768 | <p>There's no hard and fast rule. The documentation for a class should indicate whether subclasses should call the superclass method. Sometimes you want to completely replace superclass behaviour, and at other times augment it - i.e. call your own code before and/or after a superclass call.</p>
<p><strong>Update:</str... | 4 | 2009-09-06T14:13:22Z | [
"python"
] |
Should __init__() call the parent class's __init__()? | 1,385,759 | <p>I'm used that in Objective-C I've got this construct:</p>
<pre><code>- (void)init {
if (self = [super init]) {
// init class
}
return self;
}
</code></pre>
<p>Should Python also call the parent class's implementation for <code>__init__</code>?</p>
<pre><code>class NewClass(SomeOtherClass):
... | 61 | 2009-09-06T14:04:23Z | 1,385,778 | <p>In Python, calling the super-class' <code>__init__</code> is optional. If you call it, it is then also optional whether to use the <code>super</code> identifier, or whether to explicitly name the super class:</p>
<pre><code>object.__init__(self)
</code></pre>
<p>In case of object, calling the super method is not s... | 32 | 2009-09-06T14:18:07Z | [
"python"
] |
Should __init__() call the parent class's __init__()? | 1,385,759 | <p>I'm used that in Objective-C I've got this construct:</p>
<pre><code>- (void)init {
if (self = [super init]) {
// init class
}
return self;
}
</code></pre>
<p>Should Python also call the parent class's implementation for <code>__init__</code>?</p>
<pre><code>class NewClass(SomeOtherClass):
... | 61 | 2009-09-06T14:04:23Z | 1,385,826 | <p>IMO, you should call it. If your superclass is <code>object</code>, you should not, but in other cases I think it is exceptional not to call it. As already answered by others, it is very convenient if your class doesn't even have to override <code>__init__</code> itself, for example when it has no (additional) inter... | 3 | 2009-09-06T14:47:43Z | [
"python"
] |
Should __init__() call the parent class's __init__()? | 1,385,759 | <p>I'm used that in Objective-C I've got this construct:</p>
<pre><code>- (void)init {
if (self = [super init]) {
// init class
}
return self;
}
</code></pre>
<p>Should Python also call the parent class's implementation for <code>__init__</code>?</p>
<pre><code>class NewClass(SomeOtherClass):
... | 61 | 2009-09-06T14:04:23Z | 1,385,836 | <p>If you need something from super's <code>__init__</code> to be done in addition to what is being done in the current class's <code>__init__,</code> you must call it yourself, since that will not happen automatically. But if you don't need anything from super's <code>__init__,</code> no need to call it. Example:</p... | 71 | 2009-09-06T14:51:06Z | [
"python"
] |
Should __init__() call the parent class's __init__()? | 1,385,759 | <p>I'm used that in Objective-C I've got this construct:</p>
<pre><code>- (void)init {
if (self = [super init]) {
// init class
}
return self;
}
</code></pre>
<p>Should Python also call the parent class's implementation for <code>__init__</code>?</p>
<pre><code>class NewClass(SomeOtherClass):
... | 61 | 2009-09-06T14:04:23Z | 7,059,529 | <p>In Anon's answer:<br>
<em>"If you need something from super's <code>__init__</code> to be done in addition to what is being done in the current class's <code>__init__</code> , you must call it yourself, since that will not happen automatically"</em> </p>
<p>It's incredible: he is wording exactly the contrary of t... | 28 | 2011-08-14T20:31:39Z | [
"python"
] |
Group Input in Forms | 1,385,766 | <p>I've this django form</p>
<pre><code>class CustomerForm(forms.Form):
first_name = forms.CharField(label=_('Nome'), max_length=30)
last_name = forms.CharField(label=_('Cognome'), max_length=30)
business_name = forms.CharField(label=_('Ragione Sociale'),
... | 2 | 2009-09-06T14:10:23Z | 1,385,773 | <p>There's nothing to stop you doing this in your template. Remember, as the documentation says, the <code>{{ form.as_p }}</code> etc are just shortcuts. As soon as you need to do something different, you can just fall back to iterating through the fields in your template, or even listing them individually.</p>
| 0 | 2009-09-06T14:15:45Z | [
"python",
"django",
"django-forms",
"input"
] |
Group Input in Forms | 1,385,766 | <p>I've this django form</p>
<pre><code>class CustomerForm(forms.Form):
first_name = forms.CharField(label=_('Nome'), max_length=30)
last_name = forms.CharField(label=_('Cognome'), max_length=30)
business_name = forms.CharField(label=_('Ragione Sociale'),
... | 2 | 2009-09-06T14:10:23Z | 3,394,174 | <p>have a look at the <a href="http://djangosnippets.org/snippets/1783/" rel="nofollow">Stacked/Grouped Forms</a> snippet, where you can define "Stacks" (Groups) of fields in your Form.</p>
| 1 | 2010-08-03T06:47:20Z | [
"python",
"django",
"django-forms",
"input"
] |
How do you check if a widget has focus in Tkinter? | 1,385,921 | <pre><code>from Tkinter import *
app = Tk()
text_field = Entry(app)
text_field.pack()
app.mainloop()
</code></pre>
<p>I want to be able to check if <code>text_field</code> is currently selected or focused, so that I know whether or not to do something with its contents when the user presses enter.</p>
| 7 | 2009-09-06T15:25:17Z | 1,385,933 | <p>If you want to do something when the user presses enter only if the focus is on the entry widget, simply add a binding to the entry widget. It will only fire if that widget has focus. For example:</p>
<pre><code>>>> from Tkinter import *
>>> root=Tk()
>>> e1=Entry(root)
>>> e1.pa... | 11 | 2009-09-06T15:32:23Z | [
"python",
"focus",
"tkinter",
"entry"
] |
maximum number combinations | 1,385,929 | <p>I am trying to generate a list of all possible number combinations within a set of four numbers using all numbers from 0 through 9.</p>
<p>I'm getting close but the output doesn't show every possible combination starting from 0000 all the way to 9999. </p>
<p>Any clues as to why the following code is dropping cert... | 3 | 2009-09-06T15:30:45Z | 1,385,935 | <p>If you have python 2.6, why not use <a href="http://docs.python.org/library/itertools.html#itertools.combinations" rel="nofollow">itertools.combinations</a>?</p>
<pre><code>from itertools import combinations
combinations(range(10), 4)
</code></pre>
| 12 | 2009-09-06T15:34:42Z | [
"python",
"combinations"
] |
maximum number combinations | 1,385,929 | <p>I am trying to generate a list of all possible number combinations within a set of four numbers using all numbers from 0 through 9.</p>
<p>I'm getting close but the output doesn't show every possible combination starting from 0000 all the way to 9999. </p>
<p>Any clues as to why the following code is dropping cert... | 3 | 2009-09-06T15:30:45Z | 1,385,943 | <pre><code>int ra;
for(ra=0,ra<10000;ra++) printf("%04u\n",ra);
</code></pre>
| 0 | 2009-09-06T15:37:13Z | [
"python",
"combinations"
] |
maximum number combinations | 1,385,929 | <p>I am trying to generate a list of all possible number combinations within a set of four numbers using all numbers from 0 through 9.</p>
<p>I'm getting close but the output doesn't show every possible combination starting from 0000 all the way to 9999. </p>
<p>Any clues as to why the following code is dropping cert... | 3 | 2009-09-06T15:30:45Z | 1,385,955 | <p>This line:</p>
<pre><code>for cc in permgen(items[:i]+items[i+1:],n-1):
</code></pre>
<p>You're basically saying "get a number, than add another one <em>different</em> from ir, repeat n times, then return a list of these digits. That's going to give you numbers where no digit appears more than once. If you change ... | 4 | 2009-09-06T15:40:47Z | [
"python",
"combinations"
] |
maximum number combinations | 1,385,929 | <p>I am trying to generate a list of all possible number combinations within a set of four numbers using all numbers from 0 through 9.</p>
<p>I'm getting close but the output doesn't show every possible combination starting from 0000 all the way to 9999. </p>
<p>Any clues as to why the following code is dropping cert... | 3 | 2009-09-06T15:30:45Z | 1,386,207 | <p>Take a look at <a href="http://docs.python.org/library/itertools.html" rel="nofollow">itertools' combinatoric generators</a>:</p>
<pre><code>>>> from itertools import combinations, permutations, product
>>> def pp(chunks):
... print(' '.join(map(''.join, chunks)))
...
>>> pp(combinati... | 4 | 2009-09-06T17:34:13Z | [
"python",
"combinations"
] |
Add Preprocessor to HTML (Probably in Apache) | 1,385,965 | <p>I would like to add a preprocessor to HTML pages. Basically, I have a program that takes the name of an HTML file containing preprocessor instructions and outputs the contents of the file after preprocessing to stdout. This mechanism could change if it makes things easier. All I want to do is hook this into Apach... | 0 | 2009-09-06T15:46:38Z | 1,385,987 | <p>If you have Apache and a "preprocessor" written in python, why not go for <a href="http://www.modpython.org/" rel="nofollow">mod_python</a>?</p>
| 4 | 2009-09-06T15:55:13Z | [
"php",
"python",
"html",
"apache",
"preprocessor"
] |
Shall I bother with storing DateTime data as julianday in SQLite? | 1,386,093 | <p>SQLite docs specifies that the preferred format for storing datetime values in the DB is to use Julian Day (using built-in functions).</p>
<p>However, all frameworks I saw in python (pysqlite, SQLAlchemy) store the <code>datetime.datetime</code> values as ISO formatted strings. Why are they doing so?</p>
<p>I'm us... | 8 | 2009-09-06T16:43:23Z | 1,386,154 | <p>Julian Day is handy for all sorts of date calculations, but it can's store the <em>time</em> part decently (with precise hours, minutes, and seconds). In the past I've used both Julian Day fields (for dates), and seconds-from-the-Epoch (for <code>datetime</code> instances), but only when I had specific needs for com... | 6 | 2009-09-06T17:10:49Z | [
"python",
"datetime",
"sqlite",
"sqlalchemy",
"pysqlite"
] |
Shall I bother with storing DateTime data as julianday in SQLite? | 1,386,093 | <p>SQLite docs specifies that the preferred format for storing datetime values in the DB is to use Julian Day (using built-in functions).</p>
<p>However, all frameworks I saw in python (pysqlite, SQLAlchemy) store the <code>datetime.datetime</code> values as ISO formatted strings. Why are they doing so?</p>
<p>I'm us... | 8 | 2009-09-06T16:43:23Z | 1,399,537 | <p>Store it both ways. Frameworks can be set in their ways and if yours is expecting to find a raw column with an ISO formatted string then that is probably more of a pain to get around than it's worth.</p>
<p>The concern in having two columns is data consistency but sqlite should have everything you need to make it w... | 5 | 2009-09-09T12:57:15Z | [
"python",
"datetime",
"sqlite",
"sqlalchemy",
"pysqlite"
] |
Shall I bother with storing DateTime data as julianday in SQLite? | 1,386,093 | <p>SQLite docs specifies that the preferred format for storing datetime values in the DB is to use Julian Day (using built-in functions).</p>
<p>However, all frameworks I saw in python (pysqlite, SQLAlchemy) store the <code>datetime.datetime</code> values as ISO formatted strings. Why are they doing so?</p>
<p>I'm us... | 8 | 2009-09-06T16:43:23Z | 3,089,486 | <p>Because <code>2010-06-22 00:45:56</code> is far easier for a human to read than <code>2455369.5318981484</code>. Text dates are great for doing ad-hoc queries in SQLiteSpy or SQLite Manager.</p>
<p>The main drawback, of course, is that text dates require 19 bytes instead of 8.</p>
| 0 | 2010-06-22T00:50:37Z | [
"python",
"datetime",
"sqlite",
"sqlalchemy",
"pysqlite"
] |
Shall I bother with storing DateTime data as julianday in SQLite? | 1,386,093 | <p>SQLite docs specifies that the preferred format for storing datetime values in the DB is to use Julian Day (using built-in functions).</p>
<p>However, all frameworks I saw in python (pysqlite, SQLAlchemy) store the <code>datetime.datetime</code> values as ISO formatted strings. Why are they doing so?</p>
<p>I'm us... | 8 | 2009-09-06T16:43:23Z | 4,634,359 | <p>But typically, the Human doesn't read directly from the database. Fractional time on a Julian Day is easily converted to human readible by (for example)</p>
<pre><code>void hour_time(GenericDate *ConvertObject)
{
double frac_time = ConvertObject->jd;
double hour = (24.0*(frac_time - (int)frac_... | 1 | 2011-01-08T14:36:32Z | [
"python",
"datetime",
"sqlite",
"sqlalchemy",
"pysqlite"
] |
'Query' object has no attribute 'kind' when using appcfg.py download_data | 1,386,191 | <p>I'm having problems with bulk downloads -- all of my data is not being pulled down.</p>
<p>I'm still debugging, but I see in my console:</p>
<pre><code>Traceback (most recent call last):
File "/Users/matthew/local/opt/google_appengine/google/appengine/tools/adaptive_thread_pool.py", line 150, in WorkOnItems
stat... | 0 | 2009-09-06T17:28:04Z | 1,386,519 | <p>It looks like you've encountered a bug in the bulk downloader, unfortunately. Can you please file a bug report <a href="http://code.google.com/p/googleappengine/issues/entry" rel="nofollow">here</a>? It'd help if you can supply the model definition and bulk loader exporter subclass definition.</p>
| 1 | 2009-09-06T19:40:40Z | [
"python",
"google-app-engine"
] |
Should properties do nontrivial initialization? | 1,386,210 | <p>I have an object that is basically a Python implementation of an Oracle sequence. For a variety of reasons, we have to get the nextval of an Oracle sequence, count up manually when determining primary keys, then update the sequence once the records have been inserted.</p>
<p>So here's the steps my object does:</p>... | 2 | 2009-09-06T17:35:26Z | 1,386,258 | <p>I agree that attribute access and everything that looks like it (i.e. properties in the Python context) should be fairly trivial. If a property is going to perform a potentially costly operation, use a method to make this explicit. I recommend a name like "fetch_XYZ" or "retrieve_XYZ", since "get_XYZ" is used in som... | 2 | 2009-09-06T17:57:43Z | [
"python",
"properties",
"initialization"
] |
Should properties do nontrivial initialization? | 1,386,210 | <p>I have an object that is basically a Python implementation of an Oracle sequence. For a variety of reasons, we have to get the nextval of an Oracle sequence, count up manually when determining primary keys, then update the sequence once the records have been inserted.</p>
<p>So here's the steps my object does:</p>... | 2 | 2009-09-06T17:35:26Z | 1,386,269 | <p>I think your doubts come from <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP-8</a>:</p>
<blockquote>
<pre><code> Note 3: Avoid using properties for computationally expensive
operations; the attribute notation makes the caller believe
that access is (relatively) cheap.
</code></pre>... | 4 | 2009-09-06T18:01:29Z | [
"python",
"properties",
"initialization"
] |
Should properties do nontrivial initialization? | 1,386,210 | <p>I have an object that is basically a Python implementation of an Oracle sequence. For a variety of reasons, we have to get the nextval of an Oracle sequence, count up manually when determining primary keys, then update the sequence once the records have been inserted.</p>
<p>So here's the steps my object does:</p>... | 2 | 2009-09-06T17:35:26Z | 1,389,673 | <p>I've decided that the key smell in the solution I'm proposing is that the property I was creating contained the word "next" in it. Thus, instead of making a <code>next_key</code> property, I've decided to turn my DatabaseIntrospector class into a KeyCounter class and implemented the iterator protocol (ie making a p... | 0 | 2009-09-07T14:29:54Z | [
"python",
"properties",
"initialization"
] |
PIL: Thumbnail and end up with a square image | 1,386,352 | <p>Calling</p>
<pre><code>image = Image.open(data)
image.thumbnail((36,36), Image.NEAREST)
</code></pre>
<p>will maintain the aspect ratio. But I need to end up displaying the image like this:</p>
<pre><code><img src="/media/image.png" style="height:36px; width:36px" />
</code></pre>
<p>Can I have a letterbox... | 41 | 2009-09-06T18:33:59Z | 1,386,382 | <p>Paste the image into a transparent image with the right size as a background</p>
<pre><code>from PIL import Image
size = (36, 36)
image = Image.open(data)
image.thumbnail(size, Image.ANTIALIAS)
background = Image.new('RGBA', size, (255, 255, 255, 0))
background.paste(
image,
((size[0] - image.size[0]) / 2, ... | 56 | 2009-09-06T18:45:01Z | [
"python",
"png",
"thumbnails",
"python-imaging-library",
"alpha"
] |
PIL: Thumbnail and end up with a square image | 1,386,352 | <p>Calling</p>
<pre><code>image = Image.open(data)
image.thumbnail((36,36), Image.NEAREST)
</code></pre>
<p>will maintain the aspect ratio. But I need to end up displaying the image like this:</p>
<pre><code><img src="/media/image.png" style="height:36px; width:36px" />
</code></pre>
<p>Can I have a letterbox... | 41 | 2009-09-06T18:33:59Z | 8,469,920 | <p>PIL already already has a function to do exactly that</p>
<pre><code>from PIL import Image, ImageOps
thumb = ImageOps.fit(image, size, Image.ANTIALIAS)
</code></pre>
| 96 | 2011-12-12T04:25:06Z | [
"python",
"png",
"thumbnails",
"python-imaging-library",
"alpha"
] |
PIL: Thumbnail and end up with a square image | 1,386,352 | <p>Calling</p>
<pre><code>image = Image.open(data)
image.thumbnail((36,36), Image.NEAREST)
</code></pre>
<p>will maintain the aspect ratio. But I need to end up displaying the image like this:</p>
<pre><code><img src="/media/image.png" style="height:36px; width:36px" />
</code></pre>
<p>Can I have a letterbox... | 41 | 2009-09-06T18:33:59Z | 28,247,523 | <p>Or this, maybe... (forgive spaghetti)</p>
<pre><code>from PIL import Image
def process_image(image, size):
if image.size[0] > size[0] or image.size[1] > size[1]:
#preserve original
thumb = img.copy()
thumb.thumbnail(size,Image.ANTIALIAS)
img = thumb.copy()
img_padded =... | 0 | 2015-01-31T02:26:01Z | [
"python",
"png",
"thumbnails",
"python-imaging-library",
"alpha"
] |
PIL: Thumbnail and end up with a square image | 1,386,352 | <p>Calling</p>
<pre><code>image = Image.open(data)
image.thumbnail((36,36), Image.NEAREST)
</code></pre>
<p>will maintain the aspect ratio. But I need to end up displaying the image like this:</p>
<pre><code><img src="/media/image.png" style="height:36px; width:36px" />
</code></pre>
<p>Can I have a letterbox... | 41 | 2009-09-06T18:33:59Z | 38,631,007 | <pre><code>from PIL import Image
import StringIO
def thumbnail_image():
image = Image.open("image.png")
image.thumbnail((300, 200))
thumb_buffer = StringIO.StringIO()
image.save(thumb_buffer, format=image.format)
fp = open("thumbnail.png", "w")
fp.write(thumb_buffer.getvalue())
fp.close()
... | 2 | 2016-07-28T08:30:28Z | [
"python",
"png",
"thumbnails",
"python-imaging-library",
"alpha"
] |
PIL: Image resizing : Algorithm similar to firefox's | 1,386,400 | <p>I'm getting about the same <em>bad looking</em> resizing from all the 4 algorithms of PIL</p>
<pre><code>>>> data = utils.fetch("http://wavestock.com/images/beta-icon.gif")
>>> image = Image.open(StringIO.StringIO(data)); image.save("/home/ptarjan/www/tmp/metaward/original.png")
>>>
>&... | 8 | 2009-09-06T18:58:37Z | 1,386,414 | <p>Try using the <code>resize()</code> method instead of <code>thumbnail()</code>. In my experience, they behave very differently.</p>
<p>Also, your code shows reading a .gif, but your original is .png. Make sure you really have all the original data before you start reducing it.</p>
| 0 | 2009-09-06T19:01:48Z | [
"python",
"image",
"thumbnails",
"python-imaging-library"
] |
PIL: Image resizing : Algorithm similar to firefox's | 1,386,400 | <p>I'm getting about the same <em>bad looking</em> resizing from all the 4 algorithms of PIL</p>
<pre><code>>>> data = utils.fetch("http://wavestock.com/images/beta-icon.gif")
>>> image = Image.open(StringIO.StringIO(data)); image.save("/home/ptarjan/www/tmp/metaward/original.png")
>>>
>&... | 8 | 2009-09-06T18:58:37Z | 1,386,756 | <p>I resized the "original" with Python and found the same results as you did. I also resized the "original" with GIMP and I got the same (if not inferior) quality. This made me suspect that Firefox cheats. Possibly it converts to RGB ("original" mode is indexed color). Thus the following code:</p>
<pre><code>import I... | 8 | 2009-09-06T21:21:59Z | [
"python",
"image",
"thumbnails",
"python-imaging-library"
] |
PIL: Image resizing : Algorithm similar to firefox's | 1,386,400 | <p>I'm getting about the same <em>bad looking</em> resizing from all the 4 algorithms of PIL</p>
<pre><code>>>> data = utils.fetch("http://wavestock.com/images/beta-icon.gif")
>>> image = Image.open(StringIO.StringIO(data)); image.save("/home/ptarjan/www/tmp/metaward/original.png")
>>>
>&... | 8 | 2009-09-06T18:58:37Z | 1,391,502 | <blockquote>
<p>It looks like the RGB and then ANTIALIS looks the best. Any other recommendations?</p>
</blockquote>
<p>No, that is indeed the expected result. Any resizing done in the original limited palette mode is likely to produce jaggy rubbish because of the lack of available in-between colours in the palette;... | 1 | 2009-09-08T01:07:27Z | [
"python",
"image",
"thumbnails",
"python-imaging-library"
] |
python Invalid literal for float | 1,386,420 | <p>I am running a code to select chunks from a big file. I am getting some strange error that is</p>
<pre><code>"Invalid literal for float(): E-135"
</code></pre>
<p>Does anybody know how to fix this? Thanks in advance.</p>
<p>Actually this is the statement that is giving me error</p>
<pre><code>float (line_temp[li... | 2 | 2009-09-06T19:04:34Z | 1,386,431 | <p>You need a number in front of the E to make it a valid string representation of a float number</p>
<pre><code>>>> float('1E-135')
1e-135
>>> float('E-135')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): E-135
</code></p... | 6 | 2009-09-06T19:09:49Z | [
"python"
] |
python Invalid literal for float | 1,386,420 | <p>I am running a code to select chunks from a big file. I am getting some strange error that is</p>
<pre><code>"Invalid literal for float(): E-135"
</code></pre>
<p>Does anybody know how to fix this? Thanks in advance.</p>
<p>Actually this is the statement that is giving me error</p>
<pre><code>float (line_temp[li... | 2 | 2009-09-06T19:04:34Z | 1,386,432 | <p>Looks like you are trying to convert a string to a float. If the string is <code>E-135</code>, then it is indeed an invalid value to be converted to a float. Perhaps you are chopping off a digit in the beginning of the string and it really ought to be something like <code>1E-135</code>? That would be a valid float... | 3 | 2009-09-06T19:10:10Z | [
"python"
] |
python Invalid literal for float | 1,386,420 | <p>I am running a code to select chunks from a big file. I am getting some strange error that is</p>
<pre><code>"Invalid literal for float(): E-135"
</code></pre>
<p>Does anybody know how to fix this? Thanks in advance.</p>
<p>Actually this is the statement that is giving me error</p>
<pre><code>float (line_temp[li... | 2 | 2009-09-06T19:04:34Z | 1,386,508 | <p>May I suggest you replace</p>
<pre><code>float(x-y)
</code></pre>
<p>with</p>
<pre><code>float(x) - float(y)
</code></pre>
| 1 | 2009-09-06T19:37:24Z | [
"python"
] |
python Invalid literal for float | 1,386,420 | <p>I am running a code to select chunks from a big file. I am getting some strange error that is</p>
<pre><code>"Invalid literal for float(): E-135"
</code></pre>
<p>Does anybody know how to fix this? Thanks in advance.</p>
<p>Actually this is the statement that is giving me error</p>
<pre><code>float (line_temp[li... | 2 | 2009-09-06T19:04:34Z | 1,386,830 | <p>Ronald, kindly check the answers again. They are right.
What you are doing is: float(EXPRESSION), where the result of EXPRESSION is E-135. E-135 is not valid input into the float() function. I have no idea what the "line_temp[line(line_temp)-1]" does, but it returns incorrect data for the float() function.</p>
| 1 | 2009-09-06T21:53:05Z | [
"python"
] |
Python: manipulating sub trees | 1,386,493 | <p>I'm a nooby. I'd like to acknowledge Allen Downey, Jeffrey Elkner and Chris Meyers
and 'How to think like a computer scientist' for what I know.</p>
<p>I'm building a genetics inspired program to generate equations that match some provided problem.</p>
<p>The node class looks like this:</p>
<pre><code>class Node(... | 0 | 2009-09-06T19:33:38Z | 1,386,777 | <p>If I understand correctly, you are looking for something like this...</p>
<p>(I have not tested this.)</p>
<pre><code>def swap_nodes(dict_1, key_1, dict_2, key_2):
node_1 = dict_1[key_1]
node_2 = dict_2[key_2]
# Update dicts and seq fields for the two nodes...
dict_1[key_1] = node_2
node_2.seq... | 0 | 2009-09-06T21:31:34Z | [
"python",
"data-structures",
"tree"
] |
Python: manipulating sub trees | 1,386,493 | <p>I'm a nooby. I'd like to acknowledge Allen Downey, Jeffrey Elkner and Chris Meyers
and 'How to think like a computer scientist' for what I know.</p>
<p>I'm building a genetics inspired program to generate equations that match some provided problem.</p>
<p>The node class looks like this:</p>
<pre><code>class Node(... | 0 | 2009-09-06T19:33:38Z | 1,386,787 | <p>Unfortunately you don't provide us with the <code>Tree</code> class, but let's assume it's something like:</p>
<pre><code>class Tree(object):
def __init__(self):
self.data = None
self.nextkey = 0
self.thedict = {}
</code></pre>
<p>with the various attributes being updated accurately when new nodes ar... | 1 | 2009-09-06T21:39:34Z | [
"python",
"data-structures",
"tree"
] |
Handling big numbers in code | 1,386,604 | <p>I'm working on a programming problem where I need to handle a number involving 100000 digits. Can python handle numbers like this?</p>
| 7 | 2009-09-06T20:13:19Z | 1,386,615 | <p>Sure it can:</p>
<pre><code>>>> s = 10 ** 100000
</code></pre>
| 3 | 2009-09-06T20:17:25Z | [
"python",
"algorithm"
] |
Handling big numbers in code | 1,386,604 | <p>I'm working on a programming problem where I need to handle a number involving 100000 digits. Can python handle numbers like this?</p>
| 7 | 2009-09-06T20:13:19Z | 1,386,618 | <p>It seems to work fine:</p>
<pre><code>>>> x = 10**100000
>>> x
10000000000000000000000000000000000000000000000000000000000000000000000000000000
[snip]
00000000L
</code></pre>
<p>According to <a href="http://docs.python.org/library/stdtypes.html" rel="nofollow">http://docs.python.org/library/stdty... | 3 | 2009-09-06T20:19:34Z | [
"python",
"algorithm"
] |
Handling big numbers in code | 1,386,604 | <p>I'm working on a programming problem where I need to handle a number involving 100000 digits. Can python handle numbers like this?</p>
| 7 | 2009-09-06T20:13:19Z | 1,386,629 | <p>Yes; Python 2.x has two types of integers, <strong>int</strong> of limited size and <strong>long</strong> of <strong>unlimited size</strong>. However all calculations will automatically convert to long if needed. Handling big numbers works fine, but one of the slower things will be if you try to print the 100000 dig... | 7 | 2009-09-06T20:22:55Z | [
"python",
"algorithm"
] |
Handling big numbers in code | 1,386,604 | <p>I'm working on a programming problem where I need to handle a number involving 100000 digits. Can python handle numbers like this?</p>
| 7 | 2009-09-06T20:13:19Z | 1,386,735 | <p>As other answers indicated, Python does support integer numbers bounded only by the amount of memory available. If you want even faster support for them, try <a href="http://code.google.com/p/gmpy/">gmpy</a> (as gmpy's author and current co-maintainer I'm of course a little biased here;-):</p>
<pre><code>$ python -... | 22 | 2009-09-06T21:12:35Z | [
"python",
"algorithm"
] |
Handling big numbers in code | 1,386,604 | <p>I'm working on a programming problem where I need to handle a number involving 100000 digits. Can python handle numbers like this?</p>
| 7 | 2009-09-06T20:13:19Z | 1,398,808 | <p>As already pointed out, Python can handle numbers as big as your memory will allow. I would just like to add that as the numbers grow bigger, the cost of all operations on them increases. This is not just for printing/converting to string (although that's the slowest), adding two large numbers (larger that what your... | 3 | 2009-09-09T10:25:48Z | [
"python",
"algorithm"
] |
Convert binary string to list of integers using Python | 1,386,811 | <p>I am new to Python. Here's what I am trying to do: </p>
<ol>
<li>Slice a long binary string into 3 digit-long chunks. </li>
<li>Store each "chunk" into a list called row. </li>
<li>Convert each binary chunk into a number (0-7).</li>
<li>Store the converted list of numbers into a new list called numbers. </li>
</ol>... | 5 | 2009-09-06T21:46:52Z | 1,386,828 | <p>Something like this should do it:</p>
<pre><code>s = "110101001"
numbers = [int(s[i:i+3], 2) for i in range(0, len(s), 3)]
print numbers
</code></pre>
<p>The output is:</p>
<pre><code>[6, 5, 1]
</code></pre>
<p>Breaking this down step by step, first:</p>
<pre><code>>>> range(0, len(s), 3)
[0, 3, 6]
</c... | 11 | 2009-09-06T21:51:21Z | [
"python"
] |
Convert binary string to list of integers using Python | 1,386,811 | <p>I am new to Python. Here's what I am trying to do: </p>
<ol>
<li>Slice a long binary string into 3 digit-long chunks. </li>
<li>Store each "chunk" into a list called row. </li>
<li>Convert each binary chunk into a number (0-7).</li>
<li>Store the converted list of numbers into a new list called numbers. </li>
</ol>... | 5 | 2009-09-06T21:46:52Z | 1,386,836 | <p>I'll assume that by "binary string" you actually mean a normal string (i.e. text) whose items are all '0' or '1'.</p>
<p>So for points 1 and 2,</p>
<pre><code>row = [thestring[i:i+3] for i in xrange(0, len(thestring), 3)]
</code></pre>
<p>of course the last item will be only 1 or 2 characters long if <code>len(th... | 7 | 2009-09-06T21:55:15Z | [
"python"
] |
Convert binary string to list of integers using Python | 1,386,811 | <p>I am new to Python. Here's what I am trying to do: </p>
<ol>
<li>Slice a long binary string into 3 digit-long chunks. </li>
<li>Store each "chunk" into a list called row. </li>
<li>Convert each binary chunk into a number (0-7).</li>
<li>Store the converted list of numbers into a new list called numbers. </li>
</ol>... | 5 | 2009-09-06T21:46:52Z | 1,386,897 | <p>Great answers from Greg and Alex! List comprehensions and slicing are so pythonic!
For short input strings I wouldn't bother with the dictionary lookup trick, but if the input string were longer, I would, as well as using gen-exps rather than list-comps, i.e.:</p>
<p>row = list(thestring[i:i+3] for i in xrange(0,... | 0 | 2009-09-06T22:30:15Z | [
"python"
] |
Convert binary string to list of integers using Python | 1,386,811 | <p>I am new to Python. Here's what I am trying to do: </p>
<ol>
<li>Slice a long binary string into 3 digit-long chunks. </li>
<li>Store each "chunk" into a list called row. </li>
<li>Convert each binary chunk into a number (0-7).</li>
<li>Store the converted list of numbers into a new list called numbers. </li>
</ol>... | 5 | 2009-09-06T21:46:52Z | 21,275,178 | <p>Wouldn't this be easier:</p>
<p>(I wanted an array of the upper 3 bits of a variable that contained the integer 29)</p>
<p>format your variables and arrays first</p>
<p>a = ''</p>
<p>b = []</p>
<p>I stole this from a really good example in this forum, it formats the integer 29 into 5 bits, bits zero through fou... | 0 | 2014-01-22T05:48:19Z | [
"python"
] |
Convert binary string to list of integers using Python | 1,386,811 | <p>I am new to Python. Here's what I am trying to do: </p>
<ol>
<li>Slice a long binary string into 3 digit-long chunks. </li>
<li>Store each "chunk" into a list called row. </li>
<li>Convert each binary chunk into a number (0-7).</li>
<li>Store the converted list of numbers into a new list called numbers. </li>
</ol>... | 5 | 2009-09-06T21:46:52Z | 21,275,703 | <p>If you're dealing with processing raw data of any kind, I'd like to recommend the excellent <a href="https://pypi.python.org/pypi/bitstring" rel="nofollow">bitstring</a> module:</p>
<pre><code>>>> import bitstring
>>> bits = bitstring.Bits('0b110101001')
>>> [b.uint for b in bits.cut(3)]
... | 1 | 2014-01-22T06:24:37Z | [
"python"
] |
Django : select_related with ManyToManyField | 1,387,044 | <p>I have :</p>
<pre><code>class Award(models.Model) :
name = models.CharField(max_length=100, db_index=True)
class Alias(models.Model) :
awards = models.ManyToManyField('Award', through='Achiever')
class Achiever(models.Model):
award = models.ForeignKey(Award)
alias = models.ForeignKey(Alias)
co... | 13 | 2009-09-06T23:52:55Z | 1,391,125 | <p>Can you try to write more detailed about needed effect? Do you want to make simply three table join, or do you need to get correct paris from the Achiever table?</p>
<p>You can use additional methods based on ManyToMany and ForeignsKey relations.</p>
| -1 | 2009-09-07T22:10:00Z | [
"python",
"django",
"django-models",
"django-select-related"
] |
Django : select_related with ManyToManyField | 1,387,044 | <p>I have :</p>
<pre><code>class Award(models.Model) :
name = models.CharField(max_length=100, db_index=True)
class Alias(models.Model) :
awards = models.ManyToManyField('Award', through='Achiever')
class Achiever(models.Model):
award = models.ForeignKey(Award)
alias = models.ForeignKey(Alias)
co... | 13 | 2009-09-06T23:52:55Z | 9,431,210 | <p>Django versions 1.4 and above have <a href="https://docs.djangoproject.com/en/1.4/ref/models/querysets/#prefetch-related"><code>prefetch_related</code></a> for this purpose.</p>
<p>The <a href="https://docs.djangoproject.com/en/1.4/ref/models/querysets/#prefetch-related"><code>prefetch_related</code></a> method is ... | 18 | 2012-02-24T13:00:05Z | [
"python",
"django",
"django-models",
"django-select-related"
] |
Django : select_related with ManyToManyField | 1,387,044 | <p>I have :</p>
<pre><code>class Award(models.Model) :
name = models.CharField(max_length=100, db_index=True)
class Alias(models.Model) :
awards = models.ManyToManyField('Award', through='Achiever')
class Achiever(models.Model):
award = models.ForeignKey(Award)
alias = models.ForeignKey(Alias)
co... | 13 | 2009-09-06T23:52:55Z | 10,133,687 | <p>If you're not on Django 1.4, there's also the <a href="https://github.com/lilspikey/django-batch-select" rel="nofollow">django-batch-select</a> library, which works basically the same way as prefetch_related.</p>
| 3 | 2012-04-13T00:23:20Z | [
"python",
"django",
"django-models",
"django-select-related"
] |
Reliably detect Windows in Python | 1,387,222 | <p>I'm working on a couple of Linux tools and need to prevent installation on Windows, since it depends on FHS and is thus rendered useless on that platform. The <code>platform.platform</code> function comes close but only returns a string.</p>
<p>Unfortunately I don't know what to search for in that string for it to ... | 30 | 2009-09-07T01:29:16Z | 1,387,224 | <p>Try this:</p>
<pre><code>import platform
if platform.system() == "Darwin":
# Don't have Windows handy, but I'd expect "Win32" or "Windows" for it
</code></pre>
<p><strong>Edit:</strong> Just saw that you tried <code>platform.platform()</code>...<code>platform.system()</code> will work better for this case. T... | 8 | 2009-09-07T01:31:03Z | [
"python",
"windows",
"platform-detection"
] |
Reliably detect Windows in Python | 1,387,222 | <p>I'm working on a couple of Linux tools and need to prevent installation on Windows, since it depends on FHS and is thus rendered useless on that platform. The <code>platform.platform</code> function comes close but only returns a string.</p>
<p>Unfortunately I don't know what to search for in that string for it to ... | 30 | 2009-09-07T01:29:16Z | 1,387,226 | <p>On my Windows box, <code>platform.system()</code> returns <code>'Windows'</code>.</p>
<p>However, I'm not sure why you'd bother. If you want to limit the platform it runs on technologically, I'd use a white-list rather than a black-list.</p>
<p>In fact, I wouldn't do it technologically at all since perhaps the nex... | 17 | 2009-09-07T01:32:49Z | [
"python",
"windows",
"platform-detection"
] |
Reliably detect Windows in Python | 1,387,222 | <p>I'm working on a couple of Linux tools and need to prevent installation on Windows, since it depends on FHS and is thus rendered useless on that platform. The <code>platform.platform</code> function comes close but only returns a string.</p>
<p>Unfortunately I don't know what to search for in that string for it to ... | 30 | 2009-09-07T01:29:16Z | 1,387,228 | <pre><code>>>> import platform
>>> platform.system()
'Windows'
</code></pre>
| 47 | 2009-09-07T01:33:31Z | [
"python",
"windows",
"platform-detection"
] |
Reliably detect Windows in Python | 1,387,222 | <p>I'm working on a couple of Linux tools and need to prevent installation on Windows, since it depends on FHS and is thus rendered useless on that platform. The <code>platform.platform</code> function comes close but only returns a string.</p>
<p>Unfortunately I don't know what to search for in that string for it to ... | 30 | 2009-09-07T01:29:16Z | 3,469,295 | <p>From help(platform)</p>
<pre><code>system()
Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'.
An empty string is returned if the value cannot be determined.
</code></pre>
| 2 | 2010-08-12T15:24:22Z | [
"python",
"windows",
"platform-detection"
] |
Reliably detect Windows in Python | 1,387,222 | <p>I'm working on a couple of Linux tools and need to prevent installation on Windows, since it depends on FHS and is thus rendered useless on that platform. The <code>platform.platform</code> function comes close but only returns a string.</p>
<p>Unfortunately I don't know what to search for in that string for it to ... | 30 | 2009-09-07T01:29:16Z | 4,865,804 | <pre><code>>>> import os
>>> os.name
'nt'
</code></pre>
<p>"The name of the operating system dependent module imported. The following names have currently been registered: 'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos'." (c) <a href="http://docs.python.org/library/os.html#os.name" rel="nofollow"... | 4 | 2011-02-01T17:23:47Z | [
"python",
"windows",
"platform-detection"
] |
Reliably detect Windows in Python | 1,387,222 | <p>I'm working on a couple of Linux tools and need to prevent installation on Windows, since it depends on FHS and is thus rendered useless on that platform. The <code>platform.platform</code> function comes close but only returns a string.</p>
<p>Unfortunately I don't know what to search for in that string for it to ... | 30 | 2009-09-07T01:29:16Z | 7,637,706 | <p>For those that came here looking for a way to detect Cygwin from Python (as opposed to just detecting Windows), here are some example return values from <code>os.name</code> and <code>platform.system</code> on different platforms</p>
<pre><code>OS/build | os.name | platform.system()
-------------+---------+---... | 36 | 2011-10-03T16:18:44Z | [
"python",
"windows",
"platform-detection"
] |
Globbing the processing of an object's attributes in Python? | 1,387,315 | <p>Here is a Django model I'm using.</p>
<pre><code>class Person(models.Model):
surname = models.CharField(max_length=255, null=True, blank=True)
first_name = models.CharField(max_length=255, null=True, blank=True)
middle_names = models.CharField(max_length=255, null=True, blank=True)
birth_year = Wide... | 1 | 2009-09-07T02:18:55Z | 1,387,326 | <pre><code>for n in dir(self):
if getattr(self, n) is None:
setattr(self, n, '')
</code></pre>
<p>I'm using the normal <code>is None</code> idiom, assuming there's no hypersubtle motivation for that weird alternative you're using, but that's a separate issue;-)</p>
<p><strong>Edit</strong>: if you're using a fr... | 5 | 2009-09-07T02:21:59Z | [
"python",
"oop",
"django-models"
] |
MySQL INSERT data does not get stored in proper db, only temporary? | 1,387,573 | <p>I'm having trouble with MySQL or Python and can't seem to isolate the problem. <code>INSERT</code>s only seem to last the run of the script and are not stored in the database.</p>
<p>I have this script:</p>
<pre><code>import MySQLdb
db = MySQLdb.connect(host="localhost", user="user", passwd="password", db="example... | 2 | 2009-09-07T04:37:21Z | 1,387,579 | <p>You are not committing the transaction. </p>
<pre><code>conn = MySQLdb.connect (host = "localhost",
user = "testuser",
passwd = "testpass",
db = "test")
cursor = conn.cursor()
cursor.execute(...)
conn.commit()
</code></pre>
<p><a href="http:... | 8 | 2009-09-07T04:40:32Z | [
"python",
"mysql"
] |
MySQL INSERT data does not get stored in proper db, only temporary? | 1,387,573 | <p>I'm having trouble with MySQL or Python and can't seem to isolate the problem. <code>INSERT</code>s only seem to last the run of the script and are not stored in the database.</p>
<p>I have this script:</p>
<pre><code>import MySQLdb
db = MySQLdb.connect(host="localhost", user="user", passwd="password", db="example... | 2 | 2009-09-07T04:37:21Z | 1,387,589 | <p>I think you need to call</p>
<p>db.commit()</p>
| 3 | 2009-09-07T04:46:49Z | [
"python",
"mysql"
] |
MySQL INSERT data does not get stored in proper db, only temporary? | 1,387,573 | <p>I'm having trouble with MySQL or Python and can't seem to isolate the problem. <code>INSERT</code>s only seem to last the run of the script and are not stored in the database.</p>
<p>I have this script:</p>
<pre><code>import MySQLdb
db = MySQLdb.connect(host="localhost", user="user", passwd="password", db="example... | 2 | 2009-09-07T04:37:21Z | 13,190,127 | <p>The problem is you are not committing the changes. it can be done by
conn.commit()</p>
<p>read more on this <a href="http://sahanlm.blogspot.com/2012/10/mysqldb-does-not-commit-then-read-this.html" rel="nofollow">here</a></p>
| 2 | 2012-11-02T06:02:19Z | [
"python",
"mysql"
] |
Verify CSV against given format | 1,387,644 | <p>I am expecting users to upload a CSV file of max size 1MB to a web form that should fit a given format similar to:</p>
<pre><code>"<String>","<String>",<Int>,<Float>
</code></pre>
<p>That will be processed later. I would like to verify the file fits a specified format so that the program th... | 0 | 2009-09-07T05:17:30Z | 1,387,669 | <p>Ideally, you want your filtering to be as restrictive as possible - the fewer things you allow, the fewer potential avenues of attack. For instance, a float or int field has a very small number of characters (and very few configurations of those characters) which should actually be allowed. String filtering should i... | 0 | 2009-09-07T05:28:10Z | [
"python",
"regex",
"csv"
] |
Verify CSV against given format | 1,387,644 | <p>I am expecting users to upload a CSV file of max size 1MB to a web form that should fit a given format similar to:</p>
<pre><code>"<String>","<String>",<Int>,<Float>
</code></pre>
<p>That will be processed later. I would like to verify the file fits a specified format so that the program th... | 0 | 2009-09-07T05:17:30Z | 1,387,719 | <p>I'd vote for parsing the file, checking you've got 4 components per record, that the first two components are strings, the third is an int (checking for NaN conditions), and the fourth is a float (also checking for NaN conditions).</p>
<p>Python would be an excellent tool for the job.</p>
<p>I'm not aware of any l... | 2 | 2009-09-07T05:48:01Z | [
"python",
"regex",
"csv"
] |
Verify CSV against given format | 1,387,644 | <p>I am expecting users to upload a CSV file of max size 1MB to a web form that should fit a given format similar to:</p>
<pre><code>"<String>","<String>",<Int>,<Float>
</code></pre>
<p>That will be processed later. I would like to verify the file fits a specified format so that the program th... | 0 | 2009-09-07T05:17:30Z | 1,387,737 | <p>Here's a small snippet I made:</p>
<pre><code>import csv
f = csv.reader(open("test.csv"))
for value in f:
value[0] = str(value[0])
value[1] = str(value[1])
value[2] = int(value[2])
value[3] = float(value[3])
</code></pre>
<p>If you run that with a file that doesn't have the format your specified... | 1 | 2009-09-07T05:53:40Z | [
"python",
"regex",
"csv"
] |
Verify CSV against given format | 1,387,644 | <p>I am expecting users to upload a CSV file of max size 1MB to a web form that should fit a given format similar to:</p>
<pre><code>"<String>","<String>",<Int>,<Float>
</code></pre>
<p>That will be processed later. I would like to verify the file fits a specified format so that the program th... | 0 | 2009-09-07T05:17:30Z | 1,387,762 | <p>There can be a lot of corner-cases for parsing CSV, so you probably don't want to try doing it "by hand". At least start with a package/library built-in to the language that you're using, even if it doesn't do all the "verification" you can think of.</p>
<p>Once you get there, then examine the fields for your list... | 1 | 2009-09-07T06:05:08Z | [
"python",
"regex",
"csv"
] |
Verify CSV against given format | 1,387,644 | <p>I am expecting users to upload a CSV file of max size 1MB to a web form that should fit a given format similar to:</p>
<pre><code>"<String>","<String>",<Int>,<Float>
</code></pre>
<p>That will be processed later. I would like to verify the file fits a specified format so that the program th... | 0 | 2009-09-07T05:17:30Z | 1,389,585 | <p>Try <a href="http://cutplace.sourceforge.net/" rel="nofollow">Cutplace</a>. It verifies that tabluar data conforms to an <em>interface control document</em>.</p>
| 1 | 2009-09-07T14:05:57Z | [
"python",
"regex",
"csv"
] |
Verify CSV against given format | 1,387,644 | <p>I am expecting users to upload a CSV file of max size 1MB to a web form that should fit a given format similar to:</p>
<pre><code>"<String>","<String>",<Int>,<Float>
</code></pre>
<p>That will be processed later. I would like to verify the file fits a specified format so that the program th... | 0 | 2009-09-07T05:17:30Z | 1,389,940 | <p>Pyparsing will process this data, and will be tolerant of unexpected things like spaces before and after commas, commas within quotes, etc. (csv module is too, but regex solutions force you to add "\s*" bits all over the place).</p>
<pre><code>from pyparsing import *
integer = Regex(r"-?\d+").setName("integer")
i... | 3 | 2009-09-07T15:46:20Z | [
"python",
"regex",
"csv"
] |
PyGTK: IM Client Window | 1,387,729 | <p>I'm trying to write something very similar to an IM client (for learning purposes only). I don't know how to write the Chat window. I want to display Users picture, name and message as any other IM client. The problem is that I don't know which gtk widget is best suited for it. Currently I use TextView and TextBuffe... | 0 | 2009-09-07T05:51:09Z | 1,389,972 | <p>You can display images in a gtk.TextBuffer, here is how: <a href="http://pygtk.org/pygtk2tutorial/sec-TextBuffers.html#id2855808" rel="nofollow">http://pygtk.org/pygtk2tutorial/sec-TextBuffers.html#id2855808</a></p>
| 2 | 2009-09-07T15:53:27Z | [
"python",
"gtk",
"pygtk"
] |
Applescript - pygame, application bundle | 1,387,775 | <p>I'm trying to learn pygame, And I found the best way to have the finished game (assuming python 2.6 and pygame installed) is to have an applescript that runs it, and saved as an app bundle (with python files etc. inside the bundle). Here is what I have:</p>
<pre><code>do shell script "cd " & the quoted form of ... | 0 | 2009-09-07T06:11:16Z | 1,387,857 | <p><a href="http://www.pyinstaller.org/" rel="nofollow">pyinstaller</a> should let you bundle pygame (use the SVN version: the released one is WAY out of date). Also, I suggest you have your code find relative directories more nicely:</p>
<pre><code>import os
resourcesdir = os.path.join(os.path.dirname(__file__), 'Res... | 1 | 2009-09-07T06:38:48Z | [
"python",
"osx",
"applescript",
"pygame"
] |
how to convert base64 /radix64 public key to a pem format in python | 1,387,867 | <p>is there any python method for converting base64 encoded key to a pem format .</p>
<p>how to convert ASCII-armored PGP public key to a MIME encoded form.</p>
<p>thanks</p>
| 0 | 2009-09-07T06:41:35Z | 1,389,908 | <p>ASCII-armored and PEM are very similar. You just need to change the BEGIN/END markers, strip the PGP headers and checksums. I've done this before in PHP. I just ported it to Python for you,</p>
<pre><code>import re
import StringIO
def pgp_pubkey_to_pem(pgp_key):
# Normalise newlines
pgp_key = re.compile('(... | 5 | 2009-09-07T15:33:57Z | [
"python",
"encoding"
] |
IF statement causing internal server error with webpy | 1,387,902 | <p>I have this class:</p>
<pre><code>class View(object):
def main_page(self, extra_placeholders = None):
file = '/media/Shared/sites/www/subdomains/pypular/static/layout.tmpl'
placeholders = { 'site_name' : 'pypular' }
# If we passed placeholders vars, append them
if extra_placeholders != N... | 1 | 2009-09-07T06:54:40Z | 1,387,918 | <p>should you be using instead</p>
<pre><code>if !( extra_placeholders is None) :
</code></pre>
<p>See <a href="http://boodebr.org/main/python/tourist/none-empty-nothing" rel="nofollow">here</a></p>
<p>Edit: To reflect comment:</p>
<p>It appears (thanks) that you can also use:</p>
<pre><code> if extra_placehold... | 1 | 2009-09-07T07:01:22Z | [
"python",
"mod-wsgi",
"web.py"
] |
C++ with Python embedding: crash if Python not installed | 1,387,906 | <p>I'm developing on Windows, and I've searched everywhere without finding anyone talking about this kind of thing.</p>
<p>I made a C++ app on my desktop that embedded Python 3.1 using MSVC. I linked python31.lib and included python31.dll in the app's run folder alongside the executable. It works great. My extension a... | 14 | 2009-09-07T06:56:51Z | 1,387,977 | <p>In addition to pythonxy.dll, you also need the entire Python library, i.e. the contents of the lib folder, plus the extension modules, i.e. the contents of the DLLs folder. Without the standard library, Python won't even start, since it tries to find os.py (in 3.x; string.py in 2.x). On startup, it imports a number ... | 18 | 2009-09-07T07:16:51Z | [
"c++",
"python",
"dll",
"embed",
"distribution"
] |
C++ with Python embedding: crash if Python not installed | 1,387,906 | <p>I'm developing on Windows, and I've searched everywhere without finding anyone talking about this kind of thing.</p>
<p>I made a C++ app on my desktop that embedded Python 3.1 using MSVC. I linked python31.lib and included python31.dll in the app's run folder alongside the executable. It works great. My extension a... | 14 | 2009-09-07T06:56:51Z | 2,970,407 | <p>Nice. And if you do not want to zip, copy Python26\DLLs & Python26\lib to your exe directory as:</p>
<pre><code>.\myexe.exe
.\python26.dll
.\Python26\DLLs
.\Python26\lib
</code></pre>
<p>And then set PYTHONHOME with Py_SetPythonHome() API. Apparently, this API is not in the list of "allowed" calls <stro... | 10 | 2010-06-03T23:02:34Z | [
"c++",
"python",
"dll",
"embed",
"distribution"
] |
C++ with Python embedding: crash if Python not installed | 1,387,906 | <p>I'm developing on Windows, and I've searched everywhere without finding anyone talking about this kind of thing.</p>
<p>I made a C++ app on my desktop that embedded Python 3.1 using MSVC. I linked python31.lib and included python31.dll in the app's run folder alongside the executable. It works great. My extension a... | 14 | 2009-09-07T06:56:51Z | 9,115,925 | <p>A zip of the Python standard library worked for me with Python27.</p>
<p>I zipped <strong>the contents</strong> of Lib and dll, and made sure there was no additional python27-subfolder or Lib or dll subfolder. i.e. just a zip named python27.zip containing all the files.</p>
<p>I copied that zip and the python27.dl... | 4 | 2012-02-02T16:25:54Z | [
"c++",
"python",
"dll",
"embed",
"distribution"
] |
C++ with Python embedding: crash if Python not installed | 1,387,906 | <p>I'm developing on Windows, and I've searched everywhere without finding anyone talking about this kind of thing.</p>
<p>I made a C++ app on my desktop that embedded Python 3.1 using MSVC. I linked python31.lib and included python31.dll in the app's run folder alongside the executable. It works great. My extension a... | 14 | 2009-09-07T06:56:51Z | 12,539,448 | <p>I wanted to add some additional info for others who might still be having troubles with this, as I was. I was eventually able to get my application working using the method proposed by user sambha, that is:</p>
<pre>
Program Files (x86)\
MyApplicationFolder\
MyApplication.exe
python27.dll
... | 5 | 2012-09-21T23:39:36Z | [
"c++",
"python",
"dll",
"embed",
"distribution"
] |
Django: Simple rate limiting | 1,387,937 | <p>Many of my views fetch external resources. I want to make sure that under heavy load I don't blow up the remote sites (and/or get banned).</p>
<p>I only have 1 crawler so having a central lock will work fine.</p>
<p>So the details: I want to allow at most 3 queries to a host per second, and have the rest block for... | 4 | 2009-09-07T07:08:12Z | 1,388,111 | <p>What about using a different process to handle scraping, and a queue for the communication between it and Django?<br />
This way you would be able to easily change the number of concurrent requests, and it would also automatically keep track of the requests, without blocking the caller.<br />
Most of all, I think it... | 1 | 2009-09-07T08:00:28Z | [
"python",
"django",
"caching",
"mutex",
"semaphore"
] |
Django: Simple rate limiting | 1,387,937 | <p>Many of my views fetch external resources. I want to make sure that under heavy load I don't blow up the remote sites (and/or get banned).</p>
<p>I only have 1 crawler so having a central lock will work fine.</p>
<p>So the details: I want to allow at most 3 queries to a host per second, and have the rest block for... | 4 | 2009-09-07T07:08:12Z | 1,388,112 | <p>One approach; create a table like this:</p>
<pre><code>class Queries(models.Model):
site = models.CharField(max_length=200, db_index=True)
start_time = models.DateTimeField(null = True)
finished = models.BooleanField(default=False)
</code></pre>
<p>This records when each query has either taken place, o... | 1 | 2009-09-07T08:00:29Z | [
"python",
"django",
"caching",
"mutex",
"semaphore"
] |
Upgrade python in linux | 1,388,464 | <p>I have a linux VPS that uses an older version of python (2.4.3). This version doesn't include the UUID module, but I need it for a project. My options are to upgrade to python2.6 or find a way to make uuid work with the older version. I am a complete linux newbie. I don't know how to upgrade python safely or how I c... | 2 | 2009-09-07T09:36:41Z | 1,388,489 | <p>The UUID module exists as a separate package for Python 2.3 and up:</p>
<p><a href="http://pypi.python.org/pypi/uuid/1.30" rel="nofollow">http://pypi.python.org/pypi/uuid/1.30</a></p>
<p>So you can either install that in your Python2.4, or install Python2.6. If your distro doesn't have it, then Python is quite sim... | 2 | 2009-09-07T09:42:19Z | [
"python",
"linux"
] |
Upgrade python in linux | 1,388,464 | <p>I have a linux VPS that uses an older version of python (2.4.3). This version doesn't include the UUID module, but I need it for a project. My options are to upgrade to python2.6 or find a way to make uuid work with the older version. I am a complete linux newbie. I don't know how to upgrade python safely or how I c... | 2 | 2009-09-07T09:36:41Z | 1,388,552 | <p>The safest way to upgrading Python is to install it to a different location (away from the default system path).</p>
<p>To do this, download the source of python and do a </p>
<p>./configure --prefix=/opt</p>
<p>(Assuming you want to install it to /opt which is where most install non system dependant stuff to)</p... | 6 | 2009-09-07T10:02:02Z | [
"python",
"linux"
] |
Upgrade python in linux | 1,388,464 | <p>I have a linux VPS that uses an older version of python (2.4.3). This version doesn't include the UUID module, but I need it for a project. My options are to upgrade to python2.6 or find a way to make uuid work with the older version. I am a complete linux newbie. I don't know how to upgrade python safely or how I c... | 2 | 2009-09-07T09:36:41Z | 1,391,295 | <p>The best solution will be installing python2.6 in the choosen directory - It will you give you access to many great features and better memory handling (infamous python=2.4 memory leak problem).</p>
<p>I have got several pythons installed onto my two computers, I found that the best solution for are two directories... | 0 | 2009-09-07T23:24:54Z | [
"python",
"linux"
] |
How to get output from subprocess.Popen() | 1,388,753 | <p>I want output from execute Test_Pipe.py, I tried following code on Linux but it did not work. </p>
<p><strong>Test_Pipe.py</strong></p>
<pre><code>import time
while True :
print "Someting ..."
time.sleep(.1)
</code></pre>
<p><strong>Caller.py</strong></p>
<pre><code>import subprocess as subp
import time
... | 26 | 2009-09-07T10:50:52Z | 1,388,807 | <p>You obviously can use subprocess.communicate but I think you are looking for real time input and output.</p>
<p>readline was blocked because the process is probably waiting on your input. You can read character by character to overcome this like the following:</p>
<pre><code>import subprocess
import sys
process =... | 29 | 2009-09-07T11:04:18Z | [
"python",
"linux",
"subprocess",
"popen"
] |
How to get output from subprocess.Popen() | 1,388,753 | <p>I want output from execute Test_Pipe.py, I tried following code on Linux but it did not work. </p>
<p><strong>Test_Pipe.py</strong></p>
<pre><code>import time
while True :
print "Someting ..."
time.sleep(.1)
</code></pre>
<p><strong>Caller.py</strong></p>
<pre><code>import subprocess as subp
import time
... | 26 | 2009-09-07T10:50:52Z | 1,390,035 | <p>To avoid the many problems that can always arise with buffering for tasks such as "getting the subprocess's output to the main process in real time", I always recommend using <a href="http://sourceforge.net/projects/pexpect/" rel="nofollow">pexpect</a> for all non-Windows platform, <a href="http://sage.math.washingt... | 11 | 2009-09-07T16:10:41Z | [
"python",
"linux",
"subprocess",
"popen"
] |
How to get output from subprocess.Popen() | 1,388,753 | <p>I want output from execute Test_Pipe.py, I tried following code on Linux but it did not work. </p>
<p><strong>Test_Pipe.py</strong></p>
<pre><code>import time
while True :
print "Someting ..."
time.sleep(.1)
</code></pre>
<p><strong>Caller.py</strong></p>
<pre><code>import subprocess as subp
import time
... | 26 | 2009-09-07T10:50:52Z | 3,536,709 | <p>Nadia's snippet does work but calling read with a 1 byte buffer is highly unrecommended. The better way to do this would be to set the stdout file descriptor to nonblocking using fcntl</p>
<pre><code>fcntl.fcntl(
proc.stdout.fileno(),
fcntl.F_SETFL,
fcntl.fcntl(proc.stdout.fileno(), fcntl.F_GETFL) | os.... | 17 | 2010-08-21T07:03:19Z | [
"python",
"linux",
"subprocess",
"popen"
] |
How to get output from subprocess.Popen() | 1,388,753 | <p>I want output from execute Test_Pipe.py, I tried following code on Linux but it did not work. </p>
<p><strong>Test_Pipe.py</strong></p>
<pre><code>import time
while True :
print "Someting ..."
time.sleep(.1)
</code></pre>
<p><strong>Caller.py</strong></p>
<pre><code>import subprocess as subp
import time
... | 26 | 2009-09-07T10:50:52Z | 17,701,672 | <p><code>Test_Pipe.py</code> buffers its stdout by default so <code>proc</code> in <code>Caller.py</code> don't see any output until the child's buffer is full (if the buffer size is 8KB then it takes around a minute to fill <code>Test_Pipe.py</code>'s stdout buffer).</p>
<p>To make the output unbuffered (line-buffere... | 2 | 2013-07-17T13:53:02Z | [
"python",
"linux",
"subprocess",
"popen"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 1,388,836 | <p>Not the most efficient one, but by far the most obvious way to do it is:</p>
<pre><code>>>> a = [1, 2, 3, 4, 5]
>>> b = [9, 8, 7, 6, 5]
>>> set(a) & set(b)
{5}
</code></pre>
<p>if order is significant you can do it with list comprehensions like this:</p>
<pre><code>>>> [i f... | 210 | 2009-09-07T11:10:46Z | [
"python",
"list"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 1,388,837 | <p>The easiest way to do that is to use <a href="http://docs.python.org/library/stdtypes.html#set-types-set-frozenset">sets</a>:</p>
<pre><code>>>> a = [1, 2, 3, 4, 5]
>>> b = [9, 8, 7, 6, 5]
>>> set(a) & set(b)
set([5])
</code></pre>
| 9 | 2009-09-07T11:10:53Z | [
"python",
"list"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 1,388,842 | <p>Use <a href="http://docs.python.org/library/stdtypes.html#set.intersection">set.intersection()</a>, it's fast and readable.</p>
<pre><code>>>> set(a).intersection(b)
set([5])
</code></pre>
| 190 | 2009-09-07T11:11:36Z | [
"python",
"list"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 1,388,848 | <p>Quick way:</p>
<pre><code>list(set(a).intersection(set(b)))
</code></pre>
| 8 | 2009-09-07T11:12:28Z | [
"python",
"list"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 1,388,856 | <p>Do you want duplicates? If not maybe you should use sets instead:</p>
<pre><code>
>>> set([1, 2, 3, 4, 5]).intersection(set([9, 8, 7, 6, 5]))
set([5])
</code></pre>
| 5 | 2009-09-07T11:14:14Z | [
"python",
"list"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 1,388,864 | <p>You can use </p>
<pre><code>def returnMatches(a,b):
return list(set(a) & set(b))
</code></pre>
| 3 | 2009-09-07T11:16:17Z | [
"python",
"list"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 3,056,197 | <pre><code>>>> s = ['a','b','c']
>>> f = ['a','b','d','c']
>>> ss= set(s)
>>> fs =set(f)
>>> print ss.intersection(fs)
**set(['a', 'c', 'b'])**
>>> print ss.union(fs)
**set(['a', 'c', 'b', 'd'])**
>>> print ss.union(fs) - ss.i... | 7 | 2010-06-16T18:41:45Z | [
"python",
"list"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 3,834,580 | <p>I prefer the set based answers, but here's one that works anyway</p>
<pre><code>[x for x in a if x in b]
</code></pre>
| 30 | 2010-09-30T20:28:23Z | [
"python",
"list"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 5,142,340 | <p>Also you can try this,by keeping common elements in a new list. </p>
<pre><code>new_list = []
for element in a:
if element in b:
new_list.append(element)
</code></pre>
| 5 | 2011-02-28T13:04:00Z | [
"python",
"list"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 10,872,313 | <p>A quick performance test showing Lutz's solution is the best:</p>
<pre><code>import time
def speed_test(func):
def wrapper(*args, **kwargs):
t1 = time.time()
for x in xrange(5000):
results = func(*args, **kwargs)
t2 = time.time()
print '%s took %0.3f ms' % (func.func... | 51 | 2012-06-03T17:12:23Z | [
"python",
"list"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 34,631,617 | <p>You can use:</p>
<pre><code>a = [1, 3, 4, 5, 9, 6, 7, 8]
b = [1, 7, 0, 9]
same_values = set(a) & set(b)
print same_values
</code></pre>
<p>Output:</p>
<pre><code>set([1, 7, 9])
</code></pre>
| 0 | 2016-01-06T11:07:15Z | [
"python",
"list"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 38,180,267 | <p>another a bit more functional way to check list equality for list 1 (lst1) and list 2 (lst2) where objects have depth one and which keeps the order is:</p>
<pre><code>all(i == j for i, j in zip(lst1, lst2))
</code></pre>
| 0 | 2016-07-04T08:41:34Z | [
"python",
"list"
] |
How can I compare two lists in python and return matches | 1,388,818 | <p>I want to take two lists and find the values that appear in both.</p>
<pre><code>a = [1, 2, 3, 4, 5]
b = [9, 8, 7, 6, 5]
returnMatches(a, b)
</code></pre>
<p>would return <code>[5]</code>, for instance.</p>
| 168 | 2009-09-07T11:07:27Z | 38,181,023 | <p>Can use itertools.product too.</p>
<pre><code>>>> common_elements=[]
>>> for i in list(itertools.product(a,b)):
... if i[0] == i[1]:
... common_elements.append(i[0])
</code></pre>
| 0 | 2016-07-04T09:18:34Z | [
"python",
"list"
] |
how do I determine whether a python script is imported as module or run as script? | 1,389,044 | <p>The question is rather straightforward but not answered by searching. How do I determine in a python script whether this script is imported as a module or run as a script? Is there a difference at all in python?</p>
<p>The problem is, that I want to evaluate the command line parameters only if run as a script, but ... | 13 | 2009-09-07T11:58:18Z | 1,389,048 | <p>from python <a href="http://docs.python.org/dev/tutorial/modules.html#executing-modules-as-scripts">docs</a>:</p>
<blockquote>
<p>When you run a Python module with</p>
<p>python fibo.py </p>
<p>the code in the module will be
executed, just as if you imported it,
but with the <code>__name__</code> se... | 24 | 2009-09-07T11:59:19Z | [
"python",
"module"
] |
How can I tokenize this with a regex? | 1,389,062 | <p>Suppose I have strings like the following :</p>
<pre><code>OneTwo
ThreeFour
AnotherString
DVDPlayer
CDPlayer
</code></pre>
<p>I know how to tokenize the camel-case ones, except the "DVDPlayer" and "CDPlayer". I know I could tokenize them manually, but maybe you can show me a regex that can handle all the cases?</p... | 1 | 2009-09-07T12:02:18Z | 1,389,075 | <p>Try a non-greedy look ahead. A token would be one or more uppercase characters followed by zero or more lowercase characters. The token would terminate when the next two character are an upper case and lower case - matching this section is what the non-greedy matching can be used. This approach has limitation but it... | 0 | 2009-09-07T12:05:41Z | [
"python",
"ruby",
"regex",
"tokenize",
"lexical-analysis"
] |
How can I tokenize this with a regex? | 1,389,062 | <p>Suppose I have strings like the following :</p>
<pre><code>OneTwo
ThreeFour
AnotherString
DVDPlayer
CDPlayer
</code></pre>
<p>I know how to tokenize the camel-case ones, except the "DVDPlayer" and "CDPlayer". I know I could tokenize them manually, but maybe you can show me a regex that can handle all the cases?</p... | 1 | 2009-09-07T12:02:18Z | 1,389,108 | <p>Look at my answer on the question, <a href="http://stackoverflow.com/questions/155303/net-how-can-you-split-a-caps-delimited-string-into-an-array/155487#155487" title=".NET - How can you split a âcapsâ delimited string into an array?">.NET - How can you split a âcapsâ delimited string into an array?</a>.</p>... | 4 | 2009-09-07T12:12:33Z | [
"python",
"ruby",
"regex",
"tokenize",
"lexical-analysis"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.