Re: How to get output of command called by os.system()?
On Oct 30, 11:09 pm, Peng Yu wrote: > I need to integrate shell program with python. I'm wondering if there > is a way get the output of the shell program called by os.system(). > Thank you! popen should do what your after. There are several modules that have a popen method including os and subprocess. It will allow you to make a system call similar to os.system, but it gives you pipe access, like an open file, to the standard output and standard error if you use subprocess.Popen. A simple example would be: import subprocess output = subprocess.Popen('pwd') print('Present Working Directory is: ' + output.readline()) Hope that helps. -John -- http://mail.python.org/mailman/listinfo/python-list
Re: getting object instead of string from dir()
On Dec 17, 1:21 pm, Jean-Paul Calderone wrote: > On Wed, 17 Dec 2008 11:52:17 -0800 (PST), Rominsky > wrote: > >On Dec 17, 10:59 am, Christian Heimes wrote: > >> Rominsky schrieb: > > >> > I am trying to use dir to generate a list of methods, variables, etc. > >> > I would like to be able to go through the list and seperate the > >> > objects by type using the type() command, but the dir command returns > >> > a list of strings. When I ask for the type of an element, the answer > >> > is always string. How do I point at the variables themselves. A > >> > quick example is: > > >> > a = 5 > >> > b = 2.0 > >> > c = 'c' > > >> > lst = dir() > > >> > for el in lst: > >> > print type(el) > > >> for name, obj in vars().iteritems(): > >> print name, obj > > >> Christian > > >I do have some understanding of the pythonic methodology of > >programming, though by far I still don't consider myself an expert. > >The problem at hand is that I am coming from a matlab world and trying > >to drag my coworkers with me. I have gotten a lot of them excited > >about using python for this work, but the biggest gripe everytime is > >they want their matlab ide. I am trying to experiment with making > >similar pieces of the ide, in particular I am working on the workspace > >window which lists all the current variables in the namespace, along > >with their type, size, value, etc I am trying to create a python > >equivalent. I can get dir to list all the variables names in a list > >of strings, but I am trying to get more info them. hence the desire > >to do a type command on them. I like the locals and globals commands, > >but I am still trying to get more info. I have started using the eval > >command with the strings, which is working, but I am curious if there > >is a better or more elegant way of getting the info. The eval example > >would be something like: > > >a = 5 > >b = 2.0 > >c = 'c' > > >lst = dir() > > >for el in lst: > > print el + '\t' + str(eval('type(%s)'%el)) > > >It works, now I am curious if there is a better way. > > What about this: > > >> for name, obj in vars().iteritems(): > >> print name, obj > > >> Christian > > Jean-Paul vars seems to give an identical response as locals and globals, at least in my test name space. All three are new commands for me. I like the idea of adopting either vars or locals instead of dir as it sets up the value for me to use. I will play with them both a little more and read up on them to learn there uses and limitations. The key step for me is still to be able to automatically query the key names from vars or locals for what type the variable is. In my previous post I discussed using eval and the string in the key name such as eval('type(%s)'%vars().keys()[0]) I definitely have enough to move forward. Thanks everyone. If anyone has any other ideas I would still be interested in learning more. Thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Re: getting object instead of string from dir()
On Dec 17, 10:59 am, Christian Heimes wrote: > Rominsky schrieb: > > > I am trying to use dir to generate a list of methods, variables, etc. > > I would like to be able to go through the list and seperate the > > objects by type using the type() command, but the dir command returns > > a list of strings. When I ask for the type of an element, the answer > > is always string. How do I point at the variables themselves. A > > quick example is: > > > a = 5 > > b = 2.0 > > c = 'c' > > > lst = dir() > > > for el in lst: > > print type(el) > > for name, obj in vars().iteritems(): > print name, obj > > Christian I do have some understanding of the pythonic methodology of programming, though by far I still don't consider myself an expert. The problem at hand is that I am coming from a matlab world and trying to drag my coworkers with me. I have gotten a lot of them excited about using python for this work, but the biggest gripe everytime is they want their matlab ide. I am trying to experiment with making similar pieces of the ide, in particular I am working on the workspace window which lists all the current variables in the namespace, along with their type, size, value, etc I am trying to create a python equivalent. I can get dir to list all the variables names in a list of strings, but I am trying to get more info them. hence the desire to do a type command on them. I like the locals and globals commands, but I am still trying to get more info. I have started using the eval command with the strings, which is working, but I am curious if there is a better or more elegant way of getting the info. The eval example would be something like: a = 5 b = 2.0 c = 'c' lst = dir() for el in lst: print el + '\t' + str(eval('type(%s)'%el)) It works, now I am curious if there is a better way. -- http://mail.python.org/mailman/listinfo/python-list
getting object instead of string from dir()
I am trying to use dir to generate a list of methods, variables, etc. I would like to be able to go through the list and seperate the objects by type using the type() command, but the dir command returns a list of strings. When I ask for the type of an element, the answer is always string. How do I point at the variables themselves. A quick example is: a = 5 b = 2.0 c = 'c' lst = dir() for el in lst: print type(el) Right now I am understandably getting all types being output as strings, how do i get the type of the actual objects returned from dir ()? -- http://mail.python.org/mailman/listinfo/python-list
matplotlib fill command on axes plot problem
I am trying to use the fill command to draw a box around an object in an image. I can get the box drawn, but there seems to be a side effect. The fill command is adding white lines to the top and sometimes right side of my axes plots. I am using small images, 124x200, and after the fill command the axes plot is changed to 140x200, with the top 16 lines being all white. I am running it in interactive mode from the python command line. Here is code that reproduces the problem. from pylab import * im_array = zeros((124,200)) ion() figure() imshow(im_array) hold(True) x=40 y=40 fill([x-5,x+5,x+5,x-5],[y+5,y+5,y-5,y-5],ec='r', fill = False) hold(False) Any thoughts on what I might be doing wrong? -- http://mail.python.org/mailman/listinfo/python-list