Jose' Matos wrote:
>> Yes, but it would be more elegant still if I could save the stream
>> rather than convert it to a list. Is that possible?
>
> Use *read* instead of *readlines*:
Bingo! Thank you.
--
Angus
On Thursday 15 April 2004 18:36, Angus Leeming wrote:
>
> Yes, but it would be more elegant still if I could save the stream
> rather than convert it to a list. Is that possible?
Notice that you can get information easily from inside a python
interpreter:
* import sys
* we know
On Thursday 15 April 2004 18:36, Angus Leeming wrote:
> > Elegant, isn't it? ;-)
>
> Yes, but it would be more elegant still if I could save the stream
> rather than convert it to a list. Is that possible?
Use *read* instead of *readlines*:
read(...)
read([size]) -> read at most size byte
Jose' Matos wrote:
>> def run_command(cmd):
>> handle = os.popen(cmd, 'r')
>> cmd_stdout = ""
> This is unnecessary, as you overwrite it bellow.
Good point.
>> cmd_stdout = string.join(handle.readlines())
>> cmd_status = handle.close()
>>
>> return cmd_status, cmd_stdout
>
On Thursday 15 April 2004 13:31, Angus Leeming wrote:
> Angus Leeming wrote:
> > Any clues?
>
> Answering myself again (bad habit, I know)...
>
> def run_command(cmd):
> handle = os.popen(cmd, 'r')
> cmd_stdout = ""
This is unnecessary, as you overwrite it bellow.
> cmd_stdout = st
Angus Leeming wrote:
> Any clues?
Answering myself again (bad habit, I know)...
def run_command(cmd):
handle = os.popen(cmd, 'r')
cmd_stdout = ""
cmd_stdout = string.join(handle.readlines())
cmd_status = handle.close()
return cmd_status, cmd_stdout
--
Angus
Jose,
what's the recommended way to grab the stdout from an external program
(here dvipng)? dvipng outputs this to stdout:
This is dvipng 1.0 Copyright 2002-2004 Jan-?e Larsson
[1 depth=1 height=8] [2 depth=5 height=14] [3 depth=5 height=14] [4
depth=5 height=14] [5 depth=4 height=13] [6 depth=4
Jose' Matos wrote:
>> red = float(atoi(hexcolor[0:2], 16)) / 255.0
>> green = float(atoi(hexcolor[2:4], 16)) / 255.0
>> blue = float(atoi(hexcolor[4:6], 16)) / 255.0
>
> This is correct but unnecessary, either
> float(atoi(hexcolor[0:2], 16)) / 255
> or
> atoi(hexcolor[0:2], 16) / 255.0
>
> wo
Jose' Matos wrote:
>> One small inconvinience that I still don't know how to overcome,
>> I will test if the program exists in the path not if it is
>> executable. I will try to search a generic way to test this...
>
> From the manual pages I guess this should work:
> if os.access(full_p
On Wednesday 14 April 2004 14:37, Angus Leeming wrote:
> Thanks, Jose.
>
> I have an 'almost finished' python script, attached. Would you mind
> casting a look over it and telling me how to improve it?
OK.
> I'd like to write a little function to loop over a list of 'possible'
> names (lib/conf
On Wednesday 14 April 2004 15:39, Jose' Matos wrote:
>
> One small inconvinience that I still don't know how to overcome, I
> will test if the program exists in the path not if it is executable.
> I will try to search a generic way to test this...
From the manual pages I guess this should work
On Wednesday 14 April 2004 14:37, Angus Leeming wrote:
> One thing I don't know how to do:
> # Ascertain whether the latex and dvipng
> # executables are available.
> latex = "latex"
> dvipng = "dvipng"
>
> I'd like to write a little function to loop over a list of 'possible'
> name
Jose' Matos wrote:
>> I'm trying to write 'lyxpreview2png.py', to be used by lyx to
>> generate previews using dvipng. What versions of python do we
>> support? (Should I go use 'atoi' or do it the 'int' way?)
>
>We support 1.5.2, so to be on the compatible side 'atoi' is the
>way to go.
On Wednesday 14 April 2004 13:07, Angus Leeming wrote:
> Jose' Matos wrote:
>
> I'm trying to write 'lyxpreview2png.py', to be used by lyx to
> generate previews using dvipng. What versions of python do we
> support? (Should I go use 'atoi' or do it the 'int' way?)
We support 1.5.2, so to be on
Jose' Matos wrote:
> Note that for python versions starting from 2.0 then
>
> int( hex_str, 16)
>
> is enough where hex_str is the string with the hexadecimal
> representation of the number, and *int* is a built-in function, so
> no need to import any module for it.
I'm trying to write 'lyxpre
On Wednesday 14 April 2004 12:12, Angus Leeming wrote:
> Angus Leeming wrote:
> > I've started writing the equivalent in python (also attached), but
> > wonder if there is a simple way of extracting a substring 'fa' and
> > converting it to the equivalent decimal number '250'?
>
> Ok, got it.
Yo
Angus Leeming wrote:
> I've started writing the equivalent in python (also attached), but
> wonder if there is a simple way of extracting a substring 'fa' and
> converting it to the equivalent decimal number '250'?
Ok, got it.
#! /usr/bin/env python
import re, sys
from string import atoi
hexco
17 matches
Mail list logo