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

    Join Date
    Jun 2016
    Posts
    2
    Rep Power
    0

    python: two differenet entities (a library and a command) with the same name


    Hi,
    I am trying to use a library and a command with the same name (from another library) in the same code but get an error.
    My code has:

    Code:
    import copy #(from which I use deepcopy)
    from xlutils.copy import copy
    The error I get is: AttributeError: 'function' object has no attribute 'deepcopy'

    I guess this is because they have same name.
    I`ve also tried:

    from copy import deepcopy

    but got the same error. Any idea how to address this issue? Thanks
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,824
    Rep Power
    509
    closing code tag needs slash [/code]

    from xlutils.copy import copy
    replaces the object to which `copy' refers. Many approaches will work.

    from copy import deepcopy
    and replace in your code where you have copy.deepcopy simply use deepcopy

    You could

    import copy
    import xlutils
    #...
    xlutils.copy.copy(args) # refering to xlutils copy


    import copy
    twisp = copy.deepcopy # subsequently referring to twisp instead of copy.deepcopy
    from xlutils.copy import copy
    oval_lake = copy # later use oval_lake in place of copy

    Comments on this post

    • Will-O-The-Wisp agrees : Fixed their tags!
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo