Re: dictionary that discards old items

2005-07-24 Thread Bengt Richter
On Sat, 23 Jul 2005 20:07:25 -0600, Steven Bethard [EMAIL PROTECTED] wrote:

[Raymond Hettinger]
class Cache(dict):
   def __init__(self, n, *args, **kwds):
   self.n = n
   self.queue = collections.deque()
   dict.__init__(self, *args, **kwds)

[Bengt Richter]
 Minor comment: There is a potential name collision  problem for keyword 
 n=something,
 so what is considered best practice to avoid that? __n or such as the n arg?

I don't know what best practice is, but if you want to guarantee to 
avoid the name collision, you can write:

def __init__(*args, **kwargs):
 self = args[0]
 self.n = args[1]
 self.queue = collections.deque()
 dict.__init__(self, *args[2:], **kwargs)

It's not pretty though. ;)
Bullet proofing doesn't have to be ;-)
Best solution I've seen yet, thanks.

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [path-PEP] Path inherits from basestring again

2005-07-24 Thread Michael Hoffman
Peter Hansen wrote:

 Point taken.  What about ditching the file part, since it is redundant 
 and obvious that a file is in fact what is being accessed.  Thus: 
 .read_bytes(), .read_text(), .write_lines() etc.

+1. Although I've always been somewhat -0 on these methods to start with.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a dictionary from an object

2005-07-24 Thread Thanos Tsouanas
On Sun, Jul 24, 2005 at 01:43:43PM +1000, Steven D'Aprano wrote:
 On Sun, 24 Jul 2005 02:09:54 +0300, Thanos Tsouanas wrote:
  
  print foo %do
  
  where do is a dictobj object...
 
 Are you telling me that the ONLY thing you use dictobj objects for is to
 print them?

I'm sorry to disappoint you, but yes.  When you have a long text
template to fill-out, with lots of %(foo)s, and all those foos are
attributes of an object, it really helps to have dictobj.

 I don't think so. I do know how to print an object, amazingly.

Please, tell me, how would you print it in my case?

 Perhaps you would like to explain how you use the rest of the
 functionality of the dictobj, instead of taking my words out of context
 and giving an inane answer.

I dont see _ANY_ other functionality in the dictobj class.  Do you?

 Why jump through all those hoops to get attributes when Python already
 provides indexing and attribute grabbing machinery that work well? Why do
 you bother to subclass dict, only to mangle the dict __getitem__ method so
 that you can no longer retrieve items from the dict?

Because *obviously* I don't know of these indexing and attribute
grabbing machineries you are talking about in my case.  If you cared to
read my first post, all I asked was for the normal, built-in way to
do it.  Now, is there one, or not?
 
-- 
Thanos Tsouanas  .: My Music: http://www.thanostsouanas.com/
http://thanos.sians.org/ .: Sians Music: http://www.sians.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a dictionary from an object

2005-07-24 Thread Thanos Tsouanas
On Sat, Jul 23, 2005 at 06:59:43PM -0600, Steven Bethard wrote:
 Thanos Tsouanas wrote:
  I would like to have a quick way to create dicts from object, so that a
  call to foo['bar'] would return obj.bar.
  
  The following works, but I would prefer to use a built-in way if one
  exists.  Is there one?
 
 Maybe I'm not understanding your problem, but have you looked at the 
 builtin vars()?

I didn't know about it, but I knew about object.__dict__ which is, as I
see equivalent with vars(object).  But it doesn't do the job for me,
since it fails to grab all obj.foo's, some of them being properties,
etc.

vars() is good to know though, Thanks!

-- 
Thanos Tsouanas  .: My Music: http://www.thanostsouanas.com/
http://thanos.sians.org/ .: Sians Music: http://www.sians.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


How to run python script in background after i logout

2005-07-24 Thread Harlin Seritt
I have a remote linux server where I can only access it via ssh. I have
a script that I need to have run all the time. I run like so:

python script.py 

It runs fine. When I log off ssh I notice that the script died when I
logged off. How do I make sure it stays running?

thanks,

Harlin Seritt

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


Re: How to run python script in background after i logout

2005-07-24 Thread Thanos Tsouanas
On Sun, Jul 24, 2005 at 02:43:44AM -0700, Harlin Seritt wrote:
 I have a remote linux server where I can only access it via ssh. I have
 a script that I need to have run all the time. I run like so:
 
 python script.py 
 
 It runs fine. When I log off ssh I notice that the script died when I
 logged off. How do I make sure it stays running?
 
 thanks,

This hasn't got to do with python.

It's a unix/linux question.

Check at(1):
man at

-- 
Thanos Tsouanas  .: My Music: http://www.thanostsouanas.com/
http://thanos.sians.org/ .: Sians Music: http://www.sians.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run python script in background after i logout

2005-07-24 Thread Thanos Tsouanas
On Sun, Jul 24, 2005 at 12:51:17PM +0300, Thanos Tsouanas wrote:
 On Sun, Jul 24, 2005 at 02:43:44AM -0700, Harlin Seritt wrote:
  I have a remote linux server where I can only access it via ssh. I have
  a script that I need to have run all the time. I run like so:
  
  python script.py 
  
  It runs fine. When I log off ssh I notice that the script died when I
  logged off. How do I make sure it stays running?
  
  thanks,
 
 This hasn't got to do with python.
 
 It's a unix/linux question.
 
 Check at(1):
 man at

Since you want it to run all the time, check cron(8) as well.
Maybe you would like to write a small script, executing script.py if it
is not already running.

-- 
Thanos Tsouanas  .: My Music: http://www.thanostsouanas.com/
http://thanos.sians.org/ .: Sians Music: http://www.sians.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: MyNewspaper 1.2

2005-07-24 Thread Iñigo Serna
Hi there,

I'm really pleased to announce the second public release of MyNewspaper.
MyNewspaper v1.2: faster (25-35%), cleaner (100%), smaller(69%) and even 
more robust(100%).

If you liked the first version but thought... uhmm it's buggy and slow, 
then this is your release. In fact first version was a proof of concept 
to get some attention and feedback.


What is MyNewspaper after all?
==
MyNewspaper is a personal RSS Aggregator and Reader, licensed under GPL.

Why? As everybody says, I couldn't find any which fulfills all my
requirements. In fact I used liferea and was pretty happy with it, but
it eats lot of memory when you have many feeds and the program is
running for much time, but the main problem was that it's a desktop
program and I couldn't read the feeds from the work.

So I started writing my own RSS aggregator and reader. MyNewspaper is
written in Python with a bit of javascript and uses sqlite as permanent
storage for the articles. From v1.2 up sqlobject is used as an abstraction 
layer for database access, so it would be very easy to support other 
database engines.

It is installed as a CGI, so in order to use and manage it you need a
web browser and a web server. Feeds are updated by a command run by cron
or from the WebUI.


Changes
===
v1.2: faster (25-35%), cleaner (100%), smaller(69%) and even more
robust(100%)
  * a major rewrite and clean up of the whole code
  * uses sqlobject as database abstraction layer
  * uses Cheetah Template as html template
  * generated html is valid now
  * bugs fixing

IMPORTANT NOTE to upgrade from v1.0:
  * download and install sqlobject and Cheetah Template
  * copy all the needed files to the directory overwriting
old ones
  * you need to upgrade db:
$ cd /path_to/mynewspaper
$ ./migrate_db.py


Home page and download
==
Read more and download it from:

http://inigo.katxi.org/devel/mynewspaper

or http://www.terra.es/personal7/inigoserna/mynewspaper


Of course, all comments, suggestions etc. are welcome.
And yes, I know code is really awful now, but I wanted to make a public
release to get some feedback while improving the code.


Best regards,
-- 
Iñigo Serna [EMAIL PROTECTED]
Katxijasotzaileak


signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: dictionary that discards old items

2005-07-24 Thread Raymond Hettinger
[Raymond Hettinger]
 class Cache(dict):
 def __init__(self, n, *args, **kwds):
 self.n = n
 self.queue = collections.deque()
 dict.__init__(self, *args, **kwds)


[Bengt Richter]
 Minor comment: There is a potential name collision  problem for keyword 
 n=something,
 so what is considered best practice to avoid that? __n or such as the n arg?

One solution is to drop the *args and **kwds part of the __init__() API
for the subclass.  For a cache class, it doesn't make sense that you
would know all of the values when the instance is first created.  If
the need arises, the update() method will suffice:

class Cache(dict):
def __init__(self, n):
self.n = n
dict.__init__(self)
. . .


The __n form doesn't get name mangled so its only advantage is in being
a less likely key.


Raymond

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



Re: How do i do this

2005-07-24 Thread Diez B.Roggisch
Amit Regmi amitregmi at neolinuxsolutions.com writes:
 For some commad Linux like (pdbedit) its not possible to supply password 
 in the command line itself  while we add a samba user account into the 

You might be able to utilize pexpect for this. Go google :)

Diez

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


Re: tuple to string?

2005-07-24 Thread Francois De Serres
Francois De Serres wrote:

hiho,

what's the clean way to translate the tuple (0x73, 0x70, 0x61, 0x6D) to 
the string 'spam'?

TIA,
Francois
  

thanks to all!

I'll pick ('%c' * len(t)) % t, for it's readability and the fact that 
join() is on the deprec'd list.

Francois

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


Initializing interactive Python

2005-07-24 Thread qwweeeit
Hi all,
is it possible to enter an interactive session and automatically
do some initialization?
I explain better:
I want that when I start interactive Python on a console (I use Linux)
two command lines be executed automatically:

Python 2.3.4 (#2, Aug 19 2004, 15:49:40)
[GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2
Type help, copyright, credits or license for more information.
 import sys
 x01=x02=0

I would like not to have to write anything at the prompt  to run
the two commands, but be ready to start the interactive session.
Bye.

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


Re: PostgreSQL Python vs PHP

2005-07-24 Thread Bruno Desthuilliers
Luis P. Mendes a écrit :
(snip)

 I need to build it from the server and also client side.
 
 For the client side I'll be using Python.
 
 But for the server side, I would like to hear some opinions.  Is it worth
 learning Php? 

I dont think so - unless you have no other choice !-)

More seriously, Python is at least as good (much better IMHO...) as PHP 
for web applications, and the only thing (the only I can think of...) 
that's really easier to do with PHP is to write unmaintainable code with 
all logic and presention mixed up, global variables coming from outer 
space, etc...

Another point is that, since you'll need to implement your domain model 
in Python for the client app anyway, duplicating it in PHP would not 
only be a waste of time, but also lead to a maintence nightmare. Using 
Python on both the client and server side, you'll just have to write 
specific controllers and views for the web application.

A last thing is that PostgreSQL supports Python as an extension language.

My 2 cents...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Initializing interactive Python

2005-07-24 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 Hi all,
 is it possible to enter an interactive session and automatically
 do some initialization?
 I explain better:
 I want that when I start interactive Python on a console (I use Linux)
 two command lines be executed automatically:

[EMAIL PROTECTED] bruno $ python -h
(snip)
Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
(snip)

 Python 2.3.4 (#2, Aug 19 2004, 15:49:40)
 [GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2
 Type help, copyright, credits or license for more information.
 
import sys
x01=x02=0
 
 
 I would like not to have to write anything at the prompt  to run
 the two commands, but be ready to start the interactive session.
 Bye.

[EMAIL PROTECTED] bruno $ cat ~/.pythonrc.py
import sys
x01=x02=0
[EMAIL PROTECTED] bruno $ export PYTHONSTARTUP=~/.pythonrc.py
[EMAIL PROTECTED] bruno $ python
Python 2.4.1 (#1, Jul 23 2005, 00:37:37)
[GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on 
linux2
Type help, copyright, credits or license for more information.
  sys
module 'sys' (built-in)
  x01
0
  x02
0
 

Easy as pie !-)

HTH
Bruno

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


Re: Initializing interactive Python

2005-07-24 Thread Thanos Tsouanas
On Sun, Jul 24, 2005 at 03:26:06AM -0700, [EMAIL PROTECTED] wrote:
 Hi all,
 is it possible to enter an interactive session and automatically
 do some initialization?

set the enviroment variable PYTHONSTARTUP to point to a startup.py of
your own, where you put all your initializations..

HTH

-- 
Thanos Tsouanas  .: My Music: http://www.thanostsouanas.com/
http://thanos.sians.org/ .: Sians Music: http://www.sians.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


FAQ?

2005-07-24 Thread Keith P. Boruff
Hello,

Is there an FAQ available specific to this NG as I'm sure some of the 
list slicing questions I have have been asked before.

Thanks,
KPB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple to string?

2005-07-24 Thread John Machin
Steven D'Aprano wrote:
 On Sat, 23 Jul 2005 23:26:19 +1000, John Machin wrote:
 
 
Steven D'Aprano wrote:



''.join(map(lambda n: chr(n), (0x73, 0x70, 0x61, 0x6D)))

'spam'

Why the verbal diarrhoea? 
 
 
 One line is hardly verbal diarrhoea.
 
 
What's wrong with the (already posted)

''.join(map(chr, (0x73, 0x70, 0x61, 0x6D)))

???
 
 
 Nothing.
 
 If I had seen the already posted solution using chr on its own without
 lambda, I wouldn't have bothered posting the lambda solution. But I
 didn't, so I did.
 
 As another poster has already pointed out, lambda cries out for over-use,
 and this was a perfect example of it.

Here are a couple of reductions you can use in future, in the order given:

(1)
lambda args: foo(args) - foo # for *any* function foo, not just chr

(2)
lambda args: almost_any_guff
-
def meaningful_func_name(args):
almost_any_guff
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run python script in background after i logout

2005-07-24 Thread Benji York
Harlin Seritt wrote:
 python script.py 
 
 It runs fine. When I log off ssh I notice that the script died when I
 logged off. How do I make sure it stays running?

As another reply stated, cron is probably what you really want, but to 
answer your question literally:  you want the nohup command (short for 
no hangup, as in the HUP signal).  You would run it like so:

nohup python script.py 

see man nohup and info coreutils nohup for more info.
--
Benji York
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a dictionary from an object

2005-07-24 Thread Bruno Desthuilliers
Thanos Tsouanas a écrit :
 On Sun, Jul 24, 2005 at 01:43:43PM +1000, Steven D'Aprano wrote:

(snip)
 
Why jump through all those hoops to get attributes when Python already
provides indexing and attribute grabbing machinery that work well? Why do
you bother to subclass dict, only to mangle the dict __getitem__ method so
that you can no longer retrieve items from the dict?

 
 Because *obviously* I don't know of these indexing and attribute
 grabbing machineries you are talking about in my case.  If you cared to
 read my first post, all I asked was for the normal, built-in way to
 do it.  Now, is there one, or not?

If you re-read your first post, you'll notice that you didn't say 
anything about the intention, only about implementation !-)

Now if your *only* need is to access object as a dict for formated 
output, you don't need to subclass dict. This is (well, should be) enough:

class Wrapper(object):
 def __init__(self, obj):
 self._obj = obj
 def __getitem__(self, name):
 return getattr(self._obj, name)

This works with 'normal' attributes as well as with properties. Notice 
that this wrapper is read-only, and don't pretend to be a real 
dictionnary - but still it implements the minimum required interface for 
%(attname)s like formatting.

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


Re: Getting a dictionary from an object

2005-07-24 Thread Thanos Tsouanas
On Sun, Jul 24, 2005 at 02:01:30PM +0200, Bruno Desthuilliers wrote:
 Thanos Tsouanas a écrit :
  On Sun, Jul 24, 2005 at 01:43:43PM +1000, Steven D'Aprano wrote:
  
  Because *obviously* I don't know of these indexing and attribute
  grabbing machineries you are talking about in my case.  If you cared to
  read my first post, all I asked was for the normal, built-in way to
  do it.  Now, is there one, or not?
 
 If you re-read your first post, you'll notice that you didn't say 
 anything about the intention, only about implementation !-)

The following works, but I would prefer to use a built-in way if one
exists.  Is there one?
 
 Now if your *only* need is to access object as a dict for formated 
 output, you don't need to subclass dict. This is (well, should be) enough:
 
 class Wrapper(object):
  def __init__(self, obj):
  self._obj = obj
  def __getitem__(self, name):
  return getattr(self._obj, name)
 
 This works with 'normal' attributes as well as with properties. Notice 
 that this wrapper is read-only, and don't pretend to be a real 
 dictionnary - but still it implements the minimum required interface for 
 %(attname)s like formatting.

Thanks!!  You made clear what 'the extra functionality' was.  Indeed
there is no need to subclass dict...

 HTH

it does!

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

-- 
Thanos Tsouanas  .: My Music: http://www.thanostsouanas.com/
http://thanos.sians.org/ .: Sians Music: http://www.sians.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple to string?

2005-07-24 Thread John Machin
Steven D'Aprano wrote:
 On Sat, 23 Jul 2005 23:31:04 +1000, John Machin wrote:
 
 
You don't need the sissy parentheses; '%c' * len(t) % t works just fine :-)


Ah, ok. Didn't want to lookup the precedence rules...


Look up the precedence rules? Are you aware of any language where * / 
and % _don't_ have the same precedence??
 
 
 Do languages like Pascal that don't have string formatting expressions, or
 use the % operator, count?

A thousand pardons; I should have said Are you aware of any language 
which has % (as primarily a numeric remainder/modulo operator) but * /
and % _don't_ have the same precedence??

OK, given a language which does have * and / used among other things for 
numerical multiply and divide, (a) are you aware of any such language 
which does does not have * and / at the same precedence level (b) 
supposing one wanted to introduce % as a numerical 
remainder/modulo/whatever operator (plus other meaning(s) for 
non-numeric types), would you care to argue that it should not have the 
same precedence level (as * and /)?

Pascal was/is a prime example of bad precedence choice:
a  b or c  d
means
a  (b or c)  d
in Pascal (not very useful)
and
(a  b) or (c  d)
in many other languages.


 
 How about languages like Forth that don't have precedence rules at all,
 unless first come, first served is a precedence rule?

No precedence rules - no relevance to the topic
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a dictionary from an object

2005-07-24 Thread Bruno Desthuilliers
Bruno Desthuilliers a écrit :
(snip)
 class Wrapper(object):
 def __init__(self, obj):
 self._obj = obj
 def __getitem__(self, name):
 return getattr(self._obj, name)

If you want the Wrapper to be more like a Decorator (ie still can use 
the Wrapper object as if it was the wrapped object), you can add this:

 def __getattr__(self, name):
 return getattr(self._obj, name)

 def __setattr__(self, name, val):
 if name == '_obj':
 super(Wrapper, self).__setattr__(name, val)
 else:
 setattr(self._obj, name, val)

The Python cookbook may have some receipes too for this kind of funny 
things...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I get an sha1 hash in base32?

2005-07-24 Thread Elmo Mäntynen
On Sat, 23 Jul 2005 23:27:44 +0200, Marc 'BlackJack' Rintsch wrote:

 In [EMAIL PROTECTED], Elmo Mäntynen wrote:
 
 I know how to make a hash(using mhash), but instead of encoded as hex I
 want it in base32 for use with the bitzi catalog. python-bitzi is useful
 but way too slow for just getting the hash of a file(am going to use it
 elsewhere). Thanks.
 
 Doesn't Bitzi calculate some kind of audio fingerprint?  Just a hash of
 the file would result in very different hash values for different codecs,
 bitrates etc. for the same audio data.
 
 Ciao,
   Marc 'BlackJack' Rintsch

I don't think it does, but musicbrainz is designed for just that, and
there's a ptyhon binding for using the libs.

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

Re: Getting a dictionary from an object

2005-07-24 Thread Bruno Desthuilliers
Steven D'Aprano a écrit :
 On Sun, 24 Jul 2005 02:09:54 +0300, Thanos Tsouanas wrote:
 
 
(snip)
 
 Are you telling me that the ONLY thing you use dictobj objects for is to
 print them?
 
 I don't think so. I do know how to print an object, amazingly.
 
 Perhaps you would like to explain how you use the rest of the
 functionality of the dictobj, instead of taking my words out of context
 and giving an inane answer.
 
 Why jump through all those hoops to get attributes when Python already
 provides indexing and attribute grabbing machinery that work well? Why do
 you bother to subclass dict, only to mangle the dict __getitem__ method so
 that you can no longer retrieve items from the dict?
 

The idea of the OP is not to use the dictobj as a full fledged dict,
just to wrap the obj in something that is dict-like enough to be used
for %(attname)s formatting. I also assume that he doesn't want to 
manually alter the code of each and every class to achieve this !-)

So we can certainly agree that subclassing dict here is overkill and a 
bit misleading, but there are probably better ways to express this 
feeling. Of course, it would have been simpler if the OP had tell us 
from the start what was it's use case, but what...

One could of course use metaclass tricks and the like to customize the 
objects __str__ or __repr__ (as in David Mertz's gnosis.magic package), 
but that would be overkill too IMHO.

The plain old Decorator[1] pattern is probably enough in this case, 
since it's quite easy to implement a generic Decorator in Python. 
Another solution could be to dynamically modify the to-be-wrapped 
object's class to add a __getitem__ method.





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


Re: Initializing interactive Python

2005-07-24 Thread qwweeeit
Hi Bruno,
thank you...Easy as pie !-)
Bye.

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


Re: [path-PEP] Path inherits from basestring again

2005-07-24 Thread Reinhold Birkenfeld
Peter Hansen wrote:
 Reinhold Birkenfeld wrote:
 [on comparing Paths and stings]
 Do you have a use case for the comparison? Paths should be compared only
 with other paths.
 
 I can think of lots, though I don't know that I've used any in my 
 existing (somewhat limited) code that uses Path, but they all involve 
 cases where I would expect, if comparisons were disallowed, to just wrap 
 the string in a Path first, even though to me that seems like it should 
 be an unnecessary step:
 
if mypath.splitpath()[0] == 'c:/temp':
 
if 'tests' in mypath.dirs():
 
and lots of other uses which start by treating a Path as a string
first, such as by doing .endswith('_unit.py')

endswith is okay, since it is an inherited method from str.

 Any of these could be resolved by ensuring both are Paths, but then I'm 
 not sure there's much justification left for using a baseclass of 
 basestring in the first place:
 
if mypath.splitpath()[0] == Path('c:/temp'):

But you must admit that that't the cleaner solution.

if Path('tests') in mypath.dirs():
 
 Question: would this latter one actually work?  Would this check items 
 in the list using comparison or identity?  Identity would simply be 
 wrong here.

Yes, it works. I didn't do anything to make it work, but Path seems to inherit
the immutableness from str.

 [on removing properties in favour of methods for volatile data]
 My line of thought is that a path may, but does not need to refer to an
 existing, metadata-readable file. For this, I think a property is not
 proper.
 
 Fair enough, though in either case an attempt to access that information 
 leads to the same exception.  I can't make a strong argument in favour 
 of properties (nor against them, really).

Okay.

 What about iteration and indexing? Should it support
 for element in path or for char in path or nothing?
 
 As John Roth suggests, the former seems a much more useful thing to do. 
   The latter is probably as rarely needed as it is with regular strings 
 (which I believe is roughly never in Python).
 
 [on .read_file_bytes() etc]
 I think it is not exactly bad that these names are somehow outstanding,
 as that demonstrates that something complex and special happens.
 
 Point taken.  What about ditching the file part, since it is redundant 
 and obvious that a file is in fact what is being accessed.  Thus: 
 .read_bytes(), .read_text(), .write_lines() etc.

Hm. Is it so clear that a it's about a file? A path can point to anything,
so I think it's better to clearly state that this is only for a file at the
path, if it exists.

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


Re: tuple to string?

2005-07-24 Thread John Machin
Francois De Serres wrote:
 Francois De Serres wrote:
 
 hiho,

 what's the clean way to translate the tuple (0x73, 0x70, 0x61, 0x6D) 
 to the string 'spam'?

 TIA,
 Francois
  

 thanks to all!
 
 I'll pick ('%c' * len(t)) % t, for it's readability and the fact that 
 join() is on the deprec'd list.

I presume you mean deprecated.

AFAIK there is no such thing as a deprecated list.

Certain constructs cause a deprecation warning to be emitted at run time 
-- like passing a float argument where an int is expected.

Other constructs could be loosely described as deprecated because there 
is now a better way to do it, but no messages are generated. This is so 
for almost all of the functions in the string module. One example of 
this is join: instead of string.join(alist, sep) one now does 
sep.join(alist)

Given a non-string sequence of single characters, the 
common/standard/well-known idiom for producing a string uses join; it is 
''.join(seq)

Backing up to readability, I wouldn't have picked
('%c' * len(t)) % t (nor the version with 2 fewer parentheses!) as 
particulary readable -- mainly because %c is AFAIK relatively little 
used in Python and only someone familar with C etc would understand why 
it works, or why it even exists. OTOH something like ''.join(chr(x) for 
x in t) is made up of well-known frequently-used components.

Cheers,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [path-PEP] Path inherits from basestring again

2005-07-24 Thread Reinhold Birkenfeld
Reinhold Birkenfeld wrote:
 Hi,
 
 the arguments in the previous thread were convincing enough, so I made the
 Path class inherit from str/unicode again.

Further changes by now:

* subdirs() is now dirs().
* fixed compare behaviour for unicode base (unicode has no rich compare)
* __iter__() iterates over the parts().
* the following methods raise NotImplemented:
  capitalize, expandtabs, join, splitlines, title, zfill

Open issues:

What about the is* string methods?

What about __contains__ and __getitem__?

What about path * 4?

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


Re: Getting a dictionary from an object

2005-07-24 Thread Thanos Tsouanas
On Sun, Jul 24, 2005 at 03:01:40PM +0200, Bruno Desthuilliers wrote:
 I gave you a solution based on the Decorator pattern in another post, 
 but there is also the possibility to add a __getitem__ method directly 
 to the to-be-formatted object's class:
 
 def mygetitem(obj, name):
return getattr(obj, name)
 
 setattr(obj.__class__, '__getitem__', mygetitem)
 obj['bar']

I used what you suggested earlier with the Wrapper, without subclassing
dict anymore.  Thanks!

 meta
 BTW, parts of this thread should remind us all that it's usually better 
 to clearly describe the *problem* before asking for comments on the 
 solution...
 /meta

I would like to have a quick way to create dicts from object, so
that a call to foo['bar'] would return obj.bar.

Actually this is the problem, (I never said anything about _assigning_
new keys in foo), and the line following it is my question ;)

Thanks again!

-- 
Thanos Tsouanas  .: My Music: http://www.thanostsouanas.com/
http://thanos.sians.org/ .: Sians Music: http://www.sians.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyGTK or wxPython (not a flame war) on Windows

2005-07-24 Thread TPJ
 I've used pygtk with success on windows. (...)
  [will] I be able to make an executable (using Py2Exe) of an application
  that uses PyGTK?

 Yes.

So PyGTK is now my favourite. Better documentation, runs on Linux and
Windows, the possibility to make an executable program with Py2Exe.
It's enough for me.

 One point against: requires X11 on a Mac; definitely not native there,
 though that's where I do a lot of my pygtk development.

I suppose that 95% of my application's users will work on Win. The rest
will work on *nix. So my primary concern is PC world.

AFAIK PyGTK doesn't look native on Win as well, but I don't care.

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


Re: FAQ?

2005-07-24 Thread Michael Hoffman
Keith P. Boruff wrote:

 Is there an FAQ available specific to this NG as I'm sure some of the 
 list slicing questions I have have been asked before.

Try Google for python FAQ. I don't know why you would want to look in 
a FAQ *specific* to a newsgroup to look up slicing questions, since 
slicing has little to do with the newsgroup. A more general Python FAQ 
will be more helpful.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyGTK or wxPython (not a flame war) on Windows

2005-07-24 Thread TPJ
 PyQt works equally well on both systems.

I believe you. The problem is I don't like GPL.

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


Re: PyGTK or wxPython (not a flame war) on Windows

2005-07-24 Thread TPJ
Thanks a lot!

Now I know I can choose PyGTK. I really like it because of its rich
documentation.

 You could also bundle the runtime DLLs with your py2exe'd application

That's great. I think my clients will appreciate a single one
executable.

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


Re: [path-PEP] Path inherits from basestring again

2005-07-24 Thread Michael Hoffman
Reinhold Birkenfeld wrote:

 * __iter__() iterates over the parts().
 * the following methods raise NotImplemented:
   capitalize, expandtabs, join, splitlines, title, zfill

Why? They *are* implemented. I do not understand this desire to wantonly 
break basestring compatiblity for the sake of breaking compatibility.

Once you break compatibility with basestring you can no longer use a 
path anywhere that you could have used a str or unicode before. With 
compatibility broken, the only possible supported way of passing paths 
to third-party functions will be to cast the path with 
path.__bases__[0](mypath) before passing it anywhere else. You can't 
even use str() because you don't know what the base class of the path 
is. What a pain.

 From the original path.py documentation:


os.path.join doesn't map to path.join(), because there's a string method 
with that name. Instead it's path.joinpath(). This is a nuisance, but 
changing the semantics of base class methods is worse. (I know, I tried 
it.) The same goes for split().


It ain't broke. Please stop breaking it.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a dictionary from an object

2005-07-24 Thread Steven D'Aprano
On Sun, 24 Jul 2005 12:03:47 +0300, Thanos Tsouanas wrote:

 On Sun, Jul 24, 2005 at 01:43:43PM +1000, Steven D'Aprano wrote:
 On Sun, 24 Jul 2005 02:09:54 +0300, Thanos Tsouanas wrote:
  
  print foo %do
  
  where do is a dictobj object...
 
 Are you telling me that the ONLY thing you use dictobj objects for is to
 print them?
 
 I'm sorry to disappoint you, but yes.  When you have a long text
 template to fill-out, with lots of %(foo)s, and all those foos are
 attributes of an object, it really helps to have dictobj.

Ah, now we're making progress in finding out what the purpose of the
dictobj is! Thank you, this is starting to become clearer now.

 I don't think so. I do know how to print an object, amazingly.
 
 Please, tell me, how would you print it in my case?

If I have understood you, you have some object like such:

obj.foo = 1
obj.bar = 2
obj.spam = 'a'
obj.eggs = 'b'

say.

You want to use it something like this:

print My object has fields %(foo)s; %(bar)s; %(spam)s; %(eggs)s. % obj

except that doesn't work. So I would simply change the reference to obj to
obj.__dict__ and it should do exactly what you want.

Does that help?

[snip]
 Because *obviously* I don't know of these indexing and attribute
 grabbing machineries you are talking about in my case.  If you cared to
 read my first post, all I asked was for the normal, built-in way to
 do it.  Now, is there one, or not?

I did read your first post. Unfortunately, you had not explained what you
were trying to do very well. Your initial solution involved sub-classing
dict. I made the fatal mistake of trying to guess what you needed from
your sample code -- a natural mistake to make, given how vague your
requirements were. Or rather, non-existent.

It really does help to explain what your functional requirements are,
instead of focusing on one, possibly pointless, implementation.

If I have understood your functional requirements correctly, you don't
need to have a quick way to create dicts from object, so that a call to
foo['bar'] would return obj.bar at all.



-- 
Steven.

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


Re: Friend wants to learn python

2005-07-24 Thread TPJ
Why not start with Python's standard documentation? There are Python
Tutorial and Library Reference. IMHO it's the best place to start.

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


Re: [path-PEP] Path inherits from basestring again

2005-07-24 Thread Ivan Van Laningham
Hi All--

Reinhold Birkenfeld wrote:
 
 Reinhold Birkenfeld wrote:
  Hi,
 
  the arguments in the previous thread were convincing enough, so I made the
  Path class inherit from str/unicode again.
 

Thanks.

 * the following methods raise NotImplemented:
   capitalize, expandtabs, join, splitlines, title, zfill
 

If path inherits from str or unicode, why not leave these?  I can
certainly see uses for capitalize(), title() and zfill() when trying to
coerce Windows to let me use the case that I put there in the first
place;-)  What if I wanted to take a (legitimate) directory name
'parking\tlot' and change it to 'parkinglot'?

 Open issues:
 
 What about the is* string methods?

What about them?  What makes you think these wouldn't be useful? 
Imagine directory names made up of all numbers; wouldn't it be useful to
know which directories in a tree of, say, digital camera images,
comprise all numbers, all hex numbers, or alpha only?
 
 What about __contains__ and __getitem__?

I find it hard to imagine what would be returned when asking a path for
say, path[c:], other than the index. n=path[c:] = 0 ? 
 
 What about path * 4?

This one makes my brain hurt, I admit;-)


Metta,
Ivan
--
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FAQ?

2005-07-24 Thread Keith P. Boruff
Michael Hoffman wrote:
 Keith P. Boruff wrote:
 
 Is there an FAQ available specific to this NG as I'm sure some of the 
 list slicing questions I have have been asked before.
 
 
 Try Google for python FAQ. 

I tried and didn't find one. That's why I asked here.

 I don't know why you would want to look in 
 a FAQ *specific* to a newsgroup to look up slicing questions, 

I have a specific question about list slicing and this is a python NG. 
What's not to understand?

 since slicing has little to do with the newsgroup. 

I thought this was a python NG.

  A more general Python FAQ will be more helpful.

A more general FAQ (or the stuff I've accessed on slicing) didn't answer 
my question.

It doesn't matter now. I've since found the answer.

Is your attitude indicitive of most people on this NG or are you just 
one of those NG guys who gets off on making the new people feel stupid? 
If it's the former, I'll just go away. If it's the latter, I'll *PLONK* 
you.

KPB

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


Re: FAQ?

2005-07-24 Thread gene tani
Here's my trove of FAQ/Gotcha lists

http://www.ferg.org/projects/python_gotchas.html
http://zephyrfalcon.org/labs/python_pitfalls.html
http://zephyrfalcon.org/labs/beginners_mistakes.html


http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html
http://www.norvig.com/python-iaq.html
http://www.faqts.com/knowledge_base/index.phtml/fid/245
http://amk.ca/python/writing/warts

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


Re: FAQ?

2005-07-24 Thread Keith P. Boruff
gene tani wrote:
 Here's my trove of FAQ/Gotcha lists
 
 http://www.ferg.org/projects/python_gotchas.html
 http://zephyrfalcon.org/labs/python_pitfalls.html
 http://zephyrfalcon.org/labs/beginners_mistakes.html
 
 
 http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html
 http://www.norvig.com/python-iaq.html
 http://www.faqts.com/knowledge_base/index.phtml/fid/245
 http://amk.ca/python/writing/warts
 


Thanks Gene. I'll give thme a look.

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


Re: Getting a dictionary from an object

2005-07-24 Thread Steven D'Aprano
On Sun, 24 Jul 2005 12:07:02 +0300, Thanos Tsouanas wrote:

 On Sat, Jul 23, 2005 at 06:59:43PM -0600, Steven Bethard wrote:
 Thanos Tsouanas wrote:
  I would like to have a quick way to create dicts from object, so that a
  call to foo['bar'] would return obj.bar.
  
  The following works, but I would prefer to use a built-in way if one
  exists.  Is there one?
 
 Maybe I'm not understanding your problem, but have you looked at the 
 builtin vars()?
 
 I didn't know about it, but I knew about object.__dict__ which is, as I
 see equivalent with vars(object).  But it doesn't do the job for me,
 since it fails to grab all obj.foo's, some of them being properties,
 etc.

You could have mentioned this earlier.

But I don't think you are correct. As far as I can see, properties do have
an entry in obj.__dict__ the same as other attributes, although there is
certainly some strangeness going on with properties.

Using the sample code from here:
http://www.python.org/2.2.3/descrintro.html#property

class C(object):
def __init__(self):
self.__x = 0
def getx(self):
return self.__x
def setx(self, x):
if x  0: x = 0
self.__x = x
x = property(getx, setx)

I see _C__x in C().__dict__, exactly as expected. (The _C is Python's
standard name mangling of semi-private attributes starting with double
underscores.)

I can't see any way to inspect a Python object and get a list of
properties, so you might have to keep your own list: add a class-attribute
of your object which keeps a list of all the properties:

class Obj:
# various methods, attributes and properties
...
# keep a list of special properties that don't show 
# up correctly in __dict__
special = ['foo', 'bar']

# now define a special method that makes a copy of 
# __dict__ and adds special properties to it

def objdict(self):
D = self.__dict__.copy()
# assume shallow copy is enough
for property_name in self.special:
D[property_name] = self.__getattribute__(property_name)
return D

then call it when you need it:

print My object has fields %(foo)s and %(bar)s. % obj.objdict()


It would be nice to see an easier way to introspect objects and get
a list of properties.


-- 
Steven.

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


Re: FAQ?

2005-07-24 Thread rafi
Keith P. Boruff wrote:
 Michael Hoffman wrote:
 
 Keith P. Boruff wrote:

 Is there an FAQ available specific to this NG as I'm sure some of the 
 list slicing questions I have have been asked before.

 Try Google for python FAQ. 
 
 I tried and didn't find one. That's why I asked here.

surprising as the first (for me at least on googgle.com) response is: 
www.python.org/doc/faq/

 I don't know why you would want to look in a FAQ *specific* to a 
 newsgroup to look up slicing questions, 
 
 I have a specific question about list slicing and this is a python NG. 
 What's not to understand?

Michael answer could be subtitled as: if the faq is wider that the 
newsgroup, then you have more probability to find an answer.

 A more general FAQ (or the stuff I've accessed on slicing) didn't answer 
 my question.

If, after looking for information on your own you did not find a 
solution, it may mean that you are ready to post a question :-)

my 2 cents

-- 
rafi

Imagination is more important than knowledge.
(Albert Einstein)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to realize ssh scp in Python

2005-07-24 Thread Jeff Epler
Rather than doing anything with passwords, you should instead use public
key authentication.  This involves creating a keypair with ssh_keygen,
putting the private key on the machine opening the ssh connection
(~/.ssh/id_rsa), then listing the public key in the remote system's
~/.ssh/authorized_keys.

If you don't want to use this approach, `pexpect'[1] is supposed to be able
to perform this sort of tasks, and one of its examples is called
`sshls.py'.  I just downloaded it, and after changing the ssh
commandline to include
-o 'PreferredAuthentications password'
it worked for me.  In another recent thread, a different poster claimed
it didn't work, so your results may vary.

Jeff
[1] http://pexpect.sourceforge.net/


pgprScaQubqXA.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Aliasing an object's __str__ to a different method

2005-07-24 Thread Jeffrey E. Forcier
On Jul 24, 2005, at 5:00 AM, Bengt Richter wrote:

 Actually, it's not just the magic methods. [...]

Thanks for the clarification/explanation =)

 This looks a little strange because the repr of the bound method  
 includes a repr of the thing bound to,
 which returns the Edit/View presentation (after the 'of' above).
 (A possible reason to consider using just __str__ and letting  
 __repr__ be).

Yea, I must apologize, I pasted in a slightly different version of  
the class in my original email than I intended to...I fully  
understand the difference between __str__ and __repr__ and that bit  
of code where I attempted to bind to both was me attempting to  
discern exactly what was going on. The real version would only be  
binding to __str__ and leaving __repr__ alone so it could be used as  
intended =)

 A function's __get__ method will deliver a bound method if the lookup
 is via an inst, or an unbound method if the lookup is via the  
 class, in which
 case None is passed to __get__ instead of the instance.

 The upshot is that you can create descriptors __str__ and  
 __repr__for your class that will
 return bound methods using __str__ and __repr__ function attributes  
 of your instance (if they exist)
 instead of the normal class attributes, and we can chose from  
 several normal class attributes according
 to a general mode flag of the class.

[big-arse snip of code/output]

I half-understood this and what followed, but that's my fault and not  
that of your explanation. Honestly, I'm still trying to elevate my  
Python knowledge from a primarily quick-scripting level to one  
suitable for larger applications (or at least, more intelligent  
scripts =)). Specifically with things like descriptors and their ilk,  
I need to reread the various docs and PEPs out there.

But, thanks for the detailed example, and you can be sure I'll return  
to it in the near future after some more reading.


 You could use this kind of thing in a base class and specialize
 in subclasses to override stuff, and you can do other stuff too.
 Your choices are more varied that you probably thought ;-)

Oh, I know there's a whole host of ways to accomplish this, I just  
tend to get narrowly focused on a single option or couple of options  
for stretches of time, heh.

 And ideally I wanted to be able to hold a collection of these objects
 and toggle them all to one state or the other, then bandy them about

  ^^^
 does that mean all instances with a single toggling action, or each
 individually? You could have both. I.e., a general mode flag and the
 ability to assign an arbitrary __str__ and/or __repr__ override for
 a particular instance. See example, where all are toggled by default.

Well, either, depending on how flexible I want the overall design to  
be, but primarily all at once. E.g. I'd have a Page or PageBody  
container class holding a bunch of (implementing the same interface)  
objects as discussed, and would want all of those sub-objects to be  
in the same mode. In other words...a page is either displaying text  
fields for editing, or plain text for display (but with myriad form  
elements, not just text fields, of course).


Thanks again,
Jeff

--
Jeffrey E. Forcier
Junior Developer, Research and Development
Stroz Friedberg, LLC
15 Maiden Lane, 12th Floor
New York, NY 10038
[main]212-981-6540 [direct]212-981-6546
http://www.strozllc.com

This message is for the named person's use only.  It may contain
confidential, proprietary or legally privileged information. No right to
confidential or privileged treatment of this message is waived or lost
by any error in transmission.  If you have received this message in
error, please immediately notify the sender by e-mail or by telephone at
212.981.6540, delete the message and all copies from your system and
destroy any hard copies.  You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message if you are
not the intended recipient.

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


Re: FAQ?

2005-07-24 Thread Michael Hoffman
Keith P. Boruff wrote:
 Michael Hoffman wrote:
 Keith P. Boruff wrote:
 Is there an FAQ available specific to this NG as I'm sure some of the 
 list slicing questions I have have been asked before.

 Try Google for python FAQ. 
 
 I tried and didn't find one. That's why I asked here.

When I Google for Python FAQ, almost all of the search results on the 
first page are Python FAQs. The third link even has a newsgroup FAQ 
although I doubt it is what you want, even though you said otherwise.

Therefore I asked a question on why you want a *newsgroup* FAQ when it 
sounds like you want a *Python* FAQ, so that I and others could 
potentially be more helpful in answering your unasked question.

 I don't know why you would want to look in a FAQ *specific* to a 
 newsgroup to look up slicing questions, 
 
 I have a specific question about list slicing and this is a python NG. 
 What's not to understand?

I can't understand why you think your list slicing problem is specific 
to the newsgroup and not to Python.

 Is your attitude indicitive of most people on this NG or are you just 
 one of those NG guys who gets off on making the new people feel stupid? 
 If it's the former, I'll just go away.

If that's the way you respond to people who are trying to help you, 
please do so.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyGTK or wxPython (not a flame war) on Windows

2005-07-24 Thread Marek Kubica
Hello!

 AFAIK PyGTK doesn't look native on Win as well, but I don't care.
It does have a nearly-native look and feel:
http://gtk-wimp.sourceforge.net/screenshots/
And yes, the theme adjusts itself to Windows XP themes, so GTK+ apps look
nearly like any other Windows Program. The native look and feel is not as
good as the look and feel of wx but still really _much_ better than older
versions of GTK.

This is done by a theme engine.. you can find it in the gladewin32 package.

greets,
Marek

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


Re: How to realize ssh scp by Python

2005-07-24 Thread Jesse Noller
On 7/23/05, 刚 王 [EMAIL PROTECTED] wrote:
 I would like to write a Python code like this:
 
 It can login a host by SSH
 after login the host, use SCP to get a remote file, so it can deliver file
 to the host.
 then execute the program
 then leave the host
 
 For example :
 
 STEP 1. ssh _yyy at 123.45.67.89
 STEP 2. Enter the password automatically 
 STEP 3. run  scp -r zzz at 123.45.67.90:/home/xxx/program .
 STEP 4. Enter the password for SCP automatically 
 STEP 5. run ./program
 STEP 6. run  exit
 
 I know telnetlib can help us with telnet, and how to deal with this SSH
 situation in Python?
 
 Thanks a lot for your help :)
 

I would recommend looking at the following utilities:

http://www.theether.org/pssh/
http://sourceforge.net/projects/pyssh

Setting up private/public key authentication is going to allow for a
greate amount of secure automation. Barring that, use the pexpect
module to do the prompt handling.

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

Re: [path-PEP] Path inherits from basestring again

2005-07-24 Thread Reinhold Birkenfeld
Michael Hoffman wrote:
 Reinhold Birkenfeld wrote:
 
 * __iter__() iterates over the parts().
 * the following methods raise NotImplemented:
   capitalize, expandtabs, join, splitlines, title, zfill
 
 Why? They *are* implemented. I do not understand this desire to wantonly 
 break basestring compatiblity for the sake of breaking compatibility.

 Once you break compatibility with basestring you can no longer use a 
 path anywhere that you could have used a str or unicode before. With 
 compatibility broken, the only possible supported way of passing paths 
 to third-party functions will be to cast the path with 
 path.__bases__[0](mypath) before passing it anywhere else. You can't 
 even use str() because you don't know what the base class of the path 
 is. What a pain.
 
  From the original path.py documentation:
 
 
 os.path.join doesn't map to path.join(), because there's a string method 
 with that name. Instead it's path.joinpath(). This is a nuisance, but 
 changing the semantics of base class methods is worse. (I know, I tried 
 it.) The same goes for split().
 
 
 It ain't broke. Please stop breaking it.

Okay. While a path has its clear use cases and those don't need above methods,
it may be that some brain-dead functions needs them.

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


Re: FAQ?

2005-07-24 Thread tiissa
Michael Hoffman wrote:
 Keith P. Boruff wrote:
 
 Michael Hoffman wrote:

 Keith P. Boruff wrote:

 Is there an FAQ available specific to this NG as I'm sure some of 
 the list slicing questions I have have been asked before.
 
 Therefore I asked a question on why you want a *newsgroup* FAQ when it 
 sounds like you want a *Python* FAQ, so that I and others could 
 potentially be more helpful in answering your unasked question.

Seems to me there is a slight misunderstanding here.

Some newsgroups publish a FAQ, based on the questions that are asked in 
it. These FAQ are often related to the subject of the NG, not 
specifically the NG and its mechanics.

It is advised, when someone wants to post in these kind of NG, to check 
if their question is not yet answered in the FAQ published by the NG on 
the subject.

Therefore, I think the OP was checking if there was such a FAQ on Python 
published specifically in c.l.python besides the ones he already found 
on the web.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple to string?

2005-07-24 Thread Robert Kern
Francois De Serres wrote:

 I'll pick ('%c' * len(t)) % t, for it's readability and the fact that 
 join() is on the deprec'd list.

''.join() is certainly not deprecated. What made you think that?

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die.
   -- Richard Harter

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


Re: Getting a dictionary from an object

2005-07-24 Thread Bruno Desthuilliers
Steven D'Aprano a écrit :
 On Sun, 24 Jul 2005 12:03:47 +0300, Thanos Tsouanas wrote:

Please, tell me, how would you print it in my case?
  
 If I have understood you, you have some object like such:
 
 obj.foo = 1
 obj.bar = 2
 obj.spam = 'a'
 obj.eggs = 'b'
 
 say.
 
 You want to use it something like this:
 
 print My object has fields %(foo)s; %(bar)s; %(spam)s; %(eggs)s. % obj
 
 except that doesn't work. So I would simply change the reference to obj to
 obj.__dict__ and it should do exactly what you want.

Nope, it doesn't work with computed attributes (properties, descriptors, 
...).

The most obvious solution is the decorator pattern - which is somewhat 
the op was trying to do.

Another solution is to dynamically add a __getitem__ method to obj 
before using'em that way, either by setting explicitly the method as an 
attribute of the object's class or by using the import_with_metaclass() 
trick from David Mertz.

(snip)

 It really does help to explain what your functional requirements are,
 instead of focusing on one, possibly pointless, implementation.
 
+1 on this !-)
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Veusz 0.7 - a scientific plotting package

2005-07-24 Thread Jeremy Sanders
Veusz 0.7
-
Velvet Ember Under Sky Zenith
-
http://home.gna.org/veusz/
 
Veusz is a scientific plotting package written in Python (currently
100% Python). It uses PyQt for display and user-interfaces, and
numarray for handling the numeric data. Veusz is designed to produce
publication-ready Postscript output.
 
Veusz provides a GUI, command line and scripting interface (based on
Python) to its plotting facilities. The plots are built using an
object-based system to provide a consistent interface.
 
Changes from 0.6:
 Please refer to ChangeLog for all the changes.
 Highlights include:
  * 2D image support
  * FITS file data import (1D + 2D) with PyFITS module
  * Support for line separated blocks of data when importing
  * Reversed axes supported
  * Key length option
  * Linked dataset reload UI
  * Plot functions over specific range
  * Several UI improvements
 
Features of package:
 * X-Y plots (with errorbars)
 * Images (with colour mappings)
 * Stepped plots (for histograms)
 * Line plots
 * Function plots
 * Fitting functions to data
 * Stacked plots and arrays of plots
 * Plot keys
 * Plot labels
 * LaTeX-like formatting for text
 * EPS output
 * Simple data importing
 * Scripting interface
 * Save/Load plots
 * Dataset manipulation
 * Embed Veusz within other programs
 
To be done:
 * Contour plots
 * UI improvements
 * Import filters (for qdp and other plotting packages, fits, csv)
 
Requirements:
 Python (probably 2.3 or greater required)
   http://www.python.org/
 Qt (free edition)
   http://www.trolltech.com/products/qt/
 PyQt (SIP is required to be installed first)
   http://www.riverbankcomputing.co.uk/pyqt/
   http://www.riverbankcomputing.co.uk/sip/
 numarray
   http://www.stsci.edu/resources/software_hardware/numarray
 Microsoft Core Fonts (recommended)
   http://corefonts.sourceforge.net/
 PyFITS (optional)
   http://www.stsci.edu/resources/software_hardware/pyfits
 
For documentation on using Veusz, see the Documents directory. The
manual is in pdf, html and text format (generated from docbook).
 
Cheers
 
Jeremy
 

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


Re: tuple to string?

2005-07-24 Thread Francois De Serres
Robert Kern wrote:

Francois De Serres wrote:

  

I'll pick ('%c' * len(t)) % t, for it's readability and the fact that 
join() is on the deprec'd list.



''.join() is certainly not deprecated. What made you think that?

  

this:
http://www.python.org/doc/2.4.1/lib/node110.html

but I now realize it's a different version of join() that was proposed 
here...

thank you,
Francois

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


Importing User-defined Modules

2005-07-24 Thread Walter Brunswick
I need to import modules with user-defined file extensions that differ from 
'.py', and also (if possible) redirect the bytecode 
output of the file to a file of a user-defined extension.
I've already read PEP 302 (http://www.python.org/peps/pep-0302.html), but I 
didn't fully understand it. Would someone [who 
understands it] please be able to give me a synopsis of it, along with a few 
explanatory examples, or some other alternatives, if 
any? 


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


Re: tuple to string?

2005-07-24 Thread Steven D'Aprano
On Sun, 24 Jul 2005 21:55:19 +1000, John Machin wrote:

Look up the precedence rules? Are you aware of any language where * / 
and % _don't_ have the same precedence??
 
 
 Do languages like Pascal that don't have string formatting expressions, or
 use the % operator, count?
 
 A thousand pardons; I should have said Are you aware of any language 
 which has % (as primarily a numeric remainder/modulo operator) but * /
 and % _don't_ have the same precedence??

[slaps head]

Ah, I had completely forgotten that Pascal has a MOD operator that is
equivalent to % and has the same precedence as * / and DIV. So scratch
Pascal off the list.

But APL uses right-to-left precedence for all operators, and Forth uses
left-to-right. There may be others.


 OK, given a language which does have * and / used among other things for 
 numerical multiply and divide, (a) are you aware of any such language 
 which does does not have * and / at the same precedence level (b) 
 supposing one wanted to introduce % as a numerical 
 remainder/modulo/whatever operator (plus other meaning(s) for 
 non-numeric types), would you care to argue that it should not have the 
 same precedence level (as * and /)?

Yes I would.

Since the remainder (or modulo) operator is not distributive, the only
unambiguous usage is to use parentheses, or to decide on precedence rules.
The usual mathematical convention is that modulus has lower precedence
than addition, eg in clock arithmetic we expect that three hours after
ten is one: 10+3 modulo 12 is 1, not 13.


-- 
Steven.

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


Re: [path-PEP] Path inherits from basestring again

2005-07-24 Thread Peter Hansen
Reinhold Birkenfeld wrote:
 Peter Hansen wrote:
   if mypath.splitpath()[0] == 'c:/temp':

vs.

   if mypath.splitpath()[0] == Path('c:/temp'):
 
 But you must admit that that't the cleaner solution.

Cleaner?  Not at all.  I'd say it's the more expressive solution, 
perhaps, but I definitely wouldn't choose the word cleaner for 
something which, to me, adds fairly unnecessary text.

But it's clearly a subjective matter, and as the one of us not involved 
in doing the real work here, I'll bow to your judgement on the matter. ;-)

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


Re: tuple to string?

2005-07-24 Thread Robert Kern
John Machin wrote:

 No precedence rules - no relevance to the topic

Precedence rules of other languages - no relevance to the topic

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die.
   -- Richard Harter

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


Re: PyGTK or wxPython (not a flame war) on Windows

2005-07-24 Thread Torsten Bronger
Hallöchen!

Marek Kubica [EMAIL PROTECTED] writes:

 Hello!

 AFAIK PyGTK doesn't look native on Win as well, but I don't care.

 [...] The native look and feel is not as good as the look and feel
 of wx but still really _much_ better than older versions of GTK.

Is PyGTK more Pythonic by the way?  I had a look at wxPython
yesterday and didn't like that it has been brought into the Python
world nearly unchanged.  You can see its non-Python origin clearly.
How does PyGTK feel in this respect?

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: tuple to string?

2005-07-24 Thread Steven D'Aprano
On Sun, 24 Jul 2005 10:39:44 -0700, Robert Kern wrote:

 John Machin wrote:
 
 No precedence rules - no relevance to the topic
 
 Precedence rules of other languages - no relevance to the topic


I thought the topic was -- or at least had wandered in the direction of --
whether or not it was unthinkable for the precedence of % to be
anything but that of multiplication and division. Surely the precedence
rules of other languages have some relevance to that question. 

Still, the subject is rapidly losing whatever interest it may have had.


-- 
Steven.

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


Re: [path-PEP] Path inherits from basestring again

2005-07-24 Thread Mike Meyer
Steven D'Aprano [EMAIL PROTECTED] writes:

 On Sat, 23 Jul 2005 17:51:31 -0600, John Roth wrote:

 I also like to know the number of elements, which seems to make
 sense as len(path). Again, the number of characters in the path seems
 to be utterly useless information - at least, I can't imagine a use for
 it.
 There are (were?) operating systems that could only deal with a maximum
 length for pathnames. If I recall correctly, and I probably don't, Classic
 Mac (pre-OS X) was limited to file names of 31 or fewer characters and no
 more than 250-odd for the entire pathname. At the very least, some file
 manager routines would work and some would not.

Are. But I think they're a lot longer now.

bhuda% grep PATH_MAX /usr/include/sys/syslimits.h
#define   PATH_MAX 1024   /* max bytes in pathname */

  mike

-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a dictionary from an object

2005-07-24 Thread Bruno Desthuilliers
Steven D'Aprano a écrit :
 On Sun, 24 Jul 2005 12:07:02 +0300, Thanos Tsouanas wrote:

Thanos Tsouanas wrote:

(snip)
I didn't know about it, but I knew about object.__dict__ which is, as I
see equivalent with vars(object).  But it doesn't do the job for me,
since it fails to grab all obj.foo's, some of them being properties,
etc.
 
(snip)
  I don't think you are correct. As far as I can see, properties do have
 an entry in obj.__dict__ the same as other attributes, although there is
 certainly some strangeness going on with properties.
 
 Using the sample code from here:
 http://www.python.org/2.2.3/descrintro.html#property
 
 class C(object):
 def __init__(self):
 self.__x = 0
 def getx(self):
 return self.__x
 def setx(self, x):
 if x  0: x = 0
 self.__x = x
 x = property(getx, setx)
 
 I see _C__x in C().__dict__, exactly as expected. (snip)

Yes, but you don't see 'x'.  Poking into the object's __dict__ would 
defeat the whole point of computed attributes - which by the way need 
not directly map to a protected or private variable, nor even be 
properties (think: descriptors).

 I can't see any way to inspect a Python object and get a list of
 properties, 

I do :

def list_properties(obj):
 proptype = type(property()) # not defined in types
 klass = obj.__class__
 names = dir(klass) # so we get inherited attribs as well
 d  = dict([(name, getattr(klass, name)) for name in names])
 return [name for name, attrib in d.items() \
 if type(attrib) is proptype]



Note that this won't find all descriptors (I've tried and it really 
harder... there are a lot of things in a class.__dict__ that have a 
__get__() method, most of'em not defined in the types module).

Anyway, you won't need it... (I mean, the OP don't need it to solve it's 
problem)

 so you might have to keep your own list: add a class-attribute
 of your object which keeps a list of all the properties:
 
 class Obj:
 # various methods, attributes and properties
 ...
 # keep a list of special properties that don't show 
 # up correctly in __dict__
 special = ['foo', 'bar']
 
 # now define a special method that makes a copy of 
 # __dict__ and adds special properties to it
 
 def objdict(self):
 D = self.__dict__.copy()
 # assume shallow copy is enough
 for property_name in self.special:
 D[property_name] = self.__getattribute__(property_name)
 return D
 
 then call it when you need it:
 
 print My object has fields %(foo)s and %(bar)s. % obj.objdict()

This means adding responsabilities to the class when the need is 
obviously orthogonal to the class's responsabilities. Implementing a 
generic decorator pattern in Python does'nt require more code, doesn't 
requires the class nor the object to be modified at all, is probably 
more robust, and  is, well... more generic !-)  (should I say 'more 
pythonic' ?)

 It would be nice to see an easier way to introspect objects and get
 a list of properties.

You're dream is now reality. Now ain't *that* nice ?-)

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


Re: consistency: extending arrays vs. multiplication ?

2005-07-24 Thread Soeren Sonnenburg
On Sat, 2005-07-23 at 23:35 +0200, Marc 'BlackJack' Rintsch wrote:
 In [EMAIL PROTECTED], Soeren
 Sonnenburg wrote:
 
  Just having started with python, I feel that simple array operations '*'
  and '+' don't do multiplication/addition but instead extend/join an
  array:
  
  a=[1,2,3]
  b=[4,5,6]
  a+b
  [1, 2, 3, 4, 5, 6]
 
 Both operate on the lists themselves and not on their contents.  Quite
 consistent if you ask me.

But why ?? Why not have them operate on content, like is done on
*arrays ?

Soeren

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


Re: consistency: extending arrays vs. multiplication ?

2005-07-24 Thread Soeren Sonnenburg
On Sun, 2005-07-24 at 13:36 +1000, Steven D'Aprano wrote:
 On Sat, 23 Jul 2005 18:30:02 +0200, Soeren Sonnenburg wrote:
 
  Hi all,
  
  Just having started with python, I feel that simple array operations '*'
  and '+' don't do multiplication/addition but instead extend/join an
  array:
 
 * and + are not array operations, they are list operations.
 
 Lists in Python can contain anything, not just numeric values.

That seems to be *the point*. Although list(a) + list(b) could create a
list [ a[0]+b[0], ...] and bail out if for elements '+' is not
defined...

 Python doesn't have built-in mathematical arrays, otherwise known as
 matrices. There are modules that do that, but I haven't used them. Google
 on Numeric Python.

Well I am aware of that but I don't understand the reasons of having
both lists (which are infect arrays) and *arrays ? *I* would rather drop
'+' and '*' to work like they do in *array ...

Soeren

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


Re: consistency: extending arrays vs. multiplication ?

2005-07-24 Thread Soeren Sonnenburg
On Sat, 2005-07-23 at 20:25 -0700, Dan Bishop wrote:
 Soeren Sonnenburg wrote:
  Hi all,
 
  Just having started with python, I feel that simple array operations '*'
  and '+' don't do multiplication/addition but instead extend/join an
  array:
 
  a=[1,2,3]
   b=[4,5,6]
   a+b
  [1, 2, 3, 4, 5, 6]
 
  instead of what I would have expected:
  [5,7,9]
 
 To get what you expected, use
 
 [x + y for (x, y) in zip(a, b)]

Thanks for this suggestion, however I am interested in understanding the
design decision here... I could aswell just use numarray and get the
wanted a+b by:

from numarray import *
a=array([1,2,3])
b=array([1,2,3])
a+b
array([2, 4, 6])

Soeren

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


Re: consistency: extending arrays vs. multiplication ?

2005-07-24 Thread Soeren Sonnenburg
On Sat, 2005-07-23 at 12:15 -0700, Robert Kern wrote:
 Soeren Sonnenburg wrote:
  Hi all,
  
  Just having started with python, I feel that simple array operations '*'
  and '+' don't do multiplication/addition but instead extend/join an
  array:
  
  a=[1,2,3]
 
 This isn't an array. It is a list. If you want an array, use 
 Numeric/numarray. If you want lists, use lists. Lists will never grow 
 the kind of behavior you're asking for.

Sorry, but I still don't understand the reasons for that. Lists are
infect arrays so why does it make sense to have another *array ? All
that is missing is ufuncs and 'fixing' (as I see it) '+','*' ?

Soeren


signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: consistency: extending arrays vs. multiplication ?

2005-07-24 Thread Robert Kern
Soeren Sonnenburg wrote:
 On Sun, 2005-07-24 at 13:36 +1000, Steven D'Aprano wrote:
 
On Sat, 23 Jul 2005 18:30:02 +0200, Soeren Sonnenburg wrote:

Hi all,

Just having started with python, I feel that simple array operations '*'
and '+' don't do multiplication/addition but instead extend/join an
array:

* and + are not array operations, they are list operations.

Lists in Python can contain anything, not just numeric values.
 
 That seems to be *the point*.

Whose point? If you mean that you want to be able to use arbitrary 
objects in an array, then look in numarray.objects for an array type 
that handles arbitrary Python objects.

 Although list(a) + list(b) could create a
 list [ a[0]+b[0], ...] and bail out if for elements '+' is not
 defined...

Unlike the current situation, where a+b always works consistently 
despite the contents, despite how long the lists are.

Python doesn't have built-in mathematical arrays, otherwise known as
matrices. There are modules that do that, but I haven't used them. Google
on Numeric Python.
 
 Well I am aware of that but I don't understand the reasons of having
 both lists (which are infect arrays)

They are in [fact] arrays only in the sense that they are containers 
of objects with a contiguous layout in memory. That doesn't imply either 
set of semantics for + and * operators.

 and *arrays ?

They're good at different things. Arrays like Numeric/numarray are 
harder to implement than the builtin lists.

 *I* would rather drop
 '+' and '*' to work like they do in *array ...

Tough. It's 14 years or so too late to make that change.

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die.
   -- Richard Harter

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


Re: tuple to string?

2005-07-24 Thread Peter Hansen
Steven D'Aprano wrote:
 Still, the subject is rapidly losing whatever interest it may have had.

It had none.  Kill it.  Kill the witch!
-- 
http://mail.python.org/mailman/listinfo/python-list


Try this

2005-07-24 Thread RunLevelZero
I'm not sure I understand your first question but checkout the  glob 
module.  Sounds like it may help.

Here is how you could get the folders and filenames

import os

list = os.walk(C:\python24\Tools)
for file in list:
folderlist = os.path.split(file[0])
print Folder***
print folderlist[1]
print =
print
print Files*
print file[2]
print =

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


Re: PyGTK or wxPython (not a flame war) on Windows

2005-07-24 Thread Marek Kubica
Hi!

Am Sun, 24 Jul 2005 19:47:30 +0200 schrieb Torsten Bronger:

 Is PyGTK more Pythonic by the way?  I had a look at wxPython
 yesterday and didn't like that it has been brought into the Python
 world nearly unchanged.  You can see its non-Python origin clearly.
 How does PyGTK feel in this respect?
Well.. I'd say, PyGTK is still quite like GTK in C. There are some nice
features like iterators in treeviews but some things are IMHO unneccesary
difficult and much more elegant in wx.

I have started GUIs in Python with wx, but after a short time I was annoyed
how many things were buggy. I don't know why, but I fell from one bug to
the other while programming one application. Then, I tried GTK on Windows,
because I know GTK+ 2 a bit liked it. First I was very impressed, the
documentation (Tutorial + Reference + FAQ) was after wxPy 2.4.x _very_
impressive and things which were difficult in wxPy were easy in PyGTK. But
after some time I realized some other things were complicated in PyGTK.

You see, there is no non-plus-ultra GUI library and my best advice is to
test it yourself to see which one fits your needs best.

I hope a Qt4 compatible PyQt will be released soon, I'm curious about the
new Qt4, which is free for GPL-only software on Windows.

greets,
Marek

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


Re: Detecting computers on network

2005-07-24 Thread Marek Kubica
Hello!

On Fri, 22 Jul 2005 10:32:04 -0600 Sandeep Arya wrote:

 Sybren.. Does nmap is available on every systems? I tried on my linux fc4 
 machine in user previleage. it was not working. Does this just belongs to 
 superuser...
I'm not Sybren, but I think I'm able to respond.
nmap is only available if it is installed on the system, on Debian you
would need to install the package nmap first. It is not really a good idea
hoping nmap to be installed.

You can use nmap as a normal user, but some advanced scanning options are
reserved for superuser.

greets,
Marek

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


Re: [path-PEP] Path inherits from basestring again

2005-07-24 Thread Reinhold Birkenfeld
Peter Hansen wrote:
 Reinhold Birkenfeld wrote:
 Peter Hansen wrote:
   if mypath.splitpath()[0] == 'c:/temp':
 
 vs.
 
   if mypath.splitpath()[0] == Path('c:/temp'):
 
 But you must admit that that't the cleaner solution.
 
 Cleaner?  Not at all.  I'd say it's the more expressive solution, 
 perhaps, but I definitely wouldn't choose the word cleaner for 
 something which, to me, adds fairly unnecessary text.
 
 But it's clearly a subjective matter, and as the one of us not involved 
 in doing the real work here, I'll bow to your judgement on the matter. ;-)

I'm in no way the last instance on this.
For example, everyone with CVS access is free to change the files ;)

Honestly, I'm in constant fear that allowing too much and loading too much
features won't increase the acceptance of python-dev wink

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


Re: Friend wants to learn python

2005-07-24 Thread Marek Kubica
Hello,

On 23 Jul 2005 10:24:02 -0700 Pietro Campesato wrote:

 Maybe diveintopython.org can help
I consider diveintopython a little bit to hard for the beginner. I really
like this book, it's excellent, great thanks to Mike Pilgrim for providing
us the book.

I pointed a friend to Python Programming for the Absolute Beginner by
Premier Press. He liked it, although I don't know how much Python he had
learned yet.

Just my 1/50 of a bigger coin in your currency ;)

greets,
Marek

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


Re: How to run python script in background after i logout

2005-07-24 Thread Mike Meyer
Thanos Tsouanas [EMAIL PROTECTED] writes:

 On Sun, Jul 24, 2005 at 12:51:17PM +0300, Thanos Tsouanas wrote:
 On Sun, Jul 24, 2005 at 02:43:44AM -0700, Harlin Seritt wrote:
  I have a remote linux server where I can only access it via ssh. I have
  a script that I need to have run all the time. I run like so:
 Since you want it to run all the time, check cron(8) as well.
 Maybe you would like to write a small script, executing script.py if it
 is not already running.

Cron will restart the process at regular intervals, meaning you have
to have a mechanism in place to deal with multiple copies running. It
also allows for periods when no process is running.

There are usually better solutions than this, but they are
system-dependent.

On SysV like systems - which includes most (all?) Linux systems - you
can add an entry to inittab that will cause a command to be restarted
should it ever die.

On BSD based systems, the same functionality is available via
/etc/ttys. It's not very well documented, though.

The reason you don't hear much about these is because it's normal for
a Unix app to be able to deal with such issues by itself. In python,
this consists of a loop like:

while not_time_to_exit:
try:
run_main()
except:
log_problem()

I.e. - you catch any otherwise uncaught exceptions, and log them so
that you can fix whatever caused the problem later. This requires that
you run_main resets the environment properly to avoid problems from
leftover data in the python program. Of course, one way of doing that
is relaunching the python program.

not_time_to_exit depends on your environment. Proper signal handling
is usually the way to deal with this.

  mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run python script in background after i logout

2005-07-24 Thread Steve M
Harlin Seritt wrote:
 I have a remote linux server where I can only access it via ssh. I have
 a script that I need to have run all the time. I run like so:

 python script.py 

 It runs fine. When I log off ssh I notice that the script died when I
 logged off. How do I make sure it stays running?

You might also check out the extremely cool screen program. It lets you
have multiple virtual terminal sessions from one connection, and detach
them all and logout, then login later and re-attach them. I typically
use 'screen -D -R' which will re-attach if there is a set of sessions
to re-attach, or otherwise start a new one.

Then you can have a dedicated window for your script.py (you don't even
need to run it in the background of the shell with '') and you can
just detach the screen before you logout. Later you can log back in,
reattach, check for any output (you can use print statements for debug
info, etc.).

Since it can be tricky getting started, I'll tell you briefly, there is
a command key, which you use to send commands to the screen program.
Anything other than command key will be passed through to whatever
program is running, e.g. the bash shell or whatever. The default
command key is ctrl-a. So you would do 'ctrl-a c' to create a new
virtual window, 'ctrl-a 1', 'ctrl-a 2', etc. to switch between virtual
windows, and 'ctrl-a d' to detach your session. This brings you back to
your original ssh login shell. Incidentally, if you do a 'ps aux' here
you'll see one of the programs is 'SCREEN' owned by root; this is the
process that is keeping alive all your other processes and that
persists when you logout and allows you to reattach later.

A couple of problems I've had are first, that ctrl-a is also the emacs
command to go to the beginning of the line, which I use all the time.
So I've sometimes rebound the screen command key (I've tried ctrl-[
since I dont' ever seem to use that for anything else, but I don't
think it works entirely perfectly, especially in combination with the
next problem.). Another is that when I use putty.exe from Windows for
my ssh client, I can't get scroll-back buffers to work correctly with
screen. (Screen is really powerful with its own scrollback buffers and
screendumps and stuff but I don't have time to get into all that or
even learn it sometimes. I wish I were more a master of it since its
such a great program.)

Another alternative is to daemonize your program, but I don't know how
to do that off the top of my head.

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


Re: How to run python script in background after i logout

2005-07-24 Thread Tomasz Rola
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 24 Jul 2005, Harlin Seritt wrote:

 I have a remote linux server where I can only access it via ssh. I have
 a script that I need to have run all the time. I run like so:
 
 python script.py 
 
 It runs fine. When I log off ssh I notice that the script died when I
 logged off. How do I make sure it stays running?

Besides at and cron commands (mentioned by the others), have a look at
nohup, too.

Regards,
Tomasz Rola

- --
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did rm -rif on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:[EMAIL PROTECTED] **


-BEGIN PGP SIGNATURE-
Version: PGPfreeware 5.0i for non-commercial use
Charset: noconv

iQA/AwUBQuP0fhETUsyL9vbiEQINVACfVvgOcWTr3jmA21gJq24DcVHWNmgAn2tY
JAt0TM0X67bFlD3wRh9TkVeH
=tVam
-END PGP SIGNATURE-


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


Re: How to run python script in background after i logout

2005-07-24 Thread Marek Kubica
Hello!

On 24 Jul 2005 12:59:04 -0700 Steve M wrote:

 Another is that when I use putty.exe from Windows for
 my ssh client, I can't get scroll-back buffers to work correctly with
 screen. (Screen is really powerful with its own scrollback buffers and
 screendumps and stuff but I don't have time to get into all that or
 even learn it sometimes. I wish I were more a master of it since its
 such a great program.)

I use Crtl+A+Esc and go into the screen scrollback buffer, where I can
navigate with the arrow keys. After typing Esc a second time, I get back to
my program.

greets,
Marek

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


Re: Getting a dictionary from an object

2005-07-24 Thread Steven Bethard
Thanos Tsouanas wrote:
 Steven Bethard wrote:
 
Maybe I'm not understanding your problem, but have you looked at the 
builtin vars()?
 
 I didn't know about it, but I knew about object.__dict__ which is, as I
 see equivalent with vars(object).  But it doesn't do the job for me,
 since it fails to grab all obj.foo's, some of them being properties,
 etc.

How about something like:
 dict((name, getattr(obj, name)) for name in dir(obj))

For example:

py class C(object):
... x = 1
... @property
... def y(self):
... return 2
... def __init__(self):
... self.z = 3
...
py c = C()
py d = dict((name, getattr(c, name)) for name in dir(c))
py d['x']
1
py d['y']
2
py d['z']
3

Looks like this will get instance attributes, class attributes and 
properties just fine.

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


Re: PyGTK or wxPython (not a flame war) on Windows

2005-07-24 Thread Torsten Bronger
Hallöchen!

Marek Kubica [EMAIL PROTECTED] writes:

 [...]

 I have started GUIs in Python with wx, but after a short time I
 was annoyed how many things were buggy. I don't know why, but I
 fell from one bug to the other while programming one application.

I'm very suprised.  wxPython is still that buggy?  I read reports
from 2000 about such observations, but they tried wxPython in a
non-standard way, and the project has had 5 years to become more
stable after all.  Besides, wxPython prepares for being included
into the standard distribution.

What did you do?

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Try this

2005-07-24 Thread Michael Hoffman
RunLevelZero wrote:
 I'm not sure I understand your first question but checkout the  glob 
 module.  Sounds like it may help.

Who are you talking to? It would help if you quoted text from the 
original message, left some of the original subject, and replied to the 
original message instead of making a new post.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Initializing interactive Python

2005-07-24 Thread Tomasz Rola
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 24 Jul 2005 [EMAIL PROTECTED] wrote:

 Hi all,
 is it possible to enter an interactive session and automatically
 do some initialization?
 I explain better:
 I want that when I start interactive Python on a console (I use Linux)
 two command lines be executed automatically:

I did this by using python's -i option. Under Unix/Linux environment,
you can set up a script like this:

-  cut - cut - cut ---
#!/usr/bin/python -i

# init interactive session

import someutils
someutils.init()

import sys

from blah.blaaah.blah import *

print Hello there

# Now it's ready and shows you a prompt, so you can abuse it freely ;)

- --- paste - paste - paste -

It should be possible to write similar script under any other sufficiently
developed OS. After executing a script, you are presented a prompt from
properly (i.e. the way you want it) initialised interpreter.

Regards,
Tomasz Rola

- --
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did rm -rif on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:[EMAIL PROTECTED] **


-BEGIN PGP SIGNATURE-
Version: PGPfreeware 5.0i for non-commercial use
Charset: noconv

iQA/AwUBQuP75RETUsyL9vbiEQKtWgCgpIJS9nWo9tEf01QZACnoyCN5oSgAmgO0
a5+6CQiqEeT+58p/WZgjmlmw
=NVnJ
-END PGP SIGNATURE-


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


Re: Getting a dictionary from an object

2005-07-24 Thread Bruno Desthuilliers
*Grandmaster* Steven Bethard a écrit :

 How about something like:
 dict((name, getattr(obj, name)) for name in dir(obj))
 

...

voiceless-ly'rs
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run python script in background after i logout

2005-07-24 Thread James David

Harlin Seritt [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I have a remote linux server where I can only access it via ssh. I have
 a script that I need to have run all the time. I run like so:

 python script.py 

 It runs fine. When I log off ssh I notice that the script died when I
 logged off. How do I make sure it stays running?

It sounds like you want to run your script as a daemon.

There are ways to do this and it is more of a *nix issue, but google
python and run as a daemon. Also check out the createDaemon() function.


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


Re: consistency: extending arrays vs. multiplication ?

2005-07-24 Thread Carl Banks


Soeren Sonnenburg wrote:
 On Sun, 2005-07-24 at 13:36 +1000, Steven D'Aprano wrote:
  On Sat, 23 Jul 2005 18:30:02 +0200, Soeren Sonnenburg wrote:
 
   Hi all,
  
   Just having started with python, I feel that simple array operations '*'
   and '+' don't do multiplication/addition but instead extend/join an
   array:
 
  * and + are not array operations, they are list operations.
 
  Lists in Python can contain anything, not just numeric values.

 That seems to be *the point*. Although list(a) + list(b) could create a
 list [ a[0]+b[0], ...] and bail out if for elements '+' is not
 defined...

  Python doesn't have built-in mathematical arrays, otherwise known as
  matrices. There are modules that do that, but I haven't used them. Google
  on Numeric Python.

 Well I am aware of that but I don't understand the reasons of having
 both lists (which are infect arrays) and *arrays ? *I* would rather drop
 '+' and '*' to work like they do in *array ...


The number of programmers who do operations on mathematical arrays is
pretty small.  The number of programmers who need to do things like
concatenate lists is much larger.  Thus, the decision was made to use
the valuable operator for the more common thing.

Truth be told, I rarely use + on lists (I tend to use list.extend
mostly), and if + had instead been used for element-by-element
operations, I don't think it would have affected the overall quality of
Python too much.  But, as it's been said, it's a little late to change
it now.


-- 
CARL BANKS

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


Re: [path-PEP] Path inherits from basestring again

2005-07-24 Thread Michael Hoffman
Reinhold Birkenfeld wrote:

 I'm in no way the last instance on this.
 For example, everyone with CVS access is free to change the files ;)

I don't have CVS write access :(, so I'll have to keep kibitzing for now.

 Honestly, I'm in constant fear that allowing too much and loading too much
 features won't increase the acceptance of python-dev wink

What do you mean by this? To me code like this:

if _base is str:
 def __eq__(self, other):
 return isinstance(other, Path) and _base.__eq__(self, other)
[...]
else:
 # Unicode has no rich compare methods
 def __cmp__(self, other):
 if isinstance(other, Path):
 return _base.__cmp__(self, other)
 return NotImplemented

is the feature that you do not need: the feature of not returning True. 
You don't need this feature, and I consider it to be harmful. It breaks 
duck-typing unnecessarily, and means that people who want to use some 
other path library, or just str/unicode as they do today cannot compare 
those paths against stdlib Paths.

We should retain the design principle of the original path.py that Path 
objects should be drop-in replacements for the str or unicode objects 
they replace, as much as possible. We cannot predict all the things 
people are doing with strings today, and attempting to do so can only 
lead to bugs.

In the current implementation, the only cases where a path object cannot 
be used as a drop-in replacement for a string are (a) some extension 
modules, and (b) code that tests the object class using type() instead 
of using isinstance(). I think these are unavoidable but other 
incompatibilities, like changing the semantics of comparisons or join() 
are avoidable.

I've started a Wiki page for design principles and discussion here:

http://wiki.python.org/moin/PathClass
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [path-PEP] Path inherits from basestring again

2005-07-24 Thread Andrew Dalke
Reinhold Birkenfeld wrote:
 Okay. While a path has its clear use cases and those don't need above methods,
 it may be that some brain-dead functions needs them.

brain-dead?

Consider this code, which I think is not atypical.

import sys

def _read_file(filename):
  if filename == -:
# Can use '-' to mean stdin
return sys.stdin
  else:
return open(filename, rU)


def file_sum(filename):
  total = 0
  for line in _read_file(filename):
total += int(line)
  return total

(Actually, I would probably write it

def _read_file(file):
  if isinstance(file, basestring):
if filename == -:
  # Can use '-' to mean stdin
  return sys.stdin
else:
  return open(filename, rU)
  return file

)

Because the current sandbox Path doesn't support
the is-equal test with strings, the above function
won't work with a filename = path.Path(-).  It
will instead raise an exception saying
  IOError: [Errno 2] No such file or directory: '-'

(Yes, the code as-is can't handle a file named '-'.
The usual workaround (and there are many programs
which support '-' as an alias for stdin) is to use ./-

% cat  './-'
This is a file
% cat ./-
This is a file
% cat -
I'm typing directly into stdin.
^D
I'm typing directly into stdin.
% 
)


If I start using the path.Path then in order to use
this function my upstream code must be careful on
input to distinguish between filenames which are
really filenames and which are special-cased pseudo
filenames.

Often the code using the API doesn't even know which
names are special.  Even if it is documented,
the library developer may decide in the future to
extend the list of pseudo filenames to include, say,
environment variable style expansion, as
  $HOME/.config

Perhaps the library developer should have come up
with a new naming system to include both types of
file naming schemes, but that's rather overkill.

As a programmer calling the API should I convert
all my path.Path objects to strings before using it?
Or to Unicode?  How do I know which filenames will
be treated specially through time?

Is there a method to turn a path.Path into the actual
string?  str() and unicode() don't work because I
want the result to be unicode if the OSPython build
support it, otherwise string.

Is that library example I mentioned brain-dead?
I don't think so.  Instead I think you are pushing
too much for purity and making changes that will
cause problems - and hard to fix problems - with
existing libraries.



Here's an example of code from an existing library
which will break in several ways if it's passed a
path object instead of a string.  It comes from
spambayes/mboxutils.py

#

This is mostly a wrapper around the various useful classes in the
standard mailbox module, to do some intelligent guessing of the
mailbox type given a mailbox argument.

+foo  -- MH mailbox +foo
+foo,bar  -- MH mailboxes +foo and +bar concatenated
+ALL  -- a shortcut for *all* MH mailboxes
/foo/bar  -- (existing file) a Unix-style mailbox
/foo/bar/ -- (existing directory) a directory full of .txt and .lorien
 files
/foo/bar/ -- (existing directory with a cur/ subdirectory)
 Maildir mailbox
/foo/Mail/bar/ -- (existing directory with /Mail/ in its path)
 alternative way of spelling an MH mailbox

  

def getmbox(name):
Return an mbox iterator given a file/directory/folder name.

if name == -:
return [get_message(sys.stdin)]

if name.startswith(+):
# MH folder name: +folder, +f1,f2,f2, or +ALL
name = name[1:]
import mhlib
mh = mhlib.MH()
if name == ALL:
names = mh.listfolders()
elif ',' in name:
names = name.split(',')
else:
names = [name]
mboxes = []
mhpath = mh.getpath()
for name in names:
filename = os.path.join(mhpath, name)
mbox = mailbox.MHMailbox(filename, get_message)
mboxes.append(mbox)
if len(mboxes) == 1:
return iter(mboxes[0])
else:
return _cat(mboxes)

if os.path.isdir(name):
# XXX Bogus: use a Maildir if /cur is a subdirectory, else a MHMailbox
# if the pathname contains /Mail/, else a DirOfTxtFileMailbox.
if os.path.exists(os.path.join(name, 'cur')):
mbox = mailbox.Maildir(name, get_message)
elif name.find(/Mail/) = 0:
mbox = mailbox.MHMailbox(name, get_message)
else:
mbox = DirOfTxtFileMailbox(name, get_message)
else:
fp = open(name, rb)
mbox = mailbox.PortableUnixMailbox(fp, get_message)
return iter(mbox)



It breaks with the current sandbox path because:
  - a path can't be compared to -
  - range isn't supported, as name = name[1:]

note that this example uses __contains__ (, in name)


Is this function brain-dead?  Is it reasonable that people might
want to pass a path.Path() directly to it?  If not, what's
the way 

Getting the --options of configure on installed python

2005-07-24 Thread Thanos Tsouanas
Hello!

Is there a way to get the --options with which python was configured on
a system?

Thanks in advance.

-- 
Thanos Tsouanas  .: My Music: http://www.thanostsouanas.com/
http://thanos.sians.org/ .: Sians Music: http://www.sians.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Path inherits from basestring again

2005-07-24 Thread Carl Banks
Reinhold Birkenfeld wrote:
 Peter Hansen wrote:
  Reinhold Birkenfeld wrote:
  One thing is still different, though: a Path instance won't compare to a 
  regular
  string.
 
  Could you please expand on what this means?  Are you referring to doing
   and = type operations on Paths and strings, or == and != or all those
  or something else entirely?

 All of these. Do you need them?

[snip]

 At the moment, I think about overriding certain string methods that make
 absolutely no sense on a path and raising an exception from them.


Ick.  This reeks of the sort of hubris from people who think they
anticipate all valid uses of something.

Is it a basestring or not?  If it is, then let it be a basestring.  It
is unreasonable to want to format a pathame for printing?  We might
want to retain ljust and friends.  Maybe there's a filenaming scheme
where files are related by having a character changed here or there.
So we might want to iterate though the characters in a pathname.  How
do you know how people are going to use it?  We're all supposed to be
adults here.

Let me suggest that wanting to remove all these methods/operations
suggests that one doesn't really think it ought to be a basestring.
The way I see it, the only compelling reason for it to be a basestring
is to accommodate poorly designed functions that test whether an
argument is a filename or a file object using isinstance(basestring,x)
on it.  But the best thing to do is fix those interfaces, and let path
be what it should be, and not a hack to accommodate poor code.


-- 
CARL BANKS

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


Re: consistency: extending arrays vs. multiplication ?

2005-07-24 Thread Christopher Subich
Soeren Sonnenburg wrote:
 On Sat, 2005-07-23 at 23:35 +0200, Marc 'BlackJack' Rintsch wrote:
Both operate on the lists themselves and not on their contents.  Quite
consistent if you ask me.

 But why ?? Why not have them operate on content, like is done on
 *arrays ?

Because they're lists, not arrays.  What do you propose that the 
following do:

[1,2,3] + [4,5,6]
[1,2] + [3,4,5]
[1,2] + [{3:4,5:6}]
dict_var_1.keys() + dict_var_2.keys()
[g(3) for g in [f1 f2 f3] + [f4 f5 f6]]

I point out that the idiom is list + list, not numbers + 
numbers.  Operations on lists must deal with them as lists, not lists 
of any specific type.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting the --options of configure on installed python

2005-07-24 Thread gene tani
look in distutils.cfg:

http://www.python.org/doc/2.4.1/inst/config-syntax.html

for modules compiled in, sys.builtin_module_names

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


Re: PyGTK or wxPython (not a flame war) on Windows

2005-07-24 Thread Bryan
Torsten Bronger wrote:
 
 Besides, wxPython prepares for being included
 into the standard distribution.
 

wow, i've never heard this said so explicitly.  is there a reference link 
backing up this statement?  i really really hope this is true.  i'm very much 
in 
favor to see wx included in the standard distrubution.

bryan

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


Re: return None

2005-07-24 Thread Repton
geon wrote:
 Ximo wrote:
  Can I do a function which don't return anything?
 Nothing is None, or isnt?

A woodman was carrying a sack full of chopped wood on his back. His
sack was heavy and filled beyond its limit. The man, bent under his
bulky burden, was struggling not to drop any of the wood pieces as he
walked. However, the poor man couldn't avoid tripping over a stone on
the road and half of his load fell out of their precarious pile.
Another man happened to be passing by and saw the mishap.

`If I load those fallen pieces of wood back into your back sack, what
would you give me?' he asked.

`Nothing.' said the man carrying the wood.

`That's acceptable.' agreed the other man. He collected all the chopped
wood scattered on the road and crammed them back into the sack of the
woodman. When done, he asked for his payment. The woodman was baffled.

`I told you, I would give you nothing.' he said.

`Yes. And that's what I want. Nothing.' said the other, `Give me my
nothing!'

After some quarrel, the two men decided to let the qadi solve their
problem. Nasreddin Hodja was on duty at the time. He listened to both
men earnestly. Then he addressed the man who was expecting his payment
of nothing.

`My dear fellow, could you please lift the far right corner of that rug
on the floor and check what is underneath?' The man did as he was told
and looked under the rug.

`What do you see?' asked the Hodja.

`Nothing.' said the man.

'Well, there's your payment.' said the Hodja. 'Take it and go!'

-- 
John.

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


Simple Problem

2005-07-24 Thread ncf
I know I've seen this somewhere before, but does anyone know what the
function to escape a string is? (i.e., encoding newline to \n and a
chr(254) to \xfe) (and visa-versa)

Thanks for helping my ignorance :P

-Wes

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


Re: PyGTK or wxPython (not a flame war) on Windows

2005-07-24 Thread Peter Decker
On 7/24/05, Torsten Bronger [EMAIL PROTECTED] wrote:

 Is PyGTK more Pythonic by the way?  I had a look at wxPython
 yesterday and didn't like that it has been brought into the Python
 world nearly unchanged.  You can see its non-Python origin clearly.
 How does PyGTK feel in this respect?

There are several projects that have as their goal to wrap wxPython
and make it more Pythonic. IMO, the best choice now is Dabo, which is
being actively developed and improved. There is also Wax, which I got
interested a while ago, but it seems to be the work of a single author
who only works on it when he has a personal need.

I've been doing some development work in Dabo, even though I don't
currently need their database integration. The UI layer is very
Pythonic, and I much prefer writing code in Dabo than plain wxPython.
-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Problem

2005-07-24 Thread Cyril Bazin
By any chance are you speaking about the function repr ?
Cyril
On 24 Jul 2005 18:14:13 -0700, ncf [EMAIL PROTECTED] wrote:
I know I've seen this somewhere before, but does anyone know what thefunction to escape a string is? (i.e., encoding newline to \n and achr(254) to \xfe) (and visa-versa)Thanks for helping my ignorance :P
-Wes--http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Simple Problem

2005-07-24 Thread Paul Rubin
ncf [EMAIL PROTECTED] writes:
 I know I've seen this somewhere before, but does anyone know what the
 function to escape a string is? (i.e., encoding newline to \n and a
 chr(254) to \xfe) (and visa-versa)

repr(s)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Problem

2005-07-24 Thread Robert Kern
ncf wrote:
 I know I've seen this somewhere before, but does anyone know what the
 function to escape a string is? (i.e., encoding newline to \n and a
 chr(254) to \xfe) (and visa-versa)

In [1]: s = foo\n\xfe

In [2]: s.encode(string_escape)
Out[2]: 'foo\\n\\xfe'

In [3]: repr(s)[1:-1]
Out[3]: 'foo\\n\\xfe'

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die.
   -- Richard Harter

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


Re: Simple Problem

2005-07-24 Thread Jp Calderone
On 24 Jul 2005 18:14:13 -0700, ncf [EMAIL PROTECTED] wrote:
I know I've seen this somewhere before, but does anyone know what the
function to escape a string is? (i.e., encoding newline to \n and a
chr(254) to \xfe) (and visa-versa)

Thanks for helping my ignorance :P

Python 2.4.1 (#2, Mar 30 2005, 21:51:10) 
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type help, copyright, credits or license for more information.
 '\n\xfe'.encode('string-escape')
'\\n\\xfe'
 '\\n\\xfe'.decode('string-escape')
'\n\xfe'
 

  Introduced in Python 2.3

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


Re: Simple Problem

2005-07-24 Thread ncf
Thank you all for your replies. The repr() solution wasn't exactly what
I was looking for, as I wasn't planning on eval()ing it, but the
(en|de)code solution was exactly what I was looking for. An extended
thanks to Jp for informing me of the version compatibility :)

Have a GREAT day :)
-Wes

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


Re: return None

2005-07-24 Thread Christopher Subich
Repton wrote:
 'Well, there's your payment.' said the Hodja. 'Take it and go!'

+1: the koan of None

Upon hearing that, the man was enlightened.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what's wrong with my code using subprocess?

2005-07-24 Thread Tim Lesher
I see the same behavior as you do.  On Windows, the wait() isn't
hanging--what's happening is that the subprocess just never receives
anything.

I don't quite understand why, but it works fine when I change the if
clause in receiver.py to this:

if count = 1000:
p.communicate('exit')
p.wait()
break

Note the final break: if this isn't here, the next for iteration raises
an exception, as p.stdout has been closed by p.communicate.

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


  1   2   >