Re: [Tutor] Dos and os.walk with Python
Timothy Sikes wrote: > > I'm getting the "Digest" version of the mailing list, if there's any > better way to respond to a specific message, I would like to know. thanks > :> > > I use Nabble ( http://www.nabble.com ). Great interface, multiple lists, tag messages, you can control list options, etc. all from one interface. I just set it to never send emails and read and reply from the Nabble page itself. Brian -- View this message in context: http://www.nabble.com/Dos-and-os.walk-with-Python-tp15078734p15097304.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hi
Firoze Khan wrote: > Hi, > I want Tutors mailing List If you want to subscribe visit: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] namespaces and the __dict__ function?
John Gunderman wrote: > I am new to python and have found both the concept of namespaces and the > __dict__ function to be rather confusing, and I cant find any good > explanations on the web. Could any of you give me a good explanation of > these? And for __dict__, is is the same thing as __str__ except in > string form, or does it store all current objects of that class in a > __dict__? First, __dict__ is an attribute of an object whose value is a dict, not a function. A namespace is a place where names can be defined. The official tutorial says, A namespace is a mapping from names to objects. Most namespaces are currently implemented as Python dictionaries... Examples of namespaces are: the set of built-in names (functions such as abs(), and built-in exception names); the global names in a module; and the local names in a function invocation. In a sense the set of attributes of an object also form a namespace. http://docs.python.org/tut/node11.html#SECTION001120 Another way to think of it is, a namespace is a place where names are looked up. When you use a bare name (not an attribute), it is looked up in the local namespace, then the global namespace, then the built-in namespace. For example: y = 2 # Defines y in the global (module) namespace def f(): x = 1 # Defines x in the local (function) namespace # This looks up x, finds it in the local namespace # looks up abs, finds it in the built-in namespace print abs(x) # This looks up y, finds it in the global namespace print y Note that none of the above namespaces have a related __dict__ attribute, the namespace mappings are not stored that way. Objects also define a sort of namespace, where attributes are defined and looked up. The dict containing the namespace of an object is itself stored as an attribute of the object, called __dict__. So __dict__ is an implementation detail of the way object attributes are stored. As a beginner, it is important to understand the way bare names are looked up (local, global, built-in namespace) and a bit about the way attributes work. You don't have to be concerned with the implementation details such as __dict__. (For completeness, I will say that the full attribute lookup model is much more complicated than I have indicated above. I have simplified to focus on __dict__.) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] namespaces and the __dict__ function?
I am new to python and have found both the concept of namespaces and the __dict__ function to be rather confusing, and I cant find any good explanations on the web. Could any of you give me a good explanation of these? And for __dict__, is is the same thing as __str__ except in string form, or does it store all current objects of that class in a __dict__? John Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hi
Firoze Khan wrote: > Hi, > I want Tutors mailing List You seem to have found it. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] setstate trouble when unpickling
Jeff Peery wrote: > Hello, > > I've got a fairly simple class instance that I'm pickling. I'm using > setstate to update the instance when I unpickle. Although the setstate > doesn't seem to be called upon unpickling... here's an example, if > anyone see's what I'm doing wrong, please let me know. Thanks! > > so I say start out with this class: > > class dog: > def __init__(self): > self.num_legs = 4 > > then I pickle the instance of: > sparky = dog() > > then I update my dog class to: > class dog: > def __init__(self): > self.hair_color = 'brown' > self.num_legs = 4 > > def __setstate__(self, d): > if 'hair_color' not in d: > d['hair_color'] = 'brown' > self.__dict__.update(d) > print 'did this work?' > > Now when I unpickle the original pickled object sparky I would hope to > see 'did this work' and I would also hope that sparky would have updated > to have the attribute 'hair_color' but nothing of the sort happens. if > just unpickles sparky without updating the attributes as I was hoping. Are you sure the unpickle program is getting the new definition of dog? Can you show more code and tell us how you are running it? This does what you expect, when run in a single program: import pickle class dog: def __init__(self): self.num_legs = 4 sparky = dog() p = pickle.dumps(sparky) class dog: def __init__(self): self.hair_color = 'brown' self.num_legs = 4 def __setstate__(self, d): if 'hair_color' not in d: d['hair_color'] = 'brown' self.__dict__.update(d) print 'did this work?' sparky2 = pickle.loads(p) print sparky2.hair_color prints: did this work? brown Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error connecting to MySQL from Python script
Kamal wrote: > I have the MySQL Server (5.0.51) running on Windows XP machine, when I > try to connect to this server with a Python script, it gives the below > error. Wondering why is it happening? > > _mysql_exceptions.Operational > Error: (1251, 'Client does not support authentication protocol requested > by server; consider upgrading MySQL client') What version of what client are you using? Have you considered upgrading it? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Forgot something...
Timothy Sikes wrote: > Sorry, but in my previous message, I realized that I hadn't changed the > code from doesNotHave... It's supposed to be x.find(), not > x.startswith.. You meant to write: def doesNotHave(exclude, root): for x in exclude: if root.find(x) > -1: return False return True This can be written as def doesNotHave(exclude, root): for x in exclude: if x in root: return False return True or def doesNotHave(exclude, root): return not any(x in root for x in exclude) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Dos and os.walk with Python
Timothy Sikes wrote: > I can't seem to figure out how to make hotmail keep those spaces and new > lines. ah oh well You are sending HTML mail. If you can configure hotmail to send plain text that is preferable. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Projects (fwd)
Tiger12506 wrote: >> Nope, if you read the code you'll see the only mapping done is up to 20 >> and then by tens up to 100, that's all. >> The same code could be used with a list, you'd only have to change the >> exception name. > > I see. There were "..." in between each of the tens entries which I took to > mean that "big huge dictionary but left out some values in email for > simplicity". I feel ashamed for not recognizing that the ellipses where > there for some other purpose. ;-) > Checked my mail and yes, it was not outright clear what I meant in the dictionary, sorry. Anyway if you check the rest of the code you'll see it works as I said and you don't use the intermediate values between the tens. As usual I learned something from the exercise, I thought that indexed access would be faster than list access, didn't think lists where implemented as C arrays (because they have no fixed size), now I can see tuples will be faster and will save memory because memory will not have to be reserved in chunks. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Hi
Hi, I want Tutors mailing List ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor