Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

python - Pyparsing: How can I parse data and then edit a specific value in a .txt file? -


my data located in .txt file (no, can't change different format) , looks this:

varaiablename = value
= thisvalue
youget = the_idea

here code far (taken examples in pyparsing):

from pyparsing import word, alphas, alphanums, literal, restofline, oneormore, \ empty, suppress, replacewith  input = open("text.txt", "r") src = input.read()  # simple grammar match #define's ident = word(alphas + alphanums + "_") macrodef = ident.setresultsname("name") + "= " + ident.setresultsname("value") + literal("#") + restofline.setresultsname("desc") t,s,e in macrodef.scanstring(src): print t.name,"=", t.value 

so how can tell script edit specific value specific variable?
example:
want change value of variablename, value new_value. variable = (the data want edit).

i should make clear don't want go directly file , change value changing value new_value want parse data, find variable , give new value.

for task not need use special utility or module need reading lines , spliting them in list, first index left , second index right side. if need these values later might want store them in dictionary.

well here simple way, new in python. uncomment lines whit print use debug.

f=open("conf.txt","r") txt=f.read() #all text in txt f.close()  fwrite=open("modified.txt","w") splitedlines = txt.splitlines(): #print splitedlines  line in splitedlines:     #print line     conf = line.split('=')     #conf[0] on left , conf[1] on right     #print conf     if conf[0] == "youget":         #we         conf[1] = "the_super_idea" #the_idea the_super_idea     #join conf whit '=' , write     newline = '='.join(conf)     #print newline     fwrite.write(newline+"\n")  fwrite.close() 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -