@# 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> Parks: eh?
<1> im trying to read from a popen object and it seems to be blocking waiting for EOF or the process to terminate
<1> and i tried both bufsize 1 and 0
<2> is there a way to do something like __import__(full_path...?
<0> procyon: The code I gave above works just fine---provided you kill any buffering of the son-processes.
<3> Pythy, what's the difference between the code that's like >>> print and print
<1> i flush the stdout of the child process and it doesnt work
<0> dijix: But, for variable-length prefix-testing, s.startswith(x) avoids having to cope with the length of the prefix (and avoids a slice-operation, which creates a new string).
<1> Pythy: ok i tried something slightly differnet and now it works
<1> thanks
<4> Pythy: nice
<0> opioyd: the `>>> '-prefix you see on some lines pasted here is the prompt from the Python-interactive, from which the text was copy-and-pasted ("C&P'ed").
<0> procyon: What change did you make?
<5> does string.strip() take away the '/' from "/bob"
<4> print '/bob'.strip() should tell the tale..
<1> its the flush in the child process



<0> procyon: Is the son-process written in Python?
<6> okay, I'm a moron at python, so bear with me. I've got a list I've got sorted how I want. I iterate through this list like: for x in sortedlist: sortedlist[x] = "foo"
<6> now it's out of order.
<6> I need this dictionary to retain the sorting I did to the list, is that possible?
<1> the child process is currently a dummy python script for testing, its eventually going to be a growisofs session
<0> "procyon|its the flush in the child process" > As in, you didn't have one till I reminded you?
<1> well i added it before you mentioned it
<1> but with a different iterator
<0> Procyon: What iterator did you use?
<1> the problem is i dont know if growisofs is going to fflush
<1> i was doing a for i in foo.readline()
<6> or since "dictionaries have no order", is it impossible to have key-value pairs in a certain wanted order?
<3> are there any other ebooks or tutorials for a complete bigginer.
<4> floam: you can iterate through your sorted list and use them as keys to your dictionary
<0> opioyd: The was an extensive list in what the bot sent you.
<6> dijix: isn't that what I did?
<3> Pythy, there were only 4 books that i got in the pm
<6> for x in sortedlist: dictinoary[x] = "foo"
<1> Pythy: is there anyway to do this without blocking on a line buffered pty
<0> "i was doing a for i in foo.readline()" > procyon: And then you replaced that with what I gave you, but, at the same time, you decided to let the son-process buffer?
<6> for x in sortedlist: dictionary[x] = "foo"
<6> kills the order
<0> #@?>tutorials@
<1> Pythy: i added the flush() to the child and remved a sleep(), it would print but once the process exited
<1> not using the iter() method
<1> so then i went back to your method when you mentioned it
<0> opioyd: I see 17 beginner books listed in one of the URLs you were sent.
<4> floam: there's no order inside the dictionary.. if you wanted to print them out in order, you'd have to do somethign like.. for x in sortedlist: print dictionary[x]
<6> yeah, I was hoping I could avoid that. This data gets outputted in like ten different places, in different contexts
<0> Procyon: "so then i went back to your method" > (I don't follow..."went *back* to my method"?)
<4> floam: or, if a standard sort() is what you're looking for: for x in sorted(dictionary): print dictionary[x] that avoids the intermediate list
<1> changed for i in foo.readline() to foo = iter() and for i in foo
<1> heh now i am getting confused
<6> but thanks, I think I know what I'll do now
<0> opioyd: Look at the first link, "How to Think...", as that is often recommended.
<7> anyone know how I might go about getting the equation of a line that is x degrees rotated around a point?
<0> mx + b, trig gives you the slope
<7> ah. Trig. Fun :) What area of it might I look in?
<0> narg: Google: mx + b
<7> pythy: I know how to use mx+b... :p Its finding the slope that is the problem.
<8> narg: arctan(y/x)
<8> narg: iirc
<7> Jerub: thanks, I'll go look that up.
<9> how is an abstract base method defined?
<5> str = "/bob" then str = str[1,-1] -> bo ... how do i get bob?
<5> i mean str[1:-1]
<10> str="/bob"; str[1:] ==> 'bob'
<5> ah thanks
<11> hi all
<11> a simple dictionary query
<11> >>> a={'a':'2','b':'3','c':'4'}
<11> >>> a
<11> {'a': '2', 'c': '4', 'b': '3'}
<11> why does it change the order unnecessary?
<12> dictionaries are unordered.
<11> sysfault: yes I know
<4> so then the order it prints is arbitrary..
<11> but si there any specific logic to change order which I gave
<11> Now I have a data file with synatax,
<11> date name amount code credit
<11> now I have got name and amount successfully in a dict



<11> I really need to sort it on basis of amount
<11> can anyone give a clue (I was able to sort according to name)
<9> is there documentation on defining different types of methods in python, ie abstract base, instance method, cl*** method, etc.
<4> payal: for x in sorted(dict.values()): print dict[x]
<11> dijix: what is this "sorted"
<2> is there a way to do something like __import__(full_path...?
<4> payal: built-in function
<13> how do I do tail recursion in python...every time I try to do code where it only outputs on the last iteration, i get messed up by each other subloop returning 'None
<0> http://doc.python.org/lib/module-imp.html
<13> can I turn off the 'None
<11> dijix: can you point me to a doc for this specific thing
<5> gaw foreach not a python keyword?
<0> cyclic: use the `return x'-statement, and return whatever you like. (I don't see why `None' is causing you grief.)
<0> SupIAmMike: Which tutorials are you using?
<11> for x in sorted(dict.values()): print dict[x] gives an error --> KeyError: '1'
<9> nevermind, I'll just create a cl*** instance
<12> payal: you access by key, not by value.
<11> also one more thing, >>> print sorted(dict.values())
<11> ['1', '100', '10000', '20']
<11> which is wrong.
<11> sysfault: I want to sort by values
<11> the person who has taken max. amount should come last.
<8> payal: the values are strings, to convert them to ints, you need to call int('10') to get 10
<8> payal: also, that's a dict, dicts aren't ordered.
<8> what you probably want is something along the lines of:
<12> look at the optional sort arguments..
<8> sorted(dict.items(), key=lambda (k,v):int(v))
<5> how do i remove "bob" from an array - do i have to find the index?
<11> Jerub: offf!!! I haven't come to lambda yet
<11> >>> print dict.values.int()
<11> AttributeError: 'builtin_function_or_method' object has no attribute 'int'
<13> Pythy, because when I do something like def foo(n,b): if n==1: return b else: foo(n/2,b+1) instead of just returning a number, it returns the return value of the last function to finish, which is None
<4> for i in sorted(int(x) for x in dict.values()): print dict[i]
<11> dijix: KeyError: 1
<0> "else: foo(n/2,b+1)" --> else: return foo(n/2,b+1)
<8> payal: uh, my solution will work.
<8> just so you know
<8> :)
<9> is there a succinct way of expressing a list of strings, like ('foo', 'bar', 'etc.')
<4> oops..
<8> payal: I recommend playing with it a bit before you continue asking for help :)
<11> Jerub: I have to study lamda first then I believe
<4> cr3: you mean something like ['foo', 'bar', 'etc.'] ? :)
<0> 'foo bar etc.'.split() # ***uming no embedded whitespace in the elements. #==> ['foo', 'bar', 'etc.']
<8> payal: why? just accept that it works.
<11> Jerub: no no no, I am convinced but I won't use it till I understand
<13> Pythy ... ahh...that was actually the first way I did it...but then I had a different eror and thought that it was the problem...thanks though
<4> for i in sorted(int(x) for x in dict.values()): print dict[str(i)]
<4> though that only works for that particular dictionary strucuture.. no error handling..
<0> cyclic: But best to replace tail-recursion with a loop.
<11> dijix: KeyError: '1'
<4> payal: ack.. I'm using the value as the key..
<0> cyclic: Unlike, e.g., Lisp, Python doesn't do that optimization for you.
<0> cyclic: And Python's (default) max recursion limit is a depth of 1,000
<13> ahh, im used to Scheme (a lisp dialect) for this kind of stuff...what doesn't it do for you exactly?
<4> payal: you can tell what I'm getting at, though.. heh.. one of the perils of trying to code on an irc line.
<0> Cyclic: You're limited to a maximum recursive depth of 1,000 (by default---a default you *don't* want to alter, BTW). Iteration will also be faster.
<11> dijix: yes I will do it with lamda maybe later
<13> i always learned that tail recursion was basically just like iteration, since you are basically just recursing on a counter variable, and don't need to store any results from previous functions
<11> dijix: actually this was an awk program which I am using for months, I thought maybe Python can do it more easily
<4> payal: Yes you should
<11> dijix: ?
<13> seems to be true space wise, but could get messed up with a max recursion depth
<4> payal: yes?
<13> anyways, new question
<11> dijix: nothing ;0
<11> ;)
<4> new answers for new questions
<13> if I do something like for i in list
<13> when the list has 1000 members...but remove parts of the list in the body of the loop, will python go to the next original element, or the next new element
<0> cyclic: If you delete an element of a list which is the basis of your iterator, then, all the elements with higher subscripts immediately "slide to the left" one position.
<4> In other words, mind what you're doing
<13> and the loop looks at the list by reference rather than value?
<0> cyclic: It's often best to simply create a new list. Otherwise, working from right-to-left will help you maintain your sanity.


Name:

Comments:

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






Return to #python
or
Go to some related logs:

gentoo libXaw.so.8
bash script speacker
#qemu
#perl
#debian
mysql splitdebug
#perl
rhel4 mysql5
kaffeine kubuntu xvid
#gaim



Home  |  disclaimer  |  contact  |  submit quotes