Orange Forum • View topic - Tutorial help: "Load-In The Data"

Tutorial help: "Load-In The Data"

A place to ask questions about methods in Orange and how they are used and other general support.

Tutorial help: "Load-In The Data"

Postby matthewddsg » Sat Dec 01, 2012 17:21

I'm encountering a recurring syntax error while working in the Python (command line) app in Python 2.7 (I am unable to access Python from the command line otherwise). While attempting to enter:

Code: Select all
import orange
data = orange.ExampleTable("lenses")
print "Attributes:",
for i in data.domain.attributes:
    print i.name,
print
print "Class:", data.domain.classVar.name

print "First 5 data items:"
for i in range(5):
   print data[i]

I get the following result:

Code: Select all
>>> import orange
>>> data = orange.ExampleTable("lenses")
>>> print "Attributes:",
Attributes:
>>> for i in data.domain.attributes:
  File "<stdin>", line 1
    for in in data.domain.attributes:

SyntaxError: invalid syntax

I'm new to coding in general and neither understand the problem nor know how to address it. Any help would be greatly appreciated.

Re: Tutorial help: "Load-In The Data"

Postby Ales » Mon Dec 03, 2012 12:17

matthewddsg wrote:I am unable to access Python from the command line otherwise
Do you have 'C:\Python27\' in your PATH (run 'echo %PATH%' from the command line to check). Even so you should be able to run 'C:\Python27\python.exe' directly. Also see http://code.google.com/p/tryton/wiki/AddingPythonToWindowsPath
matthewddsg wrote:>>> for i in data.domain.attributes:
File "<stdin>", line 1
for in in data.domain.attributes:

SyntaxError: invalid syntax
The line written at the prompt does not match the one in the error message. I am assuming the one in the error message is correct as that is the one that is not a valid Python syntax.
In particular 'in' is a reserved keyword in python and you can't use it as a variable name (which the 'for in in data.domain.attributes' does implicitly).

Re: Tutorial help: "Load-In The Data"

Postby matthewddsg » Mon Dec 03, 2012 15:58

Ales

When I run 'echo %PATH%' is returns a number of lines, beginning with:

Code: Select all
C:\\Python27\Lib\site-packages\PyQt4\bin

I honestly do not know what this indicates.

Can you tell me how/where to run the 'win_add2path.py' script?

The error message is what appears in my Python (command line) app. After I enter 'print "Attributes:",' the 'Attributes' line appears automatically.

The implicit variable name to which you refer appears as 'i,' as in 'for i in data.domain.attributes.' I'm not sure what this indicates as I'm only just learning Python.

Thanks for your help.

Re: Tutorial help: "Load-In The Data"

Postby Ales » Mon Dec 03, 2012 17:13

matthewddsg wrote:When I run 'echo %PATH%' is returns a number of lines, beginning with:

Code: Select all
C:\\Python27\Lib\site-packages\PyQt4\bin


I honestly do not know what this indicates.

You want to make sure 'C:\\Python27' is in the list (';' separates individual paths) i.e. without any sub directories. Check the whole output.

matthewddsg wrote:Can you tell me how/where to run the 'win_add2path.py' script?

Code: Select all
C:\Python27\python.exe C:\Python27\Tools\Scripts\win_add2path.py


matthewddsg wrote:The implicit variable name to which you refer appears as 'i,' as in 'for i in data.domain.attributes.'

Code: Select all
for i in data.domain.attributes:
is valid python syntax and should not raise a SyntaxError. Are you sure you are entering the the code exactly as written. Maybe try a simpler example in a fresh interpreter instance
Code: Select all
for item in range(10):
    print item

Re: Tutorial help: "Load-In The Data"

Postby Ales » Mon Dec 03, 2012 17:15

Also if you are having problems copying text from the command prompt see http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/windows_dos_copy.mspx?mfr=true


Return to Questions & Support