Programming :: Python ConfigParser Not Saving Comments?

Jun 16, 2011

I have a lot of scripts in Bash and am 'converting' one of them to Python just to get to know how Python works. Up to now I'm loving it, the feel, the logic, the power, ...

1. I have a template file which will be filled in by a technician, meaning it's filled with comments (#) and variable = value combinations, where the technician needs to fill in the values needed under the section referring to the configuration he's performing. 2. After installing from DVD/ISO, the software RPMs get installed and there is a default configuration file containing variable = value combinations where the values need to be changed to the values indicated in the template file mentioned in 1.

In order to do this I played around (and Googled a lot) with ConfigParser. I can load the template, get whatever value I need, load the configuration file, set the new value to the correct variable and write the file.

I checked that the template and configuration files loaded (open()) contain everything, including comments. However when I write the configuration file all comments get lost.

Here's what I have so far: Class to create a fakesection header since ConfigParser needs sections and the configuration file doesn't have those.

Code:
class FakeSectionHead(object):
def __init__(self, fd):
self.fd = fd

[Code]....

View 3 Replies


ADVERTISEMENT

Programming :: Saving File Data Using Python In An Embedded System In An Safe And Fast Way?

Apr 19, 2011

I am developing a program in a system where the Linux does not take care of the sync command automatically. So I have to run it from my application always I save some data in the disk, which in my case is a 2GB sdcard. It is true that I can make the operation system takes care of the syncronization, using a proper mount option, but in this case the programm's performance drops drastically. In particular I use the shelve module from Python to save data that comes from a socket/TCP connection and I have to deal with the potencial risk of the system being turned off suddenly Initially I wrote something like that to save data using shelve:

Code:

def saveData(vo)
fd = shelve.open( 'fileName' , 'c')
fd[ key ] = vo
fd.close()
os.system("sync")

But that takes too much time to save the data. Note that I use the sync from the OS every time I close a file to prevent data corruption in the case of the "computer" being turned off with data even in the buffer. To improve the performance I made something like that:

Code:

def saveListData( list )
fd = shelve.open('file_name', 'c')
for itemVo in list:
fd[itemVo.key] = itemVo
fd.close()
os.system("sync")

Thus, first I saved an amount of objects in a list then I open the file and save the objects. In this way I have to open the file just one time to save a lot of objects.However I would like to know if adding a lot of objects before closing the file would increase the risk of data corruption.I known that turning off the system after fd.close() and before os.sync may cause problems. But what about turning off the system after

Code:

fd = shelve.open('file_name', 'c')

but before fd.close()?

View 7 Replies View Related

Programming :: Create Doc Comments In Vim Using Pre-typed Text?

Jul 5, 2011

I currently have a set up in vim so that when I type "<leader>ns" it takes any given word and turns it into a sub "sub word(){}". I also have it when I type "<leader>nc" it creates a doc comment section that is "blank". I was wondering if someone could help me out with combining the two so that when I typed <leader>ns it would create the doc comments with the word already in the Subroutine: line and create the new sub routine aswell. I'm trying to understand what I have (downloaded from the internet) and only doing so so.
Code:

" Put cursor over word and hit ,ns to create new Sub
nmap <leader>nc o
#------------------------------------------------------------------------------
# Subroutine:
# Function :

[code]....

View 3 Replies View Related

Ubuntu :: Saving Python Programs - Error Permission Denied

Apr 11, 2010

I wanted to save a python program because I am reading byte of python and I went to save in !/usr/bin. When I try to save in this folder I get this error "[Errno 13] Permission denied: 'usr/bin/helloworld.py'.

View 9 Replies View Related

Programming :: Make Python Programs Run Without Entering The Command Python?

Mar 22, 2009

I want to be able to do

sudo ./program.py

instead of always having to do

sudo python program.py

What do I need to change?

View 5 Replies View Related

Programming :: Python - Get Text File Data Into An Array On Python?

Nov 30, 2009

I've already used line split stuff to transform my data into something like this in a text file:

Code:

['1', '1', '3', '20.7505207']
['2', '1', '3', '23.0488319']
['3', '1', '3', '-1.5768747']
['4', '1', '3', '-26.4772491']

[code]....

How can I get this on a python program so I can manipulate it as an array?

View 3 Replies View Related

Programming :: Python 2.x - Represent The Same In Python 3.x

Mar 4, 2010

I have a function definition in a Python 2.x script which take a tuple as one of its arguments, but 2to3 has no answers nor any of my searching on how to represent the same in Python 3.x

Code:

def blah(self, (string1, string2))

View 4 Replies View Related

Programming :: Totem Python Plugin Programming: Any Signal For Video Mouse Click?

Feb 9, 2011

I want that I click with the mouse on the video, it paused.I notice that there is "BaconVideoWidget" which I guess is the video rendering widget but it don't have signal named "clicked":

Code:
vd = totem_object.get_video_widget()
vd.connect("clicked", vd.hide)

[code]....

View 3 Replies View Related

Programming :: Saving A Certain Variable And Using It In All The Classes?

Feb 4, 2010

facing a problem in declaring variables. i have a few classes like the one below...

Code:
#ifndef _FINANCE_H
#define_FINANCE_H

[code]....

View 1 Replies View Related

Ubuntu :: Saving Current Programming Before Upgrading?

Jun 7, 2011

I am writing this because I want to keep all of the things that I have now on my ubuntu 10.
4 computer and do not want to upgrade until I have some way of keeping all of the things that I currently have on it.Sohow so I make this happen? Should I try to load these program settings on a flash drive?

View 1 Replies View Related

Programming :: Evaluating Bash Script Without Saving ?

Sep 5, 2010

I blame myself but I am lazy person. Now I am trying to learn a bit a bash scripting. But saving any script to see how it works is so boring. You know these exercises:

Code:

Now save this in a file - say helloworld.sh (haha), chmod and execute to see

Code:

Is there a way to execute text as a script? I mean

Code:

View 6 Replies View Related

Programming :: Saving Serializable Object Within It's Own Class

May 12, 2011

I found out how to save an object using Serializable in JAVA, the standard however how can I set up my MainVariableList to have a function/method saveobject so it saves the object within it's own class, the below code compiles, however when I run it reports an error on startup but works, basically what do I use for the red line, how do I tell it what object is passed to the class?

View 1 Replies View Related

Programming :: Mistake With Sed Espression Is Saving Part Of Pattern?

Jan 20, 2010

got a textfile with : as delimiters in between fields. e.g.1:2:3:4:5:6Thomas Cruise:Johnavid:Peter:Betty:JaneThe names may or may not contain white spaces.I am required to substitute any one of these names in the file with a new one inputted by user.e.g. to change John to Johnny, David to Beckham, etc. without touching any of the other names in the same line. Just one at a time.So here's the sed expression I was trying out with:

sed -i "s/<(.:.:)David>/$1Beckham/" names.txt
I also tried:
sed -i "s/<(.*)David>/<1Beckham>/" names.txt

[code]....

View 24 Replies View Related

Fedora :: Print PDF File With Comments

Dec 19, 2010

How can I print a PDF file with comments (and highlights) on Fedora 14?

View 4 Replies View Related

Programming :: Saving A PPM File - Binary Representation Of Unsigned Chars On The Harddrive

Apr 7, 2010

I am accessing a firewire camera using the libdc1394 library and saving the image as a PPM file, using the code below:

[Code].....

My question is whether the above code is portable. I presume it is, since the result is a binary PPM file which should be capable of being read across multiple computers with different architectures and different operating systems. But at the same time, all that the above code is doing is just saving the binary representation of unsigned chars on the harddrive, and there does not seem to be any reason why the binary representations of the unsigned chars will be identical across multiple computers.

View 1 Replies View Related

Programming :: Python 2.x Vs 3.x

Apr 21, 2010

I'm starting to learn python and I am wondering whether I should start with python 2.x or should I just start learning python 3.x?

View 2 Replies View Related

Ubuntu :: Insert Written Comments Into Screen-casting

Aug 12, 2010

I went through recordMyDesktop and xvidcap and I didn't find any possibility how to insert written comments into recorded video.

View 2 Replies View Related

Software :: Excel Files Have Empty Comments In OO.o Calc

Jun 24, 2010

Imported an Excel file into OO.o Calc. EVerything is fine except the comments are all blank. It knows that comments should be there, but they're all empty. how to recover the contents?

View 2 Replies View Related

Software :: Put Vim Indentation Style Comments In A Source File?

Jul 15, 2011

I have seen that it's possible to put special comments in a source file that tell vim what indentation style to use. The problem is that i don't know how to use them, and can't find and tutorials or documeantaion since I have no clue what this feature is called.

View 3 Replies View Related

Programming :: Convert Map From Python 2.x To 3.x

Apr 6, 2010

I have an existing line of code from a P2 script that I cannot find a solution to converting to P3:

Code:
for i, x in map(None, list1, list2):
I have found the information about converting the simple case:
map(None,x) becomes list(x)

But my googling was unable to find a solution when more than one iterable exists.

View 2 Replies View Related

Programming :: How To Run Python Script From C

Jan 31, 2010

I have a python script I wrote a while ago and now I would like to call that script from inside C. I know how to do one command from C, but how would you execute an entire script from C, and passing arguments? Like:

Code:

int main(void)
{
python( myprogram(1 2 3) );
}

So I can pass arguments to my script.

View 3 Replies View Related

Programming :: Py_FindMethod In Python 3.1.1

Jan 19, 2010

what the equivalent function in Python 3.1.1 is for Python 2.6.4s:

Py_FindMethod

Be buggered if I can find anything in the doco to say what replaced it or what alternative code may need to be entered to replace it

View 1 Replies View Related

Programming :: Python With Web Development ?

Dec 17, 2010

I have decided to learn python as it seems to be powerful not just for web development (like php) but also a clean powerful language for other puposes.

Q: Can someone suggest a tutorial or book, on learning python (beginner to intermediate) which has as its focus for learning, web development?

In order of preference: 1. Comprehensive, 2. Online, 3. Free

View 2 Replies View Related

Programming :: Piping In Bash Using Python?

Dec 16, 2010

I have a bash script that I want to import in to Python, mainly just to see if I can or not. However in the script I do use some piping of commands into sed to trim it down to what I need. When I tried doing it with the os.system() call, it didn't work. The exact error is

sed: -e expression #1, char 16: unterminated `s' command

However the command that was run can be run in bash without an error. Is there a better/another way to do this? For reference the command is:

Code:

locate -n 1 wp-config.php | sed 's/wp-config.php/
/g' | sed '/wp-config.php/ d' | sed '/^$/ d'

View 3 Replies View Related

Programming :: Accessing Python Scripts Using Web?

Mar 17, 2011

I am using Centos. I have written some scipts in python that access my routers and fetch the configuration, etc. Now i was thinking of creating a web interface which i can access from my windows XP. I want it to have good look n feel :-),

View 7 Replies View Related

Programming :: C++ Or Python - Create 3D Animation ?

Jan 25, 2009

I want to create 3D animation and also make some big programs. Is python capable of that? or should I stick to C++?

View 3 Replies View Related

Programming :: Linking Options For Python?

Dec 11, 2010

I am trying to build an application that must link with python so as to load a python module during runtime.I have this makefile :

Code:
[alex@iskandhar src]$ cat Makefile
CFLAGS = -Wall -O3 -I ../../../SPOOLES.2.2 -DARCH="Linux" -DSPOOLES -DARPACK

[code]....

View 4 Replies View Related

Programming :: List Sorting In Python?

May 10, 2011

I have a list of list and I'd like to sort the list according to the last value of each row.

Let's say we have the list

L1 = [ [1,2] , [4,6] , [78,-3] ]

I wish to get

L2 = [ [78,-3] , [1,2] , [4,6] ]

Is there a simple way to do that in python?

View 4 Replies View Related

Programming :: Parsing S-Expressions In Python?

Feb 1, 2011

I've been loosely following this:http://norvig.com/lispy.htmlAnd I have a problem: the parsing function throws an array out of bounds exception. I thought that maybe I'm doing it wrong, so I copy and pasted the code from the page, and still the same error

View 2 Replies View Related

Programming :: Initializing Pmw Megawidgets For Python 2.6

Oct 12, 2010

I am having a problem initializing the Pmw megawidgets for Python 2.6.I have Pmw_1_3 loaded in the site-packages directory.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved