Re: [Tutor] How to use a str object, to find the class in exact name?

2011-03-14 Thread bob gailer
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

Re: [Tutor] Simplistic drive simulation

2011-03-14 Thread R. Alan Monroe
> "R. Alan Monroe" wrote >> Neither of these seem like they'd scale very well (say, up to the >> resolution of your screen, with one block per pixel). The end goal >> is >> just a basic do-nothing light show that simulates >> fragmentation/defragmentation as eye candy. > For that purpose the

Re: [Tutor] How to use a str object, to find the class in exact name?

2011-03-14 Thread Yaşar Arabacı
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

Re: [Tutor] How to use a str object, to find the class in exact name?

2011-03-14 Thread Steven D'Aprano
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

Re: [Tutor] How to use a str object, to find the class in exact name?

2011-03-14 Thread Yaşar Arabacı
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(" ")

Re: [Tutor] Reading in data files

2011-03-14 Thread Steven D'Aprano
Marc Tompkins wrote: On Mon, Mar 14, 2011 at 1:02 PM, Marc Tompkins wrote: On Mon, Mar 14, 2011 at 12:59 PM, paige crawford < plcrawf...@crimson.ua.edu> wrote: How do I split them by spaces? Google "Python split". That might have been a bit abrupt... but (in general) the Tutor list is happ

Re: [Tutor] How to use a str object, to find the class in exact name?

2011-03-14 Thread Steven D'Aprano
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

Re: [Tutor] How to use a str object, to find the class in exact name?

2011-03-14 Thread Steven D'Aprano
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

Re: [Tutor] How to use a str object, to find the class in exact name?

2011-03-14 Thread Prasad, Ramit
Take a look at: http://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -Original Message- From: tu

[Tutor] How to use a str object, to find the class in exact name?

2011-03-14 Thread Yaşar Arabacı
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):

Re: [Tutor] multiple if and or statement

2011-03-14 Thread bob gailer
On 3/14/2011 3:13 PM, Mike Franon wrote: Thank you everyone who responded, very fast responses I am impressed. OK now I see where I went wrong and had to do if (i == 'test1') or (i=='test2'): I guess I was thinking if I do a = ['test1', 'flag', 'monday'] for i in a: It would check each it

Re: [Tutor] multiple if and or statement

2011-03-14 Thread Emile van Sebille
On 3/14/2011 1:13 PM Mike Franon said... Thank you everyone who responded, very fast responses I am impressed. OK now I see where I went wrong Well, no, I don't think so. Your first test was: if i=='test1' or 'test2': which evaluates as true if _either_ i=='test1' _or_ 'test2' so, the fi

Re: [Tutor] multiple if and or statement

2011-03-14 Thread Mike Franon
Thank you everyone who responded, very fast responses I am impressed. OK now I see where I went wrong and had to do if (i == 'test1') or (i=='test2'): I guess I was thinking if I do a = ['test1', 'flag', 'monday'] for i in a: It would check each item in the list one at a time like a loop I

Re: [Tutor] Reading in data files

2011-03-14 Thread Marc Tompkins
On Mon, Mar 14, 2011 at 1:02 PM, Marc Tompkins wrote: > On Mon, Mar 14, 2011 at 12:59 PM, paige crawford < > plcrawf...@crimson.ua.edu> wrote: > >> How do I split them by spaces? >> >> Google "Python split". > > That might have been a bit abrupt... but (in general) the Tutor list is happy to help

Re: [Tutor] multiple if and or statement

2011-03-14 Thread Marc Tompkins
On Mon, Mar 14, 2011 at 12:41 PM, Mike Franon wrote: > HI, > > I had a question, when running this small snippet of test code: > > > > a = ['test1', 'flag', 'monday'] > > for i in a: >if i == 'test1' or 'test2': > print 'true' > > > It always prints true > > > $ ./testing.py > true > tr

Re: [Tutor] Reading in data files

2011-03-14 Thread Marc Tompkins
On Mon, Mar 14, 2011 at 12:08 PM, paige crawford wrote: > Hey, > > > How do I read in a data file that has comments then remove the comments to > get to the numbers? The numbers in the data file needs to be read into a > list. There are also comments next to the numbers. The file looks something >

Re: [Tutor] multiple if and or statement

2011-03-14 Thread Adam Bark
On 14/03/11 19:41, Mike Franon wrote: HI, I had a question, when running this small snippet of test code: a = ['test1', 'flag', 'monday'] for i in a: if i == 'test1' or 'test2': print 'true' It always prints true $ ./testing.py true true true I know I am missing something,

Re: [Tutor] multiple if and or statement

2011-03-14 Thread Corey Richardson
On 03/14/2011 03:41 PM, Mike Franon wrote: > HI, > > I had a question, when running this small snippet of test code: > > > > a = ['test1', 'flag', 'monday'] > > for i in a: > if i == 'test1' or 'test2': if i == 'test1' or i == 'test2' >print 'true' > I know I am missing something

[Tutor] multiple if and or statement

2011-03-14 Thread Mike Franon
HI, I had a question, when running this small snippet of test code: a = ['test1', 'flag', 'monday'] for i in a: if i == 'test1' or 'test2': print 'true' It always prints true $ ./testing.py true true true I know I am missing something, but in reality it should only print true

[Tutor] Reading in data files

2011-03-14 Thread paige crawford
Hey, How do I read in a data file that has comments then remove the comments to get to the numbers? The numbers in the data file needs to be read into a list. There are also comments next to the numbers. The file looks something like this # DO NOT MODIFY # # This file is for the eyebrows # # Re

Re: [Tutor] Static Variable in Functions

2011-03-14 Thread ALAN GAULD
Apologies to all, I didn't notice the [] around a. But the basic point remains that the list that he is appending to is the same list as b refers to, albeit indirectly. He is still "touching" the list. Although not directly modifying the list to which b refers, since it still only holds one mem

Re: [Tutor] Static Variable in Functions

2011-03-14 Thread Andre Engels
On Mon, Mar 14, 2011 at 9:56 AM, Alan Gauld wrote: > "Yasar Arabaci" wrote > >> >>> a=["a"] >> >>> b=[a] >> >>> a.append("c") >> >>> b >> [['a', 'c']] >> >> Apperantly, I can change something (which is mutable) inside  a list >> without even touching the list itself :) > > But the point is that y

Re: [Tutor] Static Variable in Functions

2011-03-14 Thread Marcin Wlodarczak
Alan Gauld wrote: > "Yasar Arabaci" wrote > >> >>> a=["a"] >> >>> b=[a] >> >>> a.append("c") >> >>> b >> [['a', 'c']] >> >> Apperantly, I can change something (which is mutable) inside a list >> without even touching the list itself :) > > But the point is that you *are* touching the list. > In

Re: [Tutor] Static Variable in Functions

2011-03-14 Thread Noah Hall
On Mon, Mar 14, 2011 at 8:56 AM, Alan Gauld wrote: > "Yasar Arabaci" wrote >> Apperantly, I can change something (which is mutable) inside  a list >> without even touching the list itself :) > But the point is that you *are* touching the list. > In this case you have two names referring to the sa

Re: [Tutor] Static Variable in Functions

2011-03-14 Thread Alan Gauld
"Yasar Arabaci" wrote >>> a=["a"] >>> b=[a] >>> a.append("c") >>> b [['a', 'c']] Apperantly, I can change something (which is mutable) inside a list without even touching the list itself :) But the point is that you *are* touching the list. In this case you have two names referring to the