473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 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 1270
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sean Berry | last post by:
How do I rectify this? ------vars.py------ #!/usr/local/bin/python def setUserid(value): userid = value def getUserid():
13
by: David Rysdam | last post by:
Getting no answer yesterday, I've done some investigation and I obviously don't understand how python namespaces work. Here's a test program: #!/usr/bin/python b = 2 def sumWithGlobal(a):...
6
by: flamesrock | last post by:
ok, so to my knowledge, object oriented means splitting something into the simplest number of parts and going from there. But the question is- when is it enough? For example I have the following...
4
by: Kenny Ashton | last post by:
Hello gurus Can I ask you opions on the best compromise for storing Access Ado connection strings in a IIS4 standard ASP environment. For any method I use, there seems to be an article somewhere...
16
by: WaterBug | last post by:
When clicking on the following link from an email i.e - http://myserver/myapplication/myprogram.asp?urlvar1=some%20stuff&urlvar2=more%20stuff I get a server 500 error. With that same browser...
9
by: bettina | last post by:
I have the following piece of code (symplified) require("lang.{$lang}.inc.php"); // I include the inc. files .... function decodify($technique) { // functions that give me back the value in...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
4
by: pcaisse | last post by:
I'm having issues sharing global variables with Explorer. This problem probably has a simple answer (as with most newbie questions). The script.pl file: #!/usr/bin/perl -w use strict; use...
0
by: hadrien | last post by:
Hi! I'm working with Python and MySQL and I need two global vars for an entire module. These two vars would be the connector and the cursor of the current database and I need them to work...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.