471,347 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,347 software developers and data experts.

cannot declare global vars!

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),db Table_=DBTablesHandler(),cmterID_=0,projID_=0,

fileIDNumber_=0,Commiter_={},Commit_={},StoredProj ect_={},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##### ##########################

Sep 13 '07 #1
1 1173
Konstantinos Pachopoulos wrote:
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
Sep 13 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Sean Berry | last post: by
13 posts views Thread by David Rysdam | last post: by
4 posts views Thread by Kenny Ashton | last post: by
9 posts views Thread by bettina | last post: by
reply views Thread by hadrien | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.