I hate to jump on this one a little late, but even getattr() is kind
of ghetto (though exec/eval is worse ;).
For setting up shell scripts or CLIs, the usual route is the optparse module.
- Japhy
2011/3/15 Yaşar Arabacı :
> Thanks for excellent explanations. I almost got this working. I just hav
Thanks for excellent explanations. I almost got this working. I just
have one more problem, that is:
When user enter incorrect number of arguments for a method, I naturally
get a type error. I could probably fix that with try and catch, but that
is not very explanatory to the user. Is there a
On 3/14/2011 8:49 PM, Yaşar Arabacı wrote:
As I try to implement things with getattr, I am getting a really
strange error. This is my file:
Various interspersed comments:
#!/usr/bin/env python
# -*- encoding:utf-8 -*-
class global_variables:
It is customary to start class names with an uppe
As I try to implement things with getattr, I am getting a really strange
error. This is my file:
#!/usr/bin/env python
# -*- encoding:utf-8 -*-
class global_variables:
"Holds class attributes, so that other classes can share them"
products = 0
best_bundle = []
class dispa
Yaşar Arabacı wrote:
And What I want to do is a small economy application. It will work this
way:
user add a product name, rate how much it like it over 10, and enter its
price.
[repeated as many times as wanted]
user will enter h(is|er) budget.
user will use "calcute bundle" to show much
Before being able to see 3rd answer, I did something like this and it
worked for me:
#!/usr/bin/env python
# -*- encoding:utf-8 -*-
def command_dispatcher():
"Takes comman line arguments and executes regardin method"
command = raw_input(">>>")
args = command.split(" ")
Prasad, Ramit wrote:
Take a look at:
http://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python
And then please don't do it. eval and exec should be treated as the last
resort, and then only if you really know what you are doing. They are
slow, and da
Yaşar Arabacı wrote:
Hi
I am trying to do something like this:
If you are trying to write a mini-language, the ``cmd`` and ``shlex``
modules in the standard library may be useful to you.
#!/usr/bin/env python
def command_dispatcher():
"Takes comman line arguments and executes regardi
: tutor-bounces+ramit.prasad=jpmchase@python.org
[mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] On Behalf Of Yasar
Arabaci
Sent: Monday, March 14, 2011 4:16 PM
To: tutor@python.org
Subject: [Tutor] How to use a str object, to find the class in exact name?
Hi
I am trying to do
Hi
I am trying to do something like this:
#!/usr/bin/env python
def command_dispatcher():
"Takes comman line arguments and executes regardin method"
command = raw_input(">>>")
args = command.split(" ")
args[0].args[1]
class calculate:
def bundle(self):
10 matches
Mail list logo