[Tutor] Fwd: Newbie

2015-01-02 Thread Rohan Ds
-- Forwarded message --
From: "Rohan Ds" 
Date: 2 Jan 2015 23:46
Subject: Newbie
To: 
Cc:

Hello everybody :)
I am Rohan from India. I'm new to Python. I have a basic understanding as
to how Python works. I want to contribute to PSF. The information available
on the site didn't really answer my questions.
If anyone here could tell me, how I should get started with it, I'd be
really grateful to you. Also, with GSoC coming up, if i keep contributing
dedicatedly to PSF, will I have a shot at GSoC? Someone please reply asap.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] commands module

2007-12-06 Thread ds
Evert Rol wrote:
>> So, I tried setting COLUMNS equal to 500 (arbitrarily large) prior to
>> going into python.  It seems to change back to 158 automatically
>> however.
>> For example, when I go into python, import commands, and execute
>> commands.getoutput('set') I find that COLUMNS is back to 158.  So, I
>> think my problem is that I don't know how to alter the set variable so
>> that it will stick long enough for the "ps ax" command to execute
>> properly.
>
> I've had this problem before (setting/altering shell variables when
> executing a command from Python, albeit using os.system() instead).
> What I'd use is:
> commands.getoutput('COLUMNS=500 ps ax')
> or similar. In your case, you've been able to solve in another way
> (and better, since environment independent, though still
> shell/ps-variant dependent), but sometimes one may need to set/change
> shell variables, like paths to dynamic libraries. The above should
> work (for more variables, just specify them all before the actual
> command, whitespace separated).
>
>
Thank you for mentioning that.  I'm pretty weak on bash, and had
monkeyed around with such things as set COLUMNS=500 on the previous line
in the shell program version, but hadn't actually looked up that syntax
yet, when I stumbled across the ps parameter that eventually I selected.

Thanks again.

ds
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] commands module (Forwarded back to list)

2007-12-06 Thread ds
Evert Rol wrote:

>> >> I've been trying to do something that I thought was going to be
>> >> relatively straight-forward, but so far I haven't found a good solution.
>> >>
>> >> What I'm trying to do is discover a pid on a process and kill it.  The
>> >> way that I thought that I could do it is something along the lines of:
>> >>
>> >> import commands
>> >>
>> >> program = "someprogram"
>> >>
>> >> a = commands.getoutput('ps ax|grep %s ' % (program))
>> >>
>> >> Then, I'd parse the returned info get the pid and kill it, probably via
>> >> another command.
>> >>
>> >> However, what happens is that the "ps ax" portion truncates the listing
>> >> at 158 characters.  It just so happens that the unique name that I need
>> >> in the list comes after that.  So, works from the bash shell, but
>> >> doesn't work using getoutput.
>> 
> >
> > What's the result of getoutput(); ie, what is a?
> > Note that bash and commands.getoutput() are not the same, since the
> > latter executes 'sh -c', which is slightly different. I don't expect
> > that'll solve your problem.
> > Does the -w option help? I'm guessing it won't, since the truncation
> > seem to be due to some odd character causing an EOF or something (I
> > tried myself here, both on Linux & OS X, without problems).
> >
> >   Evert
>   


I accidentally sent this directly rather than to the list:

Thanks for your reply.  When I said 158 characters I was trying to say
each _line_ of the shell command "ps ax" was truncated to 158
characters, not that the _total_ returned was 158. 

Your question got me thinking about it, and I found in my set variables:
COLUMNS=158, which corresponds pretty well.
So, I tried setting COLUMNS equal to 500 (arbitrarily large) prior to
going into python.  It seems to change back to 158 automatically however.
For example, when I go into python, import commands, and execute
commands.getoutput('set') I find that COLUMNS is back to 158.  So, I
think my problem is that I don't know how to alter the set variable so
that it will stick long enough for the "ps ax" command to execute properly.


==
End of forwarded message part.


Finally, I have solved the problem, because I discovered a width option on the 
ps command, which I hadn't been aware of before.

For example:

commands.getstatusoutput('ps ax -l --width 500')

works very well by over-riding any defaults.

Thanks for your help.

ds




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] commands module

2007-12-06 Thread DS
I've been trying to do something that I thought was going to be
relatively straight-forward, but so far I haven't found a good solution.

What I'm trying to do is discover a pid on a process and kill it.  The
way that I thought that I could do it is something along the lines of:

import commands

program = "someprogram"

a = commands.getoutput('ps ax|grep %s ' % (program))

Then, I'd parse the returned info get the pid and kill it, probably via
another command.

However, what happens is that the "ps ax" portion truncates the listing
at 158 characters.  It just so happens that the unique name that I need
in the list comes after that.  So, works from the bash shell, but
doesn't work using getoutput.

I have also tried variations on a theme.  For example, I created a shell
file and tried to route into a file:
ps ax|grep my_program_name > ps.output

No luck.

Do you have any suggestions?



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] exec, execfile, rexec

2006-02-14 Thread DS
Danny Yoo wrote:

>>I hate to admit it, but there are times when fear should be listened to,
>>and I think this is one of them.  So, I guess I'll move on to parsing it
>>myself.  Seems a shame though.
>>
>>
>
>Hi DS,
>
>Yeah, I'd recommend listening to fear.  *grin* Python's a powerful
>language, and I'd recommend erring on the side of caution here.
>
>
>By the way, if you have a lot of time on your hands and are of a CS bent,
>you might find the following PDF book interesting:
>
>http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/
>
>  
>
Thanks, I'm downloading it now.  Not sure about the "lot of time my
hands" part, but I'll try to learning something from it. 

Thanks

ds
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] exec, execfile, rexec

2006-02-14 Thread DS
Kent Johnson wrote:

>It is very challenging to even come close to safety. If you search 
>comp.lang.python for eval or exec you will find many discussions of 
>this. For example
>http://groups.google.com/group/comp.lang.python/browse_frm/thread/cf6093c5551a6587/23ddf23a6dfc3e11?q=eval&rnum=1#23ddf23a6dfc3e11
>
>One approach is to use the compiler module to parse the input data and 
>write a custom visitor for the parse tree that only allows 'safe' parse 
>elements to be processed. There is some discussion here:
>http://groups.google.com/group/comp.lang.python/browse_frm/thread/d5f4d7e2c397c2ca/5d1af7f9c7b1789b?q=python+compiler+safe+eval&rnum=1#5d1af7f9c7b1789b
>
>  
>
Thanks for the references.  I played with the parse tree yesterday a
little bit, for which I now have a little bit more understanding, since
I implemented my own extremely primitive version.  It had seemed like I
ought to be able to take advantage of it, if I had an adequate stop list.

>There is also a hack that provides an empty __builtin__ namespace to 
>eval which prevents at least naive attempts at hacking.
>
>Bottom line - it's a very hard problem which I don't think anyone has 
>solved to the satisfaction of all observers, though there are limited 
>solutions which some people find acceptable.
>
>  
>

Terry Carroll wrote:

>On Tue, 14 Feb 2006, Kent Johnson wrote:
>
>  
>
>>Bottom line - it's a very hard problem which I don't think anyone has 
>>solved to the satisfaction of all observers, though there are limited 
>>solutions which some people find acceptable.
>>
>>
>
>I think it's telling that the restricted execution modules, rexex and
>Bastion, became disabled as of python 2.3; that gives an indication of how
>difficult a problem it is to fix.
>
>http://www.python.org/doc/lib/restricted.html
>
>  
>
I hate to admit it, but there are times when fear should be listened to,
and I think this is one of them.  So, I guess I'll move on to parsing it
myself.  Seems a shame though.

ds


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] exec, execfile, rexec

2006-02-14 Thread DS
I have been writing a web-based application in which users would be able
to input expressions which would be evaluated on the server.  I had read
about the dangers of using eval for such things, and so I parse the
expressions myself, and calculate the expressions using my own code. 
This wasn't too bad, because that gave me a chance to learn about
parsing expressions, AST, and other aspects of coding that I wasn't
particularly familiar with.  If that was all I needed to do, my code
seems adequate for this purpose. 

Now, I've been starting to think about adding multiline expressions, or
really, at this point, programs.  I don't think it would be all that bad
to implement some simple structure for doing that, but I can't help but
think that it  would make more sense to simply use Python directly.  Not
only is it already implemented, but I certainly like to use it, and it
might promote the use of Python just a bit more. 

Is this simply such a bad idea that I should not even consider it?  Is
there a way that I can limit usage by filtering all programs for
operating system calls, certain imports, maybe not allowing lambdas?  I
would hate to get compromised in some way that I don't understand.

Thanks for any guidance.

ds
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CPU Utilization]

2006-01-12 Thread DS

Alan Gauld wrote:

>> shell out to perform the top command, parse the results, and report
>> those values to the job controller.
>
>
> I'd use vmstat rather than top since top is intended to run
> contuinuously whereas vmstat by default just returns a single line
> snapshot.
>
> I don't know of any native python mechanism for obtaining cpu usage.
>
> Alan G


vmstat is a beautiful thing.  Although as I mentioned in reply to others
who responded to my question that top can run just once, top actually
provides much more information than I am intending to use, making it
seem a little wasteful.  vmstat is much more focused on exactly the
information I want.  Although I am using linux pretty much exclusively
these days, there's still a lot that I don't know and I wasn't aware
that it existed.

Thanks

ds


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CPU Utilization

2006-01-12 Thread DS
Nico wrote:

> I think that libgtop and its python binding (used in gdesklets for
> example) would do the trick.
>
Thank you for your thoughts on that.  I think in other applications this
might have a shot.  In this situation I am using diskless workstations
with minimal configurations, so gnome libraries will not be an option. 

At this point I'm going to go with vmstat.

Thanks

ds
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CPU Utilization

2006-01-11 Thread DS
Thanks for your responses.

Michael Janssen wrote:

>It's perhaps easier to read the information from the /proc filesystem
>(this is where top gets it itself). "man proc" tells where the info is
>stored (guess: /proc/stat).
>
>  
>
stat does look in some ways easier.  I will say that I found the
statistics somewhat baffling, but I'm sure it's all there.


Hugo González Monteverde wrote:

>Hi,
>
>top is very interactive so it would not be easy at all to parse.
>
>  
>
Actually top has a batch mode.  This works pretty well.

*def* xmlrpc_idlecpu(self):
u = commands.getoutput('top -b -n 1')
*return* u.split('\n')[2].split(',')[3]

>I can suggest reading /proc/loadavg if you're in Linux.
>
>proc(5) ('man 5 proc') says that /proc/loadavg is
> The load average numbers give the number of jobs in
> the run queue averaged over 1, 5 and 15 minutes.
> They are the same as the load average numbers given
> by uptime(1) and other programs.
>
>It can be easily parsed with split()
>  
>
That's an interesting idea to use that.  Although if you have big jobs
and little jobs you might not know whether you can add another job to
that computer or not, because you would necessarily be attempting to
derive the utilization from those statistics. 


Thank you both for your answers.

ds
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] CPU Utilization

2006-01-11 Thread DS
I am implementing a computational cluster and am using a job controller
(for want of a better term) that contacts the worker computers,
determines how busy they currently are, and then assigns more work if
the worker computer is below a certain cpu utilization threshhold. 

For the cpu threshhold, I've been thinking I'd have the worker computer
shell out to perform the top command, parse the results, and report
those values to the job controller.

Is there a better way, or more pythonic, way to do this?

Thanks

ds
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] dictionary question

2005-11-11 Thread DS
You almost have it. Do this instead.

d = {'first':[]}
d['first'].append("string")

Append acts on the list, so assignment is unnecessary.

ds

Eric Walker wrote:

>All,
>I have a dictionary say:
>d = {'first':[]}
>I am going through another list and depending on whats going on,
>I want to add to the empty list. I have tried the following to noavail.
>
>d['first'] = d['first'].append("string")
>
>I would think this would result in the dictionary key first's empty list  to 
>become ["string"].  can anyone help clear my head?
>
>Thanks...
>
>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>  
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Object instances

2005-11-07 Thread DS
All right!  That's penetrated.  Thanks very much.

ds
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Object instances

2005-11-06 Thread DS
I had thought I was developing a clue regarding objects in Python, but I
ran across an oddity today that I didn't expect.  It had seemed to me
that once an instance was created, it would have a separate data pool
from any other instance of the same object.  It would share methods, of
course, but the data assigned to it would be totally separate.  After
running into peculiar errors I now see how this is not totally true, but
I would like to understand why not.  I think I'm missing something kind
of fundamental here.

The following is my toy example:


In [1]: class test(object):
   ...: testlist = []
   ...:

In [2]: c1 = test()

In [3]: c1.testlist.append(0)

In [4]: c2 = test()

In [5]: c2.testlist
Out[5]: [0]

In this example, I create two instances of the object test, assigned
data to c1.testlist and it shows up in the other instance, c2. 
Typically, I have been assigning values within an object from being
passed in via __init__, but it seemed like it wasn't really necessary
for this particular kind of object.  In my next example, I show the
creation of testlist via an __init__ and all goes as I expected.


In [10]: class test(object):
   : def __init__(self):
   : self.testlist = []
   :

In [11]: c1 = test()

In [12]: c2 = test()

In [13]: c1.testlist.append(0)

In [14]: c2.testlist
Out[14]: []

So, I can see the error of my ways.  I can also see that this behavior
gives me an opportunity to globally change a value in all of the object
instances, if I ever had to do something like that.  I just don't have a
clue as to why objects were designed this way.

Can anyone point me in the right direction?

Thanks

ds




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] call a def/class by reference

2005-09-29 Thread DS
Alan G wrote:

>> I'm actually pretty surprised that there isn't a built-in facility with
>> Python for referencing functions like this.
>
>
> I'm not. In fact its pretty unusual in any language to try to map
> from function name to function directly. Dictionaries are the
> universal solution for this, I can only think of a handful(4?)
> languages that I've used (Out of 20 plus) that can do
> string -> function mapping directly.
>
> Its not usually a very useful thing to do - how would the
> typical user know what the function names were? Either the
> user has access to the code or the code presents the names
> to the user(as strings) in which case a mapping has to
> exist somewhere already.
>
> I'm curious as to how you are addressing those issues?
> Is this something that only developers will be using?
> How will the user know what names are possible?
>
> Alan G.


I am playing with building a facility that accepts equations or
expressions that are parsed and solved.  I hope to use this with genetic
algorithms that would create mostly useless expressions, but that over
time might become better.  If I was doing it for users building
expressions, I'd probably do a javascript kind of approach for
assembling expressions from lists.  Your point is well taken, because
I'm often awed at the amazing ly stupid errors that I make when I'm
typing. 

Rest assured, I don't know 20 languages, computer or otherwise.  I know
that I used some sort of thing like that in the 80's with Revelation, a
database/language derived from Pick.  (That one is probably a little
obscure, it may not be on your list of 20).  I also think you can do
that in Perl, but bear in mind I know less about Perl than I do Python.

ds
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] call a def/class by reference

2005-09-29 Thread DS
Danny Yoo wrote:

>>>From what I've read so far, globals are actively discouraged.  A class
>>seems like the best approach.
>>
>>I'm actually pretty surprised that there isn't a built-in facility with
>>Python for referencing functions like this.  In reading Python in a
>>Nutshell, prior to asking my questions here, I had thought that there
>>probably was, but I just wasn't grasping it.
>>
>>
>
>
>Hi DS,
>
>
>Modules can be thought of as containers for functions.  As a concrete
>example, let's say we have a module named 'functions':
>
>##
># in functions.py
>def A(): print "A"
>
>def B(): print "B"
>
>def C(): print "C"
>##
>
>
>In other programs, this 'functions' module can be imported and dir()ed:
>
>##
>  
>
>>>>import functions
>>>>dir(functions)
>>>>
>>>>
>['A', 'B', 'C', '__builtins__', '__doc__', '__file__', '__name__']
>##
>
>
>There are our attributes of the 'functions' module.  Those functions in
>the module can also be called:
>
>##
>  
>
>>>>getattr(functions, 'A')
>>>>
>>>>
>
>  
>
>>>>getattr(functions, 'A')()
>>>>
>>>>
>A
>##
>
>
>I'm not exactly sure if this is what you want, but this shows a simple way
>to highlight a selection of functions, by using a module as the container.
>
>
>Best of wishes!
>
>  
>
Ok!!!   This is exactly it.  Thanks so much.  This provides the link
between a string that represents a function to the actual calling of
that function with getattr().  I was just reading up on the getattr()
because it was in used in Bob's answer, when your email came through.

Thanks so much to all of you that have answered my questions, including 
Liam.Clarke-Hutchinson, whom I didn't acknowledge directly with an
email.  I hope I'm not asking too many questions.  This is kind of a
departure for me.  Usually, I just bang my head against the wall till I
break through.  At some point I hope to get to a point where I can
provide answers for others who are just learning as well.

ds


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] call a def/class by reference

2005-09-29 Thread DS
bob wrote:

> At 08:23 AM 9/29/2005, DS wrote:
>
>> bob wrote:
>>
>> > At 04:29 PM 9/28/2005, DS wrote:
>> >
>> >> What I'm hoping to avoid is an
>> >> explicit reference to any of the called functions within the program.
>> >> By doing it that way, it would avoid a maintenance problem of
>> having to
>> >> remember to put a reference for every new function in the calling
>> >> program.
>> >
>> >
>> > Try this - a class in which you define all the functions. The __init__
>> > method builds the dictionary.
>> >
>> > >>> class X:
>> > ... funcs = {}
>> > ... def y(self):
>> > ... pass
>> > ... def __init__(self):
>> > ... for itemname in dir(self):
>> > ... if not itemname.startswith('__'):
>> > ... item = getattr(self, itemname)
>> > ... if callable(item):
>> > ... self.funcs[itemname] = item
>> > ...
>> > >>> y = X()
>> > >>> y.funcs
>> > {'y': >}
>> >
>>
>>
>> Thanks bob, that's an interesting approach.  That would be one huge
>> class.
>
>
> Well if you have lots of functions you will have one *huge* module.
> The additional class stuff is minor.
>
I agree.  My first thought when I saw that was that it would be a memory
issue, but then as I sat and thought about it, it I couldn't really tell
if it was any different than a huge module.  One thing I don't have
experience with yet is the amount of memory taken when an instance of
the object is created.  For example, does it use substantially more
memory if there are a bunch of if, elif clauses (representing the unused
functions within the class)?  I'll monkey around with it and see what I get.

> Also note that you can accomplish a similar thing by defining the
> functions outside any class and then finding them in globals(). Having
> said that I like the class approach in that it becomes a container for
> the functions you want to expose and other functions defined outside
> the class will be ignored.

>From what I've read so far, globals are actively discouraged.  A class
seems like the best approach. 

I'm actually pretty surprised that there isn't a built-in facility with
Python for referencing functions like this.  In reading Python in a
Nutshell, prior to asking my questions here, I had thought that there
probably was, but I just wasn't grasping it.

Thanks.

ds




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] call a def/class by reference

2005-09-29 Thread DS
bob wrote:

> At 04:29 PM 9/28/2005, DS wrote:
>
>> What I'm hoping to avoid is an
>> explicit reference to any of the called functions within the program.
>> By doing it that way, it would avoid a maintenance problem of having to
>> remember to put a reference for every new function in the calling
>> program.
>
>
> Try this - a class in which you define all the functions. The __init__
> method builds the dictionary.
>
> >>> class X:
> ... funcs = {}
> ... def y(self):
> ... pass
> ... def __init__(self):
> ... for itemname in dir(self):
> ... if not itemname.startswith('__'):
> ... item = getattr(self, itemname)
> ... if callable(item):
> ... self.funcs[itemname] = item
> ...
> >>> y = X()
> >>> y.funcs
> {'y': >}
>   


Thanks bob, that's an interesting approach.  That would be one huge class.

ds
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] call a def/class by reference

2005-09-28 Thread DS

Danny Yoo wrote:

>  
>
>>Thanks for answering my question.  What I'm hoping to avoid is an
>>explicit reference to any of the called functions within the program.
>>By doing it that way, it would avoid a maintenance problem of having to
>>remember to put a reference for every new function in the calling
>>program.
>>
>>
>
>
>In your list of requirements:
>
>  
>
>>   1.  gettting the input that consists of a function and its
>>   parameters,
>>   2.  determining if the function is on an approved function list,
>>   3.  executing the function
>>   4.  rinse, repeat.
>>
>>
>
>the second one is probably the one that needs clarifying.
>
>How do you know which functions should be callable? Adam's approach to
>expressing that knowledge is to use a dictionary:
>
>d = {"foo" : foo}
>
>And there are many other ways of doing this besides a hardcoded
>dictionary.
>
>Tell us more about what you mean for a function to be "approved", and we
>should be able to suggest practical ways to do what you want.
>
>
>  
>
As far as an "approved" function, what I was imagining was something along
the lines of importing modules where all functions are callable such as

approvedlist = dir(mymodule)

which would give a list of names and then going from there.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] call a def/class by reference

2005-09-28 Thread DS
Thanks for answering my question.  What I'm hoping to avoid is an
explicit reference to any of the called functions within the program.  
By doing it that way, it would avoid a maintenance problem of having to
remember to put a reference for every new function in the calling program.

ds


Adam wrote:

> How about something like this
>
> def foo(bar):
> print bar
>
> d = {"foo":foo}
> s = "foo"
> params = "bar"
> try: d[s](params)
> except: KeyError
>
> Then you can just put the allowed functions into the dictionary.
>
> On 29/09/05, *DS* <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
>
> Is it possible to call a function or class by reference, aside from
> using an eval approach?
>
> What I would like to do is have a loop that processes functions by:
>
> 1.  gettting the input that consists of a function and its
> parameters,
> 2.  determining if the function is on an approved function list,
> 3.  executing the function
> 4.  rinse, repeat.
>
> I don't actually mind eval, but I would want to make sure I inspect
> everything pretty thorougly before executing.
>
> Thanks for any help you can give me.
>
> ds
> ___
> Tutor maillist  -  Tutor@python.org <mailto:Tutor@python.org>
> http://mail.python.org/mailman/listinfo/tutor
> <http://mail.python.org/mailman/listinfo/tutor>
>
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] call a def/class by reference

2005-09-28 Thread DS
Is it possible to call a function or class by reference, aside from
using an eval approach?

What I would like to do is have a loop that processes functions by:

1.  gettting the input that consists of a function and its parameters,
2.  determining if the function is on an approved function list,
3.  executing the function
4.  rinse, repeat.

I don't actually mind eval, but I would want to make sure I inspect
everything pretty thorougly before executing.

Thanks for any help you can give me.

ds
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error frameworks

2005-09-21 Thread DS
>>(Please reply to the tutor list, not to me privately)

whoops

>>Generally, you want to catch the exception at the level that knows what to do 
>>about it. Your function2() isn't handling the exception in any meaningful 
>>sense, it is just converting it to a magic return value. You might as well 
>>just use magic return values everywhere if you do this.

>>Even function1() seems like it is too low-level to handle the error since it 
>>is also just converting the error to a magic return.

>>For short, simple scripts you can often omit exception handling completely. 
>>Any raised exceptions will propagate to the interpreter which will print a 
>>stack trace and exit. This is very handy - you get to see exactly where the 
>>error occured and the details of the exception type and message. This style 
>>may also be appropriate for handling any fatal error even in a complex script.

>>For more complex scripts, for example a server or GUI app, or a script that 
>>processes many items, you probably don't want to exit the script on an error. 
>>In this case you might have a high-level exception handler that logs the 
>>exception and continues. For example here is a loop that processes a list of 
>>items, if there is an error processing an item a traceback is printed and the 
>>processing continues:



I think you are correct that I haven't been letting my raised errors propagate 
high enough.  That helps.  Thanks very much.

ds



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Error frameworks

2005-09-21 Thread DS

Hi

Is there any particular standard or approach that I should use for an
error framework?  For example, suppose I have a set of functions that
call one another, and an error is triggered.  I want an error message to
be passed back to the user, so I could:

 1. have an error message passed back to each called function until
it bubbles up to a point to be passed back to the user in some
meaningful way.

 2. have a singleton error object updated.

 3.  ??

What do most people use?  Is there any url that you could point me to
that would help educate me on this point?

Thanks

ds


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor