cannot declare global vars!

  • Thread starter Konstantinos Pachopoulos
  • Start date
K

Konstantinos Pachopoulos

Hi,
i had posted earlier for not being able to declare global vars. No i
followed the suggestions and created a class, but still the vars do not
seem to have a global scope. I have tried pretty much everything. Any
advice appreciated... Here:

========================================================
#!/usr/bin/env jython

#imports
....


class SVNLogs2DBParser:

#svnLogging_
#dbTable_
#cmterID_
#projID_
#fileIDNumber_
#Commiter_
#Commit_
#StoredProject_
#ProjectVersion_
#entryList_

def
__init__(self,svnLogging_=SVNLogging(SVN_REPOS),dbTable_=DBTablesHandler(),cmterID_=0,projID_=0,

fileIDNumber_=0,Commiter_={},Commit_={},StoredProject_={},ProjectVersion_={},entryList_={}):


pass
#svnLogging_=SVNLogging(SVN_REPOS)
#print "Connection established to SVN repository..."
#dbTable_=DBTablesHandler()
#cmterID_=0
#projID_=0
#fileIDNumber_=0
#Commiter_={}
#Commit_={}
#StoredProject_={}
#ProjectVersion_={}
#entryList_={}



#reads all the revision logs (traversing them PIVOT at a time) and
#processes each log entry
def getLogsLoop(self):


while
svnLogging_.getCurrentRevisionNumber()!=svnLogging_.getLatestRevisionNumber():

entryList_=svnLogging_.getNextLogs(PIVOT);
#print "Attempting to go over the HEAD revision..."

for entry in self.entryList:
print "processing new SVN entry..."
processLogEntry(entry)

entryList_.clear()



#processes each log entry
#
#"entry" is of type SVNLogEntry. See SVNKit API
#"changedPaths" is returned as a java.util.HashMap
#with key strings (paths) and values SVNLogEntryPath objects
#"entry.getDates()" returns a java.util.Date object
def processLogEntry(self, entry):
revision = int(entry.getRevision())
commiter = str(entry.getAuthor())
datetime = getTimeStamp(entry.getDate())
message = str(entry.getMessage())
changedPaths = entry.getChangedPaths()

#array passed for updating the Commiter DB table
Commiter_[0] = cmterID_
Commiter_[1] = commiter
dbTable_.updateCommiterTable(Commiter_)

#array passed for updating the Commit DB table
Commit_[0] = projID_
Commit_[1] = datetime
Commit_[2] = cmterID_
Commit_[3] = 0.0
Commit_[4] = "" #properties
fileStats=getFileTypes(changedPaths)
Commit_[5] = fileStats[0]
Commit_[6] = fileStats[2]
Commit_[7] = fileStats[1]
Commit_[8] = fileStats[3]
Commit_[9] = fileStats[4]
dbTable_.updateCommitTable(self.Commit_)


ProjectVersion_[0]=projID_
ProjectVersion_[1]=0.0
dbTable_.updateProjectVersionTable(ProjectVersion_)


Project[0]=projID_
Project[1]=""
Project[2]=""
Project[3]=""
Project[4]=""

dbTable_.updateProjectTable(Project_)

cmterID_+=1
projID_+=1



##############################HELPER##METHODS###############################

....


##############################HELPER##METHODS###############################
 
P

Peter Otten

Konstantinos said:
i had posted earlier for not being able to declare global vars. No i

Post a followup in that thread then rather than starting a new one.
followed the suggestions and created a class, but still the vars do not
seem to have a global scope. I have tried pretty much everything. Any
advice appreciated... Here:

[snip mess]

What Guillaume C. meant is:

To make a variable that is assigned within a function global you have to
declare it global

def foo():
global x
x = 42
foo()
print x

but that having many of these globals is a bad design and you should
use instance attributes instead:

class A(object):
def foo(self):
self.x = 42
a = A()
a.foo()
print a.x

Personally, I often prefer

def foo():
return 42
x = foo()
print x

which is both explicit and concise.

These are basic considerations in Python, so I suggest that you read an
introductory text on the language before you proceed with your endeavours.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top