Naming dictionaries recursively

2007-08-17 Thread TYR
I'd like to do something like this; iterate through a file which
consists of data stored in dictionary format, one dict on each line,
and read each line into a new dict using one of the values in the dict
as its name...

for example:

stuff = open('data.txt')
 for eachLine in stuff:
  name{}
   name = eachLine
and then do something clever to extract the value of the key
(name) from the line and use it as the dictionary's name.

A line from data.txt would look like this: {'name' : Bob, 'species' :
Humboldt, 'colour' : red, 'habits' : predatory}. Aim is to call one of
them by name, and merge the values in that dictionary into a string
pulled from another source.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Naming dictionaries recursively

2007-08-17 Thread TYR

> So the tougher problem seems to be parsing those lines.  That is not a
> valid Python dictionary unless the names `Bob`, `Humboldt`, `red`, and
> `predatory` are not already defined.  So you can't just ``eval`` it.

In what way? {'key': val}, right?

Anyway, I can always change the format they go into the file in.




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Naming dictionaries recursively

2007-08-18 Thread TYR
That sounds like a solution. I think the core of the question is as
follows; if I was to call the dict() function for each line, thus
creating a dictionary, and then rename it to dict['name'], will there
be a namespace collision on the next loop when dict() is called again?
Obviously the first dictionary will still be there, as it still has a
refcount of 1; but if it gets overwritten, will the object that the
new name refers to be overwritten too?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python module for making Quicktime or mpeg movies from images

2007-10-12 Thread TYR
On Oct 11, 4:17 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
> jeremito wrote:
> > On Oct 11, 10:43 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> >> jeremito wrote:
> >>> My Python script makes a bunch of images that I want to use as frames
> >>> in a movie.  I've tried searching for a module that will take these
> >>> images and put them together in a Quicktime or mpeg movie, but haven't
> >>> found anything.  My images are currently pdfs, but I could make them
> >>> into just about anything if needed.
> >>> Is there a module, or example of how to do this?
> >>http://pymedia.org/
>
> >> Diez
>
> > That initially looked promising, but it looks like nobody is working
> > on it anymore and it doesn't compile on Mac.  (I should have mentioned
> > I am using a Mac.)  Any other suggestions?
>
> Not really a Python module but... run them
> through mencoder? (Haven't tried it but it
> seems to be saying it's possible).
>
> http://www.mplayerhq.hu/DOCS/man/en/mplayer.1.html#EXAMPLES%20OF%20ME...
>
> TJG

NodeBox; nodebox.org

GUI application that creates either PDFs or Quicktime vids from python
code. Unix/Linux/MacOS.

-- 
http://mail.python.org/mailman/listinfo/python-list


SQLite3; weird error

2007-10-29 Thread TYR
Has anyone else experienced a weird SQLite3 problem?

Going by the documentation at docs.python.org, the syntax is as
follows:
foo = sqlite3.connect(dbname) creates a connection object representing
the state of dbname and assigns it to variable foo. If dbname doesn't
exist, a file of that name is created.

To do anything with it, you then need to create a cursor object by
calling foo's method cursor (bar = foo.cursor).

You can now pass an SQL query or command to the DB by calling the
cursor object's method execute() with the SQL query as a quoted
statement.

(bar.execute("SELECT FROM squid WHERE squamous=True")

And then do other stuff.

Fine. When I call the cursor object, though, I get an AttributeError;
('builtinfunction_or_method object has no attribute 'execute')

Am running Python 2.5.1 on Mandriva Linux '08.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SQLite3; weird error

2007-10-29 Thread TYR
On Oct 29, 11:51 am, Duncan Booth <[EMAIL PROTECTED]>
wrote:
> TYR <[EMAIL PROTECTED]> wrote:
> > To do anything with it, you then need to create a cursor object by
> > calling foo's method cursor (bar = foo.cursor).
>
> Perhaps this would work better if you actually try calling foo's method?
>
> bar = foo.cursor()
>
> Without the parentheses all you are doing is assigning the method to a
> variable, not calling it.

Ah. Apologies for a silly question.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python web frameworks

2007-11-22 Thread TYR
Perhaps we need a pythonic FRONTEND.

If you're meant to be able to run java code in a browser vm; and
flash; and javascript...why not a reduced version of python?

I'm thinking a sandboxed interpreter, perhaps based on EmbeddedPython,
and a restricted set of classes; core logic, string and maths, some
good graphics stuff (perhaps similar to nodebox), SSL support,
filesystem access to a cache, network, xml, soap support. A standard
model for development defining graphic entities on one hand, and
controls on the other that the graphics are bound to. Perhaps a single
class for "RemoteControls" covering web service calls intended to be
bound to a graphical entity at one end and a mod_python function at
the other?

Force pre-compiling into .pyc; include an app to do interactive
interpreter in a browser and some basic IDE functions with each plugin
download.
-- 
http://mail.python.org/mailman/listinfo/python-list


Extracting data from dump file

2007-11-23 Thread TYR
I have a large dump file that originated in a MySQL db; I need to get
it into an SQLite file.

Various options are suggested around the web; none of them seem to
work (most failing to import the thing in the first place). So I
removed the assorted taggery from each end, leaving just a big text
file taking the following format:

('value', 'value', 'value, 'value'),
('value','value','value','value')...

I planned to find some way of splitting the thing at the commas
outside the bracketed groups, thus giving me a list of tuples; then I
could of course CREATE TABLE foo VALUES  '1', '2, '3', '4' and then
iterate through the list INSERTing INTO.

Then my problems began; I tried using the python csv method, replacing
the string ),( with \t and then using \t as the delimiter. First
problem; there's a size limit coded into the module. No problem, use
csv.field_size_limit() to alter it. Problem; it doesn't actually parse
at all, just sends the whole thing as a string and the SQL INSERT
fails with a "not enough args" error.

Tried using string.split() and re.split(data, r'\t'); first gave the
same error, second failed with a "too many named groups" error. Tried
using ; as a delimiter and going back to csv; this fails to match
the ; for some reason. Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python web frameworks

2007-11-23 Thread TYR
On Nov 23, 4:22 am, SamFeltus <[EMAIL PROTECTED]> wrote:
> """Perhaps we need a pythonic FRONTEND. """
>
> Should have happened years ago.

Python Internet Environment: PIE.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python web frameworks

2007-11-29 Thread TYR
On Nov 29, 3:15 pm, Aaron Watters <[EMAIL PROTECTED]> wrote:
> On Nov 22, 11:22 pm, SamFeltus <[EMAIL PROTECTED]> wrote:
>
> > """Perhaps we need a pythonic FRONTEND. """
>
> > Should have happened years ago.
>
> It did.  Mark Hammond embedded Python under MSIE about
> the same time javascript and java applets came along (94, maybe?)
> It didn't fly because of political and marketing problems,
> I think.  One technical killer was that C-Python can
> be crashed relatively easily by malicious code, and
> browser providers don't like that too much.  Also, the
> stuff you need to do to make it crash proof would make
> the interpreter a lot slower (which may be why javascript
> is pretty slow).
>
>   -- Aaron Watters
>
> ===http://www.xfeedme.com/nucular/pydistro.py/go?FREETEXT=msie+de-facto+...

Time for another go, perhaps, seeing as the web has become the world's
default user interface?
-- 
http://mail.python.org/mailman/listinfo/python-list


time.strptime() undocumented difference python 2.5.1>2.5.2

2009-03-25 Thread TYR
A server that runs one of my programs was upgraded to Debian Lenny
last night, which moved it from Python 2.4.4 to 2.5.2. This caused
immediate trouble. At one point, data is parsed from a Web page, and
among other things a time date group is collected. This is in a nice
human readable format, but I want it in RFC 822 format because it's
going to be used in an outbound GeoRSS feed and it's a requirement.

So the time group is split up with a regex, merged into one string,
and fed to time.strptime() with a fitting format, then passed to
Utils.formatdate() and used. The time group looks like this:
25/03/2009 21:05:00

Code:
if airline not in whitelist:
  retime = re.split('[-\s:/]', rawtime)
  timeinput = ''.join(retime)
  t = time.strptime(timeinput, "%d %m %Y %H %M %S")
  timeout = Utils.formatdate(t)

Error:
Traceback (most recent call
last):
  File "/home/yorksranter/vfeed-data/bothv7.py", line 46, in

t = time.strptime(timeinput, "%d %m %Y %H %M
%S")
  File "/usr/lib/python2.5/_strptime.py", line 330, in
strptime
(data_string,
format))
ValueError: time data did not match format:  data=25032009210500  fmt=
%d %m %Y %H %M %S

Weirdness:

Python 2.5.2 (r252:60911, Jan  4 2009, 21:59:32) #the
server
[GCC 4.3.2] on
linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> timeinput = '25032009210500'
>>> import time
>>> t = time.strptime(timeinput, "%d %m %Y %H %M %S")
Traceback (most recent call
last):
  File "", line 1, in

  File "/usr/lib/python2.5/_strptime.py", line 330, in
strptime
(data_string,
format))
ValueError: time data did not match format:  data=25032009210500  fmt=
%d %m %Y %H %M %S

But

Python 2.5.1 (r251:54863, Jan 10 2008, 18:01:57) #the laptop
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> timeinput = '25032009210500'
>>> t = time.strptime(timeinput, "%d %m %Y %H %M %S")
>>> print t
(2009, 3, 25, 21, 5, 0, 2, 84, -1)

Docs (http://docs.python.org/library/time.html#time.strptime) say:
Parses a string representing a time according to a format. If I send
it through str() to make absolutely sure it is a string I get the same
error.

I note from the changelog that there was a change affecting
time.strptime()...(http://www.python.org/download/releases/2.5.2/
NEWS.txt)

- Bug #1730389: Have time.strptime() match spaces in a format argument
with
  ``\s+`` instead of ``\s*``.

- Bug #1290505: Properly clear time.strptime's locale cache when the
locale
  changes between calls.  Backport of r54646 and r54647.

I don't see that either of these should break it, but it's got to be a
suspect.
--
http://mail.python.org/mailman/listinfo/python-list


Re: time.strptime() undocumented difference python 2.5.1>2.5.2

2009-03-25 Thread TYR
On Mar 25, 7:38 pm, MRAB  wrote:
> TYR wrote:
> > A server that runs one of my programs was upgraded to Debian Lenny
> > last night, which moved it from Python 2.4.4 to 2.5.2. This caused
> > immediate trouble. At one point, data is parsed from a Web page, and
> > among other things a time date group is collected. This is in a nice
> > human readable format, but I want it in RFC 822 format because it's
> > going to be used in an outbound GeoRSS feed and it's a requirement.
>
> > So the time group is split up with a regex, merged into one string,
> > and fed to time.strptime() with a fitting format, then passed to
> > Utils.formatdate() and used. The time group looks like this:
> > 25/03/2009 21:05:00
>
> > Code:
> > if airline not in whitelist:
> >                  retime = re.split('[-\s:/]', rawtime)
> >                  timeinput = ''.join(retime)
> >                  t = time.strptime(timeinput, "%d %m %Y %H %M %S")
> >                  timeout = Utils.formatdate(t)
>
> > Error:
> > Traceback (most recent call
> > last):
> >   File "/home/yorksranter/vfeed-data/bothv7.py", line 46, in
> > 
> >     t = time.strptime(timeinput, "%d %m %Y %H %M
> > %S")
> >   File "/usr/lib/python2.5/_strptime.py", line 330, in
> > strptime
> >     (data_string,
> > format))
> > ValueError: time data did not match format:  data=25032009210500  fmt=
> > %d %m %Y %H %M %S
>
> > Weirdness:
>
> > Python 2.5.2 (r252:60911, Jan  4 2009, 21:59:32) #the
> > server
> > [GCC 4.3.2] on
> > linux2
> > Type "help", "copyright", "credits" or "license" for more
> > information.
> >>>> timeinput = '25032009210500'
> >>>> import time
> >>>> t = time.strptime(timeinput, "%d %m %Y %H %M %S")
> > Traceback (most recent call
> > last):
> >   File "", line 1, in
> > 
> >   File "/usr/lib/python2.5/_strptime.py", line 330, in
> > strptime
> >     (data_string,
> > format))
> > ValueError: time data did not match format:  data=25032009210500  fmt=
> > %d %m %Y %H %M %S
>
> > But
>
> > Python 2.5.1 (r251:54863, Jan 10 2008, 18:01:57) #the laptop
> > [GCC 4.2.1 (SUSE Linux)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> import time
> >>>> timeinput = '25032009210500'
> >>>> t = time.strptime(timeinput, "%d %m %Y %H %M %S")
> >>>> print t
> > (2009, 3, 25, 21, 5, 0, 2, 84, -1)
>
> > Docs (http://docs.python.org/library/time.html#time.strptime) say:
> > Parses a string representing a time according to a format. If I send
> > it through str() to make absolutely sure it is a string I get the same
> > error.
>
> > I note from the changelog that there was a change affecting
> > time.strptime()...(http://www.python.org/download/releases/2.5.2/
> > NEWS.txt)
>
> > - Bug #1730389: Have time.strptime() match spaces in a format argument
> > with
> >   ``\s+`` instead of ``\s*``.
>
> > - Bug #1290505: Properly clear time.strptime's locale cache when the
> > locale
> >   changes between calls.  Backport of r54646 and r54647.
>
> > I don't see that either of these should break it, but it's got to be a
> > suspect.
>
> I think it's due to bug #1730389. This says that a space in the format
> string should match _at least one_ space in the string it's parsing.
> Your format is "%d %m %Y %H %M %S" (it contains spaces) but your string
> is "25032009210500" (it doesn't contain spaces), hence the failure.
>
> I suggest you change:
>
>      timeinput = ''.join(retime)
>
> to:
>
>      timeinput = ' '.join(retime)
>
> It'll make the string a little clearer anyway: "25 03 2009 21 05 00".

Thank you; that was indeed the issue, which helped me discover that
email.Utils.formatdate() stopped accepting struct_times in the same
change and started wanting floats.
--
http://mail.python.org/mailman/listinfo/python-list


Strange thing with types

2008-05-29 Thread TYR
I'm doing some data normalisation, which involves data from a Web site
being extracted with BeautifulSoup, cleaned up with a regex, then
having the current year as returned by time()'s tm_year attribute
inserted, before the data is concatenated with string.join() and fed
to time.strptime().

Here's some code:
timeinput = re.split('[\s:-]', rawtime)
print timeinput #trace statement
print year #trace statement
t = timeinput.insert(2, year)
print t #trace statement
t1 = string.join(t, '')
timeobject = time.strptime(t1, "%d %b %Y %H %M")

year is a Unicode string; so is the data in rawtime (BeautifulSoup
gives you Unicode, dammit). And here's the output:

[u'29', u'May', u'01', u'00'] (OK, so the regex is working)
2008 (OK, so the year is a year)
None (...but what's this?)
Traceback (most recent call last):
  File "bothv2.py", line 71, in 
t1 = string.join(t, '')
  File "/usr/lib/python2.5/string.py", line 316, in join
return sep.join(words)
TypeError
--
http://mail.python.org/mailman/listinfo/python-list


Re: Strange thing with types

2008-05-29 Thread TYR
On May 29, 2:23 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> TYR wrote:
> > I'm doing some data normalisation, which involves data from a Web site
> > being extracted with BeautifulSoup, cleaned up with a regex, then
> > having the current year as returned by time()'s tm_year attribute
> > inserted, before the data is concatenated with string.join() and fed
> > to time.strptime().
>
> > Here's some code:
> > timeinput = re.split('[\s:-]', rawtime)
> > print timeinput #trace statement
> > print year #trace statement
> > t = timeinput.insert(2, year)
> > print t #trace statement
> > t1 = string.join(t, '')
> > timeobject = time.strptime(t1, "%d %b %Y %H %M")
>
> > year is a Unicode string; so is the data in rawtime (BeautifulSoup
> > gives you Unicode, dammit). And here's the output:
>
> > [u'29', u'May', u'01', u'00'] (OK, so the regex is working)
> > 2008 (OK, so the year is a year)
> > None (...but what's this?)
> > Traceback (most recent call last):
> >   File "bothv2.py", line 71, in 
> > t1 = string.join(t, '')
> >   File "/usr/lib/python2.5/string.py", line 316, in join
> > return sep.join(words)
> > TypeError
>
> First - don't use module string anymore. Use e.g.
>
> ''.join(t)
>
> Second, you can only join strings. but year is an integer. So convert it to
> a string first:
>
> t = timeinput.insert(2, str(year))
>
> Diez

Yes, tm_year is converted to a unicode string elsewhere in the program.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Strange thing with types

2008-05-29 Thread TYR
On May 29, 2:24 pm, alex23 <[EMAIL PROTECTED]> wrote:
> On May 29, 11:09 pm, TYR <[EMAIL PROTECTED]> wrote:
>
>
>
> > I'm doing some data normalisation, which involves data from a Web site
> > being extracted with BeautifulSoup, cleaned up with a regex, then
> > having the current year as returned by time()'s tm_year attribute
> > inserted, before the data is concatenated with string.join() and fed
> > to time.strptime().
>
> > Here's some code:
> > timeinput = re.split('[\s:-]', rawtime)
> > print timeinput #trace statement
> > print year #trace statement
> > t = timeinput.insert(2, year)
> > print t #trace statement
> > t1 = string.join(t, '')
> > timeobject = time.strptime(t1, "%d %b %Y %H %M")
>
> > year is a Unicode string; so is the data in rawtime (BeautifulSoup
> > gives you Unicode, dammit). And here's the output:
>
> > [u'29', u'May', u'01', u'00'] (OK, so the regex is working)
> > 2008 (OK, so the year is a year)
> > None (...but what's this?)
> > Traceback (most recent call last):
> >   File "bothv2.py", line 71, in 
> > t1 = string.join(t, '')
> >   File "/usr/lib/python2.5/string.py", line 316, in join
> > return sep.join(words)
> > TypeError
>
> list.insert modifies the list in-place:
>
> >>> l = [1,2,3]
> >>> l.insert(2,4)
> >>> l
>
> [1, 2, 4, 3]
>
> It also returns None, which is what you're assigning to 't' and then
> trying to join.
>
> Replace your usage of 't' with 'timeinput' and it should work.

Thank you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Making wxPython a standard module?

2008-06-17 Thread TYR
>"  b = wx.Button(label="Click Me", action=myCallable)

>Instead you used to have to create a button and then call
>some utility function in some other object to bind that
>button to a callable (IIRC this was one place where Window
>IDs could be used).  Now, the button actually has a method
>you can use.  It's still an extra step...

That looks quite a lot like the behaviour of PythonForS60's appuifw
class. Frex, a menu:

appuifw.app.menu = [(u'Octopus', getfish(octopus)), (u'Cuttlefish',
getfish(cuttlefish)), (u'Squid', ((u'Humboldt', getfish(humboldt)),
(u'Giant', getfish(giantsquid)), (u'Colossal', getfish(colossal)))]

gives you a menu with three options, the last of which has three sub-
options, all of which call your getfish() function with their value.
--
http://mail.python.org/mailman/listinfo/python-list


Strange re problem

2008-06-20 Thread TYR
OK, this ought to be simple. I'm parsing a large text file (originally
a database dump) in order to process the contents back into a SQLite3
database. The data looks like this:

'AAA','PF',-17.4167,-145.5,'Anaa, French Polynesia','Pacific/
Tahiti','Anaa';'AAB','AU',-26.75,141,'Arrabury, Queensland,
Australia','?','?';'AAC','EG',31.1333,33.8,'Al Arish,
Egypt','Africa/Cairo','El Arish International';'AAE','DZ',
36.8333,8,'Annaba','Africa/Algiers','Rabah Bitat';

which goes on for another 308 lines. As keen and agile minds will no
doubt spot, the rows are separated by a ; so it should be simple to
parse it using a regex. So, I establish a db connection and cursor,
create the table, and open the source file.

Then we do this:

f = file.readlines()
biglist = re.split(';', f)

and then iterate over the output from re.split(), inserting each set
of values into the db, and finally close the file and commit
transactions. But instead, I get this error:

Traceback (most recent call last):
  File "converter.py", line 12, in 
biglist = re.split(';', f)
  File "/usr/lib/python2.5/re.py", line 157, in split
return _compile(pattern, 0).split(string, maxsplit)
TypeError: expected string or buffer

Is this because the lat and long values are integers rather than
strings? (If so, any ideas?)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Strange re problem

2008-06-20 Thread TYR
>How do you propose to parse that string into a "set of values"?  Can
>you rely there being data commas only in the 5th field, or do you need
>a general solution? What if (as Peter remarked) there is a ';' in the
>data? What if there's a "'" in the data (think O'Hare)?

My plan was to be pointlessly sarcastic.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Strange re problem

2008-06-21 Thread TYR
On Jun 20, 3:35 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Jun 20, 6:01 am, TYR <[EMAIL PROTECTED]> wrote:

Thank you very much. This pyparsing module looks damned useful.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mobile Devices

2008-06-25 Thread TYR
On Jun 25, 10:38 am, rodmc <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have been scouting around online for information on how to use
> Python and a GUI toolikit to develop mobile devices. At present I am
> using wxPython for desktop apps and would like to continue using that
> if possible. Anyway, I would like to know what people would recommend
> for developing mobile applications which can run on Windows Mobile and
> Mac OS X (iPhone etc)? It would also be cool if the same apps could
> run where possible (or atleast part of them) on desktop machines as
> well.
>
> Any tips, experiences etc welcome. This is really to stimulate some
> general discussion.
>
> Best,
>
> rod

I know nothing of running Python on WinMob devices, but I see no
reason why it shouldn't be possible. However MS doesn't, as far as I
know, support it or provide any tools/sdks/ecosystem services. Apple
has its own rather closed ecosystem for iPhone support, but as
everyone knows there is a vigorous hacker community doing unofficial
things with them. However, I'm not aware of any python activity.

Most mobile Python activity is in the nokiasphere; there is a Nokia-
backed version of Python for S60 devices, which is fully supported,
includes Python libs that wrap the devices' native functionality up to
and including N95 accelerometers, and has a desktop mobile device
emulator for convenience. However, wxPython wouldn't really be
relevant as pyS60 includes its own native GUI toolkit, appuifw; no
reason why you couldn't install the module and try, though, but using
appuifw does ensure that your GUI will look like all the other stuff
on the phone.

It won't, of course, work on your PC.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How is GUI programming in Python?

2008-04-16 Thread TYR
Who cares? Everyone does their GUI in a browser these days - keep up,
Dad. What we need is a pythonic front end.

/troll
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding out the number of rows in a CSV file [Resolved]

2008-08-27 Thread TYR
Use csv.DictReader to get a list of dicts (you get one for each row,
with the values as the vals and the column headings as the keys) and
then do a len(list)?

--
http://mail.python.org/mailman/listinfo/python-list


Re: JSON from Python mysqldb

2008-08-27 Thread TYR
There's always the naive option.

query = ('species', 'lifestyle', 'coolness', 'tentacles=>8')
db.execute('SELECT %s, %s, %s % FROM creatures WHERE %s;' % query)
record = dict(zip((query), (db.fetchall()))
array = '''{
 '''
for k,v in record:
  array.append('"(k)":"(v)"')
array.append('''
}''')




--
http://mail.python.org/mailman/listinfo/python-list


Re: JSON from Python mysqldb

2008-08-27 Thread TYR
On Aug 27, 2:37 pm, TYR <[EMAIL PROTECTED]> wrote:
> There's always the naive option.
>
> query = ('species', 'lifestyle', 'coolness', 'tentacles=>8')
> db.execute('SELECT %s, %s, %s % FROM creatures WHERE %s;' % query)
> record = dict(zip((query), (db.fetchall()))
> array = '''{
>              '''
> for k,v in record:
>   array.append('"(k)":"(v)"')
> array.append('''
>                 }''')

Actually, don't.

query = ('species', 'lifestyle', 'coolness')
limit = ('tentacles=>8')
--
http://mail.python.org/mailman/listinfo/python-list


urllib2 content-type headers

2009-06-21 Thread TYR
I have a little application that wants to send data to a Google API.
This API requires an HTTP header to be set as follows:

Authorization: GoogleLogin auth=[value of auth token goes here]

Unfortunately, I'm getting nothing but 400 Bad Requests. I suspect
this is due to an unfeature of urllib2. Notably, although you can use
urllib2.Request's add_header method to append a header, the
documentation (http://docs.python.org/library/urllib2.html) says that:

remember that a few standard headers (Content-Length, Content-Type and
Host) are added when the Request is passed to urlopen() (or
OpenerDirector.open()).

And:

Note that there cannot be more than one header with the same name, and
later calls will overwrite previous calls in case the key collides.

To put it another way, you cannot rely on Content-Type being correct
because whatever you set it to explicitly, urllib2 will silently
change it to something else which may be wrong, and there is no way to
stop it. What happened to "explicit is better than implicit"?
-- 
http://mail.python.org/mailman/listinfo/python-list