Enthought Canopy User Input - python-2.7

I'm using Enthought Canopy on Mac OSX Lion. I'm using this because of the ease at which modules and libraries can be downloaded and installed (had a lot of trouble downloading pandas and numpy through terminal due to a number of issues).
So, now I'm doing my coding for a project in Canopy, which is OK (still prefer Wing, though). The problem I have encountered is that I need to ask the user for input. When I do, for instance:
x = input('Enter your input here: ')
I get an EOF error as follows: EOFError: EOF when reading a line
I was looking around and believe that this may be something which Canopy does not support. Was wondering if this is, indeed, the case and if there is a solution/workaround to this problem?

I assume that you are entering this code in the IPython shell that is embedded in the Canopy editor. This is an upstream bug/deficiency in IPython's Qt console. Because the remote shell is not actually hooked up to a terminal, functions like input() and raw_input() need to be replaced to get the input from the GUI console widget instead. IPython (and thus Canopy) does replace raw_input() but does not replace input(). This code will work using Canopy's Python interpreter if you were to put it into a script and execute it from the command line, and it would also work in a terminal instance of IPython. It was most likely overlooked because it is usually considered a bad idea to use input().
Please use raw_input() instead and parse the string that you get. You can use eval() if you must, but I do recommend using a more specific parsing/conversion function.

Related

Running Python programs in python.exe, the command prompt, and IDLE

Let me preface this post that I am incredibly new to python. I took a course in codeacademy but haven't actually used python on my own computer until now. Let me also explain to everyone that my coding experience is limited to VBA and excel. I have very little knowledge of how to use the command prompt, how libraries work, etc, etc.
I'm having some issues. I've changed my directory to recognize python when I type python in my command prompt. Then I can do simple things like
print "hello"
however if i write something like this
def firstfunction(t):
print t+5
return
firstfunction(5)
I would expect this to print the number 10, however I get the following error:
File"stdin", line 4
first function(5)
^
syntaxerror: invalid syntax
However if I use this in IDLE and run it it works fine.
Next I've saved some python programs I wrote. One I saved as Hello.py
i want to run this code from my python exe or from the command prompt but can't figure out how.
Please any answers helpful, if you use computer lingo, try and keep it as simple as possible. I'm super new!
Thanks
If the location of python is not included in your path, add it. But in any case, you should be able to run this successfully from the directory containing your python.exe.
e.g, if python lives in C:\Python27:
cd C:\Python27
python mypythonscript.py

Enthought Canopy does not read data from or write data to csv files for Python

To my knowledge, the Code Editor application from Enthought Canopy is not able to read from or write to a csv file when using the csv module in Python 2.7.
As far as I master the technical knowledge of what is happening on the background the problem, if any, occurs when the for loop is called to print the data in the csv file. The program simply prints out nothing. Even if an additional print function is added to the for loop, nothing happens. It seems like the whole for loop is neglected. There must be something goes on wrong since the code does work in the Python 2.7 software program itself. The picture in the link below depicts the code and the outcome in the original Python 2.7 on the left and in the Enthought Canopy version on the right.
http://imgur.com/VPoFOgK
Could someone please inform me what hinders the code to execute the read and write functions?
The only way that I have been able to replicate this problem is to have an empty "coord.csv" file in my Canopy working directory. Otherwise python will raise an IOError exception. Your Canopy working directory is set to "C:\Users\Peter-Jan", but it seems like everything else is in "W:\Dropbox\School\UGent\2elEOR...". Try either changing your working directory to the location of "coord.csv", or if it is in the same location as "_read_write_csv.py" select "Keep Directory Synced To Editor" in the drop down menu.
Enthought Support here. This is odd. I cannot reproduce this problem in the current version, Canopy 1.5.5. From the ticket that you submitted to us, your Canopy version is 1.4.1.
To update Canopy to the latest version, please see this article.

Sublime Text 2: Ctrl + b error message when building Python 2.7 program

Whenever I try to build code in Sublime Text 2 (Python 2.7) in which there is either input() or raw_input(), I get this error:
EOFError: EOF when reading a line
[Finished in 0.1s with exit code 1]
I've found some tutorials that said it's a problem about ST not locating Python, so I edited the file that should have fixed it, to no avail. I still get the same error.
What is the problem here, and how can this be fixed?
It's not an issue with ST not locating Python, rather, it's the fact that ST does not support interactivity when building programs - input()/raw_input() in Python, gets in Ruby, scanf and associates in C/C++, Scanner in Java, etc. For compiled languages, the workaround is to run your program through the shell, which handles input. This can also be done with interpreted languages like Python, Ruby, Perl, etc., but for many people their preferred solution is to use SublimeREPL, available via Package Control. This essentially runs an interactive Python shell within Sublime, either the standard Python shell or IPython, which I prefer for a number of reasons.
SublimeREPL comes with a series of commands for taking lines, blocks, selections, or entire code files and passing them through the REPL (it has to be started manually first), which then takes care of handling input and output. Alternatively, if you're just testing smaller snippets of code, you can just enter and run it within SublimeREPL itself - I find myself doing this extremely often, it's incredibly helpful.

how to get value from spinctrl and send it to .exe file in python script

I am new to python and wxpython, I am making a automated tool using python and for user interface wxpython and i use shell script.shell script can be called from the python. but now I am facing problem with the spinctrl value. whenever that spinctrl value changes it have to send that value into one txt.exe file which is written in BASH .{ if we run txt.exe file in command line it will ask for number then it will accept that value whenever we press enter}. but i am not able to understand that how to send value from spinctrl to txt.exe whenever i press "ok" button in GUI. please share your thoughts and knowledge.
Thank you
To call an executable in Python, you need to look at Python's subprocess module: http://docs.python.org/2/library/subprocess.html
If your exe doesn't accept arguments, then it won't work. If you created the exe yourself using something like PyInstaller or py2Exe, then you need to make it so your app can accept arguments. The simplest way is using sys.argv, but there are also the optparse and argparse libraries in Python as well.
I do not get a good feeling about your concept. It is hard to say, but I suspect you would benefit from talking with someone experienced about what you are trying to achieve and how it could best be done.
However, to get you started down your current path, I think you should take a look at wxExecute ( http://docs.wxwidgets.org/2.8/wx_processfunctions.html#wxexecute ). This will allow you to run your txt.exe utility from inside your GUI.
wxExecute is a wxWidgets utility. If you are working in python then there will be a more direct way to do this using a python utility - some-one else will have to advise on that. I suggest you edit your question for clarity so a python expert can help you.

Django -editing files in bash

I just installed Django on my Mac and I am trying to figure out a way to edit the python modules directly from the terminal.
I know I can view the contents of a file using the less command in the command line, but is there a way I can edit Django modules from the command line, as well? It's just kind of annoying having to switch between the command line and a text editor, so I was hoping I could do everything in one spot.
Thanks,
Jerry
EDIT: rephrased.
There are lots of TUI text editors available for *nix. vim and emacs are popular, and are available in several forms for OS X.
This question is a little confused.
There's no such thing as "editing in Python", or "editing in Bash". I don't know what you're regarding as the "Python" that you have to switch to, but most people using a Mac edit their Python files in something like Textmate. That can be always running, and the Django development server automatically reloads when you save changes to any of the files in use, so this is the often most convenient way of doing it.
Bash is the shell that runs inside the terminal. Instead of talking about "editing in Bash", I expect you mean "editing in the terminal". Of course, there are hundreds of editors that run inside the terminal. One that comes installed on the Mac is vim, which I use all the time - but it has its fair share of idiosyncrasies, and takes a lot of getting used to.
However, if anything, editing in vim inside the terminal seems like it would involve more "switching" rather than less. You'd either need to have a separate terminal tab, and switch between the one running the server and the one running vim, or continually quit your server to go into vim.