Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50815 > unrolled thread
| Started by | bbechdol@gmail.com |
|---|---|
| First post | 2013-07-17 18:44 -0700 |
| Last post | 2013-07-17 19:19 -0700 |
| Articles | 7 — 3 participants |
Back to article view | Back to comp.lang.python
Need help with network script bbechdol@gmail.com - 2013-07-17 18:44 -0700
Re: Need help with network script Chris Angelico <rosuav@gmail.com> - 2013-07-18 11:50 +1000
Re: Need help with network script bbechdol@gmail.com - 2013-07-17 18:59 -0700
Re: Need help with network script bbechdol@gmail.com - 2013-07-17 19:01 -0700
Re: Need help with network script Chris Angelico <rosuav@gmail.com> - 2013-07-18 15:38 +1000
Re: Need help with network script Dave Angel <davea@davea.name> - 2013-07-17 22:06 -0400
Re: Need help with network script bbechdol@gmail.com - 2013-07-17 19:19 -0700
| From | bbechdol@gmail.com |
|---|---|
| Date | 2013-07-17 18:44 -0700 |
| Subject | Need help with network script |
| Message-ID | <c3e795f9-b195-4a51-99ff-9289f0277280@googlegroups.com> |
Hi everyone. I am starting to learn python and I decided to start with what I though was a simple script but I guess now. All I want to do is return what current network location I am using on my mac. Every time I run it, it gives me back a 0. I don't know what I am doing wrong so here is my code. I really hope some one can help me. This script is unique to MACS btw. import sys import subprocess loc = "scselect" srn = "scselect SRN" home = "scselect HOME" a = subprocess.call(loc, shell=True, stdout=subprocess.PIPE) b = subprocess.call(srn, shell=True, stdout=subprocess.PIPE) c = subprocess.call(home, shell=True, stdout=subprocess.PIPE) print "\n##### NETWORK SELECTION #####" print "\nYour current location is set to \n%s" (a)
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-07-18 11:50 +1000 |
| Message-ID | <mailman.4820.1374112253.3114.python-list@python.org> |
| In reply to | #50815 |
On Thu, Jul 18, 2013 at 11:44 AM, <bbechdol@gmail.com> wrote: > Hi everyone. I am starting to learn python and I decided to start with what I though was a simple script but I guess now. All I want to do is return what current network location I am using on my mac. Every time I run it, it gives me back a 0. I don't know what I am doing wrong so here is my code. I really hope some one can help me. This script is unique to MACS btw. > > import sys > import subprocess > > loc = "scselect" > srn = "scselect SRN" > home = "scselect HOME" > > a = subprocess.call(loc, shell=True, stdout=subprocess.PIPE) > b = subprocess.call(srn, shell=True, stdout=subprocess.PIPE) > c = subprocess.call(home, shell=True, stdout=subprocess.PIPE) > > print "\n##### NETWORK SELECTION #####" > print "\nYour current location is set to \n%s" (a) Your last line here looks wrong. Is this really the code you're using? This code will crash with a TypeError, because you're trying to call a string. Copy and paste your actual code, don't re-type it :) ChrisA
[toc] | [prev] | [next] | [standalone]
| From | bbechdol@gmail.com |
|---|---|
| Date | 2013-07-17 18:59 -0700 |
| Message-ID | <92f2a326-de72-459c-86b4-391aa530d866@googlegroups.com> |
| In reply to | #50816 |
On Wednesday, July 17, 2013 7:50:44 PM UTC-6, Chris Angelico wrote: > On Thu, Jul 18, 2013 at 11:44 AM, > > > Hi everyone. I am starting to learn python and I decided to start with what I though was a simple script but I guess now. All I want to do is return what current network location I am using on my mac. Every time I run it, it gives me back a 0. I don't know what I am doing wrong so here is my code. I really hope some one can help me. This script is unique to MACS btw. > > > > > > import sys > > > import subprocess > > > > > > loc = "scselect" > > > srn = "scselect SRN" > > > home = "scselect HOME" > > > > > > a = subprocess.call(loc, shell=True, stdout=subprocess.PIPE) > > > b = subprocess.call(srn, shell=True, stdout=subprocess.PIPE) > > > c = subprocess.call(home, shell=True, stdout=subprocess.PIPE) > > > > > > print "\n##### NETWORK SELECTION #####" > > > print "\nYour current location is set to \n%s" (a) > > > > Your last line here looks wrong. Is this really the code you're using? > > This code will crash with a TypeError, because you're trying to call a > > string. > > > > Copy and paste your actual code, don't re-type it :) > > > > ChrisA This is as far as I have gotten. THis is all my code and it has been copied and pasted. Thats why I am posting here. I know that the code can be better. Once I learn more it wont look like crap.
[toc] | [prev] | [next] | [standalone]
| From | bbechdol@gmail.com |
|---|---|
| Date | 2013-07-17 19:01 -0700 |
| Message-ID | <c83da601-8adb-45a4-a90c-6897f062ad97@googlegroups.com> |
| In reply to | #50817 |
Im trying to get the output from "scselect" and display it on a new line.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-07-18 15:38 +1000 |
| Message-ID | <mailman.4824.1374125901.3114.python-list@python.org> |
| In reply to | #50817 |
On Thu, Jul 18, 2013 at 11:59 AM, <bbechdol@gmail.com> wrote: > On Wednesday, July 17, 2013 7:50:44 PM UTC-6, Chris Angelico wrote: >> >> Copy and paste your actual code, don't re-type it :) > > This is as far as I have gotten. THis is all my code and it has been copied and pasted. Thats why I am posting here. I know that the code can be better. Once I learn more it wont look like crap. My point is that that can't be the code that always outputs "0", because the code above would not output 0, it would terminate with TypeError. By the way, if you're going to use Google Groups, please read this: http://wiki.python.org/moin/GoogleGroupsPython ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-07-17 22:06 -0400 |
| Message-ID | <mailman.4821.1374113204.3114.python-list@python.org> |
| In reply to | #50815 |
On 07/17/2013 09:50 PM, Chris Angelico wrote: > On Thu, Jul 18, 2013 at 11:44 AM, <bbechdol@gmail.com> wrote: >> Hi everyone. I am starting to learn python and I decided to start with what I though was a simple script but I guess now. All I want to do is return what current network location I am using on my mac. Every time I run it, it gives me back a 0. I don't know what I am doing wrong so here is my code. I really hope some one can help me. This script is unique to MACS btw. >> >> import sys >> import subprocess >> >> loc = "scselect" >> srn = "scselect SRN" >> home = "scselect HOME" >> >> a = subprocess.call(loc, shell=True, stdout=subprocess.PIPE) >> b = subprocess.call(srn, shell=True, stdout=subprocess.PIPE) >> c = subprocess.call(home, shell=True, stdout=subprocess.PIPE) >> >> print "\n##### NETWORK SELECTION #####" >> print "\nYour current location is set to \n%s" (a) > > Your last line here looks wrong. Is this really the code you're using? > This code will crash with a TypeError, because you're trying to call a > string. > > Copy and paste your actual code, don't re-type it :) > In addition to reposting using copy/paste, please specify the Python version. There were differences between 2.6 and 2.7. Short answer is that subprocess.call() returns an integral returncode. So zero tells you that shelling to the subprocess succeeded. Perhaps you'd like to use subprocess.check_output() instead of subprocess.call(). -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | bbechdol@gmail.com |
|---|---|
| Date | 2013-07-17 19:19 -0700 |
| Message-ID | <d3b76362-f4df-4be8-a279-31f65cffa217@googlegroups.com> |
| In reply to | #50820 |
> In addition to reposting using copy/paste, please specify the Python > > version. There were differences between 2.6 and 2.7. > > > > Short answer is that subprocess.call() returns an integral returncode. > > So zero tells you that shelling to the subprocess succeeded. > > > > Perhaps you'd like to use subprocess.check_output() instead of > > subprocess.call(). > > > > > > -- > > DaveA I will try that. I am using Python 2.7
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web