Re: [Tutor] hash value input

2010-01-29 Thread Rich Lovely
> hash(b2) == hash("foo") True >>> d2 = {b2: "bar", "foo": "baz"} >>> print d2 {<__main__.BrokenHash object at 0x657e10>: 'bar', 'foo': 'baz'} (If they both fell into the same bucket, d2['foo

Re: [Tutor] Python and Ajax classes at Foothill College

2010-01-29 Thread Rich Lovely
gt; > Can I sign up for the next class? When will it start? > > Thanks much, > Scott > ___ > Tutor maillist  -  tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor >

Re: [Tutor] Input() is not working as expected in Python 3.1

2010-02-15 Thread Rich Lovely
"How many times should it be printed?") >> print snumber >> >> A good robust alternative is to try int() and capture / report the >> failure: >> >> text = str(input("Type in some text: ")) >> snumber = input("How many times should it be printe

Re: [Tutor] Find duplicates (using dictionaries)

2010-02-17 Thread Rich Lovely
is no need to check for the existence of the other elements, so you can cut out a lot of the checks. Whilst your requirements are not exactly clear to me, here is how I would do what it sounds like you need (using the same dict layout as you used previously): def add_record(field1, field2, field3, fi

Re: [Tutor] recursive generator

2010-03-07 Thread Rich Lovely
iter__(self): if self.holdsEntry: yield self.entry for child in self.children: print "<" for val in child: #implicit call to child.__iter__() yield val print ">" Then, when the child.__iter__() is

Re: [Tutor] Proper way to use **kwargs?

2010-03-15 Thread Rich Lovely
improvement if you load the function definition into idle, and then start typing the function name. A tooltip will pop up, listing all the arguments it can take. You can still use the function in exactly the same way as with **kwargs, it just won't hand you a dictionary holding the arguments pas

Re: [Tutor] Sequences of letter

2010-04-12 Thread Rich Lovely
ion options: > http://mail.python.org/mailman/listinfo/tutor > itertools.product() also has the repeat keyword argument: for x in itertools.product('abc', 'abc', 'abc'): is the same as for x in itertools.product('abc', repeat=3): -- Rich "R

Re: [Tutor] getting original pattern from regular expression object

2010-04-19 Thread Rich Lovely
maillist  -  tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > a.pattern: >>> import re >>> a = re.compile("foo") >>> a.pattern 'foo' -- Rich "Roadie Rich" Love

Re: [Tutor] lambda vs list comp

2010-07-27 Thread Rich Lovely
ly calls the function when you ask it for the next value. You can get similar behaviour in python2 using the imap function in the itertools module. It's extremely useful if you need to deal with massive lists of millions of elements - where making the list ever

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

2009-07-01 Thread Rich Lovely
Forgot to reply-all... -- Forwarded message -- From: Rich Lovely Date: 2009/7/1 Subject: Re: [Tutor] calculating a sort key and operator.attrgetter() To: Vincent Davis 2009/7/1 Vincent Davis : > I have a class with an attribute which is a list "rank_list" this i

Re: [Tutor] Is my style OK in this elementary student exercise?

2009-07-04 Thread Rich Lovely
r use eval(raw_input(...)) for the same reasons you should never use input(...), for in effect, that is exactly what you are using. In fact, the python 3.0 docs recommend that form (using the new name for raw_input), in expert scripts allowing interactive code entry. -- Richard "Roadie Rich" Lovely, part of the JNP|UK Famile www.theJNP.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Is my style OK in this elementary student exercise?

2009-07-04 Thread Rich Lovely
le of writing their own script to do so, and would probably just be annoyed at any warnings you chose to stick in. I've never gotten to the point where I've needed input(). I'm curious to know whether anyone on the list has. -- Richard "Roadie Rich" Lovely, part of the J

Re: [Tutor] append question

2009-07-05 Thread Rich Lovely
nge(len(...)), as it adds in the overhead of two function calls, and ruins the readability of code. The latter is probably the most important of the two. An even more pythonic way to do this would be a list comprehension, http://www.python.org/doc/2.6/tutorial/datastructures.htm

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

2009-07-05 Thread Rich Lovely
27;re running - there is a maximum of only 17 passes (once for each value of coin and note) -- Richard "Roadie Rich" Lovely, part of the JNP|UK Famile www.theJNP.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] append question

2009-07-05 Thread Rich Lovely
opython.org/) has been recommended for people with some programming experience, and Think Python for those without, although I'm sure that if you ask 10 members of this list, you'll get 20 different suggestions. Real veterans get pointed at the standard libraries, which are extremly

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

2009-07-06 Thread Rich Lovely
eeing as you appear to be treating your options as (effectively) a char[]: options = "".join(chr(x) for x in (opt4, opt3, opt2, opt1)) Alternatively, like Kent said, take a look at the struct module, which will do all this for you, but is not so educational. -- Richard "Roadie Rich" Lovely, part of the JNP|UK Famile www.theJNP.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

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

2009-07-08 Thread Rich Lovely
s a key: dct = dict((i[0], i[1:]) for i in lst) Then you can access it using the normal dictionary interface. dct["3991404"][3] This will only return the last of any repeated values (previous ones will get overwritten during construction), so it really depends on the behaviour you w

Re: [Tutor] Fwd: thesaurus

2009-07-08 Thread Rich Lovely
;ve got a version prior to that, you'll need to rework it a little, or upgrade. But I think this gives the general idea. I don't think there's any more concise way of doing it than that in python. You also might want to use print instead of writing straight to a file, and use the te

Re: [Tutor] Fwd: thesaurus

2009-07-08 Thread Rich Lovely
It won't hurt code on more recent versions. from __future__ import with_statement import sys buff = [] with open("path_to_input_file", "r") as fin: for line in fin: buff.append(" ".join(lookup(word) for word in line.split())) with open("path_to_out

Re: [Tutor] Fwd: thesaurus

2009-07-08 Thread Rich Lovely
rcise for you, as I don't know the format of the reference you're using. -- Richard "Roadie Rich" Lovely, part of the JNP|UK Famile www.theJNP.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Fwd: thesaurus

2009-07-08 Thread Rich Lovely
know, but it makes the point. Unless, of course, this sort of gibberish is what you're after. Natural language parsers are one of the hardest things to create. Just look up the word "set" in a dictionary to see why. Even if you did work out that the second "set" was a nou

Re: [Tutor] Trickier exercise: convert string to complex number

2009-07-10 Thread Rich Lovely
On 11 Jul 2009, at 03:15, Angus Rodgers wrote: Wesley Chun, /Core Python Programming/, Ex. 6-13: "[...] An atoc() was never implemented in the string module, so that is your task here. atoc() takes a single string as input, a string representation of a complex number [...] and returns the eq

Re: [Tutor] just one question

2009-07-15 Thread Rich Lovely
"C", "CA", "CB") for position in positionsNeeded: print position, "ALA C = %s CA = %s CB = %s" % tuple(atoms[position].get(a,"") for a in atomsNeeded) You would then call it with something like $python myscipt.py > output.txt -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] objects becoming pointers

2009-07-15 Thread Rich Lovely
_ > Tutor maillist  -  tu...@python.org > http://mail.python.org/mailman/listinfo/tutor > > Sorry if I've sent this twice... Why would you want to do that? The closest you can get to that is using exec, but exec is usually considered a code

[Tutor] Fwd: The why

2009-07-15 Thread Rich Lovely
u...@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > > > Sorry if I've sent this twice... > > Why would you want to do that? > > The closest you can get to that is using exec, but exec is usually > considered a code smell. I'd say you&

Re: [Tutor] just one question

2009-07-16 Thread Rich Lovely
; into "values[5]", and you wonder why it's appearing in your output? >> >> Change the final for loop to the following, and it will do what I >> think you want it to do. >> >> for k, v in atoms.iteritems(): >>     print k, "ALA C = %s CA = %s

Re: [Tutor] just one question

2009-07-16 Thread Rich Lovely
= %s" % tuple(v.get(a,"") for a in atomsNeeded) Check you've got the indentation (the spaces at the start of lines) correct, exactly how it is above: this is VERY important in python. -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Form values

2009-07-17 Thread Rich Lovely
> Tutor maillist  -  tu...@python.org > http://mail.python.org/mailman/listinfo/tutor > There is an error before there: In the line entry = name + '|' + email + '|' + address + '|' + telephone + '|' + IpAddre

Re: [Tutor] large strings and garbage collection

2009-07-17 Thread Rich Lovely
ng completely different. >>> print "_".join(listOfStrings) And_now_for_something_completely_different. If you need to perform other operations first, you can pass a generator expression as the argument, for example: >>> " ".join((s.upper() if n%2 else s.lower(

Re: [Tutor] how to join two different files

2009-07-18 Thread Rich Lovely
e same length as the longer file) you can use itertools.izip_longest(). Look it up in the docs for usage. -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] sqlite: don't understand a code snippet

2009-07-25 Thread Rich Lovely
first inserted entry gets an ID of 1, the next 2, and so on. This is stored in a column in the table. The get_director_id(...) function will do something like the following query: cursor.execute("SELECT id FROM directors WHERE name == \"%s\"", (name,)) I don't know how

Re: [Tutor] Need help in making this code more pythonic

2009-07-26 Thread Rich Lovely
occupied position" Finally, you might want to put the code doing the actual work into a "if __name__ == "__main__": block, so that you can import the script as a module, and not get extra output. Take a look at some of the files in the standard library to see what I mean. -- Rich &q

Re: [Tutor] Ptyhon GUI doubt

2009-08-25 Thread Rich Lovely
now the details. > > Thanks, > Raj > ___ > Tutor maillist  -  tu...@python.org > http://mail.python.org/mailman/listinfo/tutor > > This is usually a firewall issue. What firewall software are you using, and do you have access to modify

Re: [Tutor] Input validation

2009-09-04 Thread Rich Lovely
#option 1 return "LT" elif isinstance(param, str):# option 2 if os.path.isfile(param): return "FILE" else: return "STR" else: return None Also, file-type objects aren't instances of str... -- Rich

[Tutor] Fwd: Python and google sites

2009-09-09 Thread Rich Lovely
Forgot to reply-all... -- Forwarded message -- From: Rich Lovely Date: 2009/9/9 Subject: Re: [Tutor] Python and google sites To: andy 2009/9/9 andy : > Hi people > > After searching pypy and google, I was wondering if anyone has any > experience/knowledge of a p

Re: [Tutor] How to print the next line in python

2009-09-12 Thread Rich Lovely
tions: > http://mail.python.org/mailman/listinfo/tutor > If we want to be really modern: #Only works on python 2.5 or later. On 2.6 (or higher...), the following line is not needed. from __future__ import with_statement previous_line = "" with open('somefile.txt','

Re: [Tutor] include remote module

2009-09-12 Thread Rich Lovely
://docs.python.org/library/modules.html -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one. ___ Tutor maillist - Tutor@python.org To unsubscribe or change sub

Re: [Tutor] Sorting 2-d data

2009-09-13 Thread Rich Lovely
ble to turn it into a one line comprehension: myNewList = [[decorated[1] for decorated in sorted(zip(mylist[0], L), key=lambda t: t[0])] for L in mylist] I'm not suggesting you do it like this, but it's always useful to learn new patterns. -- Rich "Roadie Rich" Lovely There

Re: [Tutor] New guy question...

2009-09-14 Thread Rich Lovely
licated the problem described. (I can't even get the eof error by hitting enter on a newline) - I am on a mac, running from terminal. I can only replicate the error one way: $ cat test.py | python3 Traceback (most recent call last): File "", line 1, in EOFError: EOF w

Re: [Tutor] New guy question...

2009-09-15 Thread Rich Lovely
st): File "", line 1, in EOFError: EOF when reading a line (I also tested the script in the OP, and got identical output to that mentioned). This supports Kent's suggestion in a way, although maybe for a slightly different reason. -- Rich "Roadie Rich" Lovely

Re: [Tutor] Fw: utf locale sorting

2009-09-16 Thread Rich Lovely
so do the same with a lambda: print sorted(words, key=lambda o: locale.strxfrm(o[0])) Hope that helps -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one. ___

Re: [Tutor] Convert doc to txt on Ubuntu

2009-09-16 Thread Rich Lovely
> Tutor maillist  -  tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > FYI, open office .odc files are zip archives of xml files. It should be trivial to access the information from them, assuming

Re: [Tutor] max min value in array

2009-09-17 Thread Rich Lovely
the indexes of the (first) minimum and maximum in the array""" minVal = 0, a[0] maxVal = 0, a[0] for v in enumerate(a): if v[1] < minVal[1]: minVal = v elif v[1] > maxVal[1]: maxVal = v return minVal[0], maxVal[0] -- Rich

Re: [Tutor] On slicing

2009-09-17 Thread Rich Lovely
) is negative. The first value is start, the second stop, and the third step. What you are saying with numbers[10,0,-2], is start at 10 (facing towards the end of the sequence), keep going until you get to 0, taking two steps backwards each time. I hope that clears things up a little.. -- Rich

Re: [Tutor] max min value in array

2009-09-17 Thread Rich Lovely
2009/9/17 Kent Johnson : > On Thu, Sep 17, 2009 at 11:01 AM, steve wrote: >> On 09/17/2009 06:04 PM, Kent Johnson wrote: >>> >>> On Thu, Sep 17, 2009 at 8:06 AM, Rich Lovely >>>  wrote: >>>> >>>>  2009/9/17 Rayon: >>>>&

Re: [Tutor] Python decorator to ensure that kwargs are correct

2009-09-18 Thread Rich Lovely
illist  -  tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > Is there any specific reason you need to use **kwargs? If you omit it from function definitions, you can use normal argument format: >>> class Demo(obje

Re: [Tutor] Python decorator to ensure that kwargs are correct

2009-09-18 Thread Rich Lovely
.. >>> Demo(name='Rich', surname='Lovely', age=24) Rich Lovely 24 <__main__.Demo object at 0x00F75230> >>> Demo(notAName='foo') Traceback (most recent call last): File "", line 1, in TypeError: __init__() got an unexpected

Re: [Tutor] Not workin!

2009-09-29 Thread Rich Lovely
this? And there is no error, btw. > > ___ > Tutor maillist  -  tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > You are testing a string, returned by raw_input()

Re: [Tutor] How to perform variable assignment and

2009-10-03 Thread Rich Lovely
hing like try: home = os.environ['HOME'] except KeyError: home = None else: print "My home directory is", home Admittedly, I don't know what the value of $home would be after executing the snippet above, but I'm assuming nil or null or whatever the perl

Re: [Tutor] __mul__ for different variable types?

2009-10-04 Thread Rich Lovely
ers.html for info. If it's not there, the code demos another feature of isinstance most people don't notice: the type argument can be a sequence of types, so I set Real to a tuple of all the builtin real number types (that I can remember off the top of my head) if the import fails. If yo

Re: [Tutor] Using a list comp in place of a for loop

2009-10-04 Thread Rich Lovely
ns are better than twice the speed (in this simple example) of a regular for loop. With an existing list, adding a comprehension is surprisingly fast (I was expecting extend to be faster). I wasn't expecting the slow comprehension to be as slow as it is, but as you can see, it is slower than a

Re: [Tutor] Which version to start with?

2009-10-05 Thread Rich Lovely
a much larger archive of questions asked previously - most of the posts to this list, archived at http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/python-Tutor (among a few other places), are about 2.x code. -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those

Re: [Tutor] for loop issue

2009-10-10 Thread Rich Lovely
h xrange() and len(), I'd always recommend using enumerate: e.g. Your example of for i in xrange(0, len(x)-1): print x[i], x[i+1] becomes for i, v in enumerate(x[:-1]): #omitting last value in list to avoid IndexError print v, x[i+1] I've got to say that of the two, I prefer

Re: [Tutor] Masking operation

2009-10-14 Thread Rich Lovely
rg/mailman/listinfo/tutor > > Look up the itertools module: http://docs.python.org/library/itertools.html Specifically, cycle and izip. itertools.cycle is the trick here, izip is a more efficient (in this case) version of zip. -- Rich "Roadie Rich" Lovely There are 10 types of p

Re: [Tutor] Most pythonic input validation

2009-10-15 Thread Rich Lovely
d a conversion to int, and I'm catching KeyError (for dicts), IndexError (for lists), and TypeError, for when int(choice) fails. This is a principle called "It's Easier to Ask Forgiveness than Permission" (EAFP), which is one of the pythonic principles. Hope that hel

Re: [Tutor] Masking operation

2009-10-15 Thread Rich Lovely
e(mask))) But that's maybe going a little over the top, unless we're entering an obfuscated code contest. -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one. _

Re: [Tutor] Most pythonic input validation

2009-10-15 Thread Rich Lovely
2009/10/15 Wayne Werner : > > > On Thu, Oct 15, 2009 at 10:50 AM, Rich Lovely > wrote: >> >> 2009/10/15 Wayne Werner : >> > Hi, >> > I'm writing a text based menu and want to validate the user input. I'm >> > giving the option

Re: [Tutor] Testing for empty list

2009-10-19 Thread Rich Lovely
d() else: queue.insert(0, PrecedentTask()) Yes, the precedentTask code could be pasted into the else block, but what if more than one class used that precedent, or the precedent had precedents itself, which in turn were used by multiple classes? OK, That was pretty contrieved, and

Re: [Tutor] request for comments regarding my function

2009-10-25 Thread Rich Lovely
ingle pass d[entry.year()][entry.month()].append(entry.data()) return d And finally, a little utility function, which DOES use recursion: def mapToDict(d): """"recursively convert defaultdicts into regular dicts""" d = dict(d) d.update((k,

Re: [Tutor] Using IDLE v2.6

2009-10-25 Thread Rich Lovely
distribution, which is the usually recommended python distribution for windows. -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one. ___ Tutor maillis

Re: [Tutor] Making http posts

2009-11-18 Thread Rich Lovely
thods to click on links and so on, exactly as you would in a browser. Basically, if you can do it with a keyboard and your prefered webbrowser, you can do it with mechanize, and a few things beside. (I've bypassed a (copypasta) javascript md5 function on a forum login before now...) -- Rich &quo

Re: [Tutor] Is pydoc the right API docs?

2009-11-24 Thread Rich Lovely
The same will happen if you try looking at the pydocs for, for example, str or repr: they are wrappers for magic methods on the object it is called with. -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who a

Re: [Tutor] Iterating over two sequences in "parallel"

2009-11-28 Thread Rich Lovely
; l1 = range(4) >>> l2 = range(2) >>> def p(x, y): ... print x, y ... >>> map(p, l1, l2) 0 0 1 1 2 None 3 None [None, None, None, None] >>> def p(x, y): ... return (x or 0) + (y or 0) ... >>> map(p, l1, l2) [0, 2, 2, 3] -- Rich "Roadie Rich" L

Re: [Tutor] loops

2009-12-08 Thread Rich Lovely
ription options: > http://mail.python.org/mailman/listinfo/tutor > This, of course is a rather dirty, implementation (and probably version) specific hack, but I can /calculate/ the sequence, using just one line: >>> print " ".join(str(i) for i in [x if x<2 else >

Re: [Tutor] Read-create-edit file

2009-12-13 Thread Rich Lovely
code on the server, unless it depends on third party modules. Uplaod it to a pastebin, send us the link, and we might consider taking a look. -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one.

Re: [Tutor] subclass question

2009-12-20 Thread Rich Lovely
ttr__ and so on, but that's a little more complicated. I will however say, that the original behaviour is entirely intentional. Python was designed to be a language used by consenting adults who should know better than doing things that are likely to break stuff. For instance, there is nothing t

Re: [Tutor] A Python Pastebin where scripts can be run

2009-12-20 Thread Rich Lovely
x27;m > hoping some Tutor could post the link. > > Thanks, > > Dick Moores > ___ > Tutor maillist  -  tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > --

Re: [Tutor] print IP address range to stdout

2009-12-22 Thread Rich Lovely
ach "quad" (the term for each number in an IP address), multiply it by a certain constant depending on where in the address it falls, and then adding it to the numeric address. Perhaps there's a library function to do this, but it's a useful learni

Re: [Tutor] using mechanize to authenticate and pull data out of site

2009-12-28 Thread Rich Lovely
rtunately, this is just a simple http request, much like you are already doing - it's just handled under the surface by javascript. -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one. _

Re: [Tutor] Finding a repeating sequence of digits

2010-01-02 Thread Rich Lovely
es to number theory, I always turn first of all to wikipedia. http://en.wikipedia.org/wiki/Repeating_decimal If that doesn't help, I usually turn to Wolfram: http://mathworld.wolfram.com/RepeatingDecimal.html Between the two, and the links therefrom, there's probably all the information you ne

Re: [Tutor] Printing data to a printer...

2010-01-02 Thread Rich Lovely
nsiderably easier on windows, there is the win32print package that does (most of) the heavy lifting for you. To be honest, I'm not even sure if option four will work _at_all_. -- Rich "Roadie Rich" Lovely Just because you CAN do s

Re: [Tutor] Problem formatting raw_input

2008-10-31 Thread Rich Lovely
The try: except: clauses allow for someone typing something like 'spam' when the program expects a number. It stops the program dying with an error message. --- Richard "Roadie Rich" Lovely Part of the JNP|UK Famille www.theJNP.com --- (Sent from my iPod - please allow f

Re: [Tutor] how to call a binding method from an imported module

2008-10-31 Thread Rich Lovely
one arguement. --- Richard "Roadie Rich" Lovely Part of the JNP|UK Famille www.theJNP.com --- (Sent from my iPod - please allow for any typos: it's a very small keyboard) On 31 Oct 2008, at 20:16, [EMAIL PROTECTED] wrote: This problem involves a callback method while using &

Re: [Tutor] Question

2008-11-09 Thread Rich Lovely
it's website. --- Richard "Roadie Rich" Lovely Part of the JNP|UK Famille www.theJNP.com (Sent from my iPod - please allow me a few typos: it's a very small keyboard) On 9 Nov 2008, at 03:22 AM, Bap <[EMAIL PROTECTED]> wrote: Can I use n

Re: [Tutor] Classes and Databases

2008-11-15 Thread Rich Lovely
@list: pickle? --- Richard "Roadie Rich" Lovely Part of the JNP|UK Famille www.theJNP.com (Sent from my iPod - please allow me a few typos: it's a very small keyboard) On 14 Nov 2008, at 04:42 PM, "Jojo Mwebaze" <[EMAIL PROTECTED]> wrote: Sorry Alan, What u de

Re: [Tutor] Help Optimise Code

2008-11-21 Thread Rich Lovely
ng a number iff not any(l[:sqrtX]). No division involved...) If that make no sense to anyone, it makes less sense to me, sounds ok, though... --- Richard "Roadie Rich" Lovely Part of the JNP|UK Famille www.theJNP.com (Sent from my iPod - please allow me a few typos: it's a very

Re: [Tutor] mod_python

2008-11-28 Thread Rich Lovely
Wsgi is also more portable than mod_python: mod_python is solely available on the Apache httpd, whereas wsgi is available on many more. --- Richard "Roadie Rich" Lovely Part of the JNP|UK Famille www.theJNP.com (Sent from my iPod - please allow me a few typos: it's a very s

Re: [Tutor] Making a dictionary of dictionaries from csv file

2008-12-03 Thread Rich Lovely
How about this: def recursiveDictFactory(): return defaultdict(recursiveDictFactory) dictOfDictsOfDictsEtc = defaultdict(recursiveDictFactory) --- Richard "Roadie Rich" Lovely Part of the JNP|UK Famille www.theJNP.com (Sent from my iPod - please allow me a few typos: it'

Re: [Tutor] Random equation generator

2008-12-05 Thread Rich Lovely
When you say linear, I'm assuming fitting y=mx+c, and passing through points? The line through points (x1, y1) and (x2,y2) is y - y1 = (y2-y1) / (x2-x1) * (x-x1) That multiplies out to: y = (y2-y1)/(x2-x1) * x - (y2-y1)/(x2-x1) + y1 That gives m = (y2-y1)/(x2-x1) and c = y1 - (y2-y1)/(x2-x1

Re: [Tutor] Random equation generator

2008-12-06 Thread Rich Lovely
Please use the reply-all button when responding, so that your message gets sent to the list as well. If that's the sort of equation you're after, than the easiest way would probably to decide on a generalised form: y=(2x-1)*4x y = 4*x**2 - 4x y=2+5(x-1) y = 5*x - 3 y=(2x+5)+(5x-25) y =

Re: [Tutor] Working with lists

2008-12-14 Thread Rich Lovely
Yeah, you could do that, but it was quite a revelation when I discovered itertools, and I'm just trying to share the love. --- Richard "Roadie Rich" Lovely Part of the JNP|UK Famille www.theJNP.com (Sent from my iPod - please allow me a few typos: it's a very small k

[Tutor] Single line webserver

2011-11-07 Thread Rich Lovely
Hi all, I was part of this list a couple of years ago, and a recent discussion at a python dojo brought to mind something I'd seen then: a one-liner (potentially single statement) webserver. I'm pretty sure it was posted to this list, but I can't find it in the archives, and a google search is

Re: [Tutor] Tutor Digest, Vol 93, Issue 38

2011-11-08 Thread Rich Lovely
-Type: text/plain; charset=ISO-8859-1; format=flowed > > Rich Lovely wrote: >> Hi all, I was part of this list a couple of years ago, and a recent >> discussion at a python dojo brought to mind something I'd seen then: a >> one-liner (potentially single statement) w

Re: [Tutor] [OSX] "Executable" .py or pyc script (stuck at Applescript)

2011-11-10 Thread Rich Lovely
On 10 Nov 2011, at 15:20, learner404 wrote: > > > On Thu, Nov 10, 2011 at 2:14 PM, Steven D'Aprano wrote: > learner404 wrote: > Hello list! > > - myapp.py is in a "myfolder" folder that the "users" will be able to > download and put anywhere on their Mac. > [...] > > In both cases OSX compla

Re: [Tutor] Find all strings that....

2011-11-10 Thread Rich Lovely
If you're on linux or OSX, there's /usr/share/dict/words, which has a few thousand words. Although no plurals, which caught me out once. If you're on windows, it's not a hard file to find. On 10 Nov 2011, at 16:14, Alex Hall wrote: > What about just grabbing a bit text file, such as from Proj

Re: [Tutor] How to raise error without the stack trace

2011-11-26 Thread Rich Lovely
 Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > Although there's nothing wrong with taking the stack trace and cleaning it up - perhaps dumping it to a logfile, using the Traceback module. Asking your users to send a fi

Re: [Tutor] where python is used in real world

2011-12-04 Thread Rich Lovely
On 4 Dec 2011, at 16:36, Modulok wrote: >>> 2. If one wants to make a commercial software using python, how can he >>> hide the code? > > While it's a valid question, it's fun to imagine it in the physical world: "We > need to permanently weld the engine compartment closed so that no one can >

[Tutor] Fwd: A shorter way to initialize a list?

2011-12-13 Thread Rich Lovely
Forgot to reply all... -- Forwarded message -- From: Rich Lovely Date: 13 December 2011 23:17 Subject: Re: [Tutor] A shorter way to initialize a list? To: Kaixi Luo On 13 December 2011 20:39, Kaixi Luo wrote: > Hello, > > I want to create a list of lists of lis

Re: [Tutor] list issue.. i think

2011-12-22 Thread Rich Lovely
itertools.product, although I can't see exactly what you want as a final result. The process will be something like: turn a into list of lists of key:value pairs call itertools.product() using star notation (http://docs.python.org/tutorial/controlfl

Re: [Tutor] something relevant to array

2011-12-23 Thread Rich Lovely
8e-01 > 2.280239e-01 > > > Thanks with best regards, > ___ > Tutor maillist  -  Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor You can't append to an int, you