I wrote this function to retrieve a list of items from a dictionary.
The first time it was called, it worked properly.
But every subsequent call returned the results of the prior call, plus
the results of the current call.
I was confused until I read in the docs that default arguments are
immuta
> The usual solution is:
>
> def get_prior_versions (item_id, priors=None):
> if priors is None:
> priors = []
Thanks!
--
http://mail.python.org/mailman/listinfo/python-list
> How about:
>
> def get_prior_versions (item_id, priors=None):
>"""Return a list of all prior item ids starting with this one"""
>global history_db # key = item id, value = prior item id
>prior_id = history_db[item_id]
>if not prior_id:
>return priors
>else:
>i
> You'll continue to be confused if you use that term. Python already
> has a specific use of the term “immutable”, and it doesn't apply
> here.
I was just following the terminology used in "A Byte of
Python" (which, that particular point aside, is a very good tutorial).
> Better to say: default
> How about this then:
>
> def get_prior_versions (item_id, priors=None):
>"""Return a list of all prior item ids starting with this one"""
>global history_db # key = item id, value = prior item id
>prior_id = history_db[item_id]
>if not prior_id:
>if priors:
>retur
I'm using the feedparser library to extract data from rss feed items.
After I wrote this function, which returns a list of item titles, I
noticed that most item attributes would be retrieved the same way,
i.e., the function would look exactly the same, except for the single
data.append line inside
On Nov 26, 2:30 pm, "Chris Rebert" <[EMAIL PROTECTED]> wrote:
> On Wed, Nov 26, 2008 at 11:13 AM, dpapathanasiou
>
> <[EMAIL PROTECTED]> wrote:
> > I'm using the feedparser library to extract data from rss feed items.
>
> > After I wrote th
If I define a dictionary where one or more of the values is also a
dictionary, e.g.:
my_dict={"a":"string", "b":"string", "c":{"x":"0","y":"1"},
"d":"string"}
How can I use the output of type() so I can do one thing if the value
is a string, and another if the value is a dictionary?
i.e., I'd li
I have some old Common Lisp functions I'd like to rewrite in Python
(I'm still new to Python), and one thing I miss is not having to
declare local variables.
For example, I have this Lisp function:
(defun random-char ()
"Generate a random char from one of [0-9][a-z][A-Z]"
(if (< 50 (random 10
> return chr( random.randrange(0, 26) + (97 if random.randrange(0,
> 100) > 50 else 65)
> or
>
> return chr( random.randrange(0, 26) + [26,97][random.randrange(0,
> 100) > 50]
Ah, thanks, these are the syntax examples I was looking for.
> but what's wrong with you original code?
I come
> Any time you port between languages, it's rarely a good idea to just
> convert code verbatim. For example:
>
> import random, string
> def random_char():
> return random.choice(string.ascii_letters + string.digits)
Good point, and thanks for the idiomatic Python example (I like the
concisen
I wrote a python script called xml_utils.py which parses xml using
minidom.
It works when it's run on its own, but when I try to import it and run
it inside a mod_python handler, I get this error:
File "../common/xml_utils.py", line 80, in parse_item_attribute
File "/usr/lib/python2.5/xml/dom
> His problem is therefore likely to be something completely different.
You are correct.
As per the earlier advice, I switched from mod_python to mod_wsgi but
I still see the same error:
[Mon May 11 10:30:21 2009] [notice] Apache/2.2.11 (Unix) mod_wsgi/2.4
Python/2.5.2 configured -- resuming no
For the record, and in case anyone else runs into this particular
problem, here's how resolved it.
My original xml_utils.py was written this way:
from xml.dom import minidom
def parse_item_attribute (item, attribute_name):
item_doc = minidom.parseString(item)
...
That version worked und
> Were you getting this issue with xml.dom showing on first request all
> the time, or only occasionally occurring? If the latter, were you
> running things in a multithreaded configuration and was the server
> being loaded with lots of concurrent requests?
It was the former.
> For your particul
I have two methods for writing binaries files: the first works with
data received by a server corresponding to a file upload, and the
second works with data sent as email attachments.
The odd thing is, they're not interchangeable: if I use the first one
to saved data parsed from an email attachmen
I'm using python to access an email account via POP, then for each
incoming message, save any attachments.
This is the function which scans the message for attachments:
def save_attachments (local_folder, msg_text):
"""Scan the email message text and save the attachments (if any)
in the local
> And where might we be able to see that stack trace?
This is it:
Exception: ('AttributeError', '', [' File "/opt/server/smtp/
smtps.py", line 213, in handle\ne
mail_replier.post_reply(recipient_mbox, \'\'.join(data))\n', ' File "/
opt/server/smtp/email_replier.py", l
ine 108, in post_repl
> Which is *really* difficult (for me) to read. Any chance of providing a
> "normal" traceback?
File "/opt/server/smtp/smtps.py", line 213, in handle
email_replier.post_reply(recipient_mbox, ''.join(data))
File "/opt/server/smtp/email_replier.py", line 108, in post_reply
save_attachm
On Oct 4, 10:27 am, dpapathanasiou
wrote:
> I'm using python to access an email account via POP, then for each
> incoming message, save any attachments.
>
> This is the function which scans the message for attachments:
>
> def save_attachments (local_folder, msg_text):
20 matches
Mail list logo