Tag Info

Hot answers tagged

7

You can using fstab module. Its documentation here. Example: fstab = Fstab() for entry in fstab.entries: pprint.pprint(entry)


6

I'd use an XML handling tool like xsh: open subtitles.xml ; for /transcript/Item { echo position() ; echo @from '-->' (@from + @duration) ; echo text() ; } Output: 1 1.16 --> 5.84 (Dong-hyuk is coming to see you now.) 2 5.92 --> 6.92 It's cold. 3 9.04 --> 11.92 - Hello. - Hello. 4 12.2 --> 13.96 You're busy as always. 5 ...


4

This will not work because /etc/fstab file doesn't conform to the format the ConfigParser supports. As man 5 fstab indicates, the /etc/fstab file is a whitespace separated file with 6 columns. The Python ConfigParser is a library for Parsing files commonly known as .ini files that, simplified, consist of sections that contain key/value pairs: ...


3

I may be missing something but I don't understand why you are fiddling with grep in the first place. That's what pgrep is for: #!/bin/sh # chkconfig: 123456 90 10 workdir=/usr/local/bin/Foo start() { cd $workdir /usr/bin/python26 $workdir/Bar.py & echo "FooBar started." } stop() { pid=`pgrep -f '/Bar.py$'` echo $pid kill $pid ...


2

I would probably do something like this: # as proposed by csny, only open file quickly (file is closed after with statement) with open('sysctl.conf') as infile: infilelines = infile.readlines() outfile = open('sysctl.conf.new', 'w') replacements = {'Net.ipv4.icmp_echo_ignore_all' :'1', 'Net.ipv4.icmp_echo_ignore_broadcasts' :'1', ...


2

awk '!/EOF/{print $1}' groups.txt|xargs -i groupadd {} If you wanted the name of the group to be e.g. IT (note that most unix/linux systems won't allow upper case names) just change the statement like so: awk '!/EOF/{print $3}' groups.txt|xargs -i groupadd {}


1

Unless you are intending on creating XMonad extensions you shouldn't need much Haskell. Looking through my xmonad.hs almost everything in there is either an import statement (which looks exactly the same as in python), or copied from other configs. So if you start with the default config and fiddle with things you should be fine. If you do need to extend ...


1

Python has pretty sketchy looking xlib support -- e.g this-- so I would not have thought so. However, perusing this list reveals there's a least one, qtile. The arch linux wiki has a bit of an introduction, since there doesn't otherwise appear to be one online (i.e., it will probably be useful to you regardless of whether you use arch or not).


1

Few comments about your code: If you want to easily insert configuration from "replacements" if it doesn't exist, consider iterating each "replacement" over the lines of the file instead of each line of the file over "replacements". This way, if you don't find any replacement key in the lines, construct and write a new configuration line. I would rather ...


1

When you run umask with system it runs in a shell: umask changes the mask of that shell, but the shell then immediately terminates and the change is lost. To change the umask of your Python process, use os.umask(), which will: Set the current numeric umask and return the previous umask. That way the change will be made to your running program, rather ...


1

This is perfectly normal behaviour, but probably not what you intend. The umask 055 settings are there for the duration of the os.system call, so they never change the settings for the Python script, and certainly not for the command called in the next os.system() call. What you should do is something like: import os old_mask = os.umask(055) ...


1

Mind that this is a late response, since someone has offered a bounty on this question. Also note that without reproducing this problem I can't verify if any solution works. I will just suggest a solution here, not provide one. I think you have to set two variables as outlined here, because py3compile needs to know where certain resources are. It looks them ...



Only top voted, non community-wiki answers of a minimum length are eligible