Re: [Tutor] immutable objects
On 10/31/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > Im facing a problem with SOAPpy which checks for recursive objects using> id(obj).>> In my case value for 2 SOAP headers are same and iam getting a recursion> error. if i pass different object with same value SOAPpy does not complain > (by using str(value) and unicode(value)).If you can include a stack trace of that error with SOAPpy, that would beexcellent. This sounds bizarre.You won't be able to do anything with the ints: some of them are internally interned by the runtime, and you can't control this. So I'dinstead focus on why SOAPpy is failing. It shouldn't have to worry aboutrecursively traversing the ints: they don't have any structure to traverse! So a stack trace would be useful.here is the stack trace. i know that SOAPpy is doing wrong by not checking the type of the element along with id(ele). I thought if there is any work around the problem i could use that without upgrading SOAPpy after it is fixed. >>> import SOAPpy>>> rmt = SOAPpy.SOAPProxy(url, header = SOAPpy.Types.headerType(data="" 'prem', 'password': 'prem'}))Traceback (most recent call last): File "", line 1, in ? NameError: name 'url' is not defined>>> url = "" href="http://soap.test.com/">http://soap.test.com/">>> rmt = SOAPpy.SOAPProxy(url, header = SOAPpy.Types.headerType(data="" 'prem', 'password': 'prem'})) >>> rmt.testcall()Traceback (most recent call last): File "", line 1, in ? File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/Client.py", line 453, in __call__ return self.__r_call(*args, **kw) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/Client.py", line 475, in __r_callself.__hd, self.__ma) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/Client.py", line 338, in __call config = self.config, noroot = self.noroot) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 624, in buildSOAPreturn t.build() File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 112, in build self.dump(self.header, "Header", typed = typed) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 294, in dumpmeth(obj, tag, typed, ns_map) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 580, in dump_instance self.dump(getattr(obj,k), k, typed, ns_map) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 294, in dumpmeth(obj, tag, typed, ns_map) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 358, in dump_string id = self.checkref(obj, tag, ns_map) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 260, in checkrefraise RecursionError, "Cannot serialize recursive object" SOAPpy.Errors.RecursionError: >>>-- With Regards,Premnath Sah T. H. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] One million and counting
Alan Gauld wrote: >Hi folks, > >In just thought I'd mention that my web tutor has now passed >the million visitors mark. Thanks to all those on the tutor >list who have paid a visit. > >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 > > > Congratulations Alan! I visited your site many times when first learning Python. Keep up the good work. Glenn -- "Ketchup. For the good times... " - Ketchup Advisory Board Glenn Norton Application Developer Nebraska.gov 1-402-471-2777 [EMAIL PROTECTED] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running multiple version of Python on 1 windows
>From Kent >>You don't say what OS you are running but under Windows it is trivial to>>have multiple versions of Python installed, I have 2.3, 2.4 and 2.5.>>They are each in their own directories, all in the system path. I have >>aliases called py23, py24 and py25 that let me launch the version I>>want. I'm pretty sure you can do something similar with other OSes.If you want script abc.py to run with python 2.3, and script xyz.py to run with 2.5, how can you control this form the command line?python abc.pyvspython xyz.py?One task I'm faced with is evaluating the benefits of migrating a huge framework from 2.3 to 2.4?I'd rather use two machines for this rather than install 2.4 on my 2.3 machine.If I need to make any changes in the scripts to work on 2.4, I don't want that interfering with a fully-working 2.3 environment. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Suggestions about documenting a function
Thanks for all your help guys, but after trying to read just bits and pieces of the manual and not understanding a single sentence, much less a single chapter, I decided to just put this function on hold until I read the whole Tutorial from start to finish. I just hope it doesn't take to long... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] off topic GNOME background
my background just disappeared it shows a black screen like it cant find the default background. if that makes sense I've added my own and it cant seem to find it i removed it and re added it it doesn't seem to be working though anyone have any ideas? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] One million and counting
On Tue, 31 Oct 2006, Alan Gauld wrote: > In just thought I'd mention that my web tutor has now passed > the million visitors mark. Thanks to all those on the tutor > list who have paid a visit. I've visted that site a few times. Thanks and congratulations. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] python and mingw home directory problem
Hi everyone,I'm trying to run some commands with mingw from python. However, somehow my home directory (for mingw) is being changed when I initialize tk. Here's an example:import osfrom Tkinter import Tkos.system("C:/msys/1.0/bin/sh.exe --login -i -c 'pwd' ") # just print my home directoryroot = Tk()os.system("C:/msys/1.0/bin/sh.exe --login -i -c 'pwd' ") # just print my home directory^^^output:/home/Pete/c/Documents and Settings/PeteAs you can see, initializing Tk has somehow changed my mingw home directory from "/home/Pete" to "/c/Documents and Settings/Pete". Since "/home/Pete" has my login script, this is a major problem.The actual change happens at _tkinter.create(.) during Tk().Any ideas?Thanks,Pete Get your email and more, right on the new Yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] One million and counting
Congrats! I know that what I know about Python I learned from your guide, so a personal thanks from me :) Alan Gauld wrote: > Hi folks, > > In just thought I'd mention that my web tutor has now passed > the million visitors mark. Thanks to all those on the tutor > list who have paid a visit. > > 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 maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Mapping to object attributes
"Mike Hansen" <[EMAIL PROTECTED]> wrote > I've got a web form with a lot of form fields. I'd like to be able > to map > the form fields to an object's attributes. I'm having a little > trouble > figuring out how. John has answered that bit. > There will be some fields I'll need to validate(boolean or int), but > the > majority are just text fields that can be passed to the object. One thing you can do is store the validation functions in the dictionary with the value. def intValidator(i): try: return int(i) except: return None def boolValidator(b): try: return b and True or False except: return None mapping = { 'field': (intvalue, intValidator), 'another': (boolvalue,boolValidator)...} You can then access the validator like so: value = mapping[fieldname][0] validator = mapping[fieldname][1] value = validator(value) if value == None: #ooops! or more concisely: value = mapping[fieldname][1](mapping[fieldname]0]) This style of validation has the "benefit" (or side-effect if you prefer) of converting compatible types into true types. eg. validating a string or float representation of an integer returns the actual integer value. HTH, -- 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] Simple calculator
I found this simple calculator on the web: from Tkinter import * from math import * ###http://sunsite.uakom.sk/sunworldonline/swol-02-1998/swol-02-python.htmlBy Cameron Laird and Kathryn Soraiz...Getting Started with Python### def evaluate(event): label['text'] = "Result: " + str(eval(expression.get())) frame = Frame(None) entry = Entry(frame) entry['textvariable'] = expression = StringVar() entry.bind("", evaluate) label = Label(frame) button = Button(frame, text = "Submit", command = evaluate) frame.pack() entry.pack() label.pack() button.pack() frame.mainloop() I get this: >>> Traceback (most recent call last): File "D:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "D:\Python24\Calculator\Calc.py", line 12, in ? entry.bind("", evaluate) File "D:\Python24\lib\lib-tk\Tkinter.py", line 933, in bind return self._bind(('bind', self._w), sequence, func, add) File "D:\Python24\lib\lib-tk\Tkinter.py", line 888, in _bind self.tk.call(what + (sequence, cmd)) TclError: no events specified in binding Please have a look for me thanks! Joe Cox 513-293-4830 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] One million and counting
Very cool! Congrats!On 10/31/06, Alan Gauld <[EMAIL PROTECTED]> wrote: Hi folks,In just thought I'd mention that my web tutor has now passedthe million visitors mark. Thanks to all those on the tutorlist who have paid a visit.Alan GauldAuthor 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 maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] One million and counting
Hi folks, In just thought I'd mention that my web tutor has now passed the million visitors mark. Thanks to all those on the tutor list who have paid a visit. 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
Re: [Tutor] Mapping to object attributes
On 01/11/06, Mike Hansen <[EMAIL PROTECTED]> wrote: > form = cgi.FieldStorage() > widget = Widget() > > form_field_object_map = {'widget_name' : widget.name, > 'alt_widget_name' : widget.alt_name, > ...} > > for form_field in form_field_object_map.keys(): > form_field_object_map[form_field]...er This won't work, because python will look up widget.name and replace it with the value of widget.name when it creates the dictionary. You can probably do something with setattr. Check the docs for details, but basically, setattr(thing, 'foo', 'bar') is equivalent to thing.foo = 'bar' eg: form_field_object_map = { 'widget_name':'name', 'alt_widget_name':'alt_name', } # etc form = cgi.FieldStorage() widget = Widget() for form_field in form_field_object_map: setattr(widget, form_field_object_map[form_field], form.getvalue(form_field)) HTH! -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Mapping to object attributes
I've got a web form with a lot of form fields. I'd like to be able to map the form fields to an object's attributes. I'm having a little trouble figuring out how. I was thinking of something like this.. form = cgi.FieldStorage() widget = Widget() form_field_object_map = {'widget_name' : widget.name, 'alt_widget_name' : widget.alt_name, ...} for form_field in form_field_object_map.keys(): form_field_object_map[form_field]...er I'd like to avoid a pile if elif elifs. It seems like there should be a cleaner way. if form_field == 'widget_name': widget.widget_name = form.getvalue(form_field) elif form_field == 'alt_widget_name': widget.alt_name = form.getvalue(form_field) elif ... There will be some fields I'll need to validate(boolean or int), but the majority are just text fields that can be passed to the object. Anyone got any ideas on how to do this? Thanks, Mike ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] senior project
i am a senior in high school, my school requires me to get a mentor and interview 2 people for my senior project. i am wondering if any one would be my mentor or be willing to answer some questions. if you are interested please email me ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] immutable objects
> Im facing a problem with SOAPpy which checks for recursive objects using > id(obj). > > In my case value for 2 SOAP headers are same and iam getting a recursion > error. if i pass different object with same value SOAPpy does not complain > (by using str(value) and unicode(value)). If you can include a stack trace of that error with SOAPpy, that would be excellent. This sounds bizarre. You won't be able to do anything with the ints: some of them are internally interned by the runtime, and you can't control this. So I'd instead focus on why SOAPpy is failing. It shouldn't have to worry about recursively traversing the ints: they don't have any structure to traverse! So a stack trace would be useful. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] M Arch Thesis
Hi to all, For my Thesis project, I want to use a Genetic Algorithm to generate multiple spatial organization solutions for Architectural projects. My idea is that a software that does this would be useful as a rapid prototyping tool and more important it will probably reach solutions that a human user would not. The problem is that I can't find a GA module for python that is reasonably easy to use, do you know if there is something out there that can help me? I would like to find something with a black box approach, in this case I would only need to feed the system some information and get a result in the end, forgetting a little about the process itself. Dont think me lazy is just that I'm new to python and my time is limited. By the way, do you think that a GA solution is good for this project, maybe someone has a better idea. Thanks, Carlos ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] immutable objects
Premnath Sah wrote: > I would like to know how i can guarantee that a new immutable object is > infact a new object. > > Example: > > >>> a = 1 > >>> b = 1 > >>> a is b > True > > is what i get. i want a and b to be two different object. I don't think there is any way to control this for the builtin types. Why do you care? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about pylab
ok, looks like the date2num() function on a datetime.datetime object is working. So cool.i am very new at this, so i may be back ( read probably be back ). Thanks much for the tips.i appreciate it a lot.sk On 10/31/06, Kent Johnson <[EMAIL PROTECTED]> wrote: shawn bright wrote:> hey there,> i am trying to use a graph and chart app called matplotlib, but i cannot> figgure out how to have it plot a simple chart over time.> the docs say to use the function plot_date() but i cannot seem to get > the values to agree.> I am sending datetimes to the charting app for x, and the y is a list of> values that the our equipment reports.> sometimes there are lots of reports in a row, and i would like the chart > to show it like that instead of plotting out every time as an evenly> spaced tick on the x scale. Does this make any sense, what i am after> here? Anyway, if any of you have much experience with this sort of > thing, or may suggest a package (pylab is my first attempt) please send> me some advice.I have used pylab to create a scatterplot of date vs value. The datevalues were created by calling pylab.date2num () on a datetime.datetimevalue. The axes were set up with this code:# Set up the xaxisax = axes([0.05, 0.05, 0.9, 0.9])ax.xaxis.set_major_locator(MinuteLocator(interval=10))ax.xaxis.set_minor_locator (MinuteLocator())ax.xaxis.set_major_formatter(DateFormatter("%H:%M"))I called pylab.scatter() to create the plot.HTH,Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] immutable objects
On 10/31/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Premnath Sah wrote:> I would like to know how i can guarantee that a new immutable object is> infact a new object.>> Example:>> >>> a = 1> >>> b = 1 > >>> a is b> True>> is what i get. i want a and b to be two different object.I don't think there is any way to control this for the builtin types.Why do you care? Im facing a problem with SOAPpy which checks for recursive objects using id(obj). In my case value for 2 SOAP headers are same and iam getting a recursion error. if i pass different object with same value SOAPpy does not complain (by using str(value) and unicode(value)). ThanksPremnath Sah T. H. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] immutable objects
Hi,from http://docs.python.org/ref/objects.htm """Types affect almost all aspects of object behavior. Even the importance of object identity is affected in some sense: for immutable types, operations that compute new values may actually return a reference to any existing object with the same type and value, while for mutable objects this is not allowed. E.g., after "a = 1; b = 1", a and b may or may not refer to the same object with the value one, depending on the implementation, but after "c = []; d = []", c and d are guaranteed to refer to two different, unique, newly created empty lists. (Note that "c = d = []" assigns the same object to both c and d.)""" I would like to know how i can guarantee that a new immutable object is infact a new object. Example:>>> a = 1>>> b = 1>>> a is bTrueis what i get. i want a and b to be two different object. Thanks in advancePremnath Sah T. H. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about pylab
shawn bright wrote: > hey there, > i am trying to use a graph and chart app called matplotlib, but i cannot > figgure out how to have it plot a simple chart over time. > the docs say to use the function plot_date() but i cannot seem to get > the values to agree. > I am sending datetimes to the charting app for x, and the y is a list of > values that the our equipment reports. > sometimes there are lots of reports in a row, and i would like the chart > to show it like that instead of plotting out every time as an evenly > spaced tick on the x scale. Does this make any sense, what i am after > here? Anyway, if any of you have much experience with this sort of > thing, or may suggest a package (pylab is my first attempt) please send > me some advice. I have used pylab to create a scatterplot of date vs value. The date values were created by calling pylab.date2num() on a datetime.datetime value. The axes were set up with this code: # Set up the xaxis ax = axes([0.05, 0.05, 0.9, 0.9]) ax.xaxis.set_major_locator(MinuteLocator(interval=10)) ax.xaxis.set_minor_locator(MinuteLocator()) ax.xaxis.set_major_formatter(DateFormatter("%H:%M")) I called pylab.scatter() to create the plot. HTH, Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about pylab
Am 31.10.2006 um 08:35 schrieb shawn bright: > hey there, > i am trying to use a graph and chart app called matplotlib, but i > cannot figgure out how to have it plot a simple chart over time. > the docs say to use the function plot_date() but i cannot seem to get > the values to agree. > I am sending datetimes to the charting app for x, and the y is a list > of values that the our equipment reports. > sometimes there are lots of reports in a row, and i would like the > chart to show it like that instead of plotting out every time as an > evenly spaced tick on the x scale. Does this make any sense, what i am > after here? Anyway, if any of you have much experience with this sort > of thing, or may suggest a package (pylab is my first attempt) please > send me some advice. > > thanks for your time, > sk I am not sure if I get it right, could you give us some sample data and some code what you have tried? I never used plot_date, but I could give it a try. Regards, Markus ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Suggestions about documenting a function
"Jorge Azedo" <[EMAIL PROTECTED]> wrote > import random > > def randomList(n1,n2,len): >'''n1-n2 range of numbers, len - length of the final list > >Returns a list''' Don't worry too much about writing the doc string to fit in the IDE hint box. Think more about how it will look when people use help() or __doc__ to print the documentation. Specifically this doc string isn't actually too helpful since it only tells me the data types of the inputs and outputs but gives no clues about the actual purpose of the function. Specifically it doesn't make it clear that the returned list will contain *unique* random numbers from the range >i=0 >rndlist=[] >if len > n2: >return 'The length of the list must be greater than n2' Huh? This can never work. If I use 99,100,101 that implies you will give me 101 unique numbers between 99 and 100... Surely the constraint should be that len < n2-n1 Also, what happens if n1 > n2? (This is also a bug in randint IMHO...) > before he runs it, but I can't think of a short enough way to say it > so > that it still appears in that little window that shows up when you > start writing the arguments to a function. Don't even try... or if you must keep the input summary on one line and expand the second paragraph to describe what it does. BTW One common notation for defining functoion signatures is param,param,param... -> result. So in your case you could use: (n1 int, n2 int, length int) -> list : n1 < n2, ln < n2-n1 which is more concise and includes the constraints... but still doesn't convey the intent. HTH -- 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
Re: [Tutor] Using sys.exit()
"Dick Moores" <[EMAIL PROTECTED]> wrote > I'd like to know how to use sys.exit() to quit a program. > I see that you already figured that out. You can also quit by raising SystemExit, which is what sys.exit does... but you don't need to import sys... > Is there a way to use it the way I want to? Maybe with an argument? You can use an argument if you want to pass an error value back to the OS. This is good practice if your script might be used in a batch file or shell script > I'm writing a script, which in a couple of places I can't > use "break" to quit. break is not intended to quit programs, break is intended to quit loops. To exit a program you should use sys.exit() and if its an abnormal exit provide an argument. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor