6 Replies - 663 Views - Last Post: 31 March 2011 - 04:20 AM Rate Topic: -----

#1 e-papa  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 45
  • Joined: 17-March 11

Open () function

Posted 26 March 2011 - 07:48 AM

I read about the open function and tried using but it told me the directory or file does not exist, please where am I supposed to put the .txt file,
Thanks in Advance.

By the open function I mean
open()
. Please put me through.
Is This A Good Question/Topic? 0
  • +

Replies To: Open () function

#2 torieLynn  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 5
  • Joined: 23-December 10

Re: Open () function

Posted 26 March 2011 - 08:23 AM

If you want to just type in the nameoffile.txt then the text file needs to be in the same folder as the program. Otherwise you need to have the path to where the file is as well such as Computer/Documents/nameoffile.txt (bad example but you get the idea)

the code would look something like
 fileNm = open("filename.txt") 


let me know if this helps

This post has been edited by torieLynn: 26 March 2011 - 08:24 AM

Was This Post Helpful? 2
  • +
  • -

#3 e-papa  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 45
  • Joined: 17-March 11

Re: Open () function

Posted 26 March 2011 - 08:43 AM

Thanks so much, I tried it and it worked Thanks a million.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6075
  • View blog
  • Posts: 23,540
  • Joined: 23-August 08

Re: Open () function

Posted 26 March 2011 - 10:15 AM

Python manual on Input and Output
Was This Post Helpful? 1
  • +
  • -

#5 e-papa  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 45
  • Joined: 17-March 11

Re: Open () function

Posted 29 March 2011 - 09:41 AM

Thanks will check it out.
Was This Post Helpful? 0
  • +
  • -

#6 EyeballKid  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 14-September 10

Re: Open () function

Posted 30 March 2011 - 02:37 PM

It's probably also helpful to know that a running program has a "current working directory" (CWD). In Windows, this usually defaults to the same directory that contains the program you are running.

In python you can get/set the current directory using calls in the os module, eg:

import os

# show the current directory
print os.getcwd()

# change directories
os.chdir("some/other/place")



Hope this helps!
Was This Post Helpful? 1
  • +
  • -

#7 e-papa  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 45
  • Joined: 17-March 11

Re: Open () function

Posted 31 March 2011 - 04:20 AM

Thanks that is the OS module, really have to read up on that.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1