@# 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> eleaf: empty line is '\n', nothing is ''
<0> Sulis: maybe with os x it is \n
<1> It doesn't seem to be working.
<2> Are you sure your empty line has no whitespace also in it?
<2> print repr(ln)
<1> not catching my if statement I'm not sure what it is.
<1> Pythy, it could have whitespace...
<3> ChrisLong: i'm just wondering cos mac is based on some BSD...vaguely
<0> eleaf: print repr(line)
<1> Sulis, I find a lot of the escape characters etc are different. In the terminal you can use the apple key to copy and stuff so you don't have to use the ctrl key, and that can make things different, I don't know.. ;p
<0> Sulis: it's quite possible that \r is from macOS<=9 times
<1> ChrisLong, where do I put that..?
<3> Eleaf: but all that's just GUI stuff, not really important
<0> Eleaf: before the if, or in the else:
<1> Sulis, true.
<1> ChrisLong, I get a new line and below that, a "0"



<0> against the line ending problem, python has open(name,"rU")
<1> It might help to show you the command I'm doing generating the line.
<1> os.system("ftpwho | grep user | awk '{print $4}'")
<1> so there is some grepping and stuff going on there.
<0> Eleaf: are you sure your line is a string? you sould have gotten someting in quotes
<1> hmm
<1> that's the command above, I didn't get quotes
<0> os.system does not return the output to your program
<1> ChrisLong, it does..
<1> that command shows how many users are connected to my ftp server
<1> if there is 1 or more, it prints the number.
<0> Eleaf: no, the output is printed to your terminal
<1> alright, I see.
<3> you need popen() i think
<1> alright, os.popen?
<0> Eleaf: you want to use subprocess.Popen or subprocess.call
<2> or os.popen()
<1> that doesn't seem to work..
<1> the command gets broken..
<4> hi - what's the best way to do manpages in distutils?
<0> "This module intends to replace several other, older modules and functions, like: os.system,os.spawn*, os.popen*,popen2.*,commands.*" from the subprocess doc
<1> <open file 'ftpwho | grep user | awk '{print $4}'', mode 'r' at 0xb7d10260>
<1> awk: close failed on file /dev/stdout (Broken pipe)
<2> First get the command working at the shell-prompt, leaving Python out of equation.
<1> Pythy, it does work
<1> doesn't work when it is done with popen
<2> Eleaf: os.popen() returns a file-object, not a string.
<1> alright..
<0> Eleaf: result=os.popen("ftpwho | grep user | awk '{print $4}'").read()
<1> well I need the output of the command.
<3> that looks like a string to me...
<1> I don't want it to tell me 'broken pipe', I want it to tell me what os.system told me.
<1> alright, hold on
<1> okay, that gave me two enter spaces ChrisLong
<1> and when somebody is connected to my ftp, a "1" and another line space.
<2> Hmmm...gives me one enter space and a ChrisInt here.
<0> here i get ftpwho: command not found :)
<3> lol
<1> ;p
<3> ChrisLong: i wonder why that could be :P
<1> ChrisLong, make sure you install the ftp package, to do this, send a check addressed to me with a bulky sum.
<3> Eleaf: you need more maths homework?
<3> bulky sums can be difficult, if you get stuck just use a calculator
<1> now why am I getting all these enter spaces whenever I do popen reading the output??
<1> That's lame..
<1> Sulis, lol
<1> it catches my if '\n' statement though
<1> I don't know why popen generates so much blank space, any ideas?
<2> Since each line read still has a \n, you don't need to append another one yourself.
<1> I'm not appending one..
<2> print does.
<0> Eleaf: print appends one
<1> oh.
<1> alright, cool, I think I got that working then..
<1> except not.
<1> if I don't add a print to it, it doesn't print it to the console
<1> ;p
<1> I need it to print to the console without adding a bunch of line breaks
<0> use line.strip()
<1> uhh, on what part?



<1> do I need to import 'line'? ..
<0> i mean result.strip()
<0> on the result from the popen call
<0> it's a string method
<3> but the result isn't a string...blah...blahh
<5> Eleaf: just print string[:-1], but make sure len(string) > 0 first
<1> sorry, I had to let a spider out... o.O
<0> Sulis: the result from os.open should be a string
<0> i mean from op.popen().read()
<1> hmmm
<2> RandolphCarter: The last line may or may not terminate with a eoln.
<1> ahh, why does it have to be so difficult to get the result of a command and print it.. ;p
<3> ChrisLong: yeah
<0> *sigh* os.popen has to many o's and p's :)
<5> Pythy: hence checking len > 0?
<1> I'm not sure which I should do?
<5> Pythy: ahh, I see what you mean. Test for \n then I guess
<1> result.strip or string[...
<0> strip(), it's easier, no need for an if
<2> s.rstrip()
<1> wait...
<5> print string[-1] == "\n" and string[:-1] or string
<2> (if you want to go that route.)
<1> I'm so confused again..
<1> RandolphCarter, the string changes.
<1> RandolphCarter, I'm making it if there is nothing, or just a line break, print "0", or just have it continue on.
<1> and print the number as normal
<6> http://news.zdnet.com/2100-9588_22-6077455.html LOLROFLMAOLOL
<2> RandolphCarter: (BTW: ""[:-1] won't raise an IndexError.)
<5> Pythy: my word, so it doesn't, I just always ***umed it would do :/
<1> RandolphCarter, I don't know how that worked... o.O
<2> "Eleaf|ahh, why does it have to be so difficult to get the result of a command and print it.." > sys.stdout.writelines(os.popen("ls"))
<1> RandolphCarter, but I need it to print "0" if it ends up being just a linespace
<1> oh I just keep my if in there..
<5> print string == "\n" and 0 or (string[-1] == "\n" and string[:-1] or string)
<5> getting fairly ugly though, probably best to keep the if
<0> Eleaf: result=os.popen(...).read().strip() , then result=='' if there is noone
<1> yea, I'll keep an if before that and have your earlier statement the else.
<1> hmm.
<1> It's just that I've never done things this way, so it's all confusing me.. ;p
<2> Then imagine how we feel.
<1> Alright, so let me recap. If you are doing an os.system call, like a = os.system('ls'), you cannot really modify a because it is not a string, from the output of ls
<5> it's the return code :/
<2> Eleaf: Are you familiar with return-codes?
<1> Pythy, possibly, what do you mean?
<7> What a function returns.
<1> RandolphCarter, is my statement correct?
<5> Eleaf: it depends what you want to do, if you want to read the output of 'ls', you need to use os.popen
<1> RandolphCarter, as in, if you wanted to take ls and modify it?
<2> Eleaf: When a application terminates, the application p***es a small integer back to the OS.
<1> i.e. find the linebreaks in it
<5> Eleaf: yeah, or use the output to do anything useful (although, there are much better ways to list directories in python)
<1> RandolphCarter, yea. I usually use the other os.* things to do that. Like os.listdir.
<1> RandolphCarter, os.listdir creates the results as editable strings correct? I usually use this method and was confused when I needed to do things with the output of a non-python-module'd system command.
<1> Alright, now to get php to p*** the results of this python program to the webpage.. ;)
<2> The convention is: If that integer -- the return-code -- is 0, it signifies a normal termination, other values signify an abnormal termination. This is the value Python returns to you, as the value of os.system()
<2> "RandolphCarter|print string == "\n" and 0 or" >
<2> >>> print "\n" == "\n" and 0 or 99 #==> 99
<2> >>> print "hi" == "\n" and 0 or 99 #==> 99
<4> how do i include manpages in distutils?
<8> wchun: ooh, neat. i like the part about compiling structs
<5> Pythy: we might as well be coding in perl ;)
<5> Pythy: grr, that's not correct
<2> exactly.
<0> result=os.popen(...).read().strip()
<0> if not result: print 0
<0> else: print result
<5> >>> a = ("\n" == "\n") and 1 or 2
<5> = 1
<5> so where's the exception for print?
<2> ("\n" == "\n") and 0 or 2 #==> 2
<2> >>> bool(0) #==> False
<2> >>> True and False or 2 #==> 2


Name:

Comments:

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






Return to #python
or
Go to some related logs:

siocsifnetmask gentoo
mysql-admin selinux fc5
#oe
mysql multiple record concat one row
force unmount cifs Device or resource busy
debian discontinued processor architectures
#php
cryptstorage
#python
bash script speacker



Home  |  disclaimer  |  contact  |  submit quotes