[issue14918] Incorrect explanation of TypeError exception

2012-05-25 Thread Thanos Tsouanas

New submission from Thanos Tsouanas tha...@sians.org:

# This correctly raises a type error, but the explanation
# that comes with it is bad:

def foo(x, y, z=28):
return

foo(x, z=8)

# TypeError: foo() takes at least 2 arguments (2 given)

--
messages: 161588
nosy: Thanos.Tsouanas
priority: normal
severity: normal
status: open
title: Incorrect explanation of TypeError exception
type: behavior
versions: Python 2.7, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14918
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Changing data of xhtml document

2005-08-13 Thread Thanos Tsouanas
Hello list!

I've got a unicode string which holds an xhtml website, begining with
!DOCTYPE ... and a functions which alters strings in a certain way.

I want to replace all actual data in this xhtml unicode string with the
function's output.  (By 'actual data' I mean anything that 

I thought I should use the XMLGenerator package, but first, I don't
like it's output, and second, it complaints about the !DOCTYPE ...
tag.  Also, it writes the ?xml ? tag which I want to avoid at this
stage.

Are there any really easy solutions to this problem?
Any modules that could be helpful for slight modification of such
sgmlish files?  The downside of SGMLParser is that I have to override
all parser functions to actually leave everything intact instead of
doing nothing and override characters(data) to print the altered data.

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: psp php integration

2005-07-25 Thread Thanos Tsouanas
On Mon, Jul 25, 2005 at 07:53:19PM +0100, Jon Hewer wrote:
 Hello,
 
 I am upgrading a PHP based site and want to use Python (using mod_python and
 psp file) to achieve what is required.  However, I do not want to recode the
 navigation part of the site which is currently coded using PHP.  Somehow I
 need to merge the outputs of the PHP file and my PSP file to create the HTML
 output which is sent to the browser.  Can this be done inside my PSP file?
 If not, is there any other way in Python (or PHP) to achieve this?

I have never used PSP, (I prefer old-time cgi's) but one *BAD* solution
is that you can open a local connection to your server asking for the
.php file through the psp file which should do the extra functionality,
or vice versa.

I _REALLY_ don't like that though...

-- 
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-25 Thread Thanos Tsouanas
On Sun, Jul 24, 2005 at 02:14:15PM -0600, Steven Bethard wrote:
 
 How about something like:
  dict((name, getattr(obj, name)) for name in dir(obj))

Pretty!!!

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

But not SQLObject's objects...
Any idea why? (Getting attribute errors, it seems that these
attributoids are not listed in dir(obj), so i have to use my ugly
dictobj class.. :(

-- 
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 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


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


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


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: 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


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


Getting a dictionary from an object

2005-07-23 Thread Thanos Tsouanas
Hello.

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?

Thanks in advance.

class dictobj(dict):

class dictobj(dict):
A dictionary d with an object attached to it,
which treats d['foo'] as d.obj.foo.

def __init__(self, obj):
self.obj = obj
def __getitem__(self, key):
return self.obj.__getattribute__(key)

-- 
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-23 Thread Thanos Tsouanas
On Sat, Jul 23, 2005 at 12:06:57PM +0200, Paolino wrote:
 use getattr(self.obj,key) possibly, as __getattribute__ gets total 
 control on attribute access

Thanks, but what do you mean by 'total control'?

-- 
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-23 Thread Thanos Tsouanas
On Sat, Jul 23, 2005 at 11:30:19AM +0200, Bruno Desthuilliers wrote:
 Thanos Tsouanas a écrit :
  class dictobj(dict):
  
  class dictobj(dict):
  A dictionary d with an object attached to it,
  which treats d['foo'] as d.obj.foo.
  
  def __init__(self, obj):
  self.obj = obj
  def __getitem__(self, key):
  return self.obj.__getattribute__(key)
 
 I'd replace this last line with:
return getattr(self.obj, key)
 
 Now given your specs, I don't see what's wrong with your solution.

I just dont want to use my class, if one already exists in the
libraries (or any other way to achieve the same thing), that's all ;)

Thanks for the tip.

-- 
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-23 Thread Thanos Tsouanas
On Sat, Jul 23, 2005 at 11:22:21PM +1000, Steven D'Aprano wrote:
 On Sat, 23 Jul 2005 11:48:27 +0300, Thanos Tsouanas wrote:
  Hello.
  
  I would like to have a quick way to create dicts from object, so that a
  call to foo['bar'] would return obj.bar.
 
 That looks rather confusing to me. Why not just call obj.bar, since it
 doesn't look like you are actually using the dictionary at all?
 
  [...]
 
 I don't think this is particularly useful behaviour. How do you use it?

print foo %do

where do is a dictobj object...

-- 
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


dictionary as property

2005-07-19 Thread Thanos Tsouanas
Hello.

(How) can I have a class property d, such that d['foo'] = 'bar' will run
a certain function of the class with 'foo' and 'bar' as it's arguments?

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: dictionary as property

2005-07-19 Thread Thanos Tsouanas
On Tue, Jul 19, 2005 at 07:00:10PM +0200, Gerhard Haering wrote:
 On Tue, Jul 19, 2005 at 07:56:20PM +0300, Thanos Tsouanas wrote:
  Hello.
  
  (How) can I have a class property d, such that d['foo'] = 'bar' will run
  a certain function of the class with 'foo' and 'bar' as it's arguments?
 
 You could implement a custom container type that will do what you want.
 See http://docs.python.org/ref/sequence-types.html for __setitem__.

Thanks, that doc had all I needed :)

-- 
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