[Tutor] saving .csv file as an xl worksheet
Hi , Can i save a file with a desired extension?? for ex: I have a .csv file (test.csv) and i want to save this file as test.xls from a python script. Thanx in advance ac ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] source file or installer
what are the benefits of building python from source file? any difference if using installer? Linda ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] after signal handler
Hi, I want to go back after signal handler to the isntruction where I was stuck. Below is the code I'm trying to play with. #!/usr/bin/env python ### Start of code ### import os, signal def handler(signum, frame): print "Signum: ", signum return signal.signal(signal.SIGALRM,handler) signal.alarm(2) # I want to come back here after signal handler raw_input("Enter input: ") signal.alarm(0) # End of code What I'm trying to do is to implement a prompt with the remaining time they have to enter some input. -- Hameed U. Khan Registered Linux User #: 354374 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to get the return value?
Alan Gauld <[EMAIL PROTECTED]> schrijft: > However the real question I have is how you intend to > access that result value. Is it a single value at the end > you want or the cumulative set of values from each > scheduled call? :) Alan, Currently I'm not quite sure what and how I want to do it, so far I've been poking around a bit in the std library to see what options there are to create a sceduling script. Finaly I'd like to be able to have a program do the following, using a "simple" ini_file: for every workingday of a week: from 7.00 until 17.00: every minute: capture a frame and save it at noon: compile a video from the frames gathered this morning do some file manipulations at 17.00: compile a video from the frames gathered this afternoon do some file manipulations on friday 17.00: compile a movie from a selection ( every n_th) of the frames of this week ... The time_lapse function was a first attempt in creating something that starts and stops at a certain time and triggers some actions inbetween. Then I thougth I could use it as the main loop that triggers all the other actions, but then I have to able to change the start and stop times for these from the intial time_lapse loop. Looking at Danny's code, I think a threaded sheduler + shared qeue would be a better approach, but that's something completly new to me. Thanks, Ingo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to get the return value?
Anna Ravenscroft <[EMAIL PROTECTED]> schrijft: > On 3/5/06, ingo <[EMAIL PROTECTED]> wrote: > > > > in news:[EMAIL PROTECTED] Kent Johnson wrote: > > [...] > > >>> > > >>>main(printtime(strf=None)) > > >>> > > >>>[...] > > >> > > >> Anna, > > >> > > >> that results in an syntax error / invalid syntax > > > > > > It's very helpful to show the actual error and traceback. > > > > > > > Sorry, here it is: > > > > File "D:\Ingo\PyScript\VIDEOC~1.9\_ij\_time_lapse.py", line 23 > > def main(printtime(strf=None)): > > ^ > > SyntaxError: invalid syntax > > > > Yep. I was suggesting calling printtime as part of your *call* to main, not > when you define main. Sorry to be unclear. >[...] > Hope that makes more sense. > Ah, that makes more sense, I'll play a bit with it, Thanks, Ingo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to get the return value?
Danny Yoo <[EMAIL PROTECTED]> schrijft: > But since the scheduler runs in a separate loop than the rest of your > program, trying to return a value between the two won't work very well. > > > However, there are other approaches: we can use some kind of shared > container or communication channel between the main() and the scheduler, > so that they can communicate. > > > One possible way they can communicate is with a shared Queue: > > http://www.python.org/doc/lib/module-Queue.html > > Here is an example that may help: > > ## > from sched import scheduler > import time > from Queue import Queue > from threading import Thread > > > s = scheduler(time.time, time.sleep) > q = Queue() > PRIORITY = 1 > > def f(n): > """Pushes n into the queue, and then reschedules itself with > n+1 to run five seconds later""" > q.put(n) > s.enter(5, PRIORITY, f, (n+1,)) > > ## Let's prime things up. We'll set up the scheduler, and then have > ## it run on its own daemon thread. > s.enter(5, PRIORITY, f, (0,)) > t = Thread(target=s.run) > t.setDaemon(True) > t.start() > > ## At this point, our main thread of execution is separate from the > ## scheduler thread t. > while True: > print "Waiting for event on queue." > print q.get() > ## > > > Does this make sense? Not yet completly Danny, I'll have to study it a bit, but from your use of threads I think you have a better understanding of what I want than I have myself. Thanks, Ingo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] curses delwin() functionality
Hello all, Im writing about a topic which was discussed previously on this mailing list but didn't seem to be answered.. Bernd Prager asked whether the curses modules in Python had functionality like that of delwin() in the C libraries. He also supplied the below code sample to demonstrate the problem. (Thanks Bernd) Where he has commented # curses.delwin(s) would be where in C one could close the sub window created in sub() and refresh the underlying scrn. Ive also been unable to find how this is done and any assistance would be appreciated. #!/usr/bin/pythonimport sys, cursesdef sub(scrn):s = curses.newwin(4, 30, 1, 1)s.erase()s.box()s.addstr(1, 1, "sub window")s.refresh()s.getch() # curses.delwin(s) <-- that doesn't exist :-/scrn.refresh()def main(scrn):scrn = curses.initscr()curses.curs_set(0) # turn cursor offscrn.erase()scrn.addstr (2, 2, "press to continue, to quit");while 1:c = scrn.getch()if c == curses.KEY_F12: sys.exit()elif c == curses.KEY_F1: sub(scrn)# main loop if __name__ == '__main__':curses.wrapper(main)sys.exit() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Analysing genetic code (DNA) using python
I have many notepad documents that all contain long chunks of genetic code. They look something like this: atggctaaactgaccaagcgcatgcgtgttatccgcgagaaagttgatgcaaccaaacag tacgacatcaacgaagctatcgcactgctgaaagagctggcgactgctaaattcgtagaa agcgtggacgtagctgttaacctcggcatcgacgctcgtaaatctgaccagaacgtacgt ggtgcaactgtactgccgcacggtactggccgttccgttcgcgtagccgtatttacccaa Basically, I want to design a program using python that can open and read these documents. However, I want them to be read 3 base pairs at a time (to analyse them codon by codon) and find the value that each codon has a value assigned to it. An example of this is below: ** If the three base pairs were UUU the value assigned to it (from the codon value table) would be 0.296 The program has to read all the sequence three pairs at a time, then I want to get all the values for each codon, multiply them together and put them to the power of 1 / the length of the sequence in codons (which is the length of the whole sequence divided by three). However, to make things even more complicated, the notebook sequences are in lowercase and the codon value table is in uppercase, so the sequences need to be converted into uppercase. Also, the Ts in the DNA sequences need to be changed to Us (again to match the codon value table). And finally, before the DNA sequences are read and analysed I need to remove the first 50 codons (i.e. the first 150 letters) and the last 20 codons (the last 60 letters) from the DNA sequence. I've also been having problems ensuring the program reads ALL the sequence 3 letters at a time. I've tried various ways of doing this but keep coming unstuck along the way. Has anyone got any suggestions for how they would tackle this problem? Thanks for any help recieved! -- View this message in context: http://www.nabble.com/Analysing-genetic-code-%28DNA%29-using-python-t1233856.html#a3263717 Sent from the Python - tutor forum at Nabble.com. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Query
Hey,I am currently working on a final year project in college building a 3-D virtual model of a building in a python based program called Vizard. I have prepared a set of tutorials on powerpoint which i would like to access by clicking on various objects in the building. e.g. Click on a Window/Air Duct and then open a powerpoint presentation on the topic. I was wondering if there is python code which will let me launch my powerpoint presentations from with my virtual world.Any help would be greatly appreciatekind regards,Robert Lane Civil and Environmental Engineering IV UCC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] source file or installer
On Mon, 6 Mar 2006, linda.s wrote: > what are the benefits of building python from source file? any > difference if using installer? Hi Linda, If a binary installer is available for your platform, you'll probably want to stick with it. It provides the most convenient way to get Python. Some weird people insist on compiling all the software on their machines (like me *grin*). But the source is also provided so that other people and organizations can build products around Python. The source code can be treated as more than the "product": it can be treated as raw material: other people can refine it as necessary and build whatever they'd like. It turns out that Python.org produces a packaged product --- the binary installer --- but other people have done so too, including the ActiveState company: http://www.activestate.com/Products/ActivePython/ and other people have embedded Python directly into their own projects. (The video game "Freedom Force", for example, has a Python runtime.) So the accessibility of the Python source code makes it easier for some creators to make shiny products. If you are just trying to get Python so you can learn to program Python, the Python source code itself is probably not so useful for you now. I hope this helps! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] after signal handler
On Mon, 6 Mar 2006, Hameed U. Khan wrote: > I want to go back after signal handler to the isntruction where I was > stuck. Below is the code I'm trying to play with. Hi Hameed, Here's a small test program that shows that the signal handling does go back to where we left off: ## import signal import time def handler(signum, frame): print "alarm!" signal.alarm(2) signal.signal(signal.SIGALRM, handler) signal.alarm(2) while True: print "hello" time.sleep(1) ### > What I'm trying to do is to implement a prompt with the remaining time > they have to enter some input. This should be doable. What can we help with? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Query
Rob Lane wrote: > Hey, > > I am currently working on a final year project in college building a 3-D > virtual model of a building in a python based program called Vizard. I > have prepared a set of tutorials on powerpoint which i would like to > access by clicking on various objects in the building. e.g. Click on a > Window/Air Duct and then open a powerpoint presentation on the topic. > > I was wondering if there is python code which will let me launch my > powerpoint presentations from with my virtual world. os.system() will let you execute a command line, for example os.system(r'"C:\Program Files\Microsoft Office\Office\POWERPNT.EXE" F:\Personal\TEACHI~1\TDDINT~1.PPT') Note the use of a raw string to allow \ path separators and the double-quotes around the path to the exe because it has spaces in it. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to get the return value?
> for every workingday of a week: > from 7.00 until 17.00: >every minute: > capture a frame and save it >at noon: > compile a video from the frames gathered this morning > do some file manipulations >at 17.00: > compile a video from the frames gathered this afternoon > do some file manipulations > on friday 17.00: > compile a movie from a selection ( every n_th) of the frames of this > week > ... To be honest I'd do this with a series of separate scripts triggered by the OS - either cron on Unix or at in Windows... Simply save the frames as individually named files, probably using the time... Another script can collect the frames into a video. With suitable choice of argv options you can do all you want with just two scripts. And no need to get caught in the mire of concurrent processing. This follows my motto of keeping things as simple as possible! :-) Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Analysing genetic code (DNA) using python
sjw28 wrote: > I have many notepad documents that all contain long chunks of genetic > code > I've tried various ways of doing this but keep coming unstuck along the > way. Has anyone got any suggestions for how they would tackle this > problem? > Thanks for any help recieved! You really should look at biopython as has been suggested on comp.lang.python. The first example in the quick start guide does most of what you are asking for: http://biopython.org/docs/tutorial/Tutorial003.html#toc5 Alternately you can post what you have tried and what questions you have and we will help you work through them. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Are we the same?
Hi, I just took this test on Tickle.com. To see how I scored, take the test. The Super IQ Test http://web.tickle.com/invite?test=3046&type=t Your score will be shown to me, too. Gavin ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Analysing genetic code (DNA) using python
On 3/6/06, sjw28 <[EMAIL PROTECTED]> wrote: I have many notepad documents that all contain long chunks of geneticcode. They look something like this:atggctaaactgaccaagcgcatgcgtgttatccgcgagaaagttgatgcaaccaaacagtacgacatcaacgaagctatcgcactgctgaaagagctggcgactgctaaattcgtagaa agcgtggacgtagctgttaacctcggcatcgacgctcgtaaatctgaccagaacgtacgtggtgcaactgtactgccgcacggtactggccgttccgttcgcgtagccgtatttacccaaBasically, I want to design a program using python that can open andread these documents. However, I want them to be read 3 base pairs at a time (to analyse them codon by codon) and find the value that eachcodon has a value assigned to it. An example of this is below:** If the three base pairs were UUU the value assigned to it (from the codon value table) would be 0.296The program has to read all the sequence three pairs at a time, then Iwant to get all the values for each codon, multiply them together andput them to the power of 1 / the length of the sequence in codons (which is the length of the whole sequence divided by three).However, to make things even more complicated, the notebook sequencesare in lowercase and the codon value table is in uppercase, so thesequences need to be converted into uppercase. Also, the Ts in the DNA sequences need to be changed to Us (again to match the codon valuetable). And finally, before the DNA sequences are read and analysed Ineed to remove the first 50 codons (i.e. the first 150 letters) and the last 20 codons (the last 60 letters) from the DNA sequence. I've alsobeen having problems ensuring the program reads ALL the sequence 3letters at a time.I've tried various ways of doing this but keep coming unstuck along the way. Has anyone got any suggestions for how they would tackle thisproblem?Thanks for any help recieved! You've got a lot of pieces to your puzzle. I would use f.read() to read all of the file in, then a list comprehension so you get only the codon characters (leaving out the newlines). A simple slicing of the list can give you each codon. something like might get you started: f = open('codons.txt', 'r') s = f.read() l = [c for c in s if c != '\n'] r = len(l) for x in range(0,r,3): y = x+3 codon = l[x:y] print codon f.close() Use ''.join() to make them back into a string. From there, you could do a lookup of the codon string in a dictionary. use the string method s.upper() to uppercase your codon string. Basically, figure out one problem at a time. Once that works, tackle the next problem. Or, use something someone else already wrote for you, like Kent suggests. cordially, Anna ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Analysing genetic code (DNA) using python
> I have many notepad documents that all contain long chunks of genetic > code. They look something like this: > > atggctaaactgaccaagcgcatgcgtgttatccgcgagaaagttgatgcaaccaaacag [data example cut] > Basically, I want to design a program using python that can open and > read these documents. Hello sjw, Ok, let's stop at this point. It sounds like you want to design a function that takes in a string of genetic code, and calculate the "number_I_dont_understand_because_Im_not_a_biologist", or for short, "magical_number". So let's at least start off by writing a template: ## def calculate_magical_number(codon): """calculate_magical_number: string -> number Calculates some magical number given a single codon. """ ## ... [fill me in] ## Let's leave it as that for the moment. > However, I want them to be read 3 base pairs at a time (to analyse them > codon by codon) and find the value that each codon has a value assigned > to it. An example of this is below: > > ** If the three base pairs were UUU the value assigned to it (from the > codon value table) would be 0.296 Ok, that sound like we can make a few test examples. Let's imagine for the moment that we did have this program. We'd like to be able to say that: calculate_magic_number("UUU") == 0.296 Let's keep that test case in mind. Can we think of other simple test examples we can think of? Write them out. Would you be able to write calculate_magical_number() at this point? Can you think of a better name than 'calculate_magical_number'? > However, to make things even more complicated, the notebook sequences > are in lowercase and the codon value table is in uppercase, so the > sequences need to be converted into uppercase. So simplify the problem. Close your eyes and ignore the other requirements entirely. *grin* But seriously, don't look at those requirements at all yet. Fix the input to something simple. If you can't get calculate_magic_number() working, there's really no point. Put in a positive light, if you can get calculate_magic_number() right, you're much closer to success. The simple subproblem above completely ignores the fact that you want to do this on whole sequences, not just single codons, but that's ok: you can tackle that problem later. And you can always write helper functions to help sanitize the ugly, messy input and turn it into something that calculate_magic_number can handle. The point is: you must try to write your program iteratively: get a simple, correct subprogram working and tested. Once you have this, you can then start adding more features and helper functions to capture more of the real problem. You end up making progress at all steps, rather than cross your fingers and hope that it all just fits together at the end. But if you try building all at once, without any kind of scaffolding or minimal testing, you'll bound to have the whole structure fall apart, and you won't probably have a good sense of what part is breaking. > I've tried various ways of doing this but keep coming unstuck along the > way. Has anyone got any suggestions for how they would tackle this > problem? The recommendations presented here come from material in: http://www.htdp.org/ If you have time reading through it, I'd highly recommend it. It's not Python, but it does talk about program design. Good luck to you. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Are we the same?
On 6 Mar 2006 [EMAIL PROTECTED] wrote: > I just took this test on Tickle.com. To see how I scored, take the test. [advertisement cut] I don't mean to be dull, but what does this have to do with Python? If it doesn't have anything to do with learning Python or programming, let's keep it off this list. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Are we the same?
I believe it is just spam pretending to be a legit invitation, that made it to the list. Hugo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] saving .csv file as an xl worksheet
Hello, .xls is a proprietary format used by Microsoft office, and unless you have the specs for that format and are willing to implement them (very very hard) it would not make much sense. If you absolutely need that, then maybe a macro in VBA from Excel itself may be a better option. Changing the file extension only (just the filename, not the contents of the file) can be done using the shutil module in Python (high level file manipulation) Hugo arun wrote: > Hi , > Can i save a file with a desired extension?? > for ex: I have a .csv file (test.csv) and i want to save this file as > test.xls from a python script. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to get the return value?
On 2006/3/06, Alan Gauld wrote: >> for every workingday of a week: >> [...] >> week >> ... > >To be honest I'd do this with a series of separate scripts triggered by the >OS - either cron on Unix or at in Windows... To be honest, I had my share of troubles with AT, so I try to stay away from it. No unix box here, so ... mmm, there seems to be a pycron maybe that's the tool I'm looking for. >Simply save the frames as individually named files, probably using the >time... Getting the frames and naming them is no big problem, for windows there's the great videocapture module http://videocapture.sourceforge.net/ >This follows my motto of keeping things as simple as possible! :-) I try, I'm trying to try God knows I try Thanks Alan, Ingo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Analysing genetic code (DNA) using python
Here's one approach to the problem (using bogus codon values). -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of sjw28 Sent: Monday, March 06, 2006 8:37 AM To: tutor@python.org Subject: [Tutor] Analysing genetic code (DNA) using python I have many notepad documents that all contain long chunks of genetic code. They look something like this: atggctaaactgaccaagcgcatgcgtgttatccgcgagaaagttgatgcaaccaaacag tacgacatcaacgaagctatcgcactgctgaaagagctggcgactgctaaattcgtagaa agcgtggacgtagctgttaacctcggcatcgacgctcgtaaatctgaccagaacgtacgt ggtgcaactgtactgccgcacggtactggccgttccgttcgcgtagccgtatttacccaa Basically, I want to design a program using python that can open and read these documents. However, I want them to be read 3 base pairs at a time (to analyse them codon by codon) and find the value that each codon has a value assigned to it. An example of this is below: ** If the three base pairs were UUU the value assigned to it (from the codon value table) would be 0.296 The program has to read all the sequence three pairs at a time, then I want to get all the values for each codon, multiply them together and put them to the power of 1 / the length of the sequence in codons (which is the length of the whole sequence divided by three). However, to make things even more complicated, the notebook sequences are in lowercase and the codon value table is in uppercase, so the sequences need to be converted into uppercase. Also, the Ts in the DNA sequences need to be changed to Us (again to match the codon value table). And finally, before the DNA sequences are read and analysed I need to remove the first 50 codons (i.e. the first 150 letters) and the last 20 codons (the last 60 letters) from the DNA sequence. I've also been having problems ensuring the program reads ALL the sequence 3 letters at a time. I've tried various ways of doing this but keep coming unstuck along the way. Has anyone got any suggestions for how they would tackle this problem? Thanks for any help recieved! -- View this message in context: http://www.nabble.com/Analysing-genetic-code-%28DNA%29-using-python-t123 3856.html#a3263717 Sent from the Python - tutor forum at Nabble.com. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor GenCode.py Description: GenCode.py atggctaaactgaccaagcgcatgcgtgttatccgcgagaaagttgatgcaaccaaacag tacgacatcaacgaagctatcgcactgctgaaagagctggcgactgctaaattcgtagaa agcgtggacgtagctgttaacctcggcatcgacgctcgtaaatctgaccagaacgtacgt ggtgcaactgtactgccgcacggtactggccgttccgttcgcgtagccgtatttacccaa ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Are we the same?
On Mon, 6 Mar 2006, [ISO-8859-1] Hugo Gonz�lez Monteverde wrote: > I believe it is just spam pretending to be a legit invitation, that made > it to the list. Followup: Gavin later sent a reply apologizing to the list --- maybe he got a virus? --- but it didn't make it through since it was addressed to too many people. *grin* Oh well, no real harm done. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Analysing genetic code (DNA) using python
Hi Anna, Let's see one thing at a time. wrote: > ** If the three base pairs were UUU the value assigned to it (from the > codon value table) would be 0.296 This can be done in Python, and one appropriate tool may be a dictionary such as: >>> dna_table = { "UUU" : 0.296, "GGG" : 0.3 } >>> print dna_table["UUU"] 0.296 >>> You'd use the table to look the corresponding value. Of course, you'd have to so some programming to get your ASCII translation tables converted to a dictionary. > The program has to read all the sequence three pairs at a time, then I > want to get all the values for each codon, multiply them together and > put them to the power of 1 / the length of the sequence in codons > (which is the length of the whole sequence divided by three). Rational powers are supported by the pow() function in module math, see: >>> import math >>> math.pow(10,0.5) 3.1622776601683791 > > > However, to make things even more complicated, the notebook sequences > are in lowercase and the codon value table is in uppercase, so the > sequences need to be converted into uppercase. Also, the Ts in the DNA > sequences need to be changed to Us (again to match the codon value > table). And finally, before the DNA sequences are read and analysed I > need to remove the first 50 codons (i.e. the first 150 letters) and the > last 20 codons (the last 60 letters) from the DNA sequence. These problems are very straightforward in python with string methods, take a looks at the docs at: http://docs.python.org/lib/string-methods.html I've also > been having problems ensuring the program reads ALL the sequence 3 > letters at a time. > Line endings may be causing you problems if you try to read line by line. Something like this should do: #read 100 characters from your file buff = fileo.read(100) #eliminate line endings buff = buff.replace("\n", "") #read three new characters word = buff[0:4] #consume part of the buffer buff = buff[4:] This is slow and can be polished. One approach could be reading characters into a list and then consuming that list (strings are a bit harder since you cannot change them) Also, the last expressions will throw an exception when the list is too short, and you'll have to read another chunk from the file. Hope this all helps, please let us know how far have you got and when you get stuck so we can help. Hugo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] saving .csv file as an xl worksheet
arun wrote: > Hi , > Can i save a file with a desired extension?? > for ex: I have a .csv file (test.csv) and i want to save this file as > test.xls from a python script. It's easy to rename a file, or read it and save it with whatever name you like, but that won't convert it to an actual Excel worksheet. To write true xls files you can use win32com to control Excel through its COM interface (google python excel for many examples) or you can use pyExcelerator. http://cheeseshop.python.org/pypi/pyExcelerator/0.6.0a Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to get the return value?
> To be honest, I had my share of troubles with AT, so I try to stay away > from it. No unix box here, so ... so... download cygwin! including a fully functioning cron. I can't imagine life on Windoze without cygwin :-) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] [OT] Shells
On 07/03/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > I can't imagine life on Windoze without cygwin :-) Agreed --- but the new Microsoft shell looks very interesting. Ars has a good review of it here: http://arstechnica.com/guides/other/msh.ars It borrows from all over the place, including Perl, Python, (ba)sh, and SQL, so the syntax sometimes seems to fight itself. But, overall, I'm very impressed. It looks a lot like the python interpreter, except customised to focus on file manipulation and process management (since that's what shells are for). -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Print list vs telnetlib.telnet.write differences
Lloyd/David and all, I'm still seeing something a bit weird with sending commands back to the router via tn.write(). This is with python 2.4.2 As per David's last email I replaced: tn.read_until('#') for item in lines: x = item tn.write(x) With: blob = string.join(lines) print blob #tn.write("\03") # Assures the device is in enable mode x = tn.read_until("#")# The "x =" seems to help flush the read buffer tn.write("conf t\n") x = tn.read_until("#") tn.write(blob) tn.read_until('#') tn.write('exit' '\n') #disconnect from the session But I am still seeing a command being sent to the device twice :( As per the above I've got a print command outputting what I'm sending back to the router. The output of the print blob looks like (output shown between the lines): ___ banner exec ^ ## switch01 Level XX, XX Some Street, Somewhere Site contact: John Citizen 555 System Contact: Helpdesk 555 5556 ## ^ ___ Yet the output on TCPWatch looks like (output shown between the lines): Enter configuration commands, one per line. End with CNTL/Z. switch01(config)#banner exec ^ ## switch01 Level XX, XX Some Street, Somewhere Site contact: John Citizen 555 System Contact: Helpdesk 555 5556 ## ^ banner exec ^ < this is the second time this command is sent to the device Enter TEXT message. End with the character '^'. ###exit Any explanation of what I'm doing wrong to get duplication of the sent commands? It looks like the script is looping on the print blob, but I can't see why it should do that? Thanks Gideon (I can send through the entire script but it's a 170+ lines and didn't want to send an epic email to the list) -Original Message- From: Python [mailto:[EMAIL PROTECTED] Sent: Saturday, 4 March 2006 3:42 AM To: STREET Gideon (SPARQ) Cc: Tutor Python Subject: Re: [Tutor] Print list vs telnetlib.telnet.write differences On Fri, 2006-03-03 at 15:41 +1000, STREET Gideon (SPARQ) wrote: > The problem I'm stumbling over is that when I print x, the output is > what I want. If I delete the print x and #, leaving only tn.write(x) > on the last line everything looks good except it writes the 1st item > in "lines" (the banner exec command) twice, once at the beginning > where it's supposed to, but then once again at the end. See except > below for example. > > Anyone able to explain why that is happening or is it me just not > understanding what I'm doing? Hope my explanation is clear I'm still > unfamiliar with the exact phrasology. > Could that be your data being echoed back to you? Is the router configured correctly after the script runs? I normally feed commands to Cisco devices using tftp. It is relatively easy to edit a file to get the commands correct. Then you could limit your "conversational script" to logging in and running tftp to transfer the command file. It looks like you are pretty close to having this working. -- Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-653-8139 fax:320-210-3409 -- Lloyd Kvam Venix Corp This e-mail (including any attachments) may contain confidential or privileged information and is intended for the sole use of the person(s) to whom it is addressed. If you are not the intended recipient, or the person responsible for delivering this message to the intended recipient, please notify the sender of the message or send an e-mail to mailto:[EMAIL PROTECTED] immediately, and delete all copies. Any unauthorised review, use, alteration, disclosure or distribution of this e-mail by an unintended recipient is prohibited. Ergon Energy accepts no responsibility for the content of any e-mail sent by an employee which is of a personal nature. Ergon Energy Corporation Limited ABN 50 087 646 062 Ergon Energy Pty Ltd ABN 66 078 875 902 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Print list vs telnetlib.telnet.write differences
On Tue, 2006-03-07 at 11:31 +1000, STREET Gideon (SPARQ) wrote: > Enter configuration commands, one per line. End with CNTL/Z. > switch01(config)#banner exec ^ > > ## > > switch01 > > Level XX, XX Some Street, Somewhere >Site contact: John Citizen 555 > System Contact: Helpdesk 555 5556 > > ## > > ^ > banner exec ^ < this is the second time this command is sent to the > device > Enter TEXT message. End with the character '^'. > > ###exit > My tcpwatch.py display shows different colors for each side of the conversation. Do you get two colors? are both in the same color? Isn't the second banner exec simply the echo back from the cisco device? It is giving you your entry instructions. 1. Is the banner exec command working? If it works, then the funny duplication is almost certainly just an artifact of characters getting echoed from the cisco device. -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Print list vs telnetlib.telnet.write differences
On Tue, 2006-03-07 at 13:39 +1000, STREET Gideon (SPARQ) wrote: > The second banner exec is red, the previous commands I send are in > green. So I take it to mean that it is an echo produced by the router. > MMmm strange as the echo is overwriting what I'm sending initially. Well the device is designed for interactive use by a human who does not spew characters nearly has quickly as your script. In this case you probably need to read the response to the exec banner command before sending the banner. Most commands are done in a single line, but banner is an exception. This kind of scripting is often done with expect and I believe that there is some expect-like module for Python. As I suggested earlier, getting tftp to send command files will make a much better long term solution. This script would only have to manage logging in and starting tftp. Once that works all other commands would be in the file that tftp transfers. Linux/Unix systems already have tftp built in. Cisco provides a tftp implementation for Windows. It is easy to put comments into the command files and also use subversion or some other version control package to track changes. > > The banner appears to work but is then overwritten, maybe I need to come > up with another way of sending the commands so I get around the echo. > > Thanks > > Gideon > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Behalf Of Python > Sent: Tuesday, 7 March 2006 12:52 PM > To: Tutor Python > Subject: Re: [Tutor] Print list vs telnetlib.telnet.write differences > > On Tue, 2006-03-07 at 11:31 +1000, STREET Gideon (SPARQ) wrote: > > Enter configuration commands, one per line. End with CNTL/Z. > > switch01(config)#banner exec ^ > > > > ## > > > > switch01 > > > > Level XX, XX Some Street, Somewhere > >Site contact: John Citizen 555 > > System Contact: Helpdesk 555 5556 > > > > ## > > > > ^ > > banner exec ^ < this is the second time this command is sent to > > the device Enter TEXT message. End with the character '^'. > > > > ###exit > > > > My tcpwatch.py display shows different colors for each side of the > conversation. Do you get two colors? are both in the same color? > > Isn't the second banner exec simply the echo back from the cisco device? > It is giving you your entry instructions. > > 1. Is the banner exec command working? > If it works, then the funny duplication is almost certainly just an > artifact of characters getting echoed from the cisco device. > > -- > Lloyd Kvam > Venix Corp > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > > This e-mail (including any attachments) may contain confidential or > privileged information and is intended for the sole use of the person(s) to > whom it is addressed. If you are not the intended recipient, or the person > responsible for delivering this message to the intended recipient, please > notify the sender of the message or send an e-mail to > mailto:[EMAIL PROTECTED] immediately, and delete all copies. Any > unauthorised review, use, alteration, disclosure or distribution of this > e-mail by an unintended recipient is prohibited. Ergon Energy accepts no > responsibility for the content of any e-mail sent by an employee which is of > a personal nature. > > Ergon Energy Corporation Limited ABN 50 087 646 062 > Ergon Energy Pty Ltd ABN 66 078 875 902 -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] search and replace
Hello, I have a problem finding specific words. I would like to filter out a word or replace it in a file. I notices that the re module is good for finding patterns. I am trying to filter out a word from strings, but having a little trouble. I was wondering if I can search a string for a specific word and nothing else. For example: hello, Othello. # just the hello and not Othello I know that I could probably put the string in a list and replace it. But I was wondering if it is possible using re module or the other find type attributes to find it. hello will not be necessarily at the beginning or end, so I am opting not to use endswith or startswith. Thank you. Best regards, tak ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] saving .csv file as an xl worksheet
On Mon, Mar 06, 2006 at 02:46:36PM +0530, arun wrote: > Can i save a file with a desired extension?? > for ex: I have a .csv file (test.csv) and i want to save this file as > test.xls from a python script. Just changing the file extension from .csv to .xls won't change the file format. OpenOffice 2.0 supports both .csv and .xls file formats and includes some sort of Python integration. It may be possible to use that. Regards Andrew ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Functions and random buttons
I'm trying just for fun to do a Game of life GUI, and want it to be a random size (later specified through some text field or something).So far it's working, but now I want to make each button clickable, so the button switches between true or false. But I can't find out how to do it. So any help would be appreciated, as well as any improvement in code :)#!/usr/bin/python# Filename: gol.pyimport timefrom Tkinter import *import threadingclass Gol: '''A board for the game of life''' def __init__(self, master): import random length = 10 aa = [] self.braet = [] self.updated = [] for i in range(length): aa.append(False) for i in range(length): self.braet.append(aa[:]) self.updated.append(aa[:]) # Makes a number of cells alive for i in range(length*2): et = random.randrange(length) to = random.randrange(length) while self.braet[et][to]: et = random.randrange(length) to = random.randrange(length) self.braet[et][to] = True self.frame = Frame(master) self.frame.grid() # A dictionary with all the buttons self.dict = {} for i in range(length): for j in range(length): self.dict['%s%s' % (i, j)] = Button(sel.frame, text = ' ') self.dict['%s%s' % (i, j)].grid(row = i, column = j) opdater = threading.Thread(target = self.run) opdater.start() def show(self): '''Updates the board, showing the changes since last''' for i in range(len(self.braet)): for j in range(len(self.braet[i])): if self.braet[i][j]: self.dict['%s%s' % (i, j)].config(text = ' X ') else: self.dict['%s%s' % (i, j)].config(text = ' ') def run(self): '''Runs the program, continually updating the board''' while True: self.show() time.sleep(1) self.update() def update(self): '''Updates the board If the cell has 3 live neighbors, it lives. Otherwise it dies''' # LONG batch of if-sentences, to check how many "neighbours" the cell has. Could probably be done in a better day for i in range(len(self.updated)): for j in range(len(self.updated[i])): self.updated[i][j] = 0 for raekke in range(len(self.braet)): for celle in range(len(self.braet[raekke])): cellmates = 0 # Way to many if sentences... if raekke == 0 or raekke == len(self.braet)-1: if celle == 0: if raekke == 0: if self.braet[raekke][celle+1]: cellmates += 1 if self.braet[raekke+1][celle]: cellmates += 1 if self.braet[raekke+1][celle+1]: cellmates += 1 elif raekke == len(self.braet)-1: if self.braet[raekke][celle+1]: cellmates += 1 if self.braet[raekke-1][celle]: cellmates += 1 if self.braet[raekke-1][celle+1]: cellmates += 1 elif celle == len(self.braet[raekke])-1: if raekke == 0: if self.braet[raekke][celle-1]: cellmates += 1 if self.braet[raekke+1][celle]: cellmates += 1 if self.braet[raekke+1][celle-1]: cellmates += 1 elif raekke == len(self.braet)-1: if self.braet[raekke][celle-1]: cellmates += 1 if self.braet[raekke-1][celle]: cellmates += 1 if self.braet[raekke-1][celle-1]: cellmates += 1 else: if raekke == 0: if self.braet[raekke][celle-1]: cellmates += 1 if self.braet[raekke][celle+1]: cellmates += 1 if self.braet[raekke+1][celle-1]: cellmates += 1 if self.braet[raekke+1][celle]: cellmates += 1 if self.braet[raekke+1][celle+1]: cellmates += 1 elif raekke == len(self.braet)-1: if self.braet[raekke][celle-1]: cellmates += 1