[Tutor] Upgrade to 2.4
I compiled Python 2.3.4 from source, but now I would like to upgrade to 2.4. There doesn't seem to be a "make uninstall" target for 2.3.4. Will compiling 2.4 overwrite the older version, or will I have two versions of Python on my system? Thanks, Will ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Upgrade to 2.4
Danny Yoo wrote: On Sat, 4 Dec 2004, William Allison wrote: I compiled Python 2.3.4 from source, but now I would like to upgrade to 2.4. There doesn't seem to be a "make uninstall" target for 2.3.4. Will compiling 2.4 overwrite the older version, or will I have two versions of Python on my system? Hi Will, According to the README, you can install Python 2.4 in a way that doesn't overwrite your older version of Python. Here's a snippet from the README: """ If you have a previous installation of Python that you don't want to replace yet, use make altinstall This installs the same set of files as "make install" except it doesn't create the hard link to "python" named "python" and it doesn't install the manual page at all. """ This should install '/usr/local/bin/python2.4', but otherwise, it should leave the rest of your Python 2.3.4 installation intact. Hope this helps! Yeah, I saw that, but didn't want two versions of Python hanging around. I went ahead and did "make install" for 2.4 and it replaced the previous version. Thanks, Will ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
[Tutor] Scrabble Help
I'd like to write a program to help find words for Scrabble but I've been having trouble right from the beginning. tiles = 'aeirstw' dictionary = ['aardvark', 'cat', 'dog', 'taste', 'stare', 'wrist'] for word in range(len(dictionary)): for letter in range(len(dictionary[word])): if dictionary[word][letter] in tiles: nothing here quite works I guess what I'm trying to do is step through every letter of every word in my dictionary and if that letter is in my tiles set it aside and compare it back to the dictionary. So in the dictionary above, 'aardvark' would not be included because there is only 1 'a' in my tiles, but 'stare' and 'wrist' should be even though there are letters left over in the tiles. Am I going about this wrong? Should I be looking at some module or a regular expression? Of course any advice is appreciated. Thanks, Will ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] <> and chomp
Hi, I'm new to programming and started with Perl but have been reading a lot of good things about Python. Thought I would switch before I have too much time invested in Perl. Anyway, my question is, is there something in Python similar to the diamond operator and chomp from Perl? I'm trying to read in from a file line by line and get rid of the '\n' at the end of each line. Thanks, Will ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Better way to substitute text?
Hi, Just learning Python, on chapter 6 of Learning Python 2nd Ed. So, on to the question. Is there a better way to implement the code below? It scans a saved html file and highlights certain keywords is a bold, red font. It works, but I suppose I'm wondering if it's the "Pythonic" way. Thanks, Will #!/usr/bin/env python in_put = open('test.html', 'r') out_put = open('test_highlight.html', 'a') for line in in_put: line = line.replace("TWY", "TWY") line = line.replace("RWY", "RWY") line = line.replace("WIP", "WIP") out_put.write(line) in_put.close() out_put.close() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to substitute text?
Shantanoo Mahajan wrote: > +++ William Allison [29-09-06 18:55 -0400]: > | Hi, > | Just learning Python, on chapter 6 of Learning Python 2nd Ed. So, on to > | the question. Is there a better way to > | implement the code below? It scans a saved html file and highlights > | certain keywords is a bold, red font. It works, > | but I suppose I'm wondering if it's the "Pythonic" way. > | Thanks, > | Will > | > | #!/usr/bin/env python > | > | in_put = open('test.html', 'r') > | out_put = open('test_highlight.html', 'a') > > = > | for line in in_put: > | line = line.replace("TWY", " | color='#FF'>TWY") > | line = line.replace("RWY", " | color='#FF'>RWY") > | line = line.replace("WIP", " | color='#FF'>WIP") > | out_put.write(line) > = > | > | in_put.close() > | out_put.close() > > > replace_words = ['TWY', 'RWY', 'WIP'] > for line in in_put: > for replace_word in replace_words: > out_put.write(line.replace(replace_word," color='#FF'>"+replace_word+"")) > > You can furthur reduce for loops. > > Shantanoo > Thanks Shantanoo, I like that a lot better. Had to modify it just a little. replace_words = ['TWY', 'RWY', 'WIP'] for line in in_put: for replace_word in replace_words: line = line.replace(replace_word, "" + replace_word + "") out_put.write(line) I can never quite get when to use a nested loop. Thanks again, Will ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to substitute text?
Thanks David, I like that better than my original. I'll remember to NOT split the input file into lines in the future. Will David Heiser wrote: > You can make it simpler by not splitting the input file into lines. > Treat it as a single string. > > in_put = open('test.html', 'r').read() > > replace_words = ['TWY', 'RWY', 'WIP'] > for replace_word in replace_words: > in_put = in_put.replace(replace_word, " color='#FF'>" + replace_word + "") > > open('test_highlight.html', 'a').write(in_put) > > > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Behalf Of William Allison > Sent: Saturday, September 30, 2006 8:10 AM > To: tutor@python.org > Subject: Re: [Tutor] Better way to substitute text? > > > Shantanoo Mahajan wrote: > >> +++ William Allison [29-09-06 18:55 -0400]: >> | Hi, >> | Just learning Python, on chapter 6 of Learning Python 2nd Ed. So, >> | on to >> | the question. Is there a better way to >> | implement the code below? It scans a saved html file and highlights >> > > >> | certain keywords is a bold, red font. It works, >> | but I suppose I'm wondering if it's the "Pythonic" way. >> | Thanks, >> | Will >> | >> | #!/usr/bin/env python >> | >> | in_put = open('test.html', 'r') >> | out_put = open('test_highlight.html', 'a') >> >> = >> | for line in in_put: >> | line = line.replace("TWY", "> | color='#FF'>TWY") >> | line = line.replace("RWY", "> | color='#FF'>RWY") >> | line = line.replace("WIP", "> | color='#FF'>WIP") >> | out_put.write(line) >> = >> | >> | in_put.close() >> | out_put.close() >> >> >> replace_words = ['TWY', 'RWY', 'WIP'] >> for line in in_put: >> for replace_word in replace_words: >> out_put.write(line.replace(replace_word,"> color='#FF'>"+replace_word+"")) >> >> You can furthur reduce for loops. >> >> Shantanoo >> >> > > Thanks Shantanoo, > I like that a lot better. Had to modify it just a little. > > replace_words = ['TWY', 'RWY', 'WIP'] > for line in in_put: >for replace_word in replace_words: > line = line.replace(replace_word, " color='#FF'>" + replace_word + "") > out_put.write(line) > > I can never quite get when to use a nested loop. > Thanks again, > Will > > > ___ > 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] question
Caicedo, Richard IT2 NSWC wrote: > > I am trying to get the $ python promt I can't seem to get it. I can > get the python shell but when I press enter I don't get the $ python? > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > The $ is probably referring to the BASH prompt at which you would type the command python to bring up the interactive interpreter. Will ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] datetime.timedelta Output Format
Is there a way to have the output of "print tis" in the same format as "print now" and "print tafmsd" in the code below? Thanks, Will savage:~ wallison$ python Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import datetime >>> now = datetime.date.today() >>> print now 2007-04-01 >>> tafmsd = datetime.date(1994, 2, 23) >>> print tafmsd 1994-02-23 >>> tis = now - tafmsd >>> print tis 4785 days, 0:00:00 >>> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] datetime.timedelta Output Format
Alan Gauld wrote: > "R. Alan Monroe" <[EMAIL PROTECTED]> wrote > > >>> Is there a way to have the output of "print tis" in the same format >>> as >>> "print now" and "print tafmsd" in the code below? >>> > > >>> >>> now = datetime.date.today() >>> >>> print now >>> 2007-04-01 >>> >>> tis = now - tafmsd >>> >>> print tis >>> 4785 days, 0:00:00 >>> > > >> That's kind of like asking how to say "128 shopping days left until >> Christmas" in the format of "2007-04-01 shopping days left until >> Christmas". It doesn't work, somehow. >> > > I assume that what Will really means is how does he > get the number of days expressed as a number of > years/months and days. > > As in: There are 4 months, 8 days to Xmas. > Yes, that's correct. Sorry I didn't express myself clearly. Thanks again, Will ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] datetime.timedelta Output Format
Kent Johnson wrote: > > It looks like Gustavo Niemeyer's dateutil module will at least do the > year/month/day calculation if not the formatting: > > In [1]: from datetime import date > In [2]: from dateutil import relativedelta > In [3]: now = date.today() > In [9]: rd = relativedelta.relativedelta(now, tafmsd) > In [10]: rd > Out[10]: relativedelta(years=+13, months=+1, days=+10) > > http://labix.org/python-dateutil > > Kent > Thank you, seems to be just what I was looking for! Will ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need a Clean Start
Keegan Johnson wrote: > I need to get the pygames, py2app, etc on my computer > (I have a Macintosh). Is there any way to clean up all these files > that I've accrued trying to get things to work? I've been able to do > a little bit but nothing more than that. Also, what should I use? > There's lots of different versions different sites recommend. Anyone > willing to authoritatively decide? > Thanks a million for any help at all, > Keegan > Not sure what you've accrued trying to get things to work so can't tell you how to clean them all up. But sounds like you might want to check out easy_install, it lets you install, upgrade, and uninstall Python packages. You can even have a "custom installation location" such as in your home directory. http://peak.telecommunity.com/DevCenter/EasyInstall As far as which version to use, I think I read somewhere that the latest version of Python is typically the best version of Python. Will ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How Compute # of Days between Two Dates?
Wayne Watson wrote: > That's the question in Subject. For example, the difference between > 08/29/2008 > and 09/03/2008 is +5. The difference between 02/28/2008 and 03/03/2008 is 4, > leap year--extra day in Feb. I'm really only interested in years between, > say, > 1990 and 2050. In other words not some really strange period of time well > outside our current era of history. I've used the datetime module to do something similar. Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import datetime >>> today = datetime.date.today() >>> print today 2008-09-01 >>> last_year = datetime.date(2007, 9, 1) >>> print today - last_year 366 days, 0:00:00 >>> HTH, Will ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor