[Tutor] Where can I download the document for twisted?
Where can I download the document for twisted? I could't find it on twistedmatrix.com . daedae11___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Where can I download the document for twisted?
On 2012/02/10 02:48 PM, daedae11 wrote: Where can I download the document for twisted? I could't find it on twistedmatrix.com . daedae11 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor There a link to The complete developer guide in PDF Format on http://twistedmatrix.com/trac/wiki/Documentation -- Christian Witts Python Developer // ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Question about an example in Python doc
The example is the third example in (Python2.7's doc)-(Python Library Reference)-17.2.2. The code of the example is: import socket # the public network interface HOST = socket.gethostbyname(socket.gethostname()) # create a raw socket and bind it to the public interface s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) s.bind((HOST, 0)) # Include IP headers s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) # receive all packages s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) # receive a package print s.recvfrom(65565) # disabled promiscuous mode s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF) However, when I run it, the interpreter show the following error: Traceback (most recent call last): File E:\c language\Eclipse\example\src\sniffer.py, line 12, in module s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) File D:\Python27\lib\socket.py, line 187, in __init__ _sock = _realsocket(family, type, proto) socket.error: [Errno 10013] What's the matter? daedae11___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Dictionaries
Ive been given a challenge in the book im learning Python from and its basically create a program with a dictionary of father - son pairs and allow the user to add, replace and delete pairs. Ive done that without any problems but ive been giving another challenge where I have to improve the previous program by adding a choice that lets the user enter a name and get back a grandfather. The program should still only use one dictionary of father-son pairs and finally I have to make sure to include several generations in your dictionary so that a match can be found. Im not sure I fully understand the task because surely its only possible to have one key and one value per pair but the challenge seems to want me to have a key (for the father), a value (for the son) and then something else (for the grandfather). Is this actually possible? Or am I just misinterpreting the challenge? Myles Broomes ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Dictionaries
On 10 Feb 2012 19:45, myles broomes mylesbroo...@hotmail.co.uk wrote: Ive been given a challenge in the book im learning Python from and its basically create a program with a dictionary of father - son pairs and allow the user to add, replace and delete pairs. Ive done that without any problems but ive been giving another challenge where I have to improve the previous program by adding a choice that lets the user enter a name and get back a grandfather. The program should still only use one dictionary of father-son pairs and finally I have to make sure to include several generations in your dictionary so that a match can be found. Im not sure I fully understand the task because surely its only possible to have one key and one value per pair but the challenge seems to want me to have a key (for the father), a value (for the son) and then something else (for the grandfather). Is this actually possible? Or am I just misinterpreting the challenge? Myles Broomes I don't think the task is asking you to modify the exisiting dictionary and that its aim is to have you modify the way you search the dictionary. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Dictionaries
On 02/10/2012 09:13 AM, myles broomes wrote: Ive been given a challenge in the book im learning Python from and its basically create a program with a dictionary of father - son pairs and allow the user to add, replace and delete pairs. Ive done that without any problems but ive been giving another challenge where I have to improve the previous program by adding a choice that lets the user enter a name and get back a grandfather. The program should still only use one dictionary of father-son pairs and finally I have to make sure to include several generations in your dictionary so that a match can be found. Im not sure I fully understand the task because surely its only possible to have one key and one value per pair but the challenge seems to want me to have a key (for the father), a value (for the son) and then something else (for the grandfather). Is this actually possible? Or am I just misinterpreting the challenge? Myles Broomes Some sample code would be good. Can I assume that in your dictionary, the key is the son's name, and the value is the father's name? if so, then a grandfather is simply a father's father. So your challenge is to see how you might get that by doing multiple lookups in the dictionary, not by changing it at all. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about an example in Python doc
On Fri, Feb 10, 2012 at 3:12 PM, daedae11 daeda...@126.com wrote: The example is the third example in (Python2.7's doc)-(Python Library Reference)-17.2.2. The code of the example is: import socket # the public network interface HOST = socket.gethostbyname(socket.gethostname()) # create a raw socket and bind it to the public interface s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) s.bind((HOST, 0)) # Include IP headers s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) # receive all packages s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) # receive a package print s.recvfrom(65565) # disabled promiscuous mode s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF) However, when I run it, the interpreter show the following error: Traceback (most recent call last): File E:\c language\Eclipse\example\src\sniffer.py, line 12, in module s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) File D:\Python27\lib\socket.py, line 187, in __init__ _sock = _realsocket(family, type, proto) socket.error: [Errno 10013] That's very strange, because when I run it, the interpreter shows the following error: Traceback (most recent call last): File C:/Users/hugo/Downloads/test.py, line 7, in module s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) File C:\Python27\lib\socket.py, line 187, in __init__ _sock = _realsocket(family, type, proto) error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions Which is identical to yours, but includes a helpful message telling you what is wrong. Did you not get that message, or did you just paste it wrong? In any case, Walter got you the solution. HTH, Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Dictionaries
Hi Myles, On 10 February 2012 14:13, myles broomes mylesbroo...@hotmail.co.uk wrote: Ive been given a challenge in the book im learning Python from and its basically create a program with a dictionary of father - son pairs and allow the user to add, replace and delete pairs. Ive done that without any problems but ive been giving another challenge where I have to improve the previous program by adding a choice that lets the user enter a name and get back a grandfather. The program should still only use one dictionary of father-son pairs and finally I have to make sure to include several generations in your dictionary so that a match can be found. Im not sure I fully understand the task because surely its only possible to have one key and one value per pair but the challenge seems to want me to have a key (for the father), a value (for the son) and then something else (for the grandfather). Is this actually possible? Or am I just misinterpreting the challenge? Sarma is correct. I'd like to add: Suppose you had a table with 2 columns, the first listing sons, the second their fathers. And suppose someone asked you to find the grandfather of someone. How would *you* go about finding the answer to this question, using the table? What steps would you execute? If you can come up with an explanation to my question, then your job is to translate this solution into Python, but using your existing dictionary instead of the table. HTH, Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Dictionaries
On 10/02/2012 14:13, myles broomes wrote: Ive been given a challenge in the book im learning Python from and its basically create a program with a dictionary of father - son pairs and allow the user to add, replace and delete pairs. Ive done that without any problems but ive been giving another challenge where I have to improve the previous program by adding a choice that lets the user enter a name and get back a grandfather. The program should still only use one dictionary of father-son pairs and finally I have to make sure to include several generations in your dictionary so that a match can be found. Im not sure I fully understand the task because surely its only possible to have one key and one value per pair but the challenge seems to want me to have a key (for the father), a value (for the son) and then something else (for the grandfather). Is this actually possible? Or am I just misinterpreting the challenge? Myles Broomes ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Take a look at this http://www.daniweb.com/software-development/python/code/217019 and think about it in relation to the replies you've already had. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Concatenating multiple lines into one
Dear python community, I have a file where I store sequences that each have a header. The structure of the file is as such: sp|(some code) =1st header AGGCGG MNKPLOI . . sp|(some code) = 2nd header AA ... . .. I am looking to implement a logical structure that would allow me to group each of the sequences (spread on multiple lines) into a single string. So instead of having the letters spread on multiple lines I would be able to have 'AGGCGGMNKP' as a single string that could be indexed. This snipped is good for isolating the sequences (=stripping headers and skipping blank lines) but how could I concatenate each sequence in order to get one string per sequence? for line in align_file: ... if line.startswith('sp'): ... continue ... elif not line.strip(): ... continue ... else: ... print line (... is just OS X terminal notation, nothing programmatic) Many thanks in advance. S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Concatenating multiple lines into one
On Fri, Feb 10, 2012 at 5:38 PM, Spyros Charonis s.charo...@gmail.com wrote: Dear python community, I have a file where I store sequences that each have a header. The structure of the file is as such: sp|(some code) =1st header AGGCGG MNKPLOI . . sp|(some code) = 2nd header AA ... . .. I am looking to implement a logical structure that would allow me to group each of the sequences (spread on multiple lines) into a single string. So instead of having the letters spread on multiple lines I would be able to have 'AGGCGGMNKP' as a single string that could be indexed. This snipped is good for isolating the sequences (=stripping headers and skipping blank lines) but how could I concatenate each sequence in order to get one string per sequence? for line in align_file: ... if line.startswith('sp'): ... continue ... elif not line.strip(): ... continue ... else: ... print line (... is just OS X terminal notation, nothing programmatic) Many thanks in advance. S. python has a simple method to do that, str.join. Let me demonstrate it: a = ['a', 'b', 'c', 'd', 'e'] ''.join(a) 'abcde' ' '.join(a) # with a space 'a b c d e' ' hello '.join(a) # go crazy if you want 'a hello b hello c hello d hello e' so, it takes a list as an argument and joins the elements together in a string. the string that you call join on is used as a separator between the arguments. Pretty simple. HTH, Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Concatenating multiple lines into one
Spyros Charonis wrote: Dear python community, I have a file where I store sequences that each have a header. The structure of the file is as such: sp|(some code) =1st header AGGCGG MNKPLOI . . sp|(some code) = 2nd header AA ... . .. I am looking to implement a logical structure that would allow me to group each of the sequences (spread on multiple lines) into a single string. So instead of having the letters spread on multiple lines I would be able to have 'AGGCGGMNKP' as a single string that could be indexed. This snipped is good for isolating the sequences (=stripping headers and skipping blank lines) but how could I concatenate each sequence in order to get one string per sequence? for line in align_file: ... if line.startswith('sp'): ... continue ... elif not line.strip(): ... continue ... else: ... print line (... is just OS X terminal notation, nothing programmatic) Many thanks in advance. Instead of printing the line directly collect it in a list (without trailing \n). When you encounter a line starting with sp check if that list is non-empty, and if so print .join(parts), assuming the list is called parts, and start with a fresh list. Don't forget to print any leftover data in the list once the for loop has terminated. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Concatenating multiple lines into one
On 10/02/2012 17:08, Peter Otten wrote: Spyros Charonis wrote: Dear python community, I have a file where I store sequences that each have a header. The structure of the file is as such: sp|(some code) =1st header AGGCGG MNKPLOI . . sp|(some code) = 2nd header AA ... . .. I am looking to implement a logical structure that would allow me to group each of the sequences (spread on multiple lines) into a single string. So instead of having the letters spread on multiple lines I would be able to have 'AGGCGGMNKP' as a single string that could be indexed. This snipped is good for isolating the sequences (=stripping headers and skipping blank lines) but how could I concatenate each sequence in order to get one string per sequence? for line in align_file: ... if line.startswith('sp'): ... continue ... elif not line.strip(): ... continue ... else: ... print line (... is just OS X terminal notation, nothing programmatic) Many thanks in advance. Instead of printing the line directly collect it in a list (without trailing \n). When you encounter a line starting withsp check if that list is non-empty, and if so print .join(parts), assuming the list is called parts, and start with a fresh list. Don't forget to print any leftover data in the list once the for loop has terminated. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor The advice from Peter is sound if the strings could grow very large but you can simply concatenate the parts if they are not. For the indexing simply store your data in a dict. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor