Iterate through list two items at a time
Hi all, I'm looking for a way to iterate through a list, two (or more) items at a time. Basically... myList = [1,2,3,4,5,6] I'd like to be able to pull out two items at a time - simple examples would be: Create this output: 1 2 3 4 5 6 Create this list: [(1,2), (3,4), (5,6)] I want the following syntax to work, but sadly it does not: for x,y in myList: print x, y I can do this with a simple foreach statement in tcl, and if it's easy in tcl it's probably not too hard in Python. Thanks, Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterate through list two items at a time
Thanks for all the fast responses. I'm particularly a fan of the zip method, followed closely by the xrange example. All, of course, are a lot of help! Thanks, Dave -- http://mail.python.org/mailman/listinfo/python-list
urlopen
Hi all, I'm running into some trouble using urllib.urlopen to grab a page from our corporate intranet. The name of the internal site is simply http://web (no www or com). I can use urlopen to grab a site like http://www.google.com just fine. However, when I use urlopen to grab the internal site, I instead get data from http://www.web.com. This is the url returned by the geturl() function. There must be a way to stop Python, or whoever is doing it, from changing my url. Maybe urllib is not the correct approach. Does anyone know a solution to this? Thanks, Dave -- http://mail.python.org/mailman/listinfo/python-list
Basic question about sockets and security
Hi all, I'm just starting out in sockets/network programming, and I have a very basic question...what are the 'security' implications of opening up a socket? For example, suppose I've written a simple chat server and chat client. The server opens a socket, listens on a port, and accepts incoming connections. The clients open a socket and connect to the server. If the server receives a message from a client, it sends that message out to every client. When a client receives a message, it places it in a text widget. So...are there inherent dangers in doing this? I have no real security concern in the actual application, but can an open socket somehow allow someone access to the rest of the computer? Is the 'security' of the socket handled at the OS level (or within the socket module)? I realize this isn't necessarily a Python question, but I wrote my application in Python and I'm not sure where to start. I'll repost this elsewhere if someone points me towards a more relevant group. Thanks, Dave -- http://mail.python.org/mailman/listinfo/python-list