[Tutor] __init__.py not working?

2005-07-08 Thread Bernard Lebel
Hello, In my script library, one directory is named rendering. When I try to import a module from this directory, I always get this error: #ImportError: dynamic module does not define init function (initrendering) However, there is an __init__.py file in there, and also the pyc version. All

Re: [Tutor] compiling python files

2005-07-01 Thread Bernard Lebel
That would be the compileall utility: http://www.python.org/doc/2.4.1/lib/module-compileall.html Cheers Bernard On 7/1/05, Johan Geldenhuys [EMAIL PROTECTED] wrote: Hi all, I have python .py files that I want to compile into .pyc files. Is there a easy way of doing this? Thanks,

[Tutor] repr()

2005-06-07 Thread Bernard Lebel
Hello, Possibly I am missing something, but how do you use the repr() function? I type this ultra-simple function: def myFunc(): print 'hello' Then run repr( myFunc ) Wich returns 'function myFunc at 0x009C6630' Okay then I run s = repr( myFunc() ) print s Wich returns 'None' Thanks

Re: [Tutor] repr()

2005-06-07 Thread Bernard Lebel
Ok thanks a lot. The real question is, then, is there a way I can print the code of a function as a string? Something like 'def myFunction: print hello' Thanks Bernard On 6/7/05, Max Noel [EMAIL PROTECTED] wrote: On Jun 7, 2005, at 20:42, Bernard Lebel wrote: repr( myFunc

Re: [Tutor] repr()

2005-06-07 Thread Bernard Lebel
Well, to make a long story short, this is because I use Python through another software, Softimage|XSI, and by design a string is required to pass logic to on-the-fly GUIs. Since XSI implements 3 other languages (ActivePerl, VBScript and JScript), I suppose this was designed that way with

Re: [Tutor] dictionary values in strings

2005-05-19 Thread Bernard Lebel
Indeed, dictionaries don't have a .key attribute. Instead, use: # Get list of values for 'key1' aList = dol[ 'key1' ] This would return the list of values you have assigned to 'key1' in the dictionary. Once you got that list, you can look in the list to find out the index of 'lil1' and return

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-19 Thread Bernard Lebel
Well, that was a nice explanation. Thanks once again Kent! Bernard On 5/16/05, Kent Johnson [EMAIL PROTECTED] wrote: Bernard Lebel wrote: Hi Kent, So if I undestand you right, mapping a function with map() when it is a built-in function will/may be faster than a for loop, but if it's

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-19 Thread Bernard Lebel
That is very interesting John. Thanks! Bernard On 5/19/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Quoting Bernard Lebel [EMAIL PROTECTED]: Well, that was a nice explanation. Thanks once again Kent! There is a nice (not too technical) essay on the running speeds of different

Re: [Tutor] Finding word in file

2005-05-18 Thread Bernard Lebel
Hi Joseph, To answer your last question first, you should use the os.path.exsits() method to see if the path is valid: http://www.python.org/doc/2.4.1/lib/module-os.path.html As for finding a word in a text, I would suggest to write a basic text parser that would work on small files. def

Re: [Tutor] Finding word in file

2005-05-18 Thread Bernard Lebel
( raw_input( 'what word to searh:' ) ) # Call function parseText() # Check if list has at least one element if len( aWords ) 1: print 'Word not found in file' else: print str( len( aWords ) ) + ' instances of our word found in file' Sorry again Bernard On 5/18/05, Bernard Lebel [EMAIL PROTECTED

Re: [Tutor] Lists of files

2005-05-14 Thread Bernard Lebel
Hi William, First, check out the os and os.path modules. It has exactly what you need to handle files and directories. http://www.python.org/doc/2.4.1/lib/module-os.html More specifically: http://www.python.org/doc/2.4.1/lib/os-file-dir.html http://www.python.org/doc/2.4.1/lib/module-os.path.html

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-14 Thread Bernard Lebel
Thanks Alan, that clears things up quite well. Bernard On 5/14/05, Alan Gauld [EMAIL PROTECTED] wrote: So if I undestand you right, mapping a function with map() when it is a built-in function will/may be faster than a for loop, but if it's a custom function (ie. a def one), it will

Re: [Tutor] Why use apply()?

2005-05-13 Thread Bernard Lebel
All right, thank you. Bernard On 5/12/05, Bob Gailer [EMAIL PROTECTED] wrote: At 02:17 PM 5/12/2005, Bernard Lebel wrote: Just a generic question: why one would use apply()? In Learning Python, on page 357, there is an example of generating an instance using apply(): class

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-13 Thread Bernard Lebel
The authors even go as far as saysing, on page 228 (first paragraph) that map() used that way has a performance benefit and is faster than a for loop. Cheers Bernard On 5/13/05, Alan Gauld [EMAIL PROTECTED] wrote: How bizarre. I'm astonished that Lutz/Ascher even show that as a means of

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-13 Thread Bernard Lebel
Hi Kent, So if I undestand you right, mapping a function with map() when it is a built-in function will/may be faster than a for loop, but if it's a custom function (ie. a def one), it will most likely be slower? Thanks Bernard On 5/13/05, Kent Johnson [EMAIL PROTECTED] wrote: Bernard Lebel

[Tutor] Why use apply()?

2005-05-12 Thread Bernard Lebel
Just a generic question: why one would use apply()? In Learning Python, on page 357, there is an example of generating an instance using apply(): class A: def __init__( self, number ): self.number = number a = apply( A, 3 ) What is the benefit of doing this over simply

[Tutor] map() and lambda to change class instance attribute

2005-05-11 Thread Bernard Lebel
Hello, Let say I have several class instances in a list, and these class instances have an attribute named value, whose value is an integer. I would like to know if it is possible to loop over the list of instances to change their value attribute, using a map( ( lambda:...), ... ) type of loop.

Re: [Tutor] map() and lambda to change class instance attribute

2005-05-11 Thread Bernard Lebel
to define a function. Cheers On 5/11/05, Danny Yoo [EMAIL PROTECTED] wrote: On Wed, 11 May 2005, Bernard Lebel wrote: Let say I have several class instances in a list, and these class instances have an attribute named value, whose value is an integer. I would like to know

[Tutor] Else in list comprehension

2005-05-07 Thread Bernard Lebel
Hello, I just started using list comprehensions (loving them!) I know you can add an if statement, but can you put in there an else? I could not find an example of this. Thanks Bernard ___ Tutor maillist - Tutor@python.org

[Tutor] Appending to many lists with list comprehension

2005-05-02 Thread Bernard Lebel
Hello, I have an object, and this object has attributes. These attributes are objects in their own right, and each attribute also have its own attributes. So I loop over the top object, and for each attribute encountered, I want to put in a list two of the attributes of this attribute. Hope it

Re: [Tutor] Dynamically composing a module name

2005-04-19 Thread Bernard Lebel
Hi, The one thing I would try, if I understand what you're after correctly, would be to run a exec command with the module name. modulename = 'myModule' exec 'import ' + modulename Then you can access the module names as any imported module. Cheers Bernard On 4/19/05, Tim Johnson [EMAIL

Re: [Tutor] Re: Class - superclass

2005-04-11 Thread Bernard Lebel
Thanks a lot, now it's clear. Bernard On Apr 8, 2005 3:48 PM, Andrei [EMAIL PROTECTED] wrote: Bernard Lebel wrote on Fri, 8 Apr 2005 15:05:13 -0400: I'm experimenting with basic inheritance concepts, and something that I would assume to work returns an error. class A: ... def

[Tutor] Class - superclass

2005-04-08 Thread Bernard Lebel
Hello, I'm experimenting with basic inheritance concepts, and something that I would assume to work returns an error. class A: ... def __init__( self ): ... self.a = 13 ... class B( A ): # create sub-class of class A ... def __init__( self ): ... self.b = 14

Re: [Tutor] [HELP]how to test properties of a file

2005-04-05 Thread Bernard Lebel
As far as I'm aware, this is very normal. The file is being used by an application, so there is a lock on it. Cheers Bernard On Apr 4, 2005 7:34 PM, Shidai Liu [EMAIL PROTECTED] wrote: I found out in the following situation, it fails to work. Say, 'somefile.csv' is opened by EXCEL,

[Tutor] test

2005-03-31 Thread Bernard Lebel
test! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] What is the best book to start?

2005-03-30 Thread Bernard Lebel
Hoffmann wrote: Hi All, I am starting to studying Python. I have some previous experience with C (beginner level). Could, anyone, please, suggest a good Python book? I have both Learning Python by Lutz Ascher, and Python How to Program by Deitel and others. Are those good books? Thanks. Hoffmann

Re: [Tutor] Basic terminology

2005-02-15 Thread Bernard Lebel
Well, thanks everyone who answered, much clearer now. Bernard Max Noel wrote: In a slightly more generic fashion (everybody started dropping examples), the goal of an integer (euclidian) division (say, a / b) is to express an integer as such: a = b * quotient + remainder Where all the

[Tutor] Queued threads

2005-02-15 Thread Bernard Lebel
Hello, I have already messed a little with simple thread programming, wich took this form: from threading import Thread def mainFunction(): pass Thread( target=mainFunction ).start() Now, I have a list of jobs, each job being a windows bat file that launches an executable and performs a

Re: [Tutor] Queued threads

2005-02-15 Thread Bernard Lebel
expecting to get. On Tue, 15 Feb 2005 20:58:15 -0500, Bernard Lebel [EMAIL PROTECTED] wrote: Hello, I have already messed a little with simple thread programming, wich took this form: from threading import Thread def mainFunction(): pass Thread( target=mainFunction ).start() Now, I have a list

Re: [Tutor] calling an external program

2005-02-13 Thread Bernard Lebel
The os module is the answer. Use chdir() to make the target executable's directory the current directory, and then os.system( 'command' ) to run the actual command. Cheers Bernard Lobster wrote: - I am trying to call up an external program with something like a Shell command - can not find a

Re: [Tutor] How to run a script file

2005-01-05 Thread Bernard Lebel
Thanks everyone who answered, it's sorted now :-D Bernard ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Basic question - How to use a class from a file?

2005-01-02 Thread Bernard Lebel
Hello, An easy one to start the year. Trying to write my first class, already running into problems after 3 lines! :-( So have this little class: class rt: def walk(self): print 'yeah' So if I write this in the Python shell, instantiate rt and call walk(), I get the

<    1   2