open file on mac
jason.swails at gmail.com
Fri Oct 8 21:40:38 CEST 2010
On Fri, Oct 8, 2010 at 3:39 PM, Jason Swails <jason.swails at gmail.com> wrote:
> On Fri, Oct 8, 2010 at 10:16 AM, tinauser <tinauser at libero.it> wrote:
>> hi, sorry if it is a stupid qustio,but i cannot figure out where's the
>> i've a simpleModule:
>> class Starter:
>> def init(self,num):
> If you want this to execute upon declaring an instance of Starter, rename
> this as __init__.
>> print "hithere!"
>> print "the answer is ",num
>> import sys,os
>> print "path:",sys.path
>> #f = open("/Users/lguerrasio/myfold/initfile.py",'r')
> Try this instead: f = open(os.path.combine('/Users/lguerrasio/myfold',
Gah, stupid. os.path.join, not os.path.combine. I'm down for the golf
> f = open("initfile.py",'r')
>> print "huurray!"
>> except IOError:
>> print "The file does not exist, exiting gracefully"
>> print "This line will always print"
>> The module is located in the same folder of initfile.py
>> now,from terminal I import sys and add to the path the folder /Users/
>> lguerrasio/myfold; the I import the module and execute
> If you had renamed the function __init__ above, all you would have to do
> instance_of_starter = Starter(48)
> Which makes more sense IMO.
> Good luck!
>> on mac I get an error if i do not give the full path of initfile.py
>> (commented out in the code above);
>> on windows i did not have this problem.
>> Am I missing anything?
> Jason M. Swails
> Quantum Theory Project,
> University of Florida
> Ph.D. Graduate Student
Jason M. Swails
Quantum Theory Project,
University of Florida
Ph.D. Graduate Student
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list