Programming Forums
User Name Password Register

RSS Feed

Thread Tools Display Modes
Old Mar 18th, 2012, 8:09 PM   #1
Join Date: Feb 2012
Posts: 4
Rep Power: 0 kaykav is on a distinguished road

I've been watching you tube tutorials,and came across the usage of modules. How do I properly use ? I'm in python interpreter, imported os, and now I want to read a text file in my home folder. : >>>'/home/kaykav/fileone.txt', 'r') . I looked at examples but could not understand them. Thank you...
kaykav is offline   Reply With Quote
Old Mar 18th, 2012, 9:00 PM   #2
Programming Guru
Sane's Avatar
Join Date: Apr 2005
Location: Google / Kitchener
Posts: 4,154
Rep Power: 16 Sane has a spectacular aura aboutSane has a spectacular aura about
Send a message via MSN to Sane
Re: using

A quote from the Python documentation on

This function is intended for low-level I/O. For normal usage, use the built-in function open().
Here is a link to the correct 'open' (no os module):

I don't know what tutorial you're using, but it sounds pretty terrible. Do some reading on the normal (non-OS) open/read/write. Feel free to ask questions about any examples that you don't understand.
PFO's Folding@Home Team | Sane's Monthly Algorithms Challenges
Rules | How to Post a Question | How to Post Code

Becoming a good programmer requires foresight of your code's execution.
Becoming an excellent programmer requires foresight of your code's modification.
Sane is offline   Reply With Quote
Old Mar 21st, 2012, 5:17 PM   #3
Hobbiest Programmer
Purity_Lake's Avatar
Join Date: May 2011
Location: Ireland
Posts: 131
Rep Power: 5 Purity_Lake is on a distinguished road
Re: using

sane is right, the open() function is the one that you should be using for reading or writing to files among other tasks that the python documentation can tell you

here is an example of the open() function in use:

# open a file and allowing you to write to file 
# (if file doesn't exist python makes one with the name you define)
file = open("hello.txt", 'w')

# you can write into this file by doing the following
file.write("Hello World")
sentence = "Hello Again World"
userInput = raw_input("Input words or numbers:\n")
list = ["Hello", "World", "from", "my", "list"]
for a in list:
   file .write(a)
# that is a few examples of how you can use the open() functions write method

# make sure to close file at the end of execution of your code

# if you want to print whats in a text file you can do the follwing
file = open("new file.txt", 'r')
content =
print content

hope these examples help u
Purity_Lake is offline   Reply With Quote
Old Mar 23rd, 2012, 8:35 AM   #4
Join Date: Feb 2012
Posts: 4
Rep Power: 0 kaykav is on a distinguished road
Re: using

I'll follow-up on your advice...Thank you; we'll talk again...
kaykav is offline   Reply With Quote



« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC