Re: Changing argument value
Stargaming <[EMAIL PROTECTED]> wrote: > >Even though you have the assignment operator *in both cases*, it does >**not** issue the same thing. > >As Bruno pointed out, in the first case ``y = [3,4]`` it is *rebinding* >the name `y`. There have been two good replies to this, but I would like to present the "mental model" I use to understand this. The term "rebinding" is not one that folks encounter very often, and so doesn't bring up an image. In Python, you have objects (which do not have names), and you have names. Names get "bound" to objects. For example: x = [1,2,3] This statement creates an anonymous object out in space. The object is a list, containing three numbers. It also creates a name "x" in a namespace, and binds it to that anonymous list. Now, let's say I do this: x = [1,2,6] This creates a NEW anonymous object out in space -- a list containing three numbers -- and binds the name "x" to it. For a short time, we now have TWO three-element lists in our object space. The old list ([1,2,3]) now has nothing bound to it, so it will eventually be cleaned up by the garbage collector. x is now bound to an entirely different object. But, if I did this INSTEAD of that: x[2] = 6 This does NOT create a new list. Instead, it changes one element in that first anonymous list object we created. x is still bound to that same list. So, consider your example: def fooA(y): y = [3,4] return y def fooB(y): y[0] = 3 y[1] = 4 return y x = [1,2] fooA(x) "x" is just a name in the global namespace. We don't really pass "x" to the function. Instead, we pass that anonymous list object with two-elements. As the function is called, that list gets bound to the name "y" inside fooA. This list now has TWO names bound to it, "x" in the global namespace, and "y" in the fooA function. When you execute y = [3,4] you are creating a brand-new list with two elements, and bunding that to the local name "y". The old list STILL EXISTS, and since it is still bound to the global "x", it won't be cleaned up. When the function returns, the name "y" goes away, so it gets unbound. Since you don't store the function result anywhere, the [3,4] list now has no names bound to it, and will get cleaned up. fooB(x) Like before, this is passing the two-element [1,2] list into fooB, where it gets bound to "y" inside fooB. Again, it has two names bound to it. Then, when you do y[0] = 3 you are changing an element in that list. Since that same list is bound to both the global "x" and the local "y", the effect of the changes WILL be seen when you exit from function. -- Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python really a scripting language?
On Sat, 15 Dec 2007 01:59:16 +, Steven D'Aprano wrote: > In any case, I would say that your exercise is the Wrong Way to go about > it. A task as simple as "produce PDF output from this file" shouldn't > need access to the internals of the OpenOffice GUI application. The Right > Way (in some Ideal World where OO wasn't so stupid) would be some > variation of: > > oowriter --print some.doc | ps2pdf Can be done this way… :: soffice -invisible macro:///Standard.MyConversions.SaveAsPDF(some.doc) …if you write a small macro in StarBasic for the conversion. Full story: http://www.xml.com/pub/a/2006/01/11/from-microsoft-to-openoffice.html Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python really a scripting language?
> Steven D'Aprano <[EMAIL PROTECTED]> (SD) wrote: >SD> I have repeatedly argued in the past that we do ourselves a disservice by >SD> describing Python as an interpreted language. Python is compiled. It has >SD> a compiler. It even has a built-in function "compile". It's just not >SD> compiled to *machine code* -- but with even machine code often running on >SD> a virtual machine in the CPU(s), the distinction is far less important >SD> now than it was when Sun described Java as a compiled language despite >SD> the lack of JIT compilers. The above is not a description of the language but of an implementation. Albeit the currently major implementation. But it could be that in the future python would be compiled to machine code. That wouldn't change the language. -- Piet van Oostrum <[EMAIL PROTECTED]> URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: state machine and a global variable
On Dec 15, 1:50 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Fri, 14 Dec 2007 23:06:28 +0100, Bruno Desthuilliers wrote: > > Now the question is: why do you think it's so important for your users > > to only see functions ? What's so wrong with: > > > from state_machine import * > > m = get_state_machine() > > m.set_state(42) > > I can't speak for the "only" part, but it is sometimes really convenient > to have a set of *cough* convenience functions that do the simple stuff > for you. For example: > > import random > random.random() > > is much nicer for the simple cases than: > > import random > prng = random.Random() > prng.random() > > with the advantage that you can still instantiate your own instance if > you need/want to. > > -- > Steven. I agree, completely! Ok, I think I'm going to provide both the simplified interface and the class to instantiate. Thanks all! Now suppose, this class looks like: class StateMachine(object): def __init__... def function0... def function1... def function2... ... up to many. And later in the library I would like to expose the simplified interface as well: _machine = StateMachine() function0 = _machine.function0 function1 = _machine.function1 function2 = _machine.function2 ... Is there a way to do so in a programmatic way? Like: _machine = StateMachine() for function in {every function in _machine}: function = _machine.function Not that it's difficult to copy-paste some lines, I'm just curious and maybe it would be a tiny bit easier to maintain the library. -- http://mail.python.org/mailman/listinfo/python-list
lotus nsf to mbox
Hi, I am wondering, if anyone tried to convert lotus nsf mails to a mbox format using python!? It would be nice, if anyone has an idea, how to do it on a linux machine. Regards! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: opposite of zip()?
Hi folks, Thanks, for all the help. I tried running the various options, and here is what I found: from array import array from time import time def f1(recs, cols): for r in recs: for i,v in enumerate(r): cols[i].append(v) def f2(recs, cols): for r in recs: for v,c in zip(r, cols): c.append(v) def f3(recs, cols): for r in recs: map(list.append, cols, r) def f4(recs): return zip(*recs) records = [ tuple(range(10)) for i in xrange(100) ] columns = tuple([] for i in xrange(10)) t = time() f1(records, columns) print 'f1: ', time()-t columns = tuple([] for i in xrange(10)) t = time() f2(records, columns) print 'f2: ', time()-t columns = tuple([] for i in xrange(10)) t = time() f3(records, columns) print 'f3: ', time()-t t = time() columns = f4(records) print 'f4: ', time()-t f1: 5.10132408142 f2: 5.06787180901 f3: 4.04700708389 f4: 19.13633203506 So there is some benefit in using map(list.append). f4 is very clever and cool but it doesn't seem to scale. Incidentally, it took me a while to figure out why the following initialization doesn't work: columns = ([],)*10 apparently you end up with 10 copies of the same list. Finally, in my case the output columns are integer arrays (to save memory). I can still use array.append but it's a little slower so the difference between f1-f3 gets even smaller. f4 is not an option with arrays. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python really a scripting language?
> John Nagle <[EMAIL PROTECTED]> (JN) wrote: >JN> There's CORBA, for example, and in theory >JN> you can script OpenOffice and Gnome via CORBA. But nobody does that. >JN> Exercise: write a Python program to convert a ".doc" file to a ".pdf" >JN> file by invoking OpenOffice via CORBA. At least in theory, this is >JN> possible. All the necessary parts supposedly exist. Somebody >JN> tried back in 2003, but gave up. See >JN> "http://mail.python.org/pipermail/python-list/2003-April/198094.html"; [Nitpicking] Scripting Openoffice.org (!) is with UNO, not Corba. -- Piet van Oostrum <[EMAIL PROTECTED]> URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Compressing a text file using count of continous characters
> > > XYZDEFAAcdAA --> XYZ8ADEF2Acd2A > (RLE), that saved a lot of googles I have written a rle in my first years in school. It compresses a bitmap image %50 compression is achivied :) The link : http://arilaripi.org/index.php?option=com_remository&Itemid=26&func=fileinfo&id=273 And it is delphi but code is easy... In python it will be easier of course :) > > Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: opposite of zip()?
[EMAIL PROTECTED] wrote: > Hi folks, > > Thanks, for all the help. I tried running the various options, and > here is what I found: > > > from array import array > from time import time > > def f1(recs, cols): > for r in recs: > for i,v in enumerate(r): > cols[i].append(v) > > def f2(recs, cols): > for r in recs: > for v,c in zip(r, cols): > c.append(v) > > def f3(recs, cols): > for r in recs: > map(list.append, cols, r) > > def f4(recs): > return zip(*recs) > > records = [ tuple(range(10)) for i in xrange(100) ] > > columns = tuple([] for i in xrange(10)) > t = time() > f1(records, columns) > print 'f1: ', time()-t > > columns = tuple([] for i in xrange(10)) > t = time() > f2(records, columns) > print 'f2: ', time()-t > > columns = tuple([] for i in xrange(10)) > t = time() > f3(records, columns) > print 'f3: ', time()-t > > t = time() > columns = f4(records) > print 'f4: ', time()-t > > f1: 5.10132408142 > f2: 5.06787180901 > f3: 4.04700708389 > f4: 19.13633203506 > > So there is some benefit in using map(list.append). f4 is very clever > and cool but it doesn't seem to scale. > > Incidentally, it took me a while to figure out why the following > initialization doesn't work: > columns = ([],)*10 > apparently you end up with 10 copies of the same list. > Yes. A well known gotcha in Python and a FAQ. > Finally, in my case the output columns are integer arrays (to save > memory). I can still use array.append but it's a little slower so the > difference between f1-f3 gets even smaller. f4 is not an option with > arrays. > -- http://mail.python.org/mailman/listinfo/python-list
Re: state machine and a global variable
On Sat, 15 Dec 2007 01:07:17 -0800, tuom.larsen wrote: ... > later in the library I would like to expose the > simplified interface as well: > > _machine = StateMachine() > function0 = _machine.function0 > function1 = _machine.function1 > function2 = _machine.function2 > ... > > Is there a way to do so in a programmatic way? Like: > > _machine = StateMachine() > for function in {every function in _machine}: > function = _machine.function > > Not that it's difficult to copy-paste some lines, I'm just curious and > maybe it would be a tiny bit easier to maintain the library. You can say: # Untested! _machine = StateMachine() from new import instancemethod for name in _machine.__class__.__dict__: if name.startswith('_'): continue obj = getattr(_machine, name) if type(obj) == instancemethod: globals()[name] = obj but that's likely to export a bunch of functions you don't actually want. A better solution might be to create a class attribute containing the names you DO want to export, and reject everything else: class StateMachine(object): _exportable = ['spam', 'eggs', 'parrot'] # function definitions go here for name in _machine.__class__.__dict__: if name in _machine._exportable: globals()[name] = getattr(_machine, name) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: How to read a binary file into a mysql table
On Dec 14, 5:41 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 14 Dec 2007 12:19:41 -0300, Hans Müller <[EMAIL PROTECTED]> escribió: > > > I cannot read a binary file into a mysql database. Everything I tried > > did not succeed. > > > What I tried (found from various google lookups...) is this: > > > con = MySQLdb.connect(to server) > > cur = con.cursor() > > > cur.execute("insert into data values('file1', %s)", (open("test.jpg", > > "rb").read(), )) > > Try wrapping the file contents with a Binary object (untested): > > data = MySQLdb.Binary(open("test.jpg","rb").read()) > cur.execute("insert into data values('file1', %s)", (data,)) > > -- > Gabriel Genellina I was suprised at what I could stick into a MySQL database. Also, you might wanna compress the binary for database performance. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to detect if a image file has icc profile embeded?
On 15 Dec, 02:40, hi and hello <[EMAIL PROTECTED]> wrote: > thx. What OS? -- http://mail.python.org/mailman/listinfo/python-list
Re: Yet another comparison of Python Web Frameworks
Gluon was made at my school? I seriously gotta start talking to the CTI department. -- http://mail.python.org/mailman/listinfo/python-list
Re: lotus nsf to mbox
Fabian Braennstroem pisze: > I am wondering, if anyone tried to convert lotus nsf mails > to a mbox format using python!? It would be nice, if anyone > has an idea, how to do it on a linux machine. You can try to read NSF databases using Lotus ActiveX controls. I am sure I saw an example few years ago. -- Jarek Zgoda http://zgodowie.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Loops and things
Jair Trejo wrote: > I was wondering how and if it's possible to write a > loop in python > which updates two or more variables at a time. For > instance, something > like this in C: > > for (i = 0, j = 10; i < 10 && j < 20; i++, j++) { > printf("i = %d, j = %d\n", i, j); > } >>> for i,j in zip(range(0, 10), range(10, 20)): ... print("i = %d, j = %d" % (i, j)) ... i = 0, j = 10 i = 1, j = 11 i = 2, j = 12 i = 3, j = 13 i = 4, j = 14 i = 5, j = 15 i = 6, j = 16 i = 7, j = 17 i = 8, j = 18 i = 9, j = 19 >>> -- Under construction -- http://mail.python.org/mailman/listinfo/python-list
Re: container.___le___ can use only <=?
On Dec 14, 11:04 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Fri, 14 Dec 2007 21:15:44 +, Neil Cerutti wrote: > > When implementing the rich comparison operators for some sort of > > container, it's tempting to save code by doing something like: > > > class LarchTree: > >... > >def __gt__(self, other): > > # A lot of code to traverse the tree > >def __le__(self): > > return not self > other > > > However, if I'm thinking correctly, this is a bad idea. The reasoning > > being that > and <= are not required to be each others opposite for > > arbitrary value types, and may not even both be supplied by the > > contained objects. > > > If a LarchTree user stores objects that don't support __gt__, will he > > have a legitimate complaint when using LarchTree.__le__ results in an > > attribute error? > > I'm not sure that an AttributeError is the right exception to raise, but > in general I'd say that if the contained objects don't support "normal" > comparisons (that is, if < and >= aren't opposites, etc.) then all bets > are off. "Behaviour is undefined" time. I wasn't going to raise the exception, I was thinking about calling a function that raised the exception. Assume for a moment that list's __le__ were implemented as above. class BadGT(object): def __gt__(self, o): raise RuntimeError("I just hate this operation") def __le__(self, o): return id(self) <= id(other) >>> x = [BadGT(), BadGT()] >>> x <= [] If lists implementation of __le__ calls __gt__ on its constituents *then* it'll be a RuntimeError. I've tested list, and it safely compares lists containing BadGT objects, as along I don't call __gt__ myself. So I was contemplating implementing a phalanx of tests along these lines, which the current version of my container will surely fail. > BTW, what is a LarchTree? Googling just brings up the actual botanical > tree, a type of conifer. > > http://en.wikipedia.org/wiki/Larch It was a Monty Python reference. I'm actually still fiddling around with a doubly-linked list implementation. It's kinda embarrassing so I hid that fact, but actually I'm learning a bunch of Python and getting design practice from this exercise (it turns out linked lists have keys!). -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Pythonic way to add method alias in subclass
I thought of several ways to add another name for a method in a subclass ... #alias.py class Foo(object): def nod(self): print "nodding" class Bar(Foo): def __init__(self): self.agree = self.nod class Bar2(Foo): agree = Foo.nod class Bar3(Foo): def agree(self): Foo.nod(self) def alias(method): def dec(m): return method return dec class Bar4(Foo): @alias(Foo.nod) def agree(self): pass b = Bar() b.agree() b2 = Bar2() b2.agree() b3 = Bar3() b3.agree() b4 = Bar4() b4.agree() # I am leaning towards Bar2 since it has the least code. Any thoughts? -- http://mail.python.org/mailman/listinfo/python-list
Re: container.___le___ can use only <=?
On Dec 14, 4:15 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > When implementing the rich comparison operators for some sort of > container, it's tempting to save code by doing something like: > > class LarchTree: >... >def __gt__(self, other): > # A lot of code to traverse the tree >def __le__(self): > return not self > other > > However, if I'm thinking correctly, this is a bad idea. The > reasoning being that > and <= are not required to be each others > opposite for arbitrary value types, and may not even both be > supplied by the contained objects. And yet, by the same reasoning, using > and <= for list and tuple is also a "bad idea". > If a LarchTree user stores objects that don't support __gt__, > will he have a legitimate complaint when using LarchTree.__le__ > results in an attribute error? No. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic way to add method alias in subclass
On Sat, 15 Dec 2007 13:03:33 +, Lee Harr wrote: > I thought of several ways to add another name for a method in a subclass ... > class Bar2(Foo): > agree = Foo.nod ... > I am leaning towards Bar2 since it has the least code. Sure, why not? Out of curiosity, what's wrong with just calling Bar2.nod()? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic way to add method alias in subclass
Lee Harr a écrit : > I thought of several ways to add another name for > a method in a subclass ... > > > #alias.py > class Foo(object): > def nod(self): > print "nodding" > > class Bar(Foo): > def __init__(self): > self.agree = self.nod Will create an instance attribute of type method for each instance of Bar. Which might or not be a problem FWIW. > class Bar2(Foo): > agree = Foo.nod The One Obvious Way. > class Bar3(Foo): > def agree(self): > Foo.nod(self) Are you willing to take the penalty of an extra method call ? > def alias(method): > def dec(m): > return method > return dec > > class Bar4(Foo): > @alias(Foo.nod) > def agree(self): > pass > Bad case of arbitrary overcomplification IMHO. Nothing with metaclasses while we're at it ?-) (snip) > I am leaning towards Bar2 since it has the least code. Indeed. > Any thoughts? cf above. -- http://mail.python.org/mailman/listinfo/python-list
Re: lotus nsf to mbox
On Dec 15, 5:18 am, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: > I am wondering, if anyone tried to convert lotus nsf mails > to a mbox format using python!? It would be nice, if anyone > has an idea, how to do it on a linux machine. I've used jython to access notes databases through the Notes Java APIs. Though I don't know if the Java APIs are available on Linux. -- http://mail.python.org/mailman/listinfo/python-list
Re: container.___le___ can use only <=?
On Dec 15, 8:33 am, Carl Banks <[EMAIL PROTECTED]> wrote: > On Dec 14, 4:15 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > > > When implementing the rich comparison operators for some sort of > > container, it's tempting to save code by doing something like: > > > class LarchTree: > >... > >def __gt__(self, other): > > # A lot of code to traverse the tree > >def __le__(self): > > return not self > other > > > However, if I'm thinking correctly, this is a bad idea. The > > reasoning being that > and <= are not required to be each others > > opposite for arbitrary value types, and may not even both be > > supplied by the contained objects. > > And yet, by the same reasoning, using > and <= for list and tuple is > also a "bad idea". My reasoning is (I hope) that the container ought to support every comparison operation supported by the contained objects. This can be ensured by being careful in the implementation. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python really a scripting language?
John Nagle wrote: > Yes. One of the basic design flaws of UNIX was that interprocess > communication was originally almost nonexistent, and it's still not all that > great. It's easy to run other programs, and easy to send command line > parameters, but all you get back is a status code, plus console-type output. > > The UNIX world might have been quite different if, when you ran a > subprocess, at the end you got return values for the command line > parameters (argv/argc) and the environment back. Then programs > would behave more like big subroutines. But all you get back > is a status code, so running programs from a "script" tends to be > a somewhat "blind" one-way process. not if you use pickle. the example below is not complete and I need to fix it to not raise privileges if name is None but it is complete enough to give you an idea. the parent uses spawn_sub to send data to/from child. child uses read_input/write_output to move data from/to the parent. I should convert it to something like json to make it possible to work with other languages. class process_handler (object): def read_input (self): """get the input from standard and can convert to Python object""" pickle_input = sys.stdin.read() real_object = pickle.loads(pickle_input) return real_object def write_output (self, real_object, err_object = None): """ errors to standard error, output to standard out, objects in pickled form""" pickled_error = pickle.dumps(err_object) sys.stderr.write(pickled_error) pickled_output = pickle.dumps(real_object) sys.stdout.write(pickled_output) def spawn_sub(self, cmd_list,stuff_in, run_as=None): """command_list is just that, a list of the command and all of its arguments. stuff_in is the string sent to the sub process via standard in stuff_out is the string returned from the sub process via standard out error_stuff is the string returned from standard error. stuff_out and error_stuff are returned as a tuple run_as is the user name you want to run as. This uses a trick with sudo to enable privilege escalation this is an example of a bad escalation specification in sudoers. It's sometimes bad because it doesn't restrict who can use the command. If you are trying to run a program as a common but different user (such as www-data because you need to share a database with a Web server, the badness is measured in terms of what data said program can change or reveal. If the access cannot be exploited, then they should be okay. Unfortunately, in almost every circumstance where privilege escalation techniques are useful, there is an exploit waiting to happen. be careful. ALL ALL = (www-data) NOPASSWD: /home/esj/vacation_scan.py """ # syslog.syslog("subprocess args %s"%str(cmd_list)) p = subprocess.Popen(cmd_list, shell=False, bufsize=4000, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) # always pickle what passes through even if it is a None pickle_in = pickle.dumps(stuff_in) (pickled_output, pickled_error) = p.communicate(pickle_in) stuff_output = pickle.loads(pickled_output) error_stuff = pickle.loads(pickled_error) # syslog.syslog(" stuff_output %s, error_stuff %s"%( stuff_output, error_stuff)) return (stuff_output, error_stuff) -- Speech-recognition in use. It makes mistakes, I correct some. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic way to add method alias in subclass
On Dec 15, 8:03 am, Lee Harr <[EMAIL PROTECTED]> wrote: > I thought of several ways to add another name for > a method in a subclass ... > > #alias.py > class Foo(object): > def nod(self): > print "nodding" > > class Bar(Foo): > def __init__(self): > self.agree = self.nod > > class Bar2(Foo): > agree = Foo.nod > > class Bar3(Foo): > def agree(self): > Foo.nod(self) > > def alias(method): > def dec(m): > return method > return dec > > class Bar4(Foo): > @alias(Foo.nod) > def agree(self): > pass > > b = Bar() > b.agree() > > b2 = Bar2() > b2.agree() > > b3 = Bar3() > b3.agree() > > b4 = Bar4() > b4.agree() > # > > I am leaning towards Bar2 since it has the least code. > Any thoughts? 1, 2, and 3 are all fine. 1 would be useful if for some reason you wanted to change the behavior of Bar.agree at runtime. 3 has a few minor advantages: stack traces will print "agree" instead of "nod", it could be easier to modify later, slightly more self-documenting. And if you had been using super(), you could have avoided repeating the symbol Foo. But 2 is more efficient and less typing than 3. Option 4 is abhorrent. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: container.___le___ can use only <=?
On Dec 15, 2:05 pm, [EMAIL PROTECTED] wrote: > My reasoning is (I hope) that the container ought to support every > comparison operation supported by the contained objects. This can be > ensured by being careful in the implementation. > If you're traversing two containers in parallel to compare them then you could do something like: class LarchTree: ... def compare(self, other, cmp): # Same code as your original __gt__ but # with cmp(x, y) instead of x > y def __lt__(self, other): return self.compare(other, operator.lt) def __gt__(self, other): return self.compare(other, operator.gt) # etc... This way the LarchTree object doesn't interpret the comparison operators, just passes them on to its elements. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Convert a sequence of bits to a bit-string
Hi guys, does anybody know how to convert a long sequence of bits to a bit-string? I want to avoid this: >>> bit=00110101110111010001 >>> >>> str(bit) '949456129574336313917039111707606368434510426593532217946399871489' I would appreciate a prompt reply because I have a python assessment to submit. Thanks, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Convert a sequence of bits to a bit-string
Hi guys, does anybody know how to convert a long sequence of bits to a bit-string? I want to avoid this: >>> bit=00110101110111010001 >>> >>> str(bit) '949456129574336313917039111707606368434510426593532217946399871489' I would appreciate a prompt reply because I have my python assessment to submit. Thanks, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert a sequence of bits to a bit-string
On Dec 15, 2:33 pm, [EMAIL PROTECTED] wrote: > Hi guys, Hi > does anybody know how to convert a long > sequence of bits to a bit-string? Yes! > > I would appreciate a prompt reply because I have a python assessment to > submit. Good luck, you're lucky you've got the whole weekend :) > Thanks, > Thomas HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: container.___le___ can use only <=?
On Dec 15, 9:05 am, [EMAIL PROTECTED] wrote: > On Dec 15, 8:33 am, Carl Banks <[EMAIL PROTECTED]> wrote: > > > > > On Dec 14, 4:15 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > > > > When implementing the rich comparison operators for some sort of > > > container, it's tempting to save code by doing something like: > > > > class LarchTree: > > >... > > >def __gt__(self, other): > > > # A lot of code to traverse the tree > > >def __le__(self): > > > return not self > other > > > > However, if I'm thinking correctly, this is a bad idea. The > > > reasoning being that > and <= are not required to be each others > > > opposite for arbitrary value types, and may not even both be > > > supplied by the contained objects. > > > And yet, by the same reasoning, using > and <= for list and tuple is > > also a "bad idea". > > My reasoning is (I hope) that the container ought to support every > comparison operation supported by the contained objects. This can be > ensured by being careful in the implementation. I see what you're asking now. Yep, probably a bad idea to use that shortcut. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing arguments to exe
On Dec 14, 8:06 pm, John Machin <[EMAIL PROTECTED]> wrote: > > > The executable runs, > > how do you know it runs? > because the program's GUI appears on-screen. > > but no argument appears to get passed into it. > > appears?? > Since the TO field doesn't get populated with the email address, it doesn't appear to receive it as an argument. Whereas if I run it as a script, it does receive the email address. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert a sequence of bits to a bit-string
> does anybody know how to convert a long > sequence of bits to a bit-string? I want to avoid this: > bit=00110101110111010001 I do not think this does what you think it does... http://docs.python.org/ref/integers.html The leading zero(s) make(s) this an octal literal, not a binary literal. str(bit) > '949456129574336313917039111707606368434510426593532217946399871489' Which happens to be the result when the above octal representation is converted to decimal. > I would appreciate a prompt reply because I have my python assessment to > submit. Thanks, Thomas All you need to do is represent your bits in a way that actually represents your bits. If you need >>> help( ... # on possible functions to do this, I can give you a h ... int # that might point you in the right direction ... ) #regarding such base matters. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert a sequence of bits to a bit-string
>> does anybody know how to convert a long >> sequence of bits to a bit-string? > >Yes! Would you like to help, please? >> I would appreciate a prompt reply because I have a python assessment to >> submit. > >Good luck, you're lucky you've got the whole weekend :) That's not the only assignment I have to do... >> Thanks, >> Thomas > >HTH I hope this is not like RTFM cause as much as I searched on the web I couldn't find an answer. -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert a sequence of bits to a bit-string
On 2007-12-15, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >>> does anybody know how to convert a long sequence of bits to a >>> bit-string? >> >>Yes! > > Would you like to help, please? You'll have to define 'sequence of bits' and 'bit string' for us. The example you showed didn't really make sense in the context of those two phrases (neither of which has any sort of commonly accepted meaning in Python). You showed code that converted a string to an integer. That is apparently not what you wanted, but it's unclear what you do want. >>> I would appreciate a prompt reply because I have a python >>> assessment to submit. >> >>Good luck, you're lucky you've got the whole weekend :) > > That's not the only assignment I have to do... > I hope this is not like RTFM cause as much as I searched on > the web I couldn't find an answer. I'm not sure what the class is, but perhaps you're not supposed to "find an answer" on the web. Perhaps you're supposed to think up an answer yourself? In any case, I'm surprised you didn't find an answer, because the answer to the question I suspect you're trying to ask comes up quite regularly in this newsgroup. Here's a hint to get you started: help(int) -- Grant Edwards grante Yow! I hope I at bought the right visi.comrelish... z... -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert a sequence of bits to a bit-string
On Sat, 15 Dec 2007 14:33:04 +, te509 wrote: > Hi guys, > does anybody know how to convert a long sequence of bits to a > bit-string? Can you explain what you actually mean? For instance... x = 1234567890 x is now a long sequence of bits. > I want to avoid this: > bit=00110101110111010001 str(bit) > '949456129574336313917039111707606368434510426593532217946399871489' Rather than telling us what you DON'T want, perhaps you should tell us what you DO want. Also, bit (singular) is a bad name for something which is obviously many bits (plural). 00110... [many digits skipped] is a very large number written in octal (base 8). It contains 220 bits, regardless of whether you print them in base 2, base 8, base 10 or base 256. > I would appreciate a prompt reply because I have a python assessment to > submit. Thank you for your honesty. You should think more carefully about what you are trying to accomplish. Is your input a string of 0 and 1 characters, or a binary sequence of bits? What is your output? e.g. bits = '010011001' # a sequence of characters representing bits bits = 987654 # bits specified in base 10 (2) Python has built-in functions oct() hex() str() and int(). You may like to Read The Fine Manual using the built-in help. e.g. help(oct) Help on built-in function oct in module __builtin__: oct(...) oct(number) -> string Return the octal representation of an integer or long integer. (3) Once you've explained what you're trying to do, think more carefully about how to accomplish it. e.g. the decimal string '123' is equal to 1*10**2 + 2*10**1 + 3*10**0. the octal string '406' is equal to 4*8**2 + 0*8**1 + 6*8**0 the binary string '101' is equal to ... ? (4) You might also like to consider the words "convert from one base to another" as worthy of further research. Good luck on your assignment. Don't forget to quote your sources, including any code snippets you find on the web. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert a sequence of bits to a bit-string
On Dec 15, 8:33�am, [EMAIL PROTECTED] wrote: > Hi guys, > does anybody know how to convert a long > sequence of bits to a bit-string? I want to avoid this: > > >>> bit=0011010111011101011�11001 > >>> str(bit) > > '949456129574336313917039111707606368434510426593532217946399871489' That's not a sequence of bits, it's a sequence of octal digits (because you started with a leading 0). There is no base 2 numeric format in Python. You can enter strings reprsenting base 2 digits and then convert the string to an integer: >>> bit='00110101110111010001' >>> bit_as_base2 = int(bit,2) Where you'll see what the correct decimal is: >>> bit_as_base2 15347835180116409679865L As I said, the number you entered was actually octal. Watch as I convert the string to base 8: >>> bit_as_base8=int(bit,8) >>> bit_as_base8 949456129574336313917039111707606368434510426593532217946399871489L See, I got your original number. You could change your original pattern from octal to binary by substituting '000' for each '0' and '001' for each '1'. This works because both octal and binary are powers of 2. >>> bit2=re.sub('0','000',bit) >>> bit2=re.sub('1','001',bit2) >>> bit2 '100101010010010010010010010010010010010010010010010100100100100100100101010010010010010010010010010010010011' This string, when interpreted as base 2 gives you the same result as the original number interpreted as base 8. >>> bit2_as_base2=int(bit2,2) >>> bit2_as_base2 949456129574336313917039111707606368434510426593532217946399871489L If you really need full base 2 capability in place of the halfway capability of Python, get the gmpy module: >>> import gmpy >>> for x in xrange(16): # convert int to base2 and pad # to a fixed number of bits print gmpy.digits(x,2).zfill(8) 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 > > I would appreciate a prompt reply because I have a python assessment to > submit. > Thanks, > Thomas -- http://mail.python.org/mailman/listinfo/python-list
Tkinter weirdness on Windows
I have some Tkinter programs that I run on two different machines. On Machine W, which runs Python 2.5.1 on Windows XP, these programs run just fine. On Machine H, which runs Python 2.5.1 on Windows XP, however, the same programs crash regularly. The crashes are not Python exceptions, but rather are reported by Windows as errors in pythonw.exe. (Of course, the error messages themselves contain absolutely no useful information.) This happens whether I run them from the command prompt or from IDLE (although IDLE itself never crashes). Further, the crashes occur at unpredictable times; sometimes the program will crash almost immediately upon startup, while at other times it will run for a while and then crash. A couple of other points that may or may not have something to do with it. (1) Both programs use the threading module to launch new threads from the GUI. (2) Machine H, but not Machine W, also has Python 2.2 installed on it. I do recall seeing a message at some point that suggested that conflicts in the MS VC++ runtime DLLs might cause this sort of problem, but I haven't been able to find that information through a search, so I'm not sure which particular DLLs to look for. Any help in tracking down the source of this problem would be appreciated. Russ _ Share life as it happens with the new Windows Live. http://www.windowslive.com/share.html?ocid=TXT_TAGHM_Wave2_sharelife_122007-- http://mail.python.org/mailman/listinfo/python-list
Re: Convert a sequence of bits to a bit-string
First of all I'd like to thank you all for your advices. Before I check all your hints I want to clarify what I'm trying to do. The question says "write a function that takes a sequence of bits as an input and return how many 1s are in the sequence", nothing more. This is quite simple for string inputs but tricky for "number inputs". I've notice that if I try to convert a number starting with 0 to a string using str(), then I take a string representing another number (probably converted to decimal). So what I want to do is to write a generic version of a function that takes as an input a sequence of 1s and 0s in any format. The only way I can think to achieve that is by converting the "number inputs" to a string and then using the count() function. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert a sequence of bits to a bit-string
On Sat, 15 Dec 2007 16:39:32 +, te509 wrote: > So what I want > to do is to write a generic version of a function that takes as an input > a sequence of 1s and 0s in any format. Given that there is an infinite number of possible formats, I suggest you lower your sights to something more practical. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert a sequence of bits to a bit-string
On Dec 15, 10:39�am, [EMAIL PROTECTED] wrote: > First of all I'd like to thank you all for your advices. Before I check all > your hints I want to clarify what I'm trying to do. The question says > "write a function that takes a sequence of bits as an input and return how > many 1s are in the sequence", nothing more. Except that there is no such thing in Python as there is no binary representation. You could enter a sequence of characters, where each character represents a bit, such as s='' for 15. > This is quite simple for string > inputs but tricky for "number inputs". I've notice that if I try to convert > a number starting with 0 to a string using str(), then I take a string > representing another number (probably converted to decimal). So what I want > to do is to write a generic version of a function that takes as an input a > sequence of 1s and 0s in any format. That's probably not what you want. You don't want to enter 1's and 0's in any format, you want to accept a number in any format. Remember, the format does not change the number (assuming you always use the correct format representation). So if the input is s=017 (octal), the number is fifteen. If s=0xf (hexadecimal), the number is fifteen. If s=15 (decimal), the number is fifteen. Once you've got that straight, you can calculate the base 2 representation of fifteen and count the ones. > The only way I can think to achieve > that is by converting the "number inputs" to a string and then using the > count() function. Do you know how base conversion is done manually? In base 2, each bit represents a power of 2, and there are only two possibilities for each digit, 0 and 1. So, in base 2, the digit positions are ... 2**7 2**6 2**5 2**4 2**3 2**2 2**1 2**0 128 64 32 16 8421 Now, for fifteen, what's the largest position that doesn't exceed 15? The fourth (counting from the right). Therefore, there's a 1 bit in position four and all higher positions would be 0. At this point, we have '1???'. To get the next lower position, subtract 8 from fifteen, leaving seven. Now repeat until you fill all positions, eventually reaching ''. But, if the highest position that doesn't exceed skips some positions, then those positions have '0'. So for nine, the highest position is still the fourth, giving us '1???'. But after subtracting eight, we're left with one. But the highest position not exceeding one is the first, giving us '1??1'. We skipped positions 2 & 3, so they must be '0' making nine '1001' in base 2. Now all you have to do is count the 1's. However, if doing > Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: opposite of zip()?
On Dec 15, 4:45 am, Gary Herron <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Hi folks, > > > Thanks, for all the help. I tried running the various options, and > > here is what I found: > > > from array import array > > from time import time > > > def f1(recs, cols): > > for r in recs: > > for i,v in enumerate(r): > > cols[i].append(v) > > > def f2(recs, cols): > > for r in recs: > > for v,c in zip(r, cols): > > c.append(v) > > > def f3(recs, cols): > > for r in recs: > > map(list.append, cols, r) > > > def f4(recs): > > return zip(*recs) > > > records = [ tuple(range(10)) for i in xrange(100) ] > > > columns = tuple([] for i in xrange(10)) > > t = time() > > f1(records, columns) > > print 'f1: ', time()-t > > > columns = tuple([] for i in xrange(10)) > > t = time() > > f2(records, columns) > > print 'f2: ', time()-t > > > columns = tuple([] for i in xrange(10)) > > t = time() > > f3(records, columns) > > print 'f3: ', time()-t > > > t = time() > > columns = f4(records) > > print 'f4: ', time()-t > > > f1: 5.10132408142 > > f2: 5.06787180901 > > f3: 4.04700708389 > > f4: 19.13633203506 > > > So there is some benefit in using map(list.append). f4 is very clever > > and cool but it doesn't seem to scale. > > > Incidentally, it took me a while to figure out why the following > > initialization doesn't work: > > columns = ([],)*10 > > apparently you end up with 10 copies of the same list. > > Yes. A well known gotcha in Python and a FAQ. > > > Finally, in my case the output columns are integer arrays (to save > > memory). I can still use array.append but it's a little slower so the > > difference between f1-f3 gets even smaller. f4 is not an option with > > arrays. If you want another answer. The opposite of zip(lists) is zip(* list_of_tuples) That is: lists == zip(zip(* lists)) I don't know about its speed though compared to the other suggestions. Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: lotus nsf to mbox
Hi to both, Dan Poirier schrieb am 12/15/2007 02:00 PM: > On Dec 15, 5:18 am, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >> I am wondering, if anyone tried to convert lotus nsf mails >> to a mbox format using python!? It would be nice, if anyone >> has an idea, how to do it on a linux machine. > > I've used jython to access notes databases through the Notes > Java APIs. Though I don't know if the Java APIs are available > on Linux. thanks for your ideas! I actually thought of something like a python parser, which just converts the nsf structure to an mbox; could that work!? Fabian -- http://mail.python.org/mailman/listinfo/python-list
ANN: eric 4.0.4 released
Hi, today I released version 4.0.4 of the eric4 Python IDE. This is a bug fix release. As usual it is available via http://www.die-offenbachs.de/eric/index.html What is eric? - eric is a Python (and Ruby) IDE written using PyQt. It comes with all batteries included. Please see the above link for more details. Regards, Detlev -- Detlev Offenbach [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Get()
Hello all I am a python "n00b", however I can't find a solution to this problem anywhere. I am using a simple setup - entry box, button and list box, the contents of the entry being inserted into the list box: from Tkinter import * def insert(): name = ent.get() box.insert(0, name) ent.delete(0, END) root = Tk() ent = Entry(root, fg = '#3a3a3a', bg = 'white', relief = 'groove').grid(row = 0, padx = 3, pady = 3) button = Button(root, text = "Remember", command = insert, relief = 'groove', fg = '#3a3a3a').grid(row = 0, column = 1, padx = 3, pady = 3) box = Listbox(root, bg = '#ebe9ed', relief = 'groove').grid(row = 2, columnspan = 2, sticky = W+E, padx = 3) root.mainloop() When I type something and press the button, i get this error: Exception in Tkinter callback Traceback (most recent call last): File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ return self.func(*args) File "C:\My Documents\My Python\Notes.py", line 6, in insert name = ent.get() AttributeError: 'NoneType' object has no attribute 'get' I am puzzled as to the last line... Help? Sam -- I intend to live forever - so far, so good. SaM -- http://mail.python.org/mailman/listinfo/python-list
Informations about hardware, computers, configurations...
http://comp-hardware.blogspot.com/ If you looking for computer hardware... -- http://mail.python.org/mailman/listinfo/python-list
Re: lotus nsf to mbox
On Dec 15, 11:04 am, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: > > thanks for your ideas! I actually thought of something like > a python parser, which just converts the nsf structure to an > mbox; could that work!? > Well, If you wish to go that route, I believe you will have to reverse engineer the Notes Database binary structure because I've never seen it published anywhere. My suggestion, if you can use a Windows machine, just use the Lotus Notes COM Objects via the Python Win32 bindings, as mentioned above. If you really need to do it from Linux and are lucky enough to be running the IIOP task on your Domino server, then you could possibly use CORBA. -- http://mail.python.org/mailman/listinfo/python-list
Re: Get()
The grid method of these widgets returns None. When you say something like: ent = Entry(root, fg = '#3a3a3a', bg = 'white', relief = 'groove').grid(row = 0, padx = 3, pady = 3) You're actually assigning the value of the last method on the right hand side (in this case, grid) to the variable on the left hand side (in this case ent). Since grid returns None, ent is set to None, and the insert function fails. What you want to do is replace your GUI initialization code with something like this: ent = Entry(root, fg = '#3a3a3a', bg = 'white', relief = 'groove') ent.grid(row = 0, padx = 3, pady = 3) button = Button(root, text = "Remember", command = insert, relief = 'groove', fg = '#3a3a3a') button.grid(row = 0, column = 1, padx = 3, pady = 3) box = Listbox(root, bg = '#ebe9ed', relief = 'groove') box.grid(row = 2, columnspan = 2, sticky = W+E, padx = 3) This way ent, button and box get set to their respective widgets, the grid method does its thing and the insert function works as expected. -- nasser -- http://mail.python.org/mailman/listinfo/python-list
Suggested Reading
I got myself into programming late in the summer and have dabbled in python for the most part in that time, recently beginning work on a music player. In January, I start my minor in Information Technology. I'd like to get ahead a bit, however, and over the break would like to do some reading. I seek your recommendations in the field of database design basics and network programming, with a bias towards texts which specifically address Python. By network programming, I mean fundamental understanding of sockets, TCP/UDP, right up to HTTP serving, etc. Thanks ahead of time. -- http://mail.python.org/mailman/listinfo/python-list
About Rational Number (PEP 239/PEP 240)
I'm very surprised actually, to see that Python rejected the use of fractional/rational numbers. However, when I read the PEP, I know exactly why the proposal was rejected: People compared fractions with integers, while it should be more fairly compared to floats. Arguments against: - When I use the result of / as a sequence index, it's usually an error which should not be hidden by making the program working for some data, since it will break for other data. > In Python 3 (and 2 w/ __future__), the / operator would always return floats, and floats is invalid as sequence index, even if the value of the float is whole. Since fractions is created with the / operator on two integers, the behavior of fractions should mimics float. So putting fractional type as sequence index should always be considered as error (exception), a behavior consistent with floats. Thus, the arguments specified above has turned invalid, at least in Python 3. - (this assumes the same type for them:) Int is a good type in itself, not to be mixed with rationals. The fact that something is an integer should be expressible as a statement about its type. Many operations require ints and don't accept rationals. It's natural to think about them as about different types. > I agree, ints shouldn't be mixed with rationals. But floats could. This argument is the main reason why I said most people compared rational with integers. Many operations that requires ints and don't accept rationals also don't accept floats. Other arguments: - Slow: Doing addition and subtraction in fractions sure is expensive, but doing division (the heaviest arithmetic operation) is extremely fast in fractional numbers compared to in floating numbers. It is clear that doing two integer multiplication and switching numerator- denominator is much faster than doing a single float division. - Memory Intensive: To represent 1/3 to infinite accuracy requires two- integer-space (theoretically, 2 bytes). There are some numbers that are hard to represent in fractions, yes, but in general those numbers could be represented using two-long-space (variable-width longs). And whenever accuracy isn't that important, it could be possible to create a method that would lossily approximate the current fraction to an acceptable length. Anyway, most computers nowadays is packed with gigantic memory, why bother with such a small issue. - Rationals must present themselves as decimal floats or it'll be confusing: There will be no confusion in a good written code. Progammers that writes good code would always use the 'behind-the- scene' number, they wouldn't convert a previously 'string'ed number back into calculation. And a convention can be created to represent a fraction in a single line output (like * for multiplication, / for division, they don't exist in paper maths) that would completely eliminate any confusion of the user (well informed about the convention, most people that never used computer before often tried to use x and : to represent mult and div), even when the fractional number is outputted to the foreground UI. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python really a scripting language?
Eric S. Johansson wrote: > John Nagle wrote: >> Yes. One of the basic design flaws of UNIX was that interprocess >> communication was originally almost nonexistent, and it's still not >> all that >> great. It's easy to run other programs, and easy to send command line >> parameters, but all you get back is a status code, plus console-type >> output. >> >> The UNIX world might have been quite different if, when you ran a >> subprocess, at the end you got return values for the command line >> parameters (argv/argc) and the environment back. Then programs >> would behave more like big subroutines. > > not if you use pickle. That assumes both programs were designed to intercommunicate that way. Most UNIX applications aren't. There's no accepted standard on how UNIX programs should intercommunicate, other than the 1970s technology of piping human-readable strings around. Yes, there are marshalling systems, of which Python's "Pickle" is one. But there's no standard interprocess call system. And Pickle is only a marshalling system, not a full IPC system. There's no resource location system. ("Where's the browser process?" "Where's the database back-end?") Both Gnome and OpenOffice use CORBA. But they use incompatible versions, and you have to have a "CORBA ORB" running for that to work. There's OpenRPC, which isn't used much any more. There's "System V IPC", which isn't used much. There are XML-based systems. There's REST, JSON, and similar approaches. None of these approaches ever got the kind of widespread use that OLE did in the Microsoft world. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Allingn controls wxPython
Hy. I need help. I'm using BoxSizer and i put TextCtrl and StaticText next to each other and they gor alligned by top of TextCtrl and it looks terrible. How can i make thm to be alligned by center of each controll. Thnaks! -- http://mail.python.org/mailman/listinfo/python-list
ANN: csvutils 0.1
csvutils is a single Python module for easily transforming csv (or csv- like) generated rows. The release is available at http://pypi.python.org/pypi/csvutils/0.1. Regards, George What is csvutils? The standard csv module is very useful for parsing tabular data in CSV format. Typically though, one or more transformations need to be applied to the generated rows before being ready to be used; for instance "convert the 3rd column to int, the 5th to float and ignore all the rest". csvutils provides an easy way to specify such transformations upfront instead of coding them every time by hand. Here are a few examples (more included as doctests): >>> import csv >>> from csvutils import SequenceTransformer >>> rows = list(csv.reader(["1,3.34,4-3.2j,John", ... "4,4,4,4", ... "0,-1.1,3.4,None"])) >>> # transform and return the first two columns only >>> for row in SequenceTransformer(int,float)(rows): ...print row [1, 3.3399] [4, 4.0] [0, -1.1001] >>> # transform the second column and leave the rest as is >>> for row in SequenceTransformer((1,float), default=None)(rows): ...print row ['1', 3.3399, '4-3.2j', 'John'] ['4', 4.0, '4', '4'] ['0', -1.1001, '3.4', 'None'] >>> # exclude the 4th column and eval() the rest (XXX: Use eval for trusted data only) >>> for row in SequenceTransformer(default=eval, exclude=[3]) (rows): ...print row [1, 3.3399, (4-3.2002j)] [4, 4, 4] [0, -1.1001, 3.3999] -- http://mail.python.org/mailman/listinfo/python-list
Re: About Rational Number (PEP 239/PEP 240)
On Dec 15, 2:00 pm, Lie <[EMAIL PROTECTED]> wrote: > I'm very surprised actually, to see that Python rejected the use of > fractional/rational numbers. However, when I read the PEP, I know > exactly why the proposal was rejected: People compared fractions with > integers, while it should be more fairly compared to floats. Pretty lame reasoning, isn't it? I use the rationals from the gmpy module very successfully. All these arguments that follow are just silly. > > Arguments against: > - When I use the result of / as a sequence index, it's usually an > error which should not be hidden by making the program working for > some data, since it will break for other data. > > In Python 3 (and 2 w/ __future__), the / operator would always > return floats, and floats is invalid as sequence index, even if the > value of the float is whole. Since fractions is created with the / > operator on two integers, the behavior of fractions should mimics > float. So putting fractional type as sequence index should always be > considered as error (exception), a behavior consistent with floats. > Thus, the arguments specified above has turned invalid, at least in > Python 3. > - (this assumes the same type for them:) Int is a good type in itself, > not to be mixed with rationals. The fact that something is an integer > should be expressible as a statement about its type. Many operations > require ints and don't accept rationals. It's natural to think about > them as about different types. > > I agree, ints shouldn't be mixed with rationals. But floats > could. This argument is the main reason why I said most people > compared rational with integers. Many operations that requires ints > and don't accept rationals also don't accept floats. > > Other arguments: > - Slow: Doing addition and subtraction in fractions sure is expensive, > but doing division (the heaviest arithmetic operation) is extremely > fast in fractional numbers compared to in floating numbers. It is > clear that doing two integer multiplication and switching numerator- > denominator is much faster than doing a single float division. > - Memory Intensive: To represent 1/3 to infinite accuracy requires two- > integer-space (theoretically, 2 bytes). There are some numbers that > are hard to represent in fractions, yes, but in general those numbers > could be represented using two-long-space (variable-width longs). And > whenever accuracy isn't that important, it could be possible to create > a method that would lossily approximate the current fraction to an > acceptable length. Anyway, most computers nowadays is packed with > gigantic memory, why bother with such a small issue. > - Rationals must present themselves as decimal floats or it'll be > confusing: There will be no confusion in a good written code. > Progammers that writes good code would always use the 'behind-the- > scene' number, they wouldn't convert a previously 'string'ed number > back into calculation. And a convention can be created to represent a > fraction in a single line output (like * for multiplication, / for > division, they don't exist in paper maths) that would completely > eliminate any confusion of the user (well informed about the > convention, most people that never used computer before often tried to > use x and : to represent mult and div), even when the fractional > number is outputted to the foreground UI. -- http://mail.python.org/mailman/listinfo/python-list
Re: About Rational Number (PEP 239/PEP 240)
The easiest implementation of using fractional datatype is probably to add a new operator. Some scientific calculators provide a special operator to signify a fraction (somewhat on the shape of a small L in mine) and I strongly believe that their internal calculation probably used fractions even when regular division is used, only when the calculator have difficulties using fraction (like calculating sin/cos/ tan function) or the screen is not wide enough to represent the fraction would it use regular division. Python implemented complex numbers, why not fractions? Random ramble past here: Actually, my vision would be not only fractions, but also rooted number (square root, cube root, etc), it could be possible to implement a type where a number consist of a rooted number times a multiplier plus a variable [a + b * root(c, d)]. But I guess this would be extremely complex and it requires nesting, probably very slow if implementation isn't good. The advantage of using such is much faster operations, as long as str() is not called. This actually reflects my way of doing paper math, I save the lossy operations (float division, root, trigonometric function) until the very end of calculation (I'm not fundamentalist though, so compromise sometimes is done here and there). -- http://mail.python.org/mailman/listinfo/python-list
Re: About Rational Number (PEP 239/PEP 240)
On Dec 15, 2007 10:05 PM, Lie <[EMAIL PROTECTED]> wrote: > Random ramble past here: > Actually, my vision would be not only fractions, but also rooted > number (square root, cube root, etc), it could be possible to > implement a type where a number consist of a rooted number times a > multiplier plus a variable [a + b * root(c, d)]. But I guess this > would be extremely complex and it requires nesting, probably very slow > if implementation isn't good. The advantage of using such is much > faster operations, as long as str() is not called. This actually > reflects my way of doing paper math, I save the lossy operations > (float division, root, trigonometric function) until the very end of > calculation (I'm not fundamentalist though, so compromise sometimes is > done here and there). You're looking for a computer algebra system. Try sympy: http://code.google.com/p/sympy/ Fredrik -- http://mail.python.org/mailman/listinfo/python-list
Re: About Rational Number (PEP 239/PEP 240)
On Dec 16, 4:55 am, "Fredrik Johansson" <[EMAIL PROTECTED]> wrote: > On Dec 15, 2007 10:05 PM, Lie <[EMAIL PROTECTED]> wrote: > > > Random ramble past here: > > Actually, my vision would be not only fractions, but also rooted > > number (square root, cube root, etc), it could be possible to > > implement a type where a number consist of a rooted number times a > > multiplier plus a variable [a + b * root(c, d)]. But I guess this > > would be extremely complex and it requires nesting, probably very slow > > if implementation isn't good. The advantage of using such is much > > faster operations, as long as str() is not called. This actually > > reflects my way of doing paper math, I save the lossy operations > > (float division, root, trigonometric function) until the very end of > > calculation (I'm not fundamentalist though, so compromise sometimes is > > done here and there). > > You're looking for a computer algebra system. Try > sympy:http://code.google.com/p/sympy/ > > Fredrik Yeah, that's why I consider them too complex for being included as a core of a general programming language like Python. Nevertheless, fraction datatype _IS_ elementary enough to be included as core language feature. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python really a scripting language?
John Nagle wrote: > Eric S. Johansson wrote: >> John Nagle wrote: >>> Yes. One of the basic design flaws of UNIX was that interprocess >>> communication was originally almost nonexistent, and it's still not >>> all that >>> great. It's easy to run other programs, and easy to send command line >>> parameters, but all you get back is a status code, plus console-type >>> output. >>> >>> The UNIX world might have been quite different if, when you ran a >>> subprocess, at the end you got return values for the command line >>> parameters (argv/argc) and the environment back. Then programs >>> would behave more like big subroutines. >> not if you use pickle. > > That assumes both programs were designed to intercommunicate that way. > Most UNIX applications aren't. There's no accepted standard on how > UNIX programs should intercommunicate, other than the 1970s technology > of piping human-readable strings around. Yes, there are marshalling > systems, of which Python's "Pickle" is one. But there's no standard > interprocess call system. And Pickle is only a marshalling system, > not a full IPC system. There's no resource location system. ("Where's > the browser process?" "Where's the database back-end?") I apologize if this gets you a bit cranky but I think you're conflating a few interprocess communications issues. I know I didn't fully articulate what I had been doing and I apologize. As your description above shows, there are multiple types of interprocess communications. My example shows how it's possible to make two cooperatively designed programs act as if they are communicating via a remote procedure call across a parent-child process boundary. Yes, other marshaling systems may be useful across multiple language environments. I wasn't concerned about that. I had to get a job done so I used pickle. when it comes right down to it, IPC systems are hard to do right. http://birrell.org/andrew/papers/ImplementingRPC.pdf is a pretty good reference for how to do it for our PCs. Also, the definition of right, depends on the communications medium used. For example, if the application is using pipes with sub processes, what I wrote is a workable implementation especially if you need to deal with privilege escalation. If you're talking over sockets or some equivalent communications channel, then yes, you need some form of resource location as well as handling methods exposure and resolution on both server and client side. But even if you have all of these items, you're still not out of the woods. There's a fundamental issue of reliability in the face of this complexity. I've written some code with psycho and, this is not meant as a slam against psycho, but the resource location subsystem was causing more problems than I care to deal with so I eliminated it from my project by hard coding certain essential bits of information. > > Both Gnome and OpenOffice use CORBA. But they use incompatible versions, > and you have to have a "CORBA ORB" running for that to work. There's > OpenRPC, which isn't used much any more. There's "System V IPC", which > isn't used much. There are XML-based systems. There's REST, JSON, and > similar approaches. None of these approaches ever got the kind of > widespread use that OLE did in the Microsoft world. All of these examples are great examples of overly complex IPC mechanisms. while the complexity may be necessary if you are going to handle 99% of all cases, the complexity makes it more difficult to document functionality in a comprehensible way. complexity reduces take up because it's too much work to figure out and use especially if it's a one-shot job. I believe it's fairly clear that a very simple IPC mechanism could handle a significant majority of project needs while making IPC functionality accessible to more developers. XML RPC almost achieves that except for its functional call orientation. But, I'm not a waste any more breath on "what ifs" because there's way too much technological alpha male behavior to ever build a simple common infrastructure component for IPC (or almost any other widely usable components for that matter). ---eric -- Speech-recognition in use. It makes mistakes, I correct some. -- http://mail.python.org/mailman/listinfo/python-list
Re: About Rational Number (PEP 239/PEP 240)
On Dec 15, 10:38 pm, Lie <[EMAIL PROTECTED]> wrote: [...] > > Yeah, that's why I consider them too complex for being included as a > core of a general programming language like Python. Nevertheless, > fraction datatype _IS_ elementary enough to be included as core > language feature. Rationals are not that simple. * Unless you are working under very controlled conditions, rationals very quickly grow enormous numerators and denominators, hence require arbitrary precision integers (which, I concede, are part of Python). * In order to have a canonical representation of integers, they need to be kept in normalised form. * Nobody uses big fractions apart from mathematicians (and maybe bookmakers?). * Having yet another numerical type would make it difficult what type to expect from a calculation. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: opposite of zip()?
[EMAIL PROTECTED] wrote: >map(append, arrays, tupl) > except there is no unbound append() (List.append() does not exist, > right?). Er, no, but list.append does: >>> list.append so you should be able to do map(list.append, arrays, tupl) provided you know that all the elements of 'arrays' are actual lists. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: About Rational Number (PEP 239/PEP 240)
I think the main objection to rationals is that extensive computation with them tends to result in numbers requiring larger and larger amounts of storage. I believe that ABC made routine use of rationals, and this caused programs to get bogged down for no apparent reason, as rationals were being used behind the scenes when people didn't realise it. So while rationals might be useful to have available for some things, you should have to explicitly ask for them. Returning rationals from '/' applied to integers would be a bad idea, for example. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Handling cookies without urllib2 and cookielib
On 14 dic, 23:44, Joshua Kugler <[EMAIL PROTECTED]> wrote: > I'm using HTTPlib to construct some functional tests for a web app we're > writing. We're not using urllib2 because we need support for PUT and > DELETE methods, which urllib2 does not do. > > We also need client-side cookie handling. So, I start reading about > cookielib and run across a problem. It's cookie handling is tied quite > tightly to urllib2's request object. httplib has somewhat different > semantics in its request object. So, you can use cookielib with httplib. > And cookie lib has no simple function (that I could find) for passing in a > set-cookie header and getting back a CookieJar object (or even a list of > Cookie objects). What about correcting the first thing, making urllib2 support HEAD/PUT/ DELETE? import urllib2 class Request(urllib2.Request): def __init__(self, url, data=None, headers={}, origin_req_host=None, unverifiable=False, method=None): urllib2.Request.__init__(self, url, data, headers, origin_req_host, unverifiable) self.method = method def get_method(self): if self.method is None: if self.data is not None: return "POST" else: return "GET" return self.method py> f = urllib2.urlopen(Request("http://www.python.org/";, method="HEAD")) py> print f.info() Date: Sun, 16 Dec 2007 00:03:43 GMT Server: Apache/2.2.3 (Debian) DAV/2 SVN/1.4.2 mod_ssl/2.2.3 OpenSSL/ 0.9.8c Last-Modified: Sat, 15 Dec 2007 16:25:58 GMT ETag: "60193-3e6a-a24fb180" Accept-Ranges: bytes Content-Length: 15978 Connection: close Content-Type: text/html py> print len(f.read()) 0 Notes: a) Instead of urlopen(url,...) you must use urlopen(Request(url,...)) b) Redirection is not handled correctly in HTTPRedirectHandler (the request method should be copied over) c) I've not verified PUT / DELETE methods d) I'll try to make a proper patch later -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: About Rational Number (PEP 239/PEP 240)
On Sat, 15 Dec 2007 15:44:26 -0800, Arnaud Delobelle wrote: > Rationals are not that simple. > > * Unless you are working under very controlled conditions, rationals > very quickly grow enormous numerators and denominators, hence require > arbitrary precision integers (which, I concede, are part of Python). Come now. Rationals aren't living things that grow if you sit them in the corner and provide them air and light. Whether the numerator and denominator grow depends on what you do with them. If you wish to say that they *can* grow enormous numerators and denominators, I won't argue, but implying that *must* and will *always* grow is misleading. It's pure propaganda. And if they do... well, longs can also "quickly grow enormous". That hasn't stopped Python integrating ints and longs. The programmer is expected to deal with it. Integrating floats and rationals isn't even on the table for discussion. Anyone using rationals is making a conscious choice to do so and can deal with the consequences. > * In order to have a canonical representation of integers, they need to > be kept in normalised form. Oh noes! Not normalised form!!! Is this supposed to be an objection? > * Nobody uses big fractions apart from mathematicians (and maybe > bookmakers?). Putting the cart before the horse. Nobody uses rationals because rationals aren't available! Nobody uses complex numbers except for mathematicians, and maybe a few electrical engineers, and they're a built in. Nobody uses math functions like sin and cos except for mathematicians and engineers, and they're available. The Forth programming language didn't even support floating point for many years. Programmers were expected to use the equivalent of rationals using integers. This was very successful, and avoided the gotchas that you get with floats. For example, with floats it is unavoidable to have unintuitive results like (x + y) - x != y and it isn't even very hard to find an example. >>> 3.1 + 0.7 - 3.1 == 0.7 False Such a bizarre result shouldn't happen with any non-buggy rational representation: 31/10 + 7/10 - 31/10 => 38/10 - 31/10 => 7/10 In the real world, people use fractions all the time, e.g. plumbers. (Not that I'm expecting plumbers to start taking laptops out to the building site in order to calculate pipe sizes.) > * Having yet another numerical type would make it difficult what type to > expect from a calculation. I simply don't believe that at all. It's not like calculations will suddenly start returning rationals unexpectedly, any more than they suddenly started returning Decimals unexpectedly. I find it bizarre that the simple to implement, simple to understand rational data type was rejected while the hard to implement, hard to understand Decimal was accepted. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Inter-process communication, how?
Hi, let's say I have two scripts: one does some computations and the other one is a graphical front end for launching the first one. And both run in separate processes (front end runs and that it spawns a subprocess with the computation). Now, if the computation has a result I would like to display it in the front end. In another words, I would like to pass some data from one process to another. How to do that? I'm affraid I can't use a pipe since the computation could print out some logging (if I understant pipes correctly). Thanks! -- http://mail.python.org/mailman/listinfo/python-list
in-client web server
Hi, I am working on a thick-client application that serves a lot of content as locally generated and modified web pages. I'm beginning to look at serving (and updating, via AJAX) these pages from a web server running within the client (mostly to provide a more natural and powerful way of interacting with the browser control). For a first cut I imagine just starting a web server within the client and serving the pages from localhost:. I have a couple questions for anyone with experience with this sort of architecture: * First, are there any existing open source libraries that exemplify this approach? I have a vague recollection that TurboGears started out based on a project with this kind of architecture, but I haven't been able to find anything so far. * Second, are there any gotchas you would point out? In particular I'm wondering if even this localhost connection will be a problem with many users' firewalls. In case it matters, the application is being developed in python 2.5.x with wxPython 2.8.x, aimed first at a Windows platform, but intended to be portable to Linux and Mac ASAP. Thanks for any pointers, David -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert a sequence of bits to a bit-string
On Sat, 15 Dec 2007 16:46:38 -0800, Dennis Lee Bieber wrote: > ... this becomes trivial... So trivial I'm going to include a solution, > even though it is a homework assignment... > inp = raw_input("Enter the sequence of 1 and 0: ") print inp > 1001101011101011101 print "The count is %s" % len( > ... [c for c in inp if c == "1"]) > The count is 12 *cough* It's even more trivial than that. >>> '1001101011101011101'.count('1') 12 -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Tk Tkinter : multiple file selection dialog over multiple directories ?
The simple/obvious way is click a "save" button which appends the files selected into a list. Then move on to the next directory and repeat. Is there a reason why this won't work? -- http://mail.python.org/mailman/listinfo/python-list
Re: About Rational Number (PEP 239/PEP 240)
On Dec 15, 6:52 pm, greg <[EMAIL PROTECTED]> wrote: > So while rationals might be useful to have available for > some things, you should have to explicitly ask for them. > Returning rationals from '/' applied to integers would > be a bad idea, for example. >From my reading of the PEP, it doesn't suggest such automatic coercions (neither rejects them explicitly though). Given the huge discussions about integer vs true division, it would be very controversial to suggest implicit rational division. Regardless, a builtin (or at least standard library) rational type would be nice to have. Of course folks that *really need* rationals are already using some 3rd party library, but for the rest of us it would be an improvement in several cases where currently floats are used, just like the motivation for Decimals. Only difference seems to be that there aren't so many or compelling use cases for rationals as for decimals (mainly money counting). George -- http://mail.python.org/mailman/listinfo/python-list
Re: embedding filedialog in a frame in tkinter
On 15 dic, 04:30, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > i am trying out tkinter to make a gui..i want to have a frame with an > embedded file explorer next to a 'open directory' label..i tried out > FileDialog and tkFileDialog methods but they open as pop up dialogs.. > how do i make this packed into the frame the way button and other > widgets can be packed? i am a newbie to tkinter.. Try using Tix, a Tkinter extension included in the Python library. It provides a DirList widget: import Tix class App: def __init__(self, master): frame = Tix.Frame(master) frame.pack() dirlist = Tix.DirList(frame, value=r"f:\download\temp", command=self.showdir) dirlist.pack(fill="x") button = Tix.Button(frame, text="Close", command=frame.quit) button.pack() def showdir(self, directory): print "user selected", directory root = Tix.Tk() app = App(root) root.mainloop() -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
ANN: Python Google Chart (pygooglechart) 0.1.2
Python Google Chart is a complete wrapper to the Google Chart API. http://pygooglechart.slowchop.com/ * Added more examples * Fixed pie labels encoding * Fixed MANIFEST.in to allow examples and COPYING in the source distribution * Added more metadata in setup.py -- Gerald Kaszuba http://geraldkaszuba.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Inter-process communication, how?
On Dec 16, 2:42 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > > Have you perused and been perplexed by the "Is Python a Scripting > Language" thread? Oh, no!! Script as in "shell script". > > Question: Are you creating both scripts from scratch? > Yes? Yes. Then you can define whatever protocol is needed for your usage and > is available on your OS. > > If it is a one-shot (spawn sub, wait, retrieve results) you could > generate a temporary file name in the parent, pass that name to the sub > when invoking it, wait for the sub to complete (giving you a status > code) and then read the result the sub has written to the file. Yes, it's once shot. But how do I pass "that name"? >From all the arguments of class Popen (http://docs.python.org/lib/ node529.html) perhaps I could use "env" only. Or am I wrong? TCP/IP sounds good but isn't it a bit too heavy? And what the other options goes I would prefer a cross platform solution, if there is one. PS: both with mmpam and temp file you probably meant that I should hard code some as-weirdest-filename-as-possible two both programs but what if I run the computation several times? And thanks for reply! > > Or, you could have parent and sub both mmap the same "file", > essentially passing data in memory unless it becomes too large and pages > out to swap disk. You might even be able to do bidirectional and dynamic > updates (rather than waiting for the sub to exit)... Define, say, an > epoch count for each process -- these would be the first two words of > the mmap file > > |p-epoch|s-epoch|n-words of p-data (fixed constant known to both)|n-words of > s-data| > > periodically the parent would examine the value of s-epoch, and if it > has changed, read the s-data.. (both sides write the data first, then > update the epoch count). When the epoch stays the same and two > consecutive reads of the data match, you have stable data (so the reads > should occur more often than updates) and can process the data > transferred. > > OR, you could have the parent open a TCP/IP socket as a server, and > pass the socket port number to the sub. The sub would then connect to > that port and write the data. For bidirectional you could pass the > parent port, and the sub's first action is to connect and pass a port > that it will be monitoring. > > On a VMS system, the processes would connect to named "mailboxes" > and use QIO operations to pass data between them. > > On an Amiga you'd use "message ports" (which operated somewhat > similar to VMS mailboxes except that mailboxes had an independent > existence, multiple processes can read or write to them -- message ports > were readable by the creating process, but could have messages sent from > anywhere; typically passing the message port [address of a linked list > of messages] for replies). Or a higher level message port: an ARexx > port. > > On a Windows NT class system, the win32 extensions allow access to > Windows Named Pipes... Or maybe the Windows clipboard could be used... > -- > WulfraedDennis Lee Bieber KD6MOG > [EMAIL PROTECTED] [EMAIL PROTECTED] > HTTP://wlfraed.home.netcom.com/ > (Bestiaria Support Staff: [EMAIL PROTECTED]) > HTTP://www.bestiaria.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Inter-process communication, how?
--- [EMAIL PROTECTED] wrote: > TCP/IP sounds good but isn't it a bit too heavy? It depends on your judgment, of course. On a simplistic level, using TCP/IP shouldn't be any more work than what you'd do if you were reading and writing files, especially if everything you're doing is on the same box. Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs -- http://mail.python.org/mailman/listinfo/python-list
Re: Inter-process communication, how?
On Dec 16, 2:34 pm, [EMAIL PROTECTED] wrote: > > If it is a one-shot (spawn sub, wait, retrieve results) you could > > generate a temporary file name in the parent, pass that name to the sub > > when invoking it, wait for the sub to complete (giving you a status > > code) and then read the result the sub has written to the file. > > Yes, it's once shot. But how do I pass "that name"? > From all the arguments of class Popen (http://docs.python.org/lib/ > node529.html) perhaps I could use "env" only. Or am I wrong? Yes. Consider this: If you were to run your calculation script from the shell prompt [strongly recommended during testing], how would you tell it the name of the file? Now look at the docs again. > > PS: both with mmpam and temp file you probably meant that I should > hard code some as-weirdest-filename-as-possible two both programs but > what if I run the computation several times? That's mmap, not mmpam. No, Dennis didn't mean that you should hard code a filename. Have a look at the tempfile module. > > And thanks for reply! > > > > > Or, you could have parent and sub both mmap the same "file", > > essentially passing data in memory unless it becomes too large and pages > > out to swap disk. You might even be able to do bidirectional and dynamic > > updates (rather than waiting for the sub to exit)... Define, say, an > > epoch count for each process -- these would be the first two words of > > the mmap file > > > |p-epoch|s-epoch|n-words of p-data (fixed constant known to both)|n-words > > of s-data| > > > periodically the parent would examine the value of s-epoch, and if it > > has changed, read the s-data.. (both sides write the data first, then > > update the epoch count). When the epoch stays the same and two > > consecutive reads of the data match, you have stable data (so the reads > > should occur more often than updates) and can process the data > > transferred. > > > OR, you could have the parent open a TCP/IP socket as a server, and > > pass the socket port number to the sub. The sub would then connect to > > that port and write the data. For bidirectional you could pass the > > parent port, and the sub's first action is to connect and pass a port > > that it will be monitoring. > > > On a VMS system, the processes would connect to named "mailboxes" > > and use QIO operations to pass data between them. > > > On an Amiga you'd use "message ports" (which operated somewhat > > similar to VMS mailboxes except that mailboxes had an independent > > existence, multiple processes can read or write to them -- message ports > > were readable by the creating process, but could have messages sent from > > anywhere; typically passing the message port [address of a linked list > > of messages] for replies). Or a higher level message port: an ARexx > > port. > > > On a Windows NT class system, the win32 extensions allow access to > > Windows Named Pipes... Or maybe the Windows clipboard could be used... > > -- > > WulfraedDennis Lee Bieber KD6MOG > > [EMAIL PROTECTED] [EMAIL PROTECTED] > > HTTP://wlfraed.home.netcom.com/ > > (Bestiaria Support Staff: [EMAIL PROTECTED]) > > HTTP://www.bestiaria.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Allingn controls wxPython
On Dec 15, 10:14 pm, SMALLp <[EMAIL PROTECTED]> wrote: > Hy. I need help. I'm using BoxSizer and i put TextCtrl and StaticText > next to each other and they gor alligned by top of TextCtrl and it looks > terrible. How can i make thm to be alligned by center of each controll. > > Thnaks! Use the flag wx.ALIGN_CENTRE_VERTICAL when adding the controls to the sizer. If you have a number of StaticText/TextCtrl pairs, and you want them to line up underneath each other, use a FlexGridSizer or a GridBagSizer. Frank Millman -- http://mail.python.org/mailman/listinfo/python-list
Re: About Rational Number (PEP 239/PEP 240)
On Sat, 15 Dec 2007 17:42:26 -0800, Dennis Lee Bieber wrote: > On Sun, 16 Dec 2007 00:42:56 -, Steven D'Aprano > <[EMAIL PROTECTED]> declaimed the following in > comp.lang.python: > >> In the real world, people use fractions all the time, e.g. plumbers. >> (Not that I'm expecting plumbers to start taking laptops out to the >> building site in order to calculate pipe sizes.) >> > Piping tends to come in a limited range of discrete diameters, with > a slew of adapters to convert from one to another. As such, they fit > more in the Ada "fixed point" system or can be treated as a scaled > integer... One does not find random pipe diameters. Yes, but my point (badly put, I admit) was that people find fractions far easier to work with than they find floating point numbers. And with any rational data type worth the name, you simply should never get anything as unintuitive as this: >>> from __future__ import division >>> 4/10 + 2/10 == 6/10 False -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested Reading
Benoit wrote: > I got myself into programming late in the summer and have dabbled in > python for the most part in that time, recently beginning work on a > music player. In January, I start my minor in Information > Technology. I'd like to get ahead a bit, however, and over the break > would like to do some reading. I seek your recommendations in the > field of database design basics and network programming, with a bias > towards texts which specifically address Python. By network > programming, I mean fundamental understanding of sockets, TCP/UDP, > right up to HTTP serving, etc. Thanks ahead of time. Steve Holden's Python Web Programming might be what you are looking for. It covers all the topics needed to deal with sockets, databases, up to building complete web apps. One of my books I'd never give away. HTH Thin -- http://mail.python.org/mailman/listinfo/python-list
Finite State Machine GUI editor in python?
I have spent some time googling and on wiki and came up with pyFSA in python. It may end up being useful, but it is not directly what I am looking for, as there is no GUI that I can see. I know about SMC, but it is not Python, and I can't find the gui. This looks good, but it seems to be in a Latin based language and I am linguistically challenged: http://www.ucse.edu.ar/fma/sepa/edt.htm I am looking for a similar front end, going from pretty pictures of state diagrams to some sort of state machine descriptor language or specification file, and I am not very fussy about the format of the output at this stage. Does anyone know of such an animal that is FOSS? - if written in Python it will be a bonus! It will also help if its in a language I can understand. : - ( - Hendrik -- http://mail.python.org/mailman/listinfo/python-list