473,772 Members | 3,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

extending file?

Hello all,

Are there any docs or examples of extending the file type? I work
with EDI messages that are very like text files, just with a few
quirks. ;-) and I was wondering if I could strech and twist the built
in file type to make things a bit faster and more full featured.

Specifically I would need to alter the iterator and ideally the line terminitor.

Chris
--
<a href="http://spreadfirefox.c om/community/?q=affiliates&i d=0&t=1">Get
Firefox!</a>
Jul 18 '05 #1
2 1346
Chris Cioffi wrote:
Are there any docs or examples of extending the file type? I work
with EDI messages that are very like text files, just with a few
quirks. ;-) and I was wondering if I could strech and twist the built
in file type to make things a bit faster and more full featured.


I'm not sure what you want to accomplish here - but one of the nicer aspects
of python is that you don't have to inherit from file when you want to pass
a file-like object to some lib. See the cStringIO module. So if you create
a edi-class that _behaves_ like a file, thats all you need - you then can
pass it to any file-accepting pieco of code.

Is that what you've been asking for?
--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
On Tue, 02 Nov 2004 12:13:34 -0500, Jeremy Jones <za******@bells outh.net> wrote:
<snip the whole thread>

So, with everything being said that's been said, here's are two
questions for myself and for Chris Cioffi:

1. How difficult would it be to modify file.readline() so it would read
until a specific character rather than the standard end of line
character(s) ?
2. What would be the best way to go about the above?

If anyone has any ideas, I think we would both listen with great interest.

Maybe this general idea could give you a way to install your own custom solution
without an app-specific custom mod to file or open:

I'd like to see a file/open hook in sys (or maybe os), so that you could intercept the open
operation for specific file paths registered with the hook. E.g., if it were a
simple directory

sys.filehook['foo.txt'] = MyFileClass # or callable factory

would cause file('foo.txt', mode, kwarg=something ) to look in sys.filehook before going to the normal
file system, and return MyFileClass('fo o.txt', mode, kwarg) instead of the normal file object. (I.e.,
file & open would be extended to accept *args, **kw to pass through to hooks if present)

This would allow passing custom input sequences as file-like objects to programs whose interface
is a file path string, and obviously you could use the file path arg passed through to open/file
to open a real file that you wanted to filter in some way (assuming you temporarily at least
removed the hook, or had an alias to the unhooked open function).

I don't think this would be hard to implement, but I haven't thought it through.
Gotta go vote. And other stuff...

An extension of this idea would be to allow registering patterns like
sys.filehook['*.cfg'] = MyConfigFilter
where a mathing open would pass through the actual matched path.
Regards,
Bengt Richter
Jul 18 '05 #3

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

Similar topics

3
2052
by: Marco Meoni | last post by:
Hi all! I've a problem with a C++ class that has to be included in a python application. One way to do it is Extending and Embedding the Python Interpreter Now i have 2 questions 1) Is there a one-file version of this tutorial? 2) Is there anyone that can help me with this problem? The class is attached. Thanks all. Marco
5
3832
by: vbgunz | last post by:
Hello everyone. I own two books. Learning Python and Python in a nutshell. When cross referencing the two books to try and clarify the ideas behind extending methods and delegates, this is where confusion veered it's ugly head :( Learning Python explains on page 324: Class Interface Techniques (21.3.3 in the ebook) the following is an extender method. ''' #################################### '''
9
5789
by: Fat Elvis | last post by:
I'd like to extend some of my Asp.net pages by using Partial Classes. Example ASP.Net Page: public partial class Admin_Customer : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Data_List(); } }
3
3677
by: katis | last post by:
Hi all :) Is it posible in xsd to change only minOccurs value of element in complex type by extending this type? The problem I'm trying to solve is this: I have two complex types - "TextField" and "FileChooser". Here is definition of "TextField" <xsd:complexType name="TextField">
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9912
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.