473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Opening a file in Python using windows.

On 3 Dec 2004 08:38:37 -0800, ed <ed******@yahoo.com> wrote:
I do have permission toa ccess the file as that file is careted and read my me.
I have read/write access to that location. regards


That shouldn't be really hard. :)
okay imagine you have a file called test.txt in C:\Python24\
now go to the IDLE prompt if you have one or just use Python prompt.
I am assuming you know what they are & how to do them. :) If you don't
then go read some books. :)

There are two basic in-built operations to open a file.
The first one is open & the the obvious other one is called file.
file is just an alias for open.

type these lines in the prompt
open("C:\\Python24\\test.txt",'r').readlines() ['This is test file. :)']

So thats there.. the whole file in a line :).. However remember that
it returns a list for further processing if you want to or just forget
it. if you break up those above line into 2 lines then they become
test = open("C:\\Python24\\test.txt",'r') # read-only
test.readlines()
['This is test file. :)']

So there you have it. The power of Python. The first line opens a file
object & places
the output at certain address in the computer memory & test
*references* that address. The second line (test.readlines()) reads
the actuall stream of bytes from that location. :)
If you do not have permission to access the files, switching to a
different language will not help you. You need to determine the cause
of your access errors first.


Agreed but the OP does have permission so this assumption doesn't hold!

[snip]
--
cheers,
Ishwor Gurung
Jul 18 '05 #1
0 994

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: news.west.cox.net | last post by:
I want to check a directory, see if there are any files in it... then open each one and do something. I have this... files = os.listdir('/direcory') if len(files) > 0: for file in files: f1...
1
by: Alfons | last post by:
Hello, I have build a program that can do file transferring between a Windows XP computer and a DOS computer via a serial port. The Windows program I have build in C++ with Visual Studio 6.0....
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
1
by: Westbrook, Christopher L (WESTBCL04) | last post by:
I am having some trouble, and I can't figure out why. I'm trying to use the simple keylogger project from source forge, and then create a web interface to open the resulting files, so people from...
8
by: Claudio Grondi | last post by:
Here an example of what I mean (Python 2.4.2, IDLE 1.1.2, Windows XP SP2, NTFS file system, 80 GByte large file): Traceback (most recent call last): File "<pyshell#1>", line 1, in -toplevel-...
5
by: jkn | last post by:
Hi all Python 2.4.2 (#1, Apr 26 2006, 23:35:31) on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "<stdin>", line 1, in...
2
by: Craig | last post by:
Hi there, I'm trying to open colour BMPs using PIL and I'm getting the following errors. Opening a 16 colour BMP I get: Traceback (most recent call last): File "<pyshell#3>", line 1, in...
1
by: gangs | last post by:
I need to know how can I open a file which is named using UTF-16 encoding in unicode. I am desperately trying to open the file using the wofstream typedef, but even it takes the parameter as const...
34
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.