@# Quotes DB     useful, funny, interesting





Google
 
Web www.quotesdb.info
Undernet  |  EFnet  |  Quakenet  |  Freenode  |  Dalnet  |  Ircnet  |  Galaxynet
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21



Comments:

<0> interesting how my book neglects to mention the insert method
<1> L.insert(index, object) -- insert object before index
<1> insert() (list method): http://doc.python.org/lib/typesseq-mutable.html#l2h-225
<0> thanks a lot
<2> Any ideas on my subprocess problem?
<3> thx guys
<4> so how goes the sanity on this channel?
<5> kosh: hm. it's quite high, but there's little I can do.
<1> Kosh: Depends on which of those voices you believe.
<6> hi there
<6> is there any Interface to implement collections in python
<6> ?
<5> bedboi: you mean, like sets?
<1> You mean, like cash-donations to #python?
<7> Is there a way to get something like an ID of an object instance?



<1> id(p)
<6> jelly: yes
<7> Pythy: Thanks, looks easy ;-)
<6> ops
<6> Jerub: yes
<6> like sets
<6> :)
<5> bedboi: okay, then use 'set'
<6> thanks
<6> checking docs
<6> btw python is cool
<6> it's difficult for me to say that a programming language is cool
<6> other than C
<6> :)
<7> I'm getting closer to understanding this closure problem, however I still don't understand which instance of a will be referenced in a closure, and when it will be done - at runtime/compile time? Simple Example here: http://pastebin.com/632281
<7> To me, the result (as seen in line 15) is illogical - why has "a" the same id as the "a"- instance in line 1?
<8> morning
<1> 12:16:09n| me-->|pyqwer: The `a' in your inner-def is a real-time updated read-only connection to the contents of `a' established outside that def.
<1> 12:17:37n| me-->|pyqwer: So, when any of your foo's are called, they all see the same (*the current*) contents of `a'.
<1> 12:18:18n| me-->|pyqwer: (Hence my "real-time updated" phrase.)
<1> 12:19:25n| me-->|pyqwer: def foo(a=a): # http://www.importanceofphilosophy.com/Metaphysics_Identity.html
<1> 12:21:32n| me-->|pyqwer: Try it with the above change. (See if Aristotle got it right.)
<1> Hello, Xro
<6> Jerub: if i would like to overload add method in Set cl*** in order to check something and then add the item
<6> i just have to do something like
<6> def MySet (Set):
<6> ops
<6> cl*** MySet (Set):
<6> def add(self, x)
<8> ey guys, has anyone converted a php application to mod_python ?
<6> if x.something > 5:
<8> sorry bedboi
<6> what i have to say to add the item to the set?
<6> using the Set add (not the overloaded one)
<9> bedboi: http://www.python.org/download/releases/2.2.3/descrintro/#subcl***ing
<10> is there a quick way to build a python without dynamic linking? (context: i'm attempting to freeze something fairly complicated (depends on pygame) and i'm trying to get it to work)
<6> nexon: thanks
<9> bedboi: np
<6> ok, it's simple
<7> Pythy: Ok, I think I got that. But if you look at the output, you see that the id of the first "a"-instance is the same as the a-instance of the second run in the for-loop. Why this?
<8> novas0x2a: i know some commercial games use pygame without releasing the source code
<1> 12:17:37n| me-->|pyqwer: So, when any of your foo's are called, they all see the same (*current*) contents of `a'.
<10> xroberx, this is for my thesis, so no worries about closed source ;) (all the source is going to be in my paper, heh)
<8> novas0x2a: what i wanted to say is that of course it is possible to build static binary pygame games
<1> pyqwer: If you don't hold a reference to an object, Python can re-use that location in some subsequent allocation, if that's your question. (I haven't looked at what you pastebin'ed.)
<8> novas0x2a: but i dunno how it is done
<7> Pythy: but why should the reference be lost in my case? I'm not leaving any inner scope or the like. All variables are global.
<10> the stuff that i've read implies that if i can figure out how to disable dynamic loading in python, everything will just fall into place
<4> I don't think that python is very cool, I tried to get it to keep my icecream cool and it did not work :)
<4> pyqwer: please don't use globals
<11> kosh: you shouldn't feed ice cream to snakes
<1> pyqwer: Pastebin a *minimal* demo of your current question.
<7> kosh: It's just for understanding how thinks work.
<10> but i don't see a --disable-dynamic or anything like that in the configure- i did see #define HAVE_DYNAMIC_LOADING 1 in pyconfig.h, and i'll probably just try that
<4> pyqwer: understand how things work better by not using bad designs :)
<7> Is this minimal? http://pastebin.com/632281
<10> but since the python faq mentions building minus dynamic loads, i figured it also would mention how to do that.. but it doesn't
<1> pyqwer: What part don't you understand?
<7> Pythy: Output of line 15 - why is the id the same as in line 13?
<7> Pythy: You see, line 15 comes from line 6 (the second run of the for-loop)
<4> pyqwer: because when that foo function runs it only has access to the variables at the time it runs ie the last a and i



<4> pyqwer: that function is not created with a stored version of what the scope was like at the of its creation
<4> pyqwer: so it just runs without any knowledge of its creation scope
<4> pyqwer: if you defined that function outside the loop you will get the same result
<4> however there are ways around this if you really want to
<7> kosh: Yes, so far I understand the problem. What I still don't really understand is why the id(a) from the second run in the for loop (line 6) is the same as the id(a) in line 1.
<4> most likely the id got reused
<1> pyqwer: Because Python is reusing the location. After the second iteration. you no longer have any
<4> to make absolutely sure have that function print out what arg the a was created with
<1> reference to the object created at the top of the program.
<4> however from my test here it certainly seems that is what it is doing
<12> What's the docstring PEP again?
<7> Ah yes, now I got it: The first id is freed when I do a a=A(i) in the first run of the loop, right?
<1> 11365952 99
<1> .. 11365992 5
<1> .. 11365952 6
<1> ---> 11365952
<1> 11365952 In Loop: 6
<12> nm, found it.
<1> 13 # 1077535212 99
<1> 14 # 1077536524 5 # loc 1077535212 is now available! Whohoo. So, no surprise that the next newly-allocated instance is placed at location...
<1> 15 # 1077535212 6
<7> So the conclusion of all this: This inner function simply looks what it has got at runtime - right? No object instances will be "stored" in the function, right?
<4> yes
<4> however I am getting a strange result
<4> let me try to figure it out more though first
<7> kosh: what does your code look like?
<4> pyqwer: I am trying to use function attributes
<13> kosh: itsn't this what the objects do - functions + attributes?
<4> functions can also have attributes :)
<14> hmm, there isn't any easy way to read four bytes from a file as a big or little endian integer is there?
<15> Zhivago: look at struct module
<14> thans
<15> ;-)
<13> Zhivago: if you are creating the file with python you might consider using pickle.
<14> there are random access issues
<13> then yaml
<14> lovely, struct seems ideal -- thanks
<7> So, the reason why a "def foo(a=a)" works is because there are different instances of foo which all have a different default parameter for a?
<4> yes
<1> pyqwer: Yes, plus the fact that the default-value-expression is evaluated (& salted-away) only at the time Python (re-)reads the def.
<7> kosh: Ok - so then that's what I originally intended: Create functions that are executed with a snapshot of the current global variables, which is done through specifying these (a=a,b=b) etc.
<16> hi
<7> Pythy: Yes, right - wow, I got it! :-)
<4> pyqwer: wait until you get references to mutable objects and modify them
<4> pyqwer: they are holding an object reference so for instnace if you had a dict that was global and each iteration through the loop at entry was added thsoe functions would see the entire dict not just the entires that existed as the time they where created
<7> kosh: True, but I could prevent this like this: def foo(a=copy.copy(a)), right?
<4> pyqwer: if a where ever large that would end up being crippling
<4> pyqwer: why do you think you need this type of design?
<4> pyqwer: I don't see what this is accomplishing
<1> "however I am getting a strange result" > Kosh: Having Python re-process a def, & then ***ign attributes to that re-wrapped function is no different than creating instances of objects & ***igning to its instance-attributes. Can you pastebin your code?
<1> >>> l = []
<1> >>> for j in XR[1,...,3]: p = lambda:0; p.v = j; l.append(p)
<1> >>> map(attrgetter('v'), l) #==> [1, 2, 3]
<7> kosh: Well, what I'm actually creating LoopingCalls with Twisted. I am creating functions in a for loop and starting these functions as a loopingCall later on.
<4> Pythy: oh the item is stored fine, the problem I got was just some strange ids that I did not expect, it was working fairly well, I got rid of the code in question though
<1> Kosh: Ja, looking at id()'s is a way to make yourself crazy.
<4> Pythy: the only problem I see is if you have a function foo and give it an attribute a when exectuting function foo there does not seem to be a clean way to get access to its a attribute
<4> Pythy: you can do it from outside the funciton trivially
<4> Pythy: also function attributes are only for basic functions ie not methods
<4> Pythy: so it is just something that is a better idea to do with the cl*** and not use functions this way
<1> Kosh: Yep, I've walked than exact path myself.
<4> pyqwer: why don't you just make an cl*** and implement __call__ for it?
<4> Pythy: the strangeness was just the ids have I VERY rarely use python ids
<7> kosh: Where would be the difference between a function and a cl*** with a call method? Wouldn't the problem stay the same?
<4> actually the only use I can think of is I defined an object that uses def __hash__(self): return id(self) it is just used so I can eliminate duplicate objects
<4> for the case I am using it for it just has to be valid for the single call to remove duplicates, it is never stored, compared against later etc
<4> so it works very well
<4> pyqwer: it would be simple actually
<4> pyqwer: let me write up a quick example
<1> "does not seem to be a clean way to get access to its a attribute" > You mean, protecting `def f(): print f.x' from a change to the value in the global-variable `f'?
<4> http://pastebin.com/632327
<4> Pythy: yeah something like that, either way it is not a corner case worth working on very hard since it is trivially solveable another way
<4> Pythy: why worry about the problems ***ociated with a nasty way to solve a problem where there is a clearer simpler way to do it? :)
<1> Kosh: What is the question arising from what you pastebin'ed?


Name:

Comments:

Please enter the result of the sum 63 + 46 (to avoid spam):






Return to #python
or
Go to some related logs:

#php
Error: the sys-apps/pam-login package conflicts with another package
#linux
apt-get s2fsprogs
gentoo drm Mobility M6 LY.
#perl
#perl
ipw220 Fedora.core.5
mysql + SELECT + INTO OUTFILE + utf8
ubuntu lilo usplash



Home  |  disclaimer  |  contact  |  submit quotes