I'm trying to learn python and I've tried really hard but for some reason I can't figure this out.   This is the module, named user_profile, where the function that I want to import comes from:  def build_profile(first, last, **user_info):     profile = {}     profile['first name'] = first     profile['last name'] = last     for key, value in user_info.items():         profile[key] = value     return profile  user_profile = build_profile('john', 'smith',                              city = 'new york',                              occupation = 'banker',                              girlfriend = 'janice')  for key, value in user_profile.items():     print(key.title() + ": " + value.title())   Now I want to import build_profile into another module like so:  from user_profile import build_profile   I just want build_profile to be imported, but for some reason it runs user_profile entirely. What's going on?
3567
Given the following code, what does the if __name__ == "__main__": do?  # Threading example import time, thread  def myfunction(string, sleeptime, lock, *args):     while True:         lock.acquire()         time.sleep(sleeptime)         lock.release()         time.sleep(sleeptime)  if __name__ == "__main__":     lock = thread.allocate_lock()     thread.start_new_thread(myfunction, ("Thread #: 1", 2, lock))     thread.start_new_thread(myfunction, ("Thread #: 2", 2, lock))
111921
Maybe I'm just missing something obvious, but what's up with this syntax? Is it because people sign up with e-mail addresses and use those for logging in, but don't bother giving themselves custom names (or completing their profile in any way)?
4439
If a large module is loaded by some submodule of your code, is there any benefit to referencing the module from that namespace instead of importing it again?  For example: I have a module MyLib, which makes extensive use of ReallyBigLib. If I have code that imports MyLib, should I dig the module out like so  import MyLib ReallyBigLib = MyLib.SomeModule.ReallyBigLib   or just  import MyLib import ReallyBigLib
38527
I'm just trying to streamline one of my classes and have introduced some functionality in the same style as the .  However, I'm a bit confused as to why __init__ is always called after __new__. I wasn't expecting this. Can anyone tell me why this is happening and how I can implement this functionality otherwise? (Apart from putting the implementation into the __new__ which feels quite hacky.)  Here's an example:  class A(object):     _dict = dict()      def __new__(cls):         if 'key' in A._dict:             print "EXISTS"             return A._dict['key']         else:             print "NEW"             return super(A, cls).__new__(cls)      def __init__(self):         print "INIT"         A._dict['key'] = self         print ""  a1 = A() a2 = A() a3 = A()   Outputs:  NEW INIT  EXISTS INIT  EXISTS INIT   Why?
67782
As part of an existing add-on, I'm trying to create an object and add it to the scene using Python. I followed a Blender Cookbook tutorial found here: . I use the following code to do so:  emptyMesh = bpy.data.meshes.new('emptyMesh') theObj = bpy.data.objects.new("object_name", emptyMesh) bpy.context.scene.objects.link(theObj)   But I get the following error when I try to link theObj to the scene objects:  AttributeError: 'bpy_prop_collection' object has no attribute 'link'   This works just fine in Blender 2.76-2.79, but doesn't work in the 2.80 test build I downloaded. Was there a change to the Python API? Or is this maybe a bug in the test build?
22022
I have found out how to get tab-delimited X,Y data into a layer but the Z field value is not given as an option on import?  I tried to edit the attributes to add and define a new field but it keeps crashing.
2152
What exactly are the Python scoping rules?  If I have some code:  code1 class Foo:    code2    def spam.....       code3       for code4..:        code5        x()   Where is x found?  Some possible choices include the list below:   In the enclosing source file In the class namespace In the function definition In the for loop index variable Inside the for loop   Also there is the context during execution, when the function spam is passed somewhere else. And maybe  pass a bit differently?  There must be a simple reference or algorithm somewhere.  It's a confusing world for intermediate Python programmers.
5757
When used like this:  import static com.showboy.Myclass;  public class Anotherclass{}   what's the difference between import static com.showboy.Myclass and import com.showboy.Myclass?
7325
How can I load a Python module given its full path? Note that the file can be anywhere in the filesystem, as it is a configuration option.
41476
I have written a script and am trying to run it in Python IDLE 2.7.6. I first try to import arcpy, but I get an error message saying:  ImportError: No module named arcpy  Why does it not work? I am using ArcGIS Desktop 10.2.
1704
This has always confused me. It seems like this would be nicer:  my_list = ["Hello", "world"] print(my_list.join("-")) # Produce: "Hello-world"   Than this:  my_list = ["Hello", "world"] print("-".join(my_list)) # Produce: "Hello-world"   Is there a specific reason it is like this?
25247
Does anyone have experience with using a feature as a module? The usage I am talking about is strictly placing hooks inside the .module file. Can that trigger any sort of bug?
6709
I was watching this  on making a custom UI tab using Python, and in the line from bpy.types import Menu, Panel, UIList, I see the names of objects that look like they can all be used to make different UI elements. Does bpy.types contain all the objects that people use when they want to make custom UI elements?
88172
So today I decided to join the hype and check 2.8 out even though I am the kind of person who does not like to try betas, because I hate change. And anyways I was already shocked by the difference of the keyboard shortcuts. My question is: Is it a good idea to import the preferences from 2.79b or would you guys advice me from doing it and if it's OK to do that, which file should I import and where is it in the Blender Foundation old files? It would be nice if someone showed me the path.
54174
From my thesis:     In this method, the get_config_value function is used that is defined within the PyWPS API.   How should I format the "get_config_value" variable?  It should be formatted differently than the rest of the text, but I don't know what the conventions are.  Using italic or bold fonts doesn't look right to me.
16558
I can't find this case in the board, so I'm asking the question.  This is input file:  module   x(a,b,c)   module   y(d,e,f,   g,h,i)   module   z(j,k,l)   And output file should be:  module x(a,b,c)   module y(d,e,f,   g,h,i)   module z(j,k,l)
63538
I created this siding generator and I have been adding some new features and I have encountered some problems that I just can't seem to get around. Currently it is not installing into Blender 2.72 properly, it works fine from the text editor, but if you try and install it as an  you get an error like this:  Traceback (most recent call last):   File "C:\Program Files\Blender Foundation\Blender\2.72\scripts\modules\addon_utils.py", line 299, in enable     mod = __import__(module_name)   File "C:\Program Files\Blender Foundation\Blender\2.72\scripts\addons\add_mesh_siding\__init__.py", line 12, in &lt;module&gt;     from add_mesh_siding_utils import * ImportError: No module named 'add_mesh_siding_utils'   Even though the other file is right there as well. I don't get what changed, it used to work just fine.