Re: [Tutor] Bowing out

2010-03-03 Thread Kent Johnson
ibly with the Mercurial project or SunlightLabs.org. Kent > > >> On 3 March 2010 14:17, Kent Johnson wrote: >>> After six years of tutor posts my interest and energy have waned and >>> I'm ready to move on to something new. > _

[Tutor] Bowing out

2010-03-03 Thread Kent Johnson
Hi all, After six years of tutor posts my interest and energy have waned and I'm ready to move on to something new. I'm planning to stop reading and contributing to the list. I have handed over list moderation duties to Alan Gauld and Wesley Chun. Thanks to everyone who contributes questions and

Re: [Tutor] returning to my quest

2010-02-25 Thread Kent Johnson
On Thu, Feb 25, 2010 at 8:59 PM, Kirk Bailey wrote: > for  WEBMAIIL portal to a pop3/smtp email service in my server; centrally > hosted or in the laptop is fine, what can people recommend? Without going to > IMAP, i want to leave the mail on the server. I still have no idea what you are asking f

[Tutor] Top posters for 2009

2010-02-25 Thread Kent Johnson
It's not really about keeping score :-), but once again I've compiled a list of the top 20 posters to the tutor list for the last year. For 2009, the rankings are 2009 (7730 posts, 709 posters) Alan Gauld 969 (12.5%) Kent Johnson 804 (10.4%) Dave Angel 254 (3.3%) spir 254 (3.3%) Wa

[Tutor] Regular expression generator

2010-02-24 Thread Kent Johnson
Another interesting tool - you give it a sample string and it helps you build a regular expression to match the string. This is not a regex tester, it actually creates the regex for you as you click on elements of the string. http://txt2re.com/index-python.php3 Kent ___

[Tutor] DreamPie - The Python shell you've always dreamed about!

2010-02-24 Thread Kent Johnson
This looks promising and probably of interest to some on this list. Kent -- Forwarded message -- From: Noam Yorav-Raphael To: python-announce-l...@python.org Date: Sun, 21 Feb 2010 11:39:02 +0200 Subject: DreamPie - The Python shell you've always dreamed about! I'm pleased to ann

Re: [Tutor] ask

2010-02-24 Thread Kent Johnson
On Tue, Feb 23, 2010 at 10:58 PM, Shurui Liu (Aaron Liu) wrote: > This time is not my assignment, I promise. > > In python, when we want to list numbers, we use the command "range", like, > if we want to list integer from 0 to 9, we can write: range(10); if we want > to list integer from 10 to 29,

Re: [Tutor] Functions returning multiple values

2010-02-23 Thread Kent Johnson
On Tue, Feb 23, 2010 at 1:55 PM, Giorgio > And, please let me ask a question: Kent told that nested_namespace(s) are > default in python 2.6. And i found a line confirming this in py2.6 library. > But, what about python 2.5 that as you know is the default on linux? Yes, since 2.2 nested namespaces

Re: [Tutor] list to numpy record array

2010-02-23 Thread Kent Johnson
On Mon, Feb 22, 2010 at 11:50 PM, Vincent Davis wrote: > > I must be missing something simple. I have a list of lists data = "[['  0', ' >  0', '234.0', '24.0', ' 25'], ['  1', '  0', '22428.0', '2378.1', ' > 25'],.." and what to make a record array from it but it gets screwed up > or I don

Re: [Tutor] Functions returning multiple values

2010-02-22 Thread Kent Johnson
On Mon, Feb 22, 2010 at 9:13 AM, Giorgio wrote: > And, i have some difficulties understanding the other "strange" example in > that howto. Just scroll down to: "However, the point is that the value > of x is picked up from the environment at the time when the function is > defined. How is this us

Re: [Tutor] Extracting comments from a file

2010-02-22 Thread Kent Johnson
On Mon, Feb 22, 2010 at 1:06 AM, Lao Mao wrote: > Hi, > > I have an html file, with xml style comments in: > > > > I'd like to extract only the comments.  My sense of smell suggests that > there's probably a library (maybe an xml library) that does this already. Take a look at BeautifulSoup: htt

Re: [Tutor] Using and

2010-02-21 Thread Kent Johnson
On Sun, Feb 21, 2010 at 8:44 AM, jim serson wrote: > Can anyone tell me if I can have my program check to see if something is > true the add to count > > For example something like > > if c_1 and c_2 and c_3 true: > >     count + 1 This will almost work as written. Try if c_1 and c_2 and

Re: [Tutor] Replacing part of a URL

2010-02-20 Thread Kent Johnson
On Sat, Feb 20, 2010 at 5:34 PM, Lao Mao wrote: > Hello, > I need to be able to replace the last bit of a bunch of URLs. > The urls look like this: > www.somesite.com/some/path/to/something.html > They may be of varying lengths, but they'll always end with > .something_or_other.html > I want to ta

Re: [Tutor] fast sampling with replacement

2010-02-20 Thread Kent Johnson
On Sat, Feb 20, 2010 at 11:22 AM, Andrew Fithian wrote: > can > you help me speed it up even more? > import random > def sample_with_replacement(list): >     l = len(list) # the sample needs to be as long as list >     r = xrange(l) >     _random = random.random >     return [list[int(_random()*l

Re: [Tutor] Superclass call problem

2010-02-20 Thread Kent Johnson
On Sat, Feb 20, 2010 at 12:50 PM, Alan Harris-Reid wrote: > Hi, > > I am having trouble understanding how superclass calls work.  Here's some > code... > > class ParentClass(): >   def __init__(self): >       do something here You should inherit object to use super(): class ParentClass(object):

Re: [Tutor] Is it possible for a Python Program to send commands to the Python Interpreter?

2010-02-19 Thread Kent Johnson
On Fri, Feb 19, 2010 at 7:07 PM, Steven D'Aprano wrote: > On Sat, 20 Feb 2010 06:33:04 am Kent Johnson wrote: > >> It sounds like you are looking for eval() >> >> (Standard warning - use eval() only on trusted data) > > > This is the tutor list, aimed at

Re: [Tutor] Reading large bz2 Files

2010-02-19 Thread Kent Johnson
On Fri, Feb 19, 2010 at 7:42 AM, Norman Rieß wrote: > Hello, > > i am trying to read a large bz2 file with this code: > > source_file = bz2.BZ2File(file, "r") > for line in source_file: >    print line.strip() > > But after 4311 lines, it stoppes without a errormessage. The bz2 file is > much bigg

Re: [Tutor] Is it possible for a Python Program to send commands to the Python Interpreter?

2010-02-19 Thread Kent Johnson
On Fri, Feb 19, 2010 at 1:56 PM, Carnell, James E wrote: > > I am trying to teach a computer program - to program. It builds grammars and > procedural memories on dictionary networks. How do I get the program to be > able to input to the interpreter/command line and read the results? I have > done

Re: [Tutor] Python and algorithms

2010-02-18 Thread Kent Johnson
On Thu, Feb 18, 2010 at 9:43 AM, C.T. Matsumoto wrote: > Here is the example. > > "To keep this simple and practical, as a suggestion, consider the problem of > sorting a list (a pack of cards, or a list of names or whatever you want) > into order." > > Yes, there are many built-ins that wrap goo

Re: [Tutor] Python and algorithms

2010-02-18 Thread Kent Johnson
On Thu, Feb 18, 2010 at 8:17 AM, C.T. Matsumoto wrote: > Kent Johnson wrote: >> But is that what you are asking for, or are you trying to sharpen your >> problem-solving skills? Many progamming problems are solved by simple >> loops and data structures without explicitly

Re: [Tutor] Python and algorithms

2010-02-18 Thread Kent Johnson
On Thu, Feb 18, 2010 at 4:59 AM, C.T. Matsumoto wrote: > Hello Tutors, > > Can someone point me to any resources that can teach me about algorithms in > python? > > I'm interested in learning how to analyze and make an algorithm. I have been reading The Algorithm Design Manual http://www.algorist

Re: [Tutor] datetime, time zones, and ISO time

2010-02-17 Thread Kent Johnson
On Wed, Feb 17, 2010 at 4:37 PM, David Perlman wrote: > OK, here's a function that does precisely what I want: > > def tzDelta(): >  """by whatever means necessary, return the current offset of the local time > from utc.""" >  s=time.time() >  t,u=time.localtime(s),time.gmtime(s) >  osec=3600*(t[3

Re: [Tutor] datetime, time zones, and ISO time

2010-02-17 Thread Kent Johnson
now that as William sent, the documentation points out that the > rules the world over are complicated and irrational.  Nonetheless, it is > implicit in the existing definitions that the system *knows* the current > offset, even if it doesn't know the whole set of rules... > > > On F

Re: [Tutor] datetime, time zones, and ISO time

2010-02-17 Thread Kent Johnson
On Wed, Feb 17, 2010 at 3:12 PM, David Perlman wrote: > Yeah, I got this part.  The thing that's hanging me up is that there doesn't > seem to be any way to get a tzinfo instance that contains the current local > time zone information.  You can do time.timezone to get the seconds from > UTC, but t

Re: [Tutor] Find duplicates (using dictionaries)

2010-02-17 Thread Kent Johnson
On Wed, Feb 17, 2010 at 11:31 AM, Karjer Jdfjdf wrote: > I'm relatively new at Python and I'm trying to write a function that fills > a dictionary acording the following rules and (example) data: > > Rules: > * No duplicate values in field1 > * No duplicates values in field2 and field3 simultaneou

Re: [Tutor] count time limit

2010-02-16 Thread Kent Johnson
On Tue, Feb 16, 2010 at 11:54 AM, Shurui Liu (Aaron Liu) wrote: > >  Modify the guess_my_number.py program to limit the number of guesses to ten (10). > >    Tell the user up front that they have ten guesses. > > > After each guess, tell the user that they have ___ guesses remaining. > > Here are

Re: [Tutor] ipython, PYTHONPATH, on a MAC

2010-02-16 Thread Kent Johnson
On Tue, Feb 16, 2010 at 10:46 AM, John [H2O] wrote: > > Hello, > > I'm not a Mac user, but I'm a promoter of Python! I have a good friend using > a Mac who's becoming sceptical of python due to frustrations with the > PYTHONPATH. I'm trying to help... > > Everything is fine running vanilla python.

Re: [Tutor] PyCon anyone?

2010-02-16 Thread Kent Johnson
On Tue, Feb 16, 2010 at 10:17 AM, Wayne Watson wrote: >> >> Hi all, >> >> I'm going to PyCon this year for the first time (yeah!) and I would >> love to meet other regular contributors to the tutor list. Is anyone >> else going to be there? Any interest in a "Meet the tutors" Open Space >> or dinn

Re: [Tutor] PyCon anyone?

2010-02-16 Thread Kent Johnson
On Tue, Feb 16, 2010 at 10:09 AM, Vern Ceder wrote: > Kent Johnson wrote: >> >> Hi all, >> >> I'm going to PyCon this year for the first time (yeah!) and I would >> love to meet other regular contributors to the tutor list. Is anyone >> else going to

[Tutor] PyCon anyone?

2010-02-16 Thread Kent Johnson
Hi all, I'm going to PyCon this year for the first time (yeah!) and I would love to meet other regular contributors to the tutor list. Is anyone else going to be there? Any interest in a "Meet the tutors" Open Space or dinner? Kent ___ Tutor maillist -

Re: [Tutor] Problem with "input" in Python 3

2010-02-15 Thread Kent Johnson
On Mon, Feb 15, 2010 at 7:34 AM, pja wrote: > 05 import math > 06 > 07 def main(): > 08 print("This program finds the real solutions to a quadratic\n") > 09 > 10 a, b, c = input("Please enter the coefficients (a, b, c): ") > 11 > 12 ''' > 13 a = int(input("Please enter the first coefficient: "))

Re: [Tutor] Editing html using python

2010-02-15 Thread Kent Johnson
On Mon, Feb 15, 2010 at 7:28 AM, Amit Sethi wrote: > Well ya I was kind of hoping to know about more tools and recommendations on > how to edit broken html . This page lists several alternatives: html5, lxml, elementtree: http://www.crummy.com/software/BeautifulSoup/3.1-problems.html > Their wer

Re: [Tutor] Getting caller name without the help of "sys._getframe(1).f_code.co_name" ?

2010-02-15 Thread Kent Johnson
On Mon, Feb 15, 2010 at 6:07 AM, patrice laporte wrote: > My own experience is that there is too much coder that forget the app they > work on is aim to be used by "real human", not by C/C++/Python/put what ever > you want here/ guru : if your app popups to the user a message that is just > what

Re: [Tutor] Editing html using python

2010-02-14 Thread Kent Johnson
On Sun, Feb 14, 2010 at 6:10 AM, Amit Sethi wrote: > Hi I need to edit html programmatically . Sadly the html might be broken at > places . I was using BeautifulSoup but there were lots of problems and it is > also not maintained can some one guide me to any tutorials on editing html > using lxml

Re: [Tutor] Getting caller name without the help of "sys._getframe(1).f_code.co_name" ?

2010-02-14 Thread Kent Johnson
On Sun, Feb 14, 2010 at 6:33 AM, patrice laporte wrote: > - try/catch open(this_file_name) and if I got an IOErro exception, I > re-raise my own exception with : >- the name of the class where that IOError occured >- the name of the method in that class that make that error occured >-

Re: [Tutor] asigning class variables

2010-02-13 Thread Kent Johnson
On Sat, Feb 13, 2010 at 8:08 PM, the kids wrote: > Hi, my name is John Paul. > > I was trying to define a class but I can't make it asign particular objects > particular variables at their creation.  Please help. It would help to see some details of what you are trying to do. It sounds like you w

Re: [Tutor] json file

2010-02-13 Thread Kent Johnson
On Sat, Feb 13, 2010 at 3:00 PM, Chris Patillo wrote: > Thanks for your response.  i did some research on json.load() and I don't > understand how you extract the data from it.  How do I get just the name and > number from the file? The value returned from json.load() is a Python dictionary. The

Re: [Tutor] ask

2010-02-13 Thread Kent Johnson
2010/2/13 Shurui Liu (Aaron Liu) : > Yeah, i know. I don't want somebody tell me all the answers of these > assignment directly. I just want to know is there any error in the commands > listed online? My teacher told us there is some, but I cannot find out. He > said we can run them on putty.exe as

Re: [Tutor] ask

2010-02-13 Thread Kent Johnson
On Sat, Feb 13, 2010 at 4:08 PM, 刘书睿 wrote: > Here are my assignment about Python, I don't know if anything is wrong. Is > there anybody can help me? > > 1. assignment 9a and 9b hyperlink: > > http://cset.sp.utoledo.edu/cset1100py/cset1100_assign.html#simplepy > > 2. I don't know how to run a prog

Re: [Tutor] Getting caller name without the help of "sys._getframe(1).f_code.co_name" ?

2010-02-13 Thread Kent Johnson
On Sat, Feb 13, 2010 at 10:56 AM, patrice laporte wrote: > Being in an exeption of my own, I want to print the name of the caller, and > I'm looking for a way to have it. > > I've found a lot of recipe all of them using what seems to be, according to > me, a not so good trick : all those recipe m

Re: [Tutor] json file

2010-02-13 Thread Kent Johnson
On Sat, Feb 13, 2010 at 7:21 AM, Chris Patillo wrote: > I need to read in a .json file and write out a file with some of the > information from this file.  I can't figure out how to read the .json file > in.  I know there is a module for this, but I don't understand how it works. > > The file I am

Re: [Tutor] The Order of Imports and install order of modules and other matters (XP vs W7, ...)

2010-02-13 Thread Kent Johnson
On Fri, Feb 12, 2010 at 10:55 PM, Wayne Watson wrote: > There seems to be something of a general consensus in ordering import > statements. Something like standard library imports first. When using tools > like matlablib or tkinter (maybe), must one keep an order among the relevant > imports? I d

Re: [Tutor] Not understanding this code example. Help, please.

2010-02-13 Thread Kent Johnson
On Fri, Feb 12, 2010 at 11:49 PM, Eduardo Vieira wrote: > Hello! I was reading the latest version of Mark Pilgrim's "Dive into > Python" and am confused with these example about the pluralization > rules. See http://diveintopython3.org/examples/plural3.py and > http://diveintopython3.org/generator

Re: [Tutor] SMTP

2010-02-11 Thread Kent Johnson
On Thu, Feb 11, 2010 at 3:13 PM, Grigor Kolev wrote: > Hi. > I try send a mail with smtplib > Server work with postfix. > I try it > >  import smtplib >  s=smtplib.SMTP("localhost") > tolist=['grigor.ko...@gmail.com'] > msg = '''\ >  From: grigor.ko

Re: [Tutor] Algorithm for combination analysis suggestion.

2010-02-11 Thread Kent Johnson
On Thu, Feb 11, 2010 at 1:59 PM, Matthew Matson wrote: > > Hi Tutors, > > I am looking for the proper approach regarding the analysis of a dictionary > of combinations I have. > > What I need to do is read from a supplied text file that has a unique ID and > that unique ID's associated combination

Re: [Tutor] string to list

2010-02-11 Thread Kent Johnson
On Thu, Feb 11, 2010 at 8:37 AM, Stefan Behnel wrote: > Kent Johnson, 11.02.2010 14:16: >> On Thu, Feb 11, 2010 at 4:44 AM, Stefan Behnel wrote: >> >>> 2) given that you have lists as items in the 'data' list, it's enough to >>> call sort() on

Re: [Tutor] Simple Stats on Apache Logs

2010-02-11 Thread Kent Johnson
On Thu, Feb 11, 2010 at 4:56 AM, Lao Mao wrote: > Hi, > > I have 3 servers which generate about 2G of webserver logfiles in a day. > These are available on my machine over NFS. > > I would like to draw up some stats which shows, for a given keyword, how > many times it appears in the logs, per hou

Re: [Tutor] string to list

2010-02-11 Thread Kent Johnson
On Thu, Feb 11, 2010 at 4:44 AM, Stefan Behnel wrote: > 2) given that you have lists as items in the 'data' list, it's enough to > call sort() once, as the comparison of lists is defined as the comparison > of each item to the corresponding item of the other list. If you want to > sort based on t

Re: [Tutor] html and python

2010-02-11 Thread Kent Johnson
2010/2/11 Григор : > I found this. > http://karrigell.sourceforge.net/en/pythoninsidehtml.htm Many options here: http://wiki.python.org/moin/Templating Kent ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://ma

Re: [Tutor] running split and count + looping to check for numbers in same line

2010-02-10 Thread Kent Johnson
On Wed, Feb 10, 2010 at 6:43 PM, jim serson wrote: > I am getting an error when I try and run split and count I seem to get it to > work with one or the other but not together. python wants a character buffer > but I am not sure how to use it. > > I would also like to use readline to check and see

Re: [Tutor] need idea

2010-02-10 Thread Kent Johnson
On Wed, Feb 10, 2010 at 4:27 PM, invincible patriot wrote: > hi > i want to compare a string with a dictionary > or u can say that i want to take user input A STRING, and want to compare > each character of that string with the KEYS  in the dictionary, and then i > wana print the values for the ch

Re: [Tutor] html and python

2010-02-10 Thread Kent Johnson
On Wed, Feb 10, 2010 at 2:54 PM, Grigor Kolev wrote: > В 14:39 -0500 на 10.02.2010 (ср), Kent Johnson написа: >> On Wed, Feb 10, 2010 at 2:30 PM, Grigor Kolev wrote: >> > Hi. >> > I want to make a list of E-mail, photos and some additional data. >> > But I w

Re: [Tutor] html and python

2010-02-10 Thread Kent Johnson
On Wed, Feb 10, 2010 at 2:30 PM, Grigor Kolev wrote: > Hi. > I want to make a list of E-mail, photos and some additional data. > But I want this list to be displayed in one site. > How can I send data from a list of site page. Which module should I use I don't understand "send data from a list of

Re: [Tutor] string to list

2010-02-10 Thread Kent Johnson
On Wed, Feb 10, 2010 at 8:32 AM, Owain Clarke wrote: > My son was doing a statistics project in which he had to sort some data by > either one of two sets of numbers, representing armspan and height of a > group of children - a boring and painstaking job.  I came across this piece > of code:- > >

Re: [Tutor] string to list

2010-02-10 Thread Kent Johnson
On Wed, Feb 10, 2010 at 6:26 AM, Owain Clarke wrote: > Please excuse the obviousness of my question (if it is), but I have searched > the documentation for how to generate a list e.g. [(1,2), (3,4)] from a > string "[(1,2), (3,4)]". I wonder if someone could point me in the right > direction. Pyt

Re: [Tutor] "Error :Attempt to overwrite cell" while using xlwt to create excel sheets

2010-02-10 Thread Kent Johnson
On Wed, Feb 10, 2010 at 6:47 AM, nikunj badjatya wrote: > I commented out the "raise Exception" statement in Row.py library > module. > Here's the (line no. 150 ) of Row.py which i have edited: > >   def insert_cell(self, col_index, cell_obj): >         if col_index in self.__cells: >            

Re: [Tutor] NameError: global name 'celsius' is not defined (actually, solved)

2010-02-10 Thread Kent Johnson
On Tue, Feb 9, 2010 at 10:00 PM, David wrote: > Hi guys, > > I just wrote this message, but after restarting ipython all worked fine. > How is it to be explained that I first had a namespace error which, after a > restart (and not merely a new "run Sande_celsius-main.py"), went away? I > mean, sur

Re: [Tutor] rstrip in list?

2010-02-09 Thread Kent Johnson
On Tue, Feb 9, 2010 at 11:09 AM, Ken G. wrote: > > Kent Johnson wrote: > > On Tue, Feb 9, 2010 at 10:28 AM, Ken G. wrote: > > > I printed out some random numbers to a datafile and use 'print mylist' and > they came out like this: > > ['102\n

Re: [Tutor] rstrip in list?

2010-02-09 Thread Kent Johnson
On Tue, Feb 9, 2010 at 10:28 AM, Ken G. wrote: > I printed out some random numbers to a list and use 'print mylist' and > they came out like this: > > ['102\n', '231\n', '463\n', '487\n', '555\n', '961\n'] How are you generating this list? You should be able to create it without the \n. That woul

Re: [Tutor] if item.find(extension)!= -1: -- what's the -1?

2010-02-06 Thread Kent Johnson
On Sat, Feb 6, 2010 at 11:35 AM, David wrote: > Hello again, > > in Knowlton's 2008 book "Python: Create, Modify, Reuse" the author makes > frequent use of the term -1 in his code, but doesn't tell to what aim. For > want of search terms Google is not helpful. Could someone please enlighten > me b

Re: [Tutor] Variable: From input and output

2010-02-05 Thread Kent Johnson
On Thu, Feb 4, 2010 at 5:39 PM, ssiverling wrote: > > > I uploaded a file.  I know it's not very impressive. Where did you upload it? For short programs you can just include them in your email. Also, please don't top-post, and please subscribe to the list. Kent >

Re: [Tutor] Variable: From input and output

2010-02-04 Thread Kent Johnson
On Thu, Feb 4, 2010 at 1:19 PM, ssiverling wrote: > So I have been working on this example for a little while.  I looked for the > answer before posting.  I tried to use two raw inputs, then use > sys.stdout.write, to add them together.  However I think I might need to use > a variable.  Any help

Re: [Tutor] correcting an Active State Recipe for conversion to ordinal

2010-02-04 Thread Kent Johnson
On Thu, Feb 4, 2010 at 1:21 PM, Serdar Tumgoren wrote: >> Perhaps the code on activestate is not a correct copy of what you are >> running? The conditional at line 23 extends all the way to line 35 - >> the end of the function - so if value % 100/10 == 1 no more code is >> executed and None is ret

Re: [Tutor] Help with cursors please

2010-02-04 Thread Kent Johnson
On Thu, Feb 4, 2010 at 12:47 PM, Alan Harris-Reid wrote: > Hi, > > I have a SQLite cursor which I want to traverse more than once, eg... > for row in MyCursor: >   method1(row) >  then later... > for row in MyCursor: >   method2(row) >  Method2 is never run, I guess because the pointer is at the b

Re: [Tutor] correcting an Active State Recipe for conversion to ordinal

2010-02-04 Thread Kent Johnson
On Thu, Feb 4, 2010 at 1:09 PM, Kent Johnson wrote: > On Thu, Feb 4, 2010 at 12:11 PM, Serdar Tumgoren wrote: >> Here's the link to the recipe: >> >> http://code.activestate.com/recipes/576888/ > > Perhaps the code on activestate is not a correct copy of what yo

Re: [Tutor] correcting an Active State Recipe for conversion to ordinal

2010-02-04 Thread Kent Johnson
On Thu, Feb 4, 2010 at 12:11 PM, Serdar Tumgoren wrote: > I just noticed, however, that in the comments section of the > ActiveState recipe that someone is getting incorrect results for > certain numbers (11 and 12, specifically). > > But when I use the code on my own machine it still works fine.

Re: [Tutor] language aid

2010-02-04 Thread Kent Johnson
On Thu, Feb 4, 2010 at 5:43 AM, Owain Clarke wrote: > My question is, that if I proceed like this I will end up with a single list > of potentially several hundred strings of the form "frword:engword". In > terms of performance, is this a reasonable way to do it, or will the program > increasingl

Re: [Tutor] help with strings

2010-02-03 Thread Kent Johnson
On Wed, Feb 3, 2010 at 8:19 AM, NISA BALAKRISHNAN wrote: > hi > > I am very new to python. > I have a string for example : 123B     new Project > i want to separate 123B as a single string and new  project as another > string . > how can i do that. > i tried using partition but couldnt do it str.

Re: [Tutor] parse text file

2010-02-02 Thread Kent Johnson
On Tue, Feb 2, 2010 at 4:56 PM, Norman Khine wrote: > On Tue, Feb 2, 2010 at 10:11 PM, Kent Johnson wrote: >> Try this version: >> >> data = file.read() >> >> get_records = re.compile(r"""openInfoWindowHtml\(.*?\ticon: >> myIcon

Re: [Tutor] parse text file

2010-02-02 Thread Kent Johnson
On Tue, Feb 2, 2010 at 1:39 PM, Norman Khine wrote: > On Tue, Feb 2, 2010 at 4:19 PM, Kent Johnson wrote: >> On Tue, Feb 2, 2010 at 9:33 AM, Norman Khine wrote: >>> On Tue, Feb 2, 2010 at 1:27 PM, Kent Johnson wrote: >>>> On Tue, Feb 2, 2010 at 4:16 AM, Norman

Re: [Tutor] parse text file

2010-02-02 Thread Kent Johnson
On Tue, Feb 2, 2010 at 9:33 AM, Norman Khine wrote: > On Tue, Feb 2, 2010 at 1:27 PM, Kent Johnson wrote: >> On Tue, Feb 2, 2010 at 4:16 AM, Norman Khine wrote: >> >>> here are the changes: >>> >>> import re >>> file=open('producer

Re: [Tutor] how to pass data to aother function from a class?

2010-02-02 Thread Kent Johnson
On Tue, Feb 2, 2010 at 8:04 AM, Zheng Jiekai wrote: > I'm beginning my python learning. My python version is 3.1 > > I‘v never learnt OOP before. > So I'm confused by the HTMLParser > > Here's the code: from html.parser import HTMLParser class parser(HTMLParser): > def handle_data(self,

Re: [Tutor] parse text file

2010-02-02 Thread Kent Johnson
On Tue, Feb 2, 2010 at 4:16 AM, Norman Khine wrote: > here are the changes: > > import re > file=open('producers_google_map_code.txt', 'r') > data =  repr( file.read().decode('utf-8') ) Why do you use repr() here? > get_record = re.compile(r"""openInfoWindowHtml\(.*?\\ticon: myIcon\\n""") > get

Re: [Tutor] parse text file

2010-02-01 Thread Kent Johnson
On Mon, Feb 1, 2010 at 6:29 AM, Norman Khine wrote: > thanks, what about the whitespace problem? \s* will match any amount of whitespace includin newlines. Kent ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: htt

Re: [Tutor] hash value input

2010-01-30 Thread Kent Johnson
On Sat, Jan 30, 2010 at 4:56 AM, spir wrote: > I'm surprised of this, for this should create as many indexes (in the > underlying array actually holding the values) as there are integer keys. With > possibly huge holes in the array. Actually, there will certainly be a > predefined number of in

Re: [Tutor] hash value input

2010-01-29 Thread Kent Johnson
On Fri, Jan 29, 2010 at 1:20 PM, Rich Lovely wrote: > I've played with this a little.  The following class was quite handy for this: > > class BrokenHash(object): >    def __init__(self, hashval): >        self.hashval = hashval >    def __hash__(self): >        return self.hashval > > It basical

Re: [Tutor] hash value input

2010-01-29 Thread Kent Johnson
On Fri, Jan 29, 2010 at 8:03 AM, spir wrote: > I recently discovered that Lua uses the data's address (read: id) as input to > the hash func. This allows Lua tables (a kind of more versatile associative > array) to use _anything_ as key, since the id is guaranteed not to change, > per definiti

Re: [Tutor] multiply and sum two lists with list comprehension?

2010-01-28 Thread Kent Johnson
On Thu, Jan 28, 2010 at 1:22 AM, Muhammad Ali wrote: > > Hi, > > I am multipliying two lists so that each of list As elements get multiplied > to the corresponding list Bs. Then I am summing the product. > > For example, A= [1, 2, 3] and B=[2, 2, 2] so that I get [2, 4, 6] after > multiplication a

Re: [Tutor] length of a string? Advice saught

2010-01-28 Thread Kent Johnson
On Wed, Jan 27, 2010 at 6:57 PM, Alan Gauld wrote: > read() functions usually have an optional buffersize parameter > set to a "reasonable" size. If you try to read more than that it > will be truncated. This is explained in the read() documentation > for files. ?? files have a buffer size that s

Re: [Tutor] The magic parentheses

2010-01-24 Thread Kent Johnson
On Sun, Jan 24, 2010 at 12:08 PM, Alan Gauld wrote: > > "Hugo Arts" wrote > > print "this is {0}".format("formatted") >> >> this is formatted > > Caveat: > this style only works in Python 3.0 upwards  (or maybe in 2.6/2.7?) It's in 2.6 http://docs.python.org/library/stdtypes.html#str.for

Re: [Tutor] combinatorics problem: assembling array

2010-01-21 Thread Kent Johnson
On Thu, Jan 21, 2010 at 8:07 AM, Kent Johnson wrote: > On Thu, Jan 21, 2010 at 4:06 AM, markus kossner wrote: >> Dear Pythonics, >> I have a rather algorithmic problem that obviously made a knot in my brain: >> >> Assume we have to build up all the arrays that are poss

Re: [Tutor] combinatorics problem: assembling array

2010-01-21 Thread Kent Johnson
On Thu, Jan 21, 2010 at 4:06 AM, markus kossner wrote: > Dear Pythonics, > I have a rather algorithmic problem that obviously made a knot in my brain: > > Assume we have to build up all the arrays that are possible if we have a > nested array > containing an array of integers that are allowed for

Re: [Tutor] Still searching in html files

2010-01-21 Thread Kent Johnson
On Thu, Jan 21, 2010 at 4:03 AM, Paul Melvin wrote: > The code is at http://python.codepad.org/S1ul2bh7 and the bit I would like > some advice on is how to get the sorted data and where to put it. Generally the code seems a bit disorganized, consider breaking it into functions. There is a fair a

Re: [Tutor] keeping track of the present line in a file

2010-01-21 Thread Kent Johnson
On Thu, Jan 21, 2010 at 1:57 AM, sudhir prasad wrote: > hi, > is there any other way to keep track of line number in a file other than > fileinput.filelineno() With enumerate(): for line_number, line in enumerate(open('myfile.txt')): # etc Kent ___

Re: [Tutor] Python workspace - IDE and version control

2010-01-19 Thread Kent Johnson
On Tue, Jan 19, 2010 at 9:12 AM, Andreas Kostyrka wrote: > The cool part about git that I've not yet replicated with hg is git add -p > which allows you to seperate out > different changes in the same file. Sounds like the record and crecord extensions come close, anyway: http://mercurial.seleni

Re: [Tutor] Python workspace - IDE and version control

2010-01-19 Thread Kent Johnson
On Mon, Jan 18, 2010 at 4:17 PM, Alan Gauld wrote: > I use plain old RCS for version control because its just me working on the > code. Wow. You should take a look at Mercurial. It is so easy to set up a Mercurial repository for a local project - just hg init # create a repository hg st # show w

Re: [Tutor] smtp project

2010-01-18 Thread Kent Johnson
smtplib to talk to the remote MTA on port 25? - The std lib contains a simple SMTP server in smtpd.py - Lamson is a more robust SMTP server http://lamsonproject.org/ - Twisted has SMTP support http://twistedmatrix.com/trac/wiki/TwistedMail Kent PS Please Reply All to reply on list. >

Re: [Tutor] smtp project

2010-01-17 Thread Kent Johnson
On Sun, Jan 17, 2010 at 3:45 PM, Kirk Z Bailey wrote: > I am writing a script that will send an email message. This will run in a > windows XP box. The box does not have a smtp server, so the script must > crete not merely a smtp client to talk to a MTA, it must BE one for the > duration of sendin

Re: [Tutor] Keeping a list of attributes of a certain type

2010-01-15 Thread Kent Johnson
On Fri, Jan 15, 2010 at 3:43 PM, Guilherme P. de Freitas wrote: > Ok, I checked the answers you all gave me, and the suggestions seem to be 2: > > a. Compute the list of members on the fly, with a list comprehension > that looks up stuff on self.__dict___; > > b. Stay with my solution, but substit

Re: [Tutor] Searching in a file

2010-01-15 Thread Kent Johnson
On Fri, Jan 15, 2010 at 4:24 AM, Paul Melvin wrote: > Hi, > > Thanks very much to all your suggestions, I am looking into the suggestions > of Hugo and Alan. > > The file is not very big, only 700KB (~2 lines), which I think should be > fine to be loaded into memory? > > I have two further que

Re: [Tutor] Keeping a list of attributes of a certain type

2010-01-14 Thread Kent Johnson
On Wed, Jan 13, 2010 at 11:15 PM, Guilherme P. de Freitas wrote: > Ok, I got something that seems to work for me. Any comments are welcome. > > > class Member(object): >    def __init__(self): >        pass > > > class Body(object): >    def __init__(self): >        self.members = [] > >    def __

Re: [Tutor] Keeping a list of attributes of a certain type

2010-01-14 Thread Kent Johnson
On Wed, Jan 13, 2010 at 9:24 PM, Guilherme P. de Freitas wrote: > Hi everybody, > > Here is my problem. I have two classes, 'Body' and 'Member', and some > attributes of 'Body' can be of type 'Member', but some may not. The > precise attributes that 'Body' has depend from instance to instance, > a

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Kent Johnson
On Wed, Jan 13, 2010 at 2:21 PM, Stefan Behnel wrote: > Hugo Arts, 13.01.2010 15:25: >> >> Here is my solution for the general case: >> >> from itertools import groupby >> def alphanum_key(string): >>    t = [] >>    for isdigit, group in groupby(string, str.isdigit): >>        group = ''.join(gro

Re: [Tutor] samples on sort method of sequence object.

2010-01-12 Thread Kent Johnson
On Tue, Jan 12, 2010 at 9:39 AM, Make Twilight wrote: >  I can understand how to use parameters of cmp and reverse,except the > key parameter... >  Would anyone give me an example of using sort method with key parameter? http://personalpages.tds.net/~kent37/kk/7.html Kent ___

Re: [Tutor] Numpy unexpected result: subtraction of cell values

2010-01-11 Thread Kent Johnson
On Mon, Jan 11, 2010 at 2:02 PM, Carnell, James E wrote: >> I want to subtract the Red Value in an array cell from a neighboring >> Red Value cell. >> >> >>> pictArray[39][4]    #pixel at 39 4 >> array([150, 140, 120], dtype=unint8) >> >> >>> pictArray[39][5]    #p

Re: [Tutor] composing one test suite from two test cases

2010-01-11 Thread Kent Johnson
On Mon, Jan 11, 2010 at 8:53 AM, Tom Roche wrote: > Kent Johnson Mon, 11 Jan 2010 06:42:39 -0500 >> However I don't recommend this style of organizing tests. I prefer >> using nose for test discovery, it saves the work of creating all the >> aggregating suites. >

Re: [Tutor] Tips

2010-01-11 Thread Kent Johnson
On Mon, Jan 11, 2010 at 12:33 AM, VacStudent wrote: > I would like to get a python book, how and where to get one? Amazon.com? Or lots of free resources online. Kent ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] what is the equivalent function to strtok() in c++

2010-01-11 Thread Kent Johnson
On Mon, Jan 11, 2010 at 2:33 AM, sudhir prasad wrote: > hi, > what is the equivalent function to strtok() in c++, > what i need to do is to divide a line into different strings and store them > in different lists,and write them in to another file To split on a single character or a fixed sequence

Re: [Tutor] composing one test suite from two test cases

2010-01-11 Thread Kent Johnson
On Sun, Jan 10, 2010 at 10:44 PM, Tom Roche wrote: > > How to create a single unittest test suite class that runs all methods > from multiple TestCase classes? Why I ask: > > I'm trying to relearn TDD and learn Python by coding a simple app. > Currently the app has 2 simple functional classes, Pid

Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-10 Thread Kent Johnson
On Sat, Jan 9, 2010 at 3:50 AM, spir wrote: > Lie Ryan dixit: > >> only use "from module import *" if the >> module was designed for such use > > In most cases, this translates to: the imported module defines __names__, > which holds the list of names (of the objects) to be exported. Check it. >

  1   2   3   4   5   6   7   8   9   10   >