[Tutor] How to save telnet output logs to a text file in python
Hi All, Please someone help on the below request. I am learning python and trying to connect my satellite decoder using telnet. When I tried to connect my device through telnet python script, I could successfully connected to the device. But i want to capture/save as well as read the output and logs of device (connected thru telnet) from starting in a text file. Also, i want to send few commands to get the output of the command and store in the text file. Please kindly help on how to capture and write the output logs of device connected thru telnet connection in a local text file. Note: Once the password is successful, my device prints some set of logs and it has to capture in the local text file, also the output of commands should also record in the text file. 1. HOST = "192.131.244.100" 2. user = "user" 3. password = "user" 4. 5. tn = Telnet(HOST) 6. tn.read_until("Login: ") 7. tn.write(user + "\n") 8. tn.read_until("Password: ") 9. tn.write(password + "\n") 10. time.sleep(5) 11. tn.write("lr\n") # lr is command to pause logs 12. tn.write("version\n") # command to check running software version 13. tn.write("exit\n") 14. str_all = tn.read_all() 15. 16. f = open("C:\\temp\\Logs\\output.txt", 'w') 17. f.write(str_all) 18. tn.close() Not able to read and save all logs from starting. Also, pls. let me know any other way to save telnet output either in putty or teraterm. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Don't Understand Problem
So I am new to this, and I have a book call /Hello Python by Anthony Briggs/. It is a good book but it is using Python 2 I think and I can't get my code to work. I get an "AttributeError: 'range' object has no attribute 'remove'". I have tried to look it up on the web with no luck. Can someone help me understand this . ** #Setting up the cave from random import choice cave_numbers = range(0,20) caves = [] for i in cave_numbers: caves.append([]) #Setting up cave network unvisited_caves = range(0,20) current = 0 visited_caves = [0] *unvisited_caves.remove(0)* #Main loop of linking cave network while unvisited_caves != []: #Picking a random visited cave i = choice(visited_caves) if len(caves[i]) >= 3: continue #link to unvisited caves next_cave = choice(unvisited_caves) caves[i].append(next_cave) caves[next_cave].append(i) #Marking cave as visited visited_caves.append(next_cave) *unvisited_caves.remove(next_cave)* #Progress report for number in cave_numbers: print( number, ":", caves[number]) print('--') for i in cave_numbers: while len(caves[i]) < 3: passage_to = choice(cave_numbers) caves[i].append(passage_to) for number in cave_numbers: print(number, ":", caves[number]) print('-') print(caves) -- View this message in context: http://python.6.x6.nabble.com/Don-t-Understand-Problem-tp5087587.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Don't Understand Problem
On 26/02/15 04:30, kcberry wrote: So I am new to this, and I have a book call /Hello Python by Anthony Briggs/. It is a good book but it is using Python 2 I think and I can't get my code to work. I get an "AttributeError: 'range' object has no attribute 'remove'". I have tried to look it up on the web with no luck. Can someone help me understand this . Please always send full error traces, they contain a lot of useful details. Meantime in this case we can figure it out... #Setting up cave network unvisited_caves = range(0,20) current = 0 visited_caves = [0] *unvisited_caves.remove(0)* In Python 3 eange does not return a list. It returns something called a "range object" which helps save memory for large daya sets. If you need to use it as a list you need to explicitly convert it using list(): unvisited_caves = range(0,20) ... unvisited_caves.remove(0) However remove() may not do what you think. It removes the value zero from your list not the first element. I this case they are the same but in other cases they might not be. You may want to use del() instead del(unvisited_caves[0]) HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Don't Understand Problem
Op 26-02-15 om 09:55 schreef Alan Gauld: On 26/02/15 04:30, kcberry wrote: So I am new to this, and I have a book call /Hello Python by Anthony Briggs/. It is a good book but it is using Python 2 I think and I can't get my code to work. I get an "AttributeError: 'range' object has no attribute 'remove'". I have tried to look it up on the web with no luck. Can someone help me understand this . Please always send full error traces, they contain a lot of useful details. Meantime in this case we can figure it out... #Setting up cave network unvisited_caves = range(0,20) current = 0 visited_caves = [0] *unvisited_caves.remove(0)* In Python 3 eange does not return a list. It returns something called a "range object" which helps save memory for large daya sets. If you need to use it as a list you need to explicitly convert it using list(): unvisited_caves = range(0,20) I think you missed your own solution here, Alan. You probably meant: unvisited_caves = list(range(0, 20)) Timo ... unvisited_caves.remove(0) However remove() may not do what you think. It removes the value zero from your list not the first element. I this case they are the same but in other cases they might not be. You may want to use del() instead del(unvisited_caves[0]) HTH ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Don't Understand Problem
On Thu, Feb 26, 2015 at 08:55:55AM +, Alan Gauld wrote: > However remove() may not do what you think. It removes the > value zero from your list not the first element. I this case they are > the same but in other cases they might not be. You may want to use del() > instead > > del(unvisited_caves[0]) del is not a function, it is a statement, so it doesn't need the brackets (parentheses for any Americans reading). del unvisited_caves[0] Although the parens don't do any harm. To be clear, `del somelist[x]` deletes the xth item from somelist. But `somelist.remove(x)` deletes the first item that equals x, equivalent to this Python code: for i in range(len(somelist)): if somelist[i] == x: del somelist[i] break -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to save telnet output logs to a text file in python
On Thu, Feb 26, 2015 at 12:24:17PM +0530, kailash ganesh wrote: > Hi All, > > Please someone help on the below request. > > I am learning python and trying to connect my satellite decoder using > telnet. When I tried to connect my device through telnet python script, I > could successfully connected to the device. Can you show the code you use? You have something below which looks like code, but it doesn't seem to be Python. It has line numbers. Can you explain what it is please? > But i want to capture/save as well as read the output and logs of device > (connected thru telnet) from starting in a text file. Also, i want to send > few commands to get the output of the command and store in the text file. The documentation for the telnetlib module includes this example: >>> from telnetlib import Telnet >>> tn = Telnet('www.python.org', 79) # connect to finger port >>> tn.write(b'guido\r\n') >>> print(tn.read_all()) Login Name TTY IdleWhenWhere guidoGuido van Rossum pts/2 snag.cnri.reston.. I tried running that example, but www.python.org doesn't respond for me and I eventually got this error: TimeoutError: [Errno 110] Connection timed out Maybe my firewall blocks that port, or maybe the site is not listening. But the important part is the tn.read_all() function. If that works for you, you can do this instead: output = tn.read_all() # display to screen print(output) # write to a file with open("MyFile.txt", "wb") as f: f.write(output) # Check that the file wrote correctly. with open("MyFile.txt", "rb") as f: print(f.read()) Does that help? If you need more help, please show your code, without line numbers, and show any errors you get. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Rearranging a list
Assuming I have the following list and code how do I best be able rearrange the list as stated below: list = [0, 0, 21, 35, 19, 42] Using print list[2:6] resulted in the following: 221 335 419 542 I would like to rearrange the list as follow: 542 335 221 419 I tried using list.reverse() and print list[0,6] and it resulted in: [42, 19, 35, 21, 0, 0] or as printed: 042 119 235 321 40 50 In another words, I would desire to show that: 5 appears 42 times 3 appears 35 times 2 appears 21 times 4 appears 19 times but then I lose my original index of the numbers by reversing. How do I best keep the original index number to the rearrange numbers within a list? Thanking in advance, Ken ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Rearranging a list
Ken G. wrote: > Assuming I have the following list and code how do I best be able > rearrange the list as stated below: > > list = [0, 0, 21, 35, 19, 42] > > Using print list[2:6] resulted in the following: > > 221 > 335 > 419 > 542 > > I would like to rearrange the list as follow: > > 542 > 335 > 221 > 419 > > I tried using list.reverse() and print list[0,6] and it resulted in: > > [42, 19, 35, 21, 0, 0] or as printed: > > 042 > 119 > 235 > 321 > 40 > 50 > > In another words, I would desire to show that: > > 5 appears 42 times > 3 appears 35 times > 2 appears 21 times > 4 appears 19 times > > but then I lose my original index of the numbers by reversing. How do I > best keep the original index number to the rearrange numbers within a > list? Don't rearrange the original list, make a new one instead: >>> frequencies = [0, 0, 21, 35, 19, 42] >>> wanted_indices = [5, 3, 2, 4] >>> [frequencies[i] for i in wanted_indices] [42, 35, 21, 19] Or look up the values as you print them: >>> for i in wanted_indices: ... print(i, "appears", frequencies[i], "times") ... 5 appears 42 times 3 appears 35 times 2 appears 21 times 4 appears 19 times The expression [frequencies[i] for i in wanted_indices] is called "list comprehension" and is a shortcut for a loop: >>> result = [] >>> for i in wanted_indices: ... result.append(frequencies[i]) ... >>> result [42, 35, 21, 19] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Rearranging a list
On Thu, Feb 26, 2015 at 07:13:57AM -0500, Ken G. wrote: > Assuming I have the following list and code how do I best be able > rearrange the list as stated below: > > list = [0, 0, 21, 35, 19, 42] Be aware that you have "shadowed" the built-in list function, which could cause trouble for you. py> list = [1, 2, 3] py> # much later, after you have forgotten you shadowed list... py> characters = list("Hello world") Traceback (most recent call last): File "", line 1, in TypeError: 'list' object is not callable Oops. Save yourself future hassles, and pick a name like "L" (don't use "l", since that looks too similar to digit 1) or "mylist" or "seq" (short for sequence). > Using print list[2:6] resulted in the following: > > 221 > 335 > 419 > 542 I'm pretty sure it doesn't. py> lst = [0, 0, 21, 35, 19, 42] py> print(lst[2:6]) [21, 35, 19, 42] You're obviously doing a lot more than just `print lst[2:6]` to get the output you say you are getting. > I would like to rearrange the list as follow: > > 542 > 335 > 221 > 419 I don't understand how to generalise that. If you know you want that EXACT output, you can say: print "542" print "335" etc. to get it. Obviously that's not what you want, but I don't understand what rule you used to get "5 42" first, "3 35" second, etc. Where does the 5, 3, 2, 4 come from? What's the rule for getting 42 first, 19 last? > I tried using list.reverse() and print list[0,6] and it resulted in: > > [42, 19, 35, 21, 0, 0] or as printed: > > 042 > 119 > 235 > 321 > 40 > 50 > > In another words, I would desire to show that: > > 5 appears 42 times > 3 appears 35 times > 2 appears 21 times > 4 appears 19 times Huh? Now I'm *completely* confused. Your list was: [0, 0, 21, 35, 19, 42] 5, 3, 2 and 4 don't appear *at all*. You have: 0 appears twice 21 appears once 35 appears once 19 appears once 42 appears once > but then I lose my original index of the numbers by reversing. How do I > best keep the original index number to the rearrange numbers within a list? No clue what you mean. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Rearranging a list
Ah wait, the penny drops! Now I understand what you mean! On Thu, Feb 26, 2015 at 07:13:57AM -0500, Ken G. wrote: > In another words, I would desire to show that: > > 5 appears 42 times > 3 appears 35 times > 2 appears 21 times > 4 appears 19 times > > but then I lose my original index of the numbers by reversing. How do I > best keep the original index number to the rearrange numbers within a list? Here's your list again: [0, 0, 21, 35, 19, 42] I think using a list is the wrong answer. I think you should use a dictionary: d = {0: 0, 1: 0, 2: 21, 3: 35, 4: 19, 5: 42} for key, value in sorted(d.items(), reverse=True): print(key, value) which gives this output: 5 42 4 19 3 35 2 21 1 0 0 0 How should you build the dict in the first place? There's an easy way, and an even easier way. Here's the easy way. # count the numbers numbers = [2, 3, 1, 4, 0, 4, 2, 5, 2, 3, 4, 1, 1, 1, 3, 5] counts = {} for n in numbers: i = counts.get(n, 0) counts[n] = i + 1 print(counts) which gives output: {0: 1, 1: 4, 2: 3, 3: 3, 4: 3, 5: 2} Here's the even easier way: from collections import Counter counts = Counter(numbers) print(counts) which gives very similar output: Counter({1: 4, 2: 3, 3: 3, 4: 3, 5: 2, 0: 1}) In both cases, you then run the earlier code to print the items in order: for key, value in sorted(counts.items(), reverse=True): print(key, value) -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Rearranging a list
Peter Otten wrote: > Ken G. wrote: > >> Assuming I have the following list and code how do I best be able >> rearrange the list as stated below: >> >> list = [0, 0, 21, 35, 19, 42] >> >> Using print list[2:6] resulted in the following: >> >> 221 >> 335 >> 419 >> 542 >> >> I would like to rearrange the list as follow: >> >> 542 >> 335 >> 221 >> 419 >> >> I tried using list.reverse() and print list[0,6] and it resulted in: >> >> [42, 19, 35, 21, 0, 0] or as printed: >> >> 042 >> 119 >> 235 >> 321 >> 40 >> 50 >> >> In another words, I would desire to show that: >> >> 5 appears 42 times >> 3 appears 35 times >> 2 appears 21 times >> 4 appears 19 times >> >> but then I lose my original index of the numbers by reversing. How do I >> best keep the original index number to the rearrange numbers within a >> list? > > Don't rearrange the original list, make a new one instead: > frequencies = [0, 0, 21, 35, 19, 42] wanted_indices = [5, 3, 2, 4] [frequencies[i] for i in wanted_indices] > [42, 35, 21, 19] > > Or look up the values as you print them: > for i in wanted_indices: > ... print(i, "appears", frequencies[i], "times") > ... > 5 appears 42 times > 3 appears 35 times > 2 appears 21 times > 4 appears 19 times > > The expression [frequencies[i] for i in wanted_indices] is called "list > comprehension" and is a shortcut for a loop: > result = [] for i in wanted_indices: > ... result.append(frequencies[i]) > ... result > [42, 35, 21, 19] Oops, it occurs to me that you may want the most frequent indices rather than specific indices. You can achieve that with >>> def lookup_frequency(index): ... return frequencies[index] ... >>> wanted_indices = sorted(range(len(frequencies)), key=lookup_frequency, reverse=True) >>> wanted_indices [5, 3, 2, 4, 0, 1] >>> wanted_indices[:4] [5, 3, 2, 4] You may also want to look at the collections.Counter class: >>> import collections >>> c = collections.Counter() >>> for i, freq in enumerate(frequencies): ... c[i] = freq ... >>> c.most_common(4) [(5, 42), (3, 35), (2, 21), (4, 19)] >> for key, freq in c.most_common(4): ... print(key, "appears", freq, "times") ... 5 appears 42 times 3 appears 35 times 2 appears 21 times 4 appears 19 times ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Rearranging a list
Steven D'Aprano wrote: > Ah wait, the penny drops! Now I understand what you mean! Glad I'm not the only one ;) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Don't get it
I have a qestion about understanding my assignment. I was wonerding if it is possible for someone to expalin. it this is whar it asks of This assignment question will give you practice with recursive backtracking. You are to create a class called AnagramSolver that uses a word list to find all combinations of words that have the same letters as a given phrase. You might want to first look at the sample log of execution at the end of this part of the assignment and i am unsure of how to work with these guidlines for the constructor of the class A constructor, __init__. Takes a list of words, and constructs an anagram solver that will use the given list as its dictionary. It is not to modify the list -- *F.T.* ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Remove a blank row of a Table
Hello, everybody: I came accross a question a few days ago. I wrote a Python script to copy something to a table in a word file. For some reaons, there are some blank rows. And I want to remove the blank rows. I tried many ways, but all didn't work. Below is the code.desfile='C:\\Daten\\TestCASE5\\Model_hill.doc' fd = w.Documents.Open(desfile)lNam = textwrap.wrap(reportItem.PName) maxLines = len(lNam)for idx in xrange (1,maxLines) : if fd.Tables[6].Rows[idx].Cells[1] == None : fd.Tables[6].Rows[idx].Remove() else : pass Thanks in advance ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Don't Understand Problem
On 26/02/15 11:06, Timo wrote: If you need to use it as a list you need to explicitly convert it using list(): unvisited_caves = range(0,20) I think you missed your own solution here, Alan. You probably meant: unvisited_caves = list(range(0, 20)) Oops! Thanks for picking that up. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Don't get it
On 26/02/15 11:52, Fatimah Taghdi wrote: I have a qestion about understanding my assignment. I was wonerding if it is possible for someone to expalin. it Your teacher maybe? As it is you have taken a question which puzzles you, sent us only a part of it and somehow expect us to understand it all based only on your partial information. This assignment question will give you practice with recursive backtracking. You are to create a class called AnagramSolver that uses a word list to find all combinations of words that have the same letters as a given phrase. That rather depends on what the definition of a "word" is. If its any combination of the letters given its not too difficult. If they must be valid words then you need a definitive list (ie a lexicon) to check against. You might want to first look at the sample log of execution at the end of this part of the assignment Maybe that would help us too? and i am unsure of how to work with these guidlines for the constructor of the class A constructor, __init__. Takes a list of words, and constructs an anagram solver that will use the given list as its dictionary. It is not to modify the list Is that last paragraph your interpretation or part of the assignment? If the latter then letting us see any other hints might help us figure out what your teacher is thinking of. As it is we can only make wild guesses. Have you tried asking your teacher for clarification? In my experience most teachers are happy to help if you ask intelligent questions that show you have seriously thought about the assignment first, -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Remove a blank row of a Table
On 26/02/15 05:53, shouqiang1...@sina.com wrote: Hello, everybody: I came accross a question a few days ago. I wrote a Python script to copy something to a table in a word file. For some reaons, there are some blank rows. And I want to remove the blank rows. I tried many ways, but all didn't work. Below is the As you can probably see your code came scrambled beyond reasonable recognition. (We can guess but we can't be sure) Can you repost in plain text please, not in HTML. code.desfile='C:\\Daten\\TestCASE5\\Model_hill.doc' fd = w.Documents.Open(desfile)lNam = textwrap.wrap(reportItem.PName) maxLines = len(lNam)for idx in xrange (1,maxLines) : if fd.Tables[6].Rows[idx].Cells[1] == None : fd.Tables[6].Rows[idx].Remove() else : pass Also, since Python by default can't handle Word files can you tell us which library you are using to do this. In other words in the line: fd = w.Documents.Open(desfile) Where do w, Document, and Open() come from? They are seemingly not a part of the standard Python library. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Rearranging a list
I may have mis-stated my intention. I will rewrite my request for assistance later and resubmit. Thanks, Ken On 02/26/2015 08:04 AM, Peter Otten wrote: Steven D'Aprano wrote: Ah wait, the penny drops! Now I understand what you mean! Glad I'm not the only one ;) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Gaussian process regression
Hi, I am trying to use Gaussian process regression for Near Infrared spectra. I have reference data(spectra), concentrations of reference data and sample data, and I am trying to predict concentrations of sample data. Here is my code. from sklearn.gaussian_process import GaussianProcess gp = GaussianProcess() gp.fit(reference, concentration) concentration_pred = gp.predict(sample) The results always gave me the same concentration even though I used different sample data. When I used some parts of reference data as sample data, it predicted concentration well. But whenever I use different data than reference data, it always gave me the same concentration. Can I get some help with this problem? What am I doing wrong? I would appreciate any help. Thanks, Jay ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Gaussian process regression
On 26/02/15 18:04, Huijae wrote: Hi, I am trying to use Gaussian process regression for Near Infrared spectra. I have reference data(spectra), concentrations of reference data and sample data, and I am trying to predict concentrations of sample data. Here is my code. from sklearn.gaussian_process import GaussianProcess gp = GaussianProcess() gp.fit(reference, concentration) concentration_pred = gp.predict(sample) The results always gave me the same concentration even though I used different sample data. When I used some parts of reference data as sample data, it predicted concentration well. But whenever I use different data than reference data, it always gave me the same concentration. Can I get some help with this problem? What am I doing wrong? I would appreciate any help. Thanks, Jay As you can probably see, your code did not make it through in readable form as HTML. Can you please repost using plain text? Also this list is aimed at beginners to Python using the standard library. You are evidently using some kind of third party library - SciPy maybe? If so you may get a better response on the SciPy support forums where more people are likely to be familiar with your issues. However, once we can see the code, some members here do use Python in science/math so might be able to help. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Rearranging a list
On 26/02/2015 16:33, Ken G. wrote: I may have mis-stated my intention. I will rewrite my request for assistance later and resubmit. Thanks, Ken When you come back please don't top post, it makes following long threads difficult if not impossible, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Use python to parse the subject line of emails, listen for and react to commands
Hello I have been trying to figure out a way to parse the subject line of new emails in Gmail, the subject line will be commands for another python script. I know this isn't the most secure way of doing things but it is for a Beagle Bone, I'm really new to python and don't know of this is even possible though I don't see why not. The way I thought it would work would to have py check email subject lines coming from one sender when it sees a subject "Command(the command to follow)" it would then start another py script with that command, or otherwise sees the subject Settings(the item to change(the change)) it would change a settings page. I haven't found any examples of using py to loop back on itself like this, mostly I'm sure because this is not secure and easy to hack and clunky for remote access, I know py can parse emails, but I cant figure out how to limit to only the subject and only if its in that certain format and only if its coming from a recognized email address and since I'm using 3.4 it seems all the other kind of examples don't work half the time anyway. can someone point me in the right direction ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Use python to parse the subject line of emails, listen for and react to commands
On 26/02/2015 20:51, Willie Sims wrote: Hello I have been trying to figure out a way to parse the subject line of new emails in Gmail, the subject line will be commands for another python script. I know this isn't the most secure way of doing things but it is for a Beagle Bone, I'm really new to python and don't know of this is even possible though I don't see why not. The way I thought it would work would to have py check email subject lines coming from one sender when it sees a subject "Command(the command to follow)" it would then start another py script with that command, or otherwise sees the subject Settings(the item to change(the change)) it would change a settings page. I haven't found any examples of using py to loop back on itself like this, mostly I'm sure because this is not secure and easy to hack and clunky for remote access, I know py can parse emails, but I cant figure out how to limit to only the subject and only if its in that certain format and only if its coming from a recognized email address and since I'm using 3.4 it seems all the other kind of examples don't work half the time anyway. can someone point me in the right direction Will this https://docs.python.org/3/library/email-examples.html at least get you going? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Use python to parse the subject line of emails, listen for and react to commands
On 26/02/15 20:51, Willie Sims wrote: I know py can parse emails, but I cant figure out how to limit to only > the subject and only if its in that certain format and only if its coming from a recognized email address OK, Show us what you've tried. That makes it easier for us to see what is tripping you up. Otherwise we are just guessing. All 3 things you ask for can be done but we need a starting point and the best one is your existing, but faulty, code. and since I'm using 3.4 it seems all the other kind of examples don't work A lot of old examples on the web will be for Python v32 and there are significant differences to v3. However, Python v3 has not lost any important functionality so whatever worked in v2 can be made to work in v3. Again we just need a clue as to what you are trying to do. (show us your code - and any error messages and tell us your OS too) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Gaussian process regression
On Fri, Feb 27, 2015 at 03:04:25AM +0900, Huijae wrote: > Hi, I am trying to use Gaussian process regression for Near Infrared > spectra. I have reference data(spectra), concentrations of reference > data and sample data, and I am trying to predict concentrations of > sample data. Here is my code. from sklearn.gaussian_process import > GaussianProcess gp = GaussianProcess() gp.fit(reference, > concentration) concentration_pred = gp.predict(sample) The results > always gave me the same concentration even though I used different > sample data. When I used some parts of reference data as sample data, > it predicted concentration well. But whenever I use different data > than reference data, it always gave me the same concentration. Can I > get some help with this problem? What am I doing wrong? I would > appreciate any help. Thanks, Jay Your mail program has mangled your code and mixed up the layout. I suggest turning off all formatting, "Rich Text" or HTML mail, since that usually destroys the layout of code. I'm going to try to guess your code's layout: from sklearn.gaussian_process import GaussianProcess gp = GaussianProcess() gp.fit(reference, concentration) concentration_pred = gp.predict(sample) This is not enough for us to give any meaningful advice. What is "sklearn"? What are "reference", "concentration", "sample"? We'd need to see actual data, and know what GaussianProcess does, to help. > The results always gave me the same concentration > even though I used different sample data. *Exactly* the same? To 17 decimal places? Or just close to the same? Perhaps the different samples give the same result because they are samples from the same population. > When I used some parts of > reference data as sample data, it predicted concentration well. But > whenever I use different data than reference data, it always gave me > the same concentration. You may need to ask people who know more about GaussianProcess and how it works. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with python in MAC OS 10.6
Dear tutor, I'd like to ask for help with an issue I have with python. My MAC is with OS 10-6.8, darwin kernel, 64 bits. For some reason I updated macports and it automatically updated python to 2.7 with a 32 bits library, and it is giving me lots of trouble. I can't install any new software that uses python, and recently I tried to use some plot (matplotlib) routines that were working fine before, simply didn't work, the window with the plot didn't open.Is there a way to force macports to install a 64bits version of python?I downloaded and installed the 3.4 and 3.1 myself, but still the computer only sees the version macports installed.Thank you!Regards, Bárbara ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor