open file on mac

T

tinauser

hi, sorry if it is a stupid qustio,but i cannot figure out where's the
problem.
i've a simpleModule:
class Starter:
def init(self,num):
print "hithere!"
print "the answer is ",num
import sys,os
print "path:",sys.path


try:
#f = open("/Users/lguerrasio/myfold/initfile.py",'r')
f = open("initfile.py",'r')
f.close()
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
simpleModule.Starter().init(48)

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?
 
A

Andreas Waldenburger

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?

open("initfile.py") opens initfile.py in the current working directory
(if you don't do anything funny, that's location where the interpreter
is started up in). I assume that you somehow start your interpreter
somewhere different on your Mac.

But that's just a guess. I don't know enough about Macs and your
environment(s) to say for sure.

/W
 
E

Emile van Sebille

On 10/8/2010 7:16 AM tinauser said...
hi, sorry if it is a stupid qustio,but i cannot figure out where's the
problem.
i've a simpleModule:
class Starter:
def init(self,num):
print "hithere!"
print "the answer is ",num
import sys,os
print "path:",sys.path


try:
#f = open("/Users/lguerrasio/myfold/initfile.py",'r')
f = open("initfile.py",'r')
f.close()
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

Only guessing here, but try launching python after you cd to the folder
containing initfile.py, then start python ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top