Re: [Tutor] Using the TIME module to extract a semi-random number

2009-09-19 Thread Kent Johnson
On Sat, Sep 19, 2009 at 12:24 AM, Katt wrote: > One last question on the TIME module: Is there one version of these examples > that is not portable to other systems?  I read something about some > functions not working on other systems and I would like to ensure that the > programs that I write a

Re: [Tutor] Problem running visual python files at home

2009-09-19 Thread Kent Johnson
On Sat, Sep 19, 2009 at 5:03 AM, shsu012 shsu012 wrote: > However, a Microsoft Visual C++ Runtime library error keeps turning up > whenever I tried to run the files which use functions imported from the > visual library(please see the attached pic) Please show the code that causes the error.

Re: [Tutor] What is this an example of (and how can i use it?)

2009-09-20 Thread Kent Johnson
On Sun, Sep 20, 2009 at 9:10 AM, kevin parks wrote: > I am afraid that in the long layoff in python has meant some new constructs > have passed me by. In googling around I found some nice little code I want > to use, but i don't quite understand it, how it is called, and what it is an > example of

Re: [Tutor] real world decorators

2009-09-20 Thread Kent Johnson
On Sun, Sep 20, 2009 at 3:40 PM, John wrote: > Hi, > > I think I understand what decorators are and how they work.  Maybe it's just > me but I don't know where I'd use them in my real world programming.  I see > how they work with profile or coverage but does anyone have real world uses. Here are

Re: [Tutor] What is this an example of (and how can i use it?)

2009-09-20 Thread Kent Johnson
On Sun, Sep 20, 2009 at 1:27 PM, kevin parks wrote: > > On Sep 21, 2009, at 1:32 AM, Alan Gauld wrote: > >> kevin parks wrote: >> >>> called, and what it is an example of. I guess there are generators and >>> iterators now and it seems this might be an example of one of those new >> >> This is a g

Re: [Tutor] need to hire a tutor for online, i can pay by week or per hr $$$

2009-09-21 Thread Kent Johnson
On Mon, Sep 21, 2009 at 4:40 PM, daggerdvm wrote: > > hi i need a tutor for help with python.  I'll ask you basic questions through > email and such.  I can pay by the hour or by week or whatever. We do that for free here, just post your questions to the list. We try not to give answers to homewo

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 1:27 PM, Alan Gauld wrote: > I tend to prefer the explicit approach since it is explicit which > class/method is getting called, but I suspect the preferred mechanism > nowadays is to use super() I prefer the older approach too, it is simple and explicit. super() comes wi

Re: [Tutor] module not found problem

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 1:56 PM, Parag Shah wrote: > Hi, > > I am using django-openid-consumer, which has a line in it's views.py > which results in an error due to module not found - > > from openid.extensions.pape import Request as PapeRequest > > where 'openid.extensions' comes from python-open

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 2:20 PM, Serdar Tumgoren wrote: > Is my case isolated enough here that I could use the old syntax, but > leave my remain usages of super in tact? My worry is that I'd have to > convert all of my subclasses (quite a few at this point) to the > old-style... I know that when

Re: [Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 5:04 PM, Sander Sweers wrote: > Hello Tutors, Because a website was giving me issues with unicode > character I created a function to force the encoding. I am not sure it > is the correct way to handle these things. > > def reader(fobject, encoding='UTF-8'): >    '''Read a

Re: [Tutor] ex-ftp

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 12:39 AM, prasad rao wrote: > hello  friends >   I am trying to write a class to save a url.page. > But it is not working.It is saving the html.page.But not getting > images.I am unable to show the list (object.links). > Please take a look at it and show me how to rectify i

Re: [Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 7:56 PM, Sander Sweers wrote: > On Tue, 2009-09-22 at 18:04 -0400, Kent Johnson wrote: >> > def reader(fobject, encoding='UTF-8'): >> >    '''Read a fileobject with specified encoding, defaults UTF-8.''' &g

Re: [Tutor] What is this an example of (and how can i use it?)

2009-09-23 Thread Kent Johnson
On Wed, Sep 23, 2009 at 12:58 AM, kevin parks wrote: > It appears it is not so impenetrable as i initially > though. Well iterators > aren't maybe, but generator do look tricky. So interators iterate over > lists, tuples, strings, dictionaries > and any data type that is iterable, and generators

Re: [Tutor] code improvement

2009-09-24 Thread Kent Johnson
On Thu, Sep 24, 2009 at 2:12 PM, Norman Khine wrote: > Hello, > I have this function in my class: > > http://paste.lisp.org/display/87659 > > Is there a better method to write the last bit of the code. Better in what way? What are these things? What is resource? Some context would be helpful, I s

Re: [Tutor] how to print a message backwards

2009-09-24 Thread Kent Johnson
On Thu, Sep 24, 2009 at 7:02 PM, Sander Sweers wrote: > Now that I know what to look for I went to the online python docs [1] > and tried to find where it has been documented. > > Unfortunately all the slicing examples I found do not even mention that > there is optional step value. See footnote

Re: [Tutor] code improvement

2009-09-25 Thread Kent Johnson
On Fri, Sep 25, 2009 at 1:00 AM, Norman Khine wrote: >>> Is there a better method to write the last bit of the code. > Apologies for not being clear. I was thinking more  that I may have > one the too many 'for' loops at the end of the code. > > http://paste.lisp.org/display/87659#1 It's only t

Re: [Tutor] Confusion with $PATH

2009-09-25 Thread Kent Johnson
On Fri, Sep 25, 2009 at 10:39 AM, David Eric wrote: > Very new to python..getting accustomed to files, directories etc > I installed a few versions of python and ended up with a very long PATH > variable, do i need this or can i change it to something shorter? > Doing an online tutorial one exerci

Re: [Tutor] Confusion with $PATH

2009-09-25 Thread Kent Johnson
On Fri, Sep 25, 2009 at 12:07 PM, David Eric wrote: > Do i need to do anything now that the issue was resolved? How did you resolve it? If you copied your program into one of the existing directories on PATH, you probably want to delete it when you are done with the exercise. If you created your

Re: [Tutor] Confusion with $PATH

2009-09-25 Thread Kent Johnson
> On Fri, Sep 25, 2009 at 11:32 AM, David Eric wrote: >> >> ok this is really weird . . . >> i tried running the helloworld again, and it doesnt work :/ >> >> DTm:~ davidteboul$ echo $PATH >> PATH$/Library/Frameworks/ >> >> Python.framework/Versions/3.1/bin:/Library/Frameworks/Python.framework/Ver

Re: [Tutor] need help with conditionals

2009-09-26 Thread Kent Johnson
On Sat, Sep 26, 2009 at 3:59 AM, Alan Gauld wrote: > What are you using for a tutorial? It appears to be http://openbookproject.net/thinkCSpy/ch04.html Kent ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://m

[Tutor] Fwd: Examples using Poachplate

2009-09-27 Thread Kent Johnson
2009/9/27 Rüdiger Wolf : > Hi > > Matt Harrison created what appears to be a really nifty tool called > poachplate. A python script boilerplate. > http://pypi.python.org/pypi?%3Aaction=search&term=poachplate > See the following links for more info. > http://panela.blog-city.com/oscon_scripting_with

Re: [Tutor] Not workin!

2009-10-01 Thread Kent Johnson
On Wed, Sep 30, 2009 at 1:32 AM, Luke Paireepinart wrote: > Oops, thanks for catching that one Marty. I thought they both > evaluated to false. They both evaluate to false in a boolean context but that is different from being *equal* to false or to each other. In [1]: s = '' In [2]: bool(s) Out

Re: [Tutor] Images, and other things.

2009-10-02 Thread Kent Johnson
On Tue, Sep 29, 2009 at 7:00 PM, Corey Richardson wrote: > I haven't looked into this, but could you make a real time image using > python? I think it would be most hard > Anyway, I am having trouble with int(). I am trying to int(raw_input("some > number")), but it returns > Traceback (most r

Re: [Tutor] Using command line tool with python script

2009-10-05 Thread Kent Johnson
On Mon, Oct 5, 2009 at 10:22 AM, Oleg Oltar wrote: > os.popen4("application -parameter1 -file temp.txt") > > I wonder if that possible to execute this script (called application) > without writing the file with initial data to the hard disk? If "application" can take its input from stdin then yo

Re: [Tutor] small program

2009-10-05 Thread Kent Johnson
This language is not appropriate for this list and I'm sorry to see it used even in a private reply. Let's keep the discussions here polite and respectful. Thanks, Kent On Sun, Oct 4, 2009 at 8:40 AM, Luke Paireepinart wrote: > > > On Sun, Oct 4, 2009 at 1:59 PM, Andrius wrote: >> >> Very good.

Re: [Tutor] Poorly understood error involving class inheritance

2009-10-05 Thread Kent Johnson
On Mon, Oct 5, 2009 at 4:41 PM, David Perlman wrote: > I fixed this by changing it to "mods=None" and then setting it in the body > of the __init__ method.  Works fine now. That is the correct fix. > My question is, is this just a quirky misbehavior, or is there a principled > reason why the co

Re: [Tutor] advice on structuring a project

2009-10-06 Thread Kent Johnson
On Tue, Oct 6, 2009 at 2:26 PM, Serdar Tumgoren wrote: > I have a set of classes that I've named models.py (following the > Django convention, though it's not technically a Django project or > app). > > Inside that file, I had initially grouped together a number of > classes, subclasses and mixin

Re: [Tutor] if n == 0 vs if not n

2009-10-06 Thread Kent Johnson
On Tue, Oct 6, 2009 at 11:08 AM, Wayne wrote: > On Tue, Oct 6, 2009 at 9:58 AM, Dave Angel wrote: >> >> >> >> No, because you're not assured that all integers that are equal are the >> same object.  Python optimizes that for small integers, but there's no >> documented range that you can count o

Re: [Tutor] if n == 0 vs if not n

2009-10-06 Thread Kent Johnson
On Tue, Oct 6, 2009 at 9:04 AM, Wayne wrote: > If it's checking the returncode against a value, Vern makes a good point: > if returncode != 0 makes a whole lot more sense than "if not returncode == > 0" > Though when dealing with an integer return code, doesn't it make more sense > to use the "is

Re: [Tutor] if n == 0 vs if not n

2009-10-08 Thread Kent Johnson
On Mon, Oct 5, 2009 at 9:13 PM, Luke Paireepinart wrote: > Actually, I just realized that "not" has higher precedence than "==" so this > is really checking if (not n) is equal to 0, not if (n == 0) is (not) True. No, "not" is lower precedence than "==". See http://docs.python.org/reference/expr

Re: [Tutor] Reading individual file from tar file as a file object

2009-10-08 Thread Kent Johnson
On Thu, Oct 8, 2009 at 4:10 PM, xbmuncher wrote: > I have a large tar.bz2 file that I want to extract certain files directly to > an FTP path. > Since the extract() method doesn't accept ftp paths...  I wanted to read the > files from the tar file like a file object or file I/O stream. > Is there

Re: [Tutor] Checking for Python version

2009-10-08 Thread Kent Johnson
On Tue, Oct 6, 2009 at 9:59 AM, Didar Hossain wrote: > Hi, > > I am using the following code to check for the Python version - > > import os > > t = os.sys.version_info[0:2] > if (t[0] + t[1]) < 6: Hmm, what would this give for Python 1.5? How about if t < (2, 4): >    os.sys.exit("Need at least

Re: [Tutor] Python 3 and tkinter Radiobuttons

2009-10-08 Thread Kent Johnson
On Thu, Oct 8, 2009 at 6:04 PM, bob smith wrote: > Hi.  I’m using Tkinter to create a new Radiobutton in Python 3.  However, > when I create the button, it starts off looking selected instead of > unselected (though it behaves correctly like an unselected Radiobutton).  So > this means when I crea

Re: [Tutor] Reading individual file from tar file as a file object

2009-10-08 Thread Kent Johnson
On Thu, Oct 8, 2009 at 8:45 PM, Xbox Muncher wrote: > Works perfectly! Thanks. Yet again, I've learned I need to read better. :) And remember, if the docs are unclear, you can always look at the source, as I did... Kent ___ Tutor maillist - Tutor@pyt

Re: [Tutor] list comprehensions

2009-10-09 Thread Kent Johnson
On Fri, Oct 9, 2009 at 1:21 AM, wesley chun wrote: > [generator expressions] are > "lazy" because you iterate over the values one at a time instead of > creating the entire list. they are slightly slower but save memory. I don't think you can make a blanket statement comparing speed of list comp

Re: [Tutor] for loop issue

2009-10-09 Thread Kent Johnson
On Fri, Oct 9, 2009 at 3:54 AM, Stefan Lesicnik wrote: > Hi, > > This feels like a strange issue, so i hope I formulate this so its > understandable. > > I have some objects. Each object has associated values. I am looping > through these objects, working with a value and printing out the > value.

Re: [Tutor] Finding and Inserting missing dates in a date range.

2009-10-09 Thread Kent Johnson
On Fri, Oct 9, 2009 at 3:16 PM, Glen Zangirolami wrote: > If i have a list of dates: > date_list = > ['2008-12-29','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-05'] > How do I find the missing dates in the range of dates and insert them into > the list so I get? > date_list = > ['2

Re: [Tutor] If you don't close file when writing, do bytes stay in memory?

2009-10-10 Thread Kent Johnson
2009/10/10 Xbox Muncher : > What does flush do technically? > "Flush the internal buffer, like stdio‘s fflush(). This may be a no-op on > some file-like objects." > > The reason I thought that closing the file after I've written about 500MB > file data to it, was smart -> was because I thought th

Re: [Tutor] [OT] Secure coding guidelines

2009-10-10 Thread Kent Johnson
On Sat, Oct 10, 2009 at 5:31 AM, Didar Hossain wrote: > Hi, > > This is a little off-topic, but, I though I might put this question in. > > Since I am learning Python, I was wondering if there are any good > references on secure > coding practices. Books, guides or even any howtos would suffice.

Re: [Tutor] Python 3 and tkinter Radiobuttons

2009-10-11 Thread Kent Johnson
On Sun, Oct 11, 2009 at 7:00 AM, Dave Angel wrote: > bob smith wrote: >> >>                  Thanks for the reply. Unfortunately, even when I include >> a variable, all of the buttons start out selected. What version of Python 3 are you using? What platform? If you are not using the latest versio

Re: [Tutor] Extracting columns from CSV

2009-10-11 Thread Kent Johnson
On Sun, Oct 11, 2009 at 8:40 AM, Utkarsh "" wrote: > Hello, I have a CSV file, from which I want to extract data. > The CSV file is arranged like this: > Time, InSec, Open, High, Low, Close, Qty > 09:55:17,35717,41.95,41.95,41.95,41.95,105 > 09:56:03,35763,41.75,41.75,41.75,41.75,20785 > 09:56:40,

Re: [Tutor] Python 3 and tkinter Radiobuttons

2009-10-11 Thread Kent Johnson
On Sun, Oct 11, 2009 at 5:16 PM, bob smith wrote: > Yes, on Windows with Python 3.1 and using a StringVar(), the initial state > is that all radio buttons look selected when the program first begins.  I'm > able to work around it so that no radio buttons look selected when the > program first begi

Re: [Tutor] Carriage return

2009-10-12 Thread Kent Johnson
On Sun, Oct 11, 2009 at 11:38 PM, Wayne wrote: > That's not an issue with IDLE so much as windows/linux. IIRC, Linux only > uses a newline, while windows uses a CRLF. There's the dos2unix util: > http://linuxcommand.org/man_pages/dos2unix1.html > that may help. There is also a crlf.py script dis

Re: [Tutor] Automaton/transitional grammar query

2009-10-12 Thread Kent Johnson
On Mon, Oct 12, 2009 at 5:01 AM, kevin parks wrote: > First, as i mentioned I would like to know what, precisely, this kind of > process is called so that i can look it up. It looks like a simple cellular automaton where a cell's neighborhood includes only the cell itself. You might be interested

Re: [Tutor] python help needed

2009-10-12 Thread Kent Johnson
On Mon, Oct 12, 2009 at 2:15 AM, mazher ahmad wrote: > i wana make ToC/headings for any PDF documents ,PDFminer solves the my > problem if ToC  are given.i came across many files where there > is no Toc. > Does any one know ,how to extract ToC/headings from such files. I guess you will have to co

Re: [Tutor] Automaton/transitional grammar query

2009-10-12 Thread Kent Johnson
On Mon, Oct 12, 2009 at 10:09 AM, kevin parks wrote: >> > I don't understand why you want to flatten outlist; when I run your >> > program I get one number per line, not one generation per line as you >> > show above. > > > That's odd. Anyway in my program I am printing the list twice. The first >

Re: [Tutor] Automaton/transitional grammar query

2009-10-12 Thread Kent Johnson
On Mon, Oct 12, 2009 at 10:47 AM, Kent Johnson wrote: > On Mon, Oct 12, 2009 at 10:09 AM, kevin parks wrote: >> Yeah i don't mean an infinite loop, but more like a perpetual dance back and >> forth between to items >> that point to each other. I think I need to be

Re: [Tutor] (no subject)

2009-10-13 Thread Kent Johnson
On Tue, Oct 13, 2009 at 3:29 AM, Albert-Jan Roskam wrote: > Hi, > > I'm using Tkinter to program my very frist GUI. Each button grays out after > it has been used so the user knows what next steps to take. > Now I want to define a Reset button to 'ungray' all buttons (state='normal'). > How can

Re: [Tutor] [OT] Secure coding guidelines

2009-10-13 Thread Kent Johnson
On Tue, Oct 13, 2009 at 11:49 AM, Serdar Tumgoren wrote: >> In reference to this tip,  my question is why? > >> - don't use string formatting to create SQL statements - use the >> two-argument form of execute() to pass args as a sequence >> > > SQL injection is the primary reason: > > http://en.wi

Re: [Tutor] writing sample program that zips files and saves in a backup directory

2009-10-13 Thread Kent Johnson
On Tue, Oct 13, 2009 at 2:01 PM, David Eric wrote: > doing a python tutorial and one of the assignments says to develop a program > that backsup files to zip files into a backup directory > > im using Darwin 10.0.0 unix version: > > this is what i came up with thus far, i did copy the sample progr

Re: [Tutor] writing sample program that zips files and saves in a backup directory

2009-10-13 Thread Kent Johnson
On Tue, Oct 13, 2009 at 2:58 PM, David Eric wrote: > printing the command line, > would it be >  print('gzip {0} {1}'.format(target, ' '.join(source))? Yes, or just print zip_command > and as far as using the tar command, > i have three files, > file1,file2,file3 > i wanted to preserve that st

Re: [Tutor] writing sample program that zips files and saves in a backup directory

2009-10-13 Thread Kent Johnson
On Tue, Oct 13, 2009 at 4:38 PM, David Eric wrote: > as far as print zip_command, i would add that to the program however, doesnt > just declaring it actually trigger it..thus it would executed and the > command line would get printed as well? I'm not sure what you mean by "declaring", but assig

Re: [Tutor] namespaces and global

2009-10-14 Thread Kent Johnson
On Wed, Oct 14, 2009 at 7:26 AM, Jose Amoreira wrote: > I want to use a variable defined in an interactive session with the python > interpreter inside a function imported from a module. > > For instance, imagine that my module (call it defs.py, for instance) consists > of: > #coding=utf-8 > def

Re: [Tutor] Not storing the PATH in ZipFile?

2009-10-14 Thread Kent Johnson
On Wed, Oct 14, 2009 at 11:38 AM, Nick Hird wrote: > I was reading another thread and decided to work on a little project > to backup some files on a regular basis. Since this will mostly be on > windows i am using zipfile and i can create my zip file just fine and > all the files are there, it wo

Re: [Tutor] PyWin32 - Library of functions to interact with windows?

2009-10-14 Thread Kent Johnson
On Wed, Oct 14, 2009 at 12:38 PM, Katt wrote: > Searching the web I have found a lot of general information or overly > specific with no way to narrow my search to what I am looking for.  I am not > sure, but it seems very difficult just to search for a way to change the > color of my text. Did

Re: [Tutor] Masking operation

2009-10-15 Thread Kent Johnson
On Wed, Oct 14, 2009 at 10:48 PM, Wayne wrote: > Using zip is redundant for me, this is what my function looks like now: > def crypt(msg, mask): >     m = itertools.cycle(mask) >     word = '' >     for l in msg: >         word += chr(ord(l) ^ ord(m.next())) >     return word With zip() and a ge

Re: [Tutor] numerical problem

2009-10-15 Thread Kent Johnson
On Thu, Oct 15, 2009 at 5:28 AM, Mr Timothy Hall wrote: > whenever i run this part of the program, no matter what values i put in for > vto, k1t etc... it always equals zero. > im slightly aware of floating point numbers but im not sure why this will > not give me a real answer. > when i do it on

Re: [Tutor] multiprocessing with more than two arguments

2009-10-15 Thread Kent Johnson
On Thu, Oct 15, 2009 at 2:04 PM, markus kossner wrote: > Hi, > let's simply start with an example: > > #!/usr/bin/python2.6 > import numpy as n > > def calculate(a,b=3,c=4): >        print b >        return n.sqrt(n.exp(a*b+c)/n.exp(c)**2) > > from multiprocessing import Pool > p = Pool(processes=

Re: [Tutor] Most pythonic input validation

2009-10-16 Thread Kent Johnson
On Fri, Oct 16, 2009 at 7:25 AM, Robert Johansson wrote: > What if a valid user input has to be an integer between 10 and 20? I mean, > it could be that you are doing something that only makes sense for that > input. Would it be pythonic to add a test like: > > If prompt in range(10,21): Better

Re: [Tutor] Understanding what the code does behind the scenes

2009-10-16 Thread Kent Johnson
On Fri, Oct 16, 2009 at 7:53 AM, Eike Welk wrote: > I have an other idea for a color function. It cam be embedded in the > print statement because it returns an empty string: > > > def color(color_num): >    '''Change text color and return empty string.''' >    textcolor(color_num) >    return ''

Re: [Tutor] Understanding what the code does behind the scenes

2009-10-16 Thread Kent Johnson
On Fri, Oct 16, 2009 at 7:21 AM, Dave Angel wrote: > My attempt at readability  (untested): > > def colorPrint(color_items):       #1 >   """Call this function to print one or more strings, each with >       a color number specified, to the console.  The argument >       is a list of items, where

Re: [Tutor] Most pythonic input validation

2009-10-16 Thread Kent Johnson
On Fri, Oct 16, 2009 at 9:44 AM, Robert Johansson wrote: > If I wanted prompt to be an integer, is my check with range still bad? If the prompt is coming from raw_input() then you have already guaranteed it is an integer when you convert it in a try/except block. > Is this the way to define my o

Re: [Tutor] way to see code execution in real-time?

2009-10-16 Thread Kent Johnson
On Fri, Oct 16, 2009 at 9:53 AM, Serdar Tumgoren wrote: > Hello everybody, > > I was wondering -- is there a way to "watch" a program execute by > piping a report of its actions to standard output or to a file? > Basically, I'd like to see the order that functions/methods are > executing as they h

Re: [Tutor] way to see code execution in real-time?

2009-10-16 Thread Kent Johnson
On Fri, Oct 16, 2009 at 1:43 PM, Serdar Tumgoren wrote: > Hey everybody, > > Thanks for the recommendations -- I usually do use pdb to step through > chunks of code, but always by setting a breakpoint. And then I have to > "manually" print out the variables to see what's going on in the code. Win

Re: [Tutor] cannot convert eps to png using PIL

2009-10-17 Thread Kent Johnson
On Fri, Oct 16, 2009 at 12:23 AM, LL wrote: > Hi.. I also asked this question on the imaging group but thought people here > might have insights as well.. > > all of the following code executes interactively except the last line. > Converting a .jpg file to .png works fine. I'm using the PIL versi

Re: [Tutor] introspecting an object for method's name?

2009-10-19 Thread Kent Johnson
On Sunday, October 18, 2009, Serdar Tumgoren wrote: > Hi everyone, > I'm trying to create a generic logging function, and I'm able to get > at the name of the module and class using the built-in attributes > __module__, __class__, and __name__. > > But I wasn't sure how to also grab the name of th

Re: [Tutor] introspecting an object for method's name?

2009-10-19 Thread Kent Johnson
On Mon, Oct 19, 2009 at 8:40 AM, Tim Golden wrote: > Or just use the built-in logging module which lets you specify > the containing function name as one of its formatting keywords: > > http://docs.python.org/library/logging.html#formatter-objects Sweet! And much better than rolling your own log

Re: [Tutor] updating Unix config file

2009-10-20 Thread Kent Johnson
On Tue, Oct 20, 2009 at 10:44 AM, Matt Herzog wrote: > Yes, thanks. What failed was the invocation of PIPE. Apparently I had to > explicitly import PIPE from subprocess or python had no clue as to what PIPE > was! > > Dare I say, "wtf?" since when fo I have to specify such? Shouldn't importing

Re: [Tutor] "if clause" in list comprehensions.

2009-10-21 Thread Kent Johnson
On Wed, Oct 21, 2009 at 3:30 AM, Albert-Jan Roskam wrote: > Is the if-else (esp. 'else') in a list comprehension specific for Python 3.x? > Or did I miss something? List comps have always allowed a condition since they were introduced: [ for in if ] This is the form of the original questi

Re: [Tutor] PyGTK: is there a library for both Linux and Windows

2009-10-21 Thread Kent Johnson
On Wed, Oct 21, 2009 at 10:43 AM, Chris Fuller wrote: > > on differences: > > The downloads include binaries, so there have to be distinct files for Linux > and Windoze.  If you download the same versions, there shouldn't be any > noticeable differences, with one big exception:  multithreading and

Re: [Tutor] PyGTK: is there a library for both Linux and Windows

2009-10-21 Thread Kent Johnson
Forwarding to the list with my reply... On Wed, Oct 21, 2009 at 1:21 PM, Chris Fuller wrote: > > There are workarounds.  The point is that they aren't necessary in Linux, and > usually involve something fishy, like sleeping a (more or less) arbitrary > period to get the synchronization right, whi

Re: [Tutor] Detect duplicate object names

2009-10-21 Thread Kent Johnson
On Wed, Oct 21, 2009 at 2:09 PM, Lizhi Yang wrote: > Hi, > > When I define functions in a Module, how to avoid override the name of > existing functions? > For example: > > define func1(): > define func2(): > define func1(): > > Is there anyway to pop up the warnings? Take a look at PyFlakes and

Re: [Tutor] ifdef in python

2009-10-21 Thread Kent Johnson
On Wed, Oct 21, 2009 at 3:26 PM, Lizhi Yang wrote: > Is there anything similar to ifdef statement in C or C++ in python? No, Python doesn't have a preprocessor. Can you say why you want it? You may be able to do what you want using an ordinary if statement, for example you can conditionally impor

Re: [Tutor] Help with my program

2009-10-23 Thread Kent Johnson
On Thu, Oct 22, 2009 at 11:59 PM, Kenny Shen wrote: > Hi tanner, > > I suppose the following is possible: > > class A: >   def __init__(self): >   self.height = 1 >   self.weight = 7 >   self.name = "tanner" >   self.grade = "A" >   def getinfo(self): >   info = [] >   info

Re: [Tutor] replacing a long list of if,elif

2009-10-23 Thread Kent Johnson
On Fri, Oct 23, 2009 at 11:05 AM, John wrote: >  mydict = {'int': 'I', 'char':'C', 'bool':'B'} >  for fldType in fieldList: >    try: >        fld = mydict[fldType] >    except: >        fld = '?' Use fld = mydict.get(fldType, '?') > I also considered some sort of  lambda function as > >

Re: [Tutor] Reading information from a text file into a list of lists (WinXP/py2.6.2)

2009-10-26 Thread Kent Johnson
On Sun, Oct 25, 2009 at 6:53 PM, Katt wrote: > Hello all, > > Currently I am working on a program that reads text from a text file.  I > would like it to place the information int a list and inside the information > would have sublists of information. > > The text file looks like this: > > "Old Te

Re: [Tutor] New to Python

2009-10-27 Thread Kent Johnson
On Tue, Oct 27, 2009 at 11:35 AM, wrote: > Hi there, > > How do you connect to a different server using python? (I have not used > python before) What kind of connection? The Python standard library includes modules which support raw sockets, http, ftp, smtp, xml-rpc and probably a few others. P

Re: [Tutor] How to load a dict into a dict subclass?

2009-10-27 Thread Kent Johnson
On Tue, Oct 27, 2009 at 3:02 PM, Albert-Jan Roskam wrote: > I thought reimplementing dict was a matter of defining a __dict__ attribute > in the Bar class? And isn't the normal dict inherited anyway? (through > __super__) > > Or, if one would want to disable inheritance of the normal dict, one c

Re: [Tutor] New to Python

2009-10-28 Thread Kent Johnson
Forwarding to the list with my reply (please use Reply All to reply to the list): On Wed, Oct 28, 2009 at 2:01 AM, wrote: > Hi Kent, > > Thank you for replying to my request, really appreciate it. > > I am not familiar with all your connections that you have mentioned below. > > What I can tell

Re: [Tutor] Access PostGreSQL 8.3 by python 2.5

2009-10-28 Thread Kent Johnson
On Wed, Oct 28, 2009 at 1:44 AM, Mahasen Dehideniya wrote: > Hi , > > I'm try to access PostGreSQL 8.3 by python 2.5. I'm working on winXP. > > I use pg module. > > At the first time i get error that no found dll. when i add C:\Program > Files\PostgreSQL\8.3\bin to  the path variable i able to fix

Re: [Tutor] New to Python

2009-10-28 Thread Kent Johnson
e don't top-post. > > > -Original Message- > From: Kent Johnson > To: asteri...@petlover.com > Cc: *tutor python > Sent: Wed, Oct 28, 2009 1:18 pm > Subject: Re: [Tutor] New to Python > > Forwarding to the list with my reply (please use Reply All to reply

Re: [Tutor] Sorting points on a 2D plane

2009-10-28 Thread Kent Johnson
On Wed, Oct 28, 2009 at 1:34 PM, Robert Berman wrote: > Hi, > > I am working on a practice problem called 'POINTS' on the CodeChef > site:http://www.codechef.com/problems/POINTS/. This simply wants the sum > of the distances between a number of points on a 2 dimensional plane. > Looking at the pro

Re: [Tutor] Accessing variables in main from functions in a module

2009-10-30 Thread Kent Johnson
On Fri, Oct 30, 2009 at 6:39 PM, Robert Lummis wrote: > I want to move some functions from my "main" program file to a module > file because the main file is getting too big for convenience. The > functions access arrays (lists of lists) that are defined and > initialised in the main file. How do

Re: [Tutor] class attribute to initiate more classes

2009-10-31 Thread Kent Johnson
On Sat, Oct 31, 2009 at 1:01 AM, Vincent Davis wrote: > I have a program that generates many instances of a class with an attribute > self.x = random.gauss(10, 2). So each instance has a different value for > self.x. This is what I want. Now I want to make a class that starts my > program and sets

Re: [Tutor] Structure of my simulation / monte-carlo

2009-11-01 Thread Kent Johnson
On Sat, Oct 31, 2009 at 12:54 PM, Vincent Davis wrote: > So my plan way to make a new class. This class would define the Applicant > characteristics "self.gpa = random.gauss(mean, SD)" and the > institutions self.quality = random.gauss(mean, sd) > so it would look something like this > > class Re

Re: [Tutor] Structure of my simulation / monte-carlo

2009-11-01 Thread Kent Johnson
On Sun, Nov 1, 2009 at 10:47 AM, Vincent Davis wrote: > Kent Johsnon writes > "This class has a lot of responsibilities: > - create applicants > - create institutions > - run a single match > - run multiple matches > - calculate statistics on the result of multiple matches > A principle of object-

Re: [Tutor] Structure of my simulation / monte-carlo

2009-11-01 Thread Kent Johnson
On Sun, Nov 1, 2009 at 11:15 AM, Vincent Davis wrote: > Just to be clear,or try, given a set of applicants and institutions the > Match will always have the same result. Yes. You have to create a new Match, with new Applicants and Institutions, for each run of the simulation. > So when I am repe

Re: [Tutor] Structure of my simulation / monte-carlo

2009-11-01 Thread Kent Johnson
On Sun, Nov 1, 2009 at 8:34 PM, Dave Angel wrote: > I mostly agree with Kent, but I apparently disagree about which classes are > actually needed.  Think what things will have actual instances that will > last long enough to be worth formally defining.  So you need Applicant, and > Institution, an

Re: [Tutor] CSS Minification

2009-11-02 Thread Kent Johnson
On Mon, Nov 2, 2009 at 6:38 AM, Stephen Nelson-Smith wrote: > Is there a Python CSS and/or javascript minifier available? cssutils can minify CSS: http://cthedot.de/cssutils/ jsmin has been ported to Python: http://www.crockford.com/javascript/jsmin.py.txt Kent _

Re: [Tutor] Can we unroll a loop?

2009-11-02 Thread Kent Johnson
On Mon, Nov 2, 2009 at 3:52 PM, Tino Dai wrote: > Hi Everybody, > > I am wondering about a better approach to doing this: > > for obj in groups: >        rVs = rVs + Event.objects.get(group=obj) >     rVs.sort() Assuming rVs is a list and Event.objects.get(group=obj) is also a list, you

Re: [Tutor] trouble using 2to3.py

2009-11-03 Thread Kent Johnson
On Tue, Nov 3, 2009 at 1:10 PM, Luke Paireepinart wrote: > I was under the impression that you were supposed to top-post unless you > were referring to a specific thing someone said, in which case you quoted > it, much like you do on a forum. > Is that not how it works? Presumably you are replyin

Re: [Tutor] Logfile Manipulation

2009-11-09 Thread Kent Johnson
On Mon, Nov 9, 2009 at 4:36 AM, Stephen Nelson-Smith wrote: I want to extract 24 hrs of data based timestamps like this: [04/Nov/2009:04:02:10 +] >>> >>> OK It looks like you could use a regex to extract the first >>> thing you find between square brackets. Then convert that to a

Re: [Tutor] Logfile multiplexing

2009-11-10 Thread Kent Johnson
On Tue, Nov 10, 2009 at 5:04 AM, Stephen Nelson-Smith wrote: > I have the following idea for multiplexing logfiles (ultimately into heapq): > > import gzip > > class LogFile: >    def __init__(self, filename, date): >        self.logfile = gzip.open(filename, 'r') >        for logline in self.logf

Re: [Tutor] Logfile multiplexing

2009-11-10 Thread Kent Johnson
On Tue, Nov 10, 2009 at 11:25 AM, Stephen Nelson-Smith wrote: > So what I want to do is be able to multiplex the files - ie read the > next line of all 12 files at once, filter them accordingly, and then > write them out to one combined file. > > My old code did this; > > min((x.stamp, x) for x i

Re: [Tutor] Logfile multiplexing

2009-11-11 Thread Kent Johnson
On Wed, Nov 11, 2009 at 4:46 AM, Stephen Nelson-Smith wrote: > Hi Kent, > >> See the Python Cookbook recipes I referenced earlier. >> http://code.activestate.com/recipes/491285/ >> http://code.activestate.com/recipes/535160/ >> >> Note they won't fix up the jumbled ordering of your files but I don

Re: [Tutor] Iterator Merging

2009-11-11 Thread Kent Johnson
On Wed, Nov 11, 2009 at 7:54 AM, Stephen Nelson-Smith wrote: > So, following Kent and Alan's advice, I've preprocessed my data, and > have code that produces 6 LogFile iterator objects: > import magpie magpie.logs[1] > for timestamp, entry in itertools.islice(magpie.logs[1], 3): > .

Re: [Tutor] How to call a method with a print statement?

2009-11-12 Thread Kent Johnson
On Thu, Nov 12, 2009 at 5:31 AM, Modulok wrote: > List, > > How do I get a print statement to call a class method? I'm using > python 2.5. I did it long ago, but can't remember how, or even where I > learned it from. Something like: > > class Foo(): >   def __init__(self): >      pass > >   def  *

Re: [Tutor] os.environ question

2009-11-12 Thread Kent Johnson
On Wed, Nov 11, 2009 at 10:34 PM, Khalid Al-Ghamdi wrote: > hi, > can anyone tell me why on python 2.6 i can enter os.environ and then get all > the items that that pertain to the os while on python 3 you just get the > following: > > with no items? I think this is perhaps an oversight in Python

Re: [Tutor] How to call a method with a print statement?

2009-11-12 Thread Kent Johnson
On Thu, Nov 12, 2009 at 6:35 AM, Luke Paireepinart wrote: > > > On Thu, Nov 12, 2009 at 5:29 AM, Jeff R. Allen wrote: >> >> You are looking for the __str__ method. See >> http://docs.python.org/reference/datamodel.html#object.__str__ >> > Can't you also implement __repr__? Yes, in fact if you ar

Re: [Tutor] parsing XML into a python dictionary

2009-11-14 Thread Kent Johnson
On Sat, Nov 14, 2009 at 1:14 AM, Christopher Spears wrote: > I've been working on a way to parse an XML document and convert it into a > python dictionary.  I want to maintain the hierarchy of the XML.  Here is the > sample XML I have been working on: > > >   >    Neil Gaiman >    Glyn Dillon >

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