| |
| |
| |
|
Comments:
<0> I'm not certain what these yield statements mean. <0> for instance: yield [i for i in range(len(int_ary)) if int_ary[i] == 1] <1> yield statement makes a function a generator <1> or actually a generator-maker, to be precise <0> but what does the term in brackets mean with regard to yielding? <2> the thing in brackets is a list comprehension <0> If int_ary is a variable in the generator function <2> it isn't necessarily ***ociated with yielding <2> in fact, typically you'd use yielding instead of iterating like that <0> So it says return the index whenever the value of the index is one, but that would seem to be multiple indices in the array? <0> So you can yield multiple values? <2> unfortunately this particular yield statement is mixing you up
<2> you can yield any object at all, even composite ones like lists <2> the expression yielded here is a list comprehension, which is a way of iterating over a list, transforming it, possibly filtering it, and getting back another list <2> so here a list is being yielded <2> type this in your interactive interpreter:: [x**2 for x in range(10) if x % 1 == 0] <2> that's a list comprehension <0> According to the way the program I first implored about works, it appears that only one value is returned- by the yield. <2> correct <0> will do... <2> only one value is being yielded -- but it's a list <2> as I mentioned, using a list comprehension and then yielding the result is a bit unusual <2> so you're seeing something inherently kind of weird <0> What determines the value that is yielded out of the list? <1> mmia: the list is yielded <1> def foo (): <1> yield [1,2,3,4,5] <1> the list jus thappens to contain a few integers <2> yes <2> lists are objects just like anything else, they can be yielded <2> for x in foo(); print x, type(x) <2> that will print the LIST [1, 2, 3, 4, 5], not the ints 1, 2, etc. <0> When I do print ilen(foo(i)) """ where foo is a generator yielding a list, I get one value, and I'm not sure what that is""" <2> you lost me <0> woops <0> sorry, one moment. <0> I think what the program is doing is trying to count the elements in the list that is yielded. Thank you for your help. <2> it sounds like it <2> but if it's only ever yielding one value, it might as well just return it (and not be a generator at all) <1> mmia: look up for an example of using generators to represent e.g. the fibonacci series or some other infinite series <1> the lazy-eval property gives some insight to the concept <3> Hello everyone <2> hello <4> I've defined an object in the main file of this app, and I'm using a function which interfaces with that object from an imported file, when I compare globals() from the function and from the other file though, the object I defined is missing, any way to remedy this? <2> globals are really module-specific <2> you'll have to p*** the object in question in to the other module <2> or, put the object in a third module which both the main and the other module import <4> Bleh. <4> The problem is that this function is supposed to be like a more complex getattr <4> It's supposed to take the object and attribute as strings, and if the attribute is callable, it returns the result of the function, and if not it returns the attribute. <2> then why is it in another module? <4> The project is a text adventure dev. library, all the stuff that does the work is in one file, the game you create is in the main file, which imports the library. <2> so why can't you p*** the object in? <2> modules don't have intimate knowledge of the modules which imported them, that's the reverse of how module systems generally work <4> Hmm. <4> I just started with the idea of everything being strings, good point.
<2> a module provides functions/cl***es that are available to other modules (including the main module) which import them <4> I'll try it without strings for the object name and see if I run into any complications, *slap self* Thanks. <4> Actually, quick question, is there a way to call a function with arguments defined by a list? <4> So in otherwords call("add",[3,5]) to replace add(3,5)? <5> I think add(*[3, 5]) works.. <4> madewokhe, it does. <6> hi. I'm totally new to python. Although I've ddone a lot of hacking with asp * vbscript. anyhow, I'm wondering what's the most user friendly web framework that I can sick my teeth in <6> to develop some web app? <6> sick/sink <7> anyone awake? <7> ready for some python a sunday morning <2> y <7> here comes a small apaste <7> import Crypto.Util.RFC1751 <7> text = key_to_english(key) <7> print text <7> NameError: name 'key_to_english' is not defined <2> is it defined in RFC1751? <2> you meant from Crypto.Util.RFC1751 import key_to_english <2> you meant:: from Crypto.Util.RFC1751 import key_to_english <2> (for clarity) <7> thanks! yes exactly <2> if module M contains function f, then you can do:: import M; m.f() <2> errr, import M, M.f() <2> or from M import f; f() <7> much obliged <8> hi all , we will talking woth Paul Everitt after few minutes in #foss_sesions you are welcome <9> hello <10> has anybody tried using os.popen (any variant) to control a shell? e.g., os.popen4("bash") or something? <11> is it possible to make python ignore the chmods of files in windows xp? <11> and delete them even though they are +r ? <1> how about chmodding the directory and the file writable? <1> but on XP you should really use Windows' own permission controls, I guess they're available through the win32 extension <11> the problem is that i dont use python myself and need to modify a script using shutil.rmtree that are unable to remove a file in the structure that is chmodded read-only <11> yesterday i was told to use walk() but then ill have to modify the script to such extent that im not sure it will work correctly even though it appears so <11> its a backup-script for subversion <11> hot-backup.py <11> the dream would be to use rmtree() and make it ignore the permissions :) <11> but i suppose that is not possible looking at python reference libraries <11> well, ill figure it out...thanks for your time <11> i think i figured it out, im gonna chmod the file explicitly <11> makes the script ugly though <12> I am having trouble running mod_python in debian(sarge), can I pick someone's brain about it? <13> what's the problem? <12> i used this demo: <12> http://www.modpython.org/live/current/doc-html/inst-testing.html <12> but it only worked if i changed the import line to: <12> import mod_python.apache as apache <12> instead of the the import ised in the manual: <12> from mod_python import apache <12> when i try to use mod_python.publisher as the handler, i get various errors.
Return to
#python or Go to some related
logs:
#politics xp oem without hardware #windows #worldcup zaina gadema L5 -30 amp extension cords #unixhelp ritilon #stocks Soccer Mom.avi
|
|