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
sequence |
---|---|---|---|---|---|---|---|---|---|
I want a program that writes every possible combination to a different line of a text file | 241,533 | <p>I want to write a program that would print every combination of a set of variables to a text file, creating a word list. Each answer should be written on a separate line and write all of the results for 1 digit, 2 digits, and 3 digits to a single text file.</p>
<p>Is there a simple way I can write a python program that can accomplish this? Here is an example of the output I am expecting when printing all the binary number combinations possible for 1, 2, and 3 digits:</p>
<pre><code>Output:
0
1
00
01
10
11
000
001
010
011
100
101
110
111
</code></pre>
| 4 | 2008-10-27T22:03:06Z | 241,577 | <p>A basic function to produce all the permutations of a list is given below. In this approach, permutations are created lazily by using generators.</p>
<pre><code>def perms(seq):
if seq == []:
yield []
else:
res = []
for index,item in enumerate(seq):
rest = seq[:index] + seq[index+1:]
for restperm in perms(rest):
yield [item] + restperm
alist = [1,1,0]
for permuation in perms(alist):
print permuation
</code></pre>
| 2 | 2008-10-27T22:21:14Z | [
"python",
"recursion"
] |
I want a program that writes every possible combination to a different line of a text file | 241,533 | <p>I want to write a program that would print every combination of a set of variables to a text file, creating a word list. Each answer should be written on a separate line and write all of the results for 1 digit, 2 digits, and 3 digits to a single text file.</p>
<p>Is there a simple way I can write a python program that can accomplish this? Here is an example of the output I am expecting when printing all the binary number combinations possible for 1, 2, and 3 digits:</p>
<pre><code>Output:
0
1
00
01
10
11
000
001
010
011
100
101
110
111
</code></pre>
| 4 | 2008-10-27T22:03:06Z | 242,141 | <p>A naïve solution which solves the problem and is general enough for any application you might have is this:</p>
<pre><code>def combinations(words, length):
if length == 0:
return []
result = [[word] for word in words]
while length > 1:
new_result = []
for combo in result:
new_result.extend(combo + [word] for word in words)
result = new_result[:]
length -= 1
return result
</code></pre>
<p>Basically, this gradually builds up a tree in memory of all the combinations, and then returns them. It is memory-intensive, however, and so is impractical for large-scale combinations.</p>
<p>Another solution for the problem is, indeed, to use counting, but then to transform the numbers generated into a list of words from the wordlist. To do so, we first need a function (called <code>number_to_list()</code>):</p>
<pre><code>def number_to_list(number, words):
list_out = []
while number:
list_out = [number % len(words)] + list_out
number = number // len(words)
return [words[n] for n in list_out]
</code></pre>
<p>This is, in fact, a system for converting decimal numbers to other bases. We then write the counting function; this is relatively simple, and will make up the core of the application:</p>
<pre><code>def combinations(words, length):
numbers = xrange(len(words)**length)
for number in numbers:
combo = number_to_list(number, words)
if len(combo) < length:
combo = [words[0]] * (length - len(combo)) + combo
yield combo
</code></pre>
<p>This is a Python generator; making it a generator allows it to use up less RAM. There is a little work to be done after turning the number into a list of words; this is because these lists will need padding so that they are at the requested length. It would be used like this:</p>
<pre><code>>>> list(combinations('01', 3))
[['0', '0', '0'], ['0', '0', '1'],
['0', '1', '0'], ['0', '1', '1'],
['1', '0', '0'], ['1', '0', '1'],
['1', '1', '0'], ['1', '1', '1']]
</code></pre>
<p>As you can see, you get back a list of lists. Each of these sub-lists contains a sequence of the original words; you might then do something like <code>map(''.join, list(combinations('01', 3)))</code> to retrieve the following result:</p>
<pre><code>['000', '001', '010', '011', '100', '101', '110', '111']
</code></pre>
<p>You could then write this to disk; a better idea, however, would be to use the built-in optimizations that generators have and do something like this:</p>
<pre><code>fileout = open('filename.txt', 'w')
fileout.writelines(
''.join(combo) for combo in combinations('01', 3))
fileout.close()
</code></pre>
<p>This will only use as much RAM as necessary (enough to store one combination). I hope this helps.</p>
| 3 | 2008-10-28T03:22:09Z | [
"python",
"recursion"
] |
SUDS - programmatic access to methods and types | 241,892 | <p>I'm investigating SUDS as a SOAP client for python. I want to inspect the methods available from a specified service, and the types required by a specified method.</p>
<p>The aim is to generate a user interface, allowing users to select a method, then fill in values in a dynamically generated form.</p>
<p>I can get some information on a particular method, but am unsure how to parse it:</p>
<pre><code>client = Client(url)
method = client.sd.service.methods['MyMethod']
</code></pre>
<p>I am unable to <strong>programmaticaly</strong> figure out what object type I need to create to be able to call the service</p>
<pre><code>obj = client.factory.create('?')
res = client.service.MyMethod(obj, soapheaders=authen)
</code></pre>
<p>Does anyone have some sample code?</p>
| 18 | 2008-10-28T00:52:41Z | 1,842,812 | <p>According to <code>suds</code> <a href="https://fedorahosted.org/suds/wiki/Documentation#BASICUSAGE">documentation</a>, you can inspect <code>service</code> object with <code>__str()__</code>. So the following gets a list of methods and complex types:</p>
<pre><code>from suds.client import Client;
url = 'http://www.webservicex.net/WeatherForecast.asmx?WSDL'
client = Client(url)
temp = str(client);
</code></pre>
<p>The code above produces following result (contents of <code>temp</code>):</p>
<pre><code>Suds ( https://fedorahosted.org/suds/ ) version: 0.3.4 (beta) build: R418-20081208
Service ( WeatherForecast ) tns="http://www.webservicex.net"
Prefixes (1)
ns0 = "http://www.webservicex.net"
Ports (2):
(WeatherForecastSoap)
Methods (2):
GetWeatherByPlaceName(xs:string PlaceName, )
GetWeatherByZipCode(xs:string ZipCode, )
Types (3):
ArrayOfWeatherData
WeatherData
WeatherForecasts
(WeatherForecastSoap12)
Methods (2):
GetWeatherByPlaceName(xs:string PlaceName, )
GetWeatherByZipCode(xs:string ZipCode, )
Types (3):
ArrayOfWeatherData
WeatherData
WeatherForecasts
</code></pre>
<p>This would be much easier to parse. Also every method is listed with their parameters along with their types. You could, probably, even use just regular expression to extract information you need. </p>
| 16 | 2009-12-03T20:46:55Z | [
"python",
"suds"
] |
SUDS - programmatic access to methods and types | 241,892 | <p>I'm investigating SUDS as a SOAP client for python. I want to inspect the methods available from a specified service, and the types required by a specified method.</p>
<p>The aim is to generate a user interface, allowing users to select a method, then fill in values in a dynamically generated form.</p>
<p>I can get some information on a particular method, but am unsure how to parse it:</p>
<pre><code>client = Client(url)
method = client.sd.service.methods['MyMethod']
</code></pre>
<p>I am unable to <strong>programmaticaly</strong> figure out what object type I need to create to be able to call the service</p>
<pre><code>obj = client.factory.create('?')
res = client.service.MyMethod(obj, soapheaders=authen)
</code></pre>
<p>Does anyone have some sample code?</p>
| 18 | 2008-10-28T00:52:41Z | 1,858,144 | <p>Okay, so SUDS does quite a bit of magic.</p>
<p>A <code>suds.client.Client</code>, is built from a WSDL file:</p>
<pre><code>client = suds.client.Client("http://mssoapinterop.org/asmx/simple.asmx?WSDL")
</code></pre>
<p>It downloads the WSDL and creates a definition in <code>client.wsdl</code>. When you call a method using SUDS via <code>client.service.<method></code> it's actually doing a whole lot of recursive resolve magic behind the scenes against that interpreted WSDL. To discover the parameters and types for methods you'll need to introspect this object.</p>
<p>For example:</p>
<pre><code>for method in client.wsdl.services[0].ports[0].methods.values():
print '%s(%s)' % (method.name, ', '.join('%s: %s' % (part.type, part.name) for part in method.soap.input.body.parts))
</code></pre>
<p>This should print something like:</p>
<pre class="lang-py prettyprint-override"><code>echoInteger((u'int', http://www.w3.org/2001/XMLSchema): inputInteger)
echoFloatArray((u'ArrayOfFloat', http://soapinterop.org/): inputFloatArray)
echoVoid()
echoDecimal((u'decimal', http://www.w3.org/2001/XMLSchema): inputDecimal)
echoStructArray((u'ArrayOfSOAPStruct', http://soapinterop.org/xsd): inputStructArray)
echoIntegerArray((u'ArrayOfInt', http://soapinterop.org/): inputIntegerArray)
echoBase64((u'base64Binary', http://www.w3.org/2001/XMLSchema): inputBase64)
echoHexBinary((u'hexBinary', http://www.w3.org/2001/XMLSchema): inputHexBinary)
echoBoolean((u'boolean', http://www.w3.org/2001/XMLSchema): inputBoolean)
echoStringArray((u'ArrayOfString', http://soapinterop.org/): inputStringArray)
echoStruct((u'SOAPStruct', http://soapinterop.org/xsd): inputStruct)
echoDate((u'dateTime', http://www.w3.org/2001/XMLSchema): inputDate)
echoFloat((u'float', http://www.w3.org/2001/XMLSchema): inputFloat)
echoString((u'string', http://www.w3.org/2001/XMLSchema): inputString)
</code></pre>
<p>So the first element of the part's type tuple is probably what you're after:</p>
<pre><code>>>> client.factory.create(u'ArrayOfInt')
(ArrayOfInt){
_arrayType = ""
_offset = ""
_id = ""
_href = ""
_arrayType = ""
}
</code></pre>
<p>Update:</p>
<p>For the Weather service it appears that the "parameters" are a part with an <code>element</code> not a <code>type</code>:</p>
<pre><code>>>> client = suds.client.Client('http://www.webservicex.net/WeatherForecast.asmx?WSDL')
>>> client.wsdl.services[0].ports[0].methods.values()[0].soap.input.body.parts[0].element
(u'GetWeatherByZipCode', http://www.webservicex.net)
>>> client.factory.create(u'GetWeatherByZipCode')
(GetWeatherByZipCode){
ZipCode = None
}
</code></pre>
<p>But this is magic'd into the parameters of the method call (a la <code>client.service.GetWeatherByZipCode("12345")</code>. IIRC this is SOAP RPC binding style? I think there's enough information here to get you started. Hint: the Python command line interface is your friend!</p>
| 22 | 2009-12-07T06:12:25Z | [
"python",
"suds"
] |
SUDS - programmatic access to methods and types | 241,892 | <p>I'm investigating SUDS as a SOAP client for python. I want to inspect the methods available from a specified service, and the types required by a specified method.</p>
<p>The aim is to generate a user interface, allowing users to select a method, then fill in values in a dynamically generated form.</p>
<p>I can get some information on a particular method, but am unsure how to parse it:</p>
<pre><code>client = Client(url)
method = client.sd.service.methods['MyMethod']
</code></pre>
<p>I am unable to <strong>programmaticaly</strong> figure out what object type I need to create to be able to call the service</p>
<pre><code>obj = client.factory.create('?')
res = client.service.MyMethod(obj, soapheaders=authen)
</code></pre>
<p>Does anyone have some sample code?</p>
| 18 | 2008-10-28T00:52:41Z | 16,616,472 | <p>Here's a quick script I wrote based on the above information to list the input methods suds reports as available on a WSDL. Pass in the WSDL URL. Works for the project I'm currently on, I can't guarantee it for yours.</p>
<pre><code>import suds
def list_all(url):
client = suds.client.Client(url)
for service in client.wsdl.services:
for port in service.ports:
methods = port.methods.values()
for method in methods:
print(method.name)
for part in method.soap.input.body.parts:
part_type = part.type
if(not part_type):
part_type = part.element[0]
print(' ' + str(part.name) + ': ' + str(part_type))
o = client.factory.create(part_type)
print(' ' + str(o))
</code></pre>
| 7 | 2013-05-17T19:25:56Z | [
"python",
"suds"
] |
SUDS - programmatic access to methods and types | 241,892 | <p>I'm investigating SUDS as a SOAP client for python. I want to inspect the methods available from a specified service, and the types required by a specified method.</p>
<p>The aim is to generate a user interface, allowing users to select a method, then fill in values in a dynamically generated form.</p>
<p>I can get some information on a particular method, but am unsure how to parse it:</p>
<pre><code>client = Client(url)
method = client.sd.service.methods['MyMethod']
</code></pre>
<p>I am unable to <strong>programmaticaly</strong> figure out what object type I need to create to be able to call the service</p>
<pre><code>obj = client.factory.create('?')
res = client.service.MyMethod(obj, soapheaders=authen)
</code></pre>
<p>Does anyone have some sample code?</p>
| 18 | 2008-10-28T00:52:41Z | 17,830,415 | <p>You can access suds's ServiceDefinition object. Here's a quick sample:</p>
<pre><code>from suds.client import Client
c = Client('http://some/wsdl/link')
types = c.sd[0].types
</code></pre>
<p>Now, if you want to know the prefixed name of a type, it's also quite easy:</p>
<pre><code>c.sd[0].xlate(c.sd[0].types[0][0])
</code></pre>
<p>This double bracket notation is because the types are a list (hence a first [0]) and then in each item on this list there may be two items. However, suds's internal implementation of <code>__unicode__</code> does exactly that (i.e. takes only the first item on the list):</p>
<pre><code>s.append('Types (%d):' % len(self.types))
for t in self.types:
s.append(indent(4))
s.append(self.xlate(t[0]))
</code></pre>
<p>Happy coding ;)</p>
| 3 | 2013-07-24T09:43:44Z | [
"python",
"suds"
] |
SUDS - programmatic access to methods and types | 241,892 | <p>I'm investigating SUDS as a SOAP client for python. I want to inspect the methods available from a specified service, and the types required by a specified method.</p>
<p>The aim is to generate a user interface, allowing users to select a method, then fill in values in a dynamically generated form.</p>
<p>I can get some information on a particular method, but am unsure how to parse it:</p>
<pre><code>client = Client(url)
method = client.sd.service.methods['MyMethod']
</code></pre>
<p>I am unable to <strong>programmaticaly</strong> figure out what object type I need to create to be able to call the service</p>
<pre><code>obj = client.factory.create('?')
res = client.service.MyMethod(obj, soapheaders=authen)
</code></pre>
<p>Does anyone have some sample code?</p>
| 18 | 2008-10-28T00:52:41Z | 34,442,878 | <p>Once you created WSDL method object you can get information about it from it's <code>__metadata__</code>, including list of it's arguments' names.</p>
<p>Given the argument's name, you can access it's actual instance in the method created. That instance also contains it's information in <code>__metadata__</code>, there you can get it's type name</p>
<pre><code># creating method object
method = client.factory.create('YourMethod')
# getting list of arguments' names
arg_names = method.__metadata__.ordering
# getting types of those arguments
types = [method.__getitem__(arg).__metadata__.sxtype.name for arg in arg_names]
</code></pre>
<p>Disclaimer: this only works with complex WSDL types. Simple types, like strings and numbers, are defaulted to None</p>
| 0 | 2015-12-23T20:01:30Z | [
"python",
"suds"
] |
Is there any way to get a REPL in pydev? | 241,995 | <p>I would like to be able to drop to the python REPL from the debugger -- if this is not possible is there an easier way to evaluate python expressions in the context of the current breakpoint other than manually adding them all as watch expressions?</p>
| 9 | 2008-10-28T01:46:37Z | 242,774 | <p>I don't use <em>pydev</em>, but to drop to python's interactive REPL from code:</p>
<pre><code>import code
code.interact(local=locals())
</code></pre>
<p>To drop to python's debugger from code:</p>
<pre><code>import pdb
pdb.set_trace()
</code></pre>
<p>Finally, to run a interactive REPL after running some code, you can use python's <code>-i</code> switch:</p>
<pre><code>python -i script.py
</code></pre>
<p>That will give you a python prompt after the code, even if it throws an exception.</p>
<p>You may be able to hook some of those solutions into <em>pydev</em>, I think.</p>
| 3 | 2008-10-28T10:21:22Z | [
"python",
"ide",
"pydev",
"read-eval-print-loop"
] |
Is there any way to get a REPL in pydev? | 241,995 | <p>I would like to be able to drop to the python REPL from the debugger -- if this is not possible is there an easier way to evaluate python expressions in the context of the current breakpoint other than manually adding them all as watch expressions?</p>
| 9 | 2008-10-28T01:46:37Z | 516,482 | <p>There is a dedicated Pydev Console available by clicking on the "New console" dropdown in the console view.</p>
<p>See <a href="http://pydev.sourceforge.net/console.html">http://pydev.sourceforge.net/console.html</a></p>
| 5 | 2009-02-05T15:52:58Z | [
"python",
"ide",
"pydev",
"read-eval-print-loop"
] |
Is there any way to get a REPL in pydev? | 241,995 | <p>I would like to be able to drop to the python REPL from the debugger -- if this is not possible is there an easier way to evaluate python expressions in the context of the current breakpoint other than manually adding them all as watch expressions?</p>
| 9 | 2008-10-28T01:46:37Z | 8,726,587 | <p>As Dag Høidahl said, the PyDev Console is actually the best option (at least on Eclipse Indigo), no need to hack around. </p>
<p>Just go to Open Console:
<img src="http://i.stack.imgur.com/nXYND.png" alt="Open Console"></p>
<p>Then select PyDev Console:</p>
<p><img src="http://i.stack.imgur.com/nx9M1.png" alt="PyDev Console"></p>
<p>If you need to add specific parameters (for example, Jython tends to miss the python.os VM property), you can change them under Window -> Properties -> PyDev -> Interactive Console.
<img src="http://i.stack.imgur.com/ysj5d.png" alt="enter image description here"></p>
| 2 | 2012-01-04T12:05:17Z | [
"python",
"ide",
"pydev",
"read-eval-print-loop"
] |
OpenGl with Python | 242,059 | <p>I am currently in a course that is using OpenGL and I have been using C for all the programs so far. I have Python installed on Fedora as well as OpenGL, however the minute I call an OpenGL command in my Python code, I get a <strong>segmentation fault</strong>. I have no idea why this is.</p>
<p>Just to avoid the "just use C" comments, here is why I want to use Python:</p>
<p>There are a couple reasons I am wanting to switch from C to Python, but the main one is because we are about to start writing a raytracer and I would like to use classes to make it easier on me. Since I hate classes in C++ and structs in C seems a little crazy, I thought I would give Python a try at it. I have also been looking for a reason to use Python again as it has been a while.</p>
<p>Thanks for any help.</p>
| 15 | 2008-10-28T02:29:24Z | 242,063 | <p>What OpenGL library are you using? What windowing library? What version of Python?</p>
<p>Most likely cause I can think of is that your windowing library (SDL or whatever you're using) isn't initializing OpenGL before you start calling into it.</p>
| 1 | 2008-10-28T02:34:02Z | [
"python",
"opengl",
"fedora"
] |
OpenGl with Python | 242,059 | <p>I am currently in a course that is using OpenGL and I have been using C for all the programs so far. I have Python installed on Fedora as well as OpenGL, however the minute I call an OpenGL command in my Python code, I get a <strong>segmentation fault</strong>. I have no idea why this is.</p>
<p>Just to avoid the "just use C" comments, here is why I want to use Python:</p>
<p>There are a couple reasons I am wanting to switch from C to Python, but the main one is because we are about to start writing a raytracer and I would like to use classes to make it easier on me. Since I hate classes in C++ and structs in C seems a little crazy, I thought I would give Python a try at it. I have also been looking for a reason to use Python again as it has been a while.</p>
<p>Thanks for any help.</p>
| 15 | 2008-10-28T02:29:24Z | 242,371 | <p>We have neither ideas about random segmentation faults. There is not enough information. What python libraries are you using for opengl? How do you use them? Can you show us your code? It's probably something trivial but my god -skill ends up to telling me just and only that.</p>
<p>Raytracer in python? I'd prefer just doing that in C with those structs. But then, I'm assuming you aren't going to do a realtime raytracer so that may be ok.</p>
| 0 | 2008-10-28T06:12:11Z | [
"python",
"opengl",
"fedora"
] |
OpenGl with Python | 242,059 | <p>I am currently in a course that is using OpenGL and I have been using C for all the programs so far. I have Python installed on Fedora as well as OpenGL, however the minute I call an OpenGL command in my Python code, I get a <strong>segmentation fault</strong>. I have no idea why this is.</p>
<p>Just to avoid the "just use C" comments, here is why I want to use Python:</p>
<p>There are a couple reasons I am wanting to switch from C to Python, but the main one is because we are about to start writing a raytracer and I would like to use classes to make it easier on me. Since I hate classes in C++ and structs in C seems a little crazy, I thought I would give Python a try at it. I have also been looking for a reason to use Python again as it has been a while.</p>
<p>Thanks for any help.</p>
| 15 | 2008-10-28T02:29:24Z | 246,894 | <p>You may also want to consider using <a href="http://www.pyglet.org/">Pyglet</a> instead of PyOpenGL. It's a ctypes-wrapper around the native OpenGL libs on the local platform, along with windowing support (should handle most of the stuff you want to use GLUT for.) The <a href="http://groups.google.com/group/pyglet-users">pyglet-users</a> list is pretty active and very helpful.</p>
| 16 | 2008-10-29T13:58:22Z | [
"python",
"opengl",
"fedora"
] |
OpenGl with Python | 242,059 | <p>I am currently in a course that is using OpenGL and I have been using C for all the programs so far. I have Python installed on Fedora as well as OpenGL, however the minute I call an OpenGL command in my Python code, I get a <strong>segmentation fault</strong>. I have no idea why this is.</p>
<p>Just to avoid the "just use C" comments, here is why I want to use Python:</p>
<p>There are a couple reasons I am wanting to switch from C to Python, but the main one is because we are about to start writing a raytracer and I would like to use classes to make it easier on me. Since I hate classes in C++ and structs in C seems a little crazy, I thought I would give Python a try at it. I have also been looking for a reason to use Python again as it has been a while.</p>
<p>Thanks for any help.</p>
| 15 | 2008-10-28T02:29:24Z | 246,922 | <p>Perhaps you are calling an OpenGL function that requires an active OpenGL context, without having one? That shouldn't necessarily crash, but I guess it might. How to set up such a context depends on the platform, and it's been a while since I used GL from Python (and when I did, I also used GTK+ which complicates matters).</p>
| 0 | 2008-10-29T14:06:59Z | [
"python",
"opengl",
"fedora"
] |
OpenGl with Python | 242,059 | <p>I am currently in a course that is using OpenGL and I have been using C for all the programs so far. I have Python installed on Fedora as well as OpenGL, however the minute I call an OpenGL command in my Python code, I get a <strong>segmentation fault</strong>. I have no idea why this is.</p>
<p>Just to avoid the "just use C" comments, here is why I want to use Python:</p>
<p>There are a couple reasons I am wanting to switch from C to Python, but the main one is because we are about to start writing a raytracer and I would like to use classes to make it easier on me. Since I hate classes in C++ and structs in C seems a little crazy, I thought I would give Python a try at it. I have also been looking for a reason to use Python again as it has been a while.</p>
<p>Thanks for any help.</p>
| 15 | 2008-10-28T02:29:24Z | 1,778,664 | <p>Well, I don't know if these are the libs the original poster are using but I saw identical issues in a pet project I'm working on (Graphics Engine using C++ and Python) using PyOpenGL.</p>
<p>PyOpenGL didn't correctly pick up the rendering context if it was created after the python script had been loaded (I was loading the script first, then calling Python methods in it from my C++ code).</p>
<p>The problem doesn't appear if you initialize the display and create the OpenGL rendering context before loading the Python script.</p>
| 2 | 2009-11-22T13:16:15Z | [
"python",
"opengl",
"fedora"
] |
OpenGl with Python | 242,059 | <p>I am currently in a course that is using OpenGL and I have been using C for all the programs so far. I have Python installed on Fedora as well as OpenGL, however the minute I call an OpenGL command in my Python code, I get a <strong>segmentation fault</strong>. I have no idea why this is.</p>
<p>Just to avoid the "just use C" comments, here is why I want to use Python:</p>
<p>There are a couple reasons I am wanting to switch from C to Python, but the main one is because we are about to start writing a raytracer and I would like to use classes to make it easier on me. Since I hate classes in C++ and structs in C seems a little crazy, I thought I would give Python a try at it. I have also been looking for a reason to use Python again as it has been a while.</p>
<p>Thanks for any help.</p>
| 15 | 2008-10-28T02:29:24Z | 2,284,461 | <p>Scripts never cause segmentation faults.
But first see if your kernel and kmod video driver working property ...
Extension modules can cause "segmentation fault".</p>
| 0 | 2010-02-17T21:14:47Z | [
"python",
"opengl",
"fedora"
] |
Python + Leopard + Fink + Mac Ports + Python.org + Idiot = broken Python - fresh start? | 242,065 | <p>I have been enjoying learning the basics of python, but before I started reading things I tried to install various python versions and modules clumsily. Now that I have some ideas of what I want to do and how to do it I'm finding that various aspects are broken. For instance, 2.6 IDLE won't launch, and when I try to import modules they usually don't work.</p>
<p>My question is, how would you recommend I clean this up and start fresh? I have read information about modifying the 2.6 install, but I still can't get it to work.</p>
<p>IDLE 2.4 works, and when I launch python from the terminal I am running python 2.4.4.</p>
| 2 | 2008-10-28T02:34:19Z | 242,159 | <p>I had this problem so much when I first got my Mac. The best solution I found was to delete everything I'd installed and just go with the <a href="http://pythonmac.org" rel="nofollow">pythonmac.org</a> version of Python (2.6). I then installed setuptools from the same site, and then used easy_install to install every other package.</p>
<p>Oh, and I got the GNU C Compiler from the Xcode developer tools CD (which you can download from Apple's website), so that I can compile C extensions.</p>
| 4 | 2008-10-28T03:28:57Z | [
"python",
"python-2.6",
"python-install"
] |
Python + Leopard + Fink + Mac Ports + Python.org + Idiot = broken Python - fresh start? | 242,065 | <p>I have been enjoying learning the basics of python, but before I started reading things I tried to install various python versions and modules clumsily. Now that I have some ideas of what I want to do and how to do it I'm finding that various aspects are broken. For instance, 2.6 IDLE won't launch, and when I try to import modules they usually don't work.</p>
<p>My question is, how would you recommend I clean this up and start fresh? I have read information about modifying the 2.6 install, but I still can't get it to work.</p>
<p>IDLE 2.4 works, and when I launch python from the terminal I am running python 2.4.4.</p>
| 2 | 2008-10-28T02:34:19Z | 248,884 | <p>Macports should be easy to get rid of; just delete /opt/local/. I think that Fink does something similar.</p>
<p>You can do <code>which python</code> to see what python is the default one. The system python should be in /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python</p>
<p>The MacPython you may have downloaded would either be in /Library/Frameworks/Python.framework. You can delete this as well.</p>
<p>Also, both MacPython and MacPorts edit your ~/.profile and change the PYTHONPATH, make sure to edit it and remove the extra paths there.</p>
| 1 | 2008-10-30T00:08:53Z | [
"python",
"python-2.6",
"python-install"
] |
Python + Leopard + Fink + Mac Ports + Python.org + Idiot = broken Python - fresh start? | 242,065 | <p>I have been enjoying learning the basics of python, but before I started reading things I tried to install various python versions and modules clumsily. Now that I have some ideas of what I want to do and how to do it I'm finding that various aspects are broken. For instance, 2.6 IDLE won't launch, and when I try to import modules they usually don't work.</p>
<p>My question is, how would you recommend I clean this up and start fresh? I have read information about modifying the 2.6 install, but I still can't get it to work.</p>
<p>IDLE 2.4 works, and when I launch python from the terminal I am running python 2.4.4.</p>
| 2 | 2008-10-28T02:34:19Z | 286,372 | <p>The easiest way to start afresh with Mac Ports or Fink is to simply remove the folder <code>/sw/</code> (for fink) or <code>/opt/</code> for MacPorts.</p>
<p>To completely remove them, you will have to remove a line in your <code>~/.profile</code> file:</p>
<p>For fink:</p>
<pre><code>test -r /sw/bin/init.sh && . /sw/bin/init.sh
</code></pre>
<p>..and for MacPorts, I don't have it installed currently, but there will be something along the lines of:</p>
<pre><code>export PATH=$PATH:/opt/local/bin
export PATH=$PATH:/opt/local/sbin
</code></pre>
<p><hr /></p>
<p>As for installing Python, currently the cleanest way is to build it from source..</p>
<p>I wrote up how I installed Python 2.6 on Leopard <a href="http://neverfear.org/blog/view/Installing_Python_2_6_3_0_without_breaking_stuff/" rel="nofollow">here</a>. It was for one of the 2.6 beta releases, so change the <code>curl -O</code> line to the newest release!</p>
<p>In short, download and extract the latest <a href="http://python.org/ftp/python/2.6/Python-2.6.tgz" rel="nofollow">python 2.6 source tarball</a>, then (in a terminal) <code>cd</code> to where you extracted the tarball, and run the following commands..</p>
<pre><code>./configure --prefix=/usr/local/python2.6
make
sudo make install
</code></pre>
<p>That will install python2.6 into <code>/usr/local/python2.6/</code> (the last line requires sudo, so will ask you for your password)</p>
<p>Finally add <code>/usr/local/python2.6</code> to $PATH, by adding the following line you the file <code>~/.profile</code></p>
<pre><code>export PATH=$PATH:/usr/local/python2.6
</code></pre>
<p>Then you will be able to run the <code>python2.6</code> command.</p>
<p>Ideally you would just install <a href="http://wiki.python.org/moin/MacPython/Leopard" rel="nofollow">MacPython</a>, but it doesn't seem to have a decent Python 2.6 installer yet.</p>
| 1 | 2008-11-13T06:24:42Z | [
"python",
"python-2.6",
"python-install"
] |
How does one add a svn repository build number to Python code? | 242,295 | <blockquote>
<p><strong>EDIT</strong>: This question duplicates <a href="http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173">http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173</a> (Thanks for the heads up, Charles!)</p>
</blockquote>
<p>Hi there,</p>
<p>This question is similar to <a href="http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code">http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code</a></p>
<p>The differences being:</p>
<ol>
<li><p>I would like to add the revision number to Python</p></li>
<li><p>I want the revision of the repository (not the checked out file)</p></li>
</ol>
<p>I.e. I would like to extract the Revision number from the return from 'svn info', likeso:</p>
<p>$ svn info</p>
<pre><code>Path: .
URL: svn://localhost/B/trunk
Repository Root: svn://localhost/B
Revision: 375
Node Kind: directory
Schedule: normal
Last Changed Author: bmh
Last Changed Rev: 375
Last Changed Date: 2008-10-27 12:09:00 -0400 (Mon, 27 Oct 2008)
</code></pre>
<p>I want a variable with 375 (the Revision). It's easy enough with put $Rev$ into a variable to keep track of changes on a file. However, I would like to keep track of the repository's version, and I understand (and it seems based on my tests) that $Rev$ only updates when the file changes.</p>
<p>My initial thoughts turn to using the svn/libsvn module built in to Python, though I can't find any documentation on or examples of how to use them.</p>
<p>Alternatively, I've thought calling 'svn info' and regex'ing the code out, though that seems rather brutal. :)</p>
<p>Help would be most appreciated.</p>
<p>Thanks & Cheers.</p>
| 3 | 2008-10-28T05:10:33Z | 242,327 | <p>I use a technique very similar to this in order to show the current subversion revision number in my shell:</p>
<pre><code>svnRev=$(echo "$(svn info)" | grep "^Revision" | awk -F": " '{print $2};')
echo $svnRev
</code></pre>
<p>It works very well for me.</p>
<p>Why do you want the python files to change every time the version number of the entire repository is incremented? This will make doing things like doing a diff between two files annoying if one is from the repo, and the other is from a tarball..</p>
| 1 | 2008-10-28T05:38:35Z | [
"python",
"svn"
] |
How does one add a svn repository build number to Python code? | 242,295 | <blockquote>
<p><strong>EDIT</strong>: This question duplicates <a href="http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173">http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173</a> (Thanks for the heads up, Charles!)</p>
</blockquote>
<p>Hi there,</p>
<p>This question is similar to <a href="http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code">http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code</a></p>
<p>The differences being:</p>
<ol>
<li><p>I would like to add the revision number to Python</p></li>
<li><p>I want the revision of the repository (not the checked out file)</p></li>
</ol>
<p>I.e. I would like to extract the Revision number from the return from 'svn info', likeso:</p>
<p>$ svn info</p>
<pre><code>Path: .
URL: svn://localhost/B/trunk
Repository Root: svn://localhost/B
Revision: 375
Node Kind: directory
Schedule: normal
Last Changed Author: bmh
Last Changed Rev: 375
Last Changed Date: 2008-10-27 12:09:00 -0400 (Mon, 27 Oct 2008)
</code></pre>
<p>I want a variable with 375 (the Revision). It's easy enough with put $Rev$ into a variable to keep track of changes on a file. However, I would like to keep track of the repository's version, and I understand (and it seems based on my tests) that $Rev$ only updates when the file changes.</p>
<p>My initial thoughts turn to using the svn/libsvn module built in to Python, though I can't find any documentation on or examples of how to use them.</p>
<p>Alternatively, I've thought calling 'svn info' and regex'ing the code out, though that seems rather brutal. :)</p>
<p>Help would be most appreciated.</p>
<p>Thanks & Cheers.</p>
| 3 | 2008-10-28T05:10:33Z | 242,508 | <p>Python has direct bindings to libsvn, so you don't need to invoke the command line client at all. See <a href="http://jtauber.com/python_subversion_binding/" rel="nofollow">this blog post</a> for more details.</p>
<p>EDIT: You can basically do something like this:</p>
<pre><code>from svn import fs, repos, core
repository = repos.open(root_path)
fs_ptr = repos.fs(repository)
youngest_revision_number = fs.youngest_rev(fs_ptr)
</code></pre>
| 2 | 2008-10-28T07:52:08Z | [
"python",
"svn"
] |
How does one add a svn repository build number to Python code? | 242,295 | <blockquote>
<p><strong>EDIT</strong>: This question duplicates <a href="http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173">http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173</a> (Thanks for the heads up, Charles!)</p>
</blockquote>
<p>Hi there,</p>
<p>This question is similar to <a href="http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code">http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code</a></p>
<p>The differences being:</p>
<ol>
<li><p>I would like to add the revision number to Python</p></li>
<li><p>I want the revision of the repository (not the checked out file)</p></li>
</ol>
<p>I.e. I would like to extract the Revision number from the return from 'svn info', likeso:</p>
<p>$ svn info</p>
<pre><code>Path: .
URL: svn://localhost/B/trunk
Repository Root: svn://localhost/B
Revision: 375
Node Kind: directory
Schedule: normal
Last Changed Author: bmh
Last Changed Rev: 375
Last Changed Date: 2008-10-27 12:09:00 -0400 (Mon, 27 Oct 2008)
</code></pre>
<p>I want a variable with 375 (the Revision). It's easy enough with put $Rev$ into a variable to keep track of changes on a file. However, I would like to keep track of the repository's version, and I understand (and it seems based on my tests) that $Rev$ only updates when the file changes.</p>
<p>My initial thoughts turn to using the svn/libsvn module built in to Python, though I can't find any documentation on or examples of how to use them.</p>
<p>Alternatively, I've thought calling 'svn info' and regex'ing the code out, though that seems rather brutal. :)</p>
<p>Help would be most appreciated.</p>
<p>Thanks & Cheers.</p>
| 3 | 2008-10-28T05:10:33Z | 242,515 | <p>There is a command called <code>svnversion</code> which comes with subversion and is meant to solve exactly that kind of problem.</p>
| 3 | 2008-10-28T07:57:08Z | [
"python",
"svn"
] |
How does one add a svn repository build number to Python code? | 242,295 | <blockquote>
<p><strong>EDIT</strong>: This question duplicates <a href="http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173">http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173</a> (Thanks for the heads up, Charles!)</p>
</blockquote>
<p>Hi there,</p>
<p>This question is similar to <a href="http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code">http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code</a></p>
<p>The differences being:</p>
<ol>
<li><p>I would like to add the revision number to Python</p></li>
<li><p>I want the revision of the repository (not the checked out file)</p></li>
</ol>
<p>I.e. I would like to extract the Revision number from the return from 'svn info', likeso:</p>
<p>$ svn info</p>
<pre><code>Path: .
URL: svn://localhost/B/trunk
Repository Root: svn://localhost/B
Revision: 375
Node Kind: directory
Schedule: normal
Last Changed Author: bmh
Last Changed Rev: 375
Last Changed Date: 2008-10-27 12:09:00 -0400 (Mon, 27 Oct 2008)
</code></pre>
<p>I want a variable with 375 (the Revision). It's easy enough with put $Rev$ into a variable to keep track of changes on a file. However, I would like to keep track of the repository's version, and I understand (and it seems based on my tests) that $Rev$ only updates when the file changes.</p>
<p>My initial thoughts turn to using the svn/libsvn module built in to Python, though I can't find any documentation on or examples of how to use them.</p>
<p>Alternatively, I've thought calling 'svn info' and regex'ing the code out, though that seems rather brutal. :)</p>
<p>Help would be most appreciated.</p>
<p>Thanks & Cheers.</p>
| 3 | 2008-10-28T05:10:33Z | 242,634 | <p>If you want to have a variable in one source file that can be set to the current working copy revision, and does not replay on subversion and a working copy being actually available at the time you run your program, then <a href="http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html" rel="nofollow">SubWCRev</a> my be your solution.</p>
<p>There also seems to be a linux port called <a href="http://svnwcrev.tigris.org/" rel="nofollow">SVNWCRev</a></p>
<p>Both perform substitution of $WCREV$ with the highest commit level of the working copy. Other information may also be provided.</p>
| 1 | 2008-10-28T09:21:22Z | [
"python",
"svn"
] |
How does one add a svn repository build number to Python code? | 242,295 | <blockquote>
<p><strong>EDIT</strong>: This question duplicates <a href="http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173">http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173</a> (Thanks for the heads up, Charles!)</p>
</blockquote>
<p>Hi there,</p>
<p>This question is similar to <a href="http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code">http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code</a></p>
<p>The differences being:</p>
<ol>
<li><p>I would like to add the revision number to Python</p></li>
<li><p>I want the revision of the repository (not the checked out file)</p></li>
</ol>
<p>I.e. I would like to extract the Revision number from the return from 'svn info', likeso:</p>
<p>$ svn info</p>
<pre><code>Path: .
URL: svn://localhost/B/trunk
Repository Root: svn://localhost/B
Revision: 375
Node Kind: directory
Schedule: normal
Last Changed Author: bmh
Last Changed Rev: 375
Last Changed Date: 2008-10-27 12:09:00 -0400 (Mon, 27 Oct 2008)
</code></pre>
<p>I want a variable with 375 (the Revision). It's easy enough with put $Rev$ into a variable to keep track of changes on a file. However, I would like to keep track of the repository's version, and I understand (and it seems based on my tests) that $Rev$ only updates when the file changes.</p>
<p>My initial thoughts turn to using the svn/libsvn module built in to Python, though I can't find any documentation on or examples of how to use them.</p>
<p>Alternatively, I've thought calling 'svn info' and regex'ing the code out, though that seems rather brutal. :)</p>
<p>Help would be most appreciated.</p>
<p>Thanks & Cheers.</p>
| 3 | 2008-10-28T05:10:33Z | 243,088 | <p>Stolen directly from django:</p>
<pre><code>def get_svn_revision(path=None):
rev = None
if path is None:
path = MODULE.__path__[0]
entries_path = '%s/.svn/entries' % path
if os.path.exists(entries_path):
entries = open(entries_path, 'r').read()
# Versions >= 7 of the entries file are flat text. The first line is
# the version number. The next set of digits after 'dir' is the revision.
if re.match('(\d+)', entries):
rev_match = re.search('\d+\s+dir\s+(\d+)', entries)
if rev_match:
rev = rev_match.groups()[0]
# Older XML versions of the file specify revision as an attribute of
# the first entries node.
else:
from xml.dom import minidom
dom = minidom.parse(entries_path)
rev = dom.getElementsByTagName('entry')[0].getAttribute('revision')
if rev:
return u'SVN-%s' % rev
return u'SVN-unknown'
</code></pre>
<p>Adapt as appropriate. YOu might want to change MODULE for the name of one of your codemodules.</p>
<p>This code has the advantage of working even if the destination system does not have subversion installed.</p>
| 3 | 2008-10-28T12:28:20Z | [
"python",
"svn"
] |
How does one add a svn repository build number to Python code? | 242,295 | <blockquote>
<p><strong>EDIT</strong>: This question duplicates <a href="http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173">http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173</a> (Thanks for the heads up, Charles!)</p>
</blockquote>
<p>Hi there,</p>
<p>This question is similar to <a href="http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code">http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code</a></p>
<p>The differences being:</p>
<ol>
<li><p>I would like to add the revision number to Python</p></li>
<li><p>I want the revision of the repository (not the checked out file)</p></li>
</ol>
<p>I.e. I would like to extract the Revision number from the return from 'svn info', likeso:</p>
<p>$ svn info</p>
<pre><code>Path: .
URL: svn://localhost/B/trunk
Repository Root: svn://localhost/B
Revision: 375
Node Kind: directory
Schedule: normal
Last Changed Author: bmh
Last Changed Rev: 375
Last Changed Date: 2008-10-27 12:09:00 -0400 (Mon, 27 Oct 2008)
</code></pre>
<p>I want a variable with 375 (the Revision). It's easy enough with put $Rev$ into a variable to keep track of changes on a file. However, I would like to keep track of the repository's version, and I understand (and it seems based on my tests) that $Rev$ only updates when the file changes.</p>
<p>My initial thoughts turn to using the svn/libsvn module built in to Python, though I can't find any documentation on or examples of how to use them.</p>
<p>Alternatively, I've thought calling 'svn info' and regex'ing the code out, though that seems rather brutal. :)</p>
<p>Help would be most appreciated.</p>
<p>Thanks & Cheers.</p>
| 3 | 2008-10-28T05:10:33Z | 245,505 | <p>Based on CesarB's response and the link Charles provided, I've done the following:</p>
<pre><code>try:
from subprocess import Popen, PIPE
_p = Popen(["svnversion", "."], stdout=PIPE)
REVISION= _p.communicate()[0]
_p = None # otherwise we get a wild exception when Django auto-reloads
except Exception, e:
print "Could not get revision number: ", e
REVISION="Unknown"
</code></pre>
<p>Golly Python is cool. :)</p>
| 0 | 2008-10-29T01:32:14Z | [
"python",
"svn"
] |
Starting python debugger automatically on error | 242,485 | <p>This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.</p>
| 106 | 2008-10-28T07:37:15Z | 242,506 | <p>This isn't the debugger, but probably just as useful(?)</p>
<p>I know I heard Guido mention this in a speech somewhere.</p>
<p>I just checked python -?, and if you use the -i command you can interact where your script stopped.</p>
<p>So given this script:</p>
<pre><code>testlist = [1,2,3,4,5, 0]
prev_i = None
for i in testlist:
if not prev_i:
prev_i = i
else:
result = prev_i/i
</code></pre>
<p>You can get this output!</p>
<pre><code>PS D:\> python -i debugtest.py
Traceback (most recent call last):
File "debugtest.py", line 10, in <module>
result = prev_i/i
ZeroDivisionError: integer division or modulo by zero
>>>
>>>
>>> prev_i
1
>>> i
0
>>>
</code></pre>
<p>To be honest I haven't used this, but I should be, seems very useful.</p>
| 26 | 2008-10-28T07:51:45Z | [
"python",
"debugging"
] |
Starting python debugger automatically on error | 242,485 | <p>This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.</p>
| 106 | 2008-10-28T07:37:15Z | 242,514 | <p>You can use <a href="http://docs.python.org/library/traceback.html#traceback.print_exc">traceback.print_exc</a> to print the exceptions traceback. Then use <a href="http://docs.python.org/library/sys#sys.exc_info">sys.exc_info</a> to extract the traceback and finally call <a href="http://docs.python.org/library/pdb#pdb.post_mortem">pdb.post_mortem</a> with that traceback</p>
<pre><code>import pdb, traceback, sys
def bombs():
a = []
print a[0]
if __name__ == '__main__':
try:
bombs()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
</code></pre>
<p>If you want to start an interactive command line with <a href="http://docs.python.org/library/code#code.interact">code.interact</a> using the locals of the frame where the exception originated you can do</p>
<pre><code>import traceback, sys, code
def bombs():
a = []
print a[0]
if __name__ == '__main__':
try:
bombs()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
last_frame = lambda tb=tb: last_frame(tb.tb_next) if tb.tb_next else tb
frame = last_frame().tb_frame
ns = dict(frame.f_globals)
ns.update(frame.f_locals)
code.interact(local=ns)
</code></pre>
| 64 | 2008-10-28T07:56:24Z | [
"python",
"debugging"
] |
Starting python debugger automatically on error | 242,485 | <p>This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.</p>
| 106 | 2008-10-28T07:37:15Z | 242,531 | <p>Use the following module:</p>
<pre><code>import sys
def info(type, value, tb):
if hasattr(sys, 'ps1') or not sys.stderr.isatty():
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
sys.__excepthook__(type, value, tb)
else:
import traceback, pdb
# we are NOT in interactive mode, print the exceptionâ¦
traceback.print_exception(type, value, tb)
print
# â¦then start the debugger in post-mortem mode.
# pdb.pm() # deprecated
pdb.post_mortem(tb) # more âmodernâ
sys.excepthook = info
</code></pre>
<p>Name it <code>debug</code> (or whatever you like) and put it somewhere in your python path.</p>
<p>Now, at the start of your script, just add an <code>import debug</code>.</p>
| 43 | 2008-10-28T08:14:56Z | [
"python",
"debugging"
] |
Starting python debugger automatically on error | 242,485 | <p>This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.</p>
| 106 | 2008-10-28T07:37:15Z | 2,438,834 | <pre><code>python -m pdb myscript.py
</code></pre>
<p>You'll need to enter 'c' (for Continue) when execution begins, but then it will run to the error point and give you control there.</p>
| 170 | 2010-03-13T15:20:52Z | [
"python",
"debugging"
] |
Starting python debugger automatically on error | 242,485 | <p>This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.</p>
| 106 | 2008-10-28T07:37:15Z | 4,873,570 | <p>You can put this line in your code:</p>
<pre><code>import pdb ; pdb.set_trace()
</code></pre>
<p>More info: <a href="http://www.technomancy.org/python/debugger-start-line/" rel="nofollow">Start the python debugger at any line</a></p>
| 4 | 2011-02-02T10:57:45Z | [
"python",
"debugging"
] |
Starting python debugger automatically on error | 242,485 | <p>This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.</p>
| 106 | 2008-10-28T07:37:15Z | 13,003,378 | <p><strong>Ipython</strong> has a command for toggling this behavior: <strong>%pdb</strong>. It does exactly what you described, maybe even a bit more (giving you more informative backtraces with syntax highlighting and code completion). It's definitely worth a try!</p>
| 16 | 2012-10-21T23:49:51Z | [
"python",
"debugging"
] |
Starting python debugger automatically on error | 242,485 | <p>This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.</p>
| 106 | 2008-10-28T07:37:15Z | 23,113,690 | <p>Put a breakpoint inside the constructor of topmost exception class in the hierarchy, and most of the times you will see where the error was raised.</p>
<p>Putting a breakpoint means whatever you want it to mean : you can use an IDE, or <code>pdb.set_trace</code>, or whatever</p>
| 0 | 2014-04-16T15:23:22Z | [
"python",
"debugging"
] |
Starting python debugger automatically on error | 242,485 | <p>This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.</p>
| 106 | 2008-10-28T07:37:15Z | 34,733,850 | <p>To have it run without having to type c at the beginning use:</p>
<pre><code>python -m pdb -c c <script name>
</code></pre>
<p>Pdb has its own command line arguments: -c c will execute c(ontinue) command at start of execution and the program will run uninterrupted until the error.</p>
| 2 | 2016-01-12T00:54:16Z | [
"python",
"debugging"
] |
Starting python debugger automatically on error | 242,485 | <p>This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.</p>
| 106 | 2008-10-28T07:37:15Z | 35,039,165 | <p>IPython makes this simple on the command line:</p>
<pre><code>python myscript.py arg1 arg2
</code></pre>
<p>can be rewritten to</p>
<pre><code>ipython --pdb myscript.py -- arg1 arg2
</code></pre>
<p>Or, similarly, if calling a module:</p>
<pre><code>python -m mymodule arg1 arg2
</code></pre>
<p>can be rewritten to</p>
<pre><code>ipython --pdb -m mymodule -- arg1 arg2
</code></pre>
<p>Note the <code>--</code> to stop IPython from reading the script's arguments as its own.</p>
<p>This also has the advantage of invoking the enhanced IPython debugger (ipdb) instead of pdb.</p>
| 5 | 2016-01-27T13:49:16Z | [
"python",
"debugging"
] |
Starting python debugger automatically on error | 242,485 | <p>This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.</p>
| 106 | 2008-10-28T07:37:15Z | 35,489,235 | <p>If you are running a module:</p>
<pre><code>python -m mymodule
</code></pre>
<p>And now you want to enter <code>pdb</code> when an exception occurs, do this:</p>
<pre><code>PYTHONPATH="." python -m pdb -c c mymodule/__main__.py
</code></pre>
<p>(or <em>extend</em> your <code>PYTHONPATH</code>). The <code>PYTHONPATH</code> is needed so that the module is found in the path, since you are running the <code>pdb</code> module now.</p>
| 0 | 2016-02-18T18:11:21Z | [
"python",
"debugging"
] |
How to set the PYTHONPATH in Emacs? | 243,060 | <p>Emacs does not recognize my correct python path. I think it is a general problem with emacs not recognizing my environment variables. I have GNU Emacs 22.1.1 (i386-apple-darwin8.9.1, Carbon Version 1.6.0) of 2007-06-17 installed.</p>
<p>I have set the PYTHONPATH in my ~/.bashrc. Maybe I should set it somewhere else?</p>
| 14 | 2008-10-28T12:17:35Z | 243,239 | <p><code>.bashrc</code> only gets read when a shell starts; it won't affect Carbon Emacs. Instead, use <code>setenv</code> in your <code>.emacs</code>:</p>
<pre><code>(setenv "PYTHONPATH" "PATH_STRING_HERE")
</code></pre>
<p>You can set <code>PYTHONPATH</code> for the entire Mac OS session, by adding it to <code>~/.MacOSX/environment.plist</code> (more <a href="http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/EnvironmentVars.html#//apple_ref/doc/uid/20002093-113982">here</a>). You probably don't want to do this unless you have XCode (and its property list editor) installed.</p>
<p>(<a href="http://procrastiblog.com/2007/07/09/changing-your-path-in-emacs-compilation-mode/">Via Procrastiblog</a>)</p>
| 21 | 2008-10-28T13:17:01Z | [
"python",
"emacs",
"environment-variables"
] |
Including a dynamic image in a web page using POST? | 243,375 | <p>I have written a CGI script that creates an image dynamically using GET data. To include this image in my webpage, I am using the following code:</p>
<pre><code><img src="image.py?text=xxxxxxxxxxxxxx">
</code></pre>
<p>The problem is that I expect in the future the "text" field will get very long and the URL will become too large. From Googling around there doesn't seem to be a fixed limit on URL length (ie. depends on the browser, server, proxy, etc.) Is there a better way to do this? </p>
<p>If it matters, I am working with Django and Python and I cannot use any client-side scripting (ie. JavaScript).</p>
<p>Cheers,
Ben</p>
| 2 | 2008-10-28T13:46:35Z | 243,393 | <p>img's use GET. You'll have to come up with another mechanism. How about calling the same functionality in image.py and saving the file as a temp file which you ref in the img tag? Or how about saving the value of text in a db row during the rendering of this img tag and using the row_id as what you pass into the image.py script?</p>
| 0 | 2008-10-28T13:52:14Z | [
"python",
"html",
"django",
"cgi",
"image"
] |
Including a dynamic image in a web page using POST? | 243,375 | <p>I have written a CGI script that creates an image dynamically using GET data. To include this image in my webpage, I am using the following code:</p>
<pre><code><img src="image.py?text=xxxxxxxxxxxxxx">
</code></pre>
<p>The problem is that I expect in the future the "text" field will get very long and the URL will become too large. From Googling around there doesn't seem to be a fixed limit on URL length (ie. depends on the browser, server, proxy, etc.) Is there a better way to do this? </p>
<p>If it matters, I am working with Django and Python and I cannot use any client-side scripting (ie. JavaScript).</p>
<p>Cheers,
Ben</p>
| 2 | 2008-10-28T13:46:35Z | 243,397 | <p>Store the text somewhere (e.g. a database) and then pass through the primary key.</p>
| 5 | 2008-10-28T13:52:34Z | [
"python",
"html",
"django",
"cgi",
"image"
] |
Including a dynamic image in a web page using POST? | 243,375 | <p>I have written a CGI script that creates an image dynamically using GET data. To include this image in my webpage, I am using the following code:</p>
<pre><code><img src="image.py?text=xxxxxxxxxxxxxx">
</code></pre>
<p>The problem is that I expect in the future the "text" field will get very long and the URL will become too large. From Googling around there doesn't seem to be a fixed limit on URL length (ie. depends on the browser, server, proxy, etc.) Is there a better way to do this? </p>
<p>If it matters, I am working with Django and Python and I cannot use any client-side scripting (ie. JavaScript).</p>
<p>Cheers,
Ben</p>
| 2 | 2008-10-28T13:46:35Z | 243,515 | <p>This will get you an Image as the result of a POST -- you may not like it</p>
<ol>
<li>Put an iFrame where you want the image and size it and remove scrollbars</li>
<li>Set the src to a form with hidden inputs set to your post parameters and the action set to the URL that will generate the image</li>
<li><p>submit the form automatically with JavaScript in the body.onload of the iFrame's HTML</p>
<p>Then, either:</p></li>
<li><p>Serve back an content-type set to an image and stream the image bytes</p>
<p>or:</p></li>
<li><p>store the post parameters somewhere and generate a small id</p></li>
<li><p>serve back HTML with an img tag using the id in the url -- on the server look up the post parameters</p>
<p>or:</p></li>
<li><p>generate a page with an image tag with an embedded image</p>
<p><a href="http://danielmclaren.net/2008/03/embedding-base64-image-data-into-a-webpage" rel="nofollow">http://danielmclaren.net/2008/03/embedding-base64-image-data-into-a-webpage</a></p></li>
</ol>
| 1 | 2008-10-28T14:22:51Z | [
"python",
"html",
"django",
"cgi",
"image"
] |
Including a dynamic image in a web page using POST? | 243,375 | <p>I have written a CGI script that creates an image dynamically using GET data. To include this image in my webpage, I am using the following code:</p>
<pre><code><img src="image.py?text=xxxxxxxxxxxxxx">
</code></pre>
<p>The problem is that I expect in the future the "text" field will get very long and the URL will become too large. From Googling around there doesn't seem to be a fixed limit on URL length (ie. depends on the browser, server, proxy, etc.) Is there a better way to do this? </p>
<p>If it matters, I am working with Django and Python and I cannot use any client-side scripting (ie. JavaScript).</p>
<p>Cheers,
Ben</p>
| 2 | 2008-10-28T13:46:35Z | 243,521 | <p>Putting together what has already been said, how about creating two pages. First page sends a POST request when the form is submitted (lets say to create_img.py) with a text=xxxxxxx... parameter. Then create_img.py takes the text parameter and creates an image with it and inserts it (or a filesystem reference) into the db, then when rendering the second page, generate img tags like <code><img src="render_img.py?row_id=0122"></code>. At this point, render_img.py simply queries the db for the given image. Before creating the image you can check to see if its already in the database therefore reusing/recycling previous images with the same text parameter.</p>
| 1 | 2008-10-28T14:24:46Z | [
"python",
"html",
"django",
"cgi",
"image"
] |
Including a dynamic image in a web page using POST? | 243,375 | <p>I have written a CGI script that creates an image dynamically using GET data. To include this image in my webpage, I am using the following code:</p>
<pre><code><img src="image.py?text=xxxxxxxxxxxxxx">
</code></pre>
<p>The problem is that I expect in the future the "text" field will get very long and the URL will become too large. From Googling around there doesn't seem to be a fixed limit on URL length (ie. depends on the browser, server, proxy, etc.) Is there a better way to do this? </p>
<p>If it matters, I am working with Django and Python and I cannot use any client-side scripting (ie. JavaScript).</p>
<p>Cheers,
Ben</p>
| 2 | 2008-10-28T13:46:35Z | 243,538 | <p>You may be able to mitigate the problem by compressing the text in the get parameter.</p>
| 0 | 2008-10-28T14:28:54Z | [
"python",
"html",
"django",
"cgi",
"image"
] |
Including a dynamic image in a web page using POST? | 243,375 | <p>I have written a CGI script that creates an image dynamically using GET data. To include this image in my webpage, I am using the following code:</p>
<pre><code><img src="image.py?text=xxxxxxxxxxxxxx">
</code></pre>
<p>The problem is that I expect in the future the "text" field will get very long and the URL will become too large. From Googling around there doesn't seem to be a fixed limit on URL length (ie. depends on the browser, server, proxy, etc.) Is there a better way to do this? </p>
<p>If it matters, I am working with Django and Python and I cannot use any client-side scripting (ie. JavaScript).</p>
<p>Cheers,
Ben</p>
| 2 | 2008-10-28T13:46:35Z | 243,603 | <p>From the link below it looks like you'll be fine for a while ;)</p>
<p><a href="http://www.boutell.com/newfaq/misc/urllength.html" rel="nofollow">http://www.boutell.com/newfaq/misc/urllength.html</a></p>
| 0 | 2008-10-28T14:48:08Z | [
"python",
"html",
"django",
"cgi",
"image"
] |
Including a dynamic image in a web page using POST? | 243,375 | <p>I have written a CGI script that creates an image dynamically using GET data. To include this image in my webpage, I am using the following code:</p>
<pre><code><img src="image.py?text=xxxxxxxxxxxxxx">
</code></pre>
<p>The problem is that I expect in the future the "text" field will get very long and the URL will become too large. From Googling around there doesn't seem to be a fixed limit on URL length (ie. depends on the browser, server, proxy, etc.) Is there a better way to do this? </p>
<p>If it matters, I am working with Django and Python and I cannot use any client-side scripting (ie. JavaScript).</p>
<p>Cheers,
Ben</p>
| 2 | 2008-10-28T13:46:35Z | 243,860 | <p>If you're using django, maybe you can do this via a template tag instead?</p>
<p>Something like:</p>
<pre><code><img src="{% create_image "This is the text that will be displayed" %}">
</code></pre>
<p>The create_image function would create the image with a dummy/random/generated filename, and return the path.</p>
<p>This avoids having to GET or POST to the script, and the images will have manageable filenames.</p>
<p>I can see some potential issues with this approach, I'm just tossing the idea out there ;)</p>
| 0 | 2008-10-28T16:05:39Z | [
"python",
"html",
"django",
"cgi",
"image"
] |
Including a dynamic image in a web page using POST? | 243,375 | <p>I have written a CGI script that creates an image dynamically using GET data. To include this image in my webpage, I am using the following code:</p>
<pre><code><img src="image.py?text=xxxxxxxxxxxxxx">
</code></pre>
<p>The problem is that I expect in the future the "text" field will get very long and the URL will become too large. From Googling around there doesn't seem to be a fixed limit on URL length (ie. depends on the browser, server, proxy, etc.) Is there a better way to do this? </p>
<p>If it matters, I am working with Django and Python and I cannot use any client-side scripting (ie. JavaScript).</p>
<p>Cheers,
Ben</p>
| 2 | 2008-10-28T13:46:35Z | 1,051,870 | <p>OK, I'm a bit late to the party, but you could use a mix of MHTML (for IE7 and below) and the data URI scheme (for all other modern browsers). It does require a bit of work on both client and server but you can ultimately end up with</p>
<pre><code>newimg.src = 'blah';
</code></pre>
<p>The write-up on how to do this is at <a href="http://gingerbbm.com/?p=127" rel="nofollow">http://gingerbbm.com/?p=127</a>.</p>
| 0 | 2009-06-27T01:05:49Z | [
"python",
"html",
"django",
"cgi",
"image"
] |
Unicode block of a character in python | 243,831 | <p>Is there a way to get the Unicode Block of a character in python? The <a href="http://www.python.org/doc/2.5.2/lib/module-unicodedata.html" rel="nofollow">unicodedata</a> module doesn't seem to have what I need, and I couldn't find an external library for it.</p>
<p>Basically, I need the same functionality as <a href="http://java.sun.com/javase/6/docs/api/java/lang/Character.UnicodeBlock.html#of(char)" rel="nofollow"><code>Character.UnicodeBlock.of()</code></a> in java.</p>
| 5 | 2008-10-28T15:56:18Z | 245,072 | <p>I couldn't find one either. Strange!</p>
<p>Luckily, the number of Unicode blocks is quite manageably small.</p>
<p>This implementation accepts a one-character Unicode string, just like the functions in <code>unicodedata</code>. If your inputs are mostly ASCII, this linear search might even be faster than binary search using <code>bisect</code> or whatever. If I were submitting this for inclusion in the Python standard library, I'd probably write it as a binary search through an array of statically-initialized <code>struct</code>s in C.</p>
<pre><code>def block(ch):
'''
Return the Unicode block name for ch, or None if ch has no block.
>>> block(u'a')
'Basic Latin'
>>> block(unichr(0x0b80))
'Tamil'
>>> block(unichr(0xe0080))
'''
assert isinstance(ch, unicode) and len(ch) == 1, repr(ch)
cp = ord(ch)
for start, end, name in _blocks:
if start <= cp <= end:
return name
def _initBlocks(text):
global _blocks
_blocks = []
import re
pattern = re.compile(r'([0-9A-F]+)\.\.([0-9A-F]+);\ (\S.*\S)')
for line in text.splitlines():
m = pattern.match(line)
if m:
start, end, name = m.groups()
_blocks.append((int(start, 16), int(end, 16), name))
# retrieved from http://unicode.org/Public/UNIDATA/Blocks.txt
_initBlocks('''
# Blocks-5.1.0.txt
# Date: 2008-03-20, 17:41:00 PDT [KW]
#
# Unicode Character Database
# Copyright (c) 1991-2008 Unicode, Inc.
# For terms of use, see http://www.unicode.org/terms_of_use.html
# For documentation, see UCD.html
#
# Note: The casing of block names is not normative.
# For example, "Basic Latin" and "BASIC LATIN" are equivalent.
#
# Format:
# Start Code..End Code; Block Name
# ================================================
# Note: When comparing block names, casing, whitespace, hyphens,
# and underbars are ignored.
# For example, "Latin Extended-A" and "latin extended a" are equivalent.
# For more information on the comparison of property values,
# see UCD.html.
#
# All code points not explicitly listed for Block
# have the value No_Block.
# Property: Block
#
# @missing: 0000..10FFFF; No_Block
0000..007F; Basic Latin
0080..00FF; Latin-1 Supplement
0100..017F; Latin Extended-A
0180..024F; Latin Extended-B
0250..02AF; IPA Extensions
02B0..02FF; Spacing Modifier Letters
0300..036F; Combining Diacritical Marks
0370..03FF; Greek and Coptic
0400..04FF; Cyrillic
0500..052F; Cyrillic Supplement
0530..058F; Armenian
0590..05FF; Hebrew
0600..06FF; Arabic
0700..074F; Syriac
0750..077F; Arabic Supplement
0780..07BF; Thaana
07C0..07FF; NKo
0900..097F; Devanagari
0980..09FF; Bengali
0A00..0A7F; Gurmukhi
0A80..0AFF; Gujarati
0B00..0B7F; Oriya
0B80..0BFF; Tamil
0C00..0C7F; Telugu
0C80..0CFF; Kannada
0D00..0D7F; Malayalam
0D80..0DFF; Sinhala
0E00..0E7F; Thai
0E80..0EFF; Lao
0F00..0FFF; Tibetan
1000..109F; Myanmar
10A0..10FF; Georgian
1100..11FF; Hangul Jamo
1200..137F; Ethiopic
1380..139F; Ethiopic Supplement
13A0..13FF; Cherokee
1400..167F; Unified Canadian Aboriginal Syllabics
1680..169F; Ogham
16A0..16FF; Runic
1700..171F; Tagalog
1720..173F; Hanunoo
1740..175F; Buhid
1760..177F; Tagbanwa
1780..17FF; Khmer
1800..18AF; Mongolian
1900..194F; Limbu
1950..197F; Tai Le
1980..19DF; New Tai Lue
19E0..19FF; Khmer Symbols
1A00..1A1F; Buginese
1B00..1B7F; Balinese
1B80..1BBF; Sundanese
1C00..1C4F; Lepcha
1C50..1C7F; Ol Chiki
1D00..1D7F; Phonetic Extensions
1D80..1DBF; Phonetic Extensions Supplement
1DC0..1DFF; Combining Diacritical Marks Supplement
1E00..1EFF; Latin Extended Additional
1F00..1FFF; Greek Extended
2000..206F; General Punctuation
2070..209F; Superscripts and Subscripts
20A0..20CF; Currency Symbols
20D0..20FF; Combining Diacritical Marks for Symbols
2100..214F; Letterlike Symbols
2150..218F; Number Forms
2190..21FF; Arrows
2200..22FF; Mathematical Operators
2300..23FF; Miscellaneous Technical
2400..243F; Control Pictures
2440..245F; Optical Character Recognition
2460..24FF; Enclosed Alphanumerics
2500..257F; Box Drawing
2580..259F; Block Elements
25A0..25FF; Geometric Shapes
2600..26FF; Miscellaneous Symbols
2700..27BF; Dingbats
27C0..27EF; Miscellaneous Mathematical Symbols-A
27F0..27FF; Supplemental Arrows-A
2800..28FF; Braille Patterns
2900..297F; Supplemental Arrows-B
2980..29FF; Miscellaneous Mathematical Symbols-B
2A00..2AFF; Supplemental Mathematical Operators
2B00..2BFF; Miscellaneous Symbols and Arrows
2C00..2C5F; Glagolitic
2C60..2C7F; Latin Extended-C
2C80..2CFF; Coptic
2D00..2D2F; Georgian Supplement
2D30..2D7F; Tifinagh
2D80..2DDF; Ethiopic Extended
2DE0..2DFF; Cyrillic Extended-A
2E00..2E7F; Supplemental Punctuation
2E80..2EFF; CJK Radicals Supplement
2F00..2FDF; Kangxi Radicals
2FF0..2FFF; Ideographic Description Characters
3000..303F; CJK Symbols and Punctuation
3040..309F; Hiragana
30A0..30FF; Katakana
3100..312F; Bopomofo
3130..318F; Hangul Compatibility Jamo
3190..319F; Kanbun
31A0..31BF; Bopomofo Extended
31C0..31EF; CJK Strokes
31F0..31FF; Katakana Phonetic Extensions
3200..32FF; Enclosed CJK Letters and Months
3300..33FF; CJK Compatibility
3400..4DBF; CJK Unified Ideographs Extension A
4DC0..4DFF; Yijing Hexagram Symbols
4E00..9FFF; CJK Unified Ideographs
A000..A48F; Yi Syllables
A490..A4CF; Yi Radicals
A500..A63F; Vai
A640..A69F; Cyrillic Extended-B
A700..A71F; Modifier Tone Letters
A720..A7FF; Latin Extended-D
A800..A82F; Syloti Nagri
A840..A87F; Phags-pa
A880..A8DF; Saurashtra
A900..A92F; Kayah Li
A930..A95F; Rejang
AA00..AA5F; Cham
AC00..D7AF; Hangul Syllables
D800..DB7F; High Surrogates
DB80..DBFF; High Private Use Surrogates
DC00..DFFF; Low Surrogates
E000..F8FF; Private Use Area
F900..FAFF; CJK Compatibility Ideographs
FB00..FB4F; Alphabetic Presentation Forms
FB50..FDFF; Arabic Presentation Forms-A
FE00..FE0F; Variation Selectors
FE10..FE1F; Vertical Forms
FE20..FE2F; Combining Half Marks
FE30..FE4F; CJK Compatibility Forms
FE50..FE6F; Small Form Variants
FE70..FEFF; Arabic Presentation Forms-B
FF00..FFEF; Halfwidth and Fullwidth Forms
FFF0..FFFF; Specials
10000..1007F; Linear B Syllabary
10080..100FF; Linear B Ideograms
10100..1013F; Aegean Numbers
10140..1018F; Ancient Greek Numbers
10190..101CF; Ancient Symbols
101D0..101FF; Phaistos Disc
10280..1029F; Lycian
102A0..102DF; Carian
10300..1032F; Old Italic
10330..1034F; Gothic
10380..1039F; Ugaritic
103A0..103DF; Old Persian
10400..1044F; Deseret
10450..1047F; Shavian
10480..104AF; Osmanya
10800..1083F; Cypriot Syllabary
10900..1091F; Phoenician
10920..1093F; Lydian
10A00..10A5F; Kharoshthi
12000..123FF; Cuneiform
12400..1247F; Cuneiform Numbers and Punctuation
1D000..1D0FF; Byzantine Musical Symbols
1D100..1D1FF; Musical Symbols
1D200..1D24F; Ancient Greek Musical Notation
1D300..1D35F; Tai Xuan Jing Symbols
1D360..1D37F; Counting Rod Numerals
1D400..1D7FF; Mathematical Alphanumeric Symbols
1F000..1F02F; Mahjong Tiles
1F030..1F09F; Domino Tiles
20000..2A6DF; CJK Unified Ideographs Extension B
2F800..2FA1F; CJK Compatibility Ideographs Supplement
E0000..E007F; Tags
E0100..E01EF; Variation Selectors Supplement
F0000..FFFFF; Supplementary Private Use Area-A
100000..10FFFF; Supplementary Private Use Area-B
# EOF
''')
</code></pre>
| 10 | 2008-10-28T22:13:30Z | [
"python",
"unicode",
"character-properties"
] |
Unicode block of a character in python | 243,831 | <p>Is there a way to get the Unicode Block of a character in python? The <a href="http://www.python.org/doc/2.5.2/lib/module-unicodedata.html" rel="nofollow">unicodedata</a> module doesn't seem to have what I need, and I couldn't find an external library for it.</p>
<p>Basically, I need the same functionality as <a href="http://java.sun.com/javase/6/docs/api/java/lang/Character.UnicodeBlock.html#of(char)" rel="nofollow"><code>Character.UnicodeBlock.of()</code></a> in java.</p>
| 5 | 2008-10-28T15:56:18Z | 1,878,387 | <p>unicodedata.name(chr)</p>
| 0 | 2009-12-10T03:00:47Z | [
"python",
"unicode",
"character-properties"
] |
How to copy all properties of an object to another object, in Python? | 243,836 | <p>Is there a library method to copy all the properties between two (already present) instances of the same class, in Python?
I mean, something like Apache Commons' PropertyUtilsBean.copyProperties()</p>
<p>Thanks!</p>
| 21 | 2008-10-28T15:58:11Z | 244,116 | <p>If your class does not modify <code>__getitem__</code> or <code>__setitem__</code> for special attribute access all your attributes are stored in <code>__dict__</code> so you can do:</p>
<pre><code> nobj.__dict__ = oobj.__dict__.copy() # just a shallow copy
</code></pre>
<p>If you use python properties you should look at <code>inspect.getmembers()</code> and filter out the ones you want to copy.</p>
| 20 | 2008-10-28T17:16:27Z | [
"python"
] |
How to copy all properties of an object to another object, in Python? | 243,836 | <p>Is there a library method to copy all the properties between two (already present) instances of the same class, in Python?
I mean, something like Apache Commons' PropertyUtilsBean.copyProperties()</p>
<p>Thanks!</p>
| 21 | 2008-10-28T15:58:11Z | 244,654 | <p>Try <code>destination.__dict__.update(source.__dict__)</code>.</p>
| 27 | 2008-10-28T20:06:09Z | [
"python"
] |
How to copy all properties of an object to another object, in Python? | 243,836 | <p>Is there a library method to copy all the properties between two (already present) instances of the same class, in Python?
I mean, something like Apache Commons' PropertyUtilsBean.copyProperties()</p>
<p>Thanks!</p>
| 21 | 2008-10-28T15:58:11Z | 244,789 | <p>I know you down-modded copy, but I disagree. It's more clear to make another copy than to modify the existing in-place with <strong>dict</strong> manipulation, as others suggested (if you lose existing copy by reassigning the variable, it will get garbage-collected immediately). Python is not meant to be fast, it's meant to be readable (though I actually believe that copy() will be faster than the other methods).</p>
| 1 | 2008-10-28T20:41:35Z | [
"python"
] |
How to copy all properties of an object to another object, in Python? | 243,836 | <p>Is there a library method to copy all the properties between two (already present) instances of the same class, in Python?
I mean, something like Apache Commons' PropertyUtilsBean.copyProperties()</p>
<p>Thanks!</p>
| 21 | 2008-10-28T15:58:11Z | 248,608 | <p>At the risk of being modded down, is there <strike>a decent</strike> any use-case for this? </p>
<p>Unless we know exactly what it's for, we can't sensibly call it as "broken" as it seems.</p>
<p>Perhaps try this:</p>
<pre><code>firstobject.an_attribute = secondobject.an_attribute
firstobject.another_attribute = secondobject.another_attribute
</code></pre>
<p>That's the sane way of copying things between instances.</p>
| -1 | 2008-10-29T22:07:04Z | [
"python"
] |
How to copy all properties of an object to another object, in Python? | 243,836 | <p>Is there a library method to copy all the properties between two (already present) instances of the same class, in Python?
I mean, something like Apache Commons' PropertyUtilsBean.copyProperties()</p>
<p>Thanks!</p>
| 21 | 2008-10-28T15:58:11Z | 252,393 | <p>If you have to do this, I guess the nicest way is to have a class attribute something like :</p>
<pre><code>Class Copyable(object):
copyable_attributes = ('an_attribute', 'another_attribute')
</code></pre>
<p>Then iterate them explicitly and use <code>setattr(new, attr, getattr(old, attr))</code>. I still believe it can be solved with a better design though, and don't recommend it.</p>
| 1 | 2008-10-31T01:48:56Z | [
"python"
] |
What is the OCaml idiom equivalent to Python's range function? | 243,864 | <p>I want to create a list of integers from 1 to n. I can do this in Python using range(1, n+1), and in Haskell using: take n (iterate (1+) 1). </p>
<p>What is the right OCaml idiom for this?</p>
| 16 | 2008-10-28T16:06:33Z | 244,078 | <p>Here you go:</p>
<pre><code>let rec range i j = if i > j then [] else i :: (range (i+1) j)
</code></pre>
<p>Note that this is not tail-recursive. Modern Python versions even have a lazy range.</p>
| 9 | 2008-10-28T17:07:22Z | [
"python",
"ocaml"
] |
What is the OCaml idiom equivalent to Python's range function? | 243,864 | <p>I want to create a list of integers from 1 to n. I can do this in Python using range(1, n+1), and in Haskell using: take n (iterate (1+) 1). </p>
<p>What is the right OCaml idiom for this?</p>
| 16 | 2008-10-28T16:06:33Z | 244,104 | <p>There is no idiom that I know of, but here is a fairly natural definition using an infix operator:</p>
<pre><code># let (--) i j =
let rec aux n acc =
if n < i then acc else aux (n-1) (n :: acc)
in aux j [] ;;
val ( -- ) : int -> int -> int list = <fun>
# 1--2;;
- : int list = [1; 2]
# 1--5;;
- : int list = [1; 2; 3; 4; 5]
# 5--10;;
- : int list = [5; 6; 7; 8; 9; 10]
</code></pre>
<p>Alternatively, the <a href="http://dutherenverseauborddelatable.wordpress.com/downloads/comprehension-for-ocaml/">comprehensions syntax extension</a> (which gives the syntax <code>[i .. j]</code> for the above) is likely to be included in a future release of the <a href="http://forge.ocamlcore.org/projects/batteries/">"community version" of OCaml</a>, so that may become idiomatic. I don't recommend you start playing with syntax extensions if you are new to the language, though.</p>
| 19 | 2008-10-28T17:13:42Z | [
"python",
"ocaml"
] |
What is the OCaml idiom equivalent to Python's range function? | 243,864 | <p>I want to create a list of integers from 1 to n. I can do this in Python using range(1, n+1), and in Haskell using: take n (iterate (1+) 1). </p>
<p>What is the right OCaml idiom for this?</p>
| 16 | 2008-10-28T16:06:33Z | 244,843 | <p>BTW, in Haskell you'd rather use</p>
<pre><code>enumFromTo 1 n
[1 .. n]
</code></pre>
<p>These are just unnecessary.</p>
<pre><code>take n [1 ..]
take n $ iterate (+1) 1
</code></pre>
| 0 | 2008-10-28T20:56:13Z | [
"python",
"ocaml"
] |
What is the OCaml idiom equivalent to Python's range function? | 243,864 | <p>I want to create a list of integers from 1 to n. I can do this in Python using range(1, n+1), and in Haskell using: take n (iterate (1+) 1). </p>
<p>What is the right OCaml idiom for this?</p>
| 16 | 2008-10-28T16:06:33Z | 2,926,149 | <p>With <a href="http://batteries.forge.ocamlcore.org">Batteries Included</a>, you can write</p>
<pre><code>let nums = List.of_enum (1--10);;
</code></pre>
<p>The <code>--</code> operator generates an enumeration from the first value to the second. The <code>--^</code> operator is similar, but enumerates a half-open interval (<code>1--^10</code> will enumerate from 1 through 9).</p>
| 10 | 2010-05-28T01:33:00Z | [
"python",
"ocaml"
] |
What is the OCaml idiom equivalent to Python's range function? | 243,864 | <p>I want to create a list of integers from 1 to n. I can do this in Python using range(1, n+1), and in Haskell using: take n (iterate (1+) 1). </p>
<p>What is the right OCaml idiom for this?</p>
| 16 | 2008-10-28T16:06:33Z | 27,674,212 | <p>If you use <code>open Batteries</code> (which is a community version of the standard library), you can do <code>range(1,n+1)</code> by <code>List.range 1 `To n</code> (notice the backquote before <code>To</code>).</p>
<p>A more general way (also need batteries) is to use <code>List.init n f</code> which returns a list containing (f 0) (f 1) ... (f (n-1)). </p>
| 2 | 2014-12-28T06:33:31Z | [
"python",
"ocaml"
] |
What is the OCaml idiom equivalent to Python's range function? | 243,864 | <p>I want to create a list of integers from 1 to n. I can do this in Python using range(1, n+1), and in Haskell using: take n (iterate (1+) 1). </p>
<p>What is the right OCaml idiom for this?</p>
| 16 | 2008-10-28T16:06:33Z | 33,000,776 | <p>OCaml has special syntax for pattern matching on ranges:</p>
<pre><code>let () =
let my_char = 'a' in
let is_lower_case = match my_char with
| 'a'..'z' -> true (* Two dots define a range pattern *)
| _ -> false
in
printf "result: %b" is_lower_case
</code></pre>
<p>To create a range, you can use <a href="https://github.com/janestreet/core" rel="nofollow"><code>Core</code></a>:</p>
<pre><code>List.range 0 1000
</code></pre>
| 1 | 2015-10-07T19:25:48Z | [
"python",
"ocaml"
] |
What is the OCaml idiom equivalent to Python's range function? | 243,864 | <p>I want to create a list of integers from 1 to n. I can do this in Python using range(1, n+1), and in Haskell using: take n (iterate (1+) 1). </p>
<p>What is the right OCaml idiom for this?</p>
| 16 | 2008-10-28T16:06:33Z | 36,098,304 | <p>A little late to the game here but here's my implementation:</p>
<pre><code>let rec range ?(start=0) len =
if start >= len
then []
else start :: (range len ~start:(start+1))
</code></pre>
<p>You can then use it very much like the python function:</p>
<pre><code>range 10
(* equals: [0; 1; 2; 3; 4; 5; 6; 7; 8; 9] *)
range ~start:(-3) 3
(* equals: [-3; -2; -1; 0; 1; 2] *)
</code></pre>
<p>naturally I think the best answer is to simply use Core, but this might be better if you only need one function and you're trying to avoid the full framework.</p>
| 0 | 2016-03-19T05:41:34Z | [
"python",
"ocaml"
] |
How do I merge two python iterators? | 243,865 | <p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>
<pre><code>>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> merged.next()
'foo'
>>> merged.next()
1
>>> merged.next()
'bar'
>>> merged.next()
2
>>> merged.next()
Traceback (most recent call last):
...
StopIteration
</code></pre>
<p>What is the simplest, most concise way to do this?</p>
| 16 | 2008-10-28T16:07:12Z | 243,892 | <p>I'd do something like this. This will be most time and space efficient, since you won't have the overhead of zipping objects together. This will also work if both <code>a</code> and <code>b</code> are infinite.</p>
<pre><code>def imerge(a, b):
i1 = iter(a)
i2 = iter(b)
while True:
try:
yield i1.next()
yield i2.next()
except StopIteration:
return
</code></pre>
| 10 | 2008-10-28T16:12:19Z | [
"python",
"merge",
"iterator"
] |
How do I merge two python iterators? | 243,865 | <p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>
<pre><code>>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> merged.next()
'foo'
>>> merged.next()
1
>>> merged.next()
'bar'
>>> merged.next()
2
>>> merged.next()
Traceback (most recent call last):
...
StopIteration
</code></pre>
<p>What is the simplest, most concise way to do this?</p>
| 16 | 2008-10-28T16:07:12Z | 243,902 | <p>A generator will solve your problem nicely.</p>
<pre><code>def imerge(a, b):
for i, j in itertools.izip(a,b):
yield i
yield j
</code></pre>
| 32 | 2008-10-28T16:14:02Z | [
"python",
"merge",
"iterator"
] |
How do I merge two python iterators? | 243,865 | <p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>
<pre><code>>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> merged.next()
'foo'
>>> merged.next()
1
>>> merged.next()
'bar'
>>> merged.next()
2
>>> merged.next()
Traceback (most recent call last):
...
StopIteration
</code></pre>
<p>What is the simplest, most concise way to do this?</p>
| 16 | 2008-10-28T16:07:12Z | 243,909 | <p>You can use <code>zip</code> as well as <code>itertools.chain</code>. This will <b>only work</b> if the first list is <b>finite</b>:</p>
<pre><code>merge=itertools.chain(*[iter(i) for i in zip(['foo', 'bar'], itertools.count(1))])
</code></pre>
| 6 | 2008-10-28T16:15:15Z | [
"python",
"merge",
"iterator"
] |
How do I merge two python iterators? | 243,865 | <p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>
<pre><code>>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> merged.next()
'foo'
>>> merged.next()
1
>>> merged.next()
'bar'
>>> merged.next()
2
>>> merged.next()
Traceback (most recent call last):
...
StopIteration
</code></pre>
<p>What is the simplest, most concise way to do this?</p>
| 16 | 2008-10-28T16:07:12Z | 244,049 | <p>You can do something that is almost exaclty what @Pramod first suggested.</p>
<pre><code>def izipmerge(a, b):
for i, j in itertools.izip(a,b):
yield i
yield j
</code></pre>
<p>The advantage of this approach is that you won't run out of memory if both a and b are infinite.</p>
| 13 | 2008-10-28T16:59:35Z | [
"python",
"merge",
"iterator"
] |
How do I merge two python iterators? | 243,865 | <p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>
<pre><code>>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> merged.next()
'foo'
>>> merged.next()
1
>>> merged.next()
'bar'
>>> merged.next()
2
>>> merged.next()
Traceback (most recent call last):
...
StopIteration
</code></pre>
<p>What is the simplest, most concise way to do this?</p>
| 16 | 2008-10-28T16:07:12Z | 244,957 | <p>Why is itertools needed?</p>
<pre><code>def imerge(a,b):
for i,j in zip(a,b):
yield i
yield j
</code></pre>
<p>In this case at least one of a or b must be of finite length, cause zip will return a list, not an iterator. If you need an iterator as output then you can go for the Claudiu solution.</p>
| 0 | 2008-10-28T21:34:43Z | [
"python",
"merge",
"iterator"
] |
How do I merge two python iterators? | 243,865 | <p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>
<pre><code>>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> merged.next()
'foo'
>>> merged.next()
1
>>> merged.next()
'bar'
>>> merged.next()
2
>>> merged.next()
Traceback (most recent call last):
...
StopIteration
</code></pre>
<p>What is the simplest, most concise way to do this?</p>
| 16 | 2008-10-28T16:07:12Z | 245,042 | <p>I'm not sure what your application is, but you might find the enumerate() function more useful.</p>
<pre><code>>>> items = ['foo', 'bar', 'baz']
>>> for i, item in enumerate(items):
... print item
... print i
...
foo
0
bar
1
baz
2
</code></pre>
| 3 | 2008-10-28T22:03:08Z | [
"python",
"merge",
"iterator"
] |
How do I merge two python iterators? | 243,865 | <p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>
<pre><code>>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> merged.next()
'foo'
>>> merged.next()
1
>>> merged.next()
'bar'
>>> merged.next()
2
>>> merged.next()
Traceback (most recent call last):
...
StopIteration
</code></pre>
<p>What is the simplest, most concise way to do this?</p>
| 16 | 2008-10-28T16:07:12Z | 345,415 | <p>I also agree that itertools is not needed.</p>
<p>But why stop at 2?</p>
<pre><code> def tmerge(*iterators):
for values in zip(*iterators):
for value in values:
yield value
</code></pre>
<p>handles any number of iterators from 0 on upwards.</p>
<p>UPDATE: DOH! A commenter pointed out that this won't work unless all the iterators are the same length.</p>
<p>The correct code is:</p>
<pre><code>def tmerge(*iterators):
empty = {}
for values in itertools.izip_longest(*iterators, fillvalue=empty):
for value in values:
if value is not empty:
yield value
</code></pre>
<p>and yes, I just tried it with lists of unequal length, and a list containing {}.</p>
| 8 | 2008-12-05T22:39:29Z | [
"python",
"merge",
"iterator"
] |
How do I merge two python iterators? | 243,865 | <p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>
<pre><code>>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> merged.next()
'foo'
>>> merged.next()
1
>>> merged.next()
'bar'
>>> merged.next()
2
>>> merged.next()
Traceback (most recent call last):
...
StopIteration
</code></pre>
<p>What is the simplest, most concise way to do this?</p>
| 16 | 2008-10-28T16:07:12Z | 345,433 | <p>Using itertools.izip(), instead of zip() as in some of the other answers, will improve performance:</p>
<p>As "pydoc itertools.izip" shows: "Works like the zip() function but consumes less memory by returning an iterator instead of a list."</p>
<p>Itertools.izip will also work properly even if one of the iterators is infinite.</p>
| 0 | 2008-12-05T22:46:37Z | [
"python",
"merge",
"iterator"
] |
How do I merge two python iterators? | 243,865 | <p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>
<pre><code>>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> merged.next()
'foo'
>>> merged.next()
1
>>> merged.next()
'bar'
>>> merged.next()
2
>>> merged.next()
Traceback (most recent call last):
...
StopIteration
</code></pre>
<p>What is the simplest, most concise way to do this?</p>
| 16 | 2008-10-28T16:07:12Z | 345,576 | <p>Use izip and chain together:</p>
<pre><code>>>> list(itertools.chain.from_iterable(itertools.izip(items, c))) # 2.6 only
['foo', 1, 'bar', 2]
>>> list(itertools.chain(*itertools.izip(items, c)))
['foo', 1, 'bar', 2]
</code></pre>
| 1 | 2008-12-06T00:08:15Z | [
"python",
"merge",
"iterator"
] |
How do I merge two python iterators? | 243,865 | <p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>
<pre><code>>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> merged.next()
'foo'
>>> merged.next()
1
>>> merged.next()
'bar'
>>> merged.next()
2
>>> merged.next()
Traceback (most recent call last):
...
StopIteration
</code></pre>
<p>What is the simplest, most concise way to do this?</p>
| 16 | 2008-10-28T16:07:12Z | 394,427 | <p>A concise method is to use a generator expression with itertools.cycle(). It avoids creating a long chain() of tuples.</p>
<pre><code>generator = (it.next() for it in itertools.cycle([i1, i2]))
</code></pre>
| 0 | 2008-12-26T23:04:50Z | [
"python",
"merge",
"iterator"
] |
How do I merge two python iterators? | 243,865 | <p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>
<pre><code>>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> merged.next()
'foo'
>>> merged.next()
1
>>> merged.next()
'bar'
>>> merged.next()
2
>>> merged.next()
Traceback (most recent call last):
...
StopIteration
</code></pre>
<p>What is the simplest, most concise way to do this?</p>
| 16 | 2008-10-28T16:07:12Z | 5,399,982 | <p>I prefer this other way which is much more concise:</p>
<pre><code>iter = reduce(lambda x,y: itertools.chain(x,y), iters)
</code></pre>
| 3 | 2011-03-23T01:48:00Z | [
"python",
"merge",
"iterator"
] |
How do I merge two python iterators? | 243,865 | <p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>
<pre><code>>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> merged.next()
'foo'
>>> merged.next()
1
>>> merged.next()
'bar'
>>> merged.next()
2
>>> merged.next()
Traceback (most recent call last):
...
StopIteration
</code></pre>
<p>What is the simplest, most concise way to do this?</p>
| 16 | 2008-10-28T16:07:12Z | 5,487,453 | <p>One of the less well known features of Python is that you can have more for clauses in a generator expression. Very useful for flattening nested lists, like those you get from zip()/izip().</p>
<pre><code>def imerge(*iterators):
return (value for row in itertools.izip(*iterators) for value in row)
</code></pre>
| 3 | 2011-03-30T14:09:21Z | [
"python",
"merge",
"iterator"
] |
Which Eclipse package to download for pydev? | 243,962 | <p>I'm getting started with python, eclipse and pydev. Which Eclipse package should I choose? Nothing on the eclipse homepage tells me what to choose and python documentation assumes I have eclipse installed. Does which package I choose matter?</p>
| 52 | 2008-10-28T16:33:20Z | 243,981 | <p>If you just plan on doing Python dev, I'd just go with <a href="http://download.eclipse.org/eclipse/downloads/" rel="nofollow">Platform Runtime Binary</a>.</p>
<p>After that, I'd follow the instructions <a href="http://pydev.org/download.html" rel="nofollow">http://pydev.org/download.html</a> and <a href="http://pydev.org/manual_101_root.html" rel="nofollow">http://pydev.org/manual_101_root.html</a> to install PyDev.</p>
<p>I use the same setup for Python development. I also have the RadRails plugin for Ruby on Rails development.</p>
| 26 | 2008-10-28T16:39:43Z | [
"python",
"eclipse",
"package",
"pydev"
] |
Which Eclipse package to download for pydev? | 243,962 | <p>I'm getting started with python, eclipse and pydev. Which Eclipse package should I choose? Nothing on the eclipse homepage tells me what to choose and python documentation assumes I have eclipse installed. Does which package I choose matter?</p>
| 52 | 2008-10-28T16:33:20Z | 244,066 | <p>If you are getting started, I would recommend you <a href="http://www.easyeclipse.org/site/distributions/python.html" rel="nofollow">python easyeclipse</a>.</p>
<p>Pydev can give some incompatibilities when using it together with other extensions.</p>
| 3 | 2008-10-28T17:04:32Z | [
"python",
"eclipse",
"package",
"pydev"
] |
Which Eclipse package to download for pydev? | 243,962 | <p>I'm getting started with python, eclipse and pydev. Which Eclipse package should I choose? Nothing on the eclipse homepage tells me what to choose and python documentation assumes I have eclipse installed. Does which package I choose matter?</p>
| 52 | 2008-10-28T16:33:20Z | 244,077 | <p>I use J2EE Eclipse for Python and Java development. It works well.
But Classic Eclipse should be enought.</p>
| 0 | 2008-10-28T17:07:04Z | [
"python",
"eclipse",
"package",
"pydev"
] |
Which Eclipse package to download for pydev? | 243,962 | <p>I'm getting started with python, eclipse and pydev. Which Eclipse package should I choose? Nothing on the eclipse homepage tells me what to choose and python documentation assumes I have eclipse installed. Does which package I choose matter?</p>
| 52 | 2008-10-28T16:33:20Z | 245,013 | <p>PyDev was acquired by <a href="http://www.aptana.com">Aptana</a>, so you might want to check that one out as well.</p>
| 5 | 2008-10-28T21:52:00Z | [
"python",
"eclipse",
"package",
"pydev"
] |
Which Eclipse package to download for pydev? | 243,962 | <p>I'm getting started with python, eclipse and pydev. Which Eclipse package should I choose? Nothing on the eclipse homepage tells me what to choose and python documentation assumes I have eclipse installed. Does which package I choose matter?</p>
| 52 | 2008-10-28T16:33:20Z | 280,400 | <p>pydev and Python2.6 doesnt work with eclipse for C++.
Download the classic version and you should be good. </p>
| 1 | 2008-11-11T09:09:21Z | [
"python",
"eclipse",
"package",
"pydev"
] |
Which Eclipse package to download for pydev? | 243,962 | <p>I'm getting started with python, eclipse and pydev. Which Eclipse package should I choose? Nothing on the eclipse homepage tells me what to choose and python documentation assumes I have eclipse installed. Does which package I choose matter?</p>
| 52 | 2008-10-28T16:33:20Z | 1,215,589 | <p>A useful shortcut is to download <a href="http://www.easyeclipse.org/site/plugins/pydev.html" rel="nofollow">EasyEclipse for PyDev</a>. This is a version of Eclipse already pre-configured for pydev, and seems to be easier to install than gathering all of the Eclipse pieces yourself. Unfortunately it uses a rather old version of PyDev, but this is easily remedied by going to <code>Help > Software Updates ></code> and letting Eclipse grab the latest version (you'll need to change the PyDev location to SourceForge before doing this).</p>
| 3 | 2009-08-01T01:31:35Z | [
"python",
"eclipse",
"package",
"pydev"
] |
Which Eclipse package to download for pydev? | 243,962 | <p>I'm getting started with python, eclipse and pydev. Which Eclipse package should I choose? Nothing on the eclipse homepage tells me what to choose and python documentation assumes I have eclipse installed. Does which package I choose matter?</p>
| 52 | 2008-10-28T16:33:20Z | 1,836,492 | <p>I think that the Aptana distribution of Eclipse the the easiest way to get PyDev these days...especially since it's now free for the full version. If you download the Studio from here: <a href="http://www.aptana.org/" rel="nofollow">http://www.aptana.org/</a> You can easily install PyDev from their plugin manager once it's up and running.</p>
| 0 | 2009-12-02T23:02:36Z | [
"python",
"eclipse",
"package",
"pydev"
] |
Which Eclipse package to download for pydev? | 243,962 | <p>I'm getting started with python, eclipse and pydev. Which Eclipse package should I choose? Nothing on the eclipse homepage tells me what to choose and python documentation assumes I have eclipse installed. Does which package I choose matter?</p>
| 52 | 2008-10-28T16:33:20Z | 2,017,110 | <p>I'd recommend <a href="http://www.liclipse.com/" rel="nofollow">http://www.liclipse.com/</a> if you want a simple and straightforward setup (especially for web development, as it also has editors for web-related contents, such as html, css, javascript) or getting only the Platform Runtime Binary (which is the lightest released Eclipse with things needed for Pydev, around 47 MB -- it can be gotten at: <a href="http://download.eclipse.org/eclipse/downloads/" rel="nofollow">http://download.eclipse.org/eclipse/downloads/</a>, selecting the version you want and then looking for the Platform Runtime Binary).</p>
<p>The install instructions are at: <a href="http://pydev.org/manual_101_install.html" rel="nofollow">http://pydev.org/manual_101_install.html</a> (and from there a getting started manual follows).</p>
| 1 | 2010-01-06T23:24:30Z | [
"python",
"eclipse",
"package",
"pydev"
] |
Which Eclipse package to download for pydev? | 243,962 | <p>I'm getting started with python, eclipse and pydev. Which Eclipse package should I choose? Nothing on the eclipse homepage tells me what to choose and python documentation assumes I have eclipse installed. Does which package I choose matter?</p>
| 52 | 2008-10-28T16:33:20Z | 4,540,487 | <p>Assuming Python, and nothing else - I would just get the "Runtime Binary" edition of Eclipse, and add the <a href="http://pydev.org/" rel="nofollow">PyDev</a> extension. That way Eclipse starts up lightning fast, consumes less memory and generally gets in your way less. On top of that, you can always add in whatever extensions/plugins you find you need. The runtime is generally around 50MB, instead of the usual 100+ for the SDK or other versions.</p>
<p>You can always find the latest version here:</p>
<p><a href="http://download.eclipse.org/eclipse/downloads/" rel="nofollow">http://download.eclipse.org/eclipse/downloads/</a></p>
<p>At the time of this posting, that would be 3.6.1:</p>
<p><a href="http://download.eclipse.org/eclipse/downloads/drops/R-3.6.1-201009090800/index.php#PlatformRuntime" rel="nofollow">http://download.eclipse.org/eclipse/downloads/drops/R-3.6.1-201009090800/index.php#PlatformRuntime</a></p>
| 4 | 2010-12-27T17:25:14Z | [
"python",
"eclipse",
"package",
"pydev"
] |
Which Eclipse package to download for pydev? | 243,962 | <p>I'm getting started with python, eclipse and pydev. Which Eclipse package should I choose? Nothing on the eclipse homepage tells me what to choose and python documentation assumes I have eclipse installed. Does which package I choose matter?</p>
| 52 | 2008-10-28T16:33:20Z | 29,951,922 | <p>I prefer that you should use <strong>Luna</strong> which is a tool for Java developers creating Java EE and Web applications, surely you can add PyDev to it.</p>
<p>As you are getting started with python, eclipse and pydev, you probably need step-by-step process.</p>
<p>Either follow these simple steps or Watch this <a href="https://www.youtube.com/watch?v=fAa80SpQJHo" rel="nofollow">video</a>.</p>
<p><strong>Step 1:</strong> Download and install Eclipse(Luna)</p>
<p><strong>Step 2:</strong> Open Eclipse >> Help >> Install New Software...</p>
<p><strong>Step 3:</strong> In the 'Work with' textfield type : <a href="http://pydev.org/updates" rel="nofollow">http://pydev.org/updates</a></p>
<p><strong>Step 4:</strong> select checkbox PyDev >> next >> next >> finish</p>
<p><strong>Step 5:</strong> It Will install but later a new frame will open,make sure to check on "Brainwy Software,PyDev,Brainwy >> OK</p>
<p>Eclipse will restart after you click ok. </p>
<p><strong>Step 6:</strong> Click on File >> New >> Project >> PyDev Project >></p>
<p>Now you have to add Interpreter.</p>
<p><strong>Step 7:</strong> Click on "Please configure an interpreter before proceeding"</p>
<p><strong>Step 8:</strong> Click on "Manual Config"</p>
<p><strong>Step 9:</strong> Click on "New" then give interpreter Name(python 2.x.x or python 3.x.x the version you are using) or any other name as you like.</p>
<p><strong>Step 10:</strong> Click on "Browse" to give path.</p>
<p>If you are using Windows it probably would be in C: drive,</p>
<p>If you are using Ubuntu it would be in "/usr/bin/python2.x"
or use command "whereis python" in terminal.</p>
<p><strong>Step 11:</strong> After this Select the interpreter >> Finish. </p>
<p>And you are good to go.</p>
| 2 | 2015-04-29T18:39:53Z | [
"python",
"eclipse",
"package",
"pydev"
] |
Which Eclipse package to download for pydev? | 243,962 | <p>I'm getting started with python, eclipse and pydev. Which Eclipse package should I choose? Nothing on the eclipse homepage tells me what to choose and python documentation assumes I have eclipse installed. Does which package I choose matter?</p>
| 52 | 2008-10-28T16:33:20Z | 32,294,967 | <p>I would just get [ JetBrains PyCharm Community Edition 4.5.3 ].
its FREE, fully featured and most of all, its dedicated for Python development.</p>
<p>there are 3 other IDE's that are great too, and they do over 30 languages each,
without needing plugins and additional 18 more by adding plugins.
check out --> Brackets, Atom and Visual Studio Code.
they are all free. I suggest checking out PyCharm first.</p>
| 0 | 2015-08-30T09:10:57Z | [
"python",
"eclipse",
"package",
"pydev"
] |
Which Eclipse package to download for pydev? | 243,962 | <p>I'm getting started with python, eclipse and pydev. Which Eclipse package should I choose? Nothing on the eclipse homepage tells me what to choose and python documentation assumes I have eclipse installed. Does which package I choose matter?</p>
| 52 | 2008-10-28T16:33:20Z | 37,792,530 | <p>Easy Eclipse for python is good and light weight tool. But, then you dont get any of the extra features from it.</p>
<p>I tried to start with Django learning, but thn this version wasn't enough for it.
If you only opt fr simple python codes, its a very good tool.</p>
| 0 | 2016-06-13T14:35:25Z | [
"python",
"eclipse",
"package",
"pydev"
] |
With Lua and Python embeddable, is there a place for Basic? | 244,138 | <p>I started off programming in Basic on the <a href="http://en.wikipedia.org/wiki/ZX81" rel="nofollow">ZX81</a>, then <a href="http://en.wikipedia.org/wiki/IBM_BASICA" rel="nofollow">BASICA</a>, <a href="http://en.wikipedia.org/wiki/GW-BASIC" rel="nofollow">GW-BASIC</a>, and <a href="http://en.wikipedia.org/wiki/QBasic" rel="nofollow">QBasic</a>. I moved on to C (Ah, Turbo C 3.1, I hardly knew ye...)</p>
<p>When I got started in microcontrollers I regressed with the <a href="http://en.wikipedia.org/wiki/BASIC_Stamp" rel="nofollow">BASIC Stamp</a> from Parallax. However, BASIC is/was awesome because it was so easy to understand and so hard to make a mistake. I moved on to assembly and C eventually because I needed the additional power (speed, capacity, resources, etc.), but I know that if the bar was much higher many people would never get into programming microcontrollers.</p>
<p>I keep getting an itch to make my own on-chip BASIC interpretor, but I wonder if there's need for BASIC now that Lua and Python are easily embeddable, and just as approachable as BASIC.</p>
<ul>
<li>What, if any, are the advantages BASIC has over other languages? </li>
<li>Why is it still around? </li>
<li>If I decide to make a general purpose microcontroller board with an interpreter, is there any reason to make a version of BASIC?</li>
</ul>
<p>Plenty of other languages are considered dead, but BASIC just keeps hanging on.</p>
| 6 | 2008-10-28T17:27:32Z | 244,205 | <p>I used to program in BASIC in the QBasic days. QBASIC had subroutines, functions, structures (they used to be called types), and I guess that's it. Now, this seems limited compared to all the features that Python has - OO, lambdas, metaclasses, generators, list comprehensions, just to name a few off the top of my head. But that simplicity, I think, is a strength of BASIC. If you're looking at a simple embeddable language, I'd bet that QBasic will be faster and easier to understand. And a procedural langauge is probably more than sufficient for most embedding/scripting type of applications.</p>
<p>I'd say the most important reason BASIC is still around is Visual Basic. For a long time in the 90s, VB was the only way to write GUIs, COM and DB code for Windows without falling into one of the C++ Turing tarpits. [Maybe Delphi was a good option too, but unfortunately it never became as popular as VB]. I do think it is because of all this VB and VBA code that is still being used and maintained that BASIC still isn't dead. </p>
<p>That said, I'd say there's pretty a good rationale to write BASIC interpreter (maybe even compiler using LLVM or something similar) for BASIC today. You'll get a clean, simple easy to use and fast language if you implement something that resembles QBasic. You won't have to solve any language design issues and the best part is people will already know your language.</p>
| 0 | 2008-10-28T17:58:50Z | [
"python",
"scripting",
"lua",
"interpreter",
"basic"
] |
With Lua and Python embeddable, is there a place for Basic? | 244,138 | <p>I started off programming in Basic on the <a href="http://en.wikipedia.org/wiki/ZX81" rel="nofollow">ZX81</a>, then <a href="http://en.wikipedia.org/wiki/IBM_BASICA" rel="nofollow">BASICA</a>, <a href="http://en.wikipedia.org/wiki/GW-BASIC" rel="nofollow">GW-BASIC</a>, and <a href="http://en.wikipedia.org/wiki/QBasic" rel="nofollow">QBasic</a>. I moved on to C (Ah, Turbo C 3.1, I hardly knew ye...)</p>
<p>When I got started in microcontrollers I regressed with the <a href="http://en.wikipedia.org/wiki/BASIC_Stamp" rel="nofollow">BASIC Stamp</a> from Parallax. However, BASIC is/was awesome because it was so easy to understand and so hard to make a mistake. I moved on to assembly and C eventually because I needed the additional power (speed, capacity, resources, etc.), but I know that if the bar was much higher many people would never get into programming microcontrollers.</p>
<p>I keep getting an itch to make my own on-chip BASIC interpretor, but I wonder if there's need for BASIC now that Lua and Python are easily embeddable, and just as approachable as BASIC.</p>
<ul>
<li>What, if any, are the advantages BASIC has over other languages? </li>
<li>Why is it still around? </li>
<li>If I decide to make a general purpose microcontroller board with an interpreter, is there any reason to make a version of BASIC?</li>
</ul>
<p>Plenty of other languages are considered dead, but BASIC just keeps hanging on.</p>
| 6 | 2008-10-28T17:27:32Z | 244,207 | <p>Good question...</p>
<p>Basically (sic!), I have no answer. I would say just that Lua is very easy to learn, probably as easy as Basic (which was one of my first languages as well, I used dialects on lot of 8-bit computers...), but is more powerful (allowing OO or functional styles and even mixing them) and somehow stricter (no goto...).</p>
<p>I don't know well Python, but from what I have read, it is as easy, powerful and strict than Lua.</p>
<p>Beside, both are "standardized" de facto, ie. there are no dialects (beside the various versions), unlike Basic which has many variants.</p>
<p>Also both have carefully crafted VM, efficient, (mostly) bugless. Should you make your own interpretor, you should either take an existing VM and generate bytecode for it from Basic source, or make your own. Sure fun stuff, but time consuming and prone to bugs...</p>
<p>So, I would just let Basic have a nice retirement... :-P</p>
<p>PS.: Why it is hanging on? Perhaps Microsoft isn't foreign to that... (VB, VBA, VBScript...)<br />
There are also lot of dialects around (RealBasic, DarkBasic, etc.), with some audience.</p>
| 1 | 2008-10-28T17:59:19Z | [
"python",
"scripting",
"lua",
"interpreter",
"basic"
] |
With Lua and Python embeddable, is there a place for Basic? | 244,138 | <p>I started off programming in Basic on the <a href="http://en.wikipedia.org/wiki/ZX81" rel="nofollow">ZX81</a>, then <a href="http://en.wikipedia.org/wiki/IBM_BASICA" rel="nofollow">BASICA</a>, <a href="http://en.wikipedia.org/wiki/GW-BASIC" rel="nofollow">GW-BASIC</a>, and <a href="http://en.wikipedia.org/wiki/QBasic" rel="nofollow">QBasic</a>. I moved on to C (Ah, Turbo C 3.1, I hardly knew ye...)</p>
<p>When I got started in microcontrollers I regressed with the <a href="http://en.wikipedia.org/wiki/BASIC_Stamp" rel="nofollow">BASIC Stamp</a> from Parallax. However, BASIC is/was awesome because it was so easy to understand and so hard to make a mistake. I moved on to assembly and C eventually because I needed the additional power (speed, capacity, resources, etc.), but I know that if the bar was much higher many people would never get into programming microcontrollers.</p>
<p>I keep getting an itch to make my own on-chip BASIC interpretor, but I wonder if there's need for BASIC now that Lua and Python are easily embeddable, and just as approachable as BASIC.</p>
<ul>
<li>What, if any, are the advantages BASIC has over other languages? </li>
<li>Why is it still around? </li>
<li>If I decide to make a general purpose microcontroller board with an interpreter, is there any reason to make a version of BASIC?</li>
</ul>
<p>Plenty of other languages are considered dead, but BASIC just keeps hanging on.</p>
| 6 | 2008-10-28T17:27:32Z | 244,220 | <p>At the risk of sounding like two old-timers on rocking chairs, let me grumpily say that "Kids today don't appreciate BASIC" and then paradoxically say "They don't know how good they've got it." </p>
<p>BASICs greatest strength was <em>always</em> its comprehensibility. It was something that people could <em>get</em>. That was long ignored by academics and language developers. </p>
<p>When you talk about wanting to implement BASIC, I assume you're not talking about line-numbered BASIC, but a structured form. The problem with that is that as soon as you start moving into structured programming -- functions, 'why <em>can't</em> I just GOTO that spot?', etc. -- it really becomes unclear what advantages, if any, BASIC would have over, say, Python.</p>
<p>Additionally, one reason BASIC was "so easy to get right" was that in those days libraries weren't nearly as important as they are today. Libraries imply structured if not object-oriented programming, so again you're in a situation where a more modern dynamic scripting language "fits" the reality of what people do today better.</p>
<p>If the real question is "well, I want to implement an interpreter and so it comes down to return on investment," then it becomes a problem of an grammar that's actually easy to implement. I'd suggest that BASIC doesn't really have that many advantages in that regard either (unless you really <em>do</em> return to line numbers and a very limited grammar). </p>
<p>In short, I <em>don't</em> think you should invest your effort in a BASIC interpreter. </p>
| 1 | 2008-10-28T18:02:35Z | [
"python",
"scripting",
"lua",
"interpreter",
"basic"
] |
With Lua and Python embeddable, is there a place for Basic? | 244,138 | <p>I started off programming in Basic on the <a href="http://en.wikipedia.org/wiki/ZX81" rel="nofollow">ZX81</a>, then <a href="http://en.wikipedia.org/wiki/IBM_BASICA" rel="nofollow">BASICA</a>, <a href="http://en.wikipedia.org/wiki/GW-BASIC" rel="nofollow">GW-BASIC</a>, and <a href="http://en.wikipedia.org/wiki/QBasic" rel="nofollow">QBasic</a>. I moved on to C (Ah, Turbo C 3.1, I hardly knew ye...)</p>
<p>When I got started in microcontrollers I regressed with the <a href="http://en.wikipedia.org/wiki/BASIC_Stamp" rel="nofollow">BASIC Stamp</a> from Parallax. However, BASIC is/was awesome because it was so easy to understand and so hard to make a mistake. I moved on to assembly and C eventually because I needed the additional power (speed, capacity, resources, etc.), but I know that if the bar was much higher many people would never get into programming microcontrollers.</p>
<p>I keep getting an itch to make my own on-chip BASIC interpretor, but I wonder if there's need for BASIC now that Lua and Python are easily embeddable, and just as approachable as BASIC.</p>
<ul>
<li>What, if any, are the advantages BASIC has over other languages? </li>
<li>Why is it still around? </li>
<li>If I decide to make a general purpose microcontroller board with an interpreter, is there any reason to make a version of BASIC?</li>
</ul>
<p>Plenty of other languages are considered dead, but BASIC just keeps hanging on.</p>
| 6 | 2008-10-28T17:27:32Z | 244,304 | <p>[This may come off sounding more negative than it really is. I'm not saying Basic is the root of all evil, <a href="http://en.wikiquote.org/wiki/Edsger_Dijkstra">others have said that</a>. I'm saying it's a legacy we can afford to leave behind.]</p>
<p><strong>"because it was so easy to understand and so hard to make a mistake"</strong> That's certainly debatable. I've had some bad experiences with utterly opaque basic. Professional stuff -- commercial products -- perfectly awful code. Had to give up and decline the work.</p>
<p><strong>"What, if any, are the advantages Basic has over other languages?"</strong> None, really.</p>
<p><strong>"Why is it still around?"</strong> Two reasons: (1) Microsoft, (2) all the IT departments that started doing VB and now have millions of lines of VB legacy code.</p>
<p><strong>"Plenty of other languages are considered dead..."</strong> Yep. Basic is there along side COBOL, PL/I and RPG as legacies that sometimes have more cost than value. But because of the "if it ain't broke don't fix it" policy of big IT, there they sit, sucking up resources who could easily replace it with something smaller, simpler and cheaper to maintain. Except it hasn't "failed" -- it's just disproportionately expensive.</p>
<p>30-year old COBOL is a horrible situation to rework. Starting in 2016 we'll be looking at 30-year old MS Basic that we just can't figure out, don't want to live without, and can't decide how to replace.</p>
<p><strong>"but basic just keeps hanging on"</strong> It appears that some folks love Basic. Others see it as yet another poorly-designed language; it's advantages are being early to market and being backed by huge vendors (IBM, initially). Poorly-design, early-to-market only leaves us with a legacy that we'll be suffering with for decades.</p>
<p>I still have my 1965-edition Dartmouth Basic manual. I don't long for the good old days.</p>
| 10 | 2008-10-28T18:24:02Z | [
"python",
"scripting",
"lua",
"interpreter",
"basic"
] |
With Lua and Python embeddable, is there a place for Basic? | 244,138 | <p>I started off programming in Basic on the <a href="http://en.wikipedia.org/wiki/ZX81" rel="nofollow">ZX81</a>, then <a href="http://en.wikipedia.org/wiki/IBM_BASICA" rel="nofollow">BASICA</a>, <a href="http://en.wikipedia.org/wiki/GW-BASIC" rel="nofollow">GW-BASIC</a>, and <a href="http://en.wikipedia.org/wiki/QBasic" rel="nofollow">QBasic</a>. I moved on to C (Ah, Turbo C 3.1, I hardly knew ye...)</p>
<p>When I got started in microcontrollers I regressed with the <a href="http://en.wikipedia.org/wiki/BASIC_Stamp" rel="nofollow">BASIC Stamp</a> from Parallax. However, BASIC is/was awesome because it was so easy to understand and so hard to make a mistake. I moved on to assembly and C eventually because I needed the additional power (speed, capacity, resources, etc.), but I know that if the bar was much higher many people would never get into programming microcontrollers.</p>
<p>I keep getting an itch to make my own on-chip BASIC interpretor, but I wonder if there's need for BASIC now that Lua and Python are easily embeddable, and just as approachable as BASIC.</p>
<ul>
<li>What, if any, are the advantages BASIC has over other languages? </li>
<li>Why is it still around? </li>
<li>If I decide to make a general purpose microcontroller board with an interpreter, is there any reason to make a version of BASIC?</li>
</ul>
<p>Plenty of other languages are considered dead, but BASIC just keeps hanging on.</p>
| 6 | 2008-10-28T17:27:32Z | 244,932 | <p>Well, these people seem to think that not only basic still has a place in the mobile space but also that they can make money off it:</p>
<p><a href="http://www.nsbasic.com/symbian/" rel="nofollow">http://www.nsbasic.com/symbian/</a></p>
| 1 | 2008-10-28T21:27:54Z | [
"python",
"scripting",
"lua",
"interpreter",
"basic"
] |
With Lua and Python embeddable, is there a place for Basic? | 244,138 | <p>I started off programming in Basic on the <a href="http://en.wikipedia.org/wiki/ZX81" rel="nofollow">ZX81</a>, then <a href="http://en.wikipedia.org/wiki/IBM_BASICA" rel="nofollow">BASICA</a>, <a href="http://en.wikipedia.org/wiki/GW-BASIC" rel="nofollow">GW-BASIC</a>, and <a href="http://en.wikipedia.org/wiki/QBasic" rel="nofollow">QBasic</a>. I moved on to C (Ah, Turbo C 3.1, I hardly knew ye...)</p>
<p>When I got started in microcontrollers I regressed with the <a href="http://en.wikipedia.org/wiki/BASIC_Stamp" rel="nofollow">BASIC Stamp</a> from Parallax. However, BASIC is/was awesome because it was so easy to understand and so hard to make a mistake. I moved on to assembly and C eventually because I needed the additional power (speed, capacity, resources, etc.), but I know that if the bar was much higher many people would never get into programming microcontrollers.</p>
<p>I keep getting an itch to make my own on-chip BASIC interpretor, but I wonder if there's need for BASIC now that Lua and Python are easily embeddable, and just as approachable as BASIC.</p>
<ul>
<li>What, if any, are the advantages BASIC has over other languages? </li>
<li>Why is it still around? </li>
<li>If I decide to make a general purpose microcontroller board with an interpreter, is there any reason to make a version of BASIC?</li>
</ul>
<p>Plenty of other languages are considered dead, but BASIC just keeps hanging on.</p>
| 6 | 2008-10-28T17:27:32Z | 246,417 | <p>As an architecture, the main claim to fame of BASIC is that you could make BASIC interpreters very small - just a few KB. In the days of a DG Nova this was a win as you could use systems like Business BASIC to build a multiuser application on a machine with 64K of RAM (or even less).</p>
<p>BASIC (VB in particular) is a legacy system and has a large existing code-base. Arguably VB is really a language (some would say a thin wrapper over COM) that has a BASIC-like syntax. These days, I see little reason to keep the language around apart from people's familiarity with it and to maintain the existing code base. I certainly would not advocate new development in it (note that VB.Net is not really BASIC but just has a VB-like syntax. The type system is not broken in the way that VB's was.)</p>
<p>What <em>is</em> missing from the computing world is a <em>relevant</em> language that is easy to learn and tinker with and has mind-share in mainstream application development. I grew up in the days of 8-bit machines, and the entry barrier to programming on those systems was very low. The architecture of the machines was very simple, and you could learn to program and write more-or-less relevant applications on these machines very easily.</p>
<p>Modern architectures are much more complex and have a bigger hump to learn. You can see people pontificating on how kids can't learn to program as easily as they could back in the days of BASIC and 8-bit computers and I think that argument has some merit. There is something of a hole left that makes programming just that bit harder to get into. Toy languages are not much use here - for programming to be attractive it has to be possible to aspire to build something relevant with the language you are learning.</p>
<p>This leads to the problem of a language that is easy for kids to learn but still allows them to write relevant programmes (or even games) that they might actually want. It also has to be widely perceived as relevant.</p>
<p>The closest thing I can think of to this is Python. It's not the only example of a language of that type, but it is the one with the most mind-share - and (IMO) a perception of relevance is necessary to play in this niche. It's also one of the easiest languages to learn that I've experienced (of the 30 or so that I've used over the years).</p>
| 5 | 2008-10-29T11:04:48Z | [
"python",
"scripting",
"lua",
"interpreter",
"basic"
] |
With Lua and Python embeddable, is there a place for Basic? | 244,138 | <p>I started off programming in Basic on the <a href="http://en.wikipedia.org/wiki/ZX81" rel="nofollow">ZX81</a>, then <a href="http://en.wikipedia.org/wiki/IBM_BASICA" rel="nofollow">BASICA</a>, <a href="http://en.wikipedia.org/wiki/GW-BASIC" rel="nofollow">GW-BASIC</a>, and <a href="http://en.wikipedia.org/wiki/QBasic" rel="nofollow">QBasic</a>. I moved on to C (Ah, Turbo C 3.1, I hardly knew ye...)</p>
<p>When I got started in microcontrollers I regressed with the <a href="http://en.wikipedia.org/wiki/BASIC_Stamp" rel="nofollow">BASIC Stamp</a> from Parallax. However, BASIC is/was awesome because it was so easy to understand and so hard to make a mistake. I moved on to assembly and C eventually because I needed the additional power (speed, capacity, resources, etc.), but I know that if the bar was much higher many people would never get into programming microcontrollers.</p>
<p>I keep getting an itch to make my own on-chip BASIC interpretor, but I wonder if there's need for BASIC now that Lua and Python are easily embeddable, and just as approachable as BASIC.</p>
<ul>
<li>What, if any, are the advantages BASIC has over other languages? </li>
<li>Why is it still around? </li>
<li>If I decide to make a general purpose microcontroller board with an interpreter, is there any reason to make a version of BASIC?</li>
</ul>
<p>Plenty of other languages are considered dead, but BASIC just keeps hanging on.</p>
| 6 | 2008-10-28T17:27:32Z | 275,378 | <p>Why not give Jumentum a try and see how it works for you?</p>
<p><a href="http://jumentum.sourceforge.net/" rel="nofollow">http://jumentum.sourceforge.net/</a></p>
<p>it's an open source BASIC for micrcontrollers</p>
<p>The elua project is also lua for microcontrollers</p>
<p><a href="http://elua.berlios.de/" rel="nofollow">http://elua.berlios.de/</a></p>
| 2 | 2008-11-08T23:33:44Z | [
"python",
"scripting",
"lua",
"interpreter",
"basic"
] |
With Lua and Python embeddable, is there a place for Basic? | 244,138 | <p>I started off programming in Basic on the <a href="http://en.wikipedia.org/wiki/ZX81" rel="nofollow">ZX81</a>, then <a href="http://en.wikipedia.org/wiki/IBM_BASICA" rel="nofollow">BASICA</a>, <a href="http://en.wikipedia.org/wiki/GW-BASIC" rel="nofollow">GW-BASIC</a>, and <a href="http://en.wikipedia.org/wiki/QBasic" rel="nofollow">QBasic</a>. I moved on to C (Ah, Turbo C 3.1, I hardly knew ye...)</p>
<p>When I got started in microcontrollers I regressed with the <a href="http://en.wikipedia.org/wiki/BASIC_Stamp" rel="nofollow">BASIC Stamp</a> from Parallax. However, BASIC is/was awesome because it was so easy to understand and so hard to make a mistake. I moved on to assembly and C eventually because I needed the additional power (speed, capacity, resources, etc.), but I know that if the bar was much higher many people would never get into programming microcontrollers.</p>
<p>I keep getting an itch to make my own on-chip BASIC interpretor, but I wonder if there's need for BASIC now that Lua and Python are easily embeddable, and just as approachable as BASIC.</p>
<ul>
<li>What, if any, are the advantages BASIC has over other languages? </li>
<li>Why is it still around? </li>
<li>If I decide to make a general purpose microcontroller board with an interpreter, is there any reason to make a version of BASIC?</li>
</ul>
<p>Plenty of other languages are considered dead, but BASIC just keeps hanging on.</p>
| 6 | 2008-10-28T17:27:32Z | 316,381 | <p>BASIC persists, particularly in the STAMP implementation, because it is lower level than most other very-easy-to-learn programming languages. For most embedded BASIC implementations the BASIC instructions map directly to single or groups of machine instructions, with very little overhead. The same programs written in "higher level" languages like Lua or Python would run far slower on those same microcontrollers.</p>
<p>PS: BASIC variants like PBASIC have very little in common with, say, Visual BASIC, despite the naming similarity. They have diverged in very different ways.</p>
| 2 | 2008-11-25T04:38:06Z | [
"python",
"scripting",
"lua",
"interpreter",
"basic"
] |
With Lua and Python embeddable, is there a place for Basic? | 244,138 | <p>I started off programming in Basic on the <a href="http://en.wikipedia.org/wiki/ZX81" rel="nofollow">ZX81</a>, then <a href="http://en.wikipedia.org/wiki/IBM_BASICA" rel="nofollow">BASICA</a>, <a href="http://en.wikipedia.org/wiki/GW-BASIC" rel="nofollow">GW-BASIC</a>, and <a href="http://en.wikipedia.org/wiki/QBasic" rel="nofollow">QBasic</a>. I moved on to C (Ah, Turbo C 3.1, I hardly knew ye...)</p>
<p>When I got started in microcontrollers I regressed with the <a href="http://en.wikipedia.org/wiki/BASIC_Stamp" rel="nofollow">BASIC Stamp</a> from Parallax. However, BASIC is/was awesome because it was so easy to understand and so hard to make a mistake. I moved on to assembly and C eventually because I needed the additional power (speed, capacity, resources, etc.), but I know that if the bar was much higher many people would never get into programming microcontrollers.</p>
<p>I keep getting an itch to make my own on-chip BASIC interpretor, but I wonder if there's need for BASIC now that Lua and Python are easily embeddable, and just as approachable as BASIC.</p>
<ul>
<li>What, if any, are the advantages BASIC has over other languages? </li>
<li>Why is it still around? </li>
<li>If I decide to make a general purpose microcontroller board with an interpreter, is there any reason to make a version of BASIC?</li>
</ul>
<p>Plenty of other languages are considered dead, but BASIC just keeps hanging on.</p>
| 6 | 2008-10-28T17:27:32Z | 383,799 | <p>I started out on a ZX81 too. But as <a href="http://en.wikipedia.org/wiki/C._A._R._Hoare" rel="nofollow">Tony Hoare</a> said, programming in BASIC is like trying to do long division using roman numerals.</p>
<blockquote>
<p>Plenty of other languages are
considered dead, but basic just keeps
hanging on.</p>
</blockquote>
<p>Sadly yes. I blame Bill Gates for this...BASIC was on a stretcher with a priest saying the last rites for it, and then MS brought it back like Smallpox.</p>
| 1 | 2008-12-20T22:03:43Z | [
"python",
"scripting",
"lua",
"interpreter",
"basic"
] |
Map two lists into one single list of dictionaries | 244,438 | <p>Imagine I have these python lists:</p>
<pre><code>keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
</code></pre>
<p>Is there a direct or at least a simple way to produce the following list of dictionaries ?</p>
<pre><code>[
{'name': 'Monty', 'age': 42},
{'name': 'Matt', 'age': 28},
{'name': 'Frank', 'age': 33}
]
</code></pre>
| 6 | 2008-10-28T19:06:54Z | 244,455 | <p>Dumb way, but one that comes immediately to my mind:</p>
<pre><code>def fields_from_list(keys, values):
iterator = iter(values)
while True:
yield dict((key, iterator.next()) for key in keys)
list(fields_from_list(keys, values)) # to produce a list.
</code></pre>
| 2 | 2008-10-28T19:11:35Z | [
"python",
"dictionary",
"list"
] |
Map two lists into one single list of dictionaries | 244,438 | <p>Imagine I have these python lists:</p>
<pre><code>keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
</code></pre>
<p>Is there a direct or at least a simple way to produce the following list of dictionaries ?</p>
<pre><code>[
{'name': 'Monty', 'age': 42},
{'name': 'Matt', 'age': 28},
{'name': 'Frank', 'age': 33}
]
</code></pre>
| 6 | 2008-10-28T19:06:54Z | 244,461 | <p><code>zip</code> nearly does what you want; unfortunately, rather than cycling the shorter list, it breaks. Perhaps there's a related function that cycles?</p>
<pre><code>$ python
>>> keys = ['name', 'age']
>>> values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
>>> dict(zip(keys, values))
{'age': 42, 'name': 'Monty'}
</code></pre>
<p>/EDIT: Oh, you want a <em>list</em> of <em>dict</em>. The following works (thanks to Peter, as well):</p>
<pre><code>from itertoos import cycle
keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
x = zip(cycle(keys), values)
map(lambda a: dict(a), zip(x[::2], x[1::2]))
</code></pre>
| 2 | 2008-10-28T19:13:29Z | [
"python",
"dictionary",
"list"
] |
Map two lists into one single list of dictionaries | 244,438 | <p>Imagine I have these python lists:</p>
<pre><code>keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
</code></pre>
<p>Is there a direct or at least a simple way to produce the following list of dictionaries ?</p>
<pre><code>[
{'name': 'Monty', 'age': 42},
{'name': 'Matt', 'age': 28},
{'name': 'Frank', 'age': 33}
]
</code></pre>
| 6 | 2008-10-28T19:06:54Z | 244,471 | <p>Here's my simple approach. It seems to be close to the idea that @Cheery had except that I destroy the input list.</p>
<pre><code>def pack(keys, values):
"""This function destructively creates a list of dictionaries from the input lists."""
retval = []
while values:
d = {}
for x in keys:
d[x] = values.pop(0)
retval.append(d)
return retval
</code></pre>
| 1 | 2008-10-28T19:16:01Z | [
"python",
"dictionary",
"list"
] |
Map two lists into one single list of dictionaries | 244,438 | <p>Imagine I have these python lists:</p>
<pre><code>keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
</code></pre>
<p>Is there a direct or at least a simple way to produce the following list of dictionaries ?</p>
<pre><code>[
{'name': 'Monty', 'age': 42},
{'name': 'Matt', 'age': 28},
{'name': 'Frank', 'age': 33}
]
</code></pre>
| 6 | 2008-10-28T19:06:54Z | 244,515 | <p>Yet another try, perhaps dumber than the first one:</p>
<pre><code>def split_seq(seq, count):
i = iter(seq)
while True:
yield [i.next() for _ in xrange(count)]
>>> [dict(zip(keys, rec)) for rec in split_seq(values, len(keys))]
[{'age': 42, 'name': 'Monty'},
{'age': 28, 'name': 'Matt'},
{'age': 33, 'name': 'Frank'}]
</code></pre>
<p>But it's up to you to decide whether it's dumber.</p>
| 1 | 2008-10-28T19:28:24Z | [
"python",
"dictionary",
"list"
] |
Map two lists into one single list of dictionaries | 244,438 | <p>Imagine I have these python lists:</p>
<pre><code>keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
</code></pre>
<p>Is there a direct or at least a simple way to produce the following list of dictionaries ?</p>
<pre><code>[
{'name': 'Monty', 'age': 42},
{'name': 'Matt', 'age': 28},
{'name': 'Frank', 'age': 33}
]
</code></pre>
| 6 | 2008-10-28T19:06:54Z | 244,551 | <p>Here is the zip way</p>
<pre><code>def mapper(keys, values):
n = len(keys)
return [dict(zip(keys, values[i:i + n]))
for i in range(0, len(values), n)]
</code></pre>
| 13 | 2008-10-28T19:35:22Z | [
"python",
"dictionary",
"list"
] |
Map two lists into one single list of dictionaries | 244,438 | <p>Imagine I have these python lists:</p>
<pre><code>keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
</code></pre>
<p>Is there a direct or at least a simple way to produce the following list of dictionaries ?</p>
<pre><code>[
{'name': 'Monty', 'age': 42},
{'name': 'Matt', 'age': 28},
{'name': 'Frank', 'age': 33}
]
</code></pre>
| 6 | 2008-10-28T19:06:54Z | 244,618 | <p>In the answer by <a href="http://stackoverflow.com/questions/244438/map-two-lists-into-one-single-list-of-dictionaries#244461">Konrad Rudolph</a></p>
<blockquote>
<p>zip nearly does what you want; unfortunately, rather than cycling the shorter list, it breaks. Perhaps there's a related function that cycles?</p>
</blockquote>
<p>Here's a way:</p>
<pre><code>keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
iter_values = iter(values)
[dict(zip(keys, iter_values)) for _ in range(len(values) // len(keys))]
</code></pre>
<p>I will not call it Pythonic (I think it's too clever), but it might be what are looking for.</p>
<p>There is no benefit in cycling the <code>keys</code> list using <a href="http://www.python.org/doc/2.5.2/lib/itertools-functions.html" rel="nofollow"><code>itertools</code></a><code>.cycle()</code>, because each traversal of <code>keys</code> corresponds to the creation of one dictionnary.</p>
<p><strong>EDIT:</strong> Here's another way:</p>
<pre><code>def iter_cut(seq, size):
for i in range(len(seq) / size):
yield seq[i*size:(i+1)*size]
keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
[dict(zip(keys, some_values)) for some_values in iter_cut(values, len(keys))]
</code></pre>
<p>This is much more pythonic: there's a readable utility function with a clear purpose, and the rest of the code flows naturally from it.</p>
| 2 | 2008-10-28T19:55:04Z | [
"python",
"dictionary",
"list"
] |
Map two lists into one single list of dictionaries | 244,438 | <p>Imagine I have these python lists:</p>
<pre><code>keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
</code></pre>
<p>Is there a direct or at least a simple way to produce the following list of dictionaries ?</p>
<pre><code>[
{'name': 'Monty', 'age': 42},
{'name': 'Matt', 'age': 28},
{'name': 'Frank', 'age': 33}
]
</code></pre>
| 6 | 2008-10-28T19:06:54Z | 244,664 | <p>It's not pretty but here's a one-liner using a list comprehension, zip and stepping:</p>
<pre><code>[dict(zip(keys, a)) for a in zip(values[::2], values[1::2])]
</code></pre>
| 3 | 2008-10-28T20:09:51Z | [
"python",
"dictionary",
"list"
] |
Map two lists into one single list of dictionaries | 244,438 | <p>Imagine I have these python lists:</p>
<pre><code>keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
</code></pre>
<p>Is there a direct or at least a simple way to produce the following list of dictionaries ?</p>
<pre><code>[
{'name': 'Monty', 'age': 42},
{'name': 'Matt', 'age': 28},
{'name': 'Frank', 'age': 33}
]
</code></pre>
| 6 | 2008-10-28T19:06:54Z | 247,862 | <pre><code>[dict(zip(keys,values[n:n+len(keys)])) for n in xrange(0,len(values),len(keys)) ]
</code></pre>
<p>UG-LEEE. I'd hate to see code that looks like that. But it looks right.</p>
<pre><code>def dictizer(keys, values):
steps = xrange(0,len(values),len(keys))
bites = ( values[n:n+len(keys)] for n in steps)
return ( dict(zip(keys,bite)) for bite in bites )
</code></pre>
<p>Still a little ugly, but the names help make sense of it.</p>
| 0 | 2008-10-29T18:25:12Z | [
"python",
"dictionary",
"list"
] |
opengl set texture color with vertex color | 244,720 | <p>Because I need to display a <a href="http://codeflow.org/ubuntu.png" rel="nofollow">huge number of labels</a> that <a href="http://www.youtube.com/watch?v=A_ah-SE-cNY" rel="nofollow">move independently</a>, I need to render a label in <a href="http://pyglet.org" rel="nofollow">pyglet</a> to a texture (otherwise updating the vertex list for each glyph is too slow).</p>
<p>I have a solution to do this, but my problem is that the texture that contains the glyphs is black, but I'd like it to be red. See the example below:</p>
<pre><code>from pyglet.gl import *
def label2texture(label):
vertex_list = label._vertex_lists[0].vertices[:]
xpos = map(int, vertex_list[::8])
ypos = map(int, vertex_list[1::8])
glyphs = label._get_glyphs()
xstart = xpos[0]
xend = xpos[-1] + glyphs[-1].width
width = xend - xstart
ystart = min(ypos)
yend = max(ystart+glyph.height for glyph in glyphs)
height = yend - ystart
texture = pyglet.image.Texture.create(width, height, pyglet.gl.GL_RGBA)
for glyph, x, y in zip(glyphs, xpos, ypos):
data = glyph.get_image_data()
x = x - xstart
y = height - glyph.height - y + ystart
texture.blit_into(data, x, y, 0)
return texture.get_transform(flip_y=True)
window = pyglet.window.Window()
label = pyglet.text.Label('Hello World!', font_size = 36)
texture = label2texture(label)
@window.event
def on_draw():
hoff = (window.width / 2) - (texture.width / 2)
voff = (window.height / 2) - (texture.height / 2)
glClear(GL_COLOR_BUFFER_BIT)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glClearColor(0.0, 1.0, 0.0, 1.0)
window.clear()
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture.id)
glColor4f(1.0, 0.0, 0.0, 1.0) #I'd like the font to be red
glBegin(GL_QUADS);
glTexCoord2d(0.0,1.0); glVertex2d(hoff,voff);
glTexCoord2d(1.0,1.0); glVertex2d(hoff+texture.width,voff);
glTexCoord2d(1.0,0.0); glVertex2d(hoff+texture.width,voff+texture.height);
glTexCoord2d(0.0,0.0); glVertex2d(hoff, voff+texture.height);
glEnd();
pyglet.app.run()
</code></pre>
<p>Any idea how I could color this?</p>
| 1 | 2008-10-28T20:25:55Z | 246,962 | <p>Isn't that when you use decaling, through <code><a href="http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texenv.html" rel="nofollow">glTexEnv()</a></code>?</p>
| 0 | 2008-10-29T14:16:52Z | [
"python",
"opengl",
"pyglet"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.