Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-25-2007, 07:37 PM   #1
LQ Newbie
Registered: Apr 2005
Location: "Big D" - Dallas, Texas
Distribution: Linux Mint 8 - "Helena"
Posts: 24

Rep: Reputation: 15
Problem with Python code under Linux

Hi all,

I am working on moving a small Python script from Windows to Linux and am running into a problem with one section of the code. Here is the snippet that is giving me problems.

for x in Dict1.keys():
        return_code =["/bin/ping -q -c 3",Dict1[x]])
        if return_code == 0:
            f.write(str(roomNo[i]) + ": \t " + str(Dict1[x]) + "\t Pass \n")
            i = i + 1
            num_pass = num_pass + 1
        elif return_code == 1:
            f.write(str(roomNo[i]) + ": \t " + str(Dict1[x]) + "\t Fail \n")
            i = i + 1
            num_fail = num_fail + 1
This code, modified accordingly, runs just fine under windows. Under Linux, it has a problem with the argument to the subprocess call. Here is the traceback:

Traceback (most recent call last):
  File "./", line 323, in ?
  File "./", line 304, in main
  File "./", line 129, in testIP
    return_code =["/bin/ping -q -c 3",Dict1[x]])
  File "/usr/lib/python2.4/", line 412, in call
    return Popen(*args, **kwargs).wait()
  File "/usr/lib/python2.4/", line 542, in __init__
    errread, errwrite)
  File "/usr/lib/python2.4/", line 975, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
Thanks in advance

Old 10-25-2007, 11:18 PM   #2
Registered: Oct 2003
Distribution: Archlinux
Posts: 147

Rep: Reputation: 21
separate each item.

return_code =["/bin/ping", "-q", "-c", "3",Dict1[x]])
or join them all up into one string and use shell=True

return_code =" ".join(["/bin/ping -q -c 3",Dict1[x]]), shell=True)
Read this for more info on the difference:

you don't need the .keys(), this should iterate over the dictionary keys just fine:
for x in Dict1:

Last edited by angrybanana; 10-25-2007 at 11:25 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Attribute error in python code digitalbrutus Programming 1 08-15-2006 04:39 PM
What is wrong with this python code ? indian Programming 5 09-22-2005 03:20 PM
converting vb6 code to python mrobertson Programming 2 06-02-2005 02:27 PM
easy python code JoeUser11 Programming 1 01-21-2005 02:40 AM
Trouble Python Code Gerardoj Programming 0 11-30-2003 05:31 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:28 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration