mardi 24 mars 2015

local and global syntaxerror python


Vote count:

0




Why does the Function def openFehBgQ(): not like the 2 instructions marked Comments 1 & 2:


Comment 1 tries to update the fehCurrent, which is declared global, but produces the following error:



SyntaxError: name 'fehCurrent' is local and global ;


Comment 2 does not work at all although timeKill is remembered for the time.sleep Function.



#!/usr/bin/env python
# -*- coding: utf-8 -*-
import glob, subprocess, time, os

def globalVariables():
global fehCurrent # Title (str) of current 'Child' window
global fehNew # Title (str) of new 'Child' window
global fehWindow # Data (array) for current 'Child' window
global timeKill
global timeZero


# Data (array) for current 'Child' window
fehBg = ['fehBg', '-g', '%ux%u+%u+%u' % (320, 240,
50,50), '-x', 'Media/Bg.jpg']
fehCurrent = 'fehq1' # Title (str) of current 'Child' window

def openFehBgQ():
if fehCurrent != fehNew:
subprocess.Popen(fehWindow)
time.sleep(timeKill)
os.popen('%s%s' % ('pkill ', fehCurrent))
# fehCurrent = fehNew # See Comment 1
timeElapsed = 0
# timeZero = time.time() # See Comment 2

fehNew = "fehBg"
fehWindow = fehBg
openFehBgQ()
print "1_", fehCurrent
fehCurrent = fehNew
print "2_", fehCurrent
timeZero = time.time()


asked 2 mins ago







local and global syntaxerror python

Aucun commentaire:

Enregistrer un commentaire