cannot declare global vars!

Discussion in 'Python' started by Konstantinos Pachopoulos, Sep 13, 2007.

  1. 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###############################
    Konstantinos Pachopoulos, Sep 13, 2007
    #1
    1. Advertising

  2. Konstantinos Pachopoulos

    Peter Otten Guest

    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
    Peter Otten, Sep 13, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    386
  2. =?Utf-8?B?cmdoYXRvbA==?=

    Re: fastest way to access global vars

    =?Utf-8?B?cmdoYXRvbA==?=, Mar 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    372
  3. Jon

    app vars and cache vars

    Jon, Dec 14, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    382
  4. Linuxguy123
    Replies:
    7
    Views:
    670
    Paddy O'Loughlin
    Feb 20, 2009
  5. caccolangrifata
    Replies:
    18
    Views:
    385
    Chris Torek
    Jul 22, 2011
Loading...

Share This Page