Re: [Tutor] Processing unix style timestamp

2008-03-07 Thread Martin Walsh
Ravi Kondamuru wrote:
 Hi,
 
 I have a log file that prints the date and time in the following format:
 Mon Feb 11 01:34:52 CST 2008
 I am expecting multiple timezone entries (eg: PST, PDT and GMT) on the
 system running in America/Los Angeles time zone.
 I am looking for a way to internally store all the different timezone
 entries in GMT.
 I looked at datetime, but it seems slightly complex to work with non GMT
 timestamps.

 Any pointers?


If you are not offended by a 3rd-party module, then the string parser
included in the egenix mxDateTime module[1] is hard to beat. You may
even have it installed already, as it appears to be a popular dependency
of other 3rd-party modules, especially db adapters.

In [1]: import mx.DateTime

In [2]: d = mx.DateTime.DateFrom('Mon Feb 11 01:34:52 CST 2008')

In [3]: d
Out[3]: mx.DateTime.DateTime object for '2008-02-11 07:34:52.00' at
b788d138

In [4]: d.strftime('%a %b %d %H:%M:%S %Y')
Out[4]: 'Mon Feb 11 07:34:52 2008'

In [5]: d = mx.DateTime.DateFrom('Mon Feb 11 01:34:52 EST 2008')

In [6]: d.strftime('%a %b %d %H:%M:%S %Y')
Out[6]: 'Mon Feb 11 06:34:52 2008'

In [7]: d = mx.DateTime.DateFrom('Mon Feb 11 01:34:52 UTC 2008')

In [8]: d.strftime('%a %b %d %H:%M:%S %Y')
Out[8]: 'Mon Feb 11 01:34:52 2008'

HTH,
Marty

[1] http://www.egenix.com/products/python/mxBase/mxDateTime/

 thanks,
 Ravi.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Const on Python

2008-03-07 Thread Alan Gauld

Andreas Kostyrka [EMAIL PROTECTED] wrote
 Yes, the problem is, that these guys are anyway forced to have
 Python/Erlang developers on board, because of external opensource
 components they need to maintain.

And that one fact completely changes the economics and
thereby renders the lead position non viable.

 The problem here is that C++ is a strong mismatch for
 the job at hand.

 With strong mismatch I mean hear at least a magnitude
 more costs. During initial development and during maintenance.

I would be amazed at anuy project where a language made
an order of magnitude difference. The difference in moving
from assembler to VB is only about double (Thats the only
case wehere I have hard experrience). The problem is as
Fred Brooks stated in his essay No Silver Bullet that the
real costs in development are the intengibles - the time
spent thinking about theproblem/solution and dealing with people.
They far outweigh the time actually writing code. The average
project delivers around 20-100 lines of working code per
day. But you can type that in mechanically in half an hour
or less. The rest of the day is doing the stuff that really costs.

 Combined with the fact that the group cannot avoid
 learning Python andErlang, because external
 OSS projects used by them that they need to
 maintain and customize are written in Python  Erlang.

But this is the critical bt that was missing from the original
problem statement. If they use these languages anyway
then it makes sense to expand their code base. If these
were niche languages on a dying legacy then it makes
no sense to increase their use.

 But basically, your argument misses one important aspect:

 While most languages are equivalent in a theoretical sense ...
 Some languages can and do provide at least a magnitude
 of improvement compared to other languages.

I do dispute that and would be interested in any objective
figures that you have. All of the figures I've seen suggest the
total project cost impact of lanmguage choice is rarely
more than 10-20% of TCO

 Now add to the fact that software developement does
 not scale linearly, and the developer efficiency point
 becomes even more important.

But as projects get bigger language choice becomes
vanishingly small in the equation. Total developer cost in
any large projerct rarely exceeds 10% and of that the language
might make up 20% at most, so total impact of language
reduces to around 1-2% of TCO.

 If, by using some higher language a problem becomes
 so easy to solve that a single developer can deal with
 it, instead of say a 4 man team,than this is a critical aspect.

In that case I agree and at that small scale of project
then language choice is still a valid argument. And for
the kind of maintenance type feature fix we were discussing
the project is quite small. (Different if the language choice
requires a rewrite of the existing app of course!)

 It's kind like having a policy that all invoices must be in
 USD and are payed only in USD. Now two companies bid.

I'm sorry, I think I missed the connection in the analogy.

 (Philosophically, that's not even that bad a comparison, as learning
 Python is a rather minor thing for a reasonable good developer.

I totally agree, but unfortunately in the corporate world where
I work there are relatively few good developers - typically one
or two per team(around 6-10 people). Indeed only about half of
our developers are formally trained to University Engineering/Computer
Science type level. Many have craft certificvates from a trade school
and (even if just psychologicalluy) learning a new language is a
huge hurdle for them. They will insist on going ona weeks
training course etc. So yes, most good developers can pick up
Python in a couple of days from the web site, many corporate
programmers balk at such an idea. (This is one area where a
hobbyist turned pro is better than a journeyman programmer,
the hobbyist is much more likely to learn new skills out of
interests sake!)

 So no, I do not concur with you. I understand why it has
 some value, but you wouldn't argue that your company
 should use passenger cars to transport 100 tons of goods,
 just because all employee have a license to drive such,
 while truck drivers are slightly harder to come by, would
 you?

No, but I might suggest hiring some trailers or using an
external haulage company. It all depends on wheher its a
one-off job or a new line of work that we need to build skills.
So in this analogy we may need to buy a truck and start
training a number of staff to drive it, but thats expensive
so before doing so I'd look to see if it was one-off and at
the other options.

If in your example they need Python/Erlang anyway
that completely changes the economics.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] identifying the calling module/function

2008-03-07 Thread tetsuo2k6
Hello Tutor!

I am building a couple of scripts to manage a database for our company. 
The projects name is 'dgf'. As a lot of the functionality is used in 
more than one of these scripts, I moved this functionality to a module 
(dgf.py). It has several functions now.

Question: Is there an easy way to determine inside dgf.py where the 
function call came from?

dgf.py:

def yetanotherfunction():
Edit Me!
if function call came from script.py:
...

Something like that?




Regards
-paul
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] identifying the calling module/function

2008-03-07 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
 Hello Tutor!
 
 I am building a couple of scripts to manage a database for our company. 
 The projects name is 'dgf'. As a lot of the functionality is used in 
 more than one of these scripts, I moved this functionality to a module 
 (dgf.py). It has several functions now.
 
 Question: Is there an easy way to determine inside dgf.py where the 
 function call came from?

Why do you need to do this? It sounds like a design change is needed. 
Anyway the answer to your question is yes. This recipe should point you 
in the right direction:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Const on Python

2008-03-07 Thread Alan Gauld
Kent Johnson [EMAIL PROTECTED] wrote in

 (Jumping in against my better judgment :-)

:-)

 Hmm...sure, programming is not about typing, it is about figuring 
 out
 what to type. With Python the conceptual activity takes place at a
 higher level because - Python provides easy-to-use, high-level
 constructs like lists, dicts and first-order functions
 - Python doesn't require you to think about low-level details like
 const, private, getters and setters, braces, etc.

Yes but thats not the bit that takes time in my experience its
trying to understand the problem. What exactly am I trying to
do here? Is it a suimulation exercise, a database problem?
A real-time or networking issue? Should my solution include
security protection? If so how much? Can I use a standard
sort or do i need a custom algorithm? And if so what is it?

Designing an algorithm takes far longer than converting it to
code in any language.

 So Python speeds up the thinking part.

It speeds up the thinking abouit code bit, it doesn't help much
in the thining about the problem part.

 As far as the code, those 20-100 lines will do more if they are in
 Python than they will if they are in Java or C++.

Absolutely, thats why I write in Python and let the developers
do the Java stuff - life is too short! And thats why I am on a
Python mailing list not a Java one :-)

 I don't see an order of magnitude difference between
 Python and Java

And thats my point, particularly for bigger projects where
the problem complexity completely dominates the code
complexity. The coding time will derinitely improve and I
suspect you could get as high as 4 or 5 times but I doubt
if you'd ever really achieve an order of magnitude.

 have compared code samples, I have found Python code
 to be 20-60% the size of equivalent Java code.

In the few cases I've measured its been about 30% less
which nearly falls into your range. But the examples were very
small - all less than 1000 lines of Java - about as much
Java as I can bring myself to type!

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Creating a Python module to drive a robot

2008-03-07 Thread Shrutarshi Basu
Hi all,
I'd like to create a library of functions that would allow writing
Python scripts that would control a Hemisson robots via a serial
interface. I'll be using the pyserial module heavily, but I'm
wondering what would be the best way to approach this . Should I
create a Robot class and define everything as functions of the
class, such as a function for setting wheel speed, turning, reading
from sensors etc. Or is there some other way that would be easier for
a user? The project is meant for students who would be using
programming the robot as an Intro to programming, so it would be best
if users don't need to understand the details of OOP (or similar
concepts) to use the code quickly and reliably.
Thanks,
Basu
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Const on Python

2008-03-07 Thread Andreas Kostyrka

Am Freitag, den 07.03.2008, 21:13 + schrieb Alan Gauld:
 Yes but thats not the bit that takes time in my experience its
 trying to understand the problem. What exactly am I trying to
 do here? Is it a suimulation exercise, a database problem?
 A real-time or networking issue? Should my solution include
 security protection? If so how much? Can I use a standard
 sort or do i need a custom algorithm? And if so what is it?
 
 Designing an algorithm takes far longer than converting it to
 code in any language.

Right, but I've encountered it more than once in my professional life,
that the C++ guys where still trying to implement a simple algorithm,
while I was already finetuning a 2nd or 3rd generation of code.

And while it's not always a magnitude, and it's hard to measure, the few
times where I had to ability to compare (either because I was working
parallel or was replacing a failed C++ project), a magnitude seems to
describe the difference in development efficiency.

And this incremental improvements is the usual way, because without a
working prototype it's hard (and partially foolish) to decide which
parts of the design need improvements. (Remember, Good-Enough is the
relevant criteria when it comes to performance, so designing and
implementating the best algorithm from scratch does not make sense
(because often vastly simpler algorithms can provide the needed
performance, and again, it's really hard to guess which parts will be
critical for the performance)


 
  So Python speeds up the thinking part.
 
 It speeds up the thinking abouit code bit, it doesn't help much
 in the thining about the problem part.

You are forgetting a critical part. When speaking about coding, I'm
talking about writing the code, and getting it reasonable
bugfree/usable. And that's where Python shines. 

 
  As far as the code, those 20-100 lines will do more if they are in
  Python than they will if they are in Java or C++.
 
 Absolutely, thats why I write in Python and let the developers
 do the Java stuff - life is too short! And thats why I am on a
 Python mailing list not a Java one :-)
 
  I don't see an order of magnitude difference between
  Python and Java
 
 And thats my point, particularly for bigger projects where
 the problem complexity completely dominates the code
 complexity. The coding time will derinitely improve and I
 suspect you could get as high as 4 or 5 times but I doubt
 if you'd ever really achieve an order of magnitude.

Actually, the project where I achieved over a magnitude speedup was
highly complicated, involved partial reverse-engineering of binary
formats, embedding Python in a C++ app, refactoring the C++ app to
support multiple input handlers, doing a framework, optimizing,
portability to all kind of old UNIX boxes (the app had designed minimum
life cycle of 30 years), ...

The C++ guys gave up in disgust after more than 9 months into the
project. I had overtaken all their tries after one month. OTOH, if I'd
compare me with the designed time for the project (which was 12 months),
I have been only 2-3 times as fast as management had planned. In
practice, the C++ guys had massive problems, and if their progress had
been any measure, they would have taken at least 24-30 months getting
the project going. I know it's unnice, because the project had not
complete specifications (well, management claimed that it had all specs
needed, as it happens the more important half of the specs needed to be
reverse engineered. With data files in the MB range, manual decoding was
not an workable solution. But the experimenting wasn't that bad with for
me, while the C++ guy never reached the point where deciphering the
semantic meaning of the data was relevant to them.)

So I stand by the magnitude of developer efficiency difference. It's
not there for every project, but OTOH there are other projects where you
can get even more speedup. (Don't you have ever listened in on projects
that are infrastructure building that is just, well, a nonissue in
Python?)

And btw, it's not just Python, it just happens to me my default
language. Highlevel languages do pay, and it's starting to show slowly
in the industry. (Well, 1-2 years ago, my CV was optimized to for
non-Python experience. The last year, I've been usually able to pick
Python contracts without much of troubles, so Python is growing in
commercial settings.)

 
  have compared code samples, I have found Python code
  to be 20-60% the size of equivalent Java code.
 
 In the few cases I've measured its been about 30% less
 which nearly falls into your range. But the examples were very
 small - all less than 1000 lines of Java - about as much
 Java as I can bring myself to type!

Well, Java is already a relative high-level language, it's basically
safe, which helps debugging greatly, and is being made into something
even more highlevel by all kinds of IDE wizards. I wouldn't expect a
magnitude between Java/Python, just because Java is way nearer to Python

Re: [Tutor] Const on Python

2008-03-07 Thread Ricardo Aráoz
Alan Gauld wrote:

 Absolutely. I totally agree that moving an organization to Python
 or similar modern language is a sensible move for many applications.
 Only where very high performance or scaleability are required would
 Python (or similar) be inappropriate and even in the largest
 organisations that is a minority case. And of course web services
 provide a glue that any language can utilise to remove most
 issues of integration between apps in different languages
 (which used to be a very valid concern).
 
 My only dispute is the wisdom of introducing foreign code
 into an existing app. Andreas has already said in fact the
 new languages are already supported so that makes the
 scenario valid also.
 

Well, I guess it's about what you think a programmer is. I think if you 
are a true programmer you'll be good in ANY language (though you may 
have your preferences) and you'll be able to do 80% of your work in any 
language (and learn 80% of any language in a short time). So there would 
not really be such a problem with foreign code, the only issues I 
foresee are establishing proper coding rules for the company, that 
might take some time and produce some flaky code. As for integration 
between apps, if the languages are python and C/C++ it seems not to be a 
problem (never done it), there is :
http://www.python.org/doc/ext/intro.html

Ricardo
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Const on Python

2008-03-07 Thread Jeff Younker
On Mar 7, 2008, at 7:48 PM, Ricardo Aráoz wrote:

 Alan Gauld wrote:
 Well, I guess it's about what you think a programmer is. I think if  
 you
 are a true programmer you'll be good in ANY language (though you may
 have your preferences) and you'll be able to do 80% of your work in  
 any
 language (and learn 80% of any language in a short time). So there  
 would
 not really be such a problem with foreign code, the only issues I
 foresee are establishing proper coding rules for the company, that
 might take some time and produce some flaky code. As for integration
 between apps, if the languages are python and C/C++ it seems not to  
 be a
 problem (never done it), there is :
 http://www.python.org/doc/ext/intro.html

It's easy to learn the basic features of a language and to use those,  
but
developing fluency is much harder, and it takes a much longer time.

- Jeff Younker - [EMAIL PROTECTED] -

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor