function & class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jupiter

    #1

    function & class

    hi friends,

    I have a program like

    some variable definations

    a function ( arg1, agr2):
    do something with arg1 & arg2
    return a list

    if condition
    do this function(arg1,a rg2)
    else
    if condition
    do this function
    else
    do this


    My problem is I want to use threading and I might need to pass values
    between function and classes. I am not sure how this can be done. I
    have read about classes and I know they are like function however does
    not return anything where as function does. If I define class and then
    function in this class how do I access this function ?????

    I am not sure and confused about classes and functions as how to go
    about them is there any simple way to understand difference between
    them and when to use what and how to pass data/reference pointer
    between them ?

    @nil
    Pythonist

  • Bruno Desthuilliers

    #2
    Re: function & class

    jupiter a écrit :
    hi friends,
    >
    I have a program like
    >
    some variable definations
    >
    a function ( arg1, agr2):
    do something with arg1 & arg2
    return a list
    >
    if condition
    do this function(arg1,a rg2)
    else
    if condition
    do this function
    else
    do this
    >
    >
    My problem is I want to use threading and I might need to pass values
    between function and classes.
    which classes ? I see no class statement in your above pseudo-code.
    I am not sure how this can be done. I
    have read about classes and I know they are like function
    Hmm. While technically, yes, Python classes are "callable" just like
    functions are, this is mostly an implementation detail (or at least you
    can consider it as such for now). Now from a conceptual POV, functions
    and classes are quite different beasts.
    however does
    not return anything where as function does.
    Where did you get such "knowledge" , if I may ask ? Looks like you need a
    better source of informations !-)
    If I define class and then
    function in this class how do I access this function ?????
    Classes are used to define and create ('instanciate' in OO jargon)
    objects. Usually, one first creates an object, then calls methods on
    this object:

    class Greeter(object) :
    def __init__(self, name, saywhat=None):
    self.name = name
    if self.saywhat is None:
    self.saywhat = "Hello %(who)s, greetings from %(name)s"
    else:
    self.saywhat = saywhat

    def greet(self, who):
    return self.saywhat % dict(name=self. name, who=who)


    bruno = Greeter('Bruno' )
    print bruno.greet('Ju piter')
    I am not sure and confused about classes and functions as how to go
    about them is there any simple way to understand difference between
    them
    Read a tutorial on OO ? Here's one:

    and when to use what and how to pass data/reference pointer
    between them ?
    In Python, everything you can name, pass to a function or return from a
    function is an object.

    @nil
    Pythonist
    >

    Comment

    • sjdevnull@yahoo.com

      #3
      Re: function & class

      Bruno Desthuilliers wrote:
      Classes are used to define and create ('instanciate' in OO jargon)
      Good info from Bruno, just a quick note that it's spelled
      "instantiat e" (I'm not usually big on spelling corrections but since
      you were teaching a new word I thought it might be worthwile).

      Comment

      • Bjoern Schliessmann

        #4
        Re: function & class

        jupiter wrote:
        My problem is I want to use threading
        You're right. Why do you think you want to use (multi-)threading?
        and I might need to pass values between function and classes. I am
        not sure how this can be done. I have read about classes and I
        know they are like function however does not return anything where
        as function does. If I define class and then function in this
        class how do I access this function ?????
        I think you could read a tutorial about OOP, for example one of
        those:



        Feel free to post here for further questions.
        I am not sure and confused about classes and functions as how to
        go about them is there any simple way to understand difference
        between them and when to use what and how to pass data/reference
        pointer between them ?
        BTW, please use some punctuation. Reading your multiline sentences
        isn't easy.

        Regards,


        Björn

        --
        BOFH excuse #393:

        Interference from the Van Allen Belt.

        Comment

        • jupiter

          #5
          Re: function & class

          c.execute("sele ct symbol,tvolume, date,time from "+self.dbas e+"
          where symbol=
          ?",t)
          ProgrammingErro r: SQLite objects created in a thread can only be used
          in that sa
          me thread.The object was created in thread id 976 and this is thread
          id 944

          I am getting this error when I am using sql command within
          class.function accessing from another class

          how can I create seperate instance for sqlite objects ???????


          @nil

          Comment

          • Bjoern Schliessmann

            #6
            Re: function & class

            jupiter wrote:
            I am getting this error when I am using sql command within
            class.function accessing from another class
            >
            how can I create seperate instance for sqlite objects ???????
            Trying to help you gets boring. I suggest reading the material
            that's being offered.

            Regards,


            Björn

            --
            BOFH excuse #241:

            _Rosin_ core solder? But...

            Comment

            Working...