Re: [Tutor] div_t
Burge Kurt wrote: >>divmod(...) >>divmod(x, y) -> (div, mod) > > > What is the easiest way to use div and mod seperately as an attribute like: > > if a = divmod(x,y) > > a.div or a.mod The result of calling divmod() is a two-element tuple. You access the elements by indexing: >>> a=divmod(10, 3) >>> a[0] 3 >>> a[1] 1 You can also use tuple assignment to assign the two values to two variables (you can use other names than div and mod): >>> div, mod = divmod(10, 3) >>> div 3 >>> mod 1 BTW you can't put an assignment in an if statement in python so your original code might be written as div, mod = divmod(x, y) if div... Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the Index of a member of a Tuple
Steve Haley wrote: > Hello everyone, > > I need to do something very simple but I'm having trouble finding the > way to do it - at least easily. I have created a tuple and now need to > find the position of individual members of that tuple. Specifically, > the tuple is something like: words = ("you", "me", "us", "we", "and", > "so", "forth") and I need to be able to name a member, for example, "us" > and find what the position (index) of that word is in the tuple. If you can use a list instead of a tuple you can use the index() method. >>> words = ["you", "me", "us", "we", "and", "so", "forth"] >>> words.index('me') 1 >>> words.index('so') 5 There is no index() method for a tuple. This is probably because in GvR's view, tuples are analogous to records - they are heterogeneous collections where position matters. Lists are for homogeneous collections. In this view, tuple.index() doesn't make sense. list.index() is documented here: http://docs.python.org/lib/typesseq-mutable.html You found the right chapter of the Lib Ref but the wrong section. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] extra characters in XML
Thanks - it was exactly as you said --- Kent Johnson <[EMAIL PROTECTED]> wrote: > Most likely your XML file is 16-bit unicode, not > utf-8. When ascii text > is represented as unicode, every other byte will be > a null byte. That is > the extra character that shows up as a space or box > depending on who is > interpreting it. The utf-8 codec must be swallowing > the null bytes. > > In your code above, instead of utf-8 try utf_16_be > and utf_16_le, one of > them should work. ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CPU Utilization
> 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 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
Thanks in advance for any help!How do you create a script in python...sorry to be so remedial...first script. With my best regards always, David Christian BEGIN:VCARD VERSION:2.1 N:Christian;David FN:David Christian ([EMAIL PROTECTED]) TITLE:CRNA TEL;HOME;VOICE:9015262444 TEL;CELL;VOICE:9014875861 ADR;WORK:;;705Harbor Edge Circle Apt.101;Memphis;Tn.;38103;United States of America LABEL;WORK;ENCODING=QUOTED-PRINTABLE:705Harbor Edge Circle Apt.101=0D=0AMemphis, Tn. 38103=0D=0AUnited States of = America EMAIL;PREF;INTERNET:[EMAIL PROTECTED] REV:20050708T184735Z END:VCARD ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On Thu, 12 Jan 2006, David Christian wrote: > Thanks in advance for any help!How do you create a script in > python...sorry to be so remedial...first script. You might want to look at: http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/ Some of the information there is a bit outdated, but it should still help you get started. If you have more questions, please feel free to ask! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the Index of a member of a Tuple
At 10:52 PM 1/11/2006, Brian van den Broek wrote: >[snip] > >I assume Bob meant that tuples have no index or find method. No, Bob is sick and not thinking clearly. At 11:04 PM 1/11/2006, Terry Carroll wrote: >Does it have to be a tuple? If you make it a list, you can use index(): >[snip] At 03:13 AM 1/12/2006, Kent Johnson wrote: >[snip] >If you can use a list instead of a tuple you can use the index() method. I'm glad there are several of us contributing to this list. I hope to think things thru better before responding, but it is also nice to see that the dictionary approach stimulated things! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CPU Utilization
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]
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