[Tutor] Why a global?
Hello, Can help me with this: I am using a python module that someone else wrote http://www.alextreme.org/projects/python_ai/ This is an example of how it works # Usage: # import ga # # ga = ga.GA() # ga.evolve() # Function arguments (fun defaults are used otherwise): # # ga.GA(population_size, gene_size, crossover_rate, mutation_rate, list_of_alleles) # ga.evolve(number_of_generations_to_process) # # ga.set_fitness(your_fitness_function) # Interesting public variables (besides the ones you can modify using arguments) # # ga.debug = 1 (turns on lots of output) # ga.halt = X.X (stop if this fitness is reached) # Note: crossover_rate is the chance two entities will reproduce # mutation_rate is the chance a single entity will have an allele changed My problem is that no matter were I put this, I have to declare ga a global. So I ended up with this: def runGA(Pop, Gen, It): # Declare a Global. This is the only solution for now global ga # Set the arguments of the GA ga = ga.GA(pop = 2, alleles = range(10), gene_size = 8) ga.debug = 1 ga.echo_entities() Can you help me with this information? or what else is needed for you to help me solve this problem? Regards, Carlos ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Why a global?
Carlos schrieb: > My problem is that no matter were I put this, I have to declare ga a > global. You are confusing two different objects with the name 'ga' here: a) the module object 'ga' which you create by import ing it: import ga this binds the name 'ga' to the module object created by reading in the module ga (probably some file name 'ga.py' or a package). b) The instance object of the the 'GA' class you create with ga = ga.GA(pop = 2, alleles = range(10), gene_size = 8) You have named the variable that holds a reference to this instance object b) also 'ga' thereby *overwriting the global variable 'ga'*, which held a reference to the module object a). If you want to overwrite a global variable in a function, you have to declar it global with the 'global' keyword. *But that's not what you want here.* Just give another name to your instance variable: import ga def runGA(pop, gen, it): ga_inst = ga.GA(pop = 2, alleles = range(10), gene_size = 8) ga_inst.debug = 1 ... HTH, Chris ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python cgi scripting
Hello. I'm just starting to learn Python, and want to do some python cgi scripting. Can someone recommend a good web site or online reference (beginner level)? Thank you. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python cgi scripting
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Troy > Sent: Tuesday, December 26, 2006 10:01 PM > To: tutor@python.org > Subject: [Tutor] Python cgi scripting > > Hello. I'm just starting to learn Python, and want to do some python > cgi scripting. Can someone recommend a good web site or online > reference (beginner level)? > > Thank you. > Check out the docs on the cgi module http://docs.python.org/lib/module-cgi.html Also, devshed has an article on cgi programming with Python http://www.devshed.com/c/a/Python/Writing-CGI-Programs-in-Python/ Mike - NOTICE: This e-mail transmission and any documents or files attached to it contain information for the sole use of the above-identified individual or entity. Its contents may be privileged, confidential, and exempt from disclosure under the law. Any dissemination, distribution, or copying of this communication is strictly prohibited. Please notify the sender immediately if you are not the intended recipient. FGNS ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python cgi scripting
"Troy" <[EMAIL PROTECTED]> wrote > Hello. I'm just starting to learn Python, and want to do some > python > cgi scripting. Can someone recommend a good web site or online > reference (beginner level)? The standard documentation for cgi is pretty good. Also check out the Web Programming Topic Guide on CGIScripts - it has links to several other tutorials. Finally, if you are serioud abouyt web programming there are quite a few Python web frameworks that take a lot of the pain away. Django and TurboGears (mainly the CherryPy stuff IMHO) seem to be the current favourites, and Zope if your needs are ambitious. But basic CGI is fine for simple apps with just a few pages. -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] [OT]Test
Sorry, just testing if I can receive mail from this list again. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor