Python tk Listbox: -listvariable class (on win XP)
I mentioned that I figured out how to use a variable with a Python TK Listbox in my post (http://www.mail-archive.com/python-list@python.org/msg271288.html). Now, I'm trying to make a class, ListVar, that allows me to operate on a Listbox's listvariable as if it were a list. The problem is, it doesn't work as expected some of the time. If I try to add a sequence of simple strings, it doesn't display anything. If I convert them to a tuple or instantiate a class (with __str__ defined), then it displays everything - the simple string, instances, tuples, everything. I don't understand why it won't show the simple strings, by themselves, in the Listbox. Notice - the spaces are important. I can make this work without as much of a headache my strings don't have spaces (which is what the 2 or 3 examples I've been able to find did), but spaces apparently makes this more complicated. Can anyone explain what's happening? I'm completely frustrated with trying to figure this out. Thanks, -JB Here is the simplest working code snippet I felt I could make: [code] import Tkinter, tkSimpleDialog class ListVar( Tkinter.Variable, list ): # Dual inheritance def __init__( self, master = None, *args, **kw ): Tkinter.Variable.__init__( self, master ) list.__init__( self, *args, **kw ) self.set( self ) # populate the Tk variable def get( self ): value = Tkinter.Variable.get( self ) if( isinstance( value, list ) ): return value return list( value ) def set( self, value ): if( isinstance( value, list ) ): value = tuple( value ) Tkinter.Variable.set( self, value ) def append( self, item ): list.append( self, item ), self.set( self ) # Class to wrap around a string and make a simple instance. class sillyString( object ): def __init__( self, s ): self.myString = s def __str__( self ): return self.myString # Dialog class to display a Listbox and test the ListVar class. class ListboxDialog( tkSimpleDialog.Dialog ): def __init__( self, master, listItems = [] ): self.myVar = ListVar( master, listItems ) # Initial set of the list tkSimpleDialog.Dialog.__init__( self, master, "Listbox testing" ) def body( self, master ): Tkinter.Listbox( master, listvariable = self.myVar, width = 50 ).grid() self.myVar.append( "appended string" ) # test append def __str__( self ): return "%s" % self.myVar.get() if( "__main__" == __name__ ): tk = Tkinter.Tk() tk.withdraw() # The spaces are important as my listbox will contain strings with spaces. # The print displays what's in the ListVar after the dialog exits print ListboxDialog( tk, '' ) # Simple String print ListboxDialog( tk, [ '' ] ) # list with empty string print ListboxDialog( tk, [ 'abc string' ] ) # list with short string print ListboxDialog( tk, [ sillyString( "instance 1" ) ] ) # class instance print ListboxDialog( tk, [ sillyString( "instance 1" ), sillyString( "instance 2" ) ] ) # 2 instances print ListboxDialog( tk, [ ( "A tuple", ), "A string" ] )# tuple and string [/code] -- http://mail.python.org/mailman/listinfo/python-list
Python tk Listbox: -listvariable
Yesterday, I searched all over trying to figure out how to properly use the "listvariable" argument with tk's Listbox class. Unfortunately, no amount of searching (online) could come up with anything more useful than telling me the variable needed to be a list, and nothing built-in exists. I finally came across a way of using it that I consider fairly simple, and wanted to toss it out there for everyone else. One post I saw mentioned using StringVar. That just didn't work well in my head, so instead I used its parent class: Variable. Apparently, the trick is to use tuples. If I use a list, string, etc - the Listbox seems to split the content based on spaces. Not the behavior I was looking for as I have spaces in the strings I wish to display. If anyone has better suggestions, I'd love to hear them. (I thought about a ListVar class, but haven't made it much beyond the thought). Regardless, I hope the following code helps others avoid the confusion I went through. Sample code: import Tkinter, tkSimpleDialog from Tkconstants import * class ListboxTest( tkSimpleDialog.Dialog ): # def __init__( self, master, tupleItems = () ): self.myVar = Tkinter.Variable() self.myVar.set( tupleItems ) tkSimpleDialog.Dialog.__init__( self, master, "Listbox testing" ) # def body( self, master ): lbox = Tkinter.Listbox( master, listvariable = self.myVar ) lbox.grid( row = 0, column = 0, sticky = N + W ) self.myVar.set( self.myVar.get() + tuple( [ "* Final string being added *" ] ) ) print type( self.myVar.get() ), self.myVar.get() if( "__main__" == __name__ ): tk = Tkinter.Tk() lt = ListboxTest( tk, tuple( [ "String 1 - with some spaces", "String 2 - with more spaces" ] ) ) -- http://mail.python.org/mailman/listinfo/python-list
Confused about error: invalid Python installation: unable to open ..../python2.4/config/Makefile
I built and installed Python 2.4 on 12/12/2007. Recently, I tried installing python-ldap-2.3.4. The error I received was: error: invalid Python installation: unable to open /usr/local/openSource/architectureIndependent:/usr/local/openSource/IRIX 6/lib/python2.4/config/Makefile (No such file or directory) I figured out what I believe to be the origin of this string. When I ran configure to build/install Python, I used the following: ./configure --prefix=/usr/local/openSource/architectureIndependent --exec-prefix=/usr/local/openSource/IRIX6 --enable-shared --without-gcc --with-cxx=CC Somewhere along the lines, the prefix and exec-prefix strings were joined with a ':'. I just went searching around, and found that sys.prefix = '', and sys.exec_prefix="/usr/local/openSource/architectureIndependent:/usr/loca l/openSource/IRIX6" In past posts, I've found people referring to needing to install python-devel, and I have no idea why installing an additional package would help the installation of other packages. Does anyone have any thoughts as to why I'm getting the error? How about thoughts on why the prefix and exec-prefix strings were joined? Thanks, -James -- http://mail.python.org/mailman/listinfo/python-list
Building Python2.4.1 with idle on HPUX11
I've been trying to build Python 2.4.1 on an HPUX11. Python builds ok, but idle has issues. And what I don't know is how to determine whether or not Python discovers the tcl/tk libraries (.sl) and headers, or if there's some other problem. If someone has thoughts on either how to invoke 'configure' or how to debug this issue, please let me know. I'm executing them from an HPUX directory (different for each one) to isolate the different platform's objects/libraries since I also build and run from IRIX646 and SunOS5 (both of which work find). Here's my configure lines: Tcl8.4.9: /bin/env SHLIB_LD_FLAGS=-fPIC /usr/local/openSource/off.the.net/www.tcl.tk/tcl8.4.9/unix/configure --prefix=/usr/local/openSource/architectureIndependent --exec-prefix=/usr/local/openSource/HPUX11; make; make install Tk8.4.9: /bin/env SHLIB_LD_FLAGS=-fPIC /usr/local/openSource/off.the.net/www.tcl.tk/tk8.4.9/unix/configure --with-tcl=/usr/local/openSource/off.the.net/www.tcl.tk/tcl8.4.9/unix/pl atforms/HPUX11 --prefix=/usr/local/openSource/architectureIndependent --exec-prefix=/usr/local/openSource/HPUX11; make; make install Python 2.4.1: ./configure --prefix=/lds/tools/openSource/mainline/architectureIndependant --exec-prefix=/lds/tools/openSource/mainline/HPUX11 --enable-shared; make; make install Thanks, -James -- http://mail.python.org/mailman/listinfo/python-list
Optimized Python bytecode
I'm using SCons to build all kinds of things, and part of our build process involves creating a "release" version of our software. In the case of Python, that means compiling the .py into a .pyc or .pyo. Because I'm placing the compiled script into a different location from the .py, I have to figure out myself whether to name the file a .pyc or a .pyo. So, how do I programatically (within Python) figure out if someone used the -O or -OO flags, without having access to the argv list? How about programatically (still within Python) setting those flags? -James -- http://mail.python.org/mailman/listinfo/python-list
RE: the annoying, verbose self
There are always tricks. If 5 characters is really too much to type, how about 2 characters "s.". Though I would recommend against that since it violates standard Python convention. def foo( self ): becomes def foo( s ): Otherwise, if you happen to be using self.something a lot, just assign it to a variable, and use that. But be careful as that can become a lot more difficult to read/maintain than simply leaving self along to begin with. ss = self.something ss.foo() To me, using 'self' in Python is no different than using some other variable pointing to a class instance in a static C++ class function. -James > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > ] On Behalf Of braver > Sent: Wednesday, November 21, 2007 4:52 PM > To: python-list@python.org > Subject: the annoying, verbose self > > Is there any trick to get rid of having to type the annoying, > character-eating "self." prefix everywhere in a class? Sometimes I > avoid OO just not to deal with its verbosity. In fact, I try to use > Ruby anywhere speed is not crucial especially for @ prefix is better- > looking than self. > > But things grow -- is there any metaprogramming tricks or whatnot we > can throw on the self? > > Cheers, > Alexy > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
RE: Writing Error in program
There could be any number of issues in your code that could cause that problem. Can you post some of the code in question? > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > ] On Behalf Of [EMAIL PROTECTED] > Sent: Tuesday, November 20, 2007 2:03 PM > To: python-list@python.org > Subject: Writing Error in program > > I have a code that writes to 2 seperate files. I keep getting a "list > index out of range" error. The strange part is that when checking the > files that I'm writing too, the script has already iterated through > and finished writing, yet the error stated implies that it hasn't? So > how can it be, that my script has written to the files, yet the error > is stating that it hasn't made it through the script? I'll have 15 > files that I have written to and the script will bog out at number > 10? Is python doing something I'm not seeing? I printed everything > that was written on the shell and it shows that it went through the > script, so how can it still say there are a few files left to iterate > through? > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
RE: formated local time
You could use: import time time.strftime( "%Y-%m-%d %H:%M:%S" ) or time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime() ) Output: '2007-11-15 11:02:34' Both strftime calls are equivalent, in this case. > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > ] On Behalf Of Nikola Skoric > Sent: Thursday, November 15, 2007 8:20 AM > To: python-list@python.org > Subject: formated local time > > I have been trying to find appropriate way to do get local time in > "-mm-dd hh:mm:ss" format, but the best I got is this: > datetime.datetime.fromtimestamp(time.mktime(time.localtime())) > It seems to me I'm missing a much simpler method, am I? > > -- > "Now the storm has passed over me > I'm left to drift on a dead calm sea > And watch her forever through the cracks in the beams > Nailed across the doorways of the bedrooms of my dreams" > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
RE: global name is not defined
Looks like you forgot to import EMR_globals, EMR_main, etc. > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > ] On Behalf Of barronmo > Sent: Tuesday, November 06, 2007 2:57 PM > To: python-list@python.org > Subject: global name is not defined > > I'm getting an error msg I don't understand, "global name EMR_globals > is not defined", and could use some help. > > I've separated the application I'm building into several modules. One > of the modules holds variables I need to pass from one module to > another and is called 'EMR_globals'. Several other modules hold > functions or user menus and then 'EMR_main' controls the initial user > interaction. I'm using MySQL to hold the data. > > The initial connection to the database is done by 'EMR_main'. > Functions then define and close a cursor for various queries. The > connection variable, 'conn', is defined 'conn = "" ' in EMR_globals > and then used in EMR_main. Unfortunately when a module.function > attempts to use it I get the error msg. > > Here is the source of the error, module 'name_lookup': > > def name_find(namefrag): > > cursor = EMR_globals.conn.cursor(MySQLdb.cursors.DictCursor) > cursor.execute("SELECT patient_ID, firstname, lastname FROM > demographics WHERE lastname LIKE '%s%%'" % (namefrag)) > > results = cursor.fetchall() > > for index, row in enumerate(results): > print "%d %s %s %s" % (index, row["patient_ID"], > row["firstname"], row["lastname"]) > > indx = int(raw_input("Select the record you want: ")) > results_list = list(results) > a = str(results_list[indx]['patient_ID']) > print 'You have chosen patient ID # ' + a > > cursor.execute("SELECT * FROM demographics WHERE patient_ID = %s" > % (a,)) > selected_pt = cursor.fetchall() > # if this query returns more than one record the following code will > fail I think > print menus.menu_demographics(selected_pt['firstname'], > selected_pt['lastname'], > selected_pt['address'], > selected_pt['city'], > selected_pt['state'], > selected_pt['zipcode'], > selected_pt['phonenumber']) > print menus.menu_pt_record > > cursor.close() > > > Thanks for any help. Mike > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
RE: shouldn't 'string'.find('ugh') return 0, not -1 ?
I believe most programming languages evaluate 0 to mean False, and anything else to be True (for the purposes of boolean evaluation). Python is no exception. From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of jelle feringa Sent: Wednesday, October 31, 2007 8:56 AM To: Luis Zarrabeitia Cc: python-list@python.org Subject: Re: shouldn't 'string'.find('ugh') return 0, not -1 ? There is a subtle point though. If the substring is not found '_'.find(' '), will return -1 Semanticly, I was expecting the that if the substring was not found, the conditional statement would not be found. However, python evaluates -1 to True, so that is what I do find confusing. So, I was arguing that '_'.find(' ') might return 0, however that is obviously ambigious, since 0 might be an index as well. So, perhaps I should rephrase and ask, why if -1 evaluates to True? I think that's pretty ugly... cheers, -jelle -- http://mail.python.org/mailman/listinfo/python-list
Python equivalent to *nix 'banner' problem
<> I have written a Python script to duplicate the 'banner' program from IRIX. Attached is the generated data file. This data is generated the first time by using 'banner' on my IRIX machine. Thereafter, the data is simply used (and can be run from anywhere). The data is a marshaled copy of the characters generated by 'banner'. Regardless of whether I run this from IRIX or Windows, I get the same results. I'm expecting the string "ab" to be displayed twice. Instead, the second time, I get ABB. If I add a 3rd print line, I'll get ABBB. I'm now stuck trying to understand what's going on. It seems like there's an overflow somewhere since it's overwriting my dictionary for the letter 'a', but I don't know how it's doing it. Does anyone see the problem, or have suggestions on how to fix it? Thanks, -JB H:\play\python\banner>Banner.py ab ## # # # ## ## # ## ## ## ## ## # ## # # # # ## ## ## # # ## ## ## ## ## ## ## # # #!/bin/env /usr/local/openSource/bin/python import os, sys, marshal from pprint import pprint class Banner: ourDataFile = "banner.dat" ourDataPath = '.' + os.sep if( 0 <= __file__.rfind( os.sep ) ): ourDataPath = __file__.rsplit( os.sep, 1 )[ 0 ] + os.sep def __init__( self ): self.myBannerDict = {} if( False == os.path.exists( Banner.ourDataPath + Banner.ourDataFile ) ): print "Having to create data file for the first time. This will take longer than normal." self.createBannerMarshal() f = open( Banner.ourDataPath + Banner.ourDataFile, 'rb' ) self.myBannerDict = marshal.load( f ) f.close() def getTotalLength( self, letterList ): totalLength = 0 for line in letterList: totalLength += len( line.strip( os.linesep ) ) return totalLength def createBannerMarshal( self ): # Create my list of all allowed ASCII characters. for i in range( 32, 127 ): c = chr( i ) self.myBannerDict[ c ] = os.popen( "banner '%s'" % c ).readlines() # Catch any of the shell specific guys that the shell didn't like. if( 0 == self.getTotalLength( self.myBannerDict[ c ] ) ): self.myBannerDict[ c ] = os.popen( 'banner "%s"' % c ).readlines() length = 0 prependSpace = "" for j in range( len( self.myBannerDict[ c ] ) ): self.myBannerDict[ c ][ j ] = self.myBannerDict[ c ][ j ].strip( os.linesep ) if( length < len( self.myBannerDict[ c ][ j ] ) ): length = len( self.myBannerDict[ c ][ j ] ) if( 0 == self.myBannerDict[ c ][ j ].find( '#' ) ): prependSpace = " " if( 0 == length ): length = 8 for j in range( len( self.myBannerDict[ c ] ) ): self.myBannerDict[ c ][ j ] = "%s%-*s" % ( prependSpace, length, self.myBannerDict[ c ][ j ] ) f = open( Banner.ourDataPath + Banner.ourDataFile, 'wb' ) marshal.dump( self.myBannerDict, f ) f.close() def getBanner( self, inputStr ): retVal = [] for c in inputStr: banneredCharList = self.myBannerDict[ c ] if( 0 == len( retVal ) ): retVal = banneredCharList else: for i in range( len( banneredCharList ) ): retVal[ i ] += banneredCharList[ i ] return os.linesep.join( retVal ) if( "__main__" == __name__ ): banner = Banner() print 40 * '-' + os.linesep + banner.getBanner( sys.argv[ 1 ] ) + os.linesep + 40 * '-' print 40 * '-' + os.linesep + banner.getBanner( sys.argv[ 1 ] ) + os.linesep + 40 * '-' #print 40 * '-' + os.linesep + banner.getBanner( sys.argv[ 1 ] ) + os.linesep + 40 * '-' banner.dat Description: banner.dat -- http://mail.python.org/mailman/listinfo/python-list
Manipulating raw data in Python
How do I get access to a data buffer in Python so that I can directly view/modify the data? My buffer size is 256 (for this specific case) bytes. Most of the time, I access want to access that data in 4-byte chunks, sometimes in single byte chunks. How do I go about doing so? I'm certain someone's come across (and has probably asked this question a few times). I've tried various searches, and I'm either missing the obvious, or am not using the right key words to get what I'm looking for. I mostly get back results about audio, files, etc. In my case, I'm using an HDLC protocol. A little background: I've got a socket connection. On the server side is C++ code. On the client (Python) side, I have a SWIG-ified C++ extension. The extension is my messaging API, so that I can interact with the socket in a known manner on both sides of the connection. In C++, I'd usually just use a method like "char *getBuffer()". However, Python seems to want to treat this as a string even though it really isn't. I usually only get a few bytes before Python encounters data which looks like a NULL. Any help is appreciated. Thanks, -JB -- http://mail.python.org/mailman/listinfo/python-list
Client -> web server communication
I'm trying to understand how to write an app that runs on my local machine, and talks to a hosted website to get access to the MySQL database I have stored there. I've read a few articles on Basic Authentication, so at least that part I partially understand (I plan on having username/password pairs to access the data). What I'm really fuzzy on is how I actually communicate with the website. I suppose the real question is what is the interface I need to use in order to talk between my local client and the website? Generate HTML pages containing the data I want? Can I use my own messaging scheme to pass databuffers back and forth? I've tried searching for this in the mailing list and elsewhere, but don't think I'm hitting on the right key words to get the information I'm looking for. Could anyone direct me to a possible answer? Thanks, -JB Looney -- http://mail.python.org/mailman/listinfo/python-list
RE: DFW Pythoneers Meeting THIS Saturday
Short answer: DFW = Dallas-Fort Worth Longer answer: I'm not pointing fingers or making opinions, I just wanted to point out that after reading Jeff's original email (in its entirity), I found: Jeff wrote: > at the usual location of Nerdbooks.com bookstore in Richardson. For So, after looking at Nerdbooks.com, they're in Richardson, TX. http://maps.google.com/maps?f=q&hl=en&q=1681+Firman+Drive,+richardson,+t x&sll=37.0625,-95.677071&sspn=31.371289,59.765625&ie=UTF8&ll=32.876127,- 96.792297&spn=0.259504,0.466919&z=11&om=1 > By the way, I've been contacted by a developer at the Travelocity Dallas > office, who is looking for local Python developers with experience in Django > or Genshi. If you're interested, let me know and I can put you in touch. Otherwise, after reading to this point in his email (and not knowing what DFW was), I'd guess that they're near Dallas. > -Original Message- > Subject: Re: DFW Pythoneers Meeting THIS Saturday > > > Precisely what? You complained that the OP didn't provide > the location > > of the event, which he did. > > Well, where is DFW? > -- > -- http://mail.python.org/mailman/listinfo/python-list
RE: Please help on Binary file manipulation
Pieter, I've found when I have questions like this, that thinking about how I'd do it in C/C++, then searching on some of those key words leads me to a Python equivalent solution, or at least heading down the right path. In this case, I believe you'll find the "file" module helpfull. You can read/seek on a number of bytes. I don't know how you'd do the playback specifically, but my guess is you'll use a loop to create new files, so use a similar loop for playback. -JB From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Pieter Potgieter Sent: Tuesday, June 05, 2007 2:43 AM To: python-list@python.org Subject: Please help on Binary file manipulation Hi all I have a binary file of about 600kbytes - I want to break it up in file chunks of 1085 bytes - every file must have a new file name. The data is binary video frames (370 frames) - I want to play the data back into an embedded system frame/file by file. I am a complete Python newby - but have C/C++ skills. Please supply/help me with an snippet or example Thanks Pieter *** Disclaimer: The information contained in this communication is confidential and may be legally privileged. It is intended solely for the use of the individual or entity to whom it is addressed and others authorised to receive it. Any review, retransmission, dissemination, copying, disclosure or other use of, or taking of any action in reliance upon, this information by person or entities other then the intended recipient is prohibited. If you have received this message in error, please notify the sender immediately by e-mail, facsimile or telephone and return and/or destroy the original message and all copies from any computer. Denel (Pty) Ltd exercises no editorial control over e-mail messages originating in the organisation and does not accept any responsibility for either the contents of the message or any copyright laws that may have been violated by the person sending this message. Denel (Pty) Ltd is neither liable for the proper and complete transmission of the information contained in this communication nor any delay in its receipt. This message should not be copied or used for any purpose other than intended, nor should it be disclosed to any other person. *** -- http://mail.python.org/mailman/listinfo/python-list
RE: os.listdir() doesn't work ??
The case sensitivity has to do with the OS you're on. So, using glob from Un*x is case sensitive, but from Windows it isn't. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Stef Mientki Sent: Monday, May 14, 2007 3:39 PM To: python-list@python.org Subject: Re: os.listdir() doesn't work ?? Michel Claveau wrote: > Hi! > > >> You want the glob module > > Warning: glob has "unix like behavior"; just a little different with > windows's DIR Don't know the details of "Unix" but I thought "unix" was case-sensitive, and glob.glob doesn't seem to be, at least not on windows systems ;-) cheers, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: preferred windows text editor?
I'm using Vim (http://www.vim.org/). -JB -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of T. Crane Sent: Wednesday, May 09, 2007 12:07 PM To: python-list@python.org Subject: preferred windows text editor? Right now I'm using Notepad++. What are other people using? trevis -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Using os.popen and os.chdir together
ok, nevermind. My coworker pointed out part of what's wrong. Guess I'll need to do more spelunking in my script to figure out what I'm messing up. -JB From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Looney, James B Sent: Tuesday, May 08, 2007 4:17 PM To: python-list@python.org Subject: Using os.popen and os.chdir together Within a script on a *nix machine, I use os.chdir then os.popen, and it appears to me as though the os.chdir had no effect so far as the os.popen is concerned. Why's that? Here's what I'm doing: >>> import os >>> os.path.realpath( os.curdir ) '/home/jlooney' >>> print os.popen( "echo $PWD" ).readlines() ['/home/jlooney\n'] >>> >>> os.chdir( "/tmp" ) >>> os.path.realpath( os.curdir ) '/tmp' >>> print os.popen( "echo $PWD" ).readlines() ['/home/jlooney\n'] >>> You'll notice that initially, the current paths are the same, and correct. After I call os.chdir, and try os.popen, it's not in the new directory. When I do other things like creating new files, the chdir did exactly what I expected. What I don't understand is why os.popen appears to be special? How do I change directories within a script and have popen see that change? -JB -- http://mail.python.org/mailman/listinfo/python-list
Using os.popen and os.chdir together
Within a script on a *nix machine, I use os.chdir then os.popen, and it appears to me as though the os.chdir had no effect so far as the os.popen is concerned. Why's that? Here's what I'm doing: >>> import os >>> os.path.realpath( os.curdir ) '/home/jlooney' >>> print os.popen( "echo $PWD" ).readlines() ['/home/jlooney\n'] >>> >>> os.chdir( "/tmp" ) >>> os.path.realpath( os.curdir ) '/tmp' >>> print os.popen( "echo $PWD" ).readlines() ['/home/jlooney\n'] >>> You'll notice that initially, the current paths are the same, and correct. After I call os.chdir, and try os.popen, it's not in the new directory. When I do other things like creating new files, the chdir did exactly what I expected. What I don't understand is why os.popen appears to be special? How do I change directories within a script and have popen see that change? -JB -- http://mail.python.org/mailman/listinfo/python-list