Re: [Tutor] random.choice()

2008-07-01 Thread Cédric Lucantis
1(), foo2()] running foo1 running foo2 ['bar1', 'bar2'] >>> [foo1, foo2] [, ] Do you see the difference now ? In the first case you call the two functions and store their returned value in the list, while in the second you only store the function objects themselves without calling them. You want the second one. -- Cédric Lucantis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] random.choice()

2008-07-01 Thread Cédric Lucantis
r_float_demo()' and 'the result of use_for_integer_demo()'. This explains why the two functions are called. You should rather use function objects like this: # choose a function (note there are no () after the names) func = choice([use_for_float_d

Re: [Tutor] Novice Python Question

2008-07-01 Thread Cédric Lucantis
ind even more in the library reference) : http://docs.python.org/tut/node5.html#SECTION005140000 http://docs.python.org/tut/node7.html#SECTION00710 http://docs.python.org/tut/node7.html#SECTION00750 -- Cédric Lucantis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Cédric Lucantis
= ['airlines-scheduled', 'airport-car-parking'] so you should rather write this (if y is a list too): table[(tuple(x), tuple(y))] += 1 but of course you can also use tuples directly if your lists don't have to be modified: x = ('airlines-scheduled

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Cédric Lucantis
but when I run this, I get the following error on the line: > > if x and y and (x, y) in table: > > TypeError: list objects are unhashable > > where: > > x = ['airlines-scheduled', 'airport-car-parking'] > lists are not hashable because hashing a

Re: [Tutor] destroying windows

2008-06-30 Thread Cédric Lucantis
display the menu self.window1.config(menu=menubar) def change_to_Colour_Picker (self) : self.window1.destroy() display_Colour_Picker_window() -- Cédric Lucantis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Deleting specified files using a python program...help with code?

2008-06-30 Thread Cédric Lucantis
emoved_files = 0 for root, dir, file in ... : ... if confirmation == 'y' : os.remove(filename) removed_files += 1 ... if removed_files : print '%d files removed' % files_removed else : print 'No files found' -- Cédric Lucantis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Create file and input text

2008-06-29 Thread Cédric Lucantis
Le Sunday 29 June 2008 22:32:23 David, vous avez écrit : > Cédric Lucantis wrote: > > Well, you're asking the user to enter -1 after the raw_input, so if the > > file exists your script will just print 'File exists... -1 to quit' and > > open it anyway. See

Re: [Tutor] Create file and input text

2008-06-29 Thread Cédric Lucantis
file exists your script will just print 'File exists... -1 to quit' and open it anyway. See my previous post for a better way of handling it, but in your case you should at least do something like this: filename = raw_input('Enter the filename: ') if os.path.exists(filename): r = raw_input('Warning, file %s exists, overwrite it [y/n] ? ' % filename) if r != 'y' : sys.exit(0) fobj = open(...) -- Cédric Lucantis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Create file and input text

2008-06-29 Thread Cédric Lucantis
th.exists and the open call), so you should rather write it like this: try: fd = os.open(filename, os.O_WRONLY | os.O_EXCL | os.O_CREAT) except IOError, exc: if exc.errno != errno.EEXIST : raise print 'File %s already exists.' % filename fobj = os.fdopen(fd) (but I guess

Re: [Tutor] Deleting specified files using a python program...help with code?

2008-06-29 Thread Cédric Lucantis
for filename in glob.glob(full_pattern) : os.remove(filename) or you can do something similar with the fnmatch module. See http://docs.python.org/lib/module-glob.html http://docs.python.org/lib/module-fnmatch.html -- Cédric Lucantis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to print numbers in scientific notation form?

2008-06-28 Thread Cédric Lucantis
esignate the number of significant digits? %g automatically choose the more readable form. Use %e for that: >>>> '%e' % 1.0 '1.00e+00' and to set the number of significant digits (it seems to only set the number of digits after the comma, so yo

Re: [Tutor] Invoking Python

2008-06-26 Thread Cédric Lucantis
he PATH environment variable by default. You can set it if you want but there are some security problems with this so it's not recommended. Typing the leading './' quickly becomes automatic for unix users. -- Cédric Lucantis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] For Loop question

2008-06-26 Thread Cédric Lucantis
your code is equivalent to: index = 0 while index < len(myList) : myList[index] += 1 index += 1 -- Cédric Lucantis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Hands-on beginner's project?

2008-06-25 Thread Cédric Lucantis
se : return chapter3 def chapter2 () : ... def main () : # Store the 'chapter1' function in 'current_chapter' # without calling it current_chapter = chapter1 while True : # Call the function stored in curren

Re: [Tutor] Hands-on beginner's project?

2008-06-24 Thread Cédric Lucantis
possible from the rest of the program. This makes the maintenance easier and improves reusability. And open source is a sure way to learn a lot and write great softwares :) -- Cédric Lucantis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Hands-on beginner's project?

2008-06-24 Thread Cédric Lucantis
"Cool, you found the Holy Graal - YOU WON!", [] ], [ "go_back", "A troll is in the way", [["fight it", "fight_troll"], ["run away", "start"]] ], [ "fight_troll", "Sorry, it's stronger than you and you die - YOU LOST!", [] ] ] # start the game run() # -- -- Cédric Lucantis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] fibonacci.py task ???

2008-06-24 Thread Cédric Lucantis
I got many tutorial with title *.py(e.g: Fibonacci.py and Password.py), > can you explain me what *.py mean? Thank's for helping me. .py is just the extension for python source files, so you're supposed to copy the example in a file called Fibonacci.py and run

Re: [Tutor] Another Newbie question

2008-06-24 Thread Cédric Lucantis
t, but until i write this: > >>> while a != 0: > > print 'Current Sum:', s > a = int(raw_input('Number?')) > s = s+a > print 'Total Sum =', s > > Oh, man... another error m