Re: [Tutor] A Million Sevens

2006-11-18 Thread Alan Gauld
"Chris Hengge" <[EMAIL PROTECTED]> wrote

> Not that it changes your reply, but just for my own sanity:
> int('7' * 10 ** 6) <- does this not just type-cast a char into an 
> int?

Chris, I suspect you may come from a C background?

Type *conversion* in Python is very differentb from
type *casting* in C.

type casting says take the binary data stored at x and treat
it as a different type, thats pretty well instantaneous.

typecasting (int)'77' in C will not give you the number
77(decimal) but will give you the hex value 0x3737
which is entirely different (actually 14135!).

Now typecasting in C++ is somewhat different, especially
if you use dynamic casts and that can involve converting
the type rather than just treating the existing data differently...
Because of this confusion over the word cast I prefer
to refer to Python as doing type conversions.

Type conversion says take the data entity in variable x
and change its internal structure to the representation
of a new type. Thats a much more complex operation.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


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


[Tutor] exception not raised XP file ?

2006-11-18 Thread Dave S
Due to some sloppy programming on a commercial app :) I have a problem.

I have some directories on an XP machine, I need to know which of these 
directories (*.cab_tmp) contains a file that that is being accessed by 
another XP program. 

I set it up so that a known file (SIZES.DBF) in a known directory is being 
accessed by said program.

If I attempt to open said file with wordpad I get the error 'the 
document ...SIZES.DBF... is being used by another application and cannot be 
accessed !'

So I wrote the following code 


posDirNames = filter((lambda x: x[-7:] == 'cab_tmp'), 
os.listdir(gsrpath))
for dirName in posDirNames:
   
print dirName

for fileName in os.listdir(gsrpath + '/' + dirName):

try:
file = gsrpath + '/' + dirName + '/' + fileName
if fileName == 'SIZES.DBF': print file,
f = open(file, 'w')
f.close()
except:
print 'xx',
print fileName, sys.exc_info()


Expecting it to raise an exception when it hits SIZES.DBF because I am opening 
the file to write - no exception is raised. I know it is scanning SIZES.DBF 
because my if statement picks it up.

Any ideas ?

Dave

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


[Tutor] A question about: Adding seconds to datetime object

2006-11-18 Thread Asrarahmed Kadri

Hi ,


I have a question:

Is it possible to add seconds to a datetime object and get the result as a
new datetime object. I mean when we keep adding, for example, 3600 seconds,
the date will get changed after 24 iterations. Is it possible to carry out
such an operation ?

TIA.
Best Regards,
Asrarahmed

--
To HIM you shall return.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A question about: Adding seconds to datetime object

2006-11-18 Thread Kent Johnson
Asrarahmed Kadri wrote:
> Hi ,
>  
>  
> I have a question:
>  
> Is it possible to add seconds to a datetime object and get the result as 
> a new datetime object. I mean when we keep adding, for example, 3600 
> seconds, the date will get changed after 24 iterations. Is it possible 
> to carry out such an operation ?

Sure, just add a datetime.timedelta to the datetime object:

In [1]: from datetime import datetime, timedelta

In [2]: d=datetime.now()

In [3]: d
Out[3]: datetime.datetime(2006, 11, 18, 9, 47, 31, 187000)

In [4]: delta=timedelta(seconds=3600)

In [5]: d+delta
Out[5]: datetime.datetime(2006, 11, 18, 10, 47, 31, 187000)

Kent

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


Re: [Tutor] OT: Vim was: free IDE for Python?

2006-11-18 Thread Chris Lasher
On 11/17/06, Mike Hansen <[EMAIL PROTECTED]> wrote:
>
> Here's what I'm doing. Not sure if it's that helpful to you.
>
> I use the mini-buffer explorer plug-in and the taglist plugin.
>
> set smartindent
>
> " shuts off the annoying "#" comment in smartindent to jump to col 1
> inoremap # X#
>
> autocmd BufRead *.py set smartindent
> cinwords=if,elif,else,for,while,try,except,finally,def,class
>

Instead of using smartindent + cinwords + the inoremap hack, simply
use "filetype indent on". This was recommended to me on #Vim IRC
channel. This takes care of the silly # problem with smartindent and
is considered the best way for getting proper indentation in Python.
Give it a try!

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


Re: [Tutor] exception not raised XP file ?

2006-11-18 Thread Roel Schroeven
Dave S schreef:
> Due to some sloppy programming on a commercial app :) I have a problem.
> 
> I have some directories on an XP machine, I need to know which of these 
> directories (*.cab_tmp) contains a file that that is being accessed by 
> another XP program.

To me the easiest solution seems to be using Process Explorer or Handle 
from Sysinternals (at http://www.microsoft.com/technet/sysinternals 
currently).

At first sight your Python solution looks good to me; I don't know why 
it doesn't work.

Another approach I have used in the past is trying to rename the 
directory instead of trying to open a file in that directory: Windows 
cannot rename the directory when some program has a file open in that 
directory. At least that's my experience.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven

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


Re: [Tutor] exception not raised XP file ?

2006-11-18 Thread Dave S
On Saturday 18 November 2006 16:08, Roel Schroeven wrote:
> Dave S schreef:
> > Due to some sloppy programming on a commercial app :) I have a problem.
> >
> > I have some directories on an XP machine, I need to know which of these
> > directories (*.cab_tmp) contains a file that that is being accessed by
> > another XP program.
>
> To me the easiest solution seems to be using Process Explorer or Handle
> from Sysinternals (at http://www.microsoft.com/technet/sysinternals
> currently).
>
> At first sight your Python solution looks good to me; I don't know why
> it doesn't work.
>
> Another approach I have used in the past is trying to rename the
> directory instead of trying to open a file in that directory: Windows
> cannot rename the directory when some program has a file open in that
> directory. At least that's my experience.

Thanks for the tip :)

Is it just me - I seem to run into a lot of weird behaviour in windows (but 
then I am a Linux Junky :)

Dave

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


Re: [Tutor] A question about: Adding seconds to datetime object

2006-11-18 Thread Asrarahmed Kadri

Thanks.

It means, you take a datetime object and then using a timedelta object,
perform the addition, the language takes care of changing the date if the
time crosses midnight.
WOW... this makes life a lot easier..

Have a brilliant evening.
Best Regards,
Asrarahmed Kadri


On 11/18/06, Kent Johnson <[EMAIL PROTECTED]> wrote:


Asrarahmed Kadri wrote:
> Hi ,
>
>
> I have a question:
>
> Is it possible to add seconds to a datetime object and get the result as
> a new datetime object. I mean when we keep adding, for example, 3600
> seconds, the date will get changed after 24 iterations. Is it possible
> to carry out such an operation ?

Sure, just add a datetime.timedelta to the datetime object:

In [1]: from datetime import datetime, timedelta

In [2]: d=datetime.now()

In [3]: d
Out[3]: datetime.datetime(2006, 11, 18, 9, 47, 31, 187000)

In [4]: delta=timedelta(seconds=3600)

In [5]: d+delta
Out[5]: datetime.datetime(2006, 11, 18, 10, 47, 31, 187000)

Kent





--
To HIM you shall return.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2006-11-18 Thread Kent D. Grimsley
I am  new subscriber to python and now, I'm getting e-mail from all sorts of 
people having to do with questions I did not ask.  Please take steps to remove 
my address from that list
and take steps to help me get e-mail only from people answering my questions.  
I hope this is not an unreasonable request; if it is not, please advise.

Kent Dee Grimsley
[EMAIL PROTECTED] ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2006-11-18 Thread Luke Paireepinart
Kent D. Grimsley wrote:
> I am  new subscriber to python and now, I'm getting e-mail from all 
> sorts of people having to do with questions I did not ask.  Please 
> take steps to remove my address from that list
> and take steps to help me get e-mail only from people 
> answering my questions.  I hope this is not an unreasonable request; 
> if it is not, please advise.
The point of a mailing list is that everyone gets e-mails from everyone 
else.
If I did not get e-mails from all the other people, how would I help 
them out?
The same goes for you.
The list doesn't try to determine who it is that wants help and who it 
is that is helping other people.
It wouldn't be very helpful if everyone just got the e-mails of the 
questions they asked, would it?
SO in other words, if it's bothering you, sign up for a digest, or 
unsubscribe.
Hope that helps,
-Luke
>  
> Kent Dee Grimsley
> [EMAIL PROTECTED]  
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   

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


Re: [Tutor] (no subject)

2006-11-18 Thread Luke Paireepinart
Mr. Grimsley,
I hope you don't mind if I forward this reply to the mailing list at large.
I believe that some other people on the list can give you some guidance 
on your transition from FORTRAN to Python,
and make it as enjoyable as possible.
I, however, know nothing of FORTRAN, so I leave it up to other members 
to help you in this regard.
If, in the future, you want to send a private reply, it would behoove 
you to notify the recipient that you'd like your communique to be 
confidential,
because it's generally assumed that all replies should go to everyone, 
because then the largest audience of people who may benefit from your 
discussion are reached.
If you mean to reply to the list, the 'reply-all' button serves this 
purpose quite well, and should be used unless it's necessary to reply 
privately.
Thank you for your time, and I wish you the best of luck.
-Luke

Kent D. Grimsley wrote:
> Mr. Luke;
>
> Thanks for your note in  reply  to my (unreasonable) request.  I am 
> looking forward to being able to chat with someone about my newness to 
> Python. There is so much to absorb and digest.
>
> I must confess to being a long term Fortran programmer ( to the 
> present day) and it might take me a while to adjust to the Python 
> environment..  From what little dabbling in and around the Python 
> site, it milght be that Python is the way I COULD go to solve the 
> genealogical problem at hand.  One obstacle to my perception is being 
> able to transform Fortran I/O to Python---which   will not probably be 
> simple to do.  The existence in Python of   "IF THEN  ELSE type 
> constructions, I think will be very helpful due to the similarity with 
> Fortran.  The actual code transformation, for example from 
> DIMENSION to whatever the Python statement might be like, at the 
> moment, escapes me,  as an example.
>
> I'm assuming that while the transformation from Fortran might  not be 
> simple, it neveertheless can be done.
>
> Thanks, again,
> Kent Dee Grimsley
> [EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A Million Sevens

2006-11-18 Thread Chris Hengge

That must be part of Pythons shiny ability of dynamic data types? Must be a
messy operation to change data-types like that.. I think I'll just do my
best to work with the right data-types the whole time ;D

On 11/18/06, Alan Gauld <[EMAIL PROTECTED]> wrote:


"Chris Hengge" <[EMAIL PROTECTED]> wrote

> Not that it changes your reply, but just for my own sanity:
> int('7' * 10 ** 6) <- does this not just type-cast a char into an
> int?

Chris, I suspect you may come from a C background?

Type *conversion* in Python is very differentb from
type *casting* in C.

type casting says take the binary data stored at x and treat
it as a different type, thats pretty well instantaneous.

typecasting (int)'77' in C will not give you the number
77(decimal) but will give you the hex value 0x3737
which is entirely different (actually 14135!).

Now typecasting in C++ is somewhat different, especially
if you use dynamic casts and that can involve converting
the type rather than just treating the existing data differently...
Because of this confusion over the word cast I prefer
to refer to Python as doing type conversions.

Type conversion says take the data entity in variable x
and change its internal structure to the representation
of a new type. Thats a much more complex operation.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


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

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


Re: [Tutor] exception not raised XP file ?

2006-11-18 Thread Roel Schroeven
Dave S schreef:
> Is it just me - I seem to run into a lot of weird behaviour in windows (but 
> then I am a Linux Junky :)

It's not just you. I knew Windows long before I started to know and 
learn Linux, and before that I knew MS-DOS. But still I have a better 
understanding of the concepts, philosophy and inner workings of Linux 
(and Unix in general) than Windows.

I think there are several reasons for that. One is that I think that 
Unix really is more logically designed.

Another is that Unix is IMO better documented: even pretty basic user 
guides explain the basic concepts behind for instance processes and the 
file system. It's very hard, in my experience, to find a clear 
explanation on those concepts and the reasonings behind them in Windows.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven

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


Re: [Tutor] os.popen, xp

2006-11-18 Thread Luke Paireepinart
Coen van der Kamp wrote:
> Hello,
> I've got a problem with the following code:
>
> import os, sys, string
> mycolors = os.popen("coloryze --monochromatic --total=6 &").read().rstrip()
> print mycolors
>
> This works fine on OS X, but when i tried it on XP the only result was 
> an empty string. When I run coloryze from the promt
when you run it from which prompt?
The OS X one or the XP one?
>  the return is a nice 
> list of colors. So coloryze works. What am I missing here?
>
> Coen.
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   

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


[Tutor] os.popen, xp

2006-11-18 Thread Coen van der Kamp
Hello,
I've got a problem with the following code:

import os, sys, string
mycolors = os.popen("coloryze --monochromatic --total=6 &").read().rstrip()
print mycolors

This works fine on OS X, but when i tried it on XP the only result was 
an empty string. When I run coloryze from the promt the return is a nice 
list of colors. So coloryze works. What am I missing here?

Coen.



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



[Tutor] Re A question about: Adding seconds to datetime object

2006-11-18 Thread Danny Yoo

> Is it possible to add seconds to a datetime object and get the result as 
> a new datetime object. I mean when we keep adding, for example, 3600 
> seconds, the date will get changed after 24 iterations. Is it possible 
> to carry out such an operation ?

Hi Asrarahmed,

I want to add that you can find more information about this in the Library 
Documentation:

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

Try reading it and see if what the documentation says makes sense, after 
seeing Kent's examples.  The idea is that it's good to practice reading 
and being able to cull out the useful stuff out of the reference 
documentation.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Changing mailing list options

2006-11-18 Thread Danny Yoo
> I am new subscriber to python and now, I'm getting e-mail from all sorts 
> of people having to do with questions I did not ask.  Please take steps 
> to remove my address from that list and take steps to help me get e-mail 
> only from people answering my questions.  I hope this is not an 
> unreasonable request; if it is not, please advise.

Hi Kent,

There's a mailing list option that you can turn off that disables message 
delivery.  You will still be able to post to the mailing list, but you 
will not receive direct traffic from the mailing list.

(Note to others: this is exactly why Reply-To-All is a good idea.)

Please visit:

 http://mail.python.org/mailman/listinfo/tutor

and go down to the bottom of the page where it says "To unsubscribe from 
Tutor, get a password reminder, or change your subscription options enter 
your subscription email address."

Fill in your address at the form below, and you should be able to navigate 
to change your subscription options from that point on.

If you have problems doing this, contact the mailing list administrators 
at '[EMAIL PROTECTED]', and we will be happy to make the changes for 
you.



That being said, you may learn a few things from listening to the general 
chatter on the list.  It's a bit busy these days, but I think there's 
still worthwhile conversation.  There is a "digest mode" option that 
bundles up messages from python-tutor so that it's easier to manage.

Good luck to you.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor