[Tutor] Fwd: listing classes

2008-05-22 Thread Kent Johnson
Forwarding to the list. -- Forwarded message -- From: Laureano Arcanio <[EMAIL PROTECTED]> Date: Wed, May 21, 2008 at 10:41 PM Subject: Re: [Tutor] listing classes To: Kent Johnson <[EMAIL PROTECTED]> I'm building a light html serialize tool, it's going to be used to build templ

Re: [Tutor] String Replacement question

2008-05-22 Thread Ricardo Aráoz
Faheem wrote: Hi all, How do I replace the same value multiple times without repeating the same variable name/value repeatedly? for ex. some = 'thing' print '%s %s %s %s' % (some,some,some,some) in this case, my question is how do i replace "% (some,some,some)" with something more concis

Re: [Tutor] Fwd: listing classes

2008-05-22 Thread W W
I don't know if this is the best solution, but what I usually do is create a list that matches the key: mydict = {} mylist = [] for x in range(1, 10): key = raw_input("Enter the key: ") mydict[key] = value mylist.append(key) You just have to change it to read from a file/hard code all

Re: [Tutor] listing classes

2008-05-22 Thread Kent Johnson
On Wed, May 21, 2008 at 10:41 PM, Laureano Arcanio <[EMAIL PROTECTED]> wrote: > The problem comes because i need to keep the order of the HTML tags, and as > you say dict doesn't work like that.. I've working on this metaclass, and > then extend list with it, but i have the same problem, the dct c

[Tutor] Randomize SSN value in field

2008-05-22 Thread GTXY20
Hello all, I will be dealing with an address list where I might have the following: Name SSN John 1 John 1 Jane 2 Jill 3 What I need to do is parse the address list and then create a unique random unidentifiable value for the SSN field like so: Name SSNrandomvalu

Re: [Tutor] Randomize SSN value in field

2008-05-22 Thread taserian
On Thu, May 22, 2008 at 12:14 PM, GTXY20 <[EMAIL PROTECTED]> wrote: > Hello all, > > I will be dealing with an address list where I might have the following: > > Name SSN > John 1 > John 1 > Jane 2 > Jill 3 > > What I need to do is parse the address list and then cre

Re: [Tutor] Randomize SSN value in field

2008-05-22 Thread W W
Oops! Maybe it works better with reply to all: You're looking for a completely random 9 digit number that you can't derive the name from? I don't know that anything would really be more or less secure than simply using random. >>> import random >>> random.randrange(1,9) 988559585

Re: [Tutor] Randomize SSN value in field

2008-05-22 Thread Kent Johnson
On Thu, May 22, 2008 at 12:14 PM, GTXY20 <[EMAIL PROTECTED]> wrote: > Hello all, > > I will be dealing with an address list where I might have the following: > > Name SSN > John 1 > John 1 > Jane 2 > Jill 3 > > What I need to do is parse the address list and then cre

Re: [Tutor] Randomize SSN value in field

2008-05-22 Thread W W
On Thu, May 22, 2008 at 12:17 PM, taserian <[EMAIL PROTECTED]> wrote: > so that I can relate it back to the original SSN when needed. Oh! Oops! I didn't clearly understand this sentence the first time. Yes, you want to learn about cryptography. Google for Bruce Schneier - one of the world's forem

Re: [Tutor] Randomize SSN value in field

2008-05-22 Thread GTXY20
Thanks all; Basically I will be given an address list of about 50 million address lines - this will boil down to approximately 15 million unique people in the list using SSN as the reference for the primary key. I was concerned that by using random I would eventually have duplicate values for diff

Re: [Tutor] Randomize SSN value in field

2008-05-22 Thread Kent Johnson
On Thu, May 22, 2008 at 1:56 PM, GTXY20 <[EMAIL PROTECTED]> wrote: > With respect to a potentially large dictionary object can you suggest > efficient ways of handling memory when working with large dictionary > objects? Consider using a database. The public value can just be the primary key of th

Re: [Tutor] String Replacement question

2008-05-22 Thread wesley chun
> > some = 'thing' > > print '%s %s %s %s' % (some,some,some,some) > > You can use named parameters, which moves the repetition to the format string: > > In [24]: print '%(some)s %(some)s %(some)s %(some)s' % (dict(some=some)) > thing thing thing thing > > With multiple values, a common trick

[Tutor] Equivalent 'case' statement

2008-05-22 Thread Dinesh B Vadhia
Is there an equivalent to the C/C++ 'case' (or 'switch') statement in Python? Dinesh ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Equivalent 'case' statement

2008-05-22 Thread inhahe
no, but you can a) use elifs if c==1: do this elif c==2: do this elif c==3: do this b) make a dictionary of functions (this is faster) def case1: do this def case2: do that def case3: do the other cases = {1: case2, 2: case2, 3:case3} cases[c]() if your functions are one expression you c

Re: [Tutor] Equivalent 'case' statement

2008-05-22 Thread inhahe
> > cases = { > 1: lambda: x*2 > 2: lambda: y**2 > 3: lambda: sys.stdout.write("hi\n") > } > i forgot the commas. cases = { 1: lambda: x*2, 2: lambda: y**2, 3: lambda: sys.stdout.write("hi\n") } > > your functions and lambdas can also take parameters of course > lambda a, b: a*b _

Re: [Tutor] Equivalent 'case' statement

2008-05-22 Thread Alan Gauld
"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote Is there an equivalent to the C/C++ 'case' (or 'switch') statement in Python? No, just if/elif However you can often achieve similar results with a dictionary: def func1(v): return v def func2(v): return v*2 switch = { 'val1': func1,

[Tutor] Reading only a few specific lines of a file

2008-05-22 Thread Jason Conner
Hey guys, Very new to programming Python, and I'm running up against a problem. I am building a program that will take a text file, search for a string in that text file. Once it finds the string its looking for, I want to put the next five lines of text into a variable. Here's what I have so far:

Re: [Tutor] Reading only a few specific lines of a file

2008-05-22 Thread John Fouhy
On 23/05/2008, Jason Conner <[EMAIL PROTECTED]> wrote: Hi Jason, > def loadItem(self, objectToLoad): > x = 0 > wordList = [] > fobj = file() > fobj.open("itemconfig.txt", 'rU') > > for line in fobj.readline(): In recent pythons, you can write this better as: for line in fob

Re: [Tutor] String Replacement question

2008-05-22 Thread Faheem
Hey All, Thanks.. That was quick. Good to know there is a mailing list like this one. Thanks to everyone and all the replies. Faheem ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor