First learning: be explicit in PyCharm. I was using the following to work with reading a file using 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:
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.
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
Post a Comment