Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looking for a module
#5
sed does come with the Linux distros i have used, like Centos, Fedora, Slackware, and Ubuntu. but sed has its limitations. sed (now days) has an option -i that applies the edit to a file in place. i wrote a wrapper (named "sedi") around that which applies the edit to multiple files.

but what i want for python is something that handles files better, writing them back in place safely (write to a temp file, hard link the old file, move the new file), keep original owner and group (when run as root), keep original permissions, and edit multiple files without the edit code needing to know. the edit code would not even need to do an open.

i did this once in C and made it work by having the edit code call a start function, getting a reference as the return value, perform all edits on "one" file, and call a final function. the "magic" was the start function would return multiple times, once for each file, so it was not necessary to code the editing in a function.

i've also done that "magic" as a function to listen for network connections. it would return multiple times, once for each incoming connection.

for the editor, i'm also thinking of a bunch of functions for common editing steps like moving code around. find a location by some means and hold on to that reference. find a block of text by some means (two searches), and move that block to the saved location.

just thinking it over ... such "magic" might be doable as a generator.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
looking for a module - by Skaperen - May-17-2018, 01:10 AM
RE: looking for a module - by snippsat - May-17-2018, 06:23 PM
RE: looking for a module - by ljmetzger - May-17-2018, 08:05 PM
RE: looking for a module - by Gribouillis - May-17-2018, 10:14 PM
RE: looking for a module - by Skaperen - May-18-2018, 02:08 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020