access __doc__ from within function without reference to function name

2007-10-02 Thread SanPy
The subject of this message might be a little cryptic, so here's an
example of what I mean:

def foo():
"""doc string of foo"""
print foo.__doc__

>>> foo()
doc string of foo

What I want to know is whether it is possible to call __doc__ against
some builtin method, like __func__ or something like that. So calling
__doc__ without the functions name, something like this:

def foo():
"""doc string of foo"""
print __func__.__doc__ # pseudo code

So basically, my question is: is there a way to access a function from
within itself without using its name?

Regards, Sander.

-- 
http://mail.python.org/mailman/listinfo/python-list


python command-line interface for GitHub Issues v2

2009-04-29 Thread SanPy
Hi,

For those of you that are using GitHub, you might want to check out a
package that
I've written in Python. It is a command-line interface to the recently
released GitHub Issues API v2.

You can find it here:
http://github.com/jsmits/github-cli

Here are some examples of what you can do:
ghi list [-s open|closed|all] # show open, closed or all
issues (default: open)
ghi [-s o|c|a] -v # same as above, but with issue
details
ghi   # same as: ghi list
ghi -v# same as: ghi list -v
ghi -v | less # pipe through less command
ghi [-s o|c] -w   # show issues' GitHub page in
web browser (default: open)
ghi show  # show issue 
ghi   # same as: ghi show 
ghi  -w   # show issue 's GitHub page
in web browser
ghi open  # create a new issue (with
$EDITOR)
ghi close # close issue 
ghi reopen# reopen issue 
ghi edit  # edit issue  (with $EDITOR)
ghi label add  # add  to issue 
ghi label remove   # remove  from issue 
ghi search  [-s open|closed]# search for  in open or
closed issues (default: open)
ghi search  [-s o|c] -v # same as above, but with
details
ghi comment   # create a comment for issue
 (with $EDITOR)
ghi -r /  # specify a repository (can be
used for all commands)
ghi -r  # specify a repository (gets
user from global git config)

Regards,
Sander Smits
--
http://mail.python.org/mailman/listinfo/python-list


writing consecutive data to subprocess command 'more'

2009-05-02 Thread SanPy
I have this method that prints a given text via a subprocess command
'more' . It is like this:

def print_by_page(text):
if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
viewer = 'more -EMR'
proc = subprocess.Popen([viewer], shell=True,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
try:
stdout, stderr = proc.communicate(text)
except OSError:
pass
else:
if stderr: # probably no 'more' available on this system
sys.stdout.write(text)
return
sys.stdout.write(text)

It works fine, but what I really want to do is first print a header
through the 'more' command, then fetch some data from the web, and
show it through the same 'more' command/process. And even more data,
another header, other data from the web, all through the same 'more'
command/process.
Can somebody help me out on this?

Regards,

Sander Smits
--
http://mail.python.org/mailman/listinfo/python-list


Re: writing consecutive data to subprocess command 'more'

2009-05-02 Thread SanPy
Thanks, that works beautifully!

Regards,
Sander

On 2 mei, 22:35, "Gabriel Genellina"  wrote:
> En Sat, 02 May 2009 15:53:17 -0300, SanPy  escribió:
>
>
>
>
>
> > I have this method that prints a given text via a subprocess command
> > 'more' . It is like this:
>
> > def print_by_page(text):
> >     if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
> >         viewer = 'more -EMR'
> >         proc = subprocess.Popen([viewer], shell=True,
> > stdin=subprocess.PIPE,
> >             stderr=subprocess.PIPE)
> >         try:
> >             stdout, stderr = proc.communicate(text)
> >         except OSError:
> >             pass
> >         else:
> >             if stderr: # probably no 'more' available on this system
> >                 sys.stdout.write(text)
> >             return
> >     sys.stdout.write(text)
>
> > It works fine, but what I really want to do is first print a header
> > through the 'more' command, then fetch some data from the web, and
> > show it through the same 'more' command/process. And even more data,
> > another header, other data from the web, all through the same 'more'
> > command/process.
> > Can somebody help me out on this?
>
> communicate writes to the child's stdin and waits for it to finish. If you  
> want to keep writing, don't use communicate. And you'll need to keep state  
>  from one call to another, so use a class. Based on the code above, create  
> a class Pager with __init__, write and close methods:
>
> class Pager:
>   def __init__(self):
>    # copy the logic above
>    self.proc = subprocess.Popen(...)
>    self.file = self.proc.stdin
>    # if something goes wrong, set self.proc=None and self.file=sys.stdout
>
>   def write(self, text):
>    self.file.write(text)
>
>   def close(self):
>    if self.proc:
>     self.file.close()
>     self.proc.wait()
>
> Also, take a look at the pager function in the pydoc module (see the  
> source) - it handles several cases.
>
> --
> Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: writing consecutive data to subprocess command 'more'

2009-05-03 Thread SanPy
Hmm, it works as long as the pager command is available on the system.
I created a test file to explain what I mean. You can find it here:
http://gist.github.com/105880

The 'pager' command is on purpose a command that is not available on
the system.
It should fall back to sys.stdout in the write method. However, it
does not show any output at all.
Strangely enough, when a put a time.sleep(1) between the first and
second printer.write statements, the second and third statement do
appear.
Btw, the normal pager command works fine on my system.
How can I solve this, so that the fallback sys.stdout does show
output?
---
Sander

On 2 mei, 23:00, SanPy  wrote:
> Thanks, that works beautifully!
>
> Regards,
> Sander
>
> On 2 mei, 22:35, "Gabriel Genellina"  wrote:
>
> > communicate writes to the child's stdin and waits for it to finish. If you  
> > want to keep writing, don't use communicate. And you'll need to keep state  
> >  from one call to another, so use a class. Based on the code above, create  
> > a class Pager with __init__, write and close methods:
>
> > class Pager:
> >   def __init__(self):
> >    # copy the logic above
> >    self.proc = subprocess.Popen(...)
> >    self.file = self.proc.stdin
> >    # if something goes wrong, set self.proc=None and self.file=sys.stdout
>
> >   def write(self, text):
> >    self.file.write(text)
>
> >   def close(self):
> >    if self.proc:
> >     self.file.close()
> >     self.proc.wait()
>
> > Also, take a look at the pager function in the pydoc module (see the  
> > source) - it handles several cases.
>
> > --
> > Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list