Script which only runs in Windows

Penfold spam at spam.com
Mon Jun 26 18:51:12 EDT 2000


The problem lies here

> try:
>     sResult = os.system('python ftpasget.py -q -g * -d ' + sFileTime
> + ' -l ' + sSugLogin + ' -p ' + sSugPWord + ' ' + sSugSite + ' ' +
> sBillDir + ' ' + sOutputDir + sDirTime)

[which might have been easier for you to type as

try:
    sResult = os.system('python ftpasget.py -q -g * -d %s -l %s -p %s %s %s
%s%s' % \
                        (sFileTime, sSugLogin, sSugPWord, sSugSite,
sBillDir, sOutputDir, sDirTime)
except:
    sGetMinutes = 0

] :-)

Probable cause:
An exception is happening in os.system, who knows what, as you are catching
absolutely everything.  Because this exception occurs,
sResult never gets defined !!.  Hence when you refer to it later, you get
the problem.  Basically the script as it stands expects sResult to exist
no matter what, and it wont if you get an exception in the above block.

Probable exception? python cant be found in the search path or ftpasget cant
or something like that.  To find out, remove the try and except block and
run it, and you'll find out.  Windows, as a rule, runs anything in system
without fail, cant remember for *nix.

Or, try something like the following, which is slightly restructured.

import os, sys, time, string, sugdb, gadfly

sBillDir, sSugLogin, sSugPWord, sSugSite = "dirname", "login", "password",
"171.1.1.1"

# The following Dirs MUST end in a path slash
SOutputDir = "/home/DATA/"
sDBLocation = "/usr/local/bin/db/"

# The script is called without any passin values.
# It starts by getting the date and extrapolating strings to use for  file
# dates
# Next, the FTPASGET script is called and its return value is checked
# If all was well, then the DB processing script is called
# The following declarations are very important.
# This reads the date and creates the strings for the following

iTime = time.time()

# This is the format string for the date of the files we need to look
#for (like: 06/09)

sFileTime, sFileName, sDirTime, sDateStart, sProcStart = \
           map(time.strftime, ["%m/%d", "%m%d", "%d%b", "%m-%d-%y",
"%H:%M:%S"], [time.localtime(iTime)]*5)

#
# here is where we do some work
#
try:
    sResult = os.system('python ftpasget.py -q -g * -d %s -l %s -p %s %s %s
%s%s' % \
                        (sFileTime, sSugLogin, sSugPWord, sSugSite,
sBillDir, sOutputDir, sDirTime)
except:
    sGetMinutes = 0
else:
    iCurrTime = time.time()
    if sResult == 0:
        sGetMinutes = (iCurrTime - iTime) / 60
    else:
        sGetMinutes = 0
    iTime = iCurrTime

Des.

<al at servana.com> wrote in message news:8j8d2n+qbe9 at eGroups.com...
> Hello.
>
> We have an odd problem with Python which we cannot resolve.
>
> Below, is a script we have been running in Win32 for months.
>
> We moved our scripts from Win32 to Slackware Linux and IF statements
> which
> are not in functions or classes will cause errors when you
> try to run the script.
>
> I have had retyped the script thinking it was the tab/space
> issue, but nothing changes - in Linux we cannot use IF outside
> a function or CLASS for some reason.
>
> We are posting this here as it seems very serious and we were hoping
> someone else had seen the problem.
>
> -----------------------------------------
> import os
> import sys
> import time
> import string
> import sugdb
> import gadfly
>
> sBillDir = "dirname"
> sSugLogin = "login"
> sSugPWord = "password"
> sSugSite = "171.1.1.1"
>
> #
> # The following Dirs MUST end in a path slash
> #
> SOutputDir = "/home/DATA/"
> sDBLocation = "/usr/local/bin/db/"
>
> #
> # The script is called without any passin values.
> #
> # It starts by getting the date and extrapolating strings to use for
> file
> # dates
> #
> # Next, the FTPASGET script is called and its return value is checked
> #
> # If all was well, then the DB processing script is called
> #
>
> #
> # The following declarations are very important.
> # This reads the date and creates the strings for the following
> #
>
> iTime = time.time()
>
> # This is the format string for the date of the files we need to look
> for (like: 06/09)
> sFileTime = time.strftime("%m/%d", time.localtime(iTime))
> sFileName = time.strftime("%m%d", time.localtime(iTime))
> sDirTime = time.strftime("%d%b", time.localtime(iTime))
> sDateStart = time.strftime("%m-%d-%y", time.localtime(iTime))
> sProcStart = time.strftime("%H:%M:%S", time.localtime(iTime))
>
> #
> # here is where we do some work
> #
> try:
>     sResult = os.system('python ftpasget.py -q -g * -d ' + sFileTime
> + ' -l ' + sSugLogin + ' -p ' + sSugPWord + ' ' + sSugSite + ' ' +
> sBillDir + ' ' + sOutputDir + sDirTime)
> except:
>     sGetMinutes = 0
>
> iCurrTime = time.time()
>
> #
> # PROBLEM: The following will fail unless in a function
> # The failure error is:
> #      Name Error: sResult
> #
> if sResult == 0:
>     sGetMinutes = (iCurrTime - iTime) / 60
> else:
>     sGetMinutes = 0
>
> iTime = iCurrTime
>
> ------------------------------------
> If we run the code in Win32, or from a function in Linux, it works
> without error.
>
> Any suggestions would be priceless.
>
>





More information about the Python-list mailing list