[Tutor] Linux variable to Python

Alberto Troiano albertito_g at hotmail.com
Sat May 14 00:39:42 CEST 2005


And again I'm gonna say BINGO!!!!!!!!!
It's like you were doing the same app as I am

Thanks

Alberto



>From: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
>To: Alberto Troiano <albertito_g at hotmail.com>
>CC: tutor at python.org
>Subject: Re: [Tutor] Linux variable to Python
>Date: Fri, 13 May 2005 14:00:50 -0700 (PDT)
>
>
>
>On Fri, 13 May 2005, Alberto Troiano wrote:
>
> > Here is an example of what I want to do:
> >
> > I run over Linux shell the following command:
> >
> > [root at siseg root]# fec=cam`date +%Y%m%d%H%M%S`.jpg
> > [root at siseg root]# echo $fec
> > cam2005051255702.jpg
> > [root at siseg root]# mv hola.txt grabacion/$fec
> >
> > I need to do this from Python but I'm having problems with the Linux
> > variable
>
>Hi Alberto,
>
>[Tangent: are you running things using the Unix 'root' account?  If so,
>you may want to consider using a regular user account unless you really
>know what you're doing.  Running things as root should never be taken
>lightly.]
>
>
>You may want to consider using the 'datetime' module for this one.  There
>are portability and security issues that you may not be considering
>whenever you "shell" out.  If you use Python's Standard Libraries, you can
>avoid these issues.
>
>
>I think you can avoid using 'date' by taking advantage
>of datetime.datetime.strftime():
>
>######
> >>> import datetime
> >>> datetime.datetime.today().strftime("%Y%m%d%H%M%S")
>'20050513135531'
>######
>
>This is portable on any system that supports the Python Standard Library.
>
>
>The problems you are running into with os.system() are related to those
>that other people have been asking about this week.  It's sorta funny how
>these questions come in streaks.  *grin*
>
>For more information on driving external processes with Python, you may
>want to look at the messages on "Pipe variable to external command" that
>Jeffrey was asking about yesterday:
>
>     http://mail.python.org/pipermail/tutor/2005-May/038341.html
>     http://mail.python.org/pipermail/tutor/2005-May/038343.html
>
>
>
>I hope this helps!
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list