Hi,
I am by no means a Python programmer, but I am dabbling with it and trying
to create a simple program that reports how many emails I have to
download. So far, using the poplib extension, I have got:
def checkEmail():
email = poplib.POP3('ma il.mydomain.ext ')
email.user('use r')
email.pass_('pa ssword')
number = email.stat()
email.quit()
if (number[0] == 0):
return "No new emails"
elif (number[0] == 1):
return "1 new email"
else:
string = str(number[0])
string += " new emails"
return string
Which is fine as long as the server doesn't timeout, or my machine isn't
doing something else that takes up all my bandwidth! Coming from a Java
background, I was wondering if there is anything similar in Python that
allows me to do something like:
try {
something();
}
catch (exception e) {
somethingelse() ;
}
Where if the "something( )" fails then the "somethingelse( )" will be ran
instead? Or is there another way that I can deal with timeouts in Python?
Cheers,
--
Dylan Parry http://www.webpageworkshop.co.uk - FREE Web tutorials and references 5 1822
On Sat, 10 Jul 2004 12:23:08 +0100, Dylan Parry <us****@dylanpa rry.com> wrote: try { something(); } catch (exception e) { somethingelse() ; }
I suggest you read http://www.python.org/doc/current/tut/node10.html,
and the rest of the tutorial too.
In short:
try:
code
goes
here
except FooError:
foofix()
chris
When I opened my eyes, it was Sat, 10 Jul 2004 12:23:08 +0100.
I couldn`t believe that Dylan Parry wrote: try { something(); } catch (exception e) { somethingelse() ; }
Where if the "something( )" fails then the "somethingelse( )" will be ran instead? Or is there another way that I can deal with timeouts in Python?
I don't know exactly how to deal with pop connections in this case, but
Python has very similar exception handling.
Read more about it at http://docs.python.org/tut/node10.html
--
_______________ _______________ _______________ _______________ ________
-=- Michal Chruszcz -=- Seen at http://prox.pl/~troll/?gallery -=-
To follow the path: look to the master, follow the master,
walk with the master, see through the master, become the master.
You can do it like this:
def checkEmail():
email = poplib.POP3('ma il.mydomain.ext ')
email.user('use r')
email.pass_('pa ssword')
numbers = email.list()
count = 0
for n in numbers:
count = count + 1
print "You have", str(count), "new e-mails in inbox."
email.quit()
Best regards Dag Hansteen
----- Original Message -----
From: "Dylan Parry" <us****@dylanpa rry.com>
Newsgroups: comp.lang.pytho n
To: <py*********@py thon.org>
Sent: Saturday, July 10, 2004 1:23 PM
Subject: Checking mail? Hi, I am by no means a Python programmer, but I am dabbling with it and trying to create a simple program that reports how many emails I have to download. So far, using the poplib extension, I have got: def checkEmail(): email = poplib.POP3('ma il.mydomain.ext ') email.user('use r') email.pass_('pa ssword') number = email.stat() email.quit() if (number[0] == 0): return "No new emails" elif (number[0] == 1): return "1 new email" else: string = str(number[0]) string += " new emails" return string Which is fine as long as the server doesn't timeout, or my machine isn't doing something else that takes up all my bandwidth! Coming from a Java background, I was wondering if there is anything similar in Python that allows me to do something like: try { something(); } catch (exception e) { somethingelse() ; } Where if the "something( )" fails then the "somethingelse( )" will be ran instead? Or is there another way that I can deal with timeouts in Python? Cheers, -- Dylan Parry http://www.webpageworkshop.co.uk - FREE Web tutorials and references -- http://mail.python.org/mailman/listinfo/python-list
In article <ma************ *************** **********@pyth on.org>,
Dag Hansteen <d-*****@online.no > wrote:
Dylan Parry wrote:
Thanks to all that replied. I have since read the tutorial pointed out,
and it seems to be exactly what I was looking for. Thanks again ;)
--
Dylan Parry http://www.webpageworkshop.co.uk - FREE Web tutorials and references This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Giobibo |
last post by:
I use the following code to send e-mails with PHP:
if(@mail(....))
{
//Send OK
} else {
//Send Bad
}
But how can I verify that a message was really sent (in case of "Sent
|
by: news |
last post by:
There's all kinds of ways to validate an email address to make sure
it's well formed and whatnot, but what about checking to see if it's a
valid e-mail account?
Like how you can use checkdnsrr() to check to see if a URL is valid.
I know finger used to be used at one time, no? But server block finger
requests, and I'm not sure many e-mail accounts out there are even
fingerable type accounts anyway.
Thanks for any suggestions!
|
by: shank |
last post by:
I'm trying to qualify email addresses. Is there any reason why the following
line would not catch an email address beginning with "www." ?
ElseIf Left(Session("em"),4) = "www." Then
I put in a dummy email address: www.mydomain@aol.com and it goes through....
<%=Left(Session("em"),4)%> does reflect "www."
why?
thanks!
|
by: Alistair |
last post by:
hey peoples.
I have a simple form (currently two fields) which is then passed to an ASP
page thats stores the data in a dbase
I have an error checking script which I can't get to work. the script is :
<script language="JavaScript">
|
by: Mikhail Teterin |
last post by:
Hello!
Consider the following simple accessor function:
typedef struct {
int i;
char name;
} MY_TYPE;
const char *
| |
by: Marlene Stebbins |
last post by:
I am entering numbers into my program from the command line. I want to
check whether they are > INT_MAX. Sounds simple, but I've discovered that
if(x <= INT_MAX)
{
/* use x in some calculation */
}
else
{
/* exit with error message */
|
by: Flip |
last post by:
I'm reading the O'Reilly's Progamming C# book and I have a question about
array bounds checking. On page 174, near the top, they show an example
where c# does indeed to array bounds checking cause the example shows a
System.IndexOutOfRangeException being thrown. However, in the very next
section (Jagged arrays) they have warning section that says "Java
programmers take note: While Java does bounds checking on array use, C# does
not." ...
|
by: lawrence k |
last post by:
I've made it habit to check all returns in my code, and usually, on
most projects, I'll have an error function that reports error messages
to some central location. I recently worked on a project where someone
suggested to me I was spending too much time writing error messages,
and that I was therefore missing the benefit of using a scripting
language. The idea, apparently, is that the PHP interpreter writes all
the error messages that are...
|
by: halcyon943 |
last post by:
have 4 folders that I watch and need to move files from to another
location. Three constraints:
-Finish time. Make sure the program stops transferring files at a
specific time
-Number of files transferred. Can only move a certain amount of files
per time period.
-Folders have a priority. The files have to be moved based on the
folder priority.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |