[Tutor] Fw: list.replace -- string.swap
Forwarding to list From: spir denis.s...@free.fr To: Alan Gauld alan.ga...@btinternet.com Sent: Wednesday, 18 March, 2009 8:41:39 AM Subject: Re: [Tutor] list.replace -- string.swap Le Tue, 17 Mar 2009 20:46:06 -, Alan Gauld s'exprima ainsi: spir wrote Sorry, I was unclear all along my post. Is there a list.replace builtin I cannot find? Or a workaround? myList[x] = newValue Or is that too obvious? I mean like string.replace. Something like: def replace(seq, v1, v2): for (index,item) in enumerate(seq): if item == v1: seq[index] = v2 Now, I know i does not exist. Also: How would perform string.swap(s1, s2) in the following cases: Here I mean exchanging s1 and s2 occurrences all along a string. As an example, in a text containing numerous formatted numbers, switch from english to european format: 1,234,567.89 1.234.567,89 meaning exchange '.' and ','. * There is no secure 'temp' char, meaning that s.replace(s1,temp).replace(s2,s1).replace(temp,s2) will fail because any char can be part of s. The use of a temp char for marking places of one the chars to be swapped is a common trick. But if the text can contain any char (even chr(0)), then there no char you can safely use as temp. The only workaround I know is to pass through lists. Then swap on the list, using eg None as temp item, and glue back the result to a string. But you need them a replace method on lists, hence my previous question ;-) * Either s1 or s2 can be more than a single char. More difficult, cause you cannot simple list() the string. It must split on s1 and s2, but keeping the delimiters! There is no option afaik for that in string.split -- too bad! So that you must split it manually at start and end of each instance of s1 and s2. Or there are other algorithms I cannot figure out. What I was asking for. Sorry you lost me there. No idea what you mean. Sorry, me! Alan G. denis -- la vita e estrany ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] combining Python 2.x and Python 3
On Wed, Mar 18, 2009 at 1:50 AM, wesley chun wes...@gmail.com wrote: wow, great links Kent. i didn't think that people would be as bold as to do this, but i guess it was inevitable. it may be worthwhile to collate all of this info into a 2to3 FAQ at some point. http://wiki.python.org/moin/PortingPythonToPy3k I should also mention the python-porting mailing list: http://mail.python.org/mailman/listinfo/python-porting Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python and Tkinter Programming by Grayson--New Version?
Here is the news about a new Tk in Python: (Posted on the TkDocs web site - the home of Tk) February 03, 2009 Ttk support in Python. Guilherme Polo passed along the great news that his pyttk module has been accepted into Python's standard library. That means we should see pyttk generally available with Python 2.7 and 3.1 (both still in development). You can see the current docs here. And of course, this is something I was waiting for before updating TkDocs with Python info and examples. Thanks for all your hard work Guilherme! Note this seems to be a recent web site and they are still building a lot of the documentation, but it looks like it should turn into a very useful Tk resource. As for the Tkinter mailing list. You can either watch it via the gmane news feed (which I do) and using your preferred news reader subscribe to: gmane.comp.python.tkinter Or on the web at: http://dir.gmane.org/gmane.comp.python.tkinter or go to http://mail.python.org/mailman/listinfo/tkinter-discuss to sign up for the emails. HTH, Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ From: Wayne Watson sierra_mtnv...@sbcglobal.net To: ALAN GAULD alan.ga...@btinternet.com Sent: Wednesday, 18 March, 2009 12:25:58 PM Subject: Re: [Tutor] Python and Tkinter Programming by Grayson--New Version? How do I get to that mail list? I see no evidence of a new Tkinter in my internet Googling. Maybe it's going by a new name? ALAN GAULD wrote: Tk is far from dead. Try the Tkinter mailing list, it is at least as busy as the tutor one. And the Tcl/Tk side of things has had a new lease of life over the past two years with a complete re-architecture of Tk resulting in the new native-look widgets. We just need that new found activity to translate to Tkinter... Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ From: Wayne Watson sierra_mtnv...@sbcglobal.net To: Alan Gauld alan.ga...@btinternet.com Sent: Wednesday, 18 March, 2009 2:24:52 AM Subject: Re: [Tutor] Python and Tkinter Programming by Grayson--New Version? Working with Tkinter is like trying to dig through fossils. So much out there is old or incomplete. It's like the Tk species went extinct. The trail seems to end in 2005. I think I read it's not quite dead, and a newer looking is coming. Alan Gauld wrote: Wayne Watson sierra_mtnv...@sbcglobal.net wrote I've poked around at the pieces of the book in Subject, which are on the web It was published in 2000, first ed. It looks quite good, and certainly is big, About a third of it is reference material. Not a bad thing, I use it a lot, but other sources have the same stuff. A lot is PMW which although still active I think, is no longer the only add on toolkit. Indeed Tix is now partof the standard library and adds a lot of the same sort of things. (Tabbed notebooks etc) The other oddity is a fair portion of the book is taken up with building photo-realistic UIs. This is not something I've ever found a need for! It is quite impressive but of distinctly limitedvalue for most programmers IMHO. I'd like to think the author is going to produce another version. I've seen no signs of that. And although some of the newer widgets are not included very little of the book is out of date. OTOH if you just need a reference the Tcl/Tk in a Nutshell by O'Reilly might suit just as well and is available very cheaply second hand on Amazon... It is my second most used Tk source. (after Lundh's online reference, Grayson is my third!) It also covers Tix. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another. -- Mark Twain -- Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another. -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] combining Python 2.x and Python 3
These are very interesting links, and I just downloaded the evoque code to see how they handled the one impossible case that has stymied me in supporting pyparsing under Python 2.x (pre-2.6) and Python 3.0 with a single code base: exception handling. For those new to this topic, here is the problem. Python 2.x uses this syntax (code in []'s is optional, syntax-wise): try: ... body of try block ... except exception_type[, exception_var]: ... body of except block ... In Python 3.0, this has become: try: ... body of try block ... except exception_type[as exception_var]: ... body of except block ... Searching through evoque's code, I found that nearly all excepts are of the form: except exception_type: (3 are bare except:'s - eek!) Unfortunately, pyparsing makes *heavy* use of exceptions for managing the navigation through the parsing alternatives defined in the users parser expression. I have already removed all cases of except exc_type, exc_var: where the exc_var is not used in the exception handling block, but there are still some cases where I *must* have the actual exception that was raised. I posted to Stephan Deibel's blog a comment asking how he resolved this - here is his reply: Instead of the version-specific except clause forms I use just 'except SomeException:' or 'except:' and then use sys.exc_info() inside the except block to get at the exception information. That returns a three-value tuple, the second element of which is the same thing you would get for 'e' in 'except SomeException, e:' or 'except SomeException as e:'. Well, this is certainly promising, but pyparsing already has performance challenges, and adding another function call in an exception handler to work around this syntax issue is not that attractive. My rough timing shows that calling exc_info to extract the exception variable incurs a ~30% performance penalty over using except exc_type, exc_var:. Note that adding this code would impact not only the Python 3.0 users, but would also degrade performance for Python 2.x users using this code base. I can certainly use this trick in those parts of pyparsing that are not performance-critical (when building the parser to begin with for instance, as opposed to the actual parsing time). But in the parse-time code, I'm unwilling to add 30% to my users' parsing time. -- Paul ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fun with Label and Entry--Why NoneType?
Title: Signature.html That change got the same result. Maybe this will make it all clearer. root = Tk() z=raw_input("howdy ") dialog = DialogPrototype(root) When the prompt appears, there is a small window showing on the screen, 2x2", I guess. It shows in the upper left a Tk icon on the title bar, and next to it in light gray tk, lower case. It persists when I press Cancel or OK. My guess is that dialog needs to be "connected" to that root window. I tried with a frame, but that didn't do it. That pretty much does it for me. I can live with it for my purposes if I stick to the command window, which nicely closes when I hit OK. IDLE forces a hang in the shell window, which requires effort to recover. The Tk window appears in using either command prompt or IDLE. Alan Gauld wrote: "Wayne Watson" sierra_mtnv...@sbcglobal.net wrote Unfortunately, that takes me back to the original situation. That is, the blank window appears along with the dialog window. OK Try this version: # Derived from Grayson 5_14.py from Tkinter import * from tkSimpleDialog import Dialog class DialogPrototype(Dialog): def body(self, master): self.title("Enter Site Data") Label(master, text='Latitude:').grid(row=0, sticky=W) self.lat=Entry(master, width=12) self.lat.grid(row=0, column=1) Label(master, text='Longitude:').grid(row=0, column=2) self.long=Entry(master, width=12) self.long.grid(row=0, column=3) self.master.withdraw() def apply(self): print "apply" print self.lat.get() print self.long.get() print "setting" lat=1.0 long=0.0 root = Tk() DialogPrototype(root) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fun with Label and Entry--Why NoneType?
That change got the same result. Maybe this will make it all clearer. When the prompt appears, there is a small window showing on the screen, 2x2, Yes, that's the root window that Python expects you to put your GUI into. The master that you pas to your GUI wFrames. It didn't show for me with the code I posted. How are you running this? Are you launching it from Windows Explorer or from a command line or from an IDE? I was just double clicking on the file in explorer... My guess is that dialog needs to be connected to that root window. I suspect the problem is that you are trying to run a dialog as an application. Dialogs are normally launched from another window. So normally that Tk window would come up with the main app form, menus etc. Then from there you would perform an action (button, menu etc) that would launch the Dialog. So we are kind of twisting the way Tkinter expects to be uased here. But putting withdraw into the body method worked for me last night. IDLE forces a hang in the shell window, which requires effort to recover. As I keep saying, don't use IDLE to run Tkinter apps. Despite the supposed fixes it is not a reliable mechanism. Use ODLE as an editor but run the app from Windows Explorer or a command line BTW I just double checked and when I double click in Explorer on the python file I only get the dialog and Dos box (which of course would go away if I changeed the file extension to .pyw) Alan G OK Try this version: # Derived from Grayson 5_14.py from Tkinter import * from tkSimpleDialog import Dialog class DialogPrototype(Dialog): def body(self, master): self.title(Enter Site Data) Label(master, text='Latitude:').grid(row=0, sticky=W) self.lat=Entry(master, width=12) self.lat.grid(row=0, column=1) Label(master, text='Longitude:').grid(row=0, column=2) self.long=Entry(master, width=12) self.long.grid(row=0, column=3) self.master.withdraw() def apply(self): print apply print self.lat.get() print self.long.get() print setting lat=1.0 long=0.0 root = Tk() DialogPrototype(root) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Executing a C Program from RH Linux in Python for Win
Title: Signature.html The Subject contains the interest here. Can it be done? I think it this case it requires executing the program command line with parameters then executing it? How dependent upon the C compiled code is this? That is, I would think various distributions of Linux might produce different executable code. The too I would want to do this in Win. Is there, in fact, some Linux environment in Win that would allow me to test its executable? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
Wayne, I think I do the opposite of what you are doing. I develop in Python on a Linux (Ubuntu 8.10) box. On that box, I also run a virtual copy of Windows XP in its own little happy environment. That way, when my XP customers have a problem, I drop into the desktop environment running XP and we are off and running. From the gist of your comment, you want to run Linux from within your Windows OS? Well, given the miracle of Virtual Memory, you can do that. Download the Xvm Virtual Memory (free) package from Sun and install it on your Windows system. Then, allocate a Linux system under the auspices of VM and you are off and running. Hope this is of some help. Robert Berman Wayne Watson wrote: The Subject contains the interest here. Can it be done? I think it this case it requires executing the program command line with parameters then executing it? How dependent upon the C compiled code is this? That is, I would think various distributions of Linux might produce different executable code. The too I would want to do this in Win. Is there, in fact, some Linux environment in Win that would allow me to test its executable? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another. -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
Wayne Watson sierra_mtnv...@sbcglobal.net wrote The Subject contains the interest here. Can it be done? A C program is compiled into a binary executable complete with link loader. The executable is not portable across operating systems (nor hardware architectures in most cases) I think it this case it requires executing the program command line with parameters then executing it? Yes and that can be done via the Popen class in the subprocess module. So your python program can launch an executable and read/write to stdout/in Alternatively you can launch a GUI program and access it via technologies such as COM in Windows. Other OS/Desktop environments have other hooks - eg Applescript can often be used on MacOS. How dependent upon the C compiled code is this? That is, I would think various distributions of Linux might produce different executable code. No the compiled code runs (or can run) on any distribution of Linux. The distributions vary in where they store system files, which packages are included/installed as standard and the admin tools they provide. But the underlying OS is essentially the same for all of them. The too I would want to do this in Win. Is there, in fact, some Linux environment in Win that would allow me to test its executable? You can run Linux on a virtual machine inside Windows. VMWare is one route to this. Or you might be able to use cygwin to produce a windows application running using cygwin (a set of Linux like libraries for Windows). The formner alloows you to run the actual Linux executable file, the latter allows you to recompile the C code to run under Windows. Depends what suits you best. HTH, -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python and Tkinter Programming by Grayson--New Version?
Thanks. Interesting. I went to the web site and thought I'd find out about how NNTP works. I clicked the line, and nothing happened, so I explored some other info, and came back here. As I opened your msg, I wizard showed up from SeaMonkey. I clicked cancel, and then realized that must be what I needed to get to gname, etc. Slow going at almost noon here. As I wander around the internet trying to get info from Lundh, New Mexico, and other sites, I wonder if, in particular New Mexico is not using the "new" Tkinter. How would I know? Still waiting for the wizard. ALAN GAULD wrote: Here is the news about a new Tk in Python: (Posted on the TkDocs web site - the home of Tk) February 03, 2009 Ttk support in Python. Guilherme Polo passed along the great news that his pyttk module has been accepted into Python's standard library. That means we should see pyttk generally available with Python 2.7 and 3.1 (both still in development). You can see the current docs here. And of course, this is something I was waiting for before updating TkDocs with Python info and examples. Thanks for all your hard work Guilherme! Note this seems to be a recent web site and they are still building a lot of the documentation, but it looks like it should turn into a very useful Tk resource. As for the Tkinter mailing list. You can either watch it via the gmane news feed (which I do) and using your preferred news reader subscribe to: gmane.comp.python.tkinter Or on the web at: http://dir.gmane.org/gmane.comp.python.tkinter or go to http://mail.python.org/mailman/listinfo/tkinter-discuss to sign up for the emails. HTH, Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ From: Wayne Watson sierra_mtnv...@sbcglobal.net To: ALAN GAULD alan.ga...@btinternet.com Sent: Wednesday, 18 March, 2009 12:25:58 PM Subject: Re: [Tutor] Python and Tkinter Programming by Grayson--New Version? How do I get to that mail list? I see no evidence of a "new" Tkinter in my internet Googling. Maybe it's going by a new name? ALAN GAULD wrote: Tk is far from dead. Try the Tkinter mailing list, it is at least as busy as the tutor one. And the Tcl/Tk side of things has had a new lease of life over the past two years with a complete re-architecture of Tk resulting in the new native-look widgets. We just need that new found activity to translate to Tkinter... Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ From: Wayne Watson sierra_mtnv...@sbcglobal.net To: Alan Gauld alan.ga...@btinternet.com Sent: Wednesday, 18 March, 2009 2:24:52 AM Subject: Re: [Tutor] Python and Tkinter Programming by Grayson--New Version? Working with Tkinter is like trying to dig through fossils. So much out there is old or incomplete. It's like the Tk species went extinct. The trail seems to end in 2005. I think I read it's not quite dead, and a newer looking is coming. Alan Gauld wrote: "Wayne Watson" sierra_mtnv...@sbcglobal.net wrote I've poked around at the pieces of the book in Subject, which are on the web It was published in 2000, first ed. It looks quite good, and certainly is big, About a third of it is reference material. Not a bad thing, I use it a lot, but other sources have the same stuff. A lot is PMW which although still active I think, is no longer the only add on toolkit. Indeed Tix is now partof the standard library and adds a lot of the same sort of things. (Tabbed notebooks etc) The other oddity is a fair portion of the book is taken up with building photo-realistic UIs. This is not something I've ever found a need for! It is quite impressive but of distinctly limitedvalue for most programmers IMHO. I'd like to think the author is going to produce another version. I've seen no signs of that. And although some of the newer widgets are not included very little of the book is out of date. OTOH if you just need a reference the "Tcl/Tk in a Nutshell" by O'Reilly might suit just as well and is available very cheaply second hand on Amazon... It is my second most used Tk source. (after Lundh's online reference, Grayson is my third!) It also covers Tix. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another." -- Mark Twain -- Signature.html Wayne Watson (Watson Adventures,
[Tutor] Playing with CENTER, Grid, Labels and Entry
Title: Signature.html I'm prototyping a dialog with about 10 rows of 4 columns of widgets. Most rows are like: Label, Entry, Label, Entry A couple only have Label, Entry. I'm using Grid. It's gone pretty well, but I'd like to make it "prettier". For example, a row with latitude and longitude gets spread across the dialog, whereas, they should be closer together. However, at the moment, I'm trying to build a title across row 8. I want some centering of the text, but the methods and options defy my attempts. Comments? ... self.title("Enter Site Data") Label(master, text='Latitude:').grid(row=0, sticky=W) self.lat = Entry(master, width=12) self.lat.grid(row=0, column=1) Label(master, text='Longitude:').grid(row=0, column=2) self.long = Entry(master, width=12) self.long.grid(row=0, column=3) ... mask_value="40" Label(master, text='Flat Mask Value:').grid(row=6, sticky=W) self.flat_value = Entry(master, width=7) self.flat_value.grid(row=6, column=1) self.flat_value.insert(4,mask_value) Label(master, text='Mask File Name:').grid(row=7, sticky=W) self.mask_name = Entry(master, width=40) self.mask_name.grid(row=7, column=1) #title=Label(master, text="This is a Title").grid(row=8,column=0, column(anchor=CENTER), columnspan=3) title=Label(master, text="This is a Title").grid(row=8, column=0, columnspan=3).columnconfigure(0,anchor=CENTER) #title.configure(anchor=CENTER) ... -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
Title: Signature.html Thanks to both above posts before this reply. I'll forgo the VM route. It would really complicate things for the users of the application having to deal with VM. Most are near neophytes. Nevertheless, it looks like there may be some hope here for just doing it from w/i Win OS. My other choice is recoding 38K lines of C code into Python. I'll pass on that. :-) Unless there's a very good translator between languages. Alan Gauld wrote: "Wayne Watson" sierra_mtnv...@sbcglobal.net wrote The Subject contains the interest here. Can it be done? A C program is compiled into a binary executable complete with link loader. The executable is not portable across operating systems (nor hardware architectures in most cases) I think it this case it requires executing the program command line with parameters then executing it? Yes and that can be done via the Popen class in the subprocess module. So your python program can launch an executable and read/write to stdout/in Alternatively you can launch a GUI program and access it via technologies such as COM in Windows. Other OS/Desktop environments have other hooks - eg Applescript can often be used on MacOS. How dependent upon the C compiled code is this? That is, I would think various distributions of Linux might produce different executable code. No the compiled code runs (or can run) on any distribution of Linux. The distributions vary in where they store system files, which packages are included/installed as standard and the admin tools they provide. But the underlying OS is essentially the same for all of them. The[This] too I would want to do this in Win. Is there, in fact, some Linux environment in Win that would allow me to test its executable? You can run Linux on a virtual machine inside Windows. VMWare is one route to this. Or you might be able to use cygwin to produce a windows application running using cygwin (a set of Linux like libraries for Windows). The formner alloows you to run the actual Linux executable file, the latter allows you to recompile the C code to run under Windows. Depends what suits you best. HTH, -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
On Wed, Mar 18, 2009 at 4:06 PM, Wayne Watson sierra_mtnv...@sbcglobal.net wrote: Thanks to both above posts before this reply. I'll forgo the VM route. It would really complicate things for the users of the application having to deal with VM. Most are near neophytes. Nevertheless, it looks like there may be some hope here for just doing it from w/i Win OS. My other choice is recoding 38K lines of C code into Python. I'll pass on that. :-) Unless there's a very good translator between languages. I'm confused about what you want to do. If you have the code and want to call it from python, then maybe you can use something like http://www.swig.org/ is what you're looking for. What is the Red Hat dependency? I.e., what libraries are needed? Many libraries are available for windows. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Iterating over letters or arbitrary symbols like they were numbers...
If there's an easy way to do this, I'd like to have a pointer to it (i.e. what functions would deal with this - not wanting my code written for me...) Right now, I have written code to generate a list of strings that happen to be a range of numbers. (The fact that they're strings is actually desirable to me). My code looks at the range given to the function and zero-pads based on the length of the start of the range. Ranges are indicated by number-colon-number, e.g. 1:9 or 01:99 or 1:99. (for reasons outside this snippet of code, I refer to these as expressions or exp for short...) Here's the code in question: __ exp_list = [] exp_range = exp.split(:) min_padding = len(exp_range[0]) for i in range(int(exp_range[0]),(int(exp_range[1])+1)): exp_list.append('%0*d' % (min_padding, i)) __ (in fact, I'm *actually* parsing something like n(1:9;13;15;17:25) - so I have multiple ranges and individual numbers to add to exp_list[], so in my actual code, the list exists elsewhere, and this code is executed if I find a colon in an element in the list created from splitting the original line on commas (and removing the n and parentheses) - hope that makes sense) I'm quite proud of that - for the level of programming I feel I'm at, I thought it was somewhat clever. ;-) But I'm open to feedback on that... BUT, here's what I need to do: That creates a list of numbers. I also need to do letters. That is, treat a-z as base 26, and do the same thing. The three examples I gave from before would be: 1:9 -- a:z 1:99 -- a:zz 01:99 -- no zero in alpha to worry about, so no padding necessary... So my first question is: Can I somehow treat letters like base 26? If I can, what about alphanumeric, i.e. 0-9+a-z would be like base 36... Am I stuck rolling my own arithmetic-type function? (i.e. z+a=aa and z+b=ab, etc) Thank you very much for any advice (and again, in addition to my actual question, I wouldn't mind hearing if my solution for the numbers is less clever than I thought-- i.e. not looking for praise; rather, looking for improvement if it's glaringly dumb) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Iterating over letters or arbitrary symbols like they were numbers...
Title: Signature.html It looks like you used the wrong thread to post this. It's connected to questions about linux and Win, and not iterations. Alexander Daychilde (Gmail) wrote: If there's an easy way to do this, I'd like to have a pointer to it (i.e. what functions would deal with this - not wanting my code written for me...) Right now, I have written code to generate a list of strings that happen to be a range of numbers. (The fact that they're strings is actually desirable to me). My code looks at the range given to the function and zero-pads based on the length of the start of the range. Ranges are indicated by number-colon-number, e.g. 1:9 or 01:99 or 1:99. (for reasons outside this snippet of code, I refer to these as "expressions" or "exp" for short...) Here's the code in question: __ exp_list = [] exp_range = exp.split(":") min_padding = len(exp_range[0]) for i in range(int(exp_range[0]),(int(exp_range[1])+1)): exp_list.append('%0*d' % (min_padding, i)) __ (in fact, I'm *actually* parsing something like n(1:9;13;15;17:25) - so I have multiple ranges and individual numbers to add to exp_list[], so in my actual code, the list exists elsewhere, and this code is executed if I find a colon in an element in the list created from splitting the original line on commas (and removing the n and parentheses) - hope that makes sense) I'm quite proud of that - for the level of programming I feel I'm at, I thought it was somewhat clever. ;-) But I'm open to feedback on that... BUT, here's what I need to do: That creates a list of numbers. I also need to do letters. That is, treat a-z as base 26, and do the same thing. The three examples I gave from before would be: 1:9 -- a:z 1:99 -- a:zz 01:99 -- no "zero" in alpha to worry about, so no padding necessary... So my first question is: Can I somehow treat letters like base 26? If I can, what about alphanumeric, i.e. 0-9+a-z would be like base 36... Am I stuck rolling my own arithmetic-type function? (i.e. z+a=aa and z+b=ab, etc) Thank you very much for any advice (and again, in addition to my actual question, I wouldn't mind hearing if my solution for the numbers is less clever than I thought-- i.e. not looking for praise; rather, looking for improvement if it's glaringly dumb) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fw: list.replace -- string.swap
It wasn't my question :-) Forwarding to list... Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ - Original Message From: Ricardo Aráoz ricar...@gmail.com Subject: Re: [Tutor] Fw: list.replace -- string.swap Also: How would perform string.swap(s1, s2) in the following cases: Here I mean exchanging s1 and s2 occurrences all along a string. As an example, in a text containing numerous formatted numbers, switch from english to european format: 1,234,567.89 1.234.567,89 meaning exchange '.' and ','. * There is no secure 'temp' char, meaning that s.replace(s1,temp).replace(s2,s1).replace(temp,s2) will fail because any char can be part of s. The use of a temp char for marking places of one the chars to be swapped is a common trick. But if the text can contain any char (even chr(0)), then there no char you can safely use as temp. The only workaround I know is to pass through lists. Then swap on the list, using eg None as temp item, and glue back the result to a string. But you need them a replace method on lists, hence my previous question ;-) * Either s1 or s2 can be more than a single char. More difficult, cause you cannot simple list() the string. It must split on s1 and s2, but keeping the delimiters! There is no option afaik for that in string.split -- too bad! So that you must split it manually at start and end of each instance of s1 and s2. Or there are other algorithms I cannot figure out. What I was asking for. So NOW I get your question!!! It's easy : import string mystr = '1,234,567.89' mystr.translate(string.maketrans('.,', ',.')) '1.234.567,89' Any length of string to be translated, any length of translation tables (not only two values, any amount of them). HTH Ricardo. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python and Tkinter Programming by Grayson--New Version?
Wayne Watson sierra_mtnv...@sbcglobal.net wrote As I wander around the internet trying to get info from Lundh, New Mexico, and other sites, I wonder if, in particular New Mexico is not using the new Tkinter. How would I know? Nobody is using the new version yet, it's targetted for 3.1 and 2.7 - both are the next releases of Python oin their respective streams. But most of the existing documentation doesn't even cover the newer widgets added since 2.x - and none that I know of covers Tix at all. Still waiting for the wizard. There are lots of news readers around. Which OS are you on? There is also the web page which only requiires a browser, but the gmane archive is much easier accessed by a newsreader IMHO. February 03, 2009 Ttk support in Python. Guilherme Polo passed along the great news that his pyttk module has been accepted into Python's standard library. Â That means we should see pyttk generally available with Python 2.7 and 3.1 (both still in development). Â You can see the current docs here. Â And of course, this is something I was waiting for before updating TkDocs with Python info and examples. Thanks for all your hard work Guilherme! and using your preferred news reader subscribe to: gmane.comp.python.tkinter Or on the web at: http://dir.gmane.org/gmane.comp.python.tkinter ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Playing with CENTER, Grid, Labels and Entry
Title: Signature.html Nothing like a good example. anchors away. It's where you put it. anchor=CENTER. See http://www.java2s.com/Code/Python/GUI-Tk/Usingthegridgeometrymanager.htm for more. fromTkinterimport* classApp: def__init__(self,master): master.geometry("300x200") fm=Frame(master) Button(fm,text='side=TOP,anchor=NW').pack(side=TOP,anchor=NW,expand=YES) Button(fm,text='side=TOP,anchor=W').pack(side=TOP,anchor=W,fill=X,expand=YES) Button(fm,text='side=TOP,anchor=E').pack(side=TOP,anchor=E,expand=YES) fm.pack(fill=BOTH,expand=YES) root=Tk() root.option_add('*font',('verdana',12,'bold')) root.title("Pack-Example11") display=App(root) root.mainloop() Wayne Watson wrote: I'm prototyping a dialog with about 10 rows of 4 columns of widgets. Most rows are like: Label, Entry, Label, Entry A couple only have Label, Entry. I'm using Grid. It's gone pretty well, but I'd like to make it "prettier". For example, a row with latitude and longitude gets spread across the dialog, whereas, they should be closer together. However, at the moment, I'm trying to build a title across row 8. I want some centering of the text, but the methods and options defy my attempts. Comments? ... self.title("Enter Site Data") Label(master, text='Latitude:').grid(row=0, sticky=W) self.lat = Entry(master, width=12) self.lat.grid(row=0, column=1) Label(master, text='Longitude:').grid(row=0, column=2) self.long = Entry(master, width=12) self.long.grid(row=0, column=3) ... mask_value="40" Label(master, text='Flat Mask Value:').grid(row=6, sticky=W) self.flat_value = Entry(master, width=7) self.flat_value.grid(row=6, column=1) self.flat_value.insert(4,mask_value) Label(master, text='Mask File Name:').grid(row=7, sticky=W) self.mask_name = Entry(master, width=40) self.mask_name.grid(row=7, column=1) #title=Label(master, text="This is a Title").grid(row=8,column=0, column(anchor=CENTER), columnspan=3) title=Label(master, text="This is a Title").grid(row=8, column=0, columnspan=3).columnconfigure(0,anchor=CENTER) #title.configure(anchor=CENTER) ... -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python and Tkinter Programming by Grayson--New Version?
Title: Signature.html Thanks. My computer continued to struggle. An hour later it was so bad I rebooted. Nothing like cleaning house. I seem to go for about 5-7 days, then things get clogged up. Running fine now. I think I'll be able to set up the newsreader now without any trouble. Alan Gauld wrote: "Wayne Watson" sierra_mtnv...@sbcglobal.net wrote As I wander around the internet trying to get info from Lundh, New Mexico, and other sites, I wonder if, in particular New Mexico is not using the "new" Tkinter. How would I know? Nobody is using the new version yet, it's targetted for 3.1 and 2.7 - both are the "next" releases of Python oin their respective streams. But most of the existing documentation doesn't even cover the newer widgets added since 2.x - and none that I know of covers Tix at all. Still waiting for the wizard. There are lots of news readers around. Which OS are you on? There is also the web page which only requiires a browser, but the gmane archive is much easier accessed by a newsreader IMHO. February 03, 2009 Ttk support in Python. Guilherme Polo passed along the great news that his pyttk module has been accepted into Python's standard library. Â That means we should see pyttk generally available with Python 2.7 and 3.1 (both still in development). Â You can see the current docs here. Â And of course, this is something I was waiting for before updating TkDocs with Python info and examples. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Playing with CENTER, Grid, Labels and Entry
Wayne Watson sierra_mtnv...@sbcglobal.net wrote I'm using Grid. It's gone pretty well, but I'd like to make it prettier. For that Frame is usually your friend. Create your widgets inside frames and then pack or grid the Frames. You can then use a combination of padding, filling and anchoring etc in both way you insert the widgets into the Frame and the way you insert the Frame into the window. Personally I find drawing it out with pencil and paper helps a lot when layouts start to get complicated. For example, a row with latitude and longitude gets spread across the dialog, whereas, they should be closer together. If you put them both in a Frame and then put the frame into one of yourgrid cells they will both be together on one side. However, at the moment, I'm trying to build a title across row 8. I want some centering of the text, but the methods Use a Frame to hold the label then use pack to put the label centred in the Frame. Then grid the frame into your window spanning cells as needed. Frames are your friend for layout. To be honest I usually use the packer for the layout of my top window then use grid inside a Frame. I can then create smaller frames to insert into the grid. Don't forget that when creating subframes the subframe should be used as the parent of the widgets: fCoords = Frame(self.master) # the subframe as child of the main window eLat = Entry(fCoords,.)# use subframe as parent eLat.grid(row=0, col=0) # grid it within the subframe so reset counts to 0 eLong = Entry(fCoords,.) # and here eLong.grid(row = 0, col=1) fCoords.grid(row = current, col = whatever) HTH, -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fun with Label and Entry--Why NoneType?
Title: Signature.html ALAN GAULD wrote: That change got the same result. Maybe this will make it all clearer. When the prompt appears, there is a small window showing on the screen, 2x2", Yes, that's the root window that Python expects you to put your GUI into. The master that you pas to your GUI wFrames. It didn't show for me with the code I posted. It was a bit hard to verify your code, since when I copied it, it had different indentation and I may not have assembled it properly. Was the only change to the code? See "nevertheless" comment below. root = Tk() DialogPrototype(root) How are you running this? Are you launching it from Windows Explorer or from a command line or from an IDE? I was just double clicking on the file in explorer... IDLE but always verifying with command prompt as the need arises. I seem to be into several programs at once, so having 3 or so command prompts open drives me a bit daffy. It seems easier to have 3 IDLE windows open. I never got clear on how to fill out a line in command line. Using tab doesn't work. F8 worked once, but never again. That would make it more attractive to just use command prompt for execution. Yes, I know I can back up to previous lines and modify them. Then too there is no way to copy things out of that window. Yes, I know I can back up likes and modify them. My guess is that dialog needs to be "connected" to that root window. I suspect the problem is that you are trying to run a dialog as an application. Dialogs are normally launched from another window. So normally that Tk window would come up with the main app form, menus etc. Then from there you would perform an action (button, menu etc) that would launch the Dialog. So we are kind of twisting the way Tkinter expects to be uased here. But putting withdraw into the body method worked for me last night. Actually, I think I'll go back to withdraw. It had been working for me. Nevertheless a solution to all this is not important to me any longer. It's only a prototype, and I can live with a bit of nuttiness. Eventually, I'll pull it all out and stick it into the application and all will be well, won't it? :-) IDLE forces a hang in the shell window, which requires effort to recover. As I keep saying, don't use IDLE to run Tkinter apps. Despite the supposed fixes it is not a reliable mechanism. Use ODLE as an editor but run the app from Windows Explorer or a command line I use both command prompt to verify IDLE results. They agreed. BTW I just double checked and when I double click in Explorer on -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Iterating over letters or arbitrary symbols like they were numbers...
2009/3/19 Alexander Daychilde (Gmail) daychi...@gmail.com: That creates a list of numbers. I also need to do letters. That is, treat a-z as base 26, and do the same thing. The three examples I gave from before would be: 1:9 -- a:z 1:99 -- a:zz 01:99 -- no zero in alpha to worry about, so no padding necessary... So my first question is: Can I somehow treat letters like base 26? If I can, what about alphanumeric, i.e. 0-9+a-z would be like base 36... The int() function takes a second parameter, which is the base. This is so that it can deal with hex strings -- for example, int('7a', 16) == 122. But the base can actually be anything up to 36. For converting a base n string to an integer, the digits are the first n elements of '0123456789abcdefghijklmnopqrstuvwxyz'. To go the other way, I had a quick poke around in the python cookbook and found this one-liner: def baseN(num,b,numerals=0123456789abcdefghijklmnopqrstuvwxyz): return ((num == 0) and 0 ) or ( baseN(num // b, b).lstrip(0) + numerals[num % b]) You may be able to find better ones. If you want to convert 'a'..'z' to integers by treating them as base-26 numbers.. it could be tricky because you (I think) have no 0. Multiplication without a 0 is really quite tricky :-) You might be better off writing a function to take one integer (e.g. 'ghzz') and produce the next one ('giaa'). Or you could cheat :-) import string letters = string.lowercase pairs = [''.join([a,b]) for a in letters for b in letters] threes = [''.join([a,b,c]) for a in letters for b in letters for c in letters] fours = [''.join([a,b,c,d]) for a in letters for b in letters for c in letters for d in letters] words = list(letters) + pairs + threes + fours def wcmp(x,y): ... if len(x) len(y): ... return -1 ... elif len(x) len(y): ... return 1 ... else: ... return cmp(x,y) ... words.sort(cmp=wcmp) words[words.index('a'):words.index('bb')+1] ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'aa', 'ab', 'ac', 'ad', 'ae', 'af', 'ag', 'ah', 'ai', 'aj', 'ak', 'al', 'am', 'an', 'ao', 'ap', 'aq', 'ar', 'as', 'at', 'au', 'av', 'aw', 'ax', 'ay', 'az', 'ba', 'bb'] Note that this is not very practical if your words can get out to five characters.. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Playing with CENTER, Grid, Labels and Entry
Title: Signature.html This couldn't be more timely. I finally gave up on the present idea, and thought to myself, "Try frames". You just saved me some Google work. Thanks. Alan Gauld wrote: "Wayne Watson" sierra_mtnv...@sbcglobal.net wrote I'm using Grid. It's gone pretty well, but I'd like to make it "prettier". For that Frame is usually your friend. Create your widgets inside frames and then pack or grid the Frames. You can then use a combination of padding, filling and anchoring etc in both way you insert the widgets into the Frame and the way you insert the Frame into the window. Personally I find drawing it out with pencil and paper helps a lot when layouts start to get complicated. For example, a row with latitude and longitude gets spread across the dialog, whereas, they should be closer together. If you put them both in a Frame and then put the frame into one of yourgrid cells they will both be together on one side. However, at the moment, I'm trying to build a title across row 8. I want some centering of the text, but the methods Use a Frame to hold the label then use pack to put the label centred in the Frame. Then grid the frame into your window spanning cells as needed. Frames are your friend for layout. To be honest I usually use the packer for the layout of my top window then use grid inside a Frame. I can then create smaller frames to insert into the grid. Don't forget that when creating subframes the subframe should be used as the parent of the widgets: fCoords = Frame(self.master) # the subframe as child of the main window eLat = Entry(fCoords,.) # use subframe as parent eLat.grid(row=0, col=0) # grid it within the subframe so reset counts to 0 eLong = Entry(fCoords,.) # and here eLong.grid(row = 0, col=1) fCoords.grid(row = current, col = whatever) HTH, -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Iterating over letters or arbitrary symbols like they were numbers...
On Wed, Mar 18, 2009 at 5:26 PM, Alexander Daychilde (Gmail) daychi...@gmail.com wrote: exp_list = [] exp_range = exp.split(:) min_padding = len(exp_range[0]) for i in range(int(exp_range[0]),(int(exp_range[1])+1)): exp_list.append('%0*d' % (min_padding, i)) This could be a little cleaner using tuple assignment to get rid of the subscripting and list comprehension to get rid of the loop: lower, upper = exp.split(':') min_padding = len(lower) exp_list = [ '%0*d' % (min_padding, i) for in in range(int(lower), int(upper)+1) ] Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fw: list.replace -- string.swap
ALAN GAULD wrote: It wasn't my question :-) Forwarding to list... Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ - Original Message From: Ricardo Aráoz ricar...@gmail.com Subject: Re: [Tutor] Fw: list.replace -- string.swap Also: How would perform string.swap(s1, s2) in the following cases: Here I mean exchanging s1 and s2 occurrences all along a string. As an example, in a text containing numerous formatted numbers, switch from english to european format: 1,234,567.89 1.234.567,89 meaning exchange '.' and ','. * There is no secure 'temp' char, meaning that s.replace(s1,temp).replace(s2,s1).replace(temp,s2) will fail because any char can be part of s. The use of a temp char for marking places of one the chars to be swapped is a common trick. But if the text can contain any char (even chr(0)), then there no char you can safely use as temp. The only workaround I know is to pass through lists. Then swap on the list, using eg None as temp item, and glue back the result to a string. But you need them a replace method on lists, hence my previous question ;-) * Either s1 or s2 can be more than a single char. More difficult, cause you cannot simple list() the string. It must split on s1 and s2, but keeping the delimiters! There is no option afaik for that in string.split -- too bad! So that you must split it manually at start and end of each instance of s1 and s2. Or there are other algorithms I cannot figure out. What I was asking for. So NOW I get your question!!! It's easy : import string mystr = '1,234,567.89' mystr.translate(string.maketrans('.,', ',.')) '1.234.567,89' Any length of string to be translated, any length of translation tables (not only two values, any amount of them). HTH Ricardo. Sorry Alan, was meant to the list. Just pressed reply and forgot here it does not go to the list. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python and Tkinter Programming by Grayson--New Version?
Well, after all that churning hours ago before the PC went down, it actually set up the newreader. Wayne Watson wrote: Thanks. My computer continued to struggle. An hour later it was so bad I rebooted. Nothing like cleaning house. I seem to go for about 5-7 days, then things get clogged up. Running fine now. I think I'll be able to set up the newsreader now without any trouble. Alan Gauld wrote: "Wayne Watson" sierra_mtnv...@sbcglobal.net wrote As I wander around the internet trying to get info from Lundh, New Mexico, and other sites, I wonder if, in particular New Mexico is not using the "new" Tkinter. How would I know? Nobody is using the new version yet, it's targetted for 3.1 and 2.7 - both are the "next" releases of Python oin their respective streams. But most of the existing documentation doesn't even cover the newer widgets added since 2.x - and none that I know of covers Tix at all. Still waiting for the wizard. There are lots of news readers around. Which OS are you on? There is also the web page which only requiires a browser, but the gmane archive is much easier accessed by a newsreader IMHO. February 03, 2009 Ttk support in Python. Guilherme Polo passed along the great news that his pyttk module has been accepted into Python's standard library. Â That means we should see pyttk generally available with Python 2.7 and 3.1 (both still in development). Â You can see the current docs here. Â And of course, this is something I was waiting for before updating TkDocs with Python info and examples. -- Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
Title: Signature.html If you can execute a C program compiled on a Linux with SWIG, then that's what I'm looking for. There's really no RH dependency according to the above posts. If it were compiled on Debian or Ubuntu, it appears it would not make any difference. That is, one could execute a RH executable from C on Ubuntu. Is there a simple example of this in action from a Python program and some small C Linux executable program? greg whittier wrote: On Wed, Mar 18, 2009 at 4:06 PM, Wayne Watson sierra_mtnv...@sbcglobal.net wrote: Thanks to both above posts before this reply. I'll forgo the VM route. It would really complicate things for the users of the application having to deal with VM. Most are near neophytes. Nevertheless, it looks like there may be some hope here for just doing it from w/i Win OS. My other choice is recoding 38K lines of C code into Python. I'll pass on that. :-) Unless there's a very good translator between languages. I'm confused about what you want to do. If you have the code and want to call it from python, then maybe you can use something like http://www.swig.org/ is what you're looking for. What is the Red Hat dependency? I.e., what libraries are needed? Many libraries are available for windows. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
Wayne Watson wrote: If you can execute a C program compiled on a Linux with SWIG, then that's what I'm looking for. There's really no RH dependency according to the above posts. If it were compiled on Debian or Ubuntu, it appears it would not make any difference. That is, one could execute a RH executable from C on Ubuntu. Yeah, probably -- if it's a static build, or if the dependencies (required libraries/versions) are installed, assuming the program has dependencies. But, I suppose we may be drifting a bit OT. Is there a simple example of this in action from a Python program and some small C Linux executable program? http://docs.python.org/library/subprocess.html The subprocess module is commonly recommended for this type of task (as opposed to os.system, etc). In fact, I believe Alan already suggested it in this thread. And speaking of ... Alan's tutorial has several very good examples of using the subprocess module (OS topic under Manipulating Processes). http://www.freenetpages.co.uk/hp/alan.gauld/tutos.htm --- I'll hazard a wild guess that you don't really want SWIG based on your original question, and subsequent comments. IIUC, SWIG is intended to ease the creation of a python wrapper (extension module) for existing C/C++ code. And, I'm not sure you've given enough information about the C program to determine if SWIG would be useful. Regardless, I suggest you get a feel for running an external program using python first. HTH, Marty ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor