Uploading files
If you upload a file using the cgi module is there anyway to discover the file name that the user submitted as well as the file data? I've googled till I squint but I can't find anything. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Uploading files
Thanks for this. Peter "Robert Brewer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Peter Mott wrote: > If you upload a file using the cgi module is there any > way to discover the file name that the user submitted > as well as the file data? I've googled till I squint > but I can't find anything. Working example (for ASP, which uses BinaryRead to get the request stream): contentLength = int(env['CONTENT_LENGTH']) content, size = request.BinaryRead(contentLength) content = StringIO.StringIO(content) form = cgi.FieldStorage(content, None, "", env, True) content.close() for key in form: value = form[key] try: filename = value.filename except AttributeError: filename = None if filename: # Store filename, filedata as a tuple. self.requestParams[key] = (filename, value.value) else: for subValue in form.getlist(key): self.requestParams[key] = subValue Robert Brewer MIS Amor Ministries [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is this?
If I use concatenation + instead of multiplication * then I get the result that Jiri expected: >>> L = [[]] + [[]] >>> L[1].append(1) >>> L [[], [1]] With * both elements are changed: >>> L = [[]] * 2 >>> L[1].append(1) >>> L [[1], [1]] Alex Martelli says in his excellent Nutshell book that + is concatenation and that "n*S is the concatenation of n copies of S". But it seems not so. Surely, from a logical point of view, S + S should be the same as S * 2? Peter The excellent Martelli Python Nutshell says that multiplication S*n is "the concatenation of n copies of S" so S+S and S*2 would be expected to be the same. It seems though that they are not but that * creates a list Jiri Barton wrote: > Hi everyone, > > I have a problem with initialization. > a, b = [[]]*2 a.append(1) b > > [1] > > Why is this? Why does not this behave like the below: > > a, b = [[], []] a.append(1) b > > [] > > And, just to add to my confusion: > > [[]]*2 > > [[], []] > [[], []] == [[]]*2 > > True > > Thanks in advance for the explanation. > jbar > > > BTW, if it matters... > Python 2.4.1 (#2, Mar 30 2005, 20:41:35) > [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2 > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is this?
Matt Hammond wrote: > On Fri, 12 Aug 2005 12:57:38 +0100, Peter Mott <[EMAIL PROTECTED]> wrote: > >> If I use concatenation + instead of multiplication * then I get the >> result that Jiri expected: >> >> >>> L = [[]] + [[]] >> >>> L[1].append(1) >> >>> L >> [[], [1]] >> >> With * both elements are changed: >> >> >>> L = [[]] * 2 >> >>> L[1].append(1) >> >>> L >> [[1], [1]] >> >> Alex Martelli says in his excellent Nutshell book that + is >> concatenation and that "n*S is the concatenation of n copies of S". >> But it seems not so. Surely, from a logical point of view, S + S >> should be the same as S * 2? > > > S+S is the same as S*2, but L= [[]] + [[]] is not S+S. The two terms > being added are different instances of an empty list. You are > adding/concatenating two different object instances. But it is still true that [[]] + [[]] is not the same as [[]] * 2. In my usage anyway this means that "S+S is the same as S*2" is false. Because there are Python expressions for which it is falsfied. The problem I have is pretty philosophical I admit, but I don't think you do it justice. It's really about identity. Logically speaking identity is a congruence relation of a language, which means that if x=y is true then C(x) = C(y) will be true for any context C of the lanuage. Python is so regular that most of the time it follows this. But not with *. If you define C(x): def C(x): ... x[1].append(1) ... return x[0] then although [[]]+[[]] == [[]]*2 evaluates true C([[]]+[[]]) is different from C([[]]*2). So == is not a congruence in Python. Inbteresting that Phil Hunt just posted about 'Unify' which, if I understand it right, has the feature that provided expressions S and T are in the canonical "Storage Manager" format then == will be a congruence and hence an idenity. Cheers Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is this?
Duncan Booth wrote: > Peter Mott wrote: > > >>But it is still true that [[]] + [[]] is not the same as [[]] * 2. In my >>usage anyway this means that "S+S is the same as S*2" is false. Because >>there are Python expressions for which it is falsfied. >> >>The problem I have is pretty philosophical I admit, but I don't think >>you do it justice. It's really about identity. > > > So would you expect: > > random.seed(0) > random.random() + random.random() > > and: > > random.seed(0) > random.random() * 2 > > to be the same? The first call to random() in each case returns the same > result, but even though the source text is identical the second call > in the addition returns something different. It is just the same with the > lists. I don't see that this bears on what I said at all. Peter -- http://mail.python.org/mailman/listinfo/python-list
Docs. for logging module typo
The documentation for SMTPHandler say "The toaddrs should be a list of strings without domain names (That's what the mailhost is for)." which does not seem to be correct. The toaddr should be a list of strings like '[EMAIL PROTECTED]'. Peter -- http://mail.python.org/mailman/listinfo/python-list