Parse file into array
I was wondering how i could parse the contents of a file into an array. the file would look something like this: gif:image/gif html:text/html jpg:image/jpeg ... As you can see, it contains the mime type and the file extension seperated by commas, 1 per line. I was wondering if it was possible to create and array like this: (Pseudocode) mimetypearray[gif] = "image/gif" mimetypearray[html] = "text/html" mimetypearray[jpg] = "image/jpeg" ... I come from a PHP backround where I know this is possible, but I am new at Python. Please disregard this if it is a stupid question. -- http://mail.python.org/mailman/listinfo/python-list
Re: Parse file into array
Thanks a lot. The webserver I am writing works now :) -- http://mail.python.org/mailman/listinfo/python-list
Command line
Hoe would I call something on the command line from python, e.g. "ls -la"? -- http://mail.python.org/mailman/listinfo/python-list
Command line
Hoe would I call something on the command line from python, e.g. "ls -la"? -- http://mail.python.org/mailman/listinfo/python-list
BaseHTTPServer module
>From the BaseHTTPServer module, how do i gget the POST or GET data sent by the client? Is it stired the the file they requested? e.g. objectname.path -- http://mail.python.org/mailman/listinfo/python-list
BaseHTTPServer module
>From the BaseHTTPServer module, how do i gget the POST or GET data sent by the client? Is it stired the the file they requested? e.g. objectname.path -- http://mail.python.org/mailman/listinfo/python-list
Re: Command line
What I am trying to do is call perl on the command line. Also, do any of these functions return the data recievved from the command? -- http://mail.python.org/mailman/listinfo/python-list
Re: Command line
Thanks for your help. Another question, is there an built in md5/sha1 function in python? -- http://mail.python.org/mailman/listinfo/python-list
Re: BaseHTTPServer module
Thanks, all I wanted to know where the post data was stored from the request -- http://mail.python.org/mailman/listinfo/python-list
Reading binary files
On windows, is there anything special I have to do to read a binary file correctly? -- http://mail.python.org/mailman/listinfo/python-list
Code returns error when not supposed to
This code always returns a ValueError when it is not supposed to: i = rest.rfind('?') Error: ValueError: need more than 0 values to unpack rfind is not supposed to generate an erro, just return -1. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: Code returns error when not supposed to
Never mind, figured out -- http://mail.python.org/mailman/listinfo/python-list
Re: BaseHTTPServer module
I looked at the doumentation and is says rfile is: "Contains an input stream, positioned at the start of the optional input data." How do i get the input out of it? -- http://mail.python.org/mailman/listinfo/python-list
Retrieve input
A little while ago, someone told me that for the BaseHTTPServer module, the whole request would be stored in self.rfile. I looked at the doumentation and is says rfile is: "Contains an input stream, positioned at the start of the optional input data." How do i get the input out of it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieve input
Thanks, but when I try to read the stream using read(), the script just keeps on going and does not stop. When i press ctrl + c, the script shows thsi (top of error taken off): File "modules/runpython.py", line 88, in runModule sys.stdin = self.rfile.read() File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/socket.py", line 283, in read data = self._sock.recv(recv_size) KeyboardInterrupt Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
CGI module does not parse data
I am writing a webserver, and I want it to be able to run python scripts. But when I set sys.stdin to self.rfile (using the BaseHTTPServer class, self.rfile is a input stream containing the request), the cgi module does not parse the data. Example script: import cgi form = cgi.FieldStorage() print form["testfield"] The above script would print nothing. Should i be setting sys.stdin to something else, or is there anthoer solution entirely? -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI module does not parse data
I have included some of the content of that file, I am writing this as an extension to my ebserver which is based on BaseHTTPServer. This part of the code was taken directly from the CGIHTTPServer file, nothing changed -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI module does not parse data
I just read somewhere that the CGIHTTPServer module does not work on mac (which I am currently using), is this true? -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI module does not parse data
I am using execfile, setting stdin and stdout like this: sys.stdin = self.wfile sys.stdout = self.rfile execfile(filename) Its the same code used in the CGIHTTPServer module. I know that the python is executing corretly, a script with this content would work: print "" print "" print "" print "blah" print "" print " print "" print "test" print "" print "" but this would not (lets say i submitted a form with the value of test being "hello world"): import cgi form = cgi.FieldStorage() print form["test"] print "test" I would only be able to see "test", not "hello world" I am sure its not my browser -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI module does not parse data
Neither work -- http://mail.python.org/mailman/listinfo/python-list