Re: Best way to delimit a list?

2008-05-14 Thread castironpi
On May 13, 11:25 pm, Dennis Lee Bieber [EMAIL PROTECTED] wrote:
 On Tue, 13 May 2008 04:14:16 -0700 (PDT), [EMAIL PROTECTED]
 declaimed the following in comp.lang.python:

  So f is a list, rather than a file object, of which os.open would have
  returned (my initial typo redirected the missive of this post, sorry!)

         Other than the facet that os.open() is low-level C file object and
 not a Python file object...

         What you have returned is a list of lines... Hmmm, if os.popen()
 supports .readlines() it might even support direct iteration

 for ln in os.popen():
         do something with the line

         Now the matter comes down to what each line looks like... It is NOT
 a list in Python terms, no matter what delimiters it has (and one of
 your examples doesn't even seem to be consistant -- ['  ]' is not
 the same as ['  '] )

         For space separated hostnames

 for ln in os.popen(...):        #assuming it works without a preread
         for host in ln.split():
                 do something with host...
 --
         Wulfraed        Dennis Lee Bieber               KD6MOG
         [EMAIL PROTECTED]               [EMAIL PROTECTED]
                 HTTP://wlfraed.home.netcom.com/
         (Bestiaria Support Staff:               [EMAIL PROTECTED])
                 HTTP://www.bestiaria.com/

Compositions can't have names in the singular case.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to delimit a list?

2008-05-13 Thread castironpi
On May 13, 5:28 am, [EMAIL PROTECTED] wrote:
 Hi - I have a list returned from popen/readlines, and am wondering how
 to go about iterating over each item which was returned (rather than
 currently having the whole lot returned).

 so far:

  f=os.open(./get_hostnames).readlines

 returns ['host1 host2 host3 ... hostN\n]'

 i'd like to be in a position to iterate through these, grabbing each
 host.  I have played with transmuting to a str, and using split, and
 this works, but I get the subscript brackets from the list output as
 expected, as the list output is now a string literal, and this is not
 what I want - and I think it's a bit long-winded to do a search 'n
 replace on it - hence why I ask in the subject what's the best way.

  f=str(f)
  f.split()

 [['host1,host2, ... ,hostN\n']]

 Any help is highly appreciated

 ta

 dan.

Bring up the Google Ring.  Where you only wiggle fingers, it might pay
to get jobs at home.  All we up here would have to do would be
schedule something.  Make a decision is easy in talking.  I think it
would be easy to centralize the time the world's at and redistribute
money.  If all we'd do is normal life, this constrained, open markets
would be easy to set up.  It's just illegal to talk about pricing in
2004 Microecon. classes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to delimit a list?

2008-05-13 Thread dannywebster
On May 13, 11:28 am, [EMAIL PROTECTED] wrote:
 Hi - I have a list returned from popen/readlines, and am wondering how
 to go about iterating over each item which was returned (rather than
 currently having the whole lot returned).

 so far:

  f=os.open(./get_hostnames).readlines

 returns ['host1 host2 host3 ... hostN\n]'

 i'd like to be in a position to iterate through these, grabbing each
 host.  I have played with transmuting to a str, and using split, and
 this works, but I get the subscript brackets from the list output as
 expected, as the list output is now a string literal, and this is not
 what I want - and I think it's a bit long-winded to do a search 'n
 replace on it - hence why I ask in the subject what's the best way.

  f=str(f)
  f.split()

 [['host1,host2, ... ,hostN\n']]

 Any help is highly appreciated

 ta

 dan.

I did indeed mean os.popen, no os.open

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


Best way to delimit a list?

2008-05-13 Thread dannywebster
Hi - I have a list returned from popen/readlines, and am wondering how
to go about iterating over each item which was returned (rather than
currently having the whole lot returned).

so far:

 f=os.open(./get_hostnames).readlines

returns ['host1 host2 host3 ... hostN\n]'

i'd like to be in a position to iterate through these, grabbing each
host.  I have played with transmuting to a str, and using split, and
this works, but I get the subscript brackets from the list output as
expected, as the list output is now a string literal, and this is not
what I want - and I think it's a bit long-winded to do a search 'n
replace on it - hence why I ask in the subject what's the best way.

 f=str(f)
 f.split()
[['host1,host2, ... ,hostN\n']]


Any help is highly appreciated

ta

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


Re: Best way to delimit a list?

2008-05-13 Thread Gabriel Genellina

En Tue, 13 May 2008 07:28:03 -0300, [EMAIL PROTECTED] escribió:


Hi - I have a list returned from popen/readlines, and am wondering how
to go about iterating over each item which was returned (rather than
currently having the whole lot returned).

so far:


f=os.open(./get_hostnames).readlines


returns ['host1 host2 host3 ... hostN\n]'


You meant readlines(), I presume. A file acts as its own iterator:

f=os.open(./get_hostnames)
try:
  for line in f:
# do something with line
finally:
  f.close()

--
Gabriel Genellina

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


Re: Best way to delimit a list?

2008-05-13 Thread castironpi
On May 13, 5:46 am, [EMAIL PROTECTED] wrote:
 On May 13, 11:28 am, [EMAIL PROTECTED] wrote:





  Hi - I have a list returned from popen/readlines, and am wondering how
  to go about iterating over each item which was returned (rather than
  currently having the whole lot returned).

  so far:

   f=os.open(./get_hostnames).readlines

  returns ['host1 host2 host3 ... hostN\n]'

  i'd like to be in a position to iterate through these, grabbing each
  host.  I have played with transmuting to a str, and using split, and
  this works, but I get the subscript brackets from the list output as
  expected, as the list output is now a string literal, and this is not
  what I want - and I think it's a bit long-winded to do a search 'n
  replace on it - hence why I ask in the subject what's the best way.

   f=str(f)
   f.split()

  [['host1,host2, ... ,hostN\n']]

  Any help is highly appreciated

  ta

  dan.

 I did indeed mean os.popen, no os.open- Hide quoted text -

 - Show quoted text -

I do indeed write a pretty fine real-time, low-bandwidth, game.  It is
like real-time chess, and seen the movie, Tron.  Can't the P2Ps zip up
in an hour?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to delimit a list?

2008-05-13 Thread dannywebster
On May 13, 11:51 am, Gabriel Genellina [EMAIL PROTECTED]
wrote:

 You meant readlines(), I presume. A file acts as its own iterator:

 f=os.open(./get_hostnames)
 try:
for line in f:
  # do something with line
 finally:
f.close()

 --
 Gabriel Genellina

Hi - thank you for your reply.

I meant:

f=os.popen(./get_hostnames).readlines()

So f is a list, rather than a file object, of which os.open would have
returned (my initial typo redirected the missive of this post, sorry!)

cheers


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


Re: Best way to delimit a list?

2008-05-13 Thread castironpi
On May 13, 6:18 am, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 En Tue, 13 May 2008 07:46:45 -0300, [EMAIL PROTECTED] escribió:

  On May 13, 11:28 am, [EMAIL PROTECTED] wrote:
  Hi - I have a list returned from popen/readlines, and am wondering how
  to go about iterating over each item which was returned (rather than
  currently having the whole lot returned).

   f=os.open(./get_hostnames).readlines

  I did indeed mean os.popen, no os.open

 Ouch, replace open with popen an my example is valid (but to get the  
 meaning I intended to write, replace os.open with open...)

 --
 Gabriel Genellina

Writing's fine, but don't the musicals suck?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to delimit a list?

2008-05-13 Thread Gabriel Genellina

En Tue, 13 May 2008 07:46:45 -0300, [EMAIL PROTECTED] escribió:

On May 13, 11:28 am, [EMAIL PROTECTED] wrote:



Hi - I have a list returned from popen/readlines, and am wondering how
to go about iterating over each item which was returned (rather than
currently having the whole lot returned).

 f=os.open(./get_hostnames).readlines


I did indeed mean os.popen, no os.open


Ouch, replace open with popen an my example is valid (but to get the  
meaning I intended to write, replace os.open with open...)


--
Gabriel Genellina

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


Re: Best way to delimit a list?

2008-05-13 Thread castironpi
On May 13, 6:18 am, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 En Tue, 13 May 2008 07:46:45 -0300, [EMAIL PROTECTED] escribió:

  On May 13, 11:28 am, [EMAIL PROTECTED] wrote:
  Hi - I have a list returned from popen/readlines, and am wondering how
  to go about iterating over each item which was returned (rather than
  currently having the whole lot returned).

   f=os.open(./get_hostnames).readlines

  I did indeed mean os.popen, no os.open

 Ouch, replace open with popen an my example is valid (but to get the  
 meaning I intended to write, replace os.open with open...)

 --
 Gabriel Genellina

Yes: fine!  But, all we do is start a Tron ring, play Tron on
laptops.  You have micro-divide currency, you can probably make
musicals -too-; and I don't have enough to say to get this...

BE TALKING!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to delimit a list?

2008-05-13 Thread Wolfgang Grafen

[EMAIL PROTECTED] schrieb:

Hi - I have a list returned from popen/readlines, and am wondering how
to go about iterating over each item which was returned (rather than
currently having the whole lot returned).

so far:


f=os.open(./get_hostnames).readlines


returns ['host1 host2 host3 ... hostN\n]'

i'd like to be in a position to iterate through these, grabbing each
host.  I have played with transmuting to a str, and using split, and
this works, but I get the subscript brackets from the list output as
expected, as the list output is now a string literal, and this is not
what I want - and I think it's a bit long-winded to do a search 'n
replace on it - hence why I ask in the subject what's the best way.


f=str(f)
f.split()

[['host1,host2, ... ,hostN\n']]


Any help is highly appreciated


untested:
f= .join(f)
f.split()

Best regards

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


Re: Best way to delimit a list?

2008-05-13 Thread J. Clifford Dyer
On Tue, 2008-05-13 at 03:28 -0700, [EMAIL PROTECTED] wrote:
 Hi - I have a list returned from popen/readlines, and am wondering how
 to go about iterating over each item which was returned (rather than
 currently having the whole lot returned).
 
 so far:
 
  f=os.open(./get_hostnames).readlines
 
 returns ['host1 host2 host3 ... hostN\n]'
 
 i'd like to be in a position to iterate through these, grabbing each
 host.  I have played with transmuting to a str, and using split, and
 this works, but I get the subscript brackets from the list output as
 expected, as the list output is now a string literal, and this is not
 what I want - and I think it's a bit long-winded to do a search 'n
 replace on it - hence why I ask in the subject what's the best way.
 
  f=str(f)
  f.split()
 [['host1,host2, ... ,hostN\n']]
 

Instead of casting to a string, each element of your list is already a
string, so use that instead:

f = open(get_hostnames)
hosts =[]

# gets each string one at a time.
for line in f:
# get rid of the pesky \n at the end
line = line.strip()
# separate the hostnames into a list
hosts += line.split(' ')

 Any help is highly appreciated
 
 ta
 
 dan.
 --
 http://mail.python.org/mailman/listinfo/python-list
 

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

Re: Best way to delimit a list?

2008-05-13 Thread Giuseppe Ottaviano


On May 13, 2008, at 12:28 PM, [EMAIL PROTECTED] wrote:


Hi - I have a list returned from popen/readlines, and am wondering how
to go about iterating over each item which was returned (rather than
currently having the whole lot returned).

so far:


f=os.open(./get_hostnames).readlines


returns ['host1 host2 host3 ... hostN\n]'

i'd like to be in a position to iterate through these, grabbing each
host.  I have played with transmuting to a str, and using split, and
this works, but I get the subscript brackets from the list output as
expected, as the list output is now a string literal, and this is not
what I want - and I think it's a bit long-winded to do a search 'n
replace on it - hence why I ask in the subject what's the best way.


f=str(f)
f.split()

[['host1,host2, ... ,hostN\n']]


If the file is really big, you may want not to construct an actual  
list with all the words, but instead use an iterator. If you define  
the function


def ichain(seq):
for s in seq:
for x in s: yield x

(which is often useful and I don't think it has been included in  
itertools) you can iterate lazily on the file:


hosts = ichain(s.split() for s in f)
for host in hosts:
# ...

HTH,
Giuseppe

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


Re: Best way to delimit a list?

2008-05-13 Thread Peter Otten
Giuseppe Ottaviano wrote:

 def ichain(seq):
 for s in seq:
 for x in s: yield x
 
 (which is often useful and I don't think it has been included in  
 itertools) you can iterate lazily on the file:

Python 2.6 includes itertools.chain.from_iterable() with that functionality.

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

Re: Best way to delimit a list?

2008-05-13 Thread castironpi
On May 13, 8:17 am, Giuseppe Ottaviano [EMAIL PROTECTED] wrote:
 On May 13, 2008, at 12:28 PM, [EMAIL PROTECTED] wrote:





  Hi - I have a list returned from popen/readlines, and am wondering how
  to go about iterating over each item which was returned (rather than
  currently having the whole lot returned).

  so far:

  f=os.open(./get_hostnames).readlines

  returns ['host1 host2 host3 ... hostN\n]'

  i'd like to be in a position to iterate through these, grabbing each
  host.  I have played with transmuting to a str, and using split, and
  this works, but I get the subscript brackets from the list output as
  expected, as the list output is now a string literal, and this is not
  what I want - and I think it's a bit long-winded to do a search 'n
  replace on it - hence why I ask in the subject what's the best way.

  f=str(f)
  f.split()
  [['host1,host2, ... ,hostN\n']]

 If the file is really big, you may want not to construct an actual  
 list with all the words, but instead use an iterator. If you define  
 the function

 def ichain(seq):
         for s in seq:
                 for x in s: yield x

 (which is often useful and I don't think it has been included in  
 itertools) you can iterate lazily on the file:

 hosts = ichain(s.split() for s in f)
 for host in hosts:
         # ...

 HTH,
 Giuseppe- Hide quoted text -

 - Show quoted text -

I am having trouble following, but I am not an always-rightter.  Was
s.split( ) one of the things you wanted to do to a line, and likely a
really common one?  I'm trying to approach problems impractically.

Now of course, if anything else is going on in the program, you will
need separate threads or separate interpreters/processes.  Does Python
meet sufficiencies on threading?  What file do we have to test it on?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to delimit a list?

2008-05-13 Thread castironpi
On May 13, 8:32 am, Peter Otten [EMAIL PROTECTED] wrote:
 Giuseppe Ottaviano wrote:
  def ichain(seq):
  for s in seq:
  for x in s: yield x

  (which is often useful and I don't think it has been included in  
  itertools) you can iterate lazily on the file:

 Python 2.6 includes itertools.chain.from_iterable() with that functionality.

 Peter

Can you color the help manual with very fine shades of off-white to
ease reading?  I was thinking a few pixels shy of red of white to
accentuate what are the class methods and which are not.  I also have
an argument that net readability would decrease, but the sample sizes
on that kind of metric are a little brinky with privacy fears around
where I'm from.  I just try to make Tron rings.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to delimit a list?

2008-05-13 Thread castironpi
On May 13, 9:08 am, [EMAIL PROTECTED] wrote:
 On May 13, 8:32 am, Peter Otten [EMAIL PROTECTED] wrote:

  Giuseppe Ottaviano wrote:
   def ichain(seq):
   for s in seq:
   for x in s: yield x

   (which is often useful and I don't think it has been included in  
   itertools) you can iterate lazily on the file:

  Python 2.6 includes itertools.chain.from_iterable() with that functionality.

  Peter

 Can you color the help manual with very fine shades of off-white to
 ease reading?  I was thinking a few pixels shy of red of white to
 accentuate what are the class methods and which are not.  I also have
 an argument that net readability would decrease, but the sample sizes
 on that kind of metric are a little brinky with privacy fears around
 where I'm from.  I just try to make Tron rings.

I am also me the that's the readability of legibles on color of light
the lighterers.

More simply, that could vary widely though, and I've heard of a
'fovea'.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to delimit a list?

2008-05-13 Thread castironpi
On May 13, 9:31 am, [EMAIL PROTECTED] wrote:
 On May 13, 9:08 am, [EMAIL PROTECTED] wrote:





  On May 13, 8:32 am, Peter Otten [EMAIL PROTECTED] wrote:

   Giuseppe Ottaviano wrote:
def ichain(seq):
for s in seq:
for x in s: yield x

(which is often useful and I don't think it has been included in  
itertools) you can iterate lazily on the file:

   Python 2.6 includes itertools.chain.from_iterable() with that 
   functionality.

   Peter

  Can you color the help manual with very fine shades of off-white to
  ease reading?  I was thinking a few pixels shy of red of white to
  accentuate what are the class methods and which are not.  I also have
  an argument that net readability would decrease, but the sample sizes
  on that kind of metric are a little brinky with privacy fears around
  where I'm from.  I just try to make Tron rings.

 I am also me the that's the readability of legibles on color of light
 the lighterers.

 More simply, that could vary widely though, and I've heard of a
 'fovea'.- Hide quoted text -

 - Show quoted text -

Furthermore Optical Sensors and Sensing Systems for Natural Resources
and Food Safety and Quality from wixipedia omits sex.  for Food and
Sex.  I think concepts are related to perceptions.  food.
--
http://mail.python.org/mailman/listinfo/python-list