RE: [Tutor] Unexpected result from decimal

2005-01-19 Thread Tony Meyer
> >>> import decimal > >>> decimal.getcontext().prec = 2 > >>> a = decimal.Decimal(2) > >>> b = decimal.Decimal(3) > >>> 100*a/b > Decimal("67") > >>> print 100*a/b This prints "67". > try - > > a=decimal.Decimal(2.0) This will not work. You can't convert a float directly to a decimal.Decimal

RE: [Tutor] ascii encoding

2005-01-25 Thread Tony Meyer
> time.timezone gives you, I think, the offset between > your current timezone and GMT. However, being myself in the GMT zone, > I don't know exactly if the returned offset is positive or negative > (it returns 0 here, which makes sense :D ). Whether or not it's positive or negative depends on wh

RE: [Tutor] Should this be a list comprehension or something?

2005-01-25 Thread Tony Meyer
> Well, you can do this with list comprehensions, yeah: > > totalmass = sum([WaterObject.mass for WaterObject in WaterList]) > totaltemp = sum([WaterObject.mass * WaterObject.temp for > WaterObject in > WaterList]) / totalmass > return Water(totalmass, totaltemp) > > Doesn't seem that much more

RE: [Tutor] Advise...

2005-01-25 Thread Tony Meyer
> Anyway, I know the first thing that some of you are going to > say is using eval(). [...] > Which, considering that it is supposed to be exactly 117, > It's darn good. > Unfortunately, it also takes about 10 seconds to do all that. > Any suggestions? Any advice? On my machine your version ta

RE: [Tutor] Advise...

2005-01-25 Thread Tony Meyer
[Tony Meyer] > If the user must be able to enter in the function, then it > would be better to evaluate this once and turn it into some > sort of function that you can call inside the loop (it's the > eval that is so expensive). I should have included some code that doe

RE: [Tutor] New to Python

2005-01-26 Thread Tony Meyer
[Jason White] >> I'm curious about good tutorial websites and books to buy. [Max Noel] > I learned Python (well, the basics thereof -- enough to do useful > stuff on my summer job, anyway ^^) in an afternoon using the official > tutorial that's found somewhere on http://www.python.org/. It's ver

RE: [Tutor] Should this be a list comprehension or something?

2005-01-27 Thread Tony Meyer
[Sean Perry] >> And now, for the pedant in me. I would recommend against naming >> functions with initial capital letters. In many languages, this >> implies a new type (like your Water class). so >> CombineWater should be combineWater. [Brian van den Broek] > Do you mean implies by the dominan

RE: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Tony Meyer
> I'm trying to write a program they may involve > needing to divide 1 by another number. In the > program below when I use 4 for the diameter of > the bore, and 1 for the diameter of the rod, > and 60 for the PSI, the force should be 706.8 . > However the program keeps giving me 0 for "rodarea".

RE: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Tony Meyer
> btw is there a place I can read everyones questions, > like I posted, or does this work my emailing a few > knowledgable people? The archives of the list are available here: (The messages from the future at the top are obviously ones where people's m

RE: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Tony Meyer
> In that case you need it to use floating point numbers. > The easiest way is to use 1.0 but if it comes from a table > or user entry you might have to explicitly convert: > > one = 1 > other = 42 > result = float(one/other) What Alan meant, presumably, was this: one = 1 other = 42 result = fl

RE: [Tutor] Tweaking list comprehensions

2005-02-13 Thread Tony Meyer
>> def approachB(files): >> >> isHTML = [filename if filename.endswith('.htm') or\ >>filename.endswith(.html') for filename in files] >> return isHTML > > No, it should be... > > isHTML = [filename for filename in files if > filename.endswith('.htm') or\ > filename.endswith('.html') for

RE: [Tutor] writing list to new file

2005-02-13 Thread Tony Meyer
> How would I save a list to a new file > > for example: > > If line.startswith('XXX'): > save list to new file > > But I get errors saying only stings can be saved this > way. What do you want to do with the file afterwards? If you want to load it back in as a list at some later

RE: [Tutor] writing list to new file

2005-02-13 Thread Tony Meyer
> I'm just trying to create a new file for all > the lines that startswith my string. So if my original > file looks like this: > > 1 Line 1 > 1 Line 2 > 2 Line 1 > 2 Line 2 > 3 Line 1 > 4 Line 1 > > I want to read in all the ones starting with 1 and > then save them to a new file. I can get the

RE: [Tutor] Case acceptance using raw_input

2005-02-15 Thread Tony Meyer
>> Is there a better way for raw_input to accept both caps and >> lower case letters than: [...] >>if action == 'y' or action == 'Y': > > if action in 'yY': > dostuff() [...] > Although, that does mean that if a user enters 'nN' they'll > get no, but that shouldn't be a huge problem, and it i

RE: [Tutor] Intro for interfacing with Microsoft Access?

2005-03-06 Thread Tony Meyer
> Does anyone know of any online resource that explains how to > interface to Microsoft Access via Python, where the intended > audience is someone who knows Python, but not the Microsoft innards? These two pages are quite good:

RE: [Tutor] Intro for interfacing with Microsoft Access?

2005-03-06 Thread Tony Meyer
[Terry Carroll] >>> Does anyone know of any online resource that explains how to >>> interface to Microsoft Access via Python, where the intended >>> audience is someone who knows Python, but not the Microsoft innards? [Tony Meyer] >> These two p

RE: [Tutor] new

2005-03-15 Thread Tony Meyer
> Hey I am new at python and i am trying to learn about > it. I was wondering if you could tell me how to write > a range to 100. such as 1+2+3+4+5 ect. without > writing it out. Do you want a container with a range in it, like the list [1,2,3,4,5,...,100]: >>> range(100) [0, 1, 2, 3, 4, 5, 6

RE: [Tutor] new

2005-03-15 Thread Tony Meyer
> Do you want a container with a range in it, like the list > [1,2,3,4,5,...,100]: > > >>> range(100) > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, [...] > 92, 93, 94, 95, 96, 97, 98, 99] Opps. Notice that I did the range 0-99, of course. But it's still the function that you wan

RE: [Tutor] Sorting more than one list

2005-03-31 Thread Tony Meyer
> What's b.index(x) do? > > I'm guessing the for a list Delta = ["a,"b","c"], you get > > Delta.index("b") > > 1 > > Am I right? Yes. For future use, the easiest way to answer a question like that is to do: >>> help([].index) Help on built-in function index: index(...) L.index(value,

RE: [Tutor] str.split and quotes

2005-04-05 Thread Tony Meyer
> >>> s = 'Hi "Python Tutors" please help' > >>> s.split() > ['Hi', '"Python', 'Tutors"', 'please', 'help'] > >>> > > I wish it would leave the stuff in quotes in tact: > > ['Hi', '"Python Tutors"', 'please', 'help'] You can do this with a regular expression: >>> import re >>> re.findall(r'\".

RE: [Tutor] str.split and quotes

2005-04-05 Thread Tony Meyer
> I recommend this http://www.amk.ca/python/howto/regex/ > and python2x/tools/scripts/redemo.py to learn how to use regexes well. I also highly recommend for learning how to use regexes. In addition, Kodos is a great tool to both experiment around with reg

RE: [Tutor] str.split and quotes

2005-04-06 Thread Tony Meyer
> That won't work for the general case. I spent about 30 minutes trying > to come up with a reliably non-re way and kept hitting bugs like the > one here. Given that Tony_combine is a function wrapping Tony's logic: > > >>> Tony_combine('This will not work as "more than two words" are > quoted

RE: [Tutor] str.split and quotes

2005-04-07 Thread Tony Meyer
> Is there a reason to prefer one over the other? Is one > faster? I compiled my regular expression to make it quicker. With Python 2.4 I get these results (all imports are factored out, all give the same result except for CSV which strips the "s) with timeit.py: Own split: 26.8668364275 Toke

RE: [Tutor] str.split and quotes

2005-04-07 Thread Tony Meyer
> Wow Tony. That is so generous of you to do this experiment. > It must be a great re engine. It really wasn't much effort - just copying & pasting it all together and throwing in a few timeit statements. The timeit module is another great thing about Python :) > "Obvious" doesn't mean we can

RE: [Tutor] Python backwards program

2005-04-12 Thread Tony Meyer
> I am very new to programming and I have an assignment > to have a raw_input string that is inputted by the user > and then is printed backwards. Can anyone help me? I can > get it to print regular but backwards in not working. I guess that I shouldn't give code if this is for an assignment, bu

RE: [Tutor] Python backwards program (fwd)

2005-04-12 Thread Tony Meyer
> I have read about loops, strings, tuples. I am taking this > class on distance education and I am lost with this > assignment. I have read what Tony has wrote and that does me > no good. I do not understand what he is talking about. Which bits? The whole lot? I teach university students

RE: [Tutor] Python backwards program (fwd)

2005-04-12 Thread Tony Meyer
> We will not do your homework for you [snip] The slicing answer I posted is possibly the answer, but I assume that the loop solution, which I didn't post (in Python), is what is actually required. If slicing is what is wanted, then I apologise for giving an answer! :) =Tony.Meyer _

RE: [Tutor] Python backwards program

2005-04-13 Thread Tony Meyer
> In the print word [::-1] line it gives me this message > (sequence index must be an integer) What does that mean As others have said, it means you're using Python 2.2 or older (so can't use extended slicing). It seems likely that what you're after is the loop approach that has been mentioned b

RE: [Tutor] newbie intro to pickle

2005-04-15 Thread Tony Meyer
> Does anyone know if there are some *beginner*-user-friendly tutorials > out there for pickle? Or can give a sample of how you would implement > it into a VERY SIMPLE program? Obviously I can get to the "import > pickle" step, but once I'm past that, I'm totally lost! There's the example in the d

Re: [Tutor] character format

2005-05-11 Thread Tony Meyer
> You mean é? Oh, it is perfectly printable. It's even on my > keyboard (as unshifted 2), along with è, ç, à and ù. Ah, American > cultural assumption... ^^ >From the email address, chances are that this was a New Zealand cultural assumption. Ah, the French, lumping all English speakers under

Re: [Tutor] character format

2005-05-11 Thread Tony Meyer
[me, typo'ing] >> hexidecimal representations of characters. [Bob Gailer] > Did you mean "hexadecimal"? Sigh. Yes. I did a one character typo. Please forgive me. =Tony.Meyer ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/lis

Re: [Tutor] [HELP]win32 shutdown, restart, logoff

2005-05-22 Thread Tony Meyer
> I have the local machine's administration privilege. [...] > When I run the command as you point out, I got the following > messages > > (5, 'InitiateSystemShutdown', 'Access is denied.') The process itself needs to have the privilege. This message has complete instructions:

Re: [Tutor] Covert numbers to hex fails

2005-05-24 Thread Tony Meyer
> FAILS > -- > >>> value = 1234567890 > >>> hexoutput = hex('%d' % (value)) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: hex() argument can't be converted to hex Just don't convert the number to a string, e.g: >>> value = 1234567890 >>> hexoutput = hex(value