473,378 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Jython

Hi

Why this doesn't work:

def go():
for line in open("bobo.txt", "r"):
print line

go()

python FileReader.py: everything ok
jython FileReader.py:

Traceback (innermost last):
File "FileReader.py", line 6
File "FileReader.py", line 3
AttributeError: __getitem__

--
"A mi smo stranci u vlastitoj zemlji zbog ljudskog sljama, lipa nasa
silovana"
Feb 3 '07 #1
6 1859
On Feb 3, 11:21 am, Boris Ozegovic <silovana.vjever...@com.gmail>
wrote:
Hi

Why this doesn't work:

def go():
for line in open("bobo.txt", "r"):
print line

go()

python FileReader.py: everything ok
jython FileReader.py:

Traceback (innermost last):
File "FileReader.py", line 6
File "FileReader.py", line 3
AttributeError: __getitem__

--
"A mi smo stranci u vlastitoj zemlji zbog ljudskog sljama, lipa nasa
silovana"
Files aren't lists and thus don't have the functions for iteration.

Try:

def go():
for line in open("bobo.txt", "r").readlines():
print line

go()

Feb 3 '07 #2
gr******@mindspring.com wrote:
Files aren't lists and thus don't have the functions for iteration.
They do have iterator:

C:\Documents and Settings\Silovana Vjeverica\Desktop>python FileReader.py
'import site' failed; use -v for traceback
boris ozegovic
vedran ozegovic

--
"A mi smo stranci u vlastitoj zemlji zbog ljudskog sljama, lipa nasa
silovana"
Feb 3 '07 #3
Boris Ozegovic wrote:
gr******@mindspring.com wrote:
>Files aren't lists and thus don't have the functions for iteration.

They do have iterator:

C:\Documents and Settings\Silovana Vjeverica\Desktop>python FileReader.py
'import site' failed; use -v for traceback
boris ozegovic
vedran ozegovic
But apparently not in Jython... Only Python.

Tnx, anyway

--
"A mi smo stranci u vlastitoj zemlji zbog ljudskog sljama, lipa nasa
silovana"
Feb 3 '07 #4
gr******@mindspring.com wrote:
Files aren't lists and thus don't have the functions for iteration.

Try:

def go():
for line in open("bobo.txt", "r").readlines():
print line

go()
For example, you can do even this:

import sys

for line in sys.stdin:
print line,
python FileReader.py < bobo.tx

'import site' failed; use -v for traceback
boris ozegovic
vedran ozegovic

--
"A mi smo stranci u vlastitoj zemlji zbog ljudskog sljama, lipa nasa
silovana"
Feb 3 '07 #5
Boris Ozegovic wrote:
Boris Ozegovic wrote:
>gr******@mindspring.com wrote:
>>Files aren't lists and thus don't have the functions for iteration.

They do have iterator:

C:\Documents and Settings\Silovana Vjeverica\Desktop>python FileReader.py
'import site' failed; use -v for traceback
boris ozegovic
vedran ozegovic

But apparently not in Jython... Only Python.
Iterable files were introduced in Python 2.2. Jython implements Python2.1,
it seems.

Peter
Feb 3 '07 #6
gregt...@mindspring.com:
Files aren't lists and thus don't have the functions for iteration.
Try:
def go():
for line in open("bobo.txt", "r").readlines():
print line
go()
CPython 2.1 has xreadlines, maybe Jython has it too.

Bye,
bearophile

Feb 3 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Chermside | last post by:
Ype writes: > For the namespaces in Jython this 'Python internal thread safety' > is handled by the Java class: > > http://www.jython.org/docs/javadoc/org/python/core/PyStringMap.html > > which...
6
by: Dave Benjamin | last post by:
Hey good people, I've been doing a lot of simultaneous Jython and CPython programming lately, and just wanted to say, with no intended ill will toward any of the individuals who have been...
4
by: angel | last post by:
A java runtime environment includes jvm and java class (for example classes.zip in sun jre). Of course jython need jvm,but does it need java class. Thanx
7
by: Jan Gregor | last post by:
Hello I found that jython catches exact java exceptions, not their subclasses. Is there some way to get around this limitation (or error) ? My program has class representing database source...
1
by: scott | last post by:
I installed darwinports and did a "sudo port install jython" ------------------------- scott$ which jython /opt/local/bin/jython ------------------------- Jython works in interactive...
12
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it...
3
by: Sloan.Kohler | last post by:
Is Jython development dead or has it just seemed that way for over a year?. The jython.org website has a recent new appearance (but no new content) and there is some message traffic on the...
3
by: donkeyboy | last post by:
All, I'm having issues installing Jython on Windows XP. I've looked on the web and this newsgroup but to no avail. Any suggestions? The shell listing is below: NB I've got Cygwin installed,...
4
by: Neil Wallace | last post by:
Hi all, I am a novice Python/Jython programmer, and Ubuntu user. Ubuntu still only supports only version 2.1 of Jython. I have used the GUI installer of Jython 2.2, and installed it to the...
5
by: sarup26 | last post by:
Hello .. I would like to know more about Python and Jython? What is the difference between both of them? What is the future for Jython and which are the areas where it is used? Swot
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.