473,320 Members | 1,799 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,320 software developers and data experts.

Re: File operations

aditya shukla wrote:
Hello guys

I am trying to search a file say xyz.txt

after searching i get the location of the file in

search_file (containing abspath) ,eg search_file="c:\\abc\\xyz.txt"

now how should i open this file

i can use file=open("c:\\abc\\xyz.txt","rb") but i have to use search_
file

file=open(search_file,"rb")
>
How can this be done?

Thanks in advance.

------------------------------------------------------------------------

--
http://mail.python.org/mailman/listinfo/python-list
Aug 21 '08 #1
2 1218
On Aug 22, 9:33 am, Gary Herron <gher...@islandtraining.comwrote:
aditya shukla wrote:
Hello guys
I am trying to search a file say xyz.txt
after searching i get the location of the file in
search_file (containing abspath) ,eg search_file="c:\\abc\\xyz.txt"
now how should i open this file
i can use file=open("c:\\abc\\xyz.txt","rb") but i have to use search_
file

file=open(search_file,"rb")
and don't use the name of the built-in file function as one of your
own names

and if it's really a text file, don't use "rb", use "r"

Aug 21 '08 #2
John Machin wrote:
and don't use the name of the built-in file function as one of your
own names
"file" is a type, not a function, and has been removed in 3.0.

given that "file" is hardly ever used in properly written Python 2 code
(if you need to check for file-like behaviour in Python 2, check for the
relevant attributes), assigning to "file" is a lot less problematic than
assigning to "len" or "str" or "open" etc.

</F>

Aug 22 '08 #3

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

Similar topics

10
by: Yang Li Ke | last post by:
Hi guys! I have some datas that I must check everytime a visitor comes to my site What is better to do: 1- Read data from a file or 2- Read data from a mysql db Thank you
5
by: Shu-Hsien Sheu | last post by:
Hi, Does the seek method would close the file object after using a for loop? My program looks like this: f = open('somefile', 'r') for lines in f: some operations f.seek(0)
3
by: Peter | last post by:
Hello, Two newbie questions: 1) I have a javascript file with a function in it. From this function I want to access a variable in another javascript file -which is not inside a function. I...
3
by: Scott Brady Drummonds | last post by:
Hello, all, My most recent assignment has me working on a medium- to large-sized Windows-based C++ software project. My background is entirely on UNIX systems, where it appears that most of my...
2
by: Eat_My_Shortz | last post by:
I'm trying to interoperate between file IO operations, on an open file, between unmanaged C++ code and Managed C++, using the .NET framework. Basically, at present, I have a C-style FILE* object,...
11
by: Jeevan | last post by:
Hi, I have some data which I am getting from a socket. I am currently storing the data in an array (so that future reading of the data will be fast as it will be in RAM instead of hard disk)....
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
9
by: Julien Biezemans | last post by:
Hi! Here is the problem: I'd like to restrict local filesystem stream operations to one directory just like a root jail. fopen('/file.bin') would actually open /some/path/file.bin. One goal...
5
by: MC | last post by:
I've been using the ASP.NET ad rotator for some time and have been asked to track the hits and click thrus, The solution that seemed obvious to me was to extend the existing control to record the...
0
by: tabassumpatil | last post by:
Please send the c code for: 1.STACK OPERATIONS : Transfer the names stored in stack s1 to stack s2 and print the contents of stack s2. 2.QUEUE OPERATIONS : Write a program to implement...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.