Justin Ezequiel | 1 Aug 05:03 2006
Picon

Re: question about headers and smtplib

When I first started with Python, I used MimeWriter to create E-mails.

Then some mail servers rejected my E-mails.

Some research (google) indicated (to me) that I needed a MIME-Version header.
(Can't recall now if I also needed a Content-Type header.)

Anyway, more research (Python docs) indicated that I should use the
email package instead.
I have been doing so since and have not had reports of anymore rejected E-mails.

Hope this helps.

>>> import email
>>> from email.MIMENonMultipart import MIMENonMultipart
>>> from email.Utils import formataddr
>>> format_addresses = lambda pairs: ', '.join([formataddr(pair) for
pair in pairs])
>>> msg = MIMENonMultipart('text', 'plain', charset='us-ascii')
>>> msg.set_payload('Foo Bar')
>>> msg.add_header('From', formataddr(('Justin', 'a <at> b.com')))
>>> msg.add_header('To', format_addresses([('Justin', 'a <at> b.com'),
('You', 'c <at> e.com')]))
>>> print msg.as_string()
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
From: Justin <a <at> b.com>
To: Justin <a <at> b.com>, You <c <at> e.com>

Foo Bar
(Continue reading)

Noufal Ibrahim | 1 Aug 07:52 2006
Picon

Debugging multithreaded programs in python

Greetings all,
    A friend here is trying to debug a rather badly written python program
which spawns off lots of threads here and there.  Are there any
frameworks that I can reccommend that would ease his pain?

    On a more general note, it seems rather strange that I can't quickly
google and find a debugger for multithreaded python programs. Python's
"batteries included" philosophy has always been very useful to me.
I've always managed to find what I need without any hassles. This is
the first exception. Any insights? Are there any decent ways to debug
a multi threaded program which make a debugger redundant?

Peace.
--

-- 
-NI

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Kent Johnson | 1 Aug 12:19 2006
Picon

Re: Debugging multithreaded programs in python

Noufal Ibrahim wrote:
> Greetings all,
>     A friend here is trying to debug a rather badly written python program
> which spawns off lots of threads here and there.  Are there any
> frameworks that I can reccommend that would ease his pain?
>   
winpdb claims to debug multi-threaded programs. I have found it useful 
for single-threaded programs, haven't tried it for m-t.
http://www.digitalpeers.com/pythondebugger/

Debugging m-t programs can be very hard. Placing a breakpoint can change 
the timing so a bug doesn't appear, or ruin a critical response time. 
Print statements can help.

You say the program is badly written, if it uses more threads than 
needed maybe the first step is to get rid of some of them. You could 
also look for subsystems that could be tested independently, perhaps 
using unittest.

Kent

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

shawn bright | 1 Aug 21:29 2006
Picon

Re: question about headers and smtplib

OK, this worked, please disregard my last. The online docs at python.org told me the answer to that one. Between their example and yours, i am able to make it work.
thanks a whole bunch !

shawn

On 7/31/06, Justin Ezequiel <justin.mailinglists <at> gmail.com> wrote:
When I first started with Python, I used MimeWriter to create E-mails.

Then some mail servers rejected my E-mails.

Some research (google) indicated (to me) that I needed a MIME-Version header.
(Can't recall now if I also needed a Content-Type header.)

Anyway, more research (Python docs) indicated that I should use the
email package instead.
I have been doing so since and have not had reports of anymore rejected E-mails.

Hope this helps.

>>> import email
>>> from email.MIMENonMultipart import MIMENonMultipart
>>> from email.Utils import formataddr
>>> format_addresses = lambda pairs: ', '.join([formataddr(pair) for
pair in pairs])
>>> msg = MIMENonMultipart('text', 'plain', charset='us-ascii')
>>> msg.set_payload('Foo Bar')
>>> msg.add_header('From', formataddr(('Justin', 'a <at> b.com')))
>>> msg.add_header('To', format_addresses([('Justin', 'a <at> b.com'),
('You', 'c <at> e.com')]))
>>> print msg.as_string()
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
From: Justin <a <at> b.com>
To: Justin <a <at> b.com>, You <c <at> e.com>

Foo Bar
>>>
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Christopher Spears | 2 Aug 00:27 2006
Picon

When am I ever going to use this?

I've been working through a tutorial:
http://www.ibiblio.org/obp/thinkCSpy/index.htm. 
Lately, I have been learning about abstract data types
(linked lists, stacks, queues, trees, etc.).  While I
do enjoy the challenge of creating these objects, I am
not sure what they are used for.

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Jordan Greenberg | 2 Aug 01:13 2006
Picon

Re: When am I ever going to use this?

Christopher Spears wrote:
> I've been working through a tutorial:
> http://www.ibiblio.org/obp/thinkCSpy/index.htm. 
> Lately, I have been learning about abstract data types
> (linked lists, stacks, queues, trees, etc.).  While I
> do enjoy the challenge of creating these objects, I am
> not sure what they are used for.
> 
> _______________________________________________
> Tutor maillist  -  Tutor <at> python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

They all have many uses. Priority Queues are used frequently in
operating systems for process scheduling, etc. Trees are fantastic for
most any searching application. Linked lists can be used for general
purpose storage (since unlike arrays, their size is not fixed.)

Learning data structures is really the one thing i wouldn't recommend
python for, just because the job is usually done for you. Why implement
a linked list, when we already have lists? Then Queues and Stacks are
trivial to implement once you've got lists.

If you're interested in learning more about data structures and their
uses, this looks like a good reference:
http://www.brpreiss.com/books/opus7/

-Jordan Greenberg

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Danny Yoo | 2 Aug 05:19 2006
Picon

Re: When am I ever going to use this?


On Tue, 1 Aug 2006, Christopher Spears wrote:

> I've been working through a tutorial: 
> http://www.ibiblio.org/obp/thinkCSpy/index.htm. Lately, I have been 
> learning about abstract data types (linked lists, stacks, queues, trees, 
> etc.).  While I do enjoy the challenge of creating these objects, I am 
> not sure what they are used for.

Hi Chris,

Let say that we are trying to write a navigator program, one that helps 
plan road trips.  One portion of the input to this program would be a map 
of the roads.

For example:

     map = [('a', 'b'),
            ('a', 'c'),
            ('c', 'f'),
            ('b', 'd'),
            ('d', 'e'),
            ('d', 'f')]

might represent the following street map:

     a ------ b
     |        |
     |        |
     c        d ------ e
      \       |
       \      |
        ----- f

where 'a', 'b', 'c', 'd', 'e', and 'f' are points of interest.  (I'm 
oversimplifying, but I hope you don't mind!)

A simple question we might ask this system is: how far is it from point 
'a' to point 'f'?  We'd like to ask the system:

     distance('a', 'f', map)

and be able to get 2, since there's a hop from 'a' to 'c', and from 'c' to 
'f'.

This problem is ripe to be attacked with an algorithm called 
"breadth-first search", and breadth-first search typically is implemented 
by keeping a queue of places.  We can talk about this in more detail if 
you'd like.

     http://en.wikipedia.org/wiki/Breadth-first_search

This is a long hand-wavy example for a short explanation: queues and and 
other data structures are "background" support tools: they themselves 
aren't so interesting, but they're the tools that a programmer often will 
reach for when working on non-string related problems.

If you remember Starcraft: there was a four-level queue of movement 
commands that you could set up by holding "shift" while navigating your 
forces.  You could also "queue" up production orders in factories.

Same data structure.  *grin*


Best of wishes!
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Marc Poulin | 2 Aug 05:58 2006
Picon

Re: When am I ever going to use this?

--- Christopher Spears <cspears2002 <at> yahoo.com> wrote:

> I've been working through a tutorial:
> http://www.ibiblio.org/obp/thinkCSpy/index.htm. 
> Lately, I have been learning about abstract data
> types
> (linked lists, stacks, queues, trees, etc.).  While
> I
> do enjoy the challenge of creating these objects, I
> am
> not sure what they are used for.
> 

You probably use a linked list every day and don't
even know it.

Do you ever hit the "Back" button on your web browser
to return to previous pages? The browser keeps a list
of the pages you've visited, all linked together, so
you can move backwards and forwards through the list.

Here is a great resource for learning about different
kinds of data structures:

http://www.nist.gov/dads

Regards,
Marc

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Michael P. Reilly | 2 Aug 15:45 2006
Picon

Re: When am I ever going to use this?

On 8/1/06, Christopher Spears <cspears2002 <at> yahoo.com> wrote:

I've been working through a tutorial:
http://www.ibiblio.org/obp/thinkCSpy/index.htm.
Lately, I have been learning about abstract data types
(linked lists, stacks, queues, trees, etc.).  While I
do enjoy the challenge of creating these objects, I am
not sure what they are used for.

Queues and linked lists are also used extensively inside operating systems.  Process lists are a large collections of queues organized in multiple queues implemented as linked lists and stored in one array.  File systems store files by accessing data blocks through linked "blocks" (not quite the same as your linked node structure) and access to the disks and the network are through queues.  Trees are used less often, but still very useful.  The directory structure (folders and files) on your disk are trees, the program to search your email may use a tree.  Stacks are often used for network protocols and program execution (every time you call a function, you are pushing something onto a stack).

How about real life uses for these structures.  Queues are one of the most natural structures from social life brought into computer science.  Insects, banks, highways, birds, even the lunch line in grade school used queues.  Stacks are the next, with stacks of books, papers, etc.  Trees are used for people's genealogies.  And you might used a linked list in a treasure hunt or for footnotes and bibliographies.  Even post-it notes are a form of mental linked list.

I hope this helps your understanding.
  -Arcege
--
There's so many different worlds,
So many different suns.
And we have just one world,
But we live in different ones.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Ron Phillips | 2 Aug 19:33 2006
Picon

Update BLOB with odbc

It must be easier than I am making it. 

--------------------
            sql = "UPDATE sa2.outfalls SET photo_content = %s WHERE
pppoint_id ='"+record[0].strip()+"';"
            newsql = sql%pstuff
            print newsql[:150]
            cursor.execute(newsql)
______________
the print newsql[:150] => "UPDATE sa2.outfalls SET photo_content =
ÿØÿá*EExif . . . "

and I get this error:

TypeError: argument 1 must be string without null bytes, not str

which sounds reasonable, but I don't know how to fix it. Is there some
escape thing that I'm missing?

Ron

 

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor


Gmane