Re: [Tutor] Question about classes

2007-08-25 Thread Eric Abrahamsen
On Aug 25, 2007, at 12:59 PM, Ara Kooser wrote: > Hello all, > >I am working on trying to understand classes by creating a > character generator for a rpg. I know I am doing something silly but I > am not sure what. When I run the program I and type no when prompted I > get the following messa

Re: [Tutor] Question about classes

2007-08-25 Thread Eric Abrahamsen
> Welcome to the wacky world of recursion. > You call __upp from inside __upp so you do indeed generate > a new layer, in fact you start a new while loop. You need to > move the while loop out into init, something like this: So all those "yes"s were actually backing out of multiple while loops..

[Tutor] sorting lists in dictionary values

2007-08-26 Thread Eric Abrahamsen
I wrote the stupid little script below for practice; it takes a text file with a list of surnames, and returns a dictionary where the keys are first letters of the names, and the values are lists of names grouped under their appropriate first-letter key, like so: {'A': ['Abercrombie'], 'B':

Re: [Tutor] sorting lists in dictionary values

2007-08-26 Thread Eric Abrahamsen
> From noob to noob : sort sorts in place. I seem to remember it > returns nothing. > > This works: > > In [12]: directoryOut[12]: > {'A': ['Abercrombie', 'Aalberg'], > 'B': ['Barnaby', 'Black', 'Biggles'], > 'D': ['Douglas', 'Dawn', 'Diggle'], > 'G': ['Granger', 'Gossen']} > > In [13]: for key i

Re: [Tutor] sorting lists in dictionary values

2007-08-26 Thread Eric Abrahamsen
Whoa, this made my brain hurt. And I thought I was being clever using a set... I can't say I really understand this yet, but I'm trying. If anyone's following along at home I found this link kind of helpful: http://python.net/crew/mwh/hacks/setdefault.html Thanks a lot for your help, Eric

Re: [Tutor] tagging pieces of information

2007-08-27 Thread Eric Abrahamsen
On Aug 28, 2007, at 11:07 AM, Che M wrote: > I don't know if there are any preexisting Python structures which > would help > with this or if it has to be done by scratch, or if it is easy or > difficult. > I also don't know what are good ideas for ways to save the tags, > whether > in a t

Re: [Tutor] Accessing Values of specific column in a 2D list or array

2007-09-02 Thread Eric Abrahamsen
> grid = [[1,1,2,7,6,9],\ > [,9,1,1,1,9,1],\ > [8,1,2,0,0,4],\ > [1,4,1,1,8,5]] > > how can i access to all the elements of the list from column no. 5. > > output should be like [6,9,0,8]... Your basic tool is sub-indexing: you can reach items in the sub-lists by us

Re: [Tutor] Accessing Values of specific column in a 2D list or array

2007-09-02 Thread Eric Abrahamsen
> > COL = 5 > [i[COL-1] for i in grid] Should have guessed... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] class awareness of variable name

2007-09-17 Thread Eric Abrahamsen
When instantiating a class, is it possible for that instance to 'know' (via the __init__ method, I suppose) the name of the variable it's been assigned to? Thanks E ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] class awareness of variable name

2007-09-17 Thread Eric Abrahamsen
On Sep 17, 2007, at 7:21 PM, Alan Gauld wrote: > > "Eric Abrahamsen" <[EMAIL PROTECTED]> wrote > >> When instantiating a class, is it possible for that instance to >> 'know' (via the __init__ method, I suppose) the name of the variable >> it&#

Re: [Tutor] class awareness of variable name

2007-09-17 Thread Eric Abrahamsen
> This is pretty hard. For one thing, the object will not be bound to > a name until after __init__() is finished. Ah, that's a good thing to know... > you could probably use the stack frame to find the point of call > and inspect the byte codes there to find the name... I was afraid the ans

[Tutor] reading POST method in cgi script

2007-10-15 Thread Eric Abrahamsen
I'm trying to learn the fundamentals of cgi scripting, before moving on to actually using the cgi module and, eventually, mod_python. I've grasped that, if users submit a form to my cgi script, I can read the form contents from os.environ['QUERY_STRING'] if it was stuck in the URL via metho

Re: [Tutor] reading POST method in cgi script

2007-10-16 Thread Eric Abrahamsen
Thanks for the detailed help. I'm dumping sys.stdin into a variable at the very start now, and operating on that variable for everything else, and all is well. Thanks again, E On Oct 16, 2007, at 12:22 PM, Luke Paireepinart wrote: > Eric Abrahamsen wrote: >> I'm

Re: [Tutor] Obtaining image date of creation

2007-11-14 Thread Eric Abrahamsen
On Nov 14, 2007, at 9:05 PM, Kent Johnson wrote: > Roy Chen wrote: >> Hello, >> >> I would like to write a simple script that would rename a bunch of >> photos according to their creation date, i.e. the date which the >> photo was taken. >> >> Is there a way to use Python to obtain that informatio

Re: [Tutor] Obtaining image date of creation

2007-11-14 Thread Eric Abrahamsen
> And while I haven't tried it, this page (http://effbot.org/zone/pil- > changes-114.htm) appears to indicate exif format is somewhat > supported in PIL; perhaps pyexif does a better job though? PIL does a pretty job, though it's a pain. from PIL import Image from PIL.ExifTags import TAGS def get

[Tutor] subclassing strings

2008-01-08 Thread Eric Abrahamsen
I'm playing around with subclassing the built-in string type, and realizing there's quite a bit I don't know about what's going on with the built-in types. When I create a string like so: x = 'myvalue' my understanding is that this is equivalent to: x = str('myvalue') and that this second f

Re: [Tutor] subclassing strings

2008-01-08 Thread Eric Abrahamsen
Thanks both of you, that cleared a lot of things up. On Jan 9, 2008, at 11:49 AM, Kent Johnson wrote: > > No, you can't access the actual byte array from Python and you can't > damage it. I don't know a lick of C and probably never will, but I do like to know what it is, exactly, that I don't

[Tutor] PIL: preserving exif data

2008-01-13 Thread Eric Abrahamsen
Can any PIL people out there tell me if it's possible to save a jpeg image with exif data? I'm opening an image file, making changes to it, and then resaving it: apparently calling save() chops off its exif data, and there doesn't appear to be a way to re-attach it via a parameter to the sa

Re: [Tutor] new guy problem, what's wrong with this program.

2008-01-13 Thread Eric Abrahamsen
mumber = 23 running = Ture Both these lines have spelling errors: 'mumber' should be 'number', and 'Ture' should be 'True'. You can see where the problem is coming from by the end of your traceback: NameError: name 'Ture' is not defined A NameError with something being 'not defined'

Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread Eric Abrahamsen
Hey, on this topic, I spent some time this afternoon googling the One Laptop Per Child (OLPC) project (the GUI is done with Python and PyGTK), to see if there were any collaborative open-source projects I could contribute to. Seems like a perfect opportunity to get a little more Python expe

Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread Eric Abrahamsen
on your PC: > http://wiki.laptop.org/go/OS_images_for_emulation > > I was looking at Metropolis (the non-TM version of SimCity) as its gui > is all written in python > > --Michael > > > > On 1/16/08, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: >> Hey,

Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread Eric Abrahamsen
configuration idjit. I'll let you know how it goes. Will it conflict with an existing pyGTK installation? Both Snakes and Ladders and the pipelines thing sound potentially interesting, I'll get back to you guys in a couple days... Thanks! Eric > > > --Michael > > O

Re: [Tutor] if ... else shorthand form ?

2008-02-09 Thread Eric Abrahamsen
> Hi all, > > Returning to python after a brief affair with C++, I have the > following code ... > >if (items.has_keys('snapshot_interval')): >self.snap_init[i] = items['snapshot_interval'] >else: >self.snap_init[i] = 0 > > I

[Tutor] sorting objects on two attributes

2008-03-03 Thread Eric Abrahamsen
I have a grisly little sorting problem to which I've hacked together a solution, but I'm hoping someone here might have a better suggestion. I have a list of objects, each of which has two attributes, object_id and submit_date. What I want is to sort them by content_type, then by submit_date

Re: [Tutor] sorting objects on two attributes

2008-03-03 Thread Eric Abrahamsen
ode I give produces > the ordering that you intend, but you may adjust the sign of the > decorate elements if necessary. > > With regard, > Michael > > +--- > | Michael Goldwasser > | Associate Professor > | Dept. Mathematics and Computer Science > | Saint Loui

Re: [Tutor] sorting objects on two attributes

2008-03-03 Thread Eric Abrahamsen
On Mar 4, 2008, at 11:04 AM, Kent Johnson wrote: > Eric Abrahamsen wrote: >> Itertools.groupby is totally impenetrable to me > > Maybe this will help: > http://personalpages.tds.net/~kent37/blog/arch_m1_2005_12.html#e69 > > Kent > It did! Thanks very much. I think I

Re: [Tutor] web programming tutorials?

2008-04-18 Thread Eric Abrahamsen
On Apr 18, 2008, at 8:01 AM, Hansen, Mike wrote: > IMHO, I think before anyone jumps into using a framework, they should > understand the basics of cgi programming. Maybe do just a small > exercise with simple form processing. After that exercise, then move > on to one of the frameworks that make

[Tutor] syntax question

2008-05-21 Thread Eric Abrahamsen
Hi all, This is a syntax that I've seen on occasion in other people's code: theme = (VALID_THEMES[0], theme) [ theme in VALID_THEMES ] I have no idea how this works, or how to go about looking it up. Can someone enlighten me as to what's happening here? Many thanks, Eric ___

[Tutor] get/set attributes

2008-05-25 Thread Eric Abrahamsen
Hello, I'm trying to create a Dummy class of objects, something that will return an empty string for any attribute. I'm making a very simple CMS with Cherrypy/Sqlalchemy/Cheetah, and I have an HTML form template that I use for editing/creating objects to save to the database. I'm using ju

Re: [Tutor] get/set attributes

2008-05-25 Thread Eric Abrahamsen
This creates an attribute named k; it does not create an attribute whose name is the *value* of k. For that you need setattr: setattr(self, k, v) There is a shortcut that replaces the entire loop: self.__dict__.update(atts) Thanks Kent, that explains a lot about how things work. return an e

[Tutor] inheritance/classmethods/metaclasses

2008-06-19 Thread Eric Abrahamsen
I'm probably in over my head here, but I really want to know how this works, and I hope someone will be willing to take a moment to explain it... I'm making a few classes for a very simple ORM, where the classes reflect objects that I'm persisting via pickle. I'd like to add and delete in

Re: [Tutor] inheritance/classmethods/metaclasses

2008-06-19 Thread Eric Abrahamsen
What you have almost works. Try this: No kidding – that's what I get for wild stabs in the dark, I thought I'd tried that. I'm pleased that it really is that simple (and that, whatever metaclasses are used for, I don't need to worry about them yet). Thanks! Eric (Grrr, bit by the reply

Re: [Tutor] TypeError: not enough arguments for format string

2008-07-01 Thread Eric Abrahamsen
On Jul 2, 2008, at 12:36 PM, Christopher Spears wrote: I'm working on problem 13-5 in Core Python Programming (2nd Edition). I am supposed to create point class. Here is what I have so far: #!/usr/bin/python class Point(object): def __init__(self, x=0.0,y=0.0): self.x = float(

Re: [Tutor] character encoding

2008-07-08 Thread Eric Abrahamsen
As for other resources, I recently came across this: http://farmdev.com/talks/unicode/ This was the first explanation that really made me understand the difference between Unicode and utf-8 (and realize that I'd been using the terms 'encode' and 'decode' backwards!). Anyway, just one more r

[Tutor] splits and pops

2008-07-12 Thread Eric Abrahamsen
I have a horribly stupid text parsing problem that is driving me crazy, and making me think my Python skills have a long, long way to go... What I've got is a poorly-though-out SQL dump, in the form of a text file, where each record is separated by a newline, and each field in each record

[Tutor] python environment

2008-07-18 Thread Eric Abrahamsen
I've been looking around for a good tutorial or background info on how the Python runtime environment works, and haven't quite found what I'm looking for. I started fooling with having different versions of modules available to difference processes on a single server, which led me to virtua

[Tutor] requests/responses from urllib2

2008-08-10 Thread Eric Abrahamsen
I've got a question about the way urllib2 makes its requests. If I've got a python web framework running behind a web server, and that framework uses urllib2 to make a request to another server, how does that traffic go in and out of my server machine? The python docs say that urllib2 requi

Re: [Tutor] requests/responses from urllib2

2008-08-13 Thread Eric Abrahamsen
Thanks to you both. I'll read up on sockets, but it seems unlikely that it works the way I thought it might... On Aug 12, 2008, at 8:45 PM, Kent Johnson wrote: On Tue, Aug 12, 2008 at 7:27 AM, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: On Aug 11, 2008, at 6:54 PM, Kent Johnson

[Tutor] __iter__ loops, partitioning list among children

2008-08-23 Thread Eric Abrahamsen
Hi, I've got a problem that takes a bit of explaining, but it's relatively simple when you get down to it. This is another django-related thing, but the issue itself is pure python. I made a custom class, called an EventEngine, which represents a span of time. You initialize it with a que

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-24 Thread Eric Abrahamsen
On Aug 24, 2008, at 7:20 PM, Kent Johnson wrote: Forwarding to the list with my reply. Please use Reply All to reply to the list. Grr, sorry, I keep forgetting... On Sun, Aug 24, 2008 at 1:02 AM, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: On Aug 23, 2008, at 11:22 PM, Kent J

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-25 Thread Eric Abrahamsen
break self.sentinel += c.dt_range if not require_events or c.has_events(): # if require_events == True, omit empty children. yield c On Aug 25, 2008, at 11:49 AM, Eric Abrahamsen wrote: On Aug 24, 2008, at 7:20 PM, Kent Johnson wrote: Forward

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-25 Thread Eric Abrahamsen
I do apologize for the large quantities of confusing description – articulating the problem here has helped me understand exactly what it is I'm after (though it hasn't improved my code!), and I've got a better grasp of the problem now than I did when I first asked. It isn't so much that I

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-26 Thread Eric Abrahamsen
On Aug 26, 2008, at 7:20 PM, Kent Johnson wrote: On Tue, Aug 26, 2008 at 1:36 AM, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: So my test case: a Month has a 'child' attribute pointing at Week, which has a 'child' attribute pointing at Day, so they all know what

Re: [Tutor] __iter__ loops, partitioning list among children

2008-08-28 Thread Eric Abrahamsen
7;s been a learning experience... E On Aug 27, 2008, at 2:22 AM, Kent Johnson wrote: On Tue, Aug 26, 2008 at 1:24 PM, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: On Aug 26, 2008, at 7:20 PM, Kent Johnson wrote: If all you want to do with the nested Month, etc is to iterate the even

Re: [Tutor] Intermediate/advanced concepts

2008-11-07 Thread Eric Abrahamsen
On Nov 7, 2008, at 12:14 PM, [EMAIL PROTECTED] wrote: Hi everyone, I've been teaching myself python for a few months and I'm becoming frustrated because I've kind of hit a wall in terms of learning new information. In an effort to continue to learn I've found some material on more interm

[Tutor] more encoding strangeness

2008-12-22 Thread Eric Abrahamsen
Hi there, I'm configuring a python command to be used by emacs to filter a buffer through python markdown, and noticed something strange. If I run this command in the terminal: python -c "import sys,markdown; print markdown.markdown(sys.stdin.read().decode('utf-8'))" < markdown_source.m

[Tutor] import confusion

2009-01-25 Thread Eric Abrahamsen
Hi there, I'm trying to understand how module imports work, and am seeing some behavior I don't understand: >>> import django >>> from django import forms >>> from forms import DecimalField Traceback (most recent call last): File "", line 1, in ImportError: No module named forms >>> import