Hi all,

I'm fairly new to programming in Python, and I have been getting on pretty well. I had a little working program compiled from old code snippets I had found online, converted to working 3.x code and combined together with some of my own ideas to create simple apps.

Now, for no apparent reason, the code no longer works. Errors are being generated and I am very confused as the code had not been edited in any way. There are 2 issues I am getting at the moment, which I'll detail below along with the relevant code sections.

Issue 1 -

sys.stdout.writelines no longer works and gives the following error:

Message File Name Line Position
Traceback
<module> C:\Python31\Programs\Build Information Consistency Checker\abicc.py 54
createQuickView C:\Python31\Programs\Build Information Consistency Checker\abiccfunc.py 68
AttributeError: 'DebugOutput' object has no attribute 'writelines'

Highlighted code:

sys.stdout.writelines(added_dirs)

I can provide the full function code if necessary, but the error tells me the sys.stdout doesn't have an atribute called writelines. It did last week and has been working for a few weeks now.

*****************************************************

Issue 2 - EOF when reading line which is awaiting text input. These files were all working but now have suddenly just stopped. Starting with the output of the program as displayed in the interpreter:

Build & Install Consistency Checker
***********************************

Microsoft Windows XP Service Pack 3 (build 2600)
Intel(R) Pentium(R) M processor 1.70GHz
Browsers:
Mozilla Firefox 3.5.3 (en-GB)
Internet Explorer 8.0.6001.18702
RAM : 503Mb total
RAM : 142Mb free
System HD : 20Gb free
Page File : 435Mb free

Please choose install to check for consistency:

1. ICM Database

9. Exit

Traceback (most recent call last):
File "C:\Python31\Programs\BUILDI~1\abicc.py", line 49, in <module>
select = menu()
File "C:\Python31\Programs\BUILDI~1\abicc.py", line 26, in menu
select = input("\t")
EOFError: EOF when reading a line

Process "Python Interpreter" terminated, ExitCode: 00000001

code of function that is providing error:

def menu():
    print ('''
Please choose install to check for consistency:

    1.  ICM Database

    9.  Exit
    ''')
    select = input("\t")
    return select #Returns users choice from function

Both of these are from different modules of a program I am working on, but they were all working fine, with no editing they have stopped working, generating these errors. Have there been any changes to affect my code, bearing in mind I have not updated my python.

Thanks in advance for your assistance
Andy

If your using old Python code with Python 3.x.x then you may have to port the programs because Python 3.x.x doesn't guarantee backwards compatibility

Its too early to start using python 3.0+, everyone is using 2.6, 3.0+ isn't compatible with previous version because they changed the code syntax and the way some builtin functions work. I'd say go for 2.6 or anything v2 basically, its still supported and about 99.9% of people use 2.x instead on 3.x

Let me clarify..

I found old code snippets online from python versions as far back as 1.3, all the way upto 2.6.

I then re-wrote all of these code snippets in python 3.x, creating new code where necessary. Up until today my python 3.x application has been working perfectly, and with no changes to the code, it has stopped working and is generating these errors.

I am not interested in python before 3.x, by the time I become proficient in Python, 3.x will be the standard, so I don't see the point of learning an old version of a language. If something doesn't work in 3.x, then I re-write it so it does. This helps accelerate my learning greatly, because I am writing programs I would never even been able to conceive had I learn't from the bottom up.

My whole program worked perfectly until today, and I haven't edited any code.

Any help is greatly appreciated :)

first off try using the raw_input function rather than the input function, second off pythion 3.x may never become standard, they may just skip it or drag 2.x out for a long long time, thing is no one like 3.x because they made very little changes and those changes aren't really worth porting all your old code to, so skipping back to 2.x would be the smartest choice in my opinion.

first off try using the raw_input function rather than the input function, second off pythion 3.x may never become standard, they may just skip it or drag 2.x out for a long long time, thing is no one like 3.x because they made very little changes and those changes aren't really worth porting all your old code to, so skipping back to 2.x would be the smartest choice in my opinion.

I think soulrider is the smart person here.

The code you gave works fine with Python 3.1.1 using IDLE. Which IDE are you using?

On another note, why on Earth would you use
sys.stdout.writelines(added_dirs) ???
That is what the print() function is for.

commented: well said sir! +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.