Only Dict,tuples ,strings and list are reference

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • psbasha
    Contributor
    • Feb 2007
    • 440

    #1

    Only Dict,tuples ,strings and list are reference

    Hi,

    Is it not possible to reference other than Dict,tuples ,strings and list datatypes /variables ,when we call the functions?

    Say int,float and boolean

    Thanks
    PSB
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by psbasha
    Hi,

    Is it not possible to reference other than Dict,tuples ,strings and list datatypes /variables ,when we call the functions?

    Say int,float and boolean

    Thanks
    PSB
    If Python doesn't do it ("Say int, float and boolean"), you can do it with a class as shown in our lengthy discussion on globals.

    Comment

    • psbasha
      Contributor
      • Feb 2007
      • 440

      #3
      Could you please help me without using global variables.With Sample example

      -PSB

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by psbasha
        Could you please help me without using global variables.With Sample example

        -PSB
        Sure:
        Code:
        class BoolByRef:  # simulate a C structure
            value = True   # or whatever you want the defualt to be
        
        
        boolByRef = BoolByRef
        
        
        def ChangeBoolByRef():
            boolByRef.value = False
        
        def PrintBoolByRef():
            print boolByRef.value
        
        
        
        ChangeBoolByRef()
        PrintBoolByRef()

        Comment

        Working...