Re: [Tutor] Binary search question

2010-04-23 Thread Steven D'Aprano
t Timer >>> t1 = Timer("457 in data1", setup) >>> t2 = Timer("457 in data2", setup) >>> t3 = Timer("bin_search(data1, 457)", setup) >>> t4 = Timer("bin_search(data2, 457)", setup) >>> >>> for t in (t1, t2

Re: [Tutor] Class Inheritance

2010-04-23 Thread Steven D'Aprano
s actually counterproductive, making a rod for your own back, by introducing bugs into code that wasn't buggy in the first place. Learning to code is hard enough when you can trust the library to be (mostly) bug free, don't make it any harder! -- Steven D'Aprano

Re: [Tutor] Binary search question

2010-04-23 Thread Steven D'Aprano
spend your time as a programmer. Hence the usual advice that premature optimization is the root of all evil. First make it work, and then only if it's not fast enough, make it work faster. Of course, none of this is meant to say you shouldn't plan ahead and choose the best data structure for the job! -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Binary search question

2010-04-23 Thread Steven D'Aprano
On Sat, 24 Apr 2010 10:37:15 am Steven D'Aprano wrote: > For the record, here's some timing benchmarks to see how badly it > turned out: [...] > 0.0346097946167 > 0.461233854294 > 3.04955101013 > 5.70547604561 > > For comparison, here's the timing on a pla

Re: [Tutor] self.attribute and import attribute

2010-04-23 Thread Steven D'Aprano
lf.filename, 'a') as f: f.write("...") and the file will be automatically closed safely even if an error occurs! (In Python 2.5, you can also do this if you run from __future__ import with_statement at the very top of your program.) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Hi everybody stuck on some error need help please thank you!!

2010-04-23 Thread Steven D'Aprano
;>> x.append('something') # Modify that list in place. >>> x is y # Still identical. True >>> y ['something'] If this is the behaviour you want, then you don't need to do anything. Otherwise you need to move the creation of the empty list inside t

Re: [Tutor] Hi everybody stuck on some error need help please thank you!!

2010-04-23 Thread Steven D'Aprano
SAME empty list. >>> a.append(1) >>> print a, b [1] [1] When you have a default value like magasins=[], it is like the second, not the first. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Class Inheritance, Beat it into the Ground

2010-04-23 Thread Steven D'Aprano
er doesn't have one, it creates it. It uses Tkinter's Frame object as the base class (not a metaclass, metaclasses are an advanced technique which are very different). That way the ScrolledCanvas class inherits behaviour from Frame. -- Steven D'Aprano __

Re: [Tutor] sqrt?

2010-04-24 Thread Steven D'Aprano
gt; > I am now officiciously pissed. Perhaps you should drink less alcohol before posting then. *wink* (For those in the US, in British and Australian English, to be "pissed" is to be drunk. Being angry is "pissed off".) -- Steven D'Aprano __

Re: [Tutor] module import problems

2010-04-25 Thread Steven D'Aprano
"tables"? Is that the same as _table? Generally you shouldn't use the "from module import *" form. You should consider it advanced usage, or at least discouraged. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To

Re: [Tutor] Modify inherited methods

2010-04-27 Thread Steven D'Aprano
This is true, as far as it goes, but what they say is that if the behaviour of dict.__init__ changes, and you *do* call it, your class may still break. (This is why dict is unlikely to change any time soon.) -- Steven D'Aprano ___ Tutor

Re: [Tutor] Modify inherited methods

2010-04-27 Thread Steven D'Aprano
On Wed, 28 Apr 2010 08:08:12 am Steven D'Aprano wrote: > Some people argue that you must call dict.__init__ even though it > doesn't do anything. Their reasoning is, some day its behaviour might > change, and if you don't call it in your subclass, then your class > may

Re: [Tutor] Modify inherited methods

2010-04-28 Thread Steven D'Aprano
On Wed, 28 Apr 2010 04:53:06 pm Walter Wefft wrote: > Steven D'Aprano wrote: > > And for guru-level mastery, replace to call to dict.__init__ with > > ... > > nothing at all, because dict.__init__ doesn't do anything. [...] > Behaviour is different depending

Re: [Tutor] Using Regex to produce text

2010-04-28 Thread Steven D'Aprano
yield c else: # There are a *lot* of unicode characters, but I don't know # how many. Take the coward's way out. raise NotImplementedError('left as an exercise for the reader') > It's too ambiguous and if you say to foll

Re: [Tutor] Python beginner having troubles understanding word lists and character lists

2010-04-28 Thread Steven D'Aprano
t;yellow", "green"] Characters are single letters, digits or punctuation marks: a e i o u 2 4 6 8 . ? $ % In Python, characters are just strings, and you can put them in a list: ["a", "e", "i", "o", "u", "2", &q

Re: [Tutor] Any

2010-04-29 Thread Steven D'Aprano
d (may it rest in peace!). And Dabo is based on Visual FoxPro. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] blackjack game

2010-04-29 Thread Steven D'Aprano
rds, something will happen -- usually the dealer will start a new, shuffled, deck. Does your code have a deck? > 2. I am not sure if I can let the winner get all of the cards and > print out what cards the winner has when the game finished. That's a question about blackjack, not Python.

Re: [Tutor] python list, right! but concretely?

2010-05-02 Thread Steven D'Aprano
ure walk(alist: ptr): begin while alist <> nil: begin writeln(alist^.data); alist := alist^.next end; end; Everything else, I leave as an exercise :) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] python list, right! but concretely?

2010-05-02 Thread Steven D'Aprano
ut is * enough to give linear-time amortized behavior over a long * sequence of appends() in the presence of a poorly-performing * system realloc(). * The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ... */ which doesn't look anything like the numbers above. I don't understand w

Re: [Tutor] Is there a better way to use scientific notation in an equation?

2010-05-02 Thread Steven D'Aprano
change your program to use float instead of int. Also, you have a lot of unnecessary brackets that don't do anything except make it hard to read. This should do it: a = 9e9*float(Q1)*float(Q2)/float(d)**2 -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Steven D'Aprano
towards the beginning), so that the changes only happen in the part of the list you've already seen. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Steven D'Aprano
rovide a stable sort method. Failure to be stable would count as a bug, and not a quality of implementation issue. Python the language promises that files will be automatically closed at some point after you have finished with them. That is a language feature. Exactly when this happens is

Re: [Tutor] portability of pickle and shelve across platforms and different python versions?

2010-05-06 Thread Steven D'Aprano
ing. Similarly if your class has a __setstate__ method which does something stupid. Python is a "consenting adults" language: if you want to shoot yourself in the foot by writing broken code, Python doesn't try to stop you. But for built-ins, with the possible exception of floats de

Re: [Tutor] Newbie & Unittest ...

2010-05-06 Thread Steven D'Aprano
TestFLAC(TestMP3): filename = 'data/lossless/01 - Christmas Waltz.flac' filetype = FLACFile def test_lossless(self): raw = open('raw sounds.wav', 'r').read() data = self.file.convert_to_wav() self.assertEquals(raw, data) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Newbie & Unittest ...

2010-05-06 Thread Steven D'Aprano
uld double check your results, e.g. sometimes I will add a test I know will fail, just to make sure that the framework will see it. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] List comprehension + lambdas - strange behaviour

2010-05-07 Thread Steven D'Aprano
reuse its memory. This is why destructors (__del__ methods) don't necessarily run when you expect them to. >>> class Example: ... def __del__(self): ... print "Goodbye!" ... >>> x = Example() >>> mylist = [x] >>> del x >>> mylist[0] = None Goodbye! Hope this helps, -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] An interesting situation befalls me

2010-05-08 Thread Steven D'Aprano
/learnpythonthehardway.com/index -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] reading binary file on windows and linux

2010-05-09 Thread Steven D'Aprano
(sys.argv[1]) as source: You're opening the file in text mode. On Linux, there's no difference, but on Windows, it will do strange things to the end of lines. You need to open the file in binary mode: open(sys.argv[1], 'rb') -- Steven D'Aprano _

Re: [Tutor] displaying clock and/or elapsed time

2010-05-11 Thread Steven D'Aprano
work took 0.015870 seconds See the documentation for the time module: http://docs.python.org/library/time.html That's a bit technical and newbie-unfriendly, so you might also like to read this: http://effbot.org/librarybook/time.htm although it's very old and parts of it are

Re: [Tutor] (no subject)

2010-05-12 Thread Steven D'Aprano
read. > but that's just MHO. The trick is not to top post, or bottom post, but in-line posting after trimming the quotes to remove extraneous and unnecessary text, while still leaving sufficient text to give context. -- Steven D'Aprano __

Re: [Tutor] Find Elements in List That Equal A Specific Value

2010-05-12 Thread Steven D'Aprano
list2, value): elements = [list1[i] for (i,x) in enumerate(list2) if x in list3] return sum(elements) And now call it in a loop: sums = [] for value in list3: sums.append(extract_and_sum(list1, list2, value)) And you are done. -- Steven D'Aprano _

Re: [Tutor] Help

2010-05-14 Thread Steven D'Aprano
text = open('test.fa', 'r').read() # includes newlines text = text.replace('\n', '') # remove newlines To get the characters 7 to 11 inclusive "TTCAC", you have to remember that Python starts counting at 0, not 1, an

Re: [Tutor] Learning python using Michael Dawson's book

2010-05-17 Thread Steven D'Aprano
; "block lettering" created by dashes and vertical lines. If I could > show a picture of it I would. Why don't you copy and paste it? > I do not get the same result as the book. What result do you get? What result do you expect? -- Steven D'Aprano

Re: [Tutor] Question about packaging with distutils (specifying metadata)

2010-05-17 Thread Steven D'Aprano
But with that proviso, there's nothing wrong with importing your own modulo to access the metadata. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Different between pass & continue

2010-05-18 Thread Steven D'Aprano
again 3 3 again >>> >>> >>> for x in (1,2,3): ... print(x) ... continue ... print(x, "again") ... 1 2 3 >>> >>> >>> for x in (1,2,3): ... print(x) ... break ... print(x, "again") ... 1 >>&

Re: [Tutor] what is wrong with this syntax?

2010-05-18 Thread Steven D'Aprano
you've written makes no sense to the Python compiler. It also tells you that the error has nothing to do with either of the print lines. Unfortunately Python isn't smart enough to recognise that the problem is with "the" rather than &q

Re: [Tutor] what is wrong with this syntax?

2010-05-18 Thread Steven D'Aprano
or: get second field put it before third field go to last card of next background -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-22 Thread Steven D'Aprano
you seem to assume a 5 always rounds up... That's how I was taught to do rounding in school too. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-22 Thread Steven D'Aprano
;> d * 3 == 1 False If you care about representing fractions exactly, use the fraction module, not decimal. >>> from fractions import Fraction >>> f = Fraction(1, 3) >>> f * 3 == 1 True -- Steven D'Aprano ___ Tuto

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-22 Thread Steven D'Aprano
On Sun, 23 May 2010 12:19:07 am Wayne Werner wrote: > On Sat, May 22, 2010 at 7:32 AM, Steven D'Aprano wrote: > > Why do people keep recommending Decimal? Decimals suffer from the > > exact same issues as floats, > > This is exactly incorrect! The Decimal operator offe

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-23 Thread Steven D'Aprano
On Mon, 24 May 2010 03:06:28 am Wayne Werner wrote: > On Sat, May 22, 2010 at 9:58 AM, Steven D'Aprano wrote: > > On Sun, 23 May 2010 12:19:07 am Wayne Werner wrote: > > > On Sat, May 22, 2010 at 7:32 AM, Steven D'Aprano > > > > wrote: > > > &g

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Steven D'Aprano
can't trust it to do *anything*. (If d.keys() and d.values() are buggy, how do you know that zip() or d.items() aren't buggy too?) The exception to this is if you are handling non-dict mappings that don't make promises about keeping d.keys() and d.values() aligned in

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-27 Thread Steven D'Aprano
te that instead, just in case." Yes, I suppose that there are buggy Python implementations where x+2 doesn't work correctly but 1+x+1 does, and there might be stupid data types that are the same, but do you really need to support such badly-

Re: [Tutor] copy directory from one part to another and preserve permissions

2010-05-27 Thread Steven D'Aprano
oughly. You might want to wrap the call to rmtree in a try...except block in case path_to_new_files doesn't exist. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] list of dicts <-> dict of lists?

2010-05-28 Thread Steven D'Aprano
awfully harsh, but perhaps he was having a bad day. I've come to understand the semantics of the global statement better, and can see that unnecessary global declarations goes against the purpose and meaning of the statement. I was, in short, cargo-cult programming, using global

Re: [Tutor] class methods: using class vars as args?

2010-05-28 Thread Steven D'Aprano
r): return True instead of None. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] class methods as static methods?

2010-05-29 Thread Steven D'Aprano
an instance C().method(x). You might also be interested in what I call "dualmethod", which passes the class as first argument if you call it from the class, and the instance if you call it from the instance: http://code.activestate.com/recipes/577030-dualmethod-descriptor/ --

Re: [Tutor] SENTINEL, & more

2010-05-29 Thread Steven D'Aprano
d.title: print "Title: %s" % record.title if record.author: print "Author: %s" % record.author If you want to distinguish between unknown and no author, the obvious solution is to pass "?" as unknown and "" for no author. -- Steve

Re: [Tutor] Generating Birthdays

2010-06-01 Thread Steven D'Aprano
ose a random number between 1 and 365, then find out which date of the year (month and day) that is. You can't do that because you have to use lists. So what would you do instead? -- Steven D'Aprano ___ Tutor maillist - Tutor@python

Re: [Tutor] OOP clarification needed

2010-06-01 Thread Steven D'Aprano
not supplied. In the body of the function, this function or class is called, to produce a value which is then named "win". Judging by the default value and the name of the inner variable, I would say it is expected to produce a window object, so any function or class that returns a win

Re: [Tutor] parse text file

2010-06-01 Thread Steven D'Aprano
file in text mode. I'm pretty sure that is not going to work well. Try passing 'rb' as the mode instead. > try: > all_data = input_file.read() > print str(len(all_data)) You don't need to call str() before calling print. print is

Re: [Tutor] parse text file

2010-06-02 Thread Steven D'Aprano
z2', 'w') # create a temporary file >>> x.write("some data") >>> x.close() >>> input_file = bz2.BZ2File('test.bz2', 'r') # open it >>> print len(input_file) Traceback (most recent call last): File "",

Re: [Tutor] parse text file

2010-06-03 Thread Steven D'Aprano
sful test of the hypothesis. Assuming this is the problem you are having, you have a number of possible solutions: (1) Re-create the bz2 file from a single stream. (2) Use another application to expand the bz2 file and then read directly from

Re: [Tutor] Fw: Misc question about scoping

2010-06-03 Thread Steven D'Aprano
ince the very earliest days, which is *at least* 1991, while list comprehensions are a newcomer. But if you insist on a list comprehension, you can re-write the above for-loop as: L = [o.someOtherAttribute for o in a if o.someAttribute > someConstant] -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Misc question about scoping

2010-06-03 Thread Steven D'Aprano
ng a simple assignment, nearly as bad as writing this: if len(mystring) == 0: n = 0 else: n = len(mystring) instead of just n = len(mystring) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] From SQL Blobs to Python Buffers to Actual Files

2010-06-03 Thread Steven D'Aprano
o look exactly like random binary characters, in other words, gibberish, so what makes you think this is not working perfectly? What do you get if you print the binary blob, and what do you expect to get? -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] From SQL Blobs to Python Buffers to Actual Files

2010-06-04 Thread Steven D'Aprano
. The database could be doing *anything* to it -- it could be compressing it, or encoding it in some way, who knows? You have to convert the data back into RTF before writing it. This almost certainly isn't a Python problem, but a database problem. Consult your database documentation, and g

Re: [Tutor] backreferences - \0

2010-06-06 Thread Steven D'Aprano
rge regexes: >>> re.sub('(one)', 'only \\1', s) 'only one' or better, use the raw string syntax so Python doesn't interpret backslashes specially: >>> re.sub('(one)', r'only \1', s) 'only one' -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] a class query

2010-06-07 Thread Steven D'Aprano
ss you directly or indirectly inherit from object. If you inherit from nothing, it is an old-style class regardless of whether you say class Name: pass or class Name(): pass In Python 3.x, there are no old-style classes. > Going forward into the 2.7/3.x world, is there a preferred style?

Re: [Tutor] a class query

2010-06-07 Thread Steven D'Aprano
exist any longer. > In other words, it seems that the following are now equivalent: > > class Name: > > -AND- > > class Name( object ): Only in Python 3.x. > My impression was the "class Name:" style created an old style class. Only in Python 2.x (and 1.x, bu

Re: [Tutor] no. of references

2010-06-08 Thread Steven D'Aprano
'b': [1, 2, 4], 'd': <__main__.C instance at 0xb7f6008c>, 'gc': , '__builtins__': , 'C': , '__name__': '__main__', '__doc__': None}] So gc says two objects *directly* refer to the list: the tuple, and glo

Re: [Tutor] Tkinter - master attribute

2010-06-08 Thread Steven D'Aprano
her widgets, which are called slaves. You can think of a geometry manager as taking control of the master widget, and deciding what will be displayed within. I suppose you could say that master and slave widgets could be named parent and child widgets instead. -- Steven D'Aprano __

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Steven D'Aprano
oelonsoftware.com/articles/fog000319.html > Seems to work... You say that now, but one day you will use it on a list of 100,000 items, and you'll wonder why it takes 45 minutes to finish, and curse Python for being slow. -- Steven D'Aprano _

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Steven D'Aprano
On Sat, 12 Jun 2010 02:18:52 am Hugo Arts wrote: > On 11 jun 2010, at 17:49, Steven D'Aprano wrote: > > On Sat, 12 Jun 2010 12:58:19 am Alan Gauld wrote: > >> Have you looked at the count method of lists? > >> > >> Something like: > >> > &g

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Steven D'Aprano
b[3], b[4]? b = a doesn't create a duplicated list, it gives the same list a second name. Watch this: >>> a = [1, 2, 3] >>> b = a >>> b.append("Surprise!") >>> a [1, 2, 3, 'Surprise!'] b and a both refer to the same obj

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Steven D'Aprano
nts if t[1] > 1] It's still has the awful O(N**2) performance, but it is nearly 25% faster (for N=18) by my tests, and is easier to read. And by some happy accident, it keeps the order of the original sorted list: >>> mylist =

Re: [Tutor] Problems with Importing into the Python Shell

2010-06-12 Thread Steven D'Aprano
ery desirable at the best of times!) is virtually impossible. Good luck! However, there is one little ray of sunshine. If you install Pygame, gasp should successfully import it and therefore not try to raise a string exception, and the second error will disappear all on its own. (But who knows how many more little landmines are waiting...) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] lib2to3 fixers

2010-06-12 Thread Steven D'Aprano
ketrans(a, b): try: return string.translate(a, b) except TypeError: return str.translate(a, b) > 2. write a fixer for doing this which I could use. I could`nt find > any good tutorials out there on writing fixers, i`d be grateful if > you could point me to any. Fo

Re: [Tutor] (no subject)

2010-06-13 Thread Steven D'Aprano
"no"] return response.lower() in ["", "y", "yes"] And then put them together in your main program like this: def main(): if ask_id('Would you like an ID?'): x = getid() do_something_with_id(x) print "Continue wor

Re: [Tutor] large file

2010-06-13 Thread Steven D'Aprano
want to call? suffix = suffixes[n] outfile.write(line + suffix(line) + '\n') n = 1 - n # n -> 1, 0, 1, 0, 1, 0, ... outfile.close() infile.close() -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] conventions for establishing and saving default values for variables

2010-06-15 Thread Steven D'Aprano
is simple enough, you can just write your data to the file manually. But honestly, you can't get much simpler than ConfigParser or plistlib. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] conventions for establishing and saving default values for variables

2010-06-16 Thread Steven D'Aprano
On Thu, 17 Jun 2010 03:44:58 am Jeff Johnson wrote: > I will send you my python script that reads and writes to a windows > style .ini file if you want me to. How is your script different from the standard ConfigParser module? -- Steven D&

Re: [Tutor] conventions for establishing and saving default valuesfor variables

2010-06-16 Thread Steven D'Aprano
stem('echo $myenvvar') value 0 but if I turn to another shell (not a subshell) it doesn't exist: [st...@sylar ~]$ echo $myenvvar [st...@sylar ~]$ See also this: http://code.activestate.com/recipes/159462-how-to-set-environment-variables/ So unless I've missed something exceed

Re: [Tutor] How to model objects aimed to persistence?

2010-06-16 Thread Steven D'Aprano
ing of Favo(u)rite, but why have you dropped the E off the end of "favorite"? I'd almost think your keyboard was broken, but no, you have E in Movies and object. Deliberate misspellings in class and variable names will cost you *far* more in debugging time when you

Re: [Tutor] help

2010-06-17 Thread Steven D'Aprano
thing" count = 1 for char in string: count *= 10 import math print "The string has", math.log10(count), "characters." There's probably a shorter way too. -- Steven D'Aprano ___ Tutor maillist - Tutor

Re: [Tutor] collectd application

2010-06-17 Thread Steven D'Aprano
we look forward to you coming back with a better question! -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] sqlite3 select extra characters

2010-06-18 Thread Steven D'Aprano
an a tuple, don't print the tuple: names = c.execute('select names from students') for t in names: name = t[0] # Extract the first item from each tuple. print name Of course you can combine the two lines inside the loop: print t[0] > It seems a shame to have to

Re: [Tutor] Importing files not located on the home directory or standardard library

2010-06-18 Thread Steven D'Aprano
= alpha.something_else(3) and so forth. By the way, __init__.py doesn't have to contain anything, although it can contain code. It just needs to exist. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Question

2010-06-19 Thread Steven D'Aprano
27;ve got the aptitude to be a programmer", it doesn't really fill me with confidence. Perhaps that's something you should keep more to yourself until *after* you've proven you do have the chops? -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Data exchange formats...

2010-06-20 Thread Steven D'Aprano
oneous data? Receiving data from random places on the Internet? You control both machines, right next to each other in the same locked server room guarded by crocodiles, and you have the only key? Depending on how serious your threat model is, the righ

Re: [Tutor] New to this

2010-06-20 Thread Steven D'Aprano
#x27;, 'spam & chips\n', 'spam & spam'] > > > > but if I do it again I get: > >>>> print inp.readlines() > > > > [] > > > > I'm baffled, why is inp now empty? > > I suspect you have hit the end of the file.

Re: [Tutor] split struggle

2010-06-22 Thread Steven D'Aprano
""]: print("Done") else: indexes = [int(k) for k in indexes] print(indexes) for i in indexes: print(lst[i]) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Calling a number's methods

2010-06-23 Thread Steven D'Aprano
ambiguity, e.g. around the `is` operator, or when using dot method access on a literal int or float. I'm sure this wasn't added to Python specifically to allow calling methods on numeric literals. You can use parentheses for that: >>> (1).__str__() '1' This w

Re: [Tutor] Time

2010-06-23 Thread Steven D'Aprano
some big chunk of work took, that's perfectly fine, e.g. if you expect to print something like this: "Processed 1734 records in 8.2 seconds." -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Repeat function until...

2010-06-23 Thread Steven D'Aprano
%s' % host).read() alive = output.find('Reply from') print alive if alive is -1: print '%s \t\t DOWN ' % host else: print '%s \t\t OK' % host -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Repeat function until...

2010-06-23 Thread Steven D'Aprano
On Thu, 24 Jun 2010 04:09:38 am Alan Gauld wrote: > "Steven D'Aprano" wrote > > > The easiest way is to just run forever, and stop when the user > > interrupts it with ctrl-D (or ctrl-Z on Windows): > > I think that would be Ctrl-C on both. > Ctrl-D/Z

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Steven D'Aprano
your code will exit when it reaches the end of the file, or on an un-caught exception. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] finally

2010-06-24 Thread Steven D'Aprano
the loop is to hit it with a hammer (kill it from outside Python), in which case the finally block never gets to run. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] finally

2010-06-24 Thread Steven D'Aprano
*not* wrong to use it (especially if you have to support versions of Python prior to 2.5) but the with statement is the preferred way to do it now. See more information about it here: http://effbot.org/zone/python-with-statement.htm -- Steven D'Aprano __

Re: [Tutor] Confirm that Python 2.6 ftplib does not support Unicode file names? Alternatives?

2010-06-24 Thread Steven D'Aprano
ia.org/wiki/Comparison_of_file_systems These days, if you're a developer on a non-Linux PC who doesn't need to worry about legacy file systems, most file systems you come across will be Unicode and not bytes. It's mostly Linux developers who have

Re: [Tutor] Running external commands from Python

2010-06-25 Thread Steven D'Aprano
to the popen* functions, for times where popen* are too much and system is too little. If all you want is the output (stdout + stderr) of an external command: import commands output = commands.getoutput('ls -l foo*') will do the trick. -- Steven D'Aprano __

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Steven D'Aprano
r more than $40 will cover? Cynical? Who, me? -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Getting an object's attributes

2010-06-26 Thread Steven D'Aprano
some are added dynamically when the instance is initialised, and some are added dynamically later. But they're all added dynamically. Python doesn't track when attributes are added because, in general, it's an unimportant difference. -- Steven D'Aprano

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Steven D'Aprano
ou know. I have no idea. That's why I asked: > > Cynical? Who, me? -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] class questions

2010-06-26 Thread Steven D'Aprano
th.sqrt(x) + math.asin(x**2) Then when you catch an error: try: print func(y) except DomainError: # only catches my own error except ValueError: # catches any other ValueError But both solutions are equally good. Normally you don't want fifty di

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Steven D'Aprano
laden toolbars and try terrifying the user with "your computer is unprotected" warnings -- no wonder the average user can't tell the difference between legitimate anti-malware and trojan horses). On the other hand, it is quite pretty. (Yes, I am speaking from experience. Eve

Re: [Tutor] class questions

2010-06-26 Thread Steven D'Aprano
On Sun, 27 Jun 2010 03:05:16 am Payal wrote: > Thanks a lot for the quick answer. Still some doubts below. > > On Sat, Jun 26, 2010 at 11:07:17PM +1000, Steven D'Aprano wrote: > > The old MRO (Method Resolution Order) is broken for classes using > > multiple inheri

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-27 Thread Steven D'Aprano
On Mon, 28 Jun 2010 03:07:47 am Richard D. Moores wrote: > A "feature" very important to me > is that with Gmail, my mail is just always THERE, with no need to > download it You see your email without downloading it? You don't understand how the Internet works, do you?

Re: [Tutor] capturing error msg in exception

2010-06-27 Thread Steven D'Aprano
t's own after the example looks silly. Re-writing the question to avoid the problem is often awkward, but can be done: [rewritten example] Hello, which of these two are better? (1) lambda x: x+1 (2) def f(x): return x+1 [end rewritten example] Since there is no One Right Answer

Re: [Tutor] TypeError when io.open is used

2010-06-27 Thread Steven D'Aprano
If you provide three: cmd = "UPDATE testtable SET jpeg = %s WHERE testtable_n = %s" cursor.execute(cmd, data1, data2) then Python fills in self and gives an error message that execute takes only three arguments, not four. So you need to read the documentation for execute to find ou

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