Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > cannot declare global vars!

Reply
Thread Tools

cannot declare global vars!

 
 
Konstantinos Pachopoulos
Guest
Posts: n/a
 
      09-13-2007
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##### ##########################

 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      09-13-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
Why I need to declare import as global in function didier.doussaud@gmail.com Python 18 11-30-2005 06:36 PM
How to declare a variable in the global scope? Miguel Dias Moura ASP .Net 41 12-27-2004 05:56 PM
how to declare session variable in global.asax file khawar ASP .Net 1 07-10-2003 08:03 PM



Advertisments