python-fam documentation.
Folks, I am trying to create an app which stares at a file and when the file is altered, the script joins a channel on freenode and reports that the file has been altered. I found a module called python-fam, unfortunately i have been unable to find documentation for it. Can someone please help me ? Thanks, Shriphani Palakodety. -- http://mail.python.org/mailman/listinfo/python-list
Re: Making a small change to a large XML document
Dan Stromberg wrote: > Say I want to take an existing XML document, and change the value="9997" > and value="9998" to two different numbers, without changing any of the > rest of the document - not even changing comments or indentation, if > avoidable. > > What's the best way of doing it in python? > > > > > > > > > My .xml file is full of such beans. > > I've played around with minidom a little in the past, and I'm targetting > python 2.5.1. > > Thanks! Hello, I hope this works: #!/usr/bin/python from BeautifulSoup import BeautifulStoneSoup #If the XML you provided is in a file named 'problem' xml_struc = open('problem','r') soup = BeautifulStoneSoup(xml_struc) list_of_tags = soup.findAll('property') for tag in list_of_tags: if tag['value'] == "9998": tag['value'] = "" #or whatever number you like soup_str = str(soup) f = open('output', 'w') f.write(soup_str) f.close() xml_struc.close() -- http://mail.python.org/mailman/listinfo/python-list
obtaining multiple values from a function.
hello all, If I have a function that loops over a few elements and is expected to throw out a few tuples as the output, then what should I be using in place of return ? Shriphani Palakodety. -- http://mail.python.org/mailman/listinfo/python-list
comparing elements of a list with a string
Hello all, I have a problem here. I have a list named list_of_files which contains filenames with their timestamps attached to the name. If I have a string "fstab", and I want to list out the files in whose names the word fstab appears should I go about like this : def listAllbackups(file): list_of_files = os.listdir("/home/shriphani/backupdir") for element in list_of_files: if element.find(file) != -1: date = ### time = return (date, time) The major trouble is that the return statement causes it to exit after attempt one. How do I use the yield statement here? Regards, Shriphani Palakodety -- http://mail.python.org/mailman/listinfo/python-list
Re: comparing elements of a list with a string
Hello, Would that mean that if I wanted to append all the (date, time) tuples to a list, I should do something like: for file in list_of_backup_files: some_list.append(file) By the way I did this: def listAllbackups(filename): list_of_backups = glob(home+'/Desktop/backupdir/*%s*'%filename) for element in list_of_back: if element.find(file) != -1: date_components = element.split('-')[-4:-1] date = str(date_components[0]) + ":" + str(date_components[1]) + ":" + str(date_components[2]) time = element.split('-')[-1] yield (date, time) print listAllbackups('fstab') I ran it in the terminal and I got: Why does it do that and not just print out all the values of (date, time) Regards, Shriphani Palakodety -- http://mail.python.org/mailman/listinfo/python-list
Re: True of False
[EMAIL PROTECTED] wrote: > I tried writing a true and false If statement and didn't get > anything? I read some previous posts, but I must be missing > something. I just tried something easy: > > a = ["a", "b", "c", "d", "e", "f"] > > if "c" in a == True: > Print "Yes" > > When I run this, it runs, but nothing prints. What am I doing wrong? > Thanks. > > Kou Hello, Just try : a = ["a","b","c","d","e","f"] if "c" in a: print "yes" That is going to work as the statement '"c" in a' itself is true. You could try that by typing "c" in a at the interpreter. regards, Shriphani Palakodety -- http://mail.python.org/mailman/listinfo/python-list
Editing particular lines of a text file.
Hello all, I am trying to create a script that looks at specific strings in a file like: msgid "I am a disco dancer." and compares the part in quotes to the keys in a dictionary, finds the value and creates a new line right after this string in the file. I have planned to write this as follows: 1. Open the file in read mode 2. parse each line to figure out which line contains "msgid" and use the shlex module's split method to go and split this line and pick the 2nd element list[1]. 3. find the value from the dictionary corresponding to the above element. 4. Insert the line. This part is where I face a problem. How do I plainly edit just one line. I would also like to look at some sample code that does this. 5. open a new file and write the new file with the inserted strings to it. 6. close both files opened. Regards, Shriphani Palakodety -- http://mail.python.org/mailman/listinfo/python-list
Last value of yield statement
Hello all, Let us say I have a function like this: def efficientFiller(file): worthless_list = [] pot_file = open(file,'r') pot_file_text = pot_file.readlines() for line in pot_file_text: if line.find("msgid") != -1: message_id = shlex.split(line)[1] if message_id in dictionary: number = pot_file_text.index(line) corresponding_crap = dictionary.get(message_id) final_string = 'msgstr' + " " + '"' + corresponding_crap + '"' + '\n' pot_file_text[number+1] = final_string yield pot_file_text efficient_filler = efficientFiller("libexo-0.3.pot") new_list = list(efficient_filler) print new_list I want to plainly get the last value the yield statement generates. How can I go about doing this please? Regards, Shriphani Palakodety -- http://mail.python.org/mailman/listinfo/python-list
Re: Last value of yield statement
On Oct 10, 3:34 pm, Dustan <[EMAIL PROTECTED]> wrote: > On Oct 10, 5:19 am, Shriphani <[EMAIL PROTECTED]> wrote: > > > Hello all, > > > Let us say I have a function like this: > > > def efficientFiller(file): > > Note that you are shadowing the built-in variable 'file' here. Better > use 'filename', or something to that effect. > > > > > worthless_list = [] > > pot_file = open(file,'r') > > pot_file_text = pot_file.readlines() > > for line in pot_file_text: > > if line.find("msgid") != -1: > > message_id = shlex.split(line)[1] > > if message_id in dictionary: > > number = pot_file_text.index(line) > > corresponding_crap = > > dictionary.get(message_id) > > final_string = 'msgstr' + " " + '"' + > > corresponding_crap + '"' + '\n' > > pot_file_text[number+1] = final_string > > yield pot_file_text > > > efficient_filler = efficientFiller("libexo-0.3.pot") > > new_list = list(efficient_filler) > > print new_list > > > I want to plainly get the last value the yield statement generates. > > How can I go about doing this please? > > > Regards, > > Shriphani Palakodety > > efficient_filler = efficientFiller("libexo-0.3.pot") > new_list = list(efficient_filler) > last_value = new_list[-1] > print last_value > > # OR > > efficient_filler = efficientFiller("libexo-0.3.pot") > for last_value in efficient_filler: pass > print last_value > > The latter assumes that the last value is the only value you want. Hello again, Well the basic trouble is that the yield statement you see there causes it to print the list over and over again when a string containing "msgid" is found and the subsequent conditions are satisfied. I just want the last list the yield statement generates. I don't want the last element of the list generated. just the last statement. Regards, Shriphani Palakodety -- http://mail.python.org/mailman/listinfo/python-list
Re: Last value of yield statement
On Oct 10, 4:05 pm, John Machin <[EMAIL PROTECTED]> wrote: > On 10/10/2007 8:19 PM, Shriphani wrote: > > > > > Hello all, > > > Let us say I have a function like this: > > > def efficientFiller(file): > > worthless_list = [] > > pot_file = open(file,'r') > > pot_file_text = pot_file.readlines() > > for line in pot_file_text: > > if line.find("msgid") != -1: > > message_id = shlex.split(line)[1] > > if message_id in dictionary: > > number = pot_file_text.index(line) > > corresponding_crap = > > dictionary.get(message_id) > > final_string = 'msgstr' + " " + '"' + > > corresponding_crap + '"' + '\n' > > pot_file_text[number+1] = final_string > > yield pot_file_text > > > efficient_filler = efficientFiller("libexo-0.3.pot") > > new_list = list(efficient_filler) > > print new_list > > > I want to plainly get the last value the yield statement generates. > > How can I go about doing this please? > > I don't think that 'efficient' and 'plainly' mean what you think they > mean. However to answer your question: > > new_list[-1] if new_list else None > > BTW I get the impression that the yield statement yields the whole > pot_file_text list each time, so that new_list will be a list of lists; > is that intentional? Hello again, I am sorry for having made that extra post and should have seen that the solution I wanted was posted here. Anyway thanks a lot Regards, Shriphani Palakodety -- http://mail.python.org/mailman/listinfo/python-list
gdbm troubles.
dictionary = gdbm.open('dictionary','c') dictionary['Ellipsize'] = 'Openbox' dictionary.get('Ellipsize') the last line generates an attribute error. Can someone tell me what I am doing wrong? Regards, Shriphani Palakodety -- http://mail.python.org/mailman/listinfo/python-list
Trouble with for loop
Hello, I want to try something like: for (a, b, c, d, e, f) in [1, 2, 3, 4, 5, 6, 7, 8, 9]: When I do that I get an error: TypeError: unpack non-sequence My main intention is to state that each of the variables namely a, b, c, ## can take value from 1 to 9. How do I go about this ? Regards, Shriphani Palakodety -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble with for loop
On Nov 6, 3:09 pm, Ant <[EMAIL PROTECTED]> wrote: > On Nov 6, 9:59 am, Shriphani <[EMAIL PROTECTED]> wrote: > ... > > > My main intention is to state that each of the variables namely a, b, > > c, ## can take value from 1 to 9. > > How do I go about this ? > > It sounds like you are after something like: > > for var in (a, b, c, d, e, f): >assert var in [1, 2, 3, 4, 5, 6, 7, 8, 9] > > but it's hard to tell without some more information from you on > exactly what you are trying to achieve. I want to obtain a number whose first digit "a" is divisible by 1, 10*b +a is divisible by 2, 10^2*c + 10b + a is divisible by 3 and so on. I hope my question is a bit clearer now. Thanks, Shriphani Palakodety -- http://mail.python.org/mailman/listinfo/python-list
pdf library.
Hi, I am looking for a pdf library that will give me a list of pages where new chapters start. Can someone point me to such a module ? Regards, Shriphani P. -- http://mail.python.org/mailman/listinfo/python-list
Re: pdf library.
On Dec 30 2007, 5:08 am, Waldemar Osuch <[EMAIL PROTECTED]> wrote: > On Dec 29, 11:54 am,Shriphani<[EMAIL PROTECTED]> wrote: > > > Hi, > > I am looking for a pdf library that will give me a list of pages where > > new chapters start. Can someone point me to such a module ? > > Regards, > >ShriphaniP. > > pyPdf may help you with that:http://pybrary.net/pyPdf/ I tried pyPdf for this and decided to get the pagelinks. The trouble is that I don't know how to determine whether a particular page is the first page of a chapter. Can someone tell me how to do this ? -- http://mail.python.org/mailman/listinfo/python-list
Re: pdf library.
On Jan 1, 4:28 pm, Piet van Oostrum <[EMAIL PROTECTED]> wrote: > >>>>>Shriphani<[EMAIL PROTECTED]> (S) wrote: > >S> I tried pyPdf for this and decided to get the pagelinks. The trouble > >S> is that I don't know how to determine whether a particular page is the > >S> first page of a chapter. Can someone tell me how to do this ? > > AFAIK PDF doesn't have the concept of "Chapter". If the document has an > outline, you could try to use the first level of that hierarchy as the > chapter starting points. But you don't have a guarantee that they really > are chapters. > -- > Piet van Oostrum <[EMAIL PROTECTED]> > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: [EMAIL PROTECTED] How would a pdf to html conversion work ? I've seen Google's search engine do it loads of times. Just that running a 500odd page ebook through one of those scripts might not be such a good idea. -- http://mail.python.org/mailman/listinfo/python-list
Re: pdf library.
On Jan 1, 5:38 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Tue, 01 Jan 2008 04:21:29 -0800,Shriphaniwrote: > > On Jan 1, 4:28 pm, Piet van Oostrum <[EMAIL PROTECTED]> wrote: > >> >>>>>Shriphani<[EMAIL PROTECTED]> (S) wrote: > >> >S> I tried pyPdf for this and decided to get the pagelinks. The trouble > >> >S> is that I don't know how to determine whether a particular page is the > >> >S> first page of a chapter. Can someone tell me how to do this ? > > >> AFAIK PDF doesn't have the concept of "Chapter". If the document has an > >> outline, you could try to use the first level of that hierarchy as the > >> chapter starting points. But you don't have a guarantee that they really > >> are chapters. > > > How would a pdf to html conversion work ? I've seen Google's search > > engine do it loads of times. Just that running a 500odd page ebook > > through one of those scripts might not be such a good idea. > > Heuristics? Neither PDF nor HTML know "chapters". So it might be > guesswork or just in your head. > > Ciao, > Marc 'BlackJack' Rintsch I could parse the html and check for the words "unit" or "chapter" at the beginning of a page. I am using pdftohtml on Debian and it seems to be generating the html versions of pdfs quite fast. I am yet to run a 500 page pdf through it though. Regards, Shriphani -- http://mail.python.org/mailman/listinfo/python-list
Parsing links within a html file.
Hello, I have a html file over here by the name guide_ind.html and it contains links to other html files like guides.html#outline . How do I point BeautifulSoup (I want to use this module) to guides.html#outline ? Thanks Shriphani P. -- http://mail.python.org/mailman/listinfo/python-list
SPOJ, Problem Code: sumtrian, Reducing time taken to solve.
Hi, I was trying to solve the sumtrian problem in the SPOJ problem set ( https://www.spoj.pl/problems/SUMTRIAN/ ) and this is the solution I submitted: http://pastebin.ca/1035867 The result was, "Your solution from 2008-06-01 15:13:06 to problem SUMTRIAN, written in Python, has exceeded the allowed time limit." I suspect that the first portion of my solution which looks at the input, figures out the number of triangles and forms a list that contains lists containing each row of the triangle, is wrong. I am not too sure how to optimize it. I would appreciate help. Thanks, Shriphani Palakodety -- http://mail.python.org/mailman/listinfo/python-list