| |
| |
| |
|
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Comments:
<0> then the last error, stating the code, is in stderr <0> I could trap the output and search it <1> Yup, scraping stderr sounds the easiest, but it's fugly. <0> basically if stderr has anything, there's an error <0> on success, it's silent <0> a-ha, I think the commands module is what I want <2> Hello all <2> I'm writing a python program to convert one unit of measure to another, and I'm wondering: I set my variables to plural names (such as Gallons)....is there any way to knoock the s off the end, or must I create both singular and plural strings for each unit? <3> storyteller: is there a reason you are writing a program to do this? is it just a learning thing? <2> Both <3> also why not set it to singular and make it plural if there are more then one since adding a character is trivial <3> well unix has a units program you can use <3> it can convert just about anything <2> I'm writing it to help my gf understand conversions between units of measure, and learning python in the process <2> I was thinking much the same, but I figured if I could learn a new trick (i.e. how to remove letters from existing strings), all the better <2> I learned basic 20 years ago, and haven't written much code since...so I'm trying to learn python....I tried several other languages, but python just feels like home, even though I don't really know my way around it yet
<3> I would have just though that something like if quantity > 1: unitString = someBaseUnitString + 's' <4> for ndays in [0,1,2]: print '%2i day%s' %( ndays, 's '[ndays == 1] ), '//', <4> #==> 0 days // 1 day // 2 days // <2> lol <2> You lost me quick lol <2> What?!? <2> A no lol zone? <3> yup <4> for ndays in [0,1,2]: print ndays, ['days','day'][ndays == 1], '//', <4> #==> 0 days // 1 day // 2 days // <2> After seeing that, I think you would get a good chuckle out of what I have written <3> most of the time that people say those things they are not really laughing <5> strings are indexable, storyteller so 's ' is equivalent to (from an iteration point of view only, of course) ['s',' ']... then ndays == 1 will return either 0 or 1, being 1 only when ndays is 1 <4> The next release of Python, 2.5, will finally add a construct to address this need. <3> so it just gets annoying and most of the time <6> huh. that's a handy trick. indexing by booleans. <5> lol <3> Pythy: what do you mean? <4> kosh: The in-line value-returning `if' that's in 2.5 <3> oh the tri state stuff <3> you know you could just write a function to do it and use that <3> def tri(cond, var1, var2): if cond: return var1 else: return var2 <2> Here's my program thus far: http://pastebin.com/628209 <3> a = tri(test, var1, var2) <5> storyteller, so you get either the value of index 0 of the string 's ' which is s (when ndays is 0) and ' ' when ndays is 1, thus adding only a space <3> storyteller: have you read the tutorial? <2> Which tutorial? <2> I have read several tutorials, but am still very much a beginner <5> storyteller, am I wasting my keyboard for nothing or are you following? :P <6> Pythy: what's the most straightforward way of getting the number of elements of an iterable satisfying some condition? anything better than len([ x for x in L if f(x) ])? <3> http://docs.python.org/tut/tut.html <4> sum( 1 for v in l if p(v) ) <3> doesn't really change much either way <2> Yango: I'm trying...I'm reading the entire contents of my screen over and over <3> except it will probably take up very slightly less space and less ram <3> so Pythy's method is the best but it probably won't matter much in almost any case <5> storyteller, play with that in the interactive console and see what happens <4> gzl: And in place of what you wrote, len(filter(f, l)) is easier to eyeball. <6> Pythy: ok. thanks <4> The sum() solution, of course, avoids creating the unnecessary list. <6> right <2> Yango: Yup...you lost me lol <6> foolishly forgot about sum(), that was the one I was looking for <2> Sorry, you lost me ell oh ell <7> *blink* <5> storyteller, play with these and see what is happening 'ale'[1];'eye'[False];'are'[True];'no'[0];'fj'[1];'a'=='b';'a'=='a';1==2 <4> gzl: But using enumerate() and a for-loop in a function also has merit. <5> storyteller, then do the same, but with lists [1,2][0] and so on <2> Is that english? <2> I pasted that into a python promt and it spit on my shirt <2> I think this amounts to: "Write a ridiculously long script and cut it down as you learn more about pythin" <2> python* <3> Pythy: the main advantage of the sum solution is that for instance if you had a list of 1 million items and they where tuples with 3 entries or something the temp list would take up a huge ammount of room <6> storyteller: as long as you don't do this: http://thedailywtf.com/forums/60067/ShowPost.aspx <3> Pythy: your solution avoids having to allocate whatever the objects are in the seq <3> gzl: ah I remember reading that one :) <3> at least reading the dailywtf cheers me up <3> I learn that there are worse stuff out there then what I have had to deal with <6> yeah that one was hilarious
<3> http://thedailywtf.com/forums/65974/ShowPost.aspx HAHAHAHAHAHAHA! <3> after reading that one you will see why the zope security model is important :) <8> You can't have try/try/except/finally blocks to get around the non-unified try/except/finally problem? <3> this is why default allow and special stuff to deny is BAD :) <9> I have a problem. My high school wont allow me to ssh or bring in my laptop or wont install a python compiler for me to learn python. So is there any way I could run the compiler from my flash drive or any alternative? <9> Just out of curiosity. <10> Eclipse75: Installing or running python would reveal a host of security problems for the school. <3> Jerub: they probably have a huge number of security problems already <10> Eclipse75: the best I can suggest is being able to run python over a web browser or something, using something like spoj.sphere.org <3> why do you want to use python at school? <3> why not just use it at home? <10> Eclipse75: have you met the 'sphere online judge' yet? <9> because I never do anything at school, and I go to school where there is not a single descently computer literate person.. <9> Jerub, nope <3> you don't do anything at school? so I guess having good grades is out <10> Eclipse75: 'decently' <9> kosh, pretty much <9> Jerub, opps <3> okay so you don't do well in school and you want to have something else to do so you spend even less time on school stuff? <9> heh, pretty much <3> okay well my help is flat out <9> its just that it bores me. i can do it, it just does not represent any challenge or use any creativity. <1> It's okay, most paychecks are like that too. <3> I have heard that a lot <3> however most of the people I have heard that from are not as good as they think <3> I have seen some of the worse code solutions from those that claimed the stuff was too easy and presented no challenge <3> the dailywtf is full of their work ;) <9> hmm yah, but last year I done so in making good grades, just boring this year. <3> you should consider attending your english cl***es :) <1> It's not just the code. The number of times I have to explain basic civics, history, language, culture, science to cow-orkers, I cringe at the world in which my daughter will grow up. <9> :) isn't part of the dictionary is it? <11> Eclipse75: The best work you can do can be done with paper and a pencil first, then translated later. <9> i just came in here to get some information, so please dont hammer me for my school work.. <3> well my advice is I won't help <3> I don't think it would be ethical to help you solve your problem <12> hi hi people ^_^ <9> kosh, well thanks for being a jack*** <12> kosh: Yeah jeez <12> what? <12> >_> <9> 1m 0utty az Us illiterates would say... <12> <_< <9> =) <2> Eclipse75: Wait a sec <11> Eclipse: kosh is doing his best to help you. He's learned the lesson you'll only learn the hard way. <13> so i have a variable that is the constant gtk.gdk.INTERP_NEAREST.. if i do a "print var, gtk.gdk.INTERP_NEAREST", it shows that they're the same. but if i do "print var == gtk.gdk.INTERP_NEAREST", it says false. what? <12> tweekgeek: Too late, he died of AIDS. <3> I am trying to help you, it is just not the help you want <12> Crap, this place seems to be on-topic so I better leave. lol <2> Storycrest: Are you following me? <13> stoneteller: yes <13> how can it say false? they are both the same. <2> I thought I smelled sulpher... <3> stonecrest: can you do print type(var), type(gtk.gdk.INTERP_NEAREST) and tell me what that says? <12> Oh wow, one cannot type l o l here. -_- <12> bye bye <1> That person was in here for 90sec and already I loathed. <13> kosh: ahh.. thank you :) is there any way to convert a string "gtk.gdk.INTERP_NEAREST" to that constant? <2> I was going to tell Eclipse75 how to install programs on most windows systems that aren't well administered ell oh ell <3> stonecrest: what do the two things say? <13> kosh: <type 'str'> <cl*** 'gtk.gdk.InterpType'> <3> okay can print str(var) == str(gtk.gdk.INTERP_NEAREST) <3> see what that does <1> Euygh. <14> I'd like to be able to interact with the DOM for an XHTML element mcuh in the way I might in JavaScript. I see the xml.dom module, but I am a total newbie when it comes to parsing. So my question may be too broad. How do I get a DOM "object" from an XHTML file? <13> kosh: it says True.. is there any way to convert the other way though, and compare as type GdkInterpType? <3> storyteller: yeah because if he gets caught doing your method he can be charged with a felony, that will sure make life a lot better <3> storyteller: it seems they don't want that stuff on there and he has already found that out <3> stonecrest: I don't know about that one, I don't use gtk and you would need a constructor somewhere to convert <13> kosh: i see.. okay, i'll just use a bunch of if statements then. thanks for the help <3> stonecrest: why not convert it to a string like I just did? <13> kosh: because elsewhere i need to use it of type GdkInterpType (for scaling images, etc) <3> so make a local copy that has it converted <3> and don't change the original
Return to
#python or Go to some related
logs:
gnome mixer applet gentoo 2.14 unknown option dhcp.option-150 #math asound.state+gentoo GTK_CONFIG experiment high freq start
#perl #mysql dpkg-deb: parse error, in file `./DEBIAN/control' near line 7:
missing package genkernel freezes
|
|