473,379 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

A question about time

Hello all,

I have a list of servers which an application connects to. If the
connection fails, the application should mark the server as temporarily
unavailable, and should try to use the server again after x units of time.

In C, I would do this:

server.invalidUntil = time(NULL) + 5*60; // five minute delay

...and the check:

if(time(NULL) > server.invalidUtil)
{
// use server
}

So the whole thing very simple... But how do I do that in Python?

I have found datetime.datetime.now(), but I don't understand what
"format" it returns the time in. I assume it's an object of some sort..
But how do I do if I want the current time as an integer (unix
timestamp) in Python?
Jul 19 '05 #1
4 1464
On 2005-06-09, Jan Danielsson <ja************@gmail.com> wrote:
In C, I would do this:

server.invalidUntil = time(NULL) + 5*60; // five minute delay
In Python, I would do this:

server.invalidUntil = time.time() + 5*60 # five minute delay
..and the check:

if(time(NULL) > server.invalidUtil)
{
// use server
}
if time() > server.invalidUntil:
# user server
So the whole thing very simple...


Yup.

--
Grant Edwards grante Yow! Look!! Karl Malden!
at
visi.com
Jul 19 '05 #2
On 2005-06-09, Grant Edwards <gr****@visi.com> wrote:
On 2005-06-09, Jan Danielsson <ja************@gmail.com> wrote:
In C, I would do this:

server.invalidUntil = time(NULL) + 5*60; // five minute delay


In Python, I would do this:

server.invalidUntil = time.time() + 5*60 # five minute delay
..and the check:

if(time(NULL) > server.invalidUtil)
{
// use server
}


if time() > server.invalidUntil:
# user server


Um, that should have been

if time.time() > server.invalidUntil:
# use server
So the whole thing very simple...


Yup.


Not quite simple enough that I could get it right the first time.

--
Grant Edwards grante Yow! I need to discuss
at BUY-BACK PROVISIONS
visi.com with at least six studio
SLEAZEBALLS!!
Jul 19 '05 #3
Grant Edwards wrote:
In C, I would do this:

server.invalidUntil = time(NULL) + 5*60; // five minute delay


In Python, I would do this:

server.invalidUntil = time.time() + 5*60 # five minute delay


Ah. Well. Um. I feel like an idiot. I found datetime by accident, and
thought "it involves time, so this must be what I'm looking for!".

Anyway; thanks, that was exactly what I was looking for.
Jul 19 '05 #4
Jan Danielsson wrote:
Hello all,

I have a list of servers which an application connects to. If the
connection fails, the application should mark the server as temporarily
unavailable, and should try to use the server again after x units of time.

In C, I would do this:

server.invalidUntil = time(NULL) + 5*60; // five minute delay

..and the check:

if(time(NULL) > server.invalidUtil)
{
// use server
}

So the whole thing very simple... But how do I do that in Python?

I have found datetime.datetime.now(), but I don't understand what
"format" it returns the time in. I assume it's an object of some sort..
Everything in Python is an object. Objects can be inspected. The builtin
function repr(obj) gives a diagnostic and often compilable
REPResentation of the object, and str(obj) [think STRing] gives a
"pretty" picture. Sometimes repr() and str() produce the same results.
To understand what "format" it's in, read the documentation; in this
case, it's found at:

http://www.python.org/doc/2.4.1/lib/...-datetime.html

and play around with the command-line interpreter (example below) or
your favourite IDE.
import datetime
t1 = datetime.datetime.now(); t2 = t1 + datetime.timedelta(minutes=5) [somewhat later] t3 = datetime.datetime.now()
for x in t1, t2, t3: print str(x), repr(x) ....
2005-06-10 07:39:15.312000 datetime.datetime(2005, 6, 10, 7, 39, 15, 312000)
2005-06-10 07:44:15.312000 datetime.datetime(2005, 6, 10, 7, 44, 15, 312000)
2005-06-10 07:56:03.031000 datetime.datetime(2005, 6, 10, 7, 56, 3, 31000) t3 > t2

True
But how do I do if I want the current time as an integer (unix
timestamp) in Python?


The Python time module would be a good starting point.

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
7
by: Robin Becker | last post by:
We've been queried about the randomness of some filenames we're producing. I worked through and seemed to satisfy myself that random is being initialised from the system time in C time(&now)...
8
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
77
by: nospam | last post by:
Reasons for a 3-tier achitecture for the WEB? (NOTE: I said, WEB, NOT WINDOWS. DON'T shoot your mouth off if you don't understand the difference.) I hear only one reason and that's to switch a...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
5
by: eScrewDotCom | last post by:
www.eScrew.com eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is...
20
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to...
0
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
10
by: colin | last post by:
Hi, I profile my code and find its spending a lot of time doing implicit conversions from similar structures. the conversions are mainly things like this class Point { implicit conversion...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.