2

I've recently started learning python and got tired of running it on the command line (terminal mac os x). I wanted an environment that I could code nicely in and run that code only when pieces of it were done, not line-by-line as in the shell. I decided to use Xcode as the interface is clean and simple, and followed this tutorial to set up Xcode so that I could run python scripts.

My problem is that when I use raw_input() and then click run, I can't type a value to pass to the variable it's stored in. Take this simple line for example:

word = raw_input("Enter a word: ")

Later on in the program, word is printed. When I click run on Xcode, the prompt shows up as expected in the console:

Enter a word:

However, I can not type anything into it, the cursor is blinking so I know it is responding but when I type a value, nothing happens. I'm not sure what is wrong here, hopefully one of you can help me out.

3
  • might be xcode problem. Try to run the python script from console. I don't understand your reason, even though you're using shell, you can execute an entire file, no need to be line-by-line (interactive) Commented Aug 25, 2013 at 8:41
  • Hi I met the same problem. Have you found an answer in the end? Commented Jun 30, 2015 at 20:06
  • @Denoising the problem is that XCode is meant for Apple development, OS X and iOS, so I would recommend using a different IDE such as Aptana Studio, mentioned below in one of the answers Commented Jul 1, 2015 at 1:57

2 Answers 2

1

If you really want to use an IDE for Python development, go for Aptana Studio 3 .

Once you are done with Pydev setup which is very easy Refer this for Pydev Setup.

Before running a script which expects some command line inputs you can click on the small arrow button adjacent to run button, it will give you a drop down menu with different options. Click on run configurations and then click on a tab named Arguments and enter your parameters there in the field names Program Arguments. Click on apply and you are good to go.

Next time you need to run the code just click on run and it will automatically fetch arguments that you have specified in the option above.

Hope this help.

Sign up to request clarification or add additional context in comments.

3 Comments

i marked this as the answer because its a good solution, im still curious as to why raw_input doesnt run correctly in xcode? could it be a bug or something simpler?
@samrap I have never used Xcode personally, so I cant give you an answer for that. But I have tried other IDEs for Python development and found Aptana to be the best. Its actually eclipse based but quite light and efficient. Give it a try u will love it
just following up. thanks for the aptana 3 recommendation - love the functionality and pydev. its great for testing individual parts, then using the shell to execute the entire program. thanks again! @abhi
1

You just need a text editor to store you Python script and run it in Terminal whenever you like. As an example, I use emacs. You may use vi, Sublime Text 2, TextWrangler or many other alternatives.

$ emacs a.py
word = raw_input("Enter a word: ")
print "Your word is: %s" % word

After the a.py file is saved, simply cd to the directory and run the script in Terminal.

$ python a.py
Enter a word: Hello
Your word is: Hello

Or import your script as a module under interactive mode.

$ python
>>> import a
Enter a word: Hello
Your word is: Hello

1 Comment

yea i did know about this way, but I was looking for an app that i could run the code in immediately, without having to switch between terminal and the editor. It does only take a few seconds, so i guess it's not that big of a deal i just thought it was strange that it wasnt working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.