#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Gobal Variables non-primitive type


    I know how to create global variables and modify them inside functions.


    Declare a Gobal Int Counter
    eg

    i = 0

    but how do you declare a global variable that is not primitive eg an opencv image object

    gobalImage = ?

    or in general any non primitive object is this even possible in python?

    in c++ you can just go

    Mat image; ect
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Joensuu, Finland
    Posts
    431
    Rep Power
    67
    Originally Posted by Sentinal_Bais
    but how do you declare a global variable that is not primitive eg an opencv image object
    There’s no need to “declare” variables: just assign values to them. In Python variables are after all only names you use when you refer to the data.
    My armada: openSUSE 13.1 (home desktop, home laptop), Crunchbang Linux 11 (mini laptop, work laptop), Android 4.2.1 (tablet)
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Code:
    import cv2  # cv2 is global
    
    def f(): pass  # f is global
    
    class c:pass # c is global
    
    img =  cv2.imread(sys.argv[1])  # img is global
    Definitions starting in column 1 are global.

    Example of opencv:
    http://forums.devshed.com/python-programming-11/sudoku-solver-school-project-error-help-934125.html
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo