Skip to main content

PyCharm vs IDLE: oddities

First learning: be explicit in PyCharm. I was using the following to work with reading a file using readlines()

sonnetFile = open('/home/csaunderson/learning/sonnet29.txt')
sonnetFile.readlines()

which returned correctly in IDLE:

>>> sonnetFile = open('/home/csaunderson/learning/sonnet29.txt')
>>> sonnetFile.readlines()
["When, in disgrace with fortune and men's eyes,\n", 'I all alone beweep my outcast state,\n', 'And trouble deaf heaven with my bootless cries,\n', 'And look upon myself and curse my fate,\n']

But in PyCharm, it returned simply a return code zero, which is success, but failure.

Instead, I had to explicitly print() the output:


sonnetFile = open('/home/csaunderson/learning/sonnet29.txt')
print(sonnetFile.readlines())

Which then gave me:
/home/csaunderson/PycharmProjects/learning/venv/bin/python /home/csaunderson/learning/first_readlines.py
["When, in disgrace with fortune and men's eyes,\n", 'I all alone beweep my outcast state,\n', 'And trouble deaf heaven with my bootless cries,\n', 'And look upon myself and curse my fate,\n', '\n']

Process finished with exit code 0

Conversely: the code to explicitly call it out in IDLE works also:

>>> sonnetFile = open('/home/csaunderson/learning/sonnet29.txt')
>>> print(sonnetFile.readlines())
["When, in disgrace with fortune and men's eyes,\n", 'I all alone beweep my outcast state,\n', 'And trouble deaf heaven with my bootless cries,\n', 'And look upon myself and curse my fate,\n', '\n']

This is a learning for later: I need to make sure that I'm testing my work from time to time in order to make sure things are working the way I want.

Comments

Popular posts from this blog

Python 2 vs Python 3

I'm going to start learning in Python3, but with an eye to keeping things compatible with Python 2.7. I'm not sure how well that'll work, but it'll be necessary in order to be able to work with the HPSA pytwist APIs