Re: [Tutor] Challenge supporting custom deepcopy with inheritance

2009-06-01 Thread Kent Johnson
On Mon, Jun 1, 2009 at 4:55 PM, Alan Gauld wrote: > We can fake the Delphi style by using a default constructor and then just > calling the "constructors" after initialisation: > > class C: >        def __init__(): pass >       @constructor >       def LoadFromFile(fname, count): ... >     �...@c

Re: [Tutor] serious problem with graphics module

2009-06-04 Thread Kent Johnson
On Wed, Jun 3, 2009 at 5:51 PM, W W wrote: > Do you (or sombody else) know how to get ipython working with Python 2.6 > (you know, > the Python release, which has that new turtle module ;-)   ) > > doesn't install on my Windows box... other than that I've got no experience > with it What trouble

Re: [Tutor] split or replace

2009-06-05 Thread Kent Johnson
On Fri, Jun 5, 2009 at 7:18 AM, Norman Khine wrote: > Hello, > What is the way to group each value so that I get a list, from a string like: > > dir = '/expert/forum/expert/expert' > list = ['/expert', '/forum', '/expert', '/expert'] Here is one way using re.split(): In [28]: import re In [29]: [

Re: [Tutor] class design

2009-06-06 Thread Kent Johnson
On Sat, Jun 6, 2009 at 5:04 AM, Norman Khine wrote: > Hello, > I would like help to design the following: > http://paste.lisp.org/display/81448 Product.get_days() may have a bug, it only returns the first container it finds. You probably don't want the view code in the same class with the data. I

Re: [Tutor] class design

2009-06-06 Thread Kent Johnson
On Sat, Jun 6, 2009 at 8:26 AM, Norman Khine wrote: >> You probably don't want the view code in the same class with the data. >> It's generally a good idea to separate the model - the representation >> of data - from the view - the display of the data. > > In iTools, each class has a view, edit, s

Re: [Tutor] class design

2009-06-06 Thread Kent Johnson
r pattern which separates the model and view. The View classes are responsible for display of data but not for the contents. It's not clear from the examples where the model fits in but it is distinct from the view. Kent > On Sat, Jun 6, 2009 at 3:24 PM, Kent Johnson wrote: >> On Sat,

Re: [Tutor] gui problem

2009-06-06 Thread Kent Johnson
Can you try that again? Kent On Sat, Jun 6, 2009 at 4:20 PM, Essah Mitges wrote: > > from math import sin, cos, pi import pygame displayWidth = 640displayHeight > = 480fpsLimit = 90 def sinInterpolation(start, end, steps=30):    values = > [start]    delta = end - start    for i in range(1, steps

Re: [Tutor] converting xls to csv

2009-06-06 Thread Kent Johnson
On Sat, Jun 6, 2009 at 5:37 PM, Nick Burgess wrote: > Thanks everyone, the following code works great.  It returns the name > of the file and the row that matched the reqex.  Is it posible to take > the regex compile from user input?  To make it take an argument,  like > >> csvSearch.py 10.192.55 >

Re: [Tutor] creating a range above & below a given number

2009-06-07 Thread Kent Johnson
On Sun, Jun 7, 2009 at 10:08 AM, Gonzalo Garcia-Perate wrote: >  the solution laid somewhere in between: > > def within_range(self, n, n2, threshold=5): >        if n in range(n2-threshold, n2+threshold+1) and n < > n2+threshold or n > n2 + threshold : return True >        return False This is a b

Re: [Tutor] creating a range above & below a given number

2009-06-07 Thread Kent Johnson
On Sun, Jun 7, 2009 at 1:17 PM, Gonzalo Garcia-Perate wrote: > Emile, Kent thank you both for your reply, after sending my previous > email I realised that it wasn't working as expected in all cases. > > this does work: > > def within_range_final(self, n, n2, threshold=5): >     return n in range(n

Re: [Tutor] creating a range above & below a given number

2009-06-07 Thread Kent Johnson
On Sun, Jun 7, 2009 at 3:34 PM, Emile van Sebille wrote: > To explain why we've tended to suggest using int and minval tests and avoid the range inclusion test, consider the following timeit > results: The performance penalty for 'in range(...)' is even greater when the value is not found, becaus

Re: [Tutor] Hi

2009-06-08 Thread Kent Johnson
On Mon, Jun 8, 2009 at 7:30 AM, Eddie wrote: > Hi, I'm new and just starting to learn Python. Just testing if this > works or not and if anybody reads it lol. Yes, it works. Welcome! Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/ma

Re: [Tutor] creating a range above & below a given number

2009-06-08 Thread Kent Johnson
On Mon, Jun 8, 2009 at 12:56 PM, Gonzalo Garcia-Perate wrote: > Kent, Emile thank you both. You're absolutely right, I was going for > range because I thought it made the code more readable/more explicit. > I hadn't taken into account the performance hit of creating the list > and iterating through

Re: [Tutor] recursive glob -- recursive dir walk

2009-06-10 Thread Kent Johnson
On Wed, Jun 10, 2009 at 2:28 AM, spir wrote: > Hello, > > A foolow-up ;-) from previous question about glob.glob(). > > I need to 'glob' files recursively from a top dir (parameter). Tried to use > os.walk, but the structure of its return value is really unhandy for such a > use (strange, because

Re: [Tutor] vpython compatibility

2009-06-10 Thread Kent Johnson
On Wed, Jun 10, 2009 at 1:52 PM, roberto wrote: > and last question: may python 3.0 and 2.6 be installed on the same pc ? Yes, no problem. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Syntax Error First Example

2009-06-11 Thread Kent Johnson
On Wed, Jun 10, 2009 at 10:02 PM, Randy Trahan wrote: > First, I am suppose to put this in the script mode vs the IDLE mode correct? > He failed to mention where.. Generally the "Python Shell" window is for interactive exploration and to see the results of your scripts. To type in a complete prog

Re: [Tutor] How do I do this in python?

2009-06-11 Thread Kent Johnson
On Wed, Jun 10, 2009 at 9:43 PM, Robert Lummis wrote: > I want to write a function that I can use for debugging purposes that > prints the values of whatever list of object references it is given as > arguments, without knowing in advance how many object references it > will be called with or what

Re: [Tutor] How do I do this in python?

2009-06-11 Thread Kent Johnson
On Wed, Jun 10, 2009 at 9:43 PM, Robert Lummis wrote: > I want to write a function that I can use for debugging purposes that > prints the values of whatever list of object references it is given as > arguments, without knowing in advance how many object references it > will be called with or what

Re: [Tutor] Help..Concatenaton Error

2009-06-12 Thread Kent Johnson
On Thu, Jun 11, 2009 at 9:00 PM, Randy Trahan wrote: > Also Programming Lanquage Question: > I have studied and an fairly proficient at XHTML and CSS, I tried Javascript > but just didn't like it for some reason..so I am trying Python which so far > fits my personality, needs, whatever that part i

Re: [Tutor] use of __new__

2009-06-12 Thread Kent Johnson
On Fri, Jun 12, 2009 at 8:37 AM, Lie Ryan wrote: class Normal(object): > ...     def __new__(cls, arg): > ...         if arg: > ...             return Special(arg) > ...         else: > ...             ret = super(Normal, cls).__new__(cls) > ...             ret.__init__(arg) > ...            

Re: [Tutor] use of __new__

2009-06-12 Thread Kent Johnson
On Fri, Jun 12, 2009 at 9:48 AM, spir wrote: > Right, thank you. I continued my trials and ended with seemingly working > code, close to yours. > >                # case pattern is Klass: yield String instead >                if isinstance(pattern,Klass): >                        self = String(pat

Re: [Tutor] use of __new__

2009-06-12 Thread Kent Johnson
On Fri, Jun 12, 2009 at 10:03 AM, spir wrote: > Don't you have a comment in the 'if' case, too? Namely that __init__ is not > invoked explicitely, while the docs clearly state: > > << f __new__() returns an instance of cls, then the new instance’s __init__() > method will be invoked like __init__

Re: [Tutor] Audio Framework for Python

2009-06-15 Thread Kent Johnson
On Sun, Jun 14, 2009 at 4:04 PM, Tycho Andersen wrote: > All: > > I'm interested in writing a simple media player in python. I've been > poking around on the internet for a framework that can play the common > audio formats (mp3, flac, ogg, etc.), but I haven't found one that I > liked a whole lot.

Re: [Tutor] which is better solution of the question

2009-06-16 Thread Kent Johnson
On Tue, Jun 16, 2009 at 9:52 AM, Abhishek Tiwari wrote: > Question : > The first list contains some items, and the second list contains their value > (higher is better). > > items = [apple, car, town, phone] > values = [5, 2, 7, 1] > > Show how to sort the 'items' list based on the 'values' list so

Re: [Tutor] variable within function retains value

2009-06-18 Thread Kent Johnson
On Thu, Jun 18, 2009 at 6:21 AM, karma wrote: > Hi All, > > I'm trying to write a function that flattens a list. However after I > call the function more than once, it appends the result (a list) from > the second call with the first. I can get around it by either setting > the list to an empty one

Re: [Tutor] Eliminating consecutive duplicates in a list

2009-06-18 Thread Kent Johnson
On Thu, Jun 18, 2009 at 9:15 AM, karma wrote: > I was playing around with eliminating duplicates in a list not using > groupby. From the two solutions below, which is more "pythonic". > Alternative solutions would be welcome. But why not use groupby()? That seems much clearer to me: In [1]: from

Re: [Tutor] converting encoded symbols from rss feed?

2009-06-18 Thread Kent Johnson
On Thu, Jun 18, 2009 at 4:37 PM, Serdar Tumgoren wrote: > On the above link, the section on "Encoding Unicode Byte Streams" has > the following example: > u = u"abc\u2013" print u > Traceback (most recent call last): >  File "", line 1, in > UnicodeEncodeError: 'ascii' codec can't encod

Re: [Tutor] list of instance objects, access attribute

2009-06-18 Thread Kent Johnson
On Thu, Jun 18, 2009 at 7:32 PM, Vincent Davis wrote: > given a class like > class B(): > def __init__(self, b1, b2): >     self.fooa = fooa >     self.foob = foob > > Ok now I have several instances in a list > b1 = B(1, 2) > b2 = B(3, 4) > b3 = B(9, 10) > alist = [b1, b2, b3] > > Lets say for eac

Re: [Tutor] converting encoded symbols from rss feed?

2009-06-18 Thread Kent Johnson
2009/6/18 Serdar Tumgoren : >> In [7]: print x.encode('cp437') >> --> print(x.encode('cp437')) >> abc░ >> > So does this mean that my python install is incapable of encoding the > en/em dash? No, the problem is with the print, not the encoding. Your console, as configured, is incapable of dis

Re: [Tutor] converting encoded symbols from rss feed?

2009-06-18 Thread Kent Johnson
On Thu, Jun 18, 2009 at 9:03 PM, Serdar Tumgoren wrote: > When I run this code: > > <<< snip >>> > for line in infile: >    cleanline = translate_code(line) >    newline = strip_html(cleanline) >    outfile.write(newline) > <<< snip >>> > > ...I receive the below traceback: > >   Traceback (most r

Re: [Tutor] Subclassing list

2009-06-18 Thread Kent Johnson
On Thu, Jun 18, 2009 at 9:48 PM, Luis N wrote: >>> I get an error "TypeError: 'rounding' is an invalid keyword argument >>> for this function" on my list subclass. >>> >>> How might I subclass list without this error? >>> >>> This is the code: >>> >>> class SeriesList(list): >>>    def __new__(cls

Re: [Tutor] home directory usage script

2009-06-18 Thread Kent Johnson
On Thu, Jun 18, 2009 at 9:48 PM, dave chachi wrote: >     A. Create a script that monitors the /home partition >     B. have it write to a log file in /var/log >     C. have crontab run it daily What do you want it to write? Kent ___ Tutor maillist -

Re: [Tutor] Generating Deck Combinations

2009-06-20 Thread Kent Johnson
On Sat, Jun 20, 2009 at 3:49 AM, Michael Morrissey wrote: > I need to generate all possible deck combinations given two different lists > as input. > The Input: > List 1 has Card names listed inside it. > List 2 has Maximum Quantities for each Card name. I generally prefer a list of pairs to paire

Re: [Tutor] Generating deck combinations

2009-06-20 Thread Kent Johnson
On Sat, Jun 20, 2009 at 1:01 PM, Paul McGuire wrote: > If you are looking for all possible 60-card deals of this deck, then you > also probably want to filter out duplicate deals caused by equivalent cards > exchanging places.  That is, say you had a deck of 3 cards: 2 Mountain, and > 1 Vial, and y

Re: [Tutor] filtering NaN values

2009-06-22 Thread Kent Johnson
On Mon, Jun 22, 2009 at 4:15 PM, Elisha Rosensweig wrote: > Hi, > > I have a list with some values being NaN (after division-by-zero). How can I > check and remove all the NaN values? In Python 2.6 you can use math.isnan() to check for NaN, so you can filter your list by newList = [ x for x in old

Re: [Tutor] variable length precision

2009-06-22 Thread Kent Johnson
On Mon, Jun 22, 2009 at 7:25 PM, Wayne wrote: > With string formatting I know you can easily specify precision a la > 'file%.2d.jpg' % 1 which would give me 'file01.jpg' but then I discovered > you can indeed chain together formatting (or use variables in place of > string constants... of course s

Re: [Tutor] Writing a csv from a dictionary

2009-06-23 Thread Kent Johnson
On Tue, Jun 23, 2009 at 1:08 AM, Mark Tolonen wrote: > import csv > > dyc = { > 'a50' : ['textfield', 50, 40], > 'k77' : ['othertext', 60, 10] > } > > myfile = open('csv-test.csv', 'w') > mywriter = csv.writer(myfile, dialect='excel') > > for k,[a,b,c] in dyc.items(): >   mywriter.writerow([k,a,b,

Re: [Tutor] filtering NaN values

2009-06-23 Thread Kent Johnson
On Tue, Jun 23, 2009 at 1:53 AM, Alan Gauld wrote: > Interesting! How is a NaN stored in Python? > ie. How do you get to the point of having one in the first place? Google 'python nan' for lots of interesting discussion... Kent ___ Tutor maillist - Tu

Re: [Tutor] string pickling and sqlite blob'ing

2009-06-24 Thread Kent Johnson
On Wed, Jun 24, 2009 at 1:17 PM, Dinesh B Vadhia wrote: > I want to pickle (very long) strings and save them in a sqlite db.  The plan > is to use pickle dumps() to turn a string into a pickle object and store it > in sqlite.  After reading the string back from the sqlite db, use pickle > loads() t

Re: [Tutor] re module / separator

2009-06-24 Thread Kent Johnson
On Wed, Jun 24, 2009 at 2:24 PM, Tiago Saboga wrote: > Hi! > > I am trying to split some lists out of a single text file, and I am > having a hard time. I have reduced the problem to the following one: > > text = "a2345b. f325. a45453b. a325643b. a435643b. g234324b." > > Of this line of text, I wan

Re: [Tutor] Program Slicing / Trace

2009-06-25 Thread Kent Johnson
On Thu, Jun 18, 2009 at 10:37 AM, Jojo Mwebaze wrote: > Hi Tutor > > The problem i have is to see which statements modify my data at execution > time without referring to the code. Referring to the code is difficult esp > because of branching. You can never tell before hand which branch execution >

Re: [Tutor] short circuiting

2009-06-25 Thread Kent Johnson
On Wed, Jun 24, 2009 at 11:32 PM, Dave C wrote: > Hi > I've read that the builtin all() function stops evaluating as soon as > it hits a false item, meaning that items after the first false one are > not evaluated. > > I was wondering if someone could give an example of where all()'s > short circui

Re: [Tutor] (no subject)

2009-06-26 Thread Kent Johnson
On Fri, Jun 26, 2009 at 6:29 AM, Febin Ameer Ahsen wrote: > how to implement diff command showing  difference in box Here are some examples of using difflib to list differences: http://blog.doughellmann.com/2007/10/pymotw-difflib.html http://personalpages.tds.net/~kent37/blog/arch_m1_2004_06.html#

Re: [Tutor] array and int

2009-06-26 Thread Kent Johnson
On Fri, Jun 26, 2009 at 2:28 PM, Dinesh B Vadhia wrote: > Say, you create an array['i'] for signed integers (which take a minimum 2 > bytes).  A calculation results in an integer that is larger than the range > of an 'i'.  Normally, Python will convert an 'i' to a 4-byte 'l' integer. > But, does th

Re: [Tutor] Very basic Python question

2009-06-27 Thread Kent Johnson
On Sat, Jun 27, 2009 at 1:16 AM, Luke Paireepinart wrote: > You should try uninstalling MacPython.  Macintosh computers come with Python > preinstalled and you should try to use that version instead.  Probably what > happened was that, when installing the other version of Python, you messed > up s

Re: [Tutor] does python have something like "#include" in C?

2009-06-29 Thread Kent Johnson
On Mon, Jun 29, 2009 at 1:23 PM, Robert Lummis wrote: > Here's an example that seems not possible in python. I'm probably > missing something so please enlighten me. I only tried doing this as > an exercise to show myself how name references work. I'm not saying > it's needed or that it's good prac

Re: [Tutor] does python have something like "#include" in C?

2009-06-29 Thread Kent Johnson
On Mon, Jun 29, 2009 at 1:46 PM, wesley chun wrote: > take your function definition and store in a file called, say > showmodule.py. then put the remaining code inside something like > foo.py. at the top of foo.py, you'll need: > > from showmodule import show > > then everything else will work. I

Re: [Tutor] About the vertical bar input

2009-06-29 Thread Kent Johnson
On Mon, Jun 29, 2009 at 1:24 PM, hyou wrote: > I’m trying to write a script that simply execute a command line like: > > C:\...(path)..\Devenv solution /build “Debug|Win32” > > > > However, in Python the “|” symbol is reserved thus I just can’t make the > command line above working once I added th

Re: [Tutor] calculating a sort key and operator.attrgetter()

2009-07-01 Thread Kent Johnson
On Tue, Jun 30, 2009 at 11:39 PM, Vincent Davis wrote: > I have a class with an attribute which is a list "rank_list" this is a list > of instances f another class that has attributes "quality, is_observed" > if I want to sort the list by the attribute "quality" I can just use, > self.rank_list.sor

Re: [Tutor] window graphics

2009-07-02 Thread Kent Johnson
On Wed, Jul 1, 2009 at 3:49 PM, David H. Burns wrote: > I am new to Python and I'm looking for help on graphics in Python3.0. All > the graphics libraries I've seen are far to complex (and don't seem > compatible with 3. What I really need to know is two things (1) how to set > up a graphic window

Re: [Tutor] window graphics

2009-07-02 Thread Kent Johnson
Forwarding to the list with my reply... On Thu, Jul 2, 2009 at 8:16 PM, David H. Burns wrote: > I don't necessarily want to plot single pixels. I'm not at all sure what > "directly" means in this context. "Plotting" to the screen involves sending > data to a software algorithm which invokes the ap

Re: [Tutor] list comprehension problem

2009-07-03 Thread Kent Johnson
On Fri, Jul 3, 2009 at 3:49 PM, Dinesh B Vadhia wrote: > d = [0, 8, 4, 4, 4, 7, 2, 5, 1, 1, 5, 11, 11, 1, 6, 3, 5, 6, 11, 1] > > and we want: > > [0, 8, 12, 16, 20, 27, 29, 34, 35, 36, 41, 52, 63, 64, 70, 73, 78, 84, 95, > 96] > dd = [ sum(d[:j]) for j in range(len(d)) ][1:] > > gives: > > [0, 8, 1

Re: [Tutor] fnmatch -or glob question

2009-07-03 Thread Kent Johnson
On Fri, Jul 3, 2009 at 8:24 PM, Damon Timm wrote: > And I thought I could just construct something for glob or fnmatch like: > > glob.glob("DSC_0065*.jpg") --or-- fnmatch.fnmatch(file, "DSC_0065*.jpg") Do you have the working directory set to the folder with the jpgs in it? If not, you have to gi

Re: [Tutor] Stack unwind using exceptions.

2009-07-04 Thread Kent Johnson
On Sat, Jul 4, 2009 at 3:56 PM, Noufal Ibrahim wrote: > Hello everyone, > > Would it be considered unorthodox or 'wrong' in some sense for me to use an > exception to unwind the stack and return to a caller for a recursive > function? > > I need to do a depth first search and when I find the right

Re: [Tutor] reading variables in a data set?

2009-07-05 Thread Kent Johnson
On Sat, Jul 4, 2009 at 12:09 PM, Steven Buck wrote: > I've used a module (StataTools) from (http://presbrey.mit.edu/PyDTA ) to get > a Stata ".dta" file into Python. In Stata the data set is an NXK matrix > where N is the number of observations (households) and K is the number of > variables. > I

Re: [Tutor] Poor style to use list as "array"?

2009-07-05 Thread Kent Johnson
On Sun, Jul 5, 2009 at 2:48 PM, Angus Rodgers wrote: > for i in range(LEN - 1): >    (count[i], amnt) = divmod(amnt, value[i]) How about this: counts = [] for val in value: count, amnt = divmod(amnt, val) counts.append(count) > This feels like a bit of a cheat, as if I am trying to program i

Re: [Tutor] append question

2009-07-06 Thread Kent Johnson
> 2009/7/6 Steven Buck : >> # I call my data set the psid (Panel Study of Income Dynamics) >> # In Stata this would look like and NXK matrix (N observations and K >> variables) >> psid=Reader(file('data3.dta')) >> >> # I gather this next just creates a list of the variable names. >> varnames=[x.na

Re: [Tutor] int to bytes and the other way around

2009-07-06 Thread Kent Johnson
On Mon, Jul 6, 2009 at 4:48 AM, Timo wrote: > I have written a program that uses a C++ module as backend. Now I found out > that I can use Python to call an underneath C lib. That's nice, so I don't > need to Popen() the C++ module. > > I have a problem though with some info that is returned (alway

Re: [Tutor] Urllib, mechanize, beautifulsoup, lxml do not compute (for me)!

2009-07-07 Thread Kent Johnson
On Mon, Jul 6, 2009 at 5:54 PM, David Kim wrote: > Hello all, > > I have two questions I'm hoping someone will have the patience to > answer as an act of mercy. > > I. How to get past a Terms of Service page? > > I've just started learning python (have never done any programming > prior) and am try

Re: [Tutor] Urllib, mechanize, beautifulsoup, lxml do not compute (for me)!

2009-07-07 Thread Kent Johnson
On Tue, Jul 7, 2009 at 1:20 PM, David Kim wrote: > On Tue, Jul 7, 2009 at 7:26 AM, Kent Johnson wrote: >> >> curl works because it ignores the redirect to the ToS page, and the >> site is (astoundingly) dumb enough to serve the content with the >> redirect. You could m

Re: [Tutor] mac os x executable

2009-07-07 Thread Kent Johnson
On Tue, Jul 7, 2009 at 5:51 PM, wrote: > Alan, > >> After all with Python 2.3 pre installed on MacOS X > > Is Python 2.3 really the most recent version of Python distributed with > new Macs? I think *new* Macs come with 2.5. My 2-year-old MacBook Pro has 2.3. > So if I wanted to distribute a Pyt

Re: [Tutor] Quick question regarding Parsing a Delimited string

2009-07-08 Thread Kent Johnson
On Wed, Jul 8, 2009 at 12:13 PM, Garry Bettle wrote: > Hi, > > I've been programming for over 20 yrs, but only the last few in python > and then only in dribs and drabs. > > I'm having a difficult time parsing a delimited string. > > e.g. > > 100657641~GBP~ACTIVE~0~1~~true~5.0~1247065352508~: > 381

Re: [Tutor] Quick question regarding Parsing a Delimited string

2009-07-08 Thread Kent Johnson
On Wed, Jul 8, 2009 at 1:22 PM, Rich Lovely wrote: > If you really want to speed up the search, you could turn the list of lists > into a dict, using the first value in each sublist as a key: > > dct = dict((i[0], i[1:]) for i in lst) > > Then you can access it using the normal dictionary interfac

Re: [Tutor] thesaurus

2009-07-10 Thread Kent Johnson
On Fri, Jul 10, 2009 at 7:08 AM, Dave Angel wrote: > Alan Gauld wrote: >> Or the translation program that translated the expression >> >> Out of sight, out of mind >> >> from English to Russian and back with the result: >> >> Invisible, lunatic > Or the expression: > "The spirit is willing, but t

[Tutor] Free webinars: Scientific computing with Python

2009-07-11 Thread Kent Johnson
Enthought is conducting a series of free webinars on scientific computing with Python. They seem to be oriented to beginners. The next one is about Chaco, the plotting tool. http://blog.enthought.com/?p=125 Kent ___ Tutor maillist - Tutor@python.org ht

Re: [Tutor] for statement with addition ...

2009-07-13 Thread Kent Johnson
On Mon, Jul 13, 2009 at 6:50 AM, Markus Hubig wrote: > Hi @all, > > within diveintopython I often found a for-statement like this: > > f for f in bla: >     print f > > So what actually is the first f for ... is it just to declare f before > starting the for loop? I can't find any information on py

Re: [Tutor] browser encoding standards?

2009-07-14 Thread Kent Johnson
On Mon, Jul 13, 2009 at 7:55 PM, Alan Gauld wrote: > OK, What kind of meta tag should I include? > I have a couple, but not very many meta tags in my files. I try to > minimalise > content and maintain HTML 3.2 compatibility for oldr browsers. > > What would a content-type meta line look like to g

Re: [Tutor] assigning list to keys

2009-07-14 Thread Kent Johnson
On Tue, Jul 14, 2009 at 2:58 AM, Todd Matsumoto wrote: > Hello, > > The other day I needed to pack a dictionary, the value of each key was a > list. In the code I was packing the list and the dictionary at the same time. > First I tried something like this: > > list = [] > dict = {} > x = 1 > > d

Re: [Tutor] University student struggling!

2009-07-14 Thread Kent Johnson
On Mon, Jul 13, 2009 at 7:23 PM, Andrea Semenik wrote: > I have no idea how to begin!! can you help me? What have you done so far? Do you know how to serve and form and respond to form submission? Do you know how to dynamically generate and serve a page of HTML? What are you using to program th

Re: [Tutor] unittests, testing a type

2009-07-14 Thread Kent Johnson
On Tue, Jul 14, 2009 at 9:45 AM, A.T.Hofkamp wrote: > Todd Matsumoto wrote: >> >> Hi, >> >> Does anyone know how to do a unittest assert for a type? > For new-style classes, you should be able to do > > > type(result) is Decimal When possible, it's better to use assertEqual() rather than a plain

Re: [Tutor] unittests, testing a type

2009-07-14 Thread Kent Johnson
On Tue, Jul 14, 2009 at 9:59 AM, Todd Matsumoto wrote: > Okay, > > Thanks that worked. > > I still needed to import the Decimal class and I'm not sure that is okay. Sure, why not? > The reason why is I'm receiving the Decimal value from another program, if I > already know that the value will be

Re: [Tutor] University student struggling!

2009-07-14 Thread Kent Johnson
Forwarding to the list with my reply. Please use Reply All to respond to the list. On Tue, Jul 14, 2009 at 11:01 AM, Andrea Semenik wrote: > Thank you so much for your quick response. This is really the first > assignment of its kind with this course, there was no warm up to get us > familiar wi

Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread Kent Johnson
On Wed, Jul 15, 2009 at 7:41 AM, Todd Matsumoto wrote: > Hi, > > Can some one give, or point to some good examples of how @decorators work, > and __call__ (able) objects? Decorators: http://personalpages.tds.net/~kent37/kk/1.html Kent ___ Tutor mai

Re: [Tutor] objects becoming pointers

2009-07-15 Thread Kent Johnson
On Wed, Jul 15, 2009 at 11:19 AM, chris Hynes wrote: > I guess I have to start somewhere to ask > > I want the user to input a name, say "Chris". I know I can use the code: > > name=raw_input() > > I now want: > > "Chris"=zeros((3,3)) > > so that when I type: > > print Chris > > the ret

Re: [Tutor] objects becoming pointers

2009-07-15 Thread Kent Johnson
> chris Hynes wrote: >> >> Ah, there you go, that's what I want to do, dynamically create variable >> names. Then I could interactively create as many arrays as I want to, say >> Chris1, Chris2, Chris3 and each of these would be different array with >> different results. >> >> But based on what you

Re: [Tutor] Fwd: The why

2009-07-16 Thread Kent Johnson
> From: chris Hynes > Date: 2009/7/15 > Subject: The why > To: roadier...@googlemail.com > > > Well, I'm trying to create an interactive program, let's say I'm > running the program, I ask the user to give the array a name, I then > do some computations and store the results in that array. While I

Re: [Tutor] Replace a character by index

2009-07-16 Thread Kent Johnson
On Thu, Jul 16, 2009 at 4:29 AM, Wayne wrote: > Hi, > > My question is more about style/timing than anything else. > > In my program I'm taking a word and generating "blanks" in that word. For > example, the word cat could generate: > _at > c_t > ca_ > > I have two different ways I can put _ in the

Re: [Tutor] weather scraping with Beautiful Soup

2009-07-17 Thread Kent Johnson
On Thu, Jul 16, 2009 at 11:21 PM, Che M wrote: > Hi, > > I am interested in gathering simple weather data using Beautiful Soup, but > am having trouble understanding what I'm doing.  I have searched the > archives and so far haven't found enough to get me moving forward. > > Basically I am trying t

Re: [Tutor] sftp get single file

2009-07-17 Thread Kent Johnson
On Fri, Jul 17, 2009 at 11:42 AM, Sander Sweers wrote: > import time > > today = time.localtime() > datestr = time.strftime("%Y%m%d",today) > ext = ".tab" > > print datestr + ext You can include literal characters in the format string: In [4]: time.strftime("%Y%m%d.tab",today) Out[4]: '20090717.

Re: [Tutor] Very wierd namespace problem

2009-07-17 Thread Kent Johnson
On Fri, Jul 17, 2009 at 12:04 PM, Amit Sethi wrote: > now I have created a class with some functions defined in it but the > thing is that they are named in a completely different manner?(or > so I think) > > <__main__.SmPriceWindow instance at 0x9dd448c> > ['_SmPriceWindow__add_columns', '_Sm

Re: [Tutor] Form values

2009-07-17 Thread Kent Johnson
On Fri, Jul 17, 2009 at 12:43 PM, wrote: > Hi, I am reading values from a form and writing them to a text file. I keep > getting > a syntax error for outfile=open("filename", "a")I cant see it, does any body > else. Indentation problems can cause mysterious syntax errors. Use a text editor that

Re: [Tutor] how to join two different files

2009-07-17 Thread Kent Johnson
On Fri, Jul 17, 2009 at 3:14 PM, Emile van Sebille wrote: > delim= '\t' > > file('ala', 'w').writelines( >  [ delim.join([ii,jj] for ii,jj in >    zip( >      [xx.strip() for xx in >        file('/home/amrita/alachems/chem2.txt','r').readlines() >        ], >      file('/home/amrita/pdbfile/pdb2.t

Re: [Tutor] hitting a wall (not a collision detection question :P)

2009-07-20 Thread Kent Johnson
On Sun, Jul 19, 2009 at 4:34 PM, Michael wrote: > I've been progressing steadily, until now. At this point, I have a pretty > solid understanding of strings, integers, tuples, lists, dictionaries, etc. > and everything up to functions vs. methods and the basics of classes and > OOP. This is where

Re: [Tutor] Question from a newbie

2009-07-21 Thread Kent Johnson
On Tue, Jul 21, 2009 at 2:12 PM, Deb wrote: > My son suggested I play around with Python.  I was wondering if anybody has > any real life applications?  It appears to be able to do quite a lot, but is > anybody really doing it with Python? Yes, Python is used in a wide variety of real-life applica

Re: [Tutor] dictionaries help

2009-07-23 Thread Kent Johnson
On Thu, Jul 23, 2009 at 7:09 PM, wrote: > Hello again, > Here is my full attempt, can you please tell me if it is OK and if there > should be any improvements >     ws_industry = ('it', 'science') code = ws_industry[0] active = [] industries = [{'code': 'it', 'name': 'Informat

Re: [Tutor] dictionaries help

2009-07-24 Thread Kent Johnson
On Fri, Jul 24, 2009 at 3:01 AM, wrote: >> If ws_industry contains 25 items, it will probably be faster to search >> it if it is a set rather than a list. Just use >> ws_industry = set(('it', 'science')) > > ws_industry contains only unique values OK. It will still be faster to check membership i

Re: [Tutor] renaming files within a directory

2009-07-27 Thread Kent Johnson
On Mon, Jul 27, 2009 at 5:10 AM, wrote: > files = set([file for file in os.listdir(os.getcwd()) if > file.endswith('svg')]) > print len(files) > > for file in files: >    file = file.strip('.svg') >    print file > #    if countries.has_key(file): > #       print file > > When I run this I get:

Re: [Tutor] Eng to Leet Speek

2009-07-27 Thread Kent Johnson
On Mon, Jul 27, 2009 at 4:02 PM, Alan Gauld wrote: > You might want to investigate the maketrans and translate functions in the > string module. > > The seem to be quite similar in intent to what you are trying to do? No, those will only do 1-for-1 character substitutions. Kent _

Re: [Tutor] self.name vs. passing a name

2009-07-27 Thread Kent Johnson
On Mon, Jul 27, 2009 at 7:39 PM, Che M wrote: > 1.Pass the variable to the second function. > > def calculate_something(self): >     answer = self.do_first_calculation()    #1st function returns answer >     self.do_second_calculation(answer)    #2nd is passed answer and uses it. > > 2. Create the

Re: [Tutor] Two problems related to dispathing.

2009-07-28 Thread Kent Johnson
On Tue, Jul 28, 2009 at 1:22 PM, Mac Ryan wrote: > def invokeAll(method, data): >    """This function is a dispatcher: it invokes all the content types >    of the application calling 'contenttype.method(data)'""" >    return [getattr(content, method)(data) for content in contents] In Python 2.6

Re: [Tutor] Assigning each line of text to a separate variable

2009-07-30 Thread Kent Johnson
On Thu, Jul 30, 2009 at 3:19 PM, Marv Boyes wrote: > Hello, all. This is probably embarrassingly basic, but I haven't been able > to find something that works. > > I'm working on a script that needs to manipulate a list (not 'list' in the > Python sense) of URLs returned in a server response. Right

Re: [Tutor] Tkinter

2009-08-01 Thread Kent Johnson
On Sat, Aug 1, 2009 at 5:05 AM, Robert Johansson wrote: > Dear all, I have a problem with Tkinter and swedish letters such as ä (or >  '\xe4'). Here’s a small code example that counts the number of occurrences > of the letter ‘a’ is in a string given by the user: > > > > from Tkinter import * > > >

Re: [Tutor] Question about the FONT in Tkinter

2009-08-03 Thread Kent Johnson
On Sat, Aug 1, 2009 at 12:12 PM, Mohannad Mohammad wrote: > Kindly refer to the attached photo. > There are two sentences appearing when the user checked two checkbutton, I > make it as a practice. > ok > I want to change the font of these two sentences. how? >     self.box = Text(self, width

Re: [Tutor] Program to Simulate Keystrokes

2009-08-04 Thread Kent Johnson
On Tue, Aug 4, 2009 at 3:01 PM, Chris Fuller wrote: > On Tuesday 04 August 2009 12:43, Megan Land wrote: >> If at all possible I need a program that will work on Windows and Linux (I >> know a tall order).  I'm trying to keep this simple but if I have to use >> two different programs I will. > If

Re: [Tutor] regex problem with colon

2009-08-06 Thread Kent Johnson
On Thu, Aug 6, 2009 at 8:47 PM, Tim Johnson wrote: > using python 2.5. > I'm having a problem with including a colon as part of a substring > bounded by whitespace or beginning of line. > Here's an example: > p = re.compile(r'\bcc:\b',re.IGNORECASE) res = p.findall('malicious cc: here CC: ther

Re: [Tutor] regex problem with colon

2009-08-07 Thread Kent Johnson
On Thu, Aug 6, 2009 at 11:37 PM, Tim Johnson wrote: >  Yes. You nailed it Kent. >  I had grokked the logic but not entirely the syntax. >  I'm looking thru docs now. Just curious .. is there a flag that >  enables adding a ':' to the internal list of "word" characters? No. The list is affected by

Re: [Tutor] Overriding MySQLdb.cursors.DictCursor.execute()

2009-08-08 Thread Kent Johnson
On Fri, Aug 7, 2009 at 10:18 PM, Tim Johnson wrote: > Hello: > I am currently using python 2.5 and do a lot of database programming > with MySQLdb. > > I need to tighten up control over queries since I am concerned about > malicious injections. If you use the two argument form of cursor.execute -

Re: [Tutor] building database with sqlite3 and matplotlib

2009-08-08 Thread Kent Johnson
On Fri, Aug 7, 2009 at 5:35 PM, David Kim wrote: > I've been learning python in a vacuum for the past few months and I > was wondering whether anyone would be willing to take a look at some > code? I've been messing around with sqlite and matplotlib, but I > couldn't get all the string substitutio

Re: [Tutor] How to Split a String

2009-08-08 Thread Kent Johnson
On Sat, Aug 8, 2009 at 2:33 PM, Paras K. wrote: > What I am trying to do is find the mail folder for our lotus notes files. > > I get it by doing the following: > > lotusnotesmaildir = glob.glob('C:\Documents and Settings/pkinariwala/Local > Settings/Application Data/lotus/notes/data/'+'*mail*/') >

Re: [Tutor] MySQLdb field type

2009-08-10 Thread Kent Johnson
On Mon, Aug 10, 2009 at 1:08 PM, Rick Pasotto wrote: > After executing a query that returns values, cursor.description contains > a list of tuples, one tuple for each field. Each tuple has seven values > consisting of > (name,type_code,display_size,internal_size,precision,scale,null_ok). > > Where

<    1   2   3   4   5   6   7   8   9   10   >